Maps numbers to names in TSGroupModel

* Maps numbers to names in TSGroupModel

Use an injected ContactsManager to look up proper user names for phone numbers in [TSGroupModel getInfoStringAboutUpdateTo].
Fixes WhisperSystems/Signal-iOS#757

* Supports custom messages for TSOutgoingMessage

This will enable Signal-iOS to push detailed information about TSGroupModel updates through SignalServiceKit and into the TSInfoMessage created by TSMessagesManager+sendMessages

// FREEBIE
pull/1/head
Matthew Douglass 9 years ago committed by Michael Kirk
parent 556dca6502
commit d4c55d6940

@ -46,6 +46,7 @@ typedef NS_ENUM(NSInteger, TSOutgoingMessageState) {
@property (nonatomic) TSOutgoingMessageState messageState; @property (nonatomic) TSOutgoingMessageState messageState;
@property BOOL hasSyncedTranscript; @property BOOL hasSyncedTranscript;
@property NSString *customMessage;
/** /**
* Signal Identifier (e.g. e164 number) or nil if in a group thread. * Signal Identifier (e.g. e164 number) or nil if in a group thread.

@ -2,6 +2,7 @@
// Copyright (c) 2014 Open Whisper Systems. All rights reserved. // Copyright (c) 2014 Open Whisper Systems. All rights reserved.
#import "TSYapDatabaseObject.h" #import "TSYapDatabaseObject.h"
#import "ContactsManagerProtocol.h"
@interface TSGroupModel : TSYapDatabaseObject @interface TSGroupModel : TSYapDatabaseObject
@ -19,7 +20,7 @@
- (BOOL)isEqual:(id)other; - (BOOL)isEqual:(id)other;
- (BOOL)isEqualToGroupModel:(TSGroupModel *)model; - (BOOL)isEqualToGroupModel:(TSGroupModel *)model;
- (NSString *)getInfoStringAboutUpdateTo:(TSGroupModel *)model; - (NSString *)getInfoStringAboutUpdateTo:(TSGroupModel *)model contactsManager:(id<ContactsManagerProtocol>)contactsManager;
#endif #endif

@ -2,6 +2,7 @@
// Copyright (c) 2014 Open Whisper Systems. All rights reserved. // Copyright (c) 2014 Open Whisper Systems. All rights reserved.
#import "TSGroupModel.h" #import "TSGroupModel.h"
#import "FunctionalUtil.h"
@implementation TSGroupModel @implementation TSGroupModel
@ -50,7 +51,7 @@
return YES; return YES;
} }
- (NSString *)getInfoStringAboutUpdateTo:(TSGroupModel *)newModel { - (NSString *)getInfoStringAboutUpdateTo:(TSGroupModel *)newModel contactsManager:(id<ContactsManagerProtocol>)contactsManager {
NSString *updatedGroupInfoString = @""; NSString *updatedGroupInfoString = @"";
if (self == newModel) { if (self == newModel) {
return NSLocalizedString(@"GROUP_UPDATED", @""); return NSLocalizedString(@"GROUP_UPDATED", @"");
@ -79,17 +80,22 @@
if ([membersWhoLeft count] > 0) { if ([membersWhoLeft count] > 0) {
NSArray *oldMembersNames = [[membersWhoLeft allObjects] map:^NSString*(NSString* item) {
return [contactsManager nameStringForPhoneIdentifier:item];
}];
updatedGroupInfoString = [updatedGroupInfoString updatedGroupInfoString = [updatedGroupInfoString
stringByAppendingString:[NSString stringByAppendingString:[NSString
stringWithFormat:NSLocalizedString(@"GROUP_MEMBER_LEFT", @""), stringWithFormat:NSLocalizedString(@"GROUP_MEMBER_LEFT", @""),
[[membersWhoLeft allObjects] componentsJoinedByString:@", "]]]; [oldMembersNames componentsJoinedByString:@", "]]];
} }
if ([membersWhoJoined count] > 0) { if ([membersWhoJoined count] > 0) {
NSArray *newMembersNames = [[membersWhoJoined allObjects] map:^NSString*(NSString* item) {
return [contactsManager nameStringForPhoneIdentifier:item];
}];
updatedGroupInfoString = [updatedGroupInfoString updatedGroupInfoString = [updatedGroupInfoString
stringByAppendingString:[NSString stringWithFormat:NSLocalizedString(@"GROUP_MEMBER_JOINED", @""), stringByAppendingString:[NSString stringWithFormat:NSLocalizedString(@"GROUP_MEMBER_JOINED", @""),
[[membersWhoJoined allObjects] [newMembersNames componentsJoinedByString:@", "]]];
componentsJoinedByString:@", "]]];
} }
return updatedGroupInfoString; return updatedGroupInfoString;

@ -583,14 +583,16 @@ dispatch_queue_t sendingQueue() {
[[[TSInfoMessage alloc] initWithTimestamp:message.timestamp [[[TSInfoMessage alloc] initWithTimestamp:message.timestamp
inThread:thread inThread:thread
messageType:TSInfoMessageTypeGroupQuit] saveWithTransaction:transaction]; messageType:TSInfoMessageTypeGroupQuit
customMessage:message.customMessage] saveWithTransaction:transaction];
}]; }];
} else { } else {
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[[[TSInfoMessage alloc] initWithTimestamp:message.timestamp [[[TSInfoMessage alloc] initWithTimestamp:message.timestamp
inThread:thread inThread:thread
messageType:TSInfoMessageTypeGroupUpdate] saveWithTransaction:transaction]; messageType:TSInfoMessageTypeGroupUpdate
customMessage:message.customMessage] saveWithTransaction:transaction];
}]; }];
} }
} }

@ -412,7 +412,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
NSString *updateGroupInfo = [gThread.groupModel getInfoStringAboutUpdateTo:model]; NSString *updateGroupInfo = [gThread.groupModel getInfoStringAboutUpdateTo:model contactsManager:self.contactsManager];
gThread.groupModel = model; gThread.groupModel = model;
[gThread saveWithTransaction:transaction]; [gThread saveWithTransaction:transaction];
[[[TSInfoMessage alloc] initWithTimestamp:timestamp [[[TSInfoMessage alloc] initWithTimestamp:timestamp

Loading…
Cancel
Save