diff --git a/Signal/src/ViewControllers/ConversationView/Cells/TypingIndicatorCell.swift b/Signal/src/ViewControllers/ConversationView/Cells/TypingIndicatorCell.swift index 27bac0dae..0713cdcea 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/TypingIndicatorCell.swift +++ b/Signal/src/ViewControllers/ConversationView/Cells/TypingIndicatorCell.swift @@ -43,10 +43,6 @@ public class TypingIndicatorCell: ConversationViewCell { avatarView.autoSetDimension(.height, toSize: kAvatarSize) } - deinit { - NotificationCenter.default.removeObserver(self) - } - @objc public override func loadForDisplay() { guard let conversationStyle = self.conversationStyle else { @@ -99,7 +95,7 @@ public class TypingIndicatorCell: ConversationViewCell { } guard let authorAvatarImage = OWSContactAvatarBuilder(signalId: typingIndicators.recipientId, - colorName: ConversationColorNameForString(colorName), + colorName: ConversationColorName(rawValue: colorName), diameter: UInt(kAvatarSize)).build() else { owsFailDebug("Could build avatar image") return nil @@ -148,7 +144,5 @@ public class TypingIndicatorCell: ConversationViewCell { avatarView.removeFromSuperview() typingIndicatorView.stopAnimation() - - NotificationCenter.default.removeObserver(self) } } diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m b/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m index 3910d2daa..f216e8bbe 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m @@ -143,7 +143,7 @@ static const int kYapDatabaseRangeMinLength = 0; @property (nonatomic, nullable) ThreadDynamicInteractions *dynamicInteractions; @property (nonatomic) BOOL hasClearedUnreadMessagesIndicator; @property (nonatomic, nullable) NSDate *collapseCutoffDate; -@property (nonatomic, nullable) NSString *typingIndicatorsRecipient; +@property (nonatomic, nullable) NSString *typingIndicatorsSender; @end @@ -250,7 +250,7 @@ static const int kYapDatabaseRangeMinLength = 0; // We need to update the "unread indicator" _before_ we determine the initial range // size, since it depends on where the unread indicator is placed. self.lastRangeLength = 0; - self.typingIndicatorsRecipient = [self.typingIndicators typingIndicatorsForThread:self.thread]; + self.typingIndicatorsSender = [self.typingIndicators typingRecipientIdForThread:self.thread]; [self ensureDynamicInteractions]; [self.primaryStorage updateUIDatabaseConnectionToLatest]; @@ -901,13 +901,13 @@ static const int kYapDatabaseRangeMinLength = 0; viewItemCache[interaction.uniqueId] = viewItem; } - if (self.typingIndicatorsRecipient) { + if (self.typingIndicatorsSender) { id _Nullable lastViewItem = viewItems.lastObject; uint64_t typingIndicatorTimestamp = (lastViewItem ? lastViewItem.interaction.timestamp + 1 : 1); TSInteraction *interaction = [[OWSTypingIndicatorInteraction alloc] initWithThread:self.thread timestamp:typingIndicatorTimestamp - recipientId:self.typingIndicatorsRecipient]; + recipientId:self.typingIndicatorsSender]; id _Nullable viewItem = self.viewItemCache[interaction.uniqueId]; if (!viewItem) { viewItem = [[ConversationInteractionViewItem alloc] initWithInteraction:interaction @@ -1337,16 +1337,16 @@ static const int kYapDatabaseRangeMinLength = 0; { OWSAssertIsOnMainThread(); - self.typingIndicatorsRecipient = [self.typingIndicators typingIndicatorsForThread:self.thread]; + self.typingIndicatorsSender = [self.typingIndicators typingRecipientIdForThread:self.thread]; } -- (void)setTypingIndicatorsRecipient:(nullable NSString *)typingIndicatorsRecipient +- (void)setTypingIndicatorsSender:(nullable NSString *)typingIndicatorsSender { OWSAssertIsOnMainThread(); - BOOL didChange = ![NSObject isNullableObject:typingIndicatorsRecipient equalTo:_typingIndicatorsRecipient]; + BOOL didChange = ![NSObject isNullableObject:typingIndicatorsSender equalTo:_typingIndicatorsSender]; - _typingIndicatorsRecipient = typingIndicatorsRecipient; + _typingIndicatorsSender = typingIndicatorsSender; // Update the view items if necessary. // We don't have to do this if they haven't been configured yet. diff --git a/Signal/src/ViewControllers/ConversationView/TypingIndicatorInteraction.swift b/Signal/src/ViewControllers/ConversationView/TypingIndicatorInteraction.swift index 2716f9cc5..f2bfc47cf 100644 --- a/Signal/src/ViewControllers/ConversationView/TypingIndicatorInteraction.swift +++ b/Signal/src/ViewControllers/ConversationView/TypingIndicatorInteraction.swift @@ -41,4 +41,9 @@ public class TypingIndicatorInteraction: TSInteraction { super.init(interactionWithUniqueId: TypingIndicatorInteraction.TypingIndicatorId, timestamp: timestamp, in: thread) } + + @objc + public override func save(with transaction: YapDatabaseReadWriteTransaction!) { + owsFailDebug("The transient interaction should not be saved in the database.") + } } diff --git a/Signal/src/ViewControllers/HomeView/HomeViewCell.m b/Signal/src/ViewControllers/HomeView/HomeViewCell.m index 45691640c..50737bb60 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewCell.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewCell.m @@ -531,7 +531,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)updatePreview { - if ([self.typingIndicators typingIndicatorsForThread:self.thread.threadRecord] != nil) { + if ([self.typingIndicators typingRecipientIdForThread:self.thread.threadRecord] != nil) { self.snippetLabel.hidden = YES; self.typingIndicatorView.hidden = NO; [self.typingIndicatorView startAnimation]; diff --git a/SignalServiceKit/src/Contacts/TSThread.h b/SignalServiceKit/src/Contacts/TSThread.h index 15cd2b20a..0bdc7c106 100644 --- a/SignalServiceKit/src/Contacts/TSThread.h +++ b/SignalServiceKit/src/Contacts/TSThread.h @@ -12,8 +12,6 @@ NS_ASSUME_NONNULL_BEGIN typedef NSString *ConversationColorName NS_STRING_ENUM; -ConversationColorName ConversationColorNameForString(NSString *value); - extern ConversationColorName const ConversationColorNameCrimson; extern ConversationColorName const ConversationColorNameVermilion; extern ConversationColorName const ConversationColorNameBurlap; diff --git a/SignalServiceKit/src/Contacts/TSThread.m b/SignalServiceKit/src/Contacts/TSThread.m index aa7831e1c..4d046f132 100644 --- a/SignalServiceKit/src/Contacts/TSThread.m +++ b/SignalServiceKit/src/Contacts/TSThread.m @@ -19,11 +19,6 @@ NS_ASSUME_NONNULL_BEGIN -ConversationColorName ConversationColorNameForString(NSString *value) -{ - return value; -} - ConversationColorName const ConversationColorNameCrimson = @"red"; ConversationColorName const ConversationColorNameVermilion = @"orange"; ConversationColorName const ConversationColorNameBurlap = @"brown"; diff --git a/SignalServiceKit/src/Util/TypingIndicators.swift b/SignalServiceKit/src/Util/TypingIndicators.swift index 043a524e6..898248d13 100644 --- a/SignalServiceKit/src/Util/TypingIndicators.swift +++ b/SignalServiceKit/src/Util/TypingIndicators.swift @@ -31,7 +31,7 @@ public protocol TypingIndicators: class { // // TODO: Use this method. @objc - func typingIndicators(forThread thread: TSThread) -> String? + func typingRecipientId(forThread thread: TSThread) -> String? @objc func setTypingIndicatorsEnabled(value: Bool) @@ -86,7 +86,7 @@ public class TypingIndicatorsImpl: NSObject, TypingIndicators { _areTypingIndicatorsEnabled = value primaryStorage.dbReadWriteConnection.setBool(value, forKey: kDatabaseKey_TypingIndicatorsEnabled, inCollection: kDatabaseCollection) - + syncManager.sendConfigurationSyncMessage() } @@ -151,7 +151,7 @@ public class TypingIndicatorsImpl: NSObject, TypingIndicators { } @objc - public func typingIndicators(forThread thread: TSThread) -> String? { + public func typingRecipientId(forThread thread: TSThread) -> String? { AssertIsOnMainThread() var firstRecipientId: String?