From 07fef16155293a1eb95114d1b822915bfb8daba0 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 18 Dec 2018 16:15:25 -0500 Subject: [PATCH] Discard typing indicators for blocked and left groups. --- .../src/Messages/OWSMessageManager.m | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index e8652d5d9..d86db8e2a 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -474,8 +474,7 @@ NS_ASSUME_NONNULL_BEGIN if ([self isDataMessageBlocked:dataMessage envelope:envelope]) { NSString *logMessage = [NSString stringWithFormat:@"Ignoring blocked message from sender: %@", envelope.source]; if (dataMessage.group) { - logMessage = - [logMessage stringByAppendingString:[NSString stringWithFormat:@" in group: %@", dataMessage.group.id]]; + logMessage = [logMessage stringByAppendingFormat:@" in group: %@", dataMessage.group.id]; } OWSLogError(@"%@", logMessage); return; @@ -692,14 +691,30 @@ NS_ASSUME_NONNULL_BEGIN if ([localNumber isEqualToString:envelope.source]) { OWSLogVerbose(@"Ignoring typing indicators from self or linked device."); return; + } else if ([self.blockingManager isRecipientIdBlocked:localNumber] + || (typingMessage.hasGroupID && [self.blockingManager isGroupIdBlocked:typingMessage.groupID])) { + NSString *logMessage = [NSString stringWithFormat:@"Ignoring blocked message from sender: %@", envelope.source]; + if (typingMessage.hasGroupID) { + logMessage = [logMessage stringByAppendingFormat:@" in group: %@", typingMessage.groupID]; + } + OWSLogError(@"%@", logMessage); + return; } TSThread *_Nullable thread; if (typingMessage.hasGroupID) { - thread = [TSGroupThread threadWithGroupId:typingMessage.groupID transaction:transaction]; + TSGroupThread *groupThread = [TSGroupThread threadWithGroupId:typingMessage.groupID transaction:transaction]; + + if (![groupThread.groupModel.groupMemberIds containsObject:self.tsAccountManager.localNumber]) { + OWSLogInfo(@"Ignoring messages for left group."); + return; + } + + thread = groupThread; } else { thread = [TSContactThread getThreadWithContactId:envelope.source transaction:transaction]; } + if (!thread) { // This isn't neccesarily an error. We might not yet know about the thread, // in which case we don't need to display the typing indicators.