Only reply to group info requester.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 85ccf2db78
commit 8d10d19f8f

@ -94,6 +94,9 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
@property (atomic, readonly) TSGroupMetaMessage groupMetaMessage; @property (atomic, readonly) TSGroupMetaMessage groupMetaMessage;
// If set, this group message should only be sent to a single recipient.
@property (atomic, readonly) NSString *singleGroupRecipient;
/** /**
* Whether the message should be serialized as a modern aka Content, or the old style legacy message. * Whether the message should be serialized as a modern aka Content, or the old style legacy message.
* Sync and Call messsages must be sent as Content, but other old style DataMessage payloads should be * Sync and Call messsages must be sent as Content, but other old style DataMessage payloads should be
@ -168,6 +171,8 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
- (void)updateWithWasDeliveredWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; - (void)updateWithWasDeliveredWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
- (void)updateWithWasDelivered; - (void)updateWithWasDelivered;
- (void)updateWithWasSentAndDelivered; - (void)updateWithWasSentAndDelivered;
- (void)updateWithSingleGroupRecipient:(NSString *)singleGroupRecipient
transaction:(YapDatabaseReadWriteTransaction *)transaction;
#pragma mark - Sent Recipients #pragma mark - Sent Recipients

@ -22,6 +22,7 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
@property (atomic) NSString *customMessage; @property (atomic) NSString *customMessage;
@property (atomic) NSString *mostRecentFailureText; @property (atomic) NSString *mostRecentFailureText;
@property (atomic) BOOL wasDelivered; @property (atomic) BOOL wasDelivered;
@property (atomic) NSString *singleGroupRecipient;
// For outgoing, non-legacy group messages sent from this client, this // For outgoing, non-legacy group messages sent from this client, this
// contains the list of recipients to whom the message has been sent. // contains the list of recipients to whom the message has been sent.
@ -321,6 +322,18 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
}]; }];
} }
- (void)updateWithSingleGroupRecipient:(NSString *)singleGroupRecipient
transaction:(YapDatabaseReadWriteTransaction *)transaction
{
OWSAssert(transaction);
OWSAssert(singleGroupRecipient.length > 0);
[self applyChangeToSelfAndLatestOutgoingMessage:transaction
changeBlock:^(TSOutgoingMessage *message) {
[message setSingleGroupRecipient:singleGroupRecipient];
}];
}
#pragma mark - Sent Recipients #pragma mark - Sent Recipients
- (NSArray<NSString *> *)sentRecipients - (NSArray<NSString *> *)sentRecipients

@ -735,11 +735,18 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
NSMutableArray<TOCFuture *> *futures = [NSMutableArray array]; NSMutableArray<TOCFuture *> *futures = [NSMutableArray array];
for (SignalRecipient *recipient in recipients) { for (SignalRecipient *recipient in recipients) {
NSString *recipientId = recipient.recipientId;
// We don't need to send the message to ourselves... // We don't need to send the message to ourselves...
if ([recipient.uniqueId isEqualToString:[TSStorageManager localNumber]]) { if ([recipientId isEqualToString:[TSStorageManager localNumber]]) {
continue;
}
// We don't need to sent the message to all group members if
// it has a "single group recipient".
if (message.singleGroupRecipient && ![message.singleGroupRecipient isEqualToString:recipientId]) {
continue; continue;
} }
if ([message wasSentToRecipient:recipient.uniqueId]) { if ([message wasSentToRecipient:recipientId]) {
// Skip recipients we have already sent this message to (on an // Skip recipients we have already sent this message to (on an
// earlier retry, perhaps). // earlier retry, perhaps).
DDLogInfo(@"%@ Skipping group message recipient; already sent: %@", self.tag, recipient.uniqueId); DDLogInfo(@"%@ Skipping group message recipient; already sent: %@", self.tag, recipient.uniqueId);

@ -775,7 +775,8 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
- (void)handleGroupInfoRequest:(OWSSignalServiceProtosDataMessage *)dataMessage - (void)handleGroupInfoRequest:(OWSSignalServiceProtosEnvelope *)envelope
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
{ {
OWSAssert([NSThread isMainThread]); OWSAssert([NSThread isMainThread]);
OWSAssert(dataMessage.group.type == OWSSignalServiceProtosGroupContextTypeRequestInfo); OWSAssert(dataMessage.group.type == OWSSignalServiceProtosGroupContextTypeRequestInfo);
@ -786,7 +787,7 @@ NS_ASSUME_NONNULL_BEGIN
return; return;
} }
DDLogInfo(@"%@ Received 'Request Group Info' message for group: %@", self.tag, groupId); DDLogInfo(@"%@ Received 'Request Group Info' message for group: %@ from: %@", self.tag, groupId, envelope.source);
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
TSGroupModel *emptyModelToFillOutId = TSGroupModel *emptyModelToFillOutId =
@ -803,6 +804,8 @@ NS_ASSUME_NONNULL_BEGIN
inThread:gThread inThread:gThread
groupMetaMessage:TSGroupMessageUpdate]; groupMetaMessage:TSGroupMessageUpdate];
[message updateWithCustomMessage:updateGroupInfo transaction:transaction]; [message updateWithCustomMessage:updateGroupInfo transaction:transaction];
// Only send this group update to the requester.
[message updateWithSingleGroupRecipient:envelope.source transaction:transaction];
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[self sendGroupUpdateForThread:gThread message:message]; [self sendGroupUpdateForThread:gThread message:message];
@ -827,7 +830,7 @@ NS_ASSUME_NONNULL_BEGIN
NSString *localNumber = [TSAccountManager localNumber]; NSString *localNumber = [TSAccountManager localNumber];
if (dataMessage.group.type == OWSSignalServiceProtosGroupContextTypeRequestInfo) { if (dataMessage.group.type == OWSSignalServiceProtosGroupContextTypeRequestInfo) {
[self handleGroupInfoRequest:dataMessage]; [self handleGroupInfoRequest:envelope dataMessage:dataMessage];
return nil; return nil;
} }

Loading…
Cancel
Save