From 7243dcb48d95e04ab7a6c9139b2159a3679b3f8a Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 14 Apr 2020 09:54:58 +1000 Subject: [PATCH] Fix iOS input being hidden after being removed then added to a group. --- .../ConversationView/ConversationViewController.m | 6 +++--- .../src/Contacts/Threads/TSGroupThread.h | 1 + .../src/Contacts/Threads/TSGroupThread.m | 13 ++++++++++++- .../src/Loki/Utilities/Notification+Loki.swift | 4 ++-- SignalServiceKit/src/Messages/OWSMessageManager.m | 15 +++++++++------ 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index f19e212b9..f4df8b1f1 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -425,8 +425,8 @@ typedef enum : NSUInteger { name:NSNotification.threadSessionRestoreDevicesChanged object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(handleGroupThreadLeftNotification:) - name:NSNotification.groupThreadLeft + selector:@selector(handleGroupThreadUpdated:) + name:NSNotification.groupThreadUpdated object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleCalculatingPoWNotification:) @@ -511,7 +511,7 @@ typedef enum : NSUInteger { [self ensureBannerState]; } -- (void)handleGroupThreadLeftNotification:(NSNotification *)notification +- (void)handleGroupThreadUpdated:(NSNotification *)notification { OWSAssertIsOnMainThread(); diff --git a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h index 3acc8a99b..89ce72249 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h +++ b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h @@ -45,6 +45,7 @@ extern NSString *const TSGroupThread_NotificationKey_UniqueId; + (NSArray *)groupThreadsWithRecipientId:(NSString *)recipientId transaction:(YapDatabaseReadWriteTransaction *)transaction; +- (void)updateGroupModel:(TSGroupModel *)newGroupModel withTransaction:(YapDatabaseReadWriteTransaction *)transaction; - (void)leaveGroupWithSneakyTransaction; - (void)leaveGroupWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; diff --git a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m index b0d3b866c..4d0ccde47 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m +++ b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m @@ -232,6 +232,17 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific return NSLocalizedString(@"NEW_GROUP_DEFAULT_TITLE", @""); } +- (void)updateGroupModel:(TSGroupModel *)newGroupModel withTransaction:(YapDatabaseReadWriteTransaction *)transaction +{ + self.groupModel = newGroupModel; + [self saveWithTransaction:transaction]; + + [transaction addCompletionQueue:dispatch_get_main_queue() + completionBlock:^{ + [NSNotificationCenter.defaultCenter postNotificationName:NSNotification.groupThreadUpdated object:self.uniqueId]; + }]; +} + - (void)leaveGroupWithSneakyTransaction { [self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { @@ -252,7 +263,7 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific [transaction addCompletionQueue:dispatch_get_main_queue() completionBlock:^{ - [NSNotificationCenter.defaultCenter postNotificationName:NSNotification.groupThreadLeft object:self.uniqueId]; + [NSNotificationCenter.defaultCenter postNotificationName:NSNotification.groupThreadUpdated object:self.uniqueId]; }]; } diff --git a/SignalServiceKit/src/Loki/Utilities/Notification+Loki.swift b/SignalServiceKit/src/Loki/Utilities/Notification+Loki.swift index edb0ad2cf..0055ebb17 100644 --- a/SignalServiceKit/src/Loki/Utilities/Notification+Loki.swift +++ b/SignalServiceKit/src/Loki/Utilities/Notification+Loki.swift @@ -4,7 +4,7 @@ public extension Notification.Name { // State changes public static let contactOnlineStatusChanged = Notification.Name("contactOnlineStatusChanged") public static let threadFriendRequestStatusChanged = Notification.Name("threadFriendRequestStatusChanged") - public static let groupThreadLeft = Notification.Name("groupThreadLeft") + public static let groupThreadUpdated = Notification.Name("groupThreadLeft") public static let messageFriendRequestStatusChanged = Notification.Name("messageFriendRequestStatusChanged") public static let threadDeleted = Notification.Name("threadDeleted") public static let threadSessionRestoreDevicesChanged = Notification.Name("threadSessionRestoreDevicesChanged") @@ -27,7 +27,7 @@ public extension Notification.Name { // State changes @objc public static let contactOnlineStatusChanged = Notification.Name.contactOnlineStatusChanged.rawValue as NSString @objc public static let threadFriendRequestStatusChanged = Notification.Name.threadFriendRequestStatusChanged.rawValue as NSString - @objc public static let groupThreadLeft = Notification.Name.groupThreadLeft.rawValue as NSString + @objc public static let groupThreadUpdated = Notification.Name.groupThreadUpdated.rawValue as NSString @objc public static let messageFriendRequestStatusChanged = Notification.Name.messageFriendRequestStatusChanged.rawValue as NSString @objc public static let threadDeleted = Notification.Name.threadDeleted.rawValue as NSString @objc public static let threadSessionRestoreDevicesChanged = Notification.Name.threadSessionRestoreDevicesChanged.rawValue as NSString diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index 4ed71cc18..e12e9ac87 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -1498,11 +1498,14 @@ NS_ASSUME_NONNULL_BEGIN newGroupModel.removedMembers = removedMemberIds; NSString *updateGroupInfo = [newGroupThread.groupModel getInfoStringAboutUpdateTo:newGroupModel contactsManager:self.contactsManager]; - newGroupThread.groupModel = newGroupModel; - [newGroupThread saveWithTransaction:transaction]; - - // Loki: Try to establish sessions with all members when a group is created or updated - [self establishSessionsWithMembersIfNeeded: newMemberIds.allObjects forThread:newGroupThread transaction:transaction]; + + [newGroupThread updateGroupModel:newGroupModel withTransaction:transaction]; + + BOOL removedFromGroup = [removedMemberIds containsObject:ourHexEncodedPublicKey]; + if (!removedFromGroup) { + // Loki: Try to establish sessions with all members when a group is created or updated + [self establishSessionsWithMembersIfNeeded: newMemberIds.allObjects forThread:newGroupThread transaction:transaction]; + } [[OWSDisappearingMessagesJob sharedJob] becomeConsistentWithDisappearingDuration:dataMessage.expireTimer thread:newGroupThread @@ -1518,7 +1521,7 @@ NS_ASSUME_NONNULL_BEGIN [infoMessage saveWithTransaction:transaction]; // If we were the one that was removed then we need to leave the group - if ([removedMemberIds containsObject:ourHexEncodedPublicKey]) { + if (removedFromGroup) { [newGroupThread leaveGroupWithTransaction:transaction]; }