Rework and unify the system messages.

// FREEBIE
pull/1/head
Matthew Chen 9 years ago
parent 0ad794dfd9
commit f63c85f5d5

@ -20,6 +20,8 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithContactId:(NSString *)contactId { - (instancetype)initWithContactId:(NSString *)contactId {
NSString *uniqueIdentifier = [[self class] threadIdFromContactId:contactId]; NSString *uniqueIdentifier = [[self class] threadIdFromContactId:contactId];
OWSAssert(contactId.length > 0);
self = [super initWithUniqueId:uniqueIdentifier]; self = [super initWithUniqueId:uniqueIdentifier];
return self; return self;
@ -29,7 +31,8 @@ NS_ASSUME_NONNULL_BEGIN
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
relay:(nullable NSString *)relay relay:(nullable NSString *)relay
{ {
OWSAssert(contactId); OWSAssert(contactId.length > 0);
SignalRecipient *recipient = SignalRecipient *recipient =
[SignalRecipient recipientWithTextSecureIdentifier:contactId withTransaction:transaction]; [SignalRecipient recipientWithTextSecureIdentifier:contactId withTransaction:transaction];
@ -55,6 +58,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId + (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId
transaction:(YapDatabaseReadWriteTransaction *)transaction { transaction:(YapDatabaseReadWriteTransaction *)transaction {
OWSAssert(contactId.length > 0);
TSContactThread *thread = TSContactThread *thread =
[self fetchObjectWithUniqueID:[self threadIdFromContactId:contactId] transaction:transaction]; [self fetchObjectWithUniqueID:[self threadIdFromContactId:contactId] transaction:transaction];
@ -68,6 +73,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId + (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId
{ {
OWSAssert(contactId.length > 0);
__block TSContactThread *thread; __block TSContactThread *thread;
[[self dbConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [[self dbConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
thread = [self getOrCreateThreadWithContactId:contactId transaction:transaction]; thread = [self getOrCreateThreadWithContactId:contactId transaction:transaction];

@ -18,6 +18,13 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithGroupModel:(TSGroupModel *)groupModel - (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]; NSString *uniqueIdentifier = [[self class] threadIdFromGroupId:groupModel.groupId];
self = [super initWithUniqueId:uniqueIdentifier]; self = [super initWithUniqueId:uniqueIdentifier];
if (!self) { if (!self) {
@ -31,6 +38,8 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithGroupIdData:(NSData *)groupId - (instancetype)initWithGroupIdData:(NSData *)groupId
{ {
OWSAssert(groupId.length > 0);
TSGroupModel *groupModel = [[TSGroupModel alloc] initWithTitle:nil memberIds:nil image:nil groupId:groupId]; TSGroupModel *groupModel = [[TSGroupModel alloc] initWithTitle:nil memberIds:nil image:nil groupId:groupId];
self = [self initWithGroupModel:groupModel]; self = [self initWithGroupModel:groupModel];
@ -43,11 +52,16 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)threadWithGroupModel:(TSGroupModel *)groupModel transaction:(YapDatabaseReadTransaction *)transaction + (instancetype)threadWithGroupModel:(TSGroupModel *)groupModel transaction:(YapDatabaseReadTransaction *)transaction
{ {
OWSAssert(groupModel);
OWSAssert(groupModel.groupId.length > 0);
return [self fetchObjectWithUniqueID:[self threadIdFromGroupId:groupModel.groupId] transaction:transaction]; return [self fetchObjectWithUniqueID:[self threadIdFromGroupId:groupModel.groupId] transaction:transaction];
} }
+ (instancetype)getOrCreateThreadWithGroupIdData:(NSData *)groupId + (instancetype)getOrCreateThreadWithGroupIdData:(NSData *)groupId
{ {
OWSAssert(groupId.length > 0);
TSGroupThread *thread = [self fetchObjectWithUniqueID:[self threadIdFromGroupId:groupId]]; TSGroupThread *thread = [self fetchObjectWithUniqueID:[self threadIdFromGroupId:groupId]];
if (!thread) { if (!thread) {
thread = [[self alloc] initWithGroupIdData:groupId]; thread = [[self alloc] initWithGroupIdData:groupId];
@ -58,6 +72,9 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)getOrCreateThreadWithGroupModel:(TSGroupModel *)groupModel + (instancetype)getOrCreateThreadWithGroupModel:(TSGroupModel *)groupModel
transaction:(YapDatabaseReadWriteTransaction *)transaction { transaction:(YapDatabaseReadWriteTransaction *)transaction {
OWSAssert(groupModel);
OWSAssert(groupModel.groupId.length > 0);
TSGroupThread *thread = TSGroupThread *thread =
[self fetchObjectWithUniqueID:[self threadIdFromGroupId:groupModel.groupId] transaction:transaction]; [self fetchObjectWithUniqueID:[self threadIdFromGroupId:groupModel.groupId] transaction:transaction];
@ -70,6 +87,9 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)getOrCreateThreadWithGroupModel:(TSGroupModel *)groupModel + (instancetype)getOrCreateThreadWithGroupModel:(TSGroupModel *)groupModel
{ {
OWSAssert(groupModel);
OWSAssert(groupModel.groupId.length > 0);
__block TSGroupThread *thread; __block TSGroupThread *thread;
[[self dbConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [[self dbConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
thread = [self getOrCreateThreadWithGroupModel:groupModel transaction:transaction]; thread = [self getOrCreateThreadWithGroupModel:groupModel transaction:transaction];
@ -79,11 +99,15 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)threadIdFromGroupId:(NSData *)groupId + (NSString *)threadIdFromGroupId:(NSData *)groupId
{ {
OWSAssert(groupId.length > 0);
return [TSGroupThreadPrefix stringByAppendingString:[groupId base64EncodedString]]; return [TSGroupThreadPrefix stringByAppendingString:[groupId base64EncodedString]];
} }
+ (NSData *)groupIdFromThreadId:(NSString *)threadId + (NSData *)groupIdFromThreadId:(NSString *)threadId
{ {
OWSAssert(threadId.length > 0);
return [NSData dataFromBase64String:[threadId substringWithRange:NSMakeRange(1, threadId.length - 1)]]; return [NSData dataFromBase64String:[threadId substringWithRange:NSMakeRange(1, threadId.length - 1)]];
} }

@ -16,7 +16,7 @@ typedef NS_ENUM(int32_t, TSErrorMessageType) {
TSErrorMessageInvalidKeyException, TSErrorMessageInvalidKeyException,
TSErrorMessageMissingKeyId, // unused TSErrorMessageMissingKeyId, // unused
TSErrorMessageInvalidMessage, TSErrorMessageInvalidMessage,
TSErrorMessageDuplicateMessage, TSErrorMessageDuplicateMessage, // unused
TSErrorMessageInvalidVersion, TSErrorMessageInvalidVersion,
TSErrorMessageNonBlockingIdentityChange, TSErrorMessageNonBlockingIdentityChange,
TSErrorMessageUnknownContactBlockOffer, TSErrorMessageUnknownContactBlockOffer,

@ -12,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, TSInfoMessageType) { typedef NS_ENUM(NSInteger, TSInfoMessageType) {
TSInfoMessageTypeSessionDidEnd, TSInfoMessageTypeSessionDidEnd,
TSInfoMessageUserNotRegistered, TSInfoMessageUserNotRegistered,
// TSInfoMessageTypeUnsupportedMessage appears to be obsolete.
TSInfoMessageTypeUnsupportedMessage, TSInfoMessageTypeUnsupportedMessage,
TSInfoMessageTypeGroupUpdate, TSInfoMessageTypeGroupUpdate,
TSInfoMessageTypeGroupQuit, TSInfoMessageTypeGroupQuit,

Loading…
Cancel
Save