2017-02-27 17:04:14 +01:00
//
2018-02-26 21:03:07 +01:00
// C o p y r i g h t ( c ) 2 0 1 8 O p e n W h i s p e r S y s t e m s . A l l r i g h t s r e s e r v e d .
2017-02-27 17:04:14 +01:00
//
import Foundation
2017-11-28 00:17:46 +01:00
import SignalServiceKit
2017-02-27 17:04:14 +01:00
2017-03-02 21:11:44 +01:00
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 " ,
2018-02-26 21:03:07 +01:00
introducingReadReceipts = " 004 " ,
introducingCustomNotificationAudio = " 005 "
2017-03-02 21:11:44 +01:00
}
2018-05-25 23:17:15 +02:00
@objc public class ExperienceUpgradeFinder : NSObject {
2017-12-07 16:33:27 +01:00
// M A R K - S i n g l e t o n c l a s s
@objc ( sharedManager )
public static let shared = ExperienceUpgradeFinder ( )
private override init ( ) {
super . init ( )
SwiftSingletons . register ( self )
}
2017-02-27 17:04:14 +01:00
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
}
2018-02-26 21:03:07 +01: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 " ) )
2018-02-26 21:03:07 +01:00
}
2017-02-27 17:04:14 +01:00
// K e e p t h e s e o r d e r e d b y i n c r e a s i n g u n i q u e I d .
2018-05-25 22:51:40 +02:00
@objc
public var allExperienceUpgrades : [ ExperienceUpgrade ] {
2017-09-05 15:38:05 +02:00
return [
2017-09-05 16:32:30 +02:00
// D i s a b l e o l d e x p e r i e n c e u p g r a d e s . M o s t p e o p l e h a v e s e e n t h e m b y n o w , a n d a c c o m o d a t i n g m u l t i p l e m a k e s l a y o u t h a r d e r .
// N o t e i f w e e v e r w a n t t o s h o w m u l t i p l e e x p e r i e n c e u p g r a d e s a g a i n
// w e ' l l h a v e t o u p d a t e t h e l a y o u t i n E x p e r i e n c e U p g r a d e s P a g e V i e w C o n t r o l l e r
//
// v i d e o C a l l i n g ,
// ( U I D e v i c e . c u r r e n t . s u p p o r t s C a l l K i t ? c a l l K i t : n i l ) ,
2018-02-26 21:03:07 +01:00
// i n t r o d u c i n g P r o f i l e s ,
// i n t r o d u c i n g R e a d R e c e i p t s ,
configurableNotificationAudio
2018-06-01 20:20:48 +02:00
] . compactMap { $0 }
2017-02-27 17:04:14 +01:00
}
// MARK: - I n s t a n c e M e t h o d s
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 }
2017-02-27 17:04:14 +01:00
}
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 " )
2017-02-27 17:04:14 +01:00
allExperienceUpgrades . forEach { $0 . save ( with : transaction ) }
}
}