mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-06 03:33:41 +02:00
Refactoring
This commit is contained in:
parent
f0f02dc4b9
commit
1141e09c1b
257 changed files with 1894 additions and 1720 deletions
|
|
@ -120,7 +120,7 @@ public final class AppLockContextImpl: AppLockContext {
|
|||
return
|
||||
}
|
||||
|
||||
let passcodeSettings: PresentationPasscodeSettings = sharedData.entries[ApplicationSpecificSharedDataKeys.presentationPasscodeSettings] as? PresentationPasscodeSettings ?? .defaultSettings
|
||||
let passcodeSettings: PresentationPasscodeSettings = sharedData.entries[ApplicationSpecificSharedDataKeys.presentationPasscodeSettings]?.get(PresentationPasscodeSettings.self) ?? .defaultSettings
|
||||
|
||||
let timestamp = CFAbsoluteTimeGetCurrent()
|
||||
var becameActiveRecently = false
|
||||
|
|
|
|||
|
|
@ -453,7 +453,7 @@ final class CallListControllerNode: ASDisplayNode {
|
|||
let showCallsTab = context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.callListSettings])
|
||||
|> map { sharedData -> Bool in
|
||||
var value = CallListSettings.defaultSettings.showTab
|
||||
if let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.callListSettings] as? CallListSettings {
|
||||
if let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.callListSettings]?.get(CallListSettings.self) {
|
||||
value = settings.showTab
|
||||
}
|
||||
return value
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ func archiveContextMenuItems(context: AccountContext, groupId: PeerGroupId, chat
|
|||
})))
|
||||
}
|
||||
|
||||
let settings = transaction.getPreferencesEntry(key: ApplicationSpecificPreferencesKeys.chatArchiveSettings) as? ChatArchiveSettings ?? ChatArchiveSettings.default
|
||||
let settings = transaction.getPreferencesEntry(key: ApplicationSpecificPreferencesKeys.chatArchiveSettings)?.get(ChatArchiveSettings.self) ?? ChatArchiveSettings.default
|
||||
let isPinned = !settings.isHiddenByDefault
|
||||
items.append(.action(ContextMenuActionItem(text: isPinned ? strings.ChatList_Context_HideArchive : strings.ChatList_Context_UnhideArchive, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: isPinned ? "Chat/Context Menu/Unpin": "Chat/Context Menu/Pin"), color: theme.contextMenu.primaryColor) }, action: { [weak chatListController] _, f in
|
||||
chatListController?.toggleArchivedFolderHiddenByDefault()
|
||||
|
|
|
|||
|
|
@ -262,7 +262,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
|
|||
|
||||
let hasProxy = context.sharedContext.accountManager.sharedData(keys: [SharedDataKeys.proxySettings])
|
||||
|> map { sharedData -> (Bool, Bool) in
|
||||
if let settings = sharedData.entries[SharedDataKeys.proxySettings] as? ProxySettings {
|
||||
if let settings = sharedData.entries[SharedDataKeys.proxySettings]?.get(ProxySettings.self) {
|
||||
return (!settings.servers.isEmpty, settings.enabled)
|
||||
} else {
|
||||
return (false, false)
|
||||
|
|
@ -1192,7 +1192,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
|
|||
let context = self.context
|
||||
let signal = combineLatest(self.context.sharedContext.accountManager.transaction { transaction -> String in
|
||||
let languageCode: String
|
||||
if let current = transaction.getSharedData(SharedDataKeys.localizationSettings) as? LocalizationSettings {
|
||||
if let current = transaction.getSharedData(SharedDataKeys.localizationSettings)?.get(LocalizationSettings.self) {
|
||||
let code = current.primaryComponent.languageCode
|
||||
let rawSuffix = "-raw"
|
||||
if code.hasSuffix(rawSuffix) {
|
||||
|
|
@ -1206,7 +1206,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
|
|||
return languageCode
|
||||
}, self.context.account.postbox.transaction { transaction -> SuggestedLocalizationEntry? in
|
||||
var suggestedLocalization: SuggestedLocalizationEntry?
|
||||
if let localization = transaction.getPreferencesEntry(key: PreferencesKeys.suggestedLocalization) as? SuggestedLocalizationEntry {
|
||||
if let localization = transaction.getPreferencesEntry(key: PreferencesKeys.suggestedLocalization)?.get(SuggestedLocalizationEntry.self) {
|
||||
suggestedLocalization = localization
|
||||
}
|
||||
return suggestedLocalization
|
||||
|
|
@ -1291,7 +1291,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
|
|||
PreferencesKeys.chatListFiltersFeaturedState
|
||||
])
|
||||
|> mapToSignal { view -> Signal<Bool, NoError> in
|
||||
if let entry = view.values[PreferencesKeys.chatListFiltersFeaturedState] as? ChatListFiltersFeaturedState {
|
||||
if let entry = view.values[PreferencesKeys.chatListFiltersFeaturedState]?.get(ChatListFiltersFeaturedState.self) {
|
||||
return .single(!entry.filters.isEmpty && !entry.isSeen)
|
||||
} else {
|
||||
return .complete()
|
||||
|
|
@ -1537,7 +1537,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
|
|||
let experimentalUISettingsKey: ValueBoxKey = ApplicationSpecificSharedDataKeys.experimentalUISettings
|
||||
let displayTabsAtBottom = self.context.sharedContext.accountManager.sharedData(keys: Set([experimentalUISettingsKey]))
|
||||
|> map { sharedData -> Bool in
|
||||
let settings: ExperimentalUISettings = sharedData.entries[experimentalUISettingsKey] as? ExperimentalUISettings ?? ExperimentalUISettings.defaultSettings
|
||||
let settings: ExperimentalUISettings = sharedData.entries[experimentalUISettingsKey]?.get(ExperimentalUISettings.self) ?? ExperimentalUISettings.defaultSettings
|
||||
return settings.foldersTabAtBottom
|
||||
}
|
||||
|> distinctUntilChanged
|
||||
|
|
|
|||
|
|
@ -307,7 +307,7 @@ public func chatListFilterPresetListController(context: AccountContext, mode: Ch
|
|||
|
||||
let featuredFilters = context.account.postbox.preferencesView(keys: [PreferencesKeys.chatListFiltersFeaturedState])
|
||||
|> map { preferences -> [ChatListFeaturedFilter] in
|
||||
guard let state = preferences.values[PreferencesKeys.chatListFiltersFeaturedState] as? ChatListFiltersFeaturedState else {
|
||||
guard let state = preferences.values[PreferencesKeys.chatListFiltersFeaturedState]?.get(ChatListFiltersFeaturedState.self) else {
|
||||
return []
|
||||
}
|
||||
return state.filters
|
||||
|
|
@ -330,7 +330,7 @@ public func chatListFilterPresetListController(context: AccountContext, mode: Ch
|
|||
featuredFilters
|
||||
)
|
||||
|> map { presentationData, state, filtersWithCountsValue, preferences, updatedFilterOrderValue, suggestedFilters -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
let filterSettings = preferences.values[ApplicationSpecificPreferencesKeys.chatListFilterSettings] as? ChatListFilterSettings ?? ChatListFilterSettings.default
|
||||
let filterSettings = preferences.values[ApplicationSpecificPreferencesKeys.chatListFilterSettings]?.get(ChatListFilterSettings.self) ?? ChatListFilterSettings.default
|
||||
let leftNavigationButton: ItemListNavigationButton?
|
||||
switch mode {
|
||||
case .default:
|
||||
|
|
|
|||
|
|
@ -1743,10 +1743,10 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
|
|||
return
|
||||
}
|
||||
let _ = (strongSelf.context.sharedContext.accountManager.transaction { transaction -> AudioPlaybackRate in
|
||||
let settings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.musicPlaybackSettings) as? MusicPlaybackSettings ?? MusicPlaybackSettings.defaultSettings
|
||||
let settings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.musicPlaybackSettings)?.get(MusicPlaybackSettings.self) ?? MusicPlaybackSettings.defaultSettings
|
||||
|
||||
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.musicPlaybackSettings, { _ in
|
||||
return settings.withUpdatedVoicePlaybackRate(rate)
|
||||
return PreferencesEntry(settings.withUpdatedVoicePlaybackRate(rate))
|
||||
})
|
||||
return rate
|
||||
}
|
||||
|
|
|
|||
|
|
@ -806,7 +806,7 @@ public final class ChatListNode: ListView {
|
|||
|
||||
let hideArchivedFolderByDefault = context.account.postbox.preferencesView(keys: [ApplicationSpecificPreferencesKeys.chatArchiveSettings])
|
||||
|> map { view -> Bool in
|
||||
let settings: ChatArchiveSettings = view.values[ApplicationSpecificPreferencesKeys.chatArchiveSettings] as? ChatArchiveSettings ?? .default
|
||||
let settings: ChatArchiveSettings = view.values[ApplicationSpecificPreferencesKeys.chatArchiveSettings]?.get(ChatArchiveSettings.self) ?? .default
|
||||
return settings.isHiddenByDefault
|
||||
}
|
||||
|> distinctUntilChanged
|
||||
|
|
@ -1759,7 +1759,7 @@ public final class ChatListNode: ListView {
|
|||
let postbox = self.context.account.postbox
|
||||
return self.context.sharedContext.accountManager.transaction { transaction -> Signal<ChatListIndex?, NoError> in
|
||||
var filter = true
|
||||
if let inAppNotificationSettings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.inAppNotificationSettings) as? InAppNotificationSettings {
|
||||
if let inAppNotificationSettings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.inAppNotificationSettings)?.get(InAppNotificationSettings.self) {
|
||||
switch inAppNotificationSettings.totalUnreadCountDisplayStyle {
|
||||
case .filtered:
|
||||
filter = true
|
||||
|
|
|
|||
|
|
@ -904,7 +904,7 @@ public final class ContactListNode: ASDisplayNode {
|
|||
|> then(
|
||||
combineLatest(context.sharedContext.accountManager.noticeEntry(key: ApplicationSpecificNotice.permissionWarningKey(permission: .contacts)!), context.account.postbox.preferencesView(keys: [PreferencesKeys.contactsSettings]))
|
||||
|> map { noticeView, preferences -> (Bool, Bool) in
|
||||
let settings: ContactsSettings = preferences.values[PreferencesKeys.contactsSettings] as? ContactsSettings ?? ContactsSettings.defaultSettings
|
||||
let settings: ContactsSettings = preferences.values[PreferencesKeys.contactsSettings]?.get(ContactsSettings.self) ?? ContactsSettings.defaultSettings
|
||||
let synchronizeDeviceContacts: Bool = settings.synchronizeContacts
|
||||
let suppressed: Bool
|
||||
let timestamp = noticeView.value.flatMap({ ApplicationSpecificNotice.getTimestampValue($0) })
|
||||
|
|
|
|||
|
|
@ -146,10 +146,10 @@ public class ContactsController: ViewController {
|
|||
if #available(iOSApplicationExtension 10.0, iOS 10.0, *) {
|
||||
self.authorizationDisposable = (combineLatest(DeviceAccess.authorizationStatus(subject: .contacts), combineLatest(context.sharedContext.accountManager.noticeEntry(key: ApplicationSpecificNotice.permissionWarningKey(permission: .contacts)!), context.account.postbox.preferencesView(keys: [PreferencesKeys.contactsSettings]), context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.contactSynchronizationSettings]))
|
||||
|> map { noticeView, preferences, sharedData -> (Bool, ContactsSortOrder) in
|
||||
let settings: ContactsSettings = preferences.values[PreferencesKeys.contactsSettings] as? ContactsSettings ?? ContactsSettings.defaultSettings
|
||||
let settings: ContactsSettings = preferences.values[PreferencesKeys.contactsSettings]?.get(ContactsSettings.self) ?? ContactsSettings.defaultSettings
|
||||
let synchronizeDeviceContacts: Bool = settings.synchronizeContacts
|
||||
|
||||
let contactsSettings = sharedData.entries[ApplicationSpecificSharedDataKeys.contactSynchronizationSettings] as? ContactSynchronizationSettings
|
||||
let contactsSettings = sharedData.entries[ApplicationSpecificSharedDataKeys.contactSynchronizationSettings]?.get(ContactSynchronizationSettings.self)
|
||||
|
||||
let sortOrder: ContactsSortOrder = contactsSettings?.sortOrder ?? .presence
|
||||
if !synchronizeDeviceContacts {
|
||||
|
|
@ -172,7 +172,7 @@ public class ContactsController: ViewController {
|
|||
} else {
|
||||
self.sortOrderPromise.set(context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.contactSynchronizationSettings])
|
||||
|> map { sharedData -> ContactsSortOrder in
|
||||
let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.contactSynchronizationSettings] as? ContactSynchronizationSettings
|
||||
let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.contactSynchronizationSettings]?.get(ContactSynchronizationSettings.self)
|
||||
return settings?.sortOrder ?? .presence
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,6 @@ private enum DebugControllerEntry: ItemListNodeEntry {
|
|||
case optimizeDatabase(PresentationTheme)
|
||||
case photoPreview(PresentationTheme, Bool)
|
||||
case knockoutWallpaper(PresentationTheme, Bool)
|
||||
case demoVideoChats(Bool)
|
||||
case experimentalCompatibility(Bool)
|
||||
case enableDebugDataDisplay(Bool)
|
||||
case playerEmbedding(Bool)
|
||||
|
|
@ -100,7 +99,7 @@ private enum DebugControllerEntry: ItemListNodeEntry {
|
|||
return DebugControllerSection.logging.rawValue
|
||||
case .enableRaiseToSpeak, .keepChatNavigationStack, .skipReadHistory, .crashOnSlowQueries:
|
||||
return DebugControllerSection.experiments.rawValue
|
||||
case .clearTips, .crash, .resetData, .resetDatabase, .resetDatabaseAndCache, .resetHoles, .reindexUnread, .resetBiometricsData, .optimizeDatabase, .photoPreview, .knockoutWallpaper, .demoVideoChats, .playerEmbedding, .playlistPlayback, .voiceConference, .experimentalCompatibility, .enableDebugDataDisplay:
|
||||
case .clearTips, .crash, .resetData, .resetDatabase, .resetDatabaseAndCache, .resetHoles, .reindexUnread, .resetBiometricsData, .optimizeDatabase, .photoPreview, .knockoutWallpaper, .playerEmbedding, .playlistPlayback, .voiceConference, .experimentalCompatibility, .enableDebugDataDisplay:
|
||||
return DebugControllerSection.experiments.rawValue
|
||||
case .preferredVideoCodec:
|
||||
return DebugControllerSection.videoExperiments.rawValue
|
||||
|
|
@ -163,8 +162,6 @@ private enum DebugControllerEntry: ItemListNodeEntry {
|
|||
return 23
|
||||
case .knockoutWallpaper:
|
||||
return 24
|
||||
case .demoVideoChats:
|
||||
return 25
|
||||
case .experimentalCompatibility:
|
||||
return 26
|
||||
case .enableDebugDataDisplay:
|
||||
|
|
@ -703,9 +700,9 @@ private enum DebugControllerEntry: ItemListNodeEntry {
|
|||
return ItemListSwitchItem(presentationData: presentationData, title: "Media Preview (Updated)", value: value, sectionId: self.section, style: .blocks, updated: { value in
|
||||
let _ = arguments.sharedContext.accountManager.transaction ({ transaction in
|
||||
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.experimentalUISettings, { settings in
|
||||
var settings = settings as? ExperimentalUISettings ?? ExperimentalUISettings.defaultSettings
|
||||
var settings = settings?.get(ExperimentalUISettings.self) ?? ExperimentalUISettings.defaultSettings
|
||||
settings.chatListPhotos = value
|
||||
return settings
|
||||
return PreferencesEntry(settings)
|
||||
})
|
||||
}).start()
|
||||
})
|
||||
|
|
@ -713,19 +710,9 @@ private enum DebugControllerEntry: ItemListNodeEntry {
|
|||
return ItemListSwitchItem(presentationData: presentationData, title: "Knockout Wallpaper", value: value, sectionId: self.section, style: .blocks, updated: { value in
|
||||
let _ = arguments.sharedContext.accountManager.transaction ({ transaction in
|
||||
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.experimentalUISettings, { settings in
|
||||
var settings = settings as? ExperimentalUISettings ?? ExperimentalUISettings.defaultSettings
|
||||
var settings = settings?.get(ExperimentalUISettings.self) ?? ExperimentalUISettings.defaultSettings
|
||||
settings.knockoutWallpaper = value
|
||||
return settings
|
||||
})
|
||||
}).start()
|
||||
})
|
||||
case let .demoVideoChats(value):
|
||||
return ItemListSwitchItem(presentationData: presentationData, title: "Demo Video", value: value, sectionId: self.section, style: .blocks, updated: { value in
|
||||
let _ = arguments.sharedContext.accountManager.transaction ({ transaction in
|
||||
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.experimentalUISettings, { settings in
|
||||
var settings = settings as? ExperimentalUISettings ?? ExperimentalUISettings.defaultSettings
|
||||
settings.demoVideoChats = value
|
||||
return settings
|
||||
return PreferencesEntry(settings)
|
||||
})
|
||||
}).start()
|
||||
})
|
||||
|
|
@ -733,9 +720,9 @@ private enum DebugControllerEntry: ItemListNodeEntry {
|
|||
return ItemListSwitchItem(presentationData: presentationData, title: "Experimental Compatibility", value: value, sectionId: self.section, style: .blocks, updated: { value in
|
||||
let _ = arguments.sharedContext.accountManager.transaction ({ transaction in
|
||||
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.experimentalUISettings, { settings in
|
||||
var settings = settings as? ExperimentalUISettings ?? ExperimentalUISettings.defaultSettings
|
||||
var settings = settings?.get(ExperimentalUISettings.self) ?? ExperimentalUISettings.defaultSettings
|
||||
settings.experimentalCompatibility = value
|
||||
return settings
|
||||
return PreferencesEntry(settings)
|
||||
})
|
||||
}).start()
|
||||
})
|
||||
|
|
@ -743,9 +730,9 @@ private enum DebugControllerEntry: ItemListNodeEntry {
|
|||
return ItemListSwitchItem(presentationData: presentationData, title: "Debug Data Display", value: value, sectionId: self.section, style: .blocks, updated: { value in
|
||||
let _ = arguments.sharedContext.accountManager.transaction ({ transaction in
|
||||
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.experimentalUISettings, { settings in
|
||||
var settings = settings as? ExperimentalUISettings ?? ExperimentalUISettings.defaultSettings
|
||||
var settings = settings?.get(ExperimentalUISettings.self) ?? ExperimentalUISettings.defaultSettings
|
||||
settings.enableDebugDataDisplay = value
|
||||
return settings
|
||||
return PreferencesEntry(settings)
|
||||
})
|
||||
}).start()
|
||||
})
|
||||
|
|
@ -753,9 +740,9 @@ private enum DebugControllerEntry: ItemListNodeEntry {
|
|||
return ItemListSwitchItem(presentationData: presentationData, title: "Player Embedding", value: value, sectionId: self.section, style: .blocks, updated: { value in
|
||||
let _ = arguments.sharedContext.accountManager.transaction ({ transaction in
|
||||
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.experimentalUISettings, { settings in
|
||||
var settings = settings as? ExperimentalUISettings ?? ExperimentalUISettings.defaultSettings
|
||||
var settings = settings?.get(ExperimentalUISettings.self) ?? ExperimentalUISettings.defaultSettings
|
||||
settings.playerEmbedding = value
|
||||
return settings
|
||||
return PreferencesEntry(settings)
|
||||
})
|
||||
}).start()
|
||||
})
|
||||
|
|
@ -763,9 +750,9 @@ private enum DebugControllerEntry: ItemListNodeEntry {
|
|||
return ItemListSwitchItem(presentationData: presentationData, title: "Playlist Playback", value: value, sectionId: self.section, style: .blocks, updated: { value in
|
||||
let _ = arguments.sharedContext.accountManager.transaction ({ transaction in
|
||||
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.experimentalUISettings, { settings in
|
||||
var settings = settings as? ExperimentalUISettings ?? ExperimentalUISettings.defaultSettings
|
||||
var settings = settings?.get(ExperimentalUISettings.self) ?? ExperimentalUISettings.defaultSettings
|
||||
settings.playlistPlayback = value
|
||||
return settings
|
||||
return PreferencesEntry(settings)
|
||||
})
|
||||
}).start()
|
||||
})
|
||||
|
|
@ -779,9 +766,9 @@ private enum DebugControllerEntry: ItemListNodeEntry {
|
|||
return ItemListCheckboxItem(presentationData: presentationData, title: title, style: .right, checked: isSelected, zeroSeparatorInsets: false, sectionId: self.section, action: {
|
||||
let _ = arguments.sharedContext.accountManager.transaction ({ transaction in
|
||||
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.experimentalUISettings, { settings in
|
||||
var settings = settings as? ExperimentalUISettings ?? ExperimentalUISettings.defaultSettings
|
||||
var settings = settings?.get(ExperimentalUISettings.self) ?? ExperimentalUISettings.defaultSettings
|
||||
settings.preferredVideoCodec = value
|
||||
return settings
|
||||
return PreferencesEntry(settings)
|
||||
})
|
||||
}).start()
|
||||
})
|
||||
|
|
@ -789,9 +776,9 @@ private enum DebugControllerEntry: ItemListNodeEntry {
|
|||
return ItemListSwitchItem(presentationData: presentationData, title: "Video Cropping Optimization", value: !value, sectionId: self.section, style: .blocks, updated: { value in
|
||||
let _ = arguments.sharedContext.accountManager.transaction ({ transaction in
|
||||
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.experimentalUISettings, { settings in
|
||||
var settings = settings as? ExperimentalUISettings ?? ExperimentalUISettings.defaultSettings
|
||||
var settings = settings?.get(ExperimentalUISettings.self) ?? ExperimentalUISettings.defaultSettings
|
||||
settings.disableVideoAspectScaling = !value
|
||||
return settings
|
||||
return PreferencesEntry(settings)
|
||||
})
|
||||
}).start()
|
||||
})
|
||||
|
|
@ -799,9 +786,9 @@ private enum DebugControllerEntry: ItemListNodeEntry {
|
|||
return ItemListSwitchItem(presentationData: presentationData, title: "Enable VoIP TCP", value: !value, sectionId: self.section, style: .blocks, updated: { value in
|
||||
let _ = arguments.sharedContext.accountManager.transaction ({ transaction in
|
||||
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.experimentalUISettings, { settings in
|
||||
var settings = settings as? ExperimentalUISettings ?? ExperimentalUISettings.defaultSettings
|
||||
var settings = settings?.get(ExperimentalUISettings.self) ?? ExperimentalUISettings.defaultSettings
|
||||
settings.enableVoipTcp = value
|
||||
return settings
|
||||
return PreferencesEntry(settings)
|
||||
})
|
||||
}).start()
|
||||
})
|
||||
|
|
@ -858,7 +845,6 @@ private func debugControllerEntries(sharedContext: SharedAccountContext, present
|
|||
entries.append(.optimizeDatabase(presentationData.theme))
|
||||
if isMainApp {
|
||||
entries.append(.knockoutWallpaper(presentationData.theme, experimentalSettings.knockoutWallpaper))
|
||||
entries.append(.demoVideoChats(experimentalSettings.demoVideoChats))
|
||||
entries.append(.experimentalCompatibility(experimentalSettings.experimentalCompatibility))
|
||||
entries.append(.enableDebugDataDisplay(experimentalSettings.enableDebugDataDisplay))
|
||||
entries.append(.playerEmbedding(experimentalSettings.playerEmbedding))
|
||||
|
|
@ -927,22 +913,22 @@ public func debugController(sharedContext: SharedAccountContext, context: Accoun
|
|||
let signal = combineLatest(sharedContext.presentationData, sharedContext.accountManager.sharedData(keys: Set([SharedDataKeys.loggingSettings, ApplicationSpecificSharedDataKeys.mediaInputSettings, ApplicationSpecificSharedDataKeys.experimentalUISettings])), preferencesSignal)
|
||||
|> map { presentationData, sharedData, preferences -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
let loggingSettings: LoggingSettings
|
||||
if let value = sharedData.entries[SharedDataKeys.loggingSettings] as? LoggingSettings {
|
||||
if let value = sharedData.entries[SharedDataKeys.loggingSettings]?.get(LoggingSettings.self) {
|
||||
loggingSettings = value
|
||||
} else {
|
||||
loggingSettings = LoggingSettings.defaultSettings
|
||||
}
|
||||
|
||||
let mediaInputSettings: MediaInputSettings
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.mediaInputSettings] as? MediaInputSettings {
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.mediaInputSettings]?.get(MediaInputSettings.self) {
|
||||
mediaInputSettings = value
|
||||
} else {
|
||||
mediaInputSettings = MediaInputSettings.defaultSettings
|
||||
}
|
||||
|
||||
let experimentalSettings: ExperimentalUISettings = (sharedData.entries[ApplicationSpecificSharedDataKeys.experimentalUISettings] as? ExperimentalUISettings) ?? ExperimentalUISettings.defaultSettings
|
||||
let experimentalSettings: ExperimentalUISettings = sharedData.entries[ApplicationSpecificSharedDataKeys.experimentalUISettings]?.get(ExperimentalUISettings.self) ?? ExperimentalUISettings.defaultSettings
|
||||
|
||||
let networkSettings: NetworkSettings? = preferences?.values[PreferencesKeys.networkSettings] as? NetworkSettings
|
||||
let networkSettings: NetworkSettings? = preferences?.values[PreferencesKeys.networkSettings]?.get(NetworkSettings.self)
|
||||
|
||||
var leftNavigationButton: ItemListNavigationButton?
|
||||
if modal {
|
||||
|
|
|
|||
|
|
@ -488,7 +488,7 @@ public class GalleryController: ViewController, StandalonePresentableController
|
|||
let f: () -> Void = {
|
||||
if let strongSelf = self {
|
||||
if let view = view {
|
||||
let appConfiguration: AppConfiguration = preferencesView.values[PreferencesKeys.appConfiguration] as? AppConfiguration ?? .defaultValue
|
||||
let appConfiguration: AppConfiguration = preferencesView.values[PreferencesKeys.appConfiguration]?.get(AppConfiguration.self) ?? .defaultValue
|
||||
let configuration = GalleryConfiguration.with(appConfiguration: appConfiguration)
|
||||
strongSelf.configuration = configuration
|
||||
|
||||
|
|
|
|||
|
|
@ -109,13 +109,13 @@ public final class InstantPageController: ViewController {
|
|||
|> deliverOnMainQueue).start(next: { [weak self] sharedData in
|
||||
if let strongSelf = self {
|
||||
let settings: InstantPagePresentationSettings
|
||||
if let current = sharedData.entries[ApplicationSpecificSharedDataKeys.instantPagePresentationSettings] as? InstantPagePresentationSettings {
|
||||
if let current = sharedData.entries[ApplicationSpecificSharedDataKeys.instantPagePresentationSettings]?.get(InstantPagePresentationSettings.self) {
|
||||
settings = current
|
||||
} else {
|
||||
settings = InstantPagePresentationSettings.defaultSettings
|
||||
}
|
||||
let themeSettings: PresentationThemeSettings
|
||||
if let current = sharedData.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings] as? PresentationThemeSettings {
|
||||
if let current = sharedData.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings]?.get(PresentationThemeSettings.self) {
|
||||
themeSettings = current
|
||||
} else {
|
||||
themeSettings = PresentationThemeSettings.defaultSettings
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ typedef enum {
|
|||
- (bool)checkObjectIsKindOfClass:(Class _Nonnull)targetClass;
|
||||
- (void)setClass:(Class _Nonnull)newClass;
|
||||
|
||||
- (NSNumber * _Nullable)floatValueForKeyPath:(NSString * _Nonnull)keyPath;
|
||||
|
||||
@end
|
||||
|
||||
SEL _Nonnull makeSelectorFromString(NSString * _Nonnull string);
|
||||
|
|
|
|||
|
|
@ -98,27 +98,17 @@
|
|||
object_setClass(self, newClass);
|
||||
}
|
||||
|
||||
static Class freedomMakeClass(Class superclass, Class subclass, SEL *copySelectors, int copySelectorsCount)
|
||||
{
|
||||
if (superclass == Nil || subclass == Nil)
|
||||
return nil;
|
||||
|
||||
Class decoratedClass = objc_allocateClassPair(superclass, [[NSString alloc] initWithFormat:@"%@_%@", NSStringFromClass(superclass), NSStringFromClass(subclass)].UTF8String, 0);
|
||||
|
||||
unsigned int count = 0;
|
||||
Method *methodList = class_copyMethodList(subclass, &count);
|
||||
if (methodList != NULL) {
|
||||
for (unsigned int i = 0; i < count; i++) {
|
||||
SEL methodName = method_getName(methodList[i]);
|
||||
class_addMethod(decoratedClass, methodName, method_getImplementation(methodList[i]), method_getTypeEncoding(methodList[i]));
|
||||
- (NSNumber * _Nullable)floatValueForKeyPath:(NSString * _Nonnull)keyPath {
|
||||
id value = [self valueForKeyPath:keyPath];
|
||||
if (value != nil) {
|
||||
if ([value respondsToSelector:@selector(floatValue)]) {
|
||||
return @([value floatValue]);
|
||||
} else {
|
||||
return nil;
|
||||
}
|
||||
|
||||
free(methodList);
|
||||
} else {
|
||||
return nil;
|
||||
}
|
||||
|
||||
objc_registerClassPair(decoratedClass);
|
||||
|
||||
return decoratedClass;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -823,7 +823,7 @@ public func channelInfoController(context: AccountContext, peerId: PeerId) -> Vi
|
|||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
let _ = (context.account.postbox.transaction { transaction -> (TelegramPeerNotificationSettings, GlobalNotificationSettings) in
|
||||
let peerSettings: TelegramPeerNotificationSettings = (transaction.getPeerNotificationSettings(peerId) as? TelegramPeerNotificationSettings) ?? TelegramPeerNotificationSettings.defaultSettings
|
||||
let globalSettings: GlobalNotificationSettings = (transaction.getPreferencesEntry(key: PreferencesKeys.globalNotifications) as? GlobalNotificationSettings) ?? GlobalNotificationSettings.defaultSettings
|
||||
let globalSettings: GlobalNotificationSettings = transaction.getPreferencesEntry(key: PreferencesKeys.globalNotifications)?.get(GlobalNotificationSettings.self) ?? GlobalNotificationSettings.defaultSettings
|
||||
return (peerSettings, globalSettings)
|
||||
}
|
||||
|> deliverOnMainQueue).start(next: { peerSettings, globalSettings in
|
||||
|
|
@ -929,7 +929,7 @@ public func channelInfoController(context: AccountContext, peerId: PeerId) -> Vi
|
|||
|
||||
var globalNotificationSettings: GlobalNotificationSettings = GlobalNotificationSettings.defaultSettings
|
||||
if let preferencesView = combinedView.views[globalNotificationsKey] as? PreferencesView {
|
||||
if let settings = preferencesView.values[PreferencesKeys.globalNotifications] as? GlobalNotificationSettings {
|
||||
if let settings = preferencesView.values[PreferencesKeys.globalNotifications]?.get(GlobalNotificationSettings.self) {
|
||||
globalNotificationSettings = settings
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -405,7 +405,7 @@ public func groupStickerPackSetupController(context: AccountContext, peerId: Pee
|
|||
let signal = combineLatest(context.sharedContext.presentationData, statePromise.get() |> deliverOnMainQueue, initialData.get() |> deliverOnMainQueue, stickerPacks.get() |> deliverOnMainQueue, searchState.get() |> deliverOnMainQueue, context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.stickerSettings]) |> deliverOnMainQueue)
|
||||
|> map { presentationData, state, initialData, view, searchState, sharedData -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
var stickerSettings = StickerSettings.defaultSettings
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.stickerSettings] as? StickerSettings {
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.stickerSettings]?.get(StickerSettings.self) {
|
||||
stickerSettings = value
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -573,7 +573,7 @@ public func peersNearbyController(context: AccountContext) -> ViewController {
|
|||
|> deliverOnMainQueue
|
||||
|> map { presentationData, data, chatLocation, displayLoading, expanded, view -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
let previous = previousData.swap(data)
|
||||
let state = view.values[PreferencesKeys.peersNearby] as? PeersNearbyState ?? .default
|
||||
let state = view.values[PreferencesKeys.peersNearby]?.get(PeersNearbyState.self) ?? .default
|
||||
|
||||
var crossfade = false
|
||||
if (data?.users.isEmpty ?? true) != (previous?.users.isEmpty ?? true) {
|
||||
|
|
|
|||
|
|
@ -444,6 +444,15 @@ public final class PostboxEncoder {
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
public func encodeObjectToRawData<T: PostboxCoding>(_ value: T) -> AdaptedPostboxEncoder.RawObjectData {
|
||||
let typeHash: Int32 = murMurHashString32("\(type(of: value))")
|
||||
|
||||
let innerEncoder = PostboxEncoder()
|
||||
value.encode(innerEncoder)
|
||||
|
||||
return AdaptedPostboxEncoder.RawObjectData(typeHash: typeHash, data: innerEncoder.makeData())
|
||||
}
|
||||
|
||||
public func encodeObjectArray<T: PostboxCoding>(_ value: [T], forKey key: String) {
|
||||
self.encodeKey(key)
|
||||
|
|
@ -649,7 +658,7 @@ public final class PostboxEncoder {
|
|||
let innerEncoder = _AdaptedPostboxEncoder(typeHash: typeHash)
|
||||
try! value.encode(to: innerEncoder)
|
||||
|
||||
let (data, valueType) = innerEncoder.makeData(addHeader: true)
|
||||
let (data, valueType) = innerEncoder.makeData(addHeader: true, isDictionary: false)
|
||||
self.encodeInnerObjectData(data, valueType: valueType, forKey: key)
|
||||
}
|
||||
|
||||
|
|
@ -1011,6 +1020,10 @@ public final class PostboxDecoder {
|
|||
public func decodeRootObject() -> PostboxCoding? {
|
||||
return self.decodeObjectForKey("_")
|
||||
}
|
||||
|
||||
public func decodeRootObjectWithHash(hash: Int32) -> PostboxCoding? {
|
||||
return typeStore.decode(hash, decoder: self)
|
||||
}
|
||||
|
||||
public func decodeCodable<T: Codable>(_ type: T.Type, forKey key: String) -> T? {
|
||||
if let data = self.decodeDataForKey(key) {
|
||||
|
|
@ -1651,6 +1664,43 @@ public final class PostboxDecoder {
|
|||
return [:]
|
||||
}
|
||||
}
|
||||
|
||||
public func decodeObjectDataDictRaw() -> [(Data, Data)] {
|
||||
var dict: [(Data, Data)] = []
|
||||
|
||||
var length: Int32 = 0
|
||||
memcpy(&length, self.buffer.memory + self.offset, 4)
|
||||
self.offset += 4
|
||||
|
||||
var i: Int32 = 0
|
||||
while i < length {
|
||||
var keyHash: Int32 = 0
|
||||
memcpy(&keyHash, self.buffer.memory + self.offset, 4)
|
||||
self.offset += 4
|
||||
|
||||
var keyLength: Int32 = 0
|
||||
memcpy(&keyLength, self.buffer.memory + self.offset, 4)
|
||||
|
||||
let keyData = ReadBuffer(memory: self.buffer.memory + (self.offset + 4), length: Int(keyLength), freeWhenDone: false).makeData()
|
||||
self.offset += 4 + Int(keyLength)
|
||||
|
||||
var valueHash: Int32 = 0
|
||||
memcpy(&valueHash, self.buffer.memory + self.offset, 4)
|
||||
self.offset += 4
|
||||
|
||||
var valueLength: Int32 = 0
|
||||
memcpy(&valueLength, self.buffer.memory + self.offset, 4)
|
||||
|
||||
let objectData = ReadBuffer(memory: self.buffer.memory + (self.offset + 4), length: Int(valueLength), freeWhenDone: false).makeData()
|
||||
self.offset += 4 + Int(valueLength)
|
||||
|
||||
dict.append((keyData, objectData))
|
||||
|
||||
i += 1
|
||||
}
|
||||
|
||||
return dict
|
||||
}
|
||||
|
||||
public func decodeBytesForKeyNoCopy(_ key: String) -> ReadBuffer? {
|
||||
if PostboxDecoder.positionOnKey(self.buffer.memory, offset: &self.offset, maxOffset: self.buffer.length, length: self.buffer.length, key: key, valueType: .Bytes) {
|
||||
|
|
@ -1728,7 +1778,13 @@ public final class PostboxDecoder {
|
|||
let innerData = innerBuffer.makeData()
|
||||
self.offset += 4 + Int(length)
|
||||
|
||||
return try? AdaptedPostboxDecoder().decode(T.self, from: innerData)
|
||||
do {
|
||||
let result = try AdaptedPostboxDecoder().decode(T.self, from: innerData)
|
||||
return result
|
||||
} catch let error {
|
||||
assertionFailure("Decoding error: \(error)")
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import Foundation
|
||||
|
||||
public final class PreferencesEntry: Equatable {
|
||||
public final class CodableEntry: Equatable {
|
||||
public let data: Data
|
||||
|
||||
public init(data: Data) {
|
||||
|
|
@ -18,6 +18,34 @@ public final class PreferencesEntry: Equatable {
|
|||
return decoder.decode(T.self, forKey: "_")
|
||||
}
|
||||
|
||||
public static func ==(lhs: CodableEntry, rhs: CodableEntry) -> Bool {
|
||||
return lhs.data == rhs.data
|
||||
}
|
||||
}
|
||||
|
||||
public final class PreferencesEntry: Equatable {
|
||||
public let data: Data
|
||||
|
||||
public init(data: Data) {
|
||||
self.data = data
|
||||
}
|
||||
|
||||
public init?<T: Encodable>(_ value: T?) {
|
||||
guard let value = value else {
|
||||
return nil
|
||||
}
|
||||
let encoder = PostboxEncoder()
|
||||
encoder.encode(value, forKey: "_")
|
||||
self.data = encoder.makeData()
|
||||
}
|
||||
|
||||
public func get<T: Decodable>(_ type: T.Type) -> T? {
|
||||
let decoder = PostboxDecoder(buffer: MemoryBuffer(data: self.data))
|
||||
let result = decoder.decode(T.self, forKey: "_")
|
||||
assert(result != nil)
|
||||
return result
|
||||
}
|
||||
|
||||
public static func ==(lhs: PreferencesEntry, rhs: PreferencesEntry) -> Bool {
|
||||
return lhs.data == rhs.data
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,27 @@ public final class SeedConfiguration {
|
|||
public let getGlobalNotificationSettings: (Transaction) -> PostboxGlobalNotificationSettings?
|
||||
public let defaultGlobalNotificationSettings: PostboxGlobalNotificationSettings
|
||||
|
||||
public init(globalMessageIdsPeerIdNamespaces: Set<GlobalMessageIdsNamespace>, initializeChatListWithHole: (topLevel: ChatListHole?, groups: ChatListHole?), messageHoles: [PeerId.Namespace: [MessageId.Namespace: Set<MessageTags>]], upgradedMessageHoles: [PeerId.Namespace: [MessageId.Namespace: Set<MessageTags>]], messageThreadHoles: [PeerId.Namespace: [MessageId.Namespace]], existingMessageTags: MessageTags, messageTagsWithSummary: MessageTags, existingGlobalMessageTags: GlobalMessageTags, peerNamespacesRequiringMessageTextIndex: [PeerId.Namespace], peerSummaryCounterTags: @escaping (Peer, Bool) -> PeerSummaryCounterTags, additionalChatListIndexNamespace: MessageId.Namespace?, messageNamespacesRequiringGroupStatsValidation: Set<MessageId.Namespace>, defaultMessageNamespaceReadStates: [MessageId.Namespace: PeerReadState], chatMessagesNamespaces: Set<MessageId.Namespace>, getGlobalNotificationSettings: @escaping (Transaction) -> PostboxGlobalNotificationSettings?, defaultGlobalNotificationSettings: PostboxGlobalNotificationSettings) {
|
||||
public init(
|
||||
globalMessageIdsPeerIdNamespaces: Set<GlobalMessageIdsNamespace>,
|
||||
initializeChatListWithHole: (
|
||||
topLevel: ChatListHole?,
|
||||
groups: ChatListHole?
|
||||
),
|
||||
messageHoles: [PeerId.Namespace: [MessageId.Namespace: Set<MessageTags>]],
|
||||
upgradedMessageHoles: [PeerId.Namespace: [MessageId.Namespace: Set<MessageTags>]],
|
||||
messageThreadHoles: [PeerId.Namespace: [MessageId.Namespace]],
|
||||
existingMessageTags: MessageTags,
|
||||
messageTagsWithSummary: MessageTags,
|
||||
existingGlobalMessageTags: GlobalMessageTags,
|
||||
peerNamespacesRequiringMessageTextIndex: [PeerId.Namespace],
|
||||
peerSummaryCounterTags: @escaping (Peer, Bool) -> PeerSummaryCounterTags,
|
||||
additionalChatListIndexNamespace: MessageId.Namespace?,
|
||||
messageNamespacesRequiringGroupStatsValidation: Set<MessageId.Namespace>,
|
||||
defaultMessageNamespaceReadStates: [MessageId.Namespace: PeerReadState],
|
||||
chatMessagesNamespaces: Set<MessageId.Namespace>,
|
||||
getGlobalNotificationSettings: @escaping (Transaction) -> PostboxGlobalNotificationSettings?,
|
||||
defaultGlobalNotificationSettings: PostboxGlobalNotificationSettings
|
||||
) {
|
||||
self.globalMessageIdsPeerIdNamespaces = globalMessageIdsPeerIdNamespaces
|
||||
self.initializeChatListWithHole = initializeChatListWithHole
|
||||
self.messageHoles = messageHoles
|
||||
|
|
|
|||
|
|
@ -8,9 +8,10 @@ final public class AdaptedPostboxDecoder {
|
|||
case objectArray
|
||||
case stringArray
|
||||
case dataArray
|
||||
case objectDict
|
||||
}
|
||||
|
||||
public final class RawObjectData: Codable {
|
||||
public final class RawObjectData: Decodable {
|
||||
public let data: Data
|
||||
public let typeHash: Int32
|
||||
|
||||
|
|
@ -55,7 +56,7 @@ extension AdaptedPostboxDecoder.ContentType {
|
|||
case .ObjectArray:
|
||||
self = .objectArray
|
||||
case .ObjectDictionary:
|
||||
return nil
|
||||
self = .objectDict
|
||||
case .Bytes:
|
||||
return nil
|
||||
case .Nil:
|
||||
|
|
@ -117,6 +118,8 @@ extension _AdaptedPostboxDecoder: Decoder {
|
|||
content = .stringArray(decoder.decodeStringArrayRaw())
|
||||
case .dataArray:
|
||||
content = .dataArray(decoder.decodeBytesArrayRaw().map { $0.makeData() })
|
||||
case .objectDict:
|
||||
content = .objectDict(decoder.decodeObjectDataDictRaw())
|
||||
}
|
||||
|
||||
if let content = content {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ extension _AdaptedPostboxDecoder {
|
|||
case objectArray([Data])
|
||||
case stringArray([String])
|
||||
case dataArray([Data])
|
||||
case objectDict([(Data, Data)])
|
||||
|
||||
var count: Int {
|
||||
switch self {
|
||||
|
|
@ -21,6 +22,8 @@ extension _AdaptedPostboxDecoder {
|
|||
return array.count
|
||||
case let .dataArray(array):
|
||||
return array.count
|
||||
case let .objectDict(dict):
|
||||
return dict.count * 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -64,6 +67,7 @@ extension _AdaptedPostboxDecoder.UnkeyedContainer: UnkeyedDecodingContainer {
|
|||
self._currentIndex += 1
|
||||
return array[index] as! T
|
||||
default:
|
||||
assertionFailure()
|
||||
throw DecodingError.typeMismatch(Data.self, DecodingError.Context(codingPath: self.codingPath, debugDescription: ""))
|
||||
}
|
||||
} else {
|
||||
|
|
@ -74,7 +78,35 @@ extension _AdaptedPostboxDecoder.UnkeyedContainer: UnkeyedDecodingContainer {
|
|||
|
||||
let data = array[index]
|
||||
return try AdaptedPostboxDecoder().decode(T.self, from: data)
|
||||
case let .objectDict(dict):
|
||||
let index = self._currentIndex
|
||||
self._currentIndex += 1
|
||||
|
||||
let dataPair = dict[index / 2]
|
||||
let data: Data
|
||||
if index % 2 == 0 {
|
||||
data = dataPair.0
|
||||
} else {
|
||||
data = dataPair.1
|
||||
}
|
||||
return try AdaptedPostboxDecoder().decode(T.self, from: data)
|
||||
case let .int32Array(array):
|
||||
let index = self._currentIndex
|
||||
self._currentIndex += 1
|
||||
|
||||
return array[index] as! T
|
||||
case let .int64Array(array):
|
||||
let index = self._currentIndex
|
||||
self._currentIndex += 1
|
||||
|
||||
return array[index] as! T
|
||||
case let .stringArray(array):
|
||||
let index = self._currentIndex
|
||||
self._currentIndex += 1
|
||||
|
||||
return array[index] as! T
|
||||
default:
|
||||
assertionFailure()
|
||||
throw DecodingError.typeMismatch(T.self, DecodingError.Context(codingPath: self.codingPath, debugDescription: ""))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,16 @@ import Foundation
|
|||
import MurMurHash32
|
||||
|
||||
public class AdaptedPostboxEncoder {
|
||||
public final class RawObjectData: Encodable {
|
||||
public let typeHash: Int32
|
||||
public let data: Data
|
||||
|
||||
public init(typeHash: Int32, data: Data) {
|
||||
self.typeHash = typeHash
|
||||
self.data = data
|
||||
}
|
||||
}
|
||||
|
||||
public init() {
|
||||
}
|
||||
|
||||
|
|
@ -10,7 +20,7 @@ public class AdaptedPostboxEncoder {
|
|||
|
||||
let encoder = _AdaptedPostboxEncoder(typeHash: typeHash)
|
||||
try value.encode(to: encoder)
|
||||
return encoder.makeData(addHeader: false).0
|
||||
return encoder.makeData(addHeader: false, isDictionary: false).0
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -27,8 +37,8 @@ final class _AdaptedPostboxEncoder {
|
|||
self.typeHash = typeHash
|
||||
}
|
||||
|
||||
func makeData(addHeader: Bool) -> (Data, ValueType) {
|
||||
return self.container!.makeData(addHeader: addHeader)
|
||||
func makeData(addHeader: Bool, isDictionary: Bool) -> (Data, ValueType) {
|
||||
return self.container!.makeData(addHeader: addHeader, isDictionary: isDictionary)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -61,5 +71,5 @@ extension _AdaptedPostboxEncoder: Encoder {
|
|||
}
|
||||
|
||||
protocol AdaptedPostboxEncodingContainer: AnyObject {
|
||||
func makeData(addHeader: Bool) -> (Data, ValueType)
|
||||
func makeData(addHeader: Bool, isDictionary: Bool) -> (Data, ValueType)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ extension _AdaptedPostboxEncoder {
|
|||
self.encoder = PostboxEncoder()
|
||||
}
|
||||
|
||||
func makeData(addHeader: Bool) -> (Data, ValueType) {
|
||||
func makeData(addHeader: Bool, isDictionary: Bool) -> (Data, ValueType) {
|
||||
let buffer = WriteBuffer()
|
||||
|
||||
if addHeader {
|
||||
|
|
@ -43,12 +43,27 @@ extension _AdaptedPostboxEncoder.KeyedContainer: KeyedEncodingContainerProtocol
|
|||
func encode<T>(_ value: T, forKey key: Key) throws where T : Encodable {
|
||||
if let value = value as? Data {
|
||||
self.encoder.encodeData(value, forKey: key.stringValue)
|
||||
} else if let value = value as? AdaptedPostboxEncoder.RawObjectData {
|
||||
let typeHash: Int32 = value.typeHash
|
||||
let innerEncoder = _AdaptedPostboxEncoder(typeHash: typeHash)
|
||||
try! value.encode(to: innerEncoder)
|
||||
|
||||
let (data, valueType) = innerEncoder.makeData(addHeader: true, isDictionary: false)
|
||||
self.encoder.encodeInnerObjectData(data, valueType: valueType, forKey: key.stringValue)
|
||||
} else {
|
||||
let typeHash: Int32 = murMurHashString32("\(type(of: value))")
|
||||
let innerEncoder = _AdaptedPostboxEncoder(typeHash: typeHash)
|
||||
try! value.encode(to: innerEncoder)
|
||||
|
||||
let (data, valueType) = innerEncoder.makeData(addHeader: true)
|
||||
let type = type(of: value)
|
||||
let typeString = "\(type)"
|
||||
var isDictionary = false
|
||||
if typeString.hasPrefix("Dictionary<") {
|
||||
isDictionary = true
|
||||
}
|
||||
|
||||
let (data, valueType) = innerEncoder.makeData(addHeader: true, isDictionary: isDictionary)
|
||||
|
||||
self.encoder.encodeInnerObjectData(data, valueType: valueType, forKey: key.stringValue)
|
||||
}
|
||||
}
|
||||
|
|
@ -65,6 +80,12 @@ extension _AdaptedPostboxEncoder.KeyedContainer: KeyedEncodingContainerProtocol
|
|||
self.encoder.encodeInt64(value, forKey: key.stringValue)
|
||||
}
|
||||
|
||||
func encode(_ value: Int, forKey key: Key) throws {
|
||||
assertionFailure()
|
||||
|
||||
self.encoder.encodeInt32(Int32(value), forKey: key.stringValue)
|
||||
}
|
||||
|
||||
func encode(_ value: Bool, forKey key: Key) throws {
|
||||
self.encoder.encodeBool(value, forKey: key.stringValue)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ extension _AdaptedPostboxEncoder.SingleValueContainer: SingleValueEncodingContai
|
|||
}
|
||||
|
||||
extension _AdaptedPostboxEncoder.SingleValueContainer: AdaptedPostboxEncodingContainer {
|
||||
func makeData(addHeader: Bool) -> (Data, ValueType) {
|
||||
func makeData(addHeader: Bool, isDictionary: Bool) -> (Data, ValueType) {
|
||||
preconditionFailure()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ extension _AdaptedPostboxEncoder {
|
|||
self.userInfo = userInfo
|
||||
}
|
||||
|
||||
func makeData(addHeader: Bool) -> (Data, ValueType) {
|
||||
func makeData(addHeader: Bool, isDictionary: Bool) -> (Data, ValueType) {
|
||||
precondition(addHeader)
|
||||
|
||||
if self.items.isEmpty {
|
||||
|
|
@ -53,7 +53,7 @@ extension _AdaptedPostboxEncoder {
|
|||
buffer.write(&length, offset: 0, length: 4)
|
||||
|
||||
for case .int64(var value) in self.items {
|
||||
buffer.write(&value, offset: 0, length: 4)
|
||||
buffer.write(&value, offset: 0, length: 8)
|
||||
}
|
||||
|
||||
return (buffer.makeData(), .Int64Array)
|
||||
|
|
@ -75,13 +75,17 @@ extension _AdaptedPostboxEncoder {
|
|||
let buffer = WriteBuffer()
|
||||
|
||||
var length: Int32 = Int32(self.items.count)
|
||||
if isDictionary {
|
||||
precondition(length % 2 == 0)
|
||||
length /= 2
|
||||
}
|
||||
buffer.write(&length, offset: 0, length: 4)
|
||||
|
||||
for case .object(let data) in self.items {
|
||||
buffer.write(data)
|
||||
}
|
||||
|
||||
return (buffer.makeData(), .ObjectArray)
|
||||
return (buffer.makeData(), isDictionary ? .ObjectDictionary : .ObjectArray)
|
||||
} else if self.items.allSatisfy({ if case .data = $0 { return true } else { return false } }) {
|
||||
let buffer = WriteBuffer()
|
||||
|
||||
|
|
@ -108,18 +112,28 @@ extension _AdaptedPostboxEncoder.UnkeyedContainer: UnkeyedEncodingContainer {
|
|||
}
|
||||
|
||||
func encode<T>(_ value: T) throws where T : Encodable {
|
||||
let typeHash: Int32 = murMurHashString32("\(type(of: value))")
|
||||
if value is Int32 {
|
||||
try self.encode(value as! Int32)
|
||||
} else if value is Int64 {
|
||||
try self.encode(value as! Int64)
|
||||
} else if value is String {
|
||||
try self.encode(value as! String)
|
||||
} else if value is Data {
|
||||
try self.encode(value as! Data)
|
||||
} else {
|
||||
let typeHash: Int32 = murMurHashString32("\(type(of: value))")
|
||||
|
||||
let innerEncoder = _AdaptedPostboxEncoder(typeHash: typeHash)
|
||||
try! value.encode(to: innerEncoder)
|
||||
let innerEncoder = _AdaptedPostboxEncoder(typeHash: typeHash)
|
||||
try! value.encode(to: innerEncoder)
|
||||
|
||||
let (data, _) = innerEncoder.makeData(addHeader: true)
|
||||
let (data, _) = innerEncoder.makeData(addHeader: true, isDictionary: false)
|
||||
|
||||
let buffer = WriteBuffer()
|
||||
let buffer = WriteBuffer()
|
||||
|
||||
buffer.write(data)
|
||||
buffer.write(data)
|
||||
|
||||
self.items.append(.object(buffer.makeData()))
|
||||
self.items.append(.object(buffer.makeData()))
|
||||
}
|
||||
}
|
||||
|
||||
func encode(_ value: Int32) throws {
|
||||
|
|
|
|||
|
|
@ -321,14 +321,14 @@ func autodownloadMediaConnectionTypeController(context: AccountContext, connecti
|
|||
|> deliverOnMainQueue
|
||||
|> map { presentationData, sharedData -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
var automaticMediaDownloadSettings: MediaAutoDownloadSettings
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.automaticMediaDownloadSettings] as? MediaAutoDownloadSettings {
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.automaticMediaDownloadSettings]?.get(MediaAutoDownloadSettings.self) {
|
||||
automaticMediaDownloadSettings = value
|
||||
} else {
|
||||
automaticMediaDownloadSettings = MediaAutoDownloadSettings.defaultSettings
|
||||
}
|
||||
|
||||
var autodownloadSettings: AutodownloadSettings
|
||||
if let value = sharedData.entries[SharedDataKeys.autodownloadSettings] as? AutodownloadSettings {
|
||||
if let value = sharedData.entries[SharedDataKeys.autodownloadSettings]?.get(AutodownloadSettings.self) {
|
||||
autodownloadSettings = value
|
||||
automaticMediaDownloadSettings = automaticMediaDownloadSettings.updatedWithAutodownloadSettings(autodownloadSettings)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -388,7 +388,7 @@ func autodownloadMediaCategoryController(context: AccountContext, connectionType
|
|||
return context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.automaticMediaDownloadSettings])
|
||||
|> take(1)
|
||||
|> map { sharedData -> MediaAutoDownloadSettings in
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.automaticMediaDownloadSettings] as? MediaAutoDownloadSettings {
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.automaticMediaDownloadSettings]?.get(MediaAutoDownloadSettings.self) {
|
||||
return value
|
||||
} else {
|
||||
return .defaultSettings
|
||||
|
|
@ -402,14 +402,14 @@ func autodownloadMediaCategoryController(context: AccountContext, connectionType
|
|||
let signal = combineLatest(context.sharedContext.presentationData, context.sharedContext.accountManager.sharedData(keys: [SharedDataKeys.autodownloadSettings, ApplicationSpecificSharedDataKeys.automaticMediaDownloadSettings])) |> deliverOnMainQueue
|
||||
|> map { presentationData, sharedData -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
var automaticMediaDownloadSettings: MediaAutoDownloadSettings
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.automaticMediaDownloadSettings] as? MediaAutoDownloadSettings {
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.automaticMediaDownloadSettings]?.get(MediaAutoDownloadSettings.self) {
|
||||
automaticMediaDownloadSettings = value
|
||||
} else {
|
||||
automaticMediaDownloadSettings = .defaultSettings
|
||||
}
|
||||
|
||||
var autodownloadSettings: AutodownloadSettings
|
||||
if let value = sharedData.entries[SharedDataKeys.autodownloadSettings] as? AutodownloadSettings {
|
||||
if let value = sharedData.entries[SharedDataKeys.autodownloadSettings]?.get(AutodownloadSettings.self) {
|
||||
autodownloadSettings = value
|
||||
automaticMediaDownloadSettings = automaticMediaDownloadSettings.updatedWithAutodownloadSettings(autodownloadSettings)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -561,14 +561,14 @@ public func dataAndStorageController(context: AccountContext, focusOnItemTag: Da
|
|||
dataAndStorageDataPromise.set(context.sharedContext.accountManager.sharedData(keys: [SharedDataKeys.autodownloadSettings, ApplicationSpecificSharedDataKeys.automaticMediaDownloadSettings, ApplicationSpecificSharedDataKeys.generatedMediaStoreSettings, ApplicationSpecificSharedDataKeys.voiceCallSettings, SharedDataKeys.proxySettings])
|
||||
|> map { sharedData -> DataAndStorageData in
|
||||
var automaticMediaDownloadSettings: MediaAutoDownloadSettings
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.automaticMediaDownloadSettings] as? MediaAutoDownloadSettings {
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.automaticMediaDownloadSettings]?.get(MediaAutoDownloadSettings.self) {
|
||||
automaticMediaDownloadSettings = value
|
||||
} else {
|
||||
automaticMediaDownloadSettings = .defaultSettings
|
||||
}
|
||||
|
||||
var autodownloadSettings: AutodownloadSettings
|
||||
if let value = sharedData.entries[SharedDataKeys.autodownloadSettings] as? AutodownloadSettings {
|
||||
if let value = sharedData.entries[SharedDataKeys.autodownloadSettings]?.get(AutodownloadSettings.self) {
|
||||
autodownloadSettings = value
|
||||
automaticMediaDownloadSettings = automaticMediaDownloadSettings.updatedWithAutodownloadSettings(autodownloadSettings)
|
||||
} else {
|
||||
|
|
@ -576,21 +576,21 @@ public func dataAndStorageController(context: AccountContext, focusOnItemTag: Da
|
|||
}
|
||||
|
||||
let generatedMediaStoreSettings: GeneratedMediaStoreSettings
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.generatedMediaStoreSettings] as? GeneratedMediaStoreSettings {
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.generatedMediaStoreSettings]?.get(GeneratedMediaStoreSettings.self) {
|
||||
generatedMediaStoreSettings = value
|
||||
} else {
|
||||
generatedMediaStoreSettings = GeneratedMediaStoreSettings.defaultSettings
|
||||
}
|
||||
|
||||
let voiceCallSettings: VoiceCallSettings
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.voiceCallSettings] as? VoiceCallSettings {
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.voiceCallSettings]?.get(VoiceCallSettings.self) {
|
||||
voiceCallSettings = value
|
||||
} else {
|
||||
voiceCallSettings = VoiceCallSettings.defaultSettings
|
||||
}
|
||||
|
||||
var proxySettings: ProxySettings?
|
||||
if let value = sharedData.entries[SharedDataKeys.proxySettings] as? ProxySettings {
|
||||
if let value = sharedData.entries[SharedDataKeys.proxySettings]?.get(ProxySettings.self) {
|
||||
proxySettings = value
|
||||
}
|
||||
|
||||
|
|
@ -682,7 +682,7 @@ public func dataAndStorageController(context: AccountContext, focusOnItemTag: Da
|
|||
contentSettingsConfiguration.get()
|
||||
)
|
||||
|> map { presentationData, state, dataAndStorageData, sharedData, contentSettingsConfiguration -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
let webBrowserSettings = (sharedData.entries[ApplicationSpecificSharedDataKeys.webBrowserSettings] as? WebBrowserSettings) ?? WebBrowserSettings.defaultSettings
|
||||
let webBrowserSettings = sharedData.entries[ApplicationSpecificSharedDataKeys.webBrowserSettings]?.get(WebBrowserSettings.self) ?? WebBrowserSettings.defaultSettings
|
||||
let options = availableOpenInOptions(context: context, item: .url(url: "https://telegram.org"))
|
||||
let defaultWebBrowser: String
|
||||
if let option = options.first(where: { $0.identifier == webBrowserSettings.defaultWebBrowser }) {
|
||||
|
|
|
|||
|
|
@ -305,7 +305,7 @@ public func intentsSettingsController(context: AccountContext) -> ViewController
|
|||
let signal = combineLatest(context.sharedContext.presentationData, context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.intentsSettings]), activeAccountsAndPeers(context: context, includePrimary: true))
|
||||
|> deliverOnMainQueue
|
||||
|> map { presentationData, sharedData, accounts -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
let settings = (sharedData.entries[ApplicationSpecificSharedDataKeys.intentsSettings] as? IntentsSettings) ?? IntentsSettings.defaultSettings
|
||||
let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.intentsSettings]?.get(IntentsSettings.self) ?? IntentsSettings.defaultSettings
|
||||
|
||||
let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(presentationData.strings.IntentsSettings_Title), leftNavigationButton: nil, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back))
|
||||
let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: intentsSettingsControllerEntries(context: context, presentationData: presentationData, settings: settings, accounts: accounts.1.map { ($0.0.account, $0.1) }), style: .blocks, animateChanges: false)
|
||||
|
|
|
|||
|
|
@ -388,7 +388,7 @@ public func proxySettingsController(accountManager: AccountManager<TelegramAccou
|
|||
let proxySettings = Promise<ProxySettings>()
|
||||
proxySettings.set(accountManager.sharedData(keys: [SharedDataKeys.proxySettings])
|
||||
|> map { sharedData -> ProxySettings in
|
||||
if let value = sharedData.entries[SharedDataKeys.proxySettings] as? ProxySettings {
|
||||
if let value = sharedData.entries[SharedDataKeys.proxySettings]?.get(ProxySettings.self) {
|
||||
return value
|
||||
} else {
|
||||
return ProxySettings.defaultSettings
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ func saveIncomingMediaController(context: AccountContext) -> ViewController {
|
|||
|> deliverOnMainQueue
|
||||
|> map { presentationData, sharedData -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
let automaticMediaDownloadSettings: MediaAutoDownloadSettings
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.automaticMediaDownloadSettings] as? MediaAutoDownloadSettings {
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.automaticMediaDownloadSettings]?.get(MediaAutoDownloadSettings.self) {
|
||||
automaticMediaDownloadSettings = value
|
||||
} else {
|
||||
automaticMediaDownloadSettings = MediaAutoDownloadSettings.defaultSettings
|
||||
|
|
|
|||
|
|
@ -408,7 +408,7 @@ public func storageUsageController(context: AccountContext, cacheUsagePromise: P
|
|||
cacheSettingsPromise.set(context.sharedContext.accountManager.sharedData(keys: [SharedDataKeys.cacheStorageSettings])
|
||||
|> map { sharedData -> CacheStorageSettings in
|
||||
let cacheSettings: CacheStorageSettings
|
||||
if let value = sharedData.entries[SharedDataKeys.cacheStorageSettings] as? CacheStorageSettings {
|
||||
if let value = sharedData.entries[SharedDataKeys.cacheStorageSettings]?.get(CacheStorageSettings.self) {
|
||||
cacheSettings = value
|
||||
} else {
|
||||
cacheSettings = CacheStorageSettings.defaultSettings
|
||||
|
|
|
|||
|
|
@ -125,14 +125,14 @@ func voiceCallDataSavingController(context: AccountContext) -> ViewController {
|
|||
let sharedSettings = context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.voiceCallSettings])
|
||||
|> map { sharedData -> (VoiceCallSettings, AutodownloadSettings) in
|
||||
let voiceCallSettings: VoiceCallSettings
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.voiceCallSettings] as? VoiceCallSettings {
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.voiceCallSettings]?.get(VoiceCallSettings.self) {
|
||||
voiceCallSettings = value
|
||||
} else {
|
||||
voiceCallSettings = VoiceCallSettings.defaultSettings
|
||||
}
|
||||
|
||||
let autodownloadSettings: AutodownloadSettings
|
||||
if let value = sharedData.entries[SharedDataKeys.autodownloadSettings] as? AutodownloadSettings {
|
||||
if let value = sharedData.entries[SharedDataKeys.autodownloadSettings]?.get(AutodownloadSettings.self) {
|
||||
autodownloadSettings = value
|
||||
} else {
|
||||
autodownloadSettings = AutodownloadSettings.defaultSettings
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ public func webBrowserSettingsController(context: AccountContext) -> ViewControl
|
|||
let signal = combineLatest(context.sharedContext.presentationData, context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.webBrowserSettings]))
|
||||
|> deliverOnMainQueue
|
||||
|> map { presentationData, sharedData -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
let settings = (sharedData.entries[ApplicationSpecificSharedDataKeys.webBrowserSettings] as? WebBrowserSettings) ?? WebBrowserSettings.defaultSettings
|
||||
let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.webBrowserSettings]?.get(WebBrowserSettings.self) ?? WebBrowserSettings.defaultSettings
|
||||
|
||||
let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(presentationData.strings.WebBrowser_Title), leftNavigationButton: nil, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back))
|
||||
let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: webBrowserSettingsControllerEntries(context: context, presentationData: presentationData, selectedBrowser: settings.defaultWebBrowser), style: .blocks, animateChanges: false)
|
||||
|
|
|
|||
|
|
@ -338,9 +338,9 @@ final class LocalizationListControllerNode: ViewControllerTracingNode {
|
|||
let removeItem: (String) -> Void = { id in
|
||||
let _ = (context.account.postbox.transaction { transaction -> Signal<LocalizationInfo?, NoError> in
|
||||
removeSavedLocalization(transaction: transaction, languageCode: id)
|
||||
let state = transaction.getPreferencesEntry(key: PreferencesKeys.localizationListState) as? LocalizationListState
|
||||
let state = transaction.getPreferencesEntry(key: PreferencesKeys.localizationListState)?.get(LocalizationListState.self)
|
||||
return context.sharedContext.accountManager.transaction { transaction -> LocalizationInfo? in
|
||||
if let settings = transaction.getSharedData(SharedDataKeys.localizationSettings) as? LocalizationSettings, let state = state {
|
||||
if let settings = transaction.getSharedData(SharedDataKeys.localizationSettings)?.get(LocalizationSettings.self), let state = state {
|
||||
if settings.primaryComponent.languageCode == id {
|
||||
for item in state.availableOfficialLocalizations {
|
||||
if item.languageCode == "en" {
|
||||
|
|
@ -374,12 +374,12 @@ final class LocalizationListControllerNode: ViewControllerTracingNode {
|
|||
|
||||
var entries: [LanguageListEntry] = []
|
||||
var activeLanguageCode: String?
|
||||
if let localizationSettings = sharedData.entries[SharedDataKeys.localizationSettings] as? LocalizationSettings {
|
||||
if let localizationSettings = sharedData.entries[SharedDataKeys.localizationSettings]?.get(LocalizationSettings.self) {
|
||||
activeLanguageCode = localizationSettings.primaryComponent.languageCode
|
||||
}
|
||||
var existingIds = Set<String>()
|
||||
|
||||
let localizationListState = (view.views[preferencesKey] as? PreferencesView)?.values[PreferencesKeys.localizationListState] as? LocalizationListState
|
||||
let localizationListState = (view.views[preferencesKey] as? PreferencesView)?.values[PreferencesKeys.localizationListState]?.get(LocalizationListState.self)
|
||||
if let localizationListState = localizationListState, !localizationListState.availableOfficialLocalizations.isEmpty {
|
||||
strongSelf.currentListState = localizationListState
|
||||
|
||||
|
|
|
|||
|
|
@ -351,7 +351,7 @@ public func notificationPeerExceptionController(context: AccountContext, peer: P
|
|||
|
||||
statePromise.set(context.account.postbox.transaction { transaction -> NotificationExceptionPeerState in
|
||||
var state = NotificationExceptionPeerState(canRemove: mode.peerIds.contains(peer.id), notifications: transaction.getPeerNotificationSettings(peer.id) as? TelegramPeerNotificationSettings)
|
||||
let globalSettings: GlobalNotificationSettings = (transaction.getPreferencesEntry(key: PreferencesKeys.globalNotifications) as? GlobalNotificationSettings) ?? GlobalNotificationSettings.defaultSettings
|
||||
let globalSettings: GlobalNotificationSettings = transaction.getPreferencesEntry(key: PreferencesKeys.globalNotifications)?.get(GlobalNotificationSettings.self) ?? GlobalNotificationSettings.defaultSettings
|
||||
switch mode {
|
||||
case .channels:
|
||||
state = state.withUpdatedDefaultSound(globalSettings.effective.channels.sound)
|
||||
|
|
|
|||
|
|
@ -1077,14 +1077,14 @@ public func notificationsAndSoundsController(context: AccountContext, exceptions
|
|||
|> map { presentationData, sharedData, view, exceptions, authorizationStatus, warningSuppressed, hasMoreThanOneAccount -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
|
||||
let viewSettings: GlobalNotificationSettingsSet
|
||||
if let settings = view.values[PreferencesKeys.globalNotifications] as? GlobalNotificationSettings {
|
||||
if let settings = view.values[PreferencesKeys.globalNotifications]?.get(GlobalNotificationSettings.self) {
|
||||
viewSettings = settings.effective
|
||||
} else {
|
||||
viewSettings = GlobalNotificationSettingsSet.defaultSettings
|
||||
}
|
||||
|
||||
let inAppSettings: InAppNotificationSettings
|
||||
if let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.inAppNotificationSettings] as? InAppNotificationSettings {
|
||||
if let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.inAppNotificationSettings]?.get(InAppNotificationSettings.self) {
|
||||
inAppSettings = settings
|
||||
} else {
|
||||
inAppSettings = InAppNotificationSettings.defaultSettings
|
||||
|
|
|
|||
|
|
@ -419,9 +419,9 @@ public func dataPrivacyController(context: AccountContext) -> ViewController {
|
|||
|
||||
let _ = context.account.postbox.transaction({ transaction in
|
||||
transaction.updatePreferencesEntry(key: PreferencesKeys.contactsSettings, { current in
|
||||
var settings = current as? ContactsSettings ?? ContactsSettings.defaultSettings
|
||||
var settings = current?.get(ContactsSettings.self) ?? ContactsSettings.defaultSettings
|
||||
settings.synchronizeContacts = false
|
||||
return settings
|
||||
return PreferencesEntry(settings)
|
||||
})
|
||||
}).start()
|
||||
|
||||
|
|
@ -440,9 +440,9 @@ public func dataPrivacyController(context: AccountContext) -> ViewController {
|
|||
}, updateSyncContacts: { value in
|
||||
let _ = context.account.postbox.transaction({ transaction in
|
||||
transaction.updatePreferencesEntry(key: PreferencesKeys.contactsSettings, { current in
|
||||
var settings = current as? ContactsSettings ?? ContactsSettings.defaultSettings
|
||||
var settings = current?.get(ContactsSettings.self) ?? ContactsSettings.defaultSettings
|
||||
settings.synchronizeContacts = value
|
||||
return settings
|
||||
return PreferencesEntry(settings)
|
||||
})
|
||||
}).start()
|
||||
}, updateSuggestFrequentContacts: { value in
|
||||
|
|
@ -506,7 +506,7 @@ public func dataPrivacyController(context: AccountContext) -> ViewController {
|
|||
|> map { presentationData, state, noticeView, sharedData, preferences, recentPeers -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
let secretChatLinkPreviews = noticeView.value.flatMap({ ApplicationSpecificNotice.getSecretChatLinkPreviews($0) })
|
||||
|
||||
let settings: ContactsSettings = preferences.values[PreferencesKeys.contactsSettings] as? ContactsSettings ?? ContactsSettings.defaultSettings
|
||||
let settings: ContactsSettings = preferences.values[PreferencesKeys.contactsSettings]?.get(ContactsSettings.self) ?? ContactsSettings.defaultSettings
|
||||
|
||||
let synchronizeDeviceContacts: Bool = settings.synchronizeContacts
|
||||
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@ func passcodeOptionsController(context: AccountContext) -> ViewController {
|
|||
|
||||
let passcodeOptionsDataPromise = Promise<PasscodeOptionsData>()
|
||||
passcodeOptionsDataPromise.set(context.sharedContext.accountManager.transaction { transaction -> (PostboxAccessChallengeData, PresentationPasscodeSettings) in
|
||||
let passcodeSettings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.presentationPasscodeSettings) as? PresentationPasscodeSettings ?? PresentationPasscodeSettings.defaultSettings
|
||||
let passcodeSettings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.presentationPasscodeSettings)?.get(PresentationPasscodeSettings.self) ?? PresentationPasscodeSettings.defaultSettings
|
||||
return (transaction.getAccessChallengeData(), passcodeSettings)
|
||||
}
|
||||
|> map { accessChallenge, passcodeSettings -> PasscodeOptionsData in
|
||||
|
|
@ -444,7 +444,7 @@ public func passcodeEntryController(context: AccountContext, animateIn: Bool = t
|
|||
}
|
||||
|> mapToSignal { accessChallengeData -> Signal<(PostboxAccessChallengeData, PresentationPasscodeSettings?), NoError> in
|
||||
return context.sharedContext.accountManager.transaction { transaction -> (PostboxAccessChallengeData, PresentationPasscodeSettings?) in
|
||||
let passcodeSettings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.presentationPasscodeSettings) as? PresentationPasscodeSettings
|
||||
let passcodeSettings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.presentationPasscodeSettings)?.get(PresentationPasscodeSettings.self)
|
||||
return (accessChallengeData, passcodeSettings)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -616,8 +616,8 @@ public func privacyAndSecurityController(context: AccountContext, initialSetting
|
|||
let callsSignal = combineLatest(context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.voiceCallSettings]), context.account.postbox.preferencesView(keys: [PreferencesKeys.voipConfiguration]))
|
||||
|> take(1)
|
||||
|> map { sharedData, view -> (VoiceCallSettings, VoipConfiguration) in
|
||||
let voiceCallSettings: VoiceCallSettings = sharedData.entries[ApplicationSpecificSharedDataKeys.voiceCallSettings] as? VoiceCallSettings ?? .defaultSettings
|
||||
let voipConfiguration = view.values[PreferencesKeys.voipConfiguration] as? VoipConfiguration ?? .defaultValue
|
||||
let voiceCallSettings: VoiceCallSettings = sharedData.entries[ApplicationSpecificSharedDataKeys.voiceCallSettings]?.get(VoiceCallSettings.self) ?? .defaultSettings
|
||||
let voipConfiguration = view.values[PreferencesKeys.voipConfiguration]?.get(VoipConfiguration.self) ?? .defaultValue
|
||||
|
||||
return (voiceCallSettings, voipConfiguration)
|
||||
}
|
||||
|
|
@ -850,7 +850,7 @@ public func privacyAndSecurityController(context: AccountContext, initialSetting
|
|||
let signal = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, statePromise.get(), privacySettingsPromise.get(), context.sharedContext.accountManager.noticeEntry(key: ApplicationSpecificNotice.secretChatLinkPreviewsKey()), context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.contactSynchronizationSettings]), context.engine.peers.recentPeers(), blockedPeersState.get(), webSessionsContext.state, context.sharedContext.accountManager.accessChallengeData(), combineLatest(twoStepAuth.get(), twoStepAuthDataValue.get()), context.account.postbox.combinedView(keys: [preferencesKey]))
|
||||
|> map { presentationData, state, privacySettings, noticeView, sharedData, recentPeers, blockedPeersState, activeWebsitesState, accessChallengeData, twoStepAuth, preferences -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
var canAutoarchive = false
|
||||
if let view = preferences.views[preferencesKey] as? PreferencesView, let appConfiguration = view.values[PreferencesKeys.appConfiguration] as? AppConfiguration, let data = appConfiguration.data, let hasAutoarchive = data["autoarchive_setting_available"] as? Bool {
|
||||
if let view = preferences.views[preferencesKey] as? PreferencesView, let appConfiguration = view.values[PreferencesKeys.appConfiguration]?.get(AppConfiguration.self), let data = appConfiguration.data, let hasAutoarchive = data["autoarchive_setting_available"] as? Bool {
|
||||
canAutoarchive = hasAutoarchive
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -639,7 +639,7 @@ public func recentSessionsController(context: AccountContext, activeSessionsCont
|
|||
|
||||
let enableQRLogin = context.account.postbox.preferencesView(keys: [PreferencesKeys.appConfiguration])
|
||||
|> map { view -> Bool in
|
||||
guard let appConfiguration = view.values[PreferencesKeys.appConfiguration] as? AppConfiguration else {
|
||||
guard let appConfiguration = view.values[PreferencesKeys.appConfiguration]?.get(AppConfiguration.self) else {
|
||||
return false
|
||||
}
|
||||
guard let data = appConfiguration.data, let enableQR = data["qr_login_camera"] as? Bool, enableQR else {
|
||||
|
|
|
|||
|
|
@ -436,8 +436,8 @@ private func privacySearchableItems(context: AccountContext, privacySettings: Ac
|
|||
callsSignal = combineLatest(context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.voiceCallSettings]), context.account.postbox.preferencesView(keys: [PreferencesKeys.voipConfiguration]))
|
||||
|> take(1)
|
||||
|> map { sharedData, view -> (VoiceCallSettings, VoipConfiguration)? in
|
||||
let voiceCallSettings: VoiceCallSettings = sharedData.entries[ApplicationSpecificSharedDataKeys.voiceCallSettings] as? VoiceCallSettings ?? .defaultSettings
|
||||
let voipConfiguration = view.values[PreferencesKeys.voipConfiguration] as? VoipConfiguration ?? .defaultValue
|
||||
let voiceCallSettings: VoiceCallSettings = sharedData.entries[ApplicationSpecificSharedDataKeys.voiceCallSettings]?.get(VoiceCallSettings.self) ?? .defaultSettings
|
||||
let voipConfiguration = view.values[PreferencesKeys.voipConfiguration]?.get(VoipConfiguration.self) ?? .defaultValue
|
||||
return (voiceCallSettings, voipConfiguration)
|
||||
}
|
||||
} else {
|
||||
|
|
@ -742,7 +742,7 @@ func settingsSearchableItems(context: AccountContext, notificationExceptionsList
|
|||
|> take(1)
|
||||
|> map { view -> GlobalNotificationSettingsSet in
|
||||
let viewSettings: GlobalNotificationSettingsSet
|
||||
if let settings = view.values[PreferencesKeys.globalNotifications] as? GlobalNotificationSettings {
|
||||
if let settings = view.values[PreferencesKeys.globalNotifications]?.get(GlobalNotificationSettings.self) {
|
||||
viewSettings = settings.effective
|
||||
} else {
|
||||
viewSettings = GlobalNotificationSettingsSet.defaultSettings
|
||||
|
|
@ -758,7 +758,7 @@ func settingsSearchableItems(context: AccountContext, notificationExceptionsList
|
|||
|
||||
let proxyServers = context.sharedContext.accountManager.sharedData(keys: [SharedDataKeys.proxySettings])
|
||||
|> map { sharedData -> ProxySettings in
|
||||
if let value = sharedData.entries[SharedDataKeys.proxySettings] as? ProxySettings {
|
||||
if let value = sharedData.entries[SharedDataKeys.proxySettings]?.get(ProxySettings.self) {
|
||||
return value
|
||||
} else {
|
||||
return ProxySettings.defaultSettings
|
||||
|
|
@ -771,13 +771,13 @@ func settingsSearchableItems(context: AccountContext, notificationExceptionsList
|
|||
let localizationPreferencesKey: PostboxViewKey = .preferences(keys: Set([PreferencesKeys.localizationListState]))
|
||||
let localizations = combineLatest(context.account.postbox.combinedView(keys: [localizationPreferencesKey]), context.sharedContext.accountManager.sharedData(keys: [SharedDataKeys.localizationSettings]))
|
||||
|> map { view, sharedData -> [LocalizationInfo] in
|
||||
if let localizationListState = (view.views[localizationPreferencesKey] as? PreferencesView)?.values[PreferencesKeys.localizationListState] as? LocalizationListState, !localizationListState.availableOfficialLocalizations.isEmpty {
|
||||
if let localizationListState = (view.views[localizationPreferencesKey] as? PreferencesView)?.values[PreferencesKeys.localizationListState]?.get(LocalizationListState.self), !localizationListState.availableOfficialLocalizations.isEmpty {
|
||||
|
||||
var existingIds = Set<String>()
|
||||
let availableSavedLocalizations = localizationListState.availableSavedLocalizations.filter({ info in !localizationListState.availableOfficialLocalizations.contains(where: { $0.languageCode == info.languageCode }) })
|
||||
|
||||
var activeLanguageCode: String?
|
||||
if let localizationSettings = sharedData.entries[SharedDataKeys.localizationSettings] as? LocalizationSettings {
|
||||
if let localizationSettings = sharedData.entries[SharedDataKeys.localizationSettings]?.get(LocalizationSettings.self) {
|
||||
activeLanguageCode = localizationSettings.primaryComponent.languageCode
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -378,7 +378,7 @@ public func archivedStickerPacksController(context: AccountContext, mode: Archiv
|
|||
|> deliverOnMainQueue
|
||||
|> map { presentationData, state, packs, installedView, sharedData -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
var stickerSettings = StickerSettings.defaultSettings
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.stickerSettings] as? StickerSettings {
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.stickerSettings]?.get(StickerSettings.self) {
|
||||
stickerSettings = value
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ public func featuredStickerPacksController(context: AccountContext) -> ViewContr
|
|||
|> deliverOnMainQueue
|
||||
|> map { presentationData, state, view, featured, sharedData -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
var stickerSettings = StickerSettings.defaultSettings
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.stickerSettings] as? StickerSettings {
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.stickerSettings]?.get(StickerSettings.self) {
|
||||
stickerSettings = value
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -644,7 +644,7 @@ public func installedStickerPacksController(context: AccountContext, mode: Insta
|
|||
|> deliverOnMainQueue
|
||||
|> map { presentationData, state, view, temporaryPackOrder, featuredAndArchived, sharedData -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
var stickerSettings = StickerSettings.defaultSettings
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.stickerSettings] as? StickerSettings {
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.stickerSettings]?.get(StickerSettings.self) {
|
||||
stickerSettings = value
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -368,7 +368,7 @@ final class ThemeAccentColorController: ViewController {
|
|||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
let settings = (sharedData.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings] as? PresentationThemeSettings) ?? PresentationThemeSettings.defaultSettings
|
||||
let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings]?.get(PresentationThemeSettings.self) ?? PresentationThemeSettings.defaultSettings
|
||||
|
||||
let accentColor: UIColor
|
||||
var initialWallpaper: TelegramWallpaper?
|
||||
|
|
|
|||
|
|
@ -369,7 +369,7 @@ public func themeAutoNightSettingsController(context: AccountContext) -> ViewCon
|
|||
let _ = (combineLatest(stagingSettingsPromise.get(), sharedData)
|
||||
|> take(1)
|
||||
|> deliverOnMainQueue).start(next: { stagingSettings, sharedData in
|
||||
let settings = (sharedData.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings] as? PresentationThemeSettings) ?? PresentationThemeSettings.defaultSettings
|
||||
let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings]?.get(PresentationThemeSettings.self) ?? PresentationThemeSettings.defaultSettings
|
||||
let updated = f(stagingSettings ?? settings.automaticThemeSwitchSetting)
|
||||
stagingSettingsPromise.set(updated)
|
||||
if areSettingsValid(updated) {
|
||||
|
|
@ -569,7 +569,7 @@ public func themeAutoNightSettingsController(context: AccountContext) -> ViewCon
|
|||
|
||||
let signal = combineLatest(context.sharedContext.presentationData |> deliverOnMainQueue, sharedData |> deliverOnMainQueue, cloudThemes.get() |> deliverOnMainQueue, stagingSettingsPromise.get() |> deliverOnMainQueue)
|
||||
|> map { presentationData, sharedData, cloudThemes, stagingSettings -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
let settings = (sharedData.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings] as? PresentationThemeSettings) ?? PresentationThemeSettings.defaultSettings
|
||||
let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings]?.get(PresentationThemeSettings.self) ?? PresentationThemeSettings.defaultSettings
|
||||
|
||||
let defaultThemes: [PresentationThemeReference] = [.builtin(.night), .builtin(.nightAccent)]
|
||||
let cloudThemes: [PresentationThemeReference] = cloudThemes.map { .cloud(PresentationCloudTheme(theme: $0, resolvedWallpaper: nil, creatorAccountId: $0.isCreator ? context.account.id : nil)) }
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ final class ThemeColorsGridController: ViewController {
|
|||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
let settings = (sharedData.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings] as? PresentationThemeSettings) ?? PresentationThemeSettings.defaultSettings
|
||||
let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings]?.get(PresentationThemeSettings.self) ?? PresentationThemeSettings.defaultSettings
|
||||
|
||||
let autoNightModeTriggered = strongSelf.presentationData.autoNightModeTriggered
|
||||
let themeReference: PresentationThemeReference
|
||||
|
|
|
|||
|
|
@ -504,7 +504,7 @@ final class ThemeGridControllerNode: ASDisplayNode {
|
|||
self.context.sharedContext.accountManager.sharedData(keys: [SharedDataKeys.wallapersState])
|
||||
)
|
||||
|> map { remoteWallpapers, sharedData -> [Wallpaper] in
|
||||
let localState = (sharedData.entries[SharedDataKeys.wallapersState] as? WallpapersState) ?? WallpapersState.default
|
||||
let localState = sharedData.entries[SharedDataKeys.wallapersState]?.get(WallpapersState.self) ?? WallpapersState.default
|
||||
|
||||
var wallpapers: [Wallpaper] = []
|
||||
for wallpaper in localState.wallpapers {
|
||||
|
|
|
|||
|
|
@ -356,7 +356,7 @@ public final class ThemePreviewController: ViewController {
|
|||
var previousDefaultTheme: (PresentationThemeReference, PresentationThemeAccentColor?, Bool, PresentationThemeReference, Bool)?
|
||||
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.presentationThemeSettings, { entry in
|
||||
let currentSettings: PresentationThemeSettings
|
||||
if let entry = entry as? PresentationThemeSettings {
|
||||
if let entry = entry?.get(PresentationThemeSettings.self) {
|
||||
currentSettings = entry
|
||||
} else {
|
||||
currentSettings = PresentationThemeSettings.defaultSettings
|
||||
|
|
@ -387,7 +387,7 @@ public final class ThemePreviewController: ViewController {
|
|||
|
||||
var themeSpecificChatWallpapers = updatedSettings.themeSpecificChatWallpapers
|
||||
themeSpecificChatWallpapers[updatedTheme.index] = nil
|
||||
return updatedSettings.withUpdatedThemeSpecificChatWallpapers(themeSpecificChatWallpapers).withUpdatedThemeSpecificAccentColors(themeSpecificAccentColors)
|
||||
return PreferencesEntry(updatedSettings.withUpdatedThemeSpecificChatWallpapers(themeSpecificChatWallpapers).withUpdatedThemeSpecificAccentColors(themeSpecificAccentColors))
|
||||
})
|
||||
return previousDefaultTheme
|
||||
}
|
||||
|
|
|
|||
|
|
@ -600,14 +600,14 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
|
|||
let _ = (context.sharedContext.accountManager.sharedData(keys: Set([ApplicationSpecificSharedDataKeys.presentationThemeSettings]))
|
||||
|> take(1)
|
||||
|> deliverOnMainQueue).start(next: { view in
|
||||
let settings = (view.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings] as? PresentationThemeSettings) ?? PresentationThemeSettings.defaultSettings
|
||||
let settings = view.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings]?.get(PresentationThemeSettings.self) ?? PresentationThemeSettings.defaultSettings
|
||||
pushControllerImpl?(TextSizeSelectionController(context: context, presentationThemeSettings: settings))
|
||||
})
|
||||
}, openBubbleSettings: {
|
||||
let _ = (context.sharedContext.accountManager.sharedData(keys: Set([ApplicationSpecificSharedDataKeys.presentationThemeSettings]))
|
||||
|> take(1)
|
||||
|> deliverOnMainQueue).start(next: { view in
|
||||
let settings = (view.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings] as? PresentationThemeSettings) ?? PresentationThemeSettings.defaultSettings
|
||||
let settings = view.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings]?.get(PresentationThemeSettings.self) ?? PresentationThemeSettings.defaultSettings
|
||||
pushControllerImpl?(BubbleSettingsController(context: context, presentationThemeSettings: settings))
|
||||
})
|
||||
}, toggleLargeEmoji: { largeEmoji in
|
||||
|
|
@ -631,7 +631,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
|
|||
pushControllerImpl?(controller)
|
||||
}, themeContextAction: { isCurrent, reference, node, gesture in
|
||||
let _ = (context.sharedContext.accountManager.transaction { transaction -> (PresentationThemeAccentColor?, TelegramWallpaper?) in
|
||||
let settings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.presentationThemeSettings) as? PresentationThemeSettings ?? PresentationThemeSettings.defaultSettings
|
||||
let settings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.presentationThemeSettings)?.get(PresentationThemeSettings.self) ?? PresentationThemeSettings.defaultSettings
|
||||
let accentColor = settings.themeSpecificAccentColors[reference.index]
|
||||
var wallpaper: TelegramWallpaper?
|
||||
if let accentColor = accentColor {
|
||||
|
|
@ -808,7 +808,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
|
|||
})
|
||||
}, colorContextAction: { isCurrent, reference, accentColor, node, gesture in
|
||||
let _ = (context.sharedContext.accountManager.transaction { transaction -> (ThemeSettingsColorOption?, TelegramWallpaper?) in
|
||||
let settings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.presentationThemeSettings) as? PresentationThemeSettings ?? PresentationThemeSettings.defaultSettings
|
||||
let settings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.presentationThemeSettings)?.get(PresentationThemeSettings.self) ?? PresentationThemeSettings.defaultSettings
|
||||
var wallpaper: TelegramWallpaper?
|
||||
if let accentColor = accentColor {
|
||||
switch accentColor {
|
||||
|
|
@ -1041,7 +1041,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
|
|||
|
||||
let signal = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.presentationThemeSettings]), cloudThemes.get(), availableAppIcons, currentAppIconName.get(), removedThemeIndexesPromise.get())
|
||||
|> map { presentationData, sharedData, cloudThemes, availableAppIcons, currentAppIconName, removedThemeIndexes -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
let settings = (sharedData.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings] as? PresentationThemeSettings) ?? PresentationThemeSettings.defaultSettings
|
||||
let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings]?.get(PresentationThemeSettings.self) ?? PresentationThemeSettings.defaultSettings
|
||||
|
||||
let themeReference: PresentationThemeReference
|
||||
if presentationData.autoNightModeTriggered {
|
||||
|
|
@ -1189,7 +1189,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
|
|||
let _ = applyTheme(accountManager: context.sharedContext.accountManager, account: context.account, theme: cloudTheme).start()
|
||||
|
||||
let currentTheme = context.sharedContext.accountManager.transaction { transaction -> (PresentationThemeReference) in
|
||||
let settings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.presentationThemeSettings) as? PresentationThemeSettings ?? PresentationThemeSettings.defaultSettings
|
||||
let settings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.presentationThemeSettings)?.get(PresentationThemeSettings.self) ?? PresentationThemeSettings.defaultSettings
|
||||
if autoNightModeTriggered {
|
||||
return settings.automaticThemeSwitchSetting.theme
|
||||
} else {
|
||||
|
|
@ -1322,7 +1322,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
|
|||
actionSheet?.dismissAnimated()
|
||||
|
||||
let _ = (context.sharedContext.accountManager.transaction { transaction -> PresentationThemeReference in
|
||||
let settings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.presentationThemeSettings) as? PresentationThemeSettings ?? PresentationThemeSettings.defaultSettings
|
||||
let settings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.presentationThemeSettings)?.get(PresentationThemeSettings.self) ?? PresentationThemeSettings.defaultSettings
|
||||
|
||||
let themeReference: PresentationThemeReference
|
||||
let autoNightModeTriggered = context.sharedContext.currentPresentationData.with { $0 }.autoNightModeTriggered
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ public func watchSettingsController(context: AccountContext) -> ViewController {
|
|||
let signal = combineLatest(context.sharedContext.presentationData, context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.watchPresetSettings]))
|
||||
|> deliverOnMainQueue
|
||||
|> map { presentationData, sharedData -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
let settings = (sharedData.entries[ApplicationSpecificSharedDataKeys.watchPresetSettings] as? WatchPresetSettings) ?? WatchPresetSettings.defaultSettings
|
||||
let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.watchPresetSettings]?.get(WatchPresetSettings.self) ?? WatchPresetSettings.defaultSettings
|
||||
|
||||
let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(presentationData.strings.AppleWatch_Title), leftNavigationButton: nil, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back))
|
||||
let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: watchSettingsControllerEntries(presentationData: presentationData, customPresets: settings.customPresets), style: .blocks, animateChanges: false)
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ public final class StickerPackPreviewController: ViewController, StandalonePrese
|
|||
self.stickerPackDisposable.set((combineLatest(self.stickerPackContents.get(), self.context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.stickerSettings]) |> take(1))
|
||||
|> mapToSignal { next, sharedData -> Signal<(LoadedStickerPack, StickerSettings), NoError> in
|
||||
var stickerSettings = StickerSettings.defaultSettings
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.stickerSettings] as? StickerSettings {
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.stickerSettings]?.get(StickerSettings.self) {
|
||||
stickerSettings = value
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -676,10 +676,10 @@ open class TelegramBaseController: ViewController, KeyShortcutResponder {
|
|||
return
|
||||
}
|
||||
let _ = (strongSelf.context.sharedContext.accountManager.transaction { transaction -> AudioPlaybackRate in
|
||||
let settings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.musicPlaybackSettings) as? MusicPlaybackSettings ?? MusicPlaybackSettings.defaultSettings
|
||||
let settings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.musicPlaybackSettings)?.get(MusicPlaybackSettings.self) ?? MusicPlaybackSettings.defaultSettings
|
||||
|
||||
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.musicPlaybackSettings, { _ in
|
||||
return settings.withUpdatedVoicePlaybackRate(rate)
|
||||
return PreferencesEntry(settings.withUpdatedVoicePlaybackRate(rate))
|
||||
})
|
||||
return rate
|
||||
}
|
||||
|
|
|
|||
|
|
@ -274,7 +274,7 @@ public final class CallController: ViewController {
|
|||
let _ = (combineLatest(strongSelf.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.callListSettings]), ApplicationSpecificNotice.getCallsTabTip(accountManager: strongSelf.sharedContext.accountManager))
|
||||
|> map { sharedData, callsTabTip -> Int32 in
|
||||
var value = false
|
||||
if let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.callListSettings] as? CallListSettings {
|
||||
if let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.callListSettings]?.get(CallListSettings.self) {
|
||||
value = settings.showTab
|
||||
}
|
||||
if value {
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
|
|||
|
||||
let enableCallKit = accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.voiceCallSettings])
|
||||
|> map { sharedData -> Bool in
|
||||
let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.voiceCallSettings] as? VoiceCallSettings ?? .defaultSettings
|
||||
let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.voiceCallSettings]?.get(VoiceCallSettings.self) ?? .defaultSettings
|
||||
return settings.enableSystemIntegration
|
||||
}
|
||||
|> distinctUntilChanged
|
||||
|
|
@ -245,7 +245,7 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
|
|||
|
||||
self.proxyServerDisposable = (accountManager.sharedData(keys: [SharedDataKeys.proxySettings])
|
||||
|> deliverOnMainQueue).start(next: { [weak self] sharedData in
|
||||
if let strongSelf = self, let settings = sharedData.entries[SharedDataKeys.proxySettings] as? ProxySettings {
|
||||
if let strongSelf = self, let settings = sharedData.entries[SharedDataKeys.proxySettings]?.get(ProxySettings.self) {
|
||||
if settings.enabled && settings.useForCalls {
|
||||
strongSelf.proxyServer = settings.activeServer
|
||||
} else {
|
||||
|
|
@ -257,7 +257,7 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
|
|||
self.callSettingsDisposable = (accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.voiceCallSettings])
|
||||
|> deliverOnMainQueue).start(next: { [weak self] sharedData in
|
||||
if let strongSelf = self {
|
||||
strongSelf.callSettings = sharedData.entries[ApplicationSpecificSharedDataKeys.voiceCallSettings] as? VoiceCallSettings ?? .defaultSettings
|
||||
strongSelf.callSettings = sharedData.entries[ApplicationSpecificSharedDataKeys.voiceCallSettings]?.get(VoiceCallSettings.self) ?? .defaultSettings
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -281,11 +281,11 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
|
|||
return
|
||||
}
|
||||
|
||||
let configuration = preferences.values[PreferencesKeys.voipConfiguration] as? VoipConfiguration ?? .defaultValue
|
||||
let derivedState = preferences.values[ApplicationSpecificPreferencesKeys.voipDerivedState] as? VoipDerivedState ?? .default
|
||||
let autodownloadSettings = sharedData.entries[SharedDataKeys.autodownloadSettings] as? AutodownloadSettings ?? .defaultSettings
|
||||
let experimentalSettings = sharedData.entries[ApplicationSpecificSharedDataKeys.experimentalUISettings] as? ExperimentalUISettings ?? .defaultSettings
|
||||
let appConfiguration = preferences.values[PreferencesKeys.appConfiguration] as? AppConfiguration ?? AppConfiguration.defaultValue
|
||||
let configuration = preferences.values[PreferencesKeys.voipConfiguration]?.get(VoipConfiguration.self) ?? .defaultValue
|
||||
let derivedState = preferences.values[ApplicationSpecificPreferencesKeys.voipDerivedState]?.get(VoipDerivedState.self) ?? .default
|
||||
let autodownloadSettings = sharedData.entries[SharedDataKeys.autodownloadSettings]?.get(AutodownloadSettings.self) ?? .defaultSettings
|
||||
let experimentalSettings = sharedData.entries[ApplicationSpecificSharedDataKeys.experimentalUISettings]?.get(ExperimentalUISettings.self) ?? .defaultSettings
|
||||
let appConfiguration = preferences.values[PreferencesKeys.appConfiguration]?.get(AppConfiguration.self) ?? AppConfiguration.defaultValue
|
||||
|
||||
let call = PresentationCallImpl(
|
||||
context: firstState.0,
|
||||
|
|
@ -486,7 +486,7 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
|
|||
}
|
||||
|
||||
let request = context.account.postbox.transaction { transaction -> (VideoCallsConfiguration, CachedUserData?) in
|
||||
let appConfiguration: AppConfiguration = transaction.getPreferencesEntry(key: PreferencesKeys.appConfiguration) as? AppConfiguration ?? AppConfiguration.defaultValue
|
||||
let appConfiguration: AppConfiguration = transaction.getPreferencesEntry(key: PreferencesKeys.appConfiguration)?.get(AppConfiguration.self) ?? AppConfiguration.defaultValue
|
||||
return (VideoCallsConfiguration(appConfiguration: appConfiguration), transaction.getPeerCachedData(peerId: peerId) as? CachedUserData)
|
||||
}
|
||||
|> mapToSignal { callsConfiguration, cachedUserData -> Signal<CallSessionInternalId, NoError> in
|
||||
|
|
@ -521,10 +521,10 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
|
|||
currentCall.rejectBusy()
|
||||
}
|
||||
|
||||
let configuration = preferences.values[PreferencesKeys.voipConfiguration] as? VoipConfiguration ?? .defaultValue
|
||||
let derivedState = preferences.values[ApplicationSpecificPreferencesKeys.voipDerivedState] as? VoipDerivedState ?? .default
|
||||
let autodownloadSettings = sharedData.entries[SharedDataKeys.autodownloadSettings] as? AutodownloadSettings ?? .defaultSettings
|
||||
let appConfiguration = preferences.values[PreferencesKeys.appConfiguration] as? AppConfiguration ?? AppConfiguration.defaultValue
|
||||
let configuration = preferences.values[PreferencesKeys.voipConfiguration]?.get(VoipConfiguration.self) ?? .defaultValue
|
||||
let derivedState = preferences.values[ApplicationSpecificPreferencesKeys.voipDerivedState]?.get(VoipDerivedState.self) ?? .default
|
||||
let autodownloadSettings = sharedData.entries[SharedDataKeys.autodownloadSettings]?.get(AutodownloadSettings.self) ?? .defaultSettings
|
||||
let appConfiguration = preferences.values[PreferencesKeys.appConfiguration]?.get(AppConfiguration.self) ?? AppConfiguration.defaultValue
|
||||
|
||||
let callsConfiguration = VideoCallsConfiguration(appConfiguration: appConfiguration)
|
||||
var isVideoPossible: Bool
|
||||
|
|
@ -541,7 +541,7 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
|
|||
isVideoPossible = false
|
||||
}
|
||||
|
||||
let experimentalSettings = sharedData.entries[ApplicationSpecificSharedDataKeys.experimentalUISettings] as? ExperimentalUISettings ?? .defaultSettings
|
||||
let experimentalSettings = sharedData.entries[ApplicationSpecificSharedDataKeys.experimentalUISettings]?.get(ExperimentalUISettings.self) ?? .defaultSettings
|
||||
|
||||
let call = PresentationCallImpl(
|
||||
context: context,
|
||||
|
|
|
|||
|
|
@ -1899,7 +1899,7 @@ public final class VoiceChatController: ViewController {
|
|||
return
|
||||
}
|
||||
|
||||
let appConfiguration: AppConfiguration = preferencesView.values[PreferencesKeys.appConfiguration] as? AppConfiguration ?? .defaultValue
|
||||
let appConfiguration: AppConfiguration = preferencesView.values[PreferencesKeys.appConfiguration]?.get(AppConfiguration.self) ?? .defaultValue
|
||||
let configuration = VoiceChatConfiguration.with(appConfiguration: appConfiguration)
|
||||
strongSelf.configuration = configuration
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ swift_library(
|
|||
srcs = glob([
|
||||
"Sources/**/*.swift",
|
||||
]),
|
||||
copts = [
|
||||
"-warnings-as-errors",
|
||||
],
|
||||
deps = [
|
||||
"//submodules/TelegramApi:TelegramApi",
|
||||
"//submodules/MtProtoKit:MtProtoKit",
|
||||
|
|
|
|||
|
|
@ -129,11 +129,11 @@ public class UnauthorizedAccount {
|
|||
let keychain = makeExclusiveKeychain(id: self.id, postbox: self.postbox)
|
||||
|
||||
return accountManager.transaction { transaction -> (LocalizationSettings?, ProxySettings?) in
|
||||
return (transaction.getSharedData(SharedDataKeys.localizationSettings) as? LocalizationSettings, transaction.getSharedData(SharedDataKeys.proxySettings) as? ProxySettings)
|
||||
return (transaction.getSharedData(SharedDataKeys.localizationSettings)?.get(LocalizationSettings.self), transaction.getSharedData(SharedDataKeys.proxySettings)?.get(ProxySettings.self))
|
||||
}
|
||||
|> mapToSignal { localizationSettings, proxySettings -> Signal<(LocalizationSettings?, ProxySettings?, NetworkSettings?), NoError> in
|
||||
return self.postbox.transaction { transaction -> (LocalizationSettings?, ProxySettings?, NetworkSettings?) in
|
||||
return (localizationSettings, proxySettings, transaction.getPreferencesEntry(key: PreferencesKeys.networkSettings) as? NetworkSettings)
|
||||
return (localizationSettings, proxySettings, transaction.getPreferencesEntry(key: PreferencesKeys.networkSettings)?.get(NetworkSettings.self))
|
||||
}
|
||||
}
|
||||
|> mapToSignal { (localizationSettings, proxySettings, networkSettings) -> Signal<UnauthorizedAccount, NoError> in
|
||||
|
|
@ -251,7 +251,7 @@ public func accountWithId(accountManager: AccountManager<TelegramAccountManagerT
|
|||
return .single(.upgrading(0.0))
|
||||
case let .postbox(postbox):
|
||||
return accountManager.transaction { transaction -> (LocalizationSettings?, ProxySettings?) in
|
||||
return (transaction.getSharedData(SharedDataKeys.localizationSettings) as? LocalizationSettings, transaction.getSharedData(SharedDataKeys.proxySettings) as? ProxySettings)
|
||||
return (transaction.getSharedData(SharedDataKeys.localizationSettings)?.get(LocalizationSettings.self), transaction.getSharedData(SharedDataKeys.proxySettings)?.get(ProxySettings.self))
|
||||
}
|
||||
|> mapToSignal { localizationSettings, proxySettings -> Signal<AccountResult, NoError> in
|
||||
return postbox.transaction { transaction -> (PostboxCoding?, LocalizationSettings?, ProxySettings?, NetworkSettings?) in
|
||||
|
|
@ -266,7 +266,7 @@ public func accountWithId(accountManager: AccountManager<TelegramAccountManagerT
|
|||
transaction.setKeychainEntry(data, forKey: "persistent:datacenterAuthInfoById")
|
||||
}
|
||||
|
||||
return (state, localizationSettings, proxySettings, transaction.getPreferencesEntry(key: PreferencesKeys.networkSettings) as? NetworkSettings)
|
||||
return (state, localizationSettings, proxySettings, transaction.getPreferencesEntry(key: PreferencesKeys.networkSettings)?.get(NetworkSettings.self))
|
||||
}
|
||||
|> mapToSignal { (accountState, localizationSettings, proxySettings, networkSettings) -> Signal<AccountResult, NoError> in
|
||||
let keychain = makeExclusiveKeychain(id: id, postbox: postbox)
|
||||
|
|
@ -407,7 +407,8 @@ func _internal_twoStepAuthData(_ network: Network) -> Signal<TwoStepAuthData, MT
|
|||
|
||||
public func hexString(_ data: Data) -> String {
|
||||
let hexString = NSMutableString()
|
||||
data.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||
data.withUnsafeBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
for i in 0 ..< data.count {
|
||||
hexString.appendFormat("%02x", UInt(bytes.advanced(by: i).pointee))
|
||||
}
|
||||
|
|
@ -437,19 +438,22 @@ public func dataWithHexString(_ string: String) -> Data {
|
|||
}
|
||||
|
||||
func sha1Digest(_ data : Data) -> Data {
|
||||
return data.withUnsafeBytes { bytes -> Data in
|
||||
return data.withUnsafeBytes { rawBytes -> Data in
|
||||
let bytes = rawBytes.baseAddress!
|
||||
return CryptoSHA1(bytes, Int32(data.count))
|
||||
}
|
||||
}
|
||||
|
||||
func sha256Digest(_ data : Data) -> Data {
|
||||
return data.withUnsafeBytes { bytes -> Data in
|
||||
return data.withUnsafeBytes { rawBytes -> Data in
|
||||
let bytes = rawBytes.baseAddress!
|
||||
return CryptoSHA256(bytes, Int32(data.count))
|
||||
}
|
||||
}
|
||||
|
||||
func sha512Digest(_ data : Data) -> Data {
|
||||
return data.withUnsafeBytes { bytes -> Data in
|
||||
return data.withUnsafeBytes { rawBytes -> Data in
|
||||
let bytes = rawBytes.baseAddress!
|
||||
return CryptoSHA512(bytes, Int32(data.count))
|
||||
}
|
||||
}
|
||||
|
|
@ -466,7 +470,8 @@ func passwordUpdateKDF(encryptionProvider: EncryptionProvider, password: String,
|
|||
var nextSalt1 = salt1
|
||||
var randomSalt1 = Data()
|
||||
randomSalt1.count = 32
|
||||
randomSalt1.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<Int8>) -> Void in
|
||||
randomSalt1.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: Int8.self)
|
||||
arc4random_buf(bytes, 32)
|
||||
}
|
||||
nextSalt1.append(randomSalt1)
|
||||
|
|
@ -474,7 +479,8 @@ func passwordUpdateKDF(encryptionProvider: EncryptionProvider, password: String,
|
|||
let nextSalt2 = salt2
|
||||
|
||||
var g = Data(count: 4)
|
||||
g.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<Int8>) -> Void in
|
||||
g.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: Int8.self)
|
||||
var gValue = gValue
|
||||
withUnsafeBytes(of: &gValue, { (sourceBuffer: UnsafeRawBufferPointer) -> Void in
|
||||
let sourceBytes = sourceBuffer.bindMemory(to: Int8.self).baseAddress!
|
||||
|
|
@ -526,8 +532,10 @@ private func paddedXor(_ a: Data, _ b: Data) -> Data {
|
|||
while b.count < count {
|
||||
b.insert(0, at: 0)
|
||||
}
|
||||
a.withUnsafeMutableBytes { (aBytes: UnsafeMutablePointer<UInt8>) -> Void in
|
||||
b.withUnsafeBytes { (bBytes: UnsafePointer<UInt8>) -> Void in
|
||||
a.withUnsafeMutableBytes { rawABytes -> Void in
|
||||
let aBytes = rawABytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
b.withUnsafeBytes { rawBBytes -> Void in
|
||||
let bBytes = rawBBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
for i in 0 ..< count {
|
||||
aBytes.advanced(by: i).pointee = aBytes.advanced(by: i).pointee ^ bBytes.advanced(by: i).pointee
|
||||
}
|
||||
|
|
@ -547,12 +555,14 @@ func passwordKDF(encryptionProvider: EncryptionProvider, password: String, deriv
|
|||
case let .sha256_sha256_PBKDF2_HMAC_sha512_sha256_srp(salt1, salt2, iterations, gValue, p):
|
||||
var a = Data(count: p.count)
|
||||
let aLength = a.count
|
||||
a.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<UInt8>) -> Void in
|
||||
a.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
let _ = SecRandomCopyBytes(nil, aLength, bytes)
|
||||
}
|
||||
|
||||
var g = Data(count: 4)
|
||||
g.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<Int8>) -> Void in
|
||||
g.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: Int8.self)
|
||||
var gValue = gValue
|
||||
withUnsafeBytes(of: &gValue, { (sourceBuffer: UnsafeRawBufferPointer) -> Void in
|
||||
let sourceBytes = sourceBuffer.bindMemory(to: Int8.self).baseAddress!
|
||||
|
|
@ -616,7 +626,8 @@ func securePasswordUpdateKDF(password: String, derivation: TwoStepSecurePassword
|
|||
var nextSalt = salt
|
||||
var randomSalt = Data()
|
||||
randomSalt.count = 32
|
||||
randomSalt.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<Int8>) -> Void in
|
||||
randomSalt.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: Int8.self)
|
||||
arc4random_buf(bytes, 32)
|
||||
}
|
||||
nextSalt.append(randomSalt)
|
||||
|
|
@ -630,7 +641,8 @@ func securePasswordUpdateKDF(password: String, derivation: TwoStepSecurePassword
|
|||
var nextSalt = salt
|
||||
var randomSalt = Data()
|
||||
randomSalt.count = 32
|
||||
randomSalt.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<Int8>) -> Void in
|
||||
randomSalt.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: Int8.self)
|
||||
arc4random_buf(bytes, 32)
|
||||
}
|
||||
nextSalt.append(randomSalt)
|
||||
|
|
@ -746,7 +758,8 @@ private func masterNotificationsKey(masterNotificationKeyValue: Atomic<MasterNot
|
|||
} else {
|
||||
var secretData = Data(count: 256)
|
||||
let secretDataCount = secretData.count
|
||||
if !secretData.withUnsafeMutableBytes({ (bytes: UnsafeMutablePointer<Int8>) -> Bool in
|
||||
if !secretData.withUnsafeMutableBytes({ rawBytes -> Bool in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: Int8.self)
|
||||
let copyResult = SecRandomCopyBytes(nil, secretDataCount, bytes)
|
||||
return copyResult == errSecSuccess
|
||||
}) {
|
||||
|
|
@ -785,7 +798,8 @@ public func decryptedNotificationPayload(key: MasterNotificationKey, data: Data)
|
|||
}
|
||||
|
||||
var dataLength: Int32 = 0
|
||||
data.withUnsafeBytes { (bytes: UnsafePointer<Int8>) -> Void in
|
||||
data.withUnsafeBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: Int8.self)
|
||||
memcpy(&dataLength, bytes, 4)
|
||||
}
|
||||
|
||||
|
|
@ -1087,7 +1101,7 @@ public class Account {
|
|||
}))
|
||||
self.managedOperationsDisposable.add((accountManager.sharedData(keys: [SharedDataKeys.proxySettings])
|
||||
|> map { sharedData -> ProxyServerSettings? in
|
||||
if let settings = sharedData.entries[SharedDataKeys.proxySettings] as? ProxySettings {
|
||||
if let settings = sharedData.entries[SharedDataKeys.proxySettings]?.get(ProxySettings.self) {
|
||||
return settings.effectiveActiveServer
|
||||
} else {
|
||||
return nil
|
||||
|
|
@ -1138,7 +1152,7 @@ public class Account {
|
|||
guard let mediaBox = mediaBox else {
|
||||
return
|
||||
}
|
||||
let settings: CacheStorageSettings = sharedData.entries[SharedDataKeys.cacheStorageSettings] as? CacheStorageSettings ?? CacheStorageSettings.defaultSettings
|
||||
let settings: CacheStorageSettings = sharedData.entries[SharedDataKeys.cacheStorageSettings]?.get(CacheStorageSettings.self) ?? CacheStorageSettings.defaultSettings
|
||||
mediaBox.setMaxStoreTimes(general: settings.defaultCacheStorageTimeout, shortLived: 60 * 60, gigabytesLimit: settings.defaultCacheStorageLimitGigabytes)
|
||||
})
|
||||
}
|
||||
|
|
@ -1238,9 +1252,9 @@ public class Account {
|
|||
}
|
||||
|
||||
public func addUpdates(serializedData: Data) -> Void {
|
||||
if let object = Api.parse(Buffer(data: serializedData)) {
|
||||
//self.stateManager.addUpdates()
|
||||
}
|
||||
/*if let object = Api.parse(Buffer(data: serializedData)) {
|
||||
self.stateManager.addUpdates()
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -591,7 +591,7 @@ struct AccountMutableState {
|
|||
self.readInboxMaxIds[peerId] = MessageId(peerId: peerId, namespace: namespace, id: maxIncomingReadId)
|
||||
}
|
||||
}
|
||||
case let .ResetMessageTagSummary(peerId, namespace, count, range):
|
||||
case .ResetMessageTagSummary:
|
||||
break
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ private var declaredEncodables: Void = {
|
|||
declareEncodable(CachedRecentPeers.self, f: { CachedRecentPeers(decoder: $0) })
|
||||
//declareEncodable(AppChangelogState.self, f: { AppChangelogState(decoder: $0) })
|
||||
//declareEncodable(AppConfiguration.self, f: { AppConfiguration(decoder: $0) })
|
||||
declareEncodable(JSON.self, f: { JSON(decoder: $0) })
|
||||
//declareEncodable(JSON.self, f: { JSON(decoder: $0) })
|
||||
//declareEncodable(SearchBotsConfiguration.self, f: { SearchBotsConfiguration(decoder: $0) })
|
||||
//declareEncodable(AutodownloadSettings.self, f: { AutodownloadSettings(decoder: $0 )})
|
||||
declareEncodable(TelegramMediaPoll.self, f: { TelegramMediaPoll(decoder: $0) })
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ extension ReplyMarkupButton {
|
|||
case let .inputKeyboardButtonUrlAuth(_, text, fwdText, url, _):
|
||||
self.init(title: text, titleWhenForwarded: fwdText, action: .urlAuth(url: url, buttonId: 0))
|
||||
case let .keyboardButtonRequestPoll(_, quiz, text):
|
||||
var isQuiz: Bool? = quiz.flatMap { quiz in
|
||||
let isQuiz: Bool? = quiz.flatMap { quiz in
|
||||
if case .boolTrue = quiz {
|
||||
return true
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -116,8 +116,8 @@ public func tagsForStoreMessage(incoming: Bool, attributes: [MessageAttribute],
|
|||
|
||||
func apiMessagePeerId(_ messsage: Api.Message) -> PeerId? {
|
||||
switch messsage {
|
||||
case let .message(message):
|
||||
let chatPeerId = message.peerId
|
||||
case let .message(_, _, _, messagePeerId, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _):
|
||||
let chatPeerId = messagePeerId
|
||||
return chatPeerId.peerId
|
||||
case let .messageEmpty(_, _, peerId):
|
||||
if let peerId = peerId {
|
||||
|
|
@ -132,7 +132,7 @@ func apiMessagePeerId(_ messsage: Api.Message) -> PeerId? {
|
|||
|
||||
func apiMessagePeerIds(_ message: Api.Message) -> [PeerId] {
|
||||
switch message {
|
||||
case let .message(flags, _, fromId, chatPeerId, fwdHeader, viaBotId, _, _, _, media, _, entities, _, _, _, _, _, _, _, _):
|
||||
case let .message(_, _, fromId, chatPeerId, fwdHeader, viaBotId, _, _, _, media, _, entities, _, _, _, _, _, _, _, _):
|
||||
let peerId: PeerId = chatPeerId.peerId
|
||||
|
||||
var result = [peerId]
|
||||
|
|
@ -145,11 +145,11 @@ func apiMessagePeerIds(_ message: Api.Message) -> [PeerId] {
|
|||
|
||||
if let fwdHeader = fwdHeader {
|
||||
switch fwdHeader {
|
||||
case let .messageFwdHeader(messageFwdHeader):
|
||||
if let fromId = messageFwdHeader.fromId {
|
||||
case let .messageFwdHeader(_, fromId, _, _, _, _, savedFromPeer, _, _):
|
||||
if let fromId = fromId {
|
||||
result.append(fromId.peerId)
|
||||
}
|
||||
if let savedFromPeer = messageFwdHeader.savedFromPeer {
|
||||
if let savedFromPeer = savedFromPeer {
|
||||
result.append(savedFromPeer.peerId)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -227,8 +227,8 @@ public func authorizeWithCode(accountManager: AccountManager<TelegramAccountMana
|
|||
}
|
||||
|> mapToSignal { result -> Signal<AuthorizationCodeResult, AuthorizationCodeVerificationError> in
|
||||
switch result {
|
||||
case let .password(password):
|
||||
return .single(.password(hint: password.hint ?? ""))
|
||||
case let .password(_, _, _, _, hint, _, _, _, _, _):
|
||||
return .single(.password(hint: hint ?? ""))
|
||||
}
|
||||
}
|
||||
case let (_, errorDescription):
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public func fetchedMediaResource(mediaBox: MediaBox, reference: MediaResourceRef
|
|||
}
|
||||
return combineLatest(signals)
|
||||
|> ignoreValues
|
||||
|> map { _ -> FetchResourceSourceType in .local }
|
||||
|> map { _ -> FetchResourceSourceType in }
|
||||
|> then(.single(.local))
|
||||
} else {
|
||||
return mediaBox.fetchedResource(reference.resource, parameters: MediaResourceFetchParameters(tag: TelegramMediaResourceFetchTag(statsCategory: statsCategory), info: TelegramCloudMediaResourceFetchInfo(reference: reference, preferBackgroundReferenceRevalidation: preferBackgroundReferenceRevalidation, continueInBackground: continueInBackground), isRandomAccessAllowed: isRandomAccessAllowed), implNext: reportResultStatus)
|
||||
|
|
@ -61,7 +61,7 @@ enum RevalidateMediaReferenceError {
|
|||
|
||||
public func stickerPackFileReference(_ file: TelegramMediaFile) -> FileMediaReference {
|
||||
for attribute in file.attributes {
|
||||
if case let .Sticker(sticker) = attribute, let stickerPack = sticker.packReference {
|
||||
if case let .Sticker(_, packReferenceValue, _) = attribute, let stickerPack = packReferenceValue {
|
||||
return .stickerPack(stickerPack: stickerPack, media: file)
|
||||
}
|
||||
}
|
||||
|
|
@ -292,8 +292,6 @@ final class MediaReferenceRevalidationContext {
|
|||
} else {
|
||||
error(.generic)
|
||||
}
|
||||
}, error: { _ in
|
||||
error(.generic)
|
||||
})
|
||||
}) |> mapToSignal { next -> Signal<Message, RevalidateMediaReferenceError> in
|
||||
if let next = next as? Message {
|
||||
|
|
@ -308,7 +306,6 @@ final class MediaReferenceRevalidationContext {
|
|||
return self.genericItem(key: .stickerPack(stickerPack: stickerPack), background: background, request: { next, error in
|
||||
return (updatedRemoteStickerPack(postbox: postbox, network: network, reference: stickerPack)
|
||||
|> mapError { _ -> RevalidateMediaReferenceError in
|
||||
return .generic
|
||||
}).start(next: { value in
|
||||
if let value = value {
|
||||
next(value)
|
||||
|
|
@ -331,7 +328,6 @@ final class MediaReferenceRevalidationContext {
|
|||
return self.genericItem(key: .webPage(webPage: webPage), background: background, request: { next, error in
|
||||
return (updatedRemoteWebpage(postbox: postbox, network: network, webPage: webPage)
|
||||
|> mapError { _ -> RevalidateMediaReferenceError in
|
||||
return .generic
|
||||
}).start(next: { value in
|
||||
if let value = value {
|
||||
next(value)
|
||||
|
|
@ -443,7 +439,6 @@ final class MediaReferenceRevalidationContext {
|
|||
return (telegramThemes(postbox: postbox, network: network, accountManager: nil, forceUpdate: true)
|
||||
|> take(1)
|
||||
|> mapError { _ -> RevalidateMediaReferenceError in
|
||||
return .generic
|
||||
}).start(next: { value in
|
||||
next(value)
|
||||
}, error: { _ in
|
||||
|
|
@ -462,7 +457,6 @@ final class MediaReferenceRevalidationContext {
|
|||
return self.genericItem(key: .peerAvatars(peer: peer), background: background, request: { next, error in
|
||||
return (_internal_requestPeerPhotos(postbox: postbox, network: network, peerId: peer.id)
|
||||
|> mapError { _ -> RevalidateMediaReferenceError in
|
||||
return .generic
|
||||
}).start(next: { value in
|
||||
next(value)
|
||||
}, error: { _ in
|
||||
|
|
@ -504,8 +498,8 @@ func revalidateMediaResourceReference(postbox: Postbox, network: Network, revali
|
|||
if revalidateWithStickerpack {
|
||||
var stickerPackReference: StickerPackReference?
|
||||
for attribute in file.attributes {
|
||||
if case let .Sticker(sticker) = attribute {
|
||||
if let packReference = sticker.packReference {
|
||||
if case let .Sticker(_, packReferenceValue, _) = attribute {
|
||||
if let packReference = packReferenceValue {
|
||||
stickerPackReference = packReference
|
||||
}
|
||||
}
|
||||
|
|
@ -599,7 +593,7 @@ func revalidateMediaResourceReference(postbox: Postbox, network: Network, revali
|
|||
case let .standalone(media):
|
||||
if let file = media as? TelegramMediaFile {
|
||||
for attribute in file.attributes {
|
||||
if case let .Sticker(sticker) = attribute, let stickerPack = sticker.packReference {
|
||||
if case let .Sticker(_, packReferenceValue, _) = attribute, let stickerPack = packReferenceValue {
|
||||
return revalidationContext.stickerPack(postbox: postbox, network: network, background: info.preferBackgroundReferenceRevalidation, stickerPack: stickerPack)
|
||||
|> mapToSignal { result -> Signal<RevalidatedMediaResource, RevalidateMediaReferenceError> in
|
||||
for item in result.1 {
|
||||
|
|
|
|||
|
|
@ -32,8 +32,10 @@ private final class MultipartDownloadState {
|
|||
assert(decryptedData.count % 16 == 0)
|
||||
let decryptedDataCount = decryptedData.count
|
||||
assert(offset == Int(self.currentSize))
|
||||
decryptedData.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<UInt8>) -> Void in
|
||||
self.aesIv.withUnsafeMutableBytes { (iv: UnsafeMutablePointer<UInt8>) -> Void in
|
||||
decryptedData.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
self.aesIv.withUnsafeMutableBytes { rawIv -> Void in
|
||||
let iv = rawIv.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
MTAesDecryptBytesInplaceAndModifyIv(bytes, decryptedDataCount, self.aesKey, iv)
|
||||
}
|
||||
}
|
||||
|
|
@ -507,7 +509,8 @@ private enum MultipartFetchSource {
|
|||
} else {
|
||||
var partIv = iv
|
||||
let partIvCount = partIv.count
|
||||
partIv.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<Int8>) -> Void in
|
||||
partIv.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
var ivOffset: Int32 = (offset / 16).bigEndian
|
||||
memcpy(bytes.advanced(by: partIvCount - 4), &ivOffset, 4)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ private struct UploadPart {
|
|||
}
|
||||
|
||||
private func md5(_ data: Data) -> Data {
|
||||
return data.withUnsafeBytes { bytes -> Data in
|
||||
return data.withUnsafeBytes { rawBytes -> Data in
|
||||
let bytes = rawBytes.baseAddress!
|
||||
return CryptoMD5(bytes, Int32(data.count))
|
||||
}
|
||||
}
|
||||
|
|
@ -54,11 +55,13 @@ private final class MultipartUploadState {
|
|||
encryptedData.count = encryptedData.count + paddingSize
|
||||
}
|
||||
let encryptedDataCount = encryptedData.count
|
||||
encryptedData.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<UInt8>) -> Void in
|
||||
encryptedData.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
if paddingSize != 0 {
|
||||
arc4random_buf(bytes.advanced(by: encryptedDataCount - paddingSize), paddingSize)
|
||||
}
|
||||
self.aesIv.withUnsafeMutableBytes { (iv: UnsafeMutablePointer<UInt8>) -> Void in
|
||||
self.aesIv.withUnsafeMutableBytes { rawIv -> Void in
|
||||
let iv = rawIv.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
MTAesEncryptBytesInplaceAndModifyIv(bytes, encryptedDataCount, self.aesKey, iv)
|
||||
}
|
||||
}
|
||||
|
|
@ -411,10 +414,12 @@ func multipartUpload(network: Network, postbox: Postbox, source: MultipartUpload
|
|||
aesKey.count = 32
|
||||
var aesIv = Data()
|
||||
aesIv.count = 32
|
||||
aesKey.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<UInt8>) -> Void in
|
||||
aesKey.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!
|
||||
arc4random_buf(bytes, 32)
|
||||
}
|
||||
aesIv.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<UInt8>) -> Void in
|
||||
aesIv.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!
|
||||
arc4random_buf(bytes, 32)
|
||||
}
|
||||
encryptionKey = SecretFileEncryptionKey(aesKey: aesKey, aesIv: aesIv)
|
||||
|
|
@ -466,7 +471,9 @@ func multipartUpload(network: Network, postbox: Postbox, source: MultipartUpload
|
|||
if let encryptionKey = encryptionKey {
|
||||
let keyDigest = md5(encryptionKey.aesKey + encryptionKey.aesIv)
|
||||
var fingerprint: Int32 = 0
|
||||
keyDigest.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||
keyDigest.withUnsafeBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
withUnsafeMutableBytes(of: &fingerprint, { ptr -> Void in
|
||||
let uintPtr = ptr.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
uintPtr[0] = bytes[0] ^ bytes[4]
|
||||
|
|
|
|||
|
|
@ -480,13 +480,10 @@ func initializedNetwork(accountId: AccountRecordId, arguments: NetworkInitializa
|
|||
let key = SharedContextStore.Key(accountId: accountId)
|
||||
|
||||
let context: MTContext
|
||||
if false, let current = store.contexts[key] {
|
||||
context = current
|
||||
context.updateApiEnvironment({ _ in return apiEnvironment})
|
||||
} else {
|
||||
context = MTContext(serialization: serialization, encryptionProvider: arguments.encryptionProvider, apiEnvironment: apiEnvironment, isTestingEnvironment: testingEnvironment, useTempAuthKeys: useTempAuthKeys)
|
||||
store.contexts[key] = context
|
||||
}
|
||||
|
||||
context = MTContext(serialization: serialization, encryptionProvider: arguments.encryptionProvider, apiEnvironment: apiEnvironment, isTestingEnvironment: testingEnvironment, useTempAuthKeys: useTempAuthKeys)
|
||||
store.contexts[key] = context
|
||||
|
||||
contextValue = context
|
||||
}
|
||||
|
||||
|
|
@ -627,7 +624,7 @@ private final class NetworkHelper: NSObject, MTContextChangeListener {
|
|||
self.contextLoggedOutUpdated = contextLoggedOutUpdated
|
||||
}
|
||||
|
||||
func fetchContextDatacenterPublicKeys(_ context: MTContext!, datacenterId: Int) -> MTSignal! {
|
||||
func fetchContextDatacenterPublicKeys(_ context: MTContext, datacenterId: Int) -> MTSignal {
|
||||
return MTSignal { subscriber in
|
||||
let disposable = self.requestPublicKeys(datacenterId).start(next: { next in
|
||||
subscriber?.putNext(next)
|
||||
|
|
@ -640,7 +637,7 @@ private final class NetworkHelper: NSObject, MTContextChangeListener {
|
|||
}
|
||||
}
|
||||
|
||||
func isContextNetworkAccessAllowed(_ context: MTContext!) -> MTSignal! {
|
||||
func isContextNetworkAccessAllowed(_ context: MTContext) -> MTSignal {
|
||||
return MTSignal { subscriber in
|
||||
let disposable = self.isContextNetworkAccessAllowedImpl().start(next: { next in
|
||||
subscriber?.putNext(next as NSNumber)
|
||||
|
|
@ -653,12 +650,12 @@ private final class NetworkHelper: NSObject, MTContextChangeListener {
|
|||
}
|
||||
}
|
||||
|
||||
func contextApiEnvironmentUpdated(_ context: MTContext!, apiEnvironment: MTApiEnvironment!) {
|
||||
func contextApiEnvironmentUpdated(_ context: MTContext, apiEnvironment: MTApiEnvironment) {
|
||||
let settings: MTSocksProxySettings? = apiEnvironment.socksProxySettings
|
||||
self.contextProxyIdUpdated(settings.flatMap(NetworkContextProxyId.init(settings:)))
|
||||
}
|
||||
|
||||
func contextLoggedOut(_ context: MTContext!) {
|
||||
func contextLoggedOut(_ context: MTContext) {
|
||||
self.contextLoggedOutUpdated()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1090,9 +1090,8 @@ extension GroupStatsTopInviter {
|
|||
extension GroupStats {
|
||||
convenience init(apiMegagroupStats: Api.stats.MegagroupStats) {
|
||||
switch apiMegagroupStats {
|
||||
case let .megagroupStats(period, members, messages, viewers, posters, apiGrowthGraph, apiMembersGraph, apiNewMembersBySourceGraph, apiLanguagesGraph, apiMessagesGraph, apiActionsGraph, apiTopHoursGraph, apiTopWeekdaysGraph, topPosters, topAdmins, topInviters, users):
|
||||
case let .megagroupStats(period, members, messages, viewers, posters, apiGrowthGraph, apiMembersGraph, apiNewMembersBySourceGraph, apiLanguagesGraph, apiMessagesGraph, apiActionsGraph, apiTopHoursGraph, apiTopWeekdaysGraph, topPosters, topAdmins, topInviters, _):
|
||||
let growthGraph = StatsGraph(apiStatsGraph: apiGrowthGraph)
|
||||
let isEmpty = growthGraph.isEmpty
|
||||
|
||||
self.init(period: StatsDateRange(apiStatsDateRangeDays: period), members: StatsValue(apiStatsAbsValueAndPrev: members), messages: StatsValue(apiStatsAbsValueAndPrev: messages), viewers: StatsValue(apiStatsAbsValueAndPrev: viewers), posters: StatsValue(apiStatsAbsValueAndPrev: posters), growthGraph: growthGraph, membersGraph: StatsGraph(apiStatsGraph: apiMembersGraph), newMembersBySourceGraph: StatsGraph(apiStatsGraph: apiNewMembersBySourceGraph), languagesGraph: StatsGraph(apiStatsGraph: apiLanguagesGraph), messagesGraph: StatsGraph(apiStatsGraph: apiMessagesGraph), actionsGraph: StatsGraph(apiStatsGraph: apiActionsGraph), topHoursGraph: StatsGraph(apiStatsGraph: apiTopHoursGraph), topWeekdaysGraph: StatsGraph(apiStatsGraph: apiTopWeekdaysGraph), topPosters: topPosters.map { GroupStatsTopPoster(apiStatsGroupTopPoster: $0) }, topAdmins: topAdmins.map { GroupStatsTopAdmin(apiStatsGroupTopAdmin: $0) }, topInviters: topInviters.map { GroupStatsTopInviter(apiStatsGroupTopInviter: $0) })
|
||||
}
|
||||
|
|
|
|||
|
|
@ -345,7 +345,7 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId,
|
|||
globallyUniqueIds.append(randomId)
|
||||
|
||||
switch message {
|
||||
case let .message(text, requestedAttributes, mediaReference, replyToMessageId, localGroupingKey, correlationId):
|
||||
case let .message(text, requestedAttributes, mediaReference, replyToMessageId, localGroupingKey, _):
|
||||
var peerAutoremoveTimeout: Int32?
|
||||
if let peer = peer as? TelegramSecretChat {
|
||||
var isAction = false
|
||||
|
|
@ -517,7 +517,7 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId,
|
|||
}
|
||||
|
||||
storeMessages.append(StoreMessage(peerId: peerId, namespace: messageNamespace, globallyUniqueId: randomId, groupingKey: localGroupingKey, threadId: threadId, timestamp: effectiveTimestamp, flags: flags, tags: tags, globalTags: globalTags, localTags: localTags, forwardInfo: nil, authorId: authorId, text: text, attributes: attributes, media: mediaList))
|
||||
case let .forward(source, grouping, requestedAttributes, correlationId):
|
||||
case let .forward(source, grouping, requestedAttributes, _):
|
||||
let sourceMessage = transaction.getMessage(source)
|
||||
if let sourceMessage = sourceMessage, let author = sourceMessage.author ?? sourceMessage.peers[sourceMessage.id.peerId] {
|
||||
var messageText = sourceMessage.text
|
||||
|
|
|
|||
|
|
@ -107,8 +107,8 @@ func mediaContentToUpload(network: Network, postbox: Postbox, auxiliaryMethods:
|
|||
if let resource = file.resource as? CloudDocumentMediaResource {
|
||||
if peerId.namespace == Namespaces.Peer.SecretChat {
|
||||
for attribute in file.attributes {
|
||||
if case let .Sticker(sticker) = attribute {
|
||||
if let _ = sticker.packReference {
|
||||
if case let .Sticker(_, packReferenceValue, _) = attribute {
|
||||
if let _ = packReferenceValue {
|
||||
return .single(.content(PendingMessageUploadedContentAndReuploadInfo(content: PendingMessageUploadedContent.text(text), reuploadInfo: nil)))
|
||||
}
|
||||
}
|
||||
|
|
@ -234,7 +234,9 @@ private func maybePredownloadedImageResource(postbox: Postbox, peerId: PeerId, r
|
|||
if data.complete {
|
||||
if data.size < 5 * 1024 * 1024, let fileData = try? Data(contentsOf: URL(fileURLWithPath: data.path), options: .mappedRead) {
|
||||
let md5 = IncrementalMD5()
|
||||
fileData.withUnsafeBytes { (bytes: UnsafePointer<Int8>) -> Void in
|
||||
fileData.withUnsafeBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: Int8.self)
|
||||
|
||||
var offset = 0
|
||||
let bufferSize = 32 * 1024
|
||||
|
||||
|
|
@ -252,7 +254,7 @@ private func maybePredownloadedImageResource(postbox: Postbox, peerId: PeerId, r
|
|||
subscriber.putNext(.single(.localReference(reference)))
|
||||
} else {
|
||||
subscriber.putNext(cachedSentMediaReference(postbox: postbox, key: reference)
|
||||
|> mapError { _ -> PendingMessageUploadError in return .generic } |> map { media -> PredownloadedResource in
|
||||
|> mapError { _ -> PendingMessageUploadError in } |> map { media -> PredownloadedResource in
|
||||
if let media = media {
|
||||
return .media(media)
|
||||
} else {
|
||||
|
|
@ -302,7 +304,7 @@ private func maybePredownloadedFileResource(postbox: Postbox, auxiliaryMethods:
|
|||
return .single(.localReference(nil))
|
||||
}
|
||||
}
|
||||
|> mapError { _ -> PendingMessageUploadError in return .generic }
|
||||
|> mapError { _ -> PendingMessageUploadError in }
|
||||
}
|
||||
|
||||
private func maybeCacheUploadedResource(postbox: Postbox, key: CachedSentMediaReferenceKey?, result: PendingMessageUploadedContentResult, media: Media) -> Signal<PendingMessageUploadedContentResult, PendingMessageUploadError> {
|
||||
|
|
@ -310,7 +312,7 @@ private func maybeCacheUploadedResource(postbox: Postbox, key: CachedSentMediaRe
|
|||
return postbox.transaction { transaction -> PendingMessageUploadedContentResult in
|
||||
storeCachedSentMediaReference(transaction: transaction, key: key, media: media)
|
||||
return result
|
||||
} |> mapError { _ -> PendingMessageUploadError in return .generic }
|
||||
} |> mapError { _ -> PendingMessageUploadError in }
|
||||
} else {
|
||||
return .single(result)
|
||||
}
|
||||
|
|
@ -391,7 +393,6 @@ private func uploadedMediaImageContent(network: Network, postbox: Postbox, trans
|
|||
|
||||
return transform
|
||||
|> mapError { _ -> PendingMessageUploadError in
|
||||
return .generic
|
||||
}
|
||||
|> mapToSignal { transformResult -> Signal<PendingMessageUploadedContentResult, PendingMessageUploadError> in
|
||||
switch transformResult {
|
||||
|
|
@ -440,7 +441,7 @@ private func uploadedMediaImageContent(network: Network, postbox: Postbox, trans
|
|||
return postbox.transaction { transaction -> Api.InputPeer? in
|
||||
return transaction.getPeer(peerId).flatMap(apiInputPeer)
|
||||
}
|
||||
|> mapError { _ -> PendingMessageUploadError in return .generic }
|
||||
|> mapError { _ -> PendingMessageUploadError in }
|
||||
|> mapToSignal { inputPeer -> Signal<PendingMessageUploadedContentResult, PendingMessageUploadError> in
|
||||
if let inputPeer = inputPeer {
|
||||
if autoclearMessageAttribute != nil {
|
||||
|
|
@ -774,7 +775,7 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, auxili
|
|||
return postbox.transaction { transaction -> Api.InputPeer? in
|
||||
return transaction.getPeer(peerId).flatMap(apiInputPeer)
|
||||
}
|
||||
|> mapError { _ -> PendingMessageUploadError in return .generic }
|
||||
|> mapError { _ -> PendingMessageUploadError in }
|
||||
|> mapToSignal { inputPeer -> Signal<PendingMessageUploadedContentResult, PendingMessageUploadError> in
|
||||
if let inputPeer = inputPeer {
|
||||
return network.request(Api.functions.messages.uploadMedia(peer: inputPeer, media: .inputMediaUploadedDocument(flags: flags, file: inputFile, thumb: thumbnailFile, mimeType: file.mimeType, attributes: inputDocumentAttributesFromFileAttributes(file.attributes), stickers: stickers, ttlSeconds: ttlSeconds)))
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ private func requestEditMessageInternal(postbox: Postbox, network: Network, stat
|
|||
}
|
||||
}
|
||||
return uploadedMedia
|
||||
|> mapError { _ -> RequestEditMessageInternalError in return .error(.generic) }
|
||||
|> mapError { _ -> RequestEditMessageInternalError in }
|
||||
|> mapToSignal { uploadedMediaResult -> Signal<RequestEditMessageResult, RequestEditMessageInternalError> in
|
||||
var pendingMediaContent: PendingMessageUploadedContent?
|
||||
if let uploadedMediaResult = uploadedMediaResult {
|
||||
|
|
@ -122,7 +122,7 @@ private func requestEditMessageInternal(postbox: Postbox, network: Network, stat
|
|||
}
|
||||
return (transaction.getPeer(messageId.peerId), message, peers)
|
||||
}
|
||||
|> mapError { _ -> RequestEditMessageInternalError in return .error(.generic) }
|
||||
|> mapError { _ -> RequestEditMessageInternalError in }
|
||||
|> mapToSignal { peer, message, associatedPeers -> Signal<RequestEditMessageResult, RequestEditMessageInternalError> in
|
||||
if let peer = peer, let message = message, let inputPeer = apiInputPeer(peer) {
|
||||
var flags: Int32 = 1 << 11
|
||||
|
|
@ -241,7 +241,6 @@ private func requestEditMessageInternal(postbox: Postbox, network: Network, stat
|
|||
return .done(true)
|
||||
}
|
||||
|> mapError { _ -> RequestEditMessageInternalError in
|
||||
return .error(.generic)
|
||||
}
|
||||
} else {
|
||||
return .single(.done(false))
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public func standaloneSendMessage(account: Account, peerId: PeerId, text: String
|
|||
return .single(progress)
|
||||
case let .result(result):
|
||||
let sendContent = sendMessageContent(account: account, peerId: peerId, attributes: attributes, content: result) |> map({ _ -> Float in return 1.0 })
|
||||
return .single(1.0) |> then(sendContent |> mapError { _ -> StandaloneSendMessageError in return .generic })
|
||||
return .single(1.0) |> then(sendContent |> mapError { _ -> StandaloneSendMessageError in })
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -128,7 +128,6 @@ private func sendMessageContent(account: Account, peerId: PeerId, attributes: [M
|
|||
return .complete()
|
||||
}
|
||||
|> `catch` { _ -> Signal<Void, NoError> in
|
||||
return .complete()
|
||||
}
|
||||
} else {
|
||||
return .complete()
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public func standaloneUploadedImage(account: Account, peerId: PeerId, text: Stri
|
|||
return account.postbox.transaction { transaction -> Api.InputPeer? in
|
||||
return transaction.getPeer(peerId).flatMap(apiInputPeer)
|
||||
}
|
||||
|> mapError { _ -> StandaloneUploadMediaError in return .generic }
|
||||
|> mapError { _ -> StandaloneUploadMediaError in }
|
||||
|> mapToSignal { inputPeer -> Signal<StandaloneUploadMediaEvent, StandaloneUploadMediaError> in
|
||||
if let inputPeer = inputPeer {
|
||||
return account.network.request(Api.functions.messages.uploadMedia(peer: inputPeer, media: Api.InputMedia.inputMediaUploadedPhoto(flags: 0, file: inputFile, stickers: nil, ttlSeconds: nil)))
|
||||
|
|
@ -150,7 +150,7 @@ public func standaloneUploadedFile(account: Account, peerId: PeerId, text: Strin
|
|||
return account.postbox.transaction { transaction -> Api.InputPeer? in
|
||||
return transaction.getPeer(peerId).flatMap(apiInputPeer)
|
||||
}
|
||||
|> mapError { _ -> StandaloneUploadMediaError in return .generic }
|
||||
|> mapError { _ -> StandaloneUploadMediaError in }
|
||||
|> mapToSignal { inputPeer -> Signal<StandaloneUploadMediaEvent, StandaloneUploadMediaError> in
|
||||
if let inputPeer = inputPeer {
|
||||
var flags: Int32 = 0
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ private func messageKey(key: SecretChatKey, msgKey: UnsafeRawPointer, mode: Secr
|
|||
|
||||
var sha1AData = Data()
|
||||
sha1AData.count = 16 + 32
|
||||
sha1AData.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<UInt8>) -> Void in
|
||||
sha1AData.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
memcpy(bytes, msgKey, 16)
|
||||
memcpy(bytes.advanced(by: 16), key.key.memory.advanced(by: x), 32)
|
||||
}
|
||||
|
|
@ -18,7 +20,9 @@ private func messageKey(key: SecretChatKey, msgKey: UnsafeRawPointer, mode: Secr
|
|||
|
||||
var sha1BData = Data()
|
||||
sha1BData.count = 16 + 16 + 16
|
||||
sha1BData.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<UInt8>) -> Void in
|
||||
sha1BData.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
memcpy(bytes, key.key.memory.advanced(by: 32 + x), 16)
|
||||
memcpy(bytes.advanced(by: 16), msgKey, 16)
|
||||
memcpy(bytes.advanced(by: 16 + 16), key.key.memory.advanced(by: 48 + x), 16)
|
||||
|
|
@ -27,7 +31,9 @@ private func messageKey(key: SecretChatKey, msgKey: UnsafeRawPointer, mode: Secr
|
|||
|
||||
var sha1CData = Data()
|
||||
sha1CData.count = 32 + 16
|
||||
sha1CData.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<UInt8>) -> Void in
|
||||
sha1CData.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
memcpy(bytes, key.key.memory.advanced(by: 64 + x), 32)
|
||||
memcpy(bytes.advanced(by: 32), msgKey, 16)
|
||||
}
|
||||
|
|
@ -35,7 +41,9 @@ private func messageKey(key: SecretChatKey, msgKey: UnsafeRawPointer, mode: Secr
|
|||
|
||||
var sha1DData = Data()
|
||||
sha1DData.count = 16 + 32
|
||||
sha1DData.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<UInt8>) -> Void in
|
||||
sha1DData.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
memcpy(bytes, msgKey, 16)
|
||||
memcpy(bytes.advanced(by: 16), key.key.memory.advanced(by: 96 + x), 32)
|
||||
}
|
||||
|
|
@ -43,32 +51,36 @@ private func messageKey(key: SecretChatKey, msgKey: UnsafeRawPointer, mode: Secr
|
|||
|
||||
var aesKey = Data()
|
||||
aesKey.count = 8 + 12 + 12
|
||||
aesKey.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<UInt8>) -> Void in
|
||||
sha1A.withUnsafeBytes { (sha1A: UnsafePointer<UInt8>) -> Void in
|
||||
memcpy(bytes, sha1A, 8)
|
||||
aesKey.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
sha1A.withUnsafeBytes { sha1A -> Void in
|
||||
memcpy(bytes, sha1A.baseAddress!.assumingMemoryBound(to: UInt8.self), 8)
|
||||
}
|
||||
sha1B.withUnsafeBytes { (sha1B: UnsafePointer<UInt8>) -> Void in
|
||||
memcpy(bytes.advanced(by: 8), sha1B.advanced(by: 8), 12)
|
||||
sha1B.withUnsafeBytes { sha1B -> Void in
|
||||
memcpy(bytes.advanced(by: 8), sha1B.baseAddress!.assumingMemoryBound(to: UInt8.self).advanced(by: 8), 12)
|
||||
}
|
||||
sha1C.withUnsafeBytes { (sha1C: UnsafePointer<UInt8>) -> Void in
|
||||
memcpy(bytes.advanced(by: 8 + 12), sha1C.advanced(by: 4), 12)
|
||||
sha1C.withUnsafeBytes { sha1C -> Void in
|
||||
memcpy(bytes.advanced(by: 8 + 12), sha1C.baseAddress!.assumingMemoryBound(to: UInt8.self).advanced(by: 4), 12)
|
||||
}
|
||||
}
|
||||
|
||||
var aesIv = Data()
|
||||
aesIv.count = 12 + 8 + 4 + 8
|
||||
aesIv.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<UInt8>) -> Void in
|
||||
sha1A.withUnsafeBytes { (sha1A: UnsafePointer<UInt8>) -> Void in
|
||||
memcpy(bytes, sha1A.advanced(by: 8), 12)
|
||||
aesIv.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
sha1A.withUnsafeBytes { sha1A -> Void in
|
||||
memcpy(bytes, sha1A.baseAddress!.assumingMemoryBound(to: UInt8.self).advanced(by: 8), 12)
|
||||
}
|
||||
sha1B.withUnsafeBytes { (sha1B: UnsafePointer<UInt8>) -> Void in
|
||||
memcpy(bytes.advanced(by: 12), sha1B, 8)
|
||||
sha1B.withUnsafeBytes { sha1B -> Void in
|
||||
memcpy(bytes.advanced(by: 12), sha1B.baseAddress!.assumingMemoryBound(to: UInt8.self), 8)
|
||||
}
|
||||
sha1C.withUnsafeBytes { (sha1C: UnsafePointer<UInt8>) -> Void in
|
||||
memcpy(bytes.advanced(by: 12 + 8), sha1C.advanced(by: 16), 4)
|
||||
sha1C.withUnsafeBytes { sha1C -> Void in
|
||||
memcpy(bytes.advanced(by: 12 + 8), sha1C.baseAddress!.assumingMemoryBound(to: UInt8.self).advanced(by: 16), 4)
|
||||
}
|
||||
sha1D.withUnsafeBytes { (sha1D: UnsafePointer<UInt8>) -> Void in
|
||||
memcpy(bytes.advanced(by: 12 + 8 + 4), sha1D, 8)
|
||||
sha1D.withUnsafeBytes { sha1D -> Void in
|
||||
memcpy(bytes.advanced(by: 12 + 8 + 4), sha1D.baseAddress!.assumingMemoryBound(to: UInt8.self), 8)
|
||||
}
|
||||
}
|
||||
return (aesKey, aesIv)
|
||||
|
|
@ -127,7 +139,9 @@ func withDecryptedMessageContents(parameters: SecretChatEncryptionParameters, da
|
|||
}
|
||||
|
||||
var payloadLength: Int32 = 0
|
||||
decryptedData.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||
decryptedData.withUnsafeBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
memcpy(&payloadLength, bytes, 4)
|
||||
}
|
||||
|
||||
|
|
@ -137,7 +151,9 @@ func withDecryptedMessageContents(parameters: SecretChatEncryptionParameters, da
|
|||
}
|
||||
|
||||
let calculatedMsgKeyData = MTSubdataSha1(decryptedData, 0, UInt(payloadLength) + 4)
|
||||
let msgKeyMatches = calculatedMsgKeyData.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Bool in
|
||||
let msgKeyMatches = calculatedMsgKeyData.withUnsafeBytes { rawBytes -> Bool in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
return memcmp(bytes.advanced(by: calculatedMsgKeyData.count - 16), msgKey, 16) == 0
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +161,9 @@ func withDecryptedMessageContents(parameters: SecretChatEncryptionParameters, da
|
|||
return nil
|
||||
}
|
||||
|
||||
let result = decryptedData.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Data in
|
||||
let result = decryptedData.withUnsafeBytes { rawBytes -> Data in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
return Data(bytes: bytes.advanced(by: 4), count: Int(payloadLength))
|
||||
}
|
||||
return MemoryBuffer(data: result)
|
||||
|
|
@ -166,7 +184,9 @@ func withDecryptedMessageContents(parameters: SecretChatEncryptionParameters, da
|
|||
}
|
||||
|
||||
var payloadLength: Int32 = 0
|
||||
decryptedData.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||
decryptedData.withUnsafeBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
memcpy(&payloadLength, bytes, 4)
|
||||
}
|
||||
|
||||
|
|
@ -203,7 +223,9 @@ func withDecryptedMessageContents(parameters: SecretChatEncryptionParameters, da
|
|||
return nil
|
||||
}
|
||||
|
||||
let result = decryptedData.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Data in
|
||||
let result = decryptedData.withUnsafeBytes { rawBytes -> Data in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
return Data(bytes: bytes.advanced(by: 4), count: Int(payloadLength))
|
||||
}
|
||||
return MemoryBuffer(data: result)
|
||||
|
|
@ -233,7 +255,7 @@ func encryptedMessageContents(parameters: SecretChatEncryptionParameters, data:
|
|||
var msgKey = MTSha1(payloadData)
|
||||
msgKey.replaceSubrange(0 ..< (msgKey.count - 16), with: Data())
|
||||
|
||||
var randomBuf = malloc(16)!
|
||||
let randomBuf = malloc(16)!
|
||||
defer {
|
||||
free(randomBuf)
|
||||
}
|
||||
|
|
@ -246,7 +268,9 @@ func encryptedMessageContents(parameters: SecretChatEncryptionParameters, data:
|
|||
randomIndex += 1
|
||||
}
|
||||
|
||||
let (aesKey, aesIv) = msgKey.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> (Data, Data) in
|
||||
let (aesKey, aesIv) = msgKey.withUnsafeBytes { rawBytes -> (Data, Data) in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
return messageKey(key: parameters.key, msgKey: bytes, mode: parameters.mode)
|
||||
}
|
||||
|
||||
|
|
@ -262,7 +286,9 @@ func encryptedMessageContents(parameters: SecretChatEncryptionParameters, data:
|
|||
case let .v2(role):
|
||||
var randomBytes = Data(count: 128)
|
||||
let randomBytesCount = randomBytes.count
|
||||
randomBytes.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<Int8>) -> Void in
|
||||
randomBytes.withUnsafeMutableBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: Int8.self)
|
||||
|
||||
arc4random_buf(bytes, randomBytesCount)
|
||||
}
|
||||
|
||||
|
|
@ -305,7 +331,9 @@ func encryptedMessageContents(parameters: SecretChatEncryptionParameters, data:
|
|||
|
||||
let msgKey = keyLarge.subdata(in: 8 ..< (8 + 16))
|
||||
|
||||
let (aesKey, aesIv) = msgKey.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> (Data, Data) in
|
||||
let (aesKey, aesIv) = msgKey.withUnsafeBytes { rawBytes -> (Data, Data) in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
return messageKey(key: parameters.key, msgKey: bytes, mode: parameters.mode)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ func secretChatAdvanceRekeySessionIfNeeded(encryptionProvider: EncryptionProvide
|
|||
if let rekeySession = sequenceState.rekeyState, rekeySession.id == rekeySessionId {
|
||||
switch rekeySession.data {
|
||||
case let .requested(a, config):
|
||||
var gValue: Int32 = config.g.byteSwapped
|
||||
//var gValue: Int32 = config.g.byteSwapped
|
||||
let p = config.p.makeData()
|
||||
|
||||
let aData = a.makeData()
|
||||
|
|
@ -62,7 +62,9 @@ func secretChatAdvanceRekeySessionIfNeeded(encryptionProvider: EncryptionProvide
|
|||
let keyHash = MTSha1(key)
|
||||
|
||||
var keyFingerprint: Int64 = 0
|
||||
keyHash.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||
keyHash.withUnsafeBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
memcpy(&keyFingerprint, bytes.advanced(by: keyHash.count - 8), 8)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ struct SecretChatRequestData {
|
|||
func updateSecretChat(encryptionProvider: EncryptionProvider, accountPeerId: PeerId, transaction: Transaction, mediaBox: MediaBox, chat: Api.EncryptedChat, requestData: SecretChatRequestData?) {
|
||||
let currentPeer = transaction.getPeer(chat.peerId) as? TelegramSecretChat
|
||||
let currentState = transaction.getPeerChatState(chat.peerId) as? SecretChatState
|
||||
let settings = transaction.getPreferencesEntry(key: PreferencesKeys.secretChatSettings) as? SecretChatSettings ?? SecretChatSettings.defaultSettings
|
||||
let settings = transaction.getPreferencesEntry(key: PreferencesKeys.secretChatSettings)?.get(SecretChatSettings.self) ?? SecretChatSettings.defaultSettings
|
||||
assert((currentPeer == nil) == (currentState == nil))
|
||||
switch chat {
|
||||
case let .encryptedChat(_, _, _, adminId, _, gAOrB, remoteKeyFingerprint):
|
||||
case let .encryptedChat(_, _, _, adminId, _, gAOrB, _):
|
||||
if let currentPeer = currentPeer, let currentState = currentState, adminId == accountPeerId.id._internalGetInt64Value() {
|
||||
if case let .handshake(handshakeState) = currentState.embeddedState, case let .requested(_, p, a) = handshakeState {
|
||||
let pData = p.makeData()
|
||||
|
|
@ -43,7 +43,9 @@ func updateSecretChat(encryptionProvider: EncryptionProvider, accountPeerId: Pee
|
|||
let keyHash = MTSha1(key)
|
||||
|
||||
var keyFingerprint: Int64 = 0
|
||||
keyHash.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||
keyHash.withUnsafeBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
memcpy(&keyFingerprint, bytes.advanced(by: keyHash.count - 8), 8)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,14 +24,14 @@ private extension ContentSettings {
|
|||
}
|
||||
|
||||
public func getContentSettings(transaction: Transaction) -> ContentSettings {
|
||||
let appConfiguration: AppConfiguration = transaction.getPreferencesEntry(key: PreferencesKeys.appConfiguration) as? AppConfiguration ?? AppConfiguration.defaultValue
|
||||
let appConfiguration: AppConfiguration = transaction.getPreferencesEntry(key: PreferencesKeys.appConfiguration)?.get(AppConfiguration.self) ?? AppConfiguration.defaultValue
|
||||
return ContentSettings(appConfiguration: appConfiguration)
|
||||
}
|
||||
|
||||
public func getContentSettings(postbox: Postbox) -> Signal<ContentSettings, NoError> {
|
||||
return postbox.preferencesView(keys: [PreferencesKeys.appConfiguration])
|
||||
|> map { view -> ContentSettings in
|
||||
let appConfiguration: AppConfiguration = view.values[PreferencesKeys.appConfiguration] as? AppConfiguration ?? AppConfiguration.defaultValue
|
||||
let appConfiguration: AppConfiguration = view.values[PreferencesKeys.appConfiguration]?.get(AppConfiguration.self) ?? AppConfiguration.defaultValue
|
||||
return ContentSettings(appConfiguration: appConfiguration)
|
||||
}
|
||||
|> distinctUntilChanged
|
||||
|
|
|
|||
|
|
@ -215,12 +215,12 @@ private func activeChannelsFromDifference(_ difference: Api.updates.Difference)
|
|||
|
||||
var chats: [Api.Chat] = []
|
||||
switch difference {
|
||||
case let .difference(difference):
|
||||
chats = difference.chats
|
||||
case let .difference(_, _, _, differenceChats, _, _):
|
||||
chats = differenceChats
|
||||
case .differenceEmpty:
|
||||
break
|
||||
case let .differenceSlice(differenceSlice):
|
||||
chats = differenceSlice.chats
|
||||
case let .differenceSlice(_, _, _, differenceChats, _, _):
|
||||
chats = differenceChats
|
||||
case .differenceTooLong:
|
||||
break
|
||||
}
|
||||
|
|
@ -466,7 +466,7 @@ private func initialStateWithPeerIds(_ transaction: Transaction, peerIds: Set<Pe
|
|||
}
|
||||
}
|
||||
|
||||
var state = AccountMutableState(initialState: AccountInitialState(state: (transaction.getState() as? AuthorizedAccountState)!.state!, peerIds: peerIds, peerIdsRequiringLocalChatState: peerIdsRequiringLocalChatState, channelStates: channelStates, peerChatInfos: peerChatInfos, locallyGeneratedMessageTimestamps: locallyGeneratedMessageTimestamps, cloudReadStates: cloudReadStates, channelsToPollExplicitely: channelsToPollExplicitely), initialPeers: peers, initialReferencedMessageIds: associatedMessageIds, initialStoredMessages: storedMessages, initialReadInboxMaxIds: readInboxMaxIds, storedMessagesByPeerIdAndTimestamp: storedMessagesByPeerIdAndTimestamp)
|
||||
let state = AccountMutableState(initialState: AccountInitialState(state: (transaction.getState() as? AuthorizedAccountState)!.state!, peerIds: peerIds, peerIdsRequiringLocalChatState: peerIdsRequiringLocalChatState, channelStates: channelStates, peerChatInfos: peerChatInfos, locallyGeneratedMessageTimestamps: locallyGeneratedMessageTimestamps, cloudReadStates: cloudReadStates, channelsToPollExplicitely: channelsToPollExplicitely), initialPeers: peers, initialReferencedMessageIds: associatedMessageIds, initialStoredMessages: storedMessages, initialReadInboxMaxIds: readInboxMaxIds, storedMessagesByPeerIdAndTimestamp: storedMessagesByPeerIdAndTimestamp)
|
||||
return state
|
||||
}
|
||||
|
||||
|
|
@ -773,7 +773,7 @@ private func sortedUpdates(_ updates: [Api.Update]) -> [Api.Update] {
|
|||
rhsPts = pts
|
||||
case let .updateEditChannelMessage(_, pts, _):
|
||||
rhsPts = pts
|
||||
case let .updatePinnedChannelMessages(_, channelId, _, pts, _):
|
||||
case let .updatePinnedChannelMessages(_, _, _, pts, _):
|
||||
rhsPts = pts
|
||||
default:
|
||||
break
|
||||
|
|
@ -1190,7 +1190,7 @@ private func finalStateWithUpdatesAndServerTime(postbox: Postbox, network: Netwo
|
|||
})
|
||||
case let .updateUserStatus(userId, status):
|
||||
updatedState.mergePeerPresences([PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId)): status], explicit: true)
|
||||
case let .updateUserName(userId, firstName, lastName, username):
|
||||
case let .updateUserName(userId, _, _, username):
|
||||
//TODO add contact checking for apply first and last name
|
||||
updatedState.updatePeer(PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId)), { peer in
|
||||
if let user = peer as? TelegramUser {
|
||||
|
|
@ -1375,8 +1375,8 @@ private func finalStateWithUpdatesAndServerTime(postbox: Postbox, network: Netwo
|
|||
case let .updateLangPack(difference):
|
||||
let langCode: String
|
||||
switch difference {
|
||||
case let .langPackDifference(langPackDifference):
|
||||
langCode = langPackDifference.langCode
|
||||
case let .langPackDifference(langCodeValue, _, _, _):
|
||||
langCode = langCodeValue
|
||||
}
|
||||
updatedState.updateLangPack(langCode: langCode, difference: difference)
|
||||
case let .updateMessagePoll(_, pollId, poll, results):
|
||||
|
|
@ -1521,6 +1521,7 @@ private func resolveAssociatedMessages(network: Network, state: AccountMutableSt
|
|||
return .single(state)
|
||||
} else {
|
||||
var missingPeers = false
|
||||
let _ = missingPeers
|
||||
|
||||
var signals: [Signal<([Api.Message], [Api.Chat], [Api.User]), NoError>] = []
|
||||
for (peerId, messageIds) in messagesIdsGroupedByPeerId(missingMessageIds) {
|
||||
|
|
@ -2027,7 +2028,7 @@ private func pollChannel(network: Network, peer: Peer, state: AccountMutableStat
|
|||
apiTimeout = timeout
|
||||
|
||||
let channelPts: Int32
|
||||
if let previousState = updatedState.channelStates[peer.id] {
|
||||
if let _ = updatedState.channelStates[peer.id] {
|
||||
channelPts = pts
|
||||
} else {
|
||||
channelPts = pts
|
||||
|
|
@ -2039,7 +2040,7 @@ private func pollChannel(network: Network, peer: Peer, state: AccountMutableStat
|
|||
var parameters: (peer: Api.Peer, pts: Int32, topMessage: Int32, readInboxMaxId: Int32, readOutboxMaxId: Int32, unreadCount: Int32, unreadMentionsCount: Int32)?
|
||||
|
||||
switch dialog {
|
||||
case let .dialog(_, peer, topMessage, readInboxMaxId, readOutboxMaxId, unreadCount, unreadMentionsCount, notifySettings, pts, draft, folderId):
|
||||
case let .dialog(_, peer, topMessage, readInboxMaxId, readOutboxMaxId, unreadCount, unreadMentionsCount, _, pts, _, _):
|
||||
if let pts = pts {
|
||||
parameters = (peer, pts, topMessage, readInboxMaxId, readOutboxMaxId, unreadCount, unreadMentionsCount)
|
||||
}
|
||||
|
|
@ -2592,8 +2593,8 @@ func replayFinalState(accountManager: AccountManager<TelegramAccountManagerTypes
|
|||
var updatedPoll = poll
|
||||
let resultsMin: Bool
|
||||
switch results {
|
||||
case let .pollResults(pollResults):
|
||||
resultsMin = (pollResults.flags & (1 << 0)) != 0
|
||||
case let .pollResults(flags, _, _, _, _, _):
|
||||
resultsMin = (flags & (1 << 0)) != 0
|
||||
}
|
||||
if let apiPoll = apiPoll {
|
||||
switch apiPoll {
|
||||
|
|
@ -2648,7 +2649,7 @@ func replayFinalState(accountManager: AccountManager<TelegramAccountManagerTypes
|
|||
if messageId.peerId != accountPeerId, messageId.peerId.namespace == Namespaces.Peer.CloudUser, let timestamp = timestamp {
|
||||
recordPeerActivityTimestamp(peerId: messageId.peerId, timestamp: timestamp, into: &peerActivityTimestamps)
|
||||
}
|
||||
case let .ReadGroupFeedInbox(groupId, index):
|
||||
case .ReadGroupFeedInbox:
|
||||
break
|
||||
//transaction.applyGroupFeedReadMaxIndex(groupId: groupId, index: index)
|
||||
case let .UpdateReadThread(threadMessageId, readMaxId, isIncoming, mainChannelMessage):
|
||||
|
|
@ -2816,6 +2817,7 @@ func replayFinalState(accountManager: AccountManager<TelegramAccountManagerTypes
|
|||
updated.remote.privateChats = notificationSettings
|
||||
return PreferencesEntry(updated)
|
||||
})
|
||||
transaction.globalNotificationSettingsUpdated()
|
||||
case .groups:
|
||||
transaction.updatePreferencesEntry(key: PreferencesKeys.globalNotifications, { current in
|
||||
var updated: GlobalNotificationSettings
|
||||
|
|
@ -2827,6 +2829,7 @@ func replayFinalState(accountManager: AccountManager<TelegramAccountManagerTypes
|
|||
updated.remote.groupChats = notificationSettings
|
||||
return PreferencesEntry(updated)
|
||||
})
|
||||
transaction.globalNotificationSettingsUpdated()
|
||||
case .channels:
|
||||
transaction.updatePreferencesEntry(key: PreferencesKeys.globalNotifications, { current in
|
||||
var updated: GlobalNotificationSettings
|
||||
|
|
@ -2838,6 +2841,7 @@ func replayFinalState(accountManager: AccountManager<TelegramAccountManagerTypes
|
|||
updated.remote.channels = notificationSettings
|
||||
return PreferencesEntry(updated)
|
||||
})
|
||||
transaction.globalNotificationSettingsUpdated()
|
||||
}
|
||||
case let .MergeApiChats(chats):
|
||||
var peers: [Peer] = []
|
||||
|
|
@ -2970,7 +2974,9 @@ func replayFinalState(accountManager: AccountManager<TelegramAccountManagerTypes
|
|||
case .sync:
|
||||
addSynchronizePinnedChatsOperation(transaction: transaction, groupId: groupId)
|
||||
}
|
||||
case let .ReadMessageContents(peerId, messageIds):
|
||||
case let .ReadMessageContents(peerIdAndMessageIds):
|
||||
let (peerId, messageIds) = peerIdAndMessageIds
|
||||
|
||||
if let peerId = peerId {
|
||||
for id in messageIds {
|
||||
markMessageContentAsConsumedRemotely(transaction: transaction, messageId: MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: id))
|
||||
|
|
|
|||
|
|
@ -416,8 +416,8 @@ public final class AccountStateManager {
|
|||
|> take(1)
|
||||
|> mapToSignal { [weak self] state -> Signal<(difference: Api.updates.Difference?, finalStatte: AccountReplayedFinalState?, skipBecauseOfError: Bool), NoError> in
|
||||
if let authorizedState = state.state {
|
||||
var flags: Int32 = 0
|
||||
var ptsTotalLimit: Int32? = nil
|
||||
let flags: Int32 = 0
|
||||
let ptsTotalLimit: Int32? = nil
|
||||
#if DEBUG
|
||||
//flags = 1 << 0
|
||||
//ptsTotalLimit = 1000
|
||||
|
|
@ -533,9 +533,6 @@ public final class AccountStateManager {
|
|||
assertionFailure()
|
||||
}
|
||||
}
|
||||
}, error: { _ in
|
||||
assertionFailure()
|
||||
Logger.shared.log("AccountStateManager", "processUpdateGroups signal completed with error")
|
||||
})
|
||||
case let .collectUpdateGroups(_, timeout):
|
||||
self.operationTimer?.invalidate()
|
||||
|
|
@ -634,9 +631,7 @@ public final class AccountStateManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
let _ = (signal |> deliverOn(self.queue)).start(error: { _ in
|
||||
completed()
|
||||
}, completed: {
|
||||
let _ = (signal |> deliverOn(self.queue)).start(completed: {
|
||||
completed()
|
||||
})
|
||||
case let .processEvents(operationId, events):
|
||||
|
|
@ -737,8 +732,6 @@ public final class AccountStateManager {
|
|||
if let strongSelf = self {
|
||||
strongSelf.notificationMessagesPipe.putNext(messages)
|
||||
}
|
||||
}, error: { _ in
|
||||
completed()
|
||||
}, completed: {
|
||||
completed()
|
||||
})
|
||||
|
|
@ -833,10 +826,6 @@ public final class AccountStateManager {
|
|||
}
|
||||
completion()
|
||||
}
|
||||
}, error: { _ in
|
||||
assertionFailure()
|
||||
Logger.shared.log("AccountStateManager", "processUpdateGroups signal completed with error")
|
||||
completion()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -1053,7 +1042,7 @@ public final class AccountStateManager {
|
|||
|
||||
if let updates = Api.parse(Buffer(data: rawData)) as? Api.Updates {
|
||||
switch updates {
|
||||
case let .updates(updates, users, chats, date, seq):
|
||||
case let .updates(updates, _, _, _, _):
|
||||
for update in updates {
|
||||
switch update {
|
||||
case let .updatePhoneCall(phoneCall):
|
||||
|
|
@ -1122,7 +1111,7 @@ public func messagesForNotification(transaction: Transaction, id: MessageId, alw
|
|||
if let notificationSettings = transaction.getPeerNotificationSettings(notificationPeerId) as? TelegramPeerNotificationSettings {
|
||||
var defaultSound: PeerMessageSound = .bundledModern(id: 0)
|
||||
var defaultNotify: Bool = true
|
||||
if let globalNotificationSettings = transaction.getPreferencesEntry(key: PreferencesKeys.globalNotifications) as? GlobalNotificationSettings {
|
||||
if let globalNotificationSettings = transaction.getPreferencesEntry(key: PreferencesKeys.globalNotifications)?.get(GlobalNotificationSettings.self) {
|
||||
if id.peerId.namespace == Namespaces.Peer.CloudUser {
|
||||
defaultNotify = globalNotificationSettings.effective.privateChats.enabled
|
||||
defaultSound = globalNotificationSettings.effective.privateChats.sound
|
||||
|
|
|
|||
|
|
@ -1172,7 +1172,7 @@ public final class AccountViewTracker {
|
|||
|
||||
return ids
|
||||
}
|
||||
|> deliverOn(self.queue)).start(next: { [weak self] messageIds in
|
||||
|> deliverOn(self.queue)).start(next: { _ in
|
||||
//self?.updateMarkMentionsSeenForMessageIds(messageIds: messageIds)
|
||||
})
|
||||
}
|
||||
|
|
@ -1585,8 +1585,6 @@ public final class AccountViewTracker {
|
|||
} else {
|
||||
subscriber.putNext([])
|
||||
}
|
||||
}, error: { error in
|
||||
subscriber.putError(error)
|
||||
}, completed: {
|
||||
subscriber.putCompletion()
|
||||
})
|
||||
|
|
@ -1721,7 +1719,7 @@ public final class AccountViewTracker {
|
|||
var currentMessages: [Message] = []
|
||||
for entry in view.entries {
|
||||
switch entry {
|
||||
case let .hole(index):
|
||||
case .hole:
|
||||
if !currentMessages.isEmpty {
|
||||
entries.append(.message(currentMessages[currentMessages.count - 1], currentMessages))
|
||||
currentMessages.removeAll()
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ func managedAppChangelog(postbox: Postbox, network: Network, stateManager: Accou
|
|||
|> take(1)
|
||||
|> mapToSignal { _ -> Signal<Void, NoError> in
|
||||
return postbox.transaction { transaction -> AppChangelogState in
|
||||
return transaction.getPreferencesEntry(key: PreferencesKeys.appChangelogState) as? AppChangelogState ?? AppChangelogState.default
|
||||
return transaction.getPreferencesEntry(key: PreferencesKeys.appChangelogState)?.get(AppChangelogState.self) ?? AppChangelogState.default
|
||||
}
|
||||
|> mapToSignal { appChangelogState -> Signal<Void, NoError> in
|
||||
let appChangelogState = appChangelogState
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@ import MtProtoKit
|
|||
|
||||
func updateAppChangelogState(transaction: Transaction, _ f: @escaping (AppChangelogState) -> AppChangelogState) {
|
||||
transaction.updatePreferencesEntry(key: PreferencesKeys.appChangelogState, { current in
|
||||
return PreferencesEntry(f((current as? AppChangelogState) ?? AppChangelogState.default))
|
||||
return PreferencesEntry(f((current?.get(AppChangelogState.self)) ?? AppChangelogState.default))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,12 +64,12 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes
|
|||
var updatedTimestamp: Int32?
|
||||
if let apiMessage = apiMessage {
|
||||
switch apiMessage {
|
||||
case let .message(message):
|
||||
updatedTimestamp = message.date
|
||||
case let .message(_, _, _, _, _, _, _, date, _, _, _, _, _, _, _, _, _, _, _, _):
|
||||
updatedTimestamp = date
|
||||
case .messageEmpty:
|
||||
break
|
||||
case let .messageService(messageService):
|
||||
updatedTimestamp = messageService.date
|
||||
case let .messageService(_, _, _, _, _, date, _, _):
|
||||
updatedTimestamp = date
|
||||
}
|
||||
} else {
|
||||
switch result {
|
||||
|
|
|
|||
|
|
@ -14,14 +14,16 @@ enum CachedSentMediaReferenceKey {
|
|||
case let .image(hash):
|
||||
let result = ValueBoxKey(length: 1 + hash.count)
|
||||
result.setUInt8(0, value: 0)
|
||||
hash.withUnsafeBytes { (bytes: UnsafePointer<Int8>) -> Void in
|
||||
hash.withUnsafeBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: Int8.self)
|
||||
memcpy(result.memory.advanced(by: 1), bytes, hash.count)
|
||||
}
|
||||
return result
|
||||
case let .file(hash):
|
||||
let result = ValueBoxKey(length: 1 + hash.count)
|
||||
result.setUInt8(0, value: 1)
|
||||
hash.withUnsafeBytes { (bytes: UnsafePointer<Int8>) -> Void in
|
||||
hash.withUnsafeBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: Int8.self)
|
||||
memcpy(result.memory.advanced(by: 1), bytes, hash.count)
|
||||
}
|
||||
return result
|
||||
|
|
|
|||
|
|
@ -562,7 +562,7 @@ private final class CallSessionManagerContext {
|
|||
|> timeout(5.0, queue: strongSelf.queue, alternate: .single(nil))
|
||||
|> deliverOnMainQueue).start(next: { debugLog in
|
||||
if let debugLog = debugLog {
|
||||
_internal_saveCallDebugLog(network: network, callId: CallId(id: id, accessHash: accessHash), log: debugLog).start()
|
||||
let _ = _internal_saveCallDebugLog(network: network, callId: CallId(id: id, accessHash: accessHash), log: debugLog).start()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -688,7 +688,8 @@ private final class CallSessionManagerContext {
|
|||
let keyHash = MTSha1(key)
|
||||
|
||||
var keyId: Int64 = 0
|
||||
keyHash.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||
keyHash.withUnsafeBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
memcpy(&keyId, bytes.advanced(by: keyHash.count - 8), 8)
|
||||
}
|
||||
|
||||
|
|
@ -891,7 +892,8 @@ private final class CallSessionManagerContext {
|
|||
let keyHash = MTSha1(key)
|
||||
|
||||
var keyId: Int64 = 0
|
||||
keyHash.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||
keyHash.withUnsafeBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
memcpy(&keyId, bytes.advanced(by: keyHash.count - 8), 8)
|
||||
}
|
||||
|
||||
|
|
@ -1267,9 +1269,9 @@ private func dropCallSession(network: Network, addUpdates: @escaping (Api.Update
|
|||
switch update {
|
||||
case .updatePhoneCall(let phoneCall):
|
||||
switch phoneCall {
|
||||
case.phoneCallDiscarded(let values):
|
||||
reportRating = (values.flags & (1 << 2)) != 0
|
||||
sendDebugLogs = (values.flags & (1 << 3)) != 0
|
||||
case let .phoneCallDiscarded(flags, _, _, _):
|
||||
reportRating = (flags & (1 << 2)) != 0
|
||||
sendDebugLogs = (flags & (1 << 3)) != 0
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
|
|
|||
|
|
@ -447,7 +447,7 @@ final class ChatHistoryPreloadManager {
|
|||
|
||||
switch index.entity {
|
||||
case let .peer(peerId):
|
||||
Logger.shared.log("HistoryPreload", "view \(peerId) hole \(updatedHole) isUpdated: \(holeIsUpdated)")
|
||||
Logger.shared.log("HistoryPreload", "view \(peerId) hole \(String(describing: updatedHole)) isUpdated: \(holeIsUpdated)")
|
||||
}
|
||||
|
||||
if previousHole != updatedHole {
|
||||
|
|
|
|||
|
|
@ -197,7 +197,6 @@ private final class ContactSyncManagerImpl {
|
|||
disposable.add(
|
||||
(syncContactsOnce(network: self.network, postbox: self.postbox, accountPeerId: self.accountPeerId)
|
||||
|> mapToSignal { _ -> Signal<PushDeviceContactsResult, NoError> in
|
||||
return .complete()
|
||||
}
|
||||
|> then(importSignal)
|
||||
|> deliverOn(self.queue)
|
||||
|
|
@ -250,8 +249,8 @@ private func pushDeviceContacts(postbox: Postbox, network: Network, importableCo
|
|||
if let updatedData = importableContacts[number] {
|
||||
if let value = value as? TelegramDeviceContactImportedData {
|
||||
switch value {
|
||||
case let .imported(imported):
|
||||
if imported.data != updatedData {
|
||||
case let .imported(data, _):
|
||||
if data != updatedData {
|
||||
updatedDataIdentifiers.insert(identifier)
|
||||
}
|
||||
case .retryLater:
|
||||
|
|
|
|||
|
|
@ -134,10 +134,10 @@ private func parseDialogs(apiDialogs: [Api.Dialog], apiMessages: [Api.Message],
|
|||
}
|
||||
|
||||
notificationSettings[peerId] = TelegramPeerNotificationSettings(apiSettings: apiNotificationSettings)
|
||||
case let .dialogFolder(dialogFolder):
|
||||
switch dialogFolder.folder {
|
||||
case let .folder(folder):
|
||||
referencedFolders[PeerGroupId(rawValue: folder.id)] = PeerGroupUnreadCountersSummary(all: PeerGroupUnreadCounters(messageCount: dialogFolder.unreadMutedMessagesCount, chatCount: dialogFolder.unreadMutedPeersCount))
|
||||
case let .dialogFolder(_, folder, _, _, unreadMutedPeersCount, _, unreadMutedMessagesCount, _):
|
||||
switch folder {
|
||||
case let .folder(_, id, _, _):
|
||||
referencedFolders[PeerGroupId(rawValue: id)] = PeerGroupUnreadCountersSummary(all: PeerGroupUnreadCounters(messageCount: unreadMutedMessagesCount, chatCount: unreadMutedPeersCount))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -228,9 +228,9 @@ final class HistoryViewStateValidationContexts {
|
|||
completedMessageIds.append(messageId)
|
||||
}
|
||||
}
|
||||
for messageId in completedMessageIds {
|
||||
//context.batchReferences.removeValue(forKey: messageId)
|
||||
}
|
||||
/*for messageId in completedMessageIds {
|
||||
context.batchReferences.removeValue(forKey: messageId)
|
||||
}*/
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ func managedChatListHoles(network: Network, postbox: Postbox, accountPeerId: Pee
|
|||
return lhs.hole.index > rhs.hole.index
|
||||
})
|
||||
|
||||
if let preferencesView = combinedView.views[filtersKey] as? PreferencesView, let filtersState = preferencesView.values[PreferencesKeys.chatListFilters] as? ChatListFiltersState, !filtersState.filters.isEmpty {
|
||||
if let preferencesView = combinedView.views[filtersKey] as? PreferencesView, let filtersState = preferencesView.values[PreferencesKeys.chatListFilters]?.get(ChatListFiltersState.self), !filtersState.filters.isEmpty {
|
||||
if let topRootHole = combinedView.views[topRootHoleKey] as? AllChatListHolesView, let hole = topRootHole.latestHole {
|
||||
let entry = ChatListHolesEntry(groupId: .root, hole: hole)
|
||||
if !entries.contains(entry) {
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ func managedConfigurationUpdates(accountManager: AccountManager<TelegramAccountM
|
|||
|> mapToSignal { result -> Signal<Void, NoError> in
|
||||
return postbox.transaction { transaction -> Signal<Void, NoError> in
|
||||
switch result {
|
||||
case let .config(config):
|
||||
case let .config(flags, _, _, _, _, dcOptions, _, chatSizeMax, megagroupSizeMax, forwardedCountMax, _, _, _, _, _, _, _, _, savedGifsLimit, editTimeLimit, revokeTimeLimit, revokePmTimeLimit, _, stickersRecentLimit, _, _, _, pinnedDialogsCountMax, pinnedInfolderCountMax, _, _, _, _, _, autoupdateUrlPrefix, gifSearchUsername, venueSearchUsername, imgSearchUsername, _, captionLengthMax, _, webfileDcId, suggestedLangCode, langPackVersion, baseLangPackVersion):
|
||||
var addressList: [Int: [MTDatacenterAddress]] = [:]
|
||||
for option in config.dcOptions {
|
||||
for option in dcOptions {
|
||||
switch option {
|
||||
case let .dcOption(flags, id, ipAddress, port, secret):
|
||||
let preferForMedia = (flags & (1 << 1)) != 0
|
||||
|
|
@ -33,24 +33,24 @@ func managedConfigurationUpdates(accountManager: AccountManager<TelegramAccountM
|
|||
}
|
||||
}
|
||||
|
||||
let blockedMode = (config.flags & 8) != 0
|
||||
let blockedMode = (flags & 8) != 0
|
||||
|
||||
updateNetworkSettingsInteractively(transaction: transaction, network: network, { settings in
|
||||
var settings = settings
|
||||
settings.reducedBackupDiscoveryTimeout = blockedMode
|
||||
settings.applicationUpdateUrlPrefix = config.autoupdateUrlPrefix
|
||||
settings.applicationUpdateUrlPrefix = autoupdateUrlPrefix
|
||||
return settings
|
||||
})
|
||||
|
||||
updateRemoteStorageConfiguration(transaction: transaction, configuration: RemoteStorageConfiguration(webDocumentsHostDatacenterId: config.webfileDcId))
|
||||
updateRemoteStorageConfiguration(transaction: transaction, configuration: RemoteStorageConfiguration(webDocumentsHostDatacenterId: webfileDcId))
|
||||
|
||||
transaction.updatePreferencesEntry(key: PreferencesKeys.suggestedLocalization, { entry in
|
||||
var currentLanguageCode: String?
|
||||
if let entry = entry?.get(SuggestedLocalizationEntry.self) {
|
||||
currentLanguageCode = entry.languageCode
|
||||
}
|
||||
if currentLanguageCode != config.suggestedLangCode {
|
||||
if let suggestedLangCode = config.suggestedLangCode {
|
||||
if currentLanguageCode != suggestedLangCode {
|
||||
if let suggestedLangCode = suggestedLangCode {
|
||||
return PreferencesEntry(SuggestedLocalizationEntry(languageCode: suggestedLangCode, isSeen: false))
|
||||
} else {
|
||||
return nil
|
||||
|
|
@ -59,17 +59,17 @@ func managedConfigurationUpdates(accountManager: AccountManager<TelegramAccountM
|
|||
return entry
|
||||
})
|
||||
|
||||
updateLimitsConfiguration(transaction: transaction, configuration: LimitsConfiguration(maxPinnedChatCount: config.pinnedDialogsCountMax, maxArchivedPinnedChatCount: config.pinnedInfolderCountMax, maxGroupMemberCount: config.chatSizeMax, maxSupergroupMemberCount: config.megagroupSizeMax, maxMessageForwardBatchSize: config.forwardedCountMax, maxSavedGifCount: config.savedGifsLimit, maxRecentStickerCount: config.stickersRecentLimit, maxMessageEditingInterval: config.editTimeLimit, maxMediaCaptionLength: config.captionLengthMax, canRemoveIncomingMessagesInPrivateChats: (config.flags & (1 << 6)) != 0, maxMessageRevokeInterval: config.revokeTimeLimit, maxMessageRevokeIntervalInPrivateChats: config.revokePmTimeLimit))
|
||||
updateLimitsConfiguration(transaction: transaction, configuration: LimitsConfiguration(maxPinnedChatCount: pinnedDialogsCountMax, maxArchivedPinnedChatCount: pinnedInfolderCountMax, maxGroupMemberCount: chatSizeMax, maxSupergroupMemberCount: megagroupSizeMax, maxMessageForwardBatchSize: forwardedCountMax, maxSavedGifCount: savedGifsLimit, maxRecentStickerCount: stickersRecentLimit, maxMessageEditingInterval: editTimeLimit, maxMediaCaptionLength: captionLengthMax, canRemoveIncomingMessagesInPrivateChats: (flags & (1 << 6)) != 0, maxMessageRevokeInterval: revokeTimeLimit, maxMessageRevokeIntervalInPrivateChats: revokePmTimeLimit))
|
||||
|
||||
updateSearchBotsConfiguration(transaction: transaction, configuration: SearchBotsConfiguration(imageBotUsername: config.imgSearchUsername, gifBotUsername: config.gifSearchUsername, venueBotUsername: config.venueSearchUsername))
|
||||
updateSearchBotsConfiguration(transaction: transaction, configuration: SearchBotsConfiguration(imageBotUsername: imgSearchUsername, gifBotUsername: gifSearchUsername, venueBotUsername: venueSearchUsername))
|
||||
|
||||
return accountManager.transaction { transaction -> Signal<Void, NoError> in
|
||||
let (primary, secondary) = getLocalization(transaction)
|
||||
var invalidateLocalization = false
|
||||
if primary.version != config.langPackVersion {
|
||||
if primary.version != langPackVersion {
|
||||
invalidateLocalization = true
|
||||
}
|
||||
if let secondary = secondary, let baseLangPackVersion = config.baseLangPackVersion {
|
||||
if let secondary = secondary, let baseLangPackVersion = baseLangPackVersion {
|
||||
if secondary.version != baseLangPackVersion {
|
||||
invalidateLocalization = true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ public func updateGlobalNotificationSettingsInteractively(postbox: Postbox, _ f:
|
|||
return PreferencesEntry(GlobalNotificationSettings(toBeSynchronized: settings, remote: settings))
|
||||
}
|
||||
})
|
||||
transaction.globalNotificationSettingsUpdated()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -83,6 +84,7 @@ func managedGlobalNotificationSettings(postbox: Postbox, network: Network) -> Si
|
|||
return PreferencesEntry(GlobalNotificationSettings(toBeSynchronized: nil, remote: settings))
|
||||
}
|
||||
})
|
||||
transaction.globalNotificationSettingsUpdated()
|
||||
}
|
||||
}
|
||||
case let .push(settings):
|
||||
|
|
@ -95,6 +97,7 @@ func managedGlobalNotificationSettings(postbox: Postbox, network: Network) -> Si
|
|||
return current
|
||||
}
|
||||
})
|
||||
transaction.globalNotificationSettingsUpdated()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ func managedPromoInfoUpdates(postbox: Postbox, network: Network, viewTracker: Ac
|
|||
switch data {
|
||||
case .promoDataEmpty:
|
||||
transaction.replaceAdditionalChatListItems([])
|
||||
case let .promoData(_, expires, peer, chats, users, psaType, psaMessage):
|
||||
case let .promoData(_, _, peer, chats, users, psaType, psaMessage):
|
||||
var peers: [Peer] = []
|
||||
var peerPresences: [PeerId: PeerPresence] = [:]
|
||||
for chat in chats {
|
||||
|
|
|
|||
|
|
@ -222,7 +222,8 @@ private func initialHandshakeAccept(postbox: Postbox, network: Network, peerId:
|
|||
let keyHash = MTSha1(key)
|
||||
|
||||
var keyFingerprint: Int64 = 0
|
||||
keyHash.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||
keyHash.withUnsafeBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
memcpy(&keyFingerprint, bytes.advanced(by: keyHash.count - 8), 8)
|
||||
}
|
||||
|
||||
|
|
@ -324,7 +325,8 @@ private func pfsAcceptKey(postbox: Postbox, network: Network, peerId: PeerId, la
|
|||
let keyHash = MTSha1(key)
|
||||
|
||||
var keyFingerprint: Int64 = 0
|
||||
keyHash.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||
keyHash.withUnsafeBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
memcpy(&keyFingerprint, bytes.advanced(by: keyHash.count - 8), 8)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,11 +88,11 @@ private func synchronizeGroupMessageStats(postbox: Postbox, network: Network, gr
|
|||
return postbox.transaction { transaction in
|
||||
if let result = result {
|
||||
switch result {
|
||||
case let .peerDialogs(peerDialogs):
|
||||
for dialog in peerDialogs.dialogs {
|
||||
case let .peerDialogs(dialogs, _, _, _, _):
|
||||
for dialog in dialogs {
|
||||
switch dialog {
|
||||
case let .dialogFolder(dialogFolder):
|
||||
transaction.resetPeerGroupSummary(groupId: groupId, namespace: namespace, summary: PeerGroupUnreadCountersSummary(all: PeerGroupUnreadCounters(messageCount: dialogFolder.unreadMutedMessagesCount, chatCount: dialogFolder.unreadMutedPeersCount)))
|
||||
case let .dialogFolder(_, _, _, _, unreadMutedPeersCount, _, unreadMutedMessagesCount, _):
|
||||
transaction.resetPeerGroupSummary(groupId: groupId, namespace: namespace, summary: PeerGroupUnreadCountersSummary(all: PeerGroupUnreadCounters(messageCount: unreadMutedMessagesCount, chatCount: unreadMutedPeersCount)))
|
||||
case .dialog:
|
||||
assertionFailure()
|
||||
break
|
||||
|
|
|
|||
|
|
@ -396,7 +396,6 @@ private func continueSynchronizeInstalledStickerPacks(transaction: Transaction,
|
|||
let sequence = request
|
||||
|> retryRequest
|
||||
|> mapError { _ -> SynchronizeInstalledStickerPacksError in
|
||||
return .restart
|
||||
}
|
||||
|> mapToSignal { result -> Signal<Void, SynchronizeInstalledStickerPacksError> in
|
||||
return postbox.transaction { transaction -> Signal<Void, SynchronizeInstalledStickerPacksError> in
|
||||
|
|
@ -444,7 +443,6 @@ private func continueSynchronizeInstalledStickerPacks(transaction: Transaction,
|
|||
}
|
||||
return resolveStickerPacks(network: network, remoteInfos: resolveRemoteInfos, localInfos: localInfos)
|
||||
|> mapError { _ -> SynchronizeInstalledStickerPacksError in
|
||||
return .restart
|
||||
}
|
||||
|> mapToSignal { replaceItems -> Signal<Void, SynchronizeInstalledStickerPacksError> in
|
||||
return postbox.transaction { transaction -> Signal<Void, SynchronizeInstalledStickerPacksError> in
|
||||
|
|
@ -481,8 +479,7 @@ private func continueSynchronizeInstalledStickerPacks(transaction: Transaction,
|
|||
|
||||
return (
|
||||
storeSignal
|
||||
|> mapError { _ -> SynchronizeInstalledStickerPacksError in return .restart
|
||||
}
|
||||
|> mapError { _ -> SynchronizeInstalledStickerPacksError in }
|
||||
)
|
||||
|> then(.fail(.done))
|
||||
}
|
||||
|
|
@ -567,7 +564,7 @@ private func continueSynchronizeInstalledStickerPacks(transaction: Transaction,
|
|||
let resolvedItems = resolveStickerPacks(network: network, remoteInfos: resultingInfos, localInfos: localInfos)
|
||||
|
||||
return combineLatest(archivedOrRemovedIds, resolvedItems)
|
||||
|> mapError { _ -> SynchronizeInstalledStickerPacksError in return .restart }
|
||||
|> mapError { _ -> SynchronizeInstalledStickerPacksError in }
|
||||
|> mapToSignal { archivedOrRemovedIds, replaceItems -> Signal<Void, SynchronizeInstalledStickerPacksError> in
|
||||
return (postbox.transaction { transaction -> Signal<Void, SynchronizeInstalledStickerPacksError> in
|
||||
let finalCheckLocalCollectionInfos = transaction.getItemCollectionsInfos(namespace: collectionNamespace).map { $0.1 as! StickerPackCollectionInfo }
|
||||
|
|
@ -590,7 +587,6 @@ private func continueSynchronizeInstalledStickerPacks(transaction: Transaction,
|
|||
return .complete()
|
||||
}
|
||||
|> mapError { _ -> SynchronizeInstalledStickerPacksError in
|
||||
return .restart
|
||||
})
|
||||
|> switchToLatest
|
||||
|> then(.fail(.done))
|
||||
|
|
@ -598,7 +594,6 @@ private func continueSynchronizeInstalledStickerPacks(transaction: Transaction,
|
|||
}
|
||||
}
|
||||
|> mapError { _ -> SynchronizeInstalledStickerPacksError in
|
||||
return .restart
|
||||
}
|
||||
|> switchToLatest
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,12 +128,12 @@ private func synchronizeMarkAllUnseen(transaction: Transaction, postbox: Postbox
|
|||
switch result {
|
||||
case let .messages(messages, _, _):
|
||||
return .single(messages.compactMap({ $0.id() }))
|
||||
case let .channelMessages(channelMessages):
|
||||
return .single(channelMessages.messages.compactMap({ $0.id() }))
|
||||
case let .channelMessages(_, _, _, _, messages, _, _):
|
||||
return .single(messages.compactMap({ $0.id() }))
|
||||
case .messagesNotModified:
|
||||
return .single([])
|
||||
case let .messagesSlice(messagesSlice):
|
||||
return .single(messagesSlice.messages.compactMap({ $0.id() }))
|
||||
case let .messagesSlice(_, _, _, _, messages, _, _):
|
||||
return .single(messages.compactMap({ $0.id() }))
|
||||
}
|
||||
}
|
||||
|> mapToSignal { ids -> Signal<Int32?, MTRpcError> in
|
||||
|
|
|
|||
|
|
@ -115,8 +115,6 @@ private func synchronizePinnedChats(transaction: Transaction, postbox: Postbox,
|
|||
switch item {
|
||||
case let .peer(peerId):
|
||||
return peerId.namespace != Namespaces.Peer.SecretChat
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
let localItemIds = transaction.getPinnedItemIds(groupId: groupId)
|
||||
|
|
@ -124,8 +122,6 @@ private func synchronizePinnedChats(transaction: Transaction, postbox: Postbox,
|
|||
switch item {
|
||||
case let .peer(peerId):
|
||||
return peerId.namespace != Namespaces.Peer.SecretChat
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -167,7 +163,7 @@ private func synchronizePinnedChats(transaction: Transaction, postbox: Postbox,
|
|||
var apiChannelPts: Int32?
|
||||
let apiNotificationSettings: Api.PeerNotifySettings
|
||||
switch dialog {
|
||||
case let .dialog(flags, peer, topMessage, readInboxMaxId, readOutboxMaxId, unreadCount, unreadMentionsCount, peerNotificationSettings, pts, _, _):
|
||||
case let .dialog(flags, peer, topMessage, readInboxMaxId, readOutboxMaxId, unreadCount, _, peerNotificationSettings, pts, _, _):
|
||||
apiPeer = peer
|
||||
apiTopMessage = topMessage
|
||||
apiReadInboxMaxId = readInboxMaxId
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue