//
// 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 .
//
import Foundation
import SignalServiceKit
enum ExperienceUpgradeId : String {
case videoCalling = " 001 " ,
callKit = " 002 " ,
introducingProfiles = " 003 " ,
introducingReadReceipts = " 004 " ,
introducingCustomNotificationAudio = " 005 " ,
introducingTypingIndicators = " 006 "
}
@objc public class ExperienceUpgradeFinder : NSObject {
// MARK: - 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 )
}
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 " ) )
}
// 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 .
@objc
public var allExperienceUpgrades : [ ExperienceUpgrade ] {
return [
// 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 ) ,
// 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 ,
// c o n f i g u r a b l e N o t i f i c a t i o n A u d i o
typingIndicators
] . compactMap { $0 }
}
// MARK: - I n s t a n c e M e t h o d s
@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 ) }
}
}