From 2ea3badeb85e06a5d1799cc4cbd65a5117241c90 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 31 May 2021 11:50:46 -0400 Subject: [PATCH 1/3] Fix chat color precedence. --- SignalMessaging/Wallpapers/Wallpaper.swift | 8 ++++++ SignalMessaging/appearance/ChatColors.swift | 28 ++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/SignalMessaging/Wallpapers/Wallpaper.swift b/SignalMessaging/Wallpapers/Wallpaper.swift index b22350adac..b421db8a25 100644 --- a/SignalMessaging/Wallpapers/Wallpaper.swift +++ b/SignalMessaging/Wallpapers/Wallpaper.swift @@ -141,6 +141,14 @@ public enum Wallpaper: String, CaseIterable { return dimInDarkMode } + public static func wallpaperSetting(for thread: TSThread?, transaction: SDSAnyReadTransaction) -> Wallpaper? { + if let thread = thread { + return get(for: thread, transaction: transaction) + } else { + return get(for: nil, transaction: transaction) + } + } + public static func wallpaperForRendering(for thread: TSThread?, transaction: SDSAnyReadTransaction) -> Wallpaper? { if let wallpaper = get(for: thread, transaction: transaction) { diff --git a/SignalMessaging/appearance/ChatColors.swift b/SignalMessaging/appearance/ChatColors.swift index 2cca6311e6..c411b30fc7 100644 --- a/SignalMessaging/appearance/ChatColors.swift +++ b/SignalMessaging/appearance/ChatColors.swift @@ -211,12 +211,34 @@ public class ChatColors: NSObject, Dependencies { public static var defaultChatColor: ChatColor { Values.ultramarine } + // Chat Color Precedence + // + // * If Conversation X has a chat color setting A + // * Use chat color A + // * If Conversation X has no chat color setting... + // * If Conversation X has a wallpaper B + // * Use default chat color for wallpaper B + // * If Conversation X has no wallpaper... + // * If there is a global chat color setting C + // * Use chat color C + // * (even if there is a global wallpaper) + // * If there is no global chat color setting... + // * If there is a global wallpaper D + // * Use default chat color for wallpaper D + // * If there is no global wallpaper... + // * Use default chat color "ultramarine gradient". public static func autoChatColorForRendering(forThread thread: TSThread?, + ignoreGlobalDefault: Bool = false, transaction: SDSAnyReadTransaction) -> ChatColor { - if let value = defaultChatColorSetting(transaction: transaction) { + if let thread = thread, + let wallpaper = Wallpaper.wallpaperSetting(for: thread, transaction: transaction) { + return autoChatColorForRendering(forWallpaper: wallpaper) + } else if !ignoreGlobalDefault, + let value = defaultChatColorSetting(transaction: transaction) { + // In the global settings, we want to ignore the global default + // when rendering the "auto" swatch. return value - } else if let wallpaper = Wallpaper.wallpaperForRendering(for: thread, - transaction: transaction) { + } else if let wallpaper = Wallpaper.wallpaperSetting(for: nil, transaction: transaction) { return autoChatColorForRendering(forWallpaper: wallpaper) } else { return Self.defaultChatColor From cb4da6c63c139aa47b162399d1457859237f471b Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 2 Jun 2021 12:24:37 -0400 Subject: [PATCH 2/3] Respond to CR. --- SignalMessaging/appearance/ChatColors.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SignalMessaging/appearance/ChatColors.swift b/SignalMessaging/appearance/ChatColors.swift index c411b30fc7..b7a4d3d9da 100644 --- a/SignalMessaging/appearance/ChatColors.swift +++ b/SignalMessaging/appearance/ChatColors.swift @@ -231,14 +231,16 @@ public class ChatColors: NSObject, Dependencies { ignoreGlobalDefault: Bool = false, transaction: SDSAnyReadTransaction) -> ChatColor { if let thread = thread, - let wallpaper = Wallpaper.wallpaperSetting(for: thread, transaction: transaction) { + let wallpaper = Wallpaper.wallpaperSetting(for: thread, transaction: transaction), + wallpaper != .photo { return autoChatColorForRendering(forWallpaper: wallpaper) } else if !ignoreGlobalDefault, let value = defaultChatColorSetting(transaction: transaction) { // In the global settings, we want to ignore the global default // when rendering the "auto" swatch. return value - } else if let wallpaper = Wallpaper.wallpaperSetting(for: nil, transaction: transaction) { + } else if let wallpaper = Wallpaper.wallpaperSetting(for: nil, transaction: transaction), + wallpaper != .photo { return autoChatColorForRendering(forWallpaper: wallpaper) } else { return Self.defaultChatColor From 6bca672bd425e433ec29f535b515a6adb53a35d2 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 2 Jun 2021 20:51:57 -0400 Subject: [PATCH 3/3] Respond to CR. --- SignalMessaging/appearance/ChatColors.swift | 41 ++++++++++++++------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/SignalMessaging/appearance/ChatColors.swift b/SignalMessaging/appearance/ChatColors.swift index b7a4d3d9da..48ffbbeb4e 100644 --- a/SignalMessaging/appearance/ChatColors.swift +++ b/SignalMessaging/appearance/ChatColors.swift @@ -230,20 +230,35 @@ public class ChatColors: NSObject, Dependencies { public static func autoChatColorForRendering(forThread thread: TSThread?, ignoreGlobalDefault: Bool = false, transaction: SDSAnyReadTransaction) -> ChatColor { - if let thread = thread, - let wallpaper = Wallpaper.wallpaperSetting(for: thread, transaction: transaction), - wallpaper != .photo { - return autoChatColorForRendering(forWallpaper: wallpaper) - } else if !ignoreGlobalDefault, - let value = defaultChatColorSetting(transaction: transaction) { - // In the global settings, we want to ignore the global default - // when rendering the "auto" swatch. - return value - } else if let wallpaper = Wallpaper.wallpaperSetting(for: nil, transaction: transaction), - wallpaper != .photo { - return autoChatColorForRendering(forWallpaper: wallpaper) + if let thread = thread { + let threadWallpaper = Wallpaper.wallpaperSetting(for: thread, transaction: transaction) + if let wallpaper = threadWallpaper, + wallpaper != .photo { + return autoChatColorForRendering(forWallpaper: wallpaper) + } else if !ignoreGlobalDefault, + let value = defaultChatColorSetting(transaction: transaction) { + // In the global settings, we want to ignore the global default + // when rendering the "auto" swatch. + return value + } else if nil == threadWallpaper, + let wallpaper = Wallpaper.wallpaperSetting(for: nil, transaction: transaction), + wallpaper != .photo { + return autoChatColorForRendering(forWallpaper: wallpaper) + } else { + return Self.defaultChatColor + } } else { - return Self.defaultChatColor + if !ignoreGlobalDefault, + let value = defaultChatColorSetting(transaction: transaction) { + // In the global settings, we want to ignore the global default + // when rendering the "auto" swatch. + return value + } else if let wallpaper = Wallpaper.wallpaperSetting(for: nil, transaction: transaction), + wallpaper != .photo { + return autoChatColorForRendering(forWallpaper: wallpaper) + } else { + return Self.defaultChatColor + } } }