Fix author conversation colors.

This commit is contained in:
Matthew Chen 2018-09-26 09:19:12 -04:00
parent 4186ce9a72
commit 72562920ed
6 changed files with 49 additions and 13 deletions

View File

@ -268,10 +268,12 @@ NS_ASSUME_NONNULL_BEGIN
return NO;
}
OWSAssertDebug(self.viewItem.incomingMessageAuthorThread);
TSThread *authorThread = self.viewItem.incomingMessageAuthorThread;
TSIncomingMessage *incomingMessage = (TSIncomingMessage *)self.viewItem.interaction;
UIImage *_Nullable authorAvatarImage =
[OWSAvatarBuilder buildImageForThread:authorThread diameter:self.avatarSize contactsManager:contactsManager];
[[[OWSContactAvatarBuilder alloc] initWithSignalId:incomingMessage.authorId
colorName:self.viewItem.authorConversationColorName
diameter:self.avatarSize
contactsManager:contactsManager] build];
self.avatarView.image = authorAvatarImage;
[self.contentView addSubview:self.avatarView];

View File

@ -46,7 +46,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);
@interface ConversationViewItem : NSObject <ConversationViewLayoutItem, OWSAudioPlayerDelegate>
@property (nonatomic, readonly) TSInteraction *interaction;
@property (nonatomic, nullable, readonly) TSThread *incomingMessageAuthorThread;
@property (nonatomic, readonly, nullable) OWSQuotedReplyModel *quotedReply;
@ -112,7 +111,10 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);
@property (nonatomic, readonly, nullable) ContactShareViewModel *contactShare;
@property (nonatomic, nullable) NSString *systemMessageText;
@property (nonatomic, readonly, nullable) NSString *systemMessageText;
// NOTE: This property is only set for incoming messages.
@property (nonatomic, readonly, nullable) NSString *authorConversationColorName;
#pragma mark - MessageActions

View File

@ -67,7 +67,9 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
@property (nonatomic, nullable) TSAttachmentPointer *attachmentPointer;
@property (nonatomic, nullable) ContactShareViewModel *contactShare;
@property (nonatomic) CGSize mediaSize;
@property (nonatomic, nullable) NSString *systemMessageText;
@property (nonatomic, nullable) TSThread *incomingMessageAuthorThread;
@property (nonatomic, nullable) NSString *authorConversationColorName;
@end
@ -93,10 +95,8 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
_interaction = interaction;
_isGroupThread = isGroupThread;
_conversationStyle = conversationStyle;
_incomingMessageAuthorThread = ([interaction isKindOfClass:[TSIncomingMessage class]]
? [TSContactThread getThreadWithContactId:((TSIncomingMessage *)interaction).authorId
transaction:transaction]
: nil);
[self updateAuthorConversationColorNameWithTransaction:transaction];
[self ensureViewState:transaction];
@ -108,10 +108,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
OWSAssertDebug(interaction);
_interaction = interaction;
_incomingMessageAuthorThread = ([interaction isKindOfClass:[TSIncomingMessage class]]
? [TSContactThread getThreadWithContactId:((TSIncomingMessage *)interaction).authorId
transaction:transaction]
: nil);
self.hasViewState = NO;
self.messageCellType = OWSMessageCellType_Unknown;
@ -123,11 +119,27 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
self.quotedReply = nil;
self.systemMessageText = nil;
[self updateAuthorConversationColorNameWithTransaction:transaction];
[self clearCachedLayoutState];
[self ensureViewState:transaction];
}
- (void)updateAuthorConversationColorNameWithTransaction:(YapDatabaseReadTransaction *)transaction
{
OWSAssertDebug(transaction);
if (self.interaction.interactionType != OWSInteractionType_IncomingMessage) {
_authorConversationColorName = nil;
return;
}
TSIncomingMessage *incomingMessage = (TSIncomingMessage *)self.interaction;
_authorConversationColorName =
[TSContactThread conversationColorNameForRecipientId:incomingMessage.authorId transaction:transaction];
}
- (BOOL)hasBodyText
{
return _displayableBodyText != nil;

View File

@ -34,6 +34,7 @@ NS_ASSUME_NONNULL_BEGIN
- (NSString *)name;
@property (readonly, nullable) NSString *conversationColorName;
- (void)updateConversationColorName:(NSString *)colorName transaction:(YapDatabaseReadWriteTransaction *)transaction;
+ (NSString *)stableConversationColorNameForString:(NSString *)colorSeed;

View File

@ -27,6 +27,12 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)threadIdFromContactId:(NSString *)contactId;
#endif
// This method can be used to get the conversation color for a given
// recipient without using a read/write transaction to create a
// contact thread.
+ (NSString *)conversationColorNameForRecipientId:(NSString *)recipientId
transaction:(YapDatabaseReadTransaction *)transaction;
@end
NS_ASSUME_NONNULL_END

View File

@ -91,6 +91,19 @@ NS_ASSUME_NONNULL_BEGIN
return [threadId substringWithRange:NSMakeRange(1, threadId.length - 1)];
}
+ (NSString *)conversationColorNameForRecipientId:(NSString *)recipientId
transaction:(YapDatabaseReadTransaction *)transaction
{
OWSAssertDebug(recipientId.length > 0);
TSContactThread *_Nullable contactThread =
[TSContactThread getThreadWithContactId:recipientId transaction:transaction];
if (contactThread) {
return contactThread.conversationColorName;
}
return [self stableConversationColorNameForString:recipientId];
}
@end
NS_ASSUME_NONNULL_END