Merge branch 'charlesmchen/chatColorPrecedence'
This commit is contained in:
commit
ef110fe22f
@ -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) {
|
||||
|
||||
@ -211,15 +211,54 @@ 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) {
|
||||
return value
|
||||
} else if let wallpaper = Wallpaper.wallpaperForRendering(for: thread,
|
||||
transaction: transaction) {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user