From e2d9c1187a8d65dc0f9760e5a30307072ff51dd2 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 18 May 2018 15:37:38 -0400 Subject: [PATCH] Fix "group avatar doesn't update after local change." --- .../ConversationViewController.m | 2 ++ SignalMessaging/Views/AvatarImageView.swift | 2 +- .../src/Contacts/Threads/TSGroupThread.h | 4 +++- .../src/Contacts/Threads/TSGroupThread.m | 20 ++++++++++++------- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 84f29df8b..771c97735 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -3835,6 +3835,8 @@ typedef enum : NSUInteger { [message updateWithCustomMessage:updateGroupInfo transaction:transaction]; }]; + [groupThread fireAvatarChangedNotification]; + if (newGroupModel.groupImage) { NSData *data = UIImagePNGRepresentation(newGroupModel.groupImage); DataSource *_Nullable dataSource = [DataSourceValue dataSourceWithData:data fileExtension:@"png"]; diff --git a/SignalMessaging/Views/AvatarImageView.swift b/SignalMessaging/Views/AvatarImageView.swift index e6ba70ec0..99fe980ad 100644 --- a/SignalMessaging/Views/AvatarImageView.swift +++ b/SignalMessaging/Views/AvatarImageView.swift @@ -129,7 +129,7 @@ public class ConversationAvatarImageView: AvatarImageView { func handleGroupAvatarChanged(notification: Notification) { Logger.debug("\(self.logTag) in \(#function)") - guard let changedGroupThreadId = notification.userInfo?[TSGroupThread_NotificaitonKey_UniqueId] as? String else { + guard let changedGroupThreadId = notification.userInfo?[TSGroupThread_NotificationKey_UniqueId] as? String else { owsFail("\(logTag) in \(#function) groupThreadId was unexpectedly nil") return } diff --git a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h index 981b7d262..15761d3a4 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h +++ b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h @@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN @class YapDatabaseReadWriteTransaction; extern NSString *const TSGroupThreadAvatarChangedNotification; -extern NSString *const TSGroupThread_NotificaitonKey_UniqueId; +extern NSString *const TSGroupThread_NotificationKey_UniqueId; @interface TSGroupThread : TSThread @@ -37,6 +37,8 @@ extern NSString *const TSGroupThread_NotificaitonKey_UniqueId; - (void)updateAvatarWithAttachmentStream:(TSAttachmentStream *)attachmentStream transaction:(YapDatabaseReadWriteTransaction *)transaction; +- (void)fireAvatarChangedNotification; + @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m index 51a33c45b..be7f09200 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m +++ b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m @@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN NSString *const TSGroupThreadAvatarChangedNotification = @"TSGroupThreadAvatarChangedNotification"; -NSString *const TSGroupThread_NotificaitonKey_UniqueId = @"TSGroupThread_NotificaitonKey_UniqueId"; +NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_NotificationKey_UniqueId"; @implementation TSGroupThread @@ -197,12 +197,7 @@ NSString *const TSGroupThread_NotificaitonKey_UniqueId = @"TSGroupThread_Notific [transaction addCompletionQueue:nil completionBlock:^{ - NSDictionary *userInfo = @{ TSGroupThread_NotificaitonKey_UniqueId : self.uniqueId }; - - [[NSNotificationCenter defaultCenter] - postNotificationName:TSGroupThreadAvatarChangedNotification - object:self.uniqueId - userInfo:userInfo]; + [self fireAvatarChangedNotification]; }]; // Avatars are stored directly in the database, so there's no need @@ -210,6 +205,17 @@ NSString *const TSGroupThread_NotificaitonKey_UniqueId = @"TSGroupThread_Notific [attachmentStream removeWithTransaction:transaction]; } +- (void)fireAvatarChangedNotification +{ + OWSAssertIsOnMainThread(); + + NSDictionary *userInfo = @{ TSGroupThread_NotificationKey_UniqueId : self.uniqueId }; + + [[NSNotificationCenter defaultCenter] postNotificationName:TSGroupThreadAvatarChangedNotification + object:self.uniqueId + userInfo:userInfo]; +} + @end NS_ASSUME_NONNULL_END