45 lines
1.2 KiB
Swift
45 lines
1.2 KiB
Swift
//
|
|
// Copyright (c) 2021 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
@objc
|
|
extension ConversationViewController {
|
|
|
|
func setupWallpaper() {
|
|
NotificationCenter.default.addObserver(
|
|
self,
|
|
selector: #selector(wallpaperDidChange),
|
|
name: Wallpaper.wallpaperDidChangeNotification,
|
|
object: nil
|
|
)
|
|
|
|
updateWallpaperView()
|
|
}
|
|
|
|
func wallpaperDidChange(_ notification: Notification) {
|
|
guard notification.object == nil || (notification.object as? String) == thread.uniqueId else { return }
|
|
updateWallpaperView()
|
|
|
|
let hasWallpaper = databaseStorage.read { transaction in
|
|
Wallpaper.exists(for: self.thread, transaction: transaction)
|
|
}
|
|
|
|
updateConversationStyle(hasWallpaper: hasWallpaper)
|
|
}
|
|
|
|
func updateWallpaperView() {
|
|
AssertIsOnMainThread()
|
|
|
|
guard let wallpaperView = databaseStorage.read(block: { transaction in
|
|
Wallpaper.view(for: self.thread, transaction: transaction)
|
|
}) else {
|
|
backgroundContainer.set(wallpaperView: nil)
|
|
return
|
|
}
|
|
|
|
backgroundContainer.set(wallpaperView: wallpaperView)
|
|
}
|
|
}
|