session-ios/Signal/src/environment/ExperienceUpgrades/ExperienceUpgradeFinder.swift

91 lines
4.6 KiB
Swift
Raw Normal View History

//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
import SignalServiceKit
enum ExperienceUpgradeId: String {
case videoCalling = "001",
2017-09-02 00:08:31 +02:00
callKit = "002",
2017-09-27 20:30:17 +02:00
introducingProfiles = "003",
introducingReadReceipts = "004",
introducingCustomNotificationAudio = "005"
}
2018-05-25 23:17:15 +02:00
@objc public class ExperienceUpgradeFinder: NSObject {
2017-12-07 16:33:27 +01:00
// MARK - Singleton class
@objc(sharedManager)
public static let shared = ExperienceUpgradeFinder()
private override init() {
super.init()
SwiftSingletons.register(self)
}
2017-09-05 15:38:05 +02:00
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"),
2018-05-25 22:51:40 +02:00
image: #imageLiteral(resourceName: "introductory_splash_profile"))
2017-09-05 15:38:05 +02:00
}
2017-09-27 20:30:17 +02:00
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"),
2018-05-25 22:51:40 +02:00
image: #imageLiteral(resourceName: "introductory_splash_read_receipts"))
2017-09-27 20:30:17 +02:00
}
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"),
2018-05-25 22:51:40 +02:00
image: #imageLiteral(resourceName: "introductory_splash_custom_audio"))
}
// Keep these ordered by increasing uniqueId.
2018-05-25 22:51:40 +02:00
@objc
public var allExperienceUpgrades: [ExperienceUpgrade] {
2017-09-05 15:38:05 +02:00
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
2018-06-01 20:20:48 +02:00
].compactMap { $0 }
}
// MARK: - Instance Methods
2018-05-25 23:17:15 +02:00
@objc public func allUnseen(transaction: YapDatabaseReadTransaction) -> [ExperienceUpgrade] {
2017-11-15 19:15:48 +01:00
return allExperienceUpgrades.filter { ExperienceUpgrade.fetch(uniqueId: $0.uniqueId!, transaction: transaction) == nil }
}
2018-05-25 23:17:15 +02:00
@objc public func markAllAsSeen(transaction: YapDatabaseReadWriteTransaction) {
2017-12-07 16:33:27 +01:00
Logger.info("\(logTag) marking experience upgrades as seen")
allExperienceUpgrades.forEach { $0.save(with: transaction) }
}
}