Merge branch 'charlesmchen/onlyReplyToGroupInfoRequester'

pull/1/head
Matthew Chen 8 years ago
commit 492aee79ef

@ -94,6 +94,9 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
@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.
* 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)updateWithWasDelivered;
- (void)updateWithWasSentAndDelivered;
- (void)updateWithSingleGroupRecipient:(NSString *)singleGroupRecipient
transaction:(YapDatabaseReadWriteTransaction *)transaction;
#pragma mark - Sent Recipients

@ -22,6 +22,7 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
@property (atomic) NSString *customMessage;
@property (atomic) NSString *mostRecentFailureText;
@property (atomic) BOOL wasDelivered;
@property (atomic) NSString *singleGroupRecipient;
// For outgoing, non-legacy group messages sent from this client, this
// 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
- (NSArray<NSString *> *)sentRecipients

@ -735,11 +735,18 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
NSMutableArray<TOCFuture *> *futures = [NSMutableArray array];
for (SignalRecipient *recipient in recipients) {
NSString *recipientId = recipient.recipientId;
// 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;
}
if ([message wasSentToRecipient:recipient.uniqueId]) {
if ([message wasSentToRecipient:recipientId]) {
// Skip recipients we have already sent this message to (on an
// earlier retry, perhaps).
DDLogInfo(@"%@ Skipping group message recipient; already sent: %@", self.tag, recipient.uniqueId);

@ -492,7 +492,9 @@ NS_ASSUME_NONNULL_BEGIN
}];
if (ignoreMessage) {
// FIXME: https://github.com/WhisperSystems/Signal-iOS/issues/1340
DDLogInfo(@"%@ Received message from group that I left or don't know about.", self.tag);
DDLogInfo(@"%@ Received message from group that I left or don't know about from: %@.",
self.tag,
incomingEnvelope.source);
NSString *recipientId = incomingEnvelope.source;
@ -508,7 +510,7 @@ NS_ASSUME_NONNULL_BEGIN
[[OWSSyncGroupsRequestMessage alloc] initWithThread:thread groupId:groupId];
[self.messageSender sendMessage:syncGroupsRequestMessage
success:^{
DDLogInfo(@"%@ Successfully sent Request Group Info message.", self.tag);
DDLogWarn(@"%@ Successfully sent Request Group Info message.", self.tag);
}
failure:^(NSError *error) {
DDLogError(@"%@ Failed to send Request Group Info message with error: %@", self.tag, error);
@ -775,7 +777,8 @@ NS_ASSUME_NONNULL_BEGIN
}
}
- (void)handleGroupInfoRequest:(OWSSignalServiceProtosDataMessage *)dataMessage
- (void)handleGroupInfoRequest:(OWSSignalServiceProtosEnvelope *)envelope
dataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage
{
OWSAssert([NSThread isMainThread]);
OWSAssert(dataMessage.group.type == OWSSignalServiceProtosGroupContextTypeRequestInfo);
@ -786,23 +789,32 @@ NS_ASSUME_NONNULL_BEGIN
return;
}
DDLogInfo(@"%@ Received 'Request Group Info' message for group: %@", self.tag, groupId);
DDLogWarn(@"%@ Received 'Request Group Info' message for group: %@ from: %@", self.tag, groupId, envelope.source);
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
TSGroupModel *emptyModelToFillOutId =
[[TSGroupModel alloc] initWithTitle:nil memberIds:nil image:nil groupId:dataMessage.group.id];
TSGroupThread *gThread = [TSGroupThread threadWithGroupModel:emptyModelToFillOutId transaction:transaction];
if (!gThread) {
DDLogInfo(@"%@ Unknown group: %@", self.tag, groupId);
DDLogWarn(@"%@ Unknown group: %@", self.tag, groupId);
return;
}
if (![gThread.groupModel.groupMemberIds containsObject:envelope.source]) {
DDLogWarn(@"%@ Ignoring 'Request Group Info' message for non-member of group. %@ not in %@",
self.tag,
envelope.source,
gThread.groupModel.groupMemberIds);
}
NSString *updateGroupInfo =
[gThread.groupModel getInfoStringAboutUpdateTo:gThread.groupModel contactsManager:self.contactsManager];
TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:gThread
groupMetaMessage:TSGroupMessageUpdate];
[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(), ^{
[self sendGroupUpdateForThread:gThread message:message];
@ -827,7 +839,7 @@ NS_ASSUME_NONNULL_BEGIN
NSString *localNumber = [TSAccountManager localNumber];
if (dataMessage.group.type == OWSSignalServiceProtosGroupContextTypeRequestInfo) {
[self handleGroupInfoRequest:dataMessage];
[self handleGroupInfoRequest:envelope dataMessage:dataMessage];
return nil;
}

Loading…
Cancel
Save