diff --git a/src/Contacts/Threads/TSContactThread.m b/src/Contacts/Threads/TSContactThread.m index 47875cb81..63d4285bb 100644 --- a/src/Contacts/Threads/TSContactThread.m +++ b/src/Contacts/Threads/TSContactThread.m @@ -20,6 +20,8 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithContactId:(NSString *)contactId { NSString *uniqueIdentifier = [[self class] threadIdFromContactId:contactId]; + OWSAssert(contactId.length > 0); + self = [super initWithUniqueId:uniqueIdentifier]; return self; @@ -29,7 +31,8 @@ NS_ASSUME_NONNULL_BEGIN transaction:(YapDatabaseReadWriteTransaction *)transaction relay:(nullable NSString *)relay { - OWSAssert(contactId); + OWSAssert(contactId.length > 0); + SignalRecipient *recipient = [SignalRecipient recipientWithTextSecureIdentifier:contactId withTransaction:transaction]; @@ -55,6 +58,8 @@ NS_ASSUME_NONNULL_BEGIN + (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId transaction:(YapDatabaseReadWriteTransaction *)transaction { + OWSAssert(contactId.length > 0); + TSContactThread *thread = [self fetchObjectWithUniqueID:[self threadIdFromContactId:contactId] transaction:transaction]; @@ -68,6 +73,8 @@ NS_ASSUME_NONNULL_BEGIN + (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId { + OWSAssert(contactId.length > 0); + __block TSContactThread *thread; [[self dbConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { thread = [self getOrCreateThreadWithContactId:contactId transaction:transaction]; diff --git a/src/Contacts/Threads/TSGroupThread.m b/src/Contacts/Threads/TSGroupThread.m index 4bcef274b..ac48250d8 100644 --- a/src/Contacts/Threads/TSGroupThread.m +++ b/src/Contacts/Threads/TSGroupThread.m @@ -18,6 +18,13 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithGroupModel:(TSGroupModel *)groupModel { + OWSAssert(groupModel); + OWSAssert(groupModel.groupId.length > 0); + OWSAssert(groupModel.groupMemberIds.count > 0); + for (NSString *recipientId in groupModel.groupMemberIds) { + OWSAssert(recipientId.length > 0); + } + NSString *uniqueIdentifier = [[self class] threadIdFromGroupId:groupModel.groupId]; self = [super initWithUniqueId:uniqueIdentifier]; if (!self) { @@ -31,6 +38,8 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithGroupIdData:(NSData *)groupId { + OWSAssert(groupId.length > 0); + TSGroupModel *groupModel = [[TSGroupModel alloc] initWithTitle:nil memberIds:nil image:nil groupId:groupId]; self = [self initWithGroupModel:groupModel]; @@ -43,11 +52,16 @@ NS_ASSUME_NONNULL_BEGIN + (instancetype)threadWithGroupModel:(TSGroupModel *)groupModel transaction:(YapDatabaseReadTransaction *)transaction { + OWSAssert(groupModel); + OWSAssert(groupModel.groupId.length > 0); + return [self fetchObjectWithUniqueID:[self threadIdFromGroupId:groupModel.groupId] transaction:transaction]; } + (instancetype)getOrCreateThreadWithGroupIdData:(NSData *)groupId { + OWSAssert(groupId.length > 0); + TSGroupThread *thread = [self fetchObjectWithUniqueID:[self threadIdFromGroupId:groupId]]; if (!thread) { thread = [[self alloc] initWithGroupIdData:groupId]; @@ -58,6 +72,9 @@ NS_ASSUME_NONNULL_BEGIN + (instancetype)getOrCreateThreadWithGroupModel:(TSGroupModel *)groupModel transaction:(YapDatabaseReadWriteTransaction *)transaction { + OWSAssert(groupModel); + OWSAssert(groupModel.groupId.length > 0); + TSGroupThread *thread = [self fetchObjectWithUniqueID:[self threadIdFromGroupId:groupModel.groupId] transaction:transaction]; @@ -70,6 +87,9 @@ NS_ASSUME_NONNULL_BEGIN + (instancetype)getOrCreateThreadWithGroupModel:(TSGroupModel *)groupModel { + OWSAssert(groupModel); + OWSAssert(groupModel.groupId.length > 0); + __block TSGroupThread *thread; [[self dbConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { thread = [self getOrCreateThreadWithGroupModel:groupModel transaction:transaction]; @@ -79,11 +99,15 @@ NS_ASSUME_NONNULL_BEGIN + (NSString *)threadIdFromGroupId:(NSData *)groupId { + OWSAssert(groupId.length > 0); + return [TSGroupThreadPrefix stringByAppendingString:[groupId base64EncodedString]]; } + (NSData *)groupIdFromThreadId:(NSString *)threadId { + OWSAssert(threadId.length > 0); + return [NSData dataFromBase64String:[threadId substringWithRange:NSMakeRange(1, threadId.length - 1)]]; } diff --git a/src/Messages/Interactions/TSErrorMessage.h b/src/Messages/Interactions/TSErrorMessage.h index 585b48782..2355778c3 100644 --- a/src/Messages/Interactions/TSErrorMessage.h +++ b/src/Messages/Interactions/TSErrorMessage.h @@ -16,7 +16,7 @@ typedef NS_ENUM(int32_t, TSErrorMessageType) { TSErrorMessageInvalidKeyException, TSErrorMessageMissingKeyId, // unused TSErrorMessageInvalidMessage, - TSErrorMessageDuplicateMessage, + TSErrorMessageDuplicateMessage, // unused TSErrorMessageInvalidVersion, TSErrorMessageNonBlockingIdentityChange, TSErrorMessageUnknownContactBlockOffer, diff --git a/src/Messages/Interactions/TSInfoMessage.h b/src/Messages/Interactions/TSInfoMessage.h index ddae00f44..7ee7c924a 100644 --- a/src/Messages/Interactions/TSInfoMessage.h +++ b/src/Messages/Interactions/TSInfoMessage.h @@ -12,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN typedef NS_ENUM(NSInteger, TSInfoMessageType) { TSInfoMessageTypeSessionDidEnd, TSInfoMessageUserNotRegistered, + // TSInfoMessageTypeUnsupportedMessage appears to be obsolete. TSInfoMessageTypeUnsupportedMessage, TSInfoMessageTypeGroupUpdate, TSInfoMessageTypeGroupQuit,