diff --git a/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m b/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m index 478981758..a20616494 100644 --- a/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m +++ b/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m @@ -468,7 +468,7 @@ const CGFloat kIconViewLength = 24; [mainSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ - NSString *colorName = self.thread.conversationColorName; + ConversationColorName colorName = self.thread.conversationColorName; UIColor *currentColor = [OWSConversationColor conversationColorOrDefaultForColorName:colorName].themeColor; NSString *title = NSLocalizedString(@"CONVERSATION_SETTINGS_CONVERSATION_COLOR", diff --git a/SignalMessaging/Views/ContactCellView.m b/SignalMessaging/Views/ContactCellView.m index 4067b0dd5..aef302c6b 100644 --- a/SignalMessaging/Views/ContactCellView.m +++ b/SignalMessaging/Views/ContactCellView.m @@ -183,7 +183,7 @@ const CGFloat kContactCellAvatarTextMargin = 12; return; } - NSString *colorName = ^{ + ConversationColorName colorName = ^{ if (self.thread) { return self.thread.conversationColorName; } else { diff --git a/SignalMessaging/appearance/OWSConversationColor.h b/SignalMessaging/appearance/OWSConversationColor.h index a8eceb6a3..838366340 100644 --- a/SignalMessaging/appearance/OWSConversationColor.h +++ b/SignalMessaging/appearance/OWSConversationColor.h @@ -2,20 +2,21 @@ // Copyright (c) 2018 Open Whisper Systems. All rights reserved. // +#import #import NS_ASSUME_NONNULL_BEGIN @interface OWSConversationColor : NSObject -@property (nonatomic, readonly) NSString *name; +@property (nonatomic, readonly) ConversationColorName name; @property (nonatomic, readonly) UIColor *primaryColor; @property (nonatomic, readonly) UIColor *shadeColor; @property (nonatomic, readonly) UIColor *tintColor; @property (nonatomic, readonly) UIColor *themeColor; -+ (OWSConversationColor *)conversationColorWithName:(NSString *)name ++ (OWSConversationColor *)conversationColorWithName:(ConversationColorName)name primaryColor:(UIColor *)primaryColor shadeColor:(UIColor *)shadeColor tintColor:(UIColor *)tintColor; @@ -66,18 +67,15 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Conversation Colors -+ (nullable OWSConversationColor *)conversationColorForColorName:(NSString *)colorName ++ (nullable OWSConversationColor *)conversationColorForColorName:(ConversationColorName)colorName NS_SWIFT_NAME(conversationColor(colorName:)); // If the conversation color name is valid, return its colors. // Otherwise return the "default" conversation colors. -+ (OWSConversationColor *)conversationColorOrDefaultForColorName:(NSString *)conversationColorName ++ (OWSConversationColor *)conversationColorOrDefaultForColorName:(ConversationColorName)conversationColorName NS_SWIFT_NAME(conversationColorOrDefault(colorName:)); -@property (class, readonly, nonatomic) NSArray *conversationColorNames; - -+ (NSString *)defaultConversationColorName; -+ (OWSConversationColor *)defaultConversationColor; +@property (class, readonly, nonatomic) NSArray *conversationColorNames; @end diff --git a/SignalMessaging/appearance/OWSConversationColor.m b/SignalMessaging/appearance/OWSConversationColor.m index ce2f2611a..74365bed0 100644 --- a/SignalMessaging/appearance/OWSConversationColor.m +++ b/SignalMessaging/appearance/OWSConversationColor.m @@ -5,12 +5,13 @@ #import "OWSConversationColor.h" #import "Theme.h" #import "UIColor+OWS.h" +#import NS_ASSUME_NONNULL_BEGIN @interface OWSConversationColor () -@property (nonatomic) NSString *name; +@property (nonatomic) ConversationColorName name; @property (nonatomic) UIColor *primaryColor; @property (nonatomic) UIColor *shadeColor; @property (nonatomic) UIColor *tintColor; @@ -21,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN @implementation OWSConversationColor -+ (OWSConversationColor *)conversationColorWithName:(NSString *)name ++ (OWSConversationColor *)conversationColorWithName:(ConversationColorName)name primaryColor:(UIColor *)primaryColor shadeColor:(UIColor *)shadeColor tintColor:(UIColor *)tintColor @@ -245,51 +246,51 @@ NS_ASSUME_NONNULL_BEGIN dispatch_once(&onceToken, ^{ // Order here affects the order in the conversation color picker. allConversationColors = @[ - [OWSConversationColor conversationColorWithName:@"crimson" + [OWSConversationColor conversationColorWithName:ConversationColorNameCrimson primaryColor:self.ows_crimsonColor shadeColor:self.ows_crimsonShadeColor tintColor:self.ows_crimsonTintColor], - [OWSConversationColor conversationColorWithName:@"vermilion" + [OWSConversationColor conversationColorWithName:ConversationColorNameVermilion primaryColor:self.ows_vermilionColor shadeColor:self.ows_vermilionShadeColor tintColor:self.ows_vermilionTintColor], - [OWSConversationColor conversationColorWithName:@"burlap" + [OWSConversationColor conversationColorWithName:ConversationColorNameBurlap primaryColor:self.ows_burlapColor shadeColor:self.ows_burlapShadeColor tintColor:self.ows_burlapTintColor], - [OWSConversationColor conversationColorWithName:@"forest" + [OWSConversationColor conversationColorWithName:ConversationColorNameForest primaryColor:self.ows_forestColor shadeColor:self.ows_forestShadeColor tintColor:self.ows_forestTintColor], - [OWSConversationColor conversationColorWithName:@"wintergreen" + [OWSConversationColor conversationColorWithName:ConversationColorNameWintergreen primaryColor:self.ows_wintergreenColor shadeColor:self.ows_wintergreenShadeColor tintColor:self.ows_wintergreenTintColor], - [OWSConversationColor conversationColorWithName:@"teal" + [OWSConversationColor conversationColorWithName:ConversationColorNameTeal primaryColor:self.ows_tealColor shadeColor:self.ows_tealShadeColor tintColor:self.ows_tealTintColor], - [OWSConversationColor conversationColorWithName:@"blue" + [OWSConversationColor conversationColorWithName:ConversationColorNameBlue primaryColor:self.ows_blueColor shadeColor:self.ows_blueShadeColor tintColor:self.ows_blueTintColor], - [OWSConversationColor conversationColorWithName:@"indigo" + [OWSConversationColor conversationColorWithName:ConversationColorNameIndigo primaryColor:self.ows_indigoColor shadeColor:self.ows_indigoShadeColor tintColor:self.ows_indigoTintColor], - [OWSConversationColor conversationColorWithName:@"violet" + [OWSConversationColor conversationColorWithName:ConversationColorNameViolet primaryColor:self.ows_violetColor shadeColor:self.ows_violetShadeColor tintColor:self.ows_violetTintColor], - [OWSConversationColor conversationColorWithName:@"plum" + [OWSConversationColor conversationColorWithName:ConversationColorNamePlum primaryColor:self.ows_plumColor shadeColor:self.ows_plumShadeColor tintColor:self.ows_plumTintColor], - [OWSConversationColor conversationColorWithName:@"taupe" + [OWSConversationColor conversationColorWithName:ConversationColorNameTaupe primaryColor:self.ows_taupeColor shadeColor:self.ows_taupeShadeColor tintColor:self.ows_taupeTintColor], - [OWSConversationColor conversationColorWithName:@"steel" + [OWSConversationColor conversationColorWithName:ConversationColorNameSteel primaryColor:self.ows_steelColor shadeColor:self.ows_steelShadeColor tintColor:self.ows_steelTintColor], @@ -299,12 +300,12 @@ NS_ASSUME_NONNULL_BEGIN return allConversationColors; } -+ (NSDictionary *)conversationColorMap ++ (NSDictionary *)conversationColorMap { - static NSDictionary *colorMap; + static NSDictionary *colorMap; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - NSMutableDictionary *mutableColorMap = [NSMutableDictionary new]; + NSMutableDictionary *mutableColorMap = [NSMutableDictionary new]; for (OWSConversationColor *conversationColor in self.allConversationColors) { mutableColorMap[conversationColor.name] = conversationColor; } @@ -314,59 +315,32 @@ NS_ASSUME_NONNULL_BEGIN return colorMap; } -+ (NSDictionary *)ows_legacyConversationColorMap ++ (NSArray *)conversationColorNames { - static NSDictionary *colorMap; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - colorMap = @{ - @"red" : @"crimson", - @"deep_orange" : @"crimson", - @"orange" : @"vermilion", - @"amber" : @"vermilion", - @"brown" : @"burlap", - @"yellow" : @"burlap", - @"pink" : @"plum", - @"purple" : @"violet", - @"deep_purple" : @"violet", - @"indigo" : @"indigo", - @"blue" : @"blue", - @"light_blue" : @"blue", - @"cyan" : @"teal", - @"teal" : @"teal", - @"green" : @"forest", - @"light_green" : @"wintergreen", - @"lime" : @"wintergreen", - @"blue_grey" : @"taupe", - @"grey" : @"steel", - }; - }); - - return colorMap; -} - -+ (NSArray *)conversationColorNames -{ - NSMutableArray *names = [NSMutableArray new]; + NSMutableArray *names = [NSMutableArray new]; for (OWSConversationColor *conversationColor in self.allConversationColors) { [names addObject:conversationColor.name]; } +#ifdef DEBUG + NSSet *colorNameSet = [NSSet setWithArray:names]; + // These constants are duplicated in two places. So this canary exists to make sure they stay in sync. + NSSet *threadColorNameSet = [NSSet setWithArray:TSThread.conversationColorNames]; + OWSAssertDebug([colorNameSet isEqual:threadColorNameSet]); +#endif return [names copy]; } -+ (nullable OWSConversationColor *)conversationColorForColorName:(NSString *)conversationColorName ++ (nullable OWSConversationColor *)conversationColorForColorName:(ConversationColorName)conversationColorName { - NSString *_Nullable mappedColorName = self.ows_legacyConversationColorMap[conversationColorName.lowercaseString]; - if (mappedColorName) { - conversationColorName = mappedColorName; - } else { - OWSAssertDebug(self.conversationColorMap[conversationColorName] != nil); - } + OWSConversationColor *_Nullable result = self.conversationColorMap[conversationColorName]; + + // Any mapping to colorNames should be done in TSThread before this method is called. + OWSAssertDebug(result != nil); - return self.conversationColorMap[conversationColorName]; + return result; } -+ (OWSConversationColor *)conversationColorOrDefaultForColorName:(NSString *)conversationColorName ++ (OWSConversationColor *)conversationColorOrDefaultForColorName:(ConversationColorName)conversationColorName { OWSConversationColor *_Nullable conversationColor = [self conversationColorForColorName:conversationColorName]; if (conversationColor) { @@ -375,16 +349,9 @@ NS_ASSUME_NONNULL_BEGIN return [self defaultConversationColor]; } -+ (NSString *)defaultConversationColorName -{ - NSString *conversationColorName = @"steel"; - OWSAssert([self.conversationColorNames containsObject:conversationColorName]); - return conversationColorName; -} - + (OWSConversationColor *)defaultConversationColor { - return [self conversationColorForColorName:self.defaultConversationColorName]; + return [self conversationColorForColorName:kConversationColorName_Default]; } @end diff --git a/SignalMessaging/utils/OWSAvatarBuilder.m b/SignalMessaging/utils/OWSAvatarBuilder.m index 4043f3814..bed4d510f 100644 --- a/SignalMessaging/utils/OWSAvatarBuilder.m +++ b/SignalMessaging/utils/OWSAvatarBuilder.m @@ -29,7 +29,7 @@ typedef void (^OWSAvatarDrawBlock)(CGContextRef context); OWSAvatarBuilder *avatarBuilder; if ([thread isKindOfClass:[TSContactThread class]]) { TSContactThread *contactThread = (TSContactThread *)thread; - NSString *colorName = thread.conversationColorName; + ConversationColorName colorName = thread.conversationColorName; avatarBuilder = [[OWSContactAvatarBuilder alloc] initWithSignalId:contactThread.contactIdentifier colorName:colorName diameter:diameter]; diff --git a/SignalMessaging/utils/OWSContactAvatarBuilder.h b/SignalMessaging/utils/OWSContactAvatarBuilder.h index bc7d05179..ab2ace61b 100644 --- a/SignalMessaging/utils/OWSContactAvatarBuilder.h +++ b/SignalMessaging/utils/OWSContactAvatarBuilder.h @@ -3,6 +3,7 @@ // #import "OWSAvatarBuilder.h" +#import NS_ASSUME_NONNULL_BEGIN @@ -13,7 +14,9 @@ NS_ASSUME_NONNULL_BEGIN /** * Build an avatar for a Signal recipient */ -- (instancetype)initWithSignalId:(NSString *)signalId colorName:(NSString *)colorName diameter:(NSUInteger)diameter; +- (instancetype)initWithSignalId:(NSString *)signalId + colorName:(ConversationColorName)colorName + diameter:(NSUInteger)diameter; /** * Build an avatar for a non-Signal recipient diff --git a/SignalMessaging/utils/OWSContactAvatarBuilder.m b/SignalMessaging/utils/OWSContactAvatarBuilder.m index 9010e67e5..ec6f72db8 100644 --- a/SignalMessaging/utils/OWSContactAvatarBuilder.m +++ b/SignalMessaging/utils/OWSContactAvatarBuilder.m @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) NSString *signalId; @property (nonatomic, readonly) NSString *contactName; -@property (nonatomic, readonly) NSString *colorName; +@property (nonatomic, readonly) ConversationColorName colorName; @property (nonatomic, readonly) NSUInteger diameter; @end @@ -29,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithContactId:(NSString *)contactId name:(NSString *)name - colorName:(NSString *)colorName + colorName:(ConversationColorName)colorName diameter:(NSUInteger)diameter { self = [super init]; @@ -48,7 +48,7 @@ NS_ASSUME_NONNULL_BEGIN } - (instancetype)initWithSignalId:(NSString *)signalId - colorName:(NSString *)colorName + colorName:(ConversationColorName)colorName diameter:(NSUInteger)diameter { // Name for avatar initials. @@ -66,7 +66,7 @@ NS_ASSUME_NONNULL_BEGIN colorSeed:(NSString *)colorSeed diameter:(NSUInteger)diameter { - NSString *colorName = [TSThread stableColorNameForNewConversationWithString:colorSeed]; + ConversationColorName colorName = [TSThread stableColorNameForNewConversationWithString:colorSeed]; return [self initWithContactId:colorSeed name:nonSignalName colorName:(NSString *)colorName diameter:diameter]; } @@ -76,9 +76,7 @@ NS_ASSUME_NONNULL_BEGIN OWSAssertDebug(localNumber.length > 0); OWSAssertDebug(diameter > 0); - NSString *colorName = [OWSConversationColor defaultConversationColorName]; - - return [self initWithSignalId:localNumber colorName:colorName diameter:diameter]; + return [self initWithSignalId:localNumber colorName:kConversationColorName_Default diameter:diameter]; } #pragma mark - Dependencies diff --git a/SignalServiceKit/src/Contacts/TSThread.h b/SignalServiceKit/src/Contacts/TSThread.h index 475db8e4f..098787a38 100644 --- a/SignalServiceKit/src/Contacts/TSThread.h +++ b/SignalServiceKit/src/Contacts/TSThread.h @@ -10,10 +10,25 @@ NS_ASSUME_NONNULL_BEGIN @class TSInteraction; @class TSInvalidIdentityKeyReceivingErrorMessage; +typedef NSString *ConversationColorName NS_STRING_ENUM; +extern ConversationColorName const ConversationColorNameCrimson; +extern ConversationColorName const ConversationColorNameVermilion; +extern ConversationColorName const ConversationColorNameBurlap; +extern ConversationColorName const ConversationColorNameForest; +extern ConversationColorName const ConversationColorNameWintergreen; +extern ConversationColorName const ConversationColorNameTeal; +extern ConversationColorName const ConversationColorNameBlue; +extern ConversationColorName const ConversationColorNameIndigo; +extern ConversationColorName const ConversationColorNameViolet; +extern ConversationColorName const ConversationColorNamePlum; +extern ConversationColorName const ConversationColorNameTaupe; +extern ConversationColorName const ConversationColorNameSteel; + +extern ConversationColorName const kConversationColorName_Default; + /** * TSThread is the superclass of TSContactThread and TSGroupThread */ - @interface TSThread : TSYapDatabaseObject // YES IFF this thread has ever had a message. @@ -33,10 +48,12 @@ NS_ASSUME_NONNULL_BEGIN */ - (NSString *)name; -@property (nonatomic, readonly) NSString *conversationColorName; +@property (nonatomic, readonly) ConversationColorName conversationColorName; -- (void)updateConversationColorName:(NSString *)colorName transaction:(YapDatabaseReadWriteTransaction *)transaction; -+ (NSString *)stableColorNameForNewConversationWithString:(NSString *)colorSeed; +- (void)updateConversationColorName:(ConversationColorName)colorName + transaction:(YapDatabaseReadWriteTransaction *)transaction; ++ (ConversationColorName)stableColorNameForNewConversationWithString:(NSString *)colorSeed; +@property (class, nonatomic, readonly) NSArray *conversationColorNames; /** * @returns diff --git a/SignalServiceKit/src/Contacts/TSThread.m b/SignalServiceKit/src/Contacts/TSThread.m index c60986577..1a9549496 100644 --- a/SignalServiceKit/src/Contacts/TSThread.m +++ b/SignalServiceKit/src/Contacts/TSThread.m @@ -19,6 +19,21 @@ NS_ASSUME_NONNULL_BEGIN +ConversationColorName const ConversationColorNameCrimson = @"red"; +ConversationColorName const ConversationColorNameVermilion = @"orange"; +ConversationColorName const ConversationColorNameBurlap = @"brown"; +ConversationColorName const ConversationColorNameForest = @"green"; +ConversationColorName const ConversationColorNameWintergreen = @"light_green"; +ConversationColorName const ConversationColorNameTeal = @"teal"; +ConversationColorName const ConversationColorNameBlue = @"blue"; +ConversationColorName const ConversationColorNameIndigo = @"indigo"; +ConversationColorName const ConversationColorNameViolet = @"purple"; +ConversationColorName const ConversationColorNamePlum = @"pink"; +ConversationColorName const ConversationColorNameTaupe = @"blue_grey"; +ConversationColorName const ConversationColorNameSteel = @"grey"; + +ConversationColorName const kConversationColorName_Default = ConversationColorNameSteel; + @interface TSThread () @property (nonatomic) NSDate *creationDate; @@ -69,15 +84,35 @@ NS_ASSUME_NONNULL_BEGIN } if (_conversationColorName.length == 0) { - NSString *_Nullable contactId = self.contactIdentifier; - if (contactId.length > 0) { - // To be consistent with colors synced to desktop - _conversationColorName = [self.class stableColorNameForLegacyConversationWithString:contactId]; - } else { - _conversationColorName = [self.class stableColorNameForLegacyConversationWithString:self.uniqueId]; + NSString *_Nullable colorSeed = self.contactIdentifier; + if (colorSeed.length > 0) { + // group threads + colorSeed = self.uniqueId; } + + // To be consistent with colors synced to desktop + ConversationColorName colorName = [self.class stableColorNameForLegacyConversationWithString:colorSeed]; + OWSAssertDebug(colorName); + + _conversationColorName = colorName; + } else if (![[[self class] conversationColorNames] containsObject:_conversationColorName]) { + // If we'd persisted a non-mapped color name + ConversationColorName _Nullable mappedColorName = self.class.legacyConversationColorMap[_conversationColorName]; + + if (!mappedColorName) { + // We previously used the wrong values for the new colors, it's possible we persited them. + // map them to the proper value + mappedColorName = self.class.legacyFixupConversationColorMap[_conversationColorName]; + } + + if (!mappedColorName) { + OWSFailDebug(@"failure: unexpected unmappable conversationColorName: %@", _conversationColorName); + mappedColorName = kConversationColorName_Default; + } + + _conversationColorName = mappedColorName; } - + return self; } @@ -441,25 +476,37 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Conversation Color -+ (NSArray *)colorNamesForNewConversation +- (ConversationColorName)conversationColorName +{ + OWSAssertDebug([self.class.conversationColorNames containsObject:_conversationColorName]); + return _conversationColorName; +} + ++ (NSArray *)colorNamesForNewConversation { // all conversation colors except "steel" return @[ - @"crimson", - @"vermilion", - @"burlap", - @"forest", - @"wintergreen", - @"teal", - @"blue", - @"indigo", - @"violet", - @"plum", - @"taupe" + ConversationColorNameCrimson, + ConversationColorNameVermilion, + ConversationColorNameBurlap, + ConversationColorNameForest, + ConversationColorNameWintergreen, + ConversationColorNameTeal, + ConversationColorNameBlue, + ConversationColorNameIndigo, + ConversationColorNameViolet, + ConversationColorNamePlum, + ConversationColorNameTaupe, ]; } -+ (NSString *)stableConversationColorNameForString:(NSString *)colorSeed colorNames:(NSArray *)colorNames ++ (NSArray *)conversationColorNames +{ + return [self.colorNamesForNewConversation arrayByAddingObject:kConversationColorName_Default]; +} + ++ (ConversationColorName)stableConversationColorNameForString:(NSString *)colorSeed + colorNames:(NSArray *)colorNames { NSData *contactData = [colorSeed dataUsingEncoding:NSUTF8StringEncoding]; @@ -476,16 +523,25 @@ NS_ASSUME_NONNULL_BEGIN return [colorNames objectAtIndex:index]; } -+ (NSString *)stableColorNameForNewConversationWithString:(NSString *)colorSeed ++ (ConversationColorName)stableColorNameForNewConversationWithString:(NSString *)colorSeed { return [self stableConversationColorNameForString:colorSeed colorNames:self.colorNamesForNewConversation]; } -// After introducing new conversation colors, we want to try to maintain as close -// as possible to the old color for an existing thread. -+ (NSString *)stableColorNameForLegacyConversationWithString:(NSString *)colorSeed +// After introducing new conversation colors, we want to try to maintain as close as possible to the old color for an +// existing thread. ++ (ConversationColorName)stableColorNameForLegacyConversationWithString:(NSString *)colorSeed { - return [self stableConversationColorNameForString:colorSeed colorNames:self.legacyConversationColorNames]; + NSString *legacyColorName = + [self stableConversationColorNameForString:colorSeed colorNames:self.legacyConversationColorNames]; + ConversationColorName _Nullable mappedColorName = self.class.legacyConversationColorMap[legacyColorName]; + + if (!mappedColorName) { + OWSFailDebug(@"failure: unexpected unmappable legacyColorName: %@", legacyColorName); + return kConversationColorName_Default; + } + + return mappedColorName; } + (NSArray *)legacyConversationColorNames @@ -504,7 +560,64 @@ NS_ASSUME_NONNULL_BEGIN ]; } -- (void)updateConversationColorName:(NSString *)colorName transaction:(YapDatabaseReadWriteTransaction *)transaction ++ (NSDictionary *)legacyConversationColorMap +{ + static NSDictionary *colorMap; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + colorMap = @{ + @"red" : ConversationColorNameCrimson, + @"deep_orange" : ConversationColorNameCrimson, + @"orange" : ConversationColorNameVermilion, + @"amber" : ConversationColorNameVermilion, + @"brown" : ConversationColorNameBurlap, + @"yellow" : ConversationColorNameBurlap, + @"pink" : ConversationColorNamePlum, + @"purple" : ConversationColorNameViolet, + @"deep_purple" : ConversationColorNameViolet, + @"indigo" : ConversationColorNameIndigo, + @"blue" : ConversationColorNameBlue, + @"light_blue" : ConversationColorNameBlue, + @"cyan" : ConversationColorNameTeal, + @"teal" : ConversationColorNameTeal, + @"green" : ConversationColorNameForest, + @"light_green" : ConversationColorNameWintergreen, + @"lime" : ConversationColorNameWintergreen, + @"blue_grey" : ConversationColorNameTaupe, + @"grey" : ConversationColorNameSteel, + }; + }); + + return colorMap; +} + +// we temporarily used the wrong value for the new color names. ++ (NSDictionary *)legacyFixupConversationColorMap +{ + static NSDictionary *colorMap; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + colorMap = @{ + @"crimson" : ConversationColorNameCrimson, + @"vermilion" : ConversationColorNameVermilion, + @"burlap" : ConversationColorNameBurlap, + @"forest" : ConversationColorNameForest, + @"wintergreen" : ConversationColorNameWintergreen, + @"teal" : ConversationColorNameTeal, + @"blue" : ConversationColorNameBlue, + @"indigo" : ConversationColorNameIndigo, + @"violet" : ConversationColorNameViolet, + @"plum" : ConversationColorNamePlum, + @"taupe" : ConversationColorNameTaupe, + @"steel" : ConversationColorNameSteel, + }; + }); + + return colorMap; +} + +- (void)updateConversationColorName:(ConversationColorName)colorName + transaction:(YapDatabaseReadWriteTransaction *)transaction { [self applyChangeToSelfAndLatestCopy:transaction changeBlock:^(TSThread *thread) { diff --git a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h index 2f9445089..3fe639295 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h +++ b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h @@ -44,7 +44,7 @@ extern NSString *const TSGroupThread_NotificationKey_UniqueId; - (void)fireAvatarChangedNotification; -+ (NSString *)defaultConversationColorNameForGroupId:(NSData *)groupId; ++ (ConversationColorName)defaultConversationColorNameForGroupId:(NSData *)groupId; @end diff --git a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m index d1981c869..8c09acbaf 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m +++ b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m @@ -242,7 +242,7 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific userInfo:userInfo]; } -+ (NSString *)defaultConversationColorNameForGroupId:(NSData *)groupId ++ (ConversationColorName)defaultConversationColorNameForGroupId:(NSData *)groupId { OWSAssertDebug(groupId.length > 0);