session-ios/Session/Signal/ExperienceUpgradeFinder.swift

117 lines
6.1 KiB
Swift

//
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
import Foundation
import SignalUtilitiesKit
enum ExperienceUpgradeId: String {
case videoCalling = "001",
callKit = "002",
introducingProfiles = "003",
introducingReadReceipts = "004",
introducingCustomNotificationAudio = "005",
introducingTypingIndicators = "006",
introducingLinkPreviews = "007"
}
@objc public class ExperienceUpgradeFinder: NSObject {
// MARK: - Singleton class
@objc(sharedManager)
public static let shared = ExperienceUpgradeFinder()
private override init() {
super.init()
SwiftSingletons.register(self)
}
var videoCalling: ExperienceUpgrade {
return ExperienceUpgrade(uniqueId: ExperienceUpgradeId.videoCalling.rawValue,
title: NSLocalizedString("UPGRADE_EXPERIENCE_VIDEO_TITLE", comment: "Header for upgrade experience"),
body: NSLocalizedString("UPGRADE_EXPERIENCE_VIDEO_DESCRIPTION", comment: "Description of video calling to upgrading (existing) users"),
image: #imageLiteral(resourceName: "introductory_splash_video_calling"))
}
var callKit: ExperienceUpgrade {
return ExperienceUpgrade(uniqueId: ExperienceUpgradeId.callKit.rawValue,
title: NSLocalizedString("UPGRADE_EXPERIENCE_CALLKIT_TITLE", comment: "Header for upgrade experience"),
body: NSLocalizedString("UPGRADE_EXPERIENCE_CALLKIT_DESCRIPTION", comment: "Description of CallKit to upgrading (existing) users"),
image: #imageLiteral(resourceName: "introductory_splash_callkit"))
}
var introducingProfiles: ExperienceUpgrade {
return ExperienceUpgrade(uniqueId: ExperienceUpgradeId.introducingProfiles.rawValue,
title: NSLocalizedString("UPGRADE_EXPERIENCE_INTRODUCING_PROFILES_TITLE", comment: "Header for upgrade experience"),
body: NSLocalizedString("UPGRADE_EXPERIENCE_INTRODUCING_PROFILES_DESCRIPTION", comment: "Description of new profile feature for upgrading (existing) users"),
image: #imageLiteral(resourceName: "introductory_splash_profile"))
}
var introducingReadReceipts: ExperienceUpgrade {
return ExperienceUpgrade(uniqueId: ExperienceUpgradeId.introducingReadReceipts.rawValue,
title: NSLocalizedString("UPGRADE_EXPERIENCE_INTRODUCING_READ_RECEIPTS_TITLE", comment: "Header for upgrade experience"),
body: NSLocalizedString("UPGRADE_EXPERIENCE_INTRODUCING_READ_RECEIPTS_DESCRIPTION", comment: "Description of new profile feature for upgrading (existing) users"),
image: #imageLiteral(resourceName: "introductory_splash_read_receipts"))
}
var configurableNotificationAudio: ExperienceUpgrade {
return ExperienceUpgrade(uniqueId: ExperienceUpgradeId.introducingCustomNotificationAudio.rawValue,
title: NSLocalizedString("UPGRADE_EXPERIENCE_INTRODUCING_NOTIFICATION_AUDIO_TITLE", comment: "Header for upgrade experience"),
body: NSLocalizedString("UPGRADE_EXPERIENCE_INTRODUCING_NOTIFICATION_AUDIO_DESCRIPTION", comment: "Description for notification audio customization"),
image: #imageLiteral(resourceName: "introductory_splash_custom_audio"))
}
var typingIndicators: ExperienceUpgrade {
return ExperienceUpgrade(uniqueId: ExperienceUpgradeId.introducingTypingIndicators.rawValue,
title: NSLocalizedString("UPGRADE_EXPERIENCE_INTRODUCING_TYPING_INDICATORS_TITLE", comment: "Header for upgrading users"),
body: NSLocalizedString("UPGRADE_EXPERIENCE_INTRODUCING_TYPING_INDICATORS_DESCRIPTION", comment: "Body text for upgrading users"),
image: #imageLiteral(resourceName: "introductory_splash_custom_audio"))
}
var linkPreviews: ExperienceUpgrade {
let imageName = Theme.isDarkThemeEnabled ? "introducing-link-previews-dark" : "introducing-link-previews-light"
let image: UIImage
if let heroImage = UIImage(named: imageName) {
image = heroImage
} else {
owsFailDebug("Could not load hero image.")
image = #imageLiteral(resourceName: "introductory_splash_custom_audio")
}
return ExperienceUpgrade(uniqueId: ExperienceUpgradeId.introducingLinkPreviews.rawValue,
title: NSLocalizedString("UPGRADE_EXPERIENCE_INTRODUCING_LINK_PREVIEWS_TITLE", comment: "Header for upgrading users"),
body: NSLocalizedString("UPGRADE_EXPERIENCE_INTRODUCING_LINK_PREVIEWS_DESCRIPTION", comment: "Body text for upgrading users"),
image: image)
}
// Keep these ordered by increasing uniqueId.
@objc
public var allExperienceUpgrades: [ExperienceUpgrade] {
return [
// Disable old experience upgrades. Most people have seen them by now, and accomodating multiple makes layout harder.
// Note if we ever want to show multiple experience upgrades again
// we'll have to update the layout in ExperienceUpgradesPageViewController
//
// videoCalling,
// (UIDevice.current.supportsCallKit ? callKit : nil),
// introducingProfiles,
// introducingReadReceipts,
// configurableNotificationAudio
// typingIndicators
linkPreviews
].compactMap { $0 }
}
// MARK: - Instance Methods
@objc public func allUnseen(transaction: YapDatabaseReadTransaction) -> [ExperienceUpgrade] {
return allExperienceUpgrades.filter { ExperienceUpgrade.fetch(uniqueId: $0.uniqueId!, transaction: transaction) == nil }
}
@objc public func markAllAsSeen(transaction: YapDatabaseReadWriteTransaction) {
Logger.info("marking experience upgrades as seen")
allExperienceUpgrades.forEach { $0.save(with: transaction) }
}
}