From 10692a323eff2c12d4b83f52996e643f05374a68 Mon Sep 17 00:00:00 2001 From: Peter <> Date: Mon, 21 Oct 2019 16:58:00 +0400 Subject: [PATCH] Refactor SyncCore --- BUCK | 9 +- Makefile | 12 + .../NotificationViewController.swift | 2 +- NotificationService/Crypto.h | 7 - NotificationService/Crypto.m | 73 -- NotificationService/FetchImage.m | 28 +- .../NotificationService-Bridging-Header.h | 9 +- NotificationService/NotificationService.m | 98 +- NotificationService/Sync.h | 4 + NotificationService/Sync.m | 1 + NotificationService/Sync.swift | 32 + Share/ShareRootController.swift | 2 +- SiriIntents/IntentContacts.swift | 1 + SiriIntents/IntentHandler.swift | 3 +- SiriIntents/IntentMessages.swift | 1 + submodules/AccountContext/BUCK | 11 +- .../Sources/AccountContext.swift | 1 + .../Sources/ChatController.swift | 1 + .../Sources/DeviceContactData.swift | 1 + .../Sources/DeviceContactDataManager.swift | 1 + .../Sources/DownloadedMediaStoreManager.swift | 1 + .../AccountContext/Sources/FetchManager.swift | 1 + .../Sources/FetchMediaUtils.swift | 1 + .../Sources/IsMediaStreamable.swift | 1 + .../Sources/LiveLocationManager.swift | 1 + .../AccountContext/Sources/MediaManager.swift | 1 + .../Sources/OpenChatMessage.swift | 1 + .../Sources/PresentationCallManager.swift | 1 + .../Sources/SharedMediaPlayer.swift | 1 + .../Sources/StoredMessageFromSearchPeer.swift | 1 + .../Sources/ThemeUpdateManager.swift | 1 + .../Sources/UniversalVideoNode.swift | 1 + .../Sources/WallpaperUploadManager.swift | 1 + submodules/ActionSheetPeerItem/BUCK | 1 + .../Sources/ActionSheetPeerItem.swift | 1 + submodules/AnimationUI/BUCK | 1 + submodules/AuthorizationUI/BUCK | 1 + .../Sources/AuthorizationOptionText.swift | 1 + submodules/AvatarNode/BUCK | 1 + .../AvatarNode/Sources/AvatarNode.swift | 1 + .../AvatarNode/Sources/PeerAvatar.swift | 1 + submodules/BotPaymentsUI/BUCK | 1 + .../Sources/BotCheckoutController.swift | 1 + .../Sources/BotCheckoutControllerNode.swift | 1 + .../Sources/BotCheckoutHeaderItem.swift | 1 + .../Sources/BotCheckoutInfoController.swift | 1 + .../BotCheckoutInfoControllerNode.swift | 1 + ...BotCheckoutNativeCardEntryController.swift | 1 + ...heckoutNativeCardEntryControllerNode.swift | 1 + .../BotCheckoutPasswordEntryController.swift | 1 + .../BotCheckoutPaymentMethodSheet.swift | 1 + ...PaymentShippingOptionSheetController.swift | 1 + .../BotCheckoutWebInteractionController.swift | 1 + .../Sources/BotReceiptController.swift | 1 + .../Sources/BotReceiptControllerNode.swift | 1 + submodules/BuildConfig/BUCK | 1 - submodules/BuildConfig/Sources/BuildConfig.h | 2 +- submodules/BuildConfig/Sources/BuildConfig.m | 256 +---- submodules/BuildConfigExtra/BUCK | 20 + .../Sources/BuildConfigExtra.h | 9 + .../Sources/BuildConfigExtra.m | 260 +++++ submodules/CallListUI/BUCK | 1 + .../CallListUI/Sources/CallListCallItem.swift | 1 + .../Sources/CallListController.swift | 1 + .../Sources/CallListControllerNode.swift | 1 + .../Sources/CallListNodeEntries.swift | 1 + .../Sources/CallListNodeLocation.swift | 1 + .../Sources/CallListViewTransition.swift | 1 + submodules/ChatListSearchRecentPeersNode/BUCK | 1 + .../ChatListSearchRecentPeersNode.swift | 1 + submodules/ChatListUI/BUCK | 1 + .../ChatListUI/Sources/ChatContextMenus.swift | 1 + .../Sources/ChatListController.swift | 1 + .../Sources/ChatListControllerNode.swift | 1 + .../Sources/ChatListRecentPeersListItem.swift | 1 + .../Sources/ChatListSearchContainerNode.swift | 1 + .../Sources/ChatListSelection.swift | 1 + .../Sources/Node/ChatListItem.swift | 1 + .../Sources/Node/ChatListItemStrings.swift | 1 + .../Sources/Node/ChatListNode.swift | 1 + .../Sources/Node/ChatListNodeEntries.swift | 1 + .../Sources/Node/ChatListNodeLocation.swift | 1 + .../Sources/Node/ChatListTypingNode.swift | 1 + .../Sources/Node/ChatListViewTransition.swift | 1 + submodules/ComposePollUI/BUCK | 1 + .../Sources/CreatePollController.swift | 1 + submodules/ContactListUI/BUCK | 1 + .../Sources/ContactAddItem.swift | 1 + .../Sources/ContactContextMenus.swift | 1 + .../Sources/ContactListNode.swift | 1 + .../Sources/ContactsController.swift | 1 + .../Sources/ContactsControllerNode.swift | 1 + .../Sources/ContactsSearchContainerNode.swift | 1 + .../Sources/InviteContactsController.swift | 1 + .../InviteContactsControllerNode.swift | 1 + submodules/ContactsPeerItem/BUCK | 1 + .../Sources/ContactsPeerItem.swift | 1 + .../ContextUI/Sources/ContextController.swift | 1 + ...quenceCountrySelectionControllerNode.swift | 1 + submodules/DeleteChatPeerActionSheetItem/BUCK | 1 + .../DeleteChatPeerActionSheetItem.swift | 1 + submodules/DeviceAccess/BUCK | 1 + .../DeviceAccess/Sources/DeviceAccess.swift | 1 + submodules/DeviceLocationManager/BUCK | 2 +- submodules/Display/BUCK | 4 +- submodules/EncryptionKeyVisualization/BUCK | 1 + .../Sources/SecretChatKeyVisualization.swift | 1 + submodules/GalleryUI/BUCK | 1 + .../ChatItemGalleryFooterContentNode.swift | 1 + .../ChatVideoGalleryItemScrubberView.swift | 1 + .../GalleryUI/Sources/GalleryController.swift | 1 + .../Items/ChatAnimationGalleryItem.swift | 1 + .../Items/ChatDocumentGalleryItem.swift | 1 + .../Items/ChatExternalFileGalleryItem.swift | 1 + .../Sources/Items/ChatImageGalleryItem.swift | 1 + .../Items/UniversalVideoGalleryItem.swift | 1 + .../SecretMediaPreviewController.swift | 1 + .../SecretMediaPreviewFooterContentNode.swift | 1 + submodules/GameUI/BUCK | 1 + .../GameUI/Sources/GameController.swift | 1 + .../GameUI/Sources/GameControllerNode.swift | 1 + .../Sources/GameControllerTitleView.swift | 1 + submodules/HashtagSearchUI/BUCK | 1 + .../Sources/HashtagSearchController.swift | 1 + .../Sources/HashtagSearchControllerNode.swift | 1 + submodules/HorizontalPeerItem/BUCK | 1 + .../Sources/HorizontalPeerItem.swift | 1 + submodules/InstantPageCache/BUCK | 1 + .../Sources/CachedInstantPages.swift | 1 + submodules/InstantPageUI/BUCK | 1 + .../Sources/InstantImageGalleryItem.swift | 1 + .../Sources/InstantPageAnchorItem.swift | 1 + .../Sources/InstantPageArticleItem.swift | 1 + .../Sources/InstantPageArticleNode.swift | 1 + .../Sources/InstantPageAudioItem.swift | 1 + .../Sources/InstantPageAudioNode.swift | 1 + .../Sources/InstantPageContentNode.swift | 1 + .../Sources/InstantPageController.swift | 1 + .../Sources/InstantPageControllerNode.swift | 1 + .../Sources/InstantPageDetailsItem.swift | 1 + .../Sources/InstantPageDetailsNode.swift | 1 + .../Sources/InstantPageFeedbackItem.swift | 1 + .../Sources/InstantPageFeedbackNode.swift | 1 + .../InstantPageGalleryController.swift | 1 + .../InstantPageGalleryFooterContentNode.swift | 1 + .../Sources/InstantPageImageItem.swift | 1 + .../Sources/InstantPageImageNode.swift | 1 + .../Sources/InstantPageItem.swift | 1 + .../Sources/InstantPageLayout.swift | 1 + .../Sources/InstantPageLayoutSpacings.swift | 1 + .../Sources/InstantPageMedia.swift | 1 + .../Sources/InstantPageMediaPlaylist.swift | 1 + .../InstantPagePeerReferenceItem.swift | 1 + .../InstantPagePeerReferenceNode.swift | 1 + .../InstantPagePlayableVideoItem.swift | 1 + .../InstantPagePlayableVideoNode.swift | 1 + .../InstantPageReferenceController.swift | 1 + .../InstantPageReferenceControllerNode.swift | 1 + .../Sources/InstantPageScrollableNode.swift | 1 + .../Sources/InstantPageShapeItem.swift | 1 + .../Sources/InstantPageSlideshowItem.swift | 1 + .../InstantPageSlideshowItemNode.swift | 1 + .../Sources/InstantPageStoredState.swift | 1 + .../Sources/InstantPageTableItem.swift | 1 + .../Sources/InstantPageTextItem.swift | 1 + .../Sources/InstantPageTextStyleStack.swift | 1 + .../Sources/InstantPageWebEmbedItem.swift | 1 + .../Sources/InstantPageWebEmbedNode.swift | 1 + submodules/ItemListAvatarAndNameInfoItem/BUCK | 1 + .../Sources/ItemListAvatarAndNameItem.swift | 1 + submodules/ItemListPeerItem/BUCK | 1 + .../Sources/ItemListPeerItem.swift | 1 + submodules/ItemListStickerPackItem/BUCK | 1 + .../Sources/ItemListStickerPackItem.swift | 1 + .../Sources/ItemListControllerNode.swift | 1 + submodules/JoinLinkPreviewUI/BUCK | 1 + .../Sources/JoinLinkPreviewController.swift | 1 + .../JoinLinkPreviewControllerNode.swift | 1 + .../JoinLinkPreviewPeerContentNode.swift | 1 + submodules/LanguageLinkPreviewUI/BUCK | 1 + .../LanguageLinkPreviewContentNode.swift | 1 + .../LanguageLinkPreviewController.swift | 1 + .../LanguageLinkPreviewControllerNode.swift | 1 + submodules/LanguageSuggestionUI/BUCK | 1 + .../LanguageSuggestionController.swift | 1 + submodules/LegacyDataImport/BUCK | 7 +- .../Sources/LegacyChatImport.swift | 1 + .../Sources/LegacyDataImport.swift | 1 + .../Sources/LegacyFileImport.swift | 1 + .../Sources/LegacyPreferencesImport.swift | 1 + .../Sources/LegacyResourceImport.swift | 1 + .../Sources/LegacyUserDataImport.swift | 1 + submodules/LegacyMediaPickerUI/BUCK | 1 + .../Sources/LegacyAttachmentMenu.swift | 1 + .../Sources/LegacyMediaPickers.swift | 1 + .../Sources/LegacySuggestionContext.swift | 1 + submodules/LegacyUI/BUCK | 1 + .../Sources/LegacyComponentsStickers.swift | 1 + .../Sources/LegacyImageDownloadActor.swift | 1 + .../LegacyLocationVenueIconDataSource.swift | 1 + .../Sources/LegacyMediaLocations.swift | 1 + ...egacyPeerAvatarPlaceholderDataSource.swift | 1 + .../TelegramInitializeLegacyComponents.swift | 1 + submodules/LiveLocationManager/BUCK | 7 +- .../Sources/LiveLocationManager.swift | 1 + .../Sources/LiveLocationSummaryManager.swift | 1 + submodules/LiveLocationPositionNode/BUCK | 1 + .../ChatMessageLiveLocationPositionNode.swift | 1 + submodules/LocalMediaResources/BUCK | 1 + .../Sources/MediaResources.swift | 1 + submodules/LocalizedPeerData/BUCK | 5 +- .../LocalizedPeerData/Sources/PeerTitle.swift | 1 + submodules/LocationUI/BUCK | 1 + .../Sources/LegacyLocationController.swift | 1 + .../Sources/LegacyLocationPicker.swift | 1 + submodules/MapResourceToAvatarSizes/BUCK | 1 + .../Sources/MapResourceToAvatarSizes.swift | 2 + submodules/MediaPlayer/BUCK | 1 + .../Sources/FFMpegMediaFrameSource.swift | 1 + .../FFMpegMediaFrameSourceContext.swift | 1 + .../MediaPlayer/Sources/MediaPlayer.swift | 1 + .../Sources/MediaPlayerAudioRenderer.swift | 1 + .../Sources/MediaPlayerFramePreview.swift | 1 + .../UniversalSoftwareVideoSource.swift | 1 + submodules/MediaResources/BUCK | 1 + .../MediaResources/Sources/MapResources.swift | 1 + submodules/MessageReactionListUI/BUCK | 1 + .../Sources/MessageReactionCategoryNode.swift | 1 + .../MessageReactionListController.swift | 1 + ...essageReactionListLoadingPlaceholder.swift | 1 + submodules/MusicAlbumArtResources/BUCK | 1 + .../ExternalMusicAlbumArtResources.swift | 1 + submodules/NotificationMuteSettingsUI/BUCK | 1 + .../NotificationMuteSettingsController.swift | 1 + submodules/NotificationSoundSelectionUI/BUCK | 1 + .../Sources/NotificationSoundSelection.swift | 1 + submodules/OpenInExternalAppUI/BUCK | 1 + .../Sources/OpenInActionSheetController.swift | 1 + .../Sources/OpenInAppIconResources.swift | 1 + .../Sources/OpenInOptions.swift | 1 + submodules/PasscodeUI/BUCK | 1 + .../Sources/PasscodeEntryControllerNode.swift | 1 + .../Sources/PasscodeSetupController.swift | 1 + .../Sources/PasscodeSetupControllerNode.swift | 1 + submodules/PassportUI/BUCK | 1 + .../Sources/FindSecureIdValue.swift | 1 + .../Sources/Form/FormController.swift | 1 + .../Sources/Form/FormControllerNode.swift | 1 + .../LegacySecureIdAttachmentMenu.swift | 1 + .../Sources/SecureIdAuthAcceptNode.swift | 1 + .../Sources/SecureIdAuthController.swift | 1 + .../Sources/SecureIdAuthControllerNode.swift | 1 + .../Sources/SecureIdAuthControllerState.swift | 1 + .../Sources/SecureIdAuthFormContentNode.swift | 1 + .../Sources/SecureIdAuthFormFieldNode.swift | 1 + .../Sources/SecureIdAuthHeaderNode.swift | 1 + .../Sources/SecureIdAuthListContentNode.swift | 1 + .../Sources/SecureIdAuthListFieldNode.swift | 1 + .../SecureIdDocumentFormController.swift | 1 + .../SecureIdDocumentFormControllerNode.swift | 1 + .../SecureIdDocumentGalleryController.swift | 1 + ...reIdDocumentGalleryFooterContentNode.swift | 1 + .../SecureIdDocumentImageGalleryItem.swift | 1 + ...ureIdDocumentTypeSelectionController.swift | 1 + .../Sources/SecureIdLocalResource.swift | 1 + .../SecureIdPlaintextFormController.swift | 1 + .../SecureIdPlaintextFormControllerNode.swift | 1 + .../Sources/SecureIdValueFormFileItem.swift | 1 + .../Sources/SecureIdValueFormPhoneItem.swift | 1 + .../PassportUI/Sources/SecureIdValues.swift | 1 + .../SecureIdVerificationDocument.swift | 1 + ...SecureIdVerificationDocumentsContext.swift | 1 + submodules/PasswordSetupUI/BUCK | 1 + .../Sources/ResetPasswordController.swift | 1 + .../SetupTwoStepVerificationController.swift | 1 + ...tupTwoStepVerificationControllerNode.swift | 1 + submodules/PeerAvatarGalleryUI/BUCK | 1 + .../Sources/AvatarGalleryController.swift | 1 + .../AvatarGalleryItemFooterContentNode.swift | 1 + .../Sources/PeerAvatarImageGalleryItem.swift | 1 + submodules/PeerInfoUI/BUCK | 1 + .../Sources/ChannelAdminController.swift | 1 + .../Sources/ChannelAdminsController.swift | 1 + .../ChannelBannedMemberController.swift | 1 + .../Sources/ChannelBlacklistController.swift | 1 + ...hannelDiscussionGroupActionSheetItem.swift | 1 + ...elDiscussionGroupSearchContainerNode.swift | 1 + ...hannelDiscussionGroupSetupController.swift | 1 + ...hannelDiscussionGroupSetupSearchItem.swift | 1 + .../Sources/ChannelInfoController.swift | 1 + .../Sources/ChannelMembersController.swift | 1 + .../ChannelMembersSearchContainerNode.swift | 1 + .../ChannelMembersSearchController.swift | 1 + .../ChannelMembersSearchControllerNode.swift | 1 + .../ChannelOwnershipTransferController.swift | 1 + .../ChannelPermissionsController.swift | 1 + .../Sources/ChannelStatsController.swift | 1 + .../Sources/ChannelStatsControllerNode.swift | 1 + .../Sources/ChannelVisibilityController.swift | 1 + .../PeerInfoUI/Sources/ChatSlowmodeItem.swift | 1 + .../ConvertToSupergroupController.swift | 1 + .../Sources/DeviceContactInfoController.swift | 1 + .../Sources/GroupInfoController.swift | 1 + .../Sources/GroupInfoSearchItem.swift | 1 + ...GroupInfoSearchNavigationContentNode.swift | 1 + .../GroupPreHistorySetupController.swift | 1 + .../Sources/GroupStickerPackCurrentItem.swift | 1 + .../GroupStickerPackSetupController.swift | 1 + .../Sources/GroupsInCommonController.swift | 1 + .../Sources/ItemListCallListItem.swift | 1 + .../Sources/ItemListSecretChatKeyItem.swift | 1 + .../Sources/PeerBanTimeoutController.swift | 1 + .../Sources/PeerInfoController.swift | 1 + .../Sources/PeerReportController.swift | 1 + .../Sources/PhoneLabelController.swift | 1 + .../Sources/SecretChatKeyController.swift | 1 + .../Sources/SecretChatKeyControllerNode.swift | 1 + .../Sources/UserInfoController.swift | 1 + submodules/PeerPresenceStatusManager/BUCK | 2 + .../Sources/PeerPresenceStatusManager.swift | 2 + submodules/PeersNearbyUI/BUCK | 1 + .../Sources/PeersNearbyController.swift | 1 + submodules/PhotoResources/BUCK | 1 + .../Sources/PhotoResources.swift | 1 + submodules/PlatformRestrictionMatching/BUCK | 4 +- .../Sources/PlatformRestrictionMatching.swift | 2 + submodules/Postbox/Postbox/Postbox.swift | 17 + submodules/RadialStatusNode/BUCK | 4 +- submodules/ReactionSelectionNode/BUCK | 1 + .../Sources/ReactionAttachedNode.swift | 1 + .../Sources/ReactionContextNode.swift | 1 + .../Sources/ReactionGestureItem.swift | 1 + .../Sources/ReactionSelectionNode.swift | 1 + .../Sources/ReactionSelectionParentNode.swift | 1 + submodules/SaveToCameraRoll/BUCK | 1 + .../Sources/SaveToCameraRoll.swift | 1 + submodules/SearchPeerMembers/BUCK | 1 + .../Sources/SearchPeerMembers.swift | 1 + submodules/SelectablePeerNode/BUCK | 1 + .../Sources/SelectablePeerNode.swift | 1 + submodules/SettingsUI/BUCK | 1 + .../SettingsUI/Sources/AccountUtils.swift | 1 + .../Sources/CachedFaqInstantPage.swift | 1 + .../ChangePhoneNumberCodeController.swift | 1 + .../Sources/ChangePhoneNumberController.swift | 1 + .../ChangePhoneNumberControllerNode.swift | 1 + .../ChangePhoneNumberIntroController.swift | 1 + ...AutodownloadConnectionTypeController.swift | 1 + .../AutodownloadDataUsagePickerItem.swift | 1 + .../AutodownloadMediaCategoryController.swift | 1 + .../AutodownloadSizeLimitItem.swift | 1 + .../DataAndStorageSettingsController.swift | 1 + .../NetworkUsageStatsController.swift | 1 + .../ProxyListSettingsController.swift | 1 + .../ProxyServerActionSheetController.swift | 1 + .../ProxyServerSettingsController.swift | 1 + .../ProxySettingsServerItem.swift | 1 + .../SaveIncomingMediaController.swift | 1 + ...hareProxyServerActionSheetController.swift | 1 + .../StorageUsageController.swift | 1 + .../VoiceCallDataSavingController.swift | 1 + .../Sources/DebugAccountsController.swift | 1 + .../SettingsUI/Sources/DebugController.swift | 1 + .../Sources/EditSettingsController.swift | 1 + .../LocalizationListController.swift | 1 + .../LocalizationListControllerNode.swift | 1 + .../Sources/LogoutOptionsController.swift | 1 + .../NotificationExceptionControllerNode.swift | 1 + ...ificationExceptionSettingsController.swift | 1 + .../Exceptions/NotificationExceptions.swift | 1 + .../NotificationsAndSounds.swift | 1 + .../SettingsUI/Sources/OpenSettings.swift | 1 + .../BlockedPeersController.swift | 1 + .../ConfirmPhoneNumberController.swift | 1 + .../CreatePasswordController.swift | 1 + .../DataPrivacySettingsController.swift | 1 + .../ForwardPrivacyChatPreviewItem.swift | 1 + .../PasscodeOptionsController.swift | 1 + .../PrivacyAndSecurityController.swift | 1 + .../PrivacyIntroController.swift | 1 + .../PrivacyIntroControllerNode.swift | 1 + .../ItemListRecentSessionItem.swift | 1 + .../Recent Sessions/ItemListWebsiteItem.swift | 1 + .../RecentSessionsController.swift | 1 + .../SelectivePrivacySettingsController.swift | 1 + ...ectivePrivacySettingsPeersController.swift | 1 + ...pVerificationPasswordEntryController.swift | 1 + .../TwoStepVerificationResetController.swift | 1 + .../TwoStepVerificationUnlockController.swift | 1 + .../Sources/Search/SettingsSearchItem.swift | 1 + .../Search/SettingsSearchRecentItem.swift | 1 + .../Search/SettingsSearchableItems.swift | 1 + .../Sources/SettingsController.swift | 1 + .../ArchivedStickerPacksController.swift | 1 + .../FeaturedStickerPacksController.swift | 1 + .../InstalledStickerPacksController.swift | 1 + .../TabBarAccountSwitchController.swift | 1 + .../TabBarAccountSwitchControllerNode.swift | 1 + .../TermsOfServiceController.swift | 1 + .../TermsOfServiceControllerNode.swift | 1 + .../Themes/CustomWallpaperPicker.swift | 1 + .../Sources/Themes/EditThemeController.swift | 1 + .../Themes/SettingsThemeWallpaperNode.swift | 1 + .../Themes/ThemeAccentColorController.swift | 1 + .../ThemeAccentColorControllerNode.swift | 1 + .../ThemeAutoNightSettingsController.swift | 1 + ...emeAutoNightTimeSelectionActionSheet.swift | 1 + .../Themes/ThemeColorsGridController.swift | 1 + .../ThemeColorsGridControllerItem.swift | 1 + .../ThemeColorsGridControllerNode.swift | 1 + .../Sources/Themes/ThemeGridController.swift | 1 + .../Themes/ThemeGridControllerItem.swift | 1 + .../Themes/ThemeGridControllerNode.swift | 1 + .../Themes/ThemeGridSearchColorsItem.swift | 1 + .../Themes/ThemeGridSearchContentNode.swift | 1 + .../Sources/Themes/ThemeGridSearchItem.swift | 1 + .../Themes/ThemeGridSelectionPanelNode.swift | 1 + .../Themes/ThemePreviewController.swift | 1 + .../Themes/ThemePreviewControllerNode.swift | 1 + .../Themes/ThemeSettingsAccentColorItem.swift | 1 + .../Themes/ThemeSettingsAppIconItem.swift | 1 + .../Themes/ThemeSettingsBrightnessItem.swift | 1 + .../Themes/ThemeSettingsChatPreviewItem.swift | 1 + .../Themes/ThemeSettingsController.swift | 1 + .../Themes/ThemeSettingsFontSizeItem.swift | 1 + .../Themes/ThemeSettingsThemeItem.swift | 1 + .../Themes/WallpaperGalleryController.swift | 1 + .../Sources/Themes/WallpaperGalleryItem.swift | 1 + .../Themes/WallpaperPatternPanelNode.swift | 1 + .../Sources/UsernameSetupController.swift | 1 + .../Watch/WatchSettingsController.swift | 1 + submodules/ShareController/BUCK | 1 + .../Sources/ShareController.swift | 1 + .../Sources/ShareControllerNode.swift | 1 + .../Sources/ShareControllerPeerGridItem.swift | 1 + .../ShareControllerRecentPeersGridItem.swift | 1 + .../Sources/SharePeersContainerNode.swift | 1 + .../Sources/ShareSearchContainerNode.swift | 1 + submodules/ShareItems/BUCK | 1 + .../ShareItems/Sources/ShareItems.swift | 1 + .../Sources/SinglePhoneInputNode.swift | 1 + submodules/StickerPackPreviewUI/BUCK | 1 + .../StickerPackPreviewController.swift | 1 + .../StickerPackPreviewControllerNode.swift | 1 + .../Sources/StickerPackPreviewGridItem.swift | 1 + .../Sources/StickerPreviewController.swift | 1 + .../StickerPreviewControllerNode.swift | 1 + .../Sources/StickerPreviewPeekContent.swift | 1 + submodules/StickerResources/BUCK | 1 + .../Sources/StickerResources.swift | 1 + submodules/SyncCore/BUCK | 15 + .../Sources/AccountBackupDataAttribute.swift | 45 + .../AccountEnvironmentAttribute.swift | 0 .../Sources}/AccountSortOrderAttribute.swift | 0 .../SyncCore/Sources/AppChangelogState.swift | 31 + .../SyncCore/Sources/AppConfiguration.swift | 37 + .../Sources}/ArchivedStickerPacksInfo.swift | 0 .../AuthorSignatureMessageAttribute.swift | 2 +- .../Sources/AuthorizedAccountState.swift | 93 ++ .../Sources/AutodownloadSettings.swift | 85 ++ .../AutoremoveTimeoutMessageAttribute.swift | 41 +- submodules/SyncCore/Sources/BotInfo.swift | 45 + .../Sources/CacheStorageSettings.swift | 37 + .../SyncCore/Sources/CachedChannelData.swift | 502 ++++++++++ .../Sources}/CachedGroupData.swift | 20 +- .../Sources/CachedGroupParticipants.swift | 84 ++ .../Sources/CachedLocalizationInfos.swift | 17 + .../SyncCore/Sources/CachedRecentPeers.swift | 26 + .../Sources/CachedResolvedByNamePeer.swift | 42 + .../Sources/CachedSecureIdConfiguration.swift | 39 + .../SyncCore/Sources/CachedStickerPack.swift | 40 + .../Sources/CachedStickerQueryResult.swift | 26 + .../Sources/CachedThemesConfiguration.swift | 17 + .../Sources}/CachedUserData.swift | 24 +- .../CachedWallpapersConfiguration.swift | 17 + .../ChannelMessageStateVersionAttribute.swift | 0 .../SyncCore/Sources/ChannelState.swift | 48 + .../CloudChatRemoveMessagesOperation.swift | 140 +++ .../Sources/CloudFileMediaResource.swift | 843 ++++++++++++++++ .../ConsumableContentMessageAttribute.swift | 0 ...mablePersonalMentionMessageAttribute.swift | 0 .../ConsumePersonalMessageAction.swift | 25 + .../Sources}/ContactsSettings.swift | 0 .../Sources/ContentPrivacySettings.swift | 42 + ...ntRequiresValidationMessageAttribute.swift | 0 .../Sources}/EditedMessageAttribute.swift | 2 +- .../Sources/EmojiKeywordCollectionInfo.swift | 57 ++ .../SyncCore/Sources/EmojiKeywordItem.swift | 38 + .../SyncCore/Sources/ExportedInvitation.swift | 21 + .../Sources}/FeaturedStickerPack.swift | 6 +- .../Sources}/ForwardSourceInfoAttribute.swift | 2 +- .../Sources/GlobalNotificationSettings.swift | 103 ++ .../Sources/ImportableDeviceContactData.swift | 31 + .../Sources}/InlineBotMessageAttribute.swift | 2 +- submodules/SyncCore/Sources/InstantPage.swift | 901 ++++++++++++++++++ submodules/SyncCore/Sources/JSON.swift | 93 ++ .../Sources/LimitsConfiguration.swift | 74 ++ .../Sources}/Localization.swift | 46 +- .../SyncCore/Sources/LocalizationInfo.swift | 57 ++ .../Sources/LocalizationListState.swift | 33 + .../Sources}/LocalizationSettings.swift | 0 .../Sources}/LoggedOutAccountAttribute.swift | 0 .../SyncCore/Sources/LoggingSettings.swift | 64 ++ .../SyncCore/Sources/MediaReference.swift | 491 ++++++++++ .../Sources}/Namespaces.swift | 46 +- .../SyncCore/Sources/NetworkSettings.swift | 45 + .../NotificationInfoMessageAttribute.swift | 0 ...ingChatContextResultMessageAttribute.swift | 2 +- .../OutgoingContentInfoMessageAttribute.swift | 0 .../OutgoingMessageInfoAttribute.swift | 21 +- ...OutgoingScheduleInfoMessageAttribute.swift | 0 .../Sources}/PeerAccessHash.swift | 0 .../Sources/PeerAccessRestrictionInfo.swift | 62 ++ ...eerGroupMessageStateVersionAttribute.swift | 0 .../SyncCore/Sources/PeerReference.swift | 58 ++ .../SyncCore/Sources/PeerStatusSettings.swift | 16 + .../SyncCore/Sources/ProxySettings.swift | 135 +++ .../Sources/ReactionsMessageAttribute.swift | 61 ++ .../SyncCore/Sources/RecentHashtagItem.swift | 12 + .../Sources}/RecentMediaItem.swift | 4 +- .../Sources}/RecentPeerItem.swift | 6 +- .../Sources}/RegularChatState.swift | 23 +- .../Sources/RemoteStorageConfiguration.swift | 27 + .../Sources/ReplyMarkupMessageAttribute.swift | 161 ++++ .../Sources}/ReplyMessageAttribute.swift | 0 .../RestrictedContentMessageAttribute.swift | 0 submodules/SyncCore/Sources/RichText.swift | 295 ++++++ .../Sources}/SavedStickerItem.swift | 2 +- .../Sources}/SearchBotsConfiguration.swift | 4 +- .../Sources/SecretChatEncryptionConfig.swift | 25 + .../Sources/SecretChatFileReference.swift | 33 + ...SecretChatIncomingDecryptedOperation.swift | 30 +- ...SecretChatIncomingEncryptedOperation.swift | 67 ++ .../Sources}/SecretChatKeychain.swift | 20 +- .../Sources/SecretChatOutgoingOperation.swift | 284 ++++++ .../Sources}/SecretChatSettings.swift | 0 .../Sources}/SecretChatState.swift | 50 +- .../Sources/SecretFileEncryptionKey.swift | 25 + .../Sources/SecureFileMediaResource.swift | 67 ++ .../Sources/SecureIdFileReference.swift | 21 + ...endScheduledMessageImmediatelyAction.swift | 20 + .../SourceReferenceMessageAttribute.swift | 0 .../StandaloneAccountTransaction.swift | 52 + .../Sources/StickerPackCollectionInfo.swift | 111 +++ .../SyncCore/Sources/StickerPackItem.swift | 42 + .../Sources/SuggestedLocalizationEntry.swift | 33 + ...uggestedLocalizationUpdatesOperation.swift | 12 + .../SynchronizeAppLogEventsOperation.swift | 60 ++ .../SynchronizeChatInputStateOperation.swift | 21 + ...onizeConsumeMessageContentsOperation.swift | 24 + .../SynchronizeEmojiKeywordsOperation.swift | 33 + .../SynchronizeGroupedPeersOperation.swift | 21 + ...onizeInstalledStickerPacksOperations.swift | 53 ++ ...rkAllUnseenPersonalMessagesOperation.swift | 17 + .../SynchronizePinnedChatsOperation.swift | 20 +- ...ynchronizeRecentlyUsedMediaOperation.swift | 69 ++ .../SynchronizeSavedGifsOperation.swift | 63 ++ .../SynchronizeSavedStickersOperation.swift | 63 ++ .../SynchronizeableChatInputState.swift | 0 .../SyncCore/Sources/TelegramChannel.swift | 300 ++++++ .../Sources/TelegramChatAdminRights.swift | 81 ++ .../Sources/TelegramChatBannedRights.swift | 50 + .../TelegramDeviceContactImportedData.swift | 29 + .../SyncCore/Sources/TelegramGroup.swift | 206 ++++ .../Sources/TelegramMediaAction.swift | 233 +++++ .../Sources}/TelegramMediaContact.swift | 9 +- .../TelegramMediaExpiredContent.swift | 0 .../SyncCore/Sources/TelegramMediaFile.swift | 474 +++++++++ .../SyncCore/Sources/TelegramMediaGame.swift | 102 ++ .../SyncCore/Sources/TelegramMediaImage.swift | 213 +++++ .../Sources}/TelegramMediaInvoice.swift | 0 .../SyncCore/Sources/TelegramMediaMap.swift | 201 ++++ .../SyncCore/Sources/TelegramMediaPoll.swift | 168 ++++ .../Sources}/TelegramMediaResource.swift | 0 .../Sources/TelegramMediaUnsupported.swift} | 2 +- .../Sources/TelegramMediaWebFile.swift | 59 ++ .../Sources/TelegramMediaWebpage.swift | 302 ++++++ .../TelegramPeerNotificationSettings.swift | 208 ++++ .../Sources}/TelegramSecretChat.swift | 6 +- .../SyncCore/Sources/TelegramTheme.swift | 77 ++ .../SyncCore/Sources/TelegramUser.swift | 255 +++++ .../Sources/TelegramUserPresence.swift | 116 +++ .../SyncCore/Sources/TelegramWallpaper.swift | 154 +++ .../TemporaryTwoStepPasswordToken.swift | 29 + .../TextEntitiesMessageAttribute.swift | 155 +++ .../SyncCore/Sources/ThemeSettings.swift | 33 + .../Sources/UnauthorizedAccountState.swift | 344 +++++++ .../UpdateMessageReactionsAction.swift | 20 + .../Sources}/ViewCountMessageAttribute.swift | 2 +- .../SyncCore/Sources/VoipConfiguration.swift | 43 + .../SyncCore/Sources/WalletCollection.swift | 55 ++ .../WasScheduledMessageAttribute.swift | 0 submodules/TelegramAnimatedStickerNode/BUCK | 1 + .../Sources/AnimatedStickerUtils.swift | 1 + .../Sources/TelegramAnimatedStickerNode.swift | 1 + submodules/TelegramAudio/BUCK | 2 +- submodules/TelegramBaseController/BUCK | 1 + .../LocationBroadcastActionSheetItem.swift | 1 + ...ionBroadcastNavigationAccessoryPanel.swift | 1 + ...ediaNavigationAccessoryContainerNode.swift | 1 + .../MediaNavigationAccessoryHeaderNode.swift | 1 + .../MediaNavigationAccessoryPanel.swift | 1 + .../Sources/TelegramBaseController.swift | 1 + .../Sources/CallController.swift | 1 + .../Sources/CallControllerNode.swift | 1 + .../Sources/CallFeedbackController.swift | 1 + .../Sources/CallKitIntegration.swift | 1 + .../Sources/CallRatingController.swift | 1 + .../Sources/CallSuggestTabController.swift | 1 + .../Sources/PresentationCall.swift | 1 + .../Sources/PresentationCallManager.swift | 1 + submodules/TelegramCore/BUCK | 1 + .../TelegramCore/TelegramCore/Account.swift | 176 +--- .../AccountIntermediateState.swift | 2 + .../TelegramCore/AccountManager.swift | 2 + .../TelegramCore/AccountState.swift | 342 +------ .../AccountStateManagementUtils.swift | 2 + .../TelegramCore/AccountStateManager.swift | 2 + .../TelegramCore/AccountStateReset.swift | 2 + .../TelegramCore/AccountViewTracker.swift | 2 + .../TelegramCore/AddPeerMember.swift | 2 + .../TelegramCore/AddressNames.swift | 2 + .../TelegramCore/ApiGroupOrChannel.swift | 2 + .../TelegramCore/TelegramCore/ApiUtils.swift | 135 +-- .../TelegramCore/AppChangelog.swift | 2 + .../TelegramCore/AppChangelogState.swift | 36 +- .../TelegramCore/AppConfiguration.swift | 39 +- .../TelegramCore/TelegramCore/AppUpdate.swift | 2 + .../ApplyMaxReadIndexInteractively.swift | 2 + .../TelegramCore/ApplyUpdateMessage.swift | 2 + .../TelegramCore/ArchivedStickerPacks.swift | 2 + .../TelegramCore/Authorization.swift | 2 + .../TelegramCore/AutodownloadSettings.swift | 85 +- .../TelegramCore/BlockedPeers.swift | 2 + .../TelegramCore/BlockedPeersContext.swift | 2 + .../TelegramCore/TelegramCore/BotInfo.swift | 44 +- .../TelegramCore/BotPaymentForm.swift | 2 + .../TelegramCore/CacheStorageSettings.swift | 36 +- .../TelegramCore/CachedChannelData.swift | 501 +--------- .../CachedChannelParticipants.swift | 2 + .../CachedGroupParticipants.swift | 106 +-- .../CachedSentMediaReferences.swift | 2 + .../TelegramCore/CachedStickerPack.swift | 39 +- .../TelegramCore/CallSessionManager.swift | 2 + .../TelegramCore/CanSendMessagesToPeer.swift | 2 + .../TelegramCore/CancelAccountReset.swift | 2 + .../ChangeAccountPhoneNumber.swift | 2 + .../ChangePeerNotificationSettings.swift | 2 + .../TelegramCore/ChannelAdminEventLogs.swift | 2 + .../TelegramCore/ChannelAdmins.swift | 2 + .../TelegramCore/ChannelBlacklist.swift | 2 + .../ChannelHistoryAvailabilitySettings.swift | 2 + .../TelegramCore/ChannelMembers.swift | 2 + .../ChannelOwnershipTransfer.swift | 1 + .../TelegramCore/ChannelParticipants.swift | 2 + .../TelegramCore/ChannelState.swift | 47 +- .../TelegramCore/ChatContextResult.swift | 2 + .../ChatHistoryPreloadManager.swift | 2 + .../CheckPeerChatServiceActions.swift | 2 + .../TelegramCore/ClearCloudDrafts.swift | 2 + .../CloudChatRemoveMessagesOperation.swift | 131 +-- .../TelegramCore/CloudFileMediaResource.swift | 848 +---------------- .../CloudMediaResourceParameters.swift | 1 + .../TelegramCore/CollectCacheUsageStats.swift | 2 + .../ConsumePersonalMessageAction.swift | 27 - .../TelegramCore/ContactManagement.swift | 2 + .../TelegramCore/ContactSyncManager.swift | 2 + .../TelegramCore/ContentPrivacySettings.swift | 41 +- .../TelegramCore/CoreSettings.swift | 2 + .../TelegramCore/DeepLinkInfo.swift | 2 + .../TelegramCore/DeleteMessages.swift | 2 + .../DeleteMessagesInteractively.swift | 11 +- .../TelegramCore/DeviceContact.swift | 32 +- ...EarliestUnseenPersonalMentionMessage.swift | 2 + .../TelegramCore/EmojiKeywords.swift | 93 +- .../TelegramCore/EnqueueMessage.swift | 2 + .../TelegramCore/ExportedInvitation.swift | 20 +- .../TelegramCore/TelegramCore/Fetch.swift | 2 + .../TelegramCore/FetchChatList.swift | 2 + .../FetchSecretFileResource.swift | 2 + .../TelegramCore/FetchedMediaResource.swift | 490 +--------- .../GlobalNotificationSettings.swift | 102 +- .../TelegramCore/GrantSecureIdAccess.swift | 2 + .../HistoryViewStateValidation.swift | 2 + .../TelegramCore/TelegramCore/Holes.swift | 2 + .../ImageRepresentationWithReference.swift | 1 + .../ImageRepresentationsUtils.swift | 2 + .../TelegramCore/ImportContact.swift | 2 + .../InitializeAccountAfterLogin.swift | 2 + ...InstallInteractiveReadMessagesAction.swift | 2 + .../TelegramCore/InstantPage.swift | 899 +---------------- .../TelegramCore/InvitationLinks.swift | 2 + .../TelegramCore/TelegramCore/JSON.swift | 135 +-- .../TelegramCore/JoinChannel.swift | 2 + .../TelegramCore/TelegramCore/JoinLink.swift | 2 + .../TelegramCore/LimitsConfiguration.swift | 73 +- .../LoadMessagesIfNecessary.swift | 2 + .../TelegramCore/LoadedPeer.swift | 2 + .../TelegramCore/LoadedPeerFromMessage.swift | 2 + .../TelegramCore/LoadedStickerPack.swift | 2 + .../TelegramCore/LocalizationInfo.swift | 56 +- .../TelegramCore/LocalizationListState.swift | 32 +- .../TelegramCore/LocalizationPreview.swift | 1 + .../TelegramCore/Localizations.swift | 18 +- .../TelegramCore/LoggingSettings.swift | 69 +- .../ManageChannelDiscussionGroup.swift | 1 + .../ManagedAppConfigurationUpdates.swift | 2 + .../ManagedAutodownloadSettingsUpdates.swift | 2 + .../ManagedAutoremoveMessageOperations.swift | 2 + ...gedCloudChatRemoveMessagesOperations.swift | 2 + .../ManagedConfigurationUpdates.swift | 2 + ...anagedConsumePersonalMessagesActions.swift | 2 + .../ManagedGlobalNotificationSettings.swift | 2 + .../ManagedLocalInputActivities.swift | 2 + ...ManagedLocalizationUpdatesOperations.swift | 2 + ...ManagedNotificationSettingsBehaviors.swift | 2 + ...nagedPendingPeerNotificationSettings.swift | 2 + .../ManagedProxyInfoUpdates.swift | 2 + .../TelegramCore/ManagedRecentStickers.swift | 2 + .../ManagedSecretChatOutgoingOperations.swift | 1 + ...gedSynchronizeAppLogEventsOperations.swift | 2 + ...dSynchronizeChatInputStateOperations.swift | 2 + ...nizeConsumeMessageContentsOperations.swift | 2 + ...edSynchronizeEmojiKeywordsOperations.swift | 2 + .../ManagedSynchronizeGroupMessageStats.swift | 3 + ...gedSynchronizeGroupedPeersOperations.swift | 2 + ...onizeInstalledStickerPacksOperations.swift | 2 + ...kAllUnseenPersonalMessagesOperations.swift | 2 + ...FeaturedStickerPacksAsSeenOperations.swift | 2 + ...agedSynchronizePinnedChatsOperations.swift | 2 + ...nchronizeRecentlyUsedMediaOperations.swift | 2 + ...anagedSynchronizeSavedGifsOperations.swift | 2 + ...edSynchronizeSavedStickersOperations.swift | 2 + .../TelegramCore/MarkAllChatsAsRead.swift | 2 + ...essageContentAsConsumedInteractively.swift | 2 + .../TelegramCore/MediaResourceApiUtils.swift | 1 + .../MessageMediaPreuploadManager.swift | 2 + .../TelegramCore/MessageReactionList.swift | 2 + .../TelegramCore/MessageReactions.swift | 19 +- .../TelegramCore/MessageUtils.swift | 51 + .../TelegramCore/MultipartFetch.swift | 2 + .../TelegramCore/MultipartUpload.swift | 26 +- .../TelegramCore/TelegramCore/Network.swift | 1 + .../TelegramCore/NetworkSettings.swift | 44 +- .../NotificationExceptionsList.swift | 2 + ...OutgoingMessageWithChatContextResult.swift | 2 + .../PeerAccessRestrictionInfo.swift | 61 +- .../TelegramCore/PeerAdmins.swift | 2 + .../TelegramCore/PeerCommands.swift | 2 + .../TelegramCore/PeerContactSettings.swift | 15 +- .../PeerLiveLocationsContext.swift | 2 + .../TelegramCore/PeerParticipants.swift | 2 + .../TelegramCore/PeerPhotoUpdater.swift | 2 + .../PeerSpecificStickerPack.swift | 2 + .../TelegramCore/TelegramCore/PeerUtils.swift | 2 + .../TelegramCore/PeersNearby.swift | 2 + .../TelegramCore/PendingMessageManager.swift | 2 + .../PendingMessageUploadedContent.swift | 2 + .../TelegramCore/TelegramCore/Polls.swift | 2 + .../TelegramCore/PrivacySettings.swift | 2 + .../TelegramCore/ProcessRemovedMedia.swift | 2 + ...ecretChatIncomingDecryptedOperations.swift | 1 + ...ecretChatIncomingEncryptedOperations.swift | 2 + .../TelegramCore/ProxyServersStatuses.swift | 2 + .../TelegramCore/ProxySettings.swift | 140 +-- .../ReactionsMessageAttribute.swift | 60 +- .../TelegramCore/RecentPeers.swift | 27 +- .../TelegramCore/RecentWebSessions.swift | 2 + .../RecentlySearchedPeerIds.swift | 2 + .../TelegramCore/RecentlyUsedHashtags.swift | 13 +- .../RegisterNotificationToken.swift | 2 + .../RemoteStorageConfiguration.swift | 26 +- .../TelegramCore/RemovePeerChat.swift | 2 + .../TelegramCore/RemovePeerMember.swift | 2 + .../ReplyMarkupMessageAttribute.swift | 160 +--- .../TelegramCore/ReportPeer.swift | 2 + .../TelegramCore/RequestEditMessage.swift | 2 + .../RequestMessageActionCallback.swift | 3 + .../TelegramCore/RequestSecureIdForm.swift | 2 + .../TelegramCore/RequestStartBot.swift | 2 + .../TelegramCore/RequestUserPhotos.swift | 2 + .../TelegramCore/ResolvePeerByName.swift | 41 +- .../TelegramCore/TelegramCore/RichText.swift | 293 +----- .../TelegramCore/SaveSecureIdValue.swift | 2 + .../TelegramCore/ScheduledMessages.swift | 19 +- .../TelegramCore/SearchGroupMembers.swift | 2 + .../TelegramCore/SearchMessages.swift | 2 + .../TelegramCore/SearchPeers.swift | 2 + .../TelegramCore/SearchStickers.swift | 27 +- .../TelegramCore/SecretChatEncryption.swift | 2 + .../SecretChatEncryptionConfig.swift | 30 +- .../SecretChatFileReference.swift | 32 +- ...SecretChatIncomingEncryptedOperation.swift | 66 +- .../SecretChatLayerNegotiation.swift | 2 + .../SecretChatOutgoingOperation.swift | 283 +----- .../TelegramCore/SecretChatRekeySession.swift | 1 + .../SecureFileMediaResource.swift | 66 +- .../SecureIdBankStatementValue.swift | 1 + .../TelegramCore/SecureIdConfiguration.swift | 38 +- .../TelegramCore/SecureIdDataTypes.swift | 12 +- ...ecureIdVerificationDocumentReference.swift | 1 + ...essageAutoremoveTimeoutInteractively.swift | 2 + .../TelegramCore/SingleMessageView.swift | 1 + .../TelegramCore/TelegramCore/SlowMode.swift | 2 + .../TelegramCore/TelegramCore/SplitTest.swift | 2 + .../TelegramCore/StandaloneSendMessage.swift | 2 + .../StandaloneUploadedMedia.swift | 1 + .../TelegramCore/StickerManagement.swift | 2 + .../TelegramCore/StickerPack.swift | 151 +-- .../StickerPackInteractiveOperations.swift | 2 + .../TelegramCore/StickerSetInstallation.swift | 2 + .../TelegramCore/StoreMessage_Telegram.swift | 2 + .../SuggestedLocalizationEntry.swift | 32 +- .../TelegramCore/SupportPeerId.swift | 2 + .../SynchronizeAppLogEventsOperation.swift | 59 +- .../SynchronizeChatInputStateOperation.swift | 20 +- ...onizeConsumeMessageContentsOperation.swift | 26 +- .../SynchronizeEmojiKeywordsOperation.swift | 32 +- .../SynchronizeGroupedPeersOperation.swift | 20 +- ...onizeInstalledStickerPacksOperation.swift} | 55 +- ...chronizeLocalizationUpdatesOperation.swift | 11 +- ...rkAllUnseenPersonalMessagesOperation.swift | 16 +- .../SynchronizePeerReadState.swift | 2 + ...nchronizeRecentlyUsedMediaOperations.swift | 68 +- .../SynchronizeSavedGifsOperation.swift | 62 +- .../SynchronizeSavedStickersOperation.swift | 62 +- .../TelegramCore/TelegramChannel.swift | 299 +----- .../TelegramChannelAdminRights.swift | 80 +- .../TelegramChannelBannedRights.swift | 49 +- .../TelegramDeviceContactImportInfo.swift | 30 +- .../TelegramCore/TelegramGroup.swift | 204 +--- .../TelegramCore/TelegramMediaAction.swift | 232 +---- .../TelegramCore/TelegramMediaFile.swift | 477 +--------- .../TelegramCore/TelegramMediaGame.swift | 101 +- .../TelegramCore/TelegramMediaImage.swift | 211 +--- .../TelegramCore/TelegramMediaMap.swift | 200 +--- .../TelegramCore/TelegramMediaPoll.swift | 167 +--- .../TelegramMediaWebDocument.swift | 66 +- .../TelegramCore/TelegramMediaWebFile.swift | 13 + .../TelegramCore/TelegramMediaWebpage.swift | 300 +----- .../TelegramPeerNotificationSettings.swift | 207 +--- .../TelegramCore/TelegramUser.swift | 254 +---- .../TelegramCore/TelegramUserPresence.swift | 115 +-- .../TelegramCore/TermsOfService.swift | 2 + .../TextEntitiesMessageAttribute.swift | 261 +---- .../TelegramCore/TelegramCore/Theme.swift | 76 +- .../TelegramCore/TelegramCore/Themes.swift | 48 +- .../ToggleChannelSignatures.swift | 2 + .../TelegramCore/TogglePeerChatPinned.swift | 2 + .../TelegramCore/TwoStepVerification.swift | 36 +- .../TelegramCore/UpdateAccountPeerName.swift | 2 + .../TelegramCore/UpdateCachedPeerData.swift | 2 + .../TelegramCore/UpdateContactName.swift | 2 + .../UpdateGroupSpecificStickerset.swift | 2 + .../TelegramCore/UpdateMessageMedia.swift | 2 + .../UpdatePeerChatInterfaceState.swift | 2 + .../TelegramCore/UpdatePeerInfo.swift | 2 + .../TelegramCore/UpdatePeers.swift | 2 + .../TelegramCore/UpdatePinnedMessage.swift | 2 + .../TelegramCore/UpdateSecretChat.swift | 2 + .../UpdatedAccountPrivacySettings.swift | 2 + .../TelegramCore/UpdatesApiUtils.swift | 2 + .../TelegramCore/VerifySecureIdValue.swift | 2 + .../TelegramCore/VoipConfiguration.swift | 43 +- .../TelegramCore/TelegramCore/Wallets.swift | 55 -- .../TelegramCore/TelegramCore/Wallpaper.swift | 153 +-- .../TelegramCore/Wallpapers.swift | 16 +- .../TelegramCore/WebpagePreview.swift | 2 + submodules/TelegramPermissions/BUCK | 1 + .../Sources/Permission.swift | 1 + submodules/TelegramPermissionsUI/BUCK | 1 + .../Sources/PermissionController.swift | 1 + .../Sources/PermissionControllerNode.swift | 1 + .../Sources/PermissionSplitTest.swift | 1 + submodules/TelegramPresentationData/BUCK | 1 + .../ChatControllerBackgroundNode.swift | 1 + .../Sources/ChatMessageBubbleImages.swift | 1 + .../Sources/DefaultDayPresentationTheme.swift | 1 + .../Sources/PresentationData.swift | 1 + .../Sources/PresentationTheme.swift | 1 + .../Sources/PresentationThemeCodable.swift | 1 + .../Sources/PresentationThemeCoder.swift | 1 + .../PresentationThemeEssentialGraphics.swift | 1 + .../Resources/PresentationResourcesChat.swift | 1 + .../Sources/WallpaperUtils.swift | 1 + submodules/TelegramStringFormatting/BUCK | 1 + .../Sources/MessageContentKind.swift | 1 + .../PeerNotificationSoundStrings.swift | 1 + .../Sources/PresenceStrings.swift | 1 + .../Sources/ServiceMessageStrings.swift | 1 + submodules/TelegramUI/BUCK | 2 + .../TelegramUI/AccountContext.swift | 1 + .../TelegramUI/TelegramUI/AppDelegate.swift | 5 +- .../TelegramUI/ApplicationContext.swift | 1 + ...orizationSequenceCodeEntryController.swift | 1 + ...ationSequenceCodeEntryControllerNode.swift | 1 + .../AuthorizationSequenceController.swift | 1 + ...rizationSequencePhoneEntryController.swift | 1 + ...tionSequencePhoneEntryControllerNode.swift | 1 + ...uthorizationSequenceSignUpController.swift | 1 + ...uthorizationSequenceSplashController.swift | 1 + .../TelegramUI/ChatBotInfoItem.swift | 1 + .../ChatBotStartInputPanelNode.swift | 1 + .../ChatButtonKeyboardInputNode.swift | 1 + .../ChatChannelSubscriberInputPanelNode.swift | 1 + .../ChatContextResultPeekContentNode.swift | 1 + .../TelegramUI/ChatController.swift | 1 + .../ChatControllerInteraction.swift | 1 + .../TelegramUI/ChatControllerNode.swift | 1 + .../ChatEditInterfaceMessageState.swift | 1 + .../TelegramUI/TelegramUI/ChatEmptyNode.swift | 1 + .../ChatFeedNavigationInputPanelNode.swift | 1 + .../ChatHistoryEntriesForView.swift | 1 + .../TelegramUI/ChatHistoryEntry.swift | 1 + .../TelegramUI/ChatHistoryGridNode.swift | 1 + .../TelegramUI/ChatHistoryListNode.swift | 1 + .../ChatHistorySearchContainerNode.swift | 1 + .../ChatHistoryViewForLocation.swift | 1 + .../TelegramUI/TelegramUI/ChatInfo.swift | 1 + .../TelegramUI/ChatInfoTitlePanelNode.swift | 1 + .../ChatInputContextPanelNode.swift | 1 + .../TelegramUI/ChatInputPanelNode.swift | 1 + .../ChatInterfaceInputContextPanels.swift | 1 + .../ChatInterfaceInputContexts.swift | 1 + .../TelegramUI/ChatInterfaceInputNodes.swift | 1 + .../TelegramUI/ChatInterfaceState.swift | 1 + .../ChatInterfaceStateAccessoryPanels.swift | 1 + .../ChatInterfaceStateContextMenus.swift | 1 + .../ChatInterfaceStateContextQueries.swift | 1 + .../ChatInterfaceStateInputPanels.swift | 1 + .../ChatInterfaceStateNavigationButtons.swift | 1 + .../ChatInterfaceTitlePanelNodes.swift | 1 + .../TelegramUI/ChatLoadingNode.swift | 1 + .../TelegramUI/ChatMediaInputGifPane.swift | 1 + .../ChatMediaInputGridEntries.swift | 1 + .../ChatMediaInputMetaSectionItemNode.swift | 1 + .../TelegramUI/ChatMediaInputNode.swift | 1 + .../ChatMediaInputPanelEntries.swift | 1 + .../ChatMediaInputPeerSpecificItem.swift | 1 + .../ChatMediaInputRecentGifsItem.swift | 1 + .../ChatMediaInputSettingsItem.swift | 1 + .../ChatMediaInputStickerGridItem.swift | 1 + .../ChatMediaInputStickerPackItem.swift | 1 + .../ChatMediaInputStickerPane.swift | 1 + .../ChatMediaInputTrendingItem.swift | 1 + .../ChatMediaInputTrendingPane.swift | 1 + .../ChatMessageActionButtonsNode.swift | 1 + .../ChatMessageActionItemNode.swift | 1 + .../ChatMessageActionUrlAuthController.swift | 1 + .../ChatMessageAnimatedStickerItemNode.swift | 1 + .../ChatMessageAttachedContentNode.swift | 1 + .../ChatMessageAvatarAccessoryItem.swift | 1 + .../ChatMessageBubbleContentNode.swift | 1 + .../ChatMessageBubbleItemNode.swift | 1 + .../ChatMessageCallBubbleContentNode.swift | 1 + .../ChatMessageContactBubbleContentNode.swift | 1 + .../ChatMessageDateAndStatusNode.swift | 1 + ...entLogPreviousDescriptionContentNode.swift | 1 + ...ssageEventLogPreviousLinkContentNode.swift | 1 + ...geEventLogPreviousMessageContentNode.swift | 1 + .../ChatMessageFileBubbleContentNode.swift | 1 + .../ChatMessageForwardInfoNode.swift | 1 + .../ChatMessageGameBubbleContentNode.swift | 1 + .../ChatMessageInstantVideoItemNode.swift | 1 + .../ChatMessageInteractiveFileNode.swift | 1 + ...atMessageInteractiveInstantVideoNode.swift | 1 + .../ChatMessageInteractiveMediaNode.swift | 1 + .../ChatMessageInvoiceBubbleContentNode.swift | 1 + .../TelegramUI/ChatMessageItem.swift | 1 + .../TelegramUI/ChatMessageItemView.swift | 1 + .../ChatMessageMapBubbleContentNode.swift | 1 + .../ChatMessageMediaBubbleContentNode.swift | 1 + .../ChatMessageNotificationItem.swift | 1 + .../ChatMessagePollBubbleContentNode.swift | 1 + .../TelegramUI/ChatMessageReplyInfoNode.swift | 1 + ...atMessageRestrictedBubbleContentNode.swift | 1 + .../ChatMessageSelectionInputPanelNode.swift | 1 + .../ChatMessageStickerItemNode.swift | 1 + .../ChatMessageTextBubbleContentNode.swift | 1 + ...tMessageUnsupportedBubbleContentNode.swift | 1 + .../ChatMessageWebpageBubbleContentNode.swift | 1 + .../TelegramUI/ChatOverlayNavigationBar.swift | 1 + .../ChatPanelInterfaceInteraction.swift | 1 + .../ChatPinnedMessageTitlePanelNode.swift | 1 + .../TelegramUI/ChatPresentationData.swift | 1 + .../ChatPresentationInterfaceState.swift | 1 + .../ChatRecentActionsController.swift | 1 + .../ChatRecentActionsControllerNode.swift | 1 + .../ChatRecentActionsControllerState.swift | 1 + .../ChatRecentActionsEmptyNode.swift | 1 + .../ChatRecentActionsFilterController.swift | 1 + .../ChatRecentActionsHistoryTransition.swift | 1 + ...ntActionsSearchNavigationContentNode.swift | 1 + .../ChatRecordingPreviewInputPanelNode.swift | 1 + .../ChatReportPeerTitlePanelNode.swift | 1 + .../ChatRestrictedInputPanelNode.swift | 1 + .../ChatScheduleTimeController.swift | 1 + .../ChatScheduleTimeControllerNode.swift | 1 + .../TelegramUI/ChatSearchInputPanelNode.swift | 1 + .../ChatSearchNavigationContentNode.swift | 1 + .../ChatSearchResultsContollerNode.swift | 1 + .../ChatSearchResultsController.swift | 1 + .../TelegramUI/ChatSearchState.swift | 1 + ...ChatSecretAutoremoveTimerActionSheet.swift | 1 + ...SendMessageActionSheetControllerNode.swift | 1 + .../ChatTextInputMediaRecordingButton.swift | 1 + .../TelegramUI/ChatTextInputPanelNode.swift | 1 + .../ChatTextLinkEditController.swift | 1 + .../TelegramUI/TelegramUI/ChatTitleView.swift | 1 + .../ChatUnblockInputPanelNode.swift | 1 + .../TelegramUI/CheckDiskSpace.swift | 1 + .../CommandChatInputContextPanelNode.swift | 1 + .../CommandChatInputPanelItem.swift | 1 + .../TelegramUI/ComposeController.swift | 1 + .../TelegramUI/ComposeControllerNode.swift | 1 + .../ContactMultiselectionController.swift | 1 + .../ContactMultiselectionControllerNode.swift | 1 + .../ContactSelectionController.swift | 1 + .../ContactSelectionControllerNode.swift | 1 + .../TelegramUI/CreateChannelController.swift | 1 + .../TelegramUI/CreateGroupController.swift | 1 + .../TelegramUI/DeleteChatInputPanelNode.swift | 1 + .../TelegramUI/DeviceContactDataManager.swift | 1 + ...textResultsChatInputContextPanelNode.swift | 1 + .../DocumentPreviewController.swift | 1 + .../TelegramUI/EditAccessoryPanelNode.swift | 1 + .../TelegramUI/EmojiResources.swift | 1 + .../EmojisChatInputContextPanelNode.swift | 1 + .../TelegramUI/EmojisChatInputPanelItem.swift | 1 + .../FetchCachedRepresentations.swift | 1 + .../TelegramUI/TelegramUI/FetchManager.swift | 1 + .../TelegramUI/TelegramUI/FetchResource.swift | 1 + .../TelegramUI/FetchVideoMediaResource.swift | 1 + .../TelegramUI/FileMediaResourceStatus.swift | 1 + .../ForwardAccessoryPanelNode.swift | 1 + .../TelegramUI/GifPaneSearchContentNode.swift | 1 + .../TelegramUI/GridMessageItem.swift | 1 + .../HashtagChatInputContextPanelNode.swift | 1 + .../HashtagChatInputPanelItem.swift | 1 + ...textResultsChatInputContextPanelNode.swift | 1 + ...ListContextResultsChatInputPanelItem.swift | 1 + .../HorizontalStickerGridItem.swift | 1 + ...rizontalStickersChatContextPanelNode.swift | 1 + .../TelegramUI/ICloudResources.swift | 1 + .../TelegramUI/InChatPrefetchManager.swift | 1 + .../TelegramUI/TelegramUI/LegacyCamera.swift | 1 + .../LegacyInstantVideoController.swift | 1 + .../LegacyLiveUploadInterface.swift | 1 + .../TelegramUI/ListMessageFileItemNode.swift | 1 + .../TelegramUI/ListMessageHoleItem.swift | 1 + .../TelegramUI/ListMessageItem.swift | 1 + .../ListMessageSnippetItemNode.swift | 1 + .../TelegramUI/ManageSharedAccountInfo.swift | 1 + .../TelegramUI/ManagedAudioRecorder.swift | 1 + .../MediaInputPaneTrendingItem.swift | 1 + .../TelegramUI/TelegramUI/MediaManager.swift | 1 + .../TelegramUI/MediaPlaybackStoredState.swift | 1 + .../MentionChatInputContextPanelNode.swift | 1 + .../MentionChatInputPanelItem.swift | 1 + ...ultiplexedSoftwareVideoSourceManager.swift | 1 + .../TelegramUI/MultiplexedVideoNode.swift | 1 + .../TelegramUI/NavigateToChatController.swift | 1 + .../NotificationContainerController.swift | 1 + .../NotificationContentContext.swift | 1 + .../TelegramUI/OpenAddContact.swift | 1 + .../TelegramUI/OpenChatMessage.swift | 1 + .../TelegramUI/OpenResolvedUrl.swift | 1 + .../TelegramUI/TelegramUI/OpenUrl.swift | 1 + .../OverlayAudioPlayerController.swift | 1 + .../TelegramUI/OverlayInstantVideoNode.swift | 1 + .../OverlayPlayerControllerNode.swift | 1 + .../OverlayPlayerControlsNode.swift | 1 + .../TelegramUI/PaneSearchContainerNode.swift | 1 + .../TelegramUI/TelegramUI/Pasteboard.swift | 1 + .../PeerMediaCollectionController.swift | 1 + .../PeerMediaCollectionControllerNode.swift | 1 + .../PeerMediaCollectionSectionsNode.swift | 1 + .../PeerMessagesMediaPlaylist.swift | 1 + .../TelegramUI/PeerSelectionController.swift | 1 + .../PeerSelectionControllerNode.swift | 1 + .../TelegramUI/PrefetchManager.swift | 1 + .../PreparedChatHistoryViewTransition.swift | 1 + .../TelegramUI/ReplyAccessoryPanelNode.swift | 1 + ...retChatHandshakeStatusInputPanelNode.swift | 1 + .../TelegramUI/ShareExtensionContext.swift | 1 + .../TelegramUI/SharedAccountContext.swift | 1 + .../TelegramUI/SharedMediaPlayer.swift | 1 + .../SharedNotificationManager.swift | 1 + .../TelegramUI/SharedWakeupManager.swift | 1 + .../SoftwareVideoLayerFrameManager.swift | 1 + .../SoftwareVideoThumbnailLayer.swift | 1 + ...StickerPanePeerSpecificSetupGridItem.swift | 1 + .../StickerPaneSearchContentNode.swift | 1 + .../StickerPaneSearchGlobaltem.swift | 1 + .../StickerPaneSearchStickerItem.swift | 1 + .../StickersChatInputContextPanelItem.swift | 1 + .../StickersChatInputContextPanelNode.swift | 1 + .../TelegramUI/StoreDownloadedMedia.swift | 1 + .../StringForMessageTimestampStatus.swift | 1 + .../TelegramUI/SuppressContactsWarning.swift | 1 + .../TelegramAccountAuxiliaryMethods.swift | 1 + .../TelegramUI/TelegramRootController.swift | 1 + .../TelegramUI/TextLinkHandling.swift | 1 + .../TelegramUI/ThemeUpdateManager.swift | 1 + .../TelegramUI/TimeBasedVideoPreload.swift | 1 + .../TransformOutgoingMessageMedia.swift | 1 + .../TelegramUI/UpgradedAccounts.swift | 1 + ...textResultsChatInputContextPanelNode.swift | 1 + ...ntextResultsChatInputPanelButtonItem.swift | 1 + ...ListContextResultsChatInputPanelItem.swift | 1 + .../TelegramUI/WalletContextImpl.swift | 1 + .../TelegramUI/WallpaperPreviewMedia.swift | 1 + .../TelegramUI/WallpaperUploadManager.swift | 1 + .../TelegramUI/TelegramUI/WatchManager.swift | 1 + .../WebpagePreviewAccessoryPanelNode.swift | 1 + .../TelegramUI/WidgetDataContext.swift | 1 + submodules/TelegramUIPreferences/BUCK | 1 + ...LegacyAutomaticMediaDownloadSettings.swift | 1 + .../Sources/MediaAutoDownloadSettings.swift | 1 + .../Sources/PostboxKeys.swift | 1 + .../Sources/PresentationThemeSettings.swift | 1 + .../Sources/VoiceCallSettings.swift | 1 + submodules/TelegramUniversalVideoContent/BUCK | 1 + .../Sources/NativeVideoContent.swift | 1 + .../Sources/OverlayUniversalVideoNode.swift | 1 + .../Sources/PlatformVideoContent.swift | 1 + .../Sources/SystemVideoContent.swift | 1 + .../Sources/WebEmbedPlayerNode.swift | 1 + .../Sources/WebEmbedVideoContent.swift | 1 + submodules/TelegramUpdateUI/BUCK | 1 + .../Sources/UpdateInfoController.swift | 1 + .../Sources/UpdateInfoItem.swift | 1 + submodules/TelegramVoip/BUCK | 1 + .../Sources/OngoingCallContext.swift | 1 + .../TemporaryCachedPeerDataManager/BUCK | 7 +- .../Sources/CachedChannelAdmins.swift | 1 + .../ChannelMemberCategoryListContext.swift | 1 + ...annelMemberCategoriesContextsManager.swift | 1 + submodules/TextFormat/BUCK | 5 +- .../Sources/GenerateTextEntities.swift | 1 + .../Sources/StringWithAppliedEntities.swift | 1 + submodules/UndoUI/BUCK | 1 + submodules/UrlHandling/BUCK | 1 + .../UrlHandling/Sources/UrlHandling.swift | 1 + submodules/WallpaperResources/BUCK | 1 + .../Sources/WallpaperCache.swift | 1 + .../Sources/WallpaperResources.swift | 1 + submodules/WatchBridge/BUCK | 1 + .../WatchBridge/Sources/WatchBridge.swift | 1 + .../Sources/WatchCommunicationManager.swift | 1 + .../Sources/WatchRequestHandlers.swift | 1 + submodules/WebSearchUI/BUCK | 1 + .../Sources/LegacyWebSearchEditor.swift | 1 + .../Sources/LegacyWebSearchGallery.swift | 1 + .../Sources/WebSearchController.swift | 1 + .../Sources/WebSearchControllerNode.swift | 1 + .../Sources/WebSearchGalleryController.swift | 1 + .../WebSearchGalleryFooterContentNode.swift | 1 + .../WebSearchUI/Sources/WebSearchItem.swift | 1 + .../WebSearchNavigationContentNode.swift | 1 + .../Sources/WebSearchRecentQueryItem.swift | 1 + .../Sources/WebSearchVideoGalleryItem.swift | 1 + 1162 files changed, 12205 insertions(+), 10925 deletions(-) delete mode 100644 NotificationService/Crypto.h delete mode 100644 NotificationService/Crypto.m create mode 100644 NotificationService/Sync.h create mode 100644 NotificationService/Sync.m create mode 100644 NotificationService/Sync.swift create mode 100644 submodules/BuildConfigExtra/BUCK create mode 100644 submodules/BuildConfigExtra/Sources/BuildConfigExtra.h create mode 100644 submodules/BuildConfigExtra/Sources/BuildConfigExtra.m create mode 100644 submodules/SyncCore/BUCK create mode 100644 submodules/SyncCore/Sources/AccountBackupDataAttribute.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/AccountEnvironmentAttribute.swift (100%) rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/AccountSortOrderAttribute.swift (100%) create mode 100644 submodules/SyncCore/Sources/AppChangelogState.swift create mode 100644 submodules/SyncCore/Sources/AppConfiguration.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/ArchivedStickerPacksInfo.swift (100%) rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/AuthorSignatureMessageAttribute.swift (93%) create mode 100644 submodules/SyncCore/Sources/AuthorizedAccountState.swift create mode 100644 submodules/SyncCore/Sources/AutodownloadSettings.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/AutoremoveTimeoutMessageAttribute.swift (67%) create mode 100644 submodules/SyncCore/Sources/BotInfo.swift create mode 100644 submodules/SyncCore/Sources/CacheStorageSettings.swift create mode 100644 submodules/SyncCore/Sources/CachedChannelData.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/CachedGroupData.swift (92%) create mode 100644 submodules/SyncCore/Sources/CachedGroupParticipants.swift create mode 100644 submodules/SyncCore/Sources/CachedLocalizationInfos.swift create mode 100644 submodules/SyncCore/Sources/CachedRecentPeers.swift create mode 100644 submodules/SyncCore/Sources/CachedResolvedByNamePeer.swift create mode 100644 submodules/SyncCore/Sources/CachedSecureIdConfiguration.swift create mode 100644 submodules/SyncCore/Sources/CachedStickerPack.swift create mode 100644 submodules/SyncCore/Sources/CachedStickerQueryResult.swift create mode 100644 submodules/SyncCore/Sources/CachedThemesConfiguration.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/CachedUserData.swift (88%) create mode 100644 submodules/SyncCore/Sources/CachedWallpapersConfiguration.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/ChannelMessageStateVersionAttribute.swift (100%) create mode 100644 submodules/SyncCore/Sources/ChannelState.swift create mode 100644 submodules/SyncCore/Sources/CloudChatRemoveMessagesOperation.swift create mode 100644 submodules/SyncCore/Sources/CloudFileMediaResource.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/ConsumableContentMessageAttribute.swift (100%) rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/ConsumablePersonalMentionMessageAttribute.swift (100%) create mode 100644 submodules/SyncCore/Sources/ConsumePersonalMessageAction.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/ContactsSettings.swift (100%) create mode 100644 submodules/SyncCore/Sources/ContentPrivacySettings.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/ContentRequiresValidationMessageAttribute.swift (100%) rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/EditedMessageAttribute.swift (93%) create mode 100644 submodules/SyncCore/Sources/EmojiKeywordCollectionInfo.swift create mode 100644 submodules/SyncCore/Sources/EmojiKeywordItem.swift create mode 100644 submodules/SyncCore/Sources/ExportedInvitation.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/FeaturedStickerPack.swift (89%) rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/ForwardSourceInfoAttribute.swift (94%) create mode 100644 submodules/SyncCore/Sources/GlobalNotificationSettings.swift create mode 100644 submodules/SyncCore/Sources/ImportableDeviceContactData.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/InlineBotMessageAttribute.swift (95%) create mode 100644 submodules/SyncCore/Sources/InstantPage.swift create mode 100644 submodules/SyncCore/Sources/JSON.swift create mode 100644 submodules/SyncCore/Sources/LimitsConfiguration.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/Localization.swift (84%) create mode 100644 submodules/SyncCore/Sources/LocalizationInfo.swift create mode 100644 submodules/SyncCore/Sources/LocalizationListState.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/LocalizationSettings.swift (100%) rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/LoggedOutAccountAttribute.swift (100%) create mode 100644 submodules/SyncCore/Sources/LoggingSettings.swift create mode 100644 submodules/SyncCore/Sources/MediaReference.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/Namespaces.swift (85%) create mode 100644 submodules/SyncCore/Sources/NetworkSettings.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/NotificationInfoMessageAttribute.swift (100%) rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/OutgoingChatContextResultMessageAttribute.swift (93%) rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/OutgoingContentInfoMessageAttribute.swift (100%) rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/OutgoingMessageInfoAttribute.swift (73%) rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/OutgoingScheduleInfoMessageAttribute.swift (100%) rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/PeerAccessHash.swift (100%) create mode 100644 submodules/SyncCore/Sources/PeerAccessRestrictionInfo.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/PeerGroupMessageStateVersionAttribute.swift (100%) create mode 100644 submodules/SyncCore/Sources/PeerReference.swift create mode 100644 submodules/SyncCore/Sources/PeerStatusSettings.swift create mode 100644 submodules/SyncCore/Sources/ProxySettings.swift create mode 100644 submodules/SyncCore/Sources/ReactionsMessageAttribute.swift create mode 100644 submodules/SyncCore/Sources/RecentHashtagItem.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/RecentMediaItem.swift (94%) rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/RecentPeerItem.swift (89%) rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/RegularChatState.swift (55%) create mode 100644 submodules/SyncCore/Sources/RemoteStorageConfiguration.swift create mode 100644 submodules/SyncCore/Sources/ReplyMarkupMessageAttribute.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/ReplyMessageAttribute.swift (100%) rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/RestrictedContentMessageAttribute.swift (100%) create mode 100644 submodules/SyncCore/Sources/RichText.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/SavedStickerItem.swift (92%) rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/SearchBotsConfiguration.swift (91%) create mode 100644 submodules/SyncCore/Sources/SecretChatEncryptionConfig.swift create mode 100644 submodules/SyncCore/Sources/SecretChatFileReference.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/SecretChatIncomingDecryptedOperation.swift (66%) create mode 100644 submodules/SyncCore/Sources/SecretChatIncomingEncryptedOperation.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/SecretChatKeychain.swift (90%) create mode 100644 submodules/SyncCore/Sources/SecretChatOutgoingOperation.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/SecretChatSettings.swift (100%) rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/SecretChatState.swift (92%) create mode 100644 submodules/SyncCore/Sources/SecretFileEncryptionKey.swift create mode 100644 submodules/SyncCore/Sources/SecureFileMediaResource.swift create mode 100644 submodules/SyncCore/Sources/SecureIdFileReference.swift create mode 100644 submodules/SyncCore/Sources/SendScheduledMessageImmediatelyAction.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/SourceReferenceMessageAttribute.swift (100%) create mode 100644 submodules/SyncCore/Sources/StandaloneAccountTransaction.swift create mode 100644 submodules/SyncCore/Sources/StickerPackCollectionInfo.swift create mode 100644 submodules/SyncCore/Sources/StickerPackItem.swift create mode 100644 submodules/SyncCore/Sources/SuggestedLocalizationEntry.swift create mode 100644 submodules/SyncCore/Sources/SuggestedLocalizationUpdatesOperation.swift create mode 100644 submodules/SyncCore/Sources/SynchronizeAppLogEventsOperation.swift create mode 100644 submodules/SyncCore/Sources/SynchronizeChatInputStateOperation.swift create mode 100644 submodules/SyncCore/Sources/SynchronizeConsumeMessageContentsOperation.swift create mode 100644 submodules/SyncCore/Sources/SynchronizeEmojiKeywordsOperation.swift create mode 100644 submodules/SyncCore/Sources/SynchronizeGroupedPeersOperation.swift create mode 100644 submodules/SyncCore/Sources/SynchronizeInstalledStickerPacksOperations.swift create mode 100644 submodules/SyncCore/Sources/SynchronizeMarkAllUnseenPersonalMessagesOperation.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/SynchronizePinnedChatsOperation.swift (79%) create mode 100644 submodules/SyncCore/Sources/SynchronizeRecentlyUsedMediaOperation.swift create mode 100644 submodules/SyncCore/Sources/SynchronizeSavedGifsOperation.swift create mode 100644 submodules/SyncCore/Sources/SynchronizeSavedStickersOperation.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/SynchronizeableChatInputState.swift (100%) create mode 100644 submodules/SyncCore/Sources/TelegramChannel.swift create mode 100644 submodules/SyncCore/Sources/TelegramChatAdminRights.swift create mode 100644 submodules/SyncCore/Sources/TelegramChatBannedRights.swift create mode 100644 submodules/SyncCore/Sources/TelegramDeviceContactImportedData.swift create mode 100644 submodules/SyncCore/Sources/TelegramGroup.swift create mode 100644 submodules/SyncCore/Sources/TelegramMediaAction.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/TelegramMediaContact.swift (96%) rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/TelegramMediaExpiredContent.swift (100%) create mode 100644 submodules/SyncCore/Sources/TelegramMediaFile.swift create mode 100644 submodules/SyncCore/Sources/TelegramMediaGame.swift create mode 100644 submodules/SyncCore/Sources/TelegramMediaImage.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/TelegramMediaInvoice.swift (100%) create mode 100644 submodules/SyncCore/Sources/TelegramMediaMap.swift create mode 100644 submodules/SyncCore/Sources/TelegramMediaPoll.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/TelegramMediaResource.swift (100%) rename submodules/{TelegramCore/TelegramCore/TeleramMediaUnsupported.swift => SyncCore/Sources/TelegramMediaUnsupported.swift} (96%) create mode 100644 submodules/SyncCore/Sources/TelegramMediaWebFile.swift create mode 100644 submodules/SyncCore/Sources/TelegramMediaWebpage.swift create mode 100644 submodules/SyncCore/Sources/TelegramPeerNotificationSettings.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/TelegramSecretChat.swift (93%) create mode 100644 submodules/SyncCore/Sources/TelegramTheme.swift create mode 100644 submodules/SyncCore/Sources/TelegramUser.swift create mode 100644 submodules/SyncCore/Sources/TelegramUserPresence.swift create mode 100644 submodules/SyncCore/Sources/TelegramWallpaper.swift create mode 100644 submodules/SyncCore/Sources/TemporaryTwoStepPasswordToken.swift create mode 100644 submodules/SyncCore/Sources/TextEntitiesMessageAttribute.swift create mode 100644 submodules/SyncCore/Sources/ThemeSettings.swift create mode 100644 submodules/SyncCore/Sources/UnauthorizedAccountState.swift create mode 100644 submodules/SyncCore/Sources/UpdateMessageReactionsAction.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/ViewCountMessageAttribute.swift (94%) create mode 100644 submodules/SyncCore/Sources/VoipConfiguration.swift create mode 100644 submodules/SyncCore/Sources/WalletCollection.swift rename submodules/{TelegramCore/TelegramCore => SyncCore/Sources}/WasScheduledMessageAttribute.swift (100%) delete mode 100644 submodules/TelegramCore/TelegramCore/ConsumePersonalMessageAction.swift rename submodules/TelegramCore/TelegramCore/{SynchronizeInstalledStickerPacksOperations.swift => SynchronizeInstalledStickerPacksOperation.swift} (71%) create mode 100644 submodules/TelegramCore/TelegramCore/TelegramMediaWebFile.swift diff --git a/BUCK b/BUCK index 3a2d304c68..cebcf05495 100644 --- a/BUCK +++ b/BUCK @@ -37,6 +37,7 @@ framework_dependencies = [ "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit", "//submodules/Postbox:Postbox", "//submodules/TelegramApi:TelegramApi", + "//submodules/SyncCore:SyncCore", "//submodules/TelegramCore:TelegramCore", "//submodules/AsyncDisplayKit:AsyncDisplayKit", "//submodules/Display:Display", @@ -313,10 +314,12 @@ apple_binary( name = "NotificationServiceBinary", srcs = glob([ "NotificationService/**/*.m", + "NotificationService/**/*.swift", ]), headers = glob([ "NotificationService/**/*.h", ]), + bridging_header = "NotificationService/NotificationService-Bridging-Header.h", configs = notification_service_extension_configs(), swift_compiler_flags = [ "-application-extension", @@ -336,7 +339,10 @@ apple_binary( deps = [ "//submodules/BuildConfig:BuildConfig", "//submodules/MtProtoKit:MtProtoKit#shared", - "//submodules/OpenSSLEncryptionProvider:OpenSSLEncryptionProvider", + "//submodules/EncryptionProvider:EncryptionProvider", + "//submodules/sqlcipher:sqlcipher", + #"//submodules/Postbox:Postbox#shared", + #"//submodules/SyncCore:SyncCore#shared", ], frameworks = [ "$SDKROOT/System/Library/Frameworks/Foundation.framework", @@ -382,6 +388,7 @@ apple_binary( "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramApi:TelegramApi#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramCore:TelegramCore#shared", "//submodules/BuildConfig:BuildConfig", "//submodules/OpenSSLEncryptionProvider:OpenSSLEncryptionProvider", diff --git a/Makefile b/Makefile index a74d87713a..565b3215a6 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,8 @@ build_arm64: check_env //submodules/Postbox:Postbox#shared,iphoneos-arm64 \ //submodules/TelegramApi:TelegramApi#dwarf-and-dsym,shared,iphoneos-arm64 \ //submodules/TelegramApi:TelegramApi#shared,iphoneos-arm64 \ + //submodules/SyncCore:SyncCore#dwarf-and-dsym,shared,iphoneos-arm64 \ + //submodules/SyncCore:SyncCore#shared,iphoneos-arm64 \ //submodules/TelegramCore:TelegramCore#dwarf-and-dsym,shared,iphoneos-arm64 \ //submodules/TelegramCore:TelegramCore#shared,iphoneos-arm64 \ //submodules/AsyncDisplayKit:AsyncDisplayKit#dwarf-and-dsym,shared,iphoneos-arm64 \ @@ -80,6 +82,8 @@ build_debug_arm64: check_env //submodules/Postbox:Postbox#shared,iphoneos-arm64 \ //submodules/TelegramApi:TelegramApi#dwarf-and-dsym,shared,iphoneos-arm64 \ //submodules/TelegramApi:TelegramApi#shared,iphoneos-arm64 \ + //submodules/SyncCore:SyncCore#dwarf-and-dsym,shared,iphoneos-arm64 \ + //submodules/SyncCore:SyncCore#shared,iphoneos-arm64 \ //submodules/TelegramCore:TelegramCore#dwarf-and-dsym,shared,iphoneos-arm64 \ //submodules/TelegramCore:TelegramCore#shared,iphoneos-arm64 \ //submodules/AsyncDisplayKit:AsyncDisplayKit#dwarf-and-dsym,shared,iphoneos-arm64 \ @@ -122,6 +126,8 @@ build_debug_armv7: check_env //submodules/Postbox:Postbox#shared,iphoneos-armv7 \ //submodules/TelegramApi:TelegramApi#dwarf-and-dsym,shared,iphoneos-armv7 \ //submodules/TelegramApi:TelegramApi#shared,iphoneos-armv7 \ + //submodules/SyncCore:SyncCore#dwarf-and-dsym,shared,iphoneos-armv7 \ + //submodules/SyncCore:SyncCore#shared,iphoneos-armv7 \ //submodules/TelegramCore:TelegramCore#dwarf-and-dsym,shared,iphoneos-armv7 \ //submodules/TelegramCore:TelegramCore#shared,iphoneos-armv7 \ //submodules/AsyncDisplayKit:AsyncDisplayKit#dwarf-and-dsym,shared,iphoneos-armv7 \ @@ -150,6 +156,8 @@ build: check_env //submodules/Postbox:Postbox#shared,iphoneos-arm64,iphoneos-armv7 \ //submodules/TelegramApi:TelegramApi#dwarf-and-dsym,shared,iphoneos-arm64,iphoneos-armv7 \ //submodules/TelegramApi:TelegramApi#shared,iphoneos-arm64,iphoneos-armv7 \ + //submodules/SyncCore:SyncCore#dwarf-and-dsym,shared,iphoneos-arm64,iphoneos-armv7 \ + //submodules/SyncCore:SyncCore#shared,iphoneos-arm64,iphoneos-armv7 \ //submodules/TelegramCore:TelegramCore#dwarf-and-dsym,shared,iphoneos-arm64,iphoneos-armv7 \ //submodules/TelegramCore:TelegramCore#shared,iphoneos-arm64,iphoneos-armv7 \ //submodules/AsyncDisplayKit:AsyncDisplayKit#dwarf-and-dsym,shared,iphoneos-arm64,iphoneos-armv7 \ @@ -292,6 +300,8 @@ build_buckdebug: check_env //submodules/Postbox:Postbox#shared,iphoneos-arm64 \ //submodules/TelegramApi:TelegramApi#dwarf-and-dsym,shared,iphoneos-arm64 \ //submodules/TelegramApi:TelegramApi#shared,iphoneos-arm64 \ + //submodules/SyncCore:SyncCore#dwarf-and-dsym,shared,iphoneos-arm64 \ + //submodules/SyncCore:SyncCore#shared,iphoneos-arm64 \ //submodules/TelegramCore:TelegramCore#dwarf-and-dsym,shared,iphoneos-arm64 \ //submodules/TelegramCore:TelegramCore#shared,iphoneos-arm64 \ //submodules/AsyncDisplayKit:AsyncDisplayKit#dwarf-and-dsym,shared,iphoneos-arm64 \ @@ -330,6 +340,8 @@ build_verbose: check_env //submodules/Postbox:Postbox#shared,iphoneos-arm64 \ //submodules/TelegramApi:TelegramApi#dwarf-and-dsym,shared,iphoneos-arm64 \ //submodules/TelegramApi:TelegramApi#shared,iphoneos-arm64 \ + //submodules/SyncCore:SyncCore#dwarf-and-dsym,shared,iphoneos-arm64 \ + //submodules/SyncCore:SyncCore#shared,iphoneos-arm64 \ //submodules/TelegramCore:TelegramCore#dwarf-and-dsym,shared,iphoneos-arm64 \ //submodules/TelegramCore:TelegramCore#shared,iphoneos-arm64 \ //submodules/AsyncDisplayKit:AsyncDisplayKit#dwarf-and-dsym,shared,iphoneos-arm64 \ diff --git a/NotificationContent/NotificationViewController.swift b/NotificationContent/NotificationViewController.swift index f08edd06a7..9f5f7e31e6 100644 --- a/NotificationContent/NotificationViewController.swift +++ b/NotificationContent/NotificationViewController.swift @@ -38,7 +38,7 @@ class NotificationViewController: UIViewController, UNNotificationContentExtensi let appVersion = (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String) ?? "unknown" - self.impl = NotificationViewControllerImpl(initializationData: NotificationViewControllerInitializationData(appGroupPath: appGroupUrl.path, apiId: buildConfig.apiId, languagesCategory: languagesCategory, encryptionParameters: encryptionParameters, appVersion: appVersion, bundleData: buildConfig.bundleData(withAppToken: nil)), setPreferredContentSize: { [weak self] size in + self.impl = NotificationViewControllerImpl(initializationData: NotificationViewControllerInitializationData(appGroupPath: appGroupUrl.path, apiId: buildConfig.apiId, languagesCategory: languagesCategory, encryptionParameters: encryptionParameters, appVersion: appVersion, bundleData: buildConfig.bundleData(withAppToken: nil, signatureDict: nil)), setPreferredContentSize: { [weak self] size in self?.preferredContentSize = size }) } diff --git a/NotificationService/Crypto.h b/NotificationService/Crypto.h deleted file mode 100644 index 02e13c6c8e..0000000000 --- a/NotificationService/Crypto.h +++ /dev/null @@ -1,7 +0,0 @@ -#import - -NS_ASSUME_NONNULL_BEGIN - -NSData *MTAesDecrypt(NSData *data, NSData *key, NSData *iv); - -NS_ASSUME_NONNULL_END diff --git a/NotificationService/Crypto.m b/NotificationService/Crypto.m deleted file mode 100644 index d5a8f0a0b4..0000000000 --- a/NotificationService/Crypto.m +++ /dev/null @@ -1,73 +0,0 @@ -#import "Crypto.h" -#import - -#define AES_BLOCK_SIZE 16 - -#define N_WORDS (AES_BLOCK_SIZE / sizeof(unsigned long)) -typedef struct { - unsigned long data[N_WORDS]; -} aes_block_t; - -static void MyAesIgeDecrypt(const void *inBytes, int length, void *outBytes, const void *key, int keyLength, void *iv) { - unsigned char aesIv[AES_BLOCK_SIZE]; - memcpy(aesIv, iv, AES_BLOCK_SIZE); - unsigned char ccIv[AES_BLOCK_SIZE]; - memcpy(ccIv, iv + AES_BLOCK_SIZE, AES_BLOCK_SIZE); - - assert(((size_t)inBytes | (size_t)outBytes | (size_t)aesIv | (size_t)ccIv) % sizeof(long) == - 0); - - CCCryptorRef decryptor = NULL; - CCCryptorCreate(kCCDecrypt, kCCAlgorithmAES128, kCCOptionECBMode, key, keyLength, nil, &decryptor); - if (decryptor != NULL) { - int len; - size_t n; - - len = length / AES_BLOCK_SIZE; - - aes_block_t *ivp = (aes_block_t *)(aesIv); - aes_block_t *iv2p = (aes_block_t *)(ccIv); - - while (len) { - aes_block_t tmp; - aes_block_t *inp = (aes_block_t *)inBytes; - aes_block_t *outp = (aes_block_t *)outBytes; - - for (n = 0; n < N_WORDS; ++n) - tmp.data[n] = inp->data[n] ^ iv2p->data[n]; - - size_t dataOutMoved = 0; - CCCryptorStatus result = CCCryptorUpdate(decryptor, &tmp, AES_BLOCK_SIZE, outBytes, AES_BLOCK_SIZE, &dataOutMoved); - assert(result == kCCSuccess); - assert(dataOutMoved == AES_BLOCK_SIZE); - - for (n = 0; n < N_WORDS; ++n) - outp->data[n] ^= ivp->data[n]; - - ivp = inp; - iv2p = outp; - - inBytes += AES_BLOCK_SIZE; - outBytes += AES_BLOCK_SIZE; - - --len; - } - - memcpy(iv, ivp->data, AES_BLOCK_SIZE); - memcpy(iv + AES_BLOCK_SIZE, iv2p->data, AES_BLOCK_SIZE); - - CCCryptorRelease(decryptor); - } -} - -NSData *MTAesDecrypt(NSData *data, NSData *key, NSData *iv) { - assert(key != nil && iv != nil); - - NSMutableData *resultData = [[NSMutableData alloc] initWithLength:data.length]; - - unsigned char aesIv[16 * 2]; - memcpy(aesIv, iv.bytes, iv.length); - MyAesIgeDecrypt(data.bytes, (int)data.length, resultData.mutableBytes, key.bytes, (int)key.length, aesIv); - - return resultData; -} diff --git a/NotificationService/FetchImage.m b/NotificationService/FetchImage.m index c8ea022d37..68d971fc1e 100644 --- a/NotificationService/FetchImage.m +++ b/NotificationService/FetchImage.m @@ -1,10 +1,34 @@ #import "FetchImage.h" #import -#import +#import #import "Serialization.h" +@interface EmptyEncryptionProvider: NSObject + +@end + +@implementation EmptyEncryptionProvider + +- (id)createBignumContext { + return nil; +} + +- (NSData * _Nullable)rsaEncryptWithPublicKey:(NSString *)publicKey data:(NSData *)data { + return nil; +} + +- (NSData * _Nullable)rsaEncryptPKCS1OAEPWithPublicKey:(NSString *)publicKey data:(NSData *)data { + return nil; +} + +- (id)parseRSAPublicKey:(NSString *)publicKey { + return nil; +} + +@end + @interface InMemoryKeychain : NSObject { NSMutableDictionary *_dict; } @@ -84,7 +108,7 @@ dispatch_block_t fetchImage(BuildConfig *buildConfig, AccountProxyConnection * _ apiEnvironment = [apiEnvironment withUpdatedSocksProxySettings:[[MTSocksProxySettings alloc] initWithIp:proxyConnection.host port:(uint16_t)proxyConnection.port username:proxyConnection.username password:proxyConnection.password secret:proxyConnection.secret]]; } - MTContext *context = [[MTContext alloc] initWithSerialization:serialization encryptionProvider:[[OpenSSLEncryptionProvider alloc] init] apiEnvironment:apiEnvironment isTestingEnvironment:account.isTestingEnvironment useTempAuthKeys:false]; + MTContext *context = [[MTContext alloc] initWithSerialization:serialization encryptionProvider:[[EmptyEncryptionProvider alloc] init] apiEnvironment:apiEnvironment isTestingEnvironment:account.isTestingEnvironment useTempAuthKeys:false]; NSDictionary *seedAddressList = @{}; diff --git a/NotificationService/NotificationService-Bridging-Header.h b/NotificationService/NotificationService-Bridging-Header.h index 2f78194d54..542d5fdd23 100644 --- a/NotificationService/NotificationService-Bridging-Header.h +++ b/NotificationService/NotificationService-Bridging-Header.h @@ -1,6 +1,13 @@ #ifndef NotificationService_BridgingHeader_h #define NotificationService_BridgingHeader_h -#import "Crypto.h" +#import +#import + +@protocol SyncProvider + +- (void)addIncomingMessageWithRootPath:(NSString * _Nonnull)rootPath accountId:(int64_t)accountId encryptionParameters:(DeviceSpecificEncryptionParameters * _Nonnull)encryptionParameters peerId:(int64_t)peerId messageId:(int32_t)messageId completion:(void (^)(int32_t))completion; + +@end #endif diff --git a/NotificationService/NotificationService.m b/NotificationService/NotificationService.m index 78fd2380db..4acf92730f 100644 --- a/NotificationService/NotificationService.m +++ b/NotificationService/NotificationService.m @@ -12,6 +12,8 @@ #import "Api.h" #import "FetchImage.h" +#import "NotificationService-Bridging-Header.h" + static NSData * _Nullable parseBase64(NSString *string) { string = [string stringByReplacingOccurrencesOfString:@"-" withString:@"+"]; string = [string stringByReplacingOccurrencesOfString:@"_" withString:@"/"]; @@ -32,12 +34,38 @@ static int64_t makePeerId(int32_t namespace, int32_t value) { return (((int64_t)(namespace)) << 32) | ((int64_t)((uint64_t)((uint32_t)value))); } +@interface ParsedNotificationMessage : NSObject + +@property (nonatomic, readonly) int64_t accountId; +@property (nonatomic, readonly) int64_t peerId; +@property (nonatomic, readonly) int32_t messageId; + +@end + +@implementation ParsedNotificationMessage + +- (instancetype)initWithAccountId:(int64_t)accountId peerId:(int64_t)peerId messageId:(int64_t)messageId { + self = [super init]; + if (self != nil) { + _accountId = accountId; + _peerId = peerId; + _messageId = messageId; + } + return self; +} + +@end + @interface NotificationService () { NSString * _Nullable _rootPath; NSString * _Nullable _baseAppBundleId; void (^_contentHandler)(UNNotificationContent *); UNMutableNotificationContent * _Nullable _bestAttemptContent; void (^_cancelFetch)(void); + + ParsedNotificationMessage * _Nullable _parsedMessage; + NSNumber * _Nullable _updatedUnreadCount; + bool _contentReady; } @end @@ -67,7 +95,21 @@ static int64_t makePeerId(int32_t namespace, int32_t value) { return self; } -- (void)completeWithContent:(UNNotificationContent * _Nonnull)content { +- (void)completeWithBestAttemptContent { + _contentReady = true; + if (_contentReady && _updatedUnreadCount) { + [self _internalComplete]; + } +} + +- (void)updateUnreadCount:(int32_t)unreadCount { + _updatedUnreadCount = @(unreadCount); + if (_contentReady && _updatedUnreadCount) { + [self _internalComplete]; + } +} + +- (void)_internalComplete { #ifdef __IPHONE_13_0 if (_baseAppBundleId != nil) { BGAppRefreshTaskRequest *request = [[BGAppRefreshTaskRequest alloc] initWithIdentifier:[_baseAppBundleId stringByAppendingString:@".refresh"]]; @@ -80,14 +122,21 @@ static int64_t makePeerId(int32_t namespace, int32_t value) { } #endif - if (_contentHandler) { - _contentHandler(content); + if (_bestAttemptContent && _contentHandler) { + if (_updatedUnreadCount != nil) { + int32_t unreadCount = (int32_t)[_updatedUnreadCount intValue]; + if (unreadCount > 0) { + _bestAttemptContent.badge = @(unreadCount); + } + } + _contentHandler(_bestAttemptContent); } } - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler { if (_rootPath == nil) { - [self completeWithContent:request.content]; + _bestAttemptContent = request.content; + [self completeWithBestAttemptContent]; return; } @@ -144,6 +193,17 @@ static int64_t makePeerId(int32_t namespace, int32_t value) { peerId = makePeerId(PeerNamespaceCloudChannel, [channelIdString intValue]); } + _parsedMessage = [[ParsedNotificationMessage alloc] initWithAccountId:account.accountId peerId:peerId messageId:messageId]; + + __weak NotificationService *weakSelf = self; + [self addUnreadMessage:_rootPath accountId:account.accountId encryptionParameters:nil peerId:peerId messageId:messageId completion:^(int32_t badge) { + __strong NotificationService *strongSelf = weakSelf; + if (strongSelf == nil) { + return; + } + [strongSelf updateUnreadCount:badge]; + }]; + NSString *silentString = decryptedPayload[@"silent"]; if ([silentString isKindOfClass:[NSString class]]) { silent = [silentString intValue] != 0; @@ -311,9 +371,7 @@ static int64_t makePeerId(int32_t namespace, int32_t value) { _bestAttemptContent.attachments = @[attachment]; } } - if (_bestAttemptContent != nil) { - [self completeWithContent:_bestAttemptContent]; - } + [self completeWithBestAttemptContent]; } else { BuildConfig *buildConfig = [[BuildConfig alloc] initWithBaseAppBundleId:_baseAppBundleId]; @@ -343,23 +401,16 @@ static int64_t makePeerId(int32_t namespace, int32_t value) { } } } - - if (strongSelf->_bestAttemptContent != nil) { - [strongSelf completeWithContent:strongSelf->_bestAttemptContent]; - } + [strongSelf completeWithBestAttemptContent]; } }); }); } } else { - if (_bestAttemptContent != nil) { - [self completeWithContent:_bestAttemptContent]; - } + [self completeWithBestAttemptContent]; } } else { - if (_bestAttemptContent != nil) { - [self completeWithContent:_bestAttemptContent]; - } + [self completeWithBestAttemptContent]; } } @@ -371,11 +422,20 @@ static int64_t makePeerId(int32_t namespace, int32_t value) { if (_contentHandler) { if(_bestAttemptContent) { - [self completeWithContent:_bestAttemptContent]; - _bestAttemptContent = nil; + if (_updatedUnreadCount == nil) { + _updatedUnreadCount = @(-1); + } + [self completeWithBestAttemptContent]; } _contentHandler = nil; } } +- (void)addUnreadMessage:(NSString * _Nonnull)rootPath accountId:(int64_t)accountId encryptionParameters:(DeviceSpecificEncryptionParameters * _Nonnull)encryptionParameters peerId:(int64_t)peerId messageId:(int32_t)messageId completion:(void (^)(int32_t))completion { + + if (completion) { + completion(-1); + } +} + @end diff --git a/NotificationService/Sync.h b/NotificationService/Sync.h new file mode 100644 index 0000000000..646fcb770d --- /dev/null +++ b/NotificationService/Sync.h @@ -0,0 +1,4 @@ +#import +#import + + diff --git a/NotificationService/Sync.m b/NotificationService/Sync.m new file mode 100644 index 0000000000..f2b2d6a155 --- /dev/null +++ b/NotificationService/Sync.m @@ -0,0 +1 @@ +#import "Sync.h" \ No newline at end of file diff --git a/NotificationService/Sync.swift b/NotificationService/Sync.swift new file mode 100644 index 0000000000..0de5fd0b6b --- /dev/null +++ b/NotificationService/Sync.swift @@ -0,0 +1,32 @@ +//import SwiftSignalKit +//import Postbox +//import SyncCore +//import BuildConfig + +@objc(SyncProviderImpl) +final class SyncProviderImpl: NSObject { +} + +/*@objc(SyncProviderImpl) +final class SyncProviderImpl: NSObject, SyncProvider { + func addIncomingMessage(withRootPath rootPath: String, accountId: Int64, encryptionParameters: DeviceSpecificEncryptionParameters, peerId: Int64, messageId: Int32, completion: ((Int32) -> Void)!) { + let _ = (addIncomingMessageImpl(rootPath: rootPath, accountId: accountId, encryptionParameters: ValueBoxEncryptionParameters(forceEncryptionIfNoSet: false, key: ValueBoxEncryptionParameters.Key(data: encryptionParameters.key)!, salt: ValueBoxEncryptionParameters.Salt(data: encryptionParameters.salt)!), peerId: peerId, messageId: messageId) + |> deliverOnMainQueue).start(next: { result in + completion(Int32(clamping: result)) + }) + } +} + +private func addIncomingMessageImpl(rootPath: String, accountId: Int64, encryptionParameters: ValueBoxEncryptionParameters, peerId: Int64, messageId: Int32) -> Signal { + return accountTransaction(rootPath: rootPath, id: AccountRecordId(rawValue: accountId), encryptionParameters: encryptionParameters, transaction: { transaction -> Int in + transaction.countIncomingMessage(id: MessageId(peerId: PeerId(peerId), namespace: Namespaces.Message.Cloud, id: messageId)) + let totalUnreadState = transaction.getTotalUnreadState() + let totalCount = totalUnreadState.count(for: .filtered, in: .chats, with: [ + .regularChatsAndPrivateGroups, + .publicGroups, + .channels + ]) + return Int(totalCount) + }) +} +*/ diff --git a/Share/ShareRootController.swift b/Share/ShareRootController.swift index 969578d05f..10207503c6 100644 --- a/Share/ShareRootController.swift +++ b/Share/ShareRootController.swift @@ -35,7 +35,7 @@ class ShareRootController: UIViewController { let appVersion = (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String) ?? "unknown" - self.impl = ShareRootControllerImpl(initializationData: ShareRootControllerInitializationData(appGroupPath: appGroupUrl.path, apiId: buildConfig.apiId, languagesCategory: languagesCategory, encryptionParameters: encryptionParameters, appVersion: appVersion, bundleData: buildConfig.bundleData(withAppToken: nil)), getExtensionContext: { [weak self] in + self.impl = ShareRootControllerImpl(initializationData: ShareRootControllerInitializationData(appGroupPath: appGroupUrl.path, apiId: buildConfig.apiId, languagesCategory: languagesCategory, encryptionParameters: encryptionParameters, appVersion: appVersion, bundleData: buildConfig.bundleData(withAppToken: nil, signatureDict: nil)), getExtensionContext: { [weak self] in return self?.extensionContext }) } diff --git a/SiriIntents/IntentContacts.swift b/SiriIntents/IntentContacts.swift index 433a3155a3..39423c63ea 100644 --- a/SiriIntents/IntentContacts.swift +++ b/SiriIntents/IntentContacts.swift @@ -2,6 +2,7 @@ import Foundation import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import Contacts import Intents diff --git a/SiriIntents/IntentHandler.swift b/SiriIntents/IntentHandler.swift index 8f32226fc8..fb0e446b30 100644 --- a/SiriIntents/IntentHandler.swift +++ b/SiriIntents/IntentHandler.swift @@ -1,6 +1,7 @@ import Foundation import Intents import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import BuildConfig @@ -98,7 +99,7 @@ class IntentHandler: INExtension, INSendMessageIntentHandling, INSearchForMessag let deviceSpecificEncryptionParameters = BuildConfig.deviceSpecificEncryptionParameters(rootPath, baseAppBundleId: baseAppBundleId) let encryptionParameters = ValueBoxEncryptionParameters(forceEncryptionIfNoSet: false, key: ValueBoxEncryptionParameters.Key(data: deviceSpecificEncryptionParameters.key)!, salt: ValueBoxEncryptionParameters.Salt(data: deviceSpecificEncryptionParameters.salt)!) - account = currentAccount(allocateIfNotExists: false, networkArguments: NetworkInitializationArguments(apiId: apiId, languagesCategory: languagesCategory, appVersion: appVersion, voipMaxLayer: 0, appData: .single(buildConfig.bundleData(withAppToken: nil)), encryptionProvider: OpenSSLEncryptionProvider()), supplementary: true, manager: accountManager, rootPath: rootPath, auxiliaryMethods: accountAuxiliaryMethods, encryptionParameters: encryptionParameters) + account = currentAccount(allocateIfNotExists: false, networkArguments: NetworkInitializationArguments(apiId: apiId, languagesCategory: languagesCategory, appVersion: appVersion, voipMaxLayer: 0, appData: .single(buildConfig.bundleData(withAppToken: nil, signatureDict: nil)), encryptionProvider: OpenSSLEncryptionProvider()), supplementary: true, manager: accountManager, rootPath: rootPath, auxiliaryMethods: accountAuxiliaryMethods, encryptionParameters: encryptionParameters) |> mapToSignal { account -> Signal in if let account = account { switch account { diff --git a/SiriIntents/IntentMessages.swift b/SiriIntents/IntentMessages.swift index 2df853fc80..d8a8831fd6 100644 --- a/SiriIntents/IntentMessages.swift +++ b/SiriIntents/IntentMessages.swift @@ -2,6 +2,7 @@ import Foundation import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import Contacts import Intents diff --git a/submodules/AccountContext/BUCK b/submodules/AccountContext/BUCK index 896ec1bb9d..120fec2a7e 100644 --- a/submodules/AccountContext/BUCK +++ b/submodules/AccountContext/BUCK @@ -7,15 +7,16 @@ static_library( ]), deps = [ "//submodules/TelegramAudio:TelegramAudio", - "//submodules/AsyncDisplayKit:AsyncDisplayKit#dynamic", + "//submodules/AsyncDisplayKit:AsyncDisplayKit#shared", "//submodules/TemporaryCachedPeerDataManager:TemporaryCachedPeerDataManager", "//submodules/DeviceLocationManager:DeviceLocationManager", "//submodules/MediaPlayer:UniversalMediaPlayer", "//submodules/TelegramPresentationData:TelegramPresentationData", - "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#dynamic", - "//submodules/Postbox:Postbox#dynamic", - "//submodules/TelegramCore:TelegramCore#dynamic", - "//submodules/WalletCore:WalletCore", + "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", + "//submodules/Postbox:Postbox#shared", + "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", + "//submodules/WalletCore:WalletCore", ], frameworks = [ "$SDKROOT/System/Library/Frameworks/Foundation.framework", diff --git a/submodules/AccountContext/Sources/AccountContext.swift b/submodules/AccountContext/Sources/AccountContext.swift index ed50295d1b..3b9522695a 100644 --- a/submodules/AccountContext/Sources/AccountContext.swift +++ b/submodules/AccountContext/Sources/AccountContext.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import SwiftSignalKit diff --git a/submodules/AccountContext/Sources/ChatController.swift b/submodules/AccountContext/Sources/ChatController.swift index 8bda67ebdb..9e21f14875 100644 --- a/submodules/AccountContext/Sources/ChatController.swift +++ b/submodules/AccountContext/Sources/ChatController.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import TextFormat import Display import SwiftSignalKit diff --git a/submodules/AccountContext/Sources/DeviceContactData.swift b/submodules/AccountContext/Sources/DeviceContactData.swift index 974dc6dde7..c219196ef8 100644 --- a/submodules/AccountContext/Sources/DeviceContactData.swift +++ b/submodules/AccountContext/Sources/DeviceContactData.swift @@ -2,6 +2,7 @@ import Foundation import Contacts import Postbox import TelegramCore +import SyncCore public final class DeviceContactPhoneNumberData: Equatable { public let label: String diff --git a/submodules/AccountContext/Sources/DeviceContactDataManager.swift b/submodules/AccountContext/Sources/DeviceContactDataManager.swift index 10db927b98..8b4fa465e3 100644 --- a/submodules/AccountContext/Sources/DeviceContactDataManager.swift +++ b/submodules/AccountContext/Sources/DeviceContactDataManager.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import TelegramUIPreferences import SwiftSignalKit diff --git a/submodules/AccountContext/Sources/DownloadedMediaStoreManager.swift b/submodules/AccountContext/Sources/DownloadedMediaStoreManager.swift index 05653f8d6d..30df77d471 100644 --- a/submodules/AccountContext/Sources/DownloadedMediaStoreManager.swift +++ b/submodules/AccountContext/Sources/DownloadedMediaStoreManager.swift @@ -1,5 +1,6 @@ import Foundation import TelegramCore +import SyncCore import Postbox import TelegramUIPreferences import SwiftSignalKit diff --git a/submodules/AccountContext/Sources/FetchManager.swift b/submodules/AccountContext/Sources/FetchManager.swift index 054348169d..930d360a0a 100644 --- a/submodules/AccountContext/Sources/FetchManager.swift +++ b/submodules/AccountContext/Sources/FetchManager.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramUIPreferences diff --git a/submodules/AccountContext/Sources/FetchMediaUtils.swift b/submodules/AccountContext/Sources/FetchMediaUtils.swift index 0afadbfd4b..a9dd942677 100644 --- a/submodules/AccountContext/Sources/FetchMediaUtils.swift +++ b/submodules/AccountContext/Sources/FetchMediaUtils.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramUIPreferences diff --git a/submodules/AccountContext/Sources/IsMediaStreamable.swift b/submodules/AccountContext/Sources/IsMediaStreamable.swift index 320dd7f351..22e0da2821 100644 --- a/submodules/AccountContext/Sources/IsMediaStreamable.swift +++ b/submodules/AccountContext/Sources/IsMediaStreamable.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore public func isMediaStreamable(message: Message, media: TelegramMediaFile) -> Bool { if message.containsSecretMedia { diff --git a/submodules/AccountContext/Sources/LiveLocationManager.swift b/submodules/AccountContext/Sources/LiveLocationManager.swift index e43ba071f0..a597a4c108 100644 --- a/submodules/AccountContext/Sources/LiveLocationManager.swift +++ b/submodules/AccountContext/Sources/LiveLocationManager.swift @@ -1,5 +1,6 @@ import Foundation import TelegramCore +import SyncCore import Postbox import SwiftSignalKit diff --git a/submodules/AccountContext/Sources/MediaManager.swift b/submodules/AccountContext/Sources/MediaManager.swift index 38ef6c68ef..7a24d417cf 100644 --- a/submodules/AccountContext/Sources/MediaManager.swift +++ b/submodules/AccountContext/Sources/MediaManager.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import UIKit import AsyncDisplayKit diff --git a/submodules/AccountContext/Sources/OpenChatMessage.swift b/submodules/AccountContext/Sources/OpenChatMessage.swift index 4f617ca118..1e3507fc3c 100644 --- a/submodules/AccountContext/Sources/OpenChatMessage.swift +++ b/submodules/AccountContext/Sources/OpenChatMessage.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Display diff --git a/submodules/AccountContext/Sources/PresentationCallManager.swift b/submodules/AccountContext/Sources/PresentationCallManager.swift index e90cbcf31c..17ee887c73 100644 --- a/submodules/AccountContext/Sources/PresentationCallManager.swift +++ b/submodules/AccountContext/Sources/PresentationCallManager.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramAudio diff --git a/submodules/AccountContext/Sources/SharedMediaPlayer.swift b/submodules/AccountContext/Sources/SharedMediaPlayer.swift index 397d7d0153..4140e3345d 100644 --- a/submodules/AccountContext/Sources/SharedMediaPlayer.swift +++ b/submodules/AccountContext/Sources/SharedMediaPlayer.swift @@ -1,5 +1,6 @@ import Foundation import TelegramCore +import SyncCore import Postbox import TelegramUIPreferences import SwiftSignalKit diff --git a/submodules/AccountContext/Sources/StoredMessageFromSearchPeer.swift b/submodules/AccountContext/Sources/StoredMessageFromSearchPeer.swift index 01deab5599..a085442e95 100644 --- a/submodules/AccountContext/Sources/StoredMessageFromSearchPeer.swift +++ b/submodules/AccountContext/Sources/StoredMessageFromSearchPeer.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit public func storedMessageFromSearchPeer(account: Account, peer: Peer) -> Signal { diff --git a/submodules/AccountContext/Sources/ThemeUpdateManager.swift b/submodules/AccountContext/Sources/ThemeUpdateManager.swift index 1e2f7bef56..2424bce36e 100644 --- a/submodules/AccountContext/Sources/ThemeUpdateManager.swift +++ b/submodules/AccountContext/Sources/ThemeUpdateManager.swift @@ -1,6 +1,7 @@ import Foundation import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData public protocol ThemeUpdateManager: class { diff --git a/submodules/AccountContext/Sources/UniversalVideoNode.swift b/submodules/AccountContext/Sources/UniversalVideoNode.swift index 686fcc711e..77e7fa0d0a 100644 --- a/submodules/AccountContext/Sources/UniversalVideoNode.swift +++ b/submodules/AccountContext/Sources/UniversalVideoNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Postbox import SwiftSignalKit import TelegramCore +import SyncCore import Display import TelegramAudio import UniversalMediaPlayer diff --git a/submodules/AccountContext/Sources/WallpaperUploadManager.swift b/submodules/AccountContext/Sources/WallpaperUploadManager.swift index 5c3a67f351..a29066ef34 100644 --- a/submodules/AccountContext/Sources/WallpaperUploadManager.swift +++ b/submodules/AccountContext/Sources/WallpaperUploadManager.swift @@ -1,6 +1,7 @@ import Foundation import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData public enum WallpaperUploadManagerStatus { diff --git a/submodules/ActionSheetPeerItem/BUCK b/submodules/ActionSheetPeerItem/BUCK index 1f87075baa..3057307d75 100644 --- a/submodules/ActionSheetPeerItem/BUCK +++ b/submodules/ActionSheetPeerItem/BUCK @@ -8,6 +8,7 @@ static_library( deps = [ "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/AsyncDisplayKit:AsyncDisplayKit#shared", "//submodules/Display:Display#shared", "//submodules/AvatarNode:AvatarNode", diff --git a/submodules/ActionSheetPeerItem/Sources/ActionSheetPeerItem.swift b/submodules/ActionSheetPeerItem/Sources/ActionSheetPeerItem.swift index 1dadcca511..8ae9668a7e 100644 --- a/submodules/ActionSheetPeerItem/Sources/ActionSheetPeerItem.swift +++ b/submodules/ActionSheetPeerItem/Sources/ActionSheetPeerItem.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import AvatarNode diff --git a/submodules/AnimationUI/BUCK b/submodules/AnimationUI/BUCK index 6ac5061a71..85c63613bc 100644 --- a/submodules/AnimationUI/BUCK +++ b/submodules/AnimationUI/BUCK @@ -9,6 +9,7 @@ static_library( "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/AsyncDisplayKit:AsyncDisplayKit#shared", "//submodules/Display:Display#shared", "//submodules/YuvConversion:YuvConversion", diff --git a/submodules/AuthorizationUI/BUCK b/submodules/AuthorizationUI/BUCK index 435baaaa24..7559527e89 100644 --- a/submodules/AuthorizationUI/BUCK +++ b/submodules/AuthorizationUI/BUCK @@ -8,6 +8,7 @@ static_library( deps = [ "//submodules/AsyncDisplayKit:AsyncDisplayKit#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/Display:Display#shared", "//submodules/TextFormat:TextFormat", "//submodules/Markdown:Markdown", diff --git a/submodules/AuthorizationUI/Sources/AuthorizationOptionText.swift b/submodules/AuthorizationUI/Sources/AuthorizationOptionText.swift index 9cc005a6f5..218d8017c9 100644 --- a/submodules/AuthorizationUI/Sources/AuthorizationOptionText.swift +++ b/submodules/AuthorizationUI/Sources/AuthorizationOptionText.swift @@ -1,5 +1,6 @@ import Foundation import TelegramCore +import SyncCore import Display import TelegramPresentationData import TextFormat diff --git a/submodules/AvatarNode/BUCK b/submodules/AvatarNode/BUCK index 93c3fb0d60..e3c4a0f5a1 100644 --- a/submodules/AvatarNode/BUCK +++ b/submodules/AvatarNode/BUCK @@ -9,6 +9,7 @@ static_library( "//submodules/AsyncDisplayKit:AsyncDisplayKit#shared", "//submodules/Display:Display#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/AnimationUI:AnimationUI", "//submodules/AppBundle:AppBundle", diff --git a/submodules/AvatarNode/Sources/AvatarNode.swift b/submodules/AvatarNode/Sources/AvatarNode.swift index d94d57f7c5..0085c2185b 100644 --- a/submodules/AvatarNode/Sources/AvatarNode.swift +++ b/submodules/AvatarNode/Sources/AvatarNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Postbox import Display import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AnimationUI diff --git a/submodules/AvatarNode/Sources/PeerAvatar.swift b/submodules/AvatarNode/Sources/PeerAvatar.swift index 7550b7367f..7922a9f410 100644 --- a/submodules/AvatarNode/Sources/PeerAvatar.swift +++ b/submodules/AvatarNode/Sources/PeerAvatar.swift @@ -5,6 +5,7 @@ import Postbox import Display import ImageIO import TelegramCore +import SyncCore private let roundCorners = { () -> UIImage in let diameter: CGFloat = 60.0 diff --git a/submodules/BotPaymentsUI/BUCK b/submodules/BotPaymentsUI/BUCK index caf603a34b..e8c0210d0e 100644 --- a/submodules/BotPaymentsUI/BUCK +++ b/submodules/BotPaymentsUI/BUCK @@ -9,6 +9,7 @@ static_library( "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/LocalAuth:LocalAuth", "//submodules/AccountContext:AccountContext", diff --git a/submodules/BotPaymentsUI/Sources/BotCheckoutController.swift b/submodules/BotPaymentsUI/Sources/BotCheckoutController.swift index 67c12f403c..4a04199444 100644 --- a/submodules/BotPaymentsUI/Sources/BotCheckoutController.swift +++ b/submodules/BotPaymentsUI/Sources/BotCheckoutController.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/BotPaymentsUI/Sources/BotCheckoutControllerNode.swift b/submodules/BotPaymentsUI/Sources/BotCheckoutControllerNode.swift index 04aade62c7..0b5a64ac53 100644 --- a/submodules/BotPaymentsUI/Sources/BotCheckoutControllerNode.swift +++ b/submodules/BotPaymentsUI/Sources/BotCheckoutControllerNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import PassKit import TelegramPresentationData diff --git a/submodules/BotPaymentsUI/Sources/BotCheckoutHeaderItem.swift b/submodules/BotPaymentsUI/Sources/BotCheckoutHeaderItem.swift index 8c7a1dd064..ba565fc0eb 100644 --- a/submodules/BotPaymentsUI/Sources/BotCheckoutHeaderItem.swift +++ b/submodules/BotPaymentsUI/Sources/BotCheckoutHeaderItem.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/BotPaymentsUI/Sources/BotCheckoutInfoController.swift b/submodules/BotPaymentsUI/Sources/BotCheckoutInfoController.swift index ac4c8706e4..64d7b0cf5f 100644 --- a/submodules/BotPaymentsUI/Sources/BotCheckoutInfoController.swift +++ b/submodules/BotPaymentsUI/Sources/BotCheckoutInfoController.swift @@ -3,6 +3,7 @@ import UIKit import SwiftSignalKit import Display import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import ProgressNavigationButtonNode diff --git a/submodules/BotPaymentsUI/Sources/BotCheckoutInfoControllerNode.swift b/submodules/BotPaymentsUI/Sources/BotCheckoutInfoControllerNode.swift index e5d5502661..03df37910f 100644 --- a/submodules/BotPaymentsUI/Sources/BotCheckoutInfoControllerNode.swift +++ b/submodules/BotPaymentsUI/Sources/BotCheckoutInfoControllerNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/BotPaymentsUI/Sources/BotCheckoutNativeCardEntryController.swift b/submodules/BotPaymentsUI/Sources/BotCheckoutNativeCardEntryController.swift index e49e48a409..c0449e73e2 100644 --- a/submodules/BotPaymentsUI/Sources/BotCheckoutNativeCardEntryController.swift +++ b/submodules/BotPaymentsUI/Sources/BotCheckoutNativeCardEntryController.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import SwiftSignalKit import Display import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import ProgressNavigationButtonNode diff --git a/submodules/BotPaymentsUI/Sources/BotCheckoutNativeCardEntryControllerNode.swift b/submodules/BotPaymentsUI/Sources/BotCheckoutNativeCardEntryControllerNode.swift index 020629178c..d0b2b3e9d5 100644 --- a/submodules/BotPaymentsUI/Sources/BotCheckoutNativeCardEntryControllerNode.swift +++ b/submodules/BotPaymentsUI/Sources/BotCheckoutNativeCardEntryControllerNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/BotPaymentsUI/Sources/BotCheckoutPasswordEntryController.swift b/submodules/BotPaymentsUI/Sources/BotCheckoutPasswordEntryController.swift index e089ff940b..c3096d8260 100644 --- a/submodules/BotPaymentsUI/Sources/BotCheckoutPasswordEntryController.swift +++ b/submodules/BotPaymentsUI/Sources/BotCheckoutPasswordEntryController.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AccountContext diff --git a/submodules/BotPaymentsUI/Sources/BotCheckoutPaymentMethodSheet.swift b/submodules/BotPaymentsUI/Sources/BotCheckoutPaymentMethodSheet.swift index bf43dd2e23..f67d0f2c32 100644 --- a/submodules/BotPaymentsUI/Sources/BotCheckoutPaymentMethodSheet.swift +++ b/submodules/BotPaymentsUI/Sources/BotCheckoutPaymentMethodSheet.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import AccountContext import AppBundle diff --git a/submodules/BotPaymentsUI/Sources/BotCheckoutPaymentShippingOptionSheetController.swift b/submodules/BotPaymentsUI/Sources/BotCheckoutPaymentShippingOptionSheetController.swift index 1115233f61..5150821641 100644 --- a/submodules/BotPaymentsUI/Sources/BotCheckoutPaymentShippingOptionSheetController.swift +++ b/submodules/BotPaymentsUI/Sources/BotCheckoutPaymentShippingOptionSheetController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import AccountContext import TelegramStringFormatting diff --git a/submodules/BotPaymentsUI/Sources/BotCheckoutWebInteractionController.swift b/submodules/BotPaymentsUI/Sources/BotCheckoutWebInteractionController.swift index a07f96cf6b..6a0fcc693b 100644 --- a/submodules/BotPaymentsUI/Sources/BotCheckoutWebInteractionController.swift +++ b/submodules/BotPaymentsUI/Sources/BotCheckoutWebInteractionController.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/BotPaymentsUI/Sources/BotReceiptController.swift b/submodules/BotPaymentsUI/Sources/BotReceiptController.swift index db972623e6..9661ef66f9 100644 --- a/submodules/BotPaymentsUI/Sources/BotReceiptController.swift +++ b/submodules/BotPaymentsUI/Sources/BotReceiptController.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/BotPaymentsUI/Sources/BotReceiptControllerNode.swift b/submodules/BotPaymentsUI/Sources/BotReceiptControllerNode.swift index f9fe4f9dea..bc4a52031f 100644 --- a/submodules/BotPaymentsUI/Sources/BotReceiptControllerNode.swift +++ b/submodules/BotPaymentsUI/Sources/BotReceiptControllerNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import ItemListUI diff --git a/submodules/BuildConfig/BUCK b/submodules/BuildConfig/BUCK index ad29259a3b..6298c2a05c 100644 --- a/submodules/BuildConfig/BUCK +++ b/submodules/BuildConfig/BUCK @@ -22,7 +22,6 @@ static_library( "Sources/*.h", ]), deps = [ - "//submodules/PKCS:PKCS", ], frameworks = [ "$SDKROOT/System/Library/Frameworks/Foundation.framework", diff --git a/submodules/BuildConfig/Sources/BuildConfig.h b/submodules/BuildConfig/Sources/BuildConfig.h index b57ccb7bf2..d13c28dc3f 100644 --- a/submodules/BuildConfig/Sources/BuildConfig.h +++ b/submodules/BuildConfig/Sources/BuildConfig.h @@ -20,7 +20,7 @@ @property (nonatomic, strong, readonly) NSString * _Nonnull appSpecificUrlScheme; + (DeviceSpecificEncryptionParameters * _Nonnull)deviceSpecificEncryptionParameters:(NSString * _Nonnull)rootPath baseAppBundleId:(NSString * _Nonnull)baseAppBundleId; -- (NSData * _Nullable)bundleDataWithAppToken:(NSData * _Nullable)appToken; +- (NSData * _Nullable)bundleDataWithAppToken:(NSData * _Nullable)appToken signatureDict:(NSDictionary * _Nullable)signatureDict; + (void)getHardwareEncryptionAvailableWithBaseAppBundleId:(NSString * _Nonnull)baseAppBundleId completion:(void (^)(NSData * _Nullable))completion; + (void)encryptApplicationSecret:(NSData * _Nonnull)secret baseAppBundleId:(NSString * _Nonnull)baseAppBundleId completion:(void (^)(NSData * _Nullable, NSData * _Nullable))completion; diff --git a/submodules/BuildConfig/Sources/BuildConfig.m b/submodules/BuildConfig/Sources/BuildConfig.m index 3e9371d03b..6c17f8f9eb 100644 --- a/submodules/BuildConfig/Sources/BuildConfig.m +++ b/submodules/BuildConfig/Sources/BuildConfig.m @@ -1,244 +1,6 @@ #import "BuildConfig.h" -#include -#include -#include - -#include -#include -#include -#include -#include - -#import -#import - -#import - -static NSData *sha1(NSData *data) { - uint8_t digest[20]; - CC_SHA1(data.bytes, (CC_LONG)data.length, digest); - - return [[NSData alloc] initWithBytes:digest length:20]; -} - static NSString *telegramApplicationSecretKey = @"telegramApplicationSecretKey_v3"; - -static uint32_t funcSwap32(uint32_t input) -{ - return OSSwapBigToHostInt32(input); -} - -static uint32_t funcNoSwap32(uint32_t input) -{ - return OSSwapLittleToHostInt32(input); -} - -/* - * Magic numbers used by Code Signing - */ -enum { - kSecCodeMagicRequirement = 0xfade0c00, /* single requirement */ - kSecCodeMagicRequirementSet = 0xfade0c01, /* requirement set */ - kSecCodeMagicCodeDirectory = 0xfade0c02, /* CodeDirectory */ - kSecCodeMagicEmbeddedSignature = 0xfade0cc0, /* single-architecture embedded signature */ - kSecCodeMagicDetachedSignature = 0xfade0cc1, /* detached multi-architecture signature */ - kSecCodeMagicEntitlement = 0xfade7171, /* entitlement blob */ - - kSecCodeMagicByte = 0xfa /* shared first byte */ -}; - - -/* - * Structure of an embedded-signature SuperBlob - */ -typedef struct __BlobIndex { - uint32_t type; /* type of entry */ - uint32_t offset; /* offset of entry */ -} CS_BlobIndex; - -typedef struct __Blob { - uint32_t magic; /* magic number */ - uint32_t length; /* total length of SuperBlob */ -} CS_Blob; - -typedef struct __SuperBlob { - CS_Blob blob; - uint32_t count; /* number of index entries following */ - CS_BlobIndex index[]; /* (count) entries */ - /* followed by Blobs in no particular order as indicated by offsets in index */ -} CS_SuperBlob; - - -/* - * C form of a CodeDirectory. - */ -typedef struct __CodeDirectory { - uint32_t magic; /* magic number (CSMAGIC_CODEDIRECTORY) */ - uint32_t length; /* total length of CodeDirectory blob */ - uint32_t version; /* compatibility version */ - uint32_t flags; /* setup and mode flags */ - uint32_t hashOffset; /* offset of hash slot element at index zero */ - uint32_t identOffset; /* offset of identifier string */ - uint32_t nSpecialSlots; /* number of special hash slots */ - uint32_t nCodeSlots; /* number of ordinary (code) hash slots */ - uint32_t codeLimit; /* limit to main image signature range */ - uint8_t hashSize; /* size of each hash in bytes */ - uint8_t hashType; /* type of hash (cdHashType* constants) */ - uint8_t spare1; /* unused (must be zero) */ - uint8_t pageSize; /* log2(page size in bytes); 0 => infinite */ - uint32_t spare2; /* unused (must be zero) */ - /* followed by dynamic content as located by offset fields above */ -} CS_CodeDirectory; - -static MTPKCS * _Nullable parseSignature(const char* buffer, size_t size) { - CS_SuperBlob* sb = (CS_SuperBlob*)buffer; - if (OSSwapBigToHostInt32(sb->blob.magic) != kSecCodeMagicEmbeddedSignature) - { - return 0; - } - - uint32_t count = OSSwapBigToHostInt32(sb->count); - - for (uint32_t i = 0; i < count; i++) - { - uint32_t offset = OSSwapBigToHostInt32(sb->index[i].offset); - - const CS_Blob* blob = (const CS_Blob*)(buffer + offset); - - if (OSSwapBigToHostInt32(blob->magic) == 0xfade0b01) // signature - { - printf("Embedded signature, length: %d\n", OSSwapBigToHostInt32(blob->length)); - - if (OSSwapBigToHostInt32(blob->length) != 8) - { - const unsigned char* message = (const unsigned char*)buffer + offset + 8; - MTPKCS *result = [MTPKCS parse:message size:(OSSwapBigToHostInt32(blob->length) - 8)]; - return result; - } - } - } - - return nil; -} - -static MTPKCS * _Nullable parseArch(const char* buffer, size_t size) { - uint32_t (*swap32)(uint32_t) = funcNoSwap32; - - uint32_t offset = 0; - - const struct mach_header* header = (struct mach_header*)(buffer + offset); - - switch (header->magic) { - case MH_CIGAM: - swap32 = funcSwap32; - case MH_MAGIC: - offset += sizeof(struct mach_header); - break; - case MH_CIGAM_64: - swap32 = funcSwap32; - case MH_MAGIC_64: - offset += sizeof(struct mach_header_64); - break; - default: - return nil; - } - - const NXArchInfo *archInfo = NXGetArchInfoFromCpuType(swap32(header->cputype), swap32(header->cpusubtype)); - if (archInfo != NULL) { - printf("Architecture: %s\n", archInfo->name); - } - - uint32_t commandCount = swap32(header->ncmds); - - for (uint32_t i = 0; i < commandCount; i++) { - const struct load_command* loadCommand = (const struct load_command*)(buffer + offset); - uint32_t commandSize = swap32(loadCommand->cmdsize); - - uint32_t commandType = swap32(loadCommand->cmd); - if (commandType == LC_CODE_SIGNATURE) { - const struct linkedit_data_command* dataCommand = (const struct linkedit_data_command*)(buffer + offset); - uint32_t dataOffset = swap32(dataCommand->dataoff); - uint32_t dataSize = swap32(dataCommand->datasize); - - return parseSignature(buffer + dataOffset, dataSize); - } - - offset += commandSize; - } - - return nil; -} - -static MTPKCS * _Nullable parseFat(const char *buffer, size_t size) { - size_t offset = 0; - - const struct fat_header* fatHeader = (const struct fat_header*)(buffer + offset); - offset += sizeof(*fatHeader); - - uint32_t archCount = OSSwapBigToHostInt32(fatHeader->nfat_arch); - - for (uint32_t i = 0; i < archCount; i++) { - const struct fat_arch* arch = (const struct fat_arch*)(buffer + offset); - offset += sizeof(*arch); - - uint32_t archOffset = OSSwapBigToHostInt32(arch->offset); - uint32_t archSize = OSSwapBigToHostInt32(arch->size); - - MTPKCS *result = parseArch(buffer + archOffset, archSize); - if (result != nil) { - return result; - } - } - - return nil; -} - -static MTPKCS * _Nullable parseMachO(const char* buffer, size_t size) { - const uint32_t* magic = (const uint32_t*)buffer; - - if (*magic == FAT_CIGAM || *magic == FAT_MAGIC) { - return parseFat(buffer, size); - } else { - return parseArch(buffer, size); - } -} - -static MTPKCS * _Nullable checkSignature(const char *filename) { - char *buffer = NULL; - - int fd = open(filename, O_RDONLY); - - if (fd == -1) { - return nil; - } - - struct stat st; - fstat(fd, &st); - - buffer = mmap(NULL, (size_t)st.st_size, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0); - - if (buffer == MAP_FAILED) { - if (buffer) { - munmap(buffer, (size_t)st.st_size); - } - if (fd != -1) { - close(fd); - } - return nil; - } - - MTPKCS *result = parseMachO(buffer, (size_t)st.st_size); - if (buffer) { - munmap(buffer, (size_t)st.st_size); - } - if (fd != -1) { - close(fd); - } - - return result; -} - API_AVAILABLE(ios(10)) @interface LocalPrivateKey : NSObject { SecKeyRef _privateKey; @@ -369,32 +131,26 @@ API_AVAILABLE(ios(10)) _apiHash = @(APP_CONFIG_API_HASH); _hockeyAppId = @(APP_CONFIG_HOCKEYAPP_ID); - MTPKCS *signature = checkSignature([[[NSBundle mainBundle] executablePath] UTF8String]); _dataDict = [[NSMutableDictionary alloc] init]; if (baseAppBundleId != nil) { _dataDict[@"bundleId"] = baseAppBundleId; } - if (signature.issuerName != nil) { - _dataDict[@"issuerName"] = signature.issuerName; - } - if (signature.subjectName != nil) { - _dataDict[@"name"] = signature.subjectName; - } - if (signature.data != nil) { - _dataDict[@"data"] = [sha1(signature.data) base64EncodedStringWithOptions:0]; - _dataDict[@"data1"] = [signature.data base64EncodedStringWithOptions:0]; - } } return self; } -- (NSData * _Nullable)bundleDataWithAppToken:(NSData * _Nullable)appToken { +- (NSData * _Nullable)bundleDataWithAppToken:(NSData * _Nullable)appToken signatureDict:(NSDictionary * _Nullable)signatureDict { NSMutableDictionary *dataDict = [[NSMutableDictionary alloc] initWithDictionary:_dataDict]; if (appToken != nil) { dataDict[@"device_token"] = [appToken base64EncodedStringWithOptions:0]; dataDict[@"device_token_type"] = @"voip"; } + if (signatureDict != nil) { + for (id key in signatureDict.allKeys) { + dataDict[key] = signatureDict[key]; + } + } NSData *data = [NSJSONSerialization dataWithJSONObject:dataDict options:0 error:nil]; return data; } diff --git a/submodules/BuildConfigExtra/BUCK b/submodules/BuildConfigExtra/BUCK new file mode 100644 index 0000000000..5d87460156 --- /dev/null +++ b/submodules/BuildConfigExtra/BUCK @@ -0,0 +1,20 @@ +load("//Config:buck_rule_macros.bzl", "static_library") + +static_library( + name = "BuildConfigExtra", + srcs = glob([ + "Sources/*.m", + ]), + headers = glob([ + "Sources/*.h", + ]), + exported_headers = glob([ + "Sources/*.h", + ]), + deps = [ + "//submodules/PKCS:PKCS", + ], + frameworks = [ + "$SDKROOT/System/Library/Frameworks/Foundation.framework", + ], +) diff --git a/submodules/BuildConfigExtra/Sources/BuildConfigExtra.h b/submodules/BuildConfigExtra/Sources/BuildConfigExtra.h new file mode 100644 index 0000000000..bd4c629fa0 --- /dev/null +++ b/submodules/BuildConfigExtra/Sources/BuildConfigExtra.h @@ -0,0 +1,9 @@ +#import + +@interface BuildConfigExtra : NSObject + +- (instancetype _Nonnull)initWithBaseAppBundleId:(NSString * _Nonnull)baseAppBundleId; + ++ (NSDictionary * _Nonnull)signatureDict; + +@end diff --git a/submodules/BuildConfigExtra/Sources/BuildConfigExtra.m b/submodules/BuildConfigExtra/Sources/BuildConfigExtra.m new file mode 100644 index 0000000000..ddb6a760ca --- /dev/null +++ b/submodules/BuildConfigExtra/Sources/BuildConfigExtra.m @@ -0,0 +1,260 @@ +#import "BuildConfigExtra.h" + +#include +#include +#include + +#include +#include +#include +#include +#include + +#import +#import + +#import + +static NSData *sha1(NSData *data) { + uint8_t digest[20]; + CC_SHA1(data.bytes, (CC_LONG)data.length, digest); + + return [[NSData alloc] initWithBytes:digest length:20]; +} + +static NSString *telegramApplicationSecretKey = @"telegramApplicationSecretKey_v3"; + +static uint32_t funcSwap32(uint32_t input) +{ + return OSSwapBigToHostInt32(input); +} + +static uint32_t funcNoSwap32(uint32_t input) +{ + return OSSwapLittleToHostInt32(input); +} + +/* + * Magic numbers used by Code Signing + */ +enum { + kSecCodeMagicRequirement = 0xfade0c00, /* single requirement */ + kSecCodeMagicRequirementSet = 0xfade0c01, /* requirement set */ + kSecCodeMagicCodeDirectory = 0xfade0c02, /* CodeDirectory */ + kSecCodeMagicEmbeddedSignature = 0xfade0cc0, /* single-architecture embedded signature */ + kSecCodeMagicDetachedSignature = 0xfade0cc1, /* detached multi-architecture signature */ + kSecCodeMagicEntitlement = 0xfade7171, /* entitlement blob */ + + kSecCodeMagicByte = 0xfa /* shared first byte */ +}; + + +/* + * Structure of an embedded-signature SuperBlob + */ +typedef struct __BlobIndex { + uint32_t type; /* type of entry */ + uint32_t offset; /* offset of entry */ +} CS_BlobIndex; + +typedef struct __Blob { + uint32_t magic; /* magic number */ + uint32_t length; /* total length of SuperBlob */ +} CS_Blob; + +typedef struct __SuperBlob { + CS_Blob blob; + uint32_t count; /* number of index entries following */ + CS_BlobIndex index[]; /* (count) entries */ + /* followed by Blobs in no particular order as indicated by offsets in index */ +} CS_SuperBlob; + + +/* + * C form of a CodeDirectory. + */ +typedef struct __CodeDirectory { + uint32_t magic; /* magic number (CSMAGIC_CODEDIRECTORY) */ + uint32_t length; /* total length of CodeDirectory blob */ + uint32_t version; /* compatibility version */ + uint32_t flags; /* setup and mode flags */ + uint32_t hashOffset; /* offset of hash slot element at index zero */ + uint32_t identOffset; /* offset of identifier string */ + uint32_t nSpecialSlots; /* number of special hash slots */ + uint32_t nCodeSlots; /* number of ordinary (code) hash slots */ + uint32_t codeLimit; /* limit to main image signature range */ + uint8_t hashSize; /* size of each hash in bytes */ + uint8_t hashType; /* type of hash (cdHashType* constants) */ + uint8_t spare1; /* unused (must be zero) */ + uint8_t pageSize; /* log2(page size in bytes); 0 => infinite */ + uint32_t spare2; /* unused (must be zero) */ + /* followed by dynamic content as located by offset fields above */ +} CS_CodeDirectory; + +static MTPKCS * _Nullable parseSignature(const char* buffer, size_t size) { + CS_SuperBlob* sb = (CS_SuperBlob*)buffer; + if (OSSwapBigToHostInt32(sb->blob.magic) != kSecCodeMagicEmbeddedSignature) + { + return 0; + } + + uint32_t count = OSSwapBigToHostInt32(sb->count); + + for (uint32_t i = 0; i < count; i++) + { + uint32_t offset = OSSwapBigToHostInt32(sb->index[i].offset); + + const CS_Blob* blob = (const CS_Blob*)(buffer + offset); + + if (OSSwapBigToHostInt32(blob->magic) == 0xfade0b01) // signature + { + printf("Embedded signature, length: %d\n", OSSwapBigToHostInt32(blob->length)); + + if (OSSwapBigToHostInt32(blob->length) != 8) + { + const unsigned char* message = (const unsigned char*)buffer + offset + 8; + MTPKCS *result = [MTPKCS parse:message size:(OSSwapBigToHostInt32(blob->length) - 8)]; + return result; + } + } + } + + return nil; +} + +static MTPKCS * _Nullable parseArch(const char* buffer, size_t size) { + uint32_t (*swap32)(uint32_t) = funcNoSwap32; + + uint32_t offset = 0; + + const struct mach_header* header = (struct mach_header*)(buffer + offset); + + switch (header->magic) { + case MH_CIGAM: + swap32 = funcSwap32; + case MH_MAGIC: + offset += sizeof(struct mach_header); + break; + case MH_CIGAM_64: + swap32 = funcSwap32; + case MH_MAGIC_64: + offset += sizeof(struct mach_header_64); + break; + default: + return nil; + } + + const NXArchInfo *archInfo = NXGetArchInfoFromCpuType(swap32(header->cputype), swap32(header->cpusubtype)); + if (archInfo != NULL) { + printf("Architecture: %s\n", archInfo->name); + } + + uint32_t commandCount = swap32(header->ncmds); + + for (uint32_t i = 0; i < commandCount; i++) { + const struct load_command* loadCommand = (const struct load_command*)(buffer + offset); + uint32_t commandSize = swap32(loadCommand->cmdsize); + + uint32_t commandType = swap32(loadCommand->cmd); + if (commandType == LC_CODE_SIGNATURE) { + const struct linkedit_data_command* dataCommand = (const struct linkedit_data_command*)(buffer + offset); + uint32_t dataOffset = swap32(dataCommand->dataoff); + uint32_t dataSize = swap32(dataCommand->datasize); + + return parseSignature(buffer + dataOffset, dataSize); + } + + offset += commandSize; + } + + return nil; +} + +static MTPKCS * _Nullable parseFat(const char *buffer, size_t size) { + size_t offset = 0; + + const struct fat_header* fatHeader = (const struct fat_header*)(buffer + offset); + offset += sizeof(*fatHeader); + + uint32_t archCount = OSSwapBigToHostInt32(fatHeader->nfat_arch); + + for (uint32_t i = 0; i < archCount; i++) { + const struct fat_arch* arch = (const struct fat_arch*)(buffer + offset); + offset += sizeof(*arch); + + uint32_t archOffset = OSSwapBigToHostInt32(arch->offset); + uint32_t archSize = OSSwapBigToHostInt32(arch->size); + + MTPKCS *result = parseArch(buffer + archOffset, archSize); + if (result != nil) { + return result; + } + } + + return nil; +} + +static MTPKCS * _Nullable parseMachO(const char* buffer, size_t size) { + const uint32_t* magic = (const uint32_t*)buffer; + + if (*magic == FAT_CIGAM || *magic == FAT_MAGIC) { + return parseFat(buffer, size); + } else { + return parseArch(buffer, size); + } +} + +static MTPKCS * _Nullable checkSignature(const char *filename) { + char *buffer = NULL; + + int fd = open(filename, O_RDONLY); + + if (fd == -1) { + return nil; + } + + struct stat st; + fstat(fd, &st); + + buffer = mmap(NULL, (size_t)st.st_size, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0); + + if (buffer == MAP_FAILED) { + if (buffer) { + munmap(buffer, (size_t)st.st_size); + } + if (fd != -1) { + close(fd); + } + return nil; + } + + MTPKCS *result = parseMachO(buffer, (size_t)st.st_size); + if (buffer) { + munmap(buffer, (size_t)st.st_size); + } + if (fd != -1) { + close(fd); + } + + return result; +} + +@implementation BuildConfigExtra + ++ (NSDictionary * _Nonnull)signatureDict { + NSMutableDictionary *dataDict = [[NSMutableDictionary alloc] init]; + MTPKCS *signature = checkSignature([[[NSBundle mainBundle] executablePath] UTF8String]); + if (signature.issuerName != nil) { + dataDict[@"issuerName"] = signature.issuerName; + } + if (signature.subjectName != nil) { + dataDict[@"name"] = signature.subjectName; + } + if (signature.data != nil) { + dataDict[@"data"] = [sha1(signature.data) base64EncodedStringWithOptions:0]; + dataDict[@"data1"] = [signature.data base64EncodedStringWithOptions:0]; + } + return dataDict; +} + +@end diff --git a/submodules/CallListUI/BUCK b/submodules/CallListUI/BUCK index d023a5116c..5499fccd86 100644 --- a/submodules/CallListUI/BUCK +++ b/submodules/CallListUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/TelegramUIPreferences:TelegramUIPreferences", "//submodules/AccountContext:AccountContext", diff --git a/submodules/CallListUI/Sources/CallListCallItem.swift b/submodules/CallListUI/Sources/CallListCallItem.swift index bdf96659e9..178de94a95 100644 --- a/submodules/CallListUI/Sources/CallListCallItem.swift +++ b/submodules/CallListUI/Sources/CallListCallItem.swift @@ -5,6 +5,7 @@ import Postbox import Display import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/CallListUI/Sources/CallListController.swift b/submodules/CallListUI/Sources/CallListController.swift index 93bbf85f66..6385301617 100644 --- a/submodules/CallListUI/Sources/CallListController.swift +++ b/submodules/CallListUI/Sources/CallListController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import ItemListUI diff --git a/submodules/CallListUI/Sources/CallListControllerNode.swift b/submodules/CallListUI/Sources/CallListControllerNode.swift index 3aa080eb51..90f865e94f 100644 --- a/submodules/CallListUI/Sources/CallListControllerNode.swift +++ b/submodules/CallListUI/Sources/CallListControllerNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/CallListUI/Sources/CallListNodeEntries.swift b/submodules/CallListUI/Sources/CallListNodeEntries.swift index bff7f0df2e..ac60b72bde 100644 --- a/submodules/CallListUI/Sources/CallListNodeEntries.swift +++ b/submodules/CallListUI/Sources/CallListNodeEntries.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import MergeLists diff --git a/submodules/CallListUI/Sources/CallListNodeLocation.swift b/submodules/CallListUI/Sources/CallListNodeLocation.swift index 9732e767d8..c5fa542031 100644 --- a/submodules/CallListUI/Sources/CallListNodeLocation.swift +++ b/submodules/CallListUI/Sources/CallListNodeLocation.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Display diff --git a/submodules/CallListUI/Sources/CallListViewTransition.swift b/submodules/CallListUI/Sources/CallListViewTransition.swift index d16b6665d9..8d72eebda2 100644 --- a/submodules/CallListUI/Sources/CallListViewTransition.swift +++ b/submodules/CallListUI/Sources/CallListViewTransition.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Display import MergeLists diff --git a/submodules/ChatListSearchRecentPeersNode/BUCK b/submodules/ChatListSearchRecentPeersNode/BUCK index 932bda3d36..b167dabe08 100644 --- a/submodules/ChatListSearchRecentPeersNode/BUCK +++ b/submodules/ChatListSearchRecentPeersNode/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/ListSectionHeaderNode:ListSectionHeaderNode", "//submodules/HorizontalPeerItem:HorizontalPeerItem", "//submodules/MergeLists:MergeLists", diff --git a/submodules/ChatListSearchRecentPeersNode/Sources/ChatListSearchRecentPeersNode.swift b/submodules/ChatListSearchRecentPeersNode/Sources/ChatListSearchRecentPeersNode.swift index db7021d202..c998b0cb76 100644 --- a/submodules/ChatListSearchRecentPeersNode/Sources/ChatListSearchRecentPeersNode.swift +++ b/submodules/ChatListSearchRecentPeersNode/Sources/ChatListSearchRecentPeersNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import MergeLists import HorizontalPeerItem diff --git a/submodules/ChatListUI/BUCK b/submodules/ChatListUI/BUCK index f69a5a995b..5b26e2660a 100644 --- a/submodules/ChatListUI/BUCK +++ b/submodules/ChatListUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/TelegramUIPreferences:TelegramUIPreferences", "//submodules/AccountContext:AccountContext", diff --git a/submodules/ChatListUI/Sources/ChatContextMenus.swift b/submodules/ChatListUI/Sources/ChatContextMenus.swift index b603bf154b..1a70bab746 100644 --- a/submodules/ChatListUI/Sources/ChatContextMenus.swift +++ b/submodules/ChatListUI/Sources/ChatContextMenus.swift @@ -5,6 +5,7 @@ import ContextUI import AccountContext import Postbox import TelegramCore +import SyncCore import Display import TelegramUIPreferences import OverlayStatusController diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index 90a3c9f6cf..f7b2929105 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -4,6 +4,7 @@ import Postbox import SwiftSignalKit import Display import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import TelegramBaseController diff --git a/submodules/ChatListUI/Sources/ChatListControllerNode.swift b/submodules/ChatListUI/Sources/ChatListControllerNode.swift index 082ef5cb8f..24211ad5c8 100644 --- a/submodules/ChatListUI/Sources/ChatListControllerNode.swift +++ b/submodules/ChatListUI/Sources/ChatListControllerNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import MergeLists diff --git a/submodules/ChatListUI/Sources/ChatListRecentPeersListItem.swift b/submodules/ChatListUI/Sources/ChatListRecentPeersListItem.swift index 10b0ce0ad1..b0d339b63c 100644 --- a/submodules/ChatListUI/Sources/ChatListRecentPeersListItem.swift +++ b/submodules/ChatListUI/Sources/ChatListRecentPeersListItem.swift @@ -5,6 +5,7 @@ import Postbox import Display import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import ChatListSearchRecentPeersNode import ContextUI diff --git a/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift b/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift index ee2c7456a1..0208ceef80 100644 --- a/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift +++ b/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import MergeLists diff --git a/submodules/ChatListUI/Sources/ChatListSelection.swift b/submodules/ChatListUI/Sources/ChatListSelection.swift index 4b28c19412..039a91e555 100644 --- a/submodules/ChatListUI/Sources/ChatListSelection.swift +++ b/submodules/ChatListUI/Sources/ChatListSelection.swift @@ -3,6 +3,7 @@ import UIKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore enum ChatListSelectionReadOption: Equatable { case all(enabled: Bool) diff --git a/submodules/ChatListUI/Sources/Node/ChatListItem.swift b/submodules/ChatListUI/Sources/Node/ChatListItem.swift index 3804fa1e17..5742165831 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListItem.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListItem.swift @@ -5,6 +5,7 @@ import Postbox import Display import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/ChatListUI/Sources/Node/ChatListItemStrings.swift b/submodules/ChatListUI/Sources/Node/ChatListItemStrings.swift index 3c665c8981..d927b769f1 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListItemStrings.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListItemStrings.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import TelegramStringFormatting diff --git a/submodules/ChatListUI/Sources/Node/ChatListNode.swift b/submodules/ChatListUI/Sources/Node/ChatListNode.swift index f003db1aeb..24957d7552 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListNode.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/ChatListUI/Sources/Node/ChatListNodeEntries.swift b/submodules/ChatListUI/Sources/Node/ChatListNodeEntries.swift index fca1a1480d..b0da7f230d 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListNodeEntries.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListNodeEntries.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import MergeLists diff --git a/submodules/ChatListUI/Sources/Node/ChatListNodeLocation.swift b/submodules/ChatListUI/Sources/Node/ChatListNodeLocation.swift index a3ad3df012..45a78f684b 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListNodeLocation.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListNodeLocation.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Display diff --git a/submodules/ChatListUI/Sources/Node/ChatListTypingNode.swift b/submodules/ChatListUI/Sources/Node/ChatListTypingNode.swift index 72f56ed7e0..dbcb66e59c 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListTypingNode.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListTypingNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import Display import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/ChatListUI/Sources/Node/ChatListViewTransition.swift b/submodules/ChatListUI/Sources/Node/ChatListViewTransition.swift index 6cf4184fee..9e5adf7de0 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListViewTransition.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListViewTransition.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Display import MergeLists diff --git a/submodules/ComposePollUI/BUCK b/submodules/ComposePollUI/BUCK index 674cdc4d74..3eec9a8776 100644 --- a/submodules/ComposePollUI/BUCK +++ b/submodules/ComposePollUI/BUCK @@ -10,6 +10,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/ItemListUI:ItemListUI", "//submodules/AccountContext:AccountContext", diff --git a/submodules/ComposePollUI/Sources/CreatePollController.swift b/submodules/ComposePollUI/Sources/CreatePollController.swift index 9e7e56b2cc..a1b13f6384 100644 --- a/submodules/ComposePollUI/Sources/CreatePollController.swift +++ b/submodules/ComposePollUI/Sources/CreatePollController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/ContactListUI/BUCK b/submodules/ContactListUI/BUCK index af4cf35239..d16c21b35c 100644 --- a/submodules/ContactListUI/BUCK +++ b/submodules/ContactListUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/AccountContext:AccountContext", "//submodules/TelegramUIPreferences:TelegramUIPreferences", diff --git a/submodules/ContactListUI/Sources/ContactAddItem.swift b/submodules/ContactListUI/Sources/ContactAddItem.swift index ccf2a6ee48..f8af432fbb 100644 --- a/submodules/ContactListUI/Sources/ContactAddItem.swift +++ b/submodules/ContactListUI/Sources/ContactAddItem.swift @@ -5,6 +5,7 @@ import Postbox import Display import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import AppBundle import PhoneNumberFormat diff --git a/submodules/ContactListUI/Sources/ContactContextMenus.swift b/submodules/ContactListUI/Sources/ContactContextMenus.swift index 13c11b6ddb..c5c09c42a4 100644 --- a/submodules/ContactListUI/Sources/ContactContextMenus.swift +++ b/submodules/ContactListUI/Sources/ContactContextMenus.swift @@ -5,6 +5,7 @@ import ContextUI import AccountContext import Postbox import TelegramCore +import SyncCore import Display import AlertUI import PresentationDataUtils diff --git a/submodules/ContactListUI/Sources/ContactListNode.swift b/submodules/ContactListUI/Sources/ContactListNode.swift index 5bc89a021e..fd789bc2dd 100644 --- a/submodules/ContactListUI/Sources/ContactListNode.swift +++ b/submodules/ContactListUI/Sources/ContactListNode.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import DeviceAccess diff --git a/submodules/ContactListUI/Sources/ContactsController.swift b/submodules/ContactListUI/Sources/ContactsController.swift index 38377dbdf5..4d8f4696e5 100644 --- a/submodules/ContactListUI/Sources/ContactsController.swift +++ b/submodules/ContactListUI/Sources/ContactsController.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import Postbox import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import DeviceAccess diff --git a/submodules/ContactListUI/Sources/ContactsControllerNode.swift b/submodules/ContactListUI/Sources/ContactsControllerNode.swift index 6ebb64baf6..0399801ae6 100644 --- a/submodules/ContactListUI/Sources/ContactsControllerNode.swift +++ b/submodules/ContactListUI/Sources/ContactsControllerNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import UIKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/ContactListUI/Sources/ContactsSearchContainerNode.swift b/submodules/ContactListUI/Sources/ContactsSearchContainerNode.swift index e26311f7c1..8a23d9bdaf 100644 --- a/submodules/ContactListUI/Sources/ContactsSearchContainerNode.swift +++ b/submodules/ContactListUI/Sources/ContactsSearchContainerNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import MergeLists diff --git a/submodules/ContactListUI/Sources/InviteContactsController.swift b/submodules/ContactListUI/Sources/InviteContactsController.swift index 5b6fc926c6..c7b846a8f5 100644 --- a/submodules/ContactListUI/Sources/InviteContactsController.swift +++ b/submodules/ContactListUI/Sources/InviteContactsController.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import Postbox import SwiftSignalKit import TelegramCore +import SyncCore import MessageUI import TelegramPresentationData import AccountContext diff --git a/submodules/ContactListUI/Sources/InviteContactsControllerNode.swift b/submodules/ContactListUI/Sources/InviteContactsControllerNode.swift index ccac76548a..59d791b2cb 100644 --- a/submodules/ContactListUI/Sources/InviteContactsControllerNode.swift +++ b/submodules/ContactListUI/Sources/InviteContactsControllerNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import UIKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/ContactsPeerItem/BUCK b/submodules/ContactsPeerItem/BUCK index 145b5971c7..3a6eea69dc 100644 --- a/submodules/ContactsPeerItem/BUCK +++ b/submodules/ContactsPeerItem/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/AccountContext:AccountContext", "//submodules/AvatarNode:AvatarNode", "//submodules/TelegramPresentationData:TelegramPresentationData", diff --git a/submodules/ContactsPeerItem/Sources/ContactsPeerItem.swift b/submodules/ContactsPeerItem/Sources/ContactsPeerItem.swift index adac687d00..638efe5a7d 100644 --- a/submodules/ContactsPeerItem/Sources/ContactsPeerItem.swift +++ b/submodules/ContactsPeerItem/Sources/ContactsPeerItem.swift @@ -5,6 +5,7 @@ import Postbox import Display import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/ContextUI/Sources/ContextController.swift b/submodules/ContextUI/Sources/ContextController.swift index 280af73552..a3cb20e5b8 100644 --- a/submodules/ContextUI/Sources/ContextController.swift +++ b/submodules/ContextUI/Sources/ContextController.swift @@ -6,6 +6,7 @@ import TelegramPresentationData import TextSelectionNode import ReactionSelectionNode import TelegramCore +import SyncCore import SwiftSignalKit private let animationDurationFactor: Double = 1.0 diff --git a/submodules/CountrySelectionUI/Sources/AuthorizationSequenceCountrySelectionControllerNode.swift b/submodules/CountrySelectionUI/Sources/AuthorizationSequenceCountrySelectionControllerNode.swift index 5aea4c95b8..a422c2f291 100644 --- a/submodules/CountrySelectionUI/Sources/AuthorizationSequenceCountrySelectionControllerNode.swift +++ b/submodules/CountrySelectionUI/Sources/AuthorizationSequenceCountrySelectionControllerNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import TelegramPresentationData import TelegramStringFormatting import AppBundle diff --git a/submodules/DeleteChatPeerActionSheetItem/BUCK b/submodules/DeleteChatPeerActionSheetItem/BUCK index d99339b04f..578a972961 100644 --- a/submodules/DeleteChatPeerActionSheetItem/BUCK +++ b/submodules/DeleteChatPeerActionSheetItem/BUCK @@ -10,6 +10,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/AccountContext:AccountContext", "//submodules/AvatarNode:AvatarNode", "//submodules/TelegramPresentationData:TelegramPresentationData", diff --git a/submodules/DeleteChatPeerActionSheetItem/Sources/DeleteChatPeerActionSheetItem.swift b/submodules/DeleteChatPeerActionSheetItem/Sources/DeleteChatPeerActionSheetItem.swift index c9e92e8510..dbd913a14b 100644 --- a/submodules/DeleteChatPeerActionSheetItem/Sources/DeleteChatPeerActionSheetItem.swift +++ b/submodules/DeleteChatPeerActionSheetItem/Sources/DeleteChatPeerActionSheetItem.swift @@ -3,6 +3,7 @@ import UIKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import AvatarNode diff --git a/submodules/DeviceAccess/BUCK b/submodules/DeviceAccess/BUCK index d74e86ec9c..3d2abcb731 100644 --- a/submodules/DeviceAccess/BUCK +++ b/submodules/DeviceAccess/BUCK @@ -7,6 +7,7 @@ static_library( ]), deps = [ "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Display:Display#shared", "//submodules/AccountContext:AccountContext", diff --git a/submodules/DeviceAccess/Sources/DeviceAccess.swift b/submodules/DeviceAccess/Sources/DeviceAccess.swift index f0f32bda1f..c70bc19e15 100644 --- a/submodules/DeviceAccess/Sources/DeviceAccess.swift +++ b/submodules/DeviceAccess/Sources/DeviceAccess.swift @@ -3,6 +3,7 @@ import UIKit import AVFoundation import Display import TelegramCore +import SyncCore import SwiftSignalKit import Photos import CoreLocation diff --git a/submodules/DeviceLocationManager/BUCK b/submodules/DeviceLocationManager/BUCK index a9f7473e71..7bd20856a8 100644 --- a/submodules/DeviceLocationManager/BUCK +++ b/submodules/DeviceLocationManager/BUCK @@ -6,7 +6,7 @@ static_library( "Sources/**/*.swift", ]), deps = [ - "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#dynamic", + "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", ], frameworks = [ "$SDKROOT/System/Library/Frameworks/Foundation.framework", diff --git a/submodules/Display/BUCK b/submodules/Display/BUCK index 77ebb925a3..64506971d0 100644 --- a/submodules/Display/BUCK +++ b/submodules/Display/BUCK @@ -13,8 +13,8 @@ framework( "Display/*.h", ], exclude = ["Display/Display.h"]), deps = [ - "//submodules/AsyncDisplayKit:AsyncDisplayKit#dynamic", - "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#dynamic", + "//submodules/AsyncDisplayKit:AsyncDisplayKit#shared", + "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/AppBundle:AppBundle", "//submodules/Markdown:Markdown", ], diff --git a/submodules/EncryptionKeyVisualization/BUCK b/submodules/EncryptionKeyVisualization/BUCK index 78c401a40d..8fa948603e 100644 --- a/submodules/EncryptionKeyVisualization/BUCK +++ b/submodules/EncryptionKeyVisualization/BUCK @@ -14,6 +14,7 @@ static_library( ], exclude = ["Sources/EncryptionKeyVisualization.h"]), deps = [ "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", ], frameworks = [ "$SDKROOT/System/Library/Frameworks/Foundation.framework", diff --git a/submodules/EncryptionKeyVisualization/Sources/SecretChatKeyVisualization.swift b/submodules/EncryptionKeyVisualization/Sources/SecretChatKeyVisualization.swift index 8252f0f1cf..cf974f1843 100644 --- a/submodules/EncryptionKeyVisualization/Sources/SecretChatKeyVisualization.swift +++ b/submodules/EncryptionKeyVisualization/Sources/SecretChatKeyVisualization.swift @@ -1,5 +1,6 @@ import Foundation import TelegramCore +import SyncCore public func secretChatKeyImage(_ fingerprint: SecretChatKeyFingerprint, size: CGSize) -> UIImage? { let keySignatureData = fingerprint.sha1.data() diff --git a/submodules/GalleryUI/BUCK b/submodules/GalleryUI/BUCK index f32a3d2406..168d8bb330 100644 --- a/submodules/GalleryUI/BUCK +++ b/submodules/GalleryUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/TextFormat:TextFormat", "//submodules/AccountContext:AccountContext", diff --git a/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift b/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift index 5e784e7d54..a57a3d5fca 100644 --- a/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift +++ b/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Photos import TelegramPresentationData diff --git a/submodules/GalleryUI/Sources/ChatVideoGalleryItemScrubberView.swift b/submodules/GalleryUI/Sources/ChatVideoGalleryItemScrubberView.swift index 98bcebc3cf..fc09e8a10e 100644 --- a/submodules/GalleryUI/Sources/ChatVideoGalleryItemScrubberView.swift +++ b/submodules/GalleryUI/Sources/ChatVideoGalleryItemScrubberView.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import Postbox import Display import UniversalMediaPlayer diff --git a/submodules/GalleryUI/Sources/GalleryController.swift b/submodules/GalleryUI/Sources/GalleryController.swift index e5ff548c09..a41b7507c3 100644 --- a/submodules/GalleryUI/Sources/GalleryController.swift +++ b/submodules/GalleryUI/Sources/GalleryController.swift @@ -6,6 +6,7 @@ import Postbox import SwiftSignalKit import AsyncDisplayKit import TelegramCore +import SyncCore import SafariServices import TelegramPresentationData import TextFormat diff --git a/submodules/GalleryUI/Sources/Items/ChatAnimationGalleryItem.swift b/submodules/GalleryUI/Sources/Items/ChatAnimationGalleryItem.swift index 6e8741fb8a..b7b82d1d3d 100644 --- a/submodules/GalleryUI/Sources/Items/ChatAnimationGalleryItem.swift +++ b/submodules/GalleryUI/Sources/Items/ChatAnimationGalleryItem.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import Lottie import TelegramPresentationData import AnimationUI diff --git a/submodules/GalleryUI/Sources/Items/ChatDocumentGalleryItem.swift b/submodules/GalleryUI/Sources/Items/ChatDocumentGalleryItem.swift index c879800a96..2bc400d803 100644 --- a/submodules/GalleryUI/Sources/Items/ChatDocumentGalleryItem.swift +++ b/submodules/GalleryUI/Sources/Items/ChatDocumentGalleryItem.swift @@ -6,6 +6,7 @@ import Display import SwiftSignalKit import WebKit import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import RadialStatusNode diff --git a/submodules/GalleryUI/Sources/Items/ChatExternalFileGalleryItem.swift b/submodules/GalleryUI/Sources/Items/ChatExternalFileGalleryItem.swift index 3f0a4df1b8..78099a5279 100644 --- a/submodules/GalleryUI/Sources/Items/ChatExternalFileGalleryItem.swift +++ b/submodules/GalleryUI/Sources/Items/ChatExternalFileGalleryItem.swift @@ -6,6 +6,7 @@ import Display import SwiftSignalKit import WebKit import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import RadialStatusNode diff --git a/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift b/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift index 1103737923..44e5a460a3 100644 --- a/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift +++ b/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import RadialStatusNode diff --git a/submodules/GalleryUI/Sources/Items/UniversalVideoGalleryItem.swift b/submodules/GalleryUI/Sources/Items/UniversalVideoGalleryItem.swift index a560bbf3ae..c568f64888 100644 --- a/submodules/GalleryUI/Sources/Items/UniversalVideoGalleryItem.swift +++ b/submodules/GalleryUI/Sources/Items/UniversalVideoGalleryItem.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import Display import Postbox import TelegramPresentationData diff --git a/submodules/GalleryUI/Sources/SecretMediaPreviewController.swift b/submodules/GalleryUI/Sources/SecretMediaPreviewController.swift index 96b89d881e..4a2df1e638 100644 --- a/submodules/GalleryUI/Sources/SecretMediaPreviewController.swift +++ b/submodules/GalleryUI/Sources/SecretMediaPreviewController.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AccountContext diff --git a/submodules/GalleryUI/Sources/SecretMediaPreviewFooterContentNode.swift b/submodules/GalleryUI/Sources/SecretMediaPreviewFooterContentNode.swift index 83c482b68f..137cb8362c 100644 --- a/submodules/GalleryUI/Sources/SecretMediaPreviewFooterContentNode.swift +++ b/submodules/GalleryUI/Sources/SecretMediaPreviewFooterContentNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit private let textFont = Font.regular(16.0) diff --git a/submodules/GameUI/BUCK b/submodules/GameUI/BUCK index 3d78cade3a..4c37fd8b55 100644 --- a/submodules/GameUI/BUCK +++ b/submodules/GameUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/AccountContext:AccountContext", "//submodules/ShareController:ShareController", diff --git a/submodules/GameUI/Sources/GameController.swift b/submodules/GameUI/Sources/GameController.swift index dc8079c6db..d9cbd217e1 100644 --- a/submodules/GameUI/Sources/GameController.swift +++ b/submodules/GameUI/Sources/GameController.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/GameUI/Sources/GameControllerNode.swift b/submodules/GameUI/Sources/GameControllerNode.swift index a5c1fc7559..91d89e57bf 100644 --- a/submodules/GameUI/Sources/GameControllerNode.swift +++ b/submodules/GameUI/Sources/GameControllerNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import WebKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/GameUI/Sources/GameControllerTitleView.swift b/submodules/GameUI/Sources/GameControllerTitleView.swift index 528d9828b1..ec012f2fae 100644 --- a/submodules/GameUI/Sources/GameControllerTitleView.swift +++ b/submodules/GameUI/Sources/GameControllerTitleView.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/HashtagSearchUI/BUCK b/submodules/HashtagSearchUI/BUCK index 4c97de6455..dd0dc6ebee 100644 --- a/submodules/HashtagSearchUI/BUCK +++ b/submodules/HashtagSearchUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/AccountContext:AccountContext", "//submodules/TelegramBaseController:TelegramBaseController", diff --git a/submodules/HashtagSearchUI/Sources/HashtagSearchController.swift b/submodules/HashtagSearchUI/Sources/HashtagSearchController.swift index 760968bf11..b353e21f39 100644 --- a/submodules/HashtagSearchUI/Sources/HashtagSearchController.swift +++ b/submodules/HashtagSearchUI/Sources/HashtagSearchController.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/HashtagSearchUI/Sources/HashtagSearchControllerNode.swift b/submodules/HashtagSearchUI/Sources/HashtagSearchControllerNode.swift index f84d45347c..866abaa0a0 100644 --- a/submodules/HashtagSearchUI/Sources/HashtagSearchControllerNode.swift +++ b/submodules/HashtagSearchUI/Sources/HashtagSearchControllerNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import ChatListUI diff --git a/submodules/HorizontalPeerItem/BUCK b/submodules/HorizontalPeerItem/BUCK index 3f152913e8..fe74c3eda8 100644 --- a/submodules/HorizontalPeerItem/BUCK +++ b/submodules/HorizontalPeerItem/BUCK @@ -9,6 +9,7 @@ static_library( "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/AsyncDisplayKit:AsyncDisplayKit#shared", "//submodules/Display:Display#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", diff --git a/submodules/HorizontalPeerItem/Sources/HorizontalPeerItem.swift b/submodules/HorizontalPeerItem/Sources/HorizontalPeerItem.swift index 3463c7d8b2..a3ee0ac522 100644 --- a/submodules/HorizontalPeerItem/Sources/HorizontalPeerItem.swift +++ b/submodules/HorizontalPeerItem/Sources/HorizontalPeerItem.swift @@ -4,6 +4,7 @@ import Display import Postbox import AsyncDisplayKit import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import TelegramStringFormatting diff --git a/submodules/InstantPageCache/BUCK b/submodules/InstantPageCache/BUCK index 6136310edf..18ecb10b55 100644 --- a/submodules/InstantPageCache/BUCK +++ b/submodules/InstantPageCache/BUCK @@ -7,6 +7,7 @@ static_library( ]), deps = [ "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/Postbox:Postbox#shared", "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/TelegramUIPreferences:TelegramUIPreferences", diff --git a/submodules/InstantPageCache/Sources/CachedInstantPages.swift b/submodules/InstantPageCache/Sources/CachedInstantPages.swift index 8b528633c6..f3e618d852 100644 --- a/submodules/InstantPageCache/Sources/CachedInstantPages.swift +++ b/submodules/InstantPageCache/Sources/CachedInstantPages.swift @@ -3,6 +3,7 @@ import UIKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramUIPreferences import PersistentStringHash diff --git a/submodules/InstantPageUI/BUCK b/submodules/InstantPageUI/BUCK index 72be45275a..4c6a52fdde 100644 --- a/submodules/InstantPageUI/BUCK +++ b/submodules/InstantPageUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/TelegramUIPreferences:TelegramUIPreferences", "//submodules/GalleryUI:GalleryUI", diff --git a/submodules/InstantPageUI/Sources/InstantImageGalleryItem.swift b/submodules/InstantPageUI/Sources/InstantImageGalleryItem.swift index ddbc4757b2..3d9c93438d 100644 --- a/submodules/InstantPageUI/Sources/InstantImageGalleryItem.swift +++ b/submodules/InstantPageUI/Sources/InstantImageGalleryItem.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import PhotoResources diff --git a/submodules/InstantPageUI/Sources/InstantPageAnchorItem.swift b/submodules/InstantPageUI/Sources/InstantPageAnchorItem.swift index 7355720c99..9c2d810467 100644 --- a/submodules/InstantPageUI/Sources/InstantPageAnchorItem.swift +++ b/submodules/InstantPageUI/Sources/InstantPageAnchorItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import AsyncDisplayKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/InstantPageUI/Sources/InstantPageArticleItem.swift b/submodules/InstantPageUI/Sources/InstantPageArticleItem.swift index 297ae995cf..0a2eb5f941 100644 --- a/submodules/InstantPageUI/Sources/InstantPageArticleItem.swift +++ b/submodules/InstantPageUI/Sources/InstantPageArticleItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import AsyncDisplayKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/InstantPageUI/Sources/InstantPageArticleNode.swift b/submodules/InstantPageUI/Sources/InstantPageArticleNode.swift index 86bb711aeb..b1aa39e3d8 100644 --- a/submodules/InstantPageUI/Sources/InstantPageArticleNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageArticleNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AccountContext diff --git a/submodules/InstantPageUI/Sources/InstantPageAudioItem.swift b/submodules/InstantPageUI/Sources/InstantPageAudioItem.swift index 81690b977e..5fcd695a29 100644 --- a/submodules/InstantPageUI/Sources/InstantPageAudioItem.swift +++ b/submodules/InstantPageUI/Sources/InstantPageAudioItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import AsyncDisplayKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/InstantPageUI/Sources/InstantPageAudioNode.swift b/submodules/InstantPageUI/Sources/InstantPageAudioNode.swift index e81b89878a..6503ccb479 100644 --- a/submodules/InstantPageUI/Sources/InstantPageAudioNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageAudioNode.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import AsyncDisplayKit diff --git a/submodules/InstantPageUI/Sources/InstantPageContentNode.swift b/submodules/InstantPageUI/Sources/InstantPageContentNode.swift index 4c66008ea6..d8e9ef8b55 100644 --- a/submodules/InstantPageUI/Sources/InstantPageContentNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageContentNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/InstantPageUI/Sources/InstantPageController.swift b/submodules/InstantPageUI/Sources/InstantPageController.swift index e943641e73..8691aa57a8 100644 --- a/submodules/InstantPageUI/Sources/InstantPageController.swift +++ b/submodules/InstantPageUI/Sources/InstantPageController.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import Display diff --git a/submodules/InstantPageUI/Sources/InstantPageControllerNode.swift b/submodules/InstantPageUI/Sources/InstantPageControllerNode.swift index d708693082..3d661e0949 100644 --- a/submodules/InstantPageUI/Sources/InstantPageControllerNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageControllerNode.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import AsyncDisplayKit import Display diff --git a/submodules/InstantPageUI/Sources/InstantPageDetailsItem.swift b/submodules/InstantPageUI/Sources/InstantPageDetailsItem.swift index ba8e7508eb..403bc21adc 100644 --- a/submodules/InstantPageUI/Sources/InstantPageDetailsItem.swift +++ b/submodules/InstantPageUI/Sources/InstantPageDetailsItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import AsyncDisplayKit import Display import TelegramPresentationData diff --git a/submodules/InstantPageUI/Sources/InstantPageDetailsNode.swift b/submodules/InstantPageUI/Sources/InstantPageDetailsNode.swift index 74d94e6a48..168e061e2c 100644 --- a/submodules/InstantPageUI/Sources/InstantPageDetailsNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageDetailsNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/InstantPageUI/Sources/InstantPageFeedbackItem.swift b/submodules/InstantPageUI/Sources/InstantPageFeedbackItem.swift index fed9f7ff03..5e499e33e1 100644 --- a/submodules/InstantPageUI/Sources/InstantPageFeedbackItem.swift +++ b/submodules/InstantPageUI/Sources/InstantPageFeedbackItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import AsyncDisplayKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/InstantPageUI/Sources/InstantPageFeedbackNode.swift b/submodules/InstantPageUI/Sources/InstantPageFeedbackNode.swift index 37e2e309ec..352782f4a0 100644 --- a/submodules/InstantPageUI/Sources/InstantPageFeedbackNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageFeedbackNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AccountContext diff --git a/submodules/InstantPageUI/Sources/InstantPageGalleryController.swift b/submodules/InstantPageUI/Sources/InstantPageGalleryController.swift index 99cd5a3ca1..7c2b5326b3 100644 --- a/submodules/InstantPageUI/Sources/InstantPageGalleryController.swift +++ b/submodules/InstantPageUI/Sources/InstantPageGalleryController.swift @@ -6,6 +6,7 @@ import Postbox import SwiftSignalKit import AsyncDisplayKit import TelegramCore +import SyncCore import SafariServices import TelegramPresentationData import AccountContext diff --git a/submodules/InstantPageUI/Sources/InstantPageGalleryFooterContentNode.swift b/submodules/InstantPageUI/Sources/InstantPageGalleryFooterContentNode.swift index 77199ced8c..38c92ee1c2 100644 --- a/submodules/InstantPageUI/Sources/InstantPageGalleryFooterContentNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageGalleryFooterContentNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Photos import TelegramPresentationData diff --git a/submodules/InstantPageUI/Sources/InstantPageImageItem.swift b/submodules/InstantPageUI/Sources/InstantPageImageItem.swift index fd41ed57f6..0b8839d178 100644 --- a/submodules/InstantPageUI/Sources/InstantPageImageItem.swift +++ b/submodules/InstantPageUI/Sources/InstantPageImageItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import AsyncDisplayKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/InstantPageUI/Sources/InstantPageImageNode.swift b/submodules/InstantPageUI/Sources/InstantPageImageNode.swift index 4dd56cc27d..314486e58e 100644 --- a/submodules/InstantPageUI/Sources/InstantPageImageNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageImageNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AccountContext diff --git a/submodules/InstantPageUI/Sources/InstantPageItem.swift b/submodules/InstantPageUI/Sources/InstantPageItem.swift index c9608e06e8..f7a9d25a9c 100644 --- a/submodules/InstantPageUI/Sources/InstantPageItem.swift +++ b/submodules/InstantPageUI/Sources/InstantPageItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import AsyncDisplayKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/InstantPageUI/Sources/InstantPageLayout.swift b/submodules/InstantPageUI/Sources/InstantPageLayout.swift index a6340316bc..a457c1d6bb 100644 --- a/submodules/InstantPageUI/Sources/InstantPageLayout.swift +++ b/submodules/InstantPageUI/Sources/InstantPageLayout.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import Postbox import Display import TelegramPresentationData diff --git a/submodules/InstantPageUI/Sources/InstantPageLayoutSpacings.swift b/submodules/InstantPageUI/Sources/InstantPageLayoutSpacings.swift index 0f95764937..4690aede4f 100644 --- a/submodules/InstantPageUI/Sources/InstantPageLayoutSpacings.swift +++ b/submodules/InstantPageUI/Sources/InstantPageLayoutSpacings.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore func spacingBetweenBlocks(upper: InstantPageBlock?, lower: InstantPageBlock?) -> CGFloat { if let upper = upper, let lower = lower { diff --git a/submodules/InstantPageUI/Sources/InstantPageMedia.swift b/submodules/InstantPageUI/Sources/InstantPageMedia.swift index 757ba68a04..a9f36fcbe7 100644 --- a/submodules/InstantPageUI/Sources/InstantPageMedia.swift +++ b/submodules/InstantPageUI/Sources/InstantPageMedia.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore public struct InstantPageMedia: Equatable { public let index: Int diff --git a/submodules/InstantPageUI/Sources/InstantPageMediaPlaylist.swift b/submodules/InstantPageUI/Sources/InstantPageMediaPlaylist.swift index 897df8529a..85175591cf 100644 --- a/submodules/InstantPageUI/Sources/InstantPageMediaPlaylist.swift +++ b/submodules/InstantPageUI/Sources/InstantPageMediaPlaylist.swift @@ -3,6 +3,7 @@ import UIKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramUIPreferences import AccountContext import MusicAlbumArtResources diff --git a/submodules/InstantPageUI/Sources/InstantPagePeerReferenceItem.swift b/submodules/InstantPageUI/Sources/InstantPagePeerReferenceItem.swift index cde027b319..6400461344 100644 --- a/submodules/InstantPageUI/Sources/InstantPagePeerReferenceItem.swift +++ b/submodules/InstantPageUI/Sources/InstantPagePeerReferenceItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import AsyncDisplayKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/InstantPageUI/Sources/InstantPagePeerReferenceNode.swift b/submodules/InstantPageUI/Sources/InstantPagePeerReferenceNode.swift index 864a488a28..410488dc4c 100644 --- a/submodules/InstantPageUI/Sources/InstantPagePeerReferenceNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPagePeerReferenceNode.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import AsyncDisplayKit diff --git a/submodules/InstantPageUI/Sources/InstantPagePlayableVideoItem.swift b/submodules/InstantPageUI/Sources/InstantPagePlayableVideoItem.swift index 432e2db8bc..a4ad1c2237 100644 --- a/submodules/InstantPageUI/Sources/InstantPagePlayableVideoItem.swift +++ b/submodules/InstantPageUI/Sources/InstantPagePlayableVideoItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import AsyncDisplayKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/InstantPageUI/Sources/InstantPagePlayableVideoNode.swift b/submodules/InstantPageUI/Sources/InstantPagePlayableVideoNode.swift index 998b3cdcdd..944c9c8f90 100644 --- a/submodules/InstantPageUI/Sources/InstantPagePlayableVideoNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPagePlayableVideoNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AccountContext diff --git a/submodules/InstantPageUI/Sources/InstantPageReferenceController.swift b/submodules/InstantPageUI/Sources/InstantPageReferenceController.swift index 02ef3e2080..a6eaf0d51d 100644 --- a/submodules/InstantPageUI/Sources/InstantPageReferenceController.swift +++ b/submodules/InstantPageUI/Sources/InstantPageReferenceController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import AccountContext diff --git a/submodules/InstantPageUI/Sources/InstantPageReferenceControllerNode.swift b/submodules/InstantPageUI/Sources/InstantPageReferenceControllerNode.swift index 648ac97cdc..a13d6c5c51 100644 --- a/submodules/InstantPageUI/Sources/InstantPageReferenceControllerNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageReferenceControllerNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SafariServices import TelegramPresentationData import AccountContext diff --git a/submodules/InstantPageUI/Sources/InstantPageScrollableNode.swift b/submodules/InstantPageUI/Sources/InstantPageScrollableNode.swift index 3b7ebaee04..33f5a4aa84 100644 --- a/submodules/InstantPageUI/Sources/InstantPageScrollableNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageScrollableNode.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import AsyncDisplayKit import TelegramCore +import SyncCore import Postbox import Display import TelegramPresentationData diff --git a/submodules/InstantPageUI/Sources/InstantPageShapeItem.swift b/submodules/InstantPageUI/Sources/InstantPageShapeItem.swift index b21f3654cd..bf5fbcf629 100644 --- a/submodules/InstantPageUI/Sources/InstantPageShapeItem.swift +++ b/submodules/InstantPageUI/Sources/InstantPageShapeItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import AsyncDisplayKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/InstantPageUI/Sources/InstantPageSlideshowItem.swift b/submodules/InstantPageUI/Sources/InstantPageSlideshowItem.swift index 10ed04f803..561f744a00 100644 --- a/submodules/InstantPageUI/Sources/InstantPageSlideshowItem.swift +++ b/submodules/InstantPageUI/Sources/InstantPageSlideshowItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import AsyncDisplayKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/InstantPageUI/Sources/InstantPageSlideshowItemNode.swift b/submodules/InstantPageUI/Sources/InstantPageSlideshowItemNode.swift index 5ff00fe512..ca2a03bdba 100644 --- a/submodules/InstantPageUI/Sources/InstantPageSlideshowItemNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageSlideshowItemNode.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import AsyncDisplayKit import Display import TelegramPresentationData diff --git a/submodules/InstantPageUI/Sources/InstantPageStoredState.swift b/submodules/InstantPageUI/Sources/InstantPageStoredState.swift index 3334d421cb..a9203e830e 100644 --- a/submodules/InstantPageUI/Sources/InstantPageStoredState.swift +++ b/submodules/InstantPageUI/Sources/InstantPageStoredState.swift @@ -3,6 +3,7 @@ import UIKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramUIPreferences public final class InstantPageStoredDetailsState: PostboxCoding { diff --git a/submodules/InstantPageUI/Sources/InstantPageTableItem.swift b/submodules/InstantPageUI/Sources/InstantPageTableItem.swift index 84e5896333..92bce80e35 100644 --- a/submodules/InstantPageUI/Sources/InstantPageTableItem.swift +++ b/submodules/InstantPageUI/Sources/InstantPageTableItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import AsyncDisplayKit import TelegramCore +import SyncCore import Postbox import Display import TelegramPresentationData diff --git a/submodules/InstantPageUI/Sources/InstantPageTextItem.swift b/submodules/InstantPageUI/Sources/InstantPageTextItem.swift index 34da7e4d8e..ff18ceb44a 100644 --- a/submodules/InstantPageUI/Sources/InstantPageTextItem.swift +++ b/submodules/InstantPageUI/Sources/InstantPageTextItem.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import Display import Postbox import AsyncDisplayKit diff --git a/submodules/InstantPageUI/Sources/InstantPageTextStyleStack.swift b/submodules/InstantPageUI/Sources/InstantPageTextStyleStack.swift index 335b66684f..29378e7c38 100644 --- a/submodules/InstantPageUI/Sources/InstantPageTextStyleStack.swift +++ b/submodules/InstantPageUI/Sources/InstantPageTextStyleStack.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import Display enum InstantPageTextStyle { diff --git a/submodules/InstantPageUI/Sources/InstantPageWebEmbedItem.swift b/submodules/InstantPageUI/Sources/InstantPageWebEmbedItem.swift index 13ee291a9c..de516b6e37 100644 --- a/submodules/InstantPageUI/Sources/InstantPageWebEmbedItem.swift +++ b/submodules/InstantPageUI/Sources/InstantPageWebEmbedItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import AsyncDisplayKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/InstantPageUI/Sources/InstantPageWebEmbedNode.swift b/submodules/InstantPageUI/Sources/InstantPageWebEmbedNode.swift index beed035c1c..b6e0575550 100644 --- a/submodules/InstantPageUI/Sources/InstantPageWebEmbedNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageWebEmbedNode.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import WebKit import AsyncDisplayKit import Display diff --git a/submodules/ItemListAvatarAndNameInfoItem/BUCK b/submodules/ItemListAvatarAndNameInfoItem/BUCK index 9d8e06f7d7..209680328a 100644 --- a/submodules/ItemListAvatarAndNameInfoItem/BUCK +++ b/submodules/ItemListAvatarAndNameInfoItem/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/PeerPresenceStatusManager:PeerPresenceStatusManager", "//submodules/TelegramStringFormatting:TelegramStringFormatting", diff --git a/submodules/ItemListAvatarAndNameInfoItem/Sources/ItemListAvatarAndNameItem.swift b/submodules/ItemListAvatarAndNameInfoItem/Sources/ItemListAvatarAndNameItem.swift index 2144449ee1..ee9d3e6654 100644 --- a/submodules/ItemListAvatarAndNameInfoItem/Sources/ItemListAvatarAndNameItem.swift +++ b/submodules/ItemListAvatarAndNameInfoItem/Sources/ItemListAvatarAndNameItem.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import ItemListUI diff --git a/submodules/ItemListPeerItem/BUCK b/submodules/ItemListPeerItem/BUCK index 465b5ecae0..8b7c78c2d3 100644 --- a/submodules/ItemListPeerItem/BUCK +++ b/submodules/ItemListPeerItem/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/AvatarNode:AvatarNode", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/TelegramStringFormatting:TelegramStringFormatting", diff --git a/submodules/ItemListPeerItem/Sources/ItemListPeerItem.swift b/submodules/ItemListPeerItem/Sources/ItemListPeerItem.swift index ab3a13e382..a4564062e6 100644 --- a/submodules/ItemListPeerItem/Sources/ItemListPeerItem.swift +++ b/submodules/ItemListPeerItem/Sources/ItemListPeerItem.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/ItemListStickerPackItem/BUCK b/submodules/ItemListStickerPackItem/BUCK index c2b14e9cef..75bb09d26c 100644 --- a/submodules/ItemListStickerPackItem/BUCK +++ b/submodules/ItemListStickerPackItem/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/ItemListUI:ItemListUI", "//submodules/StickerResources:StickerResources", diff --git a/submodules/ItemListStickerPackItem/Sources/ItemListStickerPackItem.swift b/submodules/ItemListStickerPackItem/Sources/ItemListStickerPackItem.swift index f726e85c0c..5711bb3559 100644 --- a/submodules/ItemListStickerPackItem/Sources/ItemListStickerPackItem.swift +++ b/submodules/ItemListStickerPackItem/Sources/ItemListStickerPackItem.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/ItemListUI/Sources/ItemListControllerNode.swift b/submodules/ItemListUI/Sources/ItemListControllerNode.swift index 3d31f6615e..846de989c5 100644 --- a/submodules/ItemListUI/Sources/ItemListControllerNode.swift +++ b/submodules/ItemListUI/Sources/ItemListControllerNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import MergeLists diff --git a/submodules/JoinLinkPreviewUI/BUCK b/submodules/JoinLinkPreviewUI/BUCK index 4d51dd1621..e99fe4bc84 100644 --- a/submodules/JoinLinkPreviewUI/BUCK +++ b/submodules/JoinLinkPreviewUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/AccountContext:AccountContext", "//submodules/AlertUI:AlertUI", diff --git a/submodules/JoinLinkPreviewUI/Sources/JoinLinkPreviewController.swift b/submodules/JoinLinkPreviewUI/Sources/JoinLinkPreviewController.swift index 786da5a1a8..15fcd1e12e 100644 --- a/submodules/JoinLinkPreviewUI/Sources/JoinLinkPreviewController.swift +++ b/submodules/JoinLinkPreviewUI/Sources/JoinLinkPreviewController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AccountContext diff --git a/submodules/JoinLinkPreviewUI/Sources/JoinLinkPreviewControllerNode.swift b/submodules/JoinLinkPreviewUI/Sources/JoinLinkPreviewControllerNode.swift index 6cba602e6a..ae72280393 100644 --- a/submodules/JoinLinkPreviewUI/Sources/JoinLinkPreviewControllerNode.swift +++ b/submodules/JoinLinkPreviewUI/Sources/JoinLinkPreviewControllerNode.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import ShareController diff --git a/submodules/JoinLinkPreviewUI/Sources/JoinLinkPreviewPeerContentNode.swift b/submodules/JoinLinkPreviewUI/Sources/JoinLinkPreviewPeerContentNode.swift index 073c484ec2..aa15e00e40 100644 --- a/submodules/JoinLinkPreviewUI/Sources/JoinLinkPreviewPeerContentNode.swift +++ b/submodules/JoinLinkPreviewUI/Sources/JoinLinkPreviewPeerContentNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AvatarNode import AccountContext diff --git a/submodules/LanguageLinkPreviewUI/BUCK b/submodules/LanguageLinkPreviewUI/BUCK index ccc998474e..fae07dd0cc 100644 --- a/submodules/LanguageLinkPreviewUI/BUCK +++ b/submodules/LanguageLinkPreviewUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/AccountContext:AccountContext", "//submodules/TextFormat:TextFormat", diff --git a/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewContentNode.swift b/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewContentNode.swift index ca3377b5a7..a7cd7edb06 100644 --- a/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewContentNode.swift +++ b/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewContentNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TextFormat import AccountContext diff --git a/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewController.swift b/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewController.swift index e21023b548..82c76ccd0c 100644 --- a/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewController.swift +++ b/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AccountContext diff --git a/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewControllerNode.swift b/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewControllerNode.swift index c00b384e56..e5713c7bbc 100644 --- a/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewControllerNode.swift +++ b/submodules/LanguageLinkPreviewUI/Sources/LanguageLinkPreviewControllerNode.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ActivityIndicator import AccountContext diff --git a/submodules/LanguageSuggestionUI/BUCK b/submodules/LanguageSuggestionUI/BUCK index ec182059c9..2e76df58b8 100644 --- a/submodules/LanguageSuggestionUI/BUCK +++ b/submodules/LanguageSuggestionUI/BUCK @@ -10,6 +10,7 @@ static_library( "//submodules/AsyncDisplayKit:AsyncDisplayKit#shared", "//submodules/Display:Display#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/AccountContext:AccountContext", "//submodules/ActivityIndicator:ActivityIndicator", diff --git a/submodules/LanguageSuggestionUI/Sources/LanguageSuggestionController.swift b/submodules/LanguageSuggestionUI/Sources/LanguageSuggestionController.swift index 9b1d0e6f0b..931f7d09a8 100644 --- a/submodules/LanguageSuggestionUI/Sources/LanguageSuggestionController.swift +++ b/submodules/LanguageSuggestionUI/Sources/LanguageSuggestionController.swift @@ -4,6 +4,7 @@ import SwiftSignalKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import TelegramPresentationData import ActivityIndicator import AccountContext diff --git a/submodules/LegacyDataImport/BUCK b/submodules/LegacyDataImport/BUCK index fbc31668c3..91a8201c15 100644 --- a/submodules/LegacyDataImport/BUCK +++ b/submodules/LegacyDataImport/BUCK @@ -13,9 +13,10 @@ static_library( "Sources/*.h", ], exclude = ["Sources/LegacyDataImport.h"]), deps = [ - "//submodules/TelegramCore:TelegramCore#dynamic", - "//submodules/Postbox:Postbox#dynamic", - "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#dynamic", + "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", + "//submodules/Postbox:Postbox#shared", + "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/TelegramNotices:TelegramNotices", "//submodules/TelegramUIPreferences:TelegramUIPreferences", "//submodules/RadialStatusNode:RadialStatusNode", diff --git a/submodules/LegacyDataImport/Sources/LegacyChatImport.swift b/submodules/LegacyDataImport/Sources/LegacyChatImport.swift index 1dcd261c9a..c11f17e066 100644 --- a/submodules/LegacyDataImport/Sources/LegacyChatImport.swift +++ b/submodules/LegacyDataImport/Sources/LegacyChatImport.swift @@ -1,5 +1,6 @@ import Foundation import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import LegacyComponents diff --git a/submodules/LegacyDataImport/Sources/LegacyDataImport.swift b/submodules/LegacyDataImport/Sources/LegacyDataImport.swift index 48af060cd9..3dd3d393aa 100644 --- a/submodules/LegacyDataImport/Sources/LegacyDataImport.swift +++ b/submodules/LegacyDataImport/Sources/LegacyDataImport.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox #if BUCK diff --git a/submodules/LegacyDataImport/Sources/LegacyFileImport.swift b/submodules/LegacyDataImport/Sources/LegacyFileImport.swift index 13059b077f..56308641f2 100644 --- a/submodules/LegacyDataImport/Sources/LegacyFileImport.swift +++ b/submodules/LegacyDataImport/Sources/LegacyFileImport.swift @@ -1,5 +1,6 @@ import Foundation import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import LegacyComponents diff --git a/submodules/LegacyDataImport/Sources/LegacyPreferencesImport.swift b/submodules/LegacyDataImport/Sources/LegacyPreferencesImport.swift index 8038feac0e..f54a75cc71 100644 --- a/submodules/LegacyDataImport/Sources/LegacyPreferencesImport.swift +++ b/submodules/LegacyDataImport/Sources/LegacyPreferencesImport.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox #if BUCK diff --git a/submodules/LegacyDataImport/Sources/LegacyResourceImport.swift b/submodules/LegacyDataImport/Sources/LegacyResourceImport.swift index 6dab43b831..fd4bc6f2e0 100644 --- a/submodules/LegacyDataImport/Sources/LegacyResourceImport.swift +++ b/submodules/LegacyDataImport/Sources/LegacyResourceImport.swift @@ -1,5 +1,6 @@ import Foundation import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import LegacyComponents diff --git a/submodules/LegacyDataImport/Sources/LegacyUserDataImport.swift b/submodules/LegacyDataImport/Sources/LegacyUserDataImport.swift index e4019e944c..431007d79f 100644 --- a/submodules/LegacyDataImport/Sources/LegacyUserDataImport.swift +++ b/submodules/LegacyDataImport/Sources/LegacyUserDataImport.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox diff --git a/submodules/LegacyMediaPickerUI/BUCK b/submodules/LegacyMediaPickerUI/BUCK index 5aafa18eed..a740c095be 100644 --- a/submodules/LegacyMediaPickerUI/BUCK +++ b/submodules/LegacyMediaPickerUI/BUCK @@ -18,6 +18,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/AccountContext:AccountContext", "//submodules/LegacyComponents:LegacyComponents", diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift index f6544e8573..b4056dd51d 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import DeviceAccess import AccountContext diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift index 32cf4d35d2..9e61646b24 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift @@ -3,6 +3,7 @@ import UIKit import LegacyComponents import SwiftSignalKit import TelegramCore +import SyncCore import Postbox import SSignalKit import Display diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacySuggestionContext.swift b/submodules/LegacyMediaPickerUI/Sources/LegacySuggestionContext.swift index 097d7682b1..9b6bd9ace1 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacySuggestionContext.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacySuggestionContext.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import LegacyComponents diff --git a/submodules/LegacyUI/BUCK b/submodules/LegacyUI/BUCK index 52cb17a0c9..9ad361eab1 100644 --- a/submodules/LegacyUI/BUCK +++ b/submodules/LegacyUI/BUCK @@ -9,6 +9,7 @@ static_library( "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/AsyncDisplayKit:AsyncDisplayKit#shared", "//submodules/Display:Display#shared", "//submodules/AccountContext:AccountContext", diff --git a/submodules/LegacyUI/Sources/LegacyComponentsStickers.swift b/submodules/LegacyUI/Sources/LegacyComponentsStickers.swift index 9978c8e8ba..65b3a6c924 100644 --- a/submodules/LegacyUI/Sources/LegacyComponentsStickers.swift +++ b/submodules/LegacyUI/Sources/LegacyComponentsStickers.swift @@ -3,6 +3,7 @@ import UIKit import LegacyComponents import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Display import StickerResources diff --git a/submodules/LegacyUI/Sources/LegacyImageDownloadActor.swift b/submodules/LegacyUI/Sources/LegacyImageDownloadActor.swift index d44e740e58..0292fe7891 100644 --- a/submodules/LegacyUI/Sources/LegacyImageDownloadActor.swift +++ b/submodules/LegacyUI/Sources/LegacyImageDownloadActor.swift @@ -3,6 +3,7 @@ import UIKit import LegacyComponents import Postbox import TelegramCore +import SyncCore import SwiftSignalKit final class LegacyImageDownloadActor: ASActor { diff --git a/submodules/LegacyUI/Sources/LegacyLocationVenueIconDataSource.swift b/submodules/LegacyUI/Sources/LegacyLocationVenueIconDataSource.swift index 1f1a5c71d0..112d02e0cd 100644 --- a/submodules/LegacyUI/Sources/LegacyLocationVenueIconDataSource.swift +++ b/submodules/LegacyUI/Sources/LegacyLocationVenueIconDataSource.swift @@ -3,6 +3,7 @@ import UIKit import LegacyComponents import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Display diff --git a/submodules/LegacyUI/Sources/LegacyMediaLocations.swift b/submodules/LegacyUI/Sources/LegacyMediaLocations.swift index d37e7b75cc..ca8b0fecc8 100644 --- a/submodules/LegacyUI/Sources/LegacyMediaLocations.swift +++ b/submodules/LegacyUI/Sources/LegacyMediaLocations.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore public func legacyImageLocationUri(resource: MediaResource) -> String? { if let resource = resource as? CloudPeerPhotoSizeMediaResource { diff --git a/submodules/LegacyUI/Sources/LegacyPeerAvatarPlaceholderDataSource.swift b/submodules/LegacyUI/Sources/LegacyPeerAvatarPlaceholderDataSource.swift index c1a214b37a..54fb835456 100644 --- a/submodules/LegacyUI/Sources/LegacyPeerAvatarPlaceholderDataSource.swift +++ b/submodules/LegacyUI/Sources/LegacyPeerAvatarPlaceholderDataSource.swift @@ -3,6 +3,7 @@ import UIKit import LegacyComponents import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Display diff --git a/submodules/LegacyUI/Sources/TelegramInitializeLegacyComponents.swift b/submodules/LegacyUI/Sources/TelegramInitializeLegacyComponents.swift index 61511afe1b..32df01e865 100644 --- a/submodules/LegacyUI/Sources/TelegramInitializeLegacyComponents.swift +++ b/submodules/LegacyUI/Sources/TelegramInitializeLegacyComponents.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import SwiftSignalKit #if BUCK import MtProtoKit diff --git a/submodules/LiveLocationManager/BUCK b/submodules/LiveLocationManager/BUCK index d01b28a3da..ac29a1feee 100644 --- a/submodules/LiveLocationManager/BUCK +++ b/submodules/LiveLocationManager/BUCK @@ -6,9 +6,10 @@ static_library( "Sources/**/*.swift", ]), deps = [ - "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#dynamic", - "//submodules/TelegramCore:TelegramCore#dynamic", - "//submodules/Postbox:Postbox#dynamic", + "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", + "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", + "//submodules/Postbox:Postbox#shared", "//submodules/DeviceLocationManager:DeviceLocationManager", "//submodules/AccountContext:AccountContext", ], diff --git a/submodules/LiveLocationManager/Sources/LiveLocationManager.swift b/submodules/LiveLocationManager/Sources/LiveLocationManager.swift index d63f359847..2fe8a7d087 100644 --- a/submodules/LiveLocationManager/Sources/LiveLocationManager.swift +++ b/submodules/LiveLocationManager/Sources/LiveLocationManager.swift @@ -1,5 +1,6 @@ import Foundation import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import CoreLocation diff --git a/submodules/LiveLocationManager/Sources/LiveLocationSummaryManager.swift b/submodules/LiveLocationManager/Sources/LiveLocationSummaryManager.swift index 0918406d93..93440b5d88 100644 --- a/submodules/LiveLocationManager/Sources/LiveLocationSummaryManager.swift +++ b/submodules/LiveLocationManager/Sources/LiveLocationSummaryManager.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import AccountContext diff --git a/submodules/LiveLocationPositionNode/BUCK b/submodules/LiveLocationPositionNode/BUCK index c7239974f1..c3a402be8b 100644 --- a/submodules/LiveLocationPositionNode/BUCK +++ b/submodules/LiveLocationPositionNode/BUCK @@ -10,6 +10,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/AvatarNode:AvatarNode", "//submodules/AppBundle:AppBundle", diff --git a/submodules/LiveLocationPositionNode/Sources/ChatMessageLiveLocationPositionNode.swift b/submodules/LiveLocationPositionNode/Sources/ChatMessageLiveLocationPositionNode.swift index 7da5cabc9e..b3a4b697c4 100644 --- a/submodules/LiveLocationPositionNode/Sources/ChatMessageLiveLocationPositionNode.swift +++ b/submodules/LiveLocationPositionNode/Sources/ChatMessageLiveLocationPositionNode.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import AvatarNode diff --git a/submodules/LocalMediaResources/BUCK b/submodules/LocalMediaResources/BUCK index 57447594a6..6739a9b6cf 100644 --- a/submodules/LocalMediaResources/BUCK +++ b/submodules/LocalMediaResources/BUCK @@ -9,6 +9,7 @@ static_library( "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/ImageCompression:ImageCompression", ], frameworks = [ diff --git a/submodules/LocalMediaResources/Sources/MediaResources.swift b/submodules/LocalMediaResources/Sources/MediaResources.swift index ce75f53326..bd56164cb5 100644 --- a/submodules/LocalMediaResources/Sources/MediaResources.swift +++ b/submodules/LocalMediaResources/Sources/MediaResources.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore public final class VideoMediaResourceAdjustments: PostboxCoding, Equatable { public let data: MemoryBuffer diff --git a/submodules/LocalizedPeerData/BUCK b/submodules/LocalizedPeerData/BUCK index 8790dcfcaa..150c58a399 100644 --- a/submodules/LocalizedPeerData/BUCK +++ b/submodules/LocalizedPeerData/BUCK @@ -6,8 +6,9 @@ static_library( "Sources/**/*.swift", ]), deps = [ - "//submodules/TelegramCore:TelegramCore#dynamic", - "//submodules/Postbox:Postbox#dynamic", + "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", + "//submodules/Postbox:Postbox#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/TelegramUIPreferences:TelegramUIPreferences", "//submodules/PhoneNumberFormat:PhoneNumberFormat", diff --git a/submodules/LocalizedPeerData/Sources/PeerTitle.swift b/submodules/LocalizedPeerData/Sources/PeerTitle.swift index 6ca7c26e34..80f6fc719f 100644 --- a/submodules/LocalizedPeerData/Sources/PeerTitle.swift +++ b/submodules/LocalizedPeerData/Sources/PeerTitle.swift @@ -1,5 +1,6 @@ import Foundation import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/LocationUI/BUCK b/submodules/LocationUI/BUCK index b97fa70d56..9745e8495f 100644 --- a/submodules/LocationUI/BUCK +++ b/submodules/LocationUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/LegacyComponents:LegacyComponents", "//submodules/ShareController:ShareController", diff --git a/submodules/LocationUI/Sources/LegacyLocationController.swift b/submodules/LocationUI/Sources/LegacyLocationController.swift index 38b38de4fb..704e863537 100644 --- a/submodules/LocationUI/Sources/LegacyLocationController.swift +++ b/submodules/LocationUI/Sources/LegacyLocationController.swift @@ -3,6 +3,7 @@ import UIKit import Display import LegacyComponents import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import AccountContext diff --git a/submodules/LocationUI/Sources/LegacyLocationPicker.swift b/submodules/LocationUI/Sources/LegacyLocationPicker.swift index 7534fdcf8f..881c8de8e2 100644 --- a/submodules/LocationUI/Sources/LegacyLocationPicker.swift +++ b/submodules/LocationUI/Sources/LegacyLocationPicker.swift @@ -3,6 +3,7 @@ import UIKit import Display import LegacyComponents import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/MapResourceToAvatarSizes/BUCK b/submodules/MapResourceToAvatarSizes/BUCK index 731d4c57cd..42e165bed4 100644 --- a/submodules/MapResourceToAvatarSizes/BUCK +++ b/submodules/MapResourceToAvatarSizes/BUCK @@ -9,6 +9,7 @@ static_library( "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/Display:Display#shared", ], frameworks = [ diff --git a/submodules/MapResourceToAvatarSizes/Sources/MapResourceToAvatarSizes.swift b/submodules/MapResourceToAvatarSizes/Sources/MapResourceToAvatarSizes.swift index 460bb3b3c4..5e37ba2985 100644 --- a/submodules/MapResourceToAvatarSizes/Sources/MapResourceToAvatarSizes.swift +++ b/submodules/MapResourceToAvatarSizes/Sources/MapResourceToAvatarSizes.swift @@ -3,6 +3,8 @@ import UIKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore +import SyncCore import Display public func mapResourceToAvatarSizes(postbox: Postbox, resource: MediaResource, representations: [TelegramMediaImageRepresentation]) -> Signal<[Int: Data], NoError> { diff --git a/submodules/MediaPlayer/BUCK b/submodules/MediaPlayer/BUCK index f63bd09635..ca0cbcaf82 100644 --- a/submodules/MediaPlayer/BUCK +++ b/submodules/MediaPlayer/BUCK @@ -14,6 +14,7 @@ static_library( ], exclude = ["Sources/UniversalMediaPlayer.h"]), deps = [ "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/Postbox:Postbox#shared", "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/AsyncDisplayKit:AsyncDisplayKit#shared", diff --git a/submodules/MediaPlayer/Sources/FFMpegMediaFrameSource.swift b/submodules/MediaPlayer/Sources/FFMpegMediaFrameSource.swift index 0212c47b8e..3c86dc17ca 100644 --- a/submodules/MediaPlayer/Sources/FFMpegMediaFrameSource.swift +++ b/submodules/MediaPlayer/Sources/FFMpegMediaFrameSource.swift @@ -2,6 +2,7 @@ import Foundation import SwiftSignalKit import Postbox import TelegramCore +import SyncCore private final class ThreadTaskQueue: NSObject { private var mutex: pthread_mutex_t diff --git a/submodules/MediaPlayer/Sources/FFMpegMediaFrameSourceContext.swift b/submodules/MediaPlayer/Sources/FFMpegMediaFrameSourceContext.swift index c37daadb40..af0ff9cdbf 100644 --- a/submodules/MediaPlayer/Sources/FFMpegMediaFrameSourceContext.swift +++ b/submodules/MediaPlayer/Sources/FFMpegMediaFrameSourceContext.swift @@ -3,6 +3,7 @@ import SwiftSignalKit import Postbox import CoreMedia import TelegramCore +import SyncCore import FFMpeg private struct StreamContext { diff --git a/submodules/MediaPlayer/Sources/MediaPlayer.swift b/submodules/MediaPlayer/Sources/MediaPlayer.swift index c140c9a3e9..d57c7d5366 100644 --- a/submodules/MediaPlayer/Sources/MediaPlayer.swift +++ b/submodules/MediaPlayer/Sources/MediaPlayer.swift @@ -4,6 +4,7 @@ import SwiftSignalKit import Postbox import CoreMedia import TelegramCore +import SyncCore import TelegramAudio private let traceEvents = false diff --git a/submodules/MediaPlayer/Sources/MediaPlayerAudioRenderer.swift b/submodules/MediaPlayer/Sources/MediaPlayerAudioRenderer.swift index 6907a27417..0ebf04d0e8 100644 --- a/submodules/MediaPlayer/Sources/MediaPlayerAudioRenderer.swift +++ b/submodules/MediaPlayer/Sources/MediaPlayerAudioRenderer.swift @@ -3,6 +3,7 @@ import SwiftSignalKit import CoreMedia import AVFoundation import TelegramCore +import SyncCore import TelegramAudio private enum AudioPlayerRendererState { diff --git a/submodules/MediaPlayer/Sources/MediaPlayerFramePreview.swift b/submodules/MediaPlayer/Sources/MediaPlayerFramePreview.swift index fd06ca9fdb..9bc5edcaa8 100644 --- a/submodules/MediaPlayer/Sources/MediaPlayerFramePreview.swift +++ b/submodules/MediaPlayer/Sources/MediaPlayerFramePreview.swift @@ -2,6 +2,7 @@ import Foundation import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import FFMpeg private final class FramePreviewContext { diff --git a/submodules/MediaPlayer/Sources/UniversalSoftwareVideoSource.swift b/submodules/MediaPlayer/Sources/UniversalSoftwareVideoSource.swift index e688160779..fdaa4d1b8e 100644 --- a/submodules/MediaPlayer/Sources/UniversalSoftwareVideoSource.swift +++ b/submodules/MediaPlayer/Sources/UniversalSoftwareVideoSource.swift @@ -2,6 +2,7 @@ import Foundation import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import FFMpeg private func readPacketCallback(userData: UnsafeMutableRawPointer?, buffer: UnsafeMutablePointer?, bufferSize: Int32) -> Int32 { diff --git a/submodules/MediaResources/BUCK b/submodules/MediaResources/BUCK index 241434ac98..5d75f42e63 100644 --- a/submodules/MediaResources/BUCK +++ b/submodules/MediaResources/BUCK @@ -7,6 +7,7 @@ static_library( ]), deps = [ "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/Postbox:Postbox#shared", "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", ], diff --git a/submodules/MediaResources/Sources/MapResources.swift b/submodules/MediaResources/Sources/MapResources.swift index 53ee7e3213..b0991ec29d 100644 --- a/submodules/MediaResources/Sources/MapResources.swift +++ b/submodules/MediaResources/Sources/MapResources.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import MapKit import SwiftSignalKit diff --git a/submodules/MessageReactionListUI/BUCK b/submodules/MessageReactionListUI/BUCK index ac7c739abf..3543f9575f 100644 --- a/submodules/MessageReactionListUI/BUCK +++ b/submodules/MessageReactionListUI/BUCK @@ -8,6 +8,7 @@ static_library( deps = [ "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/Postbox:Postbox#shared", "//submodules/AsyncDisplayKit:AsyncDisplayKit#shared", "//submodules/Display:Display#shared", diff --git a/submodules/MessageReactionListUI/Sources/MessageReactionCategoryNode.swift b/submodules/MessageReactionListUI/Sources/MessageReactionCategoryNode.swift index 379ef364c6..a71caccd9c 100644 --- a/submodules/MessageReactionListUI/Sources/MessageReactionCategoryNode.swift +++ b/submodules/MessageReactionListUI/Sources/MessageReactionCategoryNode.swift @@ -3,6 +3,7 @@ import AsyncDisplayKit import Display import TelegramPresentationData import TelegramCore +import SyncCore final class MessageReactionCategoryNode: ASDisplayNode { let category: MessageReactionListCategory diff --git a/submodules/MessageReactionListUI/Sources/MessageReactionListController.swift b/submodules/MessageReactionListUI/Sources/MessageReactionListController.swift index 40c7c8063d..5cdc3a252a 100644 --- a/submodules/MessageReactionListUI/Sources/MessageReactionListController.swift +++ b/submodules/MessageReactionListUI/Sources/MessageReactionListController.swift @@ -4,6 +4,7 @@ import AccountContext import TelegramPresentationData import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import MergeLists import ItemListPeerItem diff --git a/submodules/MessageReactionListUI/Sources/MessageReactionListLoadingPlaceholder.swift b/submodules/MessageReactionListUI/Sources/MessageReactionListLoadingPlaceholder.swift index 676947eb9c..7c5eebf198 100644 --- a/submodules/MessageReactionListUI/Sources/MessageReactionListLoadingPlaceholder.swift +++ b/submodules/MessageReactionListUI/Sources/MessageReactionListLoadingPlaceholder.swift @@ -3,6 +3,7 @@ import AsyncDisplayKit import Display import TelegramPresentationData import TelegramCore +import SyncCore final class MessageReactionListLoadingPlaceholder: ASDisplayNode { private let theme: PresentationTheme diff --git a/submodules/MusicAlbumArtResources/BUCK b/submodules/MusicAlbumArtResources/BUCK index a629cbb528..2fd400400c 100644 --- a/submodules/MusicAlbumArtResources/BUCK +++ b/submodules/MusicAlbumArtResources/BUCK @@ -7,6 +7,7 @@ static_library( ]), deps = [ "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/Postbox:Postbox#shared", "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/UrlEscaping:UrlEscaping", diff --git a/submodules/MusicAlbumArtResources/Sources/ExternalMusicAlbumArtResources.swift b/submodules/MusicAlbumArtResources/Sources/ExternalMusicAlbumArtResources.swift index 73c59244d7..81e63879cc 100644 --- a/submodules/MusicAlbumArtResources/Sources/ExternalMusicAlbumArtResources.swift +++ b/submodules/MusicAlbumArtResources/Sources/ExternalMusicAlbumArtResources.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import UrlEscaping diff --git a/submodules/NotificationMuteSettingsUI/BUCK b/submodules/NotificationMuteSettingsUI/BUCK index d6fbaed0d6..bf51c73ceb 100644 --- a/submodules/NotificationMuteSettingsUI/BUCK +++ b/submodules/NotificationMuteSettingsUI/BUCK @@ -9,6 +9,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/TelegramStringFormatting:TelegramStringFormatting", ], diff --git a/submodules/NotificationMuteSettingsUI/Sources/NotificationMuteSettingsController.swift b/submodules/NotificationMuteSettingsUI/Sources/NotificationMuteSettingsController.swift index e3a06112e3..513c4319c9 100644 --- a/submodules/NotificationMuteSettingsUI/Sources/NotificationMuteSettingsController.swift +++ b/submodules/NotificationMuteSettingsUI/Sources/NotificationMuteSettingsController.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import TelegramStringFormatting diff --git a/submodules/NotificationSoundSelectionUI/BUCK b/submodules/NotificationSoundSelectionUI/BUCK index 89ed604125..74a73a3abd 100644 --- a/submodules/NotificationSoundSelectionUI/BUCK +++ b/submodules/NotificationSoundSelectionUI/BUCK @@ -10,6 +10,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/ItemListUI:ItemListUI", "//submodules/AccountContext:AccountContext", diff --git a/submodules/NotificationSoundSelectionUI/Sources/NotificationSoundSelection.swift b/submodules/NotificationSoundSelectionUI/Sources/NotificationSoundSelection.swift index 99ab202e06..e63fab7609 100644 --- a/submodules/NotificationSoundSelectionUI/Sources/NotificationSoundSelection.swift +++ b/submodules/NotificationSoundSelectionUI/Sources/NotificationSoundSelection.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import AVFoundation import TelegramPresentationData import ItemListUI diff --git a/submodules/OpenInExternalAppUI/BUCK b/submodules/OpenInExternalAppUI/BUCK index 6022b3bef3..a1dc0b605c 100644 --- a/submodules/OpenInExternalAppUI/BUCK +++ b/submodules/OpenInExternalAppUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/AccountContext:AccountContext", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/PhotoResources:PhotoResources", diff --git a/submodules/OpenInExternalAppUI/Sources/OpenInActionSheetController.swift b/submodules/OpenInExternalAppUI/Sources/OpenInActionSheetController.swift index 900de7cdab..cbb3711de7 100644 --- a/submodules/OpenInExternalAppUI/Sources/OpenInActionSheetController.swift +++ b/submodules/OpenInExternalAppUI/Sources/OpenInActionSheetController.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import MapKit import TelegramPresentationData import AccountContext diff --git a/submodules/OpenInExternalAppUI/Sources/OpenInAppIconResources.swift b/submodules/OpenInExternalAppUI/Sources/OpenInAppIconResources.swift index 4c5379f68c..32f419a522 100644 --- a/submodules/OpenInExternalAppUI/Sources/OpenInAppIconResources.swift +++ b/submodules/OpenInExternalAppUI/Sources/OpenInAppIconResources.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox diff --git a/submodules/OpenInExternalAppUI/Sources/OpenInOptions.swift b/submodules/OpenInExternalAppUI/Sources/OpenInOptions.swift index d9e5e04781..ccb3e9b0c3 100644 --- a/submodules/OpenInExternalAppUI/Sources/OpenInOptions.swift +++ b/submodules/OpenInExternalAppUI/Sources/OpenInOptions.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import CoreLocation import MapKit import AccountContext diff --git a/submodules/PasscodeUI/BUCK b/submodules/PasscodeUI/BUCK index 5dd70b8987..2421d5404e 100644 --- a/submodules/PasscodeUI/BUCK +++ b/submodules/PasscodeUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/TelegramUIPreferences:TelegramUIPreferences", "//submodules/AccountContext:AccountContext", diff --git a/submodules/PasscodeUI/Sources/PasscodeEntryControllerNode.swift b/submodules/PasscodeUI/Sources/PasscodeEntryControllerNode.swift index 445a8ffbb3..cded7a46ef 100644 --- a/submodules/PasscodeUI/Sources/PasscodeEntryControllerNode.swift +++ b/submodules/PasscodeUI/Sources/PasscodeEntryControllerNode.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import LocalAuth diff --git a/submodules/PasscodeUI/Sources/PasscodeSetupController.swift b/submodules/PasscodeUI/Sources/PasscodeSetupController.swift index a48258ee4f..b3c400ae9c 100644 --- a/submodules/PasscodeUI/Sources/PasscodeSetupController.swift +++ b/submodules/PasscodeUI/Sources/PasscodeSetupController.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/PasscodeUI/Sources/PasscodeSetupControllerNode.swift b/submodules/PasscodeUI/Sources/PasscodeSetupControllerNode.swift index 41ed465470..9a88badb0a 100644 --- a/submodules/PasscodeUI/Sources/PasscodeSetupControllerNode.swift +++ b/submodules/PasscodeUI/Sources/PasscodeSetupControllerNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import TelegramPresentationData import PasscodeInputFieldNode diff --git a/submodules/PassportUI/BUCK b/submodules/PassportUI/BUCK index 501d94dbc1..a6d147e4f9 100644 --- a/submodules/PassportUI/BUCK +++ b/submodules/PassportUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/PhoneInputNode:PhoneInputNode", "//submodules/CountrySelectionUI:CountrySelectionUI", diff --git a/submodules/PassportUI/Sources/FindSecureIdValue.swift b/submodules/PassportUI/Sources/FindSecureIdValue.swift index fbda63988a..7580149f6c 100644 --- a/submodules/PassportUI/Sources/FindSecureIdValue.swift +++ b/submodules/PassportUI/Sources/FindSecureIdValue.swift @@ -1,5 +1,6 @@ import Foundation import TelegramCore +import SyncCore func findValue(_ values: [SecureIdValueWithContext], key: SecureIdValueKey) -> (Int, SecureIdValueWithContext)? { for i in 0 ..< values.count { diff --git a/submodules/PassportUI/Sources/Form/FormController.swift b/submodules/PassportUI/Sources/Form/FormController.swift index d4cf7ff378..d0ce8c2905 100644 --- a/submodules/PassportUI/Sources/Form/FormController.swift +++ b/submodules/PassportUI/Sources/Form/FormController.swift @@ -4,6 +4,7 @@ import SwiftSignalKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import TelegramPresentationData public class FormController>: ViewController { diff --git a/submodules/PassportUI/Sources/Form/FormControllerNode.swift b/submodules/PassportUI/Sources/Form/FormControllerNode.swift index cd76c108eb..9d47a6f95a 100644 --- a/submodules/PassportUI/Sources/Form/FormControllerNode.swift +++ b/submodules/PassportUI/Sources/Form/FormControllerNode.swift @@ -4,6 +4,7 @@ import SwiftSignalKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import TelegramPresentationData private func hasFirstResponder(_ view: UIView) -> Bool { diff --git a/submodules/PassportUI/Sources/LegacySecureIdAttachmentMenu.swift b/submodules/PassportUI/Sources/LegacySecureIdAttachmentMenu.swift index 47b6cd3395..eff3936045 100644 --- a/submodules/PassportUI/Sources/LegacySecureIdAttachmentMenu.swift +++ b/submodules/PassportUI/Sources/LegacySecureIdAttachmentMenu.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import OverlayStatusController import AccountContext import LegacyUI diff --git a/submodules/PassportUI/Sources/SecureIdAuthAcceptNode.swift b/submodules/PassportUI/Sources/SecureIdAuthAcceptNode.swift index 9d10b38dc3..4ea08bef1c 100644 --- a/submodules/PassportUI/Sources/SecureIdAuthAcceptNode.swift +++ b/submodules/PassportUI/Sources/SecureIdAuthAcceptNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AppBundle diff --git a/submodules/PassportUI/Sources/SecureIdAuthController.swift b/submodules/PassportUI/Sources/SecureIdAuthController.swift index 15f157859f..a21449e859 100644 --- a/submodules/PassportUI/Sources/SecureIdAuthController.swift +++ b/submodules/PassportUI/Sources/SecureIdAuthController.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TextFormat import ProgressNavigationButtonNode diff --git a/submodules/PassportUI/Sources/SecureIdAuthControllerNode.swift b/submodules/PassportUI/Sources/SecureIdAuthControllerNode.swift index e376edf4fd..56a4f4086c 100644 --- a/submodules/PassportUI/Sources/SecureIdAuthControllerNode.swift +++ b/submodules/PassportUI/Sources/SecureIdAuthControllerNode.swift @@ -5,6 +5,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ActivityIndicator diff --git a/submodules/PassportUI/Sources/SecureIdAuthControllerState.swift b/submodules/PassportUI/Sources/SecureIdAuthControllerState.swift index 632a2de9bb..ba9a0ab8fa 100644 --- a/submodules/PassportUI/Sources/SecureIdAuthControllerState.swift +++ b/submodules/PassportUI/Sources/SecureIdAuthControllerState.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore struct SecureIdEncryptedFormData { let form: EncryptedSecureIdForm diff --git a/submodules/PassportUI/Sources/SecureIdAuthFormContentNode.swift b/submodules/PassportUI/Sources/SecureIdAuthFormContentNode.swift index 5967f0cd7d..12203600c2 100644 --- a/submodules/PassportUI/Sources/SecureIdAuthFormContentNode.swift +++ b/submodules/PassportUI/Sources/SecureIdAuthFormContentNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import TextFormat diff --git a/submodules/PassportUI/Sources/SecureIdAuthFormFieldNode.swift b/submodules/PassportUI/Sources/SecureIdAuthFormFieldNode.swift index d8d768ce73..fffaf5df94 100644 --- a/submodules/PassportUI/Sources/SecureIdAuthFormFieldNode.swift +++ b/submodules/PassportUI/Sources/SecureIdAuthFormFieldNode.swift @@ -4,6 +4,7 @@ import SwiftSignalKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import TelegramPresentationData import TelegramStringFormatting import CountrySelectionUI diff --git a/submodules/PassportUI/Sources/SecureIdAuthHeaderNode.swift b/submodules/PassportUI/Sources/SecureIdAuthHeaderNode.swift index 571720da8a..99230ac2b0 100644 --- a/submodules/PassportUI/Sources/SecureIdAuthHeaderNode.swift +++ b/submodules/PassportUI/Sources/SecureIdAuthHeaderNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/PassportUI/Sources/SecureIdAuthListContentNode.swift b/submodules/PassportUI/Sources/SecureIdAuthListContentNode.swift index 5dc349a96d..a6d4df8bc6 100644 --- a/submodules/PassportUI/Sources/SecureIdAuthListContentNode.swift +++ b/submodules/PassportUI/Sources/SecureIdAuthListContentNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData final class SecureIdAuthListContentNode: ASDisplayNode, SecureIdAuthContentNode, UITextFieldDelegate { diff --git a/submodules/PassportUI/Sources/SecureIdAuthListFieldNode.swift b/submodules/PassportUI/Sources/SecureIdAuthListFieldNode.swift index c6fa7f6c8b..d84fc5facc 100644 --- a/submodules/PassportUI/Sources/SecureIdAuthListFieldNode.swift +++ b/submodules/PassportUI/Sources/SecureIdAuthListFieldNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import TelegramPresentationData import PhoneNumberFormat diff --git a/submodules/PassportUI/Sources/SecureIdDocumentFormController.swift b/submodules/PassportUI/Sources/SecureIdDocumentFormController.swift index 1cd73e5d88..36889bccac 100644 --- a/submodules/PassportUI/Sources/SecureIdDocumentFormController.swift +++ b/submodules/PassportUI/Sources/SecureIdDocumentFormController.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ProgressNavigationButtonNode import AccountContext diff --git a/submodules/PassportUI/Sources/SecureIdDocumentFormControllerNode.swift b/submodules/PassportUI/Sources/SecureIdDocumentFormControllerNode.swift index 482860b7a5..e2b30260c5 100644 --- a/submodules/PassportUI/Sources/SecureIdDocumentFormControllerNode.swift +++ b/submodules/PassportUI/Sources/SecureIdDocumentFormControllerNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/PassportUI/Sources/SecureIdDocumentGalleryController.swift b/submodules/PassportUI/Sources/SecureIdDocumentGalleryController.swift index 2906c943d9..d8a06b4494 100644 --- a/submodules/PassportUI/Sources/SecureIdDocumentGalleryController.swift +++ b/submodules/PassportUI/Sources/SecureIdDocumentGalleryController.swift @@ -6,6 +6,7 @@ import Postbox import SwiftSignalKit import AsyncDisplayKit import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import GalleryUI diff --git a/submodules/PassportUI/Sources/SecureIdDocumentGalleryFooterContentNode.swift b/submodules/PassportUI/Sources/SecureIdDocumentGalleryFooterContentNode.swift index 94aa3f5fa9..b6a15328d3 100644 --- a/submodules/PassportUI/Sources/SecureIdDocumentGalleryFooterContentNode.swift +++ b/submodules/PassportUI/Sources/SecureIdDocumentGalleryFooterContentNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Photos import TelegramPresentationData diff --git a/submodules/PassportUI/Sources/SecureIdDocumentImageGalleryItem.swift b/submodules/PassportUI/Sources/SecureIdDocumentImageGalleryItem.swift index ea0b3898b9..4ceaa45422 100644 --- a/submodules/PassportUI/Sources/SecureIdDocumentImageGalleryItem.swift +++ b/submodules/PassportUI/Sources/SecureIdDocumentImageGalleryItem.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import PhotoResources diff --git a/submodules/PassportUI/Sources/SecureIdDocumentTypeSelectionController.swift b/submodules/PassportUI/Sources/SecureIdDocumentTypeSelectionController.swift index 54d741cc95..ba7ffea302 100644 --- a/submodules/PassportUI/Sources/SecureIdDocumentTypeSelectionController.swift +++ b/submodules/PassportUI/Sources/SecureIdDocumentTypeSelectionController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext diff --git a/submodules/PassportUI/Sources/SecureIdLocalResource.swift b/submodules/PassportUI/Sources/SecureIdLocalResource.swift index dfb8a8ffce..4df088ab91 100644 --- a/submodules/PassportUI/Sources/SecureIdLocalResource.swift +++ b/submodules/PassportUI/Sources/SecureIdLocalResource.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Display diff --git a/submodules/PassportUI/Sources/SecureIdPlaintextFormController.swift b/submodules/PassportUI/Sources/SecureIdPlaintextFormController.swift index d0513fa16a..4e70b7aecc 100644 --- a/submodules/PassportUI/Sources/SecureIdPlaintextFormController.swift +++ b/submodules/PassportUI/Sources/SecureIdPlaintextFormController.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ProgressNavigationButtonNode import AccountContext diff --git a/submodules/PassportUI/Sources/SecureIdPlaintextFormControllerNode.swift b/submodules/PassportUI/Sources/SecureIdPlaintextFormControllerNode.swift index 4a30d58b84..bd1d58641a 100644 --- a/submodules/PassportUI/Sources/SecureIdPlaintextFormControllerNode.swift +++ b/submodules/PassportUI/Sources/SecureIdPlaintextFormControllerNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import CoreTelephony diff --git a/submodules/PassportUI/Sources/SecureIdValueFormFileItem.swift b/submodules/PassportUI/Sources/SecureIdValueFormFileItem.swift index 1028f65a84..4759c97acd 100644 --- a/submodules/PassportUI/Sources/SecureIdValueFormFileItem.swift +++ b/submodules/PassportUI/Sources/SecureIdValueFormFileItem.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/PassportUI/Sources/SecureIdValueFormPhoneItem.swift b/submodules/PassportUI/Sources/SecureIdValueFormPhoneItem.swift index 51487c8ab3..0d327ce953 100644 --- a/submodules/PassportUI/Sources/SecureIdValueFormPhoneItem.swift +++ b/submodules/PassportUI/Sources/SecureIdValueFormPhoneItem.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import TelegramPresentationData import PhoneInputNode diff --git a/submodules/PassportUI/Sources/SecureIdValues.swift b/submodules/PassportUI/Sources/SecureIdValues.swift index e3305225e7..ce13a43436 100644 --- a/submodules/PassportUI/Sources/SecureIdValues.swift +++ b/submodules/PassportUI/Sources/SecureIdValues.swift @@ -1,5 +1,6 @@ import Foundation import TelegramCore +import SyncCore private let dateFormatter: DateFormatter = { let formatter = DateFormatter() diff --git a/submodules/PassportUI/Sources/SecureIdVerificationDocument.swift b/submodules/PassportUI/Sources/SecureIdVerificationDocument.swift index ca8dafca8d..377ed144b5 100644 --- a/submodules/PassportUI/Sources/SecureIdVerificationDocument.swift +++ b/submodules/PassportUI/Sources/SecureIdVerificationDocument.swift @@ -1,5 +1,6 @@ import Foundation import TelegramCore +import SyncCore enum SecureIdVerificationLocalDocumentState: Equatable { case uploading(Float) diff --git a/submodules/PassportUI/Sources/SecureIdVerificationDocumentsContext.swift b/submodules/PassportUI/Sources/SecureIdVerificationDocumentsContext.swift index 9e60e8f3ff..3d585b6d32 100644 --- a/submodules/PassportUI/Sources/SecureIdVerificationDocumentsContext.swift +++ b/submodules/PassportUI/Sources/SecureIdVerificationDocumentsContext.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit private final class DocumentContext { diff --git a/submodules/PasswordSetupUI/BUCK b/submodules/PasswordSetupUI/BUCK index 4b8336b73c..d909adc847 100644 --- a/submodules/PasswordSetupUI/BUCK +++ b/submodules/PasswordSetupUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/AccountContext:AccountContext", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/ProgressNavigationButtonNode:ProgressNavigationButtonNode", diff --git a/submodules/PasswordSetupUI/Sources/ResetPasswordController.swift b/submodules/PasswordSetupUI/Sources/ResetPasswordController.swift index f8b43dd9bd..0f4ef4efa5 100644 --- a/submodules/PasswordSetupUI/Sources/ResetPasswordController.swift +++ b/submodules/PasswordSetupUI/Sources/ResetPasswordController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/PasswordSetupUI/Sources/SetupTwoStepVerificationController.swift b/submodules/PasswordSetupUI/Sources/SetupTwoStepVerificationController.swift index 00dae42d8c..9760ad783d 100644 --- a/submodules/PasswordSetupUI/Sources/SetupTwoStepVerificationController.swift +++ b/submodules/PasswordSetupUI/Sources/SetupTwoStepVerificationController.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import Postbox import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import ProgressNavigationButtonNode import AccountContext diff --git a/submodules/PasswordSetupUI/Sources/SetupTwoStepVerificationControllerNode.swift b/submodules/PasswordSetupUI/Sources/SetupTwoStepVerificationControllerNode.swift index 2bc9da7259..77cbe23d0e 100644 --- a/submodules/PasswordSetupUI/Sources/SetupTwoStepVerificationControllerNode.swift +++ b/submodules/PasswordSetupUI/Sources/SetupTwoStepVerificationControllerNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import ActivityIndicator diff --git a/submodules/PeerAvatarGalleryUI/BUCK b/submodules/PeerAvatarGalleryUI/BUCK index 7952073484..bde6746427 100644 --- a/submodules/PeerAvatarGalleryUI/BUCK +++ b/submodules/PeerAvatarGalleryUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/AccountContext:AccountContext", "//submodules/GalleryUI:GalleryUI", diff --git a/submodules/PeerAvatarGalleryUI/Sources/AvatarGalleryController.swift b/submodules/PeerAvatarGalleryUI/Sources/AvatarGalleryController.swift index 3a1680e3ae..f86fb99565 100644 --- a/submodules/PeerAvatarGalleryUI/Sources/AvatarGalleryController.swift +++ b/submodules/PeerAvatarGalleryUI/Sources/AvatarGalleryController.swift @@ -6,6 +6,7 @@ import Postbox import SwiftSignalKit import AsyncDisplayKit import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import GalleryUI diff --git a/submodules/PeerAvatarGalleryUI/Sources/AvatarGalleryItemFooterContentNode.swift b/submodules/PeerAvatarGalleryUI/Sources/AvatarGalleryItemFooterContentNode.swift index 9c7f0e144b..38d9658a65 100644 --- a/submodules/PeerAvatarGalleryUI/Sources/AvatarGalleryItemFooterContentNode.swift +++ b/submodules/PeerAvatarGalleryUI/Sources/AvatarGalleryItemFooterContentNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Photos import TelegramPresentationData diff --git a/submodules/PeerAvatarGalleryUI/Sources/PeerAvatarImageGalleryItem.swift b/submodules/PeerAvatarGalleryUI/Sources/PeerAvatarImageGalleryItem.swift index ba92495f16..2685325ddf 100644 --- a/submodules/PeerAvatarGalleryUI/Sources/PeerAvatarImageGalleryItem.swift +++ b/submodules/PeerAvatarGalleryUI/Sources/PeerAvatarImageGalleryItem.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import RadialStatusNode diff --git a/submodules/PeerInfoUI/BUCK b/submodules/PeerInfoUI/BUCK index 88d33f9dfb..8445b1bd3c 100644 --- a/submodules/PeerInfoUI/BUCK +++ b/submodules/PeerInfoUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/AccountContext:AccountContext", "//submodules/ItemListUI:ItemListUI", diff --git a/submodules/PeerInfoUI/Sources/ChannelAdminController.swift b/submodules/PeerInfoUI/Sources/ChannelAdminController.swift index a3deb8e1ef..07c88ca4f0 100644 --- a/submodules/PeerInfoUI/Sources/ChannelAdminController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelAdminController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/PeerInfoUI/Sources/ChannelAdminsController.swift b/submodules/PeerInfoUI/Sources/ChannelAdminsController.swift index 97b01fd797..ffd3b14477 100644 --- a/submodules/PeerInfoUI/Sources/ChannelAdminsController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelAdminsController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/PeerInfoUI/Sources/ChannelBannedMemberController.swift b/submodules/PeerInfoUI/Sources/ChannelBannedMemberController.swift index bc9de402e1..64c4f16894 100644 --- a/submodules/PeerInfoUI/Sources/ChannelBannedMemberController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelBannedMemberController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/PeerInfoUI/Sources/ChannelBlacklistController.swift b/submodules/PeerInfoUI/Sources/ChannelBlacklistController.swift index 5556660874..f4e88773b3 100644 --- a/submodules/PeerInfoUI/Sources/ChannelBlacklistController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelBlacklistController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupActionSheetItem.swift b/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupActionSheetItem.swift index 647a42b430..b1ce5b4439 100644 --- a/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupActionSheetItem.swift +++ b/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupActionSheetItem.swift @@ -5,6 +5,7 @@ import UIKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import AvatarNode diff --git a/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSearchContainerNode.swift b/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSearchContainerNode.swift index 02bdb288ac..bff381d31e 100644 --- a/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSearchContainerNode.swift +++ b/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSearchContainerNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import MergeLists diff --git a/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupController.swift b/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupController.swift index 028cf34979..495180435f 100644 --- a/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupSearchItem.swift b/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupSearchItem.swift index cdcda09c84..562102a2c4 100644 --- a/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupSearchItem.swift +++ b/submodules/PeerInfoUI/Sources/ChannelDiscussionGroupSetupSearchItem.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import ItemListUI diff --git a/submodules/PeerInfoUI/Sources/ChannelInfoController.swift b/submodules/PeerInfoUI/Sources/ChannelInfoController.swift index 70b6442e39..738c14c747 100644 --- a/submodules/PeerInfoUI/Sources/ChannelInfoController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelInfoController.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import LegacyComponents import TelegramPresentationData import ItemListUI diff --git a/submodules/PeerInfoUI/Sources/ChannelMembersController.swift b/submodules/PeerInfoUI/Sources/ChannelMembersController.swift index 51e617516a..a7b285875b 100644 --- a/submodules/PeerInfoUI/Sources/ChannelMembersController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelMembersController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/PeerInfoUI/Sources/ChannelMembersSearchContainerNode.swift b/submodules/PeerInfoUI/Sources/ChannelMembersSearchContainerNode.swift index 05967f1bed..2b1c511a72 100644 --- a/submodules/PeerInfoUI/Sources/ChannelMembersSearchContainerNode.swift +++ b/submodules/PeerInfoUI/Sources/ChannelMembersSearchContainerNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import MergeLists diff --git a/submodules/PeerInfoUI/Sources/ChannelMembersSearchController.swift b/submodules/PeerInfoUI/Sources/ChannelMembersSearchController.swift index c6817f423e..a9350d7aba 100644 --- a/submodules/PeerInfoUI/Sources/ChannelMembersSearchController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelMembersSearchController.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/PeerInfoUI/Sources/ChannelMembersSearchControllerNode.swift b/submodules/PeerInfoUI/Sources/ChannelMembersSearchControllerNode.swift index 3d3a760b68..4eaa0adcad 100644 --- a/submodules/PeerInfoUI/Sources/ChannelMembersSearchControllerNode.swift +++ b/submodules/PeerInfoUI/Sources/ChannelMembersSearchControllerNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/PeerInfoUI/Sources/ChannelOwnershipTransferController.swift b/submodules/PeerInfoUI/Sources/ChannelOwnershipTransferController.swift index 9f088b255a..900cfc8abc 100644 --- a/submodules/PeerInfoUI/Sources/ChannelOwnershipTransferController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelOwnershipTransferController.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ActivityIndicator import TextFormat diff --git a/submodules/PeerInfoUI/Sources/ChannelPermissionsController.swift b/submodules/PeerInfoUI/Sources/ChannelPermissionsController.swift index fea31f8d5f..48e544fd06 100644 --- a/submodules/PeerInfoUI/Sources/ChannelPermissionsController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelPermissionsController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/PeerInfoUI/Sources/ChannelStatsController.swift b/submodules/PeerInfoUI/Sources/ChannelStatsController.swift index 8dc6938a88..15982971b8 100644 --- a/submodules/PeerInfoUI/Sources/ChannelStatsController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelStatsController.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/PeerInfoUI/Sources/ChannelStatsControllerNode.swift b/submodules/PeerInfoUI/Sources/ChannelStatsControllerNode.swift index f4f12aad5e..4ebc8d4456 100644 --- a/submodules/PeerInfoUI/Sources/ChannelStatsControllerNode.swift +++ b/submodules/PeerInfoUI/Sources/ChannelStatsControllerNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import WebKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift b/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift index 0e337cc96e..64bb5a48fd 100644 --- a/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/PeerInfoUI/Sources/ChatSlowmodeItem.swift b/submodules/PeerInfoUI/Sources/ChatSlowmodeItem.swift index ece533eaea..e83f370365 100644 --- a/submodules/PeerInfoUI/Sources/ChatSlowmodeItem.swift +++ b/submodules/PeerInfoUI/Sources/ChatSlowmodeItem.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramUIPreferences import TelegramPresentationData import LegacyComponents diff --git a/submodules/PeerInfoUI/Sources/ConvertToSupergroupController.swift b/submodules/PeerInfoUI/Sources/ConvertToSupergroupController.swift index 135d19b19e..099dff3b95 100644 --- a/submodules/PeerInfoUI/Sources/ConvertToSupergroupController.swift +++ b/submodules/PeerInfoUI/Sources/ConvertToSupergroupController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/PeerInfoUI/Sources/DeviceContactInfoController.swift b/submodules/PeerInfoUI/Sources/DeviceContactInfoController.swift index e8b8ecb692..7225f52468 100644 --- a/submodules/PeerInfoUI/Sources/DeviceContactInfoController.swift +++ b/submodules/PeerInfoUI/Sources/DeviceContactInfoController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import MessageUI import TelegramPresentationData import ItemListUI diff --git a/submodules/PeerInfoUI/Sources/GroupInfoController.swift b/submodules/PeerInfoUI/Sources/GroupInfoController.swift index 01e9f90f7d..bdb0a057b6 100644 --- a/submodules/PeerInfoUI/Sources/GroupInfoController.swift +++ b/submodules/PeerInfoUI/Sources/GroupInfoController.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import LegacyComponents import TelegramPresentationData import SafariServices diff --git a/submodules/PeerInfoUI/Sources/GroupInfoSearchItem.swift b/submodules/PeerInfoUI/Sources/GroupInfoSearchItem.swift index ea6ab27fd2..072d4ef0a2 100644 --- a/submodules/PeerInfoUI/Sources/GroupInfoSearchItem.swift +++ b/submodules/PeerInfoUI/Sources/GroupInfoSearchItem.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import ItemListUI import PresentationDataUtils diff --git a/submodules/PeerInfoUI/Sources/GroupInfoSearchNavigationContentNode.swift b/submodules/PeerInfoUI/Sources/GroupInfoSearchNavigationContentNode.swift index a5b0dfb0e0..f9ad551e82 100644 --- a/submodules/PeerInfoUI/Sources/GroupInfoSearchNavigationContentNode.swift +++ b/submodules/PeerInfoUI/Sources/GroupInfoSearchNavigationContentNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/PeerInfoUI/Sources/GroupPreHistorySetupController.swift b/submodules/PeerInfoUI/Sources/GroupPreHistorySetupController.swift index 33b2192343..203081f8f8 100644 --- a/submodules/PeerInfoUI/Sources/GroupPreHistorySetupController.swift +++ b/submodules/PeerInfoUI/Sources/GroupPreHistorySetupController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/PeerInfoUI/Sources/GroupStickerPackCurrentItem.swift b/submodules/PeerInfoUI/Sources/GroupStickerPackCurrentItem.swift index 08b58c0231..135b7366b1 100644 --- a/submodules/PeerInfoUI/Sources/GroupStickerPackCurrentItem.swift +++ b/submodules/PeerInfoUI/Sources/GroupStickerPackCurrentItem.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/PeerInfoUI/Sources/GroupStickerPackSetupController.swift b/submodules/PeerInfoUI/Sources/GroupStickerPackSetupController.swift index 8171277302..da18984fc7 100644 --- a/submodules/PeerInfoUI/Sources/GroupStickerPackSetupController.swift +++ b/submodules/PeerInfoUI/Sources/GroupStickerPackSetupController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/PeerInfoUI/Sources/GroupsInCommonController.swift b/submodules/PeerInfoUI/Sources/GroupsInCommonController.swift index 987291d8c7..01c31ae65e 100644 --- a/submodules/PeerInfoUI/Sources/GroupsInCommonController.swift +++ b/submodules/PeerInfoUI/Sources/GroupsInCommonController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/PeerInfoUI/Sources/ItemListCallListItem.swift b/submodules/PeerInfoUI/Sources/ItemListCallListItem.swift index f4d46829d8..74c77fff71 100644 --- a/submodules/PeerInfoUI/Sources/ItemListCallListItem.swift +++ b/submodules/PeerInfoUI/Sources/ItemListCallListItem.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/PeerInfoUI/Sources/ItemListSecretChatKeyItem.swift b/submodules/PeerInfoUI/Sources/ItemListSecretChatKeyItem.swift index 25f800bc18..7482b7d33f 100644 --- a/submodules/PeerInfoUI/Sources/ItemListSecretChatKeyItem.swift +++ b/submodules/PeerInfoUI/Sources/ItemListSecretChatKeyItem.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/PeerInfoUI/Sources/PeerBanTimeoutController.swift b/submodules/PeerInfoUI/Sources/PeerBanTimeoutController.swift index be537f8d5a..d91a961fd7 100644 --- a/submodules/PeerInfoUI/Sources/PeerBanTimeoutController.swift +++ b/submodules/PeerInfoUI/Sources/PeerBanTimeoutController.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import UIKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import TelegramStringFormatting import AccountContext diff --git a/submodules/PeerInfoUI/Sources/PeerInfoController.swift b/submodules/PeerInfoUI/Sources/PeerInfoController.swift index c5792efe4b..f34ef9a845 100644 --- a/submodules/PeerInfoUI/Sources/PeerInfoController.swift +++ b/submodules/PeerInfoUI/Sources/PeerInfoController.swift @@ -4,6 +4,7 @@ import Display import Postbox import SwiftSignalKit import TelegramCore +import SyncCore import AccountContext public func peerInfoControllerImpl(context: AccountContext, peer: Peer, mode: PeerInfoControllerMode) -> ViewController? { diff --git a/submodules/PeerInfoUI/Sources/PeerReportController.swift b/submodules/PeerInfoUI/Sources/PeerReportController.swift index 835c709b74..4996d5fb91 100644 --- a/submodules/PeerInfoUI/Sources/PeerReportController.swift +++ b/submodules/PeerInfoUI/Sources/PeerReportController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/PeerInfoUI/Sources/PhoneLabelController.swift b/submodules/PeerInfoUI/Sources/PhoneLabelController.swift index d67f497052..ef3da80093 100644 --- a/submodules/PeerInfoUI/Sources/PhoneLabelController.swift +++ b/submodules/PeerInfoUI/Sources/PhoneLabelController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/PeerInfoUI/Sources/SecretChatKeyController.swift b/submodules/PeerInfoUI/Sources/SecretChatKeyController.swift index 6a10c006f6..baec51f9b6 100644 --- a/submodules/PeerInfoUI/Sources/SecretChatKeyController.swift +++ b/submodules/PeerInfoUI/Sources/SecretChatKeyController.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import AccountContext diff --git a/submodules/PeerInfoUI/Sources/SecretChatKeyControllerNode.swift b/submodules/PeerInfoUI/Sources/SecretChatKeyControllerNode.swift index f0c374bbd3..8c8fa3ec47 100644 --- a/submodules/PeerInfoUI/Sources/SecretChatKeyControllerNode.swift +++ b/submodules/PeerInfoUI/Sources/SecretChatKeyControllerNode.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import TextFormat diff --git a/submodules/PeerInfoUI/Sources/UserInfoController.swift b/submodules/PeerInfoUI/Sources/UserInfoController.swift index 4440da3e78..6664479ff8 100644 --- a/submodules/PeerInfoUI/Sources/UserInfoController.swift +++ b/submodules/PeerInfoUI/Sources/UserInfoController.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import LegacyComponents import TelegramPresentationData import ItemListUI diff --git a/submodules/PeerPresenceStatusManager/BUCK b/submodules/PeerPresenceStatusManager/BUCK index aab8a8561d..b7d0cf9134 100644 --- a/submodules/PeerPresenceStatusManager/BUCK +++ b/submodules/PeerPresenceStatusManager/BUCK @@ -9,6 +9,8 @@ static_library( "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", + "//submodules/SyncCore:SyncCore#shared", ], frameworks = [ "$SDKROOT/System/Library/Frameworks/Foundation.framework", diff --git a/submodules/PeerPresenceStatusManager/Sources/PeerPresenceStatusManager.swift b/submodules/PeerPresenceStatusManager/Sources/PeerPresenceStatusManager.swift index 0ec875e56f..af518befa8 100644 --- a/submodules/PeerPresenceStatusManager/Sources/PeerPresenceStatusManager.swift +++ b/submodules/PeerPresenceStatusManager/Sources/PeerPresenceStatusManager.swift @@ -1,6 +1,8 @@ import Foundation import SwiftSignalKit import TelegramCore +import SyncCore +import SyncCore private func suggestedUserPresenceStringRefreshTimeout(_ presence: TelegramUserPresence, relativeTo timestamp: Int32) -> Double { switch presence.status { diff --git a/submodules/PeersNearbyUI/BUCK b/submodules/PeersNearbyUI/BUCK index 36d45a0cf8..5a6ca7965b 100644 --- a/submodules/PeersNearbyUI/BUCK +++ b/submodules/PeersNearbyUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/AccountContext:AccountContext", "//submodules/TelegramUIPreferences:TelegramUIPreferences", diff --git a/submodules/PeersNearbyUI/Sources/PeersNearbyController.swift b/submodules/PeersNearbyUI/Sources/PeersNearbyController.swift index b34045e909..d5dfe4cf05 100644 --- a/submodules/PeersNearbyUI/Sources/PeersNearbyController.swift +++ b/submodules/PeersNearbyUI/Sources/PeersNearbyController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import MapKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/PhotoResources/BUCK b/submodules/PhotoResources/BUCK index 6629d4dcae..488bc20353 100644 --- a/submodules/PhotoResources/BUCK +++ b/submodules/PhotoResources/BUCK @@ -7,6 +7,7 @@ static_library( ]), deps = [ "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/Postbox:Postbox#shared", "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Display:Display#shared", diff --git a/submodules/PhotoResources/Sources/PhotoResources.swift b/submodules/PhotoResources/Sources/PhotoResources.swift index 48284577ce..12906f7b03 100644 --- a/submodules/PhotoResources/Sources/PhotoResources.swift +++ b/submodules/PhotoResources/Sources/PhotoResources.swift @@ -6,6 +6,7 @@ import Display import AVFoundation import ImageIO import TelegramCore +import SyncCore #if BUCK import WebPImage #else diff --git a/submodules/PlatformRestrictionMatching/BUCK b/submodules/PlatformRestrictionMatching/BUCK index be71f01fa0..312c7c4e29 100644 --- a/submodules/PlatformRestrictionMatching/BUCK +++ b/submodules/PlatformRestrictionMatching/BUCK @@ -6,7 +6,9 @@ static_library( "Sources/**/*.swift", ]), deps = [ - "//submodules/TelegramCore:TelegramCore#dynamic", + "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", + "//submodules/SyncCore:SyncCore#shared", ], frameworks = [ "$SDKROOT/System/Library/Frameworks/Foundation.framework", diff --git a/submodules/PlatformRestrictionMatching/Sources/PlatformRestrictionMatching.swift b/submodules/PlatformRestrictionMatching/Sources/PlatformRestrictionMatching.swift index ddd98ece53..3d36594562 100644 --- a/submodules/PlatformRestrictionMatching/Sources/PlatformRestrictionMatching.swift +++ b/submodules/PlatformRestrictionMatching/Sources/PlatformRestrictionMatching.swift @@ -1,5 +1,7 @@ import Foundation import TelegramCore +import SyncCore +import SyncCore public extension RestrictedContentMessageAttribute { func platformText(platform: String) -> String? { diff --git a/submodules/Postbox/Postbox/Postbox.swift b/submodules/Postbox/Postbox/Postbox.swift index ba0929d54f..bf8ce7f49a 100644 --- a/submodules/Postbox/Postbox/Postbox.swift +++ b/submodules/Postbox/Postbox/Postbox.swift @@ -42,6 +42,13 @@ public final class Transaction { } } + public func countIncomingMessage(id: MessageId) { + assert(!self.disposed) + if let postbox = self.postbox { + postbox.countIncomingMessage(id: id) + } + } + public func addHole(peerId: PeerId, namespace: MessageId.Namespace, space: MessageHistoryHoleSpace, range: ClosedRange) { assert(!self.disposed) self.postbox?.addHole(peerId: peerId, namespace: namespace, space: space, range: range) @@ -1481,6 +1488,16 @@ public final class Postbox { return addResult } + fileprivate func countIncomingMessage(id: MessageId) { + let (combinedState, _) = self.readStateTable.addIncomingMessages(id.peerId, indices: Set([MessageIndex(id: id, timestamp: 1)])) + if self.currentOperationsByPeerId[id.peerId] == nil { + self.currentOperationsByPeerId[id.peerId] = [] + } + if let combinedState = combinedState { + self.currentOperationsByPeerId[id.peerId]!.append(.UpdateReadState(id.peerId, combinedState)) + } + } + fileprivate func addHole(peerId: PeerId, namespace: MessageId.Namespace, space: MessageHistoryHoleSpace, range: ClosedRange) { self.messageHistoryHoleIndexTable.add(peerId: peerId, namespace: namespace, space: space, range: range, operations: &self.currentPeerHoleOperations) } diff --git a/submodules/RadialStatusNode/BUCK b/submodules/RadialStatusNode/BUCK index b1172e1bd2..c16bac1717 100644 --- a/submodules/RadialStatusNode/BUCK +++ b/submodules/RadialStatusNode/BUCK @@ -6,8 +6,8 @@ static_library( "Sources/**/*.swift", ]), deps = [ - "//submodules/Display:Display#dynamic", - "//submodules/AsyncDisplayKit:AsyncDisplayKit#dynamic", + "//submodules/Display:Display#shared", + "//submodules/AsyncDisplayKit:AsyncDisplayKit#shared", "//submodules/LegacyComponents:LegacyComponents", ], frameworks = [ diff --git a/submodules/ReactionSelectionNode/BUCK b/submodules/ReactionSelectionNode/BUCK index 64e82f82ba..2ba94127f9 100644 --- a/submodules/ReactionSelectionNode/BUCK +++ b/submodules/ReactionSelectionNode/BUCK @@ -8,6 +8,7 @@ static_library( deps = [ "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/AsyncDisplayKit:AsyncDisplayKit#shared", "//submodules/Display:Display#shared", "//submodules/AnimatedStickerNode:AnimatedStickerNode", diff --git a/submodules/ReactionSelectionNode/Sources/ReactionAttachedNode.swift b/submodules/ReactionSelectionNode/Sources/ReactionAttachedNode.swift index 02eda9cb31..4f99ad70bc 100644 --- a/submodules/ReactionSelectionNode/Sources/ReactionAttachedNode.swift +++ b/submodules/ReactionSelectionNode/Sources/ReactionAttachedNode.swift @@ -4,6 +4,7 @@ import AnimatedStickerNode import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AppBundle diff --git a/submodules/ReactionSelectionNode/Sources/ReactionContextNode.swift b/submodules/ReactionSelectionNode/Sources/ReactionContextNode.swift index e978592d51..427e712b6e 100644 --- a/submodules/ReactionSelectionNode/Sources/ReactionContextNode.swift +++ b/submodules/ReactionSelectionNode/Sources/ReactionContextNode.swift @@ -3,6 +3,7 @@ import AsyncDisplayKit import Display import AnimatedStickerNode import TelegramCore +import SyncCore import TelegramPresentationData public final class ReactionContextItem { diff --git a/submodules/ReactionSelectionNode/Sources/ReactionGestureItem.swift b/submodules/ReactionSelectionNode/Sources/ReactionGestureItem.swift index 9b058db8ca..65ae1c94ef 100644 --- a/submodules/ReactionSelectionNode/Sources/ReactionGestureItem.swift +++ b/submodules/ReactionSelectionNode/Sources/ReactionGestureItem.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore public enum ReactionGestureItem { case reaction(value: String, text: String, path: String) diff --git a/submodules/ReactionSelectionNode/Sources/ReactionSelectionNode.swift b/submodules/ReactionSelectionNode/Sources/ReactionSelectionNode.swift index 8ccd7e8373..eb64faf4c6 100644 --- a/submodules/ReactionSelectionNode/Sources/ReactionSelectionNode.swift +++ b/submodules/ReactionSelectionNode/Sources/ReactionSelectionNode.swift @@ -3,6 +3,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AppBundle import AnimatedStickerNode diff --git a/submodules/ReactionSelectionNode/Sources/ReactionSelectionParentNode.swift b/submodules/ReactionSelectionNode/Sources/ReactionSelectionParentNode.swift index 8290a9a4b1..66a7128362 100644 --- a/submodules/ReactionSelectionNode/Sources/ReactionSelectionParentNode.swift +++ b/submodules/ReactionSelectionNode/Sources/ReactionSelectionParentNode.swift @@ -3,6 +3,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData public final class ReactionSelectionParentNode: ASDisplayNode { diff --git a/submodules/SaveToCameraRoll/BUCK b/submodules/SaveToCameraRoll/BUCK index 8ddc060d1c..d594ecc651 100644 --- a/submodules/SaveToCameraRoll/BUCK +++ b/submodules/SaveToCameraRoll/BUCK @@ -9,6 +9,7 @@ static_library( "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/Display:Display#shared", "//submodules/AccountContext:AccountContext", "//submodules/DeviceAccess:DeviceAccess", diff --git a/submodules/SaveToCameraRoll/Sources/SaveToCameraRoll.swift b/submodules/SaveToCameraRoll/Sources/SaveToCameraRoll.swift index 3e273dceb7..a5c381ade1 100644 --- a/submodules/SaveToCameraRoll/Sources/SaveToCameraRoll.swift +++ b/submodules/SaveToCameraRoll/Sources/SaveToCameraRoll.swift @@ -3,6 +3,7 @@ import UIKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import Photos import Display import MobileCoreServices diff --git a/submodules/SearchPeerMembers/BUCK b/submodules/SearchPeerMembers/BUCK index 512cdc93c6..5c92914c2f 100644 --- a/submodules/SearchPeerMembers/BUCK +++ b/submodules/SearchPeerMembers/BUCK @@ -9,6 +9,7 @@ static_library( "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/AccountContext:AccountContext", ], frameworks = [ diff --git a/submodules/SearchPeerMembers/Sources/SearchPeerMembers.swift b/submodules/SearchPeerMembers/Sources/SearchPeerMembers.swift index b7284f6c45..6bf47f54c3 100644 --- a/submodules/SearchPeerMembers/Sources/SearchPeerMembers.swift +++ b/submodules/SearchPeerMembers/Sources/SearchPeerMembers.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import AccountContext diff --git a/submodules/SelectablePeerNode/BUCK b/submodules/SelectablePeerNode/BUCK index 2cfe2c97ea..f4bfc7b54b 100644 --- a/submodules/SelectablePeerNode/BUCK +++ b/submodules/SelectablePeerNode/BUCK @@ -9,6 +9,7 @@ static_library( "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/AsyncDisplayKit:AsyncDisplayKit#shared", "//submodules/Display:Display#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", diff --git a/submodules/SelectablePeerNode/Sources/SelectablePeerNode.swift b/submodules/SelectablePeerNode/Sources/SelectablePeerNode.swift index 6fa6314344..70204b0144 100644 --- a/submodules/SelectablePeerNode/Sources/SelectablePeerNode.swift +++ b/submodules/SelectablePeerNode/Sources/SelectablePeerNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AvatarNode diff --git a/submodules/SettingsUI/BUCK b/submodules/SettingsUI/BUCK index ec2009d1a0..46797f1273 100644 --- a/submodules/SettingsUI/BUCK +++ b/submodules/SettingsUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/MtProtoKit:MtProtoKit#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/AccountContext:AccountContext", diff --git a/submodules/SettingsUI/Sources/AccountUtils.swift b/submodules/SettingsUI/Sources/AccountUtils.swift index dea14726ec..a33713f992 100644 --- a/submodules/SettingsUI/Sources/AccountUtils.swift +++ b/submodules/SettingsUI/Sources/AccountUtils.swift @@ -2,6 +2,7 @@ import Foundation import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramUIPreferences import AccountContext diff --git a/submodules/SettingsUI/Sources/CachedFaqInstantPage.swift b/submodules/SettingsUI/Sources/CachedFaqInstantPage.swift index 5392fced23..0b0d265b76 100644 --- a/submodules/SettingsUI/Sources/CachedFaqInstantPage.swift +++ b/submodules/SettingsUI/Sources/CachedFaqInstantPage.swift @@ -2,6 +2,7 @@ import Foundation import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import AccountContext import InstantPageUI import InstantPageCache diff --git a/submodules/SettingsUI/Sources/ChangePhoneNumberCodeController.swift b/submodules/SettingsUI/Sources/ChangePhoneNumberCodeController.swift index f2d8e25091..eb8b98ef4a 100644 --- a/submodules/SettingsUI/Sources/ChangePhoneNumberCodeController.swift +++ b/submodules/SettingsUI/Sources/ChangePhoneNumberCodeController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/SettingsUI/Sources/ChangePhoneNumberController.swift b/submodules/SettingsUI/Sources/ChangePhoneNumberController.swift index 6a9262d96b..6d5e408235 100644 --- a/submodules/SettingsUI/Sources/ChangePhoneNumberController.swift +++ b/submodules/SettingsUI/Sources/ChangePhoneNumberController.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import ProgressNavigationButtonNode diff --git a/submodules/SettingsUI/Sources/ChangePhoneNumberControllerNode.swift b/submodules/SettingsUI/Sources/ChangePhoneNumberControllerNode.swift index 75a82714d1..05fdaaa7e7 100644 --- a/submodules/SettingsUI/Sources/ChangePhoneNumberControllerNode.swift +++ b/submodules/SettingsUI/Sources/ChangePhoneNumberControllerNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import CoreTelephony import TelegramPresentationData import PhoneInputNode diff --git a/submodules/SettingsUI/Sources/ChangePhoneNumberIntroController.swift b/submodules/SettingsUI/Sources/ChangePhoneNumberIntroController.swift index 11f0cfc946..b355085b82 100644 --- a/submodules/SettingsUI/Sources/ChangePhoneNumberIntroController.swift +++ b/submodules/SettingsUI/Sources/ChangePhoneNumberIntroController.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import TelegramPresentationData import TextFormat import AccountContext diff --git a/submodules/SettingsUI/Sources/Data and Storage/AutodownloadConnectionTypeController.swift b/submodules/SettingsUI/Sources/Data and Storage/AutodownloadConnectionTypeController.swift index 7f707bf109..39b3c1775c 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/AutodownloadConnectionTypeController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/AutodownloadConnectionTypeController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/Data and Storage/AutodownloadDataUsagePickerItem.swift b/submodules/SettingsUI/Sources/Data and Storage/AutodownloadDataUsagePickerItem.swift index 0904075772..531ae161d0 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/AutodownloadDataUsagePickerItem.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/AutodownloadDataUsagePickerItem.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramUIPreferences import TelegramPresentationData import LegacyComponents diff --git a/submodules/SettingsUI/Sources/Data and Storage/AutodownloadMediaCategoryController.swift b/submodules/SettingsUI/Sources/Data and Storage/AutodownloadMediaCategoryController.swift index c2e7578ab5..c506cb0b60 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/AutodownloadMediaCategoryController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/AutodownloadMediaCategoryController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/Data and Storage/AutodownloadSizeLimitItem.swift b/submodules/SettingsUI/Sources/Data and Storage/AutodownloadSizeLimitItem.swift index 9959e3e399..8640aab742 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/AutodownloadSizeLimitItem.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/AutodownloadSizeLimitItem.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import LegacyComponents import ItemListUI diff --git a/submodules/SettingsUI/Sources/Data and Storage/DataAndStorageSettingsController.swift b/submodules/SettingsUI/Sources/Data and Storage/DataAndStorageSettingsController.swift index a0787890f6..d0891a5404 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/DataAndStorageSettingsController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/DataAndStorageSettingsController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import LegacyComponents import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/SettingsUI/Sources/Data and Storage/NetworkUsageStatsController.swift b/submodules/SettingsUI/Sources/Data and Storage/NetworkUsageStatsController.swift index d87d11d041..841149016d 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/NetworkUsageStatsController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/NetworkUsageStatsController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/SettingsUI/Sources/Data and Storage/ProxyListSettingsController.swift b/submodules/SettingsUI/Sources/Data and Storage/ProxyListSettingsController.swift index 1ad4fb7e0e..b3728cb7eb 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/ProxyListSettingsController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/ProxyListSettingsController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData #if BUCK import MtProtoKit diff --git a/submodules/SettingsUI/Sources/Data and Storage/ProxyServerActionSheetController.swift b/submodules/SettingsUI/Sources/Data and Storage/ProxyServerActionSheetController.swift index 13e5c42928..4e1e356676 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/ProxyServerActionSheetController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/ProxyServerActionSheetController.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import Postbox import AsyncDisplayKit import UIKit diff --git a/submodules/SettingsUI/Sources/Data and Storage/ProxyServerSettingsController.swift b/submodules/SettingsUI/Sources/Data and Storage/ProxyServerSettingsController.swift index 491d6c4912..54b3fcaa95 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/ProxyServerSettingsController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/ProxyServerSettingsController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore #if BUCK import MtProtoKit #else diff --git a/submodules/SettingsUI/Sources/Data and Storage/ProxySettingsServerItem.swift b/submodules/SettingsUI/Sources/Data and Storage/ProxySettingsServerItem.swift index 5682236200..1813eafe7d 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/ProxySettingsServerItem.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/ProxySettingsServerItem.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/SettingsUI/Sources/Data and Storage/SaveIncomingMediaController.swift b/submodules/SettingsUI/Sources/Data and Storage/SaveIncomingMediaController.swift index 7ab84690e8..f0874558e7 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/SaveIncomingMediaController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/SaveIncomingMediaController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/Data and Storage/ShareProxyServerActionSheetController.swift b/submodules/SettingsUI/Sources/Data and Storage/ShareProxyServerActionSheetController.swift index 661de4500c..f5ba2a4277 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/ShareProxyServerActionSheetController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/ShareProxyServerActionSheetController.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import Postbox import AsyncDisplayKit import UIKit diff --git a/submodules/SettingsUI/Sources/Data and Storage/StorageUsageController.swift b/submodules/SettingsUI/Sources/Data and Storage/StorageUsageController.swift index a0f408ac7b..62f1cd7592 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/StorageUsageController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/StorageUsageController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/Data and Storage/VoiceCallDataSavingController.swift b/submodules/SettingsUI/Sources/Data and Storage/VoiceCallDataSavingController.swift index bd68ff4e66..2fc320cfbb 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/VoiceCallDataSavingController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/VoiceCallDataSavingController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/DebugAccountsController.swift b/submodules/SettingsUI/Sources/DebugAccountsController.swift index 067bcc95e4..1e525ff0a5 100644 --- a/submodules/SettingsUI/Sources/DebugAccountsController.swift +++ b/submodules/SettingsUI/Sources/DebugAccountsController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/SettingsUI/Sources/DebugController.swift b/submodules/SettingsUI/Sources/DebugController.swift index 0145fb2954..0f4d19d8c4 100644 --- a/submodules/SettingsUI/Sources/DebugController.swift +++ b/submodules/SettingsUI/Sources/DebugController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore #if BUCK import MtProtoKit #else diff --git a/submodules/SettingsUI/Sources/EditSettingsController.swift b/submodules/SettingsUI/Sources/EditSettingsController.swift index 43067aaa22..241761863a 100644 --- a/submodules/SettingsUI/Sources/EditSettingsController.swift +++ b/submodules/SettingsUI/Sources/EditSettingsController.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import LegacyComponents import TelegramPresentationData import ItemListUI diff --git a/submodules/SettingsUI/Sources/Language Selection/LocalizationListController.swift b/submodules/SettingsUI/Sources/Language Selection/LocalizationListController.swift index 9c8ba64a84..dfaca96c32 100644 --- a/submodules/SettingsUI/Sources/Language Selection/LocalizationListController.swift +++ b/submodules/SettingsUI/Sources/Language Selection/LocalizationListController.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import Postbox import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import SearchUI diff --git a/submodules/SettingsUI/Sources/Language Selection/LocalizationListControllerNode.swift b/submodules/SettingsUI/Sources/Language Selection/LocalizationListControllerNode.swift index 51e04c5344..0f2e2d931f 100644 --- a/submodules/SettingsUI/Sources/Language Selection/LocalizationListControllerNode.swift +++ b/submodules/SettingsUI/Sources/Language Selection/LocalizationListControllerNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import MergeLists diff --git a/submodules/SettingsUI/Sources/LogoutOptionsController.swift b/submodules/SettingsUI/Sources/LogoutOptionsController.swift index 63b633f971..4c1d21f9f3 100644 --- a/submodules/SettingsUI/Sources/LogoutOptionsController.swift +++ b/submodules/SettingsUI/Sources/LogoutOptionsController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import LegacyComponents import TelegramPresentationData import ItemListUI diff --git a/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionControllerNode.swift b/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionControllerNode.swift index 86274b8168..4401cee2c0 100644 --- a/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionControllerNode.swift +++ b/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionControllerNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionSettingsController.swift b/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionSettingsController.swift index 63339371fe..dec3d00836 100644 --- a/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionSettingsController.swift +++ b/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionSettingsController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import ItemListUI diff --git a/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptions.swift b/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptions.swift index 9ede887730..e56e371194 100644 --- a/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptions.swift +++ b/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptions.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import SearchUI diff --git a/submodules/SettingsUI/Sources/Notifications/NotificationsAndSounds.swift b/submodules/SettingsUI/Sources/Notifications/NotificationsAndSounds.swift index d6ff6d86f9..d808c93bb2 100644 --- a/submodules/SettingsUI/Sources/Notifications/NotificationsAndSounds.swift +++ b/submodules/SettingsUI/Sources/Notifications/NotificationsAndSounds.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import DeviceAccess diff --git a/submodules/SettingsUI/Sources/OpenSettings.swift b/submodules/SettingsUI/Sources/OpenSettings.swift index 2551f27d9d..39f0bed237 100644 --- a/submodules/SettingsUI/Sources/OpenSettings.swift +++ b/submodules/SettingsUI/Sources/OpenSettings.swift @@ -3,6 +3,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import OverlayStatusController import AccountContext diff --git a/submodules/SettingsUI/Sources/Privacy and Security/BlockedPeersController.swift b/submodules/SettingsUI/Sources/Privacy and Security/BlockedPeersController.swift index ee99ace770..3464fd0f3b 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/BlockedPeersController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/BlockedPeersController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/Privacy and Security/ConfirmPhoneNumberController.swift b/submodules/SettingsUI/Sources/Privacy and Security/ConfirmPhoneNumberController.swift index 099e5e0915..1b4c8bb18c 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/ConfirmPhoneNumberController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/ConfirmPhoneNumberController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/SettingsUI/Sources/Privacy and Security/CreatePasswordController.swift b/submodules/SettingsUI/Sources/Privacy and Security/CreatePasswordController.swift index 253e5b50af..539981eb97 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/CreatePasswordController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/CreatePasswordController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/SettingsUI/Sources/Privacy and Security/DataPrivacySettingsController.swift b/submodules/SettingsUI/Sources/Privacy and Security/DataPrivacySettingsController.swift index 81f05094c4..04e059923d 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/DataPrivacySettingsController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/DataPrivacySettingsController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/Privacy and Security/ForwardPrivacyChatPreviewItem.swift b/submodules/SettingsUI/Sources/Privacy and Security/ForwardPrivacyChatPreviewItem.swift index 8729d0abf0..adaf4a03a7 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/ForwardPrivacyChatPreviewItem.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/ForwardPrivacyChatPreviewItem.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/SettingsUI/Sources/Privacy and Security/PasscodeOptionsController.swift b/submodules/SettingsUI/Sources/Privacy and Security/PasscodeOptionsController.swift index 0f5a58b9ec..f0ec9fe268 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/PasscodeOptionsController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/PasscodeOptionsController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import LegacyComponents import LocalAuthentication import TelegramPresentationData diff --git a/submodules/SettingsUI/Sources/Privacy and Security/PrivacyAndSecurityController.swift b/submodules/SettingsUI/Sources/Privacy and Security/PrivacyAndSecurityController.swift index 9729967dc7..3fb813e6a3 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/PrivacyAndSecurityController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/PrivacyAndSecurityController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import TelegramCallsUI diff --git a/submodules/SettingsUI/Sources/Privacy and Security/PrivacyIntroController.swift b/submodules/SettingsUI/Sources/Privacy and Security/PrivacyIntroController.swift index 32f06761eb..ecf41810a2 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/PrivacyIntroController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/PrivacyIntroController.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import Postbox import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import AppBundle diff --git a/submodules/SettingsUI/Sources/Privacy and Security/PrivacyIntroControllerNode.swift b/submodules/SettingsUI/Sources/Privacy and Security/PrivacyIntroControllerNode.swift index c6ad09bdfd..08b4282688 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/PrivacyIntroControllerNode.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/PrivacyIntroControllerNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AccountContext diff --git a/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/ItemListRecentSessionItem.swift b/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/ItemListRecentSessionItem.swift index f47a9bb7ac..b5d3a63945 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/ItemListRecentSessionItem.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/ItemListRecentSessionItem.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/ItemListWebsiteItem.swift b/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/ItemListWebsiteItem.swift index 5fa6f037e7..9cc842ea72 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/ItemListWebsiteItem.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/ItemListWebsiteItem.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/RecentSessionsController.swift b/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/RecentSessionsController.swift index cb7423a2b5..7a94a462ef 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/RecentSessionsController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/RecentSessionsController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsController.swift b/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsController.swift index 1583b35cbf..8ab56b4298 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsPeersController.swift b/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsPeersController.swift index a510364b42..459fddb8f1 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsPeersController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsPeersController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/Privacy and Security/TwoStepVerificationPasswordEntryController.swift b/submodules/SettingsUI/Sources/Privacy and Security/TwoStepVerificationPasswordEntryController.swift index 9bf85f2222..c02f94bf8b 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/TwoStepVerificationPasswordEntryController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/TwoStepVerificationPasswordEntryController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/SettingsUI/Sources/Privacy and Security/TwoStepVerificationResetController.swift b/submodules/SettingsUI/Sources/Privacy and Security/TwoStepVerificationResetController.swift index 8d88e326b6..3aac1dcfb5 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/TwoStepVerificationResetController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/TwoStepVerificationResetController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/SettingsUI/Sources/Privacy and Security/TwoStepVerificationUnlockController.swift b/submodules/SettingsUI/Sources/Privacy and Security/TwoStepVerificationUnlockController.swift index dee7a2a88c..6c74094176 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/TwoStepVerificationUnlockController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/TwoStepVerificationUnlockController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/SettingsUI/Sources/Search/SettingsSearchItem.swift b/submodules/SettingsUI/Sources/Search/SettingsSearchItem.swift index 6d3ff1812a..929ebd35a0 100644 --- a/submodules/SettingsUI/Sources/Search/SettingsSearchItem.swift +++ b/submodules/SettingsUI/Sources/Search/SettingsSearchItem.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import MergeLists diff --git a/submodules/SettingsUI/Sources/Search/SettingsSearchRecentItem.swift b/submodules/SettingsUI/Sources/Search/SettingsSearchRecentItem.swift index 001a76624d..960d60eef8 100644 --- a/submodules/SettingsUI/Sources/Search/SettingsSearchRecentItem.swift +++ b/submodules/SettingsUI/Sources/Search/SettingsSearchRecentItem.swift @@ -5,6 +5,7 @@ import Postbox import Display import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift b/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift index b3242e5773..4c29c8fcd6 100644 --- a/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift +++ b/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramUIPreferences import TelegramCallsUI import OverlayStatusController diff --git a/submodules/SettingsUI/Sources/SettingsController.swift b/submodules/SettingsUI/Sources/SettingsController.swift index cdeb5ee491..13e47c6809 100644 --- a/submodules/SettingsUI/Sources/SettingsController.swift +++ b/submodules/SettingsUI/Sources/SettingsController.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import LegacyComponents import MtProtoKit import TelegramPresentationData diff --git a/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift b/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift index d395626b62..b6727c786d 100644 --- a/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift +++ b/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/Stickers/FeaturedStickerPacksController.swift b/submodules/SettingsUI/Sources/Stickers/FeaturedStickerPacksController.swift index 902311f81b..ae1c2cd704 100644 --- a/submodules/SettingsUI/Sources/Stickers/FeaturedStickerPacksController.swift +++ b/submodules/SettingsUI/Sources/Stickers/FeaturedStickerPacksController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift b/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift index 86b2922418..7a23014883 100644 --- a/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift +++ b/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/TabBarAccountSwitchController.swift b/submodules/SettingsUI/Sources/TabBarAccountSwitchController.swift index 6c3beaa573..055521ced2 100644 --- a/submodules/SettingsUI/Sources/TabBarAccountSwitchController.swift +++ b/submodules/SettingsUI/Sources/TabBarAccountSwitchController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AccountContext diff --git a/submodules/SettingsUI/Sources/TabBarAccountSwitchControllerNode.swift b/submodules/SettingsUI/Sources/TabBarAccountSwitchControllerNode.swift index 3c21497668..9f770aca53 100644 --- a/submodules/SettingsUI/Sources/TabBarAccountSwitchControllerNode.swift +++ b/submodules/SettingsUI/Sources/TabBarAccountSwitchControllerNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AvatarNode import AccountContext diff --git a/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceController.swift b/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceController.swift index 795075fa57..4ba0f94379 100644 --- a/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceController.swift +++ b/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceController.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import Display diff --git a/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceControllerNode.swift b/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceControllerNode.swift index bd765219e3..cf5c360569 100644 --- a/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceControllerNode.swift +++ b/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceControllerNode.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import Display diff --git a/submodules/SettingsUI/Sources/Themes/CustomWallpaperPicker.swift b/submodules/SettingsUI/Sources/Themes/CustomWallpaperPicker.swift index e12af5fe34..cc32b30af5 100644 --- a/submodules/SettingsUI/Sources/Themes/CustomWallpaperPicker.swift +++ b/submodules/SettingsUI/Sources/Themes/CustomWallpaperPicker.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import LegacyComponents import TelegramUIPreferences import MediaResources diff --git a/submodules/SettingsUI/Sources/Themes/EditThemeController.swift b/submodules/SettingsUI/Sources/Themes/EditThemeController.swift index f07a62fb26..44b6358b05 100644 --- a/submodules/SettingsUI/Sources/Themes/EditThemeController.swift +++ b/submodules/SettingsUI/Sources/Themes/EditThemeController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/Themes/SettingsThemeWallpaperNode.swift b/submodules/SettingsUI/Sources/Themes/SettingsThemeWallpaperNode.swift index eb4c0fdb35..5e8c81a3fb 100644 --- a/submodules/SettingsUI/Sources/Themes/SettingsThemeWallpaperNode.swift +++ b/submodules/SettingsUI/Sources/Themes/SettingsThemeWallpaperNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift index 44206f66c5..e3470bac21 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift @@ -5,6 +5,7 @@ import Postbox import SwiftSignalKit import AsyncDisplayKit import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import AccountContext diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift index c2e453b12d..350cc4e929 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift @@ -5,6 +5,7 @@ import Postbox import SwiftSignalKit import AsyncDisplayKit import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ChatListUI diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAutoNightSettingsController.swift b/submodules/SettingsUI/Sources/Themes/ThemeAutoNightSettingsController.swift index 4466137a0e..66e9ab76ad 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAutoNightSettingsController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAutoNightSettingsController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAutoNightTimeSelectionActionSheet.swift b/submodules/SettingsUI/Sources/Themes/ThemeAutoNightTimeSelectionActionSheet.swift index 099743aaa1..42516f575c 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAutoNightTimeSelectionActionSheet.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAutoNightTimeSelectionActionSheet.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import UIKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import TelegramStringFormatting import AccountContext diff --git a/submodules/SettingsUI/Sources/Themes/ThemeColorsGridController.swift b/submodules/SettingsUI/Sources/Themes/ThemeColorsGridController.swift index 10cb5e656c..3115fdd986 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeColorsGridController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeColorsGridController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import LegacyComponents import TelegramPresentationData diff --git a/submodules/SettingsUI/Sources/Themes/ThemeColorsGridControllerItem.swift b/submodules/SettingsUI/Sources/Themes/ThemeColorsGridControllerItem.swift index 357f37a975..fecf396153 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeColorsGridControllerItem.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeColorsGridControllerItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import AsyncDisplayKit import Postbox diff --git a/submodules/SettingsUI/Sources/Themes/ThemeColorsGridControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeColorsGridControllerNode.swift index a7ae32dd07..7991e6df91 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeColorsGridControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeColorsGridControllerNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import MergeLists diff --git a/submodules/SettingsUI/Sources/Themes/ThemeGridController.swift b/submodules/SettingsUI/Sources/Themes/ThemeGridController.swift index 6248bfdcfd..6d1abcadff 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeGridController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeGridController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import LegacyComponents import TelegramPresentationData diff --git a/submodules/SettingsUI/Sources/Themes/ThemeGridControllerItem.swift b/submodules/SettingsUI/Sources/Themes/ThemeGridControllerItem.swift index df83458002..5f38860949 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeGridControllerItem.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeGridControllerItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import AsyncDisplayKit import Postbox diff --git a/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift index 25bb83b3e6..d47d294107 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import UniversalMediaPlayer import TelegramPresentationData diff --git a/submodules/SettingsUI/Sources/Themes/ThemeGridSearchColorsItem.swift b/submodules/SettingsUI/Sources/Themes/ThemeGridSearchColorsItem.swift index 2001873591..2fcc5a6656 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeGridSearchColorsItem.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeGridSearchColorsItem.swift @@ -5,6 +5,7 @@ import Postbox import Display import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import ListSectionHeaderNode diff --git a/submodules/SettingsUI/Sources/Themes/ThemeGridSearchContentNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeGridSearchContentNode.swift index 490b421d31..fc3229a8b6 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeGridSearchContentNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeGridSearchContentNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import MergeLists import AccountContext diff --git a/submodules/SettingsUI/Sources/Themes/ThemeGridSearchItem.swift b/submodules/SettingsUI/Sources/Themes/ThemeGridSearchItem.swift index 2ff3d1ae2c..85d97b0c37 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeGridSearchItem.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeGridSearchItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import AsyncDisplayKit import Postbox diff --git a/submodules/SettingsUI/Sources/Themes/ThemeGridSelectionPanelNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeGridSelectionPanelNode.swift index b0a69c51b3..1002474af6 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeGridSelectionPanelNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeGridSelectionPanelNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AppBundle diff --git a/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift b/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift index 76b726eb91..cd724cf3f8 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift @@ -5,6 +5,7 @@ import Postbox import SwiftSignalKit import AsyncDisplayKit import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import AccountContext diff --git a/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift index 55ea50517b..bb7105f241 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift @@ -5,6 +5,7 @@ import Postbox import SwiftSignalKit import AsyncDisplayKit import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import AccountContext diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsAccentColorItem.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsAccentColorItem.swift index b2f9492568..8acd578b3a 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsAccentColorItem.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsAccentColorItem.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsAppIconItem.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsAppIconItem.swift index 72d9b7e786..1f5fd063ac 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsAppIconItem.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsAppIconItem.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsBrightnessItem.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsBrightnessItem.swift index 774d83e30e..098410162a 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsBrightnessItem.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsBrightnessItem.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import LegacyComponents import ItemListUI diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsChatPreviewItem.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsChatPreviewItem.swift index 8ffa279900..89a7c23cb2 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsChatPreviewItem.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsChatPreviewItem.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift index c1acce31f4..d17e9e4da7 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsFontSizeItem.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsFontSizeItem.swift index 421941940f..3e97f00deb 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsFontSizeItem.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsFontSizeItem.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import LegacyComponents diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsThemeItem.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsThemeItem.swift index 895c93174c..6f86183c20 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsThemeItem.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsThemeItem.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift index a629f40cc8..544cfcc2e6 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift @@ -6,6 +6,7 @@ import Postbox import SwiftSignalKit import AsyncDisplayKit import TelegramCore +import SyncCore import Photos import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift index f59516abd3..3ce5587616 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import LegacyComponents import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperPatternPanelNode.swift b/submodules/SettingsUI/Sources/Themes/WallpaperPatternPanelNode.swift index 21df0b555d..d06b8e1f35 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperPatternPanelNode.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperPatternPanelNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import SwiftSignalKit import Display import TelegramCore +import SyncCore import TelegramPresentationData import LegacyComponents import AccountContext diff --git a/submodules/SettingsUI/Sources/UsernameSetupController.swift b/submodules/SettingsUI/Sources/UsernameSetupController.swift index 109d915f04..3482cd4ff4 100644 --- a/submodules/SettingsUI/Sources/UsernameSetupController.swift +++ b/submodules/SettingsUI/Sources/UsernameSetupController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/SettingsUI/Sources/Watch/WatchSettingsController.swift b/submodules/SettingsUI/Sources/Watch/WatchSettingsController.swift index 51e5ac3161..ce4dbcb7c5 100644 --- a/submodules/SettingsUI/Sources/Watch/WatchSettingsController.swift +++ b/submodules/SettingsUI/Sources/Watch/WatchSettingsController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/ShareController/BUCK b/submodules/ShareController/BUCK index 5f55558f21..e67eab7f9c 100644 --- a/submodules/ShareController/BUCK +++ b/submodules/ShareController/BUCK @@ -10,6 +10,7 @@ static_library( "//submodules/AsyncDisplayKit:AsyncDisplayKit#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/SaveToCameraRoll:SaveToCameraRoll", "//submodules/StickerResources:StickerResources", "//submodules/UrlEscaping:UrlEscaping", diff --git a/submodules/ShareController/Sources/ShareController.swift b/submodules/ShareController/Sources/ShareController.swift index efca27ebba..746241c1d2 100644 --- a/submodules/ShareController/Sources/ShareController.swift +++ b/submodules/ShareController/Sources/ShareController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/ShareController/Sources/ShareControllerNode.swift b/submodules/ShareController/Sources/ShareControllerNode.swift index 8b430349bb..c5f48d2c59 100644 --- a/submodules/ShareController/Sources/ShareControllerNode.swift +++ b/submodules/ShareController/Sources/ShareControllerNode.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext diff --git a/submodules/ShareController/Sources/ShareControllerPeerGridItem.swift b/submodules/ShareController/Sources/ShareControllerPeerGridItem.swift index f31e4213b5..39b093c0f1 100644 --- a/submodules/ShareController/Sources/ShareControllerPeerGridItem.swift +++ b/submodules/ShareController/Sources/ShareControllerPeerGridItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import AsyncDisplayKit import Postbox diff --git a/submodules/ShareController/Sources/ShareControllerRecentPeersGridItem.swift b/submodules/ShareController/Sources/ShareControllerRecentPeersGridItem.swift index acc47ca20a..d41db34ba2 100644 --- a/submodules/ShareController/Sources/ShareControllerRecentPeersGridItem.swift +++ b/submodules/ShareController/Sources/ShareControllerRecentPeersGridItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import AsyncDisplayKit import Postbox diff --git a/submodules/ShareController/Sources/SharePeersContainerNode.swift b/submodules/ShareController/Sources/SharePeersContainerNode.swift index 64c7de10ef..09796a79e2 100644 --- a/submodules/ShareController/Sources/SharePeersContainerNode.swift +++ b/submodules/ShareController/Sources/SharePeersContainerNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Display import TelegramPresentationData diff --git a/submodules/ShareController/Sources/ShareSearchContainerNode.swift b/submodules/ShareController/Sources/ShareSearchContainerNode.swift index 2b9935253a..96b39da92c 100644 --- a/submodules/ShareController/Sources/ShareSearchContainerNode.swift +++ b/submodules/ShareController/Sources/ShareSearchContainerNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Display import TelegramPresentationData diff --git a/submodules/ShareItems/BUCK b/submodules/ShareItems/BUCK index 988446048f..19d6ca2f02 100644 --- a/submodules/ShareItems/BUCK +++ b/submodules/ShareItems/BUCK @@ -16,6 +16,7 @@ static_library( "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/MtProtoKit:MtProtoKit#shared", "//submodules/Display:Display#shared", "//submodules/LegacyComponents:LegacyComponents", diff --git a/submodules/ShareItems/Sources/ShareItems.swift b/submodules/ShareItems/Sources/ShareItems.swift index 9a6fc748a0..7ba80a1fb0 100644 --- a/submodules/ShareItems/Sources/ShareItems.swift +++ b/submodules/ShareItems/Sources/ShareItems.swift @@ -2,6 +2,7 @@ import Foundation import SwiftSignalKit import Postbox import TelegramCore +import SyncCore #if BUCK import MtProtoKit #else diff --git a/submodules/SinglePhoneInputNode/Sources/SinglePhoneInputNode.swift b/submodules/SinglePhoneInputNode/Sources/SinglePhoneInputNode.swift index 6e8976c3a9..f38575990d 100644 --- a/submodules/SinglePhoneInputNode/Sources/SinglePhoneInputNode.swift +++ b/submodules/SinglePhoneInputNode/Sources/SinglePhoneInputNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import TelegramStringFormatting import PhoneNumberFormat diff --git a/submodules/StickerPackPreviewUI/BUCK b/submodules/StickerPackPreviewUI/BUCK index 6058deb7bd..d9156bceac 100644 --- a/submodules/StickerPackPreviewUI/BUCK +++ b/submodules/StickerPackPreviewUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/AccountContext:AccountContext", "//submodules/TelegramUIPreferences:TelegramUIPreferences", diff --git a/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewController.swift b/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewController.swift index 07a330de21..9519818450 100644 --- a/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewController.swift +++ b/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramUIPreferences import AccountContext diff --git a/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewControllerNode.swift b/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewControllerNode.swift index f54bd56d20..25fd550957 100644 --- a/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewControllerNode.swift +++ b/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewControllerNode.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import MergeLists diff --git a/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewGridItem.swift b/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewGridItem.swift index 942ef827bd..02100c6c97 100644 --- a/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewGridItem.swift +++ b/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewGridItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import AsyncDisplayKit import Postbox diff --git a/submodules/StickerPackPreviewUI/Sources/StickerPreviewController.swift b/submodules/StickerPackPreviewUI/Sources/StickerPreviewController.swift index 0f7109cd64..d4aad4b91c 100644 --- a/submodules/StickerPackPreviewUI/Sources/StickerPreviewController.swift +++ b/submodules/StickerPackPreviewUI/Sources/StickerPreviewController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import AccountContext diff --git a/submodules/StickerPackPreviewUI/Sources/StickerPreviewControllerNode.swift b/submodules/StickerPackPreviewUI/Sources/StickerPreviewControllerNode.swift index fc51082eb6..81493a08f0 100644 --- a/submodules/StickerPackPreviewUI/Sources/StickerPreviewControllerNode.swift +++ b/submodules/StickerPackPreviewUI/Sources/StickerPreviewControllerNode.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import StickerResources diff --git a/submodules/StickerPackPreviewUI/Sources/StickerPreviewPeekContent.swift b/submodules/StickerPackPreviewUI/Sources/StickerPreviewPeekContent.swift index c56daa5f91..3c6b1a6658 100644 --- a/submodules/StickerPackPreviewUI/Sources/StickerPreviewPeekContent.swift +++ b/submodules/StickerPackPreviewUI/Sources/StickerPreviewPeekContent.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import StickerResources import AnimatedStickerNode diff --git a/submodules/StickerResources/BUCK b/submodules/StickerResources/BUCK index 8ec4b5ce08..b5d224ade2 100644 --- a/submodules/StickerResources/BUCK +++ b/submodules/StickerResources/BUCK @@ -7,6 +7,7 @@ static_library( ]), deps = [ "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/Postbox:Postbox#shared", "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Display:Display#shared", diff --git a/submodules/StickerResources/Sources/StickerResources.swift b/submodules/StickerResources/Sources/StickerResources.swift index 497fb6c292..c2ec30423f 100644 --- a/submodules/StickerResources/Sources/StickerResources.swift +++ b/submodules/StickerResources/Sources/StickerResources.swift @@ -4,6 +4,7 @@ import Postbox import SwiftSignalKit import Display import TelegramCore +import SyncCore import MediaResources import Tuples import ImageBlur diff --git a/submodules/SyncCore/BUCK b/submodules/SyncCore/BUCK new file mode 100644 index 0000000000..7236134381 --- /dev/null +++ b/submodules/SyncCore/BUCK @@ -0,0 +1,15 @@ +load("//Config:buck_rule_macros.bzl", "framework") + +framework( + name = "SyncCore", + srcs = glob([ + "Sources/**/*.swift", + ]), + deps = [ + "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", + "//submodules/Postbox:Postbox#shared", + ], + frameworks = [ + "$SDKROOT/System/Library/Frameworks/Foundation.framework", + ], +) diff --git a/submodules/SyncCore/Sources/AccountBackupDataAttribute.swift b/submodules/SyncCore/Sources/AccountBackupDataAttribute.swift new file mode 100644 index 0000000000..339147a1d3 --- /dev/null +++ b/submodules/SyncCore/Sources/AccountBackupDataAttribute.swift @@ -0,0 +1,45 @@ +import Postbox + +public struct AccountBackupData: Codable, Equatable { + public var masterDatacenterId: Int32 + public var peerId: Int64 + public var masterDatacenterKey: Data + public var masterDatacenterKeyId: Int64 + + public init(masterDatacenterId: Int32, peerId: Int64, masterDatacenterKey: Data, masterDatacenterKeyId: Int64) { + self.masterDatacenterId = masterDatacenterId + self.peerId = peerId + self.masterDatacenterKey = masterDatacenterKey + self.masterDatacenterKeyId = masterDatacenterKeyId + } +} + +public final class AccountBackupDataAttribute: AccountRecordAttribute, Equatable { + public let data: AccountBackupData? + + public init(data: AccountBackupData?) { + self.data = data + } + + public init(decoder: PostboxDecoder) { + self.data = try? JSONDecoder().decode(AccountBackupData.self, from: decoder.decodeDataForKey("data") ?? Data()) + } + + public func encode(_ encoder: PostboxEncoder) { + if let data = self.data, let serializedData = try? JSONEncoder().encode(data) { + encoder.encodeData(serializedData, forKey: "data") + } + } + + public static func ==(lhs: AccountBackupDataAttribute, rhs: AccountBackupDataAttribute) -> Bool { + return lhs.data == rhs.data + } + + public func isEqual(to: AccountRecordAttribute) -> Bool { + if let to = to as? AccountBackupDataAttribute { + return self == to + } else { + return false + } + } +} diff --git a/submodules/TelegramCore/TelegramCore/AccountEnvironmentAttribute.swift b/submodules/SyncCore/Sources/AccountEnvironmentAttribute.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/AccountEnvironmentAttribute.swift rename to submodules/SyncCore/Sources/AccountEnvironmentAttribute.swift diff --git a/submodules/TelegramCore/TelegramCore/AccountSortOrderAttribute.swift b/submodules/SyncCore/Sources/AccountSortOrderAttribute.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/AccountSortOrderAttribute.swift rename to submodules/SyncCore/Sources/AccountSortOrderAttribute.swift diff --git a/submodules/SyncCore/Sources/AppChangelogState.swift b/submodules/SyncCore/Sources/AppChangelogState.swift new file mode 100644 index 0000000000..5fb0600001 --- /dev/null +++ b/submodules/SyncCore/Sources/AppChangelogState.swift @@ -0,0 +1,31 @@ +import Postbox + +public struct AppChangelogState: PreferencesEntry, Equatable { + public var checkedVersion: String + public var previousVersion: String + + public static var `default` = AppChangelogState(checkedVersion: "", previousVersion: "5.0.8") + + public init(checkedVersion: String, previousVersion: String) { + self.checkedVersion = checkedVersion + self.previousVersion = previousVersion + } + + public init(decoder: PostboxDecoder) { + self.checkedVersion = decoder.decodeStringForKey("checkedVersion", orElse: "") + self.previousVersion = decoder.decodeStringForKey("previousVersion", orElse: "") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.checkedVersion, forKey: "checkedVersion") + encoder.encodeString(self.previousVersion, forKey: "previousVersion") + } + + public func isEqual(to: PreferencesEntry) -> Bool { + guard let to = to as? AppChangelogState else { + return false + } + + return self == to + } +} diff --git a/submodules/SyncCore/Sources/AppConfiguration.swift b/submodules/SyncCore/Sources/AppConfiguration.swift new file mode 100644 index 0000000000..e56aaa4536 --- /dev/null +++ b/submodules/SyncCore/Sources/AppConfiguration.swift @@ -0,0 +1,37 @@ +import Foundation +#if os(macOS) + import PostboxMac +#else + import Postbox +#endif + +public struct AppConfiguration: PreferencesEntry, Equatable { + public var data: JSON? + + public static var defaultValue: AppConfiguration { + return AppConfiguration(data: nil) + } + + init(data: JSON?) { + self.data = data + } + + public init(decoder: PostboxDecoder) { + self.data = decoder.decodeObjectForKey("data", decoder: { JSON(decoder: $0) }) as? JSON + } + + public func encode(_ encoder: PostboxEncoder) { + if let data = self.data { + encoder.encodeObject(data, forKey: "data") + } else { + encoder.encodeNil(forKey: "data") + } + } + + public func isEqual(to: PreferencesEntry) -> Bool { + guard let to = to as? AppConfiguration else { + return false + } + return self == to + } +} diff --git a/submodules/TelegramCore/TelegramCore/ArchivedStickerPacksInfo.swift b/submodules/SyncCore/Sources/ArchivedStickerPacksInfo.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/ArchivedStickerPacksInfo.swift rename to submodules/SyncCore/Sources/ArchivedStickerPacksInfo.swift diff --git a/submodules/TelegramCore/TelegramCore/AuthorSignatureMessageAttribute.swift b/submodules/SyncCore/Sources/AuthorSignatureMessageAttribute.swift similarity index 93% rename from submodules/TelegramCore/TelegramCore/AuthorSignatureMessageAttribute.swift rename to submodules/SyncCore/Sources/AuthorSignatureMessageAttribute.swift index 66d0a2e67f..7dbbd432be 100644 --- a/submodules/TelegramCore/TelegramCore/AuthorSignatureMessageAttribute.swift +++ b/submodules/SyncCore/Sources/AuthorSignatureMessageAttribute.swift @@ -10,7 +10,7 @@ public class AuthorSignatureMessageAttribute: MessageAttribute { public let associatedPeerIds: [PeerId] = [] - init(signature: String) { + public init(signature: String) { self.signature = signature } diff --git a/submodules/SyncCore/Sources/AuthorizedAccountState.swift b/submodules/SyncCore/Sources/AuthorizedAccountState.swift new file mode 100644 index 0000000000..822657a296 --- /dev/null +++ b/submodules/SyncCore/Sources/AuthorizedAccountState.swift @@ -0,0 +1,93 @@ +import Postbox + +public protocol AccountState: PostboxCoding { + func equalsTo(_ other: AccountState) -> Bool +} + +public func ==(lhs: AccountState, rhs: AccountState) -> Bool { + return lhs.equalsTo(rhs) +} + +public class AuthorizedAccountState: AccountState { + public final class State: PostboxCoding, Equatable, CustomStringConvertible { + public let pts: Int32 + public let qts: Int32 + public let date: Int32 + public let seq: Int32 + + public init(pts: Int32, qts: Int32, date: Int32, seq: Int32) { + self.pts = pts + self.qts = qts + self.date = date + self.seq = seq + } + + public init(decoder: PostboxDecoder) { + self.pts = decoder.decodeInt32ForKey("pts", orElse: 0) + self.qts = decoder.decodeInt32ForKey("qts", orElse: 0) + self.date = decoder.decodeInt32ForKey("date", orElse: 0) + self.seq = decoder.decodeInt32ForKey("seq", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.pts, forKey: "pts") + encoder.encodeInt32(self.qts, forKey: "qts") + encoder.encodeInt32(self.date, forKey: "date") + encoder.encodeInt32(self.seq, forKey: "seq") + } + + public var description: String { + return "(pts: \(pts), qts: \(qts), seq: \(seq), date: \(date))" + } + } + + public let isTestingEnvironment: Bool + public let masterDatacenterId: Int32 + public let peerId: PeerId + + public let state: State? + + public required init(decoder: PostboxDecoder) { + self.isTestingEnvironment = decoder.decodeInt32ForKey("isTestingEnvironment", orElse: 0) != 0 + self.masterDatacenterId = decoder.decodeInt32ForKey("masterDatacenterId", orElse: 0) + self.peerId = PeerId(decoder.decodeInt64ForKey("peerId", orElse: 0)) + self.state = decoder.decodeObjectForKey("state", decoder: { return State(decoder: $0) }) as? State + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.isTestingEnvironment ? 1 : 0, forKey: "isTestingEnvironment") + encoder.encodeInt32(self.masterDatacenterId, forKey: "masterDatacenterId") + encoder.encodeInt64(self.peerId.toInt64(), forKey: "peerId") + if let state = self.state { + encoder.encodeObject(state, forKey: "state") + } + } + + public init(isTestingEnvironment: Bool, masterDatacenterId: Int32, peerId: PeerId, state: State?) { + self.isTestingEnvironment = isTestingEnvironment + self.masterDatacenterId = masterDatacenterId + self.peerId = peerId + self.state = state + } + + public func changedState(_ state: State) -> AuthorizedAccountState { + return AuthorizedAccountState(isTestingEnvironment: self.isTestingEnvironment, masterDatacenterId: self.masterDatacenterId, peerId: self.peerId, state: state) + } + + public func equalsTo(_ other: AccountState) -> Bool { + if let other = other as? AuthorizedAccountState { + return self.isTestingEnvironment == other.isTestingEnvironment && self.masterDatacenterId == other.masterDatacenterId && + self.peerId == other.peerId && + self.state == other.state + } else { + return false + } + } +} + +public func ==(lhs: AuthorizedAccountState.State, rhs: AuthorizedAccountState.State) -> Bool { + return lhs.pts == rhs.pts && + lhs.qts == rhs.qts && + lhs.date == rhs.date && + lhs.seq == rhs.seq +} diff --git a/submodules/SyncCore/Sources/AutodownloadSettings.swift b/submodules/SyncCore/Sources/AutodownloadSettings.swift new file mode 100644 index 0000000000..3724217966 --- /dev/null +++ b/submodules/SyncCore/Sources/AutodownloadSettings.swift @@ -0,0 +1,85 @@ +import Postbox + +public enum AutodownloadPreset { + case low + case medium + case high +} + +public struct AutodownloadPresetSettings: PostboxCoding, Equatable { + public let disabled: Bool + public let photoSizeMax: Int32 + public let videoSizeMax: Int32 + public let fileSizeMax: Int32 + public let preloadLargeVideo: Bool + public let lessDataForPhoneCalls: Bool + + public init(disabled: Bool, photoSizeMax: Int32, videoSizeMax: Int32, fileSizeMax: Int32, preloadLargeVideo: Bool, lessDataForPhoneCalls: Bool) { + self.disabled = disabled + self.photoSizeMax = photoSizeMax + self.videoSizeMax = videoSizeMax + self.fileSizeMax = fileSizeMax + self.preloadLargeVideo = preloadLargeVideo + self.lessDataForPhoneCalls = lessDataForPhoneCalls + } + + public init(decoder: PostboxDecoder) { + self.disabled = decoder.decodeInt32ForKey("disabled", orElse: 0) != 0 + self.photoSizeMax = decoder.decodeInt32ForKey("photoSizeMax", orElse: 0) + self.videoSizeMax = decoder.decodeInt32ForKey("videoSizeMax", orElse: 0) + self.fileSizeMax = decoder.decodeInt32ForKey("fileSizeMax", orElse: 0) + self.preloadLargeVideo = decoder.decodeInt32ForKey("preloadLargeVideo", orElse: 0) != 0 + self.lessDataForPhoneCalls = decoder.decodeInt32ForKey("lessDataForPhoneCalls", orElse: 0) != 0 + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.disabled ? 1 : 0, forKey: "disabled") + encoder.encodeInt32(self.photoSizeMax, forKey: "photoSizeMax") + encoder.encodeInt32(self.videoSizeMax, forKey: "videoSizeMax") + encoder.encodeInt32(self.fileSizeMax, forKey: "fileSizeMax") + encoder.encodeInt32(self.preloadLargeVideo ? 1 : 0, forKey: "preloadLargeVideo") + encoder.encodeInt32(self.lessDataForPhoneCalls ? 1 : 0, forKey: "lessDataForPhoneCalls") + } +} + +public struct AutodownloadSettings: PreferencesEntry, Equatable { + public let lowPreset: AutodownloadPresetSettings + public let mediumPreset: AutodownloadPresetSettings + public let highPreset: AutodownloadPresetSettings + + public static var defaultSettings: AutodownloadSettings { + return AutodownloadSettings(lowPreset: AutodownloadPresetSettings(disabled: false, photoSizeMax: 1 * 1024 * 1024, videoSizeMax: 0, fileSizeMax: 0, preloadLargeVideo: false, lessDataForPhoneCalls: true), + mediumPreset: AutodownloadPresetSettings(disabled: false, photoSizeMax: 1 * 1024 * 1024, videoSizeMax: Int32(2.5 * 1024 * 1024), fileSizeMax: 1 * 1024 * 1024, preloadLargeVideo: false, lessDataForPhoneCalls: false), + highPreset: AutodownloadPresetSettings(disabled: false, photoSizeMax: 1 * 1024 * 1024, videoSizeMax: 10 * 1024 * 1024, fileSizeMax: 3 * 1024 * 1024, preloadLargeVideo: false, lessDataForPhoneCalls: false)) + } + + public init(lowPreset: AutodownloadPresetSettings, mediumPreset: AutodownloadPresetSettings, highPreset: AutodownloadPresetSettings) { + self.lowPreset = lowPreset + self.mediumPreset = mediumPreset + self.highPreset = highPreset + } + + public init(decoder: PostboxDecoder) { + self.lowPreset = decoder.decodeObjectForKey("lowPreset", decoder: AutodownloadPresetSettings.init(decoder:)) as! AutodownloadPresetSettings + self.mediumPreset = decoder.decodeObjectForKey("mediumPreset", decoder: AutodownloadPresetSettings.init(decoder:)) as! AutodownloadPresetSettings + self.highPreset = decoder.decodeObjectForKey("highPreset", decoder: AutodownloadPresetSettings.init(decoder:)) as! AutodownloadPresetSettings + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObject(self.lowPreset, forKey: "lowPreset") + encoder.encodeObject(self.mediumPreset, forKey: "mediumPreset") + encoder.encodeObject(self.highPreset, forKey: "highPreset") + } + + public func isEqual(to: PreferencesEntry) -> Bool { + if let to = to as? AutodownloadSettings { + return self == to + } else { + return false + } + } + + public static func ==(lhs: AutodownloadSettings, rhs: AutodownloadSettings) -> Bool { + return lhs.lowPreset == rhs.lowPreset && lhs.mediumPreset == rhs.mediumPreset && lhs.highPreset == rhs.highPreset + } +} diff --git a/submodules/TelegramCore/TelegramCore/AutoremoveTimeoutMessageAttribute.swift b/submodules/SyncCore/Sources/AutoremoveTimeoutMessageAttribute.swift similarity index 67% rename from submodules/TelegramCore/TelegramCore/AutoremoveTimeoutMessageAttribute.swift rename to submodules/SyncCore/Sources/AutoremoveTimeoutMessageAttribute.swift index 5b9b18cd53..7c50d55d6c 100644 --- a/submodules/TelegramCore/TelegramCore/AutoremoveTimeoutMessageAttribute.swift +++ b/submodules/SyncCore/Sources/AutoremoveTimeoutMessageAttribute.swift @@ -1,17 +1,5 @@ import Foundation -#if os(macOS) - import PostboxMac - import SwiftSignalKitMac - import MtProtoKitMac -#else - import Postbox - import SwiftSignalKit - #if BUCK - import MtProtoKit - #else - import MtProtoKitDynamic - #endif -#endif +import Postbox public class AutoremoveTimeoutMessageAttribute: MessageAttribute { public let timeout: Int32 @@ -71,31 +59,4 @@ public extension Message { return false } - - var secretMediaDuration: Int32? { - var found = false - for attribute in self.attributes { - if let _ = attribute as? AutoremoveTimeoutMessageAttribute { - found = true - break - } - } - - if !found { - return nil - } - - for media in self.media { - switch media { - case _ as TelegramMediaImage: - return nil - case let file as TelegramMediaFile: - return file.duration - default: - break - } - } - - return nil - } } diff --git a/submodules/SyncCore/Sources/BotInfo.swift b/submodules/SyncCore/Sources/BotInfo.swift new file mode 100644 index 0000000000..0725e864a8 --- /dev/null +++ b/submodules/SyncCore/Sources/BotInfo.swift @@ -0,0 +1,45 @@ +import Postbox + +public struct BotCommand: PostboxCoding, Hashable { + public let text: String + public let description: String + + public init(text: String, description: String) { + self.text = text + self.description = description + } + + public init(decoder: PostboxDecoder) { + self.text = decoder.decodeStringForKey("t", orElse: "") + self.description = decoder.decodeStringForKey("d", orElse: "") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.text, forKey: "t") + encoder.encodeString(self.description, forKey: "d") + } +} + +public final class BotInfo: PostboxCoding, Equatable { + public let description: String + public let commands: [BotCommand] + + public init(description: String, commands: [BotCommand]) { + self.description = description + self.commands = commands + } + + public init(decoder: PostboxDecoder) { + self.description = decoder.decodeStringForKey("d", orElse: "") + self.commands = decoder.decodeObjectArrayWithDecoderForKey("c") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.description, forKey: "d") + encoder.encodeObjectArray(self.commands, forKey: "c") + } + + public static func ==(lhs: BotInfo, rhs: BotInfo) -> Bool { + return lhs.description == rhs.description && lhs.commands == rhs.commands + } +} diff --git a/submodules/SyncCore/Sources/CacheStorageSettings.swift b/submodules/SyncCore/Sources/CacheStorageSettings.swift new file mode 100644 index 0000000000..3e3f859825 --- /dev/null +++ b/submodules/SyncCore/Sources/CacheStorageSettings.swift @@ -0,0 +1,37 @@ +import Postbox + +public struct CacheStorageSettings: PreferencesEntry, Equatable { + public let defaultCacheStorageTimeout: Int32 + + public static var defaultSettings: CacheStorageSettings { + return CacheStorageSettings(defaultCacheStorageTimeout: Int32.max) + } + + public init(defaultCacheStorageTimeout: Int32) { + self.defaultCacheStorageTimeout = defaultCacheStorageTimeout + } + + public init(decoder: PostboxDecoder) { + self.defaultCacheStorageTimeout = decoder.decodeInt32ForKey("dt", orElse: Int32.max) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.defaultCacheStorageTimeout, forKey: "dt") + } + + public func isEqual(to: PreferencesEntry) -> Bool { + if let to = to as? CacheStorageSettings { + return self == to + } else { + return false + } + } + + public static func ==(lhs: CacheStorageSettings, rhs: CacheStorageSettings) -> Bool { + return lhs.defaultCacheStorageTimeout == rhs.defaultCacheStorageTimeout + } + + public func withUpdatedDefaultCacheStorageTimeout(_ defaultCacheStorageTimeout: Int32) -> CacheStorageSettings { + return CacheStorageSettings(defaultCacheStorageTimeout: defaultCacheStorageTimeout) + } +} diff --git a/submodules/SyncCore/Sources/CachedChannelData.swift b/submodules/SyncCore/Sources/CachedChannelData.swift new file mode 100644 index 0000000000..c00a913477 --- /dev/null +++ b/submodules/SyncCore/Sources/CachedChannelData.swift @@ -0,0 +1,502 @@ +import Postbox + +public struct CachedChannelFlags: OptionSet { + public var rawValue: Int32 + + public init() { + self.rawValue = 0 + } + + public init(rawValue: Int32) { + self.rawValue = rawValue + } + + public static let canDisplayParticipants = CachedChannelFlags(rawValue: 1 << 0) + public static let canChangeUsername = CachedChannelFlags(rawValue: 1 << 1) + public static let canSetStickerSet = CachedChannelFlags(rawValue: 1 << 2) + public static let preHistoryEnabled = CachedChannelFlags(rawValue: 1 << 3) + public static let canViewStats = CachedChannelFlags(rawValue: 1 << 4) + public static let canChangePeerGeoLocation = CachedChannelFlags(rawValue: 1 << 5) +} + +public struct CachedChannelParticipantsSummary: PostboxCoding, Equatable { + public let memberCount: Int32? + public let adminCount: Int32? + public let bannedCount: Int32? + public let kickedCount: Int32? + + public init(memberCount: Int32?, adminCount: Int32?, bannedCount: Int32?, kickedCount: Int32?) { + self.memberCount = memberCount + self.adminCount = adminCount + self.bannedCount = bannedCount + self.kickedCount = kickedCount + } + + public init(decoder: PostboxDecoder) { + if let memberCount = decoder.decodeOptionalInt32ForKey("p.m") { + self.memberCount = memberCount + } else { + self.memberCount = nil + } + if let adminCount = decoder.decodeOptionalInt32ForKey("p.a") { + self.adminCount = adminCount + } else { + self.adminCount = nil + } + if let bannedCount = decoder.decodeOptionalInt32ForKey("p.b") { + self.bannedCount = bannedCount + } else { + self.bannedCount = nil + } + if let kickedCount = decoder.decodeOptionalInt32ForKey("p.k") { + self.kickedCount = kickedCount + } else { + self.kickedCount = nil + } + } + + public func encode(_ encoder: PostboxEncoder) { + if let memberCount = self.memberCount { + encoder.encodeInt32(memberCount, forKey: "p.m") + } else { + encoder.encodeNil(forKey: "p.m") + } + if let adminCount = self.adminCount { + encoder.encodeInt32(adminCount, forKey: "p.a") + } else { + encoder.encodeNil(forKey: "p.a") + } + if let bannedCount = self.bannedCount { + encoder.encodeInt32(bannedCount, forKey: "p.b") + } else { + encoder.encodeNil(forKey: "p.b") + } + if let kickedCount = self.kickedCount { + encoder.encodeInt32(kickedCount, forKey: "p.k") + } else { + encoder.encodeNil(forKey: "p.k") + } + } + + public static func ==(lhs: CachedChannelParticipantsSummary, rhs: CachedChannelParticipantsSummary) -> Bool { + return lhs.memberCount == rhs.memberCount && lhs.adminCount == rhs.adminCount && lhs.bannedCount == rhs.bannedCount && lhs.kickedCount == rhs.kickedCount + } + + public func withUpdatedMemberCount(_ memberCount: Int32?) -> CachedChannelParticipantsSummary { + return CachedChannelParticipantsSummary(memberCount: memberCount, adminCount: self.adminCount, bannedCount: self.bannedCount, kickedCount: self.kickedCount) + } + + public func withUpdatedAdminCount(_ adminCount: Int32?) -> CachedChannelParticipantsSummary { + return CachedChannelParticipantsSummary(memberCount: self.memberCount, adminCount: adminCount, bannedCount: self.bannedCount, kickedCount: self.kickedCount) + } + + public func withUpdatedBannedCount(_ bannedCount: Int32?) -> CachedChannelParticipantsSummary { + return CachedChannelParticipantsSummary(memberCount: self.memberCount, adminCount: self.adminCount, bannedCount: bannedCount, kickedCount: self.kickedCount) + } + + public func withUpdatedKickedCount(_ kickedCount: Int32?) -> CachedChannelParticipantsSummary { + return CachedChannelParticipantsSummary(memberCount: self.memberCount, adminCount: self.adminCount, bannedCount: self.bannedCount, kickedCount: kickedCount) + } +} + +public struct ChannelMigrationReference: PostboxCoding, Equatable { + public let maxMessageId: MessageId + + public init(maxMessageId: MessageId) { + self.maxMessageId = maxMessageId + } + + public init(decoder: PostboxDecoder) { + self.maxMessageId = MessageId(peerId: PeerId(decoder.decodeInt64ForKey("p", orElse: 0)), namespace: decoder.decodeInt32ForKey("n", orElse: 0), id: decoder.decodeInt32ForKey("i", orElse: 0)) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt64(self.maxMessageId.peerId.toInt64(), forKey: "p") + encoder.encodeInt32(self.maxMessageId.namespace, forKey: "n") + encoder.encodeInt32(self.maxMessageId.id, forKey: "i") + } + + public static func ==(lhs: ChannelMigrationReference, rhs: ChannelMigrationReference) -> Bool { + return lhs.maxMessageId == rhs.maxMessageId + } +} + +public struct PeerGeoLocation: PostboxCoding, Equatable { + public let latitude: Double + public let longitude: Double + public let address: String + + public init(latitude: Double, longitude: Double, address: String) { + self.latitude = latitude + self.longitude = longitude + self.address = address + } + + public init(decoder: PostboxDecoder) { + self.latitude = decoder.decodeDoubleForKey("la", orElse: 0.0) + self.longitude = decoder.decodeDoubleForKey("lo", orElse: 0.0) + self.address = decoder.decodeStringForKey("a", orElse: "") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeDouble(self.latitude, forKey: "la") + encoder.encodeDouble(self.longitude, forKey: "lo") + encoder.encodeString(self.address, forKey: "a") + } + + public static func ==(lhs: PeerGeoLocation, rhs: PeerGeoLocation) -> Bool { + return lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude && lhs.address == rhs.address + } +} + +public final class CachedChannelData: CachedPeerData { + public let isNotAccessible: Bool + public let flags: CachedChannelFlags + public let about: String? + public let participantsSummary: CachedChannelParticipantsSummary + public let exportedInvitation: ExportedInvitation? + public let botInfos: [CachedPeerBotInfo] + public let peerStatusSettings: PeerStatusSettings? + public let pinnedMessageId: MessageId? + public let stickerPack: StickerPackCollectionInfo? + public let minAvailableMessageId: MessageId? + public let migrationReference: ChannelMigrationReference? + public let linkedDiscussionPeerId: PeerId? + public let peerGeoLocation: PeerGeoLocation? + public let slowModeTimeout: Int32? + public let slowModeValidUntilTimestamp: Int32? + public let hasScheduledMessages: Bool + + public let peerIds: Set + public let messageIds: Set + public var associatedHistoryMessageId: MessageId? { + return self.migrationReference?.maxMessageId + } + + public init() { + self.isNotAccessible = false + self.flags = [] + self.about = nil + self.participantsSummary = CachedChannelParticipantsSummary(memberCount: nil, adminCount: nil, bannedCount: nil, kickedCount: nil) + self.exportedInvitation = nil + self.botInfos = [] + self.peerStatusSettings = nil + self.pinnedMessageId = nil + self.peerIds = Set() + self.messageIds = Set() + self.stickerPack = nil + self.minAvailableMessageId = nil + self.migrationReference = nil + self.linkedDiscussionPeerId = nil + self.peerGeoLocation = nil + self.slowModeTimeout = nil + self.slowModeValidUntilTimestamp = nil + self.hasScheduledMessages = false + } + + public init(isNotAccessible: Bool, flags: CachedChannelFlags, about: String?, participantsSummary: CachedChannelParticipantsSummary, exportedInvitation: ExportedInvitation?, botInfos: [CachedPeerBotInfo], peerStatusSettings: PeerStatusSettings?, pinnedMessageId: MessageId?, stickerPack: StickerPackCollectionInfo?, minAvailableMessageId: MessageId?, migrationReference: ChannelMigrationReference?, linkedDiscussionPeerId: PeerId?, peerGeoLocation: PeerGeoLocation?, slowModeTimeout: Int32?, slowModeValidUntilTimestamp: Int32?, hasScheduledMessages: Bool) { + self.isNotAccessible = isNotAccessible + self.flags = flags + self.about = about + self.participantsSummary = participantsSummary + self.exportedInvitation = exportedInvitation + self.botInfos = botInfos + self.peerStatusSettings = peerStatusSettings + self.pinnedMessageId = pinnedMessageId + self.stickerPack = stickerPack + self.minAvailableMessageId = minAvailableMessageId + self.migrationReference = migrationReference + self.linkedDiscussionPeerId = linkedDiscussionPeerId + self.peerGeoLocation = peerGeoLocation + self.slowModeTimeout = slowModeTimeout + self.slowModeValidUntilTimestamp = slowModeValidUntilTimestamp + self.hasScheduledMessages = hasScheduledMessages + + var peerIds = Set() + for botInfo in botInfos { + peerIds.insert(botInfo.peerId) + } + + if let linkedDiscussionPeerId = linkedDiscussionPeerId { + peerIds.insert(linkedDiscussionPeerId) + } + + self.peerIds = peerIds + + var messageIds = Set() + if let pinnedMessageId = self.pinnedMessageId { + messageIds.insert(pinnedMessageId) + } + self.messageIds = messageIds + } + + public func withUpdatedIsNotAccessible(_ isNotAccessible: Bool) -> CachedChannelData { + return CachedChannelData(isNotAccessible: isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) + } + + public func withUpdatedFlags(_ flags: CachedChannelFlags) -> CachedChannelData { + return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) + } + + public func withUpdatedAbout(_ about: String?) -> CachedChannelData { + return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) + } + + public func withUpdatedParticipantsSummary(_ participantsSummary: CachedChannelParticipantsSummary) -> CachedChannelData { + return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) + } + + public func withUpdatedExportedInvitation(_ exportedInvitation: ExportedInvitation?) -> CachedChannelData { + return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) + } + + public func withUpdatedBotInfos(_ botInfos: [CachedPeerBotInfo]) -> CachedChannelData { + return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) + } + + public func withUpdatedPeerStatusSettings(_ peerStatusSettings: PeerStatusSettings?) -> CachedChannelData { + return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) + } + + public func withUpdatedPinnedMessageId(_ pinnedMessageId: MessageId?) -> CachedChannelData { + return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) + } + + public func withUpdatedStickerPack(_ stickerPack: StickerPackCollectionInfo?) -> CachedChannelData { + return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) + } + + public func withUpdatedMinAvailableMessageId(_ minAvailableMessageId: MessageId?) -> CachedChannelData { + return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) + } + + public func withUpdatedMigrationReference(_ migrationReference: ChannelMigrationReference?) -> CachedChannelData { + return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) + } + + public func withUpdatedLinkedDiscussionPeerId(_ linkedDiscussionPeerId: PeerId?) -> CachedChannelData { + return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) + } + + public func withUpdatedPeerGeoLocation(_ peerGeoLocation: PeerGeoLocation?) -> CachedChannelData { + return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) + } + + public func withUpdatedSlowModeTimeout(_ slowModeTimeout: Int32?) -> CachedChannelData { + return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) + } + + public func withUpdatedSlowModeValidUntilTimestamp(_ slowModeValidUntilTimestamp: Int32?) -> CachedChannelData { + return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) + } + + public func withUpdatedHasScheduledMessages(_ hasScheduledMessages: Bool) -> CachedChannelData { + return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: hasScheduledMessages) + } + + public init(decoder: PostboxDecoder) { + self.isNotAccessible = decoder.decodeInt32ForKey("isNotAccessible", orElse: 0) != 0 + self.flags = CachedChannelFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0)) + self.about = decoder.decodeOptionalStringForKey("a") + self.participantsSummary = CachedChannelParticipantsSummary(decoder: decoder) + self.exportedInvitation = decoder.decodeObjectForKey("i", decoder: { ExportedInvitation(decoder: $0) }) as? ExportedInvitation + self.botInfos = decoder.decodeObjectArrayWithDecoderForKey("b") as [CachedPeerBotInfo] + var peerIds = Set() + if let value = decoder.decodeOptionalInt32ForKey("pcs") { + self.peerStatusSettings = PeerStatusSettings(rawValue: value) + } else { + self.peerStatusSettings = nil + } + if let pinnedMessagePeerId = decoder.decodeOptionalInt64ForKey("pm.p"), let pinnedMessageNamespace = decoder.decodeOptionalInt32ForKey("pm.n"), let pinnedMessageId = decoder.decodeOptionalInt32ForKey("pm.i") { + self.pinnedMessageId = MessageId(peerId: PeerId(pinnedMessagePeerId), namespace: pinnedMessageNamespace, id: pinnedMessageId) + } else { + self.pinnedMessageId = nil + } + + if let stickerPack = decoder.decodeObjectForKey("sp", decoder: { StickerPackCollectionInfo(decoder: $0) }) as? StickerPackCollectionInfo { + self.stickerPack = stickerPack + } else { + self.stickerPack = nil + } + + if let minAvailableMessagePeerId = decoder.decodeOptionalInt64ForKey("ma.p"), let minAvailableMessageNamespace = decoder.decodeOptionalInt32ForKey("ma.n"), let minAvailableMessageId = decoder.decodeOptionalInt32ForKey("ma.i") { + self.minAvailableMessageId = MessageId(peerId: PeerId(minAvailableMessagePeerId), namespace: minAvailableMessageNamespace, id: minAvailableMessageId) + } else { + self.minAvailableMessageId = nil + } + + self.migrationReference = decoder.decodeObjectForKey("mr", decoder: { ChannelMigrationReference(decoder: $0) }) as? ChannelMigrationReference + + for botInfo in self.botInfos { + peerIds.insert(botInfo.peerId) + } + + if let linkedDiscussionPeerId = decoder.decodeOptionalInt64ForKey("dgi") { + self.linkedDiscussionPeerId = PeerId(linkedDiscussionPeerId) + } else { + self.linkedDiscussionPeerId = nil + } + + if let peerGeoLocation = decoder.decodeObjectForKey("pgl", decoder: { PeerGeoLocation(decoder: $0) }) as? PeerGeoLocation { + self.peerGeoLocation = peerGeoLocation + } else { + self.peerGeoLocation = nil + } + + self.slowModeTimeout = decoder.decodeOptionalInt32ForKey("smt") + self.slowModeValidUntilTimestamp = decoder.decodeOptionalInt32ForKey("smv") + self.hasScheduledMessages = decoder.decodeBoolForKey("hsm", orElse: false) + + if let linkedDiscussionPeerId = self.linkedDiscussionPeerId { + peerIds.insert(linkedDiscussionPeerId) + } + + self.peerIds = peerIds + + var messageIds = Set() + if let pinnedMessageId = self.pinnedMessageId { + messageIds.insert(pinnedMessageId) + } + self.messageIds = messageIds + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.isNotAccessible ? 1 : 0, forKey: "isNotAccessible") + encoder.encodeInt32(self.flags.rawValue, forKey: "f") + if let about = self.about { + encoder.encodeString(about, forKey: "a") + } else { + encoder.encodeNil(forKey: "a") + } + self.participantsSummary.encode(encoder) + if let exportedInvitation = self.exportedInvitation { + encoder.encodeObject(exportedInvitation, forKey: "i") + } else { + encoder.encodeNil(forKey: "i") + } + encoder.encodeObjectArray(self.botInfos, forKey: "b") + if let peerStatusSettings = self.peerStatusSettings { + encoder.encodeInt32(peerStatusSettings.rawValue, forKey: "pcs") + } else { + encoder.encodeNil(forKey: "pcs") + } + if let pinnedMessageId = self.pinnedMessageId { + encoder.encodeInt64(pinnedMessageId.peerId.toInt64(), forKey: "pm.p") + encoder.encodeInt32(pinnedMessageId.namespace, forKey: "pm.n") + encoder.encodeInt32(pinnedMessageId.id, forKey: "pm.i") + } else { + encoder.encodeNil(forKey: "pm.p") + encoder.encodeNil(forKey: "pm.n") + encoder.encodeNil(forKey: "pm.i") + } + if let stickerPack = self.stickerPack { + encoder.encodeObject(stickerPack, forKey: "sp") + } else { + encoder.encodeNil(forKey: "sp") + } + if let minAvailableMessageId = self.minAvailableMessageId { + encoder.encodeInt64(minAvailableMessageId.peerId.toInt64(), forKey: "ma.p") + encoder.encodeInt32(minAvailableMessageId.namespace, forKey: "ma.n") + encoder.encodeInt32(minAvailableMessageId.id, forKey: "ma.i") + } else { + encoder.encodeNil(forKey: "ma.p") + encoder.encodeNil(forKey: "ma.n") + encoder.encodeNil(forKey: "ma.i") + } + if let migrationReference = self.migrationReference { + encoder.encodeObject(migrationReference, forKey: "mr") + } else { + encoder.encodeNil(forKey: "mr") + } + if let linkedDiscussionPeerId = self.linkedDiscussionPeerId { + encoder.encodeInt64(linkedDiscussionPeerId.toInt64(), forKey: "dgi") + } else { + encoder.encodeNil(forKey: "dgi") + } + if let peerGeoLocation = self.peerGeoLocation { + encoder.encodeObject(peerGeoLocation, forKey: "pgl") + } else { + encoder.encodeNil(forKey: "pgl") + } + + if let slowModeTimeout = self.slowModeTimeout { + encoder.encodeInt32(slowModeTimeout, forKey: "smt") + } else { + encoder.encodeNil(forKey: "smt") + } + if let slowModeValidUntilTimestamp = self.slowModeValidUntilTimestamp { + encoder.encodeInt32(slowModeValidUntilTimestamp, forKey: "smv") + } else { + encoder.encodeNil(forKey: "smv") + } + encoder.encodeBool(self.hasScheduledMessages, forKey: "hsm") + } + + public func isEqual(to: CachedPeerData) -> Bool { + guard let other = to as? CachedChannelData else { + return false + } + + if other.isNotAccessible != self.isNotAccessible { + return false + } + + if other.flags != self.flags { + return false + } + + if other.linkedDiscussionPeerId != self.linkedDiscussionPeerId { + return false + } + + if other.about != self.about { + return false + } + + if other.participantsSummary != self.participantsSummary { + return false + } + + if other.exportedInvitation != self.exportedInvitation { + return false + } + + if other.botInfos != self.botInfos { + return false + } + + if other.peerStatusSettings != self.peerStatusSettings { + return false + } + + if other.pinnedMessageId != self.pinnedMessageId { + return false + } + + if other.stickerPack != self.stickerPack { + return false + } + + if other.minAvailableMessageId != self.minAvailableMessageId { + return false + } + + if other.migrationReference != self.migrationReference { + return false + } + + if other.peerGeoLocation != self.peerGeoLocation { + return false + } + + if other.slowModeTimeout != self.slowModeTimeout { + return false + } + + if other.slowModeValidUntilTimestamp != self.slowModeValidUntilTimestamp { + return false + } + + return true + } +} diff --git a/submodules/TelegramCore/TelegramCore/CachedGroupData.swift b/submodules/SyncCore/Sources/CachedGroupData.swift similarity index 92% rename from submodules/TelegramCore/TelegramCore/CachedGroupData.swift rename to submodules/SyncCore/Sources/CachedGroupData.swift index 36c4fe6c9e..50349f4828 100644 --- a/submodules/TelegramCore/TelegramCore/CachedGroupData.swift +++ b/submodules/SyncCore/Sources/CachedGroupData.swift @@ -9,7 +9,7 @@ public final class CachedPeerBotInfo: PostboxCoding, Equatable { public let peerId: PeerId public let botInfo: BotInfo - init(peerId: PeerId, botInfo: BotInfo) { + public init(peerId: PeerId, botInfo: BotInfo) { self.peerId = peerId self.botInfo = botInfo } @@ -57,7 +57,7 @@ public final class CachedGroupData: CachedPeerData { public let messageIds: Set public let associatedHistoryMessageId: MessageId? = nil - init() { + public init() { self.participants = nil self.exportedInvitation = nil self.botInfos = [] @@ -179,35 +179,35 @@ public final class CachedGroupData: CachedPeerData { return self.participants == other.participants && self.exportedInvitation == other.exportedInvitation && self.botInfos == other.botInfos && self.peerStatusSettings == other.peerStatusSettings && self.pinnedMessageId == other.pinnedMessageId && self.about == other.about && self.flags == other.flags && self.hasScheduledMessages == other.hasScheduledMessages } - func withUpdatedParticipants(_ participants: CachedGroupParticipants?) -> CachedGroupData { + public func withUpdatedParticipants(_ participants: CachedGroupParticipants?) -> CachedGroupData { return CachedGroupData(participants: participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, about: self.about, flags: self.flags, hasScheduledMessages: self.hasScheduledMessages) } - func withUpdatedExportedInvitation(_ exportedInvitation: ExportedInvitation?) -> CachedGroupData { + public func withUpdatedExportedInvitation(_ exportedInvitation: ExportedInvitation?) -> CachedGroupData { return CachedGroupData(participants: self.participants, exportedInvitation: exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, about: self.about, flags: self.flags, hasScheduledMessages: self.hasScheduledMessages) } - func withUpdatedBotInfos(_ botInfos: [CachedPeerBotInfo]) -> CachedGroupData { + public func withUpdatedBotInfos(_ botInfos: [CachedPeerBotInfo]) -> CachedGroupData { return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, about: self.about, flags: self.flags, hasScheduledMessages: self.hasScheduledMessages) } - func withUpdatedPeerStatusSettings(_ peerStatusSettings: PeerStatusSettings?) -> CachedGroupData { + public func withUpdatedPeerStatusSettings(_ peerStatusSettings: PeerStatusSettings?) -> CachedGroupData { return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: peerStatusSettings, pinnedMessageId: self.pinnedMessageId, about: self.about, flags: self.flags, hasScheduledMessages: self.hasScheduledMessages) } - func withUpdatedPinnedMessageId(_ pinnedMessageId: MessageId?) -> CachedGroupData { + public func withUpdatedPinnedMessageId(_ pinnedMessageId: MessageId?) -> CachedGroupData { return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: pinnedMessageId, about: self.about, flags: self.flags, hasScheduledMessages: self.hasScheduledMessages) } - func withUpdatedAbout(_ about: String?) -> CachedGroupData { + public func withUpdatedAbout(_ about: String?) -> CachedGroupData { return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, about: about, flags: self.flags, hasScheduledMessages: self.hasScheduledMessages) } - func withUpdatedFlags(_ flags: CachedGroupFlags) -> CachedGroupData { + public func withUpdatedFlags(_ flags: CachedGroupFlags) -> CachedGroupData { return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, about: self.about, flags: flags, hasScheduledMessages: self.hasScheduledMessages) } - func withUpdatedHasScheduledMessages(_ hasScheduledMessages: Bool) -> CachedGroupData { + public func withUpdatedHasScheduledMessages(_ hasScheduledMessages: Bool) -> CachedGroupData { return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, about: self.about, flags: self.flags, hasScheduledMessages: hasScheduledMessages) } } diff --git a/submodules/SyncCore/Sources/CachedGroupParticipants.swift b/submodules/SyncCore/Sources/CachedGroupParticipants.swift new file mode 100644 index 0000000000..95f875a494 --- /dev/null +++ b/submodules/SyncCore/Sources/CachedGroupParticipants.swift @@ -0,0 +1,84 @@ +import Postbox + +public enum GroupParticipant: PostboxCoding, Equatable { + case member(id: PeerId, invitedBy: PeerId, invitedAt: Int32) + case creator(id: PeerId) + case admin(id: PeerId, invitedBy: PeerId, invitedAt: Int32) + + public var peerId: PeerId { + switch self { + case let .member(id, _, _): + return id + case let .creator(id): + return id + case let .admin(id, _, _): + return id + } + } + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("v", orElse: 0) { + case 0: + self = .member(id: PeerId(decoder.decodeInt64ForKey("i", orElse: 0)), invitedBy: PeerId(decoder.decodeInt64ForKey("b", orElse: 0)), invitedAt: decoder.decodeInt32ForKey("t", orElse: 0)) + case 1: + self = .creator(id: PeerId(decoder.decodeInt64ForKey("i", orElse: 0))) + case 2: + self = .admin(id: PeerId(decoder.decodeInt64ForKey("i", orElse: 0)), invitedBy: PeerId(decoder.decodeInt64ForKey("b", orElse: 0)), invitedAt: decoder.decodeInt32ForKey("t", orElse: 0)) + default: + self = .member(id: PeerId(decoder.decodeInt64ForKey("i", orElse: 0)), invitedBy: PeerId(decoder.decodeInt64ForKey("b", orElse: 0)), invitedAt: decoder.decodeInt32ForKey("t", orElse: 0)) + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .member(id, invitedBy, invitedAt): + encoder.encodeInt32(0, forKey: "v") + encoder.encodeInt64(id.toInt64(), forKey: "i") + encoder.encodeInt64(invitedBy.toInt64(), forKey: "b") + encoder.encodeInt32(invitedAt, forKey: "t") + case let .creator(id): + encoder.encodeInt32(1, forKey: "v") + encoder.encodeInt64(id.toInt64(), forKey: "i") + case let .admin(id, invitedBy, invitedAt): + encoder.encodeInt32(2, forKey: "v") + encoder.encodeInt64(id.toInt64(), forKey: "i") + encoder.encodeInt64(invitedBy.toInt64(), forKey: "b") + encoder.encodeInt32(invitedAt, forKey: "t") + } + } + + public var invitedBy: PeerId { + switch self { + case let .admin(_, invitedBy, _): + return invitedBy + case let .member(_, invitedBy, _): + return invitedBy + case let .creator(id): + return id + } + } +} + +public final class CachedGroupParticipants: PostboxCoding, Equatable { + public let participants: [GroupParticipant] + public let version: Int32 + + public init(participants: [GroupParticipant], version: Int32) { + self.participants = participants + self.version = version + } + + public init(decoder: PostboxDecoder) { + self.participants = decoder.decodeObjectArrayWithDecoderForKey("p") + self.version = decoder.decodeInt32ForKey("v", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObjectArray(self.participants, forKey: "p") + encoder.encodeInt32(self.version, forKey: "v") + } + + public static func ==(lhs: CachedGroupParticipants, rhs: CachedGroupParticipants) -> Bool { + return lhs.version == rhs.version && lhs.participants == rhs.participants + } +} diff --git a/submodules/SyncCore/Sources/CachedLocalizationInfos.swift b/submodules/SyncCore/Sources/CachedLocalizationInfos.swift new file mode 100644 index 0000000000..9026af12b2 --- /dev/null +++ b/submodules/SyncCore/Sources/CachedLocalizationInfos.swift @@ -0,0 +1,17 @@ +import Postbox + +public final class CachedLocalizationInfos: PostboxCoding { + public let list: [LocalizationInfo] + + public init(list: [LocalizationInfo]) { + self.list = list + } + + public init(decoder: PostboxDecoder) { + self.list = decoder.decodeObjectArrayWithDecoderForKey("l") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObjectArray(self.list, forKey: "l") + } +} diff --git a/submodules/SyncCore/Sources/CachedRecentPeers.swift b/submodules/SyncCore/Sources/CachedRecentPeers.swift new file mode 100644 index 0000000000..0ac338c6b6 --- /dev/null +++ b/submodules/SyncCore/Sources/CachedRecentPeers.swift @@ -0,0 +1,26 @@ +import Postbox + +public final class CachedRecentPeers: PostboxCoding { + public let enabled: Bool + public let ids: [PeerId] + + public init(enabled: Bool, ids: [PeerId]) { + self.enabled = enabled + self.ids = ids + } + + public init(decoder: PostboxDecoder) { + self.enabled = decoder.decodeInt32ForKey("enabled", orElse: 0) != 0 + self.ids = decoder.decodeInt64ArrayForKey("ids").map(PeerId.init) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.enabled ? 1 : 0, forKey: "enabled") + encoder.encodeInt64Array(self.ids.map({ $0.toInt64() }), forKey: "ids") + } + + public static func cacheKey() -> ValueBoxKey { + let key = ValueBoxKey(length: 0) + return key + } +} diff --git a/submodules/SyncCore/Sources/CachedResolvedByNamePeer.swift b/submodules/SyncCore/Sources/CachedResolvedByNamePeer.swift new file mode 100644 index 0000000000..b0946c5611 --- /dev/null +++ b/submodules/SyncCore/Sources/CachedResolvedByNamePeer.swift @@ -0,0 +1,42 @@ +import Postbox + +public final class CachedResolvedByNamePeer: PostboxCoding { + public let peerId: PeerId? + public let timestamp: Int32 + + public static func key(name: String) -> ValueBoxKey { + let key: ValueBoxKey + if let nameData = name.data(using: .utf8) { + key = ValueBoxKey(length: nameData.count) + nameData.withUnsafeBytes { (bytes: UnsafePointer) -> Void in + memcpy(key.memory, bytes, nameData.count) + } + } else { + key = ValueBoxKey(length: 0) + } + return key + } + + public init(peerId: PeerId?, timestamp: Int32) { + self.peerId = peerId + self.timestamp = timestamp + } + + public init(decoder: PostboxDecoder) { + if let peerId = decoder.decodeOptionalInt64ForKey("p") { + self.peerId = PeerId(peerId) + } else { + self.peerId = nil + } + self.timestamp = decoder.decodeInt32ForKey("t", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + if let peerId = self.peerId { + encoder.encodeInt64(peerId.toInt64(), forKey: "p") + } else { + encoder.encodeNil(forKey: "p") + } + encoder.encodeInt32(self.timestamp, forKey: "t") + } +} diff --git a/submodules/SyncCore/Sources/CachedSecureIdConfiguration.swift b/submodules/SyncCore/Sources/CachedSecureIdConfiguration.swift new file mode 100644 index 0000000000..e93cf426f2 --- /dev/null +++ b/submodules/SyncCore/Sources/CachedSecureIdConfiguration.swift @@ -0,0 +1,39 @@ +import Postbox + +public struct SecureIdConfiguration: PostboxCoding { + public let nativeLanguageByCountry: [String: String] + + public init(jsonString: String) { + self.nativeLanguageByCountry = (try? JSONDecoder().decode(Dictionary.self, from: jsonString.data(using: .utf8) ?? Data())) ?? [:] + } + + public init(decoder: PostboxDecoder) { + let nativeLanguageByCountryData = decoder.decodeBytesForKey("nativeLanguageByCountry")! + self.nativeLanguageByCountry = (try? JSONDecoder().decode(Dictionary.self, from: nativeLanguageByCountryData.dataNoCopy())) ?? [:] + } + + public func encode(_ encoder: PostboxEncoder) { + let nativeLanguageByCountryData = (try? JSONEncoder().encode(self.nativeLanguageByCountry)) ?? Data() + encoder.encodeBytes(MemoryBuffer(data: nativeLanguageByCountryData), forKey: "nativeLanguageByCountry") + } +} + +public final class CachedSecureIdConfiguration: PostboxCoding { + public let value: SecureIdConfiguration + public let hash: Int32 + + public init(value: SecureIdConfiguration, hash: Int32) { + self.value = value + self.hash = hash + } + + public init(decoder: PostboxDecoder) { + self.value = decoder.decodeObjectForKey("value", decoder: { SecureIdConfiguration(decoder: $0) }) as! SecureIdConfiguration + self.hash = decoder.decodeInt32ForKey("hash", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObject(self.value, forKey: "value") + encoder.encodeInt32(self.hash, forKey: "hash") + } +} diff --git a/submodules/SyncCore/Sources/CachedStickerPack.swift b/submodules/SyncCore/Sources/CachedStickerPack.swift new file mode 100644 index 0000000000..ea4f51d4e6 --- /dev/null +++ b/submodules/SyncCore/Sources/CachedStickerPack.swift @@ -0,0 +1,40 @@ +import Postbox + +public final class CachedStickerPack: PostboxCoding { + public let info: StickerPackCollectionInfo? + public let items: [StickerPackItem] + public let hash: Int32 + + public init(info: StickerPackCollectionInfo?, items: [StickerPackItem], hash: Int32) { + self.info = info + self.items = items + self.hash = hash + } + + public init(decoder: PostboxDecoder) { + self.info = decoder.decodeObjectForKey("in", decoder: { StickerPackCollectionInfo(decoder: $0) }) as? StickerPackCollectionInfo + self.items = decoder.decodeObjectArrayForKey("it").map { $0 as! StickerPackItem } + self.hash = decoder.decodeInt32ForKey("h", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + if let info = self.info { + encoder.encodeObject(info, forKey: "in") + } else { + encoder.encodeNil(forKey: "in") + } + encoder.encodeObjectArray(self.items, forKey: "it") + encoder.encodeInt32(self.hash, forKey: "h") + } + + public static func cacheKey(_ id: ItemCollectionId) -> ValueBoxKey { + let key = ValueBoxKey(length: 4 + 8) + key.setInt32(0, value: id.namespace) + key.setInt64(4, value: id.id) + return key + } + + public static func cacheKey(shortName: String) -> ValueBoxKey { + return ValueBoxKey(shortName) + } +} diff --git a/submodules/SyncCore/Sources/CachedStickerQueryResult.swift b/submodules/SyncCore/Sources/CachedStickerQueryResult.swift new file mode 100644 index 0000000000..ea43bda4fd --- /dev/null +++ b/submodules/SyncCore/Sources/CachedStickerQueryResult.swift @@ -0,0 +1,26 @@ +import Postbox + +public final class CachedStickerQueryResult: PostboxCoding { + public let items: [TelegramMediaFile] + public let hash: Int32 + + public init(items: [TelegramMediaFile], hash: Int32) { + self.items = items + self.hash = hash + } + + public init(decoder: PostboxDecoder) { + self.items = decoder.decodeObjectArrayForKey("it").map { $0 as! TelegramMediaFile } + self.hash = decoder.decodeInt32ForKey("h", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObjectArray(self.items, forKey: "it") + encoder.encodeInt32(self.hash, forKey: "h") + } + + public static func cacheKey(_ query: String) -> ValueBoxKey { + let key = ValueBoxKey(query) + return key + } +} diff --git a/submodules/SyncCore/Sources/CachedThemesConfiguration.swift b/submodules/SyncCore/Sources/CachedThemesConfiguration.swift new file mode 100644 index 0000000000..f8e473bbfd --- /dev/null +++ b/submodules/SyncCore/Sources/CachedThemesConfiguration.swift @@ -0,0 +1,17 @@ +import Postbox + +public final class CachedThemesConfiguration: PostboxCoding { + public let hash: Int32 + + public init(hash: Int32) { + self.hash = hash + } + + public init(decoder: PostboxDecoder) { + self.hash = decoder.decodeInt32ForKey("hash", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.hash, forKey: "hash") + } +} diff --git a/submodules/TelegramCore/TelegramCore/CachedUserData.swift b/submodules/SyncCore/Sources/CachedUserData.swift similarity index 88% rename from submodules/TelegramCore/TelegramCore/CachedUserData.swift rename to submodules/SyncCore/Sources/CachedUserData.swift index d5b4de8c30..56d878b1ac 100644 --- a/submodules/TelegramCore/TelegramCore/CachedUserData.swift +++ b/submodules/SyncCore/Sources/CachedUserData.swift @@ -21,7 +21,7 @@ public final class CachedUserData: CachedPeerData { public let messageIds: Set public let associatedHistoryMessageId: MessageId? = nil - init() { + public init() { self.about = nil self.botInfo = nil self.peerStatusSettings = nil @@ -35,7 +35,7 @@ public final class CachedUserData: CachedPeerData { self.messageIds = Set() } - init(about: String?, botInfo: BotInfo?, peerStatusSettings: PeerStatusSettings?, pinnedMessageId: MessageId?, isBlocked: Bool, commonGroupCount: Int32, callsAvailable: Bool, callsPrivate: Bool, canPinMessages: Bool, hasScheduledMessages: Bool) { + public init(about: String?, botInfo: BotInfo?, peerStatusSettings: PeerStatusSettings?, pinnedMessageId: MessageId?, isBlocked: Bool, commonGroupCount: Int32, callsAvailable: Bool, callsPrivate: Bool, canPinMessages: Bool, hasScheduledMessages: Bool) { self.about = about self.botInfo = botInfo self.peerStatusSettings = peerStatusSettings @@ -128,43 +128,43 @@ public final class CachedUserData: CachedPeerData { return other.about == self.about && other.botInfo == self.botInfo && self.peerStatusSettings == other.peerStatusSettings && self.isBlocked == other.isBlocked && self.commonGroupCount == other.commonGroupCount && self.callsAvailable == other.callsAvailable && self.callsPrivate == other.callsPrivate && self.hasScheduledMessages == other.hasScheduledMessages } - func withUpdatedAbout(_ about: String?) -> CachedUserData { + public func withUpdatedAbout(_ about: String?) -> CachedUserData { return CachedUserData(about: about, botInfo: self.botInfo, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages, hasScheduledMessages: self.hasScheduledMessages) } - func withUpdatedBotInfo(_ botInfo: BotInfo?) -> CachedUserData { + public func withUpdatedBotInfo(_ botInfo: BotInfo?) -> CachedUserData { return CachedUserData(about: self.about, botInfo: botInfo, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages, hasScheduledMessages: self.hasScheduledMessages) } - func withUpdatedPeerStatusSettings(_ peerStatusSettings: PeerStatusSettings) -> CachedUserData { + public func withUpdatedPeerStatusSettings(_ peerStatusSettings: PeerStatusSettings) -> CachedUserData { return CachedUserData(about: self.about, botInfo: self.botInfo, peerStatusSettings: peerStatusSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages, hasScheduledMessages: self.hasScheduledMessages) } - func withUpdatedPinnedMessageId(_ pinnedMessageId: MessageId?) -> CachedUserData { + public func withUpdatedPinnedMessageId(_ pinnedMessageId: MessageId?) -> CachedUserData { return CachedUserData(about: self.about, botInfo: self.botInfo, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages, hasScheduledMessages: self.hasScheduledMessages) } - func withUpdatedIsBlocked(_ isBlocked: Bool) -> CachedUserData { + public func withUpdatedIsBlocked(_ isBlocked: Bool) -> CachedUserData { return CachedUserData(about: self.about, botInfo: self.botInfo, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages, hasScheduledMessages: self.hasScheduledMessages) } - func withUpdatedCommonGroupCount(_ commonGroupCount: Int32) -> CachedUserData { + public func withUpdatedCommonGroupCount(_ commonGroupCount: Int32) -> CachedUserData { return CachedUserData(about: self.about, botInfo: self.botInfo, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages, hasScheduledMessages: self.hasScheduledMessages) } - func withUpdatedCallsAvailable(_ callsAvailable: Bool) -> CachedUserData { + public func withUpdatedCallsAvailable(_ callsAvailable: Bool) -> CachedUserData { return CachedUserData(about: self.about, botInfo: self.botInfo, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages, hasScheduledMessages: self.hasScheduledMessages) } - func withUpdatedCallsPrivate(_ callsPrivate: Bool) -> CachedUserData { + public func withUpdatedCallsPrivate(_ callsPrivate: Bool) -> CachedUserData { return CachedUserData(about: self.about, botInfo: self.botInfo, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: callsPrivate, canPinMessages: self.canPinMessages, hasScheduledMessages: self.hasScheduledMessages) } - func withUpdatedCanPinMessages(_ canPinMessages: Bool) -> CachedUserData { + public func withUpdatedCanPinMessages(_ canPinMessages: Bool) -> CachedUserData { return CachedUserData(about: self.about, botInfo: self.botInfo, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: canPinMessages, hasScheduledMessages: self.hasScheduledMessages) } - func withUpdatedHasScheduledMessages(_ hasScheduledMessages: Bool) -> CachedUserData { + public func withUpdatedHasScheduledMessages(_ hasScheduledMessages: Bool) -> CachedUserData { return CachedUserData(about: self.about, botInfo: self.botInfo, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages, hasScheduledMessages: hasScheduledMessages) } } diff --git a/submodules/SyncCore/Sources/CachedWallpapersConfiguration.swift b/submodules/SyncCore/Sources/CachedWallpapersConfiguration.swift new file mode 100644 index 0000000000..fa22f16806 --- /dev/null +++ b/submodules/SyncCore/Sources/CachedWallpapersConfiguration.swift @@ -0,0 +1,17 @@ +import Postbox + +public final class CachedWallpapersConfiguration: PostboxCoding { + public let hash: Int32 + + public init(hash: Int32) { + self.hash = hash + } + + public init(decoder: PostboxDecoder) { + self.hash = decoder.decodeInt32ForKey("hash", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.hash, forKey: "hash") + } +} diff --git a/submodules/TelegramCore/TelegramCore/ChannelMessageStateVersionAttribute.swift b/submodules/SyncCore/Sources/ChannelMessageStateVersionAttribute.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/ChannelMessageStateVersionAttribute.swift rename to submodules/SyncCore/Sources/ChannelMessageStateVersionAttribute.swift diff --git a/submodules/SyncCore/Sources/ChannelState.swift b/submodules/SyncCore/Sources/ChannelState.swift new file mode 100644 index 0000000000..a4dd98fc50 --- /dev/null +++ b/submodules/SyncCore/Sources/ChannelState.swift @@ -0,0 +1,48 @@ +import Postbox + +public final class ChannelState: PeerChatState, Equatable, CustomStringConvertible { + public let pts: Int32 + public let invalidatedPts: Int32? + + public init(pts: Int32, invalidatedPts: Int32?) { + self.pts = pts + self.invalidatedPts = invalidatedPts + } + + public init(decoder: PostboxDecoder) { + self.pts = decoder.decodeInt32ForKey("pts", orElse: 0) + self.invalidatedPts = decoder.decodeOptionalInt32ForKey("ipts") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.pts, forKey: "pts") + if let invalidatedPts = self.invalidatedPts { + encoder.encodeInt32(invalidatedPts, forKey: "ipts") + } else { + encoder.encodeNil(forKey: "ipts") + } + } + + public func withUpdatedPts(_ pts: Int32) -> ChannelState { + return ChannelState(pts: pts, invalidatedPts: self.invalidatedPts) + } + + public func withUpdatedInvalidatedPts(_ invalidatedPts: Int32?) -> ChannelState { + return ChannelState(pts: self.pts, invalidatedPts: invalidatedPts) + } + + public func equals(_ other: PeerChatState) -> Bool { + if let other = other as? ChannelState, other == self { + return true + } + return false + } + + public var description: String { + return "(pts: \(self.pts))" + } + + public static func ==(lhs: ChannelState, rhs: ChannelState) -> Bool { + return lhs.pts == rhs.pts && lhs.invalidatedPts == rhs.invalidatedPts + } +} diff --git a/submodules/SyncCore/Sources/CloudChatRemoveMessagesOperation.swift b/submodules/SyncCore/Sources/CloudChatRemoveMessagesOperation.swift new file mode 100644 index 0000000000..e022318bba --- /dev/null +++ b/submodules/SyncCore/Sources/CloudChatRemoveMessagesOperation.swift @@ -0,0 +1,140 @@ +import Foundation +#if os(macOS) + import PostboxMac +#else + import Postbox +#endif + +public enum InteractiveMessagesDeletionType: Int32 { + case forLocalPeer = 0 + case forEveryone = 1 +} + +public enum CloudChatRemoveMessagesType: Int32 { + case forLocalPeer + case forEveryone +} + +public extension CloudChatRemoveMessagesType { + init(_ type: InteractiveMessagesDeletionType) { + switch type { + case .forLocalPeer: + self = .forLocalPeer + case .forEveryone: + self = .forEveryone + } + } +} + +public final class CloudChatRemoveMessagesOperation: PostboxCoding { + public let messageIds: [MessageId] + public let type: CloudChatRemoveMessagesType + + public init(messageIds: [MessageId], type: CloudChatRemoveMessagesType) { + self.messageIds = messageIds + self.type = type + } + + public init(decoder: PostboxDecoder) { + self.messageIds = MessageId.decodeArrayFromBuffer(decoder.decodeBytesForKeyNoCopy("i")!) + self.type = CloudChatRemoveMessagesType(rawValue: decoder.decodeInt32ForKey("t", orElse: 0))! + } + + public func encode(_ encoder: PostboxEncoder) { + let buffer = WriteBuffer() + MessageId.encodeArrayToBuffer(self.messageIds, buffer: buffer) + encoder.encodeBytes(buffer, forKey: "i") + encoder.encodeInt32(self.type.rawValue, forKey: "t") + } +} + +public final class CloudChatRemoveChatOperation: PostboxCoding { + public let peerId: PeerId + public let reportChatSpam: Bool + public let deleteGloballyIfPossible: Bool + public let topMessageId: MessageId? + + public init(peerId: PeerId, reportChatSpam: Bool, deleteGloballyIfPossible: Bool, topMessageId: MessageId?) { + self.peerId = peerId + self.reportChatSpam = reportChatSpam + self.deleteGloballyIfPossible = deleteGloballyIfPossible + self.topMessageId = topMessageId + } + + public init(decoder: PostboxDecoder) { + self.peerId = PeerId(decoder.decodeInt64ForKey("p", orElse: 0)) + self.reportChatSpam = decoder.decodeInt32ForKey("r", orElse: 0) != 0 + self.deleteGloballyIfPossible = decoder.decodeInt32ForKey("deleteGloballyIfPossible", orElse: 0) != 0 + if let messageIdPeerId = decoder.decodeOptionalInt64ForKey("m.p"), let messageIdNamespace = decoder.decodeOptionalInt32ForKey("m.n"), let messageIdId = decoder.decodeOptionalInt32ForKey("m.i") { + self.topMessageId = MessageId(peerId: PeerId(messageIdPeerId), namespace: messageIdNamespace, id: messageIdId) + } else { + self.topMessageId = nil + } + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt64(self.peerId.toInt64(), forKey: "p") + encoder.encodeInt32(self.reportChatSpam ? 1 : 0, forKey: "r") + encoder.encodeInt32(self.deleteGloballyIfPossible ? 1 : 0, forKey: "deleteGloballyIfPossible") + if let topMessageId = self.topMessageId { + encoder.encodeInt64(topMessageId.peerId.toInt64(), forKey: "m.p") + encoder.encodeInt32(topMessageId.namespace, forKey: "m.n") + encoder.encodeInt32(topMessageId.id, forKey: "m.i") + } else { + encoder.encodeNil(forKey: "m.p") + encoder.encodeNil(forKey: "m.n") + encoder.encodeNil(forKey: "m.i") + } + } +} + +public enum CloudChatClearHistoryType: Int32 { + case forLocalPeer + case forEveryone + case scheduledMessages +} + +public enum InteractiveHistoryClearingType: Int32 { + case forLocalPeer = 0 + case forEveryone = 1 + case scheduledMessages = 2 +} + +public extension CloudChatClearHistoryType { + init(_ type: InteractiveHistoryClearingType) { + switch type { + case .forLocalPeer: + self = .forLocalPeer + case .forEveryone: + self = .forEveryone + case .scheduledMessages: + self = .scheduledMessages + } + } +} + +public final class CloudChatClearHistoryOperation: PostboxCoding { + public let peerId: PeerId + public let topMessageId: MessageId + public let type: CloudChatClearHistoryType + + public init(peerId: PeerId, topMessageId: MessageId, type: CloudChatClearHistoryType) { + self.peerId = peerId + self.topMessageId = topMessageId + self.type = type + } + + public init(decoder: PostboxDecoder) { + self.peerId = PeerId(decoder.decodeInt64ForKey("p", orElse: 0)) + self.topMessageId = MessageId(peerId: PeerId(decoder.decodeInt64ForKey("m.p", orElse: 0)), namespace: decoder.decodeInt32ForKey("m.n", orElse: 0), id: decoder.decodeInt32ForKey("m.i", orElse: 0)) + self.type = CloudChatClearHistoryType(rawValue: decoder.decodeInt32ForKey("type", orElse: 0)) ?? .forLocalPeer + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt64(self.peerId.toInt64(), forKey: "p") + encoder.encodeInt64(self.topMessageId.peerId.toInt64(), forKey: "m.p") + encoder.encodeInt32(self.topMessageId.namespace, forKey: "m.n") + encoder.encodeInt32(self.topMessageId.id, forKey: "m.i") + encoder.encodeInt32(self.type.rawValue, forKey: "type") + } +} diff --git a/submodules/SyncCore/Sources/CloudFileMediaResource.swift b/submodules/SyncCore/Sources/CloudFileMediaResource.swift new file mode 100644 index 0000000000..675c85f58a --- /dev/null +++ b/submodules/SyncCore/Sources/CloudFileMediaResource.swift @@ -0,0 +1,843 @@ +import Postbox + +public struct CloudFileMediaResourceId: MediaResourceId { + let datacenterId: Int + let volumeId: Int64 + let localId: Int32 + let secret: Int64 + + init(datacenterId: Int, volumeId: Int64, localId: Int32, secret: Int64) { + self.datacenterId = datacenterId + self.volumeId = volumeId + self.localId = localId + self.secret = secret + } + + public var uniqueId: String { + return "telegram-cloud-file-\(self.datacenterId)-\(self.volumeId)-\(self.localId)-\(self.secret)" + } + + public var hashValue: Int { + return self.secret.hashValue + } + + public func isEqual(to: MediaResourceId) -> Bool { + if let to = to as? CloudFileMediaResourceId { + return self.datacenterId == to.datacenterId && self.volumeId == to.volumeId && self.localId == to.localId && self.secret == to.secret + } else { + return false + } + } +} + +public final class CloudFileMediaResource: TelegramMediaResource { + public let datacenterId: Int + public let volumeId: Int64 + public let localId: Int32 + public let secret: Int64 + public let size: Int? + public let fileReference: Data? + + public var id: MediaResourceId { + return CloudFileMediaResourceId(datacenterId: self.datacenterId, volumeId: self.volumeId, localId: self.localId, secret: self.secret) + } + + public init(datacenterId: Int, volumeId: Int64, localId: Int32, secret: Int64, size: Int?, fileReference: Data?) { + self.datacenterId = datacenterId + self.volumeId = volumeId + self.localId = localId + self.secret = secret + self.size = size + self.fileReference = fileReference + } + + public required init(decoder: PostboxDecoder) { + self.datacenterId = Int(decoder.decodeInt32ForKey("d", orElse: 0)) + self.volumeId = decoder.decodeInt64ForKey("v", orElse: 0) + self.localId = decoder.decodeInt32ForKey("l", orElse: 0) + self.secret = decoder.decodeInt64ForKey("s", orElse: 0) + if let size = decoder.decodeOptionalInt32ForKey("n") { + self.size = Int(size) + } else { + self.size = nil + } + self.fileReference = decoder.decodeBytesForKey("fr")?.makeData() + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(Int32(self.datacenterId), forKey: "d") + encoder.encodeInt64(self.volumeId, forKey: "v") + encoder.encodeInt32(self.localId, forKey: "l") + encoder.encodeInt64(self.secret, forKey: "s") + if let size = self.size { + encoder.encodeInt32(Int32(size), forKey: "n") + } else { + encoder.encodeNil(forKey: "n") + } + if let fileReference = self.fileReference { + encoder.encodeBytes(MemoryBuffer(data: fileReference), forKey: "fr") + } else { + encoder.encodeNil(forKey: "fr") + } + } + + public func isEqual(to: MediaResource) -> Bool { + if let to = to as? CloudFileMediaResource { + return self.datacenterId == to.datacenterId && self.volumeId == to.volumeId && self.localId == to.localId && self.secret == to.secret && self.size == to.size && self.fileReference == to.fileReference + } else { + return false + } + } +} + +public struct CloudPhotoSizeMediaResourceId: MediaResourceId, Hashable { + let datacenterId: Int32 + let photoId: Int64 + let sizeSpec: String + + init(datacenterId: Int32, photoId: Int64, sizeSpec: String) { + self.datacenterId = datacenterId + self.photoId = photoId + self.sizeSpec = sizeSpec + } + + public var uniqueId: String { + return "telegram-cloud-photo-size-\(self.datacenterId)-\(self.photoId)-\(self.sizeSpec)" + } + + public func isEqual(to: MediaResourceId) -> Bool { + if let to = to as? CloudPhotoSizeMediaResourceId { + return self.datacenterId == to.datacenterId && self.photoId == to.photoId && self.sizeSpec == to.sizeSpec + } else { + return false + } + } +} + +public final class CloudPhotoSizeMediaResource: TelegramMediaResource { + public let datacenterId: Int + public let photoId: Int64 + public let accessHash: Int64 + public let sizeSpec: String + public let volumeId: Int64 + public let localId: Int32 + public let fileReference: Data? + + public var id: MediaResourceId { + return CloudPhotoSizeMediaResourceId(datacenterId: Int32(self.datacenterId), photoId: self.photoId, sizeSpec: self.sizeSpec) + } + + public init(datacenterId: Int32, photoId: Int64, accessHash: Int64, sizeSpec: String, volumeId: Int64, localId: Int32, fileReference: Data?) { + self.datacenterId = Int(datacenterId) + self.photoId = photoId + self.accessHash = accessHash + self.sizeSpec = sizeSpec + self.volumeId = volumeId + self.localId = localId + self.fileReference = fileReference + } + + public required init(decoder: PostboxDecoder) { + self.datacenterId = Int(decoder.decodeInt32ForKey("d", orElse: 0)) + self.photoId = decoder.decodeInt64ForKey("i", orElse: 0) + self.accessHash = decoder.decodeInt64ForKey("h", orElse: 0) + self.sizeSpec = decoder.decodeStringForKey("s", orElse: "") + self.volumeId = decoder.decodeInt64ForKey("v", orElse: 0) + self.localId = decoder.decodeInt32ForKey("l", orElse: 0) + self.fileReference = decoder.decodeBytesForKey("fr")?.makeData() + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(Int32(self.datacenterId), forKey: "d") + encoder.encodeInt64(self.photoId, forKey: "i") + encoder.encodeInt64(self.accessHash, forKey: "h") + encoder.encodeString(self.sizeSpec, forKey: "s") + encoder.encodeInt64(self.volumeId, forKey: "v") + encoder.encodeInt32(self.localId, forKey: "l") + if let fileReference = self.fileReference { + encoder.encodeBytes(MemoryBuffer(data: fileReference), forKey: "fr") + } else { + encoder.encodeNil(forKey: "fr") + } + } + + public func isEqual(to: MediaResource) -> Bool { + if let to = to as? CloudPhotoSizeMediaResource { + return self.datacenterId == to.datacenterId && self.photoId == to.photoId && self.accessHash == to.accessHash && self.sizeSpec == to.sizeSpec && self.volumeId == to.volumeId && self.localId == to.localId && self.fileReference == to.fileReference + } else { + return false + } + } +} + +public struct CloudDocumentSizeMediaResourceId: MediaResourceId, Hashable { + let datacenterId: Int32 + let documentId: Int64 + let sizeSpec: String + + init(datacenterId: Int32, documentId: Int64, sizeSpec: String) { + self.datacenterId = datacenterId + self.documentId = documentId + self.sizeSpec = sizeSpec + } + + public var uniqueId: String { + return "telegram-cloud-document-size-\(self.datacenterId)-\(self.documentId)-\(self.sizeSpec)" + } + + public func isEqual(to: MediaResourceId) -> Bool { + if let to = to as? CloudDocumentSizeMediaResourceId { + return self.datacenterId == to.datacenterId && self.documentId == to.documentId && self.sizeSpec == to.sizeSpec + } else { + return false + } + } +} + +public final class CloudDocumentSizeMediaResource: TelegramMediaResource { + public let datacenterId: Int + public let documentId: Int64 + public let accessHash: Int64 + public let sizeSpec: String + public let volumeId: Int64 + public let localId: Int32 + public let fileReference: Data? + + public var id: MediaResourceId { + return CloudDocumentSizeMediaResourceId(datacenterId: Int32(self.datacenterId), documentId: self.documentId, sizeSpec: self.sizeSpec) + } + + public init(datacenterId: Int32, documentId: Int64, accessHash: Int64, sizeSpec: String, volumeId: Int64, localId: Int32, fileReference: Data?) { + self.datacenterId = Int(datacenterId) + self.documentId = documentId + self.accessHash = accessHash + self.sizeSpec = sizeSpec + self.volumeId = volumeId + self.localId = localId + self.fileReference = fileReference + } + + public required init(decoder: PostboxDecoder) { + self.datacenterId = Int(decoder.decodeInt32ForKey("d", orElse: 0)) + self.documentId = decoder.decodeInt64ForKey("i", orElse: 0) + self.accessHash = decoder.decodeInt64ForKey("h", orElse: 0) + self.sizeSpec = decoder.decodeStringForKey("s", orElse: "") + self.volumeId = decoder.decodeInt64ForKey("v", orElse: 0) + self.localId = decoder.decodeInt32ForKey("l", orElse: 0) + self.fileReference = decoder.decodeBytesForKey("fr")?.makeData() + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(Int32(self.datacenterId), forKey: "d") + encoder.encodeInt64(self.documentId, forKey: "i") + encoder.encodeInt64(self.accessHash, forKey: "h") + encoder.encodeString(self.sizeSpec, forKey: "s") + encoder.encodeInt64(self.volumeId, forKey: "v") + encoder.encodeInt32(self.localId, forKey: "l") + if let fileReference = self.fileReference { + encoder.encodeBytes(MemoryBuffer(data: fileReference), forKey: "fr") + } else { + encoder.encodeNil(forKey: "fr") + } + } + + public func isEqual(to: MediaResource) -> Bool { + if let to = to as? CloudDocumentSizeMediaResource { + return self.datacenterId == to.datacenterId && self.documentId == to.documentId && self.accessHash == to.accessHash && self.sizeSpec == to.sizeSpec && self.volumeId == to.volumeId && self.localId == to.localId && self.fileReference == to.fileReference + } else { + return false + } + } +} + +public enum CloudPeerPhotoSizeSpec: Int32 { + case small + case fullSize +} + +public struct CloudPeerPhotoSizeMediaResourceId: MediaResourceId, Hashable { + let datacenterId: Int32 + let sizeSpec: CloudPeerPhotoSizeSpec + let volumeId: Int64 + let localId: Int32 + + init(datacenterId: Int32, sizeSpec: CloudPeerPhotoSizeSpec, volumeId: Int64, localId: Int32) { + self.datacenterId = datacenterId + self.sizeSpec = sizeSpec + self.volumeId = volumeId + self.localId = localId + } + + public var uniqueId: String { + return "telegram-peer-photo-size-\(self.datacenterId)-\(self.sizeSpec.rawValue)-\(self.volumeId)-\(self.localId)" + } + + public func isEqual(to: MediaResourceId) -> Bool { + if let to = to as? CloudPeerPhotoSizeMediaResourceId { + return self.datacenterId == to.datacenterId && self.sizeSpec == to.sizeSpec && self.volumeId == to.volumeId && self.localId == to.localId + } else { + return false + } + } +} + +public final class CloudPeerPhotoSizeMediaResource: TelegramMediaResource { + public let datacenterId: Int + public let sizeSpec: CloudPeerPhotoSizeSpec + public let volumeId: Int64 + public let localId: Int32 + + public var id: MediaResourceId { + return CloudPeerPhotoSizeMediaResourceId(datacenterId: Int32(self.datacenterId), sizeSpec: self.sizeSpec, volumeId: self.volumeId, localId: self.localId) + } + + public init(datacenterId: Int32, sizeSpec: CloudPeerPhotoSizeSpec, volumeId: Int64, localId: Int32) { + self.datacenterId = Int(datacenterId) + self.sizeSpec = sizeSpec + self.volumeId = volumeId + self.localId = localId + } + + public required init(decoder: PostboxDecoder) { + self.datacenterId = Int(decoder.decodeInt32ForKey("d", orElse: 0)) + self.sizeSpec = CloudPeerPhotoSizeSpec(rawValue: decoder.decodeInt32ForKey("s", orElse: 0)) ?? .small + self.volumeId = decoder.decodeInt64ForKey("v", orElse: 0) + self.localId = decoder.decodeInt32ForKey("l", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(Int32(self.datacenterId), forKey: "d") + encoder.encodeInt32(self.sizeSpec.rawValue, forKey: "s") + encoder.encodeInt64(self.volumeId, forKey: "v") + encoder.encodeInt32(self.localId, forKey: "l") + } + + public func isEqual(to: MediaResource) -> Bool { + if let to = to as? CloudPeerPhotoSizeMediaResource { + return self.datacenterId == to.datacenterId && self.sizeSpec == to.sizeSpec && self.volumeId == to.volumeId && self.localId == to.localId + } else { + return false + } + } +} + +public struct CloudStickerPackThumbnailMediaResourceId: MediaResourceId, Hashable { + let datacenterId: Int32 + let volumeId: Int64 + let localId: Int32 + + init(datacenterId: Int32, volumeId: Int64, localId: Int32) { + self.datacenterId = datacenterId + self.volumeId = volumeId + self.localId = localId + } + + public var uniqueId: String { + return "telegram-stickerpackthumbnail-\(self.datacenterId)-\(self.volumeId)-\(self.localId)" + } + + public func isEqual(to: MediaResourceId) -> Bool { + if let to = to as? CloudStickerPackThumbnailMediaResourceId { + return self.datacenterId == to.datacenterId && self.volumeId == to.volumeId && self.localId == to.localId + } else { + return false + } + } +} + +public final class CloudStickerPackThumbnailMediaResource: TelegramMediaResource { + public let datacenterId: Int + public let volumeId: Int64 + public let localId: Int32 + + public var id: MediaResourceId { + return CloudStickerPackThumbnailMediaResourceId(datacenterId: Int32(self.datacenterId), volumeId: self.volumeId, localId: self.localId) + } + + public init(datacenterId: Int32, volumeId: Int64, localId: Int32) { + self.datacenterId = Int(datacenterId) + self.volumeId = volumeId + self.localId = localId + } + + public required init(decoder: PostboxDecoder) { + self.datacenterId = Int(decoder.decodeInt32ForKey("d", orElse: 0)) + self.volumeId = decoder.decodeInt64ForKey("v", orElse: 0) + self.localId = decoder.decodeInt32ForKey("l", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(Int32(self.datacenterId), forKey: "d") + encoder.encodeInt64(self.volumeId, forKey: "v") + encoder.encodeInt32(self.localId, forKey: "l") + } + + public func isEqual(to: MediaResource) -> Bool { + if let to = to as? CloudPeerPhotoSizeMediaResource { + return self.datacenterId == to.datacenterId && self.volumeId == to.volumeId && self.localId == to.localId + } else { + return false + } + } +} + +public struct CloudDocumentMediaResourceId: MediaResourceId { + public let datacenterId: Int + public let fileId: Int64 + + init(datacenterId: Int, fileId: Int64) { + self.datacenterId = datacenterId + self.fileId = fileId + } + + public var uniqueId: String { + return "telegram-cloud-document-\(self.datacenterId)-\(self.fileId)" + } + + public var hashValue: Int { + return self.fileId.hashValue + } + + public func isEqual(to: MediaResourceId) -> Bool { + if let to = to as? CloudDocumentMediaResourceId { + return self.datacenterId == to.datacenterId && self.fileId == to.fileId + } else { + return false + } + } +} + +public final class CloudDocumentMediaResource: TelegramMediaResource { + public let datacenterId: Int + public let fileId: Int64 + public let accessHash: Int64 + public let size: Int? + public let fileReference: Data? + public let fileName: String? + + public var id: MediaResourceId { + return CloudDocumentMediaResourceId(datacenterId: self.datacenterId, fileId: self.fileId) + } + + public init(datacenterId: Int, fileId: Int64, accessHash: Int64, size: Int?, fileReference: Data?, fileName: String?) { + self.datacenterId = datacenterId + self.fileId = fileId + self.accessHash = accessHash + self.size = size + self.fileReference = fileReference + self.fileName = fileName + } + + public required init(decoder: PostboxDecoder) { + self.datacenterId = Int(decoder.decodeInt32ForKey("d", orElse: 0)) + self.fileId = decoder.decodeInt64ForKey("f", orElse: 0) + self.accessHash = decoder.decodeInt64ForKey("a", orElse: 0) + if let size = decoder.decodeOptionalInt32ForKey("n") { + self.size = Int(size) + } else { + self.size = nil + } + self.fileReference = decoder.decodeBytesForKey("fr")?.makeData() + self.fileName = decoder.decodeOptionalStringForKey("fn") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(Int32(self.datacenterId), forKey: "d") + encoder.encodeInt64(self.fileId, forKey: "f") + encoder.encodeInt64(self.accessHash, forKey: "a") + if let size = self.size { + encoder.encodeInt32(Int32(size), forKey: "n") + } else { + encoder.encodeNil(forKey: "n") + } + if let fileReference = self.fileReference { + encoder.encodeBytes(MemoryBuffer(data: fileReference), forKey: "fr") + } else { + encoder.encodeNil(forKey: "fr") + } + if let fileName = self.fileName { + encoder.encodeString(fileName, forKey: "fn") + } else { + encoder.encodeNil(forKey: "fn") + } + } + + public func isEqual(to: MediaResource) -> Bool { + if let to = to as? CloudDocumentMediaResource { + return self.datacenterId == to.datacenterId && self.fileId == to.fileId && self.accessHash == to.accessHash && self.size == to.size && self.fileReference == to.fileReference + } else { + return false + } + } +} + +public struct LocalFileMediaResourceId: MediaResourceId { + public let fileId: Int64 + + public var uniqueId: String { + return "telegram-local-file-\(self.fileId)" + } + + public var hashValue: Int { + return self.fileId.hashValue + } + + public func isEqual(to: MediaResourceId) -> Bool { + if let to = to as? LocalFileMediaResourceId { + return self.fileId == to.fileId + } else { + return false + } + } +} + +public class LocalFileMediaResource: TelegramMediaResource { + public let fileId: Int64 + public let size: Int? + + public init(fileId: Int64, size: Int? = nil) { + self.fileId = fileId + self.size = size + } + + public required init(decoder: PostboxDecoder) { + self.fileId = decoder.decodeInt64ForKey("f", orElse: 0) + if let size = decoder.decodeOptionalInt32ForKey("s") { + self.size = Int(size) + } else { + self.size = nil + } + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt64(self.fileId, forKey: "f") + if let size = self.size { + encoder.encodeInt32(Int32(size), forKey: "s") + } else { + encoder.encodeNil(forKey: "s") + } + } + + public var id: MediaResourceId { + return LocalFileMediaResourceId(fileId: self.fileId) + } + + public func isEqual(to: MediaResource) -> Bool { + if let to = to as? LocalFileMediaResource { + return self.fileId == to.fileId && self.size == to.size + } else { + return false + } + } +} + +public struct LocalFileReferenceMediaResourceId: MediaResourceId { + public let randomId: Int64 + + public var uniqueId: String { + return "local-file-\(self.randomId)" + } + + public var hashValue: Int { + return self.randomId.hashValue + } + + public func isEqual(to: MediaResourceId) -> Bool { + if let to = to as? LocalFileReferenceMediaResourceId { + return self.randomId == to.randomId + } else { + return false + } + } +} + +public class LocalFileReferenceMediaResource: TelegramMediaResource { + public let localFilePath: String + public let randomId: Int64 + public let isUniquelyReferencedTemporaryFile: Bool + public let size: Int32? + + public init(localFilePath: String, randomId: Int64, isUniquelyReferencedTemporaryFile: Bool = false, size: Int32? = nil) { + self.localFilePath = localFilePath + self.randomId = randomId + self.isUniquelyReferencedTemporaryFile = isUniquelyReferencedTemporaryFile + self.size = size + } + + public required init(decoder: PostboxDecoder) { + self.localFilePath = decoder.decodeStringForKey("p", orElse: "") + self.randomId = decoder.decodeInt64ForKey("r", orElse: 0) + self.isUniquelyReferencedTemporaryFile = decoder.decodeInt32ForKey("t", orElse: 0) != 0 + self.size = decoder.decodeOptionalInt32ForKey("s") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.localFilePath, forKey: "p") + encoder.encodeInt64(self.randomId, forKey: "r") + encoder.encodeInt32(self.isUniquelyReferencedTemporaryFile ? 1 : 0, forKey: "t") + if let size = self.size { + encoder.encodeInt32(size, forKey: "s") + } else { + encoder.encodeNil(forKey: "s") + } + } + + public var id: MediaResourceId { + return LocalFileReferenceMediaResourceId(randomId: self.randomId) + } + + public func isEqual(to: MediaResource) -> Bool { + if let to = to as? LocalFileReferenceMediaResource { + return self.localFilePath == to.localFilePath && self.randomId == to.randomId && self.size == to.size && self.isUniquelyReferencedTemporaryFile == to.isUniquelyReferencedTemporaryFile + } else { + return false + } + } +} + +public struct HttpReferenceMediaResourceId: MediaResourceId { + public let url: String + + public func isEqual(to: MediaResourceId) -> Bool { + if let to = to as? HttpReferenceMediaResourceId { + return self.url == to.url + } else { + return false + } + } + + public var hashValue: Int { + return self.url.hashValue + } + + public var uniqueId: String { + return "http-\(persistentHash32(self.url))" + } +} + +public final class HttpReferenceMediaResource: TelegramMediaResource { + public let url: String + public let size: Int? + + public init(url: String, size: Int?) { + self.url = url + self.size = size + } + + public required init(decoder: PostboxDecoder) { + self.url = decoder.decodeStringForKey("u", orElse: "") + if let size = decoder.decodeOptionalInt32ForKey("s") { + self.size = Int(size) + } else { + self.size = nil + } + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.url, forKey: "u") + if let size = self.size { + encoder.encodeInt32(Int32(size), forKey: "s") + } else { + encoder.encodeNil(forKey: "s") + } + } + + public var id: MediaResourceId { + return HttpReferenceMediaResourceId(url: self.url) + } + + public func isEqual(to: MediaResource) -> Bool { + if let to = to as? HttpReferenceMediaResource { + return to.url == self.url + } else { + return false + } + } +} + +public struct WebFileReferenceMediaResourceId: MediaResourceId { + public let url: String + public let accessHash: Int64 + public let size: Int32 + + public func isEqual(to: MediaResourceId) -> Bool { + if let to = to as? WebFileReferenceMediaResourceId { + return self.url == to.url && size == to.size && accessHash == to.accessHash + } else { + return false + } + } + + public var hashValue: Int { + return self.url.hashValue + } + + public var uniqueId: String { + return "proxy-\(persistentHash32(self.url))-\(size)-\(accessHash)" + } +} + +public final class WebFileReferenceMediaResource: TelegramMediaResource { + public let url: String + public let size: Int32 + public let accessHash: Int64 + + public init(url: String, size: Int32, accessHash: Int64) { + self.url = url + self.size = size + self.accessHash = accessHash + } + + public required init(decoder: PostboxDecoder) { + self.url = decoder.decodeStringForKey("u", orElse: "") + self.size = decoder.decodeInt32ForKey("s", orElse: 0) + self.accessHash = decoder.decodeInt64ForKey("h", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.url, forKey: "u") + encoder.encodeInt32(self.size, forKey: "s") + encoder.encodeInt64(self.accessHash, forKey: "h") + } + + public var id: MediaResourceId { + return WebFileReferenceMediaResourceId(url: self.url, accessHash: accessHash, size: self.size) + } + + public func isEqual(to: MediaResource) -> Bool { + if let to = to as? WebFileReferenceMediaResource { + return to.url == self.url && to.size == self.size && to.accessHash == self.accessHash + } else { + return false + } + } +} + + +public struct SecretFileMediaResourceId: MediaResourceId { + public let fileId: Int64 + public let datacenterId: Int32 + + public var uniqueId: String { + return "secret-file-\(self.fileId)-\(self.datacenterId)" + } + + public init(fileId: Int64, datacenterId: Int32) { + self.fileId = fileId + self.datacenterId = datacenterId + } + + public var hashValue: Int { + return self.fileId.hashValue + } + + public func isEqual(to: MediaResourceId) -> Bool { + if let to = to as? SecretFileMediaResourceId { + return self.fileId == to.fileId && self.datacenterId == to.datacenterId + } else { + return false + } + } +} + +public final class SecretFileMediaResource: TelegramMediaResource { + public let fileId: Int64 + public let accessHash: Int64 + public var size: Int? { + return Int(self.decryptedSize) + } + public let containerSize: Int32 + public let decryptedSize: Int32 + public let datacenterId: Int + public let key: SecretFileEncryptionKey + + public init(fileId: Int64, accessHash: Int64, containerSize: Int32, decryptedSize: Int32, datacenterId: Int, key: SecretFileEncryptionKey) { + self.fileId = fileId + self.accessHash = accessHash + self.containerSize = containerSize + self.decryptedSize = decryptedSize + self.datacenterId = datacenterId + self.key = key + } + + public init(decoder: PostboxDecoder) { + self.fileId = decoder.decodeInt64ForKey("i", orElse: 0) + self.accessHash = decoder.decodeInt64ForKey("a", orElse: 0) + self.containerSize = decoder.decodeInt32ForKey("s", orElse: 0) + self.decryptedSize = decoder.decodeInt32ForKey("ds", orElse: 0) + self.datacenterId = Int(decoder.decodeInt32ForKey("d", orElse: 0)) + self.key = decoder.decodeObjectForKey("k", decoder: { SecretFileEncryptionKey(decoder: $0) }) as! SecretFileEncryptionKey + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt64(self.fileId, forKey: "i") + encoder.encodeInt64(self.accessHash, forKey: "a") + encoder.encodeInt32(self.containerSize, forKey: "s") + encoder.encodeInt32(self.decryptedSize, forKey: "ds") + encoder.encodeInt32(Int32(self.datacenterId), forKey: "d") + encoder.encodeObject(self.key, forKey: "k") + } + + public var id: MediaResourceId { + return SecretFileMediaResourceId(fileId: self.fileId, datacenterId: Int32(self.datacenterId)) + } + + public func isEqual(to: MediaResource) -> Bool { + if let to = to as? SecretFileMediaResource { + if self.fileId != to.fileId { + return false + } + if self.accessHash != to.accessHash { + return false + } + if self.containerSize != to.containerSize { + return false + } + if self.decryptedSize != to.decryptedSize { + return false + } + if self.datacenterId != to.datacenterId { + return false + } + if self.key != to.key { + return false + } + return true + } else { + return false + } + } +} + +public struct EmptyMediaResourceId: MediaResourceId { + public var uniqueId: String { + return "empty-resource" + } + + public var hashValue: Int { + return 0 + } + + public func isEqual(to: MediaResourceId) -> Bool { + return to is EmptyMediaResourceId + } +} + +public final class EmptyMediaResource: TelegramMediaResource { + public init() { + } + + public init(decoder: PostboxDecoder) { + } + + public func encode(_ encoder: PostboxEncoder) { + } + + public var id: MediaResourceId { + return EmptyMediaResourceId() + } + + public func isEqual(to: MediaResource) -> Bool { + return to is EmptyMediaResource + } +} diff --git a/submodules/TelegramCore/TelegramCore/ConsumableContentMessageAttribute.swift b/submodules/SyncCore/Sources/ConsumableContentMessageAttribute.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/ConsumableContentMessageAttribute.swift rename to submodules/SyncCore/Sources/ConsumableContentMessageAttribute.swift diff --git a/submodules/TelegramCore/TelegramCore/ConsumablePersonalMentionMessageAttribute.swift b/submodules/SyncCore/Sources/ConsumablePersonalMentionMessageAttribute.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/ConsumablePersonalMentionMessageAttribute.swift rename to submodules/SyncCore/Sources/ConsumablePersonalMentionMessageAttribute.swift diff --git a/submodules/SyncCore/Sources/ConsumePersonalMessageAction.swift b/submodules/SyncCore/Sources/ConsumePersonalMessageAction.swift new file mode 100644 index 0000000000..b69350979b --- /dev/null +++ b/submodules/SyncCore/Sources/ConsumePersonalMessageAction.swift @@ -0,0 +1,25 @@ +import Foundation +#if os(macOS) + import PostboxMac +#else + import Postbox +#endif + +public final class ConsumePersonalMessageAction: PendingMessageActionData { + public init() { + } + + public init(decoder: PostboxDecoder) { + } + + public func encode(_ encoder: PostboxEncoder) { + } + + public func isEqual(to: PendingMessageActionData) -> Bool { + if let _ = to as? ConsumePersonalMessageAction { + return true + } else { + return false + } + } +} diff --git a/submodules/TelegramCore/TelegramCore/ContactsSettings.swift b/submodules/SyncCore/Sources/ContactsSettings.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/ContactsSettings.swift rename to submodules/SyncCore/Sources/ContactsSettings.swift diff --git a/submodules/SyncCore/Sources/ContentPrivacySettings.swift b/submodules/SyncCore/Sources/ContentPrivacySettings.swift new file mode 100644 index 0000000000..36fb7b306f --- /dev/null +++ b/submodules/SyncCore/Sources/ContentPrivacySettings.swift @@ -0,0 +1,42 @@ +import Postbox + +public final class ContentPrivacySettings: PreferencesEntry, Equatable { + public let enableSecretChatWebpagePreviews: Bool? + + public static var defaultSettings = ContentPrivacySettings(enableSecretChatWebpagePreviews: nil) + + public init(enableSecretChatWebpagePreviews: Bool?) { + self.enableSecretChatWebpagePreviews = enableSecretChatWebpagePreviews + } + + public init(decoder: PostboxDecoder) { + self.enableSecretChatWebpagePreviews = decoder.decodeOptionalInt32ForKey("enableSecretChatWebpagePreviews").flatMap { $0 != 0 } + } + + public func encode(_ encoder: PostboxEncoder) { + if let enableSecretChatWebpagePreviews = self.enableSecretChatWebpagePreviews { + encoder.encodeInt32(enableSecretChatWebpagePreviews ? 1 : 0, forKey: "enableSecretChatWebpagePreviews") + } else { + encoder.encodeNil(forKey: "enableSecretChatWebpagePreviews") + } + } + + public func withUpdatedEnableSecretChatWebpagePreviews(_ enableSecretChatWebpagePreviews: Bool) -> ContentPrivacySettings { + return ContentPrivacySettings(enableSecretChatWebpagePreviews: enableSecretChatWebpagePreviews) + } + + public func isEqual(to: PreferencesEntry) -> Bool { + guard let to = to as? ContentPrivacySettings else { + return false + } + + return self == to + } + + public static func ==(lhs: ContentPrivacySettings, rhs: ContentPrivacySettings) -> Bool { + if lhs.enableSecretChatWebpagePreviews != rhs.enableSecretChatWebpagePreviews { + return false + } + return true + } +} \ No newline at end of file diff --git a/submodules/TelegramCore/TelegramCore/ContentRequiresValidationMessageAttribute.swift b/submodules/SyncCore/Sources/ContentRequiresValidationMessageAttribute.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/ContentRequiresValidationMessageAttribute.swift rename to submodules/SyncCore/Sources/ContentRequiresValidationMessageAttribute.swift diff --git a/submodules/TelegramCore/TelegramCore/EditedMessageAttribute.swift b/submodules/SyncCore/Sources/EditedMessageAttribute.swift similarity index 93% rename from submodules/TelegramCore/TelegramCore/EditedMessageAttribute.swift rename to submodules/SyncCore/Sources/EditedMessageAttribute.swift index 6f9f3a9a2e..81f61f73ac 100644 --- a/submodules/TelegramCore/TelegramCore/EditedMessageAttribute.swift +++ b/submodules/SyncCore/Sources/EditedMessageAttribute.swift @@ -9,7 +9,7 @@ public class EditedMessageAttribute: MessageAttribute { public let date: Int32 public let isHidden: Bool - init(date: Int32, isHidden: Bool) { + public init(date: Int32, isHidden: Bool) { self.date = date self.isHidden = isHidden } diff --git a/submodules/SyncCore/Sources/EmojiKeywordCollectionInfo.swift b/submodules/SyncCore/Sources/EmojiKeywordCollectionInfo.swift new file mode 100644 index 0000000000..86a1560674 --- /dev/null +++ b/submodules/SyncCore/Sources/EmojiKeywordCollectionInfo.swift @@ -0,0 +1,57 @@ +import Postbox + +public func emojiKeywordColletionIdForCode(_ code: String) -> ItemCollectionId { + return ItemCollectionId(namespace: Namespaces.ItemCollection.EmojiKeywords, id: Int64(HashFunctions.murMurHash32(code))) +} + +public final class EmojiKeywordCollectionInfo: ItemCollectionInfo, Equatable { + public let id: ItemCollectionId + public let languageCode: String + public let inputLanguageCode: String + public let version: Int32 + public let timestamp: Int32 + + public init(languageCode: String, inputLanguageCode: String, version: Int32, timestamp: Int32) { + self.id = emojiKeywordColletionIdForCode(inputLanguageCode) + self.languageCode = languageCode + self.inputLanguageCode = inputLanguageCode + self.version = version + self.timestamp = timestamp + } + + public init(decoder: PostboxDecoder) { + self.id = ItemCollectionId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)) + self.languageCode = decoder.decodeStringForKey("lc", orElse: "") + self.inputLanguageCode = decoder.decodeStringForKey("ilc", orElse: "") + self.version = decoder.decodeInt32ForKey("v", orElse: 0) + self.timestamp = decoder.decodeInt32ForKey("t", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.id.namespace, forKey: "i.n") + encoder.encodeInt64(self.id.id, forKey: "i.i") + encoder.encodeString(self.languageCode, forKey: "lc") + encoder.encodeString(self.inputLanguageCode, forKey: "ilc") + encoder.encodeInt32(self.version, forKey: "v") + encoder.encodeInt32(self.timestamp, forKey: "t") + } + + public static func ==(lhs: EmojiKeywordCollectionInfo, rhs: EmojiKeywordCollectionInfo) -> Bool { + if lhs.id != rhs.id { + return false + } + if lhs.languageCode != rhs.languageCode { + return false + } + if lhs.inputLanguageCode != rhs.inputLanguageCode { + return false + } + if lhs.version != rhs.version { + return false + } + if lhs.timestamp != rhs.timestamp { + return false + } + return true + } +} diff --git a/submodules/SyncCore/Sources/EmojiKeywordItem.swift b/submodules/SyncCore/Sources/EmojiKeywordItem.swift new file mode 100644 index 0000000000..e7101ed86a --- /dev/null +++ b/submodules/SyncCore/Sources/EmojiKeywordItem.swift @@ -0,0 +1,38 @@ +import Postbox + +public final class EmojiKeywordItem: ItemCollectionItem, Equatable { + public let index: ItemCollectionItemIndex + public let collectionId: ItemCollectionId.Id + public let keyword: String + public let emoticons: [String] + public let indexKeys: [MemoryBuffer] + + public init(index: ItemCollectionItemIndex, collectionId: ItemCollectionId.Id, keyword: String, emoticons: [String], indexKeys: [MemoryBuffer]) { + self.index = index + self.collectionId = collectionId + self.keyword = keyword + self.emoticons = emoticons + self.indexKeys = indexKeys + } + + public init(decoder: PostboxDecoder) { + self.index = ItemCollectionItemIndex(index: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)) + self.collectionId = decoder.decodeInt64ForKey("c", orElse: 0) + self.keyword = decoder.decodeStringForKey("k", orElse: "") + self.emoticons = decoder.decodeStringArrayForKey("e") + self.indexKeys = decoder.decodeBytesArrayForKey("s") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.index.index, forKey: "i.n") + encoder.encodeInt64(self.index.id, forKey: "i.i") + encoder.encodeInt64(self.collectionId, forKey: "c") + encoder.encodeString(self.keyword, forKey: "k") + encoder.encodeStringArray(self.emoticons, forKey: "e") + encoder.encodeBytesArray(self.indexKeys, forKey: "s") + } + + public static func ==(lhs: EmojiKeywordItem, rhs: EmojiKeywordItem) -> Bool { + return lhs.index == rhs.index && lhs.collectionId == rhs.collectionId && lhs.keyword == rhs.keyword && lhs.emoticons == rhs.emoticons && lhs.indexKeys == rhs.indexKeys + } +} diff --git a/submodules/SyncCore/Sources/ExportedInvitation.swift b/submodules/SyncCore/Sources/ExportedInvitation.swift new file mode 100644 index 0000000000..29ff59ba9a --- /dev/null +++ b/submodules/SyncCore/Sources/ExportedInvitation.swift @@ -0,0 +1,21 @@ +import Postbox + +public struct ExportedInvitation: PostboxCoding, Equatable { + public let link: String + + public init(link: String) { + self.link = link + } + + public init(decoder: PostboxDecoder) { + self.link = decoder.decodeStringForKey("l", orElse: "") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.link, forKey: "l") + } + + public static func ==(lhs: ExportedInvitation, rhs: ExportedInvitation) -> Bool { + return lhs.link == rhs.link + } +} diff --git a/submodules/TelegramCore/TelegramCore/FeaturedStickerPack.swift b/submodules/SyncCore/Sources/FeaturedStickerPack.swift similarity index 89% rename from submodules/TelegramCore/TelegramCore/FeaturedStickerPack.swift rename to submodules/SyncCore/Sources/FeaturedStickerPack.swift index d92c863c5a..d5765a0d39 100644 --- a/submodules/TelegramCore/TelegramCore/FeaturedStickerPack.swift +++ b/submodules/SyncCore/Sources/FeaturedStickerPack.swift @@ -9,7 +9,7 @@ public struct FeaturedStickerPackItemId { public let rawValue: MemoryBuffer public let packId: Int64 - init(_ rawValue: MemoryBuffer) { + public init(_ rawValue: MemoryBuffer) { self.rawValue = rawValue assert(rawValue.length == 8) var idValue: Int64 = 0 @@ -17,7 +17,7 @@ public struct FeaturedStickerPackItemId { self.packId = idValue } - init(_ packId: Int64) { + public init(_ packId: Int64) { self.packId = packId var idValue: Int64 = packId self.rawValue = MemoryBuffer(memory: malloc(8)!, capacity: 8, length: 8, freeWhenDone: true) @@ -30,7 +30,7 @@ public final class FeaturedStickerPackItem: OrderedItemListEntryContents { public let topItems: [StickerPackItem] public let unread: Bool - init(info: StickerPackCollectionInfo, topItems: [StickerPackItem], unread: Bool) { + public init(info: StickerPackCollectionInfo, topItems: [StickerPackItem], unread: Bool) { self.info = info self.topItems = topItems self.unread = unread diff --git a/submodules/TelegramCore/TelegramCore/ForwardSourceInfoAttribute.swift b/submodules/SyncCore/Sources/ForwardSourceInfoAttribute.swift similarity index 94% rename from submodules/TelegramCore/TelegramCore/ForwardSourceInfoAttribute.swift rename to submodules/SyncCore/Sources/ForwardSourceInfoAttribute.swift index aee4c48459..ef7a631349 100644 --- a/submodules/TelegramCore/TelegramCore/ForwardSourceInfoAttribute.swift +++ b/submodules/SyncCore/Sources/ForwardSourceInfoAttribute.swift @@ -8,7 +8,7 @@ import Foundation public class ForwardSourceInfoAttribute: MessageAttribute { public let messageId: MessageId - init(messageId: MessageId) { + public init(messageId: MessageId) { self.messageId = messageId } diff --git a/submodules/SyncCore/Sources/GlobalNotificationSettings.swift b/submodules/SyncCore/Sources/GlobalNotificationSettings.swift new file mode 100644 index 0000000000..2a368bf52a --- /dev/null +++ b/submodules/SyncCore/Sources/GlobalNotificationSettings.swift @@ -0,0 +1,103 @@ +import Postbox + +public struct MessageNotificationSettings: PostboxCoding, Equatable { + public var enabled: Bool + public var displayPreviews: Bool + public var sound: PeerMessageSound + + public static var defaultSettings: MessageNotificationSettings { + return MessageNotificationSettings(enabled: true, displayPreviews: true, sound: .bundledModern(id: 0)) + } + + public init(enabled: Bool, displayPreviews: Bool, sound: PeerMessageSound) { + self.enabled = enabled + self.displayPreviews = displayPreviews + self.sound = sound + } + + public init(decoder: PostboxDecoder) { + self.enabled = decoder.decodeInt32ForKey("e", orElse: 0) != 0 + self.displayPreviews = decoder.decodeInt32ForKey("p", orElse: 0) != 0 + self.sound = PeerMessageSound.decodeInline(decoder) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.enabled ? 1 : 0, forKey: "e") + encoder.encodeInt32(self.displayPreviews ? 1 : 0, forKey: "p") + self.sound.encodeInline(encoder) + } +} + +public struct GlobalNotificationSettingsSet: PostboxCoding, Equatable { + public var privateChats: MessageNotificationSettings + public var groupChats: MessageNotificationSettings + public var channels: MessageNotificationSettings + public var contactsJoined: Bool + + public static var defaultSettings: GlobalNotificationSettingsSet { + return GlobalNotificationSettingsSet(privateChats: MessageNotificationSettings.defaultSettings, groupChats: .defaultSettings, channels: .defaultSettings, contactsJoined: true) + } + + public init(privateChats: MessageNotificationSettings, groupChats: MessageNotificationSettings, channels: MessageNotificationSettings, contactsJoined: Bool) { + self.privateChats = privateChats + self.groupChats = groupChats + self.channels = channels + self.contactsJoined = contactsJoined + } + + public init(decoder: PostboxDecoder) { + self.privateChats = decoder.decodeObjectForKey("p", decoder: { MessageNotificationSettings(decoder: $0) }) as! MessageNotificationSettings + self.groupChats = decoder.decodeObjectForKey("g", decoder: { MessageNotificationSettings(decoder: $0) }) as! MessageNotificationSettings + self.channels = (decoder.decodeObjectForKey("c", decoder: { MessageNotificationSettings(decoder: $0) }) as? MessageNotificationSettings) ?? MessageNotificationSettings.defaultSettings + self.contactsJoined = decoder.decodeInt32ForKey("contactsJoined", orElse: 1) != 0 + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObject(self.privateChats, forKey: "p") + encoder.encodeObject(self.groupChats, forKey: "g") + encoder.encodeObject(self.channels, forKey: "c") + encoder.encodeInt32(self.contactsJoined ? 1 : 0, forKey: "contactsJoined") + } +} + +public struct GlobalNotificationSettings: PreferencesEntry, Equatable { + public var toBeSynchronized: GlobalNotificationSettingsSet? + public var remote: GlobalNotificationSettingsSet + + public static var defaultSettings: GlobalNotificationSettings = GlobalNotificationSettings(toBeSynchronized: nil, remote: GlobalNotificationSettingsSet.defaultSettings) + + public var effective: GlobalNotificationSettingsSet { + if let toBeSynchronized = self.toBeSynchronized { + return toBeSynchronized + } else { + return self.remote + } + } + + public init(toBeSynchronized: GlobalNotificationSettingsSet?, remote: GlobalNotificationSettingsSet) { + self.toBeSynchronized = toBeSynchronized + self.remote = remote + } + + public init(decoder: PostboxDecoder) { + self.toBeSynchronized = decoder.decodeObjectForKey("s", decoder: { GlobalNotificationSettingsSet(decoder: $0) }) as? GlobalNotificationSettingsSet + self.remote = decoder.decodeObjectForKey("r", decoder: { GlobalNotificationSettingsSet(decoder: $0) }) as! GlobalNotificationSettingsSet + } + + public func encode(_ encoder: PostboxEncoder) { + if let toBeSynchronized = self.toBeSynchronized { + encoder.encodeObject(toBeSynchronized, forKey: "s") + } else { + encoder.encodeNil(forKey: "s") + } + encoder.encodeObject(self.remote, forKey: "r") + } + + public func isEqual(to: PreferencesEntry) -> Bool { + if let to = to as? GlobalNotificationSettings { + return self == to + } else { + return false + } + } +} diff --git a/submodules/SyncCore/Sources/ImportableDeviceContactData.swift b/submodules/SyncCore/Sources/ImportableDeviceContactData.swift new file mode 100644 index 0000000000..f14c06f7a6 --- /dev/null +++ b/submodules/SyncCore/Sources/ImportableDeviceContactData.swift @@ -0,0 +1,31 @@ +import Postbox + +public final class ImportableDeviceContactData: Equatable, PostboxCoding { + public let firstName: String + public let lastName: String + + public init(firstName: String, lastName: String) { + self.firstName = firstName + self.lastName = lastName + } + + public init(decoder: PostboxDecoder) { + self.firstName = decoder.decodeStringForKey("f", orElse: "") + self.lastName = decoder.decodeStringForKey("l", orElse: "") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.firstName, forKey: "f") + encoder.encodeString(self.lastName, forKey: "l") + } + + public static func ==(lhs: ImportableDeviceContactData, rhs: ImportableDeviceContactData) -> Bool { + if lhs.firstName != rhs.firstName { + return false + } + if lhs.lastName != rhs.lastName { + return false + } + return true + } +} diff --git a/submodules/TelegramCore/TelegramCore/InlineBotMessageAttribute.swift b/submodules/SyncCore/Sources/InlineBotMessageAttribute.swift similarity index 95% rename from submodules/TelegramCore/TelegramCore/InlineBotMessageAttribute.swift rename to submodules/SyncCore/Sources/InlineBotMessageAttribute.swift index c49f186678..073c7c8339 100644 --- a/submodules/TelegramCore/TelegramCore/InlineBotMessageAttribute.swift +++ b/submodules/SyncCore/Sources/InlineBotMessageAttribute.swift @@ -17,7 +17,7 @@ public class InlineBotMessageAttribute: MessageAttribute { } } - init(peerId: PeerId?, title: String?) { + public init(peerId: PeerId?, title: String?) { self.peerId = peerId self.title = title } diff --git a/submodules/SyncCore/Sources/InstantPage.swift b/submodules/SyncCore/Sources/InstantPage.swift new file mode 100644 index 0000000000..9a32d74b3f --- /dev/null +++ b/submodules/SyncCore/Sources/InstantPage.swift @@ -0,0 +1,901 @@ +import Postbox +import UIKit + +private enum InstantPageBlockType: Int32 { + case unsupported = 0 + case title = 1 + case subtitle = 2 + case authorDate = 3 + case header = 4 + case subheader = 5 + case paragraph = 6 + case preformatted = 7 + case footer = 8 + case divider = 9 + case anchor = 10 + case list = 11 + case blockQuote = 12 + case pullQuote = 13 + case image = 14 + case video = 15 + case cover = 16 + case webEmbed = 17 + case postEmbed = 18 + case collage = 19 + case slideshow = 20 + case channelBanner = 21 + case audio = 22 + case kicker = 23 + case table = 24 + case details = 25 + case relatedArticles = 26 + case map = 27 +} + +private func decodeListItems(_ decoder: PostboxDecoder) -> [InstantPageListItem] { + let legacyItems: [RichText] = decoder.decodeObjectArrayWithDecoderForKey("l") + if !legacyItems.isEmpty { + var items: [InstantPageListItem] = [] + for item in legacyItems { + items.append(.text(item, nil)) + } + return items + } + return decoder.decodeObjectArrayWithDecoderForKey("ml") +} + +private func decodeCaption(_ decoder: PostboxDecoder) -> InstantPageCaption { + if let legacyCaption = decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as? RichText { + return InstantPageCaption(text: legacyCaption, credit: .empty) + } + return decoder.decodeObjectForKey("mc", decoder: { InstantPageCaption(decoder: $0) }) as! InstantPageCaption +} + +public indirect enum InstantPageBlock: PostboxCoding, Equatable { + case unsupported + case title(RichText) + case subtitle(RichText) + case authorDate(author: RichText, date: Int32) + case header(RichText) + case subheader(RichText) + case paragraph(RichText) + case preformatted(RichText) + case footer(RichText) + case divider + case anchor(String) + case list(items: [InstantPageListItem], ordered: Bool) + case blockQuote(text: RichText, caption: RichText) + case pullQuote(text: RichText, caption: RichText) + case image(id: MediaId, caption: InstantPageCaption, url: String?, webpageId: MediaId?) + case video(id: MediaId, caption: InstantPageCaption, autoplay: Bool, loop: Bool) + case audio(id: MediaId, caption: InstantPageCaption) + case cover(InstantPageBlock) + case webEmbed(url: String?, html: String?, dimensions: CGSize?, caption: InstantPageCaption, stretchToWidth: Bool, allowScrolling: Bool, coverId: MediaId?) + case postEmbed(url: String, webpageId: MediaId?, avatarId: MediaId?, author: String, date: Int32, blocks: [InstantPageBlock], caption: InstantPageCaption) + case collage(items: [InstantPageBlock], caption: InstantPageCaption) + case slideshow(items: [InstantPageBlock], caption: InstantPageCaption) + case channelBanner(TelegramChannel?) + case kicker(RichText) + case table(title: RichText, rows: [InstantPageTableRow], bordered: Bool, striped: Bool) + case details(title: RichText, blocks: [InstantPageBlock], expanded: Bool) + case relatedArticles(title: RichText, articles: [InstantPageRelatedArticle]) + case map(latitude: Double, longitude: Double, zoom: Int32, dimensions: CGSize, caption: InstantPageCaption) + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("r", orElse: 0) { + case InstantPageBlockType.unsupported.rawValue: + self = .unsupported + case InstantPageBlockType.title.rawValue: + self = .title(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) + case InstantPageBlockType.subtitle.rawValue: + self = .subtitle(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) + case InstantPageBlockType.authorDate.rawValue: + self = .authorDate(author: decoder.decodeObjectForKey("a", decoder: { RichText(decoder: $0) }) as! RichText, date: decoder.decodeInt32ForKey("d", orElse: 0)) + case InstantPageBlockType.header.rawValue: + self = .header(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) + case InstantPageBlockType.subheader.rawValue: + self = .subheader(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) + case InstantPageBlockType.paragraph.rawValue: + self = .paragraph(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) + case InstantPageBlockType.preformatted.rawValue: + self = .preformatted(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) + case InstantPageBlockType.footer.rawValue: + self = .footer(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) + case InstantPageBlockType.divider.rawValue: + self = .divider + case InstantPageBlockType.anchor.rawValue: + self = .anchor(decoder.decodeStringForKey("s", orElse: "")) + case InstantPageBlockType.list.rawValue: + self = .list(items: decodeListItems(decoder), ordered: decoder.decodeOptionalInt32ForKey("o") != 0) + case InstantPageBlockType.blockQuote.rawValue: + self = .blockQuote(text: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, caption: decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as! RichText) + case InstantPageBlockType.pullQuote.rawValue: + self = .pullQuote(text: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, caption: decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as! RichText) + case InstantPageBlockType.image.rawValue: + var webpageId: MediaId? + if let webpageIdNamespace = decoder.decodeOptionalInt32ForKey("wi.n"), let webpageIdId = decoder.decodeOptionalInt64ForKey("wi.i") { + webpageId = MediaId(namespace: webpageIdNamespace, id: webpageIdId) + } + self = .image(id: MediaId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)), caption: decodeCaption(decoder), url: decoder.decodeOptionalStringForKey("u"), webpageId: webpageId) + case InstantPageBlockType.video.rawValue: + self = .video(id: MediaId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)), caption: decodeCaption(decoder), autoplay: decoder.decodeInt32ForKey("ap", orElse: 0) != 0, loop: decoder.decodeInt32ForKey("lo", orElse: 0) != 0) + case InstantPageBlockType.cover.rawValue: + self = .cover(decoder.decodeObjectForKey("c", decoder: { InstantPageBlock(decoder: $0) }) as! InstantPageBlock) + case InstantPageBlockType.webEmbed.rawValue: + var coverId: MediaId? + if let coverIdNamespace = decoder.decodeOptionalInt32ForKey("ci.n"), let coverIdId = decoder.decodeOptionalInt64ForKey("ci.i") { + coverId = MediaId(namespace: coverIdNamespace, id: coverIdId) + } + var dimensions: CGSize? + if let width = decoder.decodeOptionalInt32ForKey("sw"), let height = decoder.decodeOptionalInt32ForKey("sh") { + dimensions = CGSize(width: CGFloat(width), height: CGFloat(height)) + } + self = .webEmbed(url: decoder.decodeOptionalStringForKey("u"), html: decoder.decodeOptionalStringForKey("h"), dimensions: dimensions, caption: decodeCaption(decoder), stretchToWidth: decoder.decodeInt32ForKey("st", orElse: 0) != 0, allowScrolling: decoder.decodeInt32ForKey("as", orElse: 0) != 0, coverId: coverId) + case InstantPageBlockType.postEmbed.rawValue: + var avatarId: MediaId? + let avatarIdNamespace: Int32? = decoder.decodeOptionalInt32ForKey("av.n") + let avatarIdId: Int64? = decoder.decodeOptionalInt64ForKey("av.i") + if let avatarIdNamespace = avatarIdNamespace, let avatarIdId = avatarIdId { + avatarId = MediaId(namespace: avatarIdNamespace, id: avatarIdId) + } + self = .postEmbed(url: decoder.decodeStringForKey("u", orElse: ""), webpageId: MediaId(namespace: decoder.decodeInt32ForKey("w.n", orElse: 0), id: decoder.decodeInt64ForKey("w.i", orElse: 0)), avatarId: avatarId, author: decoder.decodeStringForKey("a", orElse: ""), date: decoder.decodeInt32ForKey("d", orElse: 0), blocks: decoder.decodeObjectArrayWithDecoderForKey("b"), caption: decodeCaption(decoder)) + case InstantPageBlockType.collage.rawValue: + self = .collage(items: decoder.decodeObjectArrayWithDecoderForKey("b"), caption: decodeCaption(decoder)) + case InstantPageBlockType.slideshow.rawValue: + self = .slideshow(items: decoder.decodeObjectArrayWithDecoderForKey("b"), caption: decodeCaption(decoder)) + case InstantPageBlockType.channelBanner.rawValue: + self = .channelBanner(decoder.decodeObjectForKey("c") as? TelegramChannel) + case InstantPageBlockType.audio.rawValue: + self = .audio(id: MediaId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)), caption: decodeCaption(decoder)) + case InstantPageBlockType.kicker.rawValue: + self = .kicker(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) + case InstantPageBlockType.table.rawValue: + self = .table(title: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, rows: decoder.decodeObjectArrayWithDecoderForKey("r"), bordered: decoder.decodeInt32ForKey("b", orElse: 0) != 0, striped: decoder.decodeInt32ForKey("s", orElse: 0) != 0) + case InstantPageBlockType.details.rawValue: + self = .details(title: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, blocks: decoder.decodeObjectArrayWithDecoderForKey("b"), expanded: decoder.decodeInt32ForKey("o", orElse: 0) != 0) + case InstantPageBlockType.relatedArticles.rawValue: + self = .relatedArticles(title: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, articles: decoder.decodeObjectArrayWithDecoderForKey("a")) + case InstantPageBlockType.map.rawValue: + self = .map(latitude: decoder.decodeDoubleForKey("lat", orElse: 0.0), longitude: decoder.decodeDoubleForKey("lon", orElse: 0.0), zoom: decoder.decodeInt32ForKey("z", orElse: 0), dimensions: CGSize(width: CGFloat(decoder.decodeInt32ForKey("sw", orElse: 0)), height: CGFloat(decoder.decodeInt32ForKey("sh", orElse: 0))), caption: decodeCaption(decoder)) + default: + self = .unsupported + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case .unsupported: + encoder.encodeInt32(InstantPageBlockType.unsupported.rawValue, forKey: "r") + case let .title(text): + encoder.encodeInt32(InstantPageBlockType.title.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + case let .subtitle(text): + encoder.encodeInt32(InstantPageBlockType.subtitle.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + case let .authorDate(author, date): + encoder.encodeInt32(InstantPageBlockType.authorDate.rawValue, forKey: "r") + encoder.encodeObject(author, forKey: "a") + encoder.encodeInt32(date, forKey: "d") + case let .header(text): + encoder.encodeInt32(InstantPageBlockType.header.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + case let .subheader(text): + encoder.encodeInt32(InstantPageBlockType.subheader.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + case let .paragraph(text): + encoder.encodeInt32(InstantPageBlockType.paragraph.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + case let .preformatted(text): + encoder.encodeInt32(InstantPageBlockType.preformatted.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + case let .footer(text): + encoder.encodeInt32(InstantPageBlockType.footer.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + case .divider: + encoder.encodeInt32(InstantPageBlockType.divider.rawValue, forKey: "r") + case let .anchor(anchor): + encoder.encodeInt32(InstantPageBlockType.anchor.rawValue, forKey: "r") + encoder.encodeString(anchor, forKey: "s") + case let .list(items, ordered): + encoder.encodeInt32(InstantPageBlockType.list.rawValue, forKey: "r") + encoder.encodeObjectArray(items, forKey: "ml") + encoder.encodeInt32(ordered ? 1 : 0, forKey: "o") + case let .blockQuote(text, caption): + encoder.encodeInt32(InstantPageBlockType.blockQuote.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + encoder.encodeObject(caption, forKey: "c") + case let .pullQuote(text, caption): + encoder.encodeInt32(InstantPageBlockType.pullQuote.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + encoder.encodeObject(caption, forKey: "c") + case let .image(id, caption, url, webpageId): + encoder.encodeInt32(InstantPageBlockType.image.rawValue, forKey: "r") + encoder.encodeInt32(id.namespace, forKey: "i.n") + encoder.encodeInt64(id.id, forKey: "i.i") + encoder.encodeObject(caption, forKey: "mc") + if let url = url { + encoder.encodeString(url, forKey: "u") + } else { + encoder.encodeNil(forKey: "u") + } + if let webpageId = webpageId { + encoder.encodeInt32(webpageId.namespace, forKey: "wi.n") + encoder.encodeInt64(webpageId.id, forKey: "wi.i") + } else { + encoder.encodeNil(forKey: "wi.n") + encoder.encodeNil(forKey: "wi.i") + } + case let .video(id, caption, autoplay, loop): + encoder.encodeInt32(InstantPageBlockType.video.rawValue, forKey: "r") + encoder.encodeInt32(id.namespace, forKey: "i.n") + encoder.encodeInt64(id.id, forKey: "i.i") + encoder.encodeObject(caption, forKey: "mc") + encoder.encodeInt32(autoplay ? 1 : 0, forKey: "ap") + encoder.encodeInt32(loop ? 1 : 0, forKey: "lo") + case let .cover(block): + encoder.encodeInt32(InstantPageBlockType.cover.rawValue, forKey: "r") + encoder.encodeObject(block, forKey: "c") + case let .webEmbed(url, html, dimensions, caption, stretchToWidth, allowScrolling, coverId): + encoder.encodeInt32(InstantPageBlockType.webEmbed.rawValue, forKey: "r") + if let coverId = coverId { + encoder.encodeInt32(coverId.namespace, forKey: "ci.n") + encoder.encodeInt64(coverId.id, forKey: "ci.i") + } else { + encoder.encodeNil(forKey: "ci.n") + encoder.encodeNil(forKey: "ci.i") + } + if let url = url { + encoder.encodeString(url, forKey: "u") + } else { + encoder.encodeNil(forKey: "u") + } + if let html = html { + encoder.encodeString(html, forKey: "h") + } else { + encoder.encodeNil(forKey: "h") + } + if let dimensions = dimensions { + encoder.encodeInt32(Int32(dimensions.width), forKey: "sw") + encoder.encodeInt32(Int32(dimensions.height), forKey: "sh") + } else { + encoder.encodeNil(forKey: "sw") + encoder.encodeNil(forKey: "sh") + } + encoder.encodeObject(caption, forKey: "mc") + encoder.encodeInt32(stretchToWidth ? 1 : 0, forKey: "st") + encoder.encodeInt32(allowScrolling ? 1 : 0, forKey: "as") + case let .postEmbed(url, webpageId, avatarId, author, date, blocks, caption): + encoder.encodeInt32(InstantPageBlockType.postEmbed.rawValue, forKey: "r") + if let avatarId = avatarId { + encoder.encodeInt32(avatarId.namespace, forKey: "av.n") + encoder.encodeInt64(avatarId.id, forKey: "av.i") + } else { + encoder.encodeNil(forKey: "av.n") + encoder.encodeNil(forKey: "av.i") + } + encoder.encodeString(url, forKey: "u") + if let webpageId = webpageId { + encoder.encodeInt32(webpageId.namespace, forKey: "w.n") + encoder.encodeInt64(webpageId.id, forKey: "w.i") + } else { + encoder.encodeNil(forKey: "w.n") + encoder.encodeNil(forKey: "w.i") + } + encoder.encodeString(author, forKey: "a") + encoder.encodeInt32(date, forKey: "d") + encoder.encodeObjectArray(blocks, forKey: "b") + encoder.encodeObject(caption, forKey: "mc") + case let .collage(items, caption): + encoder.encodeInt32(InstantPageBlockType.collage.rawValue, forKey: "r") + encoder.encodeObjectArray(items, forKey: "b") + encoder.encodeObject(caption, forKey: "mc") + case let .slideshow(items, caption): + encoder.encodeInt32(InstantPageBlockType.slideshow.rawValue, forKey: "r") + encoder.encodeObjectArray(items, forKey: "b") + encoder.encodeObject(caption, forKey: "mc") + case let .channelBanner(channel): + encoder.encodeInt32(InstantPageBlockType.channelBanner.rawValue, forKey: "r") + if let channel = channel { + encoder.encodeObject(channel, forKey: "c") + } else { + encoder.encodeNil(forKey: "c") + } + case let .audio(id, caption): + encoder.encodeInt32(InstantPageBlockType.audio.rawValue, forKey: "r") + encoder.encodeInt32(id.namespace, forKey: "i.n") + encoder.encodeInt64(id.id, forKey: "i.i") + encoder.encodeObject(caption, forKey: "mc") + case let .kicker(text): + encoder.encodeInt32(InstantPageBlockType.kicker.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + case let .table(title, rows, bordered, striped): + encoder.encodeInt32(InstantPageBlockType.table.rawValue, forKey: "r") + encoder.encodeObject(title, forKey: "t") + encoder.encodeObjectArray(rows, forKey: "r") + encoder.encodeInt32(bordered ? 1 : 0, forKey: "b") + encoder.encodeInt32(striped ? 1 : 0, forKey: "s") + case let .details(title, blocks, expanded): + encoder.encodeInt32(InstantPageBlockType.details.rawValue, forKey: "r") + encoder.encodeObject(title, forKey: "t") + encoder.encodeObjectArray(blocks, forKey: "b") + encoder.encodeInt32(expanded ? 1 : 0, forKey: "o") + case let .relatedArticles(title, articles): + encoder.encodeInt32(InstantPageBlockType.relatedArticles.rawValue, forKey: "r") + encoder.encodeObject(title, forKey: "t") + encoder.encodeObjectArray(articles, forKey: "a") + case let .map(latitude, longitude, zoom, dimensions, caption): + encoder.encodeInt32(InstantPageBlockType.map.rawValue, forKey: "r") + encoder.encodeDouble(latitude, forKey: "lat") + encoder.encodeDouble(longitude, forKey: "lon") + encoder.encodeInt32(zoom, forKey: "z") + encoder.encodeInt32(Int32(dimensions.width), forKey: "sw") + encoder.encodeInt32(Int32(dimensions.height), forKey: "sh") + encoder.encodeObject(caption, forKey: "mc") + } + } + + public static func ==(lhs: InstantPageBlock, rhs: InstantPageBlock) -> Bool { + switch lhs { + case .unsupported: + if case .unsupported = rhs { + return true + } else { + return false + } + case let .title(text): + if case .title(text) = rhs { + return true + } else { + return false + } + case let .subtitle(text): + if case .subtitle(text) = rhs { + return true + } else { + return false + } + case let .authorDate(author, date): + if case .authorDate(author, date) = rhs { + return true + } else { + return false + } + case let .header(text): + if case .header(text) = rhs { + return true + } else { + return false + } + case let .subheader(text): + if case .subheader(text) = rhs { + return true + } else { + return false + } + case let .paragraph(text): + if case .paragraph(text) = rhs { + return true + } else { + return false + } + case let .preformatted(text): + if case .preformatted(text) = rhs { + return true + } else { + return false + } + case let .footer(text): + if case .footer(text) = rhs { + return true + } else { + return false + } + case .divider: + if case .divider = rhs { + return true + } else { + return false + } + case let .anchor(anchor): + if case .anchor(anchor) = rhs { + return true + } else { + return false + } + case let .list(lhsItems, lhsOrdered): + if case let .list(rhsItems, rhsOrdered) = rhs, lhsItems == rhsItems, lhsOrdered == rhsOrdered { + return true + } else { + return false + } + case let .blockQuote(text, caption): + if case .blockQuote(text, caption) = rhs { + return true + } else { + return false + } + case let .pullQuote(text, caption): + if case .pullQuote(text, caption) = rhs { + return true + } else { + return false + } + case let .image(lhsId, lhsCaption, lhsUrl, lhsWebpageId): + if case let .image(rhsId, rhsCaption, rhsUrl, rhsWebpageId) = rhs, lhsId == rhsId, lhsCaption == rhsCaption, lhsUrl == rhsUrl, lhsWebpageId == rhsWebpageId { + return true + } else { + return false + } + case let .video(id, caption, autoplay, loop): + if case .video(id, caption, autoplay, loop) = rhs { + return true + } else { + return false + } + case let .cover(block): + if case .cover(block) = rhs { + return true + } else { + return false + } + case let .webEmbed(lhsUrl, lhsHtml, lhsDimensions, lhsCaption, lhsStretchToWidth, lhsAllowScrolling, lhsCoverId): + if case let .webEmbed(rhsUrl, rhsHtml, rhsDimensions, rhsCaption, rhsStretchToWidth, rhsAllowScrolling, rhsCoverId) = rhs, lhsUrl == rhsUrl && lhsHtml == rhsHtml && lhsDimensions == rhsDimensions && lhsCaption == rhsCaption && lhsStretchToWidth == rhsStretchToWidth && lhsAllowScrolling == rhsAllowScrolling && lhsCoverId == rhsCoverId { + return true + } else { + return false + } + case let .postEmbed(lhsUrl, lhsWebpageId, lhsAvatarId, lhsAuthor, lhsDate, lhsBlocks, lhsCaption): + if case let .postEmbed(rhsUrl, rhsWebpageId, rhsAvatarId, rhsAuthor, rhsDate, rhsBlocks, rhsCaption) = rhs, lhsUrl == rhsUrl && lhsWebpageId == rhsWebpageId && lhsAvatarId == rhsAvatarId && lhsAuthor == rhsAuthor && lhsDate == rhsDate && lhsBlocks == rhsBlocks && lhsCaption == rhsCaption { + return true + } else { + return false + } + case let .collage(lhsItems, lhsCaption): + if case let .collage(rhsItems, rhsCaption) = rhs, lhsItems == rhsItems && lhsCaption == rhsCaption { + return true + } else { + return false + } + case let .slideshow(lhsItems, lhsCaption): + if case let .slideshow(rhsItems, rhsCaption) = rhs, lhsItems == rhsItems && lhsCaption == rhsCaption { + return true + } else { + return false + } + case let .channelBanner(lhsChannel): + if case let .channelBanner(rhsChannel) = rhs { + if let lhsChannel = lhsChannel, let rhsChannel = rhsChannel { + if !lhsChannel.isEqual(rhsChannel) { + return false + } + } else if (lhsChannel != nil) != (rhsChannel != nil) { + return false + } + return true + } else { + return false + } + case let .audio(id, caption): + if case .audio(id, caption) = rhs { + return true + } else { + return false + } + case let .kicker(text): + if case .kicker(text) = rhs { + return true + } else { + return false + } + case let .table(lhsTitle, lhsRows, lhsBordered, lhsStriped): + if case let .table(rhsTitle, rhsRows, rhsBordered, rhsStriped) = rhs, lhsTitle == rhsTitle, lhsRows == rhsRows, lhsBordered == rhsBordered, lhsStriped == rhsStriped { + return true + } else { + return false + } + case let .details(lhsTitle, lhsBlocks, lhsExpanded): + if case let .details(rhsTitle, rhsBlocks, rhsExpanded) = rhs, lhsTitle == rhsTitle, lhsBlocks == rhsBlocks, lhsExpanded == rhsExpanded { + return true + } else { + return false + } + case let .relatedArticles(lhsTitle, lhsArticles): + if case let .relatedArticles(rhsTitle, rhsArticles) = rhs, lhsTitle == rhsTitle, lhsArticles == rhsArticles { + return true + } else { + return false + } + case let .map(latitude, longitude, zoom, dimensions, caption): + if case .map(latitude, longitude, zoom, dimensions, caption) = rhs { + return true + } else { + return false + } + } + } +} + +public final class InstantPageCaption: PostboxCoding, Equatable { + public let text: RichText + public let credit: RichText + + public init(text: RichText, credit: RichText) { + self.text = text + self.credit = credit + } + + public init(decoder: PostboxDecoder) { + self.text = decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText + self.credit = decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as! RichText + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObject(self.text, forKey: "t") + encoder.encodeObject(self.credit, forKey: "c") + } + + public static func ==(lhs: InstantPageCaption, rhs: InstantPageCaption) -> Bool { + if lhs.text != rhs.text { + return false + } + if lhs.credit != rhs.credit { + return false + } + return true + } +} + +private enum InstantPageListItemType: Int32 { + case unknown = 0 + case text = 1 + case blocks = 2 +} + +public indirect enum InstantPageListItem: PostboxCoding, Equatable { + case unknown + case text(RichText, String?) + case blocks([InstantPageBlock], String?) + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("r", orElse: 0) { + case InstantPageListItemType.text.rawValue: + self = .text(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, decoder.decodeOptionalStringForKey("n")) + case InstantPageListItemType.blocks.rawValue: + self = .blocks(decoder.decodeObjectArrayWithDecoderForKey("b"), decoder.decodeOptionalStringForKey("n")) + default: + self = .unknown + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .text(text, num): + encoder.encodeInt32(InstantPageListItemType.text.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + if let num = num { + encoder.encodeString(num, forKey: "n") + } else { + encoder.encodeNil(forKey: "n") + } + case let .blocks(blocks, num): + encoder.encodeInt32(InstantPageListItemType.blocks.rawValue, forKey: "r") + encoder.encodeObjectArray(blocks, forKey: "b") + if let num = num { + encoder.encodeString(num, forKey: "n") + } else { + encoder.encodeNil(forKey: "n") + } + default: + break + } + } + + public static func ==(lhs: InstantPageListItem, rhs: InstantPageListItem) -> Bool { + switch lhs { + case .unknown: + if case .unknown = rhs { + return true + } else { + return false + } + case let .text(lhsText, lhsNum): + if case let .text(rhsText, rhsNum) = rhs, lhsText == rhsText, lhsNum == rhsNum { + return true + } else { + return false + } + case let .blocks(lhsBlocks, lhsNum): + if case let .blocks(rhsBlocks, rhsNum) = rhs, lhsBlocks == rhsBlocks, lhsNum == rhsNum { + return true + } else { + return false + } + } + } +} + +public enum TableHorizontalAlignment: Int32 { + case left = 0 + case center = 1 + case right = 2 +} + +public enum TableVerticalAlignment: Int32 { + case top = 0 + case middle = 1 + case bottom = 2 +} + +public final class InstantPageTableCell: PostboxCoding, Equatable { + public let text: RichText? + public let header: Bool + public let alignment: TableHorizontalAlignment + public let verticalAlignment: TableVerticalAlignment + public let colspan: Int32 + public let rowspan: Int32 + + public init(text: RichText?, header: Bool, alignment: TableHorizontalAlignment, verticalAlignment: TableVerticalAlignment, colspan: Int32, rowspan: Int32) { + self.text = text + self.header = header + self.alignment = alignment + self.verticalAlignment = verticalAlignment + self.colspan = colspan + self.rowspan = rowspan + } + + public init(decoder: PostboxDecoder) { + self.text = decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as? RichText + self.header = decoder.decodeInt32ForKey("h", orElse: 0) != 0 + self.alignment = TableHorizontalAlignment(rawValue: decoder.decodeInt32ForKey("ha", orElse: 0))! + self.verticalAlignment = TableVerticalAlignment(rawValue: decoder.decodeInt32ForKey("va", orElse: 0))! + self.colspan = decoder.decodeInt32ForKey("sc", orElse: 0) + self.rowspan = decoder.decodeInt32ForKey("sr", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + if let text = self.text { + encoder.encodeObject(text, forKey: "t") + } else { + encoder.encodeNil(forKey: "t") + } + encoder.encodeInt32(self.header ? 1 : 0, forKey: "h") + encoder.encodeInt32(self.alignment.rawValue, forKey: "ha") + encoder.encodeInt32(self.verticalAlignment.rawValue, forKey: "va") + encoder.encodeInt32(self.colspan, forKey: "sc") + encoder.encodeInt32(self.rowspan, forKey: "sr") + } + + public static func ==(lhs: InstantPageTableCell, rhs: InstantPageTableCell) -> Bool { + if lhs.text != rhs.text { + return false + } + if lhs.header != rhs.header { + return false + } + if lhs.alignment != rhs.alignment { + return false + } + if lhs.verticalAlignment != rhs.verticalAlignment { + return false + } + if lhs.colspan != rhs.colspan { + return false + } + if lhs.rowspan != rhs.rowspan { + return false + } + return true + } +} + +public final class InstantPageTableRow: PostboxCoding, Equatable { + public let cells: [InstantPageTableCell] + + public init(cells: [InstantPageTableCell]) { + self.cells = cells + } + + public init(decoder: PostboxDecoder) { + self.cells = decoder.decodeObjectArrayWithDecoderForKey("c") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObjectArray(self.cells, forKey: "c") + } + + public static func ==(lhs: InstantPageTableRow, rhs: InstantPageTableRow) -> Bool { + return lhs.cells == rhs.cells + } +} + +public final class InstantPageRelatedArticle: PostboxCoding, Equatable { + public let url: String + public let webpageId: MediaId + public let title: String? + public let description: String? + public let photoId: MediaId? + public let author: String? + public let date: Int32? + + public init(url: String, webpageId: MediaId, title: String?, description: String?, photoId: MediaId?, author: String?, date: Int32?) { + self.url = url + self.webpageId = webpageId + self.title = title + self.description = description + self.photoId = photoId + self.author = author + self.date = date + } + + public init(decoder: PostboxDecoder) { + self.url = decoder.decodeStringForKey("u", orElse: "") + let webpageIdNamespace = decoder.decodeInt32ForKey("w.n", orElse: 0) + let webpageIdId = decoder.decodeInt64ForKey("w.i", orElse: 0) + self.webpageId = MediaId(namespace: webpageIdNamespace, id: webpageIdId) + + self.title = decoder.decodeOptionalStringForKey("t") + self.description = decoder.decodeOptionalStringForKey("d") + + var photoId: MediaId? + if let photoIdNamespace = decoder.decodeOptionalInt32ForKey("p.n"), let photoIdId = decoder.decodeOptionalInt64ForKey("p.i") { + photoId = MediaId(namespace: photoIdNamespace, id: photoIdId) + } + self.photoId = photoId + self.author = decoder.decodeOptionalStringForKey("a") + self.date = decoder.decodeOptionalInt32ForKey("d") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.url, forKey: "u") + encoder.encodeInt32(self.webpageId.namespace, forKey: "w.n") + encoder.encodeInt64(self.webpageId.id, forKey: "w.i") + if let title = self.title { + encoder.encodeString(title, forKey: "t") + } else { + encoder.encodeNil(forKey: "t") + } + if let description = self.description { + encoder.encodeString(description, forKey: "d") + } else { + encoder.encodeNil(forKey: "d") + } + if let photoId = photoId { + encoder.encodeInt32(photoId.namespace, forKey: "p.n") + encoder.encodeInt64(photoId.id, forKey: "p.i") + } else { + encoder.encodeNil(forKey: "p.n") + encoder.encodeNil(forKey: "p.i") + } + if let author = self.author { + encoder.encodeString(author, forKey: "a") + } else { + encoder.encodeNil(forKey: "a") + } + if let date = self.date { + encoder.encodeInt32(date, forKey: "d") + } else { + encoder.encodeNil(forKey: "d") + } + } + + public static func ==(lhs: InstantPageRelatedArticle, rhs: InstantPageRelatedArticle) -> Bool { + if lhs.url != rhs.url { + return false + } + if lhs.webpageId != rhs.webpageId { + return false + } + if lhs.title != rhs.title { + return false + } + if lhs.description != rhs.description { + return false + } + if lhs.photoId != rhs.photoId { + return false + } + if lhs.author != rhs.author { + return false + } + if lhs.date != rhs.date { + return false + } + return true + } +} + +private final class MediaDictionary: PostboxCoding { + let dict: [MediaId: Media] + + init(dict: [MediaId: Media]) { + self.dict = dict + } + + init(decoder: PostboxDecoder) { + let idsBufer = decoder.decodeBytesForKey("i")! + let mediaIds = MediaId.decodeArrayFromBuffer(idsBufer) + let medias = decoder.decodeObjectArrayForKey("m") + var dict: [MediaId: Media] = [:] + assert(mediaIds.count == medias.count) + for i in 0 ..< mediaIds.count { + if let media = medias[i] as? Media { + dict[mediaIds[i]] = media + } + } + self.dict = dict + } + + func encode(_ encoder: PostboxEncoder) { + var mediaIds: [MediaId] = [] + var medias: [PostboxCoding] = [] + for mediaId in self.dict.keys { + mediaIds.append(mediaId) + medias.append(self.dict[mediaId]!) + } + let buffer = WriteBuffer() + MediaId.encodeArrayToBuffer(mediaIds, buffer: buffer) + encoder.encodeBytes(buffer, forKey: "i") + encoder.encodeGenericObjectArray(medias, forKey: "m") + } +} + +public final class InstantPage: PostboxCoding, Equatable { + public let blocks: [InstantPageBlock] + public let media: [MediaId: Media] + public let isComplete: Bool + public let rtl: Bool + public let url: String + + public init(blocks: [InstantPageBlock], media: [MediaId: Media], isComplete: Bool, rtl: Bool, url: String) { + self.blocks = blocks + self.media = media + self.isComplete = isComplete + self.rtl = rtl + self.url = url + } + + public init(decoder: PostboxDecoder) { + self.blocks = decoder.decodeObjectArrayWithDecoderForKey("b") + self.media = MediaDictionary(decoder: decoder).dict + self.isComplete = decoder.decodeInt32ForKey("c", orElse: 0) != 0 + self.rtl = decoder.decodeInt32ForKey("r", orElse: 0) != 0 + self.url = decoder.decodeStringForKey("url", orElse: "") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObjectArray(self.blocks, forKey: "b") + MediaDictionary(dict: self.media).encode(encoder) + encoder.encodeInt32(self.isComplete ? 1 : 0, forKey: "c") + encoder.encodeInt32(self.rtl ? 1 : 0, forKey: "r") + encoder.encodeString(self.url, forKey: "url") + } + + public static func ==(lhs: InstantPage, rhs: InstantPage) -> Bool { + if lhs.blocks != rhs.blocks { + return false + } + if lhs.media.count != rhs.media.count { + return false + } else { + for (lhsKey, lhsValue) in lhs.media { + if let media = rhs.media[lhsKey] { + if !lhsValue.isEqual(to: media) { + return false + } + } else { + return false + } + } + } + if lhs.isComplete != rhs.isComplete { + return false + } + if lhs.rtl != rhs.rtl { + return false + } + if lhs.url != rhs.url { + return false + } + return true + } +} diff --git a/submodules/SyncCore/Sources/JSON.swift b/submodules/SyncCore/Sources/JSON.swift new file mode 100644 index 0000000000..ef51457723 --- /dev/null +++ b/submodules/SyncCore/Sources/JSON.swift @@ -0,0 +1,93 @@ +import Postbox + +public indirect enum JSON: PostboxCoding, Equatable { + case null + case number(Double) + case string(String) + case bool(Bool) + case array([JSON]) + case dictionary([String: JSON]) + + private enum ValueType: Int32 { + case null = 0 + case number = 1 + case string = 2 + case bool = 3 + case array = 4 + case dictionary = 5 + } + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("r", orElse: 0) { + case ValueType.null.rawValue: + self = .null + case ValueType.number.rawValue: + self = .number(decoder.decodeDoubleForKey("v", orElse: 0.0)) + case ValueType.string.rawValue: + self = .string(decoder.decodeStringForKey("v", orElse: "")) + case ValueType.bool.rawValue: + self = .bool(decoder.decodeBoolForKey("v", orElse: false)) + case ValueType.array.rawValue: + self = .array(decoder.decodeObjectArrayForKey("v")) + case ValueType.dictionary.rawValue: + self = .dictionary(decoder.decodeObjectDictionaryForKey("v", keyDecoder: { $0.decodeStringForKey("k", orElse: "") + }, valueDecoder: { JSON(decoder: $0) })) + default: + self = .null + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case .null: + encoder.encodeInt32(ValueType.null.rawValue, forKey: "r") + case let .number(value): + encoder.encodeInt32(ValueType.number.rawValue, forKey: "r") + encoder.encodeDouble(value, forKey: "v") + case let .string(value): + encoder.encodeInt32(ValueType.string.rawValue, forKey: "r") + encoder.encodeString(value, forKey: "v") + case let .bool(value): + encoder.encodeInt32(ValueType.bool.rawValue, forKey: "r") + encoder.encodeBool(value, forKey: "v") + case let .array(value): + encoder.encodeInt32(ValueType.array.rawValue, forKey: "r") + encoder.encodeObjectArray(value, forKey: "v") + case let .dictionary(value): + encoder.encodeInt32(ValueType.dictionary.rawValue, forKey: "r") + encoder.encodeObjectDictionary(value, forKey: "v") { key, encoder in + encoder.encodeString(key, forKey: "k") + } + } + } + + public enum Index: Comparable { + case array(Int) + case dictionary(DictionaryIndex) + case null + + static public func ==(lhs: Index, rhs: Index) -> Bool { + switch (lhs, rhs) { + case let (.array(lhs), .array(rhs)): + return lhs == rhs + case let (.dictionary(lhs), .dictionary(rhs)): + return lhs == rhs + case (.null, .null): + return true + default: + return false + } + } + + static public func <(lhs: Index, rhs: Index) -> Bool { + switch (lhs, rhs) { + case let (.array(lhs), .array(rhs)): + return lhs < rhs + case let (.dictionary(lhs), .dictionary(rhs)): + return lhs < rhs + default: + return false + } + } + } +} diff --git a/submodules/SyncCore/Sources/LimitsConfiguration.swift b/submodules/SyncCore/Sources/LimitsConfiguration.swift new file mode 100644 index 0000000000..b087e508ca --- /dev/null +++ b/submodules/SyncCore/Sources/LimitsConfiguration.swift @@ -0,0 +1,74 @@ +import Postbox + +public struct LimitsConfiguration: Equatable, PreferencesEntry { + public static let timeIntervalForever: Int32 = 0x7fffffff + + public var maxPinnedChatCount: Int32 + public var maxArchivedPinnedChatCount: Int32 + public var maxGroupMemberCount: Int32 + public var maxSupergroupMemberCount: Int32 + public var maxMessageForwardBatchSize: Int32 + public var maxSavedGifCount: Int32 + public var maxRecentStickerCount: Int32 + public var maxMessageEditingInterval: Int32 + public var maxMediaCaptionLength: Int32 + public var canRemoveIncomingMessagesInPrivateChats: Bool + public var maxMessageRevokeInterval: Int32 + public var maxMessageRevokeIntervalInPrivateChats: Int32 + + public static var defaultValue: LimitsConfiguration { + return LimitsConfiguration(maxPinnedChatCount: 5, maxArchivedPinnedChatCount: 20, maxGroupMemberCount: 200, maxSupergroupMemberCount: 200000, maxMessageForwardBatchSize: 50, maxSavedGifCount: 200, maxRecentStickerCount: 20, maxMessageEditingInterval: 2 * 24 * 60 * 60, maxMediaCaptionLength: 1000, canRemoveIncomingMessagesInPrivateChats: false, maxMessageRevokeInterval: 2 * 24 * 60 * 60, maxMessageRevokeIntervalInPrivateChats: 2 * 24 * 60 * 60) + } + + public init(maxPinnedChatCount: Int32, maxArchivedPinnedChatCount: Int32, maxGroupMemberCount: Int32, maxSupergroupMemberCount: Int32, maxMessageForwardBatchSize: Int32, maxSavedGifCount: Int32, maxRecentStickerCount: Int32, maxMessageEditingInterval: Int32, maxMediaCaptionLength: Int32, canRemoveIncomingMessagesInPrivateChats: Bool, maxMessageRevokeInterval: Int32, maxMessageRevokeIntervalInPrivateChats: Int32) { + self.maxPinnedChatCount = maxPinnedChatCount + self.maxArchivedPinnedChatCount = maxArchivedPinnedChatCount + self.maxGroupMemberCount = maxGroupMemberCount + self.maxSupergroupMemberCount = maxSupergroupMemberCount + self.maxMessageForwardBatchSize = maxMessageForwardBatchSize + self.maxSavedGifCount = maxSavedGifCount + self.maxRecentStickerCount = maxRecentStickerCount + self.maxMessageEditingInterval = maxMessageEditingInterval + self.maxMediaCaptionLength = maxMediaCaptionLength + self.canRemoveIncomingMessagesInPrivateChats = canRemoveIncomingMessagesInPrivateChats + self.maxMessageRevokeInterval = maxMessageRevokeInterval + self.maxMessageRevokeIntervalInPrivateChats = maxMessageRevokeIntervalInPrivateChats + } + + public init(decoder: PostboxDecoder) { + self.maxPinnedChatCount = decoder.decodeInt32ForKey("maxPinnedChatCount", orElse: 5) + self.maxArchivedPinnedChatCount = decoder.decodeInt32ForKey("maxArchivedPinnedChatCount", orElse: 20) + self.maxGroupMemberCount = decoder.decodeInt32ForKey("maxGroupMemberCount", orElse: 200) + self.maxSupergroupMemberCount = decoder.decodeInt32ForKey("maxSupergroupMemberCount", orElse: 5000) + self.maxMessageForwardBatchSize = decoder.decodeInt32ForKey("maxMessageForwardBatchSize", orElse: 50) + self.maxSavedGifCount = decoder.decodeInt32ForKey("maxSavedGifCount", orElse: 200) + self.maxRecentStickerCount = decoder.decodeInt32ForKey("maxRecentStickerCount", orElse: 20) + self.maxMessageEditingInterval = decoder.decodeInt32ForKey("maxMessageEditingInterval", orElse: 2 * 24 * 60 * 60) + self.maxMediaCaptionLength = decoder.decodeInt32ForKey("maxMediaCaptionLength", orElse: 1000) + self.canRemoveIncomingMessagesInPrivateChats = decoder.decodeInt32ForKey("canRemoveIncomingMessagesInPrivateChats", orElse: 0) != 0 + self.maxMessageRevokeInterval = decoder.decodeInt32ForKey("maxMessageRevokeInterval", orElse: 2 * 24 * 60 * 60) + self.maxMessageRevokeIntervalInPrivateChats = decoder.decodeInt32ForKey("maxMessageRevokeIntervalInPrivateChats", orElse: 2 * 24 * 60 * 60) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.maxPinnedChatCount, forKey: "maxPinnedChatCount") + encoder.encodeInt32(self.maxArchivedPinnedChatCount, forKey: "maxArchivedPinnedChatCount") + encoder.encodeInt32(self.maxGroupMemberCount, forKey: "maxGroupMemberCount") + encoder.encodeInt32(self.maxSupergroupMemberCount, forKey: "maxSupergroupMemberCount") + encoder.encodeInt32(self.maxMessageForwardBatchSize, forKey: "maxMessageForwardBatchSize") + encoder.encodeInt32(self.maxSavedGifCount, forKey: "maxSavedGifCount") + encoder.encodeInt32(self.maxRecentStickerCount, forKey: "maxRecentStickerCount") + encoder.encodeInt32(self.maxMessageEditingInterval, forKey: "maxMessageEditingInterval") + encoder.encodeInt32(self.maxMediaCaptionLength, forKey: "maxMediaCaptionLength") + encoder.encodeInt32(self.canRemoveIncomingMessagesInPrivateChats ? 1 : 0, forKey: "canRemoveIncomingMessagesInPrivateChats") + encoder.encodeInt32(self.maxMessageRevokeInterval, forKey: "maxMessageRevokeInterval") + encoder.encodeInt32(self.maxMessageRevokeIntervalInPrivateChats, forKey: "maxMessageRevokeIntervalInPrivateChats") + } + + public func isEqual(to: PreferencesEntry) -> Bool { + guard let to = to as? LimitsConfiguration else { + return false + } + return self == to + } +} diff --git a/submodules/TelegramCore/TelegramCore/Localization.swift b/submodules/SyncCore/Sources/Localization.swift similarity index 84% rename from submodules/TelegramCore/TelegramCore/Localization.swift rename to submodules/SyncCore/Sources/Localization.swift index 2cc395e0e7..73831673aa 100644 --- a/submodules/TelegramCore/TelegramCore/Localization.swift +++ b/submodules/SyncCore/Sources/Localization.swift @@ -11,48 +11,10 @@ public enum LocalizationEntry: Equatable { public var key: String { switch self { - case let .string(key, _): - return key - case let .pluralizedString(key, _, _, _, _, _, _): - return key - } - } - - public static func ==(lhs: LocalizationEntry, rhs: LocalizationEntry) -> Bool { - switch lhs { - case let .string(lhsKey, lhsValue): - if case let .string(rhsKey, rhsValue) = rhs, lhsKey == rhsKey, lhsValue == rhsValue { - return true - } else { - return false - } - case let .pluralizedString(lhsKey, lhsZero, lhsOne, lhsTwo, lhsFew, lhsMany, lhsOther): - if case let .pluralizedString(rhsKey, rhsZero, rhsOne, rhsTwo, rhsFew, rhsMany, rhsOther) = rhs { - if lhsKey != rhsKey { - return false - } - if lhsZero != rhsZero { - return false - } - if lhsOne != rhsOne { - return false - } - if lhsTwo != rhsTwo { - return false - } - if lhsFew != rhsFew { - return false - } - if lhsMany != rhsMany { - return false - } - if lhsOther != rhsOther { - return false - } - return true - } else { - return false - } + case let .string(key, _): + return key + case let .pluralizedString(key, _, _, _, _, _, _): + return key } } } diff --git a/submodules/SyncCore/Sources/LocalizationInfo.swift b/submodules/SyncCore/Sources/LocalizationInfo.swift new file mode 100644 index 0000000000..add477b445 --- /dev/null +++ b/submodules/SyncCore/Sources/LocalizationInfo.swift @@ -0,0 +1,57 @@ +import Postbox + +public struct LocalizationInfo: PostboxCoding, Equatable { + public let languageCode: String + public let baseLanguageCode: String? + public let customPluralizationCode: String? + public let title: String + public let localizedTitle: String + public let isOfficial: Bool + public let totalStringCount: Int32 + public let translatedStringCount: Int32 + public let platformUrl: String + + public init(languageCode: String, baseLanguageCode: String?, customPluralizationCode: String?, title: String, localizedTitle: String, isOfficial: Bool, totalStringCount: Int32, translatedStringCount: Int32, platformUrl: String) { + self.languageCode = languageCode + self.baseLanguageCode = baseLanguageCode + self.customPluralizationCode = customPluralizationCode + self.title = title + self.localizedTitle = localizedTitle + self.isOfficial = isOfficial + self.totalStringCount = totalStringCount + self.translatedStringCount = translatedStringCount + self.platformUrl = platformUrl + } + + public init(decoder: PostboxDecoder) { + self.languageCode = decoder.decodeStringForKey("lc", orElse: "") + self.baseLanguageCode = decoder.decodeOptionalStringForKey("nlc") + self.customPluralizationCode = decoder.decodeOptionalStringForKey("cpc") + self.title = decoder.decodeStringForKey("t", orElse: "") + self.localizedTitle = decoder.decodeStringForKey("lt", orElse: "") + self.isOfficial = decoder.decodeInt32ForKey("of", orElse: 0) != 0 + self.totalStringCount = decoder.decodeInt32ForKey("tsc", orElse: 0) + self.translatedStringCount = decoder.decodeInt32ForKey("lsc", orElse: 0) + self.platformUrl = decoder.decodeStringForKey("platformUrl", orElse: "") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.languageCode, forKey: "lc") + if let baseLanguageCode = self.baseLanguageCode { + encoder.encodeString(baseLanguageCode, forKey: "nlc") + } else { + encoder.encodeNil(forKey: "nlc") + } + if let customPluralizationCode = self.customPluralizationCode { + encoder.encodeString(customPluralizationCode, forKey: "cpc") + } else { + encoder.encodeNil(forKey: "cpc") + } + encoder.encodeString(self.title, forKey: "t") + encoder.encodeString(self.localizedTitle, forKey: "lt") + encoder.encodeInt32(self.isOfficial ? 1 : 0, forKey: "of") + encoder.encodeInt32(self.totalStringCount, forKey: "tsc") + encoder.encodeInt32(self.translatedStringCount, forKey: "lsc") + encoder.encodeString(self.platformUrl, forKey: "platformUrl") + } +} diff --git a/submodules/SyncCore/Sources/LocalizationListState.swift b/submodules/SyncCore/Sources/LocalizationListState.swift new file mode 100644 index 0000000000..e9d2195422 --- /dev/null +++ b/submodules/SyncCore/Sources/LocalizationListState.swift @@ -0,0 +1,33 @@ +import Postbox + +public struct LocalizationListState: PreferencesEntry, Equatable { + public var availableOfficialLocalizations: [LocalizationInfo] + public var availableSavedLocalizations: [LocalizationInfo] + + public static var defaultSettings: LocalizationListState { + return LocalizationListState(availableOfficialLocalizations: [], availableSavedLocalizations: []) + } + + public init(availableOfficialLocalizations: [LocalizationInfo], availableSavedLocalizations: [LocalizationInfo]) { + self.availableOfficialLocalizations = availableOfficialLocalizations + self.availableSavedLocalizations = availableSavedLocalizations + } + + public init(decoder: PostboxDecoder) { + self.availableOfficialLocalizations = decoder.decodeObjectArrayWithDecoderForKey("availableOfficialLocalizations") + self.availableSavedLocalizations = decoder.decodeObjectArrayWithDecoderForKey("availableSavedLocalizations") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObjectArray(self.availableOfficialLocalizations, forKey: "availableOfficialLocalizations") + encoder.encodeObjectArray(self.availableSavedLocalizations, forKey: "availableSavedLocalizations") + } + + public func isEqual(to: PreferencesEntry) -> Bool { + guard let to = to as? LocalizationListState else { + return false + } + + return self == to + } +} diff --git a/submodules/TelegramCore/TelegramCore/LocalizationSettings.swift b/submodules/SyncCore/Sources/LocalizationSettings.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/LocalizationSettings.swift rename to submodules/SyncCore/Sources/LocalizationSettings.swift diff --git a/submodules/TelegramCore/TelegramCore/LoggedOutAccountAttribute.swift b/submodules/SyncCore/Sources/LoggedOutAccountAttribute.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/LoggedOutAccountAttribute.swift rename to submodules/SyncCore/Sources/LoggedOutAccountAttribute.swift diff --git a/submodules/SyncCore/Sources/LoggingSettings.swift b/submodules/SyncCore/Sources/LoggingSettings.swift new file mode 100644 index 0000000000..e4925d41e7 --- /dev/null +++ b/submodules/SyncCore/Sources/LoggingSettings.swift @@ -0,0 +1,64 @@ +import Postbox + +public final class LoggingSettings: PreferencesEntry, Equatable { + public let logToFile: Bool + public let logToConsole: Bool + public let redactSensitiveData: Bool + + #if DEBUG + public static var defaultSettings = LoggingSettings(logToFile: true, logToConsole: true, redactSensitiveData: true) + #else + public static var defaultSettings = LoggingSettings(logToFile: false, logToConsole: false, redactSensitiveData: true) + #endif + + public init(logToFile: Bool, logToConsole: Bool, redactSensitiveData: Bool) { + self.logToFile = logToFile + self.logToConsole = logToConsole + self.redactSensitiveData = redactSensitiveData + } + + public init(decoder: PostboxDecoder) { + self.logToFile = decoder.decodeInt32ForKey("logToFile", orElse: 0) != 0 + self.logToConsole = decoder.decodeInt32ForKey("logToConsole", orElse: 0) != 0 + self.redactSensitiveData = decoder.decodeInt32ForKey("redactSensitiveData", orElse: 1) != 0 + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.logToFile ? 1 : 0, forKey: "logToFile") + encoder.encodeInt32(self.logToConsole ? 1 : 0, forKey: "logToConsole") + encoder.encodeInt32(self.redactSensitiveData ? 1 : 0, forKey: "redactSensitiveData") + } + + public func withUpdatedLogToFile(_ logToFile: Bool) -> LoggingSettings { + return LoggingSettings(logToFile: logToFile, logToConsole: self.logToConsole, redactSensitiveData: self.redactSensitiveData) + } + + public func withUpdatedLogToConsole(_ logToConsole: Bool) -> LoggingSettings { + return LoggingSettings(logToFile: self.logToFile, logToConsole: logToConsole, redactSensitiveData: self.redactSensitiveData) + } + + public func withUpdatedRedactSensitiveData(_ redactSensitiveData: Bool) -> LoggingSettings { + return LoggingSettings(logToFile: self.logToFile, logToConsole: self.logToConsole, redactSensitiveData: redactSensitiveData) + } + + public static func ==(lhs: LoggingSettings, rhs: LoggingSettings) -> Bool { + if lhs.logToFile != rhs.logToFile { + return false + } + if lhs.logToConsole != rhs.logToConsole { + return false + } + if lhs.redactSensitiveData != rhs.redactSensitiveData { + return false + } + return true + } + + public func isEqual(to: PreferencesEntry) -> Bool { + guard let to = to as? LoggingSettings else { + return false + } + + return self == to + } +} diff --git a/submodules/SyncCore/Sources/MediaReference.swift b/submodules/SyncCore/Sources/MediaReference.swift new file mode 100644 index 0000000000..bf20c50227 --- /dev/null +++ b/submodules/SyncCore/Sources/MediaReference.swift @@ -0,0 +1,491 @@ +import Postbox + +public struct MessageReference: PostboxCoding, Hashable, Equatable { + public let content: MessageReferenceContent + + public var peer: PeerReference? { + switch content { + case .none: + return nil + case let .message(peer, _, _, _, _): + return peer + } + } + + public var timestamp: Int32? { + switch content { + case .none: + return nil + case let .message(_, _, timestamp, _, _): + return timestamp + } + } + + public var isIncoming: Bool? { + switch content { + case .none: + return nil + case let .message(_, _, _, incoming, _): + return incoming + } + } + + public var isSecret: Bool? { + switch content { + case .none: + return nil + case let .message(_, _, _, _, secret): + return secret + } + } + + public init(_ message: Message) { + if message.id.namespace != Namespaces.Message.Local, let peer = message.peers[message.id.peerId], let inputPeer = PeerReference(peer) { + self.content = .message(peer: inputPeer, id: message.id, timestamp: message.timestamp, incoming: message.flags.contains(.Incoming), secret: message.containsSecretMedia) + } else { + self.content = .none + } + } + + public init(peer: Peer, id: MessageId, timestamp: Int32, incoming: Bool, secret: Bool) { + if let inputPeer = PeerReference(peer) { + self.content = .message(peer: inputPeer, id: id, timestamp: timestamp, incoming: incoming, secret: secret) + } else { + self.content = .none + } + } + + public init(decoder: PostboxDecoder) { + self.content = decoder.decodeObjectForKey("c", decoder: { MessageReferenceContent(decoder: $0) }) as! MessageReferenceContent + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObject(self.content, forKey: "c") + } +} + +public enum MessageReferenceContent: PostboxCoding, Hashable, Equatable { + case none + case message(peer: PeerReference, id: MessageId, timestamp: Int32, incoming: Bool, secret: Bool) + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("_r", orElse: 0) { + case 0: + self = .none + case 1: + self = .message(peer: decoder.decodeObjectForKey("p", decoder: { PeerReference(decoder: $0) }) as! PeerReference, id: MessageId(peerId: PeerId(decoder.decodeInt64ForKey("i.p", orElse: 0)), namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt32ForKey("i.i", orElse: 0)), timestamp: 0, incoming: false, secret: false) + default: + assertionFailure() + self = .none + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case .none: + encoder.encodeInt32(0, forKey: "_r") + case let .message(peer, id, _, _, _): + encoder.encodeInt32(1, forKey: "_r") + encoder.encodeObject(peer, forKey: "p") + encoder.encodeInt64(id.peerId.toInt64(), forKey: "i.p") + encoder.encodeInt32(id.namespace, forKey: "i.n") + encoder.encodeInt32(id.id, forKey: "i.i") + } + } +} + +public struct WebpageReference: PostboxCoding, Hashable, Equatable { + public let content: WebpageReferenceContent + + public init(_ webPage: TelegramMediaWebpage) { + if case let .Loaded(content) = webPage.content { + self.content = .webPage(id: webPage.webpageId.id, url: content.url) + } else { + self.content = .none + } + } + + public init(decoder: PostboxDecoder) { + self.content = decoder.decodeObjectForKey("c", decoder: { WebpageReferenceContent(decoder: $0) }) as! WebpageReferenceContent + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObject(self.content, forKey: "c") + } +} + +public enum WebpageReferenceContent: PostboxCoding, Hashable, Equatable { + case none + case webPage(id: Int64, url: String) + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("_r", orElse: 0) { + case 0: + self = .none + case 1: + self = .webPage(id: decoder.decodeInt64ForKey("i", orElse: 0), url: decoder.decodeStringForKey("u", orElse: "")) + default: + assertionFailure() + self = .none + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case .none: + encoder.encodeInt32(0, forKey: "_r") + case let .webPage(id, url): + encoder.encodeInt32(1, forKey: "_r") + encoder.encodeInt64(id, forKey: "i") + encoder.encodeString(url, forKey: "u") + } + } +} + +public enum AnyMediaReference: Equatable { + case standalone(media: Media) + case message(message: MessageReference, media: Media) + case webPage(webPage: WebpageReference, media: Media) + case stickerPack(stickerPack: StickerPackReference, media: Media) + case savedGif(media: Media) + + public static func ==(lhs: AnyMediaReference, rhs: AnyMediaReference) -> Bool { + switch lhs { + case let .standalone(lhsMedia): + if case let .standalone(rhsMedia) = rhs, lhsMedia.isEqual(to: rhsMedia) { + return true + } else { + return false + } + case let .message(lhsMessage, lhsMedia): + if case let .message(rhsMessage, rhsMedia) = rhs, lhsMessage == rhsMessage, lhsMedia.isEqual(to: rhsMedia) { + return true + } else { + return false + } + case let .webPage(lhsWebPage, lhsMedia): + if case let .webPage(rhsWebPage, rhsMedia) = rhs, lhsWebPage == rhsWebPage, lhsMedia.isEqual(to: rhsMedia) { + return true + } else { + return false + } + case let .stickerPack(lhsStickerPack, lhsMedia): + if case let .stickerPack(rhsStickerPack, rhsMedia) = rhs, lhsStickerPack == rhsStickerPack, lhsMedia.isEqual(to: rhsMedia) { + return true + } else { + return false + } + case let .savedGif(lhsMedia): + if case let .savedGif(rhsMedia) = rhs, lhsMedia.isEqual(to: rhsMedia) { + return true + } else { + return false + } + } + } + + public var partial: PartialMediaReference? { + switch self { + case .standalone: + return nil + case let .message(message, _): + return .message(message: message) + case let .webPage(webPage, _): + return .webPage(webPage: webPage) + case let .stickerPack(stickerPack, _): + return .stickerPack(stickerPack: stickerPack) + case .savedGif: + return .savedGif + } + } + + public func concrete(_ type: T.Type) -> MediaReference? { + switch self { + case let .standalone(media): + if let media = media as? T { + return .standalone(media: media) + } + case let .message(message, media): + if let media = media as? T { + return .message(message: message, media: media) + } + case let .webPage(webPage, media): + if let media = media as? T { + return .webPage(webPage: webPage, media: media) + } + case let .stickerPack(stickerPack, media): + if let media = media as? T { + return .stickerPack(stickerPack: stickerPack, media: media) + } + case let .savedGif(media): + if let media = media as? T { + return .savedGif(media: media) + } + } + return nil + } + + public var media: Media { + switch self { + case let .standalone(media): + return media + case let .message(_, media): + return media + case let .webPage(_, media): + return media + case let .stickerPack(_, media): + return media + case let .savedGif(media): + return media + } + } + + public func resourceReference(_ resource: MediaResource) -> MediaResourceReference { + return .media(media: self, resource: resource) + } +} + +public enum PartialMediaReference: Equatable { + private enum CodingCase: Int32 { + case message + case webPage + case stickerPack + case savedGif + } + + case message(message: MessageReference) + case webPage(webPage: WebpageReference) + case stickerPack(stickerPack: StickerPackReference) + case savedGif + + public init?(decoder: PostboxDecoder) { + guard let caseIdValue = decoder.decodeOptionalInt32ForKey("_r"), let caseId = CodingCase(rawValue: caseIdValue) else { + return nil + } + switch caseId { + case .message: + let message = decoder.decodeObjectForKey("msg", decoder: { MessageReference(decoder: $0) }) as! MessageReference + self = .message(message: message) + case .webPage: + let webPage = decoder.decodeObjectForKey("wpg", decoder: { WebpageReference(decoder: $0) }) as! WebpageReference + self = .webPage(webPage: webPage) + case .stickerPack: + let stickerPack = decoder.decodeObjectForKey("spk", decoder: { StickerPackReference(decoder: $0) }) as! StickerPackReference + self = .stickerPack(stickerPack: stickerPack) + case .savedGif: + self = .savedGif + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .message(message): + encoder.encodeInt32(CodingCase.message.rawValue, forKey: "_r") + encoder.encodeObject(message, forKey: "msg") + case let .webPage(webPage): + encoder.encodeInt32(CodingCase.webPage.rawValue, forKey: "_r") + encoder.encodeObject(webPage, forKey: "wpg") + case let .stickerPack(stickerPack): + encoder.encodeInt32(CodingCase.stickerPack.rawValue, forKey: "_r") + encoder.encodeObject(stickerPack, forKey: "spk") + case .savedGif: + encoder.encodeInt32(CodingCase.savedGif.rawValue, forKey: "_r") + } + } + + public func mediaReference(_ media: Media) -> AnyMediaReference { + switch self { + case let .message(message): + return .message(message: message, media: media) + case let .webPage(webPage): + return .webPage(webPage: webPage, media: media) + case let .stickerPack(stickerPack): + return .stickerPack(stickerPack: stickerPack, media: media) + case .savedGif: + return .savedGif(media: media) + } + } +} + +public enum MediaReference { + private enum CodingCase: Int32 { + case standalone + case message + case webPage + case stickerPack + case savedGif + } + + case standalone(media: T) + case message(message: MessageReference, media: T) + case webPage(webPage: WebpageReference, media: T) + case stickerPack(stickerPack: StickerPackReference, media: T) + case savedGif(media: T) + + public init?(decoder: PostboxDecoder) { + guard let caseIdValue = decoder.decodeOptionalInt32ForKey("_r"), let caseId = CodingCase(rawValue: caseIdValue) else { + return nil + } + switch caseId { + case .standalone: + guard let media = decoder.decodeObjectForKey("m") as? T else { + return nil + } + self = .standalone(media: media) + case .message: + let message = decoder.decodeObjectForKey("msg", decoder: { MessageReference(decoder: $0) }) as! MessageReference + guard let media = decoder.decodeObjectForKey("m") as? T else { + return nil + } + self = .message(message: message, media: media) + case .webPage: + let webPage = decoder.decodeObjectForKey("wpg", decoder: { WebpageReference(decoder: $0) }) as! WebpageReference + guard let media = decoder.decodeObjectForKey("m") as? T else { + return nil + } + self = .webPage(webPage: webPage, media: media) + case .stickerPack: + let stickerPack = decoder.decodeObjectForKey("spk", decoder: { StickerPackReference(decoder: $0) }) as! StickerPackReference + guard let media = decoder.decodeObjectForKey("m") as? T else { + return nil + } + self = .stickerPack(stickerPack: stickerPack, media: media) + case .savedGif: + guard let media = decoder.decodeObjectForKey("m") as? T else { + return nil + } + self = .savedGif(media: media) + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .standalone(media): + encoder.encodeInt32(CodingCase.standalone.rawValue, forKey: "_r") + encoder.encodeObject(media, forKey: "m") + case let .message(message, media): + encoder.encodeInt32(CodingCase.message.rawValue, forKey: "_r") + encoder.encodeObject(message, forKey: "msg") + encoder.encodeObject(media, forKey: "m") + case let .webPage(webPage, media): + encoder.encodeInt32(CodingCase.webPage.rawValue, forKey: "_r") + encoder.encodeObject(webPage, forKey: "wpg") + encoder.encodeObject(media, forKey: "m") + case let .stickerPack(stickerPack, media): + encoder.encodeInt32(CodingCase.stickerPack.rawValue, forKey: "_r") + encoder.encodeObject(stickerPack, forKey: "spk") + encoder.encodeObject(media, forKey: "m") + case let .savedGif(media): + encoder.encodeInt32(CodingCase.savedGif.rawValue, forKey: "_r") + encoder.encodeObject(media, forKey: "m") + } + } + + public var abstract: AnyMediaReference { + switch self { + case let .standalone(media): + return .standalone(media: media) + case let .message(message, media): + return .message(message: message, media: media) + case let .webPage(webPage, media): + return .webPage(webPage: webPage, media: media) + case let .stickerPack(stickerPack, media): + return .stickerPack(stickerPack: stickerPack, media: media) + case let .savedGif(media): + return .savedGif(media: media) + } + } + + public var partial: PartialMediaReference? { + return self.abstract.partial + } + + public var media: T { + switch self { + case let .standalone(media): + return media + case let .message(_, media): + return media + case let .webPage(_, media): + return media + case let .stickerPack(_, media): + return media + case let .savedGif(media): + return media + } + } + + public func resourceReference(_ resource: MediaResource) -> MediaResourceReference { + return .media(media: self.abstract, resource: resource) + } +} + +public typealias FileMediaReference = MediaReference +public typealias ImageMediaReference = MediaReference + +public enum MediaResourceReference: Equatable { + case media(media: AnyMediaReference, resource: MediaResource) + case standalone(resource: MediaResource) + case avatar(peer: PeerReference, resource: MediaResource) + case messageAuthorAvatar(message: MessageReference, resource: MediaResource) + case wallpaper(resource: MediaResource) + case stickerPackThumbnail(stickerPack: StickerPackReference, resource: MediaResource) + + public var resource: MediaResource { + switch self { + case let .media(_, resource): + return resource + case let .standalone(resource): + return resource + case let .avatar(_, resource): + return resource + case let .messageAuthorAvatar(_, resource): + return resource + case let .wallpaper(resource): + return resource + case let .stickerPackThumbnail(_, resource): + return resource + } + } + + public static func ==(lhs: MediaResourceReference, rhs: MediaResourceReference) -> Bool { + switch lhs { + case let .media(lhsMedia, lhsResource): + if case let .media(rhsMedia, rhsResource) = rhs, lhsMedia == rhsMedia, lhsResource.isEqual(to: rhsResource) { + return true + } else { + return false + } + case let .standalone(lhsResource): + if case let .standalone(rhsResource) = rhs, lhsResource.isEqual(to: rhsResource) { + return true + } else { + return false + } + case let .avatar(lhsPeer, lhsResource): + if case let .avatar(rhsPeer, rhsResource) = rhs, lhsPeer == rhsPeer, lhsResource.isEqual(to: rhsResource) { + return true + } else { + return false + } + case let .messageAuthorAvatar(lhsMessage, lhsResource): + if case let .messageAuthorAvatar(rhsMessage, rhsResource) = rhs, lhsMessage == rhsMessage, lhsResource.isEqual(to: rhsResource) { + return true + } else { + return false + } + case let .wallpaper(lhsResource): + if case let .wallpaper(rhsResource) = rhs, lhsResource.isEqual(to: rhsResource) { + return true + } else { + return false + } + case let .stickerPackThumbnail(lhsStickerPack, lhsResource): + if case let .stickerPackThumbnail(rhsStickerPack, rhsResource) = rhs, lhsStickerPack == rhsStickerPack, lhsResource.isEqual(to: rhsResource) { + return true + } else { + return false + } + } + } +} diff --git a/submodules/TelegramCore/TelegramCore/Namespaces.swift b/submodules/SyncCore/Sources/Namespaces.swift similarity index 85% rename from submodules/TelegramCore/TelegramCore/Namespaces.swift rename to submodules/SyncCore/Sources/Namespaces.swift index 009efa1d0f..25ec05a3a7 100644 --- a/submodules/TelegramCore/TelegramCore/Namespaces.swift +++ b/submodules/SyncCore/Sources/Namespaces.swift @@ -62,7 +62,7 @@ public struct Namespaces { public static let CloudThemes: Int32 = 9 } - struct CachedItemCollection { + public struct CachedItemCollection { public static let resolvedByNamePeers: Int8 = 0 public static let cachedTwoStepToken: Int8 = 1 public static let cachedStickerPacks: Int8 = 2 @@ -74,8 +74,8 @@ public struct Namespaces { public static let cachedThemesConfiguration: Int8 = 7 } - struct UnorderedItemList { - static let synchronizedDeviceContacts: UnorderedItemListEntryTag = { + public struct UnorderedItemList { + public static let synchronizedDeviceContacts: UnorderedItemListEntryTag = { let key = ValueBoxKey(length: 1) key.setUInt8(0, value: 0) return UnorderedItemListEntryTag(value: key) @@ -117,29 +117,29 @@ public extension PendingMessageActionType { static let sendScheduledMessageImmediately = PendingMessageActionType(rawValue: 2) } -let peerIdNamespacesWithInitialCloudMessageHoles = [Namespaces.Peer.CloudUser, Namespaces.Peer.CloudGroup, Namespaces.Peer.CloudChannel] +public let peerIdNamespacesWithInitialCloudMessageHoles = [Namespaces.Peer.CloudUser, Namespaces.Peer.CloudGroup, Namespaces.Peer.CloudChannel] public struct OperationLogTags { public static let SecretOutgoing = PeerOperationLogTag(value: 0) - static let SecretIncomingEncrypted = PeerOperationLogTag(value: 1) - static let SecretIncomingDecrypted = PeerOperationLogTag(value: 2) - static let CloudChatRemoveMessages = PeerOperationLogTag(value: 3) - static let SynchronizePinnedCloudChats = PeerOperationLogTag(value: 4) - static let AutoremoveMessages = PeerOperationLogTag(value: 5) - static let SynchronizePinnedChats = PeerOperationLogTag(value: 6) - static let SynchronizeConsumeMessageContents = PeerOperationLogTag(value: 7) - static let SynchronizeInstalledStickerPacks = PeerOperationLogTag(value: 8) - static let SynchronizeInstalledMasks = PeerOperationLogTag(value: 9) - static let SynchronizeMarkFeaturedStickerPacksAsSeen = PeerOperationLogTag(value: 10) - static let SynchronizeChatInputStates = PeerOperationLogTag(value: 11) - static let SynchronizeSavedGifs = PeerOperationLogTag(value: 12) - static let SynchronizeLocalizationUpdates = PeerOperationLogTag(value: 13) - static let SynchronizeSavedStickers = PeerOperationLogTag(value: 14) - static let SynchronizeGroupedPeers = PeerOperationLogTag(value: 15) - static let SynchronizeMarkAllUnseenPersonalMessages = PeerOperationLogTag(value: 16) - static let SynchronizeRecentlyUsedStickers = PeerOperationLogTag(value: 17) - static let SynchronizeAppLogEvents = PeerOperationLogTag(value: 18) - static let SynchronizeEmojiKeywords = PeerOperationLogTag(value: 19) + public static let SecretIncomingEncrypted = PeerOperationLogTag(value: 1) + public static let SecretIncomingDecrypted = PeerOperationLogTag(value: 2) + public static let CloudChatRemoveMessages = PeerOperationLogTag(value: 3) + public static let SynchronizePinnedCloudChats = PeerOperationLogTag(value: 4) + public static let AutoremoveMessages = PeerOperationLogTag(value: 5) + public static let SynchronizePinnedChats = PeerOperationLogTag(value: 6) + public static let SynchronizeConsumeMessageContents = PeerOperationLogTag(value: 7) + public static let SynchronizeInstalledStickerPacks = PeerOperationLogTag(value: 8) + public static let SynchronizeInstalledMasks = PeerOperationLogTag(value: 9) + public static let SynchronizeMarkFeaturedStickerPacksAsSeen = PeerOperationLogTag(value: 10) + public static let SynchronizeChatInputStates = PeerOperationLogTag(value: 11) + public static let SynchronizeSavedGifs = PeerOperationLogTag(value: 12) + public static let SynchronizeLocalizationUpdates = PeerOperationLogTag(value: 13) + public static let SynchronizeSavedStickers = PeerOperationLogTag(value: 14) + public static let SynchronizeGroupedPeers = PeerOperationLogTag(value: 15) + public static let SynchronizeMarkAllUnseenPersonalMessages = PeerOperationLogTag(value: 16) + public static let SynchronizeRecentlyUsedStickers = PeerOperationLogTag(value: 17) + public static let SynchronizeAppLogEvents = PeerOperationLogTag(value: 18) + public static let SynchronizeEmojiKeywords = PeerOperationLogTag(value: 19) } public extension PeerSummaryCounterTags { diff --git a/submodules/SyncCore/Sources/NetworkSettings.swift b/submodules/SyncCore/Sources/NetworkSettings.swift new file mode 100644 index 0000000000..b8341c79fb --- /dev/null +++ b/submodules/SyncCore/Sources/NetworkSettings.swift @@ -0,0 +1,45 @@ +import Postbox + +public struct NetworkSettings: PreferencesEntry, Equatable { + public var reducedBackupDiscoveryTimeout: Bool + public var applicationUpdateUrlPrefix: String? + public var backupHostOverride: String? + + public static var defaultSettings: NetworkSettings { + return NetworkSettings(reducedBackupDiscoveryTimeout: false, applicationUpdateUrlPrefix: nil, backupHostOverride: nil) + } + + public init(reducedBackupDiscoveryTimeout: Bool, applicationUpdateUrlPrefix: String?, backupHostOverride: String?) { + self.reducedBackupDiscoveryTimeout = reducedBackupDiscoveryTimeout + self.applicationUpdateUrlPrefix = applicationUpdateUrlPrefix + self.backupHostOverride = backupHostOverride + } + + public init(decoder: PostboxDecoder) { + self.reducedBackupDiscoveryTimeout = decoder.decodeInt32ForKey("reducedBackupDiscoveryTimeout", orElse: 0) != 0 + self.applicationUpdateUrlPrefix = decoder.decodeOptionalStringForKey("applicationUpdateUrlPrefix") + self.backupHostOverride = decoder.decodeOptionalStringForKey("backupHostOverride") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.reducedBackupDiscoveryTimeout ? 1 : 0, forKey: "reducedBackupDiscoveryTimeout") + if let applicationUpdateUrlPrefix = self.applicationUpdateUrlPrefix { + encoder.encodeString(applicationUpdateUrlPrefix, forKey: "applicationUpdateUrlPrefix") + } else { + encoder.encodeNil(forKey: "applicationUpdateUrlPrefix") + } + if let backupHostOverride = self.backupHostOverride { + encoder.encodeString(backupHostOverride, forKey: "backupHostOverride") + } else { + encoder.encodeNil(forKey: "backupHostOverride") + } + } + + public func isEqual(to: PreferencesEntry) -> Bool { + guard let to = to as? NetworkSettings else { + return false + } + + return self == to + } +} diff --git a/submodules/TelegramCore/TelegramCore/NotificationInfoMessageAttribute.swift b/submodules/SyncCore/Sources/NotificationInfoMessageAttribute.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/NotificationInfoMessageAttribute.swift rename to submodules/SyncCore/Sources/NotificationInfoMessageAttribute.swift diff --git a/submodules/TelegramCore/TelegramCore/OutgoingChatContextResultMessageAttribute.swift b/submodules/SyncCore/Sources/OutgoingChatContextResultMessageAttribute.swift similarity index 93% rename from submodules/TelegramCore/TelegramCore/OutgoingChatContextResultMessageAttribute.swift rename to submodules/SyncCore/Sources/OutgoingChatContextResultMessageAttribute.swift index 5ae4a29923..6c803a5c8e 100644 --- a/submodules/TelegramCore/TelegramCore/OutgoingChatContextResultMessageAttribute.swift +++ b/submodules/SyncCore/Sources/OutgoingChatContextResultMessageAttribute.swift @@ -10,7 +10,7 @@ public class OutgoingChatContextResultMessageAttribute: MessageAttribute { public let id: String public let hideVia: Bool - init(queryId: Int64, id: String, hideVia: Bool) { + public init(queryId: Int64, id: String, hideVia: Bool) { self.queryId = queryId self.id = id self.hideVia = hideVia diff --git a/submodules/TelegramCore/TelegramCore/OutgoingContentInfoMessageAttribute.swift b/submodules/SyncCore/Sources/OutgoingContentInfoMessageAttribute.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/OutgoingContentInfoMessageAttribute.swift rename to submodules/SyncCore/Sources/OutgoingContentInfoMessageAttribute.swift diff --git a/submodules/TelegramCore/TelegramCore/OutgoingMessageInfoAttribute.swift b/submodules/SyncCore/Sources/OutgoingMessageInfoAttribute.swift similarity index 73% rename from submodules/TelegramCore/TelegramCore/OutgoingMessageInfoAttribute.swift rename to submodules/SyncCore/Sources/OutgoingMessageInfoAttribute.swift index 93cb325e89..1dd1907241 100644 --- a/submodules/TelegramCore/TelegramCore/OutgoingMessageInfoAttribute.swift +++ b/submodules/SyncCore/Sources/OutgoingMessageInfoAttribute.swift @@ -24,7 +24,7 @@ public class OutgoingMessageInfoAttribute: MessageAttribute { public let flags: OutgoingMessageInfoFlags public let acknowledged: Bool - init(uniqueId: Int64, flags: OutgoingMessageInfoFlags, acknowledged: Bool) { + public init(uniqueId: Int64, flags: OutgoingMessageInfoFlags, acknowledged: Bool) { self.uniqueId = uniqueId self.flags = flags self.acknowledged = acknowledged @@ -50,22 +50,3 @@ public class OutgoingMessageInfoAttribute: MessageAttribute { return OutgoingMessageInfoAttribute(uniqueId: self.uniqueId, flags: self.flags, acknowledged: acknowledged) } } - -public extension Message { - var isSentOrAcknowledged: Bool { - if self.flags.contains(.Failed) { - return false - } else if self.flags.isSending { - for attribute in self.attributes { - if let attribute = attribute as? OutgoingMessageInfoAttribute { - if attribute.acknowledged { - return true - } - } - } - return false - } else { - return true - } - } -} diff --git a/submodules/TelegramCore/TelegramCore/OutgoingScheduleInfoMessageAttribute.swift b/submodules/SyncCore/Sources/OutgoingScheduleInfoMessageAttribute.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/OutgoingScheduleInfoMessageAttribute.swift rename to submodules/SyncCore/Sources/OutgoingScheduleInfoMessageAttribute.swift diff --git a/submodules/TelegramCore/TelegramCore/PeerAccessHash.swift b/submodules/SyncCore/Sources/PeerAccessHash.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/PeerAccessHash.swift rename to submodules/SyncCore/Sources/PeerAccessHash.swift diff --git a/submodules/SyncCore/Sources/PeerAccessRestrictionInfo.swift b/submodules/SyncCore/Sources/PeerAccessRestrictionInfo.swift new file mode 100644 index 0000000000..940640e28f --- /dev/null +++ b/submodules/SyncCore/Sources/PeerAccessRestrictionInfo.swift @@ -0,0 +1,62 @@ +import Postbox + +public final class RestrictionRule: PostboxCoding, Equatable { + public let platform: String + public let reason: String + public let text: String + + public init(platform: String, reason: String, text: String) { + self.platform = platform + self.reason = reason + self.text = text + } + + public init(decoder: PostboxDecoder) { + self.platform = decoder.decodeStringForKey("p", orElse: "all") + self.reason = decoder.decodeStringForKey("r", orElse: "") + self.text = decoder.decodeStringForKey("t", orElse: "") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.platform, forKey: "p") + encoder.encodeString(self.reason, forKey: "r") + encoder.encodeString(self.text, forKey: "t") + } + + public static func ==(lhs: RestrictionRule, rhs: RestrictionRule) -> Bool { + if lhs.platform != rhs.platform { + return false + } + if lhs.reason != rhs.reason { + return false + } + if lhs.text != rhs.text { + return false + } + return true + } +} + +public final class PeerAccessRestrictionInfo: PostboxCoding, Equatable { + public let rules: [RestrictionRule] + + public init(rules: [RestrictionRule]) { + self.rules = rules + } + + public init(decoder: PostboxDecoder) { + if let value = decoder.decodeOptionalStringForKey("rsn") { + self.rules = [RestrictionRule(platform: "all", reason: "", text: value)] + } else { + self.rules = decoder.decodeObjectArrayWithDecoderForKey("rs") + } + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObjectArray(self.rules, forKey: "rs") + } + + public static func ==(lhs: PeerAccessRestrictionInfo, rhs: PeerAccessRestrictionInfo) -> Bool { + return lhs.rules == rhs.rules + } +} diff --git a/submodules/TelegramCore/TelegramCore/PeerGroupMessageStateVersionAttribute.swift b/submodules/SyncCore/Sources/PeerGroupMessageStateVersionAttribute.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/PeerGroupMessageStateVersionAttribute.swift rename to submodules/SyncCore/Sources/PeerGroupMessageStateVersionAttribute.swift diff --git a/submodules/SyncCore/Sources/PeerReference.swift b/submodules/SyncCore/Sources/PeerReference.swift new file mode 100644 index 0000000000..dc50bea070 --- /dev/null +++ b/submodules/SyncCore/Sources/PeerReference.swift @@ -0,0 +1,58 @@ +import Postbox + +public enum PeerReference: PostboxCoding, Hashable, Equatable { + case user(id: Int32, accessHash: Int64) + case group(id: Int32) + case channel(id: Int32, accessHash: Int64) + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("_r", orElse: 0) { + case 0: + self = .user(id: decoder.decodeInt32ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0)) + case 1: + self = .group(id: decoder.decodeInt32ForKey("i", orElse: 0)) + case 2: + self = .channel(id: decoder.decodeInt32ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0)) + default: + assertionFailure() + self = .user(id: 0, accessHash: 0) + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .user(id, accessHash): + encoder.encodeInt32(0, forKey: "_r") + encoder.encodeInt32(id, forKey: "i") + encoder.encodeInt64(accessHash, forKey: "h") + case let .group(id): + encoder.encodeInt32(1, forKey: "_r") + encoder.encodeInt32(id, forKey: "i") + case let .channel(id, accessHash): + encoder.encodeInt32(2, forKey: "_r") + encoder.encodeInt32(id, forKey: "i") + encoder.encodeInt64(accessHash, forKey: "h") + } + } + + public init?(_ peer: Peer) { + switch peer { + case let user as TelegramUser: + if let accessHash = user.accessHash { + self = .user(id: user.id.id, accessHash: accessHash.value) + } else { + return nil + } + case let group as TelegramGroup: + self = .group(id: group.id.id) + case let channel as TelegramChannel: + if let accessHash = channel.accessHash { + self = .channel(id: channel.id.id, accessHash: accessHash.value) + } else { + return nil + } + default: + return nil + } + } +} diff --git a/submodules/SyncCore/Sources/PeerStatusSettings.swift b/submodules/SyncCore/Sources/PeerStatusSettings.swift new file mode 100644 index 0000000000..e478c5b9bd --- /dev/null +++ b/submodules/SyncCore/Sources/PeerStatusSettings.swift @@ -0,0 +1,16 @@ +import Postbox + +public struct PeerStatusSettings: OptionSet { + public var rawValue: Int32 + + public init(rawValue: Int32) { + self.rawValue = rawValue + } + + public static let canReport = PeerStatusSettings(rawValue: 1 << 1) + public static let canShareContact = PeerStatusSettings(rawValue: 1 << 2) + public static let canBlock = PeerStatusSettings(rawValue: 1 << 3) + public static let canAddContact = PeerStatusSettings(rawValue: 1 << 4) + public static let addExceptionWhenAddingContact = PeerStatusSettings(rawValue: 1 << 5) + public static let canReportIrrelevantGeoLocation = PeerStatusSettings(rawValue: 1 << 6) +} diff --git a/submodules/SyncCore/Sources/ProxySettings.swift b/submodules/SyncCore/Sources/ProxySettings.swift new file mode 100644 index 0000000000..6655cad742 --- /dev/null +++ b/submodules/SyncCore/Sources/ProxySettings.swift @@ -0,0 +1,135 @@ +import Postbox + +public enum ProxyServerConnection: Equatable, Hashable, PostboxCoding { + case socks5(username: String?, password: String?) + case mtp(secret: Data) + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("_t", orElse: 0) { + case 0: + self = .socks5(username: decoder.decodeOptionalStringForKey("username"), password: decoder.decodeOptionalStringForKey("password")) + case 1: + self = .mtp(secret: decoder.decodeBytesForKey("secret")?.makeData() ?? Data()) + default: + self = .socks5(username: nil, password: nil) + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .socks5(username, password): + encoder.encodeInt32(0, forKey: "_t") + if let username = username { + encoder.encodeString(username, forKey: "username") + } else { + encoder.encodeNil(forKey: "username") + } + if let password = password { + encoder.encodeString(password, forKey: "password") + } else { + encoder.encodeNil(forKey: "password") + } + case let .mtp(secret): + encoder.encodeInt32(1, forKey: "_t") + encoder.encodeBytes(MemoryBuffer(data: secret), forKey: "secret") + } + } +} + +public struct ProxyServerSettings: PostboxCoding, Equatable, Hashable { + public let host: String + public let port: Int32 + public let connection: ProxyServerConnection + + public init(host: String, port: Int32, connection: ProxyServerConnection) { + self.host = host + self.port = port + self.connection = connection + } + + public init(decoder: PostboxDecoder) { + self.host = decoder.decodeStringForKey("host", orElse: "") + self.port = decoder.decodeInt32ForKey("port", orElse: 0) + if let username = decoder.decodeOptionalStringForKey("username") { + self.connection = .socks5(username: username, password: decoder.decodeOptionalStringForKey("password")) + } else { + self.connection = decoder.decodeObjectForKey("connection", decoder: ProxyServerConnection.init(decoder:)) as? ProxyServerConnection ?? ProxyServerConnection.socks5(username: nil, password: nil) + } + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.host, forKey: "host") + encoder.encodeInt32(self.port, forKey: "port") + encoder.encodeObject(self.connection, forKey: "connection") + } + + public var hashValue: Int { + var hash = self.host.hashValue + hash = hash &* 31 &+ self.port.hashValue + hash = hash &* 31 &+ self.connection.hashValue + return hash + } +} + +public struct ProxySettings: PreferencesEntry, Equatable { + public var enabled: Bool + public var servers: [ProxyServerSettings] + public var activeServer: ProxyServerSettings? + public var useForCalls: Bool + + public static var defaultSettings: ProxySettings { + return ProxySettings(enabled: false, servers: [], activeServer: nil, useForCalls: false) + } + + public init(enabled: Bool, servers: [ProxyServerSettings], activeServer: ProxyServerSettings?, useForCalls: Bool) { + self.enabled = enabled + self.servers = servers + self.activeServer = activeServer + self.useForCalls = useForCalls + } + + public init(decoder: PostboxDecoder) { + if let _ = decoder.decodeOptionalStringForKey("host") { + let legacyServer = ProxyServerSettings(decoder: decoder) + if !legacyServer.host.isEmpty && legacyServer.port != 0 { + self.enabled = true + self.servers = [legacyServer] + } else { + self.enabled = false + self.servers = [] + } + } else { + self.enabled = decoder.decodeInt32ForKey("enabled", orElse: 0) != 0 + self.servers = decoder.decodeObjectArrayWithDecoderForKey("servers") + } + self.activeServer = decoder.decodeObjectForKey("activeServer", decoder: ProxyServerSettings.init(decoder:)) as? ProxyServerSettings + self.useForCalls = decoder.decodeInt32ForKey("useForCalls", orElse: 0) != 0 + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.enabled ? 1 : 0, forKey: "enabled") + encoder.encodeObjectArray(self.servers, forKey: "servers") + if let activeServer = self.activeServer { + encoder.encodeObject(activeServer, forKey: "activeServer") + } else { + encoder.encodeNil(forKey: "activeServer") + } + encoder.encodeInt32(self.useForCalls ? 1 : 0, forKey: "useForCalls") + } + + public func isEqual(to: PreferencesEntry) -> Bool { + guard let to = to as? ProxySettings else { + return false + } + + return self == to + } + + public var effectiveActiveServer: ProxyServerSettings? { + if self.enabled, let activeServer = self.activeServer { + return activeServer + } else { + return nil + } + } +} diff --git a/submodules/SyncCore/Sources/ReactionsMessageAttribute.swift b/submodules/SyncCore/Sources/ReactionsMessageAttribute.swift new file mode 100644 index 0000000000..e281a8614f --- /dev/null +++ b/submodules/SyncCore/Sources/ReactionsMessageAttribute.swift @@ -0,0 +1,61 @@ +import Postbox + +public struct MessageReaction: Equatable, PostboxCoding { + public var value: String + public var count: Int32 + public var isSelected: Bool + + public init(value: String, count: Int32, isSelected: Bool) { + self.value = value + self.count = count + self.isSelected = isSelected + } + + public init(decoder: PostboxDecoder) { + self.value = decoder.decodeStringForKey("v", orElse: "") + self.count = decoder.decodeInt32ForKey("c", orElse: 0) + self.isSelected = decoder.decodeInt32ForKey("s", orElse: 0) != 0 + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.value, forKey: "v") + encoder.encodeInt32(self.count, forKey: "c") + encoder.encodeInt32(self.isSelected ? 1 : 0, forKey: "s") + } +} + +public final class ReactionsMessageAttribute: MessageAttribute { + public let reactions: [MessageReaction] + + public init(reactions: [MessageReaction]) { + self.reactions = reactions + } + + required public init(decoder: PostboxDecoder) { + self.reactions = decoder.decodeObjectArrayWithDecoderForKey("r") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObjectArray(self.reactions, forKey: "r") + } +} + +public final class PendingReactionsMessageAttribute: MessageAttribute { + public let value: String? + + public init(value: String?) { + self.value = value + } + + required public init(decoder: PostboxDecoder) { + self.value = decoder.decodeOptionalStringForKey("v") + } + + public func encode(_ encoder: PostboxEncoder) { + if let value = self.value { + encoder.encodeString(value, forKey: "v") + } else { + encoder.encodeNil(forKey: "v") + } + } +} diff --git a/submodules/SyncCore/Sources/RecentHashtagItem.swift b/submodules/SyncCore/Sources/RecentHashtagItem.swift new file mode 100644 index 0000000000..1add80d86e --- /dev/null +++ b/submodules/SyncCore/Sources/RecentHashtagItem.swift @@ -0,0 +1,12 @@ +import Postbox + +public final class RecentHashtagItem: OrderedItemListEntryContents { + public init() { + } + + public init(decoder: PostboxDecoder) { + } + + public func encode(_ encoder: PostboxEncoder) { + } +} diff --git a/submodules/TelegramCore/TelegramCore/RecentMediaItem.swift b/submodules/SyncCore/Sources/RecentMediaItem.swift similarity index 94% rename from submodules/TelegramCore/TelegramCore/RecentMediaItem.swift rename to submodules/SyncCore/Sources/RecentMediaItem.swift index 30bd5cc1b6..8a1af5f343 100644 --- a/submodules/TelegramCore/TelegramCore/RecentMediaItem.swift +++ b/submodules/SyncCore/Sources/RecentMediaItem.swift @@ -9,7 +9,7 @@ public struct RecentMediaItemId { public let rawValue: MemoryBuffer public let mediaId: MediaId - init(_ rawValue: MemoryBuffer) { + public init(_ rawValue: MemoryBuffer) { self.rawValue = rawValue assert(rawValue.length == 4 + 8) var mediaIdNamespace: Int32 = 0 @@ -32,7 +32,7 @@ public struct RecentMediaItemId { public final class RecentMediaItem: OrderedItemListEntryContents, Equatable { public let media: Media - init(_ media: Media) { + public init(_ media: Media) { self.media = media } diff --git a/submodules/TelegramCore/TelegramCore/RecentPeerItem.swift b/submodules/SyncCore/Sources/RecentPeerItem.swift similarity index 89% rename from submodules/TelegramCore/TelegramCore/RecentPeerItem.swift rename to submodules/SyncCore/Sources/RecentPeerItem.swift index 176bf92a70..d6b95c43f3 100644 --- a/submodules/TelegramCore/TelegramCore/RecentPeerItem.swift +++ b/submodules/SyncCore/Sources/RecentPeerItem.swift @@ -9,7 +9,7 @@ public struct RecentPeerItemId { public let rawValue: MemoryBuffer public let peerId: PeerId - init(_ rawValue: MemoryBuffer) { + public init(_ rawValue: MemoryBuffer) { self.rawValue = rawValue assert(rawValue.length == 8) var idValue: Int64 = 0 @@ -17,7 +17,7 @@ public struct RecentPeerItemId { self.peerId = PeerId(idValue) } - init(_ peerId: PeerId) { + public init(_ peerId: PeerId) { self.peerId = peerId var idValue: Int64 = peerId.toInt64() self.rawValue = MemoryBuffer(memory: malloc(8)!, capacity: 8, length: 8, freeWhenDone: true) @@ -28,7 +28,7 @@ public struct RecentPeerItemId { public final class RecentPeerItem: OrderedItemListEntryContents { public let rating: Double - init(rating: Double) { + public init(rating: Double) { self.rating = rating } diff --git a/submodules/TelegramCore/TelegramCore/RegularChatState.swift b/submodules/SyncCore/Sources/RegularChatState.swift similarity index 55% rename from submodules/TelegramCore/TelegramCore/RegularChatState.swift rename to submodules/SyncCore/Sources/RegularChatState.swift index 4d2ebea322..c5bff9581b 100644 --- a/submodules/TelegramCore/TelegramCore/RegularChatState.swift +++ b/submodules/SyncCore/Sources/RegularChatState.swift @@ -1,22 +1,17 @@ -import Foundation -#if os(macOS) - import PostboxMac -#else - import Postbox -#endif +import Postbox -final class RegularChatState: PeerChatState, Equatable { - let invalidatedPts: Int32? +public final class RegularChatState: PeerChatState, Equatable { + public let invalidatedPts: Int32? - init(invalidatedPts: Int32?) { + public init(invalidatedPts: Int32?) { self.invalidatedPts = invalidatedPts } - init(decoder: PostboxDecoder) { + public init(decoder: PostboxDecoder) { self.invalidatedPts = decoder.decodeOptionalInt32ForKey("ipts") } - func encode(_ encoder: PostboxEncoder) { + public func encode(_ encoder: PostboxEncoder) { if let invalidatedPts = self.invalidatedPts { encoder.encodeInt32(invalidatedPts, forKey: "ipts") } else { @@ -24,18 +19,18 @@ final class RegularChatState: PeerChatState, Equatable { } } - func withUpdatedInvalidatedPts(_ invalidatedPts: Int32?) -> RegularChatState { + public func withUpdatedInvalidatedPts(_ invalidatedPts: Int32?) -> RegularChatState { return RegularChatState(invalidatedPts: invalidatedPts) } - func equals(_ other: PeerChatState) -> Bool { + public func equals(_ other: PeerChatState) -> Bool { if let other = other as? RegularChatState, other == self { return true } return false } - static func ==(lhs: RegularChatState, rhs: RegularChatState) -> Bool { + public static func ==(lhs: RegularChatState, rhs: RegularChatState) -> Bool { return lhs.invalidatedPts == rhs.invalidatedPts } } diff --git a/submodules/SyncCore/Sources/RemoteStorageConfiguration.swift b/submodules/SyncCore/Sources/RemoteStorageConfiguration.swift new file mode 100644 index 0000000000..d8a5efd263 --- /dev/null +++ b/submodules/SyncCore/Sources/RemoteStorageConfiguration.swift @@ -0,0 +1,27 @@ +import Postbox + +public final class RemoteStorageConfiguration: PreferencesEntry { + public let webDocumentsHostDatacenterId: Int32 + + public init(webDocumentsHostDatacenterId: Int32) { + self.webDocumentsHostDatacenterId = webDocumentsHostDatacenterId + } + + public init(decoder: PostboxDecoder) { + self.webDocumentsHostDatacenterId = decoder.decodeInt32ForKey("webDocumentsHostDatacenterId", orElse: 4) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.webDocumentsHostDatacenterId, forKey: "webDocumentsHostDatacenterId") + } + + public func isEqual(to: PreferencesEntry) -> Bool { + guard let to = to as? RemoteStorageConfiguration else { + return false + } + if self.webDocumentsHostDatacenterId != to.webDocumentsHostDatacenterId { + return false + } + return true + } +} diff --git a/submodules/SyncCore/Sources/ReplyMarkupMessageAttribute.swift b/submodules/SyncCore/Sources/ReplyMarkupMessageAttribute.swift new file mode 100644 index 0000000000..6cebd304fc --- /dev/null +++ b/submodules/SyncCore/Sources/ReplyMarkupMessageAttribute.swift @@ -0,0 +1,161 @@ +import Postbox + +public enum ReplyMarkupButtonAction: PostboxCoding, Equatable { + case text + case url(String) + case callback(MemoryBuffer) + case requestPhone + case requestMap + case switchInline(samePeer: Bool, query: String) + case openWebApp + case payment + case urlAuth(url: String, buttonId: Int32) + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("v", orElse: 0) { + case 0: + self = .text + case 1: + self = .url(decoder.decodeStringForKey("u", orElse: "")) + case 2: + self = .callback(decoder.decodeBytesForKey("d") ?? MemoryBuffer()) + case 3: + self = .requestPhone + case 4: + self = .requestMap + case 5: + self = .switchInline(samePeer: decoder.decodeInt32ForKey("s", orElse: 0) != 0, query: decoder.decodeStringForKey("q", orElse: "")) + case 6: + self = .openWebApp + case 7: + self = .payment + case 8: + self = .urlAuth(url: decoder.decodeStringForKey("u", orElse: ""), buttonId: decoder.decodeInt32ForKey("b", orElse: 0)) + default: + self = .text + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case .text: + encoder.encodeInt32(0, forKey: "v") + case let .url(url): + encoder.encodeInt32(1, forKey: "v") + encoder.encodeString(url, forKey: "u") + case let .callback(data): + encoder.encodeInt32(2, forKey: "v") + encoder.encodeBytes(data, forKey: "d") + case .requestPhone: + encoder.encodeInt32(3, forKey: "v") + case .requestMap: + encoder.encodeInt32(4, forKey: "v") + case let .switchInline(samePeer, query): + encoder.encodeInt32(5, forKey: "v") + encoder.encodeInt32(samePeer ? 1 : 0, forKey: "s") + encoder.encodeString(query, forKey: "q") + case .openWebApp: + encoder.encodeInt32(6, forKey: "v") + case .payment: + encoder.encodeInt32(7, forKey: "v") + case let .urlAuth(url, buttonId): + encoder.encodeInt32(8, forKey: "v") + encoder.encodeString(url, forKey: "u") + encoder.encodeInt32(buttonId, forKey: "b") + } + } +} + +public struct ReplyMarkupButton: PostboxCoding, Equatable { + public let title: String + public let titleWhenForwarded: String? + public let action: ReplyMarkupButtonAction + + public init(title: String, titleWhenForwarded: String?, action: ReplyMarkupButtonAction) { + self.title = title + self.titleWhenForwarded = titleWhenForwarded + self.action = action + } + + public init(decoder: PostboxDecoder) { + self.title = decoder.decodeStringForKey(".t", orElse: "") + self.titleWhenForwarded = decoder.decodeOptionalStringForKey(".tf") + self.action = ReplyMarkupButtonAction(decoder: decoder) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.title, forKey: ".t") + if let titleWhenForwarded = self.titleWhenForwarded { + encoder.encodeString(titleWhenForwarded, forKey: ".tf") + } else { + encoder.encodeNil(forKey: ".tf") + } + self.action.encode(encoder) + } + + public static func ==(lhs: ReplyMarkupButton, rhs: ReplyMarkupButton) -> Bool { + return lhs.title == rhs.title && lhs.action == rhs.action + } +} + +public struct ReplyMarkupRow: PostboxCoding, Equatable { + public let buttons: [ReplyMarkupButton] + + public init(buttons: [ReplyMarkupButton]) { + self.buttons = buttons + } + + public init(decoder: PostboxDecoder) { + self.buttons = decoder.decodeObjectArrayWithDecoderForKey("b") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObjectArray(self.buttons, forKey: "b") + } + + public static func ==(lhs: ReplyMarkupRow, rhs: ReplyMarkupRow) -> Bool { + return lhs.buttons == rhs.buttons + } +} + +public struct ReplyMarkupMessageFlags: OptionSet { + public var rawValue: Int32 + + public init(rawValue: Int32) { + self.rawValue = rawValue + } + + public init() { + self.rawValue = 0 + } + + public static let once = ReplyMarkupMessageFlags(rawValue: 1 << 0) + public static let personal = ReplyMarkupMessageFlags(rawValue: 1 << 1) + public static let setupReply = ReplyMarkupMessageFlags(rawValue: 1 << 2) + public static let inline = ReplyMarkupMessageFlags(rawValue: 1 << 3) + public static let fit = ReplyMarkupMessageFlags(rawValue: 1 << 4) +} + +public class ReplyMarkupMessageAttribute: MessageAttribute, Equatable { + public let rows: [ReplyMarkupRow] + public let flags: ReplyMarkupMessageFlags + + public init(rows: [ReplyMarkupRow], flags: ReplyMarkupMessageFlags) { + self.rows = rows + self.flags = flags + } + + public required init(decoder: PostboxDecoder) { + self.rows = decoder.decodeObjectArrayWithDecoderForKey("r") + self.flags = ReplyMarkupMessageFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0)) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObjectArray(self.rows, forKey: "r") + encoder.encodeInt32(self.flags.rawValue, forKey: "f") + } + + public static func ==(lhs: ReplyMarkupMessageAttribute, rhs: ReplyMarkupMessageAttribute) -> Bool { + return lhs.flags == rhs.flags && lhs.rows == rhs.rows + } +} diff --git a/submodules/TelegramCore/TelegramCore/ReplyMessageAttribute.swift b/submodules/SyncCore/Sources/ReplyMessageAttribute.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/ReplyMessageAttribute.swift rename to submodules/SyncCore/Sources/ReplyMessageAttribute.swift diff --git a/submodules/TelegramCore/TelegramCore/RestrictedContentMessageAttribute.swift b/submodules/SyncCore/Sources/RestrictedContentMessageAttribute.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/RestrictedContentMessageAttribute.swift rename to submodules/SyncCore/Sources/RestrictedContentMessageAttribute.swift diff --git a/submodules/SyncCore/Sources/RichText.swift b/submodules/SyncCore/Sources/RichText.swift new file mode 100644 index 0000000000..ee6fe719d2 --- /dev/null +++ b/submodules/SyncCore/Sources/RichText.swift @@ -0,0 +1,295 @@ +import Postbox +import UIKit + +private enum RichTextTypes: Int32 { + case empty = 0 + case plain = 1 + case bold = 2 + case italic = 3 + case underline = 4 + case strikethrough = 5 + case fixed = 6 + case url = 7 + case email = 8 + case concat = 9 + case `subscript` = 10 + case superscript = 11 + case marked = 12 + case phone = 13 + case image = 14 + case anchor = 15 +} + +public indirect enum RichText: PostboxCoding, Equatable { + case empty + case plain(String) + case bold(RichText) + case italic(RichText) + case underline(RichText) + case strikethrough(RichText) + case fixed(RichText) + case url(text: RichText, url: String, webpageId: MediaId?) + case email(text: RichText, email: String) + case concat([RichText]) + case `subscript`(RichText) + case superscript(RichText) + case marked(RichText) + case phone(text: RichText, phone: String) + case image(id: MediaId, dimensions: CGSize) + case anchor(text: RichText, name: String) + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("r", orElse: 0) { + case RichTextTypes.empty.rawValue: + self = .empty + case RichTextTypes.plain.rawValue: + self = .plain(decoder.decodeStringForKey("s", orElse: "")) + case RichTextTypes.bold.rawValue: + self = .bold(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) + case RichTextTypes.italic.rawValue: + self = .italic(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) + case RichTextTypes.underline.rawValue: + self = .underline(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) + case RichTextTypes.strikethrough.rawValue: + self = .strikethrough(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) + case RichTextTypes.fixed.rawValue: + self = .fixed(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) + case RichTextTypes.url.rawValue: + let webpageIdNamespace: Int32? = decoder.decodeOptionalInt32ForKey("w.n") + let webpageIdId: Int64? = decoder.decodeOptionalInt64ForKey("w.i") + var webpageId: MediaId? + if let webpageIdNamespace = webpageIdNamespace, let webpageIdId = webpageIdId { + webpageId = MediaId(namespace: webpageIdNamespace, id: webpageIdId) + } + self = .url(text: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, url: decoder.decodeStringForKey("u", orElse: ""), webpageId: webpageId) + case RichTextTypes.email.rawValue: + self = .email(text: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, email: decoder.decodeStringForKey("e", orElse: "")) + case RichTextTypes.concat.rawValue: + self = .concat(decoder.decodeObjectArrayWithDecoderForKey("a")) + case RichTextTypes.subscript.rawValue: + self = .subscript(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) + case RichTextTypes.superscript.rawValue: + self = .superscript(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) + case RichTextTypes.marked.rawValue: + self = .marked(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) + case RichTextTypes.phone.rawValue: + self = .phone(text: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, phone: decoder.decodeStringForKey("p", orElse: "")) + case RichTextTypes.image.rawValue: + self = .image(id: MediaId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)), dimensions: CGSize(width: CGFloat(decoder.decodeInt32ForKey("sw", orElse: 0)), height: CGFloat(decoder.decodeInt32ForKey("sh", orElse: 0)))) + case RichTextTypes.anchor.rawValue: + self = .anchor(text: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, name: decoder.decodeStringForKey("n", orElse: "")) + default: + self = .empty + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case .empty: + encoder.encodeInt32(RichTextTypes.empty.rawValue, forKey: "r") + case let .plain(string): + encoder.encodeInt32(RichTextTypes.plain.rawValue, forKey: "r") + encoder.encodeString(string, forKey: "s") + case let .bold(text): + encoder.encodeInt32(RichTextTypes.bold.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + case let .italic(text): + encoder.encodeInt32(RichTextTypes.italic.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + case let .underline(text): + encoder.encodeInt32(RichTextTypes.underline.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + case let .strikethrough(text): + encoder.encodeInt32(RichTextTypes.strikethrough.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + case let .fixed(text): + encoder.encodeInt32(RichTextTypes.fixed.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + case let .url(text, url, webpageId): + encoder.encodeInt32(RichTextTypes.url.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + encoder.encodeString(url, forKey: "u") + if let webpageId = webpageId { + encoder.encodeInt32(webpageId.namespace, forKey: "w.n") + encoder.encodeInt64(webpageId.id, forKey: "w.i") + } else { + encoder.encodeNil(forKey: "w.n") + encoder.encodeNil(forKey: "w.i") + } + case let .email(text, email): + encoder.encodeInt32(RichTextTypes.email.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + encoder.encodeString(email, forKey: "e") + case let .concat(texts): + encoder.encodeInt32(RichTextTypes.concat.rawValue, forKey: "r") + encoder.encodeObjectArray(texts, forKey: "a") + case let .subscript(text): + encoder.encodeInt32(RichTextTypes.subscript.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + case let .superscript(text): + encoder.encodeInt32(RichTextTypes.superscript.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + case let .marked(text): + encoder.encodeInt32(RichTextTypes.marked.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + case let .phone(text, phone): + encoder.encodeInt32(RichTextTypes.phone.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + encoder.encodeString(phone, forKey: "p") + case let .image(id, dimensions): + encoder.encodeInt32(RichTextTypes.image.rawValue, forKey: "r") + encoder.encodeInt32(id.namespace, forKey: "i.n") + encoder.encodeInt64(id.id, forKey: "i.i") + encoder.encodeInt32(Int32(dimensions.width), forKey: "sw") + encoder.encodeInt32(Int32(dimensions.height), forKey: "sh") + case let .anchor(text, name): + encoder.encodeInt32(RichTextTypes.anchor.rawValue, forKey: "r") + encoder.encodeObject(text, forKey: "t") + encoder.encodeString(name, forKey: "n") + } + } + + public static func ==(lhs: RichText, rhs: RichText) -> Bool { + switch lhs { + case .empty: + if case .empty = rhs { + return true + } else { + return false + } + case let .plain(string): + if case .plain(string) = rhs { + return true + } else { + return false + } + case let .bold(text): + if case .bold(text) = rhs { + return true + } else { + return false + } + case let .italic(text): + if case .italic(text) = rhs { + return true + } else { + return false + } + case let .underline(text): + if case .underline(text) = rhs { + return true + } else { + return false + } + case let .strikethrough(text): + if case .strikethrough(text) = rhs { + return true + } else { + return false + } + case let .fixed(text): + if case .fixed(text) = rhs { + return true + } else { + return false + } + case let .url(lhsText, lhsUrl, lhsWebpageId): + if case let .url(rhsText, rhsUrl, rhsWebpageId) = rhs, lhsText == rhsText && lhsUrl == rhsUrl && lhsWebpageId == rhsWebpageId { + return true + } else { + return false + } + case let .email(text, email): + if case .email(text, email) = rhs { + return true + } else { + return false + } + case let .concat(lhsTexts): + if case let .concat(rhsTexts) = rhs, lhsTexts == rhsTexts { + return true + } else { + return false + } + case let .subscript(text): + if case .subscript(text) = rhs { + return true + } else { + return false + } + case let .superscript(text): + if case .superscript(text) = rhs { + return true + } else { + return false + } + case let .marked(text): + if case .marked(text) = rhs { + return true + } else { + return false + } + case let .phone(text, phone): + if case .phone(text, phone) = rhs { + return true + } else { + return false + } + case let .image(id, dimensions): + if case .image(id, dimensions) = rhs { + return true + } else { + return false + } + case let .anchor(text, name): + if case .anchor(text, name) = rhs { + return true + } else { + return false + } + } + } +} + +public extension RichText { + var plainText: String { + switch self { + case .empty: + return "" + case let .plain(string): + return string + case let .bold(text): + return text.plainText + case let .italic(text): + return text.plainText + case let .underline(text): + return text.plainText + case let .strikethrough(text): + return text.plainText + case let .fixed(text): + return text.plainText + case let .url(text, _, _): + return text.plainText + case let .email(text, _): + return text.plainText + case let .concat(texts): + var string = "" + for text in texts { + string += text.plainText + } + return string + case let .subscript(text): + return text.plainText + case let .superscript(text): + return text.plainText + case let .marked(text): + return text.plainText + case let .phone(text, _): + return text.plainText + case .image: + return "" + case let .anchor(text, _): + return text.plainText + } + } +} diff --git a/submodules/TelegramCore/TelegramCore/SavedStickerItem.swift b/submodules/SyncCore/Sources/SavedStickerItem.swift similarity index 92% rename from submodules/TelegramCore/TelegramCore/SavedStickerItem.swift rename to submodules/SyncCore/Sources/SavedStickerItem.swift index 7b58381d05..b5b6318af1 100644 --- a/submodules/TelegramCore/TelegramCore/SavedStickerItem.swift +++ b/submodules/SyncCore/Sources/SavedStickerItem.swift @@ -9,7 +9,7 @@ public final class SavedStickerItem: OrderedItemListEntryContents, Equatable { public let file: TelegramMediaFile public let stringRepresentations: [String] - init(file: TelegramMediaFile, stringRepresentations: [String]) { + public init(file: TelegramMediaFile, stringRepresentations: [String]) { self.file = file self.stringRepresentations = stringRepresentations } diff --git a/submodules/TelegramCore/TelegramCore/SearchBotsConfiguration.swift b/submodules/SyncCore/Sources/SearchBotsConfiguration.swift similarity index 91% rename from submodules/TelegramCore/TelegramCore/SearchBotsConfiguration.swift rename to submodules/SyncCore/Sources/SearchBotsConfiguration.swift index 31d41bac83..b67aa0081d 100644 --- a/submodules/TelegramCore/TelegramCore/SearchBotsConfiguration.swift +++ b/submodules/SyncCore/Sources/SearchBotsConfiguration.swift @@ -14,7 +14,7 @@ public struct SearchBotsConfiguration: Equatable, PreferencesEntry { return SearchBotsConfiguration(imageBotUsername: "bing", gifBotUsername: "gif", venueBotUsername: "foursquare") } - init(imageBotUsername: String?, gifBotUsername: String?, venueBotUsername: String?) { + public init(imageBotUsername: String?, gifBotUsername: String?, venueBotUsername: String?) { self.imageBotUsername = imageBotUsername self.gifBotUsername = gifBotUsername self.venueBotUsername = venueBotUsername @@ -60,7 +60,7 @@ public func currentSearchBotsConfiguration(transaction: Transaction) -> SearchBo } } -func updateSearchBotsConfiguration(transaction: Transaction, configuration: SearchBotsConfiguration) { +public func updateSearchBotsConfiguration(transaction: Transaction, configuration: SearchBotsConfiguration) { if !currentSearchBotsConfiguration(transaction: transaction).isEqual(to: configuration) { transaction.setPreferencesEntry(key: PreferencesKeys.searchBotsConfiguration, value: configuration) } diff --git a/submodules/SyncCore/Sources/SecretChatEncryptionConfig.swift b/submodules/SyncCore/Sources/SecretChatEncryptionConfig.swift new file mode 100644 index 0000000000..58e977d4e3 --- /dev/null +++ b/submodules/SyncCore/Sources/SecretChatEncryptionConfig.swift @@ -0,0 +1,25 @@ +import Postbox + +public final class SecretChatEncryptionConfig: PostboxCoding { + public let g: Int32 + public let p: MemoryBuffer + public let version: Int32 + + public init(g: Int32, p: MemoryBuffer, version: Int32) { + self.g = g + self.p = p + self.version = version + } + + public init(decoder: PostboxDecoder) { + self.g = decoder.decodeInt32ForKey("g", orElse: 0) + self.p = decoder.decodeBytesForKey("p")! + self.version = decoder.decodeInt32ForKey("v", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.g, forKey: "g") + encoder.encodeBytes(self.p, forKey: "p") + encoder.encodeInt32(self.version, forKey: "v") + } +} diff --git a/submodules/SyncCore/Sources/SecretChatFileReference.swift b/submodules/SyncCore/Sources/SecretChatFileReference.swift new file mode 100644 index 0000000000..ed69689a12 --- /dev/null +++ b/submodules/SyncCore/Sources/SecretChatFileReference.swift @@ -0,0 +1,33 @@ +import Postbox + +public final class SecretChatFileReference: PostboxCoding { + public let id: Int64 + public let accessHash: Int64 + public let size: Int32 + public let datacenterId: Int32 + public let keyFingerprint: Int32 + + public init(id: Int64, accessHash: Int64, size: Int32, datacenterId: Int32, keyFingerprint: Int32) { + self.id = id + self.accessHash = accessHash + self.size = size + self.datacenterId = datacenterId + self.keyFingerprint = keyFingerprint + } + + public init(decoder: PostboxDecoder) { + self.id = decoder.decodeInt64ForKey("i", orElse: 0) + self.accessHash = decoder.decodeInt64ForKey("a", orElse: 0) + self.size = decoder.decodeInt32ForKey("s", orElse: 0) + self.datacenterId = decoder.decodeInt32ForKey("d", orElse: 0) + self.keyFingerprint = decoder.decodeInt32ForKey("f", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt64(self.id, forKey: "i") + encoder.encodeInt64(self.accessHash, forKey: "a") + encoder.encodeInt32(self.size, forKey: "s") + encoder.encodeInt32(self.datacenterId, forKey: "d") + encoder.encodeInt32(self.keyFingerprint, forKey: "f") + } +} diff --git a/submodules/TelegramCore/TelegramCore/SecretChatIncomingDecryptedOperation.swift b/submodules/SyncCore/Sources/SecretChatIncomingDecryptedOperation.swift similarity index 66% rename from submodules/TelegramCore/TelegramCore/SecretChatIncomingDecryptedOperation.swift rename to submodules/SyncCore/Sources/SecretChatIncomingDecryptedOperation.swift index 7087cb03af..3ae051707b 100644 --- a/submodules/TelegramCore/TelegramCore/SecretChatIncomingDecryptedOperation.swift +++ b/submodules/SyncCore/Sources/SecretChatIncomingDecryptedOperation.swift @@ -5,34 +5,34 @@ import Foundation import Postbox #endif -struct SecretChatOperationSequenceInfo: PostboxCoding { - let topReceivedOperationIndex: Int32 - let operationIndex: Int32 +public struct SecretChatOperationSequenceInfo: PostboxCoding { + public let topReceivedOperationIndex: Int32 + public let operationIndex: Int32 - init(topReceivedOperationIndex: Int32, operationIndex: Int32) { + public init(topReceivedOperationIndex: Int32, operationIndex: Int32) { self.topReceivedOperationIndex = topReceivedOperationIndex self.operationIndex = operationIndex } - init(decoder: PostboxDecoder) { + public init(decoder: PostboxDecoder) { self.topReceivedOperationIndex = decoder.decodeInt32ForKey("r", orElse: 0) self.operationIndex = decoder.decodeInt32ForKey("o", orElse: 0) } - func encode(_ encoder: PostboxEncoder) { + public func encode(_ encoder: PostboxEncoder) { encoder.encodeInt32(self.topReceivedOperationIndex, forKey: "r") encoder.encodeInt32(self.operationIndex, forKey: "o") } } -final class SecretChatIncomingDecryptedOperation: PostboxCoding { - let timestamp: Int32 - let layer: Int32 - let sequenceInfo: SecretChatOperationSequenceInfo? - let contents: MemoryBuffer - let file: SecretChatFileReference? +public final class SecretChatIncomingDecryptedOperation: PostboxCoding { + public let timestamp: Int32 + public let layer: Int32 + public let sequenceInfo: SecretChatOperationSequenceInfo? + public let contents: MemoryBuffer + public let file: SecretChatFileReference? - init(timestamp: Int32, layer: Int32, sequenceInfo: SecretChatOperationSequenceInfo?, contents: MemoryBuffer, file: SecretChatFileReference?) { + public init(timestamp: Int32, layer: Int32, sequenceInfo: SecretChatOperationSequenceInfo?, contents: MemoryBuffer, file: SecretChatFileReference?) { self.timestamp = timestamp self.layer = layer self.sequenceInfo = sequenceInfo @@ -40,7 +40,7 @@ final class SecretChatIncomingDecryptedOperation: PostboxCoding { self.file = file } - init(decoder: PostboxDecoder) { + public init(decoder: PostboxDecoder) { self.timestamp = decoder.decodeInt32ForKey("t", orElse: 0) self.layer = decoder.decodeInt32ForKey("l", orElse: 0) self.sequenceInfo = decoder.decodeObjectForKey("s", decoder: { SecretChatOperationSequenceInfo(decoder: $0) }) as? SecretChatOperationSequenceInfo @@ -48,7 +48,7 @@ final class SecretChatIncomingDecryptedOperation: PostboxCoding { self.file = decoder.decodeObjectForKey("f", decoder: { SecretChatFileReference(decoder: $0) }) as? SecretChatFileReference } - func encode(_ encoder: PostboxEncoder) { + public func encode(_ encoder: PostboxEncoder) { encoder.encodeInt32(self.timestamp, forKey: "t") encoder.encodeInt32(self.layer, forKey: "l") if let sequenceInfo = self.sequenceInfo { diff --git a/submodules/SyncCore/Sources/SecretChatIncomingEncryptedOperation.swift b/submodules/SyncCore/Sources/SecretChatIncomingEncryptedOperation.swift new file mode 100644 index 0000000000..cf4339125e --- /dev/null +++ b/submodules/SyncCore/Sources/SecretChatIncomingEncryptedOperation.swift @@ -0,0 +1,67 @@ +import Postbox + +public enum SecretChatIncomingEncryptedOperationType: Int32 { + case message + case service + + public init(_ value: Int32) { + if value == 0 { + self = .message + } else { + self = .service + } + } + + public var value: Int32 { + switch self { + case .message: + return 0 + case .service: + return 1 + } + } +} + +public final class SecretChatIncomingEncryptedOperation: PostboxCoding { + public let peerId: PeerId + public let globallyUniqueId: Int64 + public let timestamp: Int32 + public let type: SecretChatIncomingEncryptedOperationType + public let keyFingerprint: Int64 + public let contents: MemoryBuffer + public let mediaFileReference: SecretChatFileReference? + + public init(peerId: PeerId, globallyUniqueId: Int64, timestamp: Int32, type: SecretChatIncomingEncryptedOperationType, keyFingerprint: Int64, contents: MemoryBuffer, mediaFileReference: SecretChatFileReference?) { + self.peerId = peerId + self.globallyUniqueId = globallyUniqueId + self.timestamp = timestamp + self.type = type + self.keyFingerprint = keyFingerprint + self.contents = contents + self.mediaFileReference = mediaFileReference + } + + public init(decoder: PostboxDecoder) { + self.peerId = PeerId(decoder.decodeInt64ForKey("p", orElse: 0)) + self.globallyUniqueId = decoder.decodeInt64ForKey("u", orElse: 0) + self.timestamp = decoder.decodeInt32ForKey("t", orElse: 0) + self.type = SecretChatIncomingEncryptedOperationType(decoder.decodeInt32ForKey("k", orElse: 0)) + self.keyFingerprint = decoder.decodeInt64ForKey("f", orElse: 0) + self.contents = decoder.decodeBytesForKey("c")! + self.mediaFileReference = decoder.decodeObjectForKey("m", decoder: { SecretChatFileReference(decoder: $0) }) as? SecretChatFileReference + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt64(self.peerId.toInt64(), forKey: "p") + encoder.encodeInt64(self.globallyUniqueId, forKey: "u") + encoder.encodeInt32(self.timestamp, forKey: "t") + encoder.encodeInt32(self.type.value, forKey: "k") + encoder.encodeInt64(self.keyFingerprint, forKey: "f") + encoder.encodeBytes(self.contents, forKey: "c") + if let mediaFileReference = self.mediaFileReference { + encoder.encodeObject(mediaFileReference, forKey: "m") + } else { + encoder.encodeNil(forKey: "m") + } + } +} diff --git a/submodules/TelegramCore/TelegramCore/SecretChatKeychain.swift b/submodules/SyncCore/Sources/SecretChatKeychain.swift similarity index 90% rename from submodules/TelegramCore/TelegramCore/SecretChatKeychain.swift rename to submodules/SyncCore/Sources/SecretChatKeychain.swift index 90959dfe61..eb73b5171b 100644 --- a/submodules/TelegramCore/TelegramCore/SecretChatKeychain.swift +++ b/submodules/SyncCore/Sources/SecretChatKeychain.swift @@ -50,10 +50,10 @@ public enum SecretChatKeyValidity: PostboxCoding, Equatable { } public final class SecretChatKey: PostboxCoding, Equatable { - let fingerprint: Int64 - let key: MemoryBuffer - let validity: SecretChatKeyValidity - let useCount: Int32 + public let fingerprint: Int64 + public let key: MemoryBuffer + public let validity: SecretChatKeyValidity + public let useCount: Int32 public init(fingerprint: Int64, key: MemoryBuffer, validity: SecretChatKeyValidity, useCount: Int32) { self.fingerprint = fingerprint @@ -76,7 +76,7 @@ public final class SecretChatKey: PostboxCoding, Equatable { encoder.encodeInt32(self.useCount, forKey: "u") } - func withIncrementedUseCount() -> SecretChatKey { + public func withIncrementedUseCount() -> SecretChatKey { return SecretChatKey(fingerprint: self.fingerprint, key: self.key, validity: self.validity, useCount: self.useCount + 1) } @@ -95,7 +95,7 @@ public final class SecretChatKey: PostboxCoding, Equatable { } public final class SecretChatKeychain: PostboxCoding, Equatable { - let keys: [SecretChatKey] + public let keys: [SecretChatKey] public init(keys: [SecretChatKey]) { self.keys = keys @@ -109,7 +109,7 @@ public final class SecretChatKeychain: PostboxCoding, Equatable { encoder.encodeObjectArray(self.keys, forKey: "k") } - func key(fingerprint: Int64) -> SecretChatKey? { + public func key(fingerprint: Int64) -> SecretChatKey? { for key in self.keys { if key.fingerprint == fingerprint { return key @@ -118,7 +118,7 @@ public final class SecretChatKeychain: PostboxCoding, Equatable { return nil } - func indefinitelyValidKey() -> SecretChatKey? { + public func indefinitelyValidKey() -> SecretChatKey? { for key in self.keys { if case .indefinite = key.validity { return key @@ -127,7 +127,7 @@ public final class SecretChatKeychain: PostboxCoding, Equatable { return nil } - func latestKey(validForSequenceBasedCanonicalIndex index: Int32) -> SecretChatKey? { + public func latestKey(validForSequenceBasedCanonicalIndex index: Int32) -> SecretChatKey? { var maxFromCanonicalIndex: (Int, Int32)? for i in 0 ..< self.keys.count { switch self.keys[i].validity { @@ -158,7 +158,7 @@ public final class SecretChatKeychain: PostboxCoding, Equatable { return nil } - func withUpdatedKey(fingerprint: Int64, _ f: (SecretChatKey?) -> SecretChatKey?) -> SecretChatKeychain { + public func withUpdatedKey(fingerprint: Int64, _ f: (SecretChatKey?) -> SecretChatKey?) -> SecretChatKeychain { var keys = self.keys var found = false for i in 0 ..< keys.count { diff --git a/submodules/SyncCore/Sources/SecretChatOutgoingOperation.swift b/submodules/SyncCore/Sources/SecretChatOutgoingOperation.swift new file mode 100644 index 0000000000..28d3616e32 --- /dev/null +++ b/submodules/SyncCore/Sources/SecretChatOutgoingOperation.swift @@ -0,0 +1,284 @@ +import Postbox + +private enum SecretChatOutgoingFileValue: Int32 { + case remote = 0 + case uploadedRegular = 1 + case uploadedLarge = 2 +} + +public enum SecretChatOutgoingFileReference: PostboxCoding { + case remote(id: Int64, accessHash: Int64) + case uploadedRegular(id: Int64, partCount: Int32, md5Digest: String, keyFingerprint: Int32) + case uploadedLarge(id: Int64, partCount: Int32, keyFingerprint: Int32) + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("v", orElse: 0) { + case SecretChatOutgoingFileValue.remote.rawValue: + self = .remote(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("a", orElse: 0)) + case SecretChatOutgoingFileValue.uploadedRegular.rawValue: + self = .uploadedRegular(id: decoder.decodeInt64ForKey("i", orElse: 0), partCount: decoder.decodeInt32ForKey("p", orElse: 0), md5Digest: decoder.decodeStringForKey("d", orElse: ""), keyFingerprint: decoder.decodeInt32ForKey("f", orElse: 0)) + case SecretChatOutgoingFileValue.uploadedLarge.rawValue: + self = .uploadedLarge(id: decoder.decodeInt64ForKey("i", orElse: 0), partCount: decoder.decodeInt32ForKey("p", orElse: 0), keyFingerprint: decoder.decodeInt32ForKey("f", orElse: 0)) + default: + assertionFailure() + self = .remote(id: 0, accessHash: 0) + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .remote(id, accessHash): + encoder.encodeInt32(SecretChatOutgoingFileValue.remote.rawValue, forKey: "v") + encoder.encodeInt64(id, forKey: "i") + encoder.encodeInt64(accessHash, forKey: "a") + case let .uploadedRegular(id, partCount, md5Digest, keyFingerprint): + encoder.encodeInt32(SecretChatOutgoingFileValue.uploadedRegular.rawValue, forKey: "v") + encoder.encodeInt64(id, forKey: "i") + encoder.encodeInt32(partCount, forKey: "p") + encoder.encodeString(md5Digest, forKey: "d") + encoder.encodeInt32(keyFingerprint, forKey: "f") + case let .uploadedLarge(id, partCount, keyFingerprint): + encoder.encodeInt32(SecretChatOutgoingFileValue.uploadedLarge.rawValue, forKey: "v") + encoder.encodeInt64(id, forKey: "i") + encoder.encodeInt32(partCount, forKey: "p") + encoder.encodeInt32(keyFingerprint, forKey: "f") + } + } +} + +public struct SecretChatOutgoingFile: PostboxCoding { + public let reference: SecretChatOutgoingFileReference + public let size: Int32 + public let key: SecretFileEncryptionKey + + public init(reference: SecretChatOutgoingFileReference, size: Int32, key: SecretFileEncryptionKey) { + self.reference = reference + self.size = size + self.key = key + } + + public init(decoder: PostboxDecoder) { + self.reference = decoder.decodeObjectForKey("r", decoder: { SecretChatOutgoingFileReference(decoder: $0) }) as! SecretChatOutgoingFileReference + self.size = decoder.decodeInt32ForKey("s", orElse: 0) + self.key = SecretFileEncryptionKey(aesKey: decoder.decodeBytesForKey("k")!.makeData(), aesIv: decoder.decodeBytesForKey("i")!.makeData()) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObject(self.reference, forKey: "r") + encoder.encodeInt32(self.size, forKey: "s") + encoder.encodeBytes(MemoryBuffer(data: self.key.aesKey), forKey: "k") + encoder.encodeBytes(MemoryBuffer(data: self.key.aesIv), forKey: "i") + } +} + +public enum SecretChatSequenceBasedLayer: Int32 { + case layer46 = 46 + case layer73 = 73 + case layer101 = 101 + + public var secretChatLayer: SecretChatLayer { + switch self { + case .layer46: + return .layer46 + case .layer73: + return .layer73 + case .layer101: + return .layer101 + } + } +} + +private enum SecretChatOutgoingOperationValue: Int32 { + case initialHandshakeAccept = 0 + case sendMessage = 1 + case readMessagesContent = 2 + case deleteMessages = 3 + case screenshotMessages = 4 + case clearHistory = 5 + case resendOperations = 6 + case reportLayerSupport = 7 + case pfsRequestKey = 8 + case pfsAcceptKey = 9 + case pfsAbortSession = 10 + case pfsCommitKey = 11 + case noop = 12 + case setMessageAutoremoveTimeout = 13 + case terminate = 14 +} + +public enum SecretChatOutgoingOperationContents: PostboxCoding { + case initialHandshakeAccept(gA: MemoryBuffer, accessHash: Int64, b: MemoryBuffer) + case sendMessage(layer: SecretChatLayer, id: MessageId, file: SecretChatOutgoingFile?) + case readMessagesContent(layer: SecretChatLayer, actionGloballyUniqueId: Int64, globallyUniqueIds: [Int64]) + case deleteMessages(layer: SecretChatLayer, actionGloballyUniqueId: Int64, globallyUniqueIds: [Int64]) + case screenshotMessages(layer: SecretChatLayer, actionGloballyUniqueId: Int64, globallyUniqueIds: [Int64], messageId: MessageId) + case clearHistory(layer: SecretChatLayer, actionGloballyUniqueId: Int64) + case resendOperations(layer : SecretChatSequenceBasedLayer, actionGloballyUniqueId: Int64, fromSeqNo: Int32, toSeqNo: Int32) + case reportLayerSupport(layer: SecretChatLayer, actionGloballyUniqueId: Int64, layerSupport: Int32) + case pfsRequestKey(layer: SecretChatSequenceBasedLayer, actionGloballyUniqueId: Int64, rekeySessionId: Int64, a: MemoryBuffer) + case pfsAcceptKey(layer: SecretChatSequenceBasedLayer, actionGloballyUniqueId: Int64, rekeySessionId: Int64, gA: MemoryBuffer, b: MemoryBuffer) + case pfsAbortSession(layer: SecretChatSequenceBasedLayer, actionGloballyUniqueId: Int64, rekeySessionId: Int64) + case pfsCommitKey(layer: SecretChatSequenceBasedLayer, actionGloballyUniqueId: Int64, rekeySessionId: Int64, keyFingerprint: Int64) + case noop(layer: SecretChatSequenceBasedLayer, actionGloballyUniqueId: Int64) + case setMessageAutoremoveTimeout(layer: SecretChatLayer, actionGloballyUniqueId: Int64, timeout: Int32, messageId: MessageId) + case terminate(reportSpam: Bool) + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("r", orElse: 0) { + case SecretChatOutgoingOperationValue.initialHandshakeAccept.rawValue: + self = .initialHandshakeAccept(gA: decoder.decodeBytesForKey("g")!, accessHash: decoder.decodeInt64ForKey("h", orElse: 0), b: decoder.decodeBytesForKey("b")!) + case SecretChatOutgoingOperationValue.sendMessage.rawValue: + self = .sendMessage(layer: SecretChatLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, id: MessageId(peerId: PeerId(decoder.decodeInt64ForKey("i.p", orElse: 0)), namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt32ForKey("i.i", orElse: 0)), file: decoder.decodeObjectForKey("f", decoder: { SecretChatOutgoingFile(decoder: $0) }) as? SecretChatOutgoingFile) + case SecretChatOutgoingOperationValue.readMessagesContent.rawValue: + self = .readMessagesContent(layer: SecretChatLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), globallyUniqueIds: decoder.decodeInt64ArrayForKey("u")) + case SecretChatOutgoingOperationValue.deleteMessages.rawValue: + self = .deleteMessages(layer: SecretChatLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), globallyUniqueIds: decoder.decodeInt64ArrayForKey("u")) + case SecretChatOutgoingOperationValue.screenshotMessages.rawValue: + self = .screenshotMessages(layer: SecretChatLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), globallyUniqueIds: decoder.decodeInt64ArrayForKey("u"), messageId: MessageId(peerId: PeerId(decoder.decodeInt64ForKey("m.p", orElse: 0)), namespace: decoder.decodeInt32ForKey("m.n", orElse: 0), id: decoder.decodeInt32ForKey("m.i", orElse: 0))) + case SecretChatOutgoingOperationValue.clearHistory.rawValue: + self = .clearHistory(layer: SecretChatLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0)) + case SecretChatOutgoingOperationValue.resendOperations.rawValue: + self = .resendOperations(layer: SecretChatSequenceBasedLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), fromSeqNo: decoder.decodeInt32ForKey("f", orElse: 0), toSeqNo: decoder.decodeInt32ForKey("t", orElse: 0)) + case SecretChatOutgoingOperationValue.reportLayerSupport.rawValue: + self = .reportLayerSupport(layer: SecretChatLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), layerSupport: decoder.decodeInt32ForKey("l", orElse: 0)) + case SecretChatOutgoingOperationValue.pfsRequestKey.rawValue: + self = .pfsRequestKey(layer: SecretChatSequenceBasedLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), rekeySessionId: decoder.decodeInt64ForKey("s", orElse: 0), a: decoder.decodeBytesForKey("a")!) + case SecretChatOutgoingOperationValue.pfsAcceptKey.rawValue: + self = .pfsAcceptKey(layer: SecretChatSequenceBasedLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), rekeySessionId: decoder.decodeInt64ForKey("s", orElse: 0), gA: decoder.decodeBytesForKey("g")!, b: decoder.decodeBytesForKey("b")!) + case SecretChatOutgoingOperationValue.pfsAbortSession.rawValue: + self = .pfsAbortSession(layer: SecretChatSequenceBasedLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), rekeySessionId: decoder.decodeInt64ForKey("s", orElse: 0)) + case SecretChatOutgoingOperationValue.pfsCommitKey.rawValue: + self = .pfsCommitKey(layer: SecretChatSequenceBasedLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), rekeySessionId: decoder.decodeInt64ForKey("s", orElse: 0), keyFingerprint: decoder.decodeInt64ForKey("f", orElse: 0)) + case SecretChatOutgoingOperationValue.noop.rawValue: + self = .noop(layer: SecretChatSequenceBasedLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0)) + case SecretChatOutgoingOperationValue.setMessageAutoremoveTimeout.rawValue: + self = .setMessageAutoremoveTimeout(layer: SecretChatLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), timeout: decoder.decodeInt32ForKey("t", orElse: 0), messageId: MessageId(peerId: PeerId(decoder.decodeInt64ForKey("m.p", orElse: 0)), namespace: decoder.decodeInt32ForKey("m.n", orElse: 0), id: decoder.decodeInt32ForKey("m.i", orElse: 0))) + case SecretChatOutgoingOperationValue.terminate.rawValue: + self = .terminate(reportSpam: decoder.decodeInt32ForKey("rs", orElse: 0) != 0) + default: + self = .noop(layer: SecretChatSequenceBasedLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: 0) + assertionFailure() + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .initialHandshakeAccept(gA, accessHash, b): + encoder.encodeInt32(SecretChatOutgoingOperationValue.initialHandshakeAccept.rawValue, forKey: "r") + encoder.encodeBytes(gA, forKey: "g") + encoder.encodeInt64(accessHash, forKey: "h") + encoder.encodeBytes(b, forKey: "b") + case let .sendMessage(layer, id, file): + encoder.encodeInt32(SecretChatOutgoingOperationValue.sendMessage.rawValue, forKey: "r") + encoder.encodeInt32(layer.rawValue, forKey: "l") + encoder.encodeInt64(id.peerId.toInt64(), forKey: "i.p") + encoder.encodeInt32(id.namespace, forKey: "i.n") + encoder.encodeInt32(id.id, forKey: "i.i") + if let file = file { + encoder.encodeObject(file, forKey: "f") + } else { + encoder.encodeNil(forKey: "f") + } + case let .readMessagesContent(layer, actionGloballyUniqueId, globallyUniqueIds): + encoder.encodeInt32(SecretChatOutgoingOperationValue.readMessagesContent.rawValue, forKey: "r") + encoder.encodeInt32(layer.rawValue, forKey: "l") + encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") + encoder.encodeInt64Array(globallyUniqueIds, forKey: "u") + case let .deleteMessages(layer, actionGloballyUniqueId, globallyUniqueIds): + encoder.encodeInt32(SecretChatOutgoingOperationValue.deleteMessages.rawValue, forKey: "r") + encoder.encodeInt32(layer.rawValue, forKey: "l") + encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") + encoder.encodeInt64Array(globallyUniqueIds, forKey: "u") + case let .screenshotMessages(layer, actionGloballyUniqueId, globallyUniqueIds, messageId): + encoder.encodeInt32(SecretChatOutgoingOperationValue.screenshotMessages.rawValue, forKey: "r") + encoder.encodeInt32(layer.rawValue, forKey: "l") + encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") + encoder.encodeInt64Array(globallyUniqueIds, forKey: "u") + encoder.encodeInt64(messageId.peerId.toInt64(), forKey: "m.p") + encoder.encodeInt32(messageId.namespace, forKey: "m.n") + encoder.encodeInt32(messageId.id, forKey: "m.i") + case let .clearHistory(layer, actionGloballyUniqueId): + encoder.encodeInt32(SecretChatOutgoingOperationValue.clearHistory.rawValue, forKey: "r") + encoder.encodeInt32(layer.rawValue, forKey: "l") + encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") + case let .resendOperations(layer, actionGloballyUniqueId, fromSeqNo, toSeqNo): + encoder.encodeInt32(SecretChatOutgoingOperationValue.resendOperations.rawValue, forKey: "r") + encoder.encodeInt32(layer.rawValue, forKey: "l") + encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") + encoder.encodeInt32(fromSeqNo, forKey: "f") + encoder.encodeInt32(toSeqNo, forKey: "t") + case let .reportLayerSupport(layer, actionGloballyUniqueId, layerSupport): + encoder.encodeInt32(SecretChatOutgoingOperationValue.reportLayerSupport.rawValue, forKey: "r") + encoder.encodeInt32(layer.rawValue, forKey: "l") + encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") + encoder.encodeInt32(layerSupport, forKey: "l") + case let .pfsRequestKey(layer, actionGloballyUniqueId, rekeySessionId, a): + encoder.encodeInt32(SecretChatOutgoingOperationValue.pfsRequestKey.rawValue, forKey: "r") + encoder.encodeInt32(layer.rawValue, forKey: "l") + encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") + encoder.encodeInt64(rekeySessionId, forKey: "s") + encoder.encodeBytes(a, forKey: "a") + case let .pfsAcceptKey(layer, actionGloballyUniqueId, rekeySessionId, gA, b): + encoder.encodeInt32(SecretChatOutgoingOperationValue.pfsAcceptKey.rawValue, forKey: "r") + encoder.encodeInt32(layer.rawValue, forKey: "l") + encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") + encoder.encodeInt64(rekeySessionId, forKey: "s") + encoder.encodeBytes(gA, forKey: "g") + encoder.encodeBytes(b, forKey: "b") + case let .pfsAbortSession(layer, actionGloballyUniqueId, rekeySessionId): + encoder.encodeInt32(SecretChatOutgoingOperationValue.pfsAbortSession.rawValue, forKey: "r") + encoder.encodeInt32(layer.rawValue, forKey: "l") + encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") + encoder.encodeInt64(rekeySessionId, forKey: "s") + case let .pfsCommitKey(layer, actionGloballyUniqueId, rekeySessionId, keyFingerprint): + encoder.encodeInt32(SecretChatOutgoingOperationValue.pfsCommitKey.rawValue, forKey: "r") + encoder.encodeInt32(layer.rawValue, forKey: "l") + encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") + encoder.encodeInt64(rekeySessionId, forKey: "s") + encoder.encodeInt64(keyFingerprint, forKey: "f") + case let .noop(layer, actionGloballyUniqueId): + encoder.encodeInt32(SecretChatOutgoingOperationValue.noop.rawValue, forKey: "r") + encoder.encodeInt32(layer.rawValue, forKey: "l") + encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") + case let .setMessageAutoremoveTimeout(layer, actionGloballyUniqueId, timeout, messageId): + encoder.encodeInt32(SecretChatOutgoingOperationValue.setMessageAutoremoveTimeout.rawValue, forKey: "r") + encoder.encodeInt32(layer.rawValue, forKey: "l") + encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") + encoder.encodeInt32(timeout, forKey: "t") + encoder.encodeInt64(messageId.peerId.toInt64(), forKey: "m.p") + encoder.encodeInt32(messageId.namespace, forKey: "m.n") + encoder.encodeInt32(messageId.id, forKey: "m.i") + case let .terminate(reportSpam): + encoder.encodeInt32(SecretChatOutgoingOperationValue.terminate.rawValue, forKey: "r") + encoder.encodeInt32(reportSpam ? 1 : 0, forKey: "rs") + } + } +} + +public final class SecretChatOutgoingOperation: PostboxCoding { + public let contents: SecretChatOutgoingOperationContents + public let mutable: Bool + public let delivered: Bool + + public init(contents: SecretChatOutgoingOperationContents, mutable: Bool, delivered: Bool) { + self.contents = contents + self.mutable = mutable + self.delivered = delivered + } + + public init(decoder: PostboxDecoder) { + self.contents = decoder.decodeObjectForKey("c", decoder: { SecretChatOutgoingOperationContents(decoder: $0) }) as! SecretChatOutgoingOperationContents + self.mutable = decoder.decodeInt32ForKey("m", orElse: 0) != 0 + self.delivered = decoder.decodeInt32ForKey("d", orElse: 0) != 0 + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObject(self.contents, forKey: "c") + encoder.encodeInt32(self.mutable ? 1 : 0, forKey: "m") + encoder.encodeInt32(self.delivered ? 1 : 0, forKey: "d") + } + + public func withUpdatedDelivered(_ delivered: Bool) -> SecretChatOutgoingOperation { + return SecretChatOutgoingOperation(contents: self.contents, mutable: self.mutable, delivered: delivered) + } +} diff --git a/submodules/TelegramCore/TelegramCore/SecretChatSettings.swift b/submodules/SyncCore/Sources/SecretChatSettings.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/SecretChatSettings.swift rename to submodules/SyncCore/Sources/SecretChatSettings.swift diff --git a/submodules/TelegramCore/TelegramCore/SecretChatState.swift b/submodules/SyncCore/Sources/SecretChatState.swift similarity index 92% rename from submodules/TelegramCore/TelegramCore/SecretChatState.swift rename to submodules/SyncCore/Sources/SecretChatState.swift index 3d5f1aacb0..42237651a9 100644 --- a/submodules/TelegramCore/TelegramCore/SecretChatState.swift +++ b/submodules/SyncCore/Sources/SecretChatState.swift @@ -10,7 +10,7 @@ public enum SecretChatRole: Int32 { case participant } -enum SecretChatLayer: Int32 { +public enum SecretChatLayer: Int32 { case layer8 = 8 case layer46 = 46 case layer73 = 73 @@ -242,9 +242,9 @@ public enum SecretChatHandshakeState: PostboxCoding, Equatable { } public struct SecretChatLayerNegotiationState: PostboxCoding, Equatable { - let activeLayer: SecretChatSequenceBasedLayer - let locallyRequestedLayer: Int32? - let remotelyRequestedLayer: Int32? + public let activeLayer: SecretChatSequenceBasedLayer + public let locallyRequestedLayer: Int32? + public let remotelyRequestedLayer: Int32? public init(activeLayer: SecretChatSequenceBasedLayer, locallyRequestedLayer: Int32?, remotelyRequestedLayer: Int32?) { self.activeLayer = activeLayer @@ -285,15 +285,15 @@ public struct SecretChatLayerNegotiationState: PostboxCoding, Equatable { return true } - func withUpdatedActiveLayer(_ activeLayer: SecretChatSequenceBasedLayer) -> SecretChatLayerNegotiationState { + public func withUpdatedActiveLayer(_ activeLayer: SecretChatSequenceBasedLayer) -> SecretChatLayerNegotiationState { return SecretChatLayerNegotiationState(activeLayer: activeLayer, locallyRequestedLayer: self.locallyRequestedLayer, remotelyRequestedLayer: self.remotelyRequestedLayer) } - func withUpdatedLocallyRequestedLayer(_ locallyRequestedLayer: Int32?) -> SecretChatLayerNegotiationState { + public func withUpdatedLocallyRequestedLayer(_ locallyRequestedLayer: Int32?) -> SecretChatLayerNegotiationState { return SecretChatLayerNegotiationState(activeLayer: self.activeLayer, locallyRequestedLayer: locallyRequestedLayer, remotelyRequestedLayer: self.remotelyRequestedLayer) } - func withUpdatedRemotelyRequestedLayer(_ remotelyRequestedLayer: Int32?) -> SecretChatLayerNegotiationState { + public func withUpdatedRemotelyRequestedLayer(_ remotelyRequestedLayer: Int32?) -> SecretChatLayerNegotiationState { return SecretChatLayerNegotiationState(activeLayer: self.activeLayer, locallyRequestedLayer: self.locallyRequestedLayer, remotelyRequestedLayer: remotelyRequestedLayer) } } @@ -374,8 +374,8 @@ public enum SecretChatRekeySessionData: PostboxCoding, Equatable { } public struct SecretChatRekeySessionState: PostboxCoding, Equatable { - let id: Int64 - let data: SecretChatRekeySessionData + public let id: Int64 + public let data: SecretChatRekeySessionData public init(id: Int64, data: SecretChatRekeySessionData) { self.id = id @@ -404,11 +404,11 @@ public struct SecretChatRekeySessionState: PostboxCoding, Equatable { } public struct SecretChatSequenceBasedLayerState: PostboxCoding, Equatable { - let layerNegotiationState: SecretChatLayerNegotiationState - let rekeyState: SecretChatRekeySessionState? + public let layerNegotiationState: SecretChatLayerNegotiationState + public let rekeyState: SecretChatRekeySessionState? public let baseIncomingOperationIndex: Int32 public let baseOutgoingOperationIndex: Int32 - let topProcessedCanonicalIncomingOperationIndex: Int32? + public let topProcessedCanonicalIncomingOperationIndex: Int32? public init(layerNegotiationState: SecretChatLayerNegotiationState, rekeyState: SecretChatRekeySessionState?, baseIncomingOperationIndex: Int32, baseOutgoingOperationIndex: Int32, topProcessedCanonicalIncomingOperationIndex: Int32?) { self.layerNegotiationState = layerNegotiationState @@ -446,27 +446,27 @@ public struct SecretChatSequenceBasedLayerState: PostboxCoding, Equatable { } } - func canonicalIncomingOperationIndex(_ index: Int32) -> Int32 { + public func canonicalIncomingOperationIndex(_ index: Int32) -> Int32 { return index - self.baseIncomingOperationIndex } - func canonicalOutgoingOperationIndex(_ index: Int32) -> Int32 { + public func canonicalOutgoingOperationIndex(_ index: Int32) -> Int32 { return index - self.baseOutgoingOperationIndex } - func outgoingOperationIndexFromCanonicalOperationIndex(_ index: Int32) -> Int32 { + public func outgoingOperationIndexFromCanonicalOperationIndex(_ index: Int32) -> Int32 { return index + self.baseOutgoingOperationIndex } - func withUpdatedLayerNegotiationState(_ layerNegotiationState: SecretChatLayerNegotiationState) -> SecretChatSequenceBasedLayerState { + public func withUpdatedLayerNegotiationState(_ layerNegotiationState: SecretChatLayerNegotiationState) -> SecretChatSequenceBasedLayerState { return SecretChatSequenceBasedLayerState(layerNegotiationState: layerNegotiationState, rekeyState: self.rekeyState, baseIncomingOperationIndex: self.baseIncomingOperationIndex, baseOutgoingOperationIndex: self.baseOutgoingOperationIndex, topProcessedCanonicalIncomingOperationIndex: self.topProcessedCanonicalIncomingOperationIndex) } - func withUpdatedRekeyState(_ rekeyState: SecretChatRekeySessionState?) -> SecretChatSequenceBasedLayerState { + public func withUpdatedRekeyState(_ rekeyState: SecretChatRekeySessionState?) -> SecretChatSequenceBasedLayerState { return SecretChatSequenceBasedLayerState(layerNegotiationState: self.layerNegotiationState, rekeyState: rekeyState, baseIncomingOperationIndex: self.baseIncomingOperationIndex, baseOutgoingOperationIndex: self.baseOutgoingOperationIndex, topProcessedCanonicalIncomingOperationIndex: self.topProcessedCanonicalIncomingOperationIndex) } - func withUpdatedTopProcessedCanonicalIncomingOperationIndex(_ topProcessedCanonicalIncomingOperationIndex: Int32?) -> SecretChatSequenceBasedLayerState { + public func withUpdatedTopProcessedCanonicalIncomingOperationIndex(_ topProcessedCanonicalIncomingOperationIndex: Int32?) -> SecretChatSequenceBasedLayerState { return SecretChatSequenceBasedLayerState(layerNegotiationState: self.layerNegotiationState, rekeyState: self.rekeyState, baseIncomingOperationIndex: self.baseIncomingOperationIndex, baseOutgoingOperationIndex: self.baseOutgoingOperationIndex, topProcessedCanonicalIncomingOperationIndex: topProcessedCanonicalIncomingOperationIndex) } @@ -570,11 +570,11 @@ public protocol SecretChatKeyState { } public final class SecretChatState: PeerChatState, SecretChatKeyState, Equatable { - let role: SecretChatRole + public let role: SecretChatRole public let embeddedState: SecretChatEmbeddedState - let keychain: SecretChatKeychain + public let keychain: SecretChatKeychain public let keyFingerprint: SecretChatKeyFingerprint? - let messageAutoremoveTimeout: Int32? + public let messageAutoremoveTimeout: Int32? public init(role: SecretChatRole, embeddedState: SecretChatEmbeddedState, keychain: SecretChatKeychain, keyFingerprint: SecretChatKeyFingerprint?, messageAutoremoveTimeout: Int32?) { self.role = role @@ -619,19 +619,19 @@ public final class SecretChatState: PeerChatState, SecretChatKeyState, Equatable return lhs.role == rhs.role && lhs.embeddedState == rhs.embeddedState && lhs.keychain == rhs.keychain && lhs.messageAutoremoveTimeout == rhs.messageAutoremoveTimeout } - func withUpdatedKeyFingerprint(_ keyFingerprint: SecretChatKeyFingerprint?) -> SecretChatState { + public func withUpdatedKeyFingerprint(_ keyFingerprint: SecretChatKeyFingerprint?) -> SecretChatState { return SecretChatState(role: self.role, embeddedState: self.embeddedState, keychain: self.keychain, keyFingerprint: keyFingerprint, messageAutoremoveTimeout: self.messageAutoremoveTimeout) } - func withUpdatedEmbeddedState(_ embeddedState: SecretChatEmbeddedState) -> SecretChatState { + public func withUpdatedEmbeddedState(_ embeddedState: SecretChatEmbeddedState) -> SecretChatState { return SecretChatState(role: self.role, embeddedState: embeddedState, keychain: self.keychain, keyFingerprint: self.keyFingerprint, messageAutoremoveTimeout: self.messageAutoremoveTimeout) } - func withUpdatedKeychain(_ keychain: SecretChatKeychain) -> SecretChatState { + public func withUpdatedKeychain(_ keychain: SecretChatKeychain) -> SecretChatState { return SecretChatState(role: self.role, embeddedState: self.embeddedState, keychain: keychain, keyFingerprint: self.keyFingerprint, messageAutoremoveTimeout: self.messageAutoremoveTimeout) } - func withUpdatedMessageAutoremoveTimeout(_ messageAutoremoveTimeout: Int32?) -> SecretChatState { + public func withUpdatedMessageAutoremoveTimeout(_ messageAutoremoveTimeout: Int32?) -> SecretChatState { return SecretChatState(role: self.role, embeddedState: self.embeddedState, keychain: self.keychain, keyFingerprint: self.keyFingerprint, messageAutoremoveTimeout: messageAutoremoveTimeout) } } diff --git a/submodules/SyncCore/Sources/SecretFileEncryptionKey.swift b/submodules/SyncCore/Sources/SecretFileEncryptionKey.swift new file mode 100644 index 0000000000..dfc417237a --- /dev/null +++ b/submodules/SyncCore/Sources/SecretFileEncryptionKey.swift @@ -0,0 +1,25 @@ +import Postbox + +public final class SecretFileEncryptionKey: PostboxCoding, Equatable { + public let aesKey: Data + public let aesIv: Data + + public init(aesKey: Data, aesIv: Data) { + self.aesKey = aesKey + self.aesIv = aesIv + } + + public init(decoder: PostboxDecoder) { + self.aesKey = decoder.decodeBytesForKey("k")!.makeData() + self.aesIv = decoder.decodeBytesForKey("i")!.makeData() + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeBytes(MemoryBuffer(data: self.aesKey), forKey: "k") + encoder.encodeBytes(MemoryBuffer(data: self.aesIv), forKey: "i") + } + + public static func ==(lhs: SecretFileEncryptionKey, rhs: SecretFileEncryptionKey) -> Bool { + return lhs.aesKey == rhs.aesKey && lhs.aesIv == rhs.aesIv + } +} diff --git a/submodules/SyncCore/Sources/SecureFileMediaResource.swift b/submodules/SyncCore/Sources/SecureFileMediaResource.swift new file mode 100644 index 0000000000..2c135dfb4b --- /dev/null +++ b/submodules/SyncCore/Sources/SecureFileMediaResource.swift @@ -0,0 +1,67 @@ +import Postbox + +public struct SecureFileMediaResourceId: MediaResourceId { + public let fileId: Int64 + + public init(fileId: Int64) { + self.fileId = fileId + } + + public var uniqueId: String { + return "telegram-secure-file-\(self.fileId)" + } + + public var hashValue: Int { + return self.fileId.hashValue + } + + public func isEqual(to: MediaResourceId) -> Bool { + if let to = to as? SecureFileMediaResourceId { + return self.fileId == to.fileId + } else { + return false + } + } +} + +public final class SecureFileMediaResource: TelegramMediaResource { + public let file: SecureIdFileReference + + public var id: MediaResourceId { + return SecureFileMediaResourceId(fileId: self.file.id) + } + + public var datacenterId: Int { + return Int(self.file.datacenterId) + } + + public var size: Int? { + return Int(self.file.size) + } + + public init(file: SecureIdFileReference) { + self.file = file + } + + public required init(decoder: PostboxDecoder) { + self.file = SecureIdFileReference(id: decoder.decodeInt64ForKey("f", orElse: 0), accessHash: decoder.decodeInt64ForKey("a", orElse: 0), size: decoder.decodeInt32ForKey("n", orElse: 0), datacenterId: decoder.decodeInt32ForKey("d", orElse: 0), timestamp: decoder.decodeInt32ForKey("t", orElse: 0), fileHash: decoder.decodeBytesForKey("h")?.makeData() ?? Data(), encryptedSecret: decoder.decodeBytesForKey("s")?.makeData() ?? Data()) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt64(self.file.id, forKey: "f") + encoder.encodeInt64(self.file.accessHash, forKey: "a") + encoder.encodeInt32(self.file.size, forKey: "n") + encoder.encodeInt32(self.file.datacenterId, forKey: "d") + encoder.encodeInt32(self.file.timestamp, forKey: "t") + encoder.encodeBytes(MemoryBuffer(data: self.file.fileHash), forKey: "h") + encoder.encodeBytes(MemoryBuffer(data: self.file.encryptedSecret), forKey: "s") + } + + public func isEqual(to: MediaResource) -> Bool { + if let to = to as? SecureFileMediaResource { + return self.file == to.file + } else { + return false + } + } +} diff --git a/submodules/SyncCore/Sources/SecureIdFileReference.swift b/submodules/SyncCore/Sources/SecureIdFileReference.swift new file mode 100644 index 0000000000..7ae84288ce --- /dev/null +++ b/submodules/SyncCore/Sources/SecureIdFileReference.swift @@ -0,0 +1,21 @@ +import Postbox + +public struct SecureIdFileReference: Equatable { + public let id: Int64 + public let accessHash: Int64 + public let size: Int32 + public let datacenterId: Int32 + public let timestamp: Int32 + public let fileHash: Data + public let encryptedSecret: Data + + public init(id: Int64, accessHash: Int64, size: Int32, datacenterId: Int32, timestamp: Int32, fileHash: Data, encryptedSecret: Data) { + self.id = id + self.accessHash = accessHash + self.size = size + self.datacenterId = datacenterId + self.timestamp = timestamp + self.fileHash = fileHash + self.encryptedSecret = encryptedSecret + } +} diff --git a/submodules/SyncCore/Sources/SendScheduledMessageImmediatelyAction.swift b/submodules/SyncCore/Sources/SendScheduledMessageImmediatelyAction.swift new file mode 100644 index 0000000000..a091937837 --- /dev/null +++ b/submodules/SyncCore/Sources/SendScheduledMessageImmediatelyAction.swift @@ -0,0 +1,20 @@ +import Postbox + +public final class SendScheduledMessageImmediatelyAction: PendingMessageActionData { + public init() { + } + + public init(decoder: PostboxDecoder) { + } + + public func encode(_ encoder: PostboxEncoder) { + } + + public func isEqual(to: PendingMessageActionData) -> Bool { + if let _ = to as? SendScheduledMessageImmediatelyAction { + return true + } else { + return false + } + } +} diff --git a/submodules/TelegramCore/TelegramCore/SourceReferenceMessageAttribute.swift b/submodules/SyncCore/Sources/SourceReferenceMessageAttribute.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/SourceReferenceMessageAttribute.swift rename to submodules/SyncCore/Sources/SourceReferenceMessageAttribute.swift diff --git a/submodules/SyncCore/Sources/StandaloneAccountTransaction.swift b/submodules/SyncCore/Sources/StandaloneAccountTransaction.swift new file mode 100644 index 0000000000..93d625cb33 --- /dev/null +++ b/submodules/SyncCore/Sources/StandaloneAccountTransaction.swift @@ -0,0 +1,52 @@ +import SwiftSignalKit +import Postbox + +private func accountRecordIdPathName(_ id: AccountRecordId) -> String { + return "account-\(UInt64(bitPattern: id.int64))" +} + +public let telegramPostboxSeedConfiguration: SeedConfiguration = { + var messageHoles: [PeerId.Namespace: [MessageId.Namespace: Set]] = [:] + for peerNamespace in peerIdNamespacesWithInitialCloudMessageHoles { + messageHoles[peerNamespace] = [ + Namespaces.Message.Cloud: Set(MessageTags.all) + ] + } + + var globalMessageIdsPeerIdNamespaces = Set() + for peerIdNamespace in [Namespaces.Peer.CloudUser, Namespaces.Peer.CloudGroup] { + globalMessageIdsPeerIdNamespaces.insert(GlobalMessageIdsNamespace(peerIdNamespace: peerIdNamespace, messageIdNamespace: Namespaces.Message.Cloud)) + } + + return SeedConfiguration(globalMessageIdsPeerIdNamespaces: globalMessageIdsPeerIdNamespaces, initializeChatListWithHole: (topLevel: ChatListHole(index: MessageIndex(id: MessageId(peerId: PeerId(namespace: Namespaces.Peer.Empty, id: 0), namespace: Namespaces.Message.Cloud, id: 1), timestamp: Int32.max - 1)), groups: ChatListHole(index: MessageIndex(id: MessageId(peerId: PeerId(namespace: Namespaces.Peer.Empty, id: 0), namespace: Namespaces.Message.Cloud, id: 1), timestamp: Int32.max - 1))), messageHoles: messageHoles, existingMessageTags: MessageTags.all, messageTagsWithSummary: MessageTags.unseenPersonalMessage, existingGlobalMessageTags: GlobalMessageTags.all, peerNamespacesRequiringMessageTextIndex: [Namespaces.Peer.SecretChat], peerSummaryCounterTags: { peer in + if let peer = peer as? TelegramChannel { + switch peer.info { + case .group: + if let addressName = peer.username, !addressName.isEmpty { + return [.publicGroups] + } else { + return [.regularChatsAndPrivateGroups] + } + case .broadcast: + return [.channels] + } + } else { + return [.regularChatsAndPrivateGroups] + } + }, additionalChatListIndexNamespace: Namespaces.Message.Cloud, messageNamespacesRequiringGroupStatsValidation: [Namespaces.Message.Cloud], defaultMessageNamespaceReadStates: [Namespaces.Message.Local: .idBased(maxIncomingReadId: 0, maxOutgoingReadId: 0, maxKnownId: 0, count: 0, markedUnread: false)], chatMessagesNamespaces: Set([Namespaces.Message.Cloud, Namespaces.Message.Local, Namespaces.Message.SecretIncoming])) +}() + +public func accountTransaction(rootPath: String, id: AccountRecordId, encryptionParameters: ValueBoxEncryptionParameters, transaction: @escaping (Transaction) -> T) -> Signal { + let path = "\(rootPath)/\(accountRecordIdPathName(id))" + let postbox = openPostbox(basePath: path + "/postbox", seedConfiguration: telegramPostboxSeedConfiguration, encryptionParameters: encryptionParameters) + return postbox + |> mapToSignal { value -> Signal in + switch value { + case let .postbox(postbox): + return postbox.transaction(transaction) + default: + return .complete() + } + } +} + diff --git a/submodules/SyncCore/Sources/StickerPackCollectionInfo.swift b/submodules/SyncCore/Sources/StickerPackCollectionInfo.swift new file mode 100644 index 0000000000..912192cb1a --- /dev/null +++ b/submodules/SyncCore/Sources/StickerPackCollectionInfo.swift @@ -0,0 +1,111 @@ +import Postbox + +public struct StickerPackCollectionInfoFlags: OptionSet { + public var rawValue: Int32 + + public init(rawValue: Int32) { + self.rawValue = rawValue + } + + public init() { + self.rawValue = 0 + } + + public init(_ flags: StickerPackCollectionInfoFlags) { + var rawValue: Int32 = 0 + + if flags.contains(StickerPackCollectionInfoFlags.isMasks) { + rawValue |= StickerPackCollectionInfoFlags.isMasks.rawValue + } + if flags.contains(StickerPackCollectionInfoFlags.isOfficial) { + rawValue |= StickerPackCollectionInfoFlags.isOfficial.rawValue + } + if flags.contains(StickerPackCollectionInfoFlags.isAnimated) { + rawValue |= StickerPackCollectionInfoFlags.isAnimated.rawValue + } + + self.rawValue = rawValue + } + + public static let isMasks = StickerPackCollectionInfoFlags(rawValue: 1 << 0) + public static let isOfficial = StickerPackCollectionInfoFlags(rawValue: 1 << 1) + public static let isAnimated = StickerPackCollectionInfoFlags(rawValue: 1 << 2) +} + + +public final class StickerPackCollectionInfo: ItemCollectionInfo, Equatable { + public let id: ItemCollectionId + public let flags: StickerPackCollectionInfoFlags + public let accessHash: Int64 + public let title: String + public let shortName: String + public let thumbnail: TelegramMediaImageRepresentation? + public let hash: Int32 + public let count: Int32 + + public init(id: ItemCollectionId, flags: StickerPackCollectionInfoFlags, accessHash: Int64, title: String, shortName: String, thumbnail: TelegramMediaImageRepresentation?, hash: Int32, count: Int32) { + self.id = id + self.flags = flags + self.accessHash = accessHash + self.title = title + self.shortName = shortName + self.thumbnail = thumbnail + self.hash = hash + self.count = count + } + + public init(decoder: PostboxDecoder) { + self.id = ItemCollectionId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)) + self.accessHash = decoder.decodeInt64ForKey("a", orElse: 0) + self.title = decoder.decodeStringForKey("t", orElse: "") + self.shortName = decoder.decodeStringForKey("s", orElse: "") + self.thumbnail = decoder.decodeObjectForKey("th", decoder: { TelegramMediaImageRepresentation(decoder: $0) }) as? TelegramMediaImageRepresentation + self.hash = decoder.decodeInt32ForKey("h", orElse: 0) + self.flags = StickerPackCollectionInfoFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0)) + self.count = decoder.decodeInt32ForKey("n", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.id.namespace, forKey: "i.n") + encoder.encodeInt64(self.id.id, forKey: "i.i") + encoder.encodeInt64(self.accessHash, forKey: "a") + encoder.encodeString(self.title, forKey: "t") + encoder.encodeString(self.shortName, forKey: "s") + if let thumbnail = self.thumbnail { + encoder.encodeObject(thumbnail, forKey: "th") + } else { + encoder.encodeNil(forKey: "th") + } + encoder.encodeInt32(self.hash, forKey: "h") + encoder.encodeInt32(self.flags.rawValue, forKey: "f") + encoder.encodeInt32(self.count, forKey: "n") + } + + public static func ==(lhs: StickerPackCollectionInfo, rhs: StickerPackCollectionInfo) -> Bool { + if lhs.id != rhs.id { + return false + } + + if lhs.title != rhs.title { + return false + } + + if lhs.shortName != rhs.shortName { + return false + } + + if lhs.hash != rhs.hash { + return false + } + + if lhs.flags != rhs.flags { + return false + } + + if lhs.count != rhs.count { + return false + } + + return true + } +} diff --git a/submodules/SyncCore/Sources/StickerPackItem.swift b/submodules/SyncCore/Sources/StickerPackItem.swift new file mode 100644 index 0000000000..c5333a4946 --- /dev/null +++ b/submodules/SyncCore/Sources/StickerPackItem.swift @@ -0,0 +1,42 @@ +import Postbox + +public final class StickerPackItem: ItemCollectionItem, Equatable { + public let index: ItemCollectionItemIndex + public let file: TelegramMediaFile + public let indexKeys: [MemoryBuffer] + + public init(index: ItemCollectionItemIndex, file: TelegramMediaFile, indexKeys: [MemoryBuffer]) { + self.index = index + self.file = file + self.indexKeys = indexKeys + } + + public init(decoder: PostboxDecoder) { + self.index = ItemCollectionItemIndex(index: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)) + self.file = decoder.decodeObjectForKey("f") as! TelegramMediaFile + self.indexKeys = decoder.decodeBytesArrayForKey("s") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.index.index, forKey: "i.n") + encoder.encodeInt64(self.index.id, forKey: "i.i") + encoder.encodeObject(self.file, forKey: "f") + encoder.encodeBytesArray(self.indexKeys, forKey: "s") + } + + public static func ==(lhs: StickerPackItem, rhs: StickerPackItem) -> Bool { + return lhs.index == rhs.index && lhs.file == rhs.file && lhs.indexKeys == rhs.indexKeys + } + + public func getStringRepresentationsOfIndexKeys() -> [String] { + var stringRepresentations: [String] = [] + for key in self.indexKeys { + key.withDataNoCopy { data in + if let string = String(data: data, encoding: .utf8) { + stringRepresentations.append(string) + } + } + } + return stringRepresentations + } +} diff --git a/submodules/SyncCore/Sources/SuggestedLocalizationEntry.swift b/submodules/SyncCore/Sources/SuggestedLocalizationEntry.swift new file mode 100644 index 0000000000..93b18cf4e2 --- /dev/null +++ b/submodules/SyncCore/Sources/SuggestedLocalizationEntry.swift @@ -0,0 +1,33 @@ +import Postbox + +public final class SuggestedLocalizationEntry: PreferencesEntry { + public let languageCode: String + public let isSeen: Bool + + public init(languageCode: String, isSeen: Bool) { + self.languageCode = languageCode + self.isSeen = isSeen + } + + public init(decoder: PostboxDecoder) { + self.languageCode = decoder.decodeStringForKey("lc", orElse: "en") + self.isSeen = decoder.decodeInt32ForKey("s", orElse: 0) != 0 + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.languageCode, forKey: "lc") + encoder.encodeInt32(self.isSeen ? 1 : 0, forKey: "s") + } + + public func isEqual(to: PreferencesEntry) -> Bool { + if let to = to as? SuggestedLocalizationEntry { + return self == to + } else { + return false + } + } + + public static func ==(lhs: SuggestedLocalizationEntry, rhs: SuggestedLocalizationEntry) -> Bool { + return lhs.languageCode == rhs.languageCode && lhs.isSeen == rhs.isSeen + } +} diff --git a/submodules/SyncCore/Sources/SuggestedLocalizationUpdatesOperation.swift b/submodules/SyncCore/Sources/SuggestedLocalizationUpdatesOperation.swift new file mode 100644 index 0000000000..0e2778012e --- /dev/null +++ b/submodules/SyncCore/Sources/SuggestedLocalizationUpdatesOperation.swift @@ -0,0 +1,12 @@ +import Postbox + +public final class SynchronizeLocalizationUpdatesOperation: PostboxCoding { + public init() { + } + + public init(decoder: PostboxDecoder) { + } + + public func encode(_ encoder: PostboxEncoder) { + } +} diff --git a/submodules/SyncCore/Sources/SynchronizeAppLogEventsOperation.swift b/submodules/SyncCore/Sources/SynchronizeAppLogEventsOperation.swift new file mode 100644 index 0000000000..de56774577 --- /dev/null +++ b/submodules/SyncCore/Sources/SynchronizeAppLogEventsOperation.swift @@ -0,0 +1,60 @@ +import Postbox + +private enum SynchronizeAppLogEventsOperationContentType: Int32 { + case add + case sync +} + +public enum SynchronizeAppLogEventsOperationContent: PostboxCoding { + case add(time: Double, type: String, peerId: PeerId?, data: JSON) + case sync + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("r", orElse: 0) { + case SynchronizeAppLogEventsOperationContentType.add.rawValue: + var peerId: PeerId? + if let id = decoder.decodeOptionalInt64ForKey("p") { + peerId = PeerId(id) + } + self = .add(time: decoder.decodeDoubleForKey("tm", orElse: 0.0), type: decoder.decodeStringForKey("t", orElse: ""), peerId: peerId, data: decoder.decodeObjectForKey("d", decoder: { JSON(decoder: $0) }) as! JSON) + case SynchronizeAppLogEventsOperationContentType.sync.rawValue: + self = .sync + default: + assertionFailure() + self = .sync + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .add(time, type, peerId, data): + encoder.encodeInt32(SynchronizeAppLogEventsOperationContentType.add.rawValue, forKey: "r") + encoder.encodeDouble(time, forKey: "tm") + encoder.encodeString(type, forKey: "t") + if let peerId = peerId { + encoder.encodeInt64(peerId.toInt64(), forKey: "p") + } else { + encoder.encodeNil(forKey: "p") + } + encoder.encodeObject(data, forKey: "d") + case .sync: + encoder.encodeInt32(SynchronizeAppLogEventsOperationContentType.sync.rawValue, forKey: "r") + } + } +} + +public final class SynchronizeAppLogEventsOperation: PostboxCoding { + public let content: SynchronizeAppLogEventsOperationContent + + public init(content: SynchronizeAppLogEventsOperationContent) { + self.content = content + } + + public init(decoder: PostboxDecoder) { + self.content = decoder.decodeObjectForKey("c", decoder: { SynchronizeAppLogEventsOperationContent(decoder: $0) }) as! SynchronizeAppLogEventsOperationContent + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObject(self.content, forKey: "c") + } +} diff --git a/submodules/SyncCore/Sources/SynchronizeChatInputStateOperation.swift b/submodules/SyncCore/Sources/SynchronizeChatInputStateOperation.swift new file mode 100644 index 0000000000..04ddc11ef2 --- /dev/null +++ b/submodules/SyncCore/Sources/SynchronizeChatInputStateOperation.swift @@ -0,0 +1,21 @@ +import Postbox + +public final class SynchronizeChatInputStateOperation: PostboxCoding { + public let previousState: SynchronizeableChatInputState? + + public init(previousState: SynchronizeableChatInputState?) { + self.previousState = previousState + } + + public init(decoder: PostboxDecoder) { + self.previousState = decoder.decodeObjectForKey("p", decoder: { SynchronizeableChatInputState(decoder: $0) }) as? SynchronizeableChatInputState + } + + public func encode(_ encoder: PostboxEncoder) { + if let previousState = self.previousState { + encoder.encodeObject(previousState, forKey: "p") + } else { + encoder.encodeNil(forKey: "p") + } + } +} diff --git a/submodules/SyncCore/Sources/SynchronizeConsumeMessageContentsOperation.swift b/submodules/SyncCore/Sources/SynchronizeConsumeMessageContentsOperation.swift new file mode 100644 index 0000000000..6b9ff64194 --- /dev/null +++ b/submodules/SyncCore/Sources/SynchronizeConsumeMessageContentsOperation.swift @@ -0,0 +1,24 @@ +import Foundation +#if os(macOS) + import PostboxMac +#else + import Postbox +#endif + +public final class SynchronizeConsumeMessageContentsOperation: PostboxCoding { + public let messageIds: [MessageId] + + public init(messageIds: [MessageId]) { + self.messageIds = messageIds + } + + public init(decoder: PostboxDecoder) { + self.messageIds = MessageId.decodeArrayFromBuffer(decoder.decodeBytesForKeyNoCopy("i")!) + } + + public func encode(_ encoder: PostboxEncoder) { + let buffer = WriteBuffer() + MessageId.encodeArrayToBuffer(self.messageIds, buffer: buffer) + encoder.encodeBytes(buffer, forKey: "i") + } +} diff --git a/submodules/SyncCore/Sources/SynchronizeEmojiKeywordsOperation.swift b/submodules/SyncCore/Sources/SynchronizeEmojiKeywordsOperation.swift new file mode 100644 index 0000000000..a4b5cffd35 --- /dev/null +++ b/submodules/SyncCore/Sources/SynchronizeEmojiKeywordsOperation.swift @@ -0,0 +1,33 @@ +import Postbox + +public final class SynchronizeEmojiKeywordsOperation: PostboxCoding { + public let inputLanguageCode: String + public let languageCode: String? + public let fromVersion: Int32? + + public init(inputLanguageCode: String, languageCode: String?, fromVersion: Int32?) { + self.inputLanguageCode = inputLanguageCode + self.languageCode = languageCode + self.fromVersion = fromVersion + } + + public init(decoder: PostboxDecoder) { + self.inputLanguageCode = decoder.decodeStringForKey("ilc", orElse: "") + self.languageCode = decoder.decodeOptionalStringForKey("lc") + self.fromVersion = decoder.decodeOptionalInt32ForKey("v") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.inputLanguageCode, forKey: "ilc") + if let languageCode = self.languageCode { + encoder.encodeString(languageCode, forKey: "lc") + } else { + encoder.encodeNil(forKey: "lc") + } + if let fromVersion = self.fromVersion { + encoder.encodeInt32(fromVersion, forKey: "v") + } else { + encoder.encodeNil(forKey: "v") + } + } +} diff --git a/submodules/SyncCore/Sources/SynchronizeGroupedPeersOperation.swift b/submodules/SyncCore/Sources/SynchronizeGroupedPeersOperation.swift new file mode 100644 index 0000000000..fc4383cc1d --- /dev/null +++ b/submodules/SyncCore/Sources/SynchronizeGroupedPeersOperation.swift @@ -0,0 +1,21 @@ +import Postbox + +public final class SynchronizeGroupedPeersOperation: PostboxCoding { + public let peerId: PeerId + public let groupId: PeerGroupId + + public init(peerId: PeerId, groupId: PeerGroupId) { + self.peerId = peerId + self.groupId = groupId + } + + public init(decoder: PostboxDecoder) { + self.peerId = PeerId(decoder.decodeInt64ForKey("peerId", orElse: 0)) + self.groupId = PeerGroupId.init(rawValue: decoder.decodeInt32ForKey("groupId", orElse: 0)) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt64(self.peerId.toInt64(), forKey: "peerId") + encoder.encodeInt32(self.groupId.rawValue, forKey: "groupId") + } +} diff --git a/submodules/SyncCore/Sources/SynchronizeInstalledStickerPacksOperations.swift b/submodules/SyncCore/Sources/SynchronizeInstalledStickerPacksOperations.swift new file mode 100644 index 0000000000..75fd7f0613 --- /dev/null +++ b/submodules/SyncCore/Sources/SynchronizeInstalledStickerPacksOperations.swift @@ -0,0 +1,53 @@ +import Foundation +#if os(macOS) + import PostboxMac +#else + import Postbox +#endif + +public enum SynchronizeInstalledStickerPacksOperationNamespace: Int32 { + case stickers = 0 + case masks = 1 +} + +public final class SynchronizeInstalledStickerPacksOperation: PostboxCoding { + public let previousPacks: [ItemCollectionId] + public let archivedPacks: [ItemCollectionId] + + public init(previousPacks: [ItemCollectionId], archivedPacks: [ItemCollectionId]) { + self.previousPacks = previousPacks + self.archivedPacks = archivedPacks + } + + public init(decoder: PostboxDecoder) { + self.previousPacks = ItemCollectionId.decodeArrayFromBuffer(decoder.decodeBytesForKey("p")!) + self.archivedPacks = decoder.decodeBytesForKey("ap").flatMap(ItemCollectionId.decodeArrayFromBuffer) ?? [] + } + + public func encode(_ encoder: PostboxEncoder) { + let buffer = WriteBuffer() + ItemCollectionId.encodeArrayToBuffer(self.previousPacks, buffer: buffer) + encoder.encodeBytes(buffer, forKey: "p") + buffer.reset() + ItemCollectionId.encodeArrayToBuffer(self.archivedPacks, buffer: buffer) + encoder.encodeBytes(buffer, forKey: "ap") + } +} + +public final class SynchronizeMarkFeaturedStickerPacksAsSeenOperation: PostboxCoding { + public let ids: [ItemCollectionId] + + public init(ids: [ItemCollectionId]) { + self.ids = ids + } + + public init(decoder: PostboxDecoder) { + self.ids = ItemCollectionId.decodeArrayFromBuffer(decoder.decodeBytesForKey("p")!) + } + + public func encode(_ encoder: PostboxEncoder) { + let buffer = WriteBuffer() + ItemCollectionId.encodeArrayToBuffer(self.ids, buffer: buffer) + encoder.encodeBytes(buffer, forKey: "p") + } +} diff --git a/submodules/SyncCore/Sources/SynchronizeMarkAllUnseenPersonalMessagesOperation.swift b/submodules/SyncCore/Sources/SynchronizeMarkAllUnseenPersonalMessagesOperation.swift new file mode 100644 index 0000000000..bf8d597443 --- /dev/null +++ b/submodules/SyncCore/Sources/SynchronizeMarkAllUnseenPersonalMessagesOperation.swift @@ -0,0 +1,17 @@ +import Postbox + +public final class SynchronizeMarkAllUnseenPersonalMessagesOperation: PostboxCoding { + public let maxId: MessageId.Id + + public init(maxId: MessageId.Id) { + self.maxId = maxId + } + + public init(decoder: PostboxDecoder) { + self.maxId = decoder.decodeInt32ForKey("maxId", orElse: Int32.min + 1) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.maxId, forKey: "maxId") + } +} diff --git a/submodules/TelegramCore/TelegramCore/SynchronizePinnedChatsOperation.swift b/submodules/SyncCore/Sources/SynchronizePinnedChatsOperation.swift similarity index 79% rename from submodules/TelegramCore/TelegramCore/SynchronizePinnedChatsOperation.swift rename to submodules/SyncCore/Sources/SynchronizePinnedChatsOperation.swift index e13339665f..d579c8ead6 100644 --- a/submodules/TelegramCore/TelegramCore/SynchronizePinnedChatsOperation.swift +++ b/submodules/SyncCore/Sources/SynchronizePinnedChatsOperation.swift @@ -6,13 +6,13 @@ import Foundation #endif private struct PreviousPeerItemId: PostboxCoding { - let id: PinnedItemId + public let id: PinnedItemId - init(_ id: PinnedItemId) { + public init(_ id: PinnedItemId) { self.id = id } - init(decoder: PostboxDecoder) { + public init(decoder: PostboxDecoder) { switch decoder.decodeInt32ForKey("_t", orElse: 0) { case 0: self.id = .peer(PeerId(decoder.decodeInt64ForKey("i", orElse: 0))) @@ -21,7 +21,7 @@ private struct PreviousPeerItemId: PostboxCoding { } } - func encode(_ encoder: PostboxEncoder) { + public func encode(_ encoder: PostboxEncoder) { switch self.id { case let .peer(peerId): encoder.encodeInt32(0, forKey: "_t") @@ -30,24 +30,24 @@ private struct PreviousPeerItemId: PostboxCoding { } } -final class SynchronizePinnedChatsOperation: PostboxCoding { - let previousItemIds: [PinnedItemId] +public final class SynchronizePinnedChatsOperation: PostboxCoding { + public let previousItemIds: [PinnedItemId] - init(previousItemIds: [PinnedItemId]) { + public init(previousItemIds: [PinnedItemId]) { self.previousItemIds = previousItemIds } - init(decoder: PostboxDecoder) { + public init(decoder: PostboxDecoder) { let wrappedIds: [PreviousPeerItemId] = decoder.decodeObjectArrayWithDecoderForKey("previousItemIds") self.previousItemIds = wrappedIds.map { $0.id } } - func encode(_ encoder: PostboxEncoder) { + public func encode(_ encoder: PostboxEncoder) { encoder.encodeObjectArray(self.previousItemIds.map(PreviousPeerItemId.init), forKey: "previousItemIds") } } -func addSynchronizePinnedChatsOperation(transaction: Transaction, groupId: PeerGroupId) { +public func addSynchronizePinnedChatsOperation(transaction: Transaction, groupId: PeerGroupId) { let rawId: Int32 = groupId.rawValue var previousItemIds = transaction.getPinnedItemIds(groupId: groupId) var updateLocalIndex: Int32? diff --git a/submodules/SyncCore/Sources/SynchronizeRecentlyUsedMediaOperation.swift b/submodules/SyncCore/Sources/SynchronizeRecentlyUsedMediaOperation.swift new file mode 100644 index 0000000000..25bd3a6e56 --- /dev/null +++ b/submodules/SyncCore/Sources/SynchronizeRecentlyUsedMediaOperation.swift @@ -0,0 +1,69 @@ +import Postbox + +private enum SynchronizeRecentlyUsedMediaOperationContentType: Int32 { + case add + case remove + case clear + case sync +} + +public enum SynchronizeRecentlyUsedMediaOperationContent: PostboxCoding { + case add(id: Int64, accessHash: Int64, fileReference: FileMediaReference?) + case remove(id: Int64, accessHash: Int64) + case clear + case sync + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("r", orElse: 0) { + case SynchronizeRecentlyUsedMediaOperationContentType.add.rawValue: + self = .add(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0), fileReference: decoder.decodeAnyObjectForKey("fr", decoder: { FileMediaReference(decoder: $0) }) as? FileMediaReference) + case SynchronizeRecentlyUsedMediaOperationContentType.remove.rawValue: + self = .remove(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0)) + case SynchronizeRecentlyUsedMediaOperationContentType.clear.rawValue: + self = .clear + case SynchronizeRecentlyUsedMediaOperationContentType.sync.rawValue: + self = .sync + default: + assertionFailure() + self = .sync + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .add(id, accessHash, fileReference): + encoder.encodeInt32(SynchronizeRecentlyUsedMediaOperationContentType.add.rawValue, forKey: "r") + encoder.encodeInt64(id, forKey: "i") + encoder.encodeInt64(accessHash, forKey: "h") + if let fileReference = fileReference { + encoder.encodeObjectWithEncoder(fileReference, encoder: fileReference.encode, forKey: "fr") + } else { + encoder.encodeNil(forKey: "fr") + } + case let .remove(id, accessHash): + encoder.encodeInt32(SynchronizeRecentlyUsedMediaOperationContentType.remove.rawValue, forKey: "r") + encoder.encodeInt64(id, forKey: "i") + encoder.encodeInt64(accessHash, forKey: "h") + case .clear: + encoder.encodeInt32(SynchronizeRecentlyUsedMediaOperationContentType.clear.rawValue, forKey: "r") + case .sync: + encoder.encodeInt32(SynchronizeRecentlyUsedMediaOperationContentType.sync.rawValue, forKey: "r") + } + } +} + +public final class SynchronizeRecentlyUsedMediaOperation: PostboxCoding { + public let content: SynchronizeRecentlyUsedMediaOperationContent + + public init(content: SynchronizeRecentlyUsedMediaOperationContent) { + self.content = content + } + + public init(decoder: PostboxDecoder) { + self.content = decoder.decodeObjectForKey("c", decoder: { SynchronizeRecentlyUsedMediaOperationContent(decoder: $0) }) as! SynchronizeRecentlyUsedMediaOperationContent + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObject(self.content, forKey: "c") + } +} diff --git a/submodules/SyncCore/Sources/SynchronizeSavedGifsOperation.swift b/submodules/SyncCore/Sources/SynchronizeSavedGifsOperation.swift new file mode 100644 index 0000000000..7b960572be --- /dev/null +++ b/submodules/SyncCore/Sources/SynchronizeSavedGifsOperation.swift @@ -0,0 +1,63 @@ +import Postbox + +private enum SynchronizeSavedGifsOperationContentType: Int32 { + case add + case remove + case sync +} + +public enum SynchronizeSavedGifsOperationContent: PostboxCoding { + case add(id: Int64, accessHash: Int64, fileReference: FileMediaReference?) + case remove(id: Int64, accessHash: Int64) + case sync + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("r", orElse: 0) { + case SynchronizeSavedGifsOperationContentType.add.rawValue: + self = .add(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0), fileReference: decoder.decodeAnyObjectForKey("fr", decoder: { FileMediaReference(decoder: $0) }) as? FileMediaReference) + case SynchronizeSavedGifsOperationContentType.remove.rawValue: + self = .remove(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0)) + case SynchronizeSavedGifsOperationContentType.sync.rawValue: + self = .sync + default: + assertionFailure() + self = .sync + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .add(id, accessHash, fileReference): + encoder.encodeInt32(SynchronizeSavedGifsOperationContentType.add.rawValue, forKey: "r") + encoder.encodeInt64(id, forKey: "i") + encoder.encodeInt64(accessHash, forKey: "h") + if let fileReference = fileReference { + encoder.encodeObjectWithEncoder(fileReference, encoder: fileReference.encode, forKey: "fr") + } else { + encoder.encodeNil(forKey: "fr") + } + case let .remove(id, accessHash): + encoder.encodeInt32(SynchronizeSavedGifsOperationContentType.remove.rawValue, forKey: "r") + encoder.encodeInt64(id, forKey: "i") + encoder.encodeInt64(accessHash, forKey: "h") + case .sync: + encoder.encodeInt32(SynchronizeSavedGifsOperationContentType.sync.rawValue, forKey: "r") + } + } +} + +public final class SynchronizeSavedGifsOperation: PostboxCoding { + public let content: SynchronizeSavedGifsOperationContent + + public init(content: SynchronizeSavedGifsOperationContent) { + self.content = content + } + + public init(decoder: PostboxDecoder) { + self.content = decoder.decodeObjectForKey("c", decoder: { SynchronizeSavedGifsOperationContent(decoder: $0) }) as! SynchronizeSavedGifsOperationContent + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObject(self.content, forKey: "c") + } +} diff --git a/submodules/SyncCore/Sources/SynchronizeSavedStickersOperation.swift b/submodules/SyncCore/Sources/SynchronizeSavedStickersOperation.swift new file mode 100644 index 0000000000..c7a1af95b0 --- /dev/null +++ b/submodules/SyncCore/Sources/SynchronizeSavedStickersOperation.swift @@ -0,0 +1,63 @@ +import Postbox + +private enum SynchronizeSavedStickersOperationContentType: Int32 { + case add + case remove + case sync +} + +public enum SynchronizeSavedStickersOperationContent: PostboxCoding { + case add(id: Int64, accessHash: Int64, fileReference: FileMediaReference?) + case remove(id: Int64, accessHash: Int64) + case sync + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("r", orElse: 0) { + case SynchronizeSavedStickersOperationContentType.add.rawValue: + self = .add(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0), fileReference: decoder.decodeAnyObjectForKey("fr", decoder: { FileMediaReference(decoder: $0) }) as? FileMediaReference) + case SynchronizeSavedStickersOperationContentType.remove.rawValue: + self = .remove(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0)) + case SynchronizeSavedStickersOperationContentType.sync.rawValue: + self = .sync + default: + assertionFailure() + self = .sync + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .add(id, accessHash, fileReference): + encoder.encodeInt32(SynchronizeSavedStickersOperationContentType.add.rawValue, forKey: "r") + encoder.encodeInt64(id, forKey: "i") + encoder.encodeInt64(accessHash, forKey: "h") + if let fileReference = fileReference { + encoder.encodeObjectWithEncoder(fileReference, encoder: fileReference.encode, forKey: "fr") + } else { + encoder.encodeNil(forKey: "fr") + } + case let .remove(id, accessHash): + encoder.encodeInt32(SynchronizeSavedStickersOperationContentType.remove.rawValue, forKey: "r") + encoder.encodeInt64(id, forKey: "i") + encoder.encodeInt64(accessHash, forKey: "h") + case .sync: + encoder.encodeInt32(SynchronizeSavedStickersOperationContentType.sync.rawValue, forKey: "r") + } + } +} + +public final class SynchronizeSavedStickersOperation: PostboxCoding { + public let content: SynchronizeSavedStickersOperationContent + + public init(content: SynchronizeSavedStickersOperationContent) { + self.content = content + } + + public init(decoder: PostboxDecoder) { + self.content = decoder.decodeObjectForKey("c", decoder: { SynchronizeSavedStickersOperationContent(decoder: $0) }) as! SynchronizeSavedStickersOperationContent + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObject(self.content, forKey: "c") + } +} diff --git a/submodules/TelegramCore/TelegramCore/SynchronizeableChatInputState.swift b/submodules/SyncCore/Sources/SynchronizeableChatInputState.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/SynchronizeableChatInputState.swift rename to submodules/SyncCore/Sources/SynchronizeableChatInputState.swift diff --git a/submodules/SyncCore/Sources/TelegramChannel.swift b/submodules/SyncCore/Sources/TelegramChannel.swift new file mode 100644 index 0000000000..b252e3d24d --- /dev/null +++ b/submodules/SyncCore/Sources/TelegramChannel.swift @@ -0,0 +1,300 @@ +import Postbox + +public enum TelegramChannelParticipationStatus { + case member + case left + case kicked + + fileprivate var rawValue: Int32 { + switch self { + case .member: + return 0 + case .left: + return 1 + case .kicked: + return 2 + } + } + + fileprivate init(rawValue: Int32) { + switch rawValue { + case 0: + self = .member + case 1: + self = .left + case 2: + self = .kicked + default: + self = .left + } + } +} + +public struct TelegramChannelBroadcastFlags: OptionSet { + public var rawValue: Int32 + + public init() { + self.rawValue = 0 + } + + public init(rawValue: Int32) { + self.rawValue = rawValue + } + + public static let messagesShouldHaveSignatures = TelegramChannelBroadcastFlags(rawValue: 1 << 0) + public static let hasDiscussionGroup = TelegramChannelBroadcastFlags(rawValue: 1 << 1) + +} + +public struct TelegramChannelBroadcastInfo: Equatable { + public let flags: TelegramChannelBroadcastFlags + public init(flags: TelegramChannelBroadcastFlags) { + self.flags = flags + } + + public static func ==(lhs: TelegramChannelBroadcastInfo, rhs: TelegramChannelBroadcastInfo) -> Bool { + return lhs.flags == rhs.flags + } +} + +public struct TelegramChannelGroupFlags: OptionSet { + public var rawValue: Int32 + + public init() { + self.rawValue = 0 + } + + public init(rawValue: Int32) { + self.rawValue = rawValue + } + public static let slowModeEnabled = TelegramChannelGroupFlags(rawValue: 1 << 0) +} + +public struct TelegramChannelGroupInfo: Equatable { + public let flags: TelegramChannelGroupFlags + + public init(flags: TelegramChannelGroupFlags) { + self.flags = flags + } + + public static func ==(lhs: TelegramChannelGroupInfo, rhs: TelegramChannelGroupInfo) -> Bool { + return lhs.flags == rhs.flags + } +} + +public enum TelegramChannelInfo: Equatable { + case broadcast(TelegramChannelBroadcastInfo) + case group(TelegramChannelGroupInfo) + + public static func ==(lhs: TelegramChannelInfo, rhs: TelegramChannelInfo) -> Bool { + switch lhs { + case let .broadcast(lhsInfo): + switch rhs { + case .broadcast(lhsInfo): + return true + default: + return false + } + case let .group(lhsInfo): + switch rhs { + case .group(lhsInfo): + return true + default: + return false + } + } + } + + fileprivate func encode(encoder: PostboxEncoder) { + switch self { + case let .broadcast(info): + encoder.encodeInt32(0, forKey: "i.t") + encoder.encodeInt32(info.flags.rawValue, forKey: "i.f") + case let .group(info): + encoder.encodeInt32(1, forKey: "i.t") + encoder.encodeInt32(info.flags.rawValue, forKey: "i.f") + } + } + + fileprivate static func decode(decoder: PostboxDecoder) -> TelegramChannelInfo { + let type: Int32 = decoder.decodeInt32ForKey("i.t", orElse: 0) + if type == 0 { + return .broadcast(TelegramChannelBroadcastInfo(flags: TelegramChannelBroadcastFlags(rawValue: decoder.decodeInt32ForKey("i.f", orElse: 0)))) + } else { + return .group(TelegramChannelGroupInfo(flags: TelegramChannelGroupFlags(rawValue: decoder.decodeInt32ForKey("i.f", orElse: 0)))) + } + } +} + +public struct TelegramChannelFlags: OptionSet { + public var rawValue: Int32 + + public init() { + self.rawValue = 0 + } + + public init(rawValue: Int32) { + self.rawValue = rawValue + } + + public static let isVerified = TelegramChannelFlags(rawValue: 1 << 0) + public static let isCreator = TelegramChannelFlags(rawValue: 1 << 1) + public static let isScam = TelegramChannelFlags(rawValue: 1 << 2) + public static let hasGeo = TelegramChannelFlags(rawValue: 1 << 3) +} + +public final class TelegramChannel: Peer { + public let id: PeerId + public let accessHash: TelegramPeerAccessHash? + public let title: String + public let username: String? + public let photo: [TelegramMediaImageRepresentation] + public let creationDate: Int32 + public let version: Int32 + public let participationStatus: TelegramChannelParticipationStatus + public let info: TelegramChannelInfo + public let flags: TelegramChannelFlags + public let restrictionInfo: PeerAccessRestrictionInfo? + public let adminRights: TelegramChatAdminRights? + public let bannedRights: TelegramChatBannedRights? + public let defaultBannedRights: TelegramChatBannedRights? + + public var indexName: PeerIndexNameRepresentation { + return .title(title: self.title, addressName: self.username) + } + + public let associatedPeerId: PeerId? = nil + public let notificationSettingsPeerId: PeerId? = nil + + public init(id: PeerId, accessHash: TelegramPeerAccessHash?, title: String, username: String?, photo: [TelegramMediaImageRepresentation], creationDate: Int32, version: Int32, participationStatus: TelegramChannelParticipationStatus, info: TelegramChannelInfo, flags: TelegramChannelFlags, restrictionInfo: PeerAccessRestrictionInfo?, adminRights: TelegramChatAdminRights?, bannedRights: TelegramChatBannedRights?, defaultBannedRights: TelegramChatBannedRights?) { + self.id = id + self.accessHash = accessHash + self.title = title + self.username = username + self.photo = photo + self.creationDate = creationDate + self.version = version + self.participationStatus = participationStatus + self.info = info + self.flags = flags + self.restrictionInfo = restrictionInfo + self.adminRights = adminRights + self.bannedRights = bannedRights + self.defaultBannedRights = defaultBannedRights + } + + public init(decoder: PostboxDecoder) { + self.id = PeerId(decoder.decodeInt64ForKey("i", orElse: 0)) + let accessHash = decoder.decodeOptionalInt64ForKey("ah") + let accessHashType: Int32 = decoder.decodeInt32ForKey("aht", orElse: 0) + if let accessHash = accessHash { + if accessHashType == 0 { + self.accessHash = .personal(accessHash) + } else { + self.accessHash = .genericPublic(accessHash) + } + } else { + self.accessHash = nil + } + self.title = decoder.decodeStringForKey("t", orElse: "") + self.username = decoder.decodeOptionalStringForKey("un") + self.photo = decoder.decodeObjectArrayForKey("ph") + self.creationDate = decoder.decodeInt32ForKey("d", orElse: 0) + self.version = decoder.decodeInt32ForKey("v", orElse: 0) + self.participationStatus = TelegramChannelParticipationStatus(rawValue: decoder.decodeInt32ForKey("ps", orElse: 0)) + self.info = TelegramChannelInfo.decode(decoder: decoder) + self.flags = TelegramChannelFlags(rawValue: decoder.decodeInt32ForKey("fl", orElse: 0)) + self.restrictionInfo = decoder.decodeObjectForKey("ri") as? PeerAccessRestrictionInfo + self.adminRights = decoder.decodeObjectForKey("ar", decoder: { TelegramChatAdminRights(decoder: $0) }) as? TelegramChatAdminRights + self.bannedRights = decoder.decodeObjectForKey("br", decoder: { TelegramChatBannedRights(decoder: $0) }) as? TelegramChatBannedRights + self.defaultBannedRights = decoder.decodeObjectForKey("dbr", decoder: { TelegramChatBannedRights(decoder: $0) }) as? TelegramChatBannedRights + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt64(self.id.toInt64(), forKey: "i") + if let accessHash = self.accessHash { + switch accessHash { + case let .personal(value): + encoder.encodeInt64(value, forKey: "ah") + encoder.encodeInt32(0, forKey: "aht") + case let .genericPublic(value): + encoder.encodeInt64(value, forKey: "ah") + encoder.encodeInt32(1, forKey: "aht") + } + } else { + encoder.encodeNil(forKey: "ah") + } + encoder.encodeString(self.title, forKey: "t") + if let username = self.username { + encoder.encodeString(username, forKey: "un") + } else { + encoder.encodeNil(forKey: "un") + } + encoder.encodeObjectArray(self.photo, forKey: "ph") + encoder.encodeInt32(self.creationDate, forKey: "d") + encoder.encodeInt32(self.version, forKey: "v") + encoder.encodeInt32(self.participationStatus.rawValue, forKey: "ps") + self.info.encode(encoder: encoder) + encoder.encodeInt32(self.flags.rawValue, forKey: "fl") + if let restrictionInfo = self.restrictionInfo { + encoder.encodeObject(restrictionInfo, forKey: "ri") + } else { + encoder.encodeNil(forKey: "ri") + } + if let adminRights = self.adminRights { + encoder.encodeObject(adminRights, forKey: "ar") + } else { + encoder.encodeNil(forKey: "ar") + } + if let bannedRights = self.bannedRights { + encoder.encodeObject(bannedRights, forKey: "br") + } else { + encoder.encodeNil(forKey: "br") + } + if let defaultBannedRights = self.defaultBannedRights { + encoder.encodeObject(defaultBannedRights, forKey: "dbr") + } else { + encoder.encodeNil(forKey: "dbr") + } + } + + public func isEqual(_ other: Peer) -> Bool { + guard let other = other as? TelegramChannel else { + return false + } + + if self.id != other.id || self.accessHash != other.accessHash || self.title != other.title || self.username != other.username || self.photo != other.photo { + return false + } + + if self.creationDate != other.creationDate || self.version != other.version || self.participationStatus != other.participationStatus { + return false + } + + if self.info != other.info || self.flags != other.flags || self.restrictionInfo != other.restrictionInfo { + return false + } + + if self.adminRights != other.adminRights { + return false + } + + if self.bannedRights != other.bannedRights { + return false + } + + if self.defaultBannedRights != other.defaultBannedRights { + return false + } + + return true + } + + public func withUpdatedAddressName(_ addressName: String?) -> TelegramChannel { + return TelegramChannel(id: self.id, accessHash: self.accessHash, title: self.title, username: addressName, photo: self.photo, creationDate: self.creationDate, version: self.version, participationStatus: self.participationStatus, info: self.info, flags: self.flags, restrictionInfo: self.restrictionInfo, adminRights: self.adminRights, bannedRights: self.bannedRights, defaultBannedRights: self.defaultBannedRights) + } + + public func withUpdatedDefaultBannedRights(_ defaultBannedRights: TelegramChatBannedRights?) -> TelegramChannel { + return TelegramChannel(id: self.id, accessHash: self.accessHash, title: self.title, username: self.username, photo: self.photo, creationDate: self.creationDate, version: self.version, participationStatus: self.participationStatus, info: self.info, flags: self.flags, restrictionInfo: self.restrictionInfo, adminRights: self.adminRights, bannedRights: self.bannedRights, defaultBannedRights: defaultBannedRights) + } +} diff --git a/submodules/SyncCore/Sources/TelegramChatAdminRights.swift b/submodules/SyncCore/Sources/TelegramChatAdminRights.swift new file mode 100644 index 0000000000..86abc3ec9f --- /dev/null +++ b/submodules/SyncCore/Sources/TelegramChatAdminRights.swift @@ -0,0 +1,81 @@ +import Postbox + +public struct TelegramChatAdminRightsFlags: OptionSet { + public var rawValue: Int32 + + public init(rawValue: Int32) { + self.rawValue = rawValue + } + + public init() { + self.rawValue = 0 + } + + public static let canChangeInfo = TelegramChatAdminRightsFlags(rawValue: 1 << 0) + public static let canPostMessages = TelegramChatAdminRightsFlags(rawValue: 1 << 1) + public static let canEditMessages = TelegramChatAdminRightsFlags(rawValue: 1 << 2) + public static let canDeleteMessages = TelegramChatAdminRightsFlags(rawValue: 1 << 3) + public static let canBanUsers = TelegramChatAdminRightsFlags(rawValue: 1 << 4) + public static let canInviteUsers = TelegramChatAdminRightsFlags(rawValue: 1 << 5) + public static let canPinMessages = TelegramChatAdminRightsFlags(rawValue: 1 << 7) + public static let canAddAdmins = TelegramChatAdminRightsFlags(rawValue: 1 << 9) + + public static var groupSpecific: TelegramChatAdminRightsFlags = [ + .canChangeInfo, + .canDeleteMessages, + .canBanUsers, + .canInviteUsers, + .canPinMessages, + .canAddAdmins + ] + + public static var broadcastSpecific: TelegramChatAdminRightsFlags = [ + .canChangeInfo, + .canPostMessages, + .canEditMessages, + .canDeleteMessages, + .canInviteUsers, + .canAddAdmins + ] + + public var count: Int { + var result = 0 + var index = 0 + while index < 31 { + let currentValue = self.rawValue >> Int32(index) + index += 1 + if currentValue == 0 { + break + } + + if (currentValue & 1) != 0 { + result += 1 + } + } + return result + } +} + +public struct TelegramChatAdminRights: PostboxCoding, Equatable { + public let flags: TelegramChatAdminRightsFlags + + public init(flags: TelegramChatAdminRightsFlags) { + self.flags = flags + } + + public init(decoder: PostboxDecoder) { + self.flags = TelegramChatAdminRightsFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0)) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.flags.rawValue, forKey: "f") + } + + public static func ==(lhs: TelegramChatAdminRights, rhs: TelegramChatAdminRights) -> Bool { + return lhs.flags == rhs.flags + } + + public var isEmpty: Bool { + return self.flags.isEmpty + } +} diff --git a/submodules/SyncCore/Sources/TelegramChatBannedRights.swift b/submodules/SyncCore/Sources/TelegramChatBannedRights.swift new file mode 100644 index 0000000000..ef804d8858 --- /dev/null +++ b/submodules/SyncCore/Sources/TelegramChatBannedRights.swift @@ -0,0 +1,50 @@ +import Postbox + +public struct TelegramChatBannedRightsFlags: OptionSet { + public var rawValue: Int32 + + public init(rawValue: Int32) { + self.rawValue = rawValue + } + + public init() { + self.rawValue = 0 + } + + public static let banReadMessages = TelegramChatBannedRightsFlags(rawValue: 1 << 0) + public static let banSendMessages = TelegramChatBannedRightsFlags(rawValue: 1 << 1) + public static let banSendMedia = TelegramChatBannedRightsFlags(rawValue: 1 << 2) + public static let banSendStickers = TelegramChatBannedRightsFlags(rawValue: 1 << 3) + public static let banSendGifs = TelegramChatBannedRightsFlags(rawValue: 1 << 4) + public static let banSendGames = TelegramChatBannedRightsFlags(rawValue: 1 << 5) + public static let banSendInline = TelegramChatBannedRightsFlags(rawValue: 1 << 6) + public static let banEmbedLinks = TelegramChatBannedRightsFlags(rawValue: 1 << 7) + public static let banSendPolls = TelegramChatBannedRightsFlags(rawValue: 1 << 8) + public static let banChangeInfo = TelegramChatBannedRightsFlags(rawValue: 1 << 10) + public static let banAddMembers = TelegramChatBannedRightsFlags(rawValue: 1 << 15) + public static let banPinMessages = TelegramChatBannedRightsFlags(rawValue: 1 << 17) +} + +public struct TelegramChatBannedRights: PostboxCoding, Equatable { + public let flags: TelegramChatBannedRightsFlags + public let untilDate: Int32 + + public init(flags: TelegramChatBannedRightsFlags, untilDate: Int32) { + self.flags = flags + self.untilDate = untilDate + } + + public init(decoder: PostboxDecoder) { + self.flags = TelegramChatBannedRightsFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0)) + self.untilDate = decoder.decodeInt32ForKey("d", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.flags.rawValue, forKey: "f") + encoder.encodeInt32(self.untilDate, forKey: "d") + } + + public static func ==(lhs: TelegramChatBannedRights, rhs: TelegramChatBannedRights) -> Bool { + return lhs.flags == rhs.flags && lhs.untilDate == rhs.untilDate + } +} diff --git a/submodules/SyncCore/Sources/TelegramDeviceContactImportedData.swift b/submodules/SyncCore/Sources/TelegramDeviceContactImportedData.swift new file mode 100644 index 0000000000..c95e2b9e0a --- /dev/null +++ b/submodules/SyncCore/Sources/TelegramDeviceContactImportedData.swift @@ -0,0 +1,29 @@ +import Postbox + +public enum TelegramDeviceContactImportedData: PostboxCoding { + case imported(data: ImportableDeviceContactData, importedByCount: Int32) + case retryLater + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("_t", orElse: 0) { + case 0: + self = .imported(data: decoder.decodeObjectForKey("d", decoder: { ImportableDeviceContactData(decoder: $0) }) as! ImportableDeviceContactData, importedByCount: decoder.decodeInt32ForKey("c", orElse: 0)) + case 1: + self = .retryLater + default: + assertionFailure() + self = .retryLater + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .imported(data, importedByCount): + encoder.encodeInt32(0, forKey: "_t") + encoder.encodeObject(data, forKey: "d") + encoder.encodeInt32(importedByCount, forKey: "c") + case .retryLater: + encoder.encodeInt32(1, forKey: "_t") + } + } +} diff --git a/submodules/SyncCore/Sources/TelegramGroup.swift b/submodules/SyncCore/Sources/TelegramGroup.swift new file mode 100644 index 0000000000..3a3cd1bb3b --- /dev/null +++ b/submodules/SyncCore/Sources/TelegramGroup.swift @@ -0,0 +1,206 @@ +import Postbox + +public enum TelegramGroupRole: Equatable, PostboxCoding { + case creator(rank: String?) + case admin(TelegramChatAdminRights, rank: String?) + case member + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("_v", orElse: 0) { + case 0: + self = .creator(rank: decoder.decodeOptionalStringForKey("rank")) + case 1: + self = .admin(decoder.decodeObjectForKey("r", decoder: { TelegramChatAdminRights(decoder: $0) }) as! TelegramChatAdminRights, rank: decoder.decodeOptionalStringForKey("rank")) + case 2: + self = .member + default: + assertionFailure() + self = .member + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .creator(rank): + encoder.encodeInt32(0, forKey: "_v") + if let rank = rank { + encoder.encodeString(rank, forKey: "rank") + } else { + encoder.encodeNil(forKey: "rank") + } + case let .admin(rights, rank): + encoder.encodeInt32(1, forKey: "_v") + encoder.encodeObject(rights, forKey: "r") + if let rank = rank { + encoder.encodeString(rank, forKey: "rank") + } else { + encoder.encodeNil(forKey: "rank") + } + case .member: + encoder.encodeInt32(2, forKey: "_v") + } + } +} + +public enum TelegramGroupMembership: Int32 { + case Member + case Left + case Removed +} + +public struct TelegramGroupFlags: OptionSet { + public var rawValue: Int32 + + public init() { + self.rawValue = 0 + } + + public init(rawValue: Int32) { + self.rawValue = rawValue + } + + public static let deactivated = TelegramGroupFlags(rawValue: 1 << 1) +} + +public struct TelegramGroupToChannelMigrationReference: Equatable { + public let peerId: PeerId + public let accessHash: Int64 + + public init(peerId: PeerId, accessHash: Int64) { + self.peerId = peerId + self.accessHash = accessHash + } +} + +public final class TelegramGroup: Peer { + public let id: PeerId + public let title: String + public let photo: [TelegramMediaImageRepresentation] + public let participantCount: Int + public let role: TelegramGroupRole + public let membership: TelegramGroupMembership + public let flags: TelegramGroupFlags + public let defaultBannedRights: TelegramChatBannedRights? + public let migrationReference: TelegramGroupToChannelMigrationReference? + public let creationDate: Int32 + public let version: Int + + public var indexName: PeerIndexNameRepresentation { + return .title(title: self.title, addressName: nil) + } + + public let associatedPeerId: PeerId? = nil + public let notificationSettingsPeerId: PeerId? = nil + + public init(id: PeerId, title: String, photo: [TelegramMediaImageRepresentation], participantCount: Int, role: TelegramGroupRole, membership: TelegramGroupMembership, flags: TelegramGroupFlags, defaultBannedRights: TelegramChatBannedRights?, migrationReference: TelegramGroupToChannelMigrationReference?, creationDate: Int32, version: Int) { + self.id = id + self.title = title + self.photo = photo + self.participantCount = participantCount + self.role = role + self.membership = membership + self.flags = flags + self.defaultBannedRights = defaultBannedRights + self.migrationReference = migrationReference + self.creationDate = creationDate + self.version = version + } + + public init(decoder: PostboxDecoder) { + self.id = PeerId(decoder.decodeInt64ForKey("i", orElse: 0)) + self.title = decoder.decodeStringForKey("t", orElse: "") + self.photo = decoder.decodeObjectArrayForKey("ph") + self.participantCount = Int(decoder.decodeInt32ForKey("pc", orElse: 0)) + if let role = decoder.decodeObjectForKey("rv", decoder: { TelegramGroupRole(decoder: $0) }) as? TelegramGroupRole { + self.role = role + } else if let roleValue = decoder.decodeOptionalInt32ForKey("r"), roleValue == 0 { + self.role = .creator(rank: nil) + } else { + self.role = .member + } + self.membership = TelegramGroupMembership(rawValue: decoder.decodeInt32ForKey("m", orElse: 0))! + self.flags = TelegramGroupFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0)) + self.defaultBannedRights = decoder.decodeObjectForKey("dbr", decoder: { TelegramChatBannedRights(decoder: $0) }) as? TelegramChatBannedRights + let migrationPeerId: Int64? = decoder.decodeOptionalInt64ForKey("mr.i") + let migrationAccessHash: Int64? = decoder.decodeOptionalInt64ForKey("mr.a") + if let migrationPeerId = migrationPeerId, let migrationAccessHash = migrationAccessHash { + self.migrationReference = TelegramGroupToChannelMigrationReference(peerId: PeerId(migrationPeerId), accessHash: migrationAccessHash) + } else { + self.migrationReference = nil + } + self.creationDate = decoder.decodeInt32ForKey("d", orElse: 0) + self.version = Int(decoder.decodeInt32ForKey("v", orElse: 0)) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt64(self.id.toInt64(), forKey: "i") + encoder.encodeString(self.title, forKey: "t") + encoder.encodeObjectArray(self.photo, forKey: "ph") + encoder.encodeInt32(Int32(self.participantCount), forKey: "pc") + encoder.encodeObject(self.role, forKey: "rv") + encoder.encodeInt32(self.membership.rawValue, forKey: "m") + if let defaultBannedRights = self.defaultBannedRights { + encoder.encodeObject(defaultBannedRights, forKey: "dbr") + } else { + encoder.encodeNil(forKey: "dbr") + } + if let migrationReference = self.migrationReference { + encoder.encodeInt64(migrationReference.peerId.toInt64(), forKey: "mr.i") + encoder.encodeInt64(migrationReference.accessHash, forKey: "mr.a") + } else { + encoder.encodeNil(forKey: "mr.i") + encoder.encodeNil(forKey: "mr.a") + } + encoder.encodeInt32(self.creationDate, forKey: "d") + encoder.encodeInt32(Int32(self.version), forKey: "v") + } + + public func isEqual(_ other: Peer) -> Bool { + if let other = other as? TelegramGroup { + if self.id != other.id { + return false + } + if self.title != other.title { + return false + } + if self.photo != other.photo { + return false + } + if self.membership != other.membership { + return false + } + if self.version != other.version { + return false + } + if self.participantCount != other.participantCount { + return false + } + if self.role != other.role { + return false + } + if self.defaultBannedRights != other.defaultBannedRights { + return false + } + if self.migrationReference != other.migrationReference { + return false + } + if self.creationDate != other.creationDate { + return false + } + if self.flags != other.flags { + return false + } + return true + } else { + return false + } + } + + public func updateFlags(flags: TelegramGroupFlags, version: Int) -> TelegramGroup { + return TelegramGroup(id: self.id, title: self.title, photo: self.photo, participantCount: self.participantCount, role: self.role, membership: self.membership, flags: flags, defaultBannedRights: self.defaultBannedRights, migrationReference: self.migrationReference, creationDate: self.creationDate, version: version) + } + + public func updateDefaultBannedRights(_ defaultBannedRights: TelegramChatBannedRights?, version: Int) -> TelegramGroup { + return TelegramGroup(id: self.id, title: self.title, photo: self.photo, participantCount: self.participantCount, role: self.role, membership: self.membership, flags: self.flags, defaultBannedRights: defaultBannedRights, migrationReference: self.migrationReference, creationDate: self.creationDate, version: version) + } +} diff --git a/submodules/SyncCore/Sources/TelegramMediaAction.swift b/submodules/SyncCore/Sources/TelegramMediaAction.swift new file mode 100644 index 0000000000..c22b4ea4f9 --- /dev/null +++ b/submodules/SyncCore/Sources/TelegramMediaAction.swift @@ -0,0 +1,233 @@ +import Postbox + +public enum PhoneCallDiscardReason: Int32 { + case missed = 0 + case disconnect = 1 + case hangup = 2 + case busy = 3 +} + +public enum SentSecureValueType: Int32 { + case personalDetails = 0 + case passport = 1 + case driversLicense = 2 + case idCard = 3 + case address = 4 + case bankStatement = 5 + case utilityBill = 6 + case rentalAgreement = 7 + case phone = 8 + case email = 9 + case internalPassport = 10 + case passportRegistration = 11 + case temporaryRegistration = 12 +} + +public enum TelegramMediaActionType: PostboxCoding, Equatable { + case unknown + case groupCreated(title: String) + case addedMembers(peerIds: [PeerId]) + case removedMembers(peerIds: [PeerId]) + case photoUpdated(image: TelegramMediaImage?) + case titleUpdated(title: String) + case pinnedMessageUpdated + case joinedByLink(inviter: PeerId) + case channelMigratedFromGroup(title: String, groupId: PeerId) + case groupMigratedToChannel(channelId: PeerId) + case historyCleared + case historyScreenshot + case messageAutoremoveTimeoutUpdated(Int32) + case gameScore(gameId: Int64, score: Int32) + case phoneCall(callId: Int64, discardReason: PhoneCallDiscardReason?, duration: Int32?) + case paymentSent(currency: String, totalAmount: Int64) + case customText(text: String, entities: [MessageTextEntity]) + case botDomainAccessGranted(domain: String) + case botSentSecureValues(types: [SentSecureValueType]) + case peerJoined + case phoneNumberRequest + + public init(decoder: PostboxDecoder) { + let rawValue: Int32 = decoder.decodeInt32ForKey("_rawValue", orElse: 0) + switch rawValue { + case 1: + self = .groupCreated(title: decoder.decodeStringForKey("title", orElse: "")) + case 2: + self = .addedMembers(peerIds: PeerId.decodeArrayFromBuffer(decoder.decodeBytesForKeyNoCopy("peerIds")!)) + case 3: + self = .removedMembers(peerIds: PeerId.decodeArrayFromBuffer(decoder.decodeBytesForKeyNoCopy("peerIds")!)) + case 4: + self = .photoUpdated(image: decoder.decodeObjectForKey("image") as? TelegramMediaImage) + case 5: + self = .titleUpdated(title: decoder.decodeStringForKey("title", orElse: "")) + case 6: + self = .pinnedMessageUpdated + case 7: + self = .joinedByLink(inviter: PeerId(decoder.decodeInt64ForKey("inviter", orElse: 0))) + case 8: + self = .channelMigratedFromGroup(title: decoder.decodeStringForKey("title", orElse: ""), groupId: PeerId(decoder.decodeInt64ForKey("groupId", orElse: 0))) + case 9: + self = .groupMigratedToChannel(channelId: PeerId(decoder.decodeInt64ForKey("channelId", orElse: 0))) + case 10: + self = .historyCleared + case 11: + self = .historyScreenshot + case 12: + self = .messageAutoremoveTimeoutUpdated(decoder.decodeInt32ForKey("t", orElse: 0)) + case 13: + self = .gameScore(gameId: decoder.decodeInt64ForKey("i", orElse: 0), score: decoder.decodeInt32ForKey("s", orElse: 0)) + case 14: + var discardReason: PhoneCallDiscardReason? + if let value = decoder.decodeOptionalInt32ForKey("dr") { + discardReason = PhoneCallDiscardReason(rawValue: value) + } + self = .phoneCall(callId: decoder.decodeInt64ForKey("i", orElse: 0), discardReason: discardReason, duration: decoder.decodeInt32ForKey("d", orElse: 0)) + case 15: + self = .paymentSent(currency: decoder.decodeStringForKey("currency", orElse: ""), totalAmount: decoder.decodeInt64ForKey("ta", orElse: 0)) + case 16: + self = .customText(text: decoder.decodeStringForKey("text", orElse: ""), entities: decoder.decodeObjectArrayWithDecoderForKey("ent")) + case 17: + self = .botDomainAccessGranted(domain: decoder.decodeStringForKey("do", orElse: "")) + case 18: + self = .botSentSecureValues(types: decoder.decodeInt32ArrayForKey("ty").map { value -> SentSecureValueType in + return SentSecureValueType(rawValue: value) ?? .personalDetails + }) + case 19: + self = .peerJoined + case 20: + self = .phoneNumberRequest + default: + self = .unknown + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case .unknown: + break + case let .groupCreated(title): + encoder.encodeInt32(1, forKey: "_rawValue") + encoder.encodeString(title, forKey: "title") + case let .addedMembers(peerIds): + encoder.encodeInt32(2, forKey: "_rawValue") + let buffer = WriteBuffer() + PeerId.encodeArrayToBuffer(peerIds, buffer: buffer) + encoder.encodeBytes(buffer, forKey: "peerIds") + case let .removedMembers(peerIds): + encoder.encodeInt32(3, forKey: "_rawValue") + let buffer = WriteBuffer() + PeerId.encodeArrayToBuffer(peerIds, buffer: buffer) + encoder.encodeBytes(buffer, forKey: "peerIds") + case let .photoUpdated(image): + encoder.encodeInt32(4, forKey: "_rawValue") + if let image = image { + encoder.encodeObject(image, forKey: "image") + } + case let .titleUpdated(title): + encoder.encodeInt32(5, forKey: "_rawValue") + encoder.encodeString(title, forKey: "title") + case .pinnedMessageUpdated: + encoder.encodeInt32(6, forKey: "_rawValue") + case let .joinedByLink(inviter): + encoder.encodeInt32(7, forKey: "_rawValue") + encoder.encodeInt64(inviter.toInt64(), forKey: "inviter") + case let .channelMigratedFromGroup(title, groupId): + encoder.encodeInt32(8, forKey: "_rawValue") + encoder.encodeString(title, forKey: "title") + encoder.encodeInt64(groupId.toInt64(), forKey: "groupId") + case let .groupMigratedToChannel(channelId): + encoder.encodeInt32(9, forKey: "_rawValue") + encoder.encodeInt64(channelId.toInt64(), forKey: "channelId") + case .historyCleared: + encoder.encodeInt32(10, forKey: "_rawValue") + case .historyScreenshot: + encoder.encodeInt32(11, forKey: "_rawValue") + case let .messageAutoremoveTimeoutUpdated(timeout): + encoder.encodeInt32(12, forKey: "_rawValue") + encoder.encodeInt32(timeout, forKey: "t") + case let .gameScore(gameId, score): + encoder.encodeInt32(13, forKey: "_rawValue") + encoder.encodeInt64(gameId, forKey: "i") + encoder.encodeInt32(score, forKey: "s") + case let .paymentSent(currency, totalAmount): + encoder.encodeInt32(15, forKey: "_rawValue") + encoder.encodeString(currency, forKey: "currency") + encoder.encodeInt64(totalAmount, forKey: "ta") + case let .phoneCall(callId, discardReason, duration): + encoder.encodeInt32(14, forKey: "_rawValue") + encoder.encodeInt64(callId, forKey: "i") + if let discardReason = discardReason { + encoder.encodeInt32(discardReason.rawValue, forKey: "dr") + } else { + encoder.encodeNil(forKey: "dr") + } + if let duration = duration { + encoder.encodeInt32(duration, forKey: "d") + } else { + encoder.encodeNil(forKey: "d") + } + case let .customText(text, entities): + encoder.encodeInt32(16, forKey: "_rawValue") + encoder.encodeString(text, forKey: "text") + encoder.encodeObjectArray(entities, forKey: "ent") + case let .botDomainAccessGranted(domain): + encoder.encodeInt32(17, forKey: "_rawValue") + encoder.encodeString(domain, forKey: "do") + case let .botSentSecureValues(types): + encoder.encodeInt32(18, forKey: "_rawValue") + encoder.encodeInt32Array(types.map { $0.rawValue }, forKey: "ty") + case .peerJoined: + encoder.encodeInt32(19, forKey: "_rawValue") + case .phoneNumberRequest: + encoder.encodeInt32(20, forKey: "_rawValue") + } + } + + public var peerIds: [PeerId] { + switch self { + case let .addedMembers(peerIds): + return peerIds + case let .removedMembers(peerIds): + return peerIds + case let .joinedByLink(inviter): + return [inviter] + case let .channelMigratedFromGroup(_, groupId): + return [groupId] + case let .groupMigratedToChannel(channelId): + return [channelId] + default: + return [] + } + } +} + +public final class TelegramMediaAction: Media { + public let id: MediaId? = nil + public var peerIds: [PeerId] { + return self.action.peerIds + } + + public let action: TelegramMediaActionType + + public init(action: TelegramMediaActionType) { + self.action = action + } + + public init(decoder: PostboxDecoder) { + self.action = TelegramMediaActionType(decoder: decoder) + } + + public func encode(_ encoder: PostboxEncoder) { + self.action.encode(encoder) + } + + public func isEqual(to other: Media) -> Bool { + if let other = other as? TelegramMediaAction { + return self.action == other.action + } + return false + } + + public func isSemanticallyEqual(to other: Media) -> Bool { + return self.isEqual(to: other) + } +} diff --git a/submodules/TelegramCore/TelegramCore/TelegramMediaContact.swift b/submodules/SyncCore/Sources/TelegramMediaContact.swift similarity index 96% rename from submodules/TelegramCore/TelegramCore/TelegramMediaContact.swift rename to submodules/SyncCore/Sources/TelegramMediaContact.swift index b444f5e238..184a367271 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramMediaContact.swift +++ b/submodules/SyncCore/Sources/TelegramMediaContact.swift @@ -1,9 +1,4 @@ -import Foundation -#if os(macOS) - import PostboxMac -#else - import Postbox -#endif +import Postbox public final class TelegramMediaContact: Media { public let id: MediaId? = nil @@ -68,4 +63,4 @@ public final class TelegramMediaContact: Media { public func isSemanticallyEqual(to other: Media) -> Bool { return self.isEqual(to: other) } -} +} \ No newline at end of file diff --git a/submodules/TelegramCore/TelegramCore/TelegramMediaExpiredContent.swift b/submodules/SyncCore/Sources/TelegramMediaExpiredContent.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/TelegramMediaExpiredContent.swift rename to submodules/SyncCore/Sources/TelegramMediaExpiredContent.swift diff --git a/submodules/SyncCore/Sources/TelegramMediaFile.swift b/submodules/SyncCore/Sources/TelegramMediaFile.swift new file mode 100644 index 0000000000..0b05162042 --- /dev/null +++ b/submodules/SyncCore/Sources/TelegramMediaFile.swift @@ -0,0 +1,474 @@ +import Postbox +import UIKit + +private let typeFileName: Int32 = 0 +private let typeSticker: Int32 = 1 +private let typeImageSize: Int32 = 2 +private let typeAnimated: Int32 = 3 +private let typeVideo: Int32 = 4 +private let typeAudio: Int32 = 5 +private let typeHasLinkedStickers: Int32 = 6 + +public enum StickerPackReference: PostboxCoding, Hashable, Equatable { + case id(id: Int64, accessHash: Int64) + case name(String) + case animatedEmoji + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("r", orElse: 0) { + case 0: + self = .id(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0)) + case 1: + self = .name(decoder.decodeStringForKey("n", orElse: "")) + case 2: + self = .animatedEmoji + default: + self = .name("") + assertionFailure() + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .id(id, accessHash): + encoder.encodeInt32(0, forKey: "r") + encoder.encodeInt64(id, forKey: "i") + encoder.encodeInt64(accessHash, forKey: "h") + case let .name(name): + encoder.encodeInt32(1, forKey: "r") + encoder.encodeString(name, forKey: "n") + case .animatedEmoji: + encoder.encodeInt32(2, forKey: "r") + } + } + + public static func ==(lhs: StickerPackReference, rhs: StickerPackReference) -> Bool { + switch lhs { + case let .id(id, accessHash): + if case .id(id, accessHash) = rhs { + return true + } else { + return false + } + case let .name(name): + if case .name(name) = rhs { + return true + } else { + return false + } + case .animatedEmoji: + if case .animatedEmoji = rhs { + return true + } else { + return false + } + } + } +} + +public struct TelegramMediaVideoFlags: OptionSet { + public var rawValue: Int32 + + public init() { + self.rawValue = 0 + } + + public init(rawValue: Int32) { + self.rawValue = rawValue + } + + public static let instantRoundVideo = TelegramMediaVideoFlags(rawValue: 1 << 0) + public static let supportsStreaming = TelegramMediaVideoFlags(rawValue: 1 << 1) +} + +public struct StickerMaskCoords: PostboxCoding { + public let n: Int32 + public let x: Double + public let y: Double + public let zoom: Double + + public init(n: Int32, x: Double, y: Double, zoom: Double) { + self.n = n + self.x = x + self.y = y + self.zoom = zoom + } + + public init(decoder: PostboxDecoder) { + self.n = decoder.decodeInt32ForKey("n", orElse: 0) + self.x = decoder.decodeDoubleForKey("x", orElse: 0.0) + self.y = decoder.decodeDoubleForKey("y", orElse: 0.0) + self.zoom = decoder.decodeDoubleForKey("z", orElse: 0.0) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.n, forKey: "n") + encoder.encodeDouble(self.x, forKey: "x") + encoder.encodeDouble(self.y, forKey: "y") + encoder.encodeDouble(self.zoom, forKey: "z") + } +} + +public enum TelegramMediaFileAttribute: PostboxCoding { + case FileName(fileName: String) + case Sticker(displayText: String, packReference: StickerPackReference?, maskData: StickerMaskCoords?) + case ImageSize(size: CGSize) + case Animated + case Video(duration: Int, size: CGSize, flags: TelegramMediaVideoFlags) + case Audio(isVoice: Bool, duration: Int, title: String?, performer: String?, waveform: MemoryBuffer?) + case HasLinkedStickers + + public init(decoder: PostboxDecoder) { + let type: Int32 = decoder.decodeInt32ForKey("t", orElse: 0) + switch type { + case typeFileName: + self = .FileName(fileName: decoder.decodeStringForKey("fn", orElse: "")) + case typeSticker: + self = .Sticker(displayText: decoder.decodeStringForKey("dt", orElse: ""), packReference: decoder.decodeObjectForKey("pr", decoder: { StickerPackReference(decoder: $0) }) as? StickerPackReference, maskData: decoder.decodeObjectForKey("mc", decoder: { StickerMaskCoords(decoder: $0) }) as? StickerMaskCoords) + case typeImageSize: + self = .ImageSize(size: CGSize(width: CGFloat(decoder.decodeInt32ForKey("w", orElse: 0)), height: CGFloat(decoder.decodeInt32ForKey("h", orElse: 0)))) + case typeAnimated: + self = .Animated + case typeVideo: + self = .Video(duration: Int(decoder.decodeInt32ForKey("du", orElse: 0)), size: CGSize(width: CGFloat(decoder.decodeInt32ForKey("w", orElse: 0)), height: CGFloat(decoder.decodeInt32ForKey("h", orElse: 0))), flags: TelegramMediaVideoFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0))) + case typeAudio: + let waveformBuffer = decoder.decodeBytesForKeyNoCopy("wf") + var waveform: MemoryBuffer? + if let waveformBuffer = waveformBuffer { + waveform = MemoryBuffer(copyOf: waveformBuffer) + } + self = .Audio(isVoice: decoder.decodeInt32ForKey("iv", orElse: 0) != 0, duration: Int(decoder.decodeInt32ForKey("du", orElse: 0)), title: decoder.decodeOptionalStringForKey("ti"), performer: decoder.decodeOptionalStringForKey("pe"), waveform: waveform) + case typeHasLinkedStickers: + self = .HasLinkedStickers + default: + preconditionFailure() + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .FileName(fileName): + encoder.encodeInt32(typeFileName, forKey: "t") + encoder.encodeString(fileName, forKey: "fn") + case let .Sticker(displayText, packReference, maskCoords): + encoder.encodeInt32(typeSticker, forKey: "t") + encoder.encodeString(displayText, forKey: "dt") + if let packReference = packReference { + encoder.encodeObject(packReference, forKey: "pr") + } else { + encoder.encodeNil(forKey: "pr") + } + if let maskCoords = maskCoords { + encoder.encodeObject(maskCoords, forKey: "mc") + } else { + encoder.encodeNil(forKey: "mc") + } + case let .ImageSize(size): + encoder.encodeInt32(typeImageSize, forKey: "t") + encoder.encodeInt32(Int32(size.width), forKey: "w") + encoder.encodeInt32(Int32(size.height), forKey: "h") + case .Animated: + encoder.encodeInt32(typeAnimated, forKey: "t") + case let .Video(duration, size, flags): + encoder.encodeInt32(typeVideo, forKey: "t") + encoder.encodeInt32(Int32(duration), forKey: "du") + encoder.encodeInt32(Int32(size.width), forKey: "w") + encoder.encodeInt32(Int32(size.height), forKey: "h") + encoder.encodeInt32(flags.rawValue, forKey: "f") + case let .Audio(isVoice, duration, title, performer, waveform): + encoder.encodeInt32(typeAudio, forKey: "t") + encoder.encodeInt32(isVoice ? 1 : 0, forKey: "iv") + encoder.encodeInt32(Int32(duration), forKey: "du") + if let title = title { + encoder.encodeString(title, forKey: "ti") + } + if let performer = performer { + encoder.encodeString(performer, forKey: "pe") + } + if let waveform = waveform { + encoder.encodeBytes(waveform, forKey: "wf") + } + case .HasLinkedStickers: + encoder.encodeInt32(typeHasLinkedStickers, forKey: "t") + } + } +} + +public enum TelegramMediaFileReference: PostboxCoding, Equatable { + case cloud(fileId: Int64, accessHash: Int64, fileReference: Data?) + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("_v", orElse: 0) { + case 0: + self = .cloud(fileId: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0), fileReference: decoder.decodeBytesForKey("fr")?.makeData()) + default: + self = .cloud(fileId: 0, accessHash: 0, fileReference: nil) + assertionFailure() + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .cloud(imageId, accessHash, fileReference): + encoder.encodeInt32(0, forKey: "_v") + encoder.encodeInt64(imageId, forKey: "i") + encoder.encodeInt64(accessHash, forKey: "h") + if let fileReference = fileReference { + encoder.encodeBytes(MemoryBuffer(data: fileReference), forKey: "fr") + } else { + encoder.encodeNil(forKey: "fr") + } + } + } +} + +public final class TelegramMediaFile: Media, Equatable { + public let fileId: MediaId + public let partialReference: PartialMediaReference? + public let resource: TelegramMediaResource + public let previewRepresentations: [TelegramMediaImageRepresentation] + public let immediateThumbnailData: Data? + public let mimeType: String + public let size: Int? + public let attributes: [TelegramMediaFileAttribute] + public let peerIds: [PeerId] = [] + + public var id: MediaId? { + return self.fileId + } + + public init(fileId: MediaId, partialReference: PartialMediaReference?, resource: TelegramMediaResource, previewRepresentations: [TelegramMediaImageRepresentation], immediateThumbnailData: Data?, mimeType: String, size: Int?, attributes: [TelegramMediaFileAttribute]) { + self.fileId = fileId + self.partialReference = partialReference + self.resource = resource + self.previewRepresentations = previewRepresentations + self.immediateThumbnailData = immediateThumbnailData + self.mimeType = mimeType + self.size = size + self.attributes = attributes + } + + public init(decoder: PostboxDecoder) { + self.fileId = MediaId(decoder.decodeBytesForKeyNoCopy("i")!) + self.partialReference = decoder.decodeAnyObjectForKey("prf", decoder: { PartialMediaReference(decoder: $0) }) as? PartialMediaReference + self.resource = decoder.decodeObjectForKey("r") as? TelegramMediaResource ?? EmptyMediaResource() + self.previewRepresentations = decoder.decodeObjectArrayForKey("pr") + self.immediateThumbnailData = decoder.decodeDataForKey("itd") + self.mimeType = decoder.decodeStringForKey("mt", orElse: "") + if let size = decoder.decodeOptionalInt32ForKey("s") { + self.size = Int(size) + } else { + self.size = nil + } + self.attributes = decoder.decodeObjectArrayForKey("at") + } + + public func encode(_ encoder: PostboxEncoder) { + let buffer = WriteBuffer() + self.fileId.encodeToBuffer(buffer) + encoder.encodeBytes(buffer, forKey: "i") + if let partialReference = self.partialReference { + encoder.encodeObjectWithEncoder(partialReference, encoder: partialReference.encode, forKey: "prf") + } else { + encoder.encodeNil(forKey: "prf") + } + encoder.encodeObject(self.resource, forKey: "r") + encoder.encodeObjectArray(self.previewRepresentations, forKey: "pr") + if let immediateThumbnailData = self.immediateThumbnailData { + encoder.encodeData(immediateThumbnailData, forKey: "itd") + } else { + encoder.encodeNil(forKey: "itd") + } + encoder.encodeString(self.mimeType, forKey: "mt") + if let size = self.size { + encoder.encodeInt32(Int32(size), forKey: "s") + } else { + encoder.encodeNil(forKey: "s") + } + encoder.encodeObjectArray(self.attributes, forKey: "at") + } + + public var fileName: String? { + get { + for attribute in self.attributes { + switch attribute { + case let .FileName(fileName): + return fileName + case _: + break + } + } + return nil + } + } + + public var isSticker: Bool { + for attribute in self.attributes { + if case .Sticker = attribute { + return true + } + } + return false + } + + public var isStaticSticker: Bool { + for attribute in self.attributes { + if case .Sticker = attribute { + if let s = self.size, s < 200 * 1024 { + return !isAnimatedSticker + } + } + } + return false + } + + public var isVideo: Bool { + for attribute in self.attributes { + if case .Video = attribute { + return true + } + } + return false + } + + public var isInstantVideo: Bool { + for attribute in self.attributes { + if case .Video(_, _, let flags) = attribute { + return flags.contains(.instantRoundVideo) + } + } + return false + } + + public var isAnimated: Bool { + for attribute in self.attributes { + if case .Animated = attribute { + return true + } + } + return false + } + + public var isAnimatedSticker: Bool { + if let _ = self.fileName, self.mimeType == "application/x-tgsticker" { + return true + } + return false + } + + public var isMusic: Bool { + for attribute in self.attributes { + if case .Audio(false, _, _, _, _) = attribute { + return true + } + } + return false + } + + public var isVoice: Bool { + for attribute in self.attributes { + if case .Audio(true, _, _, _, _) = attribute { + return true + } + } + return false + } + + public func isEqual(to other: Media) -> Bool { + guard let other = other as? TelegramMediaFile else { + return false + } + + if self.fileId != other.fileId { + return false + } + + if self.partialReference != other.partialReference { + return false + } + + if !self.resource.isEqual(to: other.resource) { + return false + } + + if self.previewRepresentations != other.previewRepresentations { + return false + } + + if self.immediateThumbnailData != other.immediateThumbnailData { + return false + } + + if self.size != other.size { + return false + } + + if self.mimeType != other.mimeType { + return false + } + + return true + } + + public func isSemanticallyEqual(to other: Media) -> Bool { + guard let other = other as? TelegramMediaFile else { + return false + } + + if self.fileId != other.fileId { + return false + } + + if self.partialReference != other.partialReference { + return false + } + + if !self.resource.id.isEqual(to: other.resource.id) { + return false + } + + if self.previewRepresentations.count != other.previewRepresentations.count { + return false + } + + for i in 0 ..< self.previewRepresentations.count { + if !self.previewRepresentations[i].isSemanticallyEqual(to: other.previewRepresentations[i]) { + return false + } + } + + if self.immediateThumbnailData != other.immediateThumbnailData { + return false + } + + if self.size != other.size { + return false + } + + if self.mimeType != other.mimeType { + return false + } + + return true + } + + public func withUpdatedPartialReference(_ partialReference: PartialMediaReference?) -> TelegramMediaFile { + return TelegramMediaFile(fileId: self.fileId, partialReference: partialReference, resource: self.resource, previewRepresentations: self.previewRepresentations, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: self.size, attributes: self.attributes) + } + + public func withUpdatedSize(_ size: Int?) -> TelegramMediaFile { + return TelegramMediaFile(fileId: self.fileId, partialReference: self.partialReference, resource: self.resource, previewRepresentations: self.previewRepresentations, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: size, attributes: self.attributes) + } + + public func withUpdatedPreviewRepresentations(_ previewRepresentations: [TelegramMediaImageRepresentation]) -> TelegramMediaFile { + return TelegramMediaFile(fileId: self.fileId, partialReference: self.partialReference, resource: self.resource, previewRepresentations: previewRepresentations, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: self.size, attributes: self.attributes) + } + + public func withUpdatedAttributes(_ attributes: [TelegramMediaFileAttribute]) -> TelegramMediaFile { + return TelegramMediaFile(fileId: self.fileId, partialReference: self.partialReference, resource: self.resource, previewRepresentations: self.previewRepresentations, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: self.size, attributes: attributes) + } +} + +public func ==(lhs: TelegramMediaFile, rhs: TelegramMediaFile) -> Bool { + return lhs.isEqual(to: rhs) +} diff --git a/submodules/SyncCore/Sources/TelegramMediaGame.swift b/submodules/SyncCore/Sources/TelegramMediaGame.swift new file mode 100644 index 0000000000..981a067c14 --- /dev/null +++ b/submodules/SyncCore/Sources/TelegramMediaGame.swift @@ -0,0 +1,102 @@ +import Postbox + +public final class TelegramMediaGame: Media { + public let gameId: Int64 + public let accessHash: Int64 + public let name: String + public let title: String + public let description: String + public let image: TelegramMediaImage? + public let file: TelegramMediaFile? + + public var id: MediaId? { + return MediaId(namespace: Namespaces.Media.CloudGame, id: self.gameId) + } + public let peerIds: [PeerId] = [] + + public init(gameId: Int64, accessHash: Int64, name: String, title: String, description: String, image: TelegramMediaImage?, file: TelegramMediaFile?) { + self.gameId = gameId + self.accessHash = accessHash + self.name = name + self.title = title + self.description = description + self.image = image + self.file = file + } + + public init(decoder: PostboxDecoder) { + self.gameId = decoder.decodeInt64ForKey("i", orElse: 0) + self.accessHash = decoder.decodeInt64ForKey("h", orElse: 0) + self.name = decoder.decodeStringForKey("n", orElse: "") + self.title = decoder.decodeStringForKey("t", orElse: "") + self.description = decoder.decodeStringForKey("d", orElse: "") + self.image = decoder.decodeObjectForKey("p") as? TelegramMediaImage + self.file = decoder.decodeObjectForKey("f") as? TelegramMediaFile + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt64(self.gameId, forKey: "i") + encoder.encodeInt64(self.accessHash, forKey: "h") + encoder.encodeString(self.name, forKey: "n") + encoder.encodeString(self.title, forKey: "t") + encoder.encodeString(self.description, forKey: "d") + if let image = self.image { + encoder.encodeObject(image, forKey: "p") + } else { + encoder.encodeNil(forKey: "p") + } + if let file = self.file { + encoder.encodeObject(file, forKey: "f") + } else { + encoder.encodeNil(forKey: "f") + } + } + + public func isEqual(to other: Media) -> Bool { + guard let other = other as? TelegramMediaGame else { + return false + } + + if self.gameId != other.gameId { + return false + } + + if self.accessHash != other.accessHash { + return false + } + + if self.name != other.name { + return false + } + + if self.title != other.title { + return false + } + + if self.description != other.description { + return false + } + + if let lhsImage = self.image, let rhsImage = other.image { + if !lhsImage.isEqual(to: rhsImage) { + return false + } + } else if (self.image != nil) != (other.image != nil) { + return false + } + + if let lhsFile = self.file, let rhsFile = other.file { + if !lhsFile.isEqual(to: rhsFile) { + return false + } + } else if (self.file != nil) != (other.file != nil) { + return false + } + + return true + } + + public func isSemanticallyEqual(to other: Media) -> Bool { + return self.isEqual(to: other) + } +} diff --git a/submodules/SyncCore/Sources/TelegramMediaImage.swift b/submodules/SyncCore/Sources/TelegramMediaImage.swift new file mode 100644 index 0000000000..39e98b62aa --- /dev/null +++ b/submodules/SyncCore/Sources/TelegramMediaImage.swift @@ -0,0 +1,213 @@ +import Postbox +import UIKit + +public enum TelegramMediaImageReference: PostboxCoding, Equatable { + case cloud(imageId: Int64, accessHash: Int64, fileReference: Data?) + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("_v", orElse: 0) { + case 0: + self = .cloud(imageId: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0), fileReference: decoder.decodeBytesForKey("fr")?.makeData()) + default: + self = .cloud(imageId: 0, accessHash: 0, fileReference: nil) + assertionFailure() + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .cloud(imageId, accessHash, fileReference): + encoder.encodeInt32(0, forKey: "_v") + encoder.encodeInt64(imageId, forKey: "i") + encoder.encodeInt64(accessHash, forKey: "h") + if let fileReference = fileReference { + encoder.encodeBytes(MemoryBuffer(data: fileReference), forKey: "fr") + } else { + encoder.encodeNil(forKey: "fr") + } + } + } + + public static func ==(lhs: TelegramMediaImageReference, rhs: TelegramMediaImageReference) -> Bool { + switch lhs { + case let .cloud(imageId, accessHash, fileReference): + if case .cloud(imageId, accessHash, fileReference) = rhs { + return true + } else { + return false + } + } + } +} + +public final class TelegramMediaImage: Media, Equatable { + public let imageId: MediaId + public let representations: [TelegramMediaImageRepresentation] + public let immediateThumbnailData: Data? + public let reference: TelegramMediaImageReference? + public let partialReference: PartialMediaReference? + public let peerIds: [PeerId] = [] + + public var id: MediaId? { + return self.imageId + } + + public init(imageId: MediaId, representations: [TelegramMediaImageRepresentation], immediateThumbnailData: Data?, reference: TelegramMediaImageReference?, partialReference: PartialMediaReference?) { + self.imageId = imageId + self.representations = representations + self.immediateThumbnailData = immediateThumbnailData + self.reference = reference + self.partialReference = partialReference + } + + public init(decoder: PostboxDecoder) { + self.imageId = MediaId(decoder.decodeBytesForKeyNoCopy("i")!) + self.representations = decoder.decodeObjectArrayForKey("r") + self.immediateThumbnailData = decoder.decodeDataForKey("itd") + self.reference = decoder.decodeObjectForKey("rf", decoder: { TelegramMediaImageReference(decoder: $0) }) as? TelegramMediaImageReference + self.partialReference = decoder.decodeAnyObjectForKey("prf", decoder: { PartialMediaReference(decoder: $0) }) as? PartialMediaReference + } + + public func encode(_ encoder: PostboxEncoder) { + let buffer = WriteBuffer() + self.imageId.encodeToBuffer(buffer) + encoder.encodeBytes(buffer, forKey: "i") + encoder.encodeObjectArray(self.representations, forKey: "r") + if let immediateThumbnailData = self.immediateThumbnailData { + encoder.encodeData(immediateThumbnailData, forKey: "itd") + } else { + encoder.encodeNil(forKey: "itd") + } + if let reference = self.reference { + encoder.encodeObject(reference, forKey: "rf") + } else { + encoder.encodeNil(forKey: "rf") + } + if let partialReference = self.partialReference { + encoder.encodeObjectWithEncoder(partialReference, encoder: partialReference.encode, forKey: "prf") + } else { + encoder.encodeNil(forKey: "prf") + } + } + + public func representationForDisplayAtSize(_ size: CGSize) -> TelegramMediaImageRepresentation? { + if self.representations.count == 0 { + return nil + } else { + var dimensions = self.representations[0].dimensions + var index = 0 + + for i in 0 ..< self.representations.count { + let representationDimensions = self.representations[i].dimensions + + if dimensions.width >= size.width - CGFloat.ulpOfOne && dimensions.height >= size.height - CGFloat.ulpOfOne { + if representationDimensions.width >= size.width && representationDimensions.height >= dimensions.height && representationDimensions.width < dimensions.width && representationDimensions.height < dimensions.height { + dimensions = representationDimensions + index = i + } + } else { + if representationDimensions.width >= dimensions.width && representationDimensions.height >= dimensions.height { + dimensions = representationDimensions + index = i + } + } + } + + return self.representations[index] + } + } + + public func isEqual(to other: Media) -> Bool { + if let other = other as? TelegramMediaImage { + if other.imageId != self.imageId { + return false + } + if other.representations != self.representations { + return false + } + if other.immediateThumbnailData != self.immediateThumbnailData { + return false + } + if self.partialReference != other.partialReference { + return false + } + return true + } + return false + } + + public func isSemanticallyEqual(to other: Media) -> Bool { + if let other = other as? TelegramMediaImage { + if other.imageId != self.imageId { + return false + } + if other.representations.count != self.representations.count { + return false + } + for i in 0 ..< self.representations.count { + if !self.representations[i].isSemanticallyEqual(to: other.representations[i]) { + return false + } + } + + if self.partialReference != other.partialReference { + return false + } + return true + } + return false + } + + public static func ==(lhs: TelegramMediaImage, rhs: TelegramMediaImage) -> Bool { + return lhs.isEqual(to: rhs) + } + + public func withUpdatedPartialReference(_ partialReference: PartialMediaReference?) -> TelegramMediaImage { + return TelegramMediaImage(imageId: self.imageId, representations: self.representations, immediateThumbnailData: self.immediateThumbnailData, reference: self.reference, partialReference: partialReference) + } +} + +public final class TelegramMediaImageRepresentation: PostboxCoding, Equatable, CustomStringConvertible { + public let dimensions: CGSize + public let resource: TelegramMediaResource + + public init(dimensions: CGSize, resource: TelegramMediaResource) { + self.dimensions = dimensions + self.resource = resource + } + + public init(decoder: PostboxDecoder) { + self.dimensions = CGSize(width: CGFloat(decoder.decodeInt32ForKey("dx", orElse: 0)), height: CGFloat(decoder.decodeInt32ForKey("dy", orElse: 0))) + self.resource = decoder.decodeObjectForKey("r") as? TelegramMediaResource ?? EmptyMediaResource() + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(Int32(self.dimensions.width), forKey: "dx") + encoder.encodeInt32(Int32(self.dimensions.height), forKey: "dy") + encoder.encodeObject(self.resource, forKey: "r") + } + + public var description: String { + return "(\(Int(dimensions.width))x\(Int(dimensions.height)))" + } + + public func isSemanticallyEqual(to other: TelegramMediaImageRepresentation) -> Bool { + if self.dimensions != other.dimensions { + return false + } + if !self.resource.id.isEqual(to: other.resource.id) { + return false + } + return true + } +} + +public func ==(lhs: TelegramMediaImageRepresentation, rhs: TelegramMediaImageRepresentation) -> Bool { + if lhs.dimensions != rhs.dimensions { + return false + } + if !lhs.resource.isEqual(to: rhs.resource) { + return false + } + return true +} diff --git a/submodules/TelegramCore/TelegramCore/TelegramMediaInvoice.swift b/submodules/SyncCore/Sources/TelegramMediaInvoice.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/TelegramMediaInvoice.swift rename to submodules/SyncCore/Sources/TelegramMediaInvoice.swift diff --git a/submodules/SyncCore/Sources/TelegramMediaMap.swift b/submodules/SyncCore/Sources/TelegramMediaMap.swift new file mode 100644 index 0000000000..a54f276c1a --- /dev/null +++ b/submodules/SyncCore/Sources/TelegramMediaMap.swift @@ -0,0 +1,201 @@ +import Postbox + +public final class NamedGeoPlace: PostboxCoding, Equatable { + public let country: String? + public let state: String? + public let city: String? + public let district: String? + public let street: String? + + public init(country: String?, state: String?, city: String?, district: String?, street: String?) { + self.country = country + self.state = state + self.city = city + self.district = district + self.street = street + } + + public init(decoder: PostboxDecoder) { + self.country = decoder.decodeOptionalStringForKey("gp_co") + self.state = decoder.decodeOptionalStringForKey("gp_sta") + self.city = decoder.decodeOptionalStringForKey("gp_ci") + self.district = decoder.decodeOptionalStringForKey("gp_dis") + self.street = decoder.decodeOptionalStringForKey("gp_str") + } + + public func encode(_ encoder: PostboxEncoder) { + if let country = self.country { + encoder.encodeString(country, forKey: "gp_co") + } + + if let state = self.state { + encoder.encodeString(state, forKey: "gp_sta") + } + + if let city = self.city { + encoder.encodeString(city, forKey: "gp_ci") + } + + if let district = self.district { + encoder.encodeString(district, forKey: "gp_dis") + } + + if let street = self.street { + encoder.encodeString(street, forKey: "gp_str") + } + } + + public static func ==(lhs: NamedGeoPlace, rhs: NamedGeoPlace) -> Bool { + if lhs.country != rhs.country { + return false + } + if lhs.state != rhs.state { + return false + } + if lhs.city != rhs.city { + return false + } + if lhs.district != rhs.district { + return false + } + if lhs.street != rhs.street { + return false + } + return true + } +} + +public final class MapVenue: PostboxCoding, Equatable { + public let title: String + public let address: String? + public let provider: String? + public let id: String? + public let type: String? + + public init(title: String, address: String?, provider: String?, id: String?, type: String?) { + self.title = title + self.address = address + self.provider = provider + self.id = id + self.type = type + } + + public init(decoder: PostboxDecoder) { + self.title = decoder.decodeStringForKey("ti", orElse: "") + self.address = decoder.decodeOptionalStringForKey("ad") + self.provider = decoder.decodeOptionalStringForKey("pr") + self.id = decoder.decodeOptionalStringForKey("id") + self.type = decoder.decodeOptionalStringForKey("ty") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.title, forKey: "ti") + + if let address = self.address { + encoder.encodeString(address, forKey: "ad") + } else { + encoder.encodeNil(forKey: "ad") + } + if let provider = self.provider { + encoder.encodeString(provider, forKey: "pr") + } else { + encoder.encodeNil(forKey: "pr") + } + if let id = self.id { + encoder.encodeString(id, forKey: "id") + } else { + encoder.encodeNil(forKey: "id") + } + if let type = self.type { + encoder.encodeString(type, forKey: "ty") + } else { + encoder.encodeNil(forKey: "ty") + } + } + + public static func ==(lhs: MapVenue, rhs: MapVenue) -> Bool { + if lhs.address != rhs.address { + return false + } + if lhs.provider != rhs.provider { + return false + } + if lhs.id != rhs.id { + return false + } + if lhs.type != rhs.type { + return false + } + return true + } +} + +public final class TelegramMediaMap: Media { + public let latitude: Double + public let longitude: Double + public let geoPlace: NamedGeoPlace? + public let venue: MapVenue? + public let liveBroadcastingTimeout: Int32? + + public let id: MediaId? = nil + public let peerIds: [PeerId] = [] + + public init(latitude: Double, longitude: Double, geoPlace: NamedGeoPlace?, venue: MapVenue?, liveBroadcastingTimeout: Int32?) { + self.latitude = latitude + self.longitude = longitude + self.geoPlace = geoPlace + self.venue = venue + self.liveBroadcastingTimeout = liveBroadcastingTimeout + } + + public init(decoder: PostboxDecoder) { + self.latitude = decoder.decodeDoubleForKey("la", orElse: 0.0) + self.longitude = decoder.decodeDoubleForKey("lo", orElse: 0.0) + self.geoPlace = decoder.decodeObjectForKey("gp", decoder: { NamedGeoPlace(decoder: $0) }) as? NamedGeoPlace + self.venue = decoder.decodeObjectForKey("ve", decoder: { MapVenue(decoder: $0) }) as? MapVenue + self.liveBroadcastingTimeout = decoder.decodeOptionalInt32ForKey("bt") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeDouble(self.latitude, forKey: "la") + encoder.encodeDouble(self.longitude, forKey: "lo") + if let geoPlace = self.geoPlace { + encoder.encodeObject(geoPlace, forKey: "gp") + } else { + encoder.encodeNil(forKey: "gp") + } + if let venue = self.venue { + encoder.encodeObject(venue, forKey: "ve") + } else { + encoder.encodeNil(forKey: "ve") + } + if let liveBroadcastingTimeout = self.liveBroadcastingTimeout { + encoder.encodeInt32(liveBroadcastingTimeout, forKey: "bt") + } else { + encoder.encodeNil(forKey: "bt") + } + } + + public func isEqual(to other: Media) -> Bool { + if let other = other as? TelegramMediaMap { + if self.latitude != other.latitude || self.longitude != other.longitude { + return false + } + if self.geoPlace != other.geoPlace { + return false + } + if self.venue != other.venue { + return false + } + if self.liveBroadcastingTimeout != other.liveBroadcastingTimeout { + return false + } + return true + } + return false + } + + public func isSemanticallyEqual(to other: Media) -> Bool { + return self.isEqual(to: other) + } +} diff --git a/submodules/SyncCore/Sources/TelegramMediaPoll.swift b/submodules/SyncCore/Sources/TelegramMediaPoll.swift new file mode 100644 index 0000000000..91bcc68457 --- /dev/null +++ b/submodules/SyncCore/Sources/TelegramMediaPoll.swift @@ -0,0 +1,168 @@ +import Postbox + +public struct TelegramMediaPollOption: Equatable, PostboxCoding { + public let text: String + public let opaqueIdentifier: Data + + public init(text: String, opaqueIdentifier: Data) { + self.text = text + self.opaqueIdentifier = opaqueIdentifier + } + + public init(decoder: PostboxDecoder) { + self.text = decoder.decodeStringForKey("t", orElse: "") + self.opaqueIdentifier = decoder.decodeDataForKey("i") ?? Data() + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.text, forKey: "t") + encoder.encodeData(self.opaqueIdentifier, forKey: "i") + } +} + +public struct TelegramMediaPollOptionVoters: Equatable, PostboxCoding { + public let selected: Bool + public let opaqueIdentifier: Data + public let count: Int32 + + public init(selected: Bool, opaqueIdentifier: Data, count: Int32) { + self.selected = selected + self.opaqueIdentifier = opaqueIdentifier + self.count = count + } + + public init(decoder: PostboxDecoder) { + self.selected = decoder.decodeInt32ForKey("s", orElse: 0) != 0 + self.opaqueIdentifier = decoder.decodeDataForKey("i") ?? Data() + self.count = decoder.decodeInt32ForKey("c", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.selected ? 1 : 0, forKey: "s") + encoder.encodeData(self.opaqueIdentifier, forKey: "i") + encoder.encodeInt32(self.count, forKey: "c") + } +} + +public struct TelegramMediaPollResults: Equatable, PostboxCoding { + public let voters: [TelegramMediaPollOptionVoters]? + public let totalVoters: Int32? + + public init(voters: [TelegramMediaPollOptionVoters]?, totalVoters: Int32?) { + self.voters = voters + self.totalVoters = totalVoters + } + + public init(decoder: PostboxDecoder) { + self.voters = decoder.decodeOptionalObjectArrayWithDecoderForKey("v") + self.totalVoters = decoder.decodeOptionalInt32ForKey("t") + } + + public func encode(_ encoder: PostboxEncoder) { + if let voters = self.voters { + encoder.encodeObjectArray(voters, forKey: "v") + } else { + encoder.encodeNil(forKey: "v") + } + if let totalVoters = self.totalVoters { + encoder.encodeInt32(totalVoters, forKey: "t") + } else { + encoder.encodeNil(forKey: "t") + } + } +} + +public final class TelegramMediaPoll: Media, Equatable { + public var id: MediaId? { + return self.pollId + } + public let pollId: MediaId + public let peerIds: [PeerId] = [] + + public let text: String + public let options: [TelegramMediaPollOption] + public let results: TelegramMediaPollResults + public let isClosed: Bool + + public init(pollId: MediaId, text: String, options: [TelegramMediaPollOption], results: TelegramMediaPollResults, isClosed: Bool) { + self.pollId = pollId + self.text = text + self.options = options + self.results = results + self.isClosed = isClosed + } + + public init(decoder: PostboxDecoder) { + if let idBytes = decoder.decodeBytesForKeyNoCopy("i") { + self.pollId = MediaId(idBytes) + } else { + self.pollId = MediaId(namespace: Namespaces.Media.LocalPoll, id: 0) + } + self.text = decoder.decodeStringForKey("t", orElse: "") + self.options = decoder.decodeObjectArrayWithDecoderForKey("os") + self.results = decoder.decodeObjectForKey("rs", decoder: { TelegramMediaPollResults(decoder: $0) }) as? TelegramMediaPollResults ?? TelegramMediaPollResults(voters: nil, totalVoters: nil) + self.isClosed = decoder.decodeInt32ForKey("ic", orElse: 0) != 0 + } + + public func encode(_ encoder: PostboxEncoder) { + let buffer = WriteBuffer() + self.pollId.encodeToBuffer(buffer) + encoder.encodeBytes(buffer, forKey: "i") + encoder.encodeString(self.text, forKey: "t") + encoder.encodeObjectArray(self.options, forKey: "os") + encoder.encodeObject(results, forKey: "rs") + encoder.encodeInt32(self.isClosed ? 1 : 0, forKey: "ic") + } + + public func isEqual(to other: Media) -> Bool { + guard let other = other as? TelegramMediaPoll else { + return false + } + return self == other + } + + public func isSemanticallyEqual(to other: Media) -> Bool { + return self.isEqual(to: other) + } + + public static func ==(lhs: TelegramMediaPoll, rhs: TelegramMediaPoll) -> Bool { + if lhs.pollId != rhs.pollId { + return false + } + if lhs.text != rhs.text { + return false + } + if lhs.options != rhs.options { + return false + } + if lhs.results != rhs.results { + return false + } + if lhs.isClosed != rhs.isClosed { + return false + } + return true + } + + public func withUpdatedResults(_ results: TelegramMediaPollResults, min: Bool) -> TelegramMediaPoll { + let updatedResults: TelegramMediaPollResults + if min { + if let currentVoters = self.results.voters, let updatedVoters = results.voters { + var selectedOpaqueIdentifiers = Set() + for voters in currentVoters { + if voters.selected { + selectedOpaqueIdentifiers.insert(voters.opaqueIdentifier) + } + } + updatedResults = TelegramMediaPollResults(voters: updatedVoters.map({ voters in + return TelegramMediaPollOptionVoters(selected: selectedOpaqueIdentifiers.contains(voters.opaqueIdentifier), opaqueIdentifier: voters.opaqueIdentifier, count: voters.count) + }), totalVoters: results.totalVoters) + } else { + updatedResults = TelegramMediaPollResults(voters: self.results.voters, totalVoters: results.totalVoters) + } + } else { + updatedResults = results + } + return TelegramMediaPoll(pollId: self.pollId, text: self.text, options: self.options, results: updatedResults, isClosed: self.isClosed) + } +} diff --git a/submodules/TelegramCore/TelegramCore/TelegramMediaResource.swift b/submodules/SyncCore/Sources/TelegramMediaResource.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/TelegramMediaResource.swift rename to submodules/SyncCore/Sources/TelegramMediaResource.swift diff --git a/submodules/TelegramCore/TelegramCore/TeleramMediaUnsupported.swift b/submodules/SyncCore/Sources/TelegramMediaUnsupported.swift similarity index 96% rename from submodules/TelegramCore/TelegramCore/TeleramMediaUnsupported.swift rename to submodules/SyncCore/Sources/TelegramMediaUnsupported.swift index 5ff9e8b0f0..6df8541ac7 100644 --- a/submodules/TelegramCore/TelegramCore/TeleramMediaUnsupported.swift +++ b/submodules/SyncCore/Sources/TelegramMediaUnsupported.swift @@ -9,7 +9,7 @@ public final class TelegramMediaUnsupported: Media { public let id: MediaId? = nil public let peerIds: [PeerId] = [] - init() { + public init() { } public init(decoder: PostboxDecoder) { diff --git a/submodules/SyncCore/Sources/TelegramMediaWebFile.swift b/submodules/SyncCore/Sources/TelegramMediaWebFile.swift new file mode 100644 index 0000000000..1986f60bb6 --- /dev/null +++ b/submodules/SyncCore/Sources/TelegramMediaWebFile.swift @@ -0,0 +1,59 @@ +import Postbox +import UIKit + +public class TelegramMediaWebFile: Media { + public let resource: TelegramMediaResource + public let mimeType: String + public let size: Int32 + public let attributes: [TelegramMediaFileAttribute] + public let peerIds: [PeerId] = [] + + public var id: MediaId? { + return nil + } + + public init(resource: TelegramMediaResource, mimeType: String, size: Int32, attributes: [TelegramMediaFileAttribute]) { + self.resource = resource + self.mimeType = mimeType + self.size = size + self.attributes = attributes + } + + public required init(decoder: PostboxDecoder) { + self.resource = decoder.decodeObjectForKey("r") as! TelegramMediaResource + self.mimeType = decoder.decodeStringForKey("mt", orElse: "") + self.size = decoder.decodeInt32ForKey("s", orElse: 0) + self.attributes = decoder.decodeObjectArrayForKey("at") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObject(self.resource, forKey: "r") + encoder.encodeString(self.mimeType, forKey: "mt") + encoder.encodeInt32(self.size, forKey: "s") + encoder.encodeObjectArray(self.attributes, forKey: "at") + } + + public func isEqual(to other: Media) -> Bool { + guard let other = other as? TelegramMediaWebFile else { + return false + } + + if !self.resource.isEqual(to: other.resource) { + return false + } + + if self.size != other.size { + return false + } + + if self.mimeType != other.mimeType { + return false + } + + return true + } + + public func isSemanticallyEqual(to other: Media) -> Bool { + return self.isEqual(to: other) + } +} diff --git a/submodules/SyncCore/Sources/TelegramMediaWebpage.swift b/submodules/SyncCore/Sources/TelegramMediaWebpage.swift new file mode 100644 index 0000000000..dd4b0a8f42 --- /dev/null +++ b/submodules/SyncCore/Sources/TelegramMediaWebpage.swift @@ -0,0 +1,302 @@ +import Postbox +import UIKit + +public final class TelegramMediaWebpageLoadedContent: PostboxCoding, Equatable { + public let url: String + public let displayUrl: String + public let hash: Int32 + public let type: String? + public let websiteName: String? + public let title: String? + public let text: String? + public let embedUrl: String? + public let embedType: String? + public let embedSize: CGSize? + public let duration: Int? + public let author: String? + + public let image: TelegramMediaImage? + public let file: TelegramMediaFile? + public let files: [TelegramMediaFile]? + public let instantPage: InstantPage? + + public init(url: String, displayUrl: String, hash: Int32, type: String?, websiteName: String?, title: String?, text: String?, embedUrl: String?, embedType: String?, embedSize: CGSize?, duration: Int?, author: String?, image: TelegramMediaImage?, file: TelegramMediaFile?, files: [TelegramMediaFile]?, instantPage: InstantPage?) { + self.url = url + self.displayUrl = displayUrl + self.hash = hash + self.type = type + self.websiteName = websiteName + self.title = title + self.text = text + self.embedUrl = embedUrl + self.embedType = embedType + self.embedSize = embedSize + self.duration = duration + self.author = author + self.image = image + self.file = file + self.files = files + self.instantPage = instantPage + } + + public init(decoder: PostboxDecoder) { + self.url = decoder.decodeStringForKey("u", orElse: "") + self.displayUrl = decoder.decodeStringForKey("d", orElse: "") + self.hash = decoder.decodeInt32ForKey("ha", orElse: 0) + self.type = decoder.decodeOptionalStringForKey("ty") + self.websiteName = decoder.decodeOptionalStringForKey("ws") + self.title = decoder.decodeOptionalStringForKey("ti") + self.text = decoder.decodeOptionalStringForKey("tx") + self.embedUrl = decoder.decodeOptionalStringForKey("eu") + self.embedType = decoder.decodeOptionalStringForKey("et") + if let embedSizeWidth = decoder.decodeOptionalInt32ForKey("esw"), let embedSizeHeight = decoder.decodeOptionalInt32ForKey("esh") { + self.embedSize = CGSize(width: CGFloat(embedSizeWidth), height: CGFloat(embedSizeHeight)) + } else { + self.embedSize = nil + } + if let duration = decoder.decodeOptionalInt32ForKey("du") { + self.duration = Int(duration) + } else { + self.duration = nil + } + self.author = decoder.decodeOptionalStringForKey("au") + + if let image = decoder.decodeObjectForKey("im") as? TelegramMediaImage { + self.image = image + } else { + self.image = nil + } + + if let file = decoder.decodeObjectForKey("fi") as? TelegramMediaFile { + self.file = file + } else { + self.file = nil + } + + self.files = decoder.decodeOptionalObjectArrayWithDecoderForKey("fis") + + if let instantPage = decoder.decodeObjectForKey("ip", decoder: { InstantPage(decoder: $0) }) as? InstantPage { + self.instantPage = instantPage + } else { + self.instantPage = nil + } + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.url, forKey: "u") + encoder.encodeString(self.displayUrl, forKey: "d") + encoder.encodeInt32(self.hash, forKey: "ha") + if let type = self.type { + encoder.encodeString(type, forKey: "ty") + } else { + encoder.encodeNil(forKey: "ty") + } + if let websiteName = self.websiteName { + encoder.encodeString(websiteName, forKey: "ws") + } else { + encoder.encodeNil(forKey: "ws") + } + if let title = self.title { + encoder.encodeString(title, forKey: "ti") + } else { + encoder.encodeNil(forKey: "ti") + } + if let text = self.text { + encoder.encodeString(text, forKey: "tx") + } else { + encoder.encodeNil(forKey: "tx") + } + if let embedUrl = self.embedUrl { + encoder.encodeString(embedUrl, forKey: "eu") + } else { + encoder.encodeNil(forKey: "eu") + } + if let embedType = self.embedType { + encoder.encodeString(embedType, forKey: "et") + } else { + encoder.encodeNil(forKey: "et") + } + if let embedSize = self.embedSize { + encoder.encodeInt32(Int32(embedSize.width), forKey: "esw") + encoder.encodeInt32(Int32(embedSize.height), forKey: "esh") + } else { + encoder.encodeNil(forKey: "esw") + encoder.encodeNil(forKey: "esh") + } + if let duration = self.duration { + encoder.encodeInt32(Int32(duration), forKey: "du") + } else { + encoder.encodeNil(forKey: "du") + } + if let author = self.author { + encoder.encodeString(author, forKey: "au") + } else { + encoder.encodeNil(forKey: "au") + } + if let image = self.image { + encoder.encodeObject(image, forKey: "im") + } else { + encoder.encodeNil(forKey: "im") + } + if let file = self.file { + encoder.encodeObject(file, forKey: "fi") + } else { + encoder.encodeNil(forKey: "fi") + } + if let files = self.files { + encoder.encodeObjectArray(files, forKey: "fis") + } else { + encoder.encodeNil(forKey: "fis") + } + if let instantPage = self.instantPage { + encoder.encodeObject(instantPage, forKey: "ip") + } else { + encoder.encodeNil(forKey: "ip") + } + } +} + +public func ==(lhs: TelegramMediaWebpageLoadedContent, rhs: TelegramMediaWebpageLoadedContent) -> Bool { + if lhs.url != rhs.url + || lhs.displayUrl != rhs.displayUrl + || lhs.hash != rhs.hash + || lhs.type != rhs.type + || lhs.websiteName != rhs.websiteName + || lhs.title != rhs.title + || lhs.text != rhs.text + || lhs.embedUrl != rhs.embedUrl + || lhs.embedType != rhs.embedType + || lhs.embedSize != rhs.embedSize + || lhs.duration != rhs.duration + || lhs.author != rhs.author { + return false + } + + if let lhsImage = lhs.image, let rhsImage = rhs.image { + if !lhsImage.isEqual(to: rhsImage) { + return false + } + } else if (lhs.image == nil) != (rhs.image == nil) { + return false + } + + if let lhsFile = lhs.file, let rhsFile = rhs.file { + if !lhsFile.isEqual(to: rhsFile) { + return false + } + } else if (lhs.file == nil) != (rhs.file == nil) { + return false + } + + if let lhsFiles = lhs.files, let rhsFiles = rhs.files { + if lhsFiles.count != rhsFiles.count { + return false + } else { + for i in 0 ..< lhsFiles.count { + if !lhsFiles[i].isEqual(to: rhsFiles[i]) { + return false + } + } + } + } else if (lhs.files == nil) != (rhs.files == nil) { + return false + } + + if lhs.instantPage != rhs.instantPage { + return false + } + + return true +} + +public enum TelegramMediaWebpageContent { + case Pending(Int32, String?) + case Loaded(TelegramMediaWebpageLoadedContent) +} + +public final class TelegramMediaWebpage: Media, Equatable { + public var id: MediaId? { + return self.webpageId + } + public let peerIds: [PeerId] = [] + + public let webpageId: MediaId + public let content: TelegramMediaWebpageContent + + public init(webpageId: MediaId, content: TelegramMediaWebpageContent) { + self.webpageId = webpageId + self.content = content + } + + public init(decoder: PostboxDecoder) { + self.webpageId = MediaId(decoder.decodeBytesForKeyNoCopy("i")!) + + if decoder.decodeInt32ForKey("ct", orElse: 0) == 0 { + self.content = .Pending(decoder.decodeInt32ForKey("pendingDate", orElse: 0), decoder.decodeOptionalStringForKey("pendingUrl")) + } else { + self.content = .Loaded(TelegramMediaWebpageLoadedContent(decoder: decoder)) + } + } + + public func encode(_ encoder: PostboxEncoder) { + let buffer = WriteBuffer() + self.webpageId.encodeToBuffer(buffer) + encoder.encodeBytes(buffer, forKey: "i") + + switch self.content { + case let .Pending(date, url): + encoder.encodeInt32(0, forKey: "ct") + encoder.encodeInt32(date, forKey: "pendingDate") + if let url = url { + encoder.encodeString(url, forKey: "pendingUrl") + } else { + encoder.encodeNil(forKey: "pendingUrl") + } + case let .Loaded(loadedContent): + encoder.encodeInt32(1, forKey: "ct") + loadedContent.encode(encoder) + } + } + + public func isLikelyToBeUpdated() -> Bool { + return true + } + + public func isEqual(to other: Media) -> Bool { + if let other = other as? TelegramMediaWebpage, self.webpageId == other.webpageId { + return self == other + } + return false + } + + public func isSemanticallyEqual(to other: Media) -> Bool { + return self.isEqual(to: other) + } + + public static func ==(lhs: TelegramMediaWebpage, rhs: TelegramMediaWebpage) -> Bool { + if lhs.webpageId != rhs.webpageId { + return false + } + + switch lhs.content { + case let .Pending(lhsDate, lhsUrl): + switch rhs.content { + case let .Pending(rhsDate, rhsUrl): + if lhsDate == rhsDate, lhsUrl == rhsUrl { + return true + } else { + return false + } + default: + return false + } + case let .Loaded(lhsContent): + switch rhs.content { + case let .Loaded(rhsContent) where lhsContent == rhsContent: + return true + default: + return false + } + } + } +} diff --git a/submodules/SyncCore/Sources/TelegramPeerNotificationSettings.swift b/submodules/SyncCore/Sources/TelegramPeerNotificationSettings.swift new file mode 100644 index 0000000000..59c5bbf091 --- /dev/null +++ b/submodules/SyncCore/Sources/TelegramPeerNotificationSettings.swift @@ -0,0 +1,208 @@ +import Postbox + +public enum PeerMuteState: Equatable { + case `default` + case unmuted + case muted(until: Int32) + + fileprivate static func decodeInline(_ decoder: PostboxDecoder) -> PeerMuteState { + switch decoder.decodeInt32ForKey("m.v", orElse: 0) { + case 0: + return .default + case 1: + return .muted(until: decoder.decodeInt32ForKey("m.u", orElse: 0)) + case 2: + return .unmuted + default: + return .default + } + } + + fileprivate func encodeInline(_ encoder: PostboxEncoder) { + switch self { + case .default: + encoder.encodeInt32(0, forKey: "m.v") + case let .muted(until): + encoder.encodeInt32(1, forKey: "m.v") + encoder.encodeInt32(until, forKey: "m.u") + case .unmuted: + encoder.encodeInt32(2, forKey: "m.v") + } + } +} + +private enum PeerMessageSoundValue: Int32 { + case none + case bundledModern + case bundledClassic + case `default` +} + +public enum PeerMessageSound: Equatable { + case none + case `default` + case bundledModern(id: Int32) + case bundledClassic(id: Int32) + + static func decodeInline(_ decoder: PostboxDecoder) -> PeerMessageSound { + switch decoder.decodeInt32ForKey("s.v", orElse: 0) { + case PeerMessageSoundValue.none.rawValue: + return .none + case PeerMessageSoundValue.bundledModern.rawValue: + return .bundledModern(id: decoder.decodeInt32ForKey("s.i", orElse: 0)) + case PeerMessageSoundValue.bundledClassic.rawValue: + return .bundledClassic(id: decoder.decodeInt32ForKey("s.i", orElse: 0)) + case PeerMessageSoundValue.default.rawValue: + return .default + default: + assertionFailure() + return .bundledModern(id: 0) + } + } + + func encodeInline(_ encoder: PostboxEncoder) { + switch self { + case .none: + encoder.encodeInt32(PeerMessageSoundValue.none.rawValue, forKey: "s.v") + case let .bundledModern(id): + encoder.encodeInt32(PeerMessageSoundValue.bundledModern.rawValue, forKey: "s.v") + encoder.encodeInt32(id, forKey: "s.i") + case let .bundledClassic(id): + encoder.encodeInt32(PeerMessageSoundValue.bundledClassic.rawValue, forKey: "s.v") + encoder.encodeInt32(id, forKey: "s.i") + case .default: + encoder.encodeInt32(PeerMessageSoundValue.default.rawValue, forKey: "s.v") + } + } + + public static func ==(lhs: PeerMessageSound, rhs: PeerMessageSound) -> Bool { + switch lhs { + case .none: + if case .none = rhs { + return true + } else { + return false + } + case let .bundledModern(id): + if case .bundledModern(id) = rhs { + return true + } else { + return false + } + case let .bundledClassic(id): + if case .bundledClassic(id) = rhs { + return true + } else { + return false + } + case .default: + if case .default = rhs { + return true + } else { + return false + } + } + } +} + +public enum PeerNotificationDisplayPreviews { + case `default` + case show + case hide + + static func decodeInline(_ decoder: PostboxDecoder) -> PeerNotificationDisplayPreviews { + switch decoder.decodeInt32ForKey("p.v", orElse: 0) { + case 0: + return .default + case 1: + return .show + case 2: + return .hide + default: + assertionFailure() + return .default + } + } + + func encodeInline(_ encoder: PostboxEncoder) { + switch self { + case .default: + encoder.encodeInt32(0, forKey: "p.v") + case .show: + encoder.encodeInt32(1, forKey: "p.v") + case .hide: + encoder.encodeInt32(2, forKey: "p.v") + } + } +} + +public final class TelegramPeerNotificationSettings: PeerNotificationSettings, Equatable { + public let muteState: PeerMuteState + public let messageSound: PeerMessageSound + public let displayPreviews: PeerNotificationDisplayPreviews + + public static var defaultSettings: TelegramPeerNotificationSettings { + return TelegramPeerNotificationSettings(muteState: .unmuted, messageSound: .default, displayPreviews: .default) + } + + public var isRemovedFromTotalUnreadCount: Bool { + switch self.muteState { + case .unmuted: + return false + case .muted: + return true + case .default: + return false + } + } + + public var behavior: PeerNotificationSettingsBehavior { + if case let .muted(untilTimestamp) = self.muteState, untilTimestamp < Int32.max { + return .reset(atTimestamp: untilTimestamp, toValue: self.withUpdatedMuteState(.unmuted)) + } else { + return .none + } + } + + public init(muteState: PeerMuteState, messageSound: PeerMessageSound, displayPreviews: PeerNotificationDisplayPreviews) { + self.muteState = muteState + self.messageSound = messageSound + self.displayPreviews = displayPreviews + } + + public init(decoder: PostboxDecoder) { + self.muteState = PeerMuteState.decodeInline(decoder) + self.messageSound = PeerMessageSound.decodeInline(decoder) + self.displayPreviews = PeerNotificationDisplayPreviews.decodeInline(decoder) + } + + public func encode(_ encoder: PostboxEncoder) { + self.muteState.encodeInline(encoder) + self.messageSound.encodeInline(encoder) + self.displayPreviews.encodeInline(encoder) + } + + public func isEqual(to: PeerNotificationSettings) -> Bool { + if let to = to as? TelegramPeerNotificationSettings { + return self == to + } else { + return false + } + } + + public func withUpdatedMuteState(_ muteState: PeerMuteState) -> TelegramPeerNotificationSettings { + return TelegramPeerNotificationSettings(muteState: muteState, messageSound: self.messageSound, displayPreviews: self.displayPreviews) + } + + public func withUpdatedMessageSound(_ messageSound: PeerMessageSound) -> TelegramPeerNotificationSettings { + return TelegramPeerNotificationSettings(muteState: self.muteState, messageSound: messageSound, displayPreviews: self.displayPreviews) + } + + public func withUpdatedDisplayPreviews(_ displayPreviews: PeerNotificationDisplayPreviews) -> TelegramPeerNotificationSettings { + return TelegramPeerNotificationSettings(muteState: self.muteState, messageSound: self.messageSound, displayPreviews: displayPreviews) + } + + public static func ==(lhs: TelegramPeerNotificationSettings, rhs: TelegramPeerNotificationSettings) -> Bool { + return lhs.muteState == rhs.muteState && lhs.messageSound == rhs.messageSound && lhs.displayPreviews == rhs.displayPreviews + } +} diff --git a/submodules/TelegramCore/TelegramCore/TelegramSecretChat.swift b/submodules/SyncCore/Sources/TelegramSecretChat.swift similarity index 93% rename from submodules/TelegramCore/TelegramCore/TelegramSecretChat.swift rename to submodules/SyncCore/Sources/TelegramSecretChat.swift index 7b31ce958c..aa5e6a2933 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramSecretChat.swift +++ b/submodules/SyncCore/Sources/TelegramSecretChat.swift @@ -67,11 +67,11 @@ public final class TelegramSecretChat: Peer { } } - func withUpdatedEmbeddedState(_ embeddedState: SecretChatEmbeddedPeerState) -> TelegramSecretChat { + public func withUpdatedEmbeddedState(_ embeddedState: SecretChatEmbeddedPeerState) -> TelegramSecretChat { return TelegramSecretChat(id: self.id, creationDate: self.creationDate, regularPeerId: self.regularPeerId, accessHash: self.accessHash, role: self.role, embeddedState: embeddedState, messageAutoremoveTimeout: self.messageAutoremoveTimeout) } - func withUpdatedMessageAutoremoveTimeout(_ messageAutoremoveTimeout: Int32?) -> TelegramSecretChat { + public func withUpdatedMessageAutoremoveTimeout(_ messageAutoremoveTimeout: Int32?) -> TelegramSecretChat { return TelegramSecretChat(id: self.id, creationDate: self.creationDate, regularPeerId: self.regularPeerId, accessHash: self.accessHash, role: self.role, embeddedState: self.embeddedState, messageAutoremoveTimeout: messageAutoremoveTimeout) } } @@ -111,7 +111,7 @@ public final class CachedSecretChatData: CachedPeerData { } } - func withUpdatedPeerStatusSettings(_ peerStatusSettings: PeerStatusSettings) -> CachedSecretChatData { + public func withUpdatedPeerStatusSettings(_ peerStatusSettings: PeerStatusSettings) -> CachedSecretChatData { return CachedSecretChatData(peerStatusSettings: peerStatusSettings) } } diff --git a/submodules/SyncCore/Sources/TelegramTheme.swift b/submodules/SyncCore/Sources/TelegramTheme.swift new file mode 100644 index 0000000000..640005bff7 --- /dev/null +++ b/submodules/SyncCore/Sources/TelegramTheme.swift @@ -0,0 +1,77 @@ +import Postbox + +public final class TelegramTheme: OrderedItemListEntryContents, Equatable { + public let id: Int64 + public let accessHash: Int64 + public let slug: String + public let title: String + public let file: TelegramMediaFile? + public let isCreator: Bool + public let isDefault: Bool + public let installCount: Int32 + + public init(id: Int64, accessHash: Int64, slug: String, title: String, file: TelegramMediaFile?, isCreator: Bool, isDefault: Bool, installCount: Int32) { + self.id = id + self.accessHash = accessHash + self.slug = slug + self.title = title + self.file = file + self.isCreator = isCreator + self.isDefault = isDefault + self.installCount = installCount + } + + public init(decoder: PostboxDecoder) { + self.id = decoder.decodeInt64ForKey("id", orElse: 0) + self.accessHash = decoder.decodeInt64ForKey("accessHash", orElse: 0) + self.slug = decoder.decodeStringForKey("slug", orElse: "") + self.title = decoder.decodeStringForKey("title", orElse: "") + self.file = decoder.decodeObjectForKey("file", decoder: { TelegramMediaFile(decoder: $0) }) as? TelegramMediaFile + self.isCreator = decoder.decodeInt32ForKey("isCreator", orElse: 0) != 0 + self.isDefault = decoder.decodeInt32ForKey("isDefault", orElse: 0) != 0 + self.installCount = decoder.decodeInt32ForKey("installCount", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt64(self.id, forKey: "id") + encoder.encodeInt64(self.accessHash, forKey: "accessHash") + encoder.encodeString(self.slug, forKey: "slug") + encoder.encodeString(self.title, forKey: "title") + if let file = self.file { + encoder.encodeObject(file, forKey: "file") + } else { + encoder.encodeNil(forKey: "file") + } + encoder.encodeInt32(self.isCreator ? 1 : 0, forKey: "isCreator") + encoder.encodeInt32(self.isDefault ? 1 : 0, forKey: "isDefault") + encoder.encodeInt32(self.installCount, forKey: "installCount") + } + + public static func ==(lhs: TelegramTheme, rhs: TelegramTheme) -> Bool { + if lhs.id != rhs.id { + return false + } + if lhs.accessHash != rhs.accessHash { + return false + } + if lhs.slug != rhs.slug { + return false + } + if lhs.title != rhs.title { + return false + } + if lhs.file?.id != rhs.file?.id { + return false + } + if lhs.isCreator != rhs.isCreator { + return false + } + if lhs.isDefault != rhs.isDefault { + return false + } + if lhs.installCount != rhs.installCount { + return false + } + return true + } +} diff --git a/submodules/SyncCore/Sources/TelegramUser.swift b/submodules/SyncCore/Sources/TelegramUser.swift new file mode 100644 index 0000000000..ee7b0880f5 --- /dev/null +++ b/submodules/SyncCore/Sources/TelegramUser.swift @@ -0,0 +1,255 @@ +import Postbox + +public struct UserInfoFlags: OptionSet { + public var rawValue: Int32 + + public init() { + self.rawValue = 0 + } + + public init(rawValue: Int32) { + self.rawValue = rawValue + } + + public static let isVerified = UserInfoFlags(rawValue: (1 << 0)) + public static let isSupport = UserInfoFlags(rawValue: (1 << 1)) + public static let isScam = UserInfoFlags(rawValue: (1 << 2)) +} + +public struct BotUserInfoFlags: OptionSet { + public var rawValue: Int32 + + public init() { + self.rawValue = 0 + } + + public init(rawValue: Int32) { + self.rawValue = rawValue + } + + public static let hasAccessToChatHistory = BotUserInfoFlags(rawValue: (1 << 0)) + public static let worksWithGroups = BotUserInfoFlags(rawValue: (1 << 1)) + public static let requiresGeolocationForInlineRequests = BotUserInfoFlags(rawValue: (1 << 2)) +} + +public struct BotUserInfo: PostboxCoding, Equatable { + public let flags: BotUserInfoFlags + public let inlinePlaceholder: String? + + public init(flags: BotUserInfoFlags, inlinePlaceholder: String?) { + self.flags = flags + self.inlinePlaceholder = inlinePlaceholder + } + + public init(decoder: PostboxDecoder) { + self.flags = BotUserInfoFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0)) + self.inlinePlaceholder = decoder.decodeOptionalStringForKey("ip") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.flags.rawValue, forKey: "f") + if let inlinePlaceholder = self.inlinePlaceholder { + encoder.encodeString(inlinePlaceholder, forKey: "ip") + } else { + encoder.encodeNil(forKey: "ip") + } + } +} + +public final class TelegramUser: Peer { + public let id: PeerId + public let accessHash: TelegramPeerAccessHash? + public let firstName: String? + public let lastName: String? + public let username: String? + public let phone: String? + public let photo: [TelegramMediaImageRepresentation] + public let botInfo: BotUserInfo? + public let restrictionInfo: PeerAccessRestrictionInfo? + public let flags: UserInfoFlags + + public var nameOrPhone: String { + if let firstName = self.firstName { + if let lastName = self.lastName { + return "\(firstName) \(lastName)" + } else { + return firstName + } + } else if let lastName = self.lastName { + return lastName + } else if let phone = self.phone, !phone.isEmpty { + return phone + } else { + return "" + } + } + + public var shortNameOrPhone: String { + if let firstName = self.firstName { + return firstName + } else if let lastName = self.lastName { + return lastName + } else if let phone = self.phone, !phone.isEmpty { + return phone + } else { + return "" + } + } + + public var indexName: PeerIndexNameRepresentation { + return .personName(first: self.firstName ?? "", last: self.lastName ?? "", addressName: self.username, phoneNumber: self.phone) + } + + public let associatedPeerId: PeerId? = nil + public let notificationSettingsPeerId: PeerId? = nil + + public init(id: PeerId, accessHash: TelegramPeerAccessHash?, firstName: String?, lastName: String?, username: String?, phone: String?, photo: [TelegramMediaImageRepresentation], botInfo: BotUserInfo?, restrictionInfo: PeerAccessRestrictionInfo?, flags: UserInfoFlags) { + self.id = id + self.accessHash = accessHash + self.firstName = firstName + self.lastName = lastName + self.username = username + self.phone = phone + self.photo = photo + self.botInfo = botInfo + self.restrictionInfo = restrictionInfo + self.flags = flags + } + + public init(decoder: PostboxDecoder) { + self.id = PeerId(decoder.decodeInt64ForKey("i", orElse: 0)) + + let accessHash: Int64 = decoder.decodeInt64ForKey("ah", orElse: 0) + let accessHashType: Int32 = decoder.decodeInt32ForKey("aht", orElse: 0) + if accessHash != 0 { + if accessHashType == 0 { + self.accessHash = .personal(accessHash) + } else { + self.accessHash = .genericPublic(accessHash) + } + } else { + self.accessHash = nil + } + + self.firstName = decoder.decodeOptionalStringForKey("fn") + self.lastName = decoder.decodeOptionalStringForKey("ln") + + self.username = decoder.decodeOptionalStringForKey("un") + self.phone = decoder.decodeOptionalStringForKey("p") + + self.photo = decoder.decodeObjectArrayForKey("ph") + + if let botInfo = decoder.decodeObjectForKey("bi", decoder: { return BotUserInfo(decoder: $0) }) as? BotUserInfo { + self.botInfo = botInfo + } else { + self.botInfo = nil + } + + self.restrictionInfo = decoder.decodeObjectForKey("ri") as? PeerAccessRestrictionInfo + + self.flags = UserInfoFlags(rawValue: decoder.decodeInt32ForKey("fl", orElse: 0)) + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt64(self.id.toInt64(), forKey: "i") + + if let accessHash = self.accessHash { + switch accessHash { + case let .personal(value): + encoder.encodeInt64(value, forKey: "ah") + encoder.encodeInt32(0, forKey: "aht") + case let .genericPublic(value): + encoder.encodeInt64(value, forKey: "ah") + encoder.encodeInt32(1, forKey: "aht") + } + } + + if let firstName = self.firstName { + encoder.encodeString(firstName, forKey: "fn") + } + if let lastName = self.lastName { + encoder.encodeString(lastName, forKey: "ln") + } + + if let username = self.username { + encoder.encodeString(username, forKey: "un") + } + if let phone = self.phone { + encoder.encodeString(phone, forKey: "p") + } + + encoder.encodeObjectArray(self.photo, forKey: "ph") + + if let botInfo = self.botInfo { + encoder.encodeObject(botInfo, forKey: "bi") + } else { + encoder.encodeNil(forKey: "bi") + } + + if let restrictionInfo = self.restrictionInfo { + encoder.encodeObject(restrictionInfo, forKey: "ri") + } else { + encoder.encodeNil(forKey: "ri") + } + + encoder.encodeInt32(self.flags.rawValue, forKey: "fl") + } + + public func isEqual(_ other: Peer) -> Bool { + if let other = other as? TelegramUser { + if self.id != other.id { + return false + } + if self.accessHash != other.accessHash { + return false + } + if self.firstName != other.firstName { + return false + } + if self.lastName != other.lastName { + return false + } + if self.phone != other.phone { + return false + } + if self.photo.count != other.photo.count { + return false + } + for i in 0 ..< self.photo.count { + if self.photo[i] != other.photo[i] { + return false + } + } + if self.botInfo != other.botInfo { + return false + } + if self.restrictionInfo != other.restrictionInfo { + return false + } + + if self.flags != other.flags { + return false + } + + return true + } else { + return false + } + } + + public func withUpdatedUsername(_ username:String?) -> TelegramUser { + return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: self.firstName, lastName: self.lastName, username: username, phone: self.phone, photo: self.photo, botInfo: self.botInfo, restrictionInfo: self.restrictionInfo, flags: self.flags) + } + + public func withUpdatedNames(firstName: String?, lastName: String?) -> TelegramUser { + return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: firstName, lastName: lastName, username: self.username, phone: self.phone, photo: self.photo, botInfo: self.botInfo, restrictionInfo: self.restrictionInfo, flags: self.flags) + } + + public func withUpdatedPhone(_ phone: String?) -> TelegramUser { + return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: self.firstName, lastName: self.lastName, username: self.username, phone: phone, photo: self.photo, botInfo: self.botInfo, restrictionInfo: self.restrictionInfo, flags: self.flags) + } + + public func withUpdatedPhoto(_ representations: [TelegramMediaImageRepresentation]) -> TelegramUser { + return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: self.firstName, lastName: self.lastName, username: self.username, phone: phone, photo: representations, botInfo: self.botInfo, restrictionInfo: self.restrictionInfo, flags: self.flags) + } +} diff --git a/submodules/SyncCore/Sources/TelegramUserPresence.swift b/submodules/SyncCore/Sources/TelegramUserPresence.swift new file mode 100644 index 0000000000..e220adde73 --- /dev/null +++ b/submodules/SyncCore/Sources/TelegramUserPresence.swift @@ -0,0 +1,116 @@ +import Postbox + +public enum UserPresenceStatus: Comparable, PostboxCoding { + case none + case present(until: Int32) + case recently + case lastWeek + case lastMonth + + public static func <(lhs: UserPresenceStatus, rhs: UserPresenceStatus) -> Bool { + switch lhs { + case .none: + switch rhs { + case .none: + return false + case .lastMonth, .lastWeek, .recently, .present: + return true + } + case let .present(until): + switch rhs { + case .none: + return false + case let .present(rhsUntil): + return until < rhsUntil + case .lastWeek, .lastMonth, .recently: + return false + } + case .recently: + switch rhs { + case .none, .lastWeek, .lastMonth, .recently: + return false + case .present: + return true + } + case .lastWeek: + switch rhs { + case .none, .lastMonth, .lastWeek: + return false + case .present, .recently: + return true + } + case .lastMonth: + switch rhs { + case .none, .lastMonth: + return false + case .present, .recently, lastWeek: + return true + } + } + } + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("v", orElse: 0) { + case 0: + self = .none + case 1: + self = .present(until: decoder.decodeInt32ForKey("t", orElse: 0)) + case 2: + self = .recently + case 3: + self = .lastWeek + case 4: + self = .lastMonth + default: + self = .none + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case .none: + encoder.encodeInt32(0, forKey: "v") + case let .present(timestamp): + encoder.encodeInt32(1, forKey: "v") + encoder.encodeInt32(timestamp, forKey: "t") + case .recently: + encoder.encodeInt32(2, forKey: "v") + case .lastWeek: + encoder.encodeInt32(3, forKey: "v") + case .lastMonth: + encoder.encodeInt32(4, forKey: "v") + } + } +} + +public final class TelegramUserPresence: PeerPresence, Equatable { + public let status: UserPresenceStatus + public let lastActivity: Int32 + + public init(status: UserPresenceStatus, lastActivity: Int32) { + self.status = status + self.lastActivity = lastActivity + } + + public init(decoder: PostboxDecoder) { + self.status = UserPresenceStatus(decoder: decoder) + self.lastActivity = decoder.decodeInt32ForKey("la", orElse: 0) + } + + public func encode(_ encoder: PostboxEncoder) { + self.status.encode(encoder) + encoder.encodeInt32(self.lastActivity, forKey: "la") + } + + public static func ==(lhs: TelegramUserPresence, rhs: TelegramUserPresence) -> Bool { + return lhs.status == rhs.status && lhs.lastActivity == rhs.lastActivity + } + + public func isEqual(to: PeerPresence) -> Bool { + if let to = to as? TelegramUserPresence { + return self == to + } else { + return false + } + } +} diff --git a/submodules/SyncCore/Sources/TelegramWallpaper.swift b/submodules/SyncCore/Sources/TelegramWallpaper.swift new file mode 100644 index 0000000000..da472ffd7a --- /dev/null +++ b/submodules/SyncCore/Sources/TelegramWallpaper.swift @@ -0,0 +1,154 @@ +import Postbox + +public struct WallpaperSettings: PostboxCoding, Equatable { + public let blur: Bool + public let motion: Bool + public let color: Int32? + public let intensity: Int32? + + public init(blur: Bool = false, motion: Bool = false, color: Int32? = nil, intensity: Int32? = nil) { + self.blur = blur + self.motion = motion + self.color = color + self.intensity = intensity + } + + public init(decoder: PostboxDecoder) { + self.blur = decoder.decodeInt32ForKey("b", orElse: 0) != 0 + self.motion = decoder.decodeInt32ForKey("m", orElse: 0) != 0 + self.color = decoder.decodeOptionalInt32ForKey("c") + self.intensity = decoder.decodeOptionalInt32ForKey("i") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.blur ? 1 : 0, forKey: "b") + encoder.encodeInt32(self.motion ? 1 : 0, forKey: "m") + if let color = self.color { + encoder.encodeInt32(color, forKey: "c") + } else { + encoder.encodeNil(forKey: "c") + } + if let intensity = self.intensity { + encoder.encodeInt32(intensity, forKey: "i") + } else { + encoder.encodeNil(forKey: "i") + } + } +} + +public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { + case builtin(WallpaperSettings) + case color(Int32) + case image([TelegramMediaImageRepresentation], WallpaperSettings) + case file(id: Int64, accessHash: Int64, isCreator: Bool, isDefault: Bool, isPattern: Bool, isDark: Bool, slug: String, file: TelegramMediaFile, settings: WallpaperSettings) + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("v", orElse: 0) { + case 0: + let settings = decoder.decodeObjectForKey("settings", decoder: { WallpaperSettings(decoder: $0) }) as? WallpaperSettings ?? WallpaperSettings() + self = .builtin(settings) + case 1: + self = .color(decoder.decodeInt32ForKey("c", orElse: 0)) + case 2: + let settings = decoder.decodeObjectForKey("settings", decoder: { WallpaperSettings(decoder: $0) }) as? WallpaperSettings ?? WallpaperSettings() + self = .image(decoder.decodeObjectArrayWithDecoderForKey("i"), settings) + case 3: + let settings = decoder.decodeObjectForKey("settings", decoder: { WallpaperSettings(decoder: $0) }) as? WallpaperSettings ?? WallpaperSettings() + if let file = decoder.decodeObjectForKey("file", decoder: { TelegramMediaFile(decoder: $0) }) as? TelegramMediaFile { + self = .file(id: decoder.decodeInt64ForKey("id", orElse: 0), accessHash: decoder.decodeInt64ForKey("accessHash", orElse: 0), isCreator: decoder.decodeInt32ForKey("isCreator", orElse: 0) != 0, isDefault: decoder.decodeInt32ForKey("isDefault", orElse: 0) != 0, isPattern: decoder.decodeInt32ForKey("isPattern", orElse: 0) != 0, isDark: decoder.decodeInt32ForKey("isDark", orElse: 0) != 0, slug: decoder.decodeStringForKey("slug", orElse: ""), file: file, settings: settings) + } else { + self = .color(0xffffff) + } + + default: + assertionFailure() + self = .color(0xffffff) + } + } + + public var hasWallpaper: Bool { + switch self { + case .color: + return false + default: + return true + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .builtin(settings): + encoder.encodeInt32(0, forKey: "v") + encoder.encodeObject(settings, forKey: "settings") + case let .color(color): + encoder.encodeInt32(1, forKey: "v") + encoder.encodeInt32(color, forKey: "c") + case let .image(representations, settings): + encoder.encodeInt32(2, forKey: "v") + encoder.encodeObjectArray(representations, forKey: "i") + encoder.encodeObject(settings, forKey: "settings") + case let .file(id, accessHash, isCreator, isDefault, isPattern, isDark, slug, file, settings): + encoder.encodeInt32(3, forKey: "v") + encoder.encodeInt64(id, forKey: "id") + encoder.encodeInt64(accessHash, forKey: "accessHash") + encoder.encodeInt32(isCreator ? 1 : 0, forKey: "isCreator") + encoder.encodeInt32(isDefault ? 1 : 0, forKey: "isDefault") + encoder.encodeInt32(isPattern ? 1 : 0, forKey: "isPattern") + encoder.encodeInt32(isDark ? 1 : 0, forKey: "isDark") + encoder.encodeString(slug, forKey: "slug") + encoder.encodeObject(file, forKey: "file") + encoder.encodeObject(settings, forKey: "settings") + } + } + + public static func ==(lhs: TelegramWallpaper, rhs: TelegramWallpaper) -> Bool { + switch lhs { + case let .builtin(settings): + if case .builtin(settings) = rhs { + return true + } else { + return false + } + case let .color(color): + if case .color(color) = rhs { + return true + } else { + return false + } + case let .image(representations, settings): + if case .image(representations, settings) = rhs { + return true + } else { + return false + } + case let .file(lhsId, _, lhsIsCreator, lhsIsDefault, lhsIsPattern, lhsIsDark, lhsSlug, lhsFile, lhsSettings): + if case let .file(rhsId, _, rhsIsCreator, rhsIsDefault, rhsIsPattern, rhsIsDark, rhsSlug, rhsFile, rhsSettings) = rhs, lhsId == rhsId, lhsIsCreator == rhsIsCreator, lhsIsDefault == rhsIsDefault, lhsIsPattern == rhsIsPattern, lhsIsDark == rhsIsDark, lhsSlug == rhsSlug, lhsFile == rhsFile, lhsSettings == rhsSettings { + return true + } else { + return false + } + } + } + + public var settings: WallpaperSettings? { + switch self { + case let .builtin(settings), let .image(_, settings), let .file(_, _, _, _, _, _, _, _, settings): + return settings + default: + return nil + } + } + + public func withUpdatedSettings(_ settings: WallpaperSettings) -> TelegramWallpaper { + switch self { + case .builtin: + return .builtin(settings) + case .color: + return self + case let .image(representations, _): + return .image(representations, settings) + case let .file(id, accessHash, isCreator, isDefault, isPattern, isDark, slug, file, _): + return .file(id: id, accessHash: accessHash, isCreator: isCreator, isDefault: isDefault, isPattern: settings.color != nil ? true : isPattern, isDark: isDark, slug: slug, file: file, settings: settings) + } + } +} diff --git a/submodules/SyncCore/Sources/TemporaryTwoStepPasswordToken.swift b/submodules/SyncCore/Sources/TemporaryTwoStepPasswordToken.swift new file mode 100644 index 0000000000..00ddcd8b3b --- /dev/null +++ b/submodules/SyncCore/Sources/TemporaryTwoStepPasswordToken.swift @@ -0,0 +1,29 @@ +import Postbox + +public struct TemporaryTwoStepPasswordToken: PostboxCoding, Equatable { + public let token: Data + public let validUntilDate: Int32 + public let requiresBiometrics: Bool + + public init(token: Data, validUntilDate: Int32, requiresBiometrics: Bool) { + self.token = token + self.validUntilDate = validUntilDate + self.requiresBiometrics = requiresBiometrics + } + + public init(decoder: PostboxDecoder) { + self.token = decoder.decodeBytesForKey("t")!.makeData() + self.validUntilDate = decoder.decodeInt32ForKey("d", orElse: 0) + self.requiresBiometrics = decoder.decodeInt32ForKey("b", orElse: 0) != 0 + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeBytes(MemoryBuffer(data: self.token), forKey: "t") + encoder.encodeInt32(self.validUntilDate, forKey: "d") + encoder.encodeInt32(self.requiresBiometrics ? 1 : 0, forKey: "b") + } + + public static func ==(lhs: TemporaryTwoStepPasswordToken, rhs: TemporaryTwoStepPasswordToken) -> Bool { + return lhs.token == rhs.token && lhs.validUntilDate == rhs.validUntilDate && lhs.requiresBiometrics == rhs.requiresBiometrics + } +} diff --git a/submodules/SyncCore/Sources/TextEntitiesMessageAttribute.swift b/submodules/SyncCore/Sources/TextEntitiesMessageAttribute.swift new file mode 100644 index 0000000000..79fe68a5ed --- /dev/null +++ b/submodules/SyncCore/Sources/TextEntitiesMessageAttribute.swift @@ -0,0 +1,155 @@ +import Postbox + +public enum MessageTextEntityType: Equatable { + public typealias CustomEntityType = Int32 + + case Unknown + case Mention + case Hashtag + case BotCommand + case Url + case Email + case Bold + case Italic + case Code + case Pre + case TextUrl(url: String) + case TextMention(peerId: PeerId) + case PhoneNumber + case Strikethrough + case BlockQuote + case Underline + case Custom(type: CustomEntityType) +} + +public struct MessageTextEntity: PostboxCoding, Equatable { + public let range: Range + public let type: MessageTextEntityType + + public init(range: Range, type: MessageTextEntityType) { + self.range = range + self.type = type + } + + public init(decoder: PostboxDecoder) { + self.range = Int(decoder.decodeInt32ForKey("start", orElse: 0)) ..< Int(decoder.decodeInt32ForKey("end", orElse: 0)) + let type: Int32 = decoder.decodeInt32ForKey("_rawValue", orElse: 0) + switch type { + case 1: + self.type = .Mention + case 2: + self.type = .Hashtag + case 3: + self.type = .BotCommand + case 4: + self.type = .Url + case 5: + self.type = .Email + case 6: + self.type = .Bold + case 7: + self.type = .Italic + case 8: + self.type = .Code + case 9: + self.type = .Pre + case 10: + self.type = .TextUrl(url: decoder.decodeStringForKey("url", orElse: "")) + case 11: + self.type = .TextMention(peerId: PeerId(decoder.decodeInt64ForKey("peerId", orElse: 0))) + case 12: + self.type = .PhoneNumber + case 13: + self.type = .Strikethrough + case 14: + self.type = .BlockQuote + case 15: + self.type = .Underline + case Int32.max: + self.type = .Custom(type: decoder.decodeInt32ForKey("type", orElse: 0)) + default: + self.type = .Unknown + } + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(Int32(self.range.lowerBound), forKey: "start") + encoder.encodeInt32(Int32(self.range.upperBound), forKey: "end") + switch self.type { + case .Unknown: + encoder.encodeInt32(0, forKey: "_rawValue") + case .Mention: + encoder.encodeInt32(1, forKey: "_rawValue") + case .Hashtag: + encoder.encodeInt32(2, forKey: "_rawValue") + case .BotCommand: + encoder.encodeInt32(3, forKey: "_rawValue") + case .Url: + encoder.encodeInt32(4, forKey: "_rawValue") + case .Email: + encoder.encodeInt32(5, forKey: "_rawValue") + case .Bold: + encoder.encodeInt32(6, forKey: "_rawValue") + case .Italic: + encoder.encodeInt32(7, forKey: "_rawValue") + case .Code: + encoder.encodeInt32(8, forKey: "_rawValue") + case .Pre: + encoder.encodeInt32(9, forKey: "_rawValue") + case let .TextUrl(url): + encoder.encodeInt32(10, forKey: "_rawValue") + encoder.encodeString(url, forKey: "url") + case let .TextMention(peerId): + encoder.encodeInt32(11, forKey: "_rawValue") + encoder.encodeInt64(peerId.toInt64(), forKey: "peerId") + case .PhoneNumber: + encoder.encodeInt32(12, forKey: "_rawValue") + case .Strikethrough: + encoder.encodeInt32(13, forKey: "_rawValue") + case .BlockQuote: + encoder.encodeInt32(14, forKey: "_rawValue") + case .Underline: + encoder.encodeInt32(15, forKey: "_rawValue") + case let .Custom(type): + encoder.encodeInt32(Int32.max, forKey: "_rawValue") + encoder.encodeInt32(type, forKey: "type") + } + } + + public static func ==(lhs: MessageTextEntity, rhs: MessageTextEntity) -> Bool { + return lhs.range == rhs.range && lhs.type == rhs.type + } +} + +public class TextEntitiesMessageAttribute: MessageAttribute, Equatable { + public let entities: [MessageTextEntity] + + public var associatedPeerIds: [PeerId] { + var result: [PeerId] = [] + for entity in entities { + switch entity.type { + case let .TextMention(peerId): + result.append(peerId) + default: + break + } + } + return result + } + + public init(entities: [MessageTextEntity]) { + self.entities = entities + } + + required public init(decoder: PostboxDecoder) { + self.entities = decoder.decodeObjectArrayWithDecoderForKey("entities") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObjectArray(self.entities, forKey: "entities") + } + + public static func ==(lhs: TextEntitiesMessageAttribute, rhs: TextEntitiesMessageAttribute) -> Bool { + return lhs.entities == rhs.entities + } +} diff --git a/submodules/SyncCore/Sources/ThemeSettings.swift b/submodules/SyncCore/Sources/ThemeSettings.swift new file mode 100644 index 0000000000..4f4cfc163e --- /dev/null +++ b/submodules/SyncCore/Sources/ThemeSettings.swift @@ -0,0 +1,33 @@ +import Postbox + +public final class ThemeSettings: PreferencesEntry, Equatable { + public let currentTheme: TelegramTheme? + + public init(currentTheme: TelegramTheme?) { + self.currentTheme = currentTheme + } + + public init(decoder: PostboxDecoder) { + self.currentTheme = decoder.decodeObjectForKey("t", decoder: { TelegramTheme(decoder: $0) }) as? TelegramTheme + } + + public func encode(_ encoder: PostboxEncoder) { + if let currentTheme = currentTheme { + encoder.encodeObject(currentTheme, forKey: "t") + } else { + encoder.encodeNil(forKey: "t") + } + } + + public func isEqual(to: PreferencesEntry) -> Bool { + if let to = to as? ThemeSettings { + return self == to + } else { + return false + } + } + + public static func ==(lhs: ThemeSettings, rhs: ThemeSettings) -> Bool { + return lhs.currentTheme == rhs.currentTheme + } +} diff --git a/submodules/SyncCore/Sources/UnauthorizedAccountState.swift b/submodules/SyncCore/Sources/UnauthorizedAccountState.swift new file mode 100644 index 0000000000..677f9bb838 --- /dev/null +++ b/submodules/SyncCore/Sources/UnauthorizedAccountState.swift @@ -0,0 +1,344 @@ +import Postbox + +private enum SentAuthorizationCodeTypeValue: Int32 { + case otherSession = 0 + case sms = 1 + case call = 2 + case flashCall = 3 +} + +public enum SentAuthorizationCodeType: PostboxCoding, Equatable { + case otherSession(length: Int32) + case sms(length: Int32) + case call(length: Int32) + case flashCall(pattern: String) + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("v", orElse: 0) { + case SentAuthorizationCodeTypeValue.otherSession.rawValue: + self = .otherSession(length: decoder.decodeInt32ForKey("l", orElse: 0)) + case SentAuthorizationCodeTypeValue.sms.rawValue: + self = .sms(length: decoder.decodeInt32ForKey("l", orElse: 0)) + case SentAuthorizationCodeTypeValue.call.rawValue: + self = .call(length: decoder.decodeInt32ForKey("l", orElse: 0)) + case SentAuthorizationCodeTypeValue.flashCall.rawValue: + self = .flashCall(pattern: decoder.decodeStringForKey("p", orElse: "")) + default: + preconditionFailure() + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case let .otherSession(length): + encoder.encodeInt32(SentAuthorizationCodeTypeValue.otherSession.rawValue, forKey: "v") + encoder.encodeInt32(length, forKey: "l") + case let .sms(length): + encoder.encodeInt32(SentAuthorizationCodeTypeValue.sms.rawValue, forKey: "v") + encoder.encodeInt32(length, forKey: "l") + case let .call(length): + encoder.encodeInt32(SentAuthorizationCodeTypeValue.call.rawValue, forKey: "v") + encoder.encodeInt32(length, forKey: "l") + case let .flashCall(pattern): + encoder.encodeInt32(SentAuthorizationCodeTypeValue.flashCall.rawValue, forKey: "v") + encoder.encodeString(pattern, forKey: "p") + } + } + + public static func ==(lhs: SentAuthorizationCodeType, rhs: SentAuthorizationCodeType) -> Bool { + switch lhs { + case let .otherSession(length): + if case .otherSession(length) = rhs { + return true + } else { + return false + } + case let .sms(length): + if case .sms(length) = rhs { + return true + } else { + return false + } + case let .call(length): + if case .call(length) = rhs { + return true + } else { + return false + } + case let .flashCall(pattern): + if case .flashCall(pattern) = rhs { + return true + } else { + return false + } + } + } +} + +public enum AuthorizationCodeNextType: Int32 { + case sms = 0 + case call = 1 + case flashCall = 2 +} + +private enum UnauthorizedAccountStateContentsValue: Int32 { + case empty = 0 + case phoneEntry = 1 + case confirmationCodeEntry = 2 + case passwordEntry = 3 + case signUp = 5 + case passwordRecovery = 6 + case awaitingAccountReset = 7 +} + +public struct UnauthorizedAccountTermsOfService: PostboxCoding, Equatable { + public let id: String + public let text: String + public let entities: [MessageTextEntity] + public let ageConfirmation: Int32? + + public init(id: String, text: String, entities: [MessageTextEntity], ageConfirmation: Int32?) { + self.id = id + self.text = text + self.entities = entities + self.ageConfirmation = ageConfirmation + } + + public init(decoder: PostboxDecoder) { + self.id = decoder.decodeStringForKey("id", orElse: "") + self.text = decoder.decodeStringForKey("text", orElse: "") + self.entities = (try? decoder.decodeObjectArrayWithCustomDecoderForKey("entities", decoder: { MessageTextEntity(decoder: $0) })) ?? [] + self.ageConfirmation = decoder.decodeOptionalInt32ForKey("ageConfirmation") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeString(self.id, forKey: "id") + encoder.encodeString(self.text, forKey: "text") + encoder.encodeObjectArray(self.entities, forKey: "entities") + if let ageConfirmation = self.ageConfirmation { + encoder.encodeInt32(ageConfirmation, forKey: "ageConfirmation") + } else { + encoder.encodeNil(forKey: "ageConfirmation") + } + } +} + +public enum UnauthorizedAccountStateContents: PostboxCoding, Equatable { + case empty + case phoneEntry(countryCode: Int32, number: String) + case confirmationCodeEntry(number: String, type: SentAuthorizationCodeType, hash: String, timeout: Int32?, nextType: AuthorizationCodeNextType?, syncContacts: Bool) + case passwordEntry(hint: String, number: String?, code: String?, suggestReset: Bool, syncContacts: Bool) + case passwordRecovery(hint: String, number: String?, code: String?, emailPattern: String, syncContacts: Bool) + case awaitingAccountReset(protectedUntil: Int32, number: String?, syncContacts: Bool) + case signUp(number: String, codeHash: String, firstName: String, lastName: String, termsOfService: UnauthorizedAccountTermsOfService?, syncContacts: Bool) + + public init(decoder: PostboxDecoder) { + switch decoder.decodeInt32ForKey("v", orElse: 0) { + case UnauthorizedAccountStateContentsValue.empty.rawValue: + self = .empty + case UnauthorizedAccountStateContentsValue.phoneEntry.rawValue: + self = .phoneEntry(countryCode: decoder.decodeInt32ForKey("cc", orElse: 1), number: decoder.decodeStringForKey("n", orElse: "")) + case UnauthorizedAccountStateContentsValue.confirmationCodeEntry.rawValue: + var nextType: AuthorizationCodeNextType? + if let value = decoder.decodeOptionalInt32ForKey("nt") { + nextType = AuthorizationCodeNextType(rawValue: value) + } + self = .confirmationCodeEntry(number: decoder.decodeStringForKey("num", orElse: ""), type: decoder.decodeObjectForKey("t", decoder: { SentAuthorizationCodeType(decoder: $0) }) as! SentAuthorizationCodeType, hash: decoder.decodeStringForKey("h", orElse: ""), timeout: decoder.decodeOptionalInt32ForKey("tm"), nextType: nextType, syncContacts: decoder.decodeInt32ForKey("syncContacts", orElse: 1) != 0) + case UnauthorizedAccountStateContentsValue.passwordEntry.rawValue: + self = .passwordEntry(hint: decoder.decodeStringForKey("h", orElse: ""), number: decoder.decodeOptionalStringForKey("n"), code: decoder.decodeOptionalStringForKey("c"), suggestReset: decoder.decodeInt32ForKey("suggestReset", orElse: 0) != 0, syncContacts: decoder.decodeInt32ForKey("syncContacts", orElse: 1) != 0) + case UnauthorizedAccountStateContentsValue.passwordRecovery.rawValue: + self = .passwordRecovery(hint: decoder.decodeStringForKey("hint", orElse: ""), number: decoder.decodeOptionalStringForKey("number"), code: decoder.decodeOptionalStringForKey("code"), emailPattern: decoder.decodeStringForKey("emailPattern", orElse: ""), syncContacts: decoder.decodeInt32ForKey("syncContacts", orElse: 1) != 0) + case UnauthorizedAccountStateContentsValue.awaitingAccountReset.rawValue: + self = .awaitingAccountReset(protectedUntil: decoder.decodeInt32ForKey("protectedUntil", orElse: 0), number: decoder.decodeOptionalStringForKey("number"), syncContacts: decoder.decodeInt32ForKey("syncContacts", orElse: 1) != 0) + case UnauthorizedAccountStateContentsValue.signUp.rawValue: + self = .signUp(number: decoder.decodeStringForKey("n", orElse: ""), codeHash: decoder.decodeStringForKey("h", orElse: ""), firstName: decoder.decodeStringForKey("f", orElse: ""), lastName: decoder.decodeStringForKey("l", orElse: ""), termsOfService: decoder.decodeObjectForKey("tos", decoder: { UnauthorizedAccountTermsOfService(decoder: $0) }) as? UnauthorizedAccountTermsOfService, syncContacts: decoder.decodeInt32ForKey("syncContacts", orElse: 1) != 0) + default: + assertionFailure() + self = .empty + } + } + + public func encode(_ encoder: PostboxEncoder) { + switch self { + case .empty: + encoder.encodeInt32(UnauthorizedAccountStateContentsValue.empty.rawValue, forKey: "v") + case let .phoneEntry(countryCode, number): + encoder.encodeInt32(UnauthorizedAccountStateContentsValue.phoneEntry.rawValue, forKey: "v") + encoder.encodeInt32(countryCode, forKey: "cc") + encoder.encodeString(number, forKey: "n") + case let .confirmationCodeEntry(number, type, hash, timeout, nextType, syncContacts): + encoder.encodeInt32(UnauthorizedAccountStateContentsValue.confirmationCodeEntry.rawValue, forKey: "v") + encoder.encodeString(number, forKey: "num") + encoder.encodeObject(type, forKey: "t") + encoder.encodeString(hash, forKey: "h") + if let timeout = timeout { + encoder.encodeInt32(timeout, forKey: "tm") + } else { + encoder.encodeNil(forKey: "tm") + } + if let nextType = nextType { + encoder.encodeInt32(nextType.rawValue, forKey: "nt") + } else { + encoder.encodeNil(forKey: "nt") + } + encoder.encodeInt32(syncContacts ? 1 : 0, forKey: "syncContacts") + case let .passwordEntry(hint, number, code, suggestReset, syncContacts): + encoder.encodeInt32(UnauthorizedAccountStateContentsValue.passwordEntry.rawValue, forKey: "v") + encoder.encodeString(hint, forKey: "h") + if let number = number { + encoder.encodeString(number, forKey: "n") + } else { + encoder.encodeNil(forKey: "n") + } + if let code = code { + encoder.encodeString(code, forKey: "c") + } else { + encoder.encodeNil(forKey: "c") + } + encoder.encodeInt32(suggestReset ? 1 : 0, forKey: "suggestReset") + encoder.encodeInt32(syncContacts ? 1 : 0, forKey: "syncContacts") + case let .passwordRecovery(hint, number, code, emailPattern, syncContacts): + encoder.encodeInt32(UnauthorizedAccountStateContentsValue.passwordRecovery.rawValue, forKey: "v") + encoder.encodeString(hint, forKey: "hint") + if let number = number { + encoder.encodeString(number, forKey: "number") + } else { + encoder.encodeNil(forKey: "number") + } + if let code = code { + encoder.encodeString(code, forKey: "code") + } else { + encoder.encodeNil(forKey: "code") + } + encoder.encodeString(emailPattern, forKey: "emailPattern") + encoder.encodeInt32(syncContacts ? 1 : 0, forKey: "syncContacts") + case let .awaitingAccountReset(protectedUntil, number, syncContacts): + encoder.encodeInt32(UnauthorizedAccountStateContentsValue.awaitingAccountReset.rawValue, forKey: "v") + encoder.encodeInt32(protectedUntil, forKey: "protectedUntil") + if let number = number { + encoder.encodeString(number, forKey: "number") + } else { + encoder.encodeNil(forKey: "number") + } + encoder.encodeInt32(syncContacts ? 1 : 0, forKey: "syncContacts") + case let .signUp(number, codeHash, firstName, lastName, termsOfService, syncContacts): + encoder.encodeInt32(UnauthorizedAccountStateContentsValue.signUp.rawValue, forKey: "v") + encoder.encodeString(number, forKey: "n") + encoder.encodeString(codeHash, forKey: "h") + encoder.encodeString(firstName, forKey: "f") + encoder.encodeString(lastName, forKey: "l") + if let termsOfService = termsOfService { + encoder.encodeObject(termsOfService, forKey: "tos") + } else { + encoder.encodeNil(forKey: "tos") + } + encoder.encodeInt32(syncContacts ? 1 : 0, forKey: "syncContacts") + } + } + + public static func ==(lhs: UnauthorizedAccountStateContents, rhs: UnauthorizedAccountStateContents) -> Bool { + switch lhs { + case .empty: + if case .empty = rhs { + return true + } else { + return false + } + case let .phoneEntry(countryCode, number): + if case .phoneEntry(countryCode, number) = rhs { + return true + } else { + return false + } + case let .confirmationCodeEntry(lhsNumber, lhsType, lhsHash, lhsTimeout, lhsNextType, lhsSyncContacts): + if case let .confirmationCodeEntry(rhsNumber, rhsType, rhsHash, rhsTimeout, rhsNextType, rhsSyncContacts) = rhs { + if lhsNumber != rhsNumber { + return false + } + if lhsType != rhsType { + return false + } + if lhsHash != rhsHash { + return false + } + if lhsTimeout != rhsTimeout { + return false + } + if lhsNextType != rhsNextType { + return false + } + if lhsSyncContacts != rhsSyncContacts { + return false + } + return true + } else { + return false + } + case let .passwordEntry(lhsHint, lhsNumber, lhsCode, lhsSuggestReset, lhsSyncContacts): + if case let .passwordEntry(rhsHint, rhsNumber, rhsCode, rhsSuggestReset, rhsSyncContacts) = rhs { + return lhsHint == rhsHint && lhsNumber == rhsNumber && lhsCode == rhsCode && lhsSuggestReset == rhsSuggestReset && lhsSyncContacts == rhsSyncContacts + } else { + return false + } + case let .passwordRecovery(lhsHint, lhsNumber, lhsCode, lhsEmailPattern, lhsSyncContacts): + if case let .passwordRecovery(rhsHint, rhsNumber, rhsCode, rhsEmailPattern, rhsSyncContacts) = rhs { + return lhsHint == rhsHint && lhsNumber == rhsNumber && lhsCode == rhsCode && lhsEmailPattern == rhsEmailPattern && lhsSyncContacts == rhsSyncContacts + } else { + return false + } + case let .awaitingAccountReset(lhsProtectedUntil, lhsNumber, lhsSyncContacts): + if case let .awaitingAccountReset(rhsProtectedUntil, rhsNumber, rhsSyncContacts) = rhs { + return lhsProtectedUntil == rhsProtectedUntil && lhsNumber == rhsNumber && lhsSyncContacts == rhsSyncContacts + } else { + return false + } + case let .signUp(number, codeHash, firstName, lastName, termsOfService, syncContacts): + if case .signUp(number, codeHash, firstName, lastName, termsOfService, syncContacts) = rhs { + return true + } else { + return false + } + } + } +} + +public final class UnauthorizedAccountState: AccountState { + public let isTestingEnvironment: Bool + public let masterDatacenterId: Int32 + public let contents: UnauthorizedAccountStateContents + + public init(isTestingEnvironment: Bool, masterDatacenterId: Int32, contents: UnauthorizedAccountStateContents) { + self.isTestingEnvironment = isTestingEnvironment + self.masterDatacenterId = masterDatacenterId + self.contents = contents + } + + public init(decoder: PostboxDecoder) { + self.isTestingEnvironment = decoder.decodeInt32ForKey("isTestingEnvironment", orElse: 0) != 0 + self.masterDatacenterId = decoder.decodeInt32ForKey("dc", orElse: 0) + self.contents = decoder.decodeObjectForKey("c", decoder: { UnauthorizedAccountStateContents(decoder: $0) }) as! UnauthorizedAccountStateContents + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeInt32(self.isTestingEnvironment ? 1 : 0, forKey: "isTestingEnvironment") + encoder.encodeInt32(self.masterDatacenterId, forKey: "dc") + encoder.encodeObject(self.contents, forKey: "c") + } + + public func equalsTo(_ other: AccountState) -> Bool { + guard let other = other as? UnauthorizedAccountState else { + return false + } + if self.isTestingEnvironment != other.isTestingEnvironment { + return false + } + if self.masterDatacenterId != other.masterDatacenterId { + return false + } + if self.contents != other.contents { + return false + } + return true + } +} + diff --git a/submodules/SyncCore/Sources/UpdateMessageReactionsAction.swift b/submodules/SyncCore/Sources/UpdateMessageReactionsAction.swift new file mode 100644 index 0000000000..7a944f58bf --- /dev/null +++ b/submodules/SyncCore/Sources/UpdateMessageReactionsAction.swift @@ -0,0 +1,20 @@ +import Postbox + +public final class UpdateMessageReactionsAction: PendingMessageActionData { + public init() { + } + + public init(decoder: PostboxDecoder) { + } + + public func encode(_ encoder: PostboxEncoder) { + } + + public func isEqual(to: PendingMessageActionData) -> Bool { + if let _ = to as? UpdateMessageReactionsAction { + return true + } else { + return false + } + } +} diff --git a/submodules/TelegramCore/TelegramCore/ViewCountMessageAttribute.swift b/submodules/SyncCore/Sources/ViewCountMessageAttribute.swift similarity index 94% rename from submodules/TelegramCore/TelegramCore/ViewCountMessageAttribute.swift rename to submodules/SyncCore/Sources/ViewCountMessageAttribute.swift index fe75c429f2..3faa295fcd 100644 --- a/submodules/TelegramCore/TelegramCore/ViewCountMessageAttribute.swift +++ b/submodules/SyncCore/Sources/ViewCountMessageAttribute.swift @@ -10,7 +10,7 @@ public class ViewCountMessageAttribute: MessageAttribute { public var associatedMessageIds: [MessageId] = [] - init(count: Int) { + public init(count: Int) { self.count = count } diff --git a/submodules/SyncCore/Sources/VoipConfiguration.swift b/submodules/SyncCore/Sources/VoipConfiguration.swift new file mode 100644 index 0000000000..ae87506c63 --- /dev/null +++ b/submodules/SyncCore/Sources/VoipConfiguration.swift @@ -0,0 +1,43 @@ +import Foundation +#if os(macOS) +import PostboxMac +#else +import Postbox +#endif + +public enum VoiceCallP2PMode: Int32 { + case never = 0 + case contacts = 1 + case always = 2 +} + +public struct VoipConfiguration: PreferencesEntry, Equatable { + public var serializedData: String? + + public static var defaultValue: VoipConfiguration { + return VoipConfiguration(serializedData: nil) + } + + init(serializedData: String?) { + self.serializedData = serializedData + } + + public init(decoder: PostboxDecoder) { + self.serializedData = decoder.decodeOptionalStringForKey("serializedData") + } + + public func encode(_ encoder: PostboxEncoder) { + if let serializedData = self.serializedData { + encoder.encodeString(serializedData, forKey: "serializedData") + } else { + encoder.encodeNil(forKey: "serializedData") + } + } + + public func isEqual(to: PreferencesEntry) -> Bool { + guard let to = to as? VoipConfiguration else { + return false + } + return self == to + } +} diff --git a/submodules/SyncCore/Sources/WalletCollection.swift b/submodules/SyncCore/Sources/WalletCollection.swift new file mode 100644 index 0000000000..1a01954871 --- /dev/null +++ b/submodules/SyncCore/Sources/WalletCollection.swift @@ -0,0 +1,55 @@ +import Postbox + +public struct WalletCollectionItem: Equatable, PostboxCoding { + public let info: Data + public var exportCompleted: Bool + public var state: Data? + + public init(info: Data, exportCompleted: Bool, state: Data?) { + self.info = info + self.exportCompleted = exportCompleted + self.state = state + } + + public init(decoder: PostboxDecoder) { + self.info = decoder.decodeDataForKey("info") ?? Data() + self.exportCompleted = decoder.decodeInt32ForKey("exportCompleted", orElse: 0) != 0 + self.state = decoder.decodeDataForKey("state") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeData(self.info, forKey: "info") + encoder.encodeInt32(self.exportCompleted ? 1 : 0, forKey: "exportCompleted") + if let state = self.state { + encoder.encodeData(state, forKey: "state") + } else { + encoder.encodeNil(forKey: "state") + } + } +} + +public struct WalletCollection: PreferencesEntry { + public var wallets: [WalletCollectionItem] + + public init(wallets: [WalletCollectionItem]) { + self.wallets = wallets + } + + public init(decoder: PostboxDecoder) { + self.wallets = decoder.decodeObjectArrayWithDecoderForKey("wallets") + } + + public func encode(_ encoder: PostboxEncoder) { + encoder.encodeObjectArray(self.wallets, forKey: "wallets") + } + + public func isEqual(to: PreferencesEntry) -> Bool { + guard let other = to as? WalletCollection else { + return false + } + if self.wallets != other.wallets { + return false + } + return true + } +} diff --git a/submodules/TelegramCore/TelegramCore/WasScheduledMessageAttribute.swift b/submodules/SyncCore/Sources/WasScheduledMessageAttribute.swift similarity index 100% rename from submodules/TelegramCore/TelegramCore/WasScheduledMessageAttribute.swift rename to submodules/SyncCore/Sources/WasScheduledMessageAttribute.swift diff --git a/submodules/TelegramAnimatedStickerNode/BUCK b/submodules/TelegramAnimatedStickerNode/BUCK index e9b1668421..efb6000d45 100644 --- a/submodules/TelegramAnimatedStickerNode/BUCK +++ b/submodules/TelegramAnimatedStickerNode/BUCK @@ -8,6 +8,7 @@ static_library( deps = [ "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/StickerResources:StickerResources", "//submodules/MediaResources:MediaResources", "//submodules/Tuples:Tuples", diff --git a/submodules/TelegramAnimatedStickerNode/Sources/AnimatedStickerUtils.swift b/submodules/TelegramAnimatedStickerNode/Sources/AnimatedStickerUtils.swift index 9c102bef62..01b15180e1 100644 --- a/submodules/TelegramAnimatedStickerNode/Sources/AnimatedStickerUtils.swift +++ b/submodules/TelegramAnimatedStickerNode/Sources/AnimatedStickerUtils.swift @@ -4,6 +4,7 @@ import SwiftSignalKit import Postbox import Display import TelegramCore +import SyncCore import Compression import GZip import RLottieBinding diff --git a/submodules/TelegramAnimatedStickerNode/Sources/TelegramAnimatedStickerNode.swift b/submodules/TelegramAnimatedStickerNode/Sources/TelegramAnimatedStickerNode.swift index 291ead72e2..7ac6fcf1f4 100644 --- a/submodules/TelegramAnimatedStickerNode/Sources/TelegramAnimatedStickerNode.swift +++ b/submodules/TelegramAnimatedStickerNode/Sources/TelegramAnimatedStickerNode.swift @@ -3,6 +3,7 @@ import AnimatedStickerNode import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import MediaResources import StickerResources diff --git a/submodules/TelegramAudio/BUCK b/submodules/TelegramAudio/BUCK index 45103e009a..cbe05806ce 100644 --- a/submodules/TelegramAudio/BUCK +++ b/submodules/TelegramAudio/BUCK @@ -6,7 +6,7 @@ static_library( "Sources/**/*.swift", ]), deps = [ - "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#dynamic", + "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", ], frameworks = [ "$SDKROOT/System/Library/Frameworks/Foundation.framework", diff --git a/submodules/TelegramBaseController/BUCK b/submodules/TelegramBaseController/BUCK index c9bdcf90c8..3da1da6331 100644 --- a/submodules/TelegramBaseController/BUCK +++ b/submodules/TelegramBaseController/BUCK @@ -9,6 +9,7 @@ static_library( "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/AsyncDisplayKit:AsyncDisplayKit#shared", "//submodules/Display:Display#shared", "//submodules/AvatarNode:AvatarNode", diff --git a/submodules/TelegramBaseController/Sources/LocationBroadcastActionSheetItem.swift b/submodules/TelegramBaseController/Sources/LocationBroadcastActionSheetItem.swift index 5d46787ba2..8357a9cebd 100644 --- a/submodules/TelegramBaseController/Sources/LocationBroadcastActionSheetItem.swift +++ b/submodules/TelegramBaseController/Sources/LocationBroadcastActionSheetItem.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import AccountContext diff --git a/submodules/TelegramBaseController/Sources/LocationBroadcastNavigationAccessoryPanel.swift b/submodules/TelegramBaseController/Sources/LocationBroadcastNavigationAccessoryPanel.swift index 155ee96945..d75b0ee04f 100644 --- a/submodules/TelegramBaseController/Sources/LocationBroadcastNavigationAccessoryPanel.swift +++ b/submodules/TelegramBaseController/Sources/LocationBroadcastNavigationAccessoryPanel.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/TelegramBaseController/Sources/MediaNavigationAccessoryContainerNode.swift b/submodules/TelegramBaseController/Sources/MediaNavigationAccessoryContainerNode.swift index 1afdbc34b3..8c2612dec1 100644 --- a/submodules/TelegramBaseController/Sources/MediaNavigationAccessoryContainerNode.swift +++ b/submodules/TelegramBaseController/Sources/MediaNavigationAccessoryContainerNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext diff --git a/submodules/TelegramBaseController/Sources/MediaNavigationAccessoryHeaderNode.swift b/submodules/TelegramBaseController/Sources/MediaNavigationAccessoryHeaderNode.swift index a7305120e6..31d6158e39 100644 --- a/submodules/TelegramBaseController/Sources/MediaNavigationAccessoryHeaderNode.swift +++ b/submodules/TelegramBaseController/Sources/MediaNavigationAccessoryHeaderNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import UniversalMediaPlayer diff --git a/submodules/TelegramBaseController/Sources/MediaNavigationAccessoryPanel.swift b/submodules/TelegramBaseController/Sources/MediaNavigationAccessoryPanel.swift index 07c6a01c08..18534db138 100644 --- a/submodules/TelegramBaseController/Sources/MediaNavigationAccessoryPanel.swift +++ b/submodules/TelegramBaseController/Sources/MediaNavigationAccessoryPanel.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import AccountContext final class MediaNavigationAccessoryPanel: ASDisplayNode { diff --git a/submodules/TelegramBaseController/Sources/TelegramBaseController.swift b/submodules/TelegramBaseController/Sources/TelegramBaseController.swift index dd7c326179..b09f37ef9a 100644 --- a/submodules/TelegramBaseController/Sources/TelegramBaseController.swift +++ b/submodules/TelegramBaseController/Sources/TelegramBaseController.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramCallsUI/Sources/CallController.swift b/submodules/TelegramCallsUI/Sources/CallController.swift index 4962c6db50..413d6da510 100644 --- a/submodules/TelegramCallsUI/Sources/CallController.swift +++ b/submodules/TelegramCallsUI/Sources/CallController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/TelegramCallsUI/Sources/CallControllerNode.swift b/submodules/TelegramCallsUI/Sources/CallControllerNode.swift index 4f43b871e3..76496d7ce5 100644 --- a/submodules/TelegramCallsUI/Sources/CallControllerNode.swift +++ b/submodules/TelegramCallsUI/Sources/CallControllerNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/TelegramCallsUI/Sources/CallFeedbackController.swift b/submodules/TelegramCallsUI/Sources/CallFeedbackController.swift index ea63da505b..59d3dd954f 100644 --- a/submodules/TelegramCallsUI/Sources/CallFeedbackController.swift +++ b/submodules/TelegramCallsUI/Sources/CallFeedbackController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/TelegramCallsUI/Sources/CallKitIntegration.swift b/submodules/TelegramCallsUI/Sources/CallKitIntegration.swift index 9b700b800d..11addb26ea 100644 --- a/submodules/TelegramCallsUI/Sources/CallKitIntegration.swift +++ b/submodules/TelegramCallsUI/Sources/CallKitIntegration.swift @@ -5,6 +5,7 @@ import Intents import AVFoundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import AppBundle diff --git a/submodules/TelegramCallsUI/Sources/CallRatingController.swift b/submodules/TelegramCallsUI/Sources/CallRatingController.swift index 10da6c947f..6568afccea 100644 --- a/submodules/TelegramCallsUI/Sources/CallRatingController.swift +++ b/submodules/TelegramCallsUI/Sources/CallRatingController.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramVoip import AccountContext diff --git a/submodules/TelegramCallsUI/Sources/CallSuggestTabController.swift b/submodules/TelegramCallsUI/Sources/CallSuggestTabController.swift index 46af7bb168..ba5f52d066 100644 --- a/submodules/TelegramCallsUI/Sources/CallSuggestTabController.swift +++ b/submodules/TelegramCallsUI/Sources/CallSuggestTabController.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import AccountContext diff --git a/submodules/TelegramCallsUI/Sources/PresentationCall.swift b/submodules/TelegramCallsUI/Sources/PresentationCall.swift index 33fca00b04..3b06930cd1 100644 --- a/submodules/TelegramCallsUI/Sources/PresentationCall.swift +++ b/submodules/TelegramCallsUI/Sources/PresentationCall.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Display import AVFoundation diff --git a/submodules/TelegramCallsUI/Sources/PresentationCallManager.swift b/submodules/TelegramCallsUI/Sources/PresentationCallManager.swift index 2cc8b842a6..d25d195b37 100644 --- a/submodules/TelegramCallsUI/Sources/PresentationCallManager.swift +++ b/submodules/TelegramCallsUI/Sources/PresentationCallManager.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Display import DeviceAccess diff --git a/submodules/TelegramCore/BUCK b/submodules/TelegramCore/BUCK index c5c9dec010..4fcd08a641 100644 --- a/submodules/TelegramCore/BUCK +++ b/submodules/TelegramCore/BUCK @@ -21,6 +21,7 @@ framework( "//submodules/MtProtoKit:MtProtoKit#shared", "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Postbox:Postbox#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/CloudData:CloudData", "//submodules/EncryptionProvider:EncryptionProvider", ], diff --git a/submodules/TelegramCore/TelegramCore/Account.swift b/submodules/TelegramCore/TelegramCore/Account.swift index d20ac58ce5..8509fd3300 100644 --- a/submodules/TelegramCore/TelegramCore/Account.swift +++ b/submodules/TelegramCore/TelegramCore/Account.swift @@ -15,100 +15,10 @@ import Foundation #endif import UIKit #endif + +import SyncCore import EncryptionProvider -public protocol AccountState: PostboxCoding { - func equalsTo(_ other: AccountState) -> Bool -} - -public func ==(lhs: AccountState, rhs: AccountState) -> Bool { - return lhs.equalsTo(rhs) -} - -public class AuthorizedAccountState: AccountState { - public final class State: PostboxCoding, Equatable, CustomStringConvertible { - let pts: Int32 - let qts: Int32 - let date: Int32 - let seq: Int32 - - init(pts: Int32, qts: Int32, date: Int32, seq: Int32) { - self.pts = pts - self.qts = qts - self.date = date - self.seq = seq - } - - public init(decoder: PostboxDecoder) { - self.pts = decoder.decodeInt32ForKey("pts", orElse: 0) - self.qts = decoder.decodeInt32ForKey("qts", orElse: 0) - self.date = decoder.decodeInt32ForKey("date", orElse: 0) - self.seq = decoder.decodeInt32ForKey("seq", orElse: 0) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.pts, forKey: "pts") - encoder.encodeInt32(self.qts, forKey: "qts") - encoder.encodeInt32(self.date, forKey: "date") - encoder.encodeInt32(self.seq, forKey: "seq") - } - - public var description: String { - return "(pts: \(pts), qts: \(qts), seq: \(seq), date: \(date))" - } - } - - let isTestingEnvironment: Bool - let masterDatacenterId: Int32 - let peerId: PeerId - - let state: State? - - public required init(decoder: PostboxDecoder) { - self.isTestingEnvironment = decoder.decodeInt32ForKey("isTestingEnvironment", orElse: 0) != 0 - self.masterDatacenterId = decoder.decodeInt32ForKey("masterDatacenterId", orElse: 0) - self.peerId = PeerId(decoder.decodeInt64ForKey("peerId", orElse: 0)) - self.state = decoder.decodeObjectForKey("state", decoder: { return State(decoder: $0) }) as? State - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.isTestingEnvironment ? 1 : 0, forKey: "isTestingEnvironment") - encoder.encodeInt32(self.masterDatacenterId, forKey: "masterDatacenterId") - encoder.encodeInt64(self.peerId.toInt64(), forKey: "peerId") - if let state = self.state { - encoder.encodeObject(state, forKey: "state") - } - } - - public init(isTestingEnvironment: Bool, masterDatacenterId: Int32, peerId: PeerId, state: State?) { - self.isTestingEnvironment = isTestingEnvironment - self.masterDatacenterId = masterDatacenterId - self.peerId = peerId - self.state = state - } - - func changedState(_ state: State) -> AuthorizedAccountState { - return AuthorizedAccountState(isTestingEnvironment: self.isTestingEnvironment, masterDatacenterId: self.masterDatacenterId, peerId: self.peerId, state: state) - } - - public func equalsTo(_ other: AccountState) -> Bool { - if let other = other as? AuthorizedAccountState { - return self.isTestingEnvironment == other.isTestingEnvironment && self.masterDatacenterId == other.masterDatacenterId && - self.peerId == other.peerId && - self.state == other.state - } else { - return false - } - } -} - -public func ==(lhs: AuthorizedAccountState.State, rhs: AuthorizedAccountState.State) -> Bool { - return lhs.pts == rhs.pts && - lhs.qts == rhs.qts && - lhs.date == rhs.date && - lhs.seq == rhs.seq -} - private let accountRecordToActiveKeychainId = Atomic<[AccountRecordId: Int]>(value: [:]) private func makeExclusiveKeychain(id: AccountRecordId, postbox: Postbox) -> Keychain { @@ -243,37 +153,6 @@ public enum AccountResult { case authorized(Account) } -let telegramPostboxSeedConfiguration: SeedConfiguration = { - var messageHoles: [PeerId.Namespace: [MessageId.Namespace: Set]] = [:] - for peerNamespace in peerIdNamespacesWithInitialCloudMessageHoles { - messageHoles[peerNamespace] = [ - Namespaces.Message.Cloud: Set(MessageTags.all) - ] - } - - var globalMessageIdsPeerIdNamespaces = Set() - for peerIdNamespace in [Namespaces.Peer.CloudUser, Namespaces.Peer.CloudGroup] { - globalMessageIdsPeerIdNamespaces.insert(GlobalMessageIdsNamespace(peerIdNamespace: peerIdNamespace, messageIdNamespace: Namespaces.Message.Cloud)) - } - - return SeedConfiguration(globalMessageIdsPeerIdNamespaces: globalMessageIdsPeerIdNamespaces, initializeChatListWithHole: (topLevel: ChatListHole(index: MessageIndex(id: MessageId(peerId: PeerId(namespace: Namespaces.Peer.Empty, id: 0), namespace: Namespaces.Message.Cloud, id: 1), timestamp: Int32.max - 1)), groups: ChatListHole(index: MessageIndex(id: MessageId(peerId: PeerId(namespace: Namespaces.Peer.Empty, id: 0), namespace: Namespaces.Message.Cloud, id: 1), timestamp: Int32.max - 1))), messageHoles: messageHoles, existingMessageTags: MessageTags.all, messageTagsWithSummary: MessageTags.unseenPersonalMessage, existingGlobalMessageTags: GlobalMessageTags.all, peerNamespacesRequiringMessageTextIndex: [Namespaces.Peer.SecretChat], peerSummaryCounterTags: { peer in - if let peer = peer as? TelegramChannel { - switch peer.info { - case .group: - if let addressName = peer.addressName, !addressName.isEmpty { - return [.publicGroups] - } else { - return [.regularChatsAndPrivateGroups] - } - case .broadcast: - return [.channels] - } - } else { - return [.regularChatsAndPrivateGroups] - } - }, additionalChatListIndexNamespace: Namespaces.Message.Cloud, messageNamespacesRequiringGroupStatsValidation: [Namespaces.Message.Cloud], defaultMessageNamespaceReadStates: [Namespaces.Message.Local: .idBased(maxIncomingReadId: 0, maxOutgoingReadId: 0, maxKnownId: 0, count: 0, markedUnread: false)], chatMessagesNamespaces: Set([Namespaces.Message.Cloud, Namespaces.Message.Local, Namespaces.Message.SecretIncoming])) -}() - public enum AccountPreferenceEntriesResult { case progress(Float) case result(String, [ValueBoxKey: PreferencesEntry]) @@ -343,20 +222,6 @@ public func accountLegacyAccessChallengeData(rootPath: String, id: AccountRecord } } -public func accountTransaction(rootPath: String, id: AccountRecordId, encryptionParameters: ValueBoxEncryptionParameters, transaction: @escaping (Transaction) -> T) -> Signal { - let path = "\(rootPath)/\(accountRecordIdPathName(id))" - let postbox = openPostbox(basePath: path + "/postbox", seedConfiguration: telegramPostboxSeedConfiguration, encryptionParameters: encryptionParameters) - return postbox - |> mapToSignal { value -> Signal in - switch value { - case let .postbox(postbox): - return postbox.transaction(transaction) - default: - return .complete() - } - } -} - public func accountWithId(accountManager: AccountManager, networkArguments: NetworkInitializationArguments, id: AccountRecordId, encryptionParameters: ValueBoxEncryptionParameters, supplementary: Bool, rootPath: String, beginWithTestingEnvironment: Bool, backupData: AccountBackupData?, auxiliaryMethods: AccountAuxiliaryMethods, shouldKeepAutoConnection: Bool = true) -> Signal { let path = "\(rootPath)/\(accountRecordIdPathName(id))" @@ -929,43 +794,6 @@ public func decryptedNotificationPayload(account: Account, data: Data) -> Signal } } -public struct AccountBackupData: Codable, Equatable { - public var masterDatacenterId: Int32 - public var peerId: Int64 - public var masterDatacenterKey: Data - public var masterDatacenterKeyId: Int64 -} - -public final class AccountBackupDataAttribute: AccountRecordAttribute, Equatable { - public let data: AccountBackupData? - - public init(data: AccountBackupData?) { - self.data = data - } - - public init(decoder: PostboxDecoder) { - self.data = try? JSONDecoder().decode(AccountBackupData.self, from: decoder.decodeDataForKey("data") ?? Data()) - } - - public func encode(_ encoder: PostboxEncoder) { - if let data = self.data, let serializedData = try? JSONEncoder().encode(data) { - encoder.encodeData(serializedData, forKey: "data") - } - } - - public static func ==(lhs: AccountBackupDataAttribute, rhs: AccountBackupDataAttribute) -> Bool { - return lhs.data == rhs.data - } - - public func isEqual(to: AccountRecordAttribute) -> Bool { - if let to = to as? AccountBackupDataAttribute { - return self == to - } else { - return false - } - } -} - public func accountBackupData(postbox: Postbox) -> Signal { return postbox.transaction { transaction -> AccountBackupData? in guard let state = transaction.getState() as? AuthorizedAccountState else { diff --git a/submodules/TelegramCore/TelegramCore/AccountIntermediateState.swift b/submodules/TelegramCore/TelegramCore/AccountIntermediateState.swift index 56420815fe..a225b50f5f 100644 --- a/submodules/TelegramCore/TelegramCore/AccountIntermediateState.swift +++ b/submodules/TelegramCore/TelegramCore/AccountIntermediateState.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + struct PeerChatInfo { var notificationSettings: PeerNotificationSettings } diff --git a/submodules/TelegramCore/TelegramCore/AccountManager.swift b/submodules/TelegramCore/TelegramCore/AccountManager.swift index b6357d4717..d0c071fe8d 100644 --- a/submodules/TelegramCore/TelegramCore/AccountManager.swift +++ b/submodules/TelegramCore/TelegramCore/AccountManager.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private enum AccountKind { case authorized case unauthorized diff --git a/submodules/TelegramCore/TelegramCore/AccountState.swift b/submodules/TelegramCore/TelegramCore/AccountState.swift index ca57a4b82a..074c926b38 100644 --- a/submodules/TelegramCore/TelegramCore/AccountState.swift +++ b/submodules/TelegramCore/TelegramCore/AccountState.swift @@ -7,128 +7,7 @@ import Foundation import TelegramApi #endif -private enum SentAuthorizationCodeTypeValue: Int32 { - case otherSession = 0 - case sms = 1 - case call = 2 - case flashCall = 3 -} - -public enum SentAuthorizationCodeType: PostboxCoding, Equatable { - case otherSession(length: Int32) - case sms(length: Int32) - case call(length: Int32) - case flashCall(pattern: String) - - public init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("v", orElse: 0) { - case SentAuthorizationCodeTypeValue.otherSession.rawValue: - self = .otherSession(length: decoder.decodeInt32ForKey("l", orElse: 0)) - case SentAuthorizationCodeTypeValue.sms.rawValue: - self = .sms(length: decoder.decodeInt32ForKey("l", orElse: 0)) - case SentAuthorizationCodeTypeValue.call.rawValue: - self = .call(length: decoder.decodeInt32ForKey("l", orElse: 0)) - case SentAuthorizationCodeTypeValue.flashCall.rawValue: - self = .flashCall(pattern: decoder.decodeStringForKey("p", orElse: "")) - default: - preconditionFailure() - } - } - - public func encode(_ encoder: PostboxEncoder) { - switch self { - case let .otherSession(length): - encoder.encodeInt32(SentAuthorizationCodeTypeValue.otherSession.rawValue, forKey: "v") - encoder.encodeInt32(length, forKey: "l") - case let .sms(length): - encoder.encodeInt32(SentAuthorizationCodeTypeValue.sms.rawValue, forKey: "v") - encoder.encodeInt32(length, forKey: "l") - case let .call(length): - encoder.encodeInt32(SentAuthorizationCodeTypeValue.call.rawValue, forKey: "v") - encoder.encodeInt32(length, forKey: "l") - case let .flashCall(pattern): - encoder.encodeInt32(SentAuthorizationCodeTypeValue.flashCall.rawValue, forKey: "v") - encoder.encodeString(pattern, forKey: "p") - } - } - - public static func ==(lhs: SentAuthorizationCodeType, rhs: SentAuthorizationCodeType) -> Bool { - switch lhs { - case let .otherSession(length): - if case .otherSession(length) = rhs { - return true - } else { - return false - } - case let .sms(length): - if case .sms(length) = rhs { - return true - } else { - return false - } - case let .call(length): - if case .call(length) = rhs { - return true - } else { - return false - } - case let .flashCall(pattern): - if case .flashCall(pattern) = rhs { - return true - } else { - return false - } - } - } -} - -public enum AuthorizationCodeNextType: Int32 { - case sms = 0 - case call = 1 - case flashCall = 2 -} - -private enum UnauthorizedAccountStateContentsValue: Int32 { - case empty = 0 - case phoneEntry = 1 - case confirmationCodeEntry = 2 - case passwordEntry = 3 - case signUp = 5 - case passwordRecovery = 6 - case awaitingAccountReset = 7 -} - -public struct UnauthorizedAccountTermsOfService: PostboxCoding, Equatable { - public let id: String - public let text: String - public let entities: [MessageTextEntity] - public let ageConfirmation: Int32? - - init(id: String, text: String, entities: [MessageTextEntity], ageConfirmation: Int32?) { - self.id = id - self.text = text - self.entities = entities - self.ageConfirmation = ageConfirmation - } - - public init(decoder: PostboxDecoder) { - self.id = decoder.decodeStringForKey("id", orElse: "") - self.text = decoder.decodeStringForKey("text", orElse: "") - self.entities = (try? decoder.decodeObjectArrayWithCustomDecoderForKey("entities", decoder: { MessageTextEntity(decoder: $0) })) ?? [] - self.ageConfirmation = decoder.decodeOptionalInt32ForKey("ageConfirmation") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.id, forKey: "id") - encoder.encodeString(self.text, forKey: "text") - encoder.encodeObjectArray(self.entities, forKey: "entities") - if let ageConfirmation = self.ageConfirmation { - encoder.encodeInt32(ageConfirmation, forKey: "ageConfirmation") - } else { - encoder.encodeNil(forKey: "ageConfirmation") - } - } -} +import SyncCore extension UnauthorizedAccountTermsOfService { init?(apiTermsOfService: Api.help.TermsOfService) { @@ -144,225 +23,6 @@ extension UnauthorizedAccountTermsOfService { } } -public enum UnauthorizedAccountStateContents: PostboxCoding, Equatable { - case empty - case phoneEntry(countryCode: Int32, number: String) - case confirmationCodeEntry(number: String, type: SentAuthorizationCodeType, hash: String, timeout: Int32?, nextType: AuthorizationCodeNextType?, syncContacts: Bool) - case passwordEntry(hint: String, number: String?, code: String?, suggestReset: Bool, syncContacts: Bool) - case passwordRecovery(hint: String, number: String?, code: String?, emailPattern: String, syncContacts: Bool) - case awaitingAccountReset(protectedUntil: Int32, number: String?, syncContacts: Bool) - case signUp(number: String, codeHash: String, firstName: String, lastName: String, termsOfService: UnauthorizedAccountTermsOfService?, syncContacts: Bool) - - public init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("v", orElse: 0) { - case UnauthorizedAccountStateContentsValue.empty.rawValue: - self = .empty - case UnauthorizedAccountStateContentsValue.phoneEntry.rawValue: - self = .phoneEntry(countryCode: decoder.decodeInt32ForKey("cc", orElse: 1), number: decoder.decodeStringForKey("n", orElse: "")) - case UnauthorizedAccountStateContentsValue.confirmationCodeEntry.rawValue: - var nextType: AuthorizationCodeNextType? - if let value = decoder.decodeOptionalInt32ForKey("nt") { - nextType = AuthorizationCodeNextType(rawValue: value) - } - self = .confirmationCodeEntry(number: decoder.decodeStringForKey("num", orElse: ""), type: decoder.decodeObjectForKey("t", decoder: { SentAuthorizationCodeType(decoder: $0) }) as! SentAuthorizationCodeType, hash: decoder.decodeStringForKey("h", orElse: ""), timeout: decoder.decodeOptionalInt32ForKey("tm"), nextType: nextType, syncContacts: decoder.decodeInt32ForKey("syncContacts", orElse: 1) != 0) - case UnauthorizedAccountStateContentsValue.passwordEntry.rawValue: - self = .passwordEntry(hint: decoder.decodeStringForKey("h", orElse: ""), number: decoder.decodeOptionalStringForKey("n"), code: decoder.decodeOptionalStringForKey("c"), suggestReset: decoder.decodeInt32ForKey("suggestReset", orElse: 0) != 0, syncContacts: decoder.decodeInt32ForKey("syncContacts", orElse: 1) != 0) - case UnauthorizedAccountStateContentsValue.passwordRecovery.rawValue: - self = .passwordRecovery(hint: decoder.decodeStringForKey("hint", orElse: ""), number: decoder.decodeOptionalStringForKey("number"), code: decoder.decodeOptionalStringForKey("code"), emailPattern: decoder.decodeStringForKey("emailPattern", orElse: ""), syncContacts: decoder.decodeInt32ForKey("syncContacts", orElse: 1) != 0) - case UnauthorizedAccountStateContentsValue.awaitingAccountReset.rawValue: - self = .awaitingAccountReset(protectedUntil: decoder.decodeInt32ForKey("protectedUntil", orElse: 0), number: decoder.decodeOptionalStringForKey("number"), syncContacts: decoder.decodeInt32ForKey("syncContacts", orElse: 1) != 0) - case UnauthorizedAccountStateContentsValue.signUp.rawValue: - self = .signUp(number: decoder.decodeStringForKey("n", orElse: ""), codeHash: decoder.decodeStringForKey("h", orElse: ""), firstName: decoder.decodeStringForKey("f", orElse: ""), lastName: decoder.decodeStringForKey("l", orElse: ""), termsOfService: decoder.decodeObjectForKey("tos", decoder: { UnauthorizedAccountTermsOfService(decoder: $0) }) as? UnauthorizedAccountTermsOfService, syncContacts: decoder.decodeInt32ForKey("syncContacts", orElse: 1) != 0) - default: - assertionFailure() - self = .empty - } - } - - public func encode(_ encoder: PostboxEncoder) { - switch self { - case .empty: - encoder.encodeInt32(UnauthorizedAccountStateContentsValue.empty.rawValue, forKey: "v") - case let .phoneEntry(countryCode, number): - encoder.encodeInt32(UnauthorizedAccountStateContentsValue.phoneEntry.rawValue, forKey: "v") - encoder.encodeInt32(countryCode, forKey: "cc") - encoder.encodeString(number, forKey: "n") - case let .confirmationCodeEntry(number, type, hash, timeout, nextType, syncContacts): - encoder.encodeInt32(UnauthorizedAccountStateContentsValue.confirmationCodeEntry.rawValue, forKey: "v") - encoder.encodeString(number, forKey: "num") - encoder.encodeObject(type, forKey: "t") - encoder.encodeString(hash, forKey: "h") - if let timeout = timeout { - encoder.encodeInt32(timeout, forKey: "tm") - } else { - encoder.encodeNil(forKey: "tm") - } - if let nextType = nextType { - encoder.encodeInt32(nextType.rawValue, forKey: "nt") - } else { - encoder.encodeNil(forKey: "nt") - } - encoder.encodeInt32(syncContacts ? 1 : 0, forKey: "syncContacts") - case let .passwordEntry(hint, number, code, suggestReset, syncContacts): - encoder.encodeInt32(UnauthorizedAccountStateContentsValue.passwordEntry.rawValue, forKey: "v") - encoder.encodeString(hint, forKey: "h") - if let number = number { - encoder.encodeString(number, forKey: "n") - } else { - encoder.encodeNil(forKey: "n") - } - if let code = code { - encoder.encodeString(code, forKey: "c") - } else { - encoder.encodeNil(forKey: "c") - } - encoder.encodeInt32(suggestReset ? 1 : 0, forKey: "suggestReset") - encoder.encodeInt32(syncContacts ? 1 : 0, forKey: "syncContacts") - case let .passwordRecovery(hint, number, code, emailPattern, syncContacts): - encoder.encodeInt32(UnauthorizedAccountStateContentsValue.passwordRecovery.rawValue, forKey: "v") - encoder.encodeString(hint, forKey: "hint") - if let number = number { - encoder.encodeString(number, forKey: "number") - } else { - encoder.encodeNil(forKey: "number") - } - if let code = code { - encoder.encodeString(code, forKey: "code") - } else { - encoder.encodeNil(forKey: "code") - } - encoder.encodeString(emailPattern, forKey: "emailPattern") - encoder.encodeInt32(syncContacts ? 1 : 0, forKey: "syncContacts") - case let .awaitingAccountReset(protectedUntil, number, syncContacts): - encoder.encodeInt32(UnauthorizedAccountStateContentsValue.awaitingAccountReset.rawValue, forKey: "v") - encoder.encodeInt32(protectedUntil, forKey: "protectedUntil") - if let number = number { - encoder.encodeString(number, forKey: "number") - } else { - encoder.encodeNil(forKey: "number") - } - encoder.encodeInt32(syncContacts ? 1 : 0, forKey: "syncContacts") - case let .signUp(number, codeHash, firstName, lastName, termsOfService, syncContacts): - encoder.encodeInt32(UnauthorizedAccountStateContentsValue.signUp.rawValue, forKey: "v") - encoder.encodeString(number, forKey: "n") - encoder.encodeString(codeHash, forKey: "h") - encoder.encodeString(firstName, forKey: "f") - encoder.encodeString(lastName, forKey: "l") - if let termsOfService = termsOfService { - encoder.encodeObject(termsOfService, forKey: "tos") - } else { - encoder.encodeNil(forKey: "tos") - } - encoder.encodeInt32(syncContacts ? 1 : 0, forKey: "syncContacts") - } - } - - public static func ==(lhs: UnauthorizedAccountStateContents, rhs: UnauthorizedAccountStateContents) -> Bool { - switch lhs { - case .empty: - if case .empty = rhs { - return true - } else { - return false - } - case let .phoneEntry(countryCode, number): - if case .phoneEntry(countryCode, number) = rhs { - return true - } else { - return false - } - case let .confirmationCodeEntry(lhsNumber, lhsType, lhsHash, lhsTimeout, lhsNextType, lhsSyncContacts): - if case let .confirmationCodeEntry(rhsNumber, rhsType, rhsHash, rhsTimeout, rhsNextType, rhsSyncContacts) = rhs { - if lhsNumber != rhsNumber { - return false - } - if lhsType != rhsType { - return false - } - if lhsHash != rhsHash { - return false - } - if lhsTimeout != rhsTimeout { - return false - } - if lhsNextType != rhsNextType { - return false - } - if lhsSyncContacts != rhsSyncContacts { - return false - } - return true - } else { - return false - } - case let .passwordEntry(lhsHint, lhsNumber, lhsCode, lhsSuggestReset, lhsSyncContacts): - if case let .passwordEntry(rhsHint, rhsNumber, rhsCode, rhsSuggestReset, rhsSyncContacts) = rhs { - return lhsHint == rhsHint && lhsNumber == rhsNumber && lhsCode == rhsCode && lhsSuggestReset == rhsSuggestReset && lhsSyncContacts == rhsSyncContacts - } else { - return false - } - case let .passwordRecovery(lhsHint, lhsNumber, lhsCode, lhsEmailPattern, lhsSyncContacts): - if case let .passwordRecovery(rhsHint, rhsNumber, rhsCode, rhsEmailPattern, rhsSyncContacts) = rhs { - return lhsHint == rhsHint && lhsNumber == rhsNumber && lhsCode == rhsCode && lhsEmailPattern == rhsEmailPattern && lhsSyncContacts == rhsSyncContacts - } else { - return false - } - case let .awaitingAccountReset(lhsProtectedUntil, lhsNumber, lhsSyncContacts): - if case let .awaitingAccountReset(rhsProtectedUntil, rhsNumber, rhsSyncContacts) = rhs { - return lhsProtectedUntil == rhsProtectedUntil && lhsNumber == rhsNumber && lhsSyncContacts == rhsSyncContacts - } else { - return false - } - case let .signUp(number, codeHash, firstName, lastName, termsOfService, syncContacts): - if case .signUp(number, codeHash, firstName, lastName, termsOfService, syncContacts) = rhs { - return true - } else { - return false - } - } - } -} - -public final class UnauthorizedAccountState: AccountState { - public let isTestingEnvironment: Bool - public let masterDatacenterId: Int32 - public let contents: UnauthorizedAccountStateContents - - public init(isTestingEnvironment: Bool, masterDatacenterId: Int32, contents: UnauthorizedAccountStateContents) { - self.isTestingEnvironment = isTestingEnvironment - self.masterDatacenterId = masterDatacenterId - self.contents = contents - } - - public init(decoder: PostboxDecoder) { - self.isTestingEnvironment = decoder.decodeInt32ForKey("isTestingEnvironment", orElse: 0) != 0 - self.masterDatacenterId = decoder.decodeInt32ForKey("dc", orElse: 0) - self.contents = decoder.decodeObjectForKey("c", decoder: { UnauthorizedAccountStateContents(decoder: $0) }) as! UnauthorizedAccountStateContents - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.isTestingEnvironment ? 1 : 0, forKey: "isTestingEnvironment") - encoder.encodeInt32(self.masterDatacenterId, forKey: "dc") - encoder.encodeObject(self.contents, forKey: "c") - } - - public func equalsTo(_ other: AccountState) -> Bool { - guard let other = other as? UnauthorizedAccountState else { - return false - } - if self.isTestingEnvironment != other.isTestingEnvironment { - return false - } - if self.masterDatacenterId != other.masterDatacenterId { - return false - } - if self.contents != other.contents { - return false - } - return true - } -} - extension SentAuthorizationCodeType { init(apiType: Api.auth.SentCodeType) { switch apiType { diff --git a/submodules/TelegramCore/TelegramCore/AccountStateManagementUtils.swift b/submodules/TelegramCore/TelegramCore/AccountStateManagementUtils.swift index 6a43bcb418..b159425fe9 100644 --- a/submodules/TelegramCore/TelegramCore/AccountStateManagementUtils.swift +++ b/submodules/TelegramCore/TelegramCore/AccountStateManagementUtils.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private func peerIdsFromUpdateGroups(_ groups: [UpdateGroup]) -> Set { var peerIds = Set() diff --git a/submodules/TelegramCore/TelegramCore/AccountStateManager.swift b/submodules/TelegramCore/TelegramCore/AccountStateManager.swift index 99d4597fdf..737c84e78e 100644 --- a/submodules/TelegramCore/TelegramCore/AccountStateManager.swift +++ b/submodules/TelegramCore/TelegramCore/AccountStateManager.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private enum AccountStateManagerOperationContent { case pollDifference(AccountFinalStateEvents) case collectUpdateGroups([UpdateGroup], Double) diff --git a/submodules/TelegramCore/TelegramCore/AccountStateReset.swift b/submodules/TelegramCore/TelegramCore/AccountStateReset.swift index 806fdc791a..3c3f49d531 100644 --- a/submodules/TelegramCore/TelegramCore/AccountStateReset.swift +++ b/submodules/TelegramCore/TelegramCore/AccountStateReset.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private struct LocalChatListEntryRange { var entries: [ChatListNamespaceEntry] var upperBound: ChatListIndex? diff --git a/submodules/TelegramCore/TelegramCore/AccountViewTracker.swift b/submodules/TelegramCore/TelegramCore/AccountViewTracker.swift index 62f6928005..479ba6c3df 100644 --- a/submodules/TelegramCore/TelegramCore/AccountViewTracker.swift +++ b/submodules/TelegramCore/TelegramCore/AccountViewTracker.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public enum CallListViewType { case all case missed diff --git a/submodules/TelegramCore/TelegramCore/AddPeerMember.swift b/submodules/TelegramCore/TelegramCore/AddPeerMember.swift index ccf95ad7d9..693592c196 100644 --- a/submodules/TelegramCore/TelegramCore/AddPeerMember.swift +++ b/submodules/TelegramCore/TelegramCore/AddPeerMember.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public enum AddGroupMemberError { case generic case groupFull diff --git a/submodules/TelegramCore/TelegramCore/AddressNames.swift b/submodules/TelegramCore/TelegramCore/AddressNames.swift index 94fbdbcd16..7a620736ee 100644 --- a/submodules/TelegramCore/TelegramCore/AddressNames.swift +++ b/submodules/TelegramCore/TelegramCore/AddressNames.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public enum AddressNameFormatError { case startsWithUnderscore case endsWithUnderscore diff --git a/submodules/TelegramCore/TelegramCore/ApiGroupOrChannel.swift b/submodules/TelegramCore/TelegramCore/ApiGroupOrChannel.swift index 2aa6d3de04..2822810631 100644 --- a/submodules/TelegramCore/TelegramCore/ApiGroupOrChannel.swift +++ b/submodules/TelegramCore/TelegramCore/ApiGroupOrChannel.swift @@ -8,6 +8,8 @@ import Foundation import TelegramApi #endif +import SyncCore + func imageRepresentationsForApiChatPhoto(_ photo: Api.ChatPhoto) -> [TelegramMediaImageRepresentation] { var representations: [TelegramMediaImageRepresentation] = [] switch photo { diff --git a/submodules/TelegramCore/TelegramCore/ApiUtils.swift b/submodules/TelegramCore/TelegramCore/ApiUtils.swift index 846130ac95..7a0b867860 100644 --- a/submodules/TelegramCore/TelegramCore/ApiUtils.swift +++ b/submodules/TelegramCore/TelegramCore/ApiUtils.swift @@ -1,87 +1,34 @@ import Foundation #if os(macOS) - import PostboxMac - import TelegramApiMac +import PostboxMac +import TelegramApiMac #else - import Postbox - import TelegramApi +import Postbox +import TelegramApi #endif -public enum PeerReference: PostboxCoding, Hashable, Equatable { - case user(id: Int32, accessHash: Int64) - case group(id: Int32) - case channel(id: Int32, accessHash: Int64) - - public init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("_r", orElse: 0) { - case 0: - self = .user(id: decoder.decodeInt32ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0)) - case 1: - self = .group(id: decoder.decodeInt32ForKey("i", orElse: 0)) - case 2: - self = .channel(id: decoder.decodeInt32ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0)) - default: - assertionFailure() - self = .user(id: 0, accessHash: 0) - } - } - - public func encode(_ encoder: PostboxEncoder) { - switch self { - case let .user(id, accessHash): - encoder.encodeInt32(0, forKey: "_r") - encoder.encodeInt32(id, forKey: "i") - encoder.encodeInt64(accessHash, forKey: "h") - case let .group(id): - encoder.encodeInt32(1, forKey: "_r") - encoder.encodeInt32(id, forKey: "i") - case let .channel(id, accessHash): - encoder.encodeInt32(2, forKey: "_r") - encoder.encodeInt32(id, forKey: "i") - encoder.encodeInt64(accessHash, forKey: "h") - } - } - +import SyncCore + +extension PeerReference { var id: PeerId { switch self { - case let .user(id, _): - return PeerId(namespace: Namespaces.Peer.CloudUser, id: id) - case let .group(id): - return PeerId(namespace: Namespaces.Peer.CloudGroup, id: id) - case let .channel(id, _): - return PeerId(namespace: Namespaces.Peer.CloudChannel, id: id) - } - } - - public init?(_ peer: Peer) { - switch peer { - case let user as TelegramUser: - if let accessHash = user.accessHash { - self = .user(id: user.id.id, accessHash: accessHash.value) - } else { - return nil - } - case let group as TelegramGroup: - self = .group(id: group.id.id) - case let channel as TelegramChannel: - if let accessHash = channel.accessHash { - self = .channel(id: channel.id.id, accessHash: accessHash.value) - } else { - return nil - } - default: - return nil + case let .user(id, _): + return PeerId(namespace: Namespaces.Peer.CloudUser, id: id) + case let .group(id): + return PeerId(namespace: Namespaces.Peer.CloudGroup, id: id) + case let .channel(id, _): + return PeerId(namespace: Namespaces.Peer.CloudChannel, id: id) } } var inputPeer: Api.InputPeer { switch self { - case let .user(id, accessHash): - return .inputPeerUser(userId: id, accessHash: accessHash) - case let .group(id): - return .inputPeerChat(chatId: id) - case let .channel(id, accessHash): - return .inputPeerChannel(channelId: id, accessHash: accessHash) + case let .user(id, accessHash): + return .inputPeerUser(userId: id, accessHash: accessHash) + case let .group(id): + return .inputPeerChat(chatId: id) + case let .channel(id, accessHash): + return .inputPeerChannel(channelId: id, accessHash: accessHash) } } @@ -104,35 +51,35 @@ public enum PeerReference: PostboxCoding, Hashable, Equatable { func forceApiInputPeer(_ peer: Peer) -> Api.InputPeer? { switch peer { - case let user as TelegramUser: - return Api.InputPeer.inputPeerUser(userId: user.id.id, accessHash: user.accessHash?.value ?? 0) - case let group as TelegramGroup: - return Api.InputPeer.inputPeerChat(chatId: group.id.id) - case let channel as TelegramChannel: - if let accessHash = channel.accessHash { - return Api.InputPeer.inputPeerChannel(channelId: channel.id.id, accessHash: accessHash.value) - } else { - return nil - } - default: + case let user as TelegramUser: + return Api.InputPeer.inputPeerUser(userId: user.id.id, accessHash: user.accessHash?.value ?? 0) + case let group as TelegramGroup: + return Api.InputPeer.inputPeerChat(chatId: group.id.id) + case let channel as TelegramChannel: + if let accessHash = channel.accessHash { + return Api.InputPeer.inputPeerChannel(channelId: channel.id.id, accessHash: accessHash.value) + } else { return nil + } + default: + return nil } } func apiInputPeer(_ peer: Peer) -> Api.InputPeer? { switch peer { - case let user as TelegramUser where user.accessHash != nil: - return Api.InputPeer.inputPeerUser(userId: user.id.id, accessHash: user.accessHash!.value) - case let group as TelegramGroup: - return Api.InputPeer.inputPeerChat(chatId: group.id.id) - case let channel as TelegramChannel: - if let accessHash = channel.accessHash { - return Api.InputPeer.inputPeerChannel(channelId: channel.id.id, accessHash: accessHash.value) - } else { - return nil - } - default: + case let user as TelegramUser where user.accessHash != nil: + return Api.InputPeer.inputPeerUser(userId: user.id.id, accessHash: user.accessHash!.value) + case let group as TelegramGroup: + return Api.InputPeer.inputPeerChat(chatId: group.id.id) + case let channel as TelegramChannel: + if let accessHash = channel.accessHash { + return Api.InputPeer.inputPeerChannel(channelId: channel.id.id, accessHash: accessHash.value) + } else { return nil + } + default: + return nil } } diff --git a/submodules/TelegramCore/TelegramCore/AppChangelog.swift b/submodules/TelegramCore/TelegramCore/AppChangelog.swift index 0b5ca59dee..d3febb325a 100644 --- a/submodules/TelegramCore/TelegramCore/AppChangelog.swift +++ b/submodules/TelegramCore/TelegramCore/AppChangelog.swift @@ -15,6 +15,8 @@ import SwiftSignalKit #endif #endif +import SyncCore + func managedAppChangelog(postbox: Postbox, network: Network, stateManager: AccountStateManager, appVersion: String) -> Signal { return stateManager.pollStateUpdateCompletion() |> take(1) diff --git a/submodules/TelegramCore/TelegramCore/AppChangelogState.swift b/submodules/TelegramCore/TelegramCore/AppChangelogState.swift index e87208d983..71d57ee213 100644 --- a/submodules/TelegramCore/TelegramCore/AppChangelogState.swift +++ b/submodules/TelegramCore/TelegramCore/AppChangelogState.swift @@ -6,42 +6,10 @@ import MtProtoKitMac #else import Postbox import SwiftSignalKit - #if BUCK - import MtProtoKit - #else - import MtProtoKitDynamic - #endif +import MtProtoKit #endif -struct AppChangelogState: PreferencesEntry, Equatable { - var checkedVersion: String - var previousVersion: String - - static var `default` = AppChangelogState(checkedVersion: "", previousVersion: "5.0.8") - - init(checkedVersion: String, previousVersion: String) { - self.checkedVersion = checkedVersion - self.previousVersion = previousVersion - } - - init(decoder: PostboxDecoder) { - self.checkedVersion = decoder.decodeStringForKey("checkedVersion", orElse: "") - self.previousVersion = decoder.decodeStringForKey("previousVersion", orElse: "") - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.checkedVersion, forKey: "checkedVersion") - encoder.encodeString(self.previousVersion, forKey: "previousVersion") - } - - func isEqual(to: PreferencesEntry) -> Bool { - guard let to = to as? AppChangelogState else { - return false - } - - return self == to - } -} +import SyncCore func updateAppChangelogState(transaction: Transaction, _ f: @escaping (AppChangelogState) -> AppChangelogState) { transaction.updatePreferencesEntry(key: PreferencesKeys.appChangelogState, { current in diff --git a/submodules/TelegramCore/TelegramCore/AppConfiguration.swift b/submodules/TelegramCore/TelegramCore/AppConfiguration.swift index 2719561a11..827589c8ad 100644 --- a/submodules/TelegramCore/TelegramCore/AppConfiguration.swift +++ b/submodules/TelegramCore/TelegramCore/AppConfiguration.swift @@ -1,40 +1,5 @@ -import Foundation -#if os(macOS) - import PostboxMac -#else - import Postbox -#endif - -public struct AppConfiguration: PreferencesEntry, Equatable { - public var data: JSON? - - public static var defaultValue: AppConfiguration { - return AppConfiguration(data: nil) - } - - init(data: JSON?) { - self.data = data - } - - public init(decoder: PostboxDecoder) { - self.data = decoder.decodeObjectForKey("data", decoder: { JSON(decoder: $0) }) as? JSON - } - - public func encode(_ encoder: PostboxEncoder) { - if let data = self.data { - encoder.encodeObject(data, forKey: "data") - } else { - encoder.encodeNil(forKey: "data") - } - } - - public func isEqual(to: PreferencesEntry) -> Bool { - guard let to = to as? AppConfiguration else { - return false - } - return self == to - } -} +import Postbox +import SyncCore public func currentAppConfiguration(transaction: Transaction) -> AppConfiguration { if let entry = transaction.getPreferencesEntry(key: PreferencesKeys.appConfiguration) as? AppConfiguration { diff --git a/submodules/TelegramCore/TelegramCore/AppUpdate.swift b/submodules/TelegramCore/TelegramCore/AppUpdate.swift index 41cb4ae90f..fa6fc6dfbe 100644 --- a/submodules/TelegramCore/TelegramCore/AppUpdate.swift +++ b/submodules/TelegramCore/TelegramCore/AppUpdate.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public struct AppUpdateInfo: Equatable { public let blocking: Bool public let version: String diff --git a/submodules/TelegramCore/TelegramCore/ApplyMaxReadIndexInteractively.swift b/submodules/TelegramCore/TelegramCore/ApplyMaxReadIndexInteractively.swift index 6aa05b4242..0f178c3fcf 100644 --- a/submodules/TelegramCore/TelegramCore/ApplyMaxReadIndexInteractively.swift +++ b/submodules/TelegramCore/TelegramCore/ApplyMaxReadIndexInteractively.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public func applyMaxReadIndexInteractively(postbox: Postbox, stateManager: AccountStateManager, index: MessageIndex) -> Signal { return postbox.transaction { transaction -> Void in applyMaxReadIndexInteractively(transaction: transaction, stateManager: stateManager, index: index) diff --git a/submodules/TelegramCore/TelegramCore/ApplyUpdateMessage.swift b/submodules/TelegramCore/TelegramCore/ApplyUpdateMessage.swift index a40c2fa155..307c6b8665 100644 --- a/submodules/TelegramCore/TelegramCore/ApplyUpdateMessage.swift +++ b/submodules/TelegramCore/TelegramCore/ApplyUpdateMessage.swift @@ -10,6 +10,8 @@ import Foundation import UIKit #endif +import SyncCore + func applyMediaResourceChanges(from: Media, to: Media, postbox: Postbox) { if let fromImage = from as? TelegramMediaImage, let toImage = to as? TelegramMediaImage { let fromSmallestRepresentation = smallestImageRepresentation(fromImage.representations) diff --git a/submodules/TelegramCore/TelegramCore/ArchivedStickerPacks.swift b/submodules/TelegramCore/TelegramCore/ArchivedStickerPacks.swift index ec47ab28c3..686fb20863 100644 --- a/submodules/TelegramCore/TelegramCore/ArchivedStickerPacks.swift +++ b/submodules/TelegramCore/TelegramCore/ArchivedStickerPacks.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public enum ArchivedStickerPacksNamespace: Int32 { case stickers = 0 case masks = 1 diff --git a/submodules/TelegramCore/TelegramCore/Authorization.swift b/submodules/TelegramCore/TelegramCore/Authorization.swift index 03bc2a91e7..12897b5599 100644 --- a/submodules/TelegramCore/TelegramCore/Authorization.swift +++ b/submodules/TelegramCore/TelegramCore/Authorization.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public enum AuthorizationCodeRequestError { case invalidPhoneNumber case limitExceeded diff --git a/submodules/TelegramCore/TelegramCore/AutodownloadSettings.swift b/submodules/TelegramCore/TelegramCore/AutodownloadSettings.swift index 3dc0ae54ff..dde6126a1d 100644 --- a/submodules/TelegramCore/TelegramCore/AutodownloadSettings.swift +++ b/submodules/TelegramCore/TelegramCore/AutodownloadSettings.swift @@ -9,90 +9,7 @@ import Foundation import SwiftSignalKit #endif - -public enum AutodownloadPreset { - case low - case medium - case high -} - -public struct AutodownloadPresetSettings: PostboxCoding, Equatable { - public let disabled: Bool - public let photoSizeMax: Int32 - public let videoSizeMax: Int32 - public let fileSizeMax: Int32 - public let preloadLargeVideo: Bool - public let lessDataForPhoneCalls: Bool - - public init(disabled: Bool, photoSizeMax: Int32, videoSizeMax: Int32, fileSizeMax: Int32, preloadLargeVideo: Bool, lessDataForPhoneCalls: Bool) { - self.disabled = disabled - self.photoSizeMax = photoSizeMax - self.videoSizeMax = videoSizeMax - self.fileSizeMax = fileSizeMax - self.preloadLargeVideo = preloadLargeVideo - self.lessDataForPhoneCalls = lessDataForPhoneCalls - } - - public init(decoder: PostboxDecoder) { - self.disabled = decoder.decodeInt32ForKey("disabled", orElse: 0) != 0 - self.photoSizeMax = decoder.decodeInt32ForKey("photoSizeMax", orElse: 0) - self.videoSizeMax = decoder.decodeInt32ForKey("videoSizeMax", orElse: 0) - self.fileSizeMax = decoder.decodeInt32ForKey("fileSizeMax", orElse: 0) - self.preloadLargeVideo = decoder.decodeInt32ForKey("preloadLargeVideo", orElse: 0) != 0 - self.lessDataForPhoneCalls = decoder.decodeInt32ForKey("lessDataForPhoneCalls", orElse: 0) != 0 - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.disabled ? 1 : 0, forKey: "disabled") - encoder.encodeInt32(self.photoSizeMax, forKey: "photoSizeMax") - encoder.encodeInt32(self.videoSizeMax, forKey: "videoSizeMax") - encoder.encodeInt32(self.fileSizeMax, forKey: "fileSizeMax") - encoder.encodeInt32(self.preloadLargeVideo ? 1 : 0, forKey: "preloadLargeVideo") - encoder.encodeInt32(self.lessDataForPhoneCalls ? 1 : 0, forKey: "lessDataForPhoneCalls") - } -} - -public struct AutodownloadSettings: PreferencesEntry, Equatable { - public let lowPreset: AutodownloadPresetSettings - public let mediumPreset: AutodownloadPresetSettings - public let highPreset: AutodownloadPresetSettings - - public static var defaultSettings: AutodownloadSettings { - return AutodownloadSettings(lowPreset: AutodownloadPresetSettings(disabled: false, photoSizeMax: 1 * 1024 * 1024, videoSizeMax: 0, fileSizeMax: 0, preloadLargeVideo: false, lessDataForPhoneCalls: true), - mediumPreset: AutodownloadPresetSettings(disabled: false, photoSizeMax: 1 * 1024 * 1024, videoSizeMax: Int32(2.5 * 1024 * 1024), fileSizeMax: 1 * 1024 * 1024, preloadLargeVideo: false, lessDataForPhoneCalls: false), - highPreset: AutodownloadPresetSettings(disabled: false, photoSizeMax: 1 * 1024 * 1024, videoSizeMax: 10 * 1024 * 1024, fileSizeMax: 3 * 1024 * 1024, preloadLargeVideo: false, lessDataForPhoneCalls: false)) - } - - init(lowPreset: AutodownloadPresetSettings, mediumPreset: AutodownloadPresetSettings, highPreset: AutodownloadPresetSettings) { - self.lowPreset = lowPreset - self.mediumPreset = mediumPreset - self.highPreset = highPreset - } - - public init(decoder: PostboxDecoder) { - self.lowPreset = decoder.decodeObjectForKey("lowPreset", decoder: AutodownloadPresetSettings.init(decoder:)) as! AutodownloadPresetSettings - self.mediumPreset = decoder.decodeObjectForKey("mediumPreset", decoder: AutodownloadPresetSettings.init(decoder:)) as! AutodownloadPresetSettings - self.highPreset = decoder.decodeObjectForKey("highPreset", decoder: AutodownloadPresetSettings.init(decoder:)) as! AutodownloadPresetSettings - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeObject(self.lowPreset, forKey: "lowPreset") - encoder.encodeObject(self.mediumPreset, forKey: "mediumPreset") - encoder.encodeObject(self.highPreset, forKey: "highPreset") - } - - public func isEqual(to: PreferencesEntry) -> Bool { - if let to = to as? AutodownloadSettings { - return self == to - } else { - return false - } - } - - public static func ==(lhs: AutodownloadSettings, rhs: AutodownloadSettings) -> Bool { - return lhs.lowPreset == rhs.lowPreset && lhs.mediumPreset == rhs.mediumPreset && lhs.highPreset == rhs.highPreset - } -} +import SyncCore public func updateAutodownloadSettingsInteractively(accountManager: AccountManager, _ f: @escaping (AutodownloadSettings) -> AutodownloadSettings) -> Signal { return accountManager.transaction { transaction -> Void in diff --git a/submodules/TelegramCore/TelegramCore/BlockedPeers.swift b/submodules/TelegramCore/TelegramCore/BlockedPeers.swift index 86e1c89945..c94525d68f 100644 --- a/submodules/TelegramCore/TelegramCore/BlockedPeers.swift +++ b/submodules/TelegramCore/TelegramCore/BlockedPeers.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public func requestBlockedPeers(account: Account) -> Signal<[Peer], NoError> { return account.network.request(Api.functions.contacts.getBlocked(offset: 0, limit: 100)) |> retryRequest diff --git a/submodules/TelegramCore/TelegramCore/BlockedPeersContext.swift b/submodules/TelegramCore/TelegramCore/BlockedPeersContext.swift index e7ea63b5d5..6e323724b3 100644 --- a/submodules/TelegramCore/TelegramCore/BlockedPeersContext.swift +++ b/submodules/TelegramCore/TelegramCore/BlockedPeersContext.swift @@ -15,6 +15,8 @@ import SwiftSignalKit #endif #endif +import SyncCore + public struct BlockedPeersContextState: Equatable { public var isLoadingMore: Bool public var canLoadMore: Bool diff --git a/submodules/TelegramCore/TelegramCore/BotInfo.swift b/submodules/TelegramCore/TelegramCore/BotInfo.swift index b139c6258c..2a471286f3 100644 --- a/submodules/TelegramCore/TelegramCore/BotInfo.swift +++ b/submodules/TelegramCore/TelegramCore/BotInfo.swift @@ -7,49 +7,7 @@ import Foundation import TelegramApi #endif -public struct BotCommand: PostboxCoding, Hashable { - public let text: String - public let description: String - - init(text: String, description: String) { - self.text = text - self.description = description - } - - public init(decoder: PostboxDecoder) { - self.text = decoder.decodeStringForKey("t", orElse: "") - self.description = decoder.decodeStringForKey("d", orElse: "") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.text, forKey: "t") - encoder.encodeString(self.description, forKey: "d") - } -} - -public final class BotInfo: PostboxCoding, Equatable { - public let description: String - public let commands: [BotCommand] - - init(description: String, commands: [BotCommand]) { - self.description = description - self.commands = commands - } - - public init(decoder: PostboxDecoder) { - self.description = decoder.decodeStringForKey("d", orElse: "") - self.commands = decoder.decodeObjectArrayWithDecoderForKey("c") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.description, forKey: "d") - encoder.encodeObjectArray(self.commands, forKey: "c") - } - - public static func ==(lhs: BotInfo, rhs: BotInfo) -> Bool { - return lhs.description == rhs.description && lhs.commands == rhs.commands - } -} +import SyncCore extension BotInfo { convenience init(apiBotInfo: Api.BotInfo) { diff --git a/submodules/TelegramCore/TelegramCore/BotPaymentForm.swift b/submodules/TelegramCore/TelegramCore/BotPaymentForm.swift index 42b74c0c63..ba891678ae 100644 --- a/submodules/TelegramCore/TelegramCore/BotPaymentForm.swift +++ b/submodules/TelegramCore/TelegramCore/BotPaymentForm.swift @@ -15,6 +15,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public struct BotPaymentInvoiceFields: OptionSet { public var rawValue: Int32 diff --git a/submodules/TelegramCore/TelegramCore/CacheStorageSettings.swift b/submodules/TelegramCore/TelegramCore/CacheStorageSettings.swift index d0c5e28908..85d691dee6 100644 --- a/submodules/TelegramCore/TelegramCore/CacheStorageSettings.swift +++ b/submodules/TelegramCore/TelegramCore/CacheStorageSettings.swift @@ -7,41 +7,7 @@ import Foundation import SwiftSignalKit #endif -public struct CacheStorageSettings: PreferencesEntry, Equatable { - public let defaultCacheStorageTimeout: Int32 - - public static var defaultSettings: CacheStorageSettings { - return CacheStorageSettings(defaultCacheStorageTimeout: Int32.max) - } - - init(defaultCacheStorageTimeout: Int32) { - self.defaultCacheStorageTimeout = defaultCacheStorageTimeout - } - - public init(decoder: PostboxDecoder) { - self.defaultCacheStorageTimeout = decoder.decodeInt32ForKey("dt", orElse: Int32.max) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.defaultCacheStorageTimeout, forKey: "dt") - } - - public func isEqual(to: PreferencesEntry) -> Bool { - if let to = to as? CacheStorageSettings { - return self == to - } else { - return false - } - } - - public static func ==(lhs: CacheStorageSettings, rhs: CacheStorageSettings) -> Bool { - return lhs.defaultCacheStorageTimeout == rhs.defaultCacheStorageTimeout - } - - public func withUpdatedDefaultCacheStorageTimeout(_ defaultCacheStorageTimeout: Int32) -> CacheStorageSettings { - return CacheStorageSettings(defaultCacheStorageTimeout: defaultCacheStorageTimeout) - } -} +import SyncCore public func updateCacheStorageSettingsInteractively(accountManager: AccountManager, _ f: @escaping (CacheStorageSettings) -> CacheStorageSettings) -> Signal { return accountManager.transaction { transaction -> Void in diff --git a/submodules/TelegramCore/TelegramCore/CachedChannelData.swift b/submodules/TelegramCore/TelegramCore/CachedChannelData.swift index e9af1ffcb9..0c293d7b98 100644 --- a/submodules/TelegramCore/TelegramCore/CachedChannelData.swift +++ b/submodules/TelegramCore/TelegramCore/CachedChannelData.swift @@ -7,506 +7,7 @@ import Foundation import TelegramApi #endif -public struct CachedChannelFlags: OptionSet { - public var rawValue: Int32 - - public init() { - self.rawValue = 0 - } - - public init(rawValue: Int32) { - self.rawValue = rawValue - } - - public static let canDisplayParticipants = CachedChannelFlags(rawValue: 1 << 0) - public static let canChangeUsername = CachedChannelFlags(rawValue: 1 << 1) - public static let canSetStickerSet = CachedChannelFlags(rawValue: 1 << 2) - public static let preHistoryEnabled = CachedChannelFlags(rawValue: 1 << 3) - public static let canViewStats = CachedChannelFlags(rawValue: 1 << 4) - public static let canChangePeerGeoLocation = CachedChannelFlags(rawValue: 1 << 5) -} - -public struct CachedChannelParticipantsSummary: PostboxCoding, Equatable { - public let memberCount: Int32? - public let adminCount: Int32? - public let bannedCount: Int32? - public let kickedCount: Int32? - - init(memberCount: Int32?, adminCount: Int32?, bannedCount: Int32?, kickedCount: Int32?) { - self.memberCount = memberCount - self.adminCount = adminCount - self.bannedCount = bannedCount - self.kickedCount = kickedCount - } - - public init(decoder: PostboxDecoder) { - if let memberCount = decoder.decodeOptionalInt32ForKey("p.m") { - self.memberCount = memberCount - } else { - self.memberCount = nil - } - if let adminCount = decoder.decodeOptionalInt32ForKey("p.a") { - self.adminCount = adminCount - } else { - self.adminCount = nil - } - if let bannedCount = decoder.decodeOptionalInt32ForKey("p.b") { - self.bannedCount = bannedCount - } else { - self.bannedCount = nil - } - if let kickedCount = decoder.decodeOptionalInt32ForKey("p.k") { - self.kickedCount = kickedCount - } else { - self.kickedCount = nil - } - } - - public func encode(_ encoder: PostboxEncoder) { - if let memberCount = self.memberCount { - encoder.encodeInt32(memberCount, forKey: "p.m") - } else { - encoder.encodeNil(forKey: "p.m") - } - if let adminCount = self.adminCount { - encoder.encodeInt32(adminCount, forKey: "p.a") - } else { - encoder.encodeNil(forKey: "p.a") - } - if let bannedCount = self.bannedCount { - encoder.encodeInt32(bannedCount, forKey: "p.b") - } else { - encoder.encodeNil(forKey: "p.b") - } - if let kickedCount = self.kickedCount { - encoder.encodeInt32(kickedCount, forKey: "p.k") - } else { - encoder.encodeNil(forKey: "p.k") - } - } - - public static func ==(lhs: CachedChannelParticipantsSummary, rhs: CachedChannelParticipantsSummary) -> Bool { - return lhs.memberCount == rhs.memberCount && lhs.adminCount == rhs.adminCount && lhs.bannedCount == rhs.bannedCount && lhs.kickedCount == rhs.kickedCount - } - - public func withUpdatedMemberCount(_ memberCount: Int32?) -> CachedChannelParticipantsSummary { - return CachedChannelParticipantsSummary(memberCount: memberCount, adminCount: self.adminCount, bannedCount: self.bannedCount, kickedCount: self.kickedCount) - } - - public func withUpdatedAdminCount(_ adminCount: Int32?) -> CachedChannelParticipantsSummary { - return CachedChannelParticipantsSummary(memberCount: self.memberCount, adminCount: adminCount, bannedCount: self.bannedCount, kickedCount: self.kickedCount) - } - - public func withUpdatedBannedCount(_ bannedCount: Int32?) -> CachedChannelParticipantsSummary { - return CachedChannelParticipantsSummary(memberCount: self.memberCount, adminCount: self.adminCount, bannedCount: bannedCount, kickedCount: self.kickedCount) - } - - public func withUpdatedKickedCount(_ kickedCount: Int32?) -> CachedChannelParticipantsSummary { - return CachedChannelParticipantsSummary(memberCount: self.memberCount, adminCount: self.adminCount, bannedCount: self.bannedCount, kickedCount: kickedCount) - } -} - -public struct ChannelMigrationReference: PostboxCoding, Equatable { - public let maxMessageId: MessageId - - public init(maxMessageId: MessageId) { - self.maxMessageId = maxMessageId - } - - public init(decoder: PostboxDecoder) { - self.maxMessageId = MessageId(peerId: PeerId(decoder.decodeInt64ForKey("p", orElse: 0)), namespace: decoder.decodeInt32ForKey("n", orElse: 0), id: decoder.decodeInt32ForKey("i", orElse: 0)) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt64(self.maxMessageId.peerId.toInt64(), forKey: "p") - encoder.encodeInt32(self.maxMessageId.namespace, forKey: "n") - encoder.encodeInt32(self.maxMessageId.id, forKey: "i") - } - - public static func ==(lhs: ChannelMigrationReference, rhs: ChannelMigrationReference) -> Bool { - return lhs.maxMessageId == rhs.maxMessageId - } -} - -public struct PeerGeoLocation: PostboxCoding, Equatable { - public let latitude: Double - public let longitude: Double - public let address: String - - public init(latitude: Double, longitude: Double, address: String) { - self.latitude = latitude - self.longitude = longitude - self.address = address - } - - public init(decoder: PostboxDecoder) { - self.latitude = decoder.decodeDoubleForKey("la", orElse: 0.0) - self.longitude = decoder.decodeDoubleForKey("lo", orElse: 0.0) - self.address = decoder.decodeStringForKey("a", orElse: "") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeDouble(self.latitude, forKey: "la") - encoder.encodeDouble(self.longitude, forKey: "lo") - encoder.encodeString(self.address, forKey: "a") - } - - public static func ==(lhs: PeerGeoLocation, rhs: PeerGeoLocation) -> Bool { - return lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude && lhs.address == rhs.address - } -} - -public final class CachedChannelData: CachedPeerData { - public let isNotAccessible: Bool - public let flags: CachedChannelFlags - public let about: String? - public let participantsSummary: CachedChannelParticipantsSummary - public let exportedInvitation: ExportedInvitation? - public let botInfos: [CachedPeerBotInfo] - public let peerStatusSettings: PeerStatusSettings? - public let pinnedMessageId: MessageId? - public let stickerPack: StickerPackCollectionInfo? - public let minAvailableMessageId: MessageId? - public let migrationReference: ChannelMigrationReference? - public let linkedDiscussionPeerId: PeerId? - public let peerGeoLocation: PeerGeoLocation? - public let slowModeTimeout: Int32? - public let slowModeValidUntilTimestamp: Int32? - public let hasScheduledMessages: Bool - - public let peerIds: Set - public let messageIds: Set - public var associatedHistoryMessageId: MessageId? { - return self.migrationReference?.maxMessageId - } - - init() { - self.isNotAccessible = false - self.flags = [] - self.about = nil - self.participantsSummary = CachedChannelParticipantsSummary(memberCount: nil, adminCount: nil, bannedCount: nil, kickedCount: nil) - self.exportedInvitation = nil - self.botInfos = [] - self.peerStatusSettings = nil - self.pinnedMessageId = nil - self.peerIds = Set() - self.messageIds = Set() - self.stickerPack = nil - self.minAvailableMessageId = nil - self.migrationReference = nil - self.linkedDiscussionPeerId = nil - self.peerGeoLocation = nil - self.slowModeTimeout = nil - self.slowModeValidUntilTimestamp = nil - self.hasScheduledMessages = false - } - - init(isNotAccessible: Bool, flags: CachedChannelFlags, about: String?, participantsSummary: CachedChannelParticipantsSummary, exportedInvitation: ExportedInvitation?, botInfos: [CachedPeerBotInfo], peerStatusSettings: PeerStatusSettings?, pinnedMessageId: MessageId?, stickerPack: StickerPackCollectionInfo?, minAvailableMessageId: MessageId?, migrationReference: ChannelMigrationReference?, linkedDiscussionPeerId: PeerId?, peerGeoLocation: PeerGeoLocation?, slowModeTimeout: Int32?, slowModeValidUntilTimestamp: Int32?, hasScheduledMessages: Bool) { - self.isNotAccessible = isNotAccessible - self.flags = flags - self.about = about - self.participantsSummary = participantsSummary - self.exportedInvitation = exportedInvitation - self.botInfos = botInfos - self.peerStatusSettings = peerStatusSettings - self.pinnedMessageId = pinnedMessageId - self.stickerPack = stickerPack - self.minAvailableMessageId = minAvailableMessageId - self.migrationReference = migrationReference - self.linkedDiscussionPeerId = linkedDiscussionPeerId - self.peerGeoLocation = peerGeoLocation - self.slowModeTimeout = slowModeTimeout - self.slowModeValidUntilTimestamp = slowModeValidUntilTimestamp - self.hasScheduledMessages = hasScheduledMessages - - var peerIds = Set() - for botInfo in botInfos { - peerIds.insert(botInfo.peerId) - } - - if let linkedDiscussionPeerId = linkedDiscussionPeerId { - peerIds.insert(linkedDiscussionPeerId) - } - - self.peerIds = peerIds - - var messageIds = Set() - if let pinnedMessageId = self.pinnedMessageId { - messageIds.insert(pinnedMessageId) - } - self.messageIds = messageIds - } - - func withUpdatedIsNotAccessible(_ isNotAccessible: Bool) -> CachedChannelData { - return CachedChannelData(isNotAccessible: isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) - } - - func withUpdatedFlags(_ flags: CachedChannelFlags) -> CachedChannelData { - return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) - } - - func withUpdatedAbout(_ about: String?) -> CachedChannelData { - return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) - } - - func withUpdatedParticipantsSummary(_ participantsSummary: CachedChannelParticipantsSummary) -> CachedChannelData { - return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) - } - - func withUpdatedExportedInvitation(_ exportedInvitation: ExportedInvitation?) -> CachedChannelData { - return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) - } - - func withUpdatedBotInfos(_ botInfos: [CachedPeerBotInfo]) -> CachedChannelData { - return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) - } - - func withUpdatedPeerStatusSettings(_ peerStatusSettings: PeerStatusSettings?) -> CachedChannelData { - return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) - } - - func withUpdatedPinnedMessageId(_ pinnedMessageId: MessageId?) -> CachedChannelData { - return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) - } - - func withUpdatedStickerPack(_ stickerPack: StickerPackCollectionInfo?) -> CachedChannelData { - return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) - } - - func withUpdatedMinAvailableMessageId(_ minAvailableMessageId: MessageId?) -> CachedChannelData { - return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) - } - - func withUpdatedMigrationReference(_ migrationReference: ChannelMigrationReference?) -> CachedChannelData { - return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) - } - - func withUpdatedLinkedDiscussionPeerId(_ linkedDiscussionPeerId: PeerId?) -> CachedChannelData { - return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) - } - - func withUpdatedPeerGeoLocation(_ peerGeoLocation: PeerGeoLocation?) -> CachedChannelData { - return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) - } - - func withUpdatedSlowModeTimeout(_ slowModeTimeout: Int32?) -> CachedChannelData { - return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) - } - - func withUpdatedSlowModeValidUntilTimestamp(_ slowModeValidUntilTimestamp: Int32?) -> CachedChannelData { - return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: slowModeValidUntilTimestamp, hasScheduledMessages: self.hasScheduledMessages) - } - - func withUpdatedHasScheduledMessages(_ hasScheduledMessages: Bool) -> CachedChannelData { - return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId, peerGeoLocation: self.peerGeoLocation, slowModeTimeout: self.slowModeTimeout, slowModeValidUntilTimestamp: self.slowModeValidUntilTimestamp, hasScheduledMessages: hasScheduledMessages) - } - - public init(decoder: PostboxDecoder) { - self.isNotAccessible = decoder.decodeInt32ForKey("isNotAccessible", orElse: 0) != 0 - self.flags = CachedChannelFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0)) - self.about = decoder.decodeOptionalStringForKey("a") - self.participantsSummary = CachedChannelParticipantsSummary(decoder: decoder) - self.exportedInvitation = decoder.decodeObjectForKey("i", decoder: { ExportedInvitation(decoder: $0) }) as? ExportedInvitation - self.botInfos = decoder.decodeObjectArrayWithDecoderForKey("b") as [CachedPeerBotInfo] - var peerIds = Set() - if let value = decoder.decodeOptionalInt32ForKey("pcs") { - self.peerStatusSettings = PeerStatusSettings(rawValue: value) - } else { - self.peerStatusSettings = nil - } - if let pinnedMessagePeerId = decoder.decodeOptionalInt64ForKey("pm.p"), let pinnedMessageNamespace = decoder.decodeOptionalInt32ForKey("pm.n"), let pinnedMessageId = decoder.decodeOptionalInt32ForKey("pm.i") { - self.pinnedMessageId = MessageId(peerId: PeerId(pinnedMessagePeerId), namespace: pinnedMessageNamespace, id: pinnedMessageId) - } else { - self.pinnedMessageId = nil - } - - if let stickerPack = decoder.decodeObjectForKey("sp", decoder: { StickerPackCollectionInfo(decoder: $0) }) as? StickerPackCollectionInfo { - self.stickerPack = stickerPack - } else { - self.stickerPack = nil - } - - if let minAvailableMessagePeerId = decoder.decodeOptionalInt64ForKey("ma.p"), let minAvailableMessageNamespace = decoder.decodeOptionalInt32ForKey("ma.n"), let minAvailableMessageId = decoder.decodeOptionalInt32ForKey("ma.i") { - self.minAvailableMessageId = MessageId(peerId: PeerId(minAvailableMessagePeerId), namespace: minAvailableMessageNamespace, id: minAvailableMessageId) - } else { - self.minAvailableMessageId = nil - } - - self.migrationReference = decoder.decodeObjectForKey("mr", decoder: { ChannelMigrationReference(decoder: $0) }) as? ChannelMigrationReference - - for botInfo in self.botInfos { - peerIds.insert(botInfo.peerId) - } - - if let linkedDiscussionPeerId = decoder.decodeOptionalInt64ForKey("dgi") { - self.linkedDiscussionPeerId = PeerId(linkedDiscussionPeerId) - } else { - self.linkedDiscussionPeerId = nil - } - - if let peerGeoLocation = decoder.decodeObjectForKey("pgl", decoder: { PeerGeoLocation(decoder: $0) }) as? PeerGeoLocation { - self.peerGeoLocation = peerGeoLocation - } else { - self.peerGeoLocation = nil - } - - self.slowModeTimeout = decoder.decodeOptionalInt32ForKey("smt") - self.slowModeValidUntilTimestamp = decoder.decodeOptionalInt32ForKey("smv") - self.hasScheduledMessages = decoder.decodeBoolForKey("hsm", orElse: false) - - if let linkedDiscussionPeerId = self.linkedDiscussionPeerId { - peerIds.insert(linkedDiscussionPeerId) - } - - self.peerIds = peerIds - - var messageIds = Set() - if let pinnedMessageId = self.pinnedMessageId { - messageIds.insert(pinnedMessageId) - } - self.messageIds = messageIds - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.isNotAccessible ? 1 : 0, forKey: "isNotAccessible") - encoder.encodeInt32(self.flags.rawValue, forKey: "f") - if let about = self.about { - encoder.encodeString(about, forKey: "a") - } else { - encoder.encodeNil(forKey: "a") - } - self.participantsSummary.encode(encoder) - if let exportedInvitation = self.exportedInvitation { - encoder.encodeObject(exportedInvitation, forKey: "i") - } else { - encoder.encodeNil(forKey: "i") - } - encoder.encodeObjectArray(self.botInfos, forKey: "b") - if let peerStatusSettings = self.peerStatusSettings { - encoder.encodeInt32(peerStatusSettings.rawValue, forKey: "pcs") - } else { - encoder.encodeNil(forKey: "pcs") - } - if let pinnedMessageId = self.pinnedMessageId { - encoder.encodeInt64(pinnedMessageId.peerId.toInt64(), forKey: "pm.p") - encoder.encodeInt32(pinnedMessageId.namespace, forKey: "pm.n") - encoder.encodeInt32(pinnedMessageId.id, forKey: "pm.i") - } else { - encoder.encodeNil(forKey: "pm.p") - encoder.encodeNil(forKey: "pm.n") - encoder.encodeNil(forKey: "pm.i") - } - if let stickerPack = self.stickerPack { - encoder.encodeObject(stickerPack, forKey: "sp") - } else { - encoder.encodeNil(forKey: "sp") - } - if let minAvailableMessageId = self.minAvailableMessageId { - encoder.encodeInt64(minAvailableMessageId.peerId.toInt64(), forKey: "ma.p") - encoder.encodeInt32(minAvailableMessageId.namespace, forKey: "ma.n") - encoder.encodeInt32(minAvailableMessageId.id, forKey: "ma.i") - } else { - encoder.encodeNil(forKey: "ma.p") - encoder.encodeNil(forKey: "ma.n") - encoder.encodeNil(forKey: "ma.i") - } - if let migrationReference = self.migrationReference { - encoder.encodeObject(migrationReference, forKey: "mr") - } else { - encoder.encodeNil(forKey: "mr") - } - if let linkedDiscussionPeerId = self.linkedDiscussionPeerId { - encoder.encodeInt64(linkedDiscussionPeerId.toInt64(), forKey: "dgi") - } else { - encoder.encodeNil(forKey: "dgi") - } - if let peerGeoLocation = self.peerGeoLocation { - encoder.encodeObject(peerGeoLocation, forKey: "pgl") - } else { - encoder.encodeNil(forKey: "pgl") - } - - if let slowModeTimeout = self.slowModeTimeout { - encoder.encodeInt32(slowModeTimeout, forKey: "smt") - } else { - encoder.encodeNil(forKey: "smt") - } - if let slowModeValidUntilTimestamp = self.slowModeValidUntilTimestamp { - encoder.encodeInt32(slowModeValidUntilTimestamp, forKey: "smv") - } else { - encoder.encodeNil(forKey: "smv") - } - encoder.encodeBool(self.hasScheduledMessages, forKey: "hsm") - } - - public func isEqual(to: CachedPeerData) -> Bool { - guard let other = to as? CachedChannelData else { - return false - } - - if other.isNotAccessible != self.isNotAccessible { - return false - } - - if other.flags != self.flags { - return false - } - - if other.linkedDiscussionPeerId != self.linkedDiscussionPeerId { - return false - } - - if other.about != self.about { - return false - } - - if other.participantsSummary != self.participantsSummary { - return false - } - - if other.exportedInvitation != self.exportedInvitation { - return false - } - - if other.botInfos != self.botInfos { - return false - } - - if other.peerStatusSettings != self.peerStatusSettings { - return false - } - - if other.pinnedMessageId != self.pinnedMessageId { - return false - } - - if other.stickerPack != self.stickerPack { - return false - } - - if other.minAvailableMessageId != self.minAvailableMessageId { - return false - } - - if other.migrationReference != self.migrationReference { - return false - } - - if other.peerGeoLocation != self.peerGeoLocation { - return false - } - - if other.slowModeTimeout != self.slowModeTimeout { - return false - } - - if other.slowModeValidUntilTimestamp != self.slowModeValidUntilTimestamp { - return false - } - - return true - } -} +import SyncCore extension PeerGeoLocation { init?(apiLocation: Api.ChannelLocation) { diff --git a/submodules/TelegramCore/TelegramCore/CachedChannelParticipants.swift b/submodules/TelegramCore/TelegramCore/CachedChannelParticipants.swift index 6a8e4d1f44..d9eda4b38e 100644 --- a/submodules/TelegramCore/TelegramCore/CachedChannelParticipants.swift +++ b/submodules/TelegramCore/TelegramCore/CachedChannelParticipants.swift @@ -7,6 +7,8 @@ import Foundation import TelegramApi #endif +import SyncCore + private enum ChannelParticipantValue: Int32 { case member = 0 case creator = 1 diff --git a/submodules/TelegramCore/TelegramCore/CachedGroupParticipants.swift b/submodules/TelegramCore/TelegramCore/CachedGroupParticipants.swift index deef543c4d..648971e628 100644 --- a/submodules/TelegramCore/TelegramCore/CachedGroupParticipants.swift +++ b/submodules/TelegramCore/TelegramCore/CachedGroupParticipants.swift @@ -7,111 +7,7 @@ import Foundation import TelegramApi #endif -public enum GroupParticipant: PostboxCoding, Equatable { - case member(id: PeerId, invitedBy: PeerId, invitedAt: Int32) - case creator(id: PeerId) - case admin(id: PeerId, invitedBy: PeerId, invitedAt: Int32) - - public var peerId: PeerId { - switch self { - case let .member(id, _, _): - return id - case let .creator(id): - return id - case let .admin(id, _, _): - return id - } - } - - public init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("v", orElse: 0) { - case 0: - self = .member(id: PeerId(decoder.decodeInt64ForKey("i", orElse: 0)), invitedBy: PeerId(decoder.decodeInt64ForKey("b", orElse: 0)), invitedAt: decoder.decodeInt32ForKey("t", orElse: 0)) - case 1: - self = .creator(id: PeerId(decoder.decodeInt64ForKey("i", orElse: 0))) - case 2: - self = .admin(id: PeerId(decoder.decodeInt64ForKey("i", orElse: 0)), invitedBy: PeerId(decoder.decodeInt64ForKey("b", orElse: 0)), invitedAt: decoder.decodeInt32ForKey("t", orElse: 0)) - default: - self = .member(id: PeerId(decoder.decodeInt64ForKey("i", orElse: 0)), invitedBy: PeerId(decoder.decodeInt64ForKey("b", orElse: 0)), invitedAt: decoder.decodeInt32ForKey("t", orElse: 0)) - } - } - - public func encode(_ encoder: PostboxEncoder) { - switch self { - case let .member(id, invitedBy, invitedAt): - encoder.encodeInt32(0, forKey: "v") - encoder.encodeInt64(id.toInt64(), forKey: "i") - encoder.encodeInt64(invitedBy.toInt64(), forKey: "b") - encoder.encodeInt32(invitedAt, forKey: "t") - case let .creator(id): - encoder.encodeInt32(1, forKey: "v") - encoder.encodeInt64(id.toInt64(), forKey: "i") - case let .admin(id, invitedBy, invitedAt): - encoder.encodeInt32(2, forKey: "v") - encoder.encodeInt64(id.toInt64(), forKey: "i") - encoder.encodeInt64(invitedBy.toInt64(), forKey: "b") - encoder.encodeInt32(invitedAt, forKey: "t") - } - } - - public static func ==(lhs: GroupParticipant, rhs: GroupParticipant) -> Bool { - switch lhs { - case let .admin(lhsId, lhIinvitedBy, lhsInvitedAt): - if case .admin(lhsId, lhIinvitedBy, lhsInvitedAt) = rhs { - return true - } else { - return false - } - case let .creator(lhsId): - if case .creator(lhsId) = rhs { - return true - } else { - return false - } - case let .member(lhsId, lhIinvitedBy, lhsInvitedAt): - if case .member(lhsId, lhIinvitedBy, lhsInvitedAt) = rhs { - return true - } else { - return false - } - } - } - - public var invitedBy: PeerId { - switch self { - case let .admin(_, invitedBy, _): - return invitedBy - case let .member(_, invitedBy, _): - return invitedBy - case let .creator(id): - return id - } - } -} - -public final class CachedGroupParticipants: PostboxCoding, Equatable { - public let participants: [GroupParticipant] - let version: Int32 - - init(participants: [GroupParticipant], version: Int32) { - self.participants = participants - self.version = version - } - - public init(decoder: PostboxDecoder) { - self.participants = decoder.decodeObjectArrayWithDecoderForKey("p") - self.version = decoder.decodeInt32ForKey("v", orElse: 0) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeObjectArray(self.participants, forKey: "p") - encoder.encodeInt32(self.version, forKey: "v") - } - - public static func ==(lhs: CachedGroupParticipants, rhs: CachedGroupParticipants) -> Bool { - return lhs.version == rhs.version && lhs.participants == rhs.participants - } -} +import SyncCore extension GroupParticipant { init(apiParticipant: Api.ChatParticipant) { diff --git a/submodules/TelegramCore/TelegramCore/CachedSentMediaReferences.swift b/submodules/TelegramCore/TelegramCore/CachedSentMediaReferences.swift index f2079a6d05..47d9a9c5d7 100644 --- a/submodules/TelegramCore/TelegramCore/CachedSentMediaReferences.swift +++ b/submodules/TelegramCore/TelegramCore/CachedSentMediaReferences.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + private let cachedSentMediaCollectionSpec = ItemCacheCollectionSpec(lowWaterItemCount: 10000, highWaterItemCount: 20000) enum CachedSentMediaReferenceKey { diff --git a/submodules/TelegramCore/TelegramCore/CachedStickerPack.swift b/submodules/TelegramCore/TelegramCore/CachedStickerPack.swift index ce3639f702..d9c8e5f2f4 100644 --- a/submodules/TelegramCore/TelegramCore/CachedStickerPack.swift +++ b/submodules/TelegramCore/TelegramCore/CachedStickerPack.swift @@ -7,44 +7,7 @@ import Foundation import SwiftSignalKit #endif -final class CachedStickerPack: PostboxCoding { - let info: StickerPackCollectionInfo? - let items: [StickerPackItem] - let hash: Int32 - - init(info: StickerPackCollectionInfo?, items: [StickerPackItem], hash: Int32) { - self.info = info - self.items = items - self.hash = hash - } - - init(decoder: PostboxDecoder) { - self.info = decoder.decodeObjectForKey("in", decoder: { StickerPackCollectionInfo(decoder: $0) }) as? StickerPackCollectionInfo - self.items = decoder.decodeObjectArrayForKey("it").map { $0 as! StickerPackItem } - self.hash = decoder.decodeInt32ForKey("h", orElse: 0) - } - - func encode(_ encoder: PostboxEncoder) { - if let info = self.info { - encoder.encodeObject(info, forKey: "in") - } else { - encoder.encodeNil(forKey: "in") - } - encoder.encodeObjectArray(self.items, forKey: "it") - encoder.encodeInt32(self.hash, forKey: "h") - } - - static func cacheKey(_ id: ItemCollectionId) -> ValueBoxKey { - let key = ValueBoxKey(length: 4 + 8) - key.setInt32(0, value: id.namespace) - key.setInt64(4, value: id.id) - return key - } - - static func cacheKey(shortName: String) -> ValueBoxKey { - return ValueBoxKey(shortName) - } -} +import SyncCore private let collectionSpec = ItemCacheCollectionSpec(lowWaterItemCount: 100, highWaterItemCount: 200) diff --git a/submodules/TelegramCore/TelegramCore/CallSessionManager.swift b/submodules/TelegramCore/TelegramCore/CallSessionManager.swift index 5280e86909..fb1103931a 100644 --- a/submodules/TelegramCore/TelegramCore/CallSessionManager.swift +++ b/submodules/TelegramCore/TelegramCore/CallSessionManager.swift @@ -16,6 +16,8 @@ import SwiftSignalKit #endif +import SyncCore + private let minLayer: Int32 = 65 public enum CallSessionError: Equatable { diff --git a/submodules/TelegramCore/TelegramCore/CanSendMessagesToPeer.swift b/submodules/TelegramCore/TelegramCore/CanSendMessagesToPeer.swift index a472b83596..cb13ee91f2 100644 --- a/submodules/TelegramCore/TelegramCore/CanSendMessagesToPeer.swift +++ b/submodules/TelegramCore/TelegramCore/CanSendMessagesToPeer.swift @@ -5,6 +5,8 @@ import Foundation import Postbox #endif +import SyncCore + public func canSendMessagesToPeer(_ peer: Peer) -> Bool { if peer is TelegramUser || peer is TelegramGroup { return !peer.isDeleted diff --git a/submodules/TelegramCore/TelegramCore/CancelAccountReset.swift b/submodules/TelegramCore/TelegramCore/CancelAccountReset.swift index 4f1f717116..c2d3e65e9d 100644 --- a/submodules/TelegramCore/TelegramCore/CancelAccountReset.swift +++ b/submodules/TelegramCore/TelegramCore/CancelAccountReset.swift @@ -15,6 +15,8 @@ import SwiftSignalKit #endif #endif +import SyncCore + public struct CancelAccountResetData: Equatable { public let type: SentAuthorizationCodeType public let hash: String diff --git a/submodules/TelegramCore/TelegramCore/ChangeAccountPhoneNumber.swift b/submodules/TelegramCore/TelegramCore/ChangeAccountPhoneNumber.swift index 46fca165d0..1ad85b8b42 100644 --- a/submodules/TelegramCore/TelegramCore/ChangeAccountPhoneNumber.swift +++ b/submodules/TelegramCore/TelegramCore/ChangeAccountPhoneNumber.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public struct ChangeAccountPhoneNumberData: Equatable { public let type: SentAuthorizationCodeType public let hash: String diff --git a/submodules/TelegramCore/TelegramCore/ChangePeerNotificationSettings.swift b/submodules/TelegramCore/TelegramCore/ChangePeerNotificationSettings.swift index 42f3137f0e..757e9932e6 100644 --- a/submodules/TelegramCore/TelegramCore/ChangePeerNotificationSettings.swift +++ b/submodules/TelegramCore/TelegramCore/ChangePeerNotificationSettings.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public func togglePeerMuted(account: Account, peerId: PeerId) -> Signal { return account.postbox.transaction { transaction -> Void in if let peer = transaction.getPeer(peerId) { diff --git a/submodules/TelegramCore/TelegramCore/ChannelAdminEventLogs.swift b/submodules/TelegramCore/TelegramCore/ChannelAdminEventLogs.swift index 817c7dfbb6..f9cc410b83 100644 --- a/submodules/TelegramCore/TelegramCore/ChannelAdminEventLogs.swift +++ b/submodules/TelegramCore/TelegramCore/ChannelAdminEventLogs.swift @@ -14,6 +14,8 @@ #endif #endif +import SyncCore + public typealias AdminLogEventId = Int64 public struct AdminLogEvent: Comparable { diff --git a/submodules/TelegramCore/TelegramCore/ChannelAdmins.swift b/submodules/TelegramCore/TelegramCore/ChannelAdmins.swift index db7ce8ed64..955cee3886 100644 --- a/submodules/TelegramCore/TelegramCore/ChannelAdmins.swift +++ b/submodules/TelegramCore/TelegramCore/ChannelAdmins.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public func channelAdmins(account: Account, peerId: PeerId) -> Signal<[RenderedChannelParticipant], NoError> { return account.postbox.transaction { transaction -> Signal<[RenderedChannelParticipant], NoError> in if let peer = transaction.getPeer(peerId), let inputChannel = apiInputChannel(peer) { diff --git a/submodules/TelegramCore/TelegramCore/ChannelBlacklist.swift b/submodules/TelegramCore/TelegramCore/ChannelBlacklist.swift index d050e0374c..c0c8be64ff 100644 --- a/submodules/TelegramCore/TelegramCore/ChannelBlacklist.swift +++ b/submodules/TelegramCore/TelegramCore/ChannelBlacklist.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private enum ChannelBlacklistFilter { case restricted case banned diff --git a/submodules/TelegramCore/TelegramCore/ChannelHistoryAvailabilitySettings.swift b/submodules/TelegramCore/TelegramCore/ChannelHistoryAvailabilitySettings.swift index 47a9eb0897..b4c2946403 100644 --- a/submodules/TelegramCore/TelegramCore/ChannelHistoryAvailabilitySettings.swift +++ b/submodules/TelegramCore/TelegramCore/ChannelHistoryAvailabilitySettings.swift @@ -8,6 +8,8 @@ import SwiftSignalKit #endif +import SyncCore + public enum ChannelHistoryAvailabilityError { case generic case hasNotPermissions diff --git a/submodules/TelegramCore/TelegramCore/ChannelMembers.swift b/submodules/TelegramCore/TelegramCore/ChannelMembers.swift index 2cc891484f..28d51d41f0 100644 --- a/submodules/TelegramCore/TelegramCore/ChannelMembers.swift +++ b/submodules/TelegramCore/TelegramCore/ChannelMembers.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public enum ChannelMembersCategoryFilter { case all case search(String) diff --git a/submodules/TelegramCore/TelegramCore/ChannelOwnershipTransfer.swift b/submodules/TelegramCore/TelegramCore/ChannelOwnershipTransfer.swift index 9e33ad12de..4da968c512 100644 --- a/submodules/TelegramCore/TelegramCore/ChannelOwnershipTransfer.swift +++ b/submodules/TelegramCore/TelegramCore/ChannelOwnershipTransfer.swift @@ -9,6 +9,7 @@ import Postbox import TelegramApi #endif +import SyncCore public enum ChannelOwnershipTransferError { case generic diff --git a/submodules/TelegramCore/TelegramCore/ChannelParticipants.swift b/submodules/TelegramCore/TelegramCore/ChannelParticipants.swift index f82a167beb..77796e0a20 100644 --- a/submodules/TelegramCore/TelegramCore/ChannelParticipants.swift +++ b/submodules/TelegramCore/TelegramCore/ChannelParticipants.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public struct RenderedChannelParticipant: Equatable { public let participant: ChannelParticipant public let peer: Peer diff --git a/submodules/TelegramCore/TelegramCore/ChannelState.swift b/submodules/TelegramCore/TelegramCore/ChannelState.swift index 1bcbc39a2d..490f597857 100644 --- a/submodules/TelegramCore/TelegramCore/ChannelState.swift +++ b/submodules/TelegramCore/TelegramCore/ChannelState.swift @@ -7,52 +7,7 @@ import Foundation import TelegramApi #endif -final class ChannelState: PeerChatState, Equatable, CustomStringConvertible { - let pts: Int32 - let invalidatedPts: Int32? - - init(pts: Int32, invalidatedPts: Int32?) { - self.pts = pts - self.invalidatedPts = invalidatedPts - } - - init(decoder: PostboxDecoder) { - self.pts = decoder.decodeInt32ForKey("pts", orElse: 0) - self.invalidatedPts = decoder.decodeOptionalInt32ForKey("ipts") - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.pts, forKey: "pts") - if let invalidatedPts = self.invalidatedPts { - encoder.encodeInt32(invalidatedPts, forKey: "ipts") - } else { - encoder.encodeNil(forKey: "ipts") - } - } - - func withUpdatedPts(_ pts: Int32) -> ChannelState { - return ChannelState(pts: pts, invalidatedPts: self.invalidatedPts) - } - - func withUpdatedInvalidatedPts(_ invalidatedPts: Int32?) -> ChannelState { - return ChannelState(pts: self.pts, invalidatedPts: invalidatedPts) - } - - func equals(_ other: PeerChatState) -> Bool { - if let other = other as? ChannelState, other == self { - return true - } - return false - } - - var description: String { - return "(pts: \(self.pts))" - } -} - -func ==(lhs: ChannelState, rhs: ChannelState) -> Bool { - return lhs.pts == rhs.pts && lhs.invalidatedPts == rhs.invalidatedPts -} +import SyncCore struct ChannelUpdate { let update: Api.Update diff --git a/submodules/TelegramCore/TelegramCore/ChatContextResult.swift b/submodules/TelegramCore/TelegramCore/ChatContextResult.swift index a97cae03b7..f0486de13f 100644 --- a/submodules/TelegramCore/TelegramCore/ChatContextResult.swift +++ b/submodules/TelegramCore/TelegramCore/ChatContextResult.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public enum ChatContextResultMessage: PostboxCoding, Equatable { case auto(caption: String, entities: TextEntitiesMessageAttribute?, replyMarkup: ReplyMarkupMessageAttribute?) case text(text: String, entities: TextEntitiesMessageAttribute?, disableUrlPreview: Bool, replyMarkup: ReplyMarkupMessageAttribute?) diff --git a/submodules/TelegramCore/TelegramCore/ChatHistoryPreloadManager.swift b/submodules/TelegramCore/TelegramCore/ChatHistoryPreloadManager.swift index 4534620ab3..e386f32ddb 100644 --- a/submodules/TelegramCore/TelegramCore/ChatHistoryPreloadManager.swift +++ b/submodules/TelegramCore/TelegramCore/ChatHistoryPreloadManager.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public struct HistoryPreloadIndex: Comparable { public let index: ChatListIndex? public let hasUnread: Bool diff --git a/submodules/TelegramCore/TelegramCore/CheckPeerChatServiceActions.swift b/submodules/TelegramCore/TelegramCore/CheckPeerChatServiceActions.swift index 3cb76a539b..07b82cbbd0 100644 --- a/submodules/TelegramCore/TelegramCore/CheckPeerChatServiceActions.swift +++ b/submodules/TelegramCore/TelegramCore/CheckPeerChatServiceActions.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public func checkPeerChatServiceActions(postbox: Postbox, peerId: PeerId) -> Signal { return postbox.transaction { transaction -> Void in transaction.applyMarkUnread(peerId: peerId, namespace: Namespaces.Message.SecretIncoming, value: false, interactive: true) diff --git a/submodules/TelegramCore/TelegramCore/ClearCloudDrafts.swift b/submodules/TelegramCore/TelegramCore/ClearCloudDrafts.swift index 39f37487fd..cacb4354a8 100644 --- a/submodules/TelegramCore/TelegramCore/ClearCloudDrafts.swift +++ b/submodules/TelegramCore/TelegramCore/ClearCloudDrafts.swift @@ -9,6 +9,8 @@ import SwiftSignalKit import TelegramApi #endif +import SyncCore + public func clearCloudDraftsInteractively(postbox: Postbox, network: Network, accountPeerId: PeerId) -> Signal { return network.request(Api.functions.messages.getAllDrafts()) |> retryRequest diff --git a/submodules/TelegramCore/TelegramCore/CloudChatRemoveMessagesOperation.swift b/submodules/TelegramCore/TelegramCore/CloudChatRemoveMessagesOperation.swift index 5c684d6ac7..5815d12880 100644 --- a/submodules/TelegramCore/TelegramCore/CloudChatRemoveMessagesOperation.swift +++ b/submodules/TelegramCore/TelegramCore/CloudChatRemoveMessagesOperation.swift @@ -1,132 +1,5 @@ -import Foundation -#if os(macOS) - import PostboxMac -#else - import Postbox -#endif - -enum CloudChatRemoveMessagesType: Int32 { - case forLocalPeer - case forEveryone -} - -extension CloudChatRemoveMessagesType { - init(_ type: InteractiveMessagesDeletionType) { - switch type { - case .forLocalPeer: - self = .forLocalPeer - case .forEveryone: - self = .forEveryone - } - } -} - -final class CloudChatRemoveMessagesOperation: PostboxCoding { - let messageIds: [MessageId] - let type: CloudChatRemoveMessagesType - - init(messageIds: [MessageId], type: CloudChatRemoveMessagesType) { - self.messageIds = messageIds - self.type = type - } - - init(decoder: PostboxDecoder) { - self.messageIds = MessageId.decodeArrayFromBuffer(decoder.decodeBytesForKeyNoCopy("i")!) - self.type = CloudChatRemoveMessagesType(rawValue: decoder.decodeInt32ForKey("t", orElse: 0))! - } - - func encode(_ encoder: PostboxEncoder) { - let buffer = WriteBuffer() - MessageId.encodeArrayToBuffer(self.messageIds, buffer: buffer) - encoder.encodeBytes(buffer, forKey: "i") - encoder.encodeInt32(self.type.rawValue, forKey: "t") - } -} - -final class CloudChatRemoveChatOperation: PostboxCoding { - let peerId: PeerId - let reportChatSpam: Bool - let deleteGloballyIfPossible: Bool - let topMessageId: MessageId? - - init(peerId: PeerId, reportChatSpam: Bool, deleteGloballyIfPossible: Bool, topMessageId: MessageId?) { - self.peerId = peerId - self.reportChatSpam = reportChatSpam - self.deleteGloballyIfPossible = deleteGloballyIfPossible - self.topMessageId = topMessageId - } - - init(decoder: PostboxDecoder) { - self.peerId = PeerId(decoder.decodeInt64ForKey("p", orElse: 0)) - self.reportChatSpam = decoder.decodeInt32ForKey("r", orElse: 0) != 0 - self.deleteGloballyIfPossible = decoder.decodeInt32ForKey("deleteGloballyIfPossible", orElse: 0) != 0 - if let messageIdPeerId = decoder.decodeOptionalInt64ForKey("m.p"), let messageIdNamespace = decoder.decodeOptionalInt32ForKey("m.n"), let messageIdId = decoder.decodeOptionalInt32ForKey("m.i") { - self.topMessageId = MessageId(peerId: PeerId(messageIdPeerId), namespace: messageIdNamespace, id: messageIdId) - } else { - self.topMessageId = nil - } - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt64(self.peerId.toInt64(), forKey: "p") - encoder.encodeInt32(self.reportChatSpam ? 1 : 0, forKey: "r") - encoder.encodeInt32(self.deleteGloballyIfPossible ? 1 : 0, forKey: "deleteGloballyIfPossible") - if let topMessageId = self.topMessageId { - encoder.encodeInt64(topMessageId.peerId.toInt64(), forKey: "m.p") - encoder.encodeInt32(topMessageId.namespace, forKey: "m.n") - encoder.encodeInt32(topMessageId.id, forKey: "m.i") - } else { - encoder.encodeNil(forKey: "m.p") - encoder.encodeNil(forKey: "m.n") - encoder.encodeNil(forKey: "m.i") - } - } -} - -enum CloudChatClearHistoryType: Int32 { - case forLocalPeer - case forEveryone - case scheduledMessages -} - -extension CloudChatClearHistoryType { - init(_ type: InteractiveHistoryClearingType) { - switch type { - case .forLocalPeer: - self = .forLocalPeer - case .forEveryone: - self = .forEveryone - case .scheduledMessages: - self = .scheduledMessages - } - } -} - -final class CloudChatClearHistoryOperation: PostboxCoding { - let peerId: PeerId - let topMessageId: MessageId - let type: CloudChatClearHistoryType - - init(peerId: PeerId, topMessageId: MessageId, type: CloudChatClearHistoryType) { - self.peerId = peerId - self.topMessageId = topMessageId - self.type = type - } - - init(decoder: PostboxDecoder) { - self.peerId = PeerId(decoder.decodeInt64ForKey("p", orElse: 0)) - self.topMessageId = MessageId(peerId: PeerId(decoder.decodeInt64ForKey("m.p", orElse: 0)), namespace: decoder.decodeInt32ForKey("m.n", orElse: 0), id: decoder.decodeInt32ForKey("m.i", orElse: 0)) - self.type = CloudChatClearHistoryType(rawValue: decoder.decodeInt32ForKey("type", orElse: 0)) ?? .forLocalPeer - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt64(self.peerId.toInt64(), forKey: "p") - encoder.encodeInt64(self.topMessageId.peerId.toInt64(), forKey: "m.p") - encoder.encodeInt32(self.topMessageId.namespace, forKey: "m.n") - encoder.encodeInt32(self.topMessageId.id, forKey: "m.i") - encoder.encodeInt32(self.type.rawValue, forKey: "type") - } -} +import Postbox +import SyncCore func cloudChatAddRemoveMessagesOperation(transaction: Transaction, peerId: PeerId, messageIds: [MessageId], type: CloudChatRemoveMessagesType) { transaction.operationLogAddEntry(peerId: peerId, tag: OperationLogTags.CloudChatRemoveMessages, tagLocalIndex: .automatic, tagMergedIndex: .automatic, contents: CloudChatRemoveMessagesOperation(messageIds: messageIds, type: type)) diff --git a/submodules/TelegramCore/TelegramCore/CloudFileMediaResource.swift b/submodules/TelegramCore/TelegramCore/CloudFileMediaResource.swift index 36883a5a57..a90846e2d3 100644 --- a/submodules/TelegramCore/TelegramCore/CloudFileMediaResource.swift +++ b/submodules/TelegramCore/TelegramCore/CloudFileMediaResource.swift @@ -7,6 +7,8 @@ import Foundation import TelegramApi #endif +import SyncCore + protocol TelegramCloudMediaResource: TelegramMediaResource { func apiInputLocation(fileReference: Data?) -> Api.InputFileLocation? } @@ -15,313 +17,29 @@ protocol TelegramMultipartFetchableResource: TelegramMediaResource { var datacenterId: Int { get } } -public struct CloudFileMediaResourceId: MediaResourceId { - let datacenterId: Int - let volumeId: Int64 - let localId: Int32 - let secret: Int64 - - init(datacenterId: Int, volumeId: Int64, localId: Int32, secret: Int64) { - self.datacenterId = datacenterId - self.volumeId = volumeId - self.localId = localId - self.secret = secret - } - - public var uniqueId: String { - return "telegram-cloud-file-\(self.datacenterId)-\(self.volumeId)-\(self.localId)-\(self.secret)" - } - - public var hashValue: Int { - return self.secret.hashValue - } - - public func isEqual(to: MediaResourceId) -> Bool { - if let to = to as? CloudFileMediaResourceId { - return self.datacenterId == to.datacenterId && self.volumeId == to.volumeId && self.localId == to.localId && self.secret == to.secret - } else { - return false - } - } -} - public protocol TelegramCloudMediaResourceWithFileReference { var fileReference: Data? { get } } -public class CloudFileMediaResource: TelegramCloudMediaResource, TelegramMultipartFetchableResource, TelegramCloudMediaResourceWithFileReference { - public let datacenterId: Int - public let volumeId: Int64 - public let localId: Int32 - public let secret: Int64 - public let size: Int? - public let fileReference: Data? - - public var id: MediaResourceId { - return CloudFileMediaResourceId(datacenterId: self.datacenterId, volumeId: self.volumeId, localId: self.localId, secret: self.secret) - } - +extension CloudFileMediaResource: TelegramCloudMediaResource, TelegramMultipartFetchableResource, TelegramCloudMediaResourceWithFileReference { func apiInputLocation(fileReference: Data?) -> Api.InputFileLocation? { return Api.InputFileLocation.inputFileLocation(volumeId: self.volumeId, localId: self.localId, secret: self.secret, fileReference: Buffer(data: fileReference ?? Data())) } - - public init(datacenterId: Int, volumeId: Int64, localId: Int32, secret: Int64, size: Int?, fileReference: Data?) { - self.datacenterId = datacenterId - self.volumeId = volumeId - self.localId = localId - self.secret = secret - self.size = size - self.fileReference = fileReference - } - - public required init(decoder: PostboxDecoder) { - self.datacenterId = Int(decoder.decodeInt32ForKey("d", orElse: 0)) - self.volumeId = decoder.decodeInt64ForKey("v", orElse: 0) - self.localId = decoder.decodeInt32ForKey("l", orElse: 0) - self.secret = decoder.decodeInt64ForKey("s", orElse: 0) - if let size = decoder.decodeOptionalInt32ForKey("n") { - self.size = Int(size) - } else { - self.size = nil - } - self.fileReference = decoder.decodeBytesForKey("fr")?.makeData() - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(Int32(self.datacenterId), forKey: "d") - encoder.encodeInt64(self.volumeId, forKey: "v") - encoder.encodeInt32(self.localId, forKey: "l") - encoder.encodeInt64(self.secret, forKey: "s") - if let size = self.size { - encoder.encodeInt32(Int32(size), forKey: "n") - } else { - encoder.encodeNil(forKey: "n") - } - if let fileReference = self.fileReference { - encoder.encodeBytes(MemoryBuffer(data: fileReference), forKey: "fr") - } else { - encoder.encodeNil(forKey: "fr") - } - } - - public func isEqual(to: MediaResource) -> Bool { - if let to = to as? CloudFileMediaResource { - return self.datacenterId == to.datacenterId && self.volumeId == to.volumeId && self.localId == to.localId && self.secret == to.secret && self.size == to.size && self.fileReference == to.fileReference - } else { - return false - } - } } -public struct CloudPhotoSizeMediaResourceId: MediaResourceId, Hashable { - let datacenterId: Int32 - let photoId: Int64 - let sizeSpec: String - - init(datacenterId: Int32, photoId: Int64, sizeSpec: String) { - self.datacenterId = datacenterId - self.photoId = photoId - self.sizeSpec = sizeSpec - } - - public var uniqueId: String { - return "telegram-cloud-photo-size-\(self.datacenterId)-\(self.photoId)-\(self.sizeSpec)" - } - - public func isEqual(to: MediaResourceId) -> Bool { - if let to = to as? CloudPhotoSizeMediaResourceId { - return self.datacenterId == to.datacenterId && self.photoId == to.photoId && self.sizeSpec == to.sizeSpec - } else { - return false - } - } -} - -public class CloudPhotoSizeMediaResource: TelegramCloudMediaResource, TelegramMultipartFetchableResource, TelegramCloudMediaResourceWithFileReference { - public let datacenterId: Int - public let photoId: Int64 - public let accessHash: Int64 - public let sizeSpec: String - public let volumeId: Int64 - public let localId: Int32 - public let fileReference: Data? - - public var id: MediaResourceId { - return CloudPhotoSizeMediaResourceId(datacenterId: Int32(self.datacenterId), photoId: self.photoId, sizeSpec: self.sizeSpec) - } - +extension CloudPhotoSizeMediaResource: TelegramCloudMediaResource, TelegramMultipartFetchableResource, TelegramCloudMediaResourceWithFileReference { func apiInputLocation(fileReference: Data?) -> Api.InputFileLocation? { return Api.InputFileLocation.inputPhotoFileLocation(id: self.photoId, accessHash: self.accessHash, fileReference: Buffer(data: fileReference ?? Data()), thumbSize: self.sizeSpec) } - - public init(datacenterId: Int32, photoId: Int64, accessHash: Int64, sizeSpec: String, volumeId: Int64, localId: Int32, fileReference: Data?) { - self.datacenterId = Int(datacenterId) - self.photoId = photoId - self.accessHash = accessHash - self.sizeSpec = sizeSpec - self.volumeId = volumeId - self.localId = localId - self.fileReference = fileReference - } - - public required init(decoder: PostboxDecoder) { - self.datacenterId = Int(decoder.decodeInt32ForKey("d", orElse: 0)) - self.photoId = decoder.decodeInt64ForKey("i", orElse: 0) - self.accessHash = decoder.decodeInt64ForKey("h", orElse: 0) - self.sizeSpec = decoder.decodeStringForKey("s", orElse: "") - self.volumeId = decoder.decodeInt64ForKey("v", orElse: 0) - self.localId = decoder.decodeInt32ForKey("l", orElse: 0) - self.fileReference = decoder.decodeBytesForKey("fr")?.makeData() - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(Int32(self.datacenterId), forKey: "d") - encoder.encodeInt64(self.photoId, forKey: "i") - encoder.encodeInt64(self.accessHash, forKey: "h") - encoder.encodeString(self.sizeSpec, forKey: "s") - encoder.encodeInt64(self.volumeId, forKey: "v") - encoder.encodeInt32(self.localId, forKey: "l") - if let fileReference = self.fileReference { - encoder.encodeBytes(MemoryBuffer(data: fileReference), forKey: "fr") - } else { - encoder.encodeNil(forKey: "fr") - } - } - - public func isEqual(to: MediaResource) -> Bool { - if let to = to as? CloudPhotoSizeMediaResource { - return self.datacenterId == to.datacenterId && self.photoId == to.photoId && self.accessHash == to.accessHash && self.sizeSpec == to.sizeSpec && self.volumeId == to.volumeId && self.localId == to.localId && self.fileReference == to.fileReference - } else { - return false - } - } } -public struct CloudDocumentSizeMediaResourceId: MediaResourceId, Hashable { - let datacenterId: Int32 - let documentId: Int64 - let sizeSpec: String - - init(datacenterId: Int32, documentId: Int64, sizeSpec: String) { - self.datacenterId = datacenterId - self.documentId = documentId - self.sizeSpec = sizeSpec - } - - public var uniqueId: String { - return "telegram-cloud-document-size-\(self.datacenterId)-\(self.documentId)-\(self.sizeSpec)" - } - - public func isEqual(to: MediaResourceId) -> Bool { - if let to = to as? CloudDocumentSizeMediaResourceId { - return self.datacenterId == to.datacenterId && self.documentId == to.documentId && self.sizeSpec == to.sizeSpec - } else { - return false - } - } -} - -public class CloudDocumentSizeMediaResource: TelegramCloudMediaResource, TelegramMultipartFetchableResource, TelegramCloudMediaResourceWithFileReference { - public let datacenterId: Int - public let documentId: Int64 - public let accessHash: Int64 - public let sizeSpec: String - public let volumeId: Int64 - public let localId: Int32 - public let fileReference: Data? - - public var id: MediaResourceId { - return CloudDocumentSizeMediaResourceId(datacenterId: Int32(self.datacenterId), documentId: self.documentId, sizeSpec: self.sizeSpec) - } - +extension CloudDocumentSizeMediaResource: TelegramCloudMediaResource, TelegramMultipartFetchableResource, TelegramCloudMediaResourceWithFileReference { func apiInputLocation(fileReference: Data?) -> Api.InputFileLocation? { return Api.InputFileLocation.inputDocumentFileLocation(id: self.documentId, accessHash: self.accessHash, fileReference: Buffer(data: fileReference ?? Data()), thumbSize: self.sizeSpec) } - - public init(datacenterId: Int32, documentId: Int64, accessHash: Int64, sizeSpec: String, volumeId: Int64, localId: Int32, fileReference: Data?) { - self.datacenterId = Int(datacenterId) - self.documentId = documentId - self.accessHash = accessHash - self.sizeSpec = sizeSpec - self.volumeId = volumeId - self.localId = localId - self.fileReference = fileReference - } - - public required init(decoder: PostboxDecoder) { - self.datacenterId = Int(decoder.decodeInt32ForKey("d", orElse: 0)) - self.documentId = decoder.decodeInt64ForKey("i", orElse: 0) - self.accessHash = decoder.decodeInt64ForKey("h", orElse: 0) - self.sizeSpec = decoder.decodeStringForKey("s", orElse: "") - self.volumeId = decoder.decodeInt64ForKey("v", orElse: 0) - self.localId = decoder.decodeInt32ForKey("l", orElse: 0) - self.fileReference = decoder.decodeBytesForKey("fr")?.makeData() - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(Int32(self.datacenterId), forKey: "d") - encoder.encodeInt64(self.documentId, forKey: "i") - encoder.encodeInt64(self.accessHash, forKey: "h") - encoder.encodeString(self.sizeSpec, forKey: "s") - encoder.encodeInt64(self.volumeId, forKey: "v") - encoder.encodeInt32(self.localId, forKey: "l") - if let fileReference = self.fileReference { - encoder.encodeBytes(MemoryBuffer(data: fileReference), forKey: "fr") - } else { - encoder.encodeNil(forKey: "fr") - } - } - - public func isEqual(to: MediaResource) -> Bool { - if let to = to as? CloudDocumentSizeMediaResource { - return self.datacenterId == to.datacenterId && self.documentId == to.documentId && self.accessHash == to.accessHash && self.sizeSpec == to.sizeSpec && self.volumeId == to.volumeId && self.localId == to.localId && self.fileReference == to.fileReference - } else { - return false - } - } } -public enum CloudPeerPhotoSizeSpec: Int32 { - case small - case fullSize -} - -public struct CloudPeerPhotoSizeMediaResourceId: MediaResourceId, Hashable { - let datacenterId: Int32 - let sizeSpec: CloudPeerPhotoSizeSpec - let volumeId: Int64 - let localId: Int32 - - init(datacenterId: Int32, sizeSpec: CloudPeerPhotoSizeSpec, volumeId: Int64, localId: Int32) { - self.datacenterId = datacenterId - self.sizeSpec = sizeSpec - self.volumeId = volumeId - self.localId = localId - } - - public var uniqueId: String { - return "telegram-peer-photo-size-\(self.datacenterId)-\(self.sizeSpec.rawValue)-\(self.volumeId)-\(self.localId)" - } - - public func isEqual(to: MediaResourceId) -> Bool { - if let to = to as? CloudPeerPhotoSizeMediaResourceId { - return self.datacenterId == to.datacenterId && self.sizeSpec == to.sizeSpec && self.volumeId == to.volumeId && self.localId == to.localId - } else { - return false - } - } -} - -public class CloudPeerPhotoSizeMediaResource: TelegramMultipartFetchableResource { - public let datacenterId: Int - let sizeSpec: CloudPeerPhotoSizeSpec - let volumeId: Int64 - let localId: Int32 - - public var id: MediaResourceId { - return CloudPeerPhotoSizeMediaResourceId(datacenterId: Int32(self.datacenterId), sizeSpec: self.sizeSpec, volumeId: self.volumeId, localId: self.localId) - } - +extension CloudPeerPhotoSizeMediaResource: TelegramMultipartFetchableResource { func apiInputLocation(peerReference: PeerReference) -> Api.InputFileLocation? { let flags: Int32 switch self.sizeSpec { @@ -332,570 +50,28 @@ public class CloudPeerPhotoSizeMediaResource: TelegramMultipartFetchableResourc } return Api.InputFileLocation.inputPeerPhotoFileLocation(flags: flags, peer: peerReference.inputPeer, volumeId: self.volumeId, localId: self.localId) } - - public init(datacenterId: Int32, sizeSpec: CloudPeerPhotoSizeSpec, volumeId: Int64, localId: Int32) { - self.datacenterId = Int(datacenterId) - self.sizeSpec = sizeSpec - self.volumeId = volumeId - self.localId = localId - } - - public required init(decoder: PostboxDecoder) { - self.datacenterId = Int(decoder.decodeInt32ForKey("d", orElse: 0)) - self.sizeSpec = CloudPeerPhotoSizeSpec(rawValue: decoder.decodeInt32ForKey("s", orElse: 0)) ?? .small - self.volumeId = decoder.decodeInt64ForKey("v", orElse: 0) - self.localId = decoder.decodeInt32ForKey("l", orElse: 0) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(Int32(self.datacenterId), forKey: "d") - encoder.encodeInt32(self.sizeSpec.rawValue, forKey: "s") - encoder.encodeInt64(self.volumeId, forKey: "v") - encoder.encodeInt32(self.localId, forKey: "l") - } - - public func isEqual(to: MediaResource) -> Bool { - if let to = to as? CloudPeerPhotoSizeMediaResource { - return self.datacenterId == to.datacenterId && self.sizeSpec == to.sizeSpec && self.volumeId == to.volumeId && self.localId == to.localId - } else { - return false - } - } } -public struct CloudStickerPackThumbnailMediaResourceId: MediaResourceId, Hashable { - let datacenterId: Int32 - let volumeId: Int64 - let localId: Int32 - - init(datacenterId: Int32, volumeId: Int64, localId: Int32) { - self.datacenterId = datacenterId - self.volumeId = volumeId - self.localId = localId - } - - public var uniqueId: String { - return "telegram-stickerpackthumbnail-\(self.datacenterId)-\(self.volumeId)-\(self.localId)" - } - - public func isEqual(to: MediaResourceId) -> Bool { - if let to = to as? CloudStickerPackThumbnailMediaResourceId { - return self.datacenterId == to.datacenterId && self.volumeId == to.volumeId && self.localId == to.localId - } else { - return false - } - } -} - -public class CloudStickerPackThumbnailMediaResource: TelegramMultipartFetchableResource { - public let datacenterId: Int - let volumeId: Int64 - let localId: Int32 - - public var id: MediaResourceId { - return CloudStickerPackThumbnailMediaResourceId(datacenterId: Int32(self.datacenterId), volumeId: self.volumeId, localId: self.localId) - } - +extension CloudStickerPackThumbnailMediaResource: TelegramMultipartFetchableResource { func apiInputLocation(packReference: StickerPackReference) -> Api.InputFileLocation? { return Api.InputFileLocation.inputStickerSetThumb(stickerset: packReference.apiInputStickerSet, volumeId: self.volumeId, localId: self.localId) } - - public init(datacenterId: Int32, volumeId: Int64, localId: Int32) { - self.datacenterId = Int(datacenterId) - self.volumeId = volumeId - self.localId = localId - } - - public required init(decoder: PostboxDecoder) { - self.datacenterId = Int(decoder.decodeInt32ForKey("d", orElse: 0)) - self.volumeId = decoder.decodeInt64ForKey("v", orElse: 0) - self.localId = decoder.decodeInt32ForKey("l", orElse: 0) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(Int32(self.datacenterId), forKey: "d") - encoder.encodeInt64(self.volumeId, forKey: "v") - encoder.encodeInt32(self.localId, forKey: "l") - } - - public func isEqual(to: MediaResource) -> Bool { - if let to = to as? CloudPeerPhotoSizeMediaResource { - return self.datacenterId == to.datacenterId && self.volumeId == to.volumeId && self.localId == to.localId - } else { - return false - } - } } -public struct CloudDocumentMediaResourceId: MediaResourceId { - let datacenterId: Int - let fileId: Int64 - - init(datacenterId: Int, fileId: Int64) { - self.datacenterId = datacenterId - self.fileId = fileId - } - - public var uniqueId: String { - return "telegram-cloud-document-\(self.datacenterId)-\(self.fileId)" - } - - public var hashValue: Int { - return self.fileId.hashValue - } - - public func isEqual(to: MediaResourceId) -> Bool { - if let to = to as? CloudDocumentMediaResourceId { - return self.datacenterId == to.datacenterId && self.fileId == to.fileId - } else { - return false - } - } -} - -public class CloudDocumentMediaResource: TelegramCloudMediaResource, TelegramMultipartFetchableResource, TelegramCloudMediaResourceWithFileReference { - public let datacenterId: Int - public let fileId: Int64 - public let accessHash: Int64 - public let size: Int? - public let fileReference: Data? - public let fileName: String? - - public var id: MediaResourceId { - return CloudDocumentMediaResourceId(datacenterId: self.datacenterId, fileId: self.fileId) - } - +extension CloudDocumentMediaResource: TelegramCloudMediaResource, TelegramMultipartFetchableResource, TelegramCloudMediaResourceWithFileReference { func apiInputLocation(fileReference: Data?) -> Api.InputFileLocation? { return Api.InputFileLocation.inputDocumentFileLocation(id: self.fileId, accessHash: self.accessHash, fileReference: Buffer(data: fileReference ?? Data()), thumbSize: "") } - - public init(datacenterId: Int, fileId: Int64, accessHash: Int64, size: Int?, fileReference: Data?, fileName: String?) { - self.datacenterId = datacenterId - self.fileId = fileId - self.accessHash = accessHash - self.size = size - self.fileReference = fileReference - self.fileName = fileName - } - - public required init(decoder: PostboxDecoder) { - self.datacenterId = Int(decoder.decodeInt32ForKey("d", orElse: 0)) - self.fileId = decoder.decodeInt64ForKey("f", orElse: 0) - self.accessHash = decoder.decodeInt64ForKey("a", orElse: 0) - if let size = decoder.decodeOptionalInt32ForKey("n") { - self.size = Int(size) - } else { - self.size = nil - } - self.fileReference = decoder.decodeBytesForKey("fr")?.makeData() - self.fileName = decoder.decodeOptionalStringForKey("fn") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(Int32(self.datacenterId), forKey: "d") - encoder.encodeInt64(self.fileId, forKey: "f") - encoder.encodeInt64(self.accessHash, forKey: "a") - if let size = self.size { - encoder.encodeInt32(Int32(size), forKey: "n") - } else { - encoder.encodeNil(forKey: "n") - } - if let fileReference = self.fileReference { - encoder.encodeBytes(MemoryBuffer(data: fileReference), forKey: "fr") - } else { - encoder.encodeNil(forKey: "fr") - } - if let fileName = self.fileName { - encoder.encodeString(fileName, forKey: "fn") - } else { - encoder.encodeNil(forKey: "fn") - } - } - - public func isEqual(to: MediaResource) -> Bool { - if let to = to as? CloudDocumentMediaResource { - return self.datacenterId == to.datacenterId && self.fileId == to.fileId && self.accessHash == to.accessHash && self.size == to.size && self.fileReference == to.fileReference - } else { - return false - } - } } -public struct LocalFileMediaResourceId: MediaResourceId { - public let fileId: Int64 - - public var uniqueId: String { - return "telegram-local-file-\(self.fileId)" - } - - public var hashValue: Int { - return self.fileId.hashValue - } - - public func isEqual(to: MediaResourceId) -> Bool { - if let to = to as? LocalFileMediaResourceId { - return self.fileId == to.fileId - } else { - return false - } - } -} - -public class LocalFileMediaResource: TelegramMediaResource { - public let fileId: Int64 - public let size: Int? - - public init(fileId: Int64, size: Int? = nil) { - self.fileId = fileId - self.size = size - } - - public required init(decoder: PostboxDecoder) { - self.fileId = decoder.decodeInt64ForKey("f", orElse: 0) - if let size = decoder.decodeOptionalInt32ForKey("s") { - self.size = Int(size) - } else { - self.size = nil - } - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt64(self.fileId, forKey: "f") - if let size = self.size { - encoder.encodeInt32(Int32(size), forKey: "s") - } else { - encoder.encodeNil(forKey: "s") - } - } - - public var id: MediaResourceId { - return LocalFileMediaResourceId(fileId: self.fileId) - } - - public func isEqual(to: MediaResource) -> Bool { - if let to = to as? LocalFileMediaResource { - return self.fileId == to.fileId && self.size == to.size - } else { - return false - } - } -} - -public struct LocalFileReferenceMediaResourceId: MediaResourceId { - public let randomId: Int64 - - public var uniqueId: String { - return "local-file-\(self.randomId)" - } - - public var hashValue: Int { - return self.randomId.hashValue - } - - public func isEqual(to: MediaResourceId) -> Bool { - if let to = to as? LocalFileReferenceMediaResourceId { - return self.randomId == to.randomId - } else { - return false - } - } -} - -public class LocalFileReferenceMediaResource: TelegramMediaResource { - public let localFilePath: String - let randomId: Int64 - let isUniquelyReferencedTemporaryFile: Bool - public let size: Int32? - - public init(localFilePath: String, randomId: Int64, isUniquelyReferencedTemporaryFile: Bool = false, size: Int32? = nil) { - self.localFilePath = localFilePath - self.randomId = randomId - self.isUniquelyReferencedTemporaryFile = isUniquelyReferencedTemporaryFile - self.size = size - } - - public required init(decoder: PostboxDecoder) { - self.localFilePath = decoder.decodeStringForKey("p", orElse: "") - self.randomId = decoder.decodeInt64ForKey("r", orElse: 0) - self.isUniquelyReferencedTemporaryFile = decoder.decodeInt32ForKey("t", orElse: 0) != 0 - self.size = decoder.decodeOptionalInt32ForKey("s") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.localFilePath, forKey: "p") - encoder.encodeInt64(self.randomId, forKey: "r") - encoder.encodeInt32(self.isUniquelyReferencedTemporaryFile ? 1 : 0, forKey: "t") - if let size = self.size { - encoder.encodeInt32(size, forKey: "s") - } else { - encoder.encodeNil(forKey: "s") - } - } - - public var id: MediaResourceId { - return LocalFileReferenceMediaResourceId(randomId: self.randomId) - } - - public func isEqual(to: MediaResource) -> Bool { - if let to = to as? LocalFileReferenceMediaResource { - return self.localFilePath == to.localFilePath && self.randomId == to.randomId && self.size == to.size && self.isUniquelyReferencedTemporaryFile == to.isUniquelyReferencedTemporaryFile - } else { - return false - } - } -} - -public struct HttpReferenceMediaResourceId: MediaResourceId { - public let url: String - - public func isEqual(to: MediaResourceId) -> Bool { - if let to = to as? HttpReferenceMediaResourceId { - return self.url == to.url - } else { - return false - } - } - - public var hashValue: Int { - return self.url.hashValue - } - - public var uniqueId: String { - return "http-\(persistentHash32(self.url))" - } -} - -public final class HttpReferenceMediaResource: TelegramMediaResource { - public let url: String - public let size: Int? - - public init(url: String, size: Int?) { - self.url = url - self.size = size - } - - public required init(decoder: PostboxDecoder) { - self.url = decoder.decodeStringForKey("u", orElse: "") - if let size = decoder.decodeOptionalInt32ForKey("s") { - self.size = Int(size) - } else { - self.size = nil - } - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.url, forKey: "u") - if let size = self.size { - encoder.encodeInt32(Int32(size), forKey: "s") - } else { - encoder.encodeNil(forKey: "s") - } - } - - public var id: MediaResourceId { - return HttpReferenceMediaResourceId(url: self.url) - } - - public func isEqual(to: MediaResource) -> Bool { - if let to = to as? HttpReferenceMediaResource { - return to.url == self.url - } else { - return false - } - } -} - -public struct WebFileReferenceMediaResourceId: MediaResourceId { - public let url: String - public let accessHash: Int64 - public let size: Int32 - - public func isEqual(to: MediaResourceId) -> Bool { - if let to = to as? WebFileReferenceMediaResourceId { - return self.url == to.url && size == to.size && accessHash == to.accessHash - } else { - return false - } - } - - public var hashValue: Int { - return self.url.hashValue - } - - public var uniqueId: String { - return "proxy-\(persistentHash32(self.url))-\(size)-\(accessHash)" - } -} - -public final class WebFileReferenceMediaResource: TelegramMediaResource { - public let url: String - public let size: Int32 - public let accessHash: Int64 - - public init(url: String, size: Int32, accessHash: Int64) { - self.url = url - self.size = size - self.accessHash = accessHash - } - - var apiInputLocation: Api.InputWebFileLocation { - return Api.InputWebFileLocation.inputWebFileLocation(url: url, accessHash: accessHash) - } - - public required init(decoder: PostboxDecoder) { - self.url = decoder.decodeStringForKey("u", orElse: "") - self.size = decoder.decodeInt32ForKey("s", orElse: 0) - self.accessHash = decoder.decodeInt64ForKey("h", orElse: 0) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.url, forKey: "u") - encoder.encodeInt32(self.size, forKey: "s") - encoder.encodeInt64(self.accessHash, forKey: "h") - } - - public var id: MediaResourceId { - return WebFileReferenceMediaResourceId(url: self.url, accessHash: accessHash, size: self.size) - } - - public func isEqual(to: MediaResource) -> Bool { - if let to = to as? WebFileReferenceMediaResource { - return to.url == self.url && to.size == self.size && to.accessHash == self.accessHash - } else { - return false - } - } -} - - -public struct SecretFileMediaResourceId: MediaResourceId { - public let fileId: Int64 - public let datacenterId: Int32 - - public var uniqueId: String { - return "secret-file-\(self.fileId)-\(self.datacenterId)" - } - - public init(fileId: Int64, datacenterId: Int32) { - self.fileId = fileId - self.datacenterId = datacenterId - } - - public var hashValue: Int { - return self.fileId.hashValue - } - - public func isEqual(to: MediaResourceId) -> Bool { - if let to = to as? SecretFileMediaResourceId { - return self.fileId == to.fileId && self.datacenterId == to.datacenterId - } else { - return false - } - } -} - -public struct SecretFileMediaResource: TelegramCloudMediaResource, TelegramMultipartFetchableResource { - public let fileId: Int64 - public let accessHash: Int64 - public var size: Int? { - return Int(self.decryptedSize) - } - public let containerSize: Int32 - public let decryptedSize: Int32 - public let datacenterId: Int - public let key: SecretFileEncryptionKey - +extension SecretFileMediaResource: TelegramCloudMediaResource, TelegramMultipartFetchableResource { func apiInputLocation(fileReference: Data?) -> Api.InputFileLocation? { return .inputEncryptedFileLocation(id: self.fileId, accessHash: self.accessHash) } - - public init(fileId: Int64, accessHash: Int64, containerSize: Int32, decryptedSize: Int32, datacenterId: Int, key: SecretFileEncryptionKey) { - self.fileId = fileId - self.accessHash = accessHash - self.containerSize = containerSize - self.decryptedSize = decryptedSize - self.datacenterId = datacenterId - self.key = key - } - - public init(decoder: PostboxDecoder) { - self.fileId = decoder.decodeInt64ForKey("i", orElse: 0) - self.accessHash = decoder.decodeInt64ForKey("a", orElse: 0) - self.containerSize = decoder.decodeInt32ForKey("s", orElse: 0) - self.decryptedSize = decoder.decodeInt32ForKey("ds", orElse: 0) - self.datacenterId = Int(decoder.decodeInt32ForKey("d", orElse: 0)) - self.key = decoder.decodeObjectForKey("k", decoder: { SecretFileEncryptionKey(decoder: $0) }) as! SecretFileEncryptionKey - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt64(self.fileId, forKey: "i") - encoder.encodeInt64(self.accessHash, forKey: "a") - encoder.encodeInt32(self.containerSize, forKey: "s") - encoder.encodeInt32(self.decryptedSize, forKey: "ds") - encoder.encodeInt32(Int32(self.datacenterId), forKey: "d") - encoder.encodeObject(self.key, forKey: "k") - } - - public var id: MediaResourceId { - return SecretFileMediaResourceId(fileId: self.fileId, datacenterId: Int32(self.datacenterId)) - } - - public func isEqual(to: MediaResource) -> Bool { - if let to = to as? SecretFileMediaResource { - if self.fileId != to.fileId { - return false - } - if self.accessHash != to.accessHash { - return false - } - if self.containerSize != to.containerSize { - return false - } - if self.decryptedSize != to.decryptedSize { - return false - } - if self.datacenterId != to.datacenterId { - return false - } - if self.key != to.key { - return false - } - return true - } else { - return false - } - } } -public struct EmptyMediaResourceId: MediaResourceId { - public var uniqueId: String { - return "empty-resource" - } - - public var hashValue: Int { - return 0 - } - - public func isEqual(to: MediaResourceId) -> Bool { - return to is EmptyMediaResourceId - } -} - -public final class EmptyMediaResource: TelegramMediaResource { - public init() { - } - - public init(decoder: PostboxDecoder) { - } - - public func encode(_ encoder: PostboxEncoder) { - } - - public var id: MediaResourceId { - return EmptyMediaResourceId() - } - - public func isEqual(to: MediaResource) -> Bool { - return to is EmptyMediaResource +extension WebFileReferenceMediaResource { + var apiInputLocation: Api.InputWebFileLocation { + return .inputWebFileLocation(url: self.url, accessHash: self.accessHash) } } diff --git a/submodules/TelegramCore/TelegramCore/CloudMediaResourceParameters.swift b/submodules/TelegramCore/TelegramCore/CloudMediaResourceParameters.swift index e9e165bf24..a572e568bf 100644 --- a/submodules/TelegramCore/TelegramCore/CloudMediaResourceParameters.swift +++ b/submodules/TelegramCore/TelegramCore/CloudMediaResourceParameters.swift @@ -1,4 +1,5 @@ import Foundation +import SyncCore public enum CloudMediaResourceLocation: Equatable { case photo(id: Int64, accessHash: Int64, fileReference: Data, thumbSize: String) diff --git a/submodules/TelegramCore/TelegramCore/CollectCacheUsageStats.swift b/submodules/TelegramCore/TelegramCore/CollectCacheUsageStats.swift index 699893259a..8811e63a17 100644 --- a/submodules/TelegramCore/TelegramCore/CollectCacheUsageStats.swift +++ b/submodules/TelegramCore/TelegramCore/CollectCacheUsageStats.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public enum PeerCacheUsageCategory: Int32 { case image = 0 case video diff --git a/submodules/TelegramCore/TelegramCore/ConsumePersonalMessageAction.swift b/submodules/TelegramCore/TelegramCore/ConsumePersonalMessageAction.swift deleted file mode 100644 index 2cac19e09e..0000000000 --- a/submodules/TelegramCore/TelegramCore/ConsumePersonalMessageAction.swift +++ /dev/null @@ -1,27 +0,0 @@ -import Foundation -#if os(macOS) - import PostboxMac - import SwiftSignalKitMac -#else - import Postbox - import SwiftSignalKit -#endif - -final class ConsumePersonalMessageAction: PendingMessageActionData { - init() { - } - - init(decoder: PostboxDecoder) { - } - - func encode(_ encoder: PostboxEncoder) { - } - - func isEqual(to: PendingMessageActionData) -> Bool { - if let _ = to as? ConsumePersonalMessageAction { - return true - } else { - return false - } - } -} diff --git a/submodules/TelegramCore/TelegramCore/ContactManagement.swift b/submodules/TelegramCore/TelegramCore/ContactManagement.swift index ca6bdce912..7afd214e68 100644 --- a/submodules/TelegramCore/TelegramCore/ContactManagement.swift +++ b/submodules/TelegramCore/TelegramCore/ContactManagement.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + private func md5(_ data: Data) -> Data { return data.withUnsafeBytes { bytes -> Data in return CryptoMD5(bytes, Int32(data.count)) diff --git a/submodules/TelegramCore/TelegramCore/ContactSyncManager.swift b/submodules/TelegramCore/TelegramCore/ContactSyncManager.swift index ab44d8956f..d6434ff194 100644 --- a/submodules/TelegramCore/TelegramCore/ContactSyncManager.swift +++ b/submodules/TelegramCore/TelegramCore/ContactSyncManager.swift @@ -9,6 +9,8 @@ import SwiftSignalKit import TelegramApi #endif +import SyncCore + private func normalizedPhoneNumber(_ value: String) -> String { var result = "" for c in value { diff --git a/submodules/TelegramCore/TelegramCore/ContentPrivacySettings.swift b/submodules/TelegramCore/TelegramCore/ContentPrivacySettings.swift index 1928ce35e3..478a44a6a6 100644 --- a/submodules/TelegramCore/TelegramCore/ContentPrivacySettings.swift +++ b/submodules/TelegramCore/TelegramCore/ContentPrivacySettings.swift @@ -13,46 +13,7 @@ import Foundation #endif #endif -public final class ContentPrivacySettings: PreferencesEntry, Equatable { - public let enableSecretChatWebpagePreviews: Bool? - - public static var defaultSettings = ContentPrivacySettings(enableSecretChatWebpagePreviews: nil) - - public init(enableSecretChatWebpagePreviews: Bool?) { - self.enableSecretChatWebpagePreviews = enableSecretChatWebpagePreviews - } - - public init(decoder: PostboxDecoder) { - self.enableSecretChatWebpagePreviews = decoder.decodeOptionalInt32ForKey("enableSecretChatWebpagePreviews").flatMap { $0 != 0 } - } - - public func encode(_ encoder: PostboxEncoder) { - if let enableSecretChatWebpagePreviews = self.enableSecretChatWebpagePreviews { - encoder.encodeInt32(enableSecretChatWebpagePreviews ? 1 : 0, forKey: "enableSecretChatWebpagePreviews") - } else { - encoder.encodeNil(forKey: "enableSecretChatWebpagePreviews") - } - } - - public func withUpdatedEnableSecretChatWebpagePreviews(_ enableSecretChatWebpagePreviews: Bool) -> ContentPrivacySettings { - return ContentPrivacySettings(enableSecretChatWebpagePreviews: enableSecretChatWebpagePreviews) - } - - public func isEqual(to: PreferencesEntry) -> Bool { - guard let to = to as? ContentPrivacySettings else { - return false - } - - return self == to - } - - public static func ==(lhs: ContentPrivacySettings, rhs: ContentPrivacySettings) -> Bool { - if lhs.enableSecretChatWebpagePreviews != rhs.enableSecretChatWebpagePreviews { - return false - } - return true - } -} +import SyncCore public func updateContentPrivacySettings(postbox: Postbox, _ f: @escaping (ContentPrivacySettings) -> ContentPrivacySettings) -> Signal { return postbox.transaction { transaction -> Void in diff --git a/submodules/TelegramCore/TelegramCore/CoreSettings.swift b/submodules/TelegramCore/TelegramCore/CoreSettings.swift index 87b262db74..9d5fcd7c3f 100644 --- a/submodules/TelegramCore/TelegramCore/CoreSettings.swift +++ b/submodules/TelegramCore/TelegramCore/CoreSettings.swift @@ -13,6 +13,8 @@ import Foundation #endif #endif +import SyncCore + public final class CoreSettings: PreferencesEntry, Equatable { public let fastForward: Bool diff --git a/submodules/TelegramCore/TelegramCore/DeepLinkInfo.swift b/submodules/TelegramCore/TelegramCore/DeepLinkInfo.swift index cbe394e411..f9432ad501 100644 --- a/submodules/TelegramCore/TelegramCore/DeepLinkInfo.swift +++ b/submodules/TelegramCore/TelegramCore/DeepLinkInfo.swift @@ -7,6 +7,8 @@ import SwiftSignalKit import TelegramApi #endif +import SyncCore + public struct DeepLinkInfo { public let message: String public let entities: [MessageTextEntity] diff --git a/submodules/TelegramCore/TelegramCore/DeleteMessages.swift b/submodules/TelegramCore/TelegramCore/DeleteMessages.swift index 606ab0cf4e..b0636ba150 100644 --- a/submodules/TelegramCore/TelegramCore/DeleteMessages.swift +++ b/submodules/TelegramCore/TelegramCore/DeleteMessages.swift @@ -7,6 +7,8 @@ import Postbox import SwiftSignalKit #endif +import SyncCore + private func removeMessageMedia(message: Message, mediaBox: MediaBox) { for media in message.media { if let image = media as? TelegramMediaImage { diff --git a/submodules/TelegramCore/TelegramCore/DeleteMessagesInteractively.swift b/submodules/TelegramCore/TelegramCore/DeleteMessagesInteractively.swift index 0b8992a424..e98bf4e555 100644 --- a/submodules/TelegramCore/TelegramCore/DeleteMessagesInteractively.swift +++ b/submodules/TelegramCore/TelegramCore/DeleteMessagesInteractively.swift @@ -15,10 +15,7 @@ import Foundation #endif #endif -public enum InteractiveMessagesDeletionType: Int32 { - case forLocalPeer = 0 - case forEveryone = 1 -} +import SyncCore public func deleteMessagesInteractively(postbox: Postbox, messageIds initialMessageIds: [MessageId], type: InteractiveMessagesDeletionType, deleteAllInGroup: Bool = false) -> Signal { return postbox.transaction { transaction -> Void in @@ -80,12 +77,6 @@ public func deleteMessagesInteractively(postbox: Postbox, messageIds initialMess } } -public enum InteractiveHistoryClearingType: Int32 { - case forLocalPeer = 0 - case forEveryone = 1 - case scheduledMessages = 2 -} - public func clearHistoryInteractively(postbox: Postbox, peerId: PeerId, type: InteractiveHistoryClearingType) -> Signal { return postbox.transaction { transaction -> Void in if peerId.namespace == Namespaces.Peer.CloudUser || peerId.namespace == Namespaces.Peer.CloudGroup || peerId.namespace == Namespaces.Peer.CloudChannel { diff --git a/submodules/TelegramCore/TelegramCore/DeviceContact.swift b/submodules/TelegramCore/TelegramCore/DeviceContact.swift index f8ac991254..2343224b67 100644 --- a/submodules/TelegramCore/TelegramCore/DeviceContact.swift +++ b/submodules/TelegramCore/TelegramCore/DeviceContact.swift @@ -5,6 +5,8 @@ import PostboxMac import Postbox #endif +import SyncCore + public struct DeviceContactNormalizedPhoneNumber: Hashable, RawRepresentable { public let rawValue: String @@ -76,33 +78,3 @@ public final class DeviceContact: Equatable { return true } } - -public final class ImportableDeviceContactData: Equatable, PostboxCoding { - public let firstName: String - public let lastName: String - - public init(firstName: String, lastName: String) { - self.firstName = firstName - self.lastName = lastName - } - - public init(decoder: PostboxDecoder) { - self.firstName = decoder.decodeStringForKey("f", orElse: "") - self.lastName = decoder.decodeStringForKey("l", orElse: "") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.firstName, forKey: "f") - encoder.encodeString(self.lastName, forKey: "l") - } - - public static func ==(lhs: ImportableDeviceContactData, rhs: ImportableDeviceContactData) -> Bool { - if lhs.firstName != rhs.firstName { - return false - } - if lhs.lastName != rhs.lastName { - return false - } - return true - } -} diff --git a/submodules/TelegramCore/TelegramCore/EarliestUnseenPersonalMentionMessage.swift b/submodules/TelegramCore/TelegramCore/EarliestUnseenPersonalMentionMessage.swift index adfeb61e91..59e12df2de 100644 --- a/submodules/TelegramCore/TelegramCore/EarliestUnseenPersonalMentionMessage.swift +++ b/submodules/TelegramCore/TelegramCore/EarliestUnseenPersonalMentionMessage.swift @@ -13,6 +13,8 @@ import Foundation #endif #endif +import SyncCore + public enum EarliestUnseenPersonalMentionMessageResult: Equatable { case loading case result(MessageId?) diff --git a/submodules/TelegramCore/TelegramCore/EmojiKeywords.swift b/submodules/TelegramCore/TelegramCore/EmojiKeywords.swift index e08a1d1300..9c34d89fb5 100644 --- a/submodules/TelegramCore/TelegramCore/EmojiKeywords.swift +++ b/submodules/TelegramCore/TelegramCore/EmojiKeywords.swift @@ -7,98 +7,7 @@ import Postbox import SwiftSignalKit #endif -func emojiKeywordColletionIdForCode(_ code: String) -> ItemCollectionId { - return ItemCollectionId(namespace: Namespaces.ItemCollection.EmojiKeywords, id: Int64(HashFunctions.murMurHash32(code))) -} - -public final class EmojiKeywordCollectionInfo: ItemCollectionInfo, Equatable { - public let id: ItemCollectionId - public let languageCode: String - public let inputLanguageCode: String - public let version: Int32 - public let timestamp: Int32 - - public init(languageCode: String, inputLanguageCode: String, version: Int32, timestamp: Int32) { - self.id = emojiKeywordColletionIdForCode(inputLanguageCode) - self.languageCode = languageCode - self.inputLanguageCode = inputLanguageCode - self.version = version - self.timestamp = timestamp - } - - public init(decoder: PostboxDecoder) { - self.id = ItemCollectionId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)) - self.languageCode = decoder.decodeStringForKey("lc", orElse: "") - self.inputLanguageCode = decoder.decodeStringForKey("ilc", orElse: "") - self.version = decoder.decodeInt32ForKey("v", orElse: 0) - self.timestamp = decoder.decodeInt32ForKey("t", orElse: 0) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.id.namespace, forKey: "i.n") - encoder.encodeInt64(self.id.id, forKey: "i.i") - encoder.encodeString(self.languageCode, forKey: "lc") - encoder.encodeString(self.inputLanguageCode, forKey: "ilc") - encoder.encodeInt32(self.version, forKey: "v") - encoder.encodeInt32(self.timestamp, forKey: "t") - } - - public static func ==(lhs: EmojiKeywordCollectionInfo, rhs: EmojiKeywordCollectionInfo) -> Bool { - if lhs.id != rhs.id { - return false - } - if lhs.languageCode != rhs.languageCode { - return false - } - if lhs.inputLanguageCode != rhs.inputLanguageCode { - return false - } - if lhs.version != rhs.version { - return false - } - if lhs.timestamp != rhs.timestamp { - return false - } - return true - } -} - -public final class EmojiKeywordItem: ItemCollectionItem, Equatable { - public let index: ItemCollectionItemIndex - public let collectionId: ItemCollectionId.Id - public let keyword: String - public let emoticons: [String] - public let indexKeys: [MemoryBuffer] - - public init(index: ItemCollectionItemIndex, collectionId: ItemCollectionId.Id, keyword: String, emoticons: [String], indexKeys: [MemoryBuffer]) { - self.index = index - self.collectionId = collectionId - self.keyword = keyword - self.emoticons = emoticons - self.indexKeys = indexKeys - } - - public init(decoder: PostboxDecoder) { - self.index = ItemCollectionItemIndex(index: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)) - self.collectionId = decoder.decodeInt64ForKey("c", orElse: 0) - self.keyword = decoder.decodeStringForKey("k", orElse: "") - self.emoticons = decoder.decodeStringArrayForKey("e") - self.indexKeys = decoder.decodeBytesArrayForKey("s") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.index.index, forKey: "i.n") - encoder.encodeInt64(self.index.id, forKey: "i.i") - encoder.encodeInt64(self.collectionId, forKey: "c") - encoder.encodeString(self.keyword, forKey: "k") - encoder.encodeStringArray(self.emoticons, forKey: "e") - encoder.encodeBytesArray(self.indexKeys, forKey: "s") - } - - public static func ==(lhs: EmojiKeywordItem, rhs: EmojiKeywordItem) -> Bool { - return lhs.index == rhs.index && lhs.collectionId == rhs.collectionId && lhs.keyword == rhs.keyword && lhs.emoticons == rhs.emoticons && lhs.indexKeys == rhs.indexKeys - } -} +import SyncCore private let refreshTimeout: Int32 = 60 * 60 diff --git a/submodules/TelegramCore/TelegramCore/EnqueueMessage.swift b/submodules/TelegramCore/TelegramCore/EnqueueMessage.swift index 1589fe8dbd..17c715bbd3 100644 --- a/submodules/TelegramCore/TelegramCore/EnqueueMessage.swift +++ b/submodules/TelegramCore/TelegramCore/EnqueueMessage.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public enum EnqueueMessageGrouping { case none case auto diff --git a/submodules/TelegramCore/TelegramCore/ExportedInvitation.swift b/submodules/TelegramCore/TelegramCore/ExportedInvitation.swift index 972ce71639..0a01853a77 100644 --- a/submodules/TelegramCore/TelegramCore/ExportedInvitation.swift +++ b/submodules/TelegramCore/TelegramCore/ExportedInvitation.swift @@ -7,25 +7,7 @@ import Foundation import TelegramApi #endif -public struct ExportedInvitation: PostboxCoding, Equatable { - public let link: String - - init(link: String) { - self.link = link - } - - public init(decoder: PostboxDecoder) { - self.link = decoder.decodeStringForKey("l", orElse: "") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.link, forKey: "l") - } - - public static func ==(lhs: ExportedInvitation, rhs: ExportedInvitation) -> Bool { - return lhs.link == rhs.link - } -} +import SyncCore extension ExportedInvitation { init?(apiExportedInvite: Api.ExportedChatInvite) { diff --git a/submodules/TelegramCore/TelegramCore/Fetch.swift b/submodules/TelegramCore/TelegramCore/Fetch.swift index f5e9487fce..d88db40a36 100644 --- a/submodules/TelegramCore/TelegramCore/Fetch.swift +++ b/submodules/TelegramCore/TelegramCore/Fetch.swift @@ -9,6 +9,8 @@ import SwiftSignalKit import Photos #endif +import SyncCore + private final class MediaResourceDataCopyFile : MediaResourceDataFetchCopyLocalItem { let path: String init(path: String) { diff --git a/submodules/TelegramCore/TelegramCore/FetchChatList.swift b/submodules/TelegramCore/TelegramCore/FetchChatList.swift index 303e6bc334..63a2b83545 100644 --- a/submodules/TelegramCore/TelegramCore/FetchChatList.swift +++ b/submodules/TelegramCore/TelegramCore/FetchChatList.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + enum FetchChatListLocation { case general case group(PeerGroupId) diff --git a/submodules/TelegramCore/TelegramCore/FetchSecretFileResource.swift b/submodules/TelegramCore/TelegramCore/FetchSecretFileResource.swift index f53a699d35..d9e808219f 100644 --- a/submodules/TelegramCore/TelegramCore/FetchSecretFileResource.swift +++ b/submodules/TelegramCore/TelegramCore/FetchSecretFileResource.swift @@ -13,6 +13,8 @@ import Foundation #endif #endif +import SyncCore + func fetchSecretFileResource(account: Account, resource: SecretFileMediaResource, intervals: Signal<[(Range, MediaBoxFetchPriority)], NoError>, parameters: MediaResourceFetchParameters?) -> Signal { return multipartFetch(postbox: account.postbox, network: account.network, mediaReferenceRevalidationContext: account.mediaReferenceRevalidationContext, resource: resource, datacenterId: resource.datacenterId, size: resource.size, intervals: intervals, parameters: parameters, encryptionKey: resource.key, decryptedSize: resource.decryptedSize) } diff --git a/submodules/TelegramCore/TelegramCore/FetchedMediaResource.swift b/submodules/TelegramCore/TelegramCore/FetchedMediaResource.swift index 058c82e38d..2647c14389 100644 --- a/submodules/TelegramCore/TelegramCore/FetchedMediaResource.swift +++ b/submodules/TelegramCore/TelegramCore/FetchedMediaResource.swift @@ -7,495 +7,7 @@ import Postbox import SwiftSignalKit #endif -public struct MessageReference: PostboxCoding, Hashable, Equatable { - let content: MessageReferenceContent - - public var peer: PeerReference? { - switch content { - case .none: - return nil - case let .message(peer, _, _, _, _): - return peer - } - } - - public var timestamp: Int32? { - switch content { - case .none: - return nil - case let .message(_, _, timestamp, _, _): - return timestamp - } - } - - public var isIncoming: Bool? { - switch content { - case .none: - return nil - case let .message(_, _, _, incoming, _): - return incoming - } - } - - public var isSecret: Bool? { - switch content { - case .none: - return nil - case let .message(_, _, _, _, secret): - return secret - } - } - - public init(_ message: Message) { - if message.id.namespace != Namespaces.Message.Local, let peer = message.peers[message.id.peerId], let inputPeer = PeerReference(peer) { - self.content = .message(peer: inputPeer, id: message.id, timestamp: message.timestamp, incoming: message.flags.contains(.Incoming), secret: message.containsSecretMedia) - } else { - self.content = .none - } - } - - public init(peer: Peer, id: MessageId, timestamp: Int32, incoming: Bool, secret: Bool) { - if let inputPeer = PeerReference(peer) { - self.content = .message(peer: inputPeer, id: id, timestamp: timestamp, incoming: incoming, secret: secret) - } else { - self.content = .none - } - } - - public init(decoder: PostboxDecoder) { - self.content = decoder.decodeObjectForKey("c", decoder: { MessageReferenceContent(decoder: $0) }) as! MessageReferenceContent - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeObject(self.content, forKey: "c") - } -} - -enum MessageReferenceContent: PostboxCoding, Hashable, Equatable { - case none - case message(peer: PeerReference, id: MessageId, timestamp: Int32, incoming: Bool, secret: Bool) - - init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("_r", orElse: 0) { - case 0: - self = .none - case 1: - self = .message(peer: decoder.decodeObjectForKey("p", decoder: { PeerReference(decoder: $0) }) as! PeerReference, id: MessageId(peerId: PeerId(decoder.decodeInt64ForKey("i.p", orElse: 0)), namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt32ForKey("i.i", orElse: 0)), timestamp: 0, incoming: false, secret: false) - default: - assertionFailure() - self = .none - } - } - - func encode(_ encoder: PostboxEncoder) { - switch self { - case .none: - encoder.encodeInt32(0, forKey: "_r") - case let .message(peer, id, _, _, _): - encoder.encodeInt32(1, forKey: "_r") - encoder.encodeObject(peer, forKey: "p") - encoder.encodeInt64(id.peerId.toInt64(), forKey: "i.p") - encoder.encodeInt32(id.namespace, forKey: "i.n") - encoder.encodeInt32(id.id, forKey: "i.i") - } - } -} - -public struct WebpageReference: PostboxCoding, Hashable, Equatable { - let content: WebpageReferenceContent - - public init(_ webPage: TelegramMediaWebpage) { - if case let .Loaded(content) = webPage.content { - self.content = .webPage(id: webPage.webpageId.id, url: content.url) - } else { - self.content = .none - } - } - - public init(decoder: PostboxDecoder) { - self.content = decoder.decodeObjectForKey("c", decoder: { WebpageReferenceContent(decoder: $0) }) as! WebpageReferenceContent - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeObject(self.content, forKey: "c") - } -} - -enum WebpageReferenceContent: PostboxCoding, Hashable, Equatable { - case none - case webPage(id: Int64, url: String) - - init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("_r", orElse: 0) { - case 0: - self = .none - case 1: - self = .webPage(id: decoder.decodeInt64ForKey("i", orElse: 0), url: decoder.decodeStringForKey("u", orElse: "")) - default: - assertionFailure() - self = .none - } - } - - func encode(_ encoder: PostboxEncoder) { - switch self { - case .none: - encoder.encodeInt32(0, forKey: "_r") - case let .webPage(id, url): - encoder.encodeInt32(1, forKey: "_r") - encoder.encodeInt64(id, forKey: "i") - encoder.encodeString(url, forKey: "u") - } - } -} - -public enum AnyMediaReference: Equatable { - case standalone(media: Media) - case message(message: MessageReference, media: Media) - case webPage(webPage: WebpageReference, media: Media) - case stickerPack(stickerPack: StickerPackReference, media: Media) - case savedGif(media: Media) - - public static func ==(lhs: AnyMediaReference, rhs: AnyMediaReference) -> Bool { - switch lhs { - case let .standalone(lhsMedia): - if case let .standalone(rhsMedia) = rhs, lhsMedia.isEqual(to: rhsMedia) { - return true - } else { - return false - } - case let .message(lhsMessage, lhsMedia): - if case let .message(rhsMessage, rhsMedia) = rhs, lhsMessage == rhsMessage, lhsMedia.isEqual(to: rhsMedia) { - return true - } else { - return false - } - case let .webPage(lhsWebPage, lhsMedia): - if case let .webPage(rhsWebPage, rhsMedia) = rhs, lhsWebPage == rhsWebPage, lhsMedia.isEqual(to: rhsMedia) { - return true - } else { - return false - } - case let .stickerPack(lhsStickerPack, lhsMedia): - if case let .stickerPack(rhsStickerPack, rhsMedia) = rhs, lhsStickerPack == rhsStickerPack, lhsMedia.isEqual(to: rhsMedia) { - return true - } else { - return false - } - case let .savedGif(lhsMedia): - if case let .savedGif(rhsMedia) = rhs, lhsMedia.isEqual(to: rhsMedia) { - return true - } else { - return false - } - } - } - - public var partial: PartialMediaReference? { - switch self { - case .standalone: - return nil - case let .message(message, _): - return .message(message: message) - case let .webPage(webPage, _): - return .webPage(webPage: webPage) - case let .stickerPack(stickerPack, _): - return .stickerPack(stickerPack: stickerPack) - case .savedGif: - return .savedGif - } - } - - public func concrete(_ type: T.Type) -> MediaReference? { - switch self { - case let .standalone(media): - if let media = media as? T { - return .standalone(media: media) - } - case let .message(message, media): - if let media = media as? T { - return .message(message: message, media: media) - } - case let .webPage(webPage, media): - if let media = media as? T { - return .webPage(webPage: webPage, media: media) - } - case let .stickerPack(stickerPack, media): - if let media = media as? T { - return .stickerPack(stickerPack: stickerPack, media: media) - } - case let .savedGif(media): - if let media = media as? T { - return .savedGif(media: media) - } - } - return nil - } - - public var media: Media { - switch self { - case let .standalone(media): - return media - case let .message(_, media): - return media - case let .webPage(_, media): - return media - case let .stickerPack(_, media): - return media - case let .savedGif(media): - return media - } - } - - public func resourceReference(_ resource: MediaResource) -> MediaResourceReference { - return .media(media: self, resource: resource) - } -} - -public enum PartialMediaReference: Equatable { - private enum CodingCase: Int32 { - case message - case webPage - case stickerPack - case savedGif - } - - case message(message: MessageReference) - case webPage(webPage: WebpageReference) - case stickerPack(stickerPack: StickerPackReference) - case savedGif - - init?(decoder: PostboxDecoder) { - guard let caseIdValue = decoder.decodeOptionalInt32ForKey("_r"), let caseId = CodingCase(rawValue: caseIdValue) else { - return nil - } - switch caseId { - case .message: - let message = decoder.decodeObjectForKey("msg", decoder: { MessageReference(decoder: $0) }) as! MessageReference - self = .message(message: message) - case .webPage: - let webPage = decoder.decodeObjectForKey("wpg", decoder: { WebpageReference(decoder: $0) }) as! WebpageReference - self = .webPage(webPage: webPage) - case .stickerPack: - let stickerPack = decoder.decodeObjectForKey("spk", decoder: { StickerPackReference(decoder: $0) }) as! StickerPackReference - self = .stickerPack(stickerPack: stickerPack) - case .savedGif: - self = .savedGif - } - } - - func encode(_ encoder: PostboxEncoder) { - switch self { - case let .message(message): - encoder.encodeInt32(CodingCase.message.rawValue, forKey: "_r") - encoder.encodeObject(message, forKey: "msg") - case let .webPage(webPage): - encoder.encodeInt32(CodingCase.webPage.rawValue, forKey: "_r") - encoder.encodeObject(webPage, forKey: "wpg") - case let .stickerPack(stickerPack): - encoder.encodeInt32(CodingCase.stickerPack.rawValue, forKey: "_r") - encoder.encodeObject(stickerPack, forKey: "spk") - case .savedGif: - encoder.encodeInt32(CodingCase.savedGif.rawValue, forKey: "_r") - } - } - - func mediaReference(_ media: Media) -> AnyMediaReference { - switch self { - case let .message(message): - return .message(message: message, media: media) - case let .webPage(webPage): - return .webPage(webPage: webPage, media: media) - case let .stickerPack(stickerPack): - return .stickerPack(stickerPack: stickerPack, media: media) - case .savedGif: - return .savedGif(media: media) - } - } -} - -public enum MediaReference { - private enum CodingCase: Int32 { - case standalone - case message - case webPage - case stickerPack - case savedGif - } - - case standalone(media: T) - case message(message: MessageReference, media: T) - case webPage(webPage: WebpageReference, media: T) - case stickerPack(stickerPack: StickerPackReference, media: T) - case savedGif(media: T) - - init?(decoder: PostboxDecoder) { - guard let caseIdValue = decoder.decodeOptionalInt32ForKey("_r"), let caseId = CodingCase(rawValue: caseIdValue) else { - return nil - } - switch caseId { - case .standalone: - guard let media = decoder.decodeObjectForKey("m") as? T else { - return nil - } - self = .standalone(media: media) - case .message: - let message = decoder.decodeObjectForKey("msg", decoder: { MessageReference(decoder: $0) }) as! MessageReference - guard let media = decoder.decodeObjectForKey("m") as? T else { - return nil - } - self = .message(message: message, media: media) - case .webPage: - let webPage = decoder.decodeObjectForKey("wpg", decoder: { WebpageReference(decoder: $0) }) as! WebpageReference - guard let media = decoder.decodeObjectForKey("m") as? T else { - return nil - } - self = .webPage(webPage: webPage, media: media) - case .stickerPack: - let stickerPack = decoder.decodeObjectForKey("spk", decoder: { StickerPackReference(decoder: $0) }) as! StickerPackReference - guard let media = decoder.decodeObjectForKey("m") as? T else { - return nil - } - self = .stickerPack(stickerPack: stickerPack, media: media) - case .savedGif: - guard let media = decoder.decodeObjectForKey("m") as? T else { - return nil - } - self = .savedGif(media: media) - } - } - - func encode(_ encoder: PostboxEncoder) { - switch self { - case let .standalone(media): - encoder.encodeInt32(CodingCase.standalone.rawValue, forKey: "_r") - encoder.encodeObject(media, forKey: "m") - case let .message(message, media): - encoder.encodeInt32(CodingCase.message.rawValue, forKey: "_r") - encoder.encodeObject(message, forKey: "msg") - encoder.encodeObject(media, forKey: "m") - case let .webPage(webPage, media): - encoder.encodeInt32(CodingCase.webPage.rawValue, forKey: "_r") - encoder.encodeObject(webPage, forKey: "wpg") - encoder.encodeObject(media, forKey: "m") - case let .stickerPack(stickerPack, media): - encoder.encodeInt32(CodingCase.stickerPack.rawValue, forKey: "_r") - encoder.encodeObject(stickerPack, forKey: "spk") - encoder.encodeObject(media, forKey: "m") - case let .savedGif(media): - encoder.encodeInt32(CodingCase.savedGif.rawValue, forKey: "_r") - encoder.encodeObject(media, forKey: "m") - } - } - - public var abstract: AnyMediaReference { - switch self { - case let .standalone(media): - return .standalone(media: media) - case let .message(message, media): - return .message(message: message, media: media) - case let .webPage(webPage, media): - return .webPage(webPage: webPage, media: media) - case let .stickerPack(stickerPack, media): - return .stickerPack(stickerPack: stickerPack, media: media) - case let .savedGif(media): - return .savedGif(media: media) - } - } - - public var partial: PartialMediaReference? { - return self.abstract.partial - } - - public var media: T { - switch self { - case let .standalone(media): - return media - case let .message(_, media): - return media - case let .webPage(_, media): - return media - case let .stickerPack(_, media): - return media - case let .savedGif(media): - return media - } - } - - public func resourceReference(_ resource: MediaResource) -> MediaResourceReference { - return .media(media: self.abstract, resource: resource) - } -} - -public typealias FileMediaReference = MediaReference -public typealias ImageMediaReference = MediaReference - -public enum MediaResourceReference: Equatable { - case media(media: AnyMediaReference, resource: MediaResource) - case standalone(resource: MediaResource) - case avatar(peer: PeerReference, resource: MediaResource) - case messageAuthorAvatar(message: MessageReference, resource: MediaResource) - case wallpaper(resource: MediaResource) - case stickerPackThumbnail(stickerPack: StickerPackReference, resource: MediaResource) - - public var resource: MediaResource { - switch self { - case let .media(_, resource): - return resource - case let .standalone(resource): - return resource - case let .avatar(_, resource): - return resource - case let .messageAuthorAvatar(_, resource): - return resource - case let .wallpaper(resource): - return resource - case let .stickerPackThumbnail(_, resource): - return resource - } - } - - public static func ==(lhs: MediaResourceReference, rhs: MediaResourceReference) -> Bool { - switch lhs { - case let .media(lhsMedia, lhsResource): - if case let .media(rhsMedia, rhsResource) = rhs, lhsMedia == rhsMedia, lhsResource.isEqual(to: rhsResource) { - return true - } else { - return false - } - case let .standalone(lhsResource): - if case let .standalone(rhsResource) = rhs, lhsResource.isEqual(to: rhsResource) { - return true - } else { - return false - } - case let .avatar(lhsPeer, lhsResource): - if case let .avatar(rhsPeer, rhsResource) = rhs, lhsPeer == rhsPeer, lhsResource.isEqual(to: rhsResource) { - return true - } else { - return false - } - case let .messageAuthorAvatar(lhsMessage, lhsResource): - if case let .messageAuthorAvatar(rhsMessage, rhsResource) = rhs, lhsMessage == rhsMessage, lhsResource.isEqual(to: rhsResource) { - return true - } else { - return false - } - case let .wallpaper(lhsResource): - if case let .wallpaper(rhsResource) = rhs, lhsResource.isEqual(to: rhsResource) { - return true - } else { - return false - } - case let .stickerPackThumbnail(lhsStickerPack, lhsResource): - if case let .stickerPackThumbnail(rhsStickerPack, rhsResource) = rhs, lhsStickerPack == rhsStickerPack, lhsResource.isEqual(to: rhsResource) { - return true - } else { - return false - } - } - } -} +import SyncCore extension MediaResourceReference { var apiFileReference: Data? { diff --git a/submodules/TelegramCore/TelegramCore/GlobalNotificationSettings.swift b/submodules/TelegramCore/TelegramCore/GlobalNotificationSettings.swift index 06320fcb29..60b985f39a 100644 --- a/submodules/TelegramCore/TelegramCore/GlobalNotificationSettings.swift +++ b/submodules/TelegramCore/TelegramCore/GlobalNotificationSettings.swift @@ -7,107 +7,7 @@ import Foundation import TelegramApi #endif -public struct MessageNotificationSettings: PostboxCoding, Equatable { - public var enabled: Bool - public var displayPreviews: Bool - public var sound: PeerMessageSound - - public static var defaultSettings: MessageNotificationSettings { - return MessageNotificationSettings(enabled: true, displayPreviews: true, sound: .bundledModern(id: 0)) - } - - public init(enabled: Bool, displayPreviews: Bool, sound: PeerMessageSound) { - self.enabled = enabled - self.displayPreviews = displayPreviews - self.sound = sound - } - - public init(decoder: PostboxDecoder) { - self.enabled = decoder.decodeInt32ForKey("e", orElse: 0) != 0 - self.displayPreviews = decoder.decodeInt32ForKey("p", orElse: 0) != 0 - self.sound = PeerMessageSound.decodeInline(decoder) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.enabled ? 1 : 0, forKey: "e") - encoder.encodeInt32(self.displayPreviews ? 1 : 0, forKey: "p") - self.sound.encodeInline(encoder) - } -} - -public struct GlobalNotificationSettingsSet: PostboxCoding, Equatable { - public var privateChats: MessageNotificationSettings - public var groupChats: MessageNotificationSettings - public var channels: MessageNotificationSettings - public var contactsJoined: Bool - - public static var defaultSettings: GlobalNotificationSettingsSet { - return GlobalNotificationSettingsSet(privateChats: MessageNotificationSettings.defaultSettings, groupChats: .defaultSettings, channels: .defaultSettings, contactsJoined: true) - } - - public init(privateChats: MessageNotificationSettings, groupChats: MessageNotificationSettings, channels: MessageNotificationSettings, contactsJoined: Bool) { - self.privateChats = privateChats - self.groupChats = groupChats - self.channels = channels - self.contactsJoined = contactsJoined - } - - public init(decoder: PostboxDecoder) { - self.privateChats = decoder.decodeObjectForKey("p", decoder: { MessageNotificationSettings(decoder: $0) }) as! MessageNotificationSettings - self.groupChats = decoder.decodeObjectForKey("g", decoder: { MessageNotificationSettings(decoder: $0) }) as! MessageNotificationSettings - self.channels = (decoder.decodeObjectForKey("c", decoder: { MessageNotificationSettings(decoder: $0) }) as? MessageNotificationSettings) ?? MessageNotificationSettings.defaultSettings - self.contactsJoined = decoder.decodeInt32ForKey("contactsJoined", orElse: 1) != 0 - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeObject(self.privateChats, forKey: "p") - encoder.encodeObject(self.groupChats, forKey: "g") - encoder.encodeObject(self.channels, forKey: "c") - encoder.encodeInt32(self.contactsJoined ? 1 : 0, forKey: "contactsJoined") - } -} - -public struct GlobalNotificationSettings: PreferencesEntry, Equatable { - var toBeSynchronized: GlobalNotificationSettingsSet? - var remote: GlobalNotificationSettingsSet - - public static var defaultSettings: GlobalNotificationSettings = GlobalNotificationSettings(toBeSynchronized: nil, remote: GlobalNotificationSettingsSet.defaultSettings) - - public var effective: GlobalNotificationSettingsSet { - if let toBeSynchronized = self.toBeSynchronized { - return toBeSynchronized - } else { - return self.remote - } - } - - init(toBeSynchronized: GlobalNotificationSettingsSet?, remote: GlobalNotificationSettingsSet) { - self.toBeSynchronized = toBeSynchronized - self.remote = remote - } - - public init(decoder: PostboxDecoder) { - self.toBeSynchronized = decoder.decodeObjectForKey("s", decoder: { GlobalNotificationSettingsSet(decoder: $0) }) as? GlobalNotificationSettingsSet - self.remote = decoder.decodeObjectForKey("r", decoder: { GlobalNotificationSettingsSet(decoder: $0) }) as! GlobalNotificationSettingsSet - } - - public func encode(_ encoder: PostboxEncoder) { - if let toBeSynchronized = self.toBeSynchronized { - encoder.encodeObject(toBeSynchronized, forKey: "s") - } else { - encoder.encodeNil(forKey: "s") - } - encoder.encodeObject(self.remote, forKey: "r") - } - - public func isEqual(to: PreferencesEntry) -> Bool { - if let to = to as? GlobalNotificationSettings { - return self == to - } else { - return false - } - } -} +import SyncCore extension MessageNotificationSettings { init(apiSettings: Api.PeerNotifySettings) { diff --git a/submodules/TelegramCore/TelegramCore/GrantSecureIdAccess.swift b/submodules/TelegramCore/TelegramCore/GrantSecureIdAccess.swift index 3b680d0c85..b9e9c6a65e 100644 --- a/submodules/TelegramCore/TelegramCore/GrantSecureIdAccess.swift +++ b/submodules/TelegramCore/TelegramCore/GrantSecureIdAccess.swift @@ -15,6 +15,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + func apiSecureValueType(value: SecureIdValue) -> Api.SecureValueType { let type: Api.SecureValueType switch value { diff --git a/submodules/TelegramCore/TelegramCore/HistoryViewStateValidation.swift b/submodules/TelegramCore/TelegramCore/HistoryViewStateValidation.swift index 12091534d8..29e86a3631 100644 --- a/submodules/TelegramCore/TelegramCore/HistoryViewStateValidation.swift +++ b/submodules/TelegramCore/TelegramCore/HistoryViewStateValidation.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private final class HistoryStateValidationBatch { private let disposable: Disposable let invalidatedState: HistoryState? diff --git a/submodules/TelegramCore/TelegramCore/Holes.swift b/submodules/TelegramCore/TelegramCore/Holes.swift index 859f709377..cccfda604c 100644 --- a/submodules/TelegramCore/TelegramCore/Holes.swift +++ b/submodules/TelegramCore/TelegramCore/Holes.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private func messageFilterForTagMask(_ tagMask: MessageTags) -> Api.MessagesFilter? { if tagMask == .photoOrVideo { return Api.MessagesFilter.inputMessagesFilterPhotoVideo diff --git a/submodules/TelegramCore/TelegramCore/ImageRepresentationWithReference.swift b/submodules/TelegramCore/TelegramCore/ImageRepresentationWithReference.swift index f69c62bfbf..9c9242373e 100644 --- a/submodules/TelegramCore/TelegramCore/ImageRepresentationWithReference.swift +++ b/submodules/TelegramCore/TelegramCore/ImageRepresentationWithReference.swift @@ -1,4 +1,5 @@ import Foundation +import SyncCore public struct ImageRepresentationWithReference: Equatable { public let representation: TelegramMediaImageRepresentation diff --git a/submodules/TelegramCore/TelegramCore/ImageRepresentationsUtils.swift b/submodules/TelegramCore/TelegramCore/ImageRepresentationsUtils.swift index ad2b3c6b32..4e95f26989 100644 --- a/submodules/TelegramCore/TelegramCore/ImageRepresentationsUtils.swift +++ b/submodules/TelegramCore/TelegramCore/ImageRepresentationsUtils.swift @@ -13,6 +13,8 @@ #endif #endif +import SyncCore + public func smallestImageRepresentation(_ representations: [TelegramMediaImageRepresentation]) -> TelegramMediaImageRepresentation? { if representations.count == 0 { return nil diff --git a/submodules/TelegramCore/TelegramCore/ImportContact.swift b/submodules/TelegramCore/TelegramCore/ImportContact.swift index adc0f3bf4b..04aecfb348 100644 --- a/submodules/TelegramCore/TelegramCore/ImportContact.swift +++ b/submodules/TelegramCore/TelegramCore/ImportContact.swift @@ -8,6 +8,8 @@ import SwiftSignalKit #endif +import SyncCore + public func importContact(account: Account, firstName: String, lastName: String, phoneNumber: String) -> Signal { let input = Api.InputContact.inputPhoneContact(clientId: 1, phone: phoneNumber, firstName: firstName, lastName: lastName) diff --git a/submodules/TelegramCore/TelegramCore/InitializeAccountAfterLogin.swift b/submodules/TelegramCore/TelegramCore/InitializeAccountAfterLogin.swift index 51329eba44..a2bb3e5704 100644 --- a/submodules/TelegramCore/TelegramCore/InitializeAccountAfterLogin.swift +++ b/submodules/TelegramCore/TelegramCore/InitializeAccountAfterLogin.swift @@ -7,6 +7,8 @@ import SwiftSignalKit import Postbox #endif +import SyncCore + func initializedAppSettingsAfterLogin(transaction: Transaction, appVersion: String, syncContacts: Bool) { updateAppChangelogState(transaction: transaction, { state in var state = state diff --git a/submodules/TelegramCore/TelegramCore/InstallInteractiveReadMessagesAction.swift b/submodules/TelegramCore/TelegramCore/InstallInteractiveReadMessagesAction.swift index bf4b4c68dc..b546f5e722 100644 --- a/submodules/TelegramCore/TelegramCore/InstallInteractiveReadMessagesAction.swift +++ b/submodules/TelegramCore/TelegramCore/InstallInteractiveReadMessagesAction.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public func installInteractiveReadMessagesAction(postbox: Postbox, stateManager: AccountStateManager, peerId: PeerId) -> Disposable { return postbox.installStoreMessageAction(peerId: peerId, { messages, transaction in var consumeMessageIds: [MessageId] = [] diff --git a/submodules/TelegramCore/TelegramCore/InstantPage.swift b/submodules/TelegramCore/TelegramCore/InstantPage.swift index 8700cc027c..536c2bd55d 100644 --- a/submodules/TelegramCore/TelegramCore/InstantPage.swift +++ b/submodules/TelegramCore/TelegramCore/InstantPage.swift @@ -8,904 +8,7 @@ import Foundation import TelegramApi #endif -private enum InstantPageBlockType: Int32 { - case unsupported = 0 - case title = 1 - case subtitle = 2 - case authorDate = 3 - case header = 4 - case subheader = 5 - case paragraph = 6 - case preformatted = 7 - case footer = 8 - case divider = 9 - case anchor = 10 - case list = 11 - case blockQuote = 12 - case pullQuote = 13 - case image = 14 - case video = 15 - case cover = 16 - case webEmbed = 17 - case postEmbed = 18 - case collage = 19 - case slideshow = 20 - case channelBanner = 21 - case audio = 22 - case kicker = 23 - case table = 24 - case details = 25 - case relatedArticles = 26 - case map = 27 -} - -private func decodeListItems(_ decoder: PostboxDecoder) -> [InstantPageListItem] { - let legacyItems: [RichText] = decoder.decodeObjectArrayWithDecoderForKey("l") - if !legacyItems.isEmpty { - var items: [InstantPageListItem] = [] - for item in legacyItems { - items.append(.text(item, nil)) - } - return items - } - return decoder.decodeObjectArrayWithDecoderForKey("ml") -} - -private func decodeCaption(_ decoder: PostboxDecoder) -> InstantPageCaption { - if let legacyCaption = decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as? RichText { - return InstantPageCaption(text: legacyCaption, credit: .empty) - } - return decoder.decodeObjectForKey("mc", decoder: { InstantPageCaption(decoder: $0) }) as! InstantPageCaption -} - -public indirect enum InstantPageBlock: PostboxCoding, Equatable { - case unsupported - case title(RichText) - case subtitle(RichText) - case authorDate(author: RichText, date: Int32) - case header(RichText) - case subheader(RichText) - case paragraph(RichText) - case preformatted(RichText) - case footer(RichText) - case divider - case anchor(String) - case list(items: [InstantPageListItem], ordered: Bool) - case blockQuote(text: RichText, caption: RichText) - case pullQuote(text: RichText, caption: RichText) - case image(id: MediaId, caption: InstantPageCaption, url: String?, webpageId: MediaId?) - case video(id: MediaId, caption: InstantPageCaption, autoplay: Bool, loop: Bool) - case audio(id: MediaId, caption: InstantPageCaption) - case cover(InstantPageBlock) - case webEmbed(url: String?, html: String?, dimensions: CGSize?, caption: InstantPageCaption, stretchToWidth: Bool, allowScrolling: Bool, coverId: MediaId?) - case postEmbed(url: String, webpageId: MediaId?, avatarId: MediaId?, author: String, date: Int32, blocks: [InstantPageBlock], caption: InstantPageCaption) - case collage(items: [InstantPageBlock], caption: InstantPageCaption) - case slideshow(items: [InstantPageBlock], caption: InstantPageCaption) - case channelBanner(TelegramChannel?) - case kicker(RichText) - case table(title: RichText, rows: [InstantPageTableRow], bordered: Bool, striped: Bool) - case details(title: RichText, blocks: [InstantPageBlock], expanded: Bool) - case relatedArticles(title: RichText, articles: [InstantPageRelatedArticle]) - case map(latitude: Double, longitude: Double, zoom: Int32, dimensions: CGSize, caption: InstantPageCaption) - - public init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("r", orElse: 0) { - case InstantPageBlockType.unsupported.rawValue: - self = .unsupported - case InstantPageBlockType.title.rawValue: - self = .title(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) - case InstantPageBlockType.subtitle.rawValue: - self = .subtitle(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) - case InstantPageBlockType.authorDate.rawValue: - self = .authorDate(author: decoder.decodeObjectForKey("a", decoder: { RichText(decoder: $0) }) as! RichText, date: decoder.decodeInt32ForKey("d", orElse: 0)) - case InstantPageBlockType.header.rawValue: - self = .header(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) - case InstantPageBlockType.subheader.rawValue: - self = .subheader(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) - case InstantPageBlockType.paragraph.rawValue: - self = .paragraph(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) - case InstantPageBlockType.preformatted.rawValue: - self = .preformatted(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) - case InstantPageBlockType.footer.rawValue: - self = .footer(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) - case InstantPageBlockType.divider.rawValue: - self = .divider - case InstantPageBlockType.anchor.rawValue: - self = .anchor(decoder.decodeStringForKey("s", orElse: "")) - case InstantPageBlockType.list.rawValue: - self = .list(items: decodeListItems(decoder), ordered: decoder.decodeOptionalInt32ForKey("o") != 0) - case InstantPageBlockType.blockQuote.rawValue: - self = .blockQuote(text: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, caption: decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as! RichText) - case InstantPageBlockType.pullQuote.rawValue: - self = .pullQuote(text: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, caption: decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as! RichText) - case InstantPageBlockType.image.rawValue: - var webpageId: MediaId? - if let webpageIdNamespace = decoder.decodeOptionalInt32ForKey("wi.n"), let webpageIdId = decoder.decodeOptionalInt64ForKey("wi.i") { - webpageId = MediaId(namespace: webpageIdNamespace, id: webpageIdId) - } - self = .image(id: MediaId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)), caption: decodeCaption(decoder), url: decoder.decodeOptionalStringForKey("u"), webpageId: webpageId) - case InstantPageBlockType.video.rawValue: - self = .video(id: MediaId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)), caption: decodeCaption(decoder), autoplay: decoder.decodeInt32ForKey("ap", orElse: 0) != 0, loop: decoder.decodeInt32ForKey("lo", orElse: 0) != 0) - case InstantPageBlockType.cover.rawValue: - self = .cover(decoder.decodeObjectForKey("c", decoder: { InstantPageBlock(decoder: $0) }) as! InstantPageBlock) - case InstantPageBlockType.webEmbed.rawValue: - var coverId: MediaId? - if let coverIdNamespace = decoder.decodeOptionalInt32ForKey("ci.n"), let coverIdId = decoder.decodeOptionalInt64ForKey("ci.i") { - coverId = MediaId(namespace: coverIdNamespace, id: coverIdId) - } - var dimensions: CGSize? - if let width = decoder.decodeOptionalInt32ForKey("sw"), let height = decoder.decodeOptionalInt32ForKey("sh") { - dimensions = CGSize(width: CGFloat(width), height: CGFloat(height)) - } - self = .webEmbed(url: decoder.decodeOptionalStringForKey("u"), html: decoder.decodeOptionalStringForKey("h"), dimensions: dimensions, caption: decodeCaption(decoder), stretchToWidth: decoder.decodeInt32ForKey("st", orElse: 0) != 0, allowScrolling: decoder.decodeInt32ForKey("as", orElse: 0) != 0, coverId: coverId) - case InstantPageBlockType.postEmbed.rawValue: - var avatarId: MediaId? - let avatarIdNamespace: Int32? = decoder.decodeOptionalInt32ForKey("av.n") - let avatarIdId: Int64? = decoder.decodeOptionalInt64ForKey("av.i") - if let avatarIdNamespace = avatarIdNamespace, let avatarIdId = avatarIdId { - avatarId = MediaId(namespace: avatarIdNamespace, id: avatarIdId) - } - self = .postEmbed(url: decoder.decodeStringForKey("u", orElse: ""), webpageId: MediaId(namespace: decoder.decodeInt32ForKey("w.n", orElse: 0), id: decoder.decodeInt64ForKey("w.i", orElse: 0)), avatarId: avatarId, author: decoder.decodeStringForKey("a", orElse: ""), date: decoder.decodeInt32ForKey("d", orElse: 0), blocks: decoder.decodeObjectArrayWithDecoderForKey("b"), caption: decodeCaption(decoder)) - case InstantPageBlockType.collage.rawValue: - self = .collage(items: decoder.decodeObjectArrayWithDecoderForKey("b"), caption: decodeCaption(decoder)) - case InstantPageBlockType.slideshow.rawValue: - self = .slideshow(items: decoder.decodeObjectArrayWithDecoderForKey("b"), caption: decodeCaption(decoder)) - case InstantPageBlockType.channelBanner.rawValue: - self = .channelBanner(decoder.decodeObjectForKey("c") as? TelegramChannel) - case InstantPageBlockType.audio.rawValue: - self = .audio(id: MediaId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)), caption: decodeCaption(decoder)) - case InstantPageBlockType.kicker.rawValue: - self = .kicker(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) - case InstantPageBlockType.table.rawValue: - self = .table(title: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, rows: decoder.decodeObjectArrayWithDecoderForKey("r"), bordered: decoder.decodeInt32ForKey("b", orElse: 0) != 0, striped: decoder.decodeInt32ForKey("s", orElse: 0) != 0) - case InstantPageBlockType.details.rawValue: - self = .details(title: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, blocks: decoder.decodeObjectArrayWithDecoderForKey("b"), expanded: decoder.decodeInt32ForKey("o", orElse: 0) != 0) - case InstantPageBlockType.relatedArticles.rawValue: - self = .relatedArticles(title: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, articles: decoder.decodeObjectArrayWithDecoderForKey("a")) - case InstantPageBlockType.map.rawValue: - self = .map(latitude: decoder.decodeDoubleForKey("lat", orElse: 0.0), longitude: decoder.decodeDoubleForKey("lon", orElse: 0.0), zoom: decoder.decodeInt32ForKey("z", orElse: 0), dimensions: CGSize(width: CGFloat(decoder.decodeInt32ForKey("sw", orElse: 0)), height: CGFloat(decoder.decodeInt32ForKey("sh", orElse: 0))), caption: decodeCaption(decoder)) - default: - self = .unsupported - } - } - - public func encode(_ encoder: PostboxEncoder) { - switch self { - case .unsupported: - encoder.encodeInt32(InstantPageBlockType.unsupported.rawValue, forKey: "r") - case let .title(text): - encoder.encodeInt32(InstantPageBlockType.title.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - case let .subtitle(text): - encoder.encodeInt32(InstantPageBlockType.subtitle.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - case let .authorDate(author, date): - encoder.encodeInt32(InstantPageBlockType.authorDate.rawValue, forKey: "r") - encoder.encodeObject(author, forKey: "a") - encoder.encodeInt32(date, forKey: "d") - case let .header(text): - encoder.encodeInt32(InstantPageBlockType.header.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - case let .subheader(text): - encoder.encodeInt32(InstantPageBlockType.subheader.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - case let .paragraph(text): - encoder.encodeInt32(InstantPageBlockType.paragraph.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - case let .preformatted(text): - encoder.encodeInt32(InstantPageBlockType.preformatted.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - case let .footer(text): - encoder.encodeInt32(InstantPageBlockType.footer.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - case .divider: - encoder.encodeInt32(InstantPageBlockType.divider.rawValue, forKey: "r") - case let .anchor(anchor): - encoder.encodeInt32(InstantPageBlockType.anchor.rawValue, forKey: "r") - encoder.encodeString(anchor, forKey: "s") - case let .list(items, ordered): - encoder.encodeInt32(InstantPageBlockType.list.rawValue, forKey: "r") - encoder.encodeObjectArray(items, forKey: "ml") - encoder.encodeInt32(ordered ? 1 : 0, forKey: "o") - case let .blockQuote(text, caption): - encoder.encodeInt32(InstantPageBlockType.blockQuote.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - encoder.encodeObject(caption, forKey: "c") - case let .pullQuote(text, caption): - encoder.encodeInt32(InstantPageBlockType.pullQuote.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - encoder.encodeObject(caption, forKey: "c") - case let .image(id, caption, url, webpageId): - encoder.encodeInt32(InstantPageBlockType.image.rawValue, forKey: "r") - encoder.encodeInt32(id.namespace, forKey: "i.n") - encoder.encodeInt64(id.id, forKey: "i.i") - encoder.encodeObject(caption, forKey: "mc") - if let url = url { - encoder.encodeString(url, forKey: "u") - } else { - encoder.encodeNil(forKey: "u") - } - if let webpageId = webpageId { - encoder.encodeInt32(webpageId.namespace, forKey: "wi.n") - encoder.encodeInt64(webpageId.id, forKey: "wi.i") - } else { - encoder.encodeNil(forKey: "wi.n") - encoder.encodeNil(forKey: "wi.i") - } - case let .video(id, caption, autoplay, loop): - encoder.encodeInt32(InstantPageBlockType.video.rawValue, forKey: "r") - encoder.encodeInt32(id.namespace, forKey: "i.n") - encoder.encodeInt64(id.id, forKey: "i.i") - encoder.encodeObject(caption, forKey: "mc") - encoder.encodeInt32(autoplay ? 1 : 0, forKey: "ap") - encoder.encodeInt32(loop ? 1 : 0, forKey: "lo") - case let .cover(block): - encoder.encodeInt32(InstantPageBlockType.cover.rawValue, forKey: "r") - encoder.encodeObject(block, forKey: "c") - case let .webEmbed(url, html, dimensions, caption, stretchToWidth, allowScrolling, coverId): - encoder.encodeInt32(InstantPageBlockType.webEmbed.rawValue, forKey: "r") - if let coverId = coverId { - encoder.encodeInt32(coverId.namespace, forKey: "ci.n") - encoder.encodeInt64(coverId.id, forKey: "ci.i") - } else { - encoder.encodeNil(forKey: "ci.n") - encoder.encodeNil(forKey: "ci.i") - } - if let url = url { - encoder.encodeString(url, forKey: "u") - } else { - encoder.encodeNil(forKey: "u") - } - if let html = html { - encoder.encodeString(html, forKey: "h") - } else { - encoder.encodeNil(forKey: "h") - } - if let dimensions = dimensions { - encoder.encodeInt32(Int32(dimensions.width), forKey: "sw") - encoder.encodeInt32(Int32(dimensions.height), forKey: "sh") - } else { - encoder.encodeNil(forKey: "sw") - encoder.encodeNil(forKey: "sh") - } - encoder.encodeObject(caption, forKey: "mc") - encoder.encodeInt32(stretchToWidth ? 1 : 0, forKey: "st") - encoder.encodeInt32(allowScrolling ? 1 : 0, forKey: "as") - case let .postEmbed(url, webpageId, avatarId, author, date, blocks, caption): - encoder.encodeInt32(InstantPageBlockType.postEmbed.rawValue, forKey: "r") - if let avatarId = avatarId { - encoder.encodeInt32(avatarId.namespace, forKey: "av.n") - encoder.encodeInt64(avatarId.id, forKey: "av.i") - } else { - encoder.encodeNil(forKey: "av.n") - encoder.encodeNil(forKey: "av.i") - } - encoder.encodeString(url, forKey: "u") - if let webpageId = webpageId { - encoder.encodeInt32(webpageId.namespace, forKey: "w.n") - encoder.encodeInt64(webpageId.id, forKey: "w.i") - } else { - encoder.encodeNil(forKey: "w.n") - encoder.encodeNil(forKey: "w.i") - } - encoder.encodeString(author, forKey: "a") - encoder.encodeInt32(date, forKey: "d") - encoder.encodeObjectArray(blocks, forKey: "b") - encoder.encodeObject(caption, forKey: "mc") - case let .collage(items, caption): - encoder.encodeInt32(InstantPageBlockType.collage.rawValue, forKey: "r") - encoder.encodeObjectArray(items, forKey: "b") - encoder.encodeObject(caption, forKey: "mc") - case let .slideshow(items, caption): - encoder.encodeInt32(InstantPageBlockType.slideshow.rawValue, forKey: "r") - encoder.encodeObjectArray(items, forKey: "b") - encoder.encodeObject(caption, forKey: "mc") - case let .channelBanner(channel): - encoder.encodeInt32(InstantPageBlockType.channelBanner.rawValue, forKey: "r") - if let channel = channel { - encoder.encodeObject(channel, forKey: "c") - } else { - encoder.encodeNil(forKey: "c") - } - case let .audio(id, caption): - encoder.encodeInt32(InstantPageBlockType.audio.rawValue, forKey: "r") - encoder.encodeInt32(id.namespace, forKey: "i.n") - encoder.encodeInt64(id.id, forKey: "i.i") - encoder.encodeObject(caption, forKey: "mc") - case let .kicker(text): - encoder.encodeInt32(InstantPageBlockType.kicker.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - case let .table(title, rows, bordered, striped): - encoder.encodeInt32(InstantPageBlockType.table.rawValue, forKey: "r") - encoder.encodeObject(title, forKey: "t") - encoder.encodeObjectArray(rows, forKey: "r") - encoder.encodeInt32(bordered ? 1 : 0, forKey: "b") - encoder.encodeInt32(striped ? 1 : 0, forKey: "s") - case let .details(title, blocks, expanded): - encoder.encodeInt32(InstantPageBlockType.details.rawValue, forKey: "r") - encoder.encodeObject(title, forKey: "t") - encoder.encodeObjectArray(blocks, forKey: "b") - encoder.encodeInt32(expanded ? 1 : 0, forKey: "o") - case let .relatedArticles(title, articles): - encoder.encodeInt32(InstantPageBlockType.relatedArticles.rawValue, forKey: "r") - encoder.encodeObject(title, forKey: "t") - encoder.encodeObjectArray(articles, forKey: "a") - case let .map(latitude, longitude, zoom, dimensions, caption): - encoder.encodeInt32(InstantPageBlockType.map.rawValue, forKey: "r") - encoder.encodeDouble(latitude, forKey: "lat") - encoder.encodeDouble(longitude, forKey: "lon") - encoder.encodeInt32(zoom, forKey: "z") - encoder.encodeInt32(Int32(dimensions.width), forKey: "sw") - encoder.encodeInt32(Int32(dimensions.height), forKey: "sh") - encoder.encodeObject(caption, forKey: "mc") - } - } - - public static func ==(lhs: InstantPageBlock, rhs: InstantPageBlock) -> Bool { - switch lhs { - case .unsupported: - if case .unsupported = rhs { - return true - } else { - return false - } - case let .title(text): - if case .title(text) = rhs { - return true - } else { - return false - } - case let .subtitle(text): - if case .subtitle(text) = rhs { - return true - } else { - return false - } - case let .authorDate(author, date): - if case .authorDate(author, date) = rhs { - return true - } else { - return false - } - case let .header(text): - if case .header(text) = rhs { - return true - } else { - return false - } - case let .subheader(text): - if case .subheader(text) = rhs { - return true - } else { - return false - } - case let .paragraph(text): - if case .paragraph(text) = rhs { - return true - } else { - return false - } - case let .preformatted(text): - if case .preformatted(text) = rhs { - return true - } else { - return false - } - case let .footer(text): - if case .footer(text) = rhs { - return true - } else { - return false - } - case .divider: - if case .divider = rhs { - return true - } else { - return false - } - case let .anchor(anchor): - if case .anchor(anchor) = rhs { - return true - } else { - return false - } - case let .list(lhsItems, lhsOrdered): - if case let .list(rhsItems, rhsOrdered) = rhs, lhsItems == rhsItems, lhsOrdered == rhsOrdered { - return true - } else { - return false - } - case let .blockQuote(text, caption): - if case .blockQuote(text, caption) = rhs { - return true - } else { - return false - } - case let .pullQuote(text, caption): - if case .pullQuote(text, caption) = rhs { - return true - } else { - return false - } - case let .image(lhsId, lhsCaption, lhsUrl, lhsWebpageId): - if case let .image(rhsId, rhsCaption, rhsUrl, rhsWebpageId) = rhs, lhsId == rhsId, lhsCaption == rhsCaption, lhsUrl == rhsUrl, lhsWebpageId == rhsWebpageId { - return true - } else { - return false - } - case let .video(id, caption, autoplay, loop): - if case .video(id, caption, autoplay, loop) = rhs { - return true - } else { - return false - } - case let .cover(block): - if case .cover(block) = rhs { - return true - } else { - return false - } - case let .webEmbed(lhsUrl, lhsHtml, lhsDimensions, lhsCaption, lhsStretchToWidth, lhsAllowScrolling, lhsCoverId): - if case let .webEmbed(rhsUrl, rhsHtml, rhsDimensions, rhsCaption, rhsStretchToWidth, rhsAllowScrolling, rhsCoverId) = rhs, lhsUrl == rhsUrl && lhsHtml == rhsHtml && lhsDimensions == rhsDimensions && lhsCaption == rhsCaption && lhsStretchToWidth == rhsStretchToWidth && lhsAllowScrolling == rhsAllowScrolling && lhsCoverId == rhsCoverId { - return true - } else { - return false - } - case let .postEmbed(lhsUrl, lhsWebpageId, lhsAvatarId, lhsAuthor, lhsDate, lhsBlocks, lhsCaption): - if case let .postEmbed(rhsUrl, rhsWebpageId, rhsAvatarId, rhsAuthor, rhsDate, rhsBlocks, rhsCaption) = rhs, lhsUrl == rhsUrl && lhsWebpageId == rhsWebpageId && lhsAvatarId == rhsAvatarId && lhsAuthor == rhsAuthor && lhsDate == rhsDate && lhsBlocks == rhsBlocks && lhsCaption == rhsCaption { - return true - } else { - return false - } - case let .collage(lhsItems, lhsCaption): - if case let .collage(rhsItems, rhsCaption) = rhs, lhsItems == rhsItems && lhsCaption == rhsCaption { - return true - } else { - return false - } - case let .slideshow(lhsItems, lhsCaption): - if case let .slideshow(rhsItems, rhsCaption) = rhs, lhsItems == rhsItems && lhsCaption == rhsCaption { - return true - } else { - return false - } - case let .channelBanner(lhsChannel): - if case let .channelBanner(rhsChannel) = rhs { - if let lhsChannel = lhsChannel, let rhsChannel = rhsChannel { - if !lhsChannel.isEqual(rhsChannel) { - return false - } - } else if (lhsChannel != nil) != (rhsChannel != nil) { - return false - } - return true - } else { - return false - } - case let .audio(id, caption): - if case .audio(id, caption) = rhs { - return true - } else { - return false - } - case let .kicker(text): - if case .kicker(text) = rhs { - return true - } else { - return false - } - case let .table(lhsTitle, lhsRows, lhsBordered, lhsStriped): - if case let .table(rhsTitle, rhsRows, rhsBordered, rhsStriped) = rhs, lhsTitle == rhsTitle, lhsRows == rhsRows, lhsBordered == rhsBordered, lhsStriped == rhsStriped { - return true - } else { - return false - } - case let .details(lhsTitle, lhsBlocks, lhsExpanded): - if case let .details(rhsTitle, rhsBlocks, rhsExpanded) = rhs, lhsTitle == rhsTitle, lhsBlocks == rhsBlocks, lhsExpanded == rhsExpanded { - return true - } else { - return false - } - case let .relatedArticles(lhsTitle, lhsArticles): - if case let .relatedArticles(rhsTitle, rhsArticles) = rhs, lhsTitle == rhsTitle, lhsArticles == rhsArticles { - return true - } else { - return false - } - case let .map(latitude, longitude, zoom, dimensions, caption): - if case .map(latitude, longitude, zoom, dimensions, caption) = rhs { - return true - } else { - return false - } - } - } -} - -public final class InstantPageCaption: PostboxCoding, Equatable { - public let text: RichText - public let credit: RichText - - init(text: RichText, credit: RichText) { - self.text = text - self.credit = credit - } - - public init(decoder: PostboxDecoder) { - self.text = decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText - self.credit = decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as! RichText - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeObject(self.text, forKey: "t") - encoder.encodeObject(self.credit, forKey: "c") - } - - public static func ==(lhs: InstantPageCaption, rhs: InstantPageCaption) -> Bool { - if lhs.text != rhs.text { - return false - } - if lhs.credit != rhs.credit { - return false - } - return true - } -} - -private enum InstantPageListItemType: Int32 { - case unknown = 0 - case text = 1 - case blocks = 2 -} - -public indirect enum InstantPageListItem: PostboxCoding, Equatable { - case unknown - case text(RichText, String?) - case blocks([InstantPageBlock], String?) - - public init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("r", orElse: 0) { - case InstantPageListItemType.text.rawValue: - self = .text(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, decoder.decodeOptionalStringForKey("n")) - case InstantPageListItemType.blocks.rawValue: - self = .blocks(decoder.decodeObjectArrayWithDecoderForKey("b"), decoder.decodeOptionalStringForKey("n")) - default: - self = .unknown - } - } - - public func encode(_ encoder: PostboxEncoder) { - switch self { - case let .text(text, num): - encoder.encodeInt32(InstantPageListItemType.text.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - if let num = num { - encoder.encodeString(num, forKey: "n") - } else { - encoder.encodeNil(forKey: "n") - } - case let .blocks(blocks, num): - encoder.encodeInt32(InstantPageListItemType.blocks.rawValue, forKey: "r") - encoder.encodeObjectArray(blocks, forKey: "b") - if let num = num { - encoder.encodeString(num, forKey: "n") - } else { - encoder.encodeNil(forKey: "n") - } - default: - break - } - } - - public static func ==(lhs: InstantPageListItem, rhs: InstantPageListItem) -> Bool { - switch lhs { - case .unknown: - if case .unknown = rhs { - return true - } else { - return false - } - case let .text(lhsText, lhsNum): - if case let .text(rhsText, rhsNum) = rhs, lhsText == rhsText, lhsNum == rhsNum { - return true - } else { - return false - } - case let .blocks(lhsBlocks, lhsNum): - if case let .blocks(rhsBlocks, rhsNum) = rhs, lhsBlocks == rhsBlocks, lhsNum == rhsNum { - return true - } else { - return false - } - } - } -} - -public enum TableHorizontalAlignment: Int32 { - case left = 0 - case center = 1 - case right = 2 -} - -public enum TableVerticalAlignment: Int32 { - case top = 0 - case middle = 1 - case bottom = 2 -} - -public final class InstantPageTableCell: PostboxCoding, Equatable { - public let text: RichText? - public let header: Bool - public let alignment: TableHorizontalAlignment - public let verticalAlignment: TableVerticalAlignment - public let colspan: Int32 - public let rowspan: Int32 - - public init(text: RichText?, header: Bool, alignment: TableHorizontalAlignment, verticalAlignment: TableVerticalAlignment, colspan: Int32, rowspan: Int32) { - self.text = text - self.header = header - self.alignment = alignment - self.verticalAlignment = verticalAlignment - self.colspan = colspan - self.rowspan = rowspan - } - - public init(decoder: PostboxDecoder) { - self.text = decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as? RichText - self.header = decoder.decodeInt32ForKey("h", orElse: 0) != 0 - self.alignment = TableHorizontalAlignment(rawValue: decoder.decodeInt32ForKey("ha", orElse: 0))! - self.verticalAlignment = TableVerticalAlignment(rawValue: decoder.decodeInt32ForKey("va", orElse: 0))! - self.colspan = decoder.decodeInt32ForKey("sc", orElse: 0) - self.rowspan = decoder.decodeInt32ForKey("sr", orElse: 0) - } - - public func encode(_ encoder: PostboxEncoder) { - if let text = self.text { - encoder.encodeObject(text, forKey: "t") - } else { - encoder.encodeNil(forKey: "t") - } - encoder.encodeInt32(self.header ? 1 : 0, forKey: "h") - encoder.encodeInt32(self.alignment.rawValue, forKey: "ha") - encoder.encodeInt32(self.verticalAlignment.rawValue, forKey: "va") - encoder.encodeInt32(self.colspan, forKey: "sc") - encoder.encodeInt32(self.rowspan, forKey: "sr") - } - - public static func ==(lhs: InstantPageTableCell, rhs: InstantPageTableCell) -> Bool { - if lhs.text != rhs.text { - return false - } - if lhs.header != rhs.header { - return false - } - if lhs.alignment != rhs.alignment { - return false - } - if lhs.verticalAlignment != rhs.verticalAlignment { - return false - } - if lhs.colspan != rhs.colspan { - return false - } - if lhs.rowspan != rhs.rowspan { - return false - } - return true - } -} - -public final class InstantPageTableRow: PostboxCoding, Equatable { - public let cells: [InstantPageTableCell] - - public init(cells: [InstantPageTableCell]) { - self.cells = cells - } - - public init(decoder: PostboxDecoder) { - self.cells = decoder.decodeObjectArrayWithDecoderForKey("c") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeObjectArray(self.cells, forKey: "c") - } - - public static func ==(lhs: InstantPageTableRow, rhs: InstantPageTableRow) -> Bool { - return lhs.cells == rhs.cells - } -} - -public final class InstantPageRelatedArticle: PostboxCoding, Equatable { - public let url: String - public let webpageId: MediaId - public let title: String? - public let description: String? - public let photoId: MediaId? - public let author: String? - public let date: Int32? - - init(url: String, webpageId: MediaId, title: String?, description: String?, photoId: MediaId?, author: String?, date: Int32?) { - self.url = url - self.webpageId = webpageId - self.title = title - self.description = description - self.photoId = photoId - self.author = author - self.date = date - } - - public init(decoder: PostboxDecoder) { - self.url = decoder.decodeStringForKey("u", orElse: "") - let webpageIdNamespace = decoder.decodeInt32ForKey("w.n", orElse: 0) - let webpageIdId = decoder.decodeInt64ForKey("w.i", orElse: 0) - self.webpageId = MediaId(namespace: webpageIdNamespace, id: webpageIdId) - - self.title = decoder.decodeOptionalStringForKey("t") - self.description = decoder.decodeOptionalStringForKey("d") - - var photoId: MediaId? - if let photoIdNamespace = decoder.decodeOptionalInt32ForKey("p.n"), let photoIdId = decoder.decodeOptionalInt64ForKey("p.i") { - photoId = MediaId(namespace: photoIdNamespace, id: photoIdId) - } - self.photoId = photoId - self.author = decoder.decodeOptionalStringForKey("a") - self.date = decoder.decodeOptionalInt32ForKey("d") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.url, forKey: "u") - encoder.encodeInt32(self.webpageId.namespace, forKey: "w.n") - encoder.encodeInt64(self.webpageId.id, forKey: "w.i") - if let title = self.title { - encoder.encodeString(title, forKey: "t") - } else { - encoder.encodeNil(forKey: "t") - } - if let description = self.description { - encoder.encodeString(description, forKey: "d") - } else { - encoder.encodeNil(forKey: "d") - } - if let photoId = photoId { - encoder.encodeInt32(photoId.namespace, forKey: "p.n") - encoder.encodeInt64(photoId.id, forKey: "p.i") - } else { - encoder.encodeNil(forKey: "p.n") - encoder.encodeNil(forKey: "p.i") - } - if let author = self.author { - encoder.encodeString(author, forKey: "a") - } else { - encoder.encodeNil(forKey: "a") - } - if let date = self.date { - encoder.encodeInt32(date, forKey: "d") - } else { - encoder.encodeNil(forKey: "d") - } - } - - public static func ==(lhs: InstantPageRelatedArticle, rhs: InstantPageRelatedArticle) -> Bool { - if lhs.url != rhs.url { - return false - } - if lhs.webpageId != rhs.webpageId { - return false - } - if lhs.title != rhs.title { - return false - } - if lhs.description != rhs.description { - return false - } - if lhs.photoId != rhs.photoId { - return false - } - if lhs.author != rhs.author { - return false - } - if lhs.date != rhs.date { - return false - } - return true - } -} - -private final class MediaDictionary: PostboxCoding { - let dict: [MediaId: Media] - - init(dict: [MediaId: Media]) { - self.dict = dict - } - - init(decoder: PostboxDecoder) { - let idsBufer = decoder.decodeBytesForKey("i")! - let mediaIds = MediaId.decodeArrayFromBuffer(idsBufer) - let medias = decoder.decodeObjectArrayForKey("m") - var dict: [MediaId: Media] = [:] - assert(mediaIds.count == medias.count) - for i in 0 ..< mediaIds.count { - if let media = medias[i] as? Media { - dict[mediaIds[i]] = media - } - } - self.dict = dict - } - - func encode(_ encoder: PostboxEncoder) { - var mediaIds: [MediaId] = [] - var medias: [PostboxCoding] = [] - for mediaId in self.dict.keys { - mediaIds.append(mediaId) - medias.append(self.dict[mediaId]!) - } - let buffer = WriteBuffer() - MediaId.encodeArrayToBuffer(mediaIds, buffer: buffer) - encoder.encodeBytes(buffer, forKey: "i") - encoder.encodeGenericObjectArray(medias, forKey: "m") - } -} - -public final class InstantPage: PostboxCoding, Equatable { - public let blocks: [InstantPageBlock] - public let media: [MediaId: Media] - public let isComplete: Bool - public let rtl: Bool - public let url: String - - init(blocks: [InstantPageBlock], media: [MediaId: Media], isComplete: Bool, rtl: Bool, url: String) { - self.blocks = blocks - self.media = media - self.isComplete = isComplete - self.rtl = rtl - self.url = url - } - - public init(decoder: PostboxDecoder) { - self.blocks = decoder.decodeObjectArrayWithDecoderForKey("b") - self.media = MediaDictionary(decoder: decoder).dict - self.isComplete = decoder.decodeInt32ForKey("c", orElse: 0) != 0 - self.rtl = decoder.decodeInt32ForKey("r", orElse: 0) != 0 - self.url = decoder.decodeStringForKey("url", orElse: "") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeObjectArray(self.blocks, forKey: "b") - MediaDictionary(dict: self.media).encode(encoder) - encoder.encodeInt32(self.isComplete ? 1 : 0, forKey: "c") - encoder.encodeInt32(self.rtl ? 1 : 0, forKey: "r") - encoder.encodeString(self.url, forKey: "url") - } - - public static func ==(lhs: InstantPage, rhs: InstantPage) -> Bool { - if lhs.blocks != rhs.blocks { - return false - } - if lhs.media.count != rhs.media.count { - return false - } else { - for (lhsKey, lhsValue) in lhs.media { - if let media = rhs.media[lhsKey] { - if !lhsValue.isEqual(to: media) { - return false - } - } else { - return false - } - } - } - if lhs.isComplete != rhs.isComplete { - return false - } - if lhs.rtl != rhs.rtl { - return false - } - if lhs.url != rhs.url { - return false - } - return true - } -} +import SyncCore extension InstantPageCaption { convenience init(apiCaption: Api.PageCaption) { diff --git a/submodules/TelegramCore/TelegramCore/InvitationLinks.swift b/submodules/TelegramCore/TelegramCore/InvitationLinks.swift index 8f35202636..8bc210127b 100644 --- a/submodules/TelegramCore/TelegramCore/InvitationLinks.swift +++ b/submodules/TelegramCore/TelegramCore/InvitationLinks.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public func ensuredExistingPeerExportedInvitation(account: Account, peerId: PeerId, revokeExisted: Bool = false) -> Signal { return account.postbox.transaction { transaction -> Signal in if let peer = transaction.getPeer(peerId), let inputPeer = apiInputPeer(peer) { diff --git a/submodules/TelegramCore/TelegramCore/JSON.swift b/submodules/TelegramCore/TelegramCore/JSON.swift index 07f8ba6638..5174d4861a 100644 --- a/submodules/TelegramCore/TelegramCore/JSON.swift +++ b/submodules/TelegramCore/TelegramCore/JSON.swift @@ -7,23 +7,9 @@ import Postbox import TelegramApi #endif -public indirect enum JSON: PostboxCoding, Equatable { - case null - case number(Double) - case string(String) - case bool(Bool) - case array([JSON]) - case dictionary([String: JSON]) - - private enum ValueType: Int32 { - case null = 0 - case number = 1 - case string = 2 - case bool = 3 - case array = 4 - case dictionary = 5 - } - +import SyncCore + +extension JSON { private init?(_ object: Any) { if let object = object as? JSONValue { self = object.jsonValue @@ -72,121 +58,6 @@ public indirect enum JSON: PostboxCoding, Equatable { return nil } } - - public init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("r", orElse: 0) { - case ValueType.null.rawValue: - self = .null - case ValueType.number.rawValue: - self = .number(decoder.decodeDoubleForKey("v", orElse: 0.0)) - case ValueType.string.rawValue: - self = .string(decoder.decodeStringForKey("v", orElse: "")) - case ValueType.bool.rawValue: - self = .bool(decoder.decodeBoolForKey("v", orElse: false)) - case ValueType.array.rawValue: - self = .array(decoder.decodeObjectArrayForKey("v")) - case ValueType.dictionary.rawValue: - self = .dictionary(decoder.decodeObjectDictionaryForKey("v", keyDecoder: { $0.decodeStringForKey("k", orElse: "") - }, valueDecoder: { JSON(decoder: $0) })) - default: - self = .null - } - } - - public func encode(_ encoder: PostboxEncoder) { - switch self { - case .null: - encoder.encodeInt32(ValueType.null.rawValue, forKey: "r") - case let .number(value): - encoder.encodeInt32(ValueType.number.rawValue, forKey: "r") - encoder.encodeDouble(value, forKey: "v") - case let .string(value): - encoder.encodeInt32(ValueType.string.rawValue, forKey: "r") - encoder.encodeString(value, forKey: "v") - case let .bool(value): - encoder.encodeInt32(ValueType.bool.rawValue, forKey: "r") - encoder.encodeBool(value, forKey: "v") - case let .array(value): - encoder.encodeInt32(ValueType.array.rawValue, forKey: "r") - encoder.encodeObjectArray(value, forKey: "v") - case let .dictionary(value): - encoder.encodeInt32(ValueType.dictionary.rawValue, forKey: "r") - encoder.encodeObjectDictionary(value, forKey: "v") { key, encoder in - encoder.encodeString(key, forKey: "k") - } - } - } - - public static func ==(lhs: JSON, rhs: JSON) -> Bool { - switch lhs { - case .null: - if case .null = rhs { - return true - } else { - return false - } - case let .number(value): - if case .number(value) = rhs { - return true - } else { - return false - } - case let .string(value): - if case .string(value) = rhs { - return true - } else { - return false - } - case let .bool(value): - if case .bool(value) = rhs { - return true - } else { - return false - } - case let .array(value): - if case .array(value) = rhs { - return true - } else { - return false - } - case let .dictionary(value): - if case .dictionary(value) = rhs { - return true - } else { - return false - } - } - } - - public enum Index: Comparable { - case array(Int) - case dictionary(DictionaryIndex) - case null - - static public func ==(lhs: Index, rhs: Index) -> Bool { - switch (lhs, rhs) { - case let (.array(lhs), .array(rhs)): - return lhs == rhs - case let (.dictionary(lhs), .dictionary(rhs)): - return lhs == rhs - case (.null, .null): - return true - default: - return false - } - } - - static public func <(lhs: Index, rhs: Index) -> Bool { - switch (lhs, rhs) { - case let (.array(lhs), .array(rhs)): - return lhs < rhs - case let (.dictionary(lhs), .dictionary(rhs)): - return lhs < rhs - default: - return false - } - } - } } extension JSON: Collection { diff --git a/submodules/TelegramCore/TelegramCore/JoinChannel.swift b/submodules/TelegramCore/TelegramCore/JoinChannel.swift index 622883999f..b9705d6163 100644 --- a/submodules/TelegramCore/TelegramCore/JoinChannel.swift +++ b/submodules/TelegramCore/TelegramCore/JoinChannel.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public enum JoinChannelError { case generic case tooMuchJoined diff --git a/submodules/TelegramCore/TelegramCore/JoinLink.swift b/submodules/TelegramCore/TelegramCore/JoinLink.swift index 4052a4e8f8..ffbfdb3618 100644 --- a/submodules/TelegramCore/TelegramCore/JoinLink.swift +++ b/submodules/TelegramCore/TelegramCore/JoinLink.swift @@ -14,6 +14,8 @@ #endif #endif +import SyncCore + public enum JoinLinkError { case generic case tooMuchJoined diff --git a/submodules/TelegramCore/TelegramCore/LimitsConfiguration.swift b/submodules/TelegramCore/TelegramCore/LimitsConfiguration.swift index dc95b68f0c..ab8774fefb 100644 --- a/submodules/TelegramCore/TelegramCore/LimitsConfiguration.swift +++ b/submodules/TelegramCore/TelegramCore/LimitsConfiguration.swift @@ -5,78 +5,7 @@ import Foundation import Postbox #endif -public struct LimitsConfiguration: Equatable, PreferencesEntry { - public static let timeIntervalForever: Int32 = 0x7fffffff - - public var maxPinnedChatCount: Int32 - public var maxArchivedPinnedChatCount: Int32 - public var maxGroupMemberCount: Int32 - public var maxSupergroupMemberCount: Int32 - public var maxMessageForwardBatchSize: Int32 - public var maxSavedGifCount: Int32 - public var maxRecentStickerCount: Int32 - public var maxMessageEditingInterval: Int32 - public var maxMediaCaptionLength: Int32 - public var canRemoveIncomingMessagesInPrivateChats: Bool - public var maxMessageRevokeInterval: Int32 - public var maxMessageRevokeIntervalInPrivateChats: Int32 - - public static var defaultValue: LimitsConfiguration { - return LimitsConfiguration(maxPinnedChatCount: 5, maxArchivedPinnedChatCount: 20, maxGroupMemberCount: 200, maxSupergroupMemberCount: 200000, maxMessageForwardBatchSize: 50, maxSavedGifCount: 200, maxRecentStickerCount: 20, maxMessageEditingInterval: 2 * 24 * 60 * 60, maxMediaCaptionLength: 1000, canRemoveIncomingMessagesInPrivateChats: false, maxMessageRevokeInterval: 2 * 24 * 60 * 60, maxMessageRevokeIntervalInPrivateChats: 2 * 24 * 60 * 60) - } - - init(maxPinnedChatCount: Int32, maxArchivedPinnedChatCount: Int32, maxGroupMemberCount: Int32, maxSupergroupMemberCount: Int32, maxMessageForwardBatchSize: Int32, maxSavedGifCount: Int32, maxRecentStickerCount: Int32, maxMessageEditingInterval: Int32, maxMediaCaptionLength: Int32, canRemoveIncomingMessagesInPrivateChats: Bool, maxMessageRevokeInterval: Int32, maxMessageRevokeIntervalInPrivateChats: Int32) { - self.maxPinnedChatCount = maxPinnedChatCount - self.maxArchivedPinnedChatCount = maxArchivedPinnedChatCount - self.maxGroupMemberCount = maxGroupMemberCount - self.maxSupergroupMemberCount = maxSupergroupMemberCount - self.maxMessageForwardBatchSize = maxMessageForwardBatchSize - self.maxSavedGifCount = maxSavedGifCount - self.maxRecentStickerCount = maxRecentStickerCount - self.maxMessageEditingInterval = maxMessageEditingInterval - self.maxMediaCaptionLength = maxMediaCaptionLength - self.canRemoveIncomingMessagesInPrivateChats = canRemoveIncomingMessagesInPrivateChats - self.maxMessageRevokeInterval = maxMessageRevokeInterval - self.maxMessageRevokeIntervalInPrivateChats = maxMessageRevokeIntervalInPrivateChats - } - - public init(decoder: PostboxDecoder) { - self.maxPinnedChatCount = decoder.decodeInt32ForKey("maxPinnedChatCount", orElse: 5) - self.maxArchivedPinnedChatCount = decoder.decodeInt32ForKey("maxArchivedPinnedChatCount", orElse: 20) - self.maxGroupMemberCount = decoder.decodeInt32ForKey("maxGroupMemberCount", orElse: 200) - self.maxSupergroupMemberCount = decoder.decodeInt32ForKey("maxSupergroupMemberCount", orElse: 5000) - self.maxMessageForwardBatchSize = decoder.decodeInt32ForKey("maxMessageForwardBatchSize", orElse: 50) - self.maxSavedGifCount = decoder.decodeInt32ForKey("maxSavedGifCount", orElse: 200) - self.maxRecentStickerCount = decoder.decodeInt32ForKey("maxRecentStickerCount", orElse: 20) - self.maxMessageEditingInterval = decoder.decodeInt32ForKey("maxMessageEditingInterval", orElse: 2 * 24 * 60 * 60) - self.maxMediaCaptionLength = decoder.decodeInt32ForKey("maxMediaCaptionLength", orElse: 1000) - self.canRemoveIncomingMessagesInPrivateChats = decoder.decodeInt32ForKey("canRemoveIncomingMessagesInPrivateChats", orElse: 0) != 0 - self.maxMessageRevokeInterval = decoder.decodeInt32ForKey("maxMessageRevokeInterval", orElse: 2 * 24 * 60 * 60) - self.maxMessageRevokeIntervalInPrivateChats = decoder.decodeInt32ForKey("maxMessageRevokeIntervalInPrivateChats", orElse: 2 * 24 * 60 * 60) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.maxPinnedChatCount, forKey: "maxPinnedChatCount") - encoder.encodeInt32(self.maxArchivedPinnedChatCount, forKey: "maxArchivedPinnedChatCount") - encoder.encodeInt32(self.maxGroupMemberCount, forKey: "maxGroupMemberCount") - encoder.encodeInt32(self.maxSupergroupMemberCount, forKey: "maxSupergroupMemberCount") - encoder.encodeInt32(self.maxMessageForwardBatchSize, forKey: "maxMessageForwardBatchSize") - encoder.encodeInt32(self.maxSavedGifCount, forKey: "maxSavedGifCount") - encoder.encodeInt32(self.maxRecentStickerCount, forKey: "maxRecentStickerCount") - encoder.encodeInt32(self.maxMessageEditingInterval, forKey: "maxMessageEditingInterval") - encoder.encodeInt32(self.maxMediaCaptionLength, forKey: "maxMediaCaptionLength") - encoder.encodeInt32(self.canRemoveIncomingMessagesInPrivateChats ? 1 : 0, forKey: "canRemoveIncomingMessagesInPrivateChats") - encoder.encodeInt32(self.maxMessageRevokeInterval, forKey: "maxMessageRevokeInterval") - encoder.encodeInt32(self.maxMessageRevokeIntervalInPrivateChats, forKey: "maxMessageRevokeIntervalInPrivateChats") - } - - public func isEqual(to: PreferencesEntry) -> Bool { - guard let to = to as? LimitsConfiguration else { - return false - } - return self == to - } -} +import SyncCore public func currentLimitsConfiguration(transaction: Transaction) -> LimitsConfiguration { if let entry = transaction.getPreferencesEntry(key: PreferencesKeys.limitsConfiguration) as? LimitsConfiguration { diff --git a/submodules/TelegramCore/TelegramCore/LoadMessagesIfNecessary.swift b/submodules/TelegramCore/TelegramCore/LoadMessagesIfNecessary.swift index fc18a97ab1..0a39026554 100644 --- a/submodules/TelegramCore/TelegramCore/LoadMessagesIfNecessary.swift +++ b/submodules/TelegramCore/TelegramCore/LoadMessagesIfNecessary.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public enum GetMessagesStrategy { case local case cloud diff --git a/submodules/TelegramCore/TelegramCore/LoadedPeer.swift b/submodules/TelegramCore/TelegramCore/LoadedPeer.swift index 81eda2ea5c..225296214c 100644 --- a/submodules/TelegramCore/TelegramCore/LoadedPeer.swift +++ b/submodules/TelegramCore/TelegramCore/LoadedPeer.swift @@ -8,6 +8,8 @@ import SwiftSignalKit #endif +import SyncCore + public func actualizedPeer(postbox: Postbox, network: Network, peer: Peer) -> Signal { return postbox.transaction { transaction -> Signal in var signal: Signal diff --git a/submodules/TelegramCore/TelegramCore/LoadedPeerFromMessage.swift b/submodules/TelegramCore/TelegramCore/LoadedPeerFromMessage.swift index a15637b8ce..fdb6c7a573 100644 --- a/submodules/TelegramCore/TelegramCore/LoadedPeerFromMessage.swift +++ b/submodules/TelegramCore/TelegramCore/LoadedPeerFromMessage.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public func loadedPeerFromMessage(account: Account, peerId: PeerId, messageId: MessageId) -> Signal { return account.postbox.transaction { transaction -> Signal in if let peer = transaction.getPeer(peerId) { diff --git a/submodules/TelegramCore/TelegramCore/LoadedStickerPack.swift b/submodules/TelegramCore/TelegramCore/LoadedStickerPack.swift index 05b0385db8..b268f490b9 100644 --- a/submodules/TelegramCore/TelegramCore/LoadedStickerPack.swift +++ b/submodules/TelegramCore/TelegramCore/LoadedStickerPack.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + extension StickerPackReference { init(_ stickerPackInfo: StickerPackCollectionInfo) { self = .id(id: stickerPackInfo.id.id, accessHash: stickerPackInfo.accessHash) diff --git a/submodules/TelegramCore/TelegramCore/LocalizationInfo.swift b/submodules/TelegramCore/TelegramCore/LocalizationInfo.swift index a364fae4bb..2b0e3b928f 100644 --- a/submodules/TelegramCore/TelegramCore/LocalizationInfo.swift +++ b/submodules/TelegramCore/TelegramCore/LocalizationInfo.swift @@ -7,61 +7,7 @@ import Foundation import TelegramApi #endif -public struct LocalizationInfo: PostboxCoding, Equatable { - public let languageCode: String - public let baseLanguageCode: String? - public let customPluralizationCode: String? - public let title: String - public let localizedTitle: String - public let isOfficial: Bool - public let totalStringCount: Int32 - public let translatedStringCount: Int32 - public let platformUrl: String - - public init(languageCode: String, baseLanguageCode: String?, customPluralizationCode: String?, title: String, localizedTitle: String, isOfficial: Bool, totalStringCount: Int32, translatedStringCount: Int32, platformUrl: String) { - self.languageCode = languageCode - self.baseLanguageCode = baseLanguageCode - self.customPluralizationCode = customPluralizationCode - self.title = title - self.localizedTitle = localizedTitle - self.isOfficial = isOfficial - self.totalStringCount = totalStringCount - self.translatedStringCount = translatedStringCount - self.platformUrl = platformUrl - } - - public init(decoder: PostboxDecoder) { - self.languageCode = decoder.decodeStringForKey("lc", orElse: "") - self.baseLanguageCode = decoder.decodeOptionalStringForKey("nlc") - self.customPluralizationCode = decoder.decodeOptionalStringForKey("cpc") - self.title = decoder.decodeStringForKey("t", orElse: "") - self.localizedTitle = decoder.decodeStringForKey("lt", orElse: "") - self.isOfficial = decoder.decodeInt32ForKey("of", orElse: 0) != 0 - self.totalStringCount = decoder.decodeInt32ForKey("tsc", orElse: 0) - self.translatedStringCount = decoder.decodeInt32ForKey("lsc", orElse: 0) - self.platformUrl = decoder.decodeStringForKey("platformUrl", orElse: "") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.languageCode, forKey: "lc") - if let baseLanguageCode = self.baseLanguageCode { - encoder.encodeString(baseLanguageCode, forKey: "nlc") - } else { - encoder.encodeNil(forKey: "nlc") - } - if let customPluralizationCode = self.customPluralizationCode { - encoder.encodeString(customPluralizationCode, forKey: "cpc") - } else { - encoder.encodeNil(forKey: "cpc") - } - encoder.encodeString(self.title, forKey: "t") - encoder.encodeString(self.localizedTitle, forKey: "lt") - encoder.encodeInt32(self.isOfficial ? 1 : 0, forKey: "of") - encoder.encodeInt32(self.totalStringCount, forKey: "tsc") - encoder.encodeInt32(self.translatedStringCount, forKey: "lsc") - encoder.encodeString(self.platformUrl, forKey: "platformUrl") - } -} +import SyncCore extension LocalizationInfo { init(apiLanguage: Api.LangPackLanguage) { diff --git a/submodules/TelegramCore/TelegramCore/LocalizationListState.swift b/submodules/TelegramCore/TelegramCore/LocalizationListState.swift index 8bc1e1df18..af8b286739 100644 --- a/submodules/TelegramCore/TelegramCore/LocalizationListState.swift +++ b/submodules/TelegramCore/TelegramCore/LocalizationListState.swift @@ -9,37 +9,7 @@ import SwiftSignalKit import TelegramApi #endif -public struct LocalizationListState: PreferencesEntry, Equatable { - public var availableOfficialLocalizations: [LocalizationInfo] - public var availableSavedLocalizations: [LocalizationInfo] - - public static var defaultSettings: LocalizationListState { - return LocalizationListState(availableOfficialLocalizations: [], availableSavedLocalizations: []) - } - - public init(availableOfficialLocalizations: [LocalizationInfo], availableSavedLocalizations: [LocalizationInfo]) { - self.availableOfficialLocalizations = availableOfficialLocalizations - self.availableSavedLocalizations = availableSavedLocalizations - } - - public init(decoder: PostboxDecoder) { - self.availableOfficialLocalizations = decoder.decodeObjectArrayWithDecoderForKey("availableOfficialLocalizations") - self.availableSavedLocalizations = decoder.decodeObjectArrayWithDecoderForKey("availableSavedLocalizations") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeObjectArray(self.availableOfficialLocalizations, forKey: "availableOfficialLocalizations") - encoder.encodeObjectArray(self.availableSavedLocalizations, forKey: "availableSavedLocalizations") - } - - public func isEqual(to: PreferencesEntry) -> Bool { - guard let to = to as? LocalizationListState else { - return false - } - - return self == to - } -} +import SyncCore public func removeSavedLocalization(transaction: Transaction, languageCode: String) { updateLocalizationListStateInteractively(transaction: transaction, { state in diff --git a/submodules/TelegramCore/TelegramCore/LocalizationPreview.swift b/submodules/TelegramCore/TelegramCore/LocalizationPreview.swift index 530abe7cea..8502f0d5cd 100644 --- a/submodules/TelegramCore/TelegramCore/LocalizationPreview.swift +++ b/submodules/TelegramCore/TelegramCore/LocalizationPreview.swift @@ -14,6 +14,7 @@ import SwiftSignalKit #endif #endif +import SyncCore public enum RequestLocalizationPreviewError { case generic diff --git a/submodules/TelegramCore/TelegramCore/Localizations.swift b/submodules/TelegramCore/TelegramCore/Localizations.swift index 43f8bb05fe..3125095b8f 100644 --- a/submodules/TelegramCore/TelegramCore/Localizations.swift +++ b/submodules/TelegramCore/TelegramCore/Localizations.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public func currentlySuggestedLocalization(network: Network, extractKeys: [String]) -> Signal { return network.request(Api.functions.help.getConfig()) |> retryRequest @@ -44,22 +46,6 @@ public func suggestedLocalizationInfo(network: Network, languageCode: String, ex } } -final class CachedLocalizationInfos: PostboxCoding { - let list: [LocalizationInfo] - - init(list: [LocalizationInfo]) { - self.list = list - } - - init(decoder: PostboxDecoder) { - self.list = decoder.decodeObjectArrayWithDecoderForKey("l") - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeObjectArray(self.list, forKey: "l") - } -} - public func availableLocalizations(postbox: Postbox, network: Network, allowCached: Bool) -> Signal<[LocalizationInfo], NoError> { let cached: Signal<[LocalizationInfo], NoError> if allowCached { diff --git a/submodules/TelegramCore/TelegramCore/LoggingSettings.swift b/submodules/TelegramCore/TelegramCore/LoggingSettings.swift index 8e283e9848..83ddd82f14 100644 --- a/submodules/TelegramCore/TelegramCore/LoggingSettings.swift +++ b/submodules/TelegramCore/TelegramCore/LoggingSettings.swift @@ -6,75 +6,10 @@ import Foundation #else import Postbox import SwiftSignalKit - #if BUCK - import MtProtoKit - #else - import MtProtoKitDynamic - #endif + import MtProtoKit #endif -public final class LoggingSettings: PreferencesEntry, Equatable { - public let logToFile: Bool - public let logToConsole: Bool - public let redactSensitiveData: Bool - - #if DEBUG - public static var defaultSettings = LoggingSettings(logToFile: true, logToConsole: true, redactSensitiveData: true) - #else - public static var defaultSettings = LoggingSettings(logToFile: false, logToConsole: false, redactSensitiveData: true) - #endif - - public init(logToFile: Bool, logToConsole: Bool, redactSensitiveData: Bool) { - self.logToFile = logToFile - self.logToConsole = logToConsole - self.redactSensitiveData = redactSensitiveData - } - - public init(decoder: PostboxDecoder) { - self.logToFile = decoder.decodeInt32ForKey("logToFile", orElse: 0) != 0 - self.logToConsole = decoder.decodeInt32ForKey("logToConsole", orElse: 0) != 0 - self.redactSensitiveData = decoder.decodeInt32ForKey("redactSensitiveData", orElse: 1) != 0 - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.logToFile ? 1 : 0, forKey: "logToFile") - encoder.encodeInt32(self.logToConsole ? 1 : 0, forKey: "logToConsole") - encoder.encodeInt32(self.redactSensitiveData ? 1 : 0, forKey: "redactSensitiveData") - } - - public func withUpdatedLogToFile(_ logToFile: Bool) -> LoggingSettings { - return LoggingSettings(logToFile: logToFile, logToConsole: self.logToConsole, redactSensitiveData: self.redactSensitiveData) - } - - public func withUpdatedLogToConsole(_ logToConsole: Bool) -> LoggingSettings { - return LoggingSettings(logToFile: self.logToFile, logToConsole: logToConsole, redactSensitiveData: self.redactSensitiveData) - } - - public func withUpdatedRedactSensitiveData(_ redactSensitiveData: Bool) -> LoggingSettings { - return LoggingSettings(logToFile: self.logToFile, logToConsole: self.logToConsole, redactSensitiveData: redactSensitiveData) - } - - public static func ==(lhs: LoggingSettings, rhs: LoggingSettings) -> Bool { - if lhs.logToFile != rhs.logToFile { - return false - } - if lhs.logToConsole != rhs.logToConsole { - return false - } - if lhs.redactSensitiveData != rhs.redactSensitiveData { - return false - } - return true - } - - public func isEqual(to: PreferencesEntry) -> Bool { - guard let to = to as? LoggingSettings else { - return false - } - - return self == to - } -} +import SyncCore public func updateLoggingSettings(accountManager: AccountManager, _ f: @escaping (LoggingSettings) -> LoggingSettings) -> Signal { return accountManager.transaction { transaction -> Void in diff --git a/submodules/TelegramCore/TelegramCore/ManageChannelDiscussionGroup.swift b/submodules/TelegramCore/TelegramCore/ManageChannelDiscussionGroup.swift index 5e43a8bd9c..0c9b541273 100644 --- a/submodules/TelegramCore/TelegramCore/ManageChannelDiscussionGroup.swift +++ b/submodules/TelegramCore/TelegramCore/ManageChannelDiscussionGroup.swift @@ -9,6 +9,7 @@ import Postbox import TelegramApi #endif +import SyncCore public enum AvailableChannelDiscussionGroupError { case generic diff --git a/submodules/TelegramCore/TelegramCore/ManagedAppConfigurationUpdates.swift b/submodules/TelegramCore/TelegramCore/ManagedAppConfigurationUpdates.swift index 4b364abcf7..c5d5af7c87 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedAppConfigurationUpdates.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedAppConfigurationUpdates.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + func managedAppConfigurationUpdates(postbox: Postbox, network: Network) -> Signal { let poll = Signal { subscriber in return (network.request(Api.functions.help.getAppConfig()) diff --git a/submodules/TelegramCore/TelegramCore/ManagedAutodownloadSettingsUpdates.swift b/submodules/TelegramCore/TelegramCore/ManagedAutodownloadSettingsUpdates.swift index 8bfdb7ea78..5e3fcac489 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedAutodownloadSettingsUpdates.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedAutodownloadSettingsUpdates.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + func managedAutodownloadSettingsUpdates(accountManager: AccountManager, network: Network) -> Signal { let poll = Signal { subscriber in return (network.request(Api.functions.account.getAutoDownloadSettings()) diff --git a/submodules/TelegramCore/TelegramCore/ManagedAutoremoveMessageOperations.swift b/submodules/TelegramCore/TelegramCore/ManagedAutoremoveMessageOperations.swift index 2f4532fc1d..6c1eb22563 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedAutoremoveMessageOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedAutoremoveMessageOperations.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + #if os(macOS) private typealias SignalKitTimer = SwiftSignalKitMac.Timer #else diff --git a/submodules/TelegramCore/TelegramCore/ManagedCloudChatRemoveMessagesOperations.swift b/submodules/TelegramCore/TelegramCore/ManagedCloudChatRemoveMessagesOperations.swift index a3a49414c3..27c209b072 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedCloudChatRemoveMessagesOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedCloudChatRemoveMessagesOperations.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private final class ManagedCloudChatRemoveMessagesOperationsHelper { var operationDisposables: [Int32: Disposable] = [:] diff --git a/submodules/TelegramCore/TelegramCore/ManagedConfigurationUpdates.swift b/submodules/TelegramCore/TelegramCore/ManagedConfigurationUpdates.swift index 3b24e17550..73466b6d2c 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedConfigurationUpdates.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedConfigurationUpdates.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + func managedConfigurationUpdates(accountManager: AccountManager, postbox: Postbox, network: Network) -> Signal { let poll = Signal { subscriber in return (network.request(Api.functions.help.getConfig()) diff --git a/submodules/TelegramCore/TelegramCore/ManagedConsumePersonalMessagesActions.swift b/submodules/TelegramCore/TelegramCore/ManagedConsumePersonalMessagesActions.swift index ffff3c965e..d01fa03578 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedConsumePersonalMessagesActions.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedConsumePersonalMessagesActions.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private final class ManagedConsumePersonalMessagesActionsHelper { var operationDisposables: [MessageId: Disposable] = [:] var validateDisposables: [InvalidatedMessageHistoryTagsSummaryEntry: Disposable] = [:] diff --git a/submodules/TelegramCore/TelegramCore/ManagedGlobalNotificationSettings.swift b/submodules/TelegramCore/TelegramCore/ManagedGlobalNotificationSettings.swift index 0557fc2705..c545d3d4d7 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedGlobalNotificationSettings.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedGlobalNotificationSettings.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public func updateGlobalNotificationSettingsInteractively(postbox: Postbox, _ f: @escaping (GlobalNotificationSettingsSet) -> GlobalNotificationSettingsSet) -> Signal { return postbox.transaction { transaction -> Void in transaction.updatePreferencesEntry(key: PreferencesKeys.globalNotifications, { current in diff --git a/submodules/TelegramCore/TelegramCore/ManagedLocalInputActivities.swift b/submodules/TelegramCore/TelegramCore/ManagedLocalInputActivities.swift index 17518968b6..49aeb75457 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedLocalInputActivities.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedLocalInputActivities.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + struct PeerInputActivityRecord: Equatable { let activity: PeerInputActivity let updateId: Int32 diff --git a/submodules/TelegramCore/TelegramCore/ManagedLocalizationUpdatesOperations.swift b/submodules/TelegramCore/TelegramCore/ManagedLocalizationUpdatesOperations.swift index c2d3f1a696..4be6e72e7c 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedLocalizationUpdatesOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedLocalizationUpdatesOperations.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private final class ManagedLocalizationUpdatesOperationsHelper { var operationDisposables: [Int32: Disposable] = [:] diff --git a/submodules/TelegramCore/TelegramCore/ManagedNotificationSettingsBehaviors.swift b/submodules/TelegramCore/TelegramCore/ManagedNotificationSettingsBehaviors.swift index 828a4d46c4..98a16f66b0 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedNotificationSettingsBehaviors.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedNotificationSettingsBehaviors.swift @@ -7,6 +7,8 @@ import Postbox import SwiftSignalKit #endif +import SyncCore + func managedNotificationSettingsBehaviors(postbox: Postbox) -> Signal { return postbox.combinedView(keys: [.peerNotificationSettingsBehaviorTimestampView]) |> mapToSignal { views -> Signal in diff --git a/submodules/TelegramCore/TelegramCore/ManagedPendingPeerNotificationSettings.swift b/submodules/TelegramCore/TelegramCore/ManagedPendingPeerNotificationSettings.swift index b9d9149333..7f4a4bec2f 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedPendingPeerNotificationSettings.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedPendingPeerNotificationSettings.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private final class ManagedPendingPeerNotificationSettingsHelper { var operationDisposables: [PeerId: (PeerNotificationSettings, Disposable)] = [:] diff --git a/submodules/TelegramCore/TelegramCore/ManagedProxyInfoUpdates.swift b/submodules/TelegramCore/TelegramCore/ManagedProxyInfoUpdates.swift index 34a57147e1..1f4f3e6949 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedProxyInfoUpdates.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedProxyInfoUpdates.swift @@ -15,6 +15,8 @@ import SwiftSignalKit #endif #endif +import SyncCore + func managedProxyInfoUpdates(postbox: Postbox, network: Network, viewTracker: AccountViewTracker) -> Signal { return Signal { subscriber in let queue = Queue() diff --git a/submodules/TelegramCore/TelegramCore/ManagedRecentStickers.swift b/submodules/TelegramCore/TelegramCore/ManagedRecentStickers.swift index ad984252ce..3f17508b77 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedRecentStickers.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedRecentStickers.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + private func hashForIds(_ ids: [Int64]) -> Int32 { var acc: UInt32 = 0 diff --git a/submodules/TelegramCore/TelegramCore/ManagedSecretChatOutgoingOperations.swift b/submodules/TelegramCore/TelegramCore/ManagedSecretChatOutgoingOperations.swift index a2eeb3e504..c94fe4582d 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedSecretChatOutgoingOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedSecretChatOutgoingOperations.swift @@ -16,6 +16,7 @@ import Foundation import UIKit #endif +import SyncCore func addSecretChatOutgoingOperation(transaction: Transaction, peerId: PeerId, operation: SecretChatOutgoingOperationContents, state: SecretChatState) -> SecretChatState { var updatedState = state diff --git a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeAppLogEventsOperations.swift b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeAppLogEventsOperations.swift index 24c939ee30..8627918b47 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeAppLogEventsOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeAppLogEventsOperations.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private final class ManagedSynchronizeAppLogEventsOperationsHelper { var operationDisposables: [Int32: Disposable] = [:] diff --git a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeChatInputStateOperations.swift b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeChatInputStateOperations.swift index d534b46a48..40399ec9cb 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeChatInputStateOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeChatInputStateOperations.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private final class ManagedSynchronizeChatInputStateOperationsHelper { var operationDisposables: [Int32: Disposable] = [:] diff --git a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeConsumeMessageContentsOperations.swift b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeConsumeMessageContentsOperations.swift index c8ace296c4..4da9fb23b6 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeConsumeMessageContentsOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeConsumeMessageContentsOperations.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private final class ManagedSynchronizeConsumeMessageContentsOperationHelper { var operationDisposables: [Int32: Disposable] = [:] diff --git a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeEmojiKeywordsOperations.swift b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeEmojiKeywordsOperations.swift index 414c1f9a12..4461e27d58 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeEmojiKeywordsOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeEmojiKeywordsOperations.swift @@ -15,6 +15,8 @@ import SwiftSignalKit #endif #endif +import SyncCore + private final class ManagedSynchronizeEmojiKeywordsOperationHelper { var operationDisposables: [Int32: Disposable] = [:] diff --git a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeGroupMessageStats.swift b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeGroupMessageStats.swift index 70e2b2ba2e..b8c020dc97 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeGroupMessageStats.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeGroupMessageStats.swift @@ -8,6 +8,9 @@ import Postbox import SwiftSignalKit import TelegramApi #endif + +import SyncCore + private final class ManagedSynchronizeGroupMessageStatsState { private var synchronizeDisposables: [PeerGroupAndNamespace: Disposable] = [:] diff --git a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeGroupedPeersOperations.swift b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeGroupedPeersOperations.swift index 872d537fb3..6a297cefb7 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeGroupedPeersOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeGroupedPeersOperations.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private final class ManagedSynchronizeGroupedPeersOperationsHelper { var operationDisposables: [Int32: Disposable] = [:] diff --git a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeInstalledStickerPacksOperations.swift b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeInstalledStickerPacksOperations.swift index 8fdccffa8a..a05eb632a4 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeInstalledStickerPacksOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeInstalledStickerPacksOperations.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private final class ManagedSynchronizeInstalledStickerPacksOperationsHelper { var operationDisposables: [Int32: Disposable] = [:] diff --git a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeMarkAllUnseenPersonalMessagesOperations.swift b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeMarkAllUnseenPersonalMessagesOperations.swift index d5185e07df..18d82367af 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeMarkAllUnseenPersonalMessagesOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeMarkAllUnseenPersonalMessagesOperations.swift @@ -15,6 +15,8 @@ import SwiftSignalKit #endif #endif +import SyncCore + private final class ManagedSynchronizeMarkAllUnseenPersonalMessagesOperationsHelper { var operationDisposables: [Int32: Disposable] = [:] diff --git a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeMarkFeaturedStickerPacksAsSeenOperations.swift b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeMarkFeaturedStickerPacksAsSeenOperations.swift index 35f3e823de..17bd941e78 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeMarkFeaturedStickerPacksAsSeenOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeMarkFeaturedStickerPacksAsSeenOperations.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private final class ManagedSynchronizeMarkFeaturedStickerPacksAsSeenOperationsHelper { var operationDisposables: [Int32: Disposable] = [:] diff --git a/submodules/TelegramCore/TelegramCore/ManagedSynchronizePinnedChatsOperations.swift b/submodules/TelegramCore/TelegramCore/ManagedSynchronizePinnedChatsOperations.swift index 50edb4ccf5..31773ee887 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedSynchronizePinnedChatsOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedSynchronizePinnedChatsOperations.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private final class ManagedSynchronizePinnedChatsOperationsHelper { var operationDisposables: [Int32: Disposable] = [:] diff --git a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeRecentlyUsedMediaOperations.swift b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeRecentlyUsedMediaOperations.swift index e932a72cb1..fec1b03094 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeRecentlyUsedMediaOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeRecentlyUsedMediaOperations.swift @@ -15,6 +15,8 @@ import SwiftSignalKit #endif #endif +import SyncCore + private final class ManagedSynchronizeRecentlyUsedMediaOperationsHelper { var operationDisposables: [Int32: Disposable] = [:] diff --git a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeSavedGifsOperations.swift b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeSavedGifsOperations.swift index 6ea80a781b..8003ee0258 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeSavedGifsOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeSavedGifsOperations.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private final class ManagedSynchronizeSavedGifsOperationsHelper { var operationDisposables: [Int32: Disposable] = [:] diff --git a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeSavedStickersOperations.swift b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeSavedStickersOperations.swift index 034801dda7..080e26626e 100644 --- a/submodules/TelegramCore/TelegramCore/ManagedSynchronizeSavedStickersOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ManagedSynchronizeSavedStickersOperations.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + private final class ManagedSynchronizeSavedStickersOperationsHelper { var operationDisposables: [Int32: Disposable] = [:] diff --git a/submodules/TelegramCore/TelegramCore/MarkAllChatsAsRead.swift b/submodules/TelegramCore/TelegramCore/MarkAllChatsAsRead.swift index 6607d16c28..37d37c24f4 100644 --- a/submodules/TelegramCore/TelegramCore/MarkAllChatsAsRead.swift +++ b/submodules/TelegramCore/TelegramCore/MarkAllChatsAsRead.swift @@ -15,6 +15,8 @@ import SwiftSignalKit #endif #endif +import SyncCore + public func markAllChatsAsRead(postbox: Postbox, network: Network, stateManager: AccountStateManager) -> Signal { return network.request(Api.functions.messages.getDialogUnreadMarks()) |> map(Optional.init) diff --git a/submodules/TelegramCore/TelegramCore/MarkMessageContentAsConsumedInteractively.swift b/submodules/TelegramCore/TelegramCore/MarkMessageContentAsConsumedInteractively.swift index fd0e9c3030..47cc924977 100644 --- a/submodules/TelegramCore/TelegramCore/MarkMessageContentAsConsumedInteractively.swift +++ b/submodules/TelegramCore/TelegramCore/MarkMessageContentAsConsumedInteractively.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public func markMessageContentAsConsumedInteractively(postbox: Postbox, messageId: MessageId) -> Signal { return postbox.transaction { transaction -> Void in if let message = transaction.getMessage(messageId), message.flags.contains(.Incoming) { diff --git a/submodules/TelegramCore/TelegramCore/MediaResourceApiUtils.swift b/submodules/TelegramCore/TelegramCore/MediaResourceApiUtils.swift index d3471fd83c..d3afe47d15 100644 --- a/submodules/TelegramCore/TelegramCore/MediaResourceApiUtils.swift +++ b/submodules/TelegramCore/TelegramCore/MediaResourceApiUtils.swift @@ -1,4 +1,5 @@ import Foundation +import SyncCore extension SecretChatFileReference { func resource(key: SecretFileEncryptionKey, decryptedSize: Int32) -> SecretFileMediaResource { diff --git a/submodules/TelegramCore/TelegramCore/MessageMediaPreuploadManager.swift b/submodules/TelegramCore/TelegramCore/MessageMediaPreuploadManager.swift index 5b34f66a6f..cc4feb46b8 100644 --- a/submodules/TelegramCore/TelegramCore/MessageMediaPreuploadManager.swift +++ b/submodules/TelegramCore/TelegramCore/MessageMediaPreuploadManager.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + private func localIdForResource(_ resource: MediaResource) -> Int64? { if let resource = resource as? LocalFileMediaResource { return resource.fileId diff --git a/submodules/TelegramCore/TelegramCore/MessageReactionList.swift b/submodules/TelegramCore/TelegramCore/MessageReactionList.swift index f371041316..1b4682b058 100644 --- a/submodules/TelegramCore/TelegramCore/MessageReactionList.swift +++ b/submodules/TelegramCore/TelegramCore/MessageReactionList.swift @@ -15,6 +15,8 @@ import MtProtoKitDynamic #endif #endif +import SyncCore + public enum MessageReactionListCategory: Hashable { case all case reaction(String) diff --git a/submodules/TelegramCore/TelegramCore/MessageReactions.swift b/submodules/TelegramCore/TelegramCore/MessageReactions.swift index ec2a860834..4a3cd265f0 100644 --- a/submodules/TelegramCore/TelegramCore/MessageReactions.swift +++ b/submodules/TelegramCore/TelegramCore/MessageReactions.swift @@ -15,24 +15,7 @@ import MtProtoKitDynamic #endif #endif -final class UpdateMessageReactionsAction: PendingMessageActionData { - init() { - } - - init(decoder: PostboxDecoder) { - } - - func encode(_ encoder: PostboxEncoder) { - } - - func isEqual(to: PendingMessageActionData) -> Bool { - if let _ = to as? UpdateMessageReactionsAction { - return true - } else { - return false - } - } -} +import SyncCore public func updateMessageReactionsInteractively(postbox: Postbox, messageId: MessageId, reaction: String?) -> Signal { return postbox.transaction { transaction -> Void in diff --git a/submodules/TelegramCore/TelegramCore/MessageUtils.swift b/submodules/TelegramCore/TelegramCore/MessageUtils.swift index 3a354e6fab..57adb0fba2 100644 --- a/submodules/TelegramCore/TelegramCore/MessageUtils.swift +++ b/submodules/TelegramCore/TelegramCore/MessageUtils.swift @@ -5,6 +5,8 @@ import Foundation import Postbox #endif +import SyncCore + public extension MessageFlags { var isSending: Bool { return (self.contains(.Unsent) || self.contains(.Sending)) && !self.contains(.Failed) @@ -200,3 +202,52 @@ public extension Message { } } } + +public extension Message { + var secretMediaDuration: Int32? { + var found = false + for attribute in self.attributes { + if let _ = attribute as? AutoremoveTimeoutMessageAttribute { + found = true + break + } + } + + if !found { + return nil + } + + for media in self.media { + switch media { + case _ as TelegramMediaImage: + return nil + case let file as TelegramMediaFile: + return file.duration + default: + break + } + } + + return nil + } +} + +public extension Message { + var isSentOrAcknowledged: Bool { + if self.flags.contains(.Failed) { + return false + } else if self.flags.isSending { + for attribute in self.attributes { + if let attribute = attribute as? OutgoingMessageInfoAttribute { + if attribute.acknowledged { + return true + } + } + } + return false + } else { + return true + } + } +} + diff --git a/submodules/TelegramCore/TelegramCore/MultipartFetch.swift b/submodules/TelegramCore/TelegramCore/MultipartFetch.swift index c9d058a265..84b071e7e0 100644 --- a/submodules/TelegramCore/TelegramCore/MultipartFetch.swift +++ b/submodules/TelegramCore/TelegramCore/MultipartFetch.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + #if os(macOS) private typealias SignalKitTimer = SwiftSignalKitMac.Timer #else diff --git a/submodules/TelegramCore/TelegramCore/MultipartUpload.swift b/submodules/TelegramCore/TelegramCore/MultipartUpload.swift index 6584919c1a..4b3a2ac29b 100644 --- a/submodules/TelegramCore/TelegramCore/MultipartUpload.swift +++ b/submodules/TelegramCore/TelegramCore/MultipartUpload.swift @@ -15,36 +15,14 @@ import Foundation #endif #endif +import SyncCore + #if os(macOS) private typealias SignalKitTimer = SwiftSignalKitMac.Timer #else private typealias SignalKitTimer = SwiftSignalKit.Timer #endif -public final class SecretFileEncryptionKey: PostboxCoding, Equatable { - public let aesKey: Data - public let aesIv: Data - - public init(aesKey: Data, aesIv: Data) { - self.aesKey = aesKey - self.aesIv = aesIv - } - - public init(decoder: PostboxDecoder) { - self.aesKey = decoder.decodeBytesForKey("k")!.makeData() - self.aesIv = decoder.decodeBytesForKey("i")!.makeData() - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeBytes(MemoryBuffer(data: self.aesKey), forKey: "k") - encoder.encodeBytes(MemoryBuffer(data: self.aesIv), forKey: "i") - } - - public static func ==(lhs: SecretFileEncryptionKey, rhs: SecretFileEncryptionKey) -> Bool { - return lhs.aesKey == rhs.aesKey && lhs.aesIv == rhs.aesIv - } -} - private struct UploadPart { let fileId: Int64 let index: Int diff --git a/submodules/TelegramCore/TelegramCore/Network.swift b/submodules/TelegramCore/TelegramCore/Network.swift index 8767d35495..900e540888 100644 --- a/submodules/TelegramCore/TelegramCore/Network.swift +++ b/submodules/TelegramCore/TelegramCore/Network.swift @@ -16,6 +16,7 @@ import Foundation import CloudData #endif +import SyncCore import EncryptionProvider public enum ConnectionStatus: Equatable { diff --git a/submodules/TelegramCore/TelegramCore/NetworkSettings.swift b/submodules/TelegramCore/TelegramCore/NetworkSettings.swift index 59aa28f50a..b7e543c0bc 100644 --- a/submodules/TelegramCore/TelegramCore/NetworkSettings.swift +++ b/submodules/TelegramCore/TelegramCore/NetworkSettings.swift @@ -13,49 +13,7 @@ import SwiftSignalKit #endif #endif -public struct NetworkSettings: PreferencesEntry, Equatable { - public var reducedBackupDiscoveryTimeout: Bool - public internal(set) var applicationUpdateUrlPrefix: String? - public var backupHostOverride: String? - - public static var defaultSettings: NetworkSettings { - return NetworkSettings(reducedBackupDiscoveryTimeout: false, applicationUpdateUrlPrefix: nil, backupHostOverride: nil) - } - - public init(reducedBackupDiscoveryTimeout: Bool, applicationUpdateUrlPrefix: String?, backupHostOverride: String?) { - self.reducedBackupDiscoveryTimeout = reducedBackupDiscoveryTimeout - self.applicationUpdateUrlPrefix = applicationUpdateUrlPrefix - self.backupHostOverride = backupHostOverride - } - - public init(decoder: PostboxDecoder) { - self.reducedBackupDiscoveryTimeout = decoder.decodeInt32ForKey("reducedBackupDiscoveryTimeout", orElse: 0) != 0 - self.applicationUpdateUrlPrefix = decoder.decodeOptionalStringForKey("applicationUpdateUrlPrefix") - self.backupHostOverride = decoder.decodeOptionalStringForKey("backupHostOverride") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.reducedBackupDiscoveryTimeout ? 1 : 0, forKey: "reducedBackupDiscoveryTimeout") - if let applicationUpdateUrlPrefix = self.applicationUpdateUrlPrefix { - encoder.encodeString(applicationUpdateUrlPrefix, forKey: "applicationUpdateUrlPrefix") - } else { - encoder.encodeNil(forKey: "applicationUpdateUrlPrefix") - } - if let backupHostOverride = self.backupHostOverride { - encoder.encodeString(backupHostOverride, forKey: "backupHostOverride") - } else { - encoder.encodeNil(forKey: "backupHostOverride") - } - } - - public func isEqual(to: PreferencesEntry) -> Bool { - guard let to = to as? NetworkSettings else { - return false - } - - return self == to - } -} +import SyncCore public func updateNetworkSettingsInteractively(postbox: Postbox, network: Network, _ f: @escaping (NetworkSettings) -> NetworkSettings) -> Signal { return postbox.transaction { transaction -> Void in diff --git a/submodules/TelegramCore/TelegramCore/NotificationExceptionsList.swift b/submodules/TelegramCore/TelegramCore/NotificationExceptionsList.swift index bbb301cc3c..46742dc7f8 100644 --- a/submodules/TelegramCore/TelegramCore/NotificationExceptionsList.swift +++ b/submodules/TelegramCore/TelegramCore/NotificationExceptionsList.swift @@ -9,6 +9,8 @@ import Postbox import TelegramApi #endif +import SyncCore + public final class NotificationExceptionsList: Equatable { public let peers: [PeerId: Peer] public let settings: [PeerId: TelegramPeerNotificationSettings] diff --git a/submodules/TelegramCore/TelegramCore/OutgoingMessageWithChatContextResult.swift b/submodules/TelegramCore/TelegramCore/OutgoingMessageWithChatContextResult.swift index fcfcf3ccd5..7216745876 100644 --- a/submodules/TelegramCore/TelegramCore/OutgoingMessageWithChatContextResult.swift +++ b/submodules/TelegramCore/TelegramCore/OutgoingMessageWithChatContextResult.swift @@ -8,6 +8,8 @@ import Foundation import UIKit #endif +import SyncCore + private func aspectFitSize(_ size: CGSize, to: CGSize) -> CGSize { let scale = min(to.width / max(1.0, size.width), to.height / max(1.0, size.height)) return CGSize(width: floor(size.width * scale), height: floor(size.height * scale)) diff --git a/submodules/TelegramCore/TelegramCore/PeerAccessRestrictionInfo.swift b/submodules/TelegramCore/TelegramCore/PeerAccessRestrictionInfo.swift index 965146c0c9..e2bc4e985a 100644 --- a/submodules/TelegramCore/TelegramCore/PeerAccessRestrictionInfo.swift +++ b/submodules/TelegramCore/TelegramCore/PeerAccessRestrictionInfo.swift @@ -7,66 +7,7 @@ import Foundation import TelegramApi #endif -public final class RestrictionRule: PostboxCoding, Equatable { - public let platform: String - public let reason: String - public let text: String - - public init(platform: String, reason: String, text: String) { - self.platform = platform - self.reason = reason - self.text = text - } - - public init(decoder: PostboxDecoder) { - self.platform = decoder.decodeStringForKey("p", orElse: "all") - self.reason = decoder.decodeStringForKey("r", orElse: "") - self.text = decoder.decodeStringForKey("t", orElse: "") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.platform, forKey: "p") - encoder.encodeString(self.reason, forKey: "r") - encoder.encodeString(self.text, forKey: "t") - } - - public static func ==(lhs: RestrictionRule, rhs: RestrictionRule) -> Bool { - if lhs.platform != rhs.platform { - return false - } - if lhs.reason != rhs.reason { - return false - } - if lhs.text != rhs.text { - return false - } - return true - } -} - -public final class PeerAccessRestrictionInfo: PostboxCoding, Equatable { - public let rules: [RestrictionRule] - - init(rules: [RestrictionRule]) { - self.rules = rules - } - - public init(decoder: PostboxDecoder) { - if let value = decoder.decodeOptionalStringForKey("rsn") { - self.rules = [RestrictionRule(platform: "all", reason: "", text: value)] - } else { - self.rules = decoder.decodeObjectArrayWithDecoderForKey("rs") - } - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeObjectArray(self.rules, forKey: "rs") - } - - public static func ==(lhs: PeerAccessRestrictionInfo, rhs: PeerAccessRestrictionInfo) -> Bool { - return lhs.rules == rhs.rules - } -} +import SyncCore extension RestrictionRule { convenience init(apiReason: Api.RestrictionReason) { diff --git a/submodules/TelegramCore/TelegramCore/PeerAdmins.swift b/submodules/TelegramCore/TelegramCore/PeerAdmins.swift index 51df9fd46d..1cb1ffee31 100644 --- a/submodules/TelegramCore/TelegramCore/PeerAdmins.swift +++ b/submodules/TelegramCore/TelegramCore/PeerAdmins.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public enum RemoveGroupAdminError { case generic } diff --git a/submodules/TelegramCore/TelegramCore/PeerCommands.swift b/submodules/TelegramCore/TelegramCore/PeerCommands.swift index 2c5f0dd6db..60e928dfb5 100644 --- a/submodules/TelegramCore/TelegramCore/PeerCommands.swift +++ b/submodules/TelegramCore/TelegramCore/PeerCommands.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public struct PeerCommand: Hashable { public let peer: Peer public let command: BotCommand diff --git a/submodules/TelegramCore/TelegramCore/PeerContactSettings.swift b/submodules/TelegramCore/TelegramCore/PeerContactSettings.swift index b19c391f17..a69cac1d6c 100644 --- a/submodules/TelegramCore/TelegramCore/PeerContactSettings.swift +++ b/submodules/TelegramCore/TelegramCore/PeerContactSettings.swift @@ -7,20 +7,7 @@ import Foundation import TelegramApi #endif -public struct PeerStatusSettings: OptionSet { - public var rawValue: Int32 - - public init(rawValue: Int32) { - self.rawValue = rawValue - } - - public static let canReport = PeerStatusSettings(rawValue: 1 << 1) - public static let canShareContact = PeerStatusSettings(rawValue: 1 << 2) - public static let canBlock = PeerStatusSettings(rawValue: 1 << 3) - public static let canAddContact = PeerStatusSettings(rawValue: 1 << 4) - public static let addExceptionWhenAddingContact = PeerStatusSettings(rawValue: 1 << 5) - public static let canReportIrrelevantGeoLocation = PeerStatusSettings(rawValue: 1 << 6) -} +import SyncCore extension PeerStatusSettings { init(apiSettings: Api.PeerSettings) { diff --git a/submodules/TelegramCore/TelegramCore/PeerLiveLocationsContext.swift b/submodules/TelegramCore/TelegramCore/PeerLiveLocationsContext.swift index b97cd7cbd2..5f37477a14 100644 --- a/submodules/TelegramCore/TelegramCore/PeerLiveLocationsContext.swift +++ b/submodules/TelegramCore/TelegramCore/PeerLiveLocationsContext.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public func topPeerActiveLiveLocationMessages(viewTracker: AccountViewTracker, accountPeerId: PeerId, peerId: PeerId) -> Signal<(Peer?, [Message]), NoError> { return viewTracker.aroundMessageHistoryViewForLocation(.peer(peerId), index: .upperBound, anchorIndex: .upperBound, count: 50, fixedCombinedReadStates: nil, tagMask: .liveLocation, orderStatistics: [], additionalData: [.peer(accountPeerId)]) |> map { (view, _, _) -> (Peer?, [Message]) in diff --git a/submodules/TelegramCore/TelegramCore/PeerParticipants.swift b/submodules/TelegramCore/TelegramCore/PeerParticipants.swift index 2d1c399859..7587d8acbc 100644 --- a/submodules/TelegramCore/TelegramCore/PeerParticipants.swift +++ b/submodules/TelegramCore/TelegramCore/PeerParticipants.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + private struct PeerParticipants: Equatable { let peers: [Peer] diff --git a/submodules/TelegramCore/TelegramCore/PeerPhotoUpdater.swift b/submodules/TelegramCore/TelegramCore/PeerPhotoUpdater.swift index 05e1223a90..862a79b9f4 100644 --- a/submodules/TelegramCore/TelegramCore/PeerPhotoUpdater.swift +++ b/submodules/TelegramCore/TelegramCore/PeerPhotoUpdater.swift @@ -16,6 +16,8 @@ import Foundation import UIKit #endif +import SyncCore + public enum UpdatePeerPhotoStatus { case progress(Float) case complete([TelegramMediaImageRepresentation]) diff --git a/submodules/TelegramCore/TelegramCore/PeerSpecificStickerPack.swift b/submodules/TelegramCore/TelegramCore/PeerSpecificStickerPack.swift index d97a84fffb..cd3981f6ed 100644 --- a/submodules/TelegramCore/TelegramCore/PeerSpecificStickerPack.swift +++ b/submodules/TelegramCore/TelegramCore/PeerSpecificStickerPack.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + private struct WrappedStickerPackCollectionInfo: Equatable { let info: StickerPackCollectionInfo? diff --git a/submodules/TelegramCore/TelegramCore/PeerUtils.swift b/submodules/TelegramCore/TelegramCore/PeerUtils.swift index ae95b69fe0..8d25fba940 100644 --- a/submodules/TelegramCore/TelegramCore/PeerUtils.swift +++ b/submodules/TelegramCore/TelegramCore/PeerUtils.swift @@ -5,6 +5,8 @@ import PostboxMac import Postbox #endif +import SyncCore + public extension Peer { var debugDisplayTitle: String { switch self { diff --git a/submodules/TelegramCore/TelegramCore/PeersNearby.swift b/submodules/TelegramCore/TelegramCore/PeersNearby.swift index 66498671bc..2b3899decd 100644 --- a/submodules/TelegramCore/TelegramCore/PeersNearby.swift +++ b/submodules/TelegramCore/TelegramCore/PeersNearby.swift @@ -9,6 +9,8 @@ import Postbox import TelegramApi #endif +import SyncCore + #if os(macOS) private typealias SignalKitTimer = SwiftSignalKitMac.Timer #else diff --git a/submodules/TelegramCore/TelegramCore/PendingMessageManager.swift b/submodules/TelegramCore/TelegramCore/PendingMessageManager.swift index 0059a66ffd..039ab9f9ec 100644 --- a/submodules/TelegramCore/TelegramCore/PendingMessageManager.swift +++ b/submodules/TelegramCore/TelegramCore/PendingMessageManager.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public struct PendingMessageStatus: Equatable { public let isRunning: Bool public let progress: Float diff --git a/submodules/TelegramCore/TelegramCore/PendingMessageUploadedContent.swift b/submodules/TelegramCore/TelegramCore/PendingMessageUploadedContent.swift index 0b7d6dc4e2..c5ec3c1bde 100644 --- a/submodules/TelegramCore/TelegramCore/PendingMessageUploadedContent.swift +++ b/submodules/TelegramCore/TelegramCore/PendingMessageUploadedContent.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + enum PendingMessageUploadedContent { case text(String) case media(Api.InputMedia, String) diff --git a/submodules/TelegramCore/TelegramCore/Polls.swift b/submodules/TelegramCore/TelegramCore/Polls.swift index 4f4cba801a..b23ba9fb47 100644 --- a/submodules/TelegramCore/TelegramCore/Polls.swift +++ b/submodules/TelegramCore/TelegramCore/Polls.swift @@ -15,6 +15,8 @@ import SwiftSignalKit #endif #endif +import SyncCore + public enum RequestMessageSelectPollOptionError { case generic } diff --git a/submodules/TelegramCore/TelegramCore/PrivacySettings.swift b/submodules/TelegramCore/TelegramCore/PrivacySettings.swift index e313ecf68a..da5fc00f11 100644 --- a/submodules/TelegramCore/TelegramCore/PrivacySettings.swift +++ b/submodules/TelegramCore/TelegramCore/PrivacySettings.swift @@ -7,6 +7,8 @@ import Foundation import TelegramApi #endif +import SyncCore + public final class SelectivePrivacyPeer: Equatable { public let peer: Peer public let participantCount: Int32? diff --git a/submodules/TelegramCore/TelegramCore/ProcessRemovedMedia.swift b/submodules/TelegramCore/TelegramCore/ProcessRemovedMedia.swift index fdeacf55fa..27b81e6f62 100644 --- a/submodules/TelegramCore/TelegramCore/ProcessRemovedMedia.swift +++ b/submodules/TelegramCore/TelegramCore/ProcessRemovedMedia.swift @@ -5,6 +5,8 @@ import PostboxMac import Postbox #endif +import SyncCore + func processRemovedMedia(_ mediaBox: MediaBox, _ media: Media) { if let image = media as? TelegramMediaImage { let _ = mediaBox.removeCachedResources(Set(image.representations.map({ WrappedMediaResourceId($0.resource.id) }))).start() diff --git a/submodules/TelegramCore/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift b/submodules/TelegramCore/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift index 049a2da46e..6465900ea8 100644 --- a/submodules/TelegramCore/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift @@ -8,6 +8,7 @@ import Foundation import TelegramApi #endif +import SyncCore import EncryptionProvider private enum MessageParsingError: Error { diff --git a/submodules/TelegramCore/TelegramCore/ProcessSecretChatIncomingEncryptedOperations.swift b/submodules/TelegramCore/TelegramCore/ProcessSecretChatIncomingEncryptedOperations.swift index 729ee6f098..e97d4c7eb4 100644 --- a/submodules/TelegramCore/TelegramCore/ProcessSecretChatIncomingEncryptedOperations.swift +++ b/submodules/TelegramCore/TelegramCore/ProcessSecretChatIncomingEncryptedOperations.swift @@ -7,6 +7,8 @@ import Foundation import TelegramApi #endif +import SyncCore + private enum MessagePreParsingError: Error { case invalidChatState case malformedData diff --git a/submodules/TelegramCore/TelegramCore/ProxyServersStatuses.swift b/submodules/TelegramCore/TelegramCore/ProxyServersStatuses.swift index 3662863252..24ac494c28 100644 --- a/submodules/TelegramCore/TelegramCore/ProxyServersStatuses.swift +++ b/submodules/TelegramCore/TelegramCore/ProxyServersStatuses.swift @@ -11,6 +11,8 @@ import Foundation #endif #endif +import SyncCore + public enum ProxyServerStatus: Equatable { case checking case notAvailable diff --git a/submodules/TelegramCore/TelegramCore/ProxySettings.swift b/submodules/TelegramCore/TelegramCore/ProxySettings.swift index f16020db46..d1498bb0ad 100644 --- a/submodules/TelegramCore/TelegramCore/ProxySettings.swift +++ b/submodules/TelegramCore/TelegramCore/ProxySettings.swift @@ -6,146 +6,10 @@ import Foundation #else import Postbox import SwiftSignalKit - #if BUCK - import MtProtoKit - #else - import MtProtoKitDynamic - #endif + import MtProtoKit #endif -public enum ProxyServerConnection: Equatable, Hashable, PostboxCoding { - case socks5(username: String?, password: String?) - case mtp(secret: Data) - - public init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("_t", orElse: 0) { - case 0: - self = .socks5(username: decoder.decodeOptionalStringForKey("username"), password: decoder.decodeOptionalStringForKey("password")) - case 1: - self = .mtp(secret: decoder.decodeBytesForKey("secret")?.makeData() ?? Data()) - default: - self = .socks5(username: nil, password: nil) - } - } - - public func encode(_ encoder: PostboxEncoder) { - switch self { - case let .socks5(username, password): - encoder.encodeInt32(0, forKey: "_t") - if let username = username { - encoder.encodeString(username, forKey: "username") - } else { - encoder.encodeNil(forKey: "username") - } - if let password = password { - encoder.encodeString(password, forKey: "password") - } else { - encoder.encodeNil(forKey: "password") - } - case let .mtp(secret): - encoder.encodeInt32(1, forKey: "_t") - encoder.encodeBytes(MemoryBuffer(data: secret), forKey: "secret") - } - } -} - -public struct ProxyServerSettings: PostboxCoding, Equatable, Hashable { - public let host: String - public let port: Int32 - public let connection: ProxyServerConnection - - public init(host: String, port: Int32, connection: ProxyServerConnection) { - self.host = host - self.port = port - self.connection = connection - } - - public init(decoder: PostboxDecoder) { - self.host = decoder.decodeStringForKey("host", orElse: "") - self.port = decoder.decodeInt32ForKey("port", orElse: 0) - if let username = decoder.decodeOptionalStringForKey("username") { - self.connection = .socks5(username: username, password: decoder.decodeOptionalStringForKey("password")) - } else { - self.connection = decoder.decodeObjectForKey("connection", decoder: ProxyServerConnection.init(decoder:)) as? ProxyServerConnection ?? ProxyServerConnection.socks5(username: nil, password: nil) - } - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.host, forKey: "host") - encoder.encodeInt32(self.port, forKey: "port") - encoder.encodeObject(self.connection, forKey: "connection") - } - - public var hashValue: Int { - var hash = self.host.hashValue - hash = hash &* 31 &+ self.port.hashValue - hash = hash &* 31 &+ self.connection.hashValue - return hash - } -} - -public struct ProxySettings: PreferencesEntry, Equatable { - public var enabled: Bool - public var servers: [ProxyServerSettings] - public var activeServer: ProxyServerSettings? - public var useForCalls: Bool - - public static var defaultSettings: ProxySettings { - return ProxySettings(enabled: false, servers: [], activeServer: nil, useForCalls: false) - } - - public init(enabled: Bool, servers: [ProxyServerSettings], activeServer: ProxyServerSettings?, useForCalls: Bool) { - self.enabled = enabled - self.servers = servers - self.activeServer = activeServer - self.useForCalls = useForCalls - } - - public init(decoder: PostboxDecoder) { - if let _ = decoder.decodeOptionalStringForKey("host") { - let legacyServer = ProxyServerSettings(decoder: decoder) - if !legacyServer.host.isEmpty && legacyServer.port != 0 { - self.enabled = true - self.servers = [legacyServer] - } else { - self.enabled = false - self.servers = [] - } - } else { - self.enabled = decoder.decodeInt32ForKey("enabled", orElse: 0) != 0 - self.servers = decoder.decodeObjectArrayWithDecoderForKey("servers") - } - self.activeServer = decoder.decodeObjectForKey("activeServer", decoder: ProxyServerSettings.init(decoder:)) as? ProxyServerSettings - self.useForCalls = decoder.decodeInt32ForKey("useForCalls", orElse: 0) != 0 - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.enabled ? 1 : 0, forKey: "enabled") - encoder.encodeObjectArray(self.servers, forKey: "servers") - if let activeServer = self.activeServer { - encoder.encodeObject(activeServer, forKey: "activeServer") - } else { - encoder.encodeNil(forKey: "activeServer") - } - encoder.encodeInt32(self.useForCalls ? 1 : 0, forKey: "useForCalls") - } - - public func isEqual(to: PreferencesEntry) -> Bool { - guard let to = to as? ProxySettings else { - return false - } - - return self == to - } - - public var effectiveActiveServer: ProxyServerSettings? { - if self.enabled, let activeServer = self.activeServer { - return activeServer - } else { - return nil - } - } -} +import SyncCore public func updateProxySettingsInteractively(accountManager: AccountManager, _ f: @escaping (ProxySettings) -> ProxySettings) -> Signal { return accountManager.transaction { transaction -> Void in diff --git a/submodules/TelegramCore/TelegramCore/ReactionsMessageAttribute.swift b/submodules/TelegramCore/TelegramCore/ReactionsMessageAttribute.swift index ce3ab1104c..c70a20b726 100644 --- a/submodules/TelegramCore/TelegramCore/ReactionsMessageAttribute.swift +++ b/submodules/TelegramCore/TelegramCore/ReactionsMessageAttribute.swift @@ -7,45 +7,9 @@ import Postbox import TelegramApi #endif -public struct MessageReaction: Equatable, PostboxCoding { - public var value: String - public var count: Int32 - public var isSelected: Bool - - public init(value: String, count: Int32, isSelected: Bool) { - self.value = value - self.count = count - self.isSelected = isSelected - } - - public init(decoder: PostboxDecoder) { - self.value = decoder.decodeStringForKey("v", orElse: "") - self.count = decoder.decodeInt32ForKey("c", orElse: 0) - self.isSelected = decoder.decodeInt32ForKey("s", orElse: 0) != 0 - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.value, forKey: "v") - encoder.encodeInt32(self.count, forKey: "c") - encoder.encodeInt32(self.isSelected ? 1 : 0, forKey: "s") - } -} +import SyncCore -public final class ReactionsMessageAttribute: MessageAttribute { - public let reactions: [MessageReaction] - - init(reactions: [MessageReaction]) { - self.reactions = reactions - } - - required public init(decoder: PostboxDecoder) { - self.reactions = decoder.decodeObjectArrayWithDecoderForKey("r") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeObjectArray(self.reactions, forKey: "r") - } - +extension ReactionsMessageAttribute { /*func withUpdatedResults(_ reactions: Api.MessageReactions) -> ReactionsMessageAttribute { switch reactions { case let .messageReactions(flags, results): @@ -127,26 +91,6 @@ public func mergedMessageReactions(attributes: [MessageAttribute]) -> ReactionsM } } -public final class PendingReactionsMessageAttribute: MessageAttribute { - public let value: String? - - init(value: String?) { - self.value = value - } - - required public init(decoder: PostboxDecoder) { - self.value = decoder.decodeOptionalStringForKey("v") - } - - public func encode(_ encoder: PostboxEncoder) { - if let value = self.value { - encoder.encodeString(value, forKey: "v") - } else { - encoder.encodeNil(forKey: "v") - } - } -} - /*extension ReactionsMessageAttribute { convenience init(apiReactions: Api.MessageReactions) { switch apiReactions { diff --git a/submodules/TelegramCore/TelegramCore/RecentPeers.swift b/submodules/TelegramCore/TelegramCore/RecentPeers.swift index f7ef9467b1..3fe5226d85 100644 --- a/submodules/TelegramCore/TelegramCore/RecentPeers.swift +++ b/submodules/TelegramCore/TelegramCore/RecentPeers.swift @@ -9,36 +9,13 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public enum RecentPeers { case peers([Peer]) case disabled } -final class CachedRecentPeers: PostboxCoding { - let enabled: Bool - let ids: [PeerId] - - init(enabled: Bool, ids: [PeerId]) { - self.enabled = enabled - self.ids = ids - } - - init(decoder: PostboxDecoder) { - self.enabled = decoder.decodeInt32ForKey("enabled", orElse: 0) != 0 - self.ids = decoder.decodeInt64ArrayForKey("ids").map(PeerId.init) - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.enabled ? 1 : 0, forKey: "enabled") - encoder.encodeInt64Array(self.ids.map({ $0.toInt64() }), forKey: "ids") - } - - static func cacheKey() -> ValueBoxKey { - let key = ValueBoxKey(length: 0) - return key - } -} - private let collectionSpec = ItemCacheCollectionSpec(lowWaterItemCount: 1, highWaterItemCount: 1) private func cachedRecentPeersEntryId() -> ItemCacheEntryId { diff --git a/submodules/TelegramCore/TelegramCore/RecentWebSessions.swift b/submodules/TelegramCore/TelegramCore/RecentWebSessions.swift index 25298d4bab..8a6b7bb0a6 100644 --- a/submodules/TelegramCore/TelegramCore/RecentWebSessions.swift +++ b/submodules/TelegramCore/TelegramCore/RecentWebSessions.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public struct WebAuthorization : Equatable { public let hash: Int64 public let botId: PeerId diff --git a/submodules/TelegramCore/TelegramCore/RecentlySearchedPeerIds.swift b/submodules/TelegramCore/TelegramCore/RecentlySearchedPeerIds.swift index 8161f39563..084d01d6d0 100644 --- a/submodules/TelegramCore/TelegramCore/RecentlySearchedPeerIds.swift +++ b/submodules/TelegramCore/TelegramCore/RecentlySearchedPeerIds.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public func addRecentlySearchedPeer(postbox: Postbox, peerId: PeerId) -> Signal { return postbox.transaction { transaction -> Void in transaction.addOrMoveToFirstPositionOrderedItemListItem(collectionId: Namespaces.OrderedItemList.RecentlySearchedPeerIds, item: OrderedItemListEntry(id: RecentPeerItemId(peerId).rawValue, contents: RecentPeerItem(rating: 0.0)), removeTailIfCountExceeds: 20) diff --git a/submodules/TelegramCore/TelegramCore/RecentlyUsedHashtags.swift b/submodules/TelegramCore/TelegramCore/RecentlyUsedHashtags.swift index 4e21bf102c..04a7d8c981 100644 --- a/submodules/TelegramCore/TelegramCore/RecentlyUsedHashtags.swift +++ b/submodules/TelegramCore/TelegramCore/RecentlyUsedHashtags.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + private struct RecentHashtagItemId { public let rawValue: MemoryBuffer @@ -27,17 +29,6 @@ private struct RecentHashtagItemId { } } -final class RecentHashtagItem: OrderedItemListEntryContents { - init() { - } - - public init(decoder: PostboxDecoder) { - } - - public func encode(_ encoder: PostboxEncoder) { - } -} - func addRecentlyUsedHashtag(transaction: Transaction, string: String) { if let itemId = RecentHashtagItemId(string) { transaction.addOrMoveToFirstPositionOrderedItemListItem(collectionId: Namespaces.OrderedItemList.RecentlyUsedHashtags, item: OrderedItemListEntry(id: itemId.rawValue, contents: RecentHashtagItem()), removeTailIfCountExceeds: 100) diff --git a/submodules/TelegramCore/TelegramCore/RegisterNotificationToken.swift b/submodules/TelegramCore/TelegramCore/RegisterNotificationToken.swift index 1975810603..a317b93a8f 100644 --- a/submodules/TelegramCore/TelegramCore/RegisterNotificationToken.swift +++ b/submodules/TelegramCore/TelegramCore/RegisterNotificationToken.swift @@ -9,6 +9,8 @@ import Postbox import TelegramApi #endif +import SyncCore + public enum NotificationTokenType { case aps(encrypt: Bool) case voip diff --git a/submodules/TelegramCore/TelegramCore/RemoteStorageConfiguration.swift b/submodules/TelegramCore/TelegramCore/RemoteStorageConfiguration.swift index 63b3210a50..316835b6c7 100644 --- a/submodules/TelegramCore/TelegramCore/RemoteStorageConfiguration.swift +++ b/submodules/TelegramCore/TelegramCore/RemoteStorageConfiguration.swift @@ -7,31 +7,7 @@ import Postbox import SwiftSignalKit #endif -public final class RemoteStorageConfiguration: PreferencesEntry { - public let webDocumentsHostDatacenterId: Int32 - - init(webDocumentsHostDatacenterId: Int32) { - self.webDocumentsHostDatacenterId = webDocumentsHostDatacenterId - } - - public init(decoder: PostboxDecoder) { - self.webDocumentsHostDatacenterId = decoder.decodeInt32ForKey("webDocumentsHostDatacenterId", orElse: 4) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.webDocumentsHostDatacenterId, forKey: "webDocumentsHostDatacenterId") - } - - public func isEqual(to: PreferencesEntry) -> Bool { - guard let to = to as? RemoteStorageConfiguration else { - return false - } - if self.webDocumentsHostDatacenterId != to.webDocumentsHostDatacenterId { - return false - } - return true - } -} +import SyncCore public func currentWebDocumentsHostDatacenterId(postbox: Postbox, isTestingEnvironment: Bool) -> Signal { return postbox.transaction { transaction -> Int32 in diff --git a/submodules/TelegramCore/TelegramCore/RemovePeerChat.swift b/submodules/TelegramCore/TelegramCore/RemovePeerChat.swift index d0425ea25a..ae7d7f0a7b 100644 --- a/submodules/TelegramCore/TelegramCore/RemovePeerChat.swift +++ b/submodules/TelegramCore/TelegramCore/RemovePeerChat.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public func removePeerChat(account: Account, peerId: PeerId, reportChatSpam: Bool, deleteGloballyIfPossible: Bool = false) -> Signal { return account.postbox.transaction { transaction -> Void in removePeerChat(account: account, transaction: transaction, mediaBox: account.postbox.mediaBox, peerId: peerId, reportChatSpam: reportChatSpam, deleteGloballyIfPossible: deleteGloballyIfPossible) diff --git a/submodules/TelegramCore/TelegramCore/RemovePeerMember.swift b/submodules/TelegramCore/TelegramCore/RemovePeerMember.swift index f084a7e1af..b92aa69288 100644 --- a/submodules/TelegramCore/TelegramCore/RemovePeerMember.swift +++ b/submodules/TelegramCore/TelegramCore/RemovePeerMember.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public func removePeerMember(account: Account, peerId: PeerId, memberId: PeerId) -> Signal { if peerId.namespace == Namespaces.Peer.CloudChannel { return updateChannelMemberBannedRights(account: account, peerId: peerId, memberId: memberId, rights: TelegramChatBannedRights(flags: [.banReadMessages], untilDate: 0)) diff --git a/submodules/TelegramCore/TelegramCore/ReplyMarkupMessageAttribute.swift b/submodules/TelegramCore/TelegramCore/ReplyMarkupMessageAttribute.swift index 20c3ca2bcb..11300d8922 100644 --- a/submodules/TelegramCore/TelegramCore/ReplyMarkupMessageAttribute.swift +++ b/submodules/TelegramCore/TelegramCore/ReplyMarkupMessageAttribute.swift @@ -7,165 +7,7 @@ import Foundation import TelegramApi #endif -public enum ReplyMarkupButtonAction: PostboxCoding, Equatable { - case text - case url(String) - case callback(MemoryBuffer) - case requestPhone - case requestMap - case switchInline(samePeer: Bool, query: String) - case openWebApp - case payment - case urlAuth(url: String, buttonId: Int32) - - public init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("v", orElse: 0) { - case 0: - self = .text - case 1: - self = .url(decoder.decodeStringForKey("u", orElse: "")) - case 2: - self = .callback(decoder.decodeBytesForKey("d") ?? MemoryBuffer()) - case 3: - self = .requestPhone - case 4: - self = .requestMap - case 5: - self = .switchInline(samePeer: decoder.decodeInt32ForKey("s", orElse: 0) != 0, query: decoder.decodeStringForKey("q", orElse: "")) - case 6: - self = .openWebApp - case 7: - self = .payment - case 8: - self = .urlAuth(url: decoder.decodeStringForKey("u", orElse: ""), buttonId: decoder.decodeInt32ForKey("b", orElse: 0)) - default: - self = .text - } - } - - public func encode(_ encoder: PostboxEncoder) { - switch self { - case .text: - encoder.encodeInt32(0, forKey: "v") - case let .url(url): - encoder.encodeInt32(1, forKey: "v") - encoder.encodeString(url, forKey: "u") - case let .callback(data): - encoder.encodeInt32(2, forKey: "v") - encoder.encodeBytes(data, forKey: "d") - case .requestPhone: - encoder.encodeInt32(3, forKey: "v") - case .requestMap: - encoder.encodeInt32(4, forKey: "v") - case let .switchInline(samePeer, query): - encoder.encodeInt32(5, forKey: "v") - encoder.encodeInt32(samePeer ? 1 : 0, forKey: "s") - encoder.encodeString(query, forKey: "q") - case .openWebApp: - encoder.encodeInt32(6, forKey: "v") - case .payment: - encoder.encodeInt32(7, forKey: "v") - case let .urlAuth(url, buttonId): - encoder.encodeInt32(8, forKey: "v") - encoder.encodeString(url, forKey: "u") - encoder.encodeInt32(buttonId, forKey: "b") - } - } -} - -public struct ReplyMarkupButton: PostboxCoding, Equatable { - public let title: String - public let titleWhenForwarded: String? - public let action: ReplyMarkupButtonAction - - public init(title: String, titleWhenForwarded: String?, action: ReplyMarkupButtonAction) { - self.title = title - self.titleWhenForwarded = titleWhenForwarded - self.action = action - } - - public init(decoder: PostboxDecoder) { - self.title = decoder.decodeStringForKey(".t", orElse: "") - self.titleWhenForwarded = decoder.decodeOptionalStringForKey(".tf") - self.action = ReplyMarkupButtonAction(decoder: decoder) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.title, forKey: ".t") - if let titleWhenForwarded = self.titleWhenForwarded { - encoder.encodeString(titleWhenForwarded, forKey: ".tf") - } else { - encoder.encodeNil(forKey: ".tf") - } - self.action.encode(encoder) - } - - public static func ==(lhs: ReplyMarkupButton, rhs: ReplyMarkupButton) -> Bool { - return lhs.title == rhs.title && lhs.action == rhs.action - } -} - -public struct ReplyMarkupRow: PostboxCoding, Equatable { - public let buttons: [ReplyMarkupButton] - - public init(buttons: [ReplyMarkupButton]) { - self.buttons = buttons - } - - public init(decoder: PostboxDecoder) { - self.buttons = decoder.decodeObjectArrayWithDecoderForKey("b") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeObjectArray(self.buttons, forKey: "b") - } - - public static func ==(lhs: ReplyMarkupRow, rhs: ReplyMarkupRow) -> Bool { - return lhs.buttons == rhs.buttons - } -} - -public struct ReplyMarkupMessageFlags: OptionSet { - public var rawValue: Int32 - - public init(rawValue: Int32) { - self.rawValue = rawValue - } - - public init() { - self.rawValue = 0 - } - - public static let once = ReplyMarkupMessageFlags(rawValue: 1 << 0) - public static let personal = ReplyMarkupMessageFlags(rawValue: 1 << 1) - public static let setupReply = ReplyMarkupMessageFlags(rawValue: 1 << 2) - public static let inline = ReplyMarkupMessageFlags(rawValue: 1 << 3) - public static let fit = ReplyMarkupMessageFlags(rawValue: 1 << 4) -} - -public class ReplyMarkupMessageAttribute: MessageAttribute, Equatable { - public let rows: [ReplyMarkupRow] - public let flags: ReplyMarkupMessageFlags - - init(rows: [ReplyMarkupRow], flags: ReplyMarkupMessageFlags) { - self.rows = rows - self.flags = flags - } - - public required init(decoder: PostboxDecoder) { - self.rows = decoder.decodeObjectArrayWithDecoderForKey("r") - self.flags = ReplyMarkupMessageFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0)) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeObjectArray(self.rows, forKey: "r") - encoder.encodeInt32(self.flags.rawValue, forKey: "f") - } - - public static func ==(lhs: ReplyMarkupMessageAttribute, rhs: ReplyMarkupMessageAttribute) -> Bool { - return lhs.flags == rhs.flags && lhs.rows == rhs.rows - } -} +import SyncCore extension ReplyMarkupButton { init(apiButton: Api.KeyboardButton) { diff --git a/submodules/TelegramCore/TelegramCore/ReportPeer.swift b/submodules/TelegramCore/TelegramCore/ReportPeer.swift index 42585d0420..d626351feb 100644 --- a/submodules/TelegramCore/TelegramCore/ReportPeer.swift +++ b/submodules/TelegramCore/TelegramCore/ReportPeer.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public func reportPeer(account: Account, peerId: PeerId) -> Signal { return account.postbox.transaction { transaction -> Signal in if let peer = transaction.getPeer(peerId) { diff --git a/submodules/TelegramCore/TelegramCore/RequestEditMessage.swift b/submodules/TelegramCore/TelegramCore/RequestEditMessage.swift index e929d7f5ae..4eeb177be4 100644 --- a/submodules/TelegramCore/TelegramCore/RequestEditMessage.swift +++ b/submodules/TelegramCore/TelegramCore/RequestEditMessage.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public enum RequestEditMessageMedia : Equatable { case keep case update(AnyMediaReference) diff --git a/submodules/TelegramCore/TelegramCore/RequestMessageActionCallback.swift b/submodules/TelegramCore/TelegramCore/RequestMessageActionCallback.swift index ae2a652f72..9625d12fde 100644 --- a/submodules/TelegramCore/TelegramCore/RequestMessageActionCallback.swift +++ b/submodules/TelegramCore/TelegramCore/RequestMessageActionCallback.swift @@ -15,6 +15,9 @@ import Foundation #endif #endif + +import SyncCore + public enum MessageActionCallbackResult { case none case alert(String) diff --git a/submodules/TelegramCore/TelegramCore/RequestSecureIdForm.swift b/submodules/TelegramCore/TelegramCore/RequestSecureIdForm.swift index a2e0e5c7f7..e29ec1197d 100644 --- a/submodules/TelegramCore/TelegramCore/RequestSecureIdForm.swift +++ b/submodules/TelegramCore/TelegramCore/RequestSecureIdForm.swift @@ -15,6 +15,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public enum RequestSecureIdFormError { case generic case serverError(String) diff --git a/submodules/TelegramCore/TelegramCore/RequestStartBot.swift b/submodules/TelegramCore/TelegramCore/RequestStartBot.swift index 6f98e03733..8a514808ab 100644 --- a/submodules/TelegramCore/TelegramCore/RequestStartBot.swift +++ b/submodules/TelegramCore/TelegramCore/RequestStartBot.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public func requestStartBot(account: Account, botPeerId: PeerId, payload: String?) -> Signal { if let payload = payload, !payload.isEmpty { return account.postbox.loadedPeerWithId(botPeerId) diff --git a/submodules/TelegramCore/TelegramCore/RequestUserPhotos.swift b/submodules/TelegramCore/TelegramCore/RequestUserPhotos.swift index 1d7b9f3b3f..8aa3ab5618 100644 --- a/submodules/TelegramCore/TelegramCore/RequestUserPhotos.swift +++ b/submodules/TelegramCore/TelegramCore/RequestUserPhotos.swift @@ -16,6 +16,8 @@ import Foundation #endif #endif +import SyncCore + public struct TelegramPeerPhoto { public let image: TelegramMediaImage public let date: Int32 diff --git a/submodules/TelegramCore/TelegramCore/ResolvePeerByName.swift b/submodules/TelegramCore/TelegramCore/ResolvePeerByName.swift index b8eb899e5a..ac9851b251 100644 --- a/submodules/TelegramCore/TelegramCore/ResolvePeerByName.swift +++ b/submodules/TelegramCore/TelegramCore/ResolvePeerByName.swift @@ -9,46 +9,7 @@ import Foundation import SwiftSignalKit #endif -final class CachedResolvedByNamePeer: PostboxCoding { - let peerId: PeerId? - let timestamp: Int32 - - static func key(name: String) -> ValueBoxKey { - let key: ValueBoxKey - if let nameData = name.data(using: .utf8) { - key = ValueBoxKey(length: nameData.count) - nameData.withUnsafeBytes { (bytes: UnsafePointer) -> Void in - memcpy(key.memory, bytes, nameData.count) - } - } else { - key = ValueBoxKey(length: 0) - } - return key - } - - init(peerId: PeerId?, timestamp: Int32) { - self.peerId = peerId - self.timestamp = timestamp - } - - init(decoder: PostboxDecoder) { - if let peerId = decoder.decodeOptionalInt64ForKey("p") { - self.peerId = PeerId(peerId) - } else { - self.peerId = nil - } - self.timestamp = decoder.decodeInt32ForKey("t", orElse: 0) - } - - func encode(_ encoder: PostboxEncoder) { - if let peerId = self.peerId { - encoder.encodeInt64(peerId.toInt64(), forKey: "p") - } else { - encoder.encodeNil(forKey: "p") - } - encoder.encodeInt32(self.timestamp, forKey: "t") - } -} +import SyncCore private let resolvedByNamePeersCollectionSpec = ItemCacheCollectionSpec(lowWaterItemCount: 150, highWaterItemCount: 200) diff --git a/submodules/TelegramCore/TelegramCore/RichText.swift b/submodules/TelegramCore/TelegramCore/RichText.swift index 1ceaa7808b..af86168ec9 100644 --- a/submodules/TelegramCore/TelegramCore/RichText.swift +++ b/submodules/TelegramCore/TelegramCore/RichText.swift @@ -8,298 +8,7 @@ import Foundation import TelegramApi #endif -private enum RichTextTypes: Int32 { - case empty = 0 - case plain = 1 - case bold = 2 - case italic = 3 - case underline = 4 - case strikethrough = 5 - case fixed = 6 - case url = 7 - case email = 8 - case concat = 9 - case `subscript` = 10 - case superscript = 11 - case marked = 12 - case phone = 13 - case image = 14 - case anchor = 15 -} - -public indirect enum RichText: PostboxCoding, Equatable { - case empty - case plain(String) - case bold(RichText) - case italic(RichText) - case underline(RichText) - case strikethrough(RichText) - case fixed(RichText) - case url(text: RichText, url: String, webpageId: MediaId?) - case email(text: RichText, email: String) - case concat([RichText]) - case `subscript`(RichText) - case superscript(RichText) - case marked(RichText) - case phone(text: RichText, phone: String) - case image(id: MediaId, dimensions: CGSize) - case anchor(text: RichText, name: String) - - public init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("r", orElse: 0) { - case RichTextTypes.empty.rawValue: - self = .empty - case RichTextTypes.plain.rawValue: - self = .plain(decoder.decodeStringForKey("s", orElse: "")) - case RichTextTypes.bold.rawValue: - self = .bold(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) - case RichTextTypes.italic.rawValue: - self = .italic(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) - case RichTextTypes.underline.rawValue: - self = .underline(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) - case RichTextTypes.strikethrough.rawValue: - self = .strikethrough(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) - case RichTextTypes.fixed.rawValue: - self = .fixed(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) - case RichTextTypes.url.rawValue: - let webpageIdNamespace: Int32? = decoder.decodeOptionalInt32ForKey("w.n") - let webpageIdId: Int64? = decoder.decodeOptionalInt64ForKey("w.i") - var webpageId: MediaId? - if let webpageIdNamespace = webpageIdNamespace, let webpageIdId = webpageIdId { - webpageId = MediaId(namespace: webpageIdNamespace, id: webpageIdId) - } - self = .url(text: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, url: decoder.decodeStringForKey("u", orElse: ""), webpageId: webpageId) - case RichTextTypes.email.rawValue: - self = .email(text: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, email: decoder.decodeStringForKey("e", orElse: "")) - case RichTextTypes.concat.rawValue: - self = .concat(decoder.decodeObjectArrayWithDecoderForKey("a")) - case RichTextTypes.subscript.rawValue: - self = .subscript(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) - case RichTextTypes.superscript.rawValue: - self = .superscript(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) - case RichTextTypes.marked.rawValue: - self = .marked(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText) - case RichTextTypes.phone.rawValue: - self = .phone(text: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, phone: decoder.decodeStringForKey("p", orElse: "")) - case RichTextTypes.image.rawValue: - self = .image(id: MediaId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)), dimensions: CGSize(width: CGFloat(decoder.decodeInt32ForKey("sw", orElse: 0)), height: CGFloat(decoder.decodeInt32ForKey("sh", orElse: 0)))) - case RichTextTypes.anchor.rawValue: - self = .anchor(text: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, name: decoder.decodeStringForKey("n", orElse: "")) - default: - self = .empty - } - } - - public func encode(_ encoder: PostboxEncoder) { - switch self { - case .empty: - encoder.encodeInt32(RichTextTypes.empty.rawValue, forKey: "r") - case let .plain(string): - encoder.encodeInt32(RichTextTypes.plain.rawValue, forKey: "r") - encoder.encodeString(string, forKey: "s") - case let .bold(text): - encoder.encodeInt32(RichTextTypes.bold.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - case let .italic(text): - encoder.encodeInt32(RichTextTypes.italic.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - case let .underline(text): - encoder.encodeInt32(RichTextTypes.underline.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - case let .strikethrough(text): - encoder.encodeInt32(RichTextTypes.strikethrough.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - case let .fixed(text): - encoder.encodeInt32(RichTextTypes.fixed.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - case let .url(text, url, webpageId): - encoder.encodeInt32(RichTextTypes.url.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - encoder.encodeString(url, forKey: "u") - if let webpageId = webpageId { - encoder.encodeInt32(webpageId.namespace, forKey: "w.n") - encoder.encodeInt64(webpageId.id, forKey: "w.i") - } else { - encoder.encodeNil(forKey: "w.n") - encoder.encodeNil(forKey: "w.i") - } - case let .email(text, email): - encoder.encodeInt32(RichTextTypes.email.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - encoder.encodeString(email, forKey: "e") - case let .concat(texts): - encoder.encodeInt32(RichTextTypes.concat.rawValue, forKey: "r") - encoder.encodeObjectArray(texts, forKey: "a") - case let .subscript(text): - encoder.encodeInt32(RichTextTypes.subscript.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - case let .superscript(text): - encoder.encodeInt32(RichTextTypes.superscript.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - case let .marked(text): - encoder.encodeInt32(RichTextTypes.marked.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - case let .phone(text, phone): - encoder.encodeInt32(RichTextTypes.phone.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - encoder.encodeString(phone, forKey: "p") - case let .image(id, dimensions): - encoder.encodeInt32(RichTextTypes.image.rawValue, forKey: "r") - encoder.encodeInt32(id.namespace, forKey: "i.n") - encoder.encodeInt64(id.id, forKey: "i.i") - encoder.encodeInt32(Int32(dimensions.width), forKey: "sw") - encoder.encodeInt32(Int32(dimensions.height), forKey: "sh") - case let .anchor(text, name): - encoder.encodeInt32(RichTextTypes.anchor.rawValue, forKey: "r") - encoder.encodeObject(text, forKey: "t") - encoder.encodeString(name, forKey: "n") - } - } - - public static func ==(lhs: RichText, rhs: RichText) -> Bool { - switch lhs { - case .empty: - if case .empty = rhs { - return true - } else { - return false - } - case let .plain(string): - if case .plain(string) = rhs { - return true - } else { - return false - } - case let .bold(text): - if case .bold(text) = rhs { - return true - } else { - return false - } - case let .italic(text): - if case .italic(text) = rhs { - return true - } else { - return false - } - case let .underline(text): - if case .underline(text) = rhs { - return true - } else { - return false - } - case let .strikethrough(text): - if case .strikethrough(text) = rhs { - return true - } else { - return false - } - case let .fixed(text): - if case .fixed(text) = rhs { - return true - } else { - return false - } - case let .url(lhsText, lhsUrl, lhsWebpageId): - if case let .url(rhsText, rhsUrl, rhsWebpageId) = rhs, lhsText == rhsText && lhsUrl == rhsUrl && lhsWebpageId == rhsWebpageId { - return true - } else { - return false - } - case let .email(text, email): - if case .email(text, email) = rhs { - return true - } else { - return false - } - case let .concat(lhsTexts): - if case let .concat(rhsTexts) = rhs, lhsTexts == rhsTexts { - return true - } else { - return false - } - case let .subscript(text): - if case .subscript(text) = rhs { - return true - } else { - return false - } - case let .superscript(text): - if case .superscript(text) = rhs { - return true - } else { - return false - } - case let .marked(text): - if case .marked(text) = rhs { - return true - } else { - return false - } - case let .phone(text, phone): - if case .phone(text, phone) = rhs { - return true - } else { - return false - } - case let .image(id, dimensions): - if case .image(id, dimensions) = rhs { - return true - } else { - return false - } - case let .anchor(text, name): - if case .anchor(text, name) = rhs { - return true - } else { - return false - } - } - } -} - -public extension RichText { - var plainText: String { - switch self { - case .empty: - return "" - case let .plain(string): - return string - case let .bold(text): - return text.plainText - case let .italic(text): - return text.plainText - case let .underline(text): - return text.plainText - case let .strikethrough(text): - return text.plainText - case let .fixed(text): - return text.plainText - case let .url(text, _, _): - return text.plainText - case let .email(text, _): - return text.plainText - case let .concat(texts): - var string = "" - for text in texts { - string += text.plainText - } - return string - case let .subscript(text): - return text.plainText - case let .superscript(text): - return text.plainText - case let .marked(text): - return text.plainText - case let .phone(text, _): - return text.plainText - case .image: - return "" - case let .anchor(text, _): - return text.plainText - } - } -} +import SyncCore extension RichText { init(apiText: Api.RichText) { diff --git a/submodules/TelegramCore/TelegramCore/SaveSecureIdValue.swift b/submodules/TelegramCore/TelegramCore/SaveSecureIdValue.swift index 78a4798a88..e2da085f46 100644 --- a/submodules/TelegramCore/TelegramCore/SaveSecureIdValue.swift +++ b/submodules/TelegramCore/TelegramCore/SaveSecureIdValue.swift @@ -15,6 +15,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public enum SaveSecureIdValueError { case generic case verificationRequired diff --git a/submodules/TelegramCore/TelegramCore/ScheduledMessages.swift b/submodules/TelegramCore/TelegramCore/ScheduledMessages.swift index cabdc9f19d..f89da8a6c0 100644 --- a/submodules/TelegramCore/TelegramCore/ScheduledMessages.swift +++ b/submodules/TelegramCore/TelegramCore/ScheduledMessages.swift @@ -9,24 +9,7 @@ import Foundation import TelegramApi #endif -final class SendScheduledMessageImmediatelyAction: PendingMessageActionData { - init() { - } - - init(decoder: PostboxDecoder) { - } - - func encode(_ encoder: PostboxEncoder) { - } - - func isEqual(to: PendingMessageActionData) -> Bool { - if let _ = to as? SendScheduledMessageImmediatelyAction { - return true - } else { - return false - } - } -} +import SyncCore public func sendScheduledMessageNowInteractively(postbox: Postbox, messageId: MessageId) -> Signal { return postbox.transaction { transaction -> Void in diff --git a/submodules/TelegramCore/TelegramCore/SearchGroupMembers.swift b/submodules/TelegramCore/TelegramCore/SearchGroupMembers.swift index ffe2ee997e..74ce58454d 100644 --- a/submodules/TelegramCore/TelegramCore/SearchGroupMembers.swift +++ b/submodules/TelegramCore/TelegramCore/SearchGroupMembers.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + private func searchLocalGroupMembers(postbox: Postbox, peerId: PeerId, query: String) -> Signal<[Peer], NoError> { return peerParticipants(postbox: postbox, id: peerId) |> map { peers -> [Peer] in diff --git a/submodules/TelegramCore/TelegramCore/SearchMessages.swift b/submodules/TelegramCore/TelegramCore/SearchMessages.swift index 2534c03b70..41b98ccbfc 100644 --- a/submodules/TelegramCore/TelegramCore/SearchMessages.swift +++ b/submodules/TelegramCore/TelegramCore/SearchMessages.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public enum SearchMessagesLocation: Equatable { case general case group(PeerGroupId) diff --git a/submodules/TelegramCore/TelegramCore/SearchPeers.swift b/submodules/TelegramCore/TelegramCore/SearchPeers.swift index f80ae494da..5248ee97ce 100644 --- a/submodules/TelegramCore/TelegramCore/SearchPeers.swift +++ b/submodules/TelegramCore/TelegramCore/SearchPeers.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public struct FoundPeer: Equatable { public let peer: Peer public let subscribers: Int32? diff --git a/submodules/TelegramCore/TelegramCore/SearchStickers.swift b/submodules/TelegramCore/TelegramCore/SearchStickers.swift index d6a19fa05f..c7f12c6dfa 100644 --- a/submodules/TelegramCore/TelegramCore/SearchStickers.swift +++ b/submodules/TelegramCore/TelegramCore/SearchStickers.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public final class FoundStickerItem: Equatable { public let file: TelegramMediaFile public let stringRepresentations: [String] @@ -49,31 +51,6 @@ extension Sequence { } } -final class CachedStickerQueryResult: PostboxCoding { - let items: [TelegramMediaFile] - let hash: Int32 - - init(items: [TelegramMediaFile], hash: Int32) { - self.items = items - self.hash = hash - } - - init(decoder: PostboxDecoder) { - self.items = decoder.decodeObjectArrayForKey("it").map { $0 as! TelegramMediaFile } - self.hash = decoder.decodeInt32ForKey("h", orElse: 0) - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeObjectArray(self.items, forKey: "it") - encoder.encodeInt32(self.hash, forKey: "h") - } - - static func cacheKey(_ query: String) -> ValueBoxKey { - let key = ValueBoxKey(query) - return key - } -} - private let collectionSpec = ItemCacheCollectionSpec(lowWaterItemCount: 100, highWaterItemCount: 200) public struct SearchStickersScope: OptionSet { diff --git a/submodules/TelegramCore/TelegramCore/SecretChatEncryption.swift b/submodules/TelegramCore/TelegramCore/SecretChatEncryption.swift index 5bce7d278c..4c20b69eb1 100644 --- a/submodules/TelegramCore/TelegramCore/SecretChatEncryption.swift +++ b/submodules/TelegramCore/TelegramCore/SecretChatEncryption.swift @@ -11,6 +11,8 @@ import Foundation #endif #endif +import SyncCore + private func messageKey(key: SecretChatKey, msgKey: UnsafeRawPointer, mode: SecretChatEncryptionMode) -> (aesKey: Data, aesIv: Data) { switch mode { case .v1: diff --git a/submodules/TelegramCore/TelegramCore/SecretChatEncryptionConfig.swift b/submodules/TelegramCore/TelegramCore/SecretChatEncryptionConfig.swift index 8b7144e7e7..e1337da0f7 100644 --- a/submodules/TelegramCore/TelegramCore/SecretChatEncryptionConfig.swift +++ b/submodules/TelegramCore/TelegramCore/SecretChatEncryptionConfig.swift @@ -8,36 +8,10 @@ import Foundation import Postbox import SwiftSignalKit import TelegramApi - #if BUCK - import MtProtoKit - #else - import MtProtoKitDynamic - #endif + import MtProtoKit #endif -public final class SecretChatEncryptionConfig: PostboxCoding { - let g: Int32 - let p: MemoryBuffer - let version: Int32 - - public init(g: Int32, p: MemoryBuffer, version: Int32) { - self.g = g - self.p = p - self.version = version - } - - public init(decoder: PostboxDecoder) { - self.g = decoder.decodeInt32ForKey("g", orElse: 0) - self.p = decoder.decodeBytesForKey("p")! - self.version = decoder.decodeInt32ForKey("v", orElse: 0) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.g, forKey: "g") - encoder.encodeBytes(self.p, forKey: "p") - encoder.encodeInt32(self.version, forKey: "v") - } -} +import SyncCore func validatedEncryptionConfig(postbox: Postbox, network: Network) -> Signal { return network.request(Api.functions.messages.getDhConfig(version: 0, randomLength: 0)) diff --git a/submodules/TelegramCore/TelegramCore/SecretChatFileReference.swift b/submodules/TelegramCore/TelegramCore/SecretChatFileReference.swift index 7005c6456e..cf689a4d37 100644 --- a/submodules/TelegramCore/TelegramCore/SecretChatFileReference.swift +++ b/submodules/TelegramCore/TelegramCore/SecretChatFileReference.swift @@ -7,37 +7,7 @@ import Foundation import TelegramApi #endif -final class SecretChatFileReference: PostboxCoding { - let id: Int64 - let accessHash: Int64 - let size: Int32 - let datacenterId: Int32 - let keyFingerprint: Int32 - - init(id: Int64, accessHash: Int64, size: Int32, datacenterId: Int32, keyFingerprint: Int32) { - self.id = id - self.accessHash = accessHash - self.size = size - self.datacenterId = datacenterId - self.keyFingerprint = keyFingerprint - } - - init(decoder: PostboxDecoder) { - self.id = decoder.decodeInt64ForKey("i", orElse: 0) - self.accessHash = decoder.decodeInt64ForKey("a", orElse: 0) - self.size = decoder.decodeInt32ForKey("s", orElse: 0) - self.datacenterId = decoder.decodeInt32ForKey("d", orElse: 0) - self.keyFingerprint = decoder.decodeInt32ForKey("f", orElse: 0) - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt64(self.id, forKey: "i") - encoder.encodeInt64(self.accessHash, forKey: "a") - encoder.encodeInt32(self.size, forKey: "s") - encoder.encodeInt32(self.datacenterId, forKey: "d") - encoder.encodeInt32(self.keyFingerprint, forKey: "f") - } -} +import SyncCore extension SecretChatFileReference { convenience init?(_ file: Api.EncryptedFile) { diff --git a/submodules/TelegramCore/TelegramCore/SecretChatIncomingEncryptedOperation.swift b/submodules/TelegramCore/TelegramCore/SecretChatIncomingEncryptedOperation.swift index 3050554beb..796e485e1c 100644 --- a/submodules/TelegramCore/TelegramCore/SecretChatIncomingEncryptedOperation.swift +++ b/submodules/TelegramCore/TelegramCore/SecretChatIncomingEncryptedOperation.swift @@ -7,71 +7,7 @@ import Foundation import TelegramApi #endif -enum SecretChatIncomingEncryptedOperationType: Int32 { - case message - case service - - init(_ value: Int32) { - if value == 0 { - self = .message - } else { - self = .service - } - } - - var value: Int32 { - switch self { - case .message: - return 0 - case .service: - return 1 - } - } -} - -final class SecretChatIncomingEncryptedOperation: PostboxCoding { - let peerId: PeerId - let globallyUniqueId: Int64 - let timestamp: Int32 - let type: SecretChatIncomingEncryptedOperationType - let keyFingerprint: Int64 - let contents: MemoryBuffer - let mediaFileReference: SecretChatFileReference? - - init(peerId: PeerId, globallyUniqueId: Int64, timestamp: Int32, type: SecretChatIncomingEncryptedOperationType, keyFingerprint: Int64, contents: MemoryBuffer, mediaFileReference: SecretChatFileReference?) { - self.peerId = peerId - self.globallyUniqueId = globallyUniqueId - self.timestamp = timestamp - self.type = type - self.keyFingerprint = keyFingerprint - self.contents = contents - self.mediaFileReference = mediaFileReference - } - - init(decoder: PostboxDecoder) { - self.peerId = PeerId(decoder.decodeInt64ForKey("p", orElse: 0)) - self.globallyUniqueId = decoder.decodeInt64ForKey("u", orElse: 0) - self.timestamp = decoder.decodeInt32ForKey("t", orElse: 0) - self.type = SecretChatIncomingEncryptedOperationType(decoder.decodeInt32ForKey("k", orElse: 0)) - self.keyFingerprint = decoder.decodeInt64ForKey("f", orElse: 0) - self.contents = decoder.decodeBytesForKey("c")! - self.mediaFileReference = decoder.decodeObjectForKey("m", decoder: { SecretChatFileReference(decoder: $0) }) as? SecretChatFileReference - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt64(self.peerId.toInt64(), forKey: "p") - encoder.encodeInt64(self.globallyUniqueId, forKey: "u") - encoder.encodeInt32(self.timestamp, forKey: "t") - encoder.encodeInt32(self.type.value, forKey: "k") - encoder.encodeInt64(self.keyFingerprint, forKey: "f") - encoder.encodeBytes(self.contents, forKey: "c") - if let mediaFileReference = self.mediaFileReference { - encoder.encodeObject(mediaFileReference, forKey: "m") - } else { - encoder.encodeNil(forKey: "m") - } - } -} +import SyncCore private func keyFingerprintFromBytes(_ bytes: Buffer) -> Int64 { if let memory = bytes.data, bytes.size >= 4 { diff --git a/submodules/TelegramCore/TelegramCore/SecretChatLayerNegotiation.swift b/submodules/TelegramCore/TelegramCore/SecretChatLayerNegotiation.swift index d7bc4c10be..03d71edab7 100644 --- a/submodules/TelegramCore/TelegramCore/SecretChatLayerNegotiation.swift +++ b/submodules/TelegramCore/TelegramCore/SecretChatLayerNegotiation.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + private let topSupportedLayer: SecretChatSequenceBasedLayer = .layer101 func secretChatCommonSupportedLayer(remoteLayer: Int32) -> SecretChatSequenceBasedLayer { diff --git a/submodules/TelegramCore/TelegramCore/SecretChatOutgoingOperation.swift b/submodules/TelegramCore/TelegramCore/SecretChatOutgoingOperation.swift index 69b54688b9..adb6d6aeaf 100644 --- a/submodules/TelegramCore/TelegramCore/SecretChatOutgoingOperation.swift +++ b/submodules/TelegramCore/TelegramCore/SecretChatOutgoingOperation.swift @@ -7,288 +7,7 @@ import Foundation import TelegramApi #endif -private enum SecretChatOutgoingFileValue: Int32 { - case remote = 0 - case uploadedRegular = 1 - case uploadedLarge = 2 -} - -enum SecretChatOutgoingFileReference: PostboxCoding { - case remote(id: Int64, accessHash: Int64) - case uploadedRegular(id: Int64, partCount: Int32, md5Digest: String, keyFingerprint: Int32) - case uploadedLarge(id: Int64, partCount: Int32, keyFingerprint: Int32) - - init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("v", orElse: 0) { - case SecretChatOutgoingFileValue.remote.rawValue: - self = .remote(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("a", orElse: 0)) - case SecretChatOutgoingFileValue.uploadedRegular.rawValue: - self = .uploadedRegular(id: decoder.decodeInt64ForKey("i", orElse: 0), partCount: decoder.decodeInt32ForKey("p", orElse: 0), md5Digest: decoder.decodeStringForKey("d", orElse: ""), keyFingerprint: decoder.decodeInt32ForKey("f", orElse: 0)) - case SecretChatOutgoingFileValue.uploadedLarge.rawValue: - self = .uploadedLarge(id: decoder.decodeInt64ForKey("i", orElse: 0), partCount: decoder.decodeInt32ForKey("p", orElse: 0), keyFingerprint: decoder.decodeInt32ForKey("f", orElse: 0)) - default: - assertionFailure() - self = .remote(id: 0, accessHash: 0) - } - } - - func encode(_ encoder: PostboxEncoder) { - switch self { - case let .remote(id, accessHash): - encoder.encodeInt32(SecretChatOutgoingFileValue.remote.rawValue, forKey: "v") - encoder.encodeInt64(id, forKey: "i") - encoder.encodeInt64(accessHash, forKey: "a") - case let .uploadedRegular(id, partCount, md5Digest, keyFingerprint): - encoder.encodeInt32(SecretChatOutgoingFileValue.uploadedRegular.rawValue, forKey: "v") - encoder.encodeInt64(id, forKey: "i") - encoder.encodeInt32(partCount, forKey: "p") - encoder.encodeString(md5Digest, forKey: "d") - encoder.encodeInt32(keyFingerprint, forKey: "f") - case let .uploadedLarge(id, partCount, keyFingerprint): - encoder.encodeInt32(SecretChatOutgoingFileValue.uploadedLarge.rawValue, forKey: "v") - encoder.encodeInt64(id, forKey: "i") - encoder.encodeInt32(partCount, forKey: "p") - encoder.encodeInt32(keyFingerprint, forKey: "f") - } - } -} - -struct SecretChatOutgoingFile: PostboxCoding { - let reference: SecretChatOutgoingFileReference - let size: Int32 - let key: SecretFileEncryptionKey - - init(reference: SecretChatOutgoingFileReference, size: Int32, key: SecretFileEncryptionKey) { - self.reference = reference - self.size = size - self.key = key - } - - init(decoder: PostboxDecoder) { - self.reference = decoder.decodeObjectForKey("r", decoder: { SecretChatOutgoingFileReference(decoder: $0) }) as! SecretChatOutgoingFileReference - self.size = decoder.decodeInt32ForKey("s", orElse: 0) - self.key = SecretFileEncryptionKey(aesKey: decoder.decodeBytesForKey("k")!.makeData(), aesIv: decoder.decodeBytesForKey("i")!.makeData()) - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeObject(self.reference, forKey: "r") - encoder.encodeInt32(self.size, forKey: "s") - encoder.encodeBytes(MemoryBuffer(data: self.key.aesKey), forKey: "k") - encoder.encodeBytes(MemoryBuffer(data: self.key.aesIv), forKey: "i") - } -} - -public enum SecretChatSequenceBasedLayer: Int32 { - case layer46 = 46 - case layer73 = 73 - case layer101 = 101 - - var secretChatLayer: SecretChatLayer { - switch self { - case .layer46: - return .layer46 - case .layer73: - return .layer73 - case .layer101: - return .layer101 - } - } -} - -private enum SecretChatOutgoingOperationValue: Int32 { - case initialHandshakeAccept = 0 - case sendMessage = 1 - case readMessagesContent = 2 - case deleteMessages = 3 - case screenshotMessages = 4 - case clearHistory = 5 - case resendOperations = 6 - case reportLayerSupport = 7 - case pfsRequestKey = 8 - case pfsAcceptKey = 9 - case pfsAbortSession = 10 - case pfsCommitKey = 11 - case noop = 12 - case setMessageAutoremoveTimeout = 13 - case terminate = 14 -} - -enum SecretChatOutgoingOperationContents: PostboxCoding { - case initialHandshakeAccept(gA: MemoryBuffer, accessHash: Int64, b: MemoryBuffer) - case sendMessage(layer: SecretChatLayer, id: MessageId, file: SecretChatOutgoingFile?) - case readMessagesContent(layer: SecretChatLayer, actionGloballyUniqueId: Int64, globallyUniqueIds: [Int64]) - case deleteMessages(layer: SecretChatLayer, actionGloballyUniqueId: Int64, globallyUniqueIds: [Int64]) - case screenshotMessages(layer: SecretChatLayer, actionGloballyUniqueId: Int64, globallyUniqueIds: [Int64], messageId: MessageId) - case clearHistory(layer: SecretChatLayer, actionGloballyUniqueId: Int64) - case resendOperations(layer : SecretChatSequenceBasedLayer, actionGloballyUniqueId: Int64, fromSeqNo: Int32, toSeqNo: Int32) - case reportLayerSupport(layer: SecretChatLayer, actionGloballyUniqueId: Int64, layerSupport: Int32) - case pfsRequestKey(layer: SecretChatSequenceBasedLayer, actionGloballyUniqueId: Int64, rekeySessionId: Int64, a: MemoryBuffer) - case pfsAcceptKey(layer: SecretChatSequenceBasedLayer, actionGloballyUniqueId: Int64, rekeySessionId: Int64, gA: MemoryBuffer, b: MemoryBuffer) - case pfsAbortSession(layer: SecretChatSequenceBasedLayer, actionGloballyUniqueId: Int64, rekeySessionId: Int64) - case pfsCommitKey(layer: SecretChatSequenceBasedLayer, actionGloballyUniqueId: Int64, rekeySessionId: Int64, keyFingerprint: Int64) - case noop(layer: SecretChatSequenceBasedLayer, actionGloballyUniqueId: Int64) - case setMessageAutoremoveTimeout(layer: SecretChatLayer, actionGloballyUniqueId: Int64, timeout: Int32, messageId: MessageId) - case terminate(reportSpam: Bool) - - init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("r", orElse: 0) { - case SecretChatOutgoingOperationValue.initialHandshakeAccept.rawValue: - self = .initialHandshakeAccept(gA: decoder.decodeBytesForKey("g")!, accessHash: decoder.decodeInt64ForKey("h", orElse: 0), b: decoder.decodeBytesForKey("b")!) - case SecretChatOutgoingOperationValue.sendMessage.rawValue: - self = .sendMessage(layer: SecretChatLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, id: MessageId(peerId: PeerId(decoder.decodeInt64ForKey("i.p", orElse: 0)), namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt32ForKey("i.i", orElse: 0)), file: decoder.decodeObjectForKey("f", decoder: { SecretChatOutgoingFile(decoder: $0) }) as? SecretChatOutgoingFile) - case SecretChatOutgoingOperationValue.readMessagesContent.rawValue: - self = .readMessagesContent(layer: SecretChatLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), globallyUniqueIds: decoder.decodeInt64ArrayForKey("u")) - case SecretChatOutgoingOperationValue.deleteMessages.rawValue: - self = .deleteMessages(layer: SecretChatLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), globallyUniqueIds: decoder.decodeInt64ArrayForKey("u")) - case SecretChatOutgoingOperationValue.screenshotMessages.rawValue: - self = .screenshotMessages(layer: SecretChatLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), globallyUniqueIds: decoder.decodeInt64ArrayForKey("u"), messageId: MessageId(peerId: PeerId(decoder.decodeInt64ForKey("m.p", orElse: 0)), namespace: decoder.decodeInt32ForKey("m.n", orElse: 0), id: decoder.decodeInt32ForKey("m.i", orElse: 0))) - case SecretChatOutgoingOperationValue.clearHistory.rawValue: - self = .clearHistory(layer: SecretChatLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0)) - case SecretChatOutgoingOperationValue.resendOperations.rawValue: - self = .resendOperations(layer: SecretChatSequenceBasedLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), fromSeqNo: decoder.decodeInt32ForKey("f", orElse: 0), toSeqNo: decoder.decodeInt32ForKey("t", orElse: 0)) - case SecretChatOutgoingOperationValue.reportLayerSupport.rawValue: - self = .reportLayerSupport(layer: SecretChatLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), layerSupport: decoder.decodeInt32ForKey("l", orElse: 0)) - case SecretChatOutgoingOperationValue.pfsRequestKey.rawValue: - self = .pfsRequestKey(layer: SecretChatSequenceBasedLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), rekeySessionId: decoder.decodeInt64ForKey("s", orElse: 0), a: decoder.decodeBytesForKey("a")!) - case SecretChatOutgoingOperationValue.pfsAcceptKey.rawValue: - self = .pfsAcceptKey(layer: SecretChatSequenceBasedLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), rekeySessionId: decoder.decodeInt64ForKey("s", orElse: 0), gA: decoder.decodeBytesForKey("g")!, b: decoder.decodeBytesForKey("b")!) - case SecretChatOutgoingOperationValue.pfsAbortSession.rawValue: - self = .pfsAbortSession(layer: SecretChatSequenceBasedLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), rekeySessionId: decoder.decodeInt64ForKey("s", orElse: 0)) - case SecretChatOutgoingOperationValue.pfsCommitKey.rawValue: - self = .pfsCommitKey(layer: SecretChatSequenceBasedLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), rekeySessionId: decoder.decodeInt64ForKey("s", orElse: 0), keyFingerprint: decoder.decodeInt64ForKey("f", orElse: 0)) - case SecretChatOutgoingOperationValue.noop.rawValue: - self = .noop(layer: SecretChatSequenceBasedLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0)) - case SecretChatOutgoingOperationValue.setMessageAutoremoveTimeout.rawValue: - self = .setMessageAutoremoveTimeout(layer: SecretChatLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: decoder.decodeInt64ForKey("i", orElse: 0), timeout: decoder.decodeInt32ForKey("t", orElse: 0), messageId: MessageId(peerId: PeerId(decoder.decodeInt64ForKey("m.p", orElse: 0)), namespace: decoder.decodeInt32ForKey("m.n", orElse: 0), id: decoder.decodeInt32ForKey("m.i", orElse: 0))) - case SecretChatOutgoingOperationValue.terminate.rawValue: - self = .terminate(reportSpam: decoder.decodeInt32ForKey("rs", orElse: 0) != 0) - default: - self = .noop(layer: SecretChatSequenceBasedLayer(rawValue: decoder.decodeInt32ForKey("l", orElse: 0))!, actionGloballyUniqueId: 0) - assertionFailure() - } - } - - func encode(_ encoder: PostboxEncoder) { - switch self { - case let .initialHandshakeAccept(gA, accessHash, b): - encoder.encodeInt32(SecretChatOutgoingOperationValue.initialHandshakeAccept.rawValue, forKey: "r") - encoder.encodeBytes(gA, forKey: "g") - encoder.encodeInt64(accessHash, forKey: "h") - encoder.encodeBytes(b, forKey: "b") - case let .sendMessage(layer, id, file): - encoder.encodeInt32(SecretChatOutgoingOperationValue.sendMessage.rawValue, forKey: "r") - encoder.encodeInt32(layer.rawValue, forKey: "l") - encoder.encodeInt64(id.peerId.toInt64(), forKey: "i.p") - encoder.encodeInt32(id.namespace, forKey: "i.n") - encoder.encodeInt32(id.id, forKey: "i.i") - if let file = file { - encoder.encodeObject(file, forKey: "f") - } else { - encoder.encodeNil(forKey: "f") - } - case let .readMessagesContent(layer, actionGloballyUniqueId, globallyUniqueIds): - encoder.encodeInt32(SecretChatOutgoingOperationValue.readMessagesContent.rawValue, forKey: "r") - encoder.encodeInt32(layer.rawValue, forKey: "l") - encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") - encoder.encodeInt64Array(globallyUniqueIds, forKey: "u") - case let .deleteMessages(layer, actionGloballyUniqueId, globallyUniqueIds): - encoder.encodeInt32(SecretChatOutgoingOperationValue.deleteMessages.rawValue, forKey: "r") - encoder.encodeInt32(layer.rawValue, forKey: "l") - encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") - encoder.encodeInt64Array(globallyUniqueIds, forKey: "u") - case let .screenshotMessages(layer, actionGloballyUniqueId, globallyUniqueIds, messageId): - encoder.encodeInt32(SecretChatOutgoingOperationValue.screenshotMessages.rawValue, forKey: "r") - encoder.encodeInt32(layer.rawValue, forKey: "l") - encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") - encoder.encodeInt64Array(globallyUniqueIds, forKey: "u") - encoder.encodeInt64(messageId.peerId.toInt64(), forKey: "m.p") - encoder.encodeInt32(messageId.namespace, forKey: "m.n") - encoder.encodeInt32(messageId.id, forKey: "m.i") - case let .clearHistory(layer, actionGloballyUniqueId): - encoder.encodeInt32(SecretChatOutgoingOperationValue.clearHistory.rawValue, forKey: "r") - encoder.encodeInt32(layer.rawValue, forKey: "l") - encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") - case let .resendOperations(layer, actionGloballyUniqueId, fromSeqNo, toSeqNo): - encoder.encodeInt32(SecretChatOutgoingOperationValue.resendOperations.rawValue, forKey: "r") - encoder.encodeInt32(layer.rawValue, forKey: "l") - encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") - encoder.encodeInt32(fromSeqNo, forKey: "f") - encoder.encodeInt32(toSeqNo, forKey: "t") - case let .reportLayerSupport(layer, actionGloballyUniqueId, layerSupport): - encoder.encodeInt32(SecretChatOutgoingOperationValue.reportLayerSupport.rawValue, forKey: "r") - encoder.encodeInt32(layer.rawValue, forKey: "l") - encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") - encoder.encodeInt32(layerSupport, forKey: "l") - case let .pfsRequestKey(layer, actionGloballyUniqueId, rekeySessionId, a): - encoder.encodeInt32(SecretChatOutgoingOperationValue.pfsRequestKey.rawValue, forKey: "r") - encoder.encodeInt32(layer.rawValue, forKey: "l") - encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") - encoder.encodeInt64(rekeySessionId, forKey: "s") - encoder.encodeBytes(a, forKey: "a") - case let .pfsAcceptKey(layer, actionGloballyUniqueId, rekeySessionId, gA, b): - encoder.encodeInt32(SecretChatOutgoingOperationValue.pfsAcceptKey.rawValue, forKey: "r") - encoder.encodeInt32(layer.rawValue, forKey: "l") - encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") - encoder.encodeInt64(rekeySessionId, forKey: "s") - encoder.encodeBytes(gA, forKey: "g") - encoder.encodeBytes(b, forKey: "b") - case let .pfsAbortSession(layer, actionGloballyUniqueId, rekeySessionId): - encoder.encodeInt32(SecretChatOutgoingOperationValue.pfsAbortSession.rawValue, forKey: "r") - encoder.encodeInt32(layer.rawValue, forKey: "l") - encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") - encoder.encodeInt64(rekeySessionId, forKey: "s") - case let .pfsCommitKey(layer, actionGloballyUniqueId, rekeySessionId, keyFingerprint): - encoder.encodeInt32(SecretChatOutgoingOperationValue.pfsCommitKey.rawValue, forKey: "r") - encoder.encodeInt32(layer.rawValue, forKey: "l") - encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") - encoder.encodeInt64(rekeySessionId, forKey: "s") - encoder.encodeInt64(keyFingerprint, forKey: "f") - case let .noop(layer, actionGloballyUniqueId): - encoder.encodeInt32(SecretChatOutgoingOperationValue.noop.rawValue, forKey: "r") - encoder.encodeInt32(layer.rawValue, forKey: "l") - encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") - case let .setMessageAutoremoveTimeout(layer, actionGloballyUniqueId, timeout, messageId): - encoder.encodeInt32(SecretChatOutgoingOperationValue.setMessageAutoremoveTimeout.rawValue, forKey: "r") - encoder.encodeInt32(layer.rawValue, forKey: "l") - encoder.encodeInt64(actionGloballyUniqueId, forKey: "i") - encoder.encodeInt32(timeout, forKey: "t") - encoder.encodeInt64(messageId.peerId.toInt64(), forKey: "m.p") - encoder.encodeInt32(messageId.namespace, forKey: "m.n") - encoder.encodeInt32(messageId.id, forKey: "m.i") - case let .terminate(reportSpam): - encoder.encodeInt32(SecretChatOutgoingOperationValue.terminate.rawValue, forKey: "r") - encoder.encodeInt32(reportSpam ? 1 : 0, forKey: "rs") - } - } -} - -final class SecretChatOutgoingOperation: PostboxCoding { - let contents: SecretChatOutgoingOperationContents - let mutable: Bool - let delivered: Bool - - init(contents: SecretChatOutgoingOperationContents, mutable: Bool, delivered: Bool) { - self.contents = contents - self.mutable = mutable - self.delivered = delivered - } - - init(decoder: PostboxDecoder) { - self.contents = decoder.decodeObjectForKey("c", decoder: { SecretChatOutgoingOperationContents(decoder: $0) }) as! SecretChatOutgoingOperationContents - self.mutable = decoder.decodeInt32ForKey("m", orElse: 0) != 0 - self.delivered = decoder.decodeInt32ForKey("d", orElse: 0) != 0 - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeObject(self.contents, forKey: "c") - encoder.encodeInt32(self.mutable ? 1 : 0, forKey: "m") - encoder.encodeInt32(self.delivered ? 1 : 0, forKey: "d") - } - - func withUpdatedDelivered(_ delivered: Bool) -> SecretChatOutgoingOperation { - return SecretChatOutgoingOperation(contents: self.contents, mutable: self.mutable, delivered: delivered) - } -} +import SyncCore extension SecretChatOutgoingFileReference { init?(_ apiFile: Api.InputEncryptedFile) { diff --git a/submodules/TelegramCore/TelegramCore/SecretChatRekeySession.swift b/submodules/TelegramCore/TelegramCore/SecretChatRekeySession.swift index c1b8d17def..c05ef1d35c 100644 --- a/submodules/TelegramCore/TelegramCore/SecretChatRekeySession.swift +++ b/submodules/TelegramCore/TelegramCore/SecretChatRekeySession.swift @@ -11,6 +11,7 @@ import Foundation #endif #endif +import SyncCore import EncryptionProvider private let keyUseCountThreshold: Int32 = 100 diff --git a/submodules/TelegramCore/TelegramCore/SecureFileMediaResource.swift b/submodules/TelegramCore/TelegramCore/SecureFileMediaResource.swift index e776e98bf1..47632ffd04 100644 --- a/submodules/TelegramCore/TelegramCore/SecureFileMediaResource.swift +++ b/submodules/TelegramCore/TelegramCore/SecureFileMediaResource.swift @@ -7,75 +7,13 @@ import Foundation import TelegramApi #endif -public struct SecureFileMediaResourceId: MediaResourceId { - let fileId: Int64 - - init(fileId: Int64) { - self.fileId = fileId - } - - public var uniqueId: String { - return "telegram-secure-file-\(self.fileId)" - } - - public var hashValue: Int { - return self.fileId.hashValue - } - - public func isEqual(to: MediaResourceId) -> Bool { - if let to = to as? SecureFileMediaResourceId { - return self.fileId == to.fileId - } else { - return false - } - } -} +import SyncCore -public class SecureFileMediaResource: TelegramCloudMediaResource, TelegramMultipartFetchableResource, EncryptedMediaResource { - public let file: SecureIdFileReference - - public var id: MediaResourceId { - return SecureFileMediaResourceId(fileId: self.file.id) - } - - public var datacenterId: Int { - return Int(self.file.datacenterId) - } - - public var size: Int? { - return Int(self.file.size) - } - +extension SecureFileMediaResource: TelegramCloudMediaResource, TelegramMultipartFetchableResource, EncryptedMediaResource { func apiInputLocation(fileReference: Data?) -> Api.InputFileLocation? { return Api.InputFileLocation.inputSecureFileLocation(id: self.file.id, accessHash: self.file.accessHash) } - public init(file: SecureIdFileReference) { - self.file = file - } - - public required init(decoder: PostboxDecoder) { - self.file = SecureIdFileReference(id: decoder.decodeInt64ForKey("f", orElse: 0), accessHash: decoder.decodeInt64ForKey("a", orElse: 0), size: decoder.decodeInt32ForKey("n", orElse: 0), datacenterId: decoder.decodeInt32ForKey("d", orElse: 0), timestamp: decoder.decodeInt32ForKey("t", orElse: 0), fileHash: decoder.decodeBytesForKey("h")?.makeData() ?? Data(), encryptedSecret: decoder.decodeBytesForKey("s")?.makeData() ?? Data()) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt64(self.file.id, forKey: "f") - encoder.encodeInt64(self.file.accessHash, forKey: "a") - encoder.encodeInt32(self.file.size, forKey: "n") - encoder.encodeInt32(self.file.datacenterId, forKey: "d") - encoder.encodeInt32(self.file.timestamp, forKey: "t") - encoder.encodeBytes(MemoryBuffer(data: self.file.fileHash), forKey: "h") - encoder.encodeBytes(MemoryBuffer(data: self.file.encryptedSecret), forKey: "s") - } - - public func isEqual(to: MediaResource) -> Bool { - if let to = to as? SecureFileMediaResource { - return self.file == to.file - } else { - return false - } - } - public func decrypt(data: Data, params: Any) -> Data? { guard let context = params as? SecureIdAccessContext else { return nil diff --git a/submodules/TelegramCore/TelegramCore/SecureIdBankStatementValue.swift b/submodules/TelegramCore/TelegramCore/SecureIdBankStatementValue.swift index f0fd226a4d..ffde28e0b2 100644 --- a/submodules/TelegramCore/TelegramCore/SecureIdBankStatementValue.swift +++ b/submodules/TelegramCore/TelegramCore/SecureIdBankStatementValue.swift @@ -1,4 +1,5 @@ import Foundation +import SyncCore public struct SecureIdBankStatementValue: Equatable { public var verificationDocuments: [SecureIdVerificationDocumentReference] diff --git a/submodules/TelegramCore/TelegramCore/SecureIdConfiguration.swift b/submodules/TelegramCore/TelegramCore/SecureIdConfiguration.swift index 7568e1f2de..ea1d560726 100644 --- a/submodules/TelegramCore/TelegramCore/SecureIdConfiguration.swift +++ b/submodules/TelegramCore/TelegramCore/SecureIdConfiguration.swift @@ -15,43 +15,7 @@ import TelegramApi import SwiftSignalKit #endif -final class CachedSecureIdConfiguration: PostboxCoding { - let value: SecureIdConfiguration - let hash: Int32 - - init(value: SecureIdConfiguration, hash: Int32) { - self.value = value - self.hash = hash - } - - init(decoder: PostboxDecoder) { - self.value = decoder.decodeObjectForKey("value", decoder: { SecureIdConfiguration(decoder: $0) }) as! SecureIdConfiguration - self.hash = decoder.decodeInt32ForKey("hash", orElse: 0) - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeObject(self.value, forKey: "value") - encoder.encodeInt32(self.hash, forKey: "hash") - } -} - -public struct SecureIdConfiguration: PostboxCoding { - public let nativeLanguageByCountry: [String: String] - - fileprivate init(jsonString: String) { - self.nativeLanguageByCountry = (try? JSONDecoder().decode(Dictionary.self, from: jsonString.data(using: .utf8) ?? Data())) ?? [:] - } - - public init(decoder: PostboxDecoder) { - let nativeLanguageByCountryData = decoder.decodeBytesForKey("nativeLanguageByCountry")! - self.nativeLanguageByCountry = (try? JSONDecoder().decode(Dictionary.self, from: nativeLanguageByCountryData.dataNoCopy())) ?? [:] - } - - public func encode(_ encoder: PostboxEncoder) { - let nativeLanguageByCountryData = (try? JSONEncoder().encode(self.nativeLanguageByCountry)) ?? Data() - encoder.encodeBytes(MemoryBuffer(data: nativeLanguageByCountryData), forKey: "nativeLanguageByCountry") - } -} +import SyncCore public func secureIdConfiguration(postbox: Postbox, network: Network) -> Signal { let cached: Signal = postbox.transaction { transaction -> CachedSecureIdConfiguration? in diff --git a/submodules/TelegramCore/TelegramCore/SecureIdDataTypes.swift b/submodules/TelegramCore/TelegramCore/SecureIdDataTypes.swift index 10bb59090c..059aec4ebc 100644 --- a/submodules/TelegramCore/TelegramCore/SecureIdDataTypes.swift +++ b/submodules/TelegramCore/TelegramCore/SecureIdDataTypes.swift @@ -5,6 +5,8 @@ import TelegramApiMac import TelegramApi #endif +import SyncCore + public struct SecureIdPersonName: Equatable { public let firstName: String public let lastName: String @@ -38,16 +40,6 @@ public enum SecureIdGender { case female } -public struct SecureIdFileReference: Equatable { - public let id: Int64 - let accessHash: Int64 - let size: Int32 - let datacenterId: Int32 - public let timestamp: Int32 - public let fileHash: Data - let encryptedSecret: Data -} - extension SecureIdFileReference { init?(apiFile: Api.SecureFile) { switch apiFile { diff --git a/submodules/TelegramCore/TelegramCore/SecureIdVerificationDocumentReference.swift b/submodules/TelegramCore/TelegramCore/SecureIdVerificationDocumentReference.swift index 0e46208fdd..35319bd472 100644 --- a/submodules/TelegramCore/TelegramCore/SecureIdVerificationDocumentReference.swift +++ b/submodules/TelegramCore/TelegramCore/SecureIdVerificationDocumentReference.swift @@ -1,4 +1,5 @@ import Foundation +import SyncCore public enum SecureIdVerificationDocumentReference: Equatable { case remote(SecureIdFileReference) diff --git a/submodules/TelegramCore/TelegramCore/SetSecretChatMessageAutoremoveTimeoutInteractively.swift b/submodules/TelegramCore/TelegramCore/SetSecretChatMessageAutoremoveTimeoutInteractively.swift index a03dcc3e59..14b9bab855 100644 --- a/submodules/TelegramCore/TelegramCore/SetSecretChatMessageAutoremoveTimeoutInteractively.swift +++ b/submodules/TelegramCore/TelegramCore/SetSecretChatMessageAutoremoveTimeoutInteractively.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public func setSecretChatMessageAutoremoveTimeoutInteractively(account: Account, peerId: PeerId, timeout: Int32?) -> Signal { return account.postbox.transaction { transaction -> Void in if let peer = transaction.getPeer(peerId) as? TelegramSecretChat, let state = transaction.getPeerChatState(peerId) as? SecretChatState { diff --git a/submodules/TelegramCore/TelegramCore/SingleMessageView.swift b/submodules/TelegramCore/TelegramCore/SingleMessageView.swift index 24a395509c..14a5dd7207 100644 --- a/submodules/TelegramCore/TelegramCore/SingleMessageView.swift +++ b/submodules/TelegramCore/TelegramCore/SingleMessageView.swift @@ -15,6 +15,7 @@ import Foundation #endif #endif +import SyncCore public func singleMessageView(account: Account, messageId: MessageId, loadIfNotExists: Bool) -> Signal { return Signal { subscriber in diff --git a/submodules/TelegramCore/TelegramCore/SlowMode.swift b/submodules/TelegramCore/TelegramCore/SlowMode.swift index daa1c986d3..4436a17c49 100644 --- a/submodules/TelegramCore/TelegramCore/SlowMode.swift +++ b/submodules/TelegramCore/TelegramCore/SlowMode.swift @@ -8,6 +8,8 @@ import TelegramApi import SwiftSignalKit #endif +import SyncCore + public enum UpdateChannelSlowModeError { case generic } diff --git a/submodules/TelegramCore/TelegramCore/SplitTest.swift b/submodules/TelegramCore/TelegramCore/SplitTest.swift index 2c5ccbe724..a632f27935 100644 --- a/submodules/TelegramCore/TelegramCore/SplitTest.swift +++ b/submodules/TelegramCore/TelegramCore/SplitTest.swift @@ -5,6 +5,8 @@ import PostboxMac import Postbox #endif +import SyncCore + public protocol SplitTestEvent: RawRepresentable where RawValue == String { } diff --git a/submodules/TelegramCore/TelegramCore/StandaloneSendMessage.swift b/submodules/TelegramCore/TelegramCore/StandaloneSendMessage.swift index 4271332540..df3b8f1e0d 100644 --- a/submodules/TelegramCore/TelegramCore/StandaloneSendMessage.swift +++ b/submodules/TelegramCore/TelegramCore/StandaloneSendMessage.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public enum StandaloneMedia { case image(Data) case file(data: Data, mimeType: String, attributes: [TelegramMediaFileAttribute]) diff --git a/submodules/TelegramCore/TelegramCore/StandaloneUploadedMedia.swift b/submodules/TelegramCore/TelegramCore/StandaloneUploadedMedia.swift index 9154de6cbf..bad9d6c00a 100644 --- a/submodules/TelegramCore/TelegramCore/StandaloneUploadedMedia.swift +++ b/submodules/TelegramCore/TelegramCore/StandaloneUploadedMedia.swift @@ -10,6 +10,7 @@ import Foundation import UIKit #endif +import SyncCore public enum StandaloneUploadMediaError { case generic diff --git a/submodules/TelegramCore/TelegramCore/StickerManagement.swift b/submodules/TelegramCore/TelegramCore/StickerManagement.swift index 8d329f235a..f12adda9cd 100644 --- a/submodules/TelegramCore/TelegramCore/StickerManagement.swift +++ b/submodules/TelegramCore/TelegramCore/StickerManagement.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + private func hashForIdsReverse(_ ids: [Int64]) -> Int32 { var acc: UInt32 = 0 diff --git a/submodules/TelegramCore/TelegramCore/StickerPack.swift b/submodules/TelegramCore/TelegramCore/StickerPack.swift index 27f062e0bf..01d1934342 100644 --- a/submodules/TelegramCore/TelegramCore/StickerPack.swift +++ b/submodules/TelegramCore/TelegramCore/StickerPack.swift @@ -8,156 +8,7 @@ import Foundation import TelegramApi #endif -public struct StickerPackCollectionInfoFlags: OptionSet { - public var rawValue: Int32 - - public init(rawValue: Int32) { - self.rawValue = rawValue - } - - public init() { - self.rawValue = 0 - } - - public init(_ flags: StickerPackCollectionInfoFlags) { - var rawValue: Int32 = 0 - - if flags.contains(StickerPackCollectionInfoFlags.isMasks) { - rawValue |= StickerPackCollectionInfoFlags.isMasks.rawValue - } - if flags.contains(StickerPackCollectionInfoFlags.isOfficial) { - rawValue |= StickerPackCollectionInfoFlags.isOfficial.rawValue - } - if flags.contains(StickerPackCollectionInfoFlags.isAnimated) { - rawValue |= StickerPackCollectionInfoFlags.isAnimated.rawValue - } - - self.rawValue = rawValue - } - - public static let isMasks = StickerPackCollectionInfoFlags(rawValue: 1 << 0) - public static let isOfficial = StickerPackCollectionInfoFlags(rawValue: 1 << 1) - public static let isAnimated = StickerPackCollectionInfoFlags(rawValue: 1 << 2) -} - - -public final class StickerPackCollectionInfo: ItemCollectionInfo, Equatable { - public let id: ItemCollectionId - public let flags: StickerPackCollectionInfoFlags - public let accessHash: Int64 - public let title: String - public let shortName: String - public let thumbnail: TelegramMediaImageRepresentation? - public let hash: Int32 - public let count: Int32 - - public init(id: ItemCollectionId, flags: StickerPackCollectionInfoFlags, accessHash: Int64, title: String, shortName: String, thumbnail: TelegramMediaImageRepresentation?, hash: Int32, count: Int32) { - self.id = id - self.flags = flags - self.accessHash = accessHash - self.title = title - self.shortName = shortName - self.thumbnail = thumbnail - self.hash = hash - self.count = count - } - - public init(decoder: PostboxDecoder) { - self.id = ItemCollectionId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)) - self.accessHash = decoder.decodeInt64ForKey("a", orElse: 0) - self.title = decoder.decodeStringForKey("t", orElse: "") - self.shortName = decoder.decodeStringForKey("s", orElse: "") - self.thumbnail = decoder.decodeObjectForKey("th", decoder: { TelegramMediaImageRepresentation(decoder: $0) }) as? TelegramMediaImageRepresentation - self.hash = decoder.decodeInt32ForKey("h", orElse: 0) - self.flags = StickerPackCollectionInfoFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0)) - self.count = decoder.decodeInt32ForKey("n", orElse: 0) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.id.namespace, forKey: "i.n") - encoder.encodeInt64(self.id.id, forKey: "i.i") - encoder.encodeInt64(self.accessHash, forKey: "a") - encoder.encodeString(self.title, forKey: "t") - encoder.encodeString(self.shortName, forKey: "s") - if let thumbnail = self.thumbnail { - encoder.encodeObject(thumbnail, forKey: "th") - } else { - encoder.encodeNil(forKey: "th") - } - encoder.encodeInt32(self.hash, forKey: "h") - encoder.encodeInt32(self.flags.rawValue, forKey: "f") - encoder.encodeInt32(self.count, forKey: "n") - } - - public static func ==(lhs: StickerPackCollectionInfo, rhs: StickerPackCollectionInfo) -> Bool { - if lhs.id != rhs.id { - return false - } - - if lhs.title != rhs.title { - return false - } - - if lhs.shortName != rhs.shortName { - return false - } - - if lhs.hash != rhs.hash { - return false - } - - if lhs.flags != rhs.flags { - return false - } - - if lhs.count != rhs.count { - return false - } - - return true - } -} - -public final class StickerPackItem: ItemCollectionItem, Equatable { - public let index: ItemCollectionItemIndex - public let file: TelegramMediaFile - public let indexKeys: [MemoryBuffer] - - public init(index: ItemCollectionItemIndex, file: TelegramMediaFile, indexKeys: [MemoryBuffer]) { - self.index = index - self.file = file - self.indexKeys = indexKeys - } - - public init(decoder: PostboxDecoder) { - self.index = ItemCollectionItemIndex(index: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)) - self.file = decoder.decodeObjectForKey("f") as! TelegramMediaFile - self.indexKeys = decoder.decodeBytesArrayForKey("s") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.index.index, forKey: "i.n") - encoder.encodeInt64(self.index.id, forKey: "i.i") - encoder.encodeObject(self.file, forKey: "f") - encoder.encodeBytesArray(self.indexKeys, forKey: "s") - } - - public static func ==(lhs: StickerPackItem, rhs: StickerPackItem) -> Bool { - return lhs.index == rhs.index && lhs.file == rhs.file && lhs.indexKeys == rhs.indexKeys - } - - public func getStringRepresentationsOfIndexKeys() -> [String] { - var stringRepresentations: [String] = [] - for key in self.indexKeys { - key.withDataNoCopy { data in - if let string = String(data: data, encoding: .utf8) { - stringRepresentations.append(string) - } - } - } - return stringRepresentations - } -} +import SyncCore func telegramStickerPachThumbnailRepresentationFromApiSize(datacenterId: Int32, size: Api.PhotoSize) -> TelegramMediaImageRepresentation? { switch size { diff --git a/submodules/TelegramCore/TelegramCore/StickerPackInteractiveOperations.swift b/submodules/TelegramCore/TelegramCore/StickerPackInteractiveOperations.swift index 589941604c..8c2c9b90ff 100644 --- a/submodules/TelegramCore/TelegramCore/StickerPackInteractiveOperations.swift +++ b/submodules/TelegramCore/TelegramCore/StickerPackInteractiveOperations.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public func addStickerPackInteractively(postbox: Postbox, info: StickerPackCollectionInfo, items: [ItemCollectionItem]) -> Signal { return postbox.transaction { transaction -> Void in let namespace: SynchronizeInstalledStickerPacksOperationNamespace? diff --git a/submodules/TelegramCore/TelegramCore/StickerSetInstallation.swift b/submodules/TelegramCore/TelegramCore/StickerSetInstallation.swift index f1c18c9545..9fac2b1c00 100644 --- a/submodules/TelegramCore/TelegramCore/StickerSetInstallation.swift +++ b/submodules/TelegramCore/TelegramCore/StickerSetInstallation.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public enum RequestStickerSetError { case generic case invalid diff --git a/submodules/TelegramCore/TelegramCore/StoreMessage_Telegram.swift b/submodules/TelegramCore/TelegramCore/StoreMessage_Telegram.swift index 36085bc8bd..e904a3612a 100644 --- a/submodules/TelegramCore/TelegramCore/StoreMessage_Telegram.swift +++ b/submodules/TelegramCore/TelegramCore/StoreMessage_Telegram.swift @@ -7,6 +7,8 @@ import Foundation import TelegramApi #endif +import SyncCore + public func tagsForStoreMessage(incoming: Bool, attributes: [MessageAttribute], media: [Media], textEntities: [MessageTextEntity]?) -> (MessageTags, GlobalMessageTags) { var isSecret = false var isUnconsumedPersonalMention = false diff --git a/submodules/TelegramCore/TelegramCore/SuggestedLocalizationEntry.swift b/submodules/TelegramCore/TelegramCore/SuggestedLocalizationEntry.swift index b165799eaf..8cb3a49c84 100644 --- a/submodules/TelegramCore/TelegramCore/SuggestedLocalizationEntry.swift +++ b/submodules/TelegramCore/TelegramCore/SuggestedLocalizationEntry.swift @@ -7,37 +7,7 @@ import Foundation import SwiftSignalKit #endif -public final class SuggestedLocalizationEntry: PreferencesEntry { - public let languageCode: String - public let isSeen: Bool - - init(languageCode: String, isSeen: Bool) { - self.languageCode = languageCode - self.isSeen = isSeen - } - - public init(decoder: PostboxDecoder) { - self.languageCode = decoder.decodeStringForKey("lc", orElse: "en") - self.isSeen = decoder.decodeInt32ForKey("s", orElse: 0) != 0 - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.languageCode, forKey: "lc") - encoder.encodeInt32(self.isSeen ? 1 : 0, forKey: "s") - } - - public func isEqual(to: PreferencesEntry) -> Bool { - if let to = to as? SuggestedLocalizationEntry { - return self == to - } else { - return false - } - } - - public static func ==(lhs: SuggestedLocalizationEntry, rhs: SuggestedLocalizationEntry) -> Bool { - return lhs.languageCode == rhs.languageCode && lhs.isSeen == rhs.isSeen - } -} +import SyncCore public func markSuggestedLocalizationAsSeenInteractively(postbox: Postbox, languageCode: String) -> Signal { return postbox.transaction { transaction -> Void in diff --git a/submodules/TelegramCore/TelegramCore/SupportPeerId.swift b/submodules/TelegramCore/TelegramCore/SupportPeerId.swift index 4932997687..f50bb256d6 100644 --- a/submodules/TelegramCore/TelegramCore/SupportPeerId.swift +++ b/submodules/TelegramCore/TelegramCore/SupportPeerId.swift @@ -14,6 +14,8 @@ #endif #endif +import SyncCore + public func supportPeerId(account:Account) -> Signal { return account.network.request(Api.functions.help.getSupport()) |> map(Optional.init) diff --git a/submodules/TelegramCore/TelegramCore/SynchronizeAppLogEventsOperation.swift b/submodules/TelegramCore/TelegramCore/SynchronizeAppLogEventsOperation.swift index 268c5e5d91..88183abcee 100644 --- a/submodules/TelegramCore/TelegramCore/SynchronizeAppLogEventsOperation.swift +++ b/submodules/TelegramCore/TelegramCore/SynchronizeAppLogEventsOperation.swift @@ -13,64 +13,7 @@ import Foundation #endif #endif -private enum SynchronizeAppLogEventsOperationContentType: Int32 { - case add - case sync -} - -enum SynchronizeAppLogEventsOperationContent: PostboxCoding { - case add(time: Double, type: String, peerId: PeerId?, data: JSON) - case sync - - init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("r", orElse: 0) { - case SynchronizeAppLogEventsOperationContentType.add.rawValue: - var peerId: PeerId? - if let id = decoder.decodeOptionalInt64ForKey("p") { - peerId = PeerId(id) - } - self = .add(time: decoder.decodeDoubleForKey("tm", orElse: 0.0), type: decoder.decodeStringForKey("t", orElse: ""), peerId: peerId, data: decoder.decodeObjectForKey("d", decoder: { JSON(decoder: $0) }) as! JSON) - case SynchronizeAppLogEventsOperationContentType.sync.rawValue: - self = .sync - default: - assertionFailure() - self = .sync - } - } - - func encode(_ encoder: PostboxEncoder) { - switch self { - case let .add(time, type, peerId, data): - encoder.encodeInt32(SynchronizeAppLogEventsOperationContentType.add.rawValue, forKey: "r") - encoder.encodeDouble(time, forKey: "tm") - encoder.encodeString(type, forKey: "t") - if let peerId = peerId { - encoder.encodeInt64(peerId.toInt64(), forKey: "p") - } else { - encoder.encodeNil(forKey: "p") - } - encoder.encodeObject(data, forKey: "d") - case .sync: - encoder.encodeInt32(SynchronizeAppLogEventsOperationContentType.sync.rawValue, forKey: "r") - } - } -} - -final class SynchronizeAppLogEventsOperation: PostboxCoding { - let content: SynchronizeAppLogEventsOperationContent - - init(content: SynchronizeAppLogEventsOperationContent) { - self.content = content - } - - init(decoder: PostboxDecoder) { - self.content = decoder.decodeObjectForKey("c", decoder: { SynchronizeAppLogEventsOperationContent(decoder: $0) }) as! SynchronizeAppLogEventsOperationContent - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeObject(self.content, forKey: "c") - } -} +import SyncCore public func addAppLogEvent(postbox: Postbox, time: Double, type: String, peerId: PeerId?, data: JSON) { let tag: PeerOperationLogTag = OperationLogTags.SynchronizeAppLogEvents diff --git a/submodules/TelegramCore/TelegramCore/SynchronizeChatInputStateOperation.swift b/submodules/TelegramCore/TelegramCore/SynchronizeChatInputStateOperation.swift index c00e5ffc4c..1c6220c78c 100644 --- a/submodules/TelegramCore/TelegramCore/SynchronizeChatInputStateOperation.swift +++ b/submodules/TelegramCore/TelegramCore/SynchronizeChatInputStateOperation.swift @@ -5,25 +5,7 @@ import Foundation import Postbox #endif -final class SynchronizeChatInputStateOperation: PostboxCoding { - let previousState: SynchronizeableChatInputState? - - init(previousState: SynchronizeableChatInputState?) { - self.previousState = previousState - } - - init(decoder: PostboxDecoder) { - self.previousState = decoder.decodeObjectForKey("p", decoder: { SynchronizeableChatInputState(decoder: $0) }) as? SynchronizeableChatInputState - } - - func encode(_ encoder: PostboxEncoder) { - if let previousState = self.previousState { - encoder.encodeObject(previousState, forKey: "p") - } else { - encoder.encodeNil(forKey: "p") - } - } -} +import SyncCore func addSynchronizeChatInputStateOperation(transaction: Transaction, peerId: PeerId) { var updateLocalIndex: Int32? diff --git a/submodules/TelegramCore/TelegramCore/SynchronizeConsumeMessageContentsOperation.swift b/submodules/TelegramCore/TelegramCore/SynchronizeConsumeMessageContentsOperation.swift index 23c3bf7943..01c0b0cf4d 100644 --- a/submodules/TelegramCore/TelegramCore/SynchronizeConsumeMessageContentsOperation.swift +++ b/submodules/TelegramCore/TelegramCore/SynchronizeConsumeMessageContentsOperation.swift @@ -1,27 +1,5 @@ -import Foundation -#if os(macOS) - import PostboxMac -#else - import Postbox -#endif - -final class SynchronizeConsumeMessageContentsOperation: PostboxCoding { - let messageIds: [MessageId] - - init(messageIds: [MessageId]) { - self.messageIds = messageIds - } - - init(decoder: PostboxDecoder) { - self.messageIds = MessageId.decodeArrayFromBuffer(decoder.decodeBytesForKeyNoCopy("i")!) - } - - func encode(_ encoder: PostboxEncoder) { - let buffer = WriteBuffer() - MessageId.encodeArrayToBuffer(self.messageIds, buffer: buffer) - encoder.encodeBytes(buffer, forKey: "i") - } -} +import Postbox +import SyncCore func addSynchronizeConsumeMessageContentsOperation(transaction: Transaction, messageIds: [MessageId]) { for (peerId, messageIds) in messagesIdsGroupedByPeerId(Set(messageIds)) { diff --git a/submodules/TelegramCore/TelegramCore/SynchronizeEmojiKeywordsOperation.swift b/submodules/TelegramCore/TelegramCore/SynchronizeEmojiKeywordsOperation.swift index 3b15084071..28705e8289 100644 --- a/submodules/TelegramCore/TelegramCore/SynchronizeEmojiKeywordsOperation.swift +++ b/submodules/TelegramCore/TelegramCore/SynchronizeEmojiKeywordsOperation.swift @@ -5,37 +5,7 @@ import PostboxMac import Postbox #endif -final class SynchronizeEmojiKeywordsOperation: PostboxCoding { - let inputLanguageCode: String - let languageCode: String? - let fromVersion: Int32? - - init(inputLanguageCode: String, languageCode: String?, fromVersion: Int32?) { - self.inputLanguageCode = inputLanguageCode - self.languageCode = languageCode - self.fromVersion = fromVersion - } - - init(decoder: PostboxDecoder) { - self.inputLanguageCode = decoder.decodeStringForKey("ilc", orElse: "") - self.languageCode = decoder.decodeOptionalStringForKey("lc") - self.fromVersion = decoder.decodeOptionalInt32ForKey("v") - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.inputLanguageCode, forKey: "ilc") - if let languageCode = self.languageCode { - encoder.encodeString(languageCode, forKey: "lc") - } else { - encoder.encodeNil(forKey: "lc") - } - if let fromVersion = self.fromVersion { - encoder.encodeInt32(fromVersion, forKey: "v") - } else { - encoder.encodeNil(forKey: "v") - } - } -} +import SyncCore func addSynchronizeEmojiKeywordsOperation(transaction: Transaction, inputLanguageCode: String, languageCode: String?, fromVersion: Int32?) { let tag = OperationLogTags.SynchronizeEmojiKeywords diff --git a/submodules/TelegramCore/TelegramCore/SynchronizeGroupedPeersOperation.swift b/submodules/TelegramCore/TelegramCore/SynchronizeGroupedPeersOperation.swift index d48676c3d8..5cb52d0102 100644 --- a/submodules/TelegramCore/TelegramCore/SynchronizeGroupedPeersOperation.swift +++ b/submodules/TelegramCore/TelegramCore/SynchronizeGroupedPeersOperation.swift @@ -7,25 +7,7 @@ import Foundation import SwiftSignalKit #endif -final class SynchronizeGroupedPeersOperation: PostboxCoding { - let peerId: PeerId - let groupId: PeerGroupId - - init(peerId: PeerId, groupId: PeerGroupId) { - self.peerId = peerId - self.groupId = groupId - } - - init(decoder: PostboxDecoder) { - self.peerId = PeerId(decoder.decodeInt64ForKey("peerId", orElse: 0)) - self.groupId = PeerGroupId.init(rawValue: decoder.decodeInt32ForKey("groupId", orElse: 0)) - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt64(self.peerId.toInt64(), forKey: "peerId") - encoder.encodeInt32(self.groupId.rawValue, forKey: "groupId") - } -} +import SyncCore public func updatePeerGroupIdInteractively(postbox: Postbox, peerId: PeerId, groupId: PeerGroupId) -> Signal { return postbox.transaction { transaction -> Void in diff --git a/submodules/TelegramCore/TelegramCore/SynchronizeInstalledStickerPacksOperations.swift b/submodules/TelegramCore/TelegramCore/SynchronizeInstalledStickerPacksOperation.swift similarity index 71% rename from submodules/TelegramCore/TelegramCore/SynchronizeInstalledStickerPacksOperations.swift rename to submodules/TelegramCore/TelegramCore/SynchronizeInstalledStickerPacksOperation.swift index cafe0a9b73..6c95c4b044 100644 --- a/submodules/TelegramCore/TelegramCore/SynchronizeInstalledStickerPacksOperations.swift +++ b/submodules/TelegramCore/TelegramCore/SynchronizeInstalledStickerPacksOperation.swift @@ -1,56 +1,5 @@ -import Foundation -#if os(macOS) - import PostboxMac -#else - import Postbox -#endif - -enum SynchronizeInstalledStickerPacksOperationNamespace: Int32 { - case stickers = 0 - case masks = 1 -} - -final class SynchronizeInstalledStickerPacksOperation: PostboxCoding { - let previousPacks: [ItemCollectionId] - let archivedPacks: [ItemCollectionId] - - init(previousPacks: [ItemCollectionId], archivedPacks: [ItemCollectionId]) { - self.previousPacks = previousPacks - self.archivedPacks = archivedPacks - } - - init(decoder: PostboxDecoder) { - self.previousPacks = ItemCollectionId.decodeArrayFromBuffer(decoder.decodeBytesForKey("p")!) - self.archivedPacks = decoder.decodeBytesForKey("ap").flatMap(ItemCollectionId.decodeArrayFromBuffer) ?? [] - } - - func encode(_ encoder: PostboxEncoder) { - let buffer = WriteBuffer() - ItemCollectionId.encodeArrayToBuffer(self.previousPacks, buffer: buffer) - encoder.encodeBytes(buffer, forKey: "p") - buffer.reset() - ItemCollectionId.encodeArrayToBuffer(self.archivedPacks, buffer: buffer) - encoder.encodeBytes(buffer, forKey: "ap") - } -} - -final class SynchronizeMarkFeaturedStickerPacksAsSeenOperation: PostboxCoding { - let ids: [ItemCollectionId] - - init(ids: [ItemCollectionId]) { - self.ids = ids - } - - init(decoder: PostboxDecoder) { - self.ids = ItemCollectionId.decodeArrayFromBuffer(decoder.decodeBytesForKey("p")!) - } - - func encode(_ encoder: PostboxEncoder) { - let buffer = WriteBuffer() - ItemCollectionId.encodeArrayToBuffer(self.ids, buffer: buffer) - encoder.encodeBytes(buffer, forKey: "p") - } -} +import Postbox +import SyncCore public enum AddSynchronizeInstalledStickerPacksOperationContent { case sync diff --git a/submodules/TelegramCore/TelegramCore/SynchronizeLocalizationUpdatesOperation.swift b/submodules/TelegramCore/TelegramCore/SynchronizeLocalizationUpdatesOperation.swift index ae5ea727e7..615dfd17d7 100644 --- a/submodules/TelegramCore/TelegramCore/SynchronizeLocalizationUpdatesOperation.swift +++ b/submodules/TelegramCore/TelegramCore/SynchronizeLocalizationUpdatesOperation.swift @@ -7,16 +7,7 @@ import Foundation import SwiftSignalKit #endif -final class SynchronizeLocalizationUpdatesOperation: PostboxCoding { - init() { - } - - init(decoder: PostboxDecoder) { - } - - func encode(_ encoder: PostboxEncoder) { - } -} +import SyncCore func addSynchronizeLocalizationUpdatesOperation(transaction: Transaction) { let tag: PeerOperationLogTag = OperationLogTags.SynchronizeLocalizationUpdates diff --git a/submodules/TelegramCore/TelegramCore/SynchronizeMarkAllUnseenPersonalMessagesOperation.swift b/submodules/TelegramCore/TelegramCore/SynchronizeMarkAllUnseenPersonalMessagesOperation.swift index 1fa91c7a00..b317103d97 100644 --- a/submodules/TelegramCore/TelegramCore/SynchronizeMarkAllUnseenPersonalMessagesOperation.swift +++ b/submodules/TelegramCore/TelegramCore/SynchronizeMarkAllUnseenPersonalMessagesOperation.swift @@ -7,21 +7,7 @@ import Postbox import SwiftSignalKit #endif -final class SynchronizeMarkAllUnseenPersonalMessagesOperation: PostboxCoding { - let maxId: MessageId.Id - - init(maxId: MessageId.Id) { - self.maxId = maxId - } - - init(decoder: PostboxDecoder) { - self.maxId = decoder.decodeInt32ForKey("maxId", orElse: Int32.min + 1) - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.maxId, forKey: "maxId") - } -} +import SyncCore func addSynchronizeMarkAllUnseenPersonalMessagesOperation(transaction: Transaction, peerId: PeerId, maxId: MessageId.Id) { let tag: PeerOperationLogTag = OperationLogTags.SynchronizeMarkAllUnseenPersonalMessages diff --git a/submodules/TelegramCore/TelegramCore/SynchronizePeerReadState.swift b/submodules/TelegramCore/TelegramCore/SynchronizePeerReadState.swift index 2dc8384a5f..d24111b987 100644 --- a/submodules/TelegramCore/TelegramCore/SynchronizePeerReadState.swift +++ b/submodules/TelegramCore/TelegramCore/SynchronizePeerReadState.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + private enum VerifyReadStateError { case Abort case Retry diff --git a/submodules/TelegramCore/TelegramCore/SynchronizeRecentlyUsedMediaOperations.swift b/submodules/TelegramCore/TelegramCore/SynchronizeRecentlyUsedMediaOperations.swift index f7e35283e0..3145923a25 100644 --- a/submodules/TelegramCore/TelegramCore/SynchronizeRecentlyUsedMediaOperations.swift +++ b/submodules/TelegramCore/TelegramCore/SynchronizeRecentlyUsedMediaOperations.swift @@ -7,73 +7,7 @@ import Postbox import SwiftSignalKit #endif -private enum SynchronizeRecentlyUsedMediaOperationContentType: Int32 { - case add - case remove - case clear - case sync -} - -enum SynchronizeRecentlyUsedMediaOperationContent: PostboxCoding { - case add(id: Int64, accessHash: Int64, fileReference: FileMediaReference?) - case remove(id: Int64, accessHash: Int64) - case clear - case sync - - init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("r", orElse: 0) { - case SynchronizeRecentlyUsedMediaOperationContentType.add.rawValue: - self = .add(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0), fileReference: decoder.decodeAnyObjectForKey("fr", decoder: { FileMediaReference(decoder: $0) }) as? FileMediaReference) - case SynchronizeRecentlyUsedMediaOperationContentType.remove.rawValue: - self = .remove(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0)) - case SynchronizeRecentlyUsedMediaOperationContentType.clear.rawValue: - self = .clear - case SynchronizeRecentlyUsedMediaOperationContentType.sync.rawValue: - self = .sync - default: - assertionFailure() - self = .sync - } - } - - func encode(_ encoder: PostboxEncoder) { - switch self { - case let .add(id, accessHash, fileReference): - encoder.encodeInt32(SynchronizeRecentlyUsedMediaOperationContentType.add.rawValue, forKey: "r") - encoder.encodeInt64(id, forKey: "i") - encoder.encodeInt64(accessHash, forKey: "h") - if let fileReference = fileReference { - encoder.encodeObjectWithEncoder(fileReference, encoder: fileReference.encode, forKey: "fr") - } else { - encoder.encodeNil(forKey: "fr") - } - case let .remove(id, accessHash): - encoder.encodeInt32(SynchronizeRecentlyUsedMediaOperationContentType.remove.rawValue, forKey: "r") - encoder.encodeInt64(id, forKey: "i") - encoder.encodeInt64(accessHash, forKey: "h") - case .clear: - encoder.encodeInt32(SynchronizeRecentlyUsedMediaOperationContentType.clear.rawValue, forKey: "r") - case .sync: - encoder.encodeInt32(SynchronizeRecentlyUsedMediaOperationContentType.sync.rawValue, forKey: "r") - } - } -} - -final class SynchronizeRecentlyUsedMediaOperation: PostboxCoding { - let content: SynchronizeRecentlyUsedMediaOperationContent - - init(content: SynchronizeRecentlyUsedMediaOperationContent) { - self.content = content - } - - init(decoder: PostboxDecoder) { - self.content = decoder.decodeObjectForKey("c", decoder: { SynchronizeRecentlyUsedMediaOperationContent(decoder: $0) }) as! SynchronizeRecentlyUsedMediaOperationContent - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeObject(self.content, forKey: "c") - } -} +import SyncCore enum RecentlyUsedMediaCategory { case stickers diff --git a/submodules/TelegramCore/TelegramCore/SynchronizeSavedGifsOperation.swift b/submodules/TelegramCore/TelegramCore/SynchronizeSavedGifsOperation.swift index 7ddaba6b57..c25e90fed8 100644 --- a/submodules/TelegramCore/TelegramCore/SynchronizeSavedGifsOperation.swift +++ b/submodules/TelegramCore/TelegramCore/SynchronizeSavedGifsOperation.swift @@ -7,67 +7,7 @@ import Foundation import SwiftSignalKit #endif -private enum SynchronizeSavedGifsOperationContentType: Int32 { - case add - case remove - case sync -} - -enum SynchronizeSavedGifsOperationContent: PostboxCoding { - case add(id: Int64, accessHash: Int64, fileReference: FileMediaReference?) - case remove(id: Int64, accessHash: Int64) - case sync - - init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("r", orElse: 0) { - case SynchronizeSavedGifsOperationContentType.add.rawValue: - self = .add(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0), fileReference: decoder.decodeAnyObjectForKey("fr", decoder: { FileMediaReference(decoder: $0) }) as? FileMediaReference) - case SynchronizeSavedGifsOperationContentType.remove.rawValue: - self = .remove(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0)) - case SynchronizeSavedGifsOperationContentType.sync.rawValue: - self = .sync - default: - assertionFailure() - self = .sync - } - } - - func encode(_ encoder: PostboxEncoder) { - switch self { - case let .add(id, accessHash, fileReference): - encoder.encodeInt32(SynchronizeSavedGifsOperationContentType.add.rawValue, forKey: "r") - encoder.encodeInt64(id, forKey: "i") - encoder.encodeInt64(accessHash, forKey: "h") - if let fileReference = fileReference { - encoder.encodeObjectWithEncoder(fileReference, encoder: fileReference.encode, forKey: "fr") - } else { - encoder.encodeNil(forKey: "fr") - } - case let .remove(id, accessHash): - encoder.encodeInt32(SynchronizeSavedGifsOperationContentType.remove.rawValue, forKey: "r") - encoder.encodeInt64(id, forKey: "i") - encoder.encodeInt64(accessHash, forKey: "h") - case .sync: - encoder.encodeInt32(SynchronizeSavedGifsOperationContentType.sync.rawValue, forKey: "r") - } - } -} - -final class SynchronizeSavedGifsOperation: PostboxCoding { - let content: SynchronizeSavedGifsOperationContent - - init(content: SynchronizeSavedGifsOperationContent) { - self.content = content - } - - init(decoder: PostboxDecoder) { - self.content = decoder.decodeObjectForKey("c", decoder: { SynchronizeSavedGifsOperationContent(decoder: $0) }) as! SynchronizeSavedGifsOperationContent - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeObject(self.content, forKey: "c") - } -} +import SyncCore func addSynchronizeSavedGifsOperation(transaction: Transaction, operation: SynchronizeSavedGifsOperationContent) { let tag: PeerOperationLogTag = OperationLogTags.SynchronizeSavedGifs diff --git a/submodules/TelegramCore/TelegramCore/SynchronizeSavedStickersOperation.swift b/submodules/TelegramCore/TelegramCore/SynchronizeSavedStickersOperation.swift index 284361edd5..d42e164e0e 100644 --- a/submodules/TelegramCore/TelegramCore/SynchronizeSavedStickersOperation.swift +++ b/submodules/TelegramCore/TelegramCore/SynchronizeSavedStickersOperation.swift @@ -9,67 +9,7 @@ import Foundation import SwiftSignalKit #endif -private enum SynchronizeSavedStickersOperationContentType: Int32 { - case add - case remove - case sync -} - -enum SynchronizeSavedStickersOperationContent: PostboxCoding { - case add(id: Int64, accessHash: Int64, fileReference: FileMediaReference?) - case remove(id: Int64, accessHash: Int64) - case sync - - init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("r", orElse: 0) { - case SynchronizeSavedStickersOperationContentType.add.rawValue: - self = .add(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0), fileReference: decoder.decodeAnyObjectForKey("fr", decoder: { FileMediaReference(decoder: $0) }) as? FileMediaReference) - case SynchronizeSavedStickersOperationContentType.remove.rawValue: - self = .remove(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0)) - case SynchronizeSavedStickersOperationContentType.sync.rawValue: - self = .sync - default: - assertionFailure() - self = .sync - } - } - - func encode(_ encoder: PostboxEncoder) { - switch self { - case let .add(id, accessHash, fileReference): - encoder.encodeInt32(SynchronizeSavedStickersOperationContentType.add.rawValue, forKey: "r") - encoder.encodeInt64(id, forKey: "i") - encoder.encodeInt64(accessHash, forKey: "h") - if let fileReference = fileReference { - encoder.encodeObjectWithEncoder(fileReference, encoder: fileReference.encode, forKey: "fr") - } else { - encoder.encodeNil(forKey: "fr") - } - case let .remove(id, accessHash): - encoder.encodeInt32(SynchronizeSavedStickersOperationContentType.remove.rawValue, forKey: "r") - encoder.encodeInt64(id, forKey: "i") - encoder.encodeInt64(accessHash, forKey: "h") - case .sync: - encoder.encodeInt32(SynchronizeSavedStickersOperationContentType.sync.rawValue, forKey: "r") - } - } -} - -final class SynchronizeSavedStickersOperation: PostboxCoding { - let content: SynchronizeSavedStickersOperationContent - - init(content: SynchronizeSavedStickersOperationContent) { - self.content = content - } - - init(decoder: PostboxDecoder) { - self.content = decoder.decodeObjectForKey("c", decoder: { SynchronizeSavedStickersOperationContent(decoder: $0) }) as! SynchronizeSavedStickersOperationContent - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeObject(self.content, forKey: "c") - } -} +import SyncCore func addSynchronizeSavedStickersOperation(transaction: Transaction, operation: SynchronizeSavedStickersOperationContent) { let tag: PeerOperationLogTag = OperationLogTags.SynchronizeSavedStickers diff --git a/submodules/TelegramCore/TelegramCore/TelegramChannel.swift b/submodules/TelegramCore/TelegramCore/TelegramChannel.swift index 398819c234..a062834b3c 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramChannel.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramChannel.swift @@ -5,304 +5,7 @@ import Foundation import Postbox #endif -public enum TelegramChannelParticipationStatus { - case member - case left - case kicked - - fileprivate var rawValue: Int32 { - switch self { - case .member: - return 0 - case .left: - return 1 - case .kicked: - return 2 - } - } - - fileprivate init(rawValue: Int32) { - switch rawValue { - case 0: - self = .member - case 1: - self = .left - case 2: - self = .kicked - default: - self = .left - } - } -} - -public struct TelegramChannelBroadcastFlags: OptionSet { - public var rawValue: Int32 - - public init() { - self.rawValue = 0 - } - - public init(rawValue: Int32) { - self.rawValue = rawValue - } - - public static let messagesShouldHaveSignatures = TelegramChannelBroadcastFlags(rawValue: 1 << 0) - public static let hasDiscussionGroup = TelegramChannelBroadcastFlags(rawValue: 1 << 1) - -} - -public struct TelegramChannelBroadcastInfo: Equatable { - public let flags: TelegramChannelBroadcastFlags - public init(flags: TelegramChannelBroadcastFlags) { - self.flags = flags - } - - public static func ==(lhs: TelegramChannelBroadcastInfo, rhs: TelegramChannelBroadcastInfo) -> Bool { - return lhs.flags == rhs.flags - } -} - -public struct TelegramChannelGroupFlags: OptionSet { - public var rawValue: Int32 - - public init() { - self.rawValue = 0 - } - - public init(rawValue: Int32) { - self.rawValue = rawValue - } - public static let slowModeEnabled = TelegramChannelGroupFlags(rawValue: 1 << 0) -} - -public struct TelegramChannelGroupInfo: Equatable { - public let flags: TelegramChannelGroupFlags - - public init(flags: TelegramChannelGroupFlags) { - self.flags = flags - } - - public static func ==(lhs: TelegramChannelGroupInfo, rhs: TelegramChannelGroupInfo) -> Bool { - return lhs.flags == rhs.flags - } -} - -public enum TelegramChannelInfo: Equatable { - case broadcast(TelegramChannelBroadcastInfo) - case group(TelegramChannelGroupInfo) - - public static func ==(lhs: TelegramChannelInfo, rhs: TelegramChannelInfo) -> Bool { - switch lhs { - case let .broadcast(lhsInfo): - switch rhs { - case .broadcast(lhsInfo): - return true - default: - return false - } - case let .group(lhsInfo): - switch rhs { - case .group(lhsInfo): - return true - default: - return false - } - } - } - - fileprivate func encode(encoder: PostboxEncoder) { - switch self { - case let .broadcast(info): - encoder.encodeInt32(0, forKey: "i.t") - encoder.encodeInt32(info.flags.rawValue, forKey: "i.f") - case let .group(info): - encoder.encodeInt32(1, forKey: "i.t") - encoder.encodeInt32(info.flags.rawValue, forKey: "i.f") - } - } - - fileprivate static func decode(decoder: PostboxDecoder) -> TelegramChannelInfo { - let type: Int32 = decoder.decodeInt32ForKey("i.t", orElse: 0) - if type == 0 { - return .broadcast(TelegramChannelBroadcastInfo(flags: TelegramChannelBroadcastFlags(rawValue: decoder.decodeInt32ForKey("i.f", orElse: 0)))) - } else { - return .group(TelegramChannelGroupInfo(flags: TelegramChannelGroupFlags(rawValue: decoder.decodeInt32ForKey("i.f", orElse: 0)))) - } - } -} - -public struct TelegramChannelFlags: OptionSet { - public var rawValue: Int32 - - public init() { - self.rawValue = 0 - } - - public init(rawValue: Int32) { - self.rawValue = rawValue - } - - public static let isVerified = TelegramChannelFlags(rawValue: 1 << 0) - public static let isCreator = TelegramChannelFlags(rawValue: 1 << 1) - public static let isScam = TelegramChannelFlags(rawValue: 1 << 2) - public static let hasGeo = TelegramChannelFlags(rawValue: 1 << 3) -} - -public final class TelegramChannel: Peer { - public let id: PeerId - public let accessHash: TelegramPeerAccessHash? - public let title: String - public let username: String? - public let photo: [TelegramMediaImageRepresentation] - public let creationDate: Int32 - public let version: Int32 - public let participationStatus: TelegramChannelParticipationStatus - public let info: TelegramChannelInfo - public let flags: TelegramChannelFlags - public let restrictionInfo: PeerAccessRestrictionInfo? - public let adminRights: TelegramChatAdminRights? - public let bannedRights: TelegramChatBannedRights? - public let defaultBannedRights: TelegramChatBannedRights? - - public var indexName: PeerIndexNameRepresentation { - return .title(title: self.title, addressName: self.username) - } - - public let associatedPeerId: PeerId? = nil - public let notificationSettingsPeerId: PeerId? = nil - - public init(id: PeerId, accessHash: TelegramPeerAccessHash?, title: String, username: String?, photo: [TelegramMediaImageRepresentation], creationDate: Int32, version: Int32, participationStatus: TelegramChannelParticipationStatus, info: TelegramChannelInfo, flags: TelegramChannelFlags, restrictionInfo: PeerAccessRestrictionInfo?, adminRights: TelegramChatAdminRights?, bannedRights: TelegramChatBannedRights?, defaultBannedRights: TelegramChatBannedRights?) { - self.id = id - self.accessHash = accessHash - self.title = title - self.username = username - self.photo = photo - self.creationDate = creationDate - self.version = version - self.participationStatus = participationStatus - self.info = info - self.flags = flags - self.restrictionInfo = restrictionInfo - self.adminRights = adminRights - self.bannedRights = bannedRights - self.defaultBannedRights = defaultBannedRights - } - - public init(decoder: PostboxDecoder) { - self.id = PeerId(decoder.decodeInt64ForKey("i", orElse: 0)) - let accessHash = decoder.decodeOptionalInt64ForKey("ah") - let accessHashType: Int32 = decoder.decodeInt32ForKey("aht", orElse: 0) - if let accessHash = accessHash { - if accessHashType == 0 { - self.accessHash = .personal(accessHash) - } else { - self.accessHash = .genericPublic(accessHash) - } - } else { - self.accessHash = nil - } - self.title = decoder.decodeStringForKey("t", orElse: "") - self.username = decoder.decodeOptionalStringForKey("un") - self.photo = decoder.decodeObjectArrayForKey("ph") - self.creationDate = decoder.decodeInt32ForKey("d", orElse: 0) - self.version = decoder.decodeInt32ForKey("v", orElse: 0) - self.participationStatus = TelegramChannelParticipationStatus(rawValue: decoder.decodeInt32ForKey("ps", orElse: 0)) - self.info = TelegramChannelInfo.decode(decoder: decoder) - self.flags = TelegramChannelFlags(rawValue: decoder.decodeInt32ForKey("fl", orElse: 0)) - self.restrictionInfo = decoder.decodeObjectForKey("ri") as? PeerAccessRestrictionInfo - self.adminRights = decoder.decodeObjectForKey("ar", decoder: { TelegramChatAdminRights(decoder: $0) }) as? TelegramChatAdminRights - self.bannedRights = decoder.decodeObjectForKey("br", decoder: { TelegramChatBannedRights(decoder: $0) }) as? TelegramChatBannedRights - self.defaultBannedRights = decoder.decodeObjectForKey("dbr", decoder: { TelegramChatBannedRights(decoder: $0) }) as? TelegramChatBannedRights - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt64(self.id.toInt64(), forKey: "i") - if let accessHash = self.accessHash { - switch accessHash { - case let .personal(value): - encoder.encodeInt64(value, forKey: "ah") - encoder.encodeInt32(0, forKey: "aht") - case let .genericPublic(value): - encoder.encodeInt64(value, forKey: "ah") - encoder.encodeInt32(1, forKey: "aht") - } - } else { - encoder.encodeNil(forKey: "ah") - } - encoder.encodeString(self.title, forKey: "t") - if let username = self.username { - encoder.encodeString(username, forKey: "un") - } else { - encoder.encodeNil(forKey: "un") - } - encoder.encodeObjectArray(self.photo, forKey: "ph") - encoder.encodeInt32(self.creationDate, forKey: "d") - encoder.encodeInt32(self.version, forKey: "v") - encoder.encodeInt32(self.participationStatus.rawValue, forKey: "ps") - self.info.encode(encoder: encoder) - encoder.encodeInt32(self.flags.rawValue, forKey: "fl") - if let restrictionInfo = self.restrictionInfo { - encoder.encodeObject(restrictionInfo, forKey: "ri") - } else { - encoder.encodeNil(forKey: "ri") - } - if let adminRights = self.adminRights { - encoder.encodeObject(adminRights, forKey: "ar") - } else { - encoder.encodeNil(forKey: "ar") - } - if let bannedRights = self.bannedRights { - encoder.encodeObject(bannedRights, forKey: "br") - } else { - encoder.encodeNil(forKey: "br") - } - if let defaultBannedRights = self.defaultBannedRights { - encoder.encodeObject(defaultBannedRights, forKey: "dbr") - } else { - encoder.encodeNil(forKey: "dbr") - } - } - - public func isEqual(_ other: Peer) -> Bool { - guard let other = other as? TelegramChannel else { - return false - } - - if self.id != other.id || self.accessHash != other.accessHash || self.title != other.title || self.username != other.username || self.photo != other.photo { - return false - } - - if self.creationDate != other.creationDate || self.version != other.version || self.participationStatus != other.participationStatus { - return false - } - - if self.info != other.info || self.flags != other.flags || self.restrictionInfo != other.restrictionInfo { - return false - } - - if self.adminRights != other.adminRights { - return false - } - - if self.bannedRights != other.bannedRights { - return false - } - - if self.defaultBannedRights != other.defaultBannedRights { - return false - } - - return true - } - - func withUpdatedAddressName(_ addressName: String?) -> TelegramChannel { - return TelegramChannel(id: self.id, accessHash: self.accessHash, title: self.title, username: addressName, photo: self.photo, creationDate: self.creationDate, version: self.version, participationStatus: self.participationStatus, info: self.info, flags: self.flags, restrictionInfo: self.restrictionInfo, adminRights: self.adminRights, bannedRights: self.bannedRights, defaultBannedRights: self.defaultBannedRights) - } - - func withUpdatedDefaultBannedRights(_ defaultBannedRights: TelegramChatBannedRights?) -> TelegramChannel { - return TelegramChannel(id: self.id, accessHash: self.accessHash, title: self.title, username: self.addressName, photo: self.photo, creationDate: self.creationDate, version: self.version, participationStatus: self.participationStatus, info: self.info, flags: self.flags, restrictionInfo: self.restrictionInfo, adminRights: self.adminRights, bannedRights: self.bannedRights, defaultBannedRights: defaultBannedRights) - } -} +import SyncCore public enum TelegramChannelPermission { case sendMessages diff --git a/submodules/TelegramCore/TelegramCore/TelegramChannelAdminRights.swift b/submodules/TelegramCore/TelegramCore/TelegramChannelAdminRights.swift index f6b879abd5..2bb6989f71 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramChannelAdminRights.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramChannelAdminRights.swift @@ -7,85 +7,7 @@ import Foundation import TelegramApi #endif -public struct TelegramChatAdminRightsFlags: OptionSet { - public var rawValue: Int32 - - public init(rawValue: Int32) { - self.rawValue = rawValue - } - - public init() { - self.rawValue = 0 - } - - public static let canChangeInfo = TelegramChatAdminRightsFlags(rawValue: 1 << 0) - public static let canPostMessages = TelegramChatAdminRightsFlags(rawValue: 1 << 1) - public static let canEditMessages = TelegramChatAdminRightsFlags(rawValue: 1 << 2) - public static let canDeleteMessages = TelegramChatAdminRightsFlags(rawValue: 1 << 3) - public static let canBanUsers = TelegramChatAdminRightsFlags(rawValue: 1 << 4) - public static let canInviteUsers = TelegramChatAdminRightsFlags(rawValue: 1 << 5) - public static let canPinMessages = TelegramChatAdminRightsFlags(rawValue: 1 << 7) - public static let canAddAdmins = TelegramChatAdminRightsFlags(rawValue: 1 << 9) - - public static var groupSpecific: TelegramChatAdminRightsFlags = [ - .canChangeInfo, - .canDeleteMessages, - .canBanUsers, - .canInviteUsers, - .canPinMessages, - .canAddAdmins - ] - - public static var broadcastSpecific: TelegramChatAdminRightsFlags = [ - .canChangeInfo, - .canPostMessages, - .canEditMessages, - .canDeleteMessages, - .canInviteUsers, - .canAddAdmins - ] - - public var count: Int { - var result = 0 - var index = 0 - while index < 31 { - let currentValue = self.rawValue >> Int32(index) - index += 1 - if currentValue == 0 { - break - } - - if (currentValue & 1) != 0 { - result += 1 - } - } - return result - } -} - -public struct TelegramChatAdminRights: PostboxCoding, Equatable { - public let flags: TelegramChatAdminRightsFlags - - public init(flags: TelegramChatAdminRightsFlags) { - self.flags = flags - } - - public init(decoder: PostboxDecoder) { - self.flags = TelegramChatAdminRightsFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0)) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.flags.rawValue, forKey: "f") - } - - public static func ==(lhs: TelegramChatAdminRights, rhs: TelegramChatAdminRights) -> Bool { - return lhs.flags == rhs.flags - } - - public var isEmpty: Bool { - return self.flags.isEmpty - } -} +import SyncCore extension TelegramChatAdminRights { init(apiAdminRights: Api.ChatAdminRights) { diff --git a/submodules/TelegramCore/TelegramCore/TelegramChannelBannedRights.swift b/submodules/TelegramCore/TelegramCore/TelegramChannelBannedRights.swift index 87c0965365..8a07c2c225 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramChannelBannedRights.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramChannelBannedRights.swift @@ -7,54 +7,7 @@ import Foundation import TelegramApi #endif -public struct TelegramChatBannedRightsFlags: OptionSet { - public var rawValue: Int32 - - public init(rawValue: Int32) { - self.rawValue = rawValue - } - - public init() { - self.rawValue = 0 - } - - public static let banReadMessages = TelegramChatBannedRightsFlags(rawValue: 1 << 0) - public static let banSendMessages = TelegramChatBannedRightsFlags(rawValue: 1 << 1) - public static let banSendMedia = TelegramChatBannedRightsFlags(rawValue: 1 << 2) - public static let banSendStickers = TelegramChatBannedRightsFlags(rawValue: 1 << 3) - public static let banSendGifs = TelegramChatBannedRightsFlags(rawValue: 1 << 4) - public static let banSendGames = TelegramChatBannedRightsFlags(rawValue: 1 << 5) - public static let banSendInline = TelegramChatBannedRightsFlags(rawValue: 1 << 6) - public static let banEmbedLinks = TelegramChatBannedRightsFlags(rawValue: 1 << 7) - public static let banSendPolls = TelegramChatBannedRightsFlags(rawValue: 1 << 8) - public static let banChangeInfo = TelegramChatBannedRightsFlags(rawValue: 1 << 10) - public static let banAddMembers = TelegramChatBannedRightsFlags(rawValue: 1 << 15) - public static let banPinMessages = TelegramChatBannedRightsFlags(rawValue: 1 << 17) -} - -public struct TelegramChatBannedRights: PostboxCoding, Equatable { - public let flags: TelegramChatBannedRightsFlags - public let untilDate: Int32 - - public init(flags: TelegramChatBannedRightsFlags, untilDate: Int32) { - self.flags = flags - self.untilDate = untilDate - } - - public init(decoder: PostboxDecoder) { - self.flags = TelegramChatBannedRightsFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0)) - self.untilDate = decoder.decodeInt32ForKey("d", orElse: 0) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.flags.rawValue, forKey: "f") - encoder.encodeInt32(self.untilDate, forKey: "d") - } - - public static func ==(lhs: TelegramChatBannedRights, rhs: TelegramChatBannedRights) -> Bool { - return lhs.flags == rhs.flags && lhs.untilDate == rhs.untilDate - } -} +import SyncCore extension TelegramChatBannedRights { init(apiBannedRights: Api.ChatBannedRights) { diff --git a/submodules/TelegramCore/TelegramCore/TelegramDeviceContactImportInfo.swift b/submodules/TelegramCore/TelegramCore/TelegramDeviceContactImportInfo.swift index d3cfe6de13..e222b6d405 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramDeviceContactImportInfo.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramDeviceContactImportInfo.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + private let phoneNumberKeyPrefix: ValueBoxKey = { let result = ValueBoxKey(length: 1) result.setInt8(0, value: 0) @@ -51,34 +53,6 @@ enum TelegramDeviceContactImportIdentifier: Hashable, Comparable, Equatable { } } -enum TelegramDeviceContactImportedData: PostboxCoding { - case imported(data: ImportableDeviceContactData, importedByCount: Int32) - case retryLater - - init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("_t", orElse: 0) { - case 0: - self = .imported(data: decoder.decodeObjectForKey("d", decoder: { ImportableDeviceContactData(decoder: $0) }) as! ImportableDeviceContactData, importedByCount: decoder.decodeInt32ForKey("c", orElse: 0)) - case 1: - self = .retryLater - default: - assertionFailure() - self = .retryLater - } - } - - func encode(_ encoder: PostboxEncoder) { - switch self { - case let .imported(data, importedByCount): - encoder.encodeInt32(0, forKey: "_t") - encoder.encodeObject(data, forKey: "d") - encoder.encodeInt32(importedByCount, forKey: "c") - case .retryLater: - encoder.encodeInt32(1, forKey: "_t") - } - } -} - public func deviceContactsImportedByCount(postbox: Postbox, contacts: [(String, [DeviceContactNormalizedPhoneNumber])]) -> Signal<[String: Int32], NoError> { return postbox.transaction { transaction -> [String: Int32] in var result: [String: Int32] = [:] diff --git a/submodules/TelegramCore/TelegramCore/TelegramGroup.swift b/submodules/TelegramCore/TelegramCore/TelegramGroup.swift index 74bde61610..62ba4be67f 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramGroup.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramGroup.swift @@ -5,209 +5,7 @@ import Foundation import Postbox #endif -public enum TelegramGroupRole: Equatable, PostboxCoding { - case creator(rank: String?) - case admin(TelegramChatAdminRights, rank: String?) - case member - - public init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("_v", orElse: 0) { - case 0: - self = .creator(rank: decoder.decodeOptionalStringForKey("rank")) - case 1: - self = .admin(decoder.decodeObjectForKey("r", decoder: { TelegramChatAdminRights(decoder: $0) }) as! TelegramChatAdminRights, rank: decoder.decodeOptionalStringForKey("rank")) - case 2: - self = .member - default: - assertionFailure() - self = .member - } - } - - public func encode(_ encoder: PostboxEncoder) { - switch self { - case let .creator(rank): - encoder.encodeInt32(0, forKey: "_v") - if let rank = rank { - encoder.encodeString(rank, forKey: "rank") - } else { - encoder.encodeNil(forKey: "rank") - } - case let .admin(rights, rank): - encoder.encodeInt32(1, forKey: "_v") - encoder.encodeObject(rights, forKey: "r") - if let rank = rank { - encoder.encodeString(rank, forKey: "rank") - } else { - encoder.encodeNil(forKey: "rank") - } - case .member: - encoder.encodeInt32(2, forKey: "_v") - } - } -} - -public enum TelegramGroupMembership: Int32 { - case Member - case Left - case Removed -} - -public struct TelegramGroupFlags: OptionSet { - public var rawValue: Int32 - - public init() { - self.rawValue = 0 - } - - public init(rawValue: Int32) { - self.rawValue = rawValue - } - - public static let deactivated = TelegramGroupFlags(rawValue: 1 << 1) -} - -public struct TelegramGroupToChannelMigrationReference: Equatable { - public let peerId: PeerId - public let accessHash: Int64 - - public static func ==(lhs: TelegramGroupToChannelMigrationReference, rhs: TelegramGroupToChannelMigrationReference) -> Bool { - return lhs.peerId == rhs.peerId && lhs.accessHash == rhs.accessHash - } -} - -public final class TelegramGroup: Peer { - public let id: PeerId - public let title: String - public let photo: [TelegramMediaImageRepresentation] - public let participantCount: Int - public let role: TelegramGroupRole - public let membership: TelegramGroupMembership - public let flags: TelegramGroupFlags - public let defaultBannedRights: TelegramChatBannedRights? - public let migrationReference: TelegramGroupToChannelMigrationReference? - public let creationDate: Int32 - public let version: Int - - public var indexName: PeerIndexNameRepresentation { - return .title(title: self.title, addressName: nil) - } - - public let associatedPeerId: PeerId? = nil - public let notificationSettingsPeerId: PeerId? = nil - - public init(id: PeerId, title: String, photo: [TelegramMediaImageRepresentation], participantCount: Int, role: TelegramGroupRole, membership: TelegramGroupMembership, flags: TelegramGroupFlags, defaultBannedRights: TelegramChatBannedRights?, migrationReference: TelegramGroupToChannelMigrationReference?, creationDate: Int32, version: Int) { - self.id = id - self.title = title - self.photo = photo - self.participantCount = participantCount - self.role = role - self.membership = membership - self.flags = flags - self.defaultBannedRights = defaultBannedRights - self.migrationReference = migrationReference - self.creationDate = creationDate - self.version = version - } - - public init(decoder: PostboxDecoder) { - self.id = PeerId(decoder.decodeInt64ForKey("i", orElse: 0)) - self.title = decoder.decodeStringForKey("t", orElse: "") - self.photo = decoder.decodeObjectArrayForKey("ph") - self.participantCount = Int(decoder.decodeInt32ForKey("pc", orElse: 0)) - if let role = decoder.decodeObjectForKey("rv", decoder: { TelegramGroupRole(decoder: $0) }) as? TelegramGroupRole { - self.role = role - } else if let roleValue = decoder.decodeOptionalInt32ForKey("r"), roleValue == 0 { - self.role = .creator(rank: nil) - } else { - self.role = .member - } - self.membership = TelegramGroupMembership(rawValue: decoder.decodeInt32ForKey("m", orElse: 0))! - self.flags = TelegramGroupFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0)) - self.defaultBannedRights = decoder.decodeObjectForKey("dbr", decoder: { TelegramChatBannedRights(decoder: $0) }) as? TelegramChatBannedRights - let migrationPeerId: Int64? = decoder.decodeOptionalInt64ForKey("mr.i") - let migrationAccessHash: Int64? = decoder.decodeOptionalInt64ForKey("mr.a") - if let migrationPeerId = migrationPeerId, let migrationAccessHash = migrationAccessHash { - self.migrationReference = TelegramGroupToChannelMigrationReference(peerId: PeerId(migrationPeerId), accessHash: migrationAccessHash) - } else { - self.migrationReference = nil - } - self.creationDate = decoder.decodeInt32ForKey("d", orElse: 0) - self.version = Int(decoder.decodeInt32ForKey("v", orElse: 0)) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt64(self.id.toInt64(), forKey: "i") - encoder.encodeString(self.title, forKey: "t") - encoder.encodeObjectArray(self.photo, forKey: "ph") - encoder.encodeInt32(Int32(self.participantCount), forKey: "pc") - encoder.encodeObject(self.role, forKey: "rv") - encoder.encodeInt32(self.membership.rawValue, forKey: "m") - if let defaultBannedRights = self.defaultBannedRights { - encoder.encodeObject(defaultBannedRights, forKey: "dbr") - } else { - encoder.encodeNil(forKey: "dbr") - } - if let migrationReference = self.migrationReference { - encoder.encodeInt64(migrationReference.peerId.toInt64(), forKey: "mr.i") - encoder.encodeInt64(migrationReference.accessHash, forKey: "mr.a") - } else { - encoder.encodeNil(forKey: "mr.i") - encoder.encodeNil(forKey: "mr.a") - } - encoder.encodeInt32(self.creationDate, forKey: "d") - encoder.encodeInt32(Int32(self.version), forKey: "v") - } - - public func isEqual(_ other: Peer) -> Bool { - if let other = other as? TelegramGroup { - if self.id != other.id { - return false - } - if self.title != other.title { - return false - } - if self.photo != other.photo { - return false - } - if self.membership != other.membership { - return false - } - if self.version != other.version { - return false - } - if self.participantCount != other.participantCount { - return false - } - if self.role != other.role { - return false - } - if self.defaultBannedRights != other.defaultBannedRights { - return false - } - if self.migrationReference != other.migrationReference { - return false - } - if self.creationDate != other.creationDate { - return false - } - if self.flags != other.flags { - return false - } - return true - } else { - return false - } - } - - public func updateFlags(flags: TelegramGroupFlags, version: Int) -> TelegramGroup { - return TelegramGroup(id: self.id, title: self.title, photo: self.photo, participantCount: self.participantCount, role: self.role, membership: self.membership, flags: flags, defaultBannedRights: self.defaultBannedRights, migrationReference: self.migrationReference, creationDate: self.creationDate, version: version) - } - - public func updateDefaultBannedRights(_ defaultBannedRights: TelegramChatBannedRights?, version: Int) -> TelegramGroup { - return TelegramGroup(id: self.id, title: self.title, photo: self.photo, participantCount: self.participantCount, role: self.role, membership: self.membership, flags: self.flags, defaultBannedRights: defaultBannedRights, migrationReference: self.migrationReference, creationDate: self.creationDate, version: version) - } -} +import SyncCore public extension TelegramGroup { func hasBannedPermission(_ rights: TelegramChatBannedRightsFlags) -> Bool { diff --git a/submodules/TelegramCore/TelegramCore/TelegramMediaAction.swift b/submodules/TelegramCore/TelegramCore/TelegramMediaAction.swift index 43085a1b5c..ca16d3a200 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramMediaAction.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramMediaAction.swift @@ -7,237 +7,7 @@ import Foundation import TelegramApi #endif -public enum PhoneCallDiscardReason: Int32 { - case missed = 0 - case disconnect = 1 - case hangup = 2 - case busy = 3 -} - -public enum SentSecureValueType: Int32 { - case personalDetails = 0 - case passport = 1 - case driversLicense = 2 - case idCard = 3 - case address = 4 - case bankStatement = 5 - case utilityBill = 6 - case rentalAgreement = 7 - case phone = 8 - case email = 9 - case internalPassport = 10 - case passportRegistration = 11 - case temporaryRegistration = 12 -} - -public enum TelegramMediaActionType: PostboxCoding, Equatable { - case unknown - case groupCreated(title: String) - case addedMembers(peerIds: [PeerId]) - case removedMembers(peerIds: [PeerId]) - case photoUpdated(image: TelegramMediaImage?) - case titleUpdated(title: String) - case pinnedMessageUpdated - case joinedByLink(inviter: PeerId) - case channelMigratedFromGroup(title: String, groupId: PeerId) - case groupMigratedToChannel(channelId: PeerId) - case historyCleared - case historyScreenshot - case messageAutoremoveTimeoutUpdated(Int32) - case gameScore(gameId: Int64, score: Int32) - case phoneCall(callId: Int64, discardReason: PhoneCallDiscardReason?, duration: Int32?) - case paymentSent(currency: String, totalAmount: Int64) - case customText(text: String, entities: [MessageTextEntity]) - case botDomainAccessGranted(domain: String) - case botSentSecureValues(types: [SentSecureValueType]) - case peerJoined - case phoneNumberRequest - - public init(decoder: PostboxDecoder) { - let rawValue: Int32 = decoder.decodeInt32ForKey("_rawValue", orElse: 0) - switch rawValue { - case 1: - self = .groupCreated(title: decoder.decodeStringForKey("title", orElse: "")) - case 2: - self = .addedMembers(peerIds: PeerId.decodeArrayFromBuffer(decoder.decodeBytesForKeyNoCopy("peerIds")!)) - case 3: - self = .removedMembers(peerIds: PeerId.decodeArrayFromBuffer(decoder.decodeBytesForKeyNoCopy("peerIds")!)) - case 4: - self = .photoUpdated(image: decoder.decodeObjectForKey("image") as? TelegramMediaImage) - case 5: - self = .titleUpdated(title: decoder.decodeStringForKey("title", orElse: "")) - case 6: - self = .pinnedMessageUpdated - case 7: - self = .joinedByLink(inviter: PeerId(decoder.decodeInt64ForKey("inviter", orElse: 0))) - case 8: - self = .channelMigratedFromGroup(title: decoder.decodeStringForKey("title", orElse: ""), groupId: PeerId(decoder.decodeInt64ForKey("groupId", orElse: 0))) - case 9: - self = .groupMigratedToChannel(channelId: PeerId(decoder.decodeInt64ForKey("channelId", orElse: 0))) - case 10: - self = .historyCleared - case 11: - self = .historyScreenshot - case 12: - self = .messageAutoremoveTimeoutUpdated(decoder.decodeInt32ForKey("t", orElse: 0)) - case 13: - self = .gameScore(gameId: decoder.decodeInt64ForKey("i", orElse: 0), score: decoder.decodeInt32ForKey("s", orElse: 0)) - case 14: - var discardReason: PhoneCallDiscardReason? - if let value = decoder.decodeOptionalInt32ForKey("dr") { - discardReason = PhoneCallDiscardReason(rawValue: value) - } - self = .phoneCall(callId: decoder.decodeInt64ForKey("i", orElse: 0), discardReason: discardReason, duration: decoder.decodeInt32ForKey("d", orElse: 0)) - case 15: - self = .paymentSent(currency: decoder.decodeStringForKey("currency", orElse: ""), totalAmount: decoder.decodeInt64ForKey("ta", orElse: 0)) - case 16: - self = .customText(text: decoder.decodeStringForKey("text", orElse: ""), entities: decoder.decodeObjectArrayWithDecoderForKey("ent")) - case 17: - self = .botDomainAccessGranted(domain: decoder.decodeStringForKey("do", orElse: "")) - case 18: - self = .botSentSecureValues(types: decoder.decodeInt32ArrayForKey("ty").map { value -> SentSecureValueType in - return SentSecureValueType(rawValue: value) ?? .personalDetails - }) - case 19: - self = .peerJoined - case 20: - self = .phoneNumberRequest - default: - self = .unknown - } - } - - public func encode(_ encoder: PostboxEncoder) { - switch self { - case .unknown: - break - case let .groupCreated(title): - encoder.encodeInt32(1, forKey: "_rawValue") - encoder.encodeString(title, forKey: "title") - case let .addedMembers(peerIds): - encoder.encodeInt32(2, forKey: "_rawValue") - let buffer = WriteBuffer() - PeerId.encodeArrayToBuffer(peerIds, buffer: buffer) - encoder.encodeBytes(buffer, forKey: "peerIds") - case let .removedMembers(peerIds): - encoder.encodeInt32(3, forKey: "_rawValue") - let buffer = WriteBuffer() - PeerId.encodeArrayToBuffer(peerIds, buffer: buffer) - encoder.encodeBytes(buffer, forKey: "peerIds") - case let .photoUpdated(image): - encoder.encodeInt32(4, forKey: "_rawValue") - if let image = image { - encoder.encodeObject(image, forKey: "image") - } - case let .titleUpdated(title): - encoder.encodeInt32(5, forKey: "_rawValue") - encoder.encodeString(title, forKey: "title") - case .pinnedMessageUpdated: - encoder.encodeInt32(6, forKey: "_rawValue") - case let .joinedByLink(inviter): - encoder.encodeInt32(7, forKey: "_rawValue") - encoder.encodeInt64(inviter.toInt64(), forKey: "inviter") - case let .channelMigratedFromGroup(title, groupId): - encoder.encodeInt32(8, forKey: "_rawValue") - encoder.encodeString(title, forKey: "title") - encoder.encodeInt64(groupId.toInt64(), forKey: "groupId") - case let .groupMigratedToChannel(channelId): - encoder.encodeInt32(9, forKey: "_rawValue") - encoder.encodeInt64(channelId.toInt64(), forKey: "channelId") - case .historyCleared: - encoder.encodeInt32(10, forKey: "_rawValue") - case .historyScreenshot: - encoder.encodeInt32(11, forKey: "_rawValue") - case let .messageAutoremoveTimeoutUpdated(timeout): - encoder.encodeInt32(12, forKey: "_rawValue") - encoder.encodeInt32(timeout, forKey: "t") - case let .gameScore(gameId, score): - encoder.encodeInt32(13, forKey: "_rawValue") - encoder.encodeInt64(gameId, forKey: "i") - encoder.encodeInt32(score, forKey: "s") - case let .paymentSent(currency, totalAmount): - encoder.encodeInt32(15, forKey: "_rawValue") - encoder.encodeString(currency, forKey: "currency") - encoder.encodeInt64(totalAmount, forKey: "ta") - case let .phoneCall(callId, discardReason, duration): - encoder.encodeInt32(14, forKey: "_rawValue") - encoder.encodeInt64(callId, forKey: "i") - if let discardReason = discardReason { - encoder.encodeInt32(discardReason.rawValue, forKey: "dr") - } else { - encoder.encodeNil(forKey: "dr") - } - if let duration = duration { - encoder.encodeInt32(duration, forKey: "d") - } else { - encoder.encodeNil(forKey: "d") - } - case let .customText(text, entities): - encoder.encodeInt32(16, forKey: "_rawValue") - encoder.encodeString(text, forKey: "text") - encoder.encodeObjectArray(entities, forKey: "ent") - case let .botDomainAccessGranted(domain): - encoder.encodeInt32(17, forKey: "_rawValue") - encoder.encodeString(domain, forKey: "do") - case let .botSentSecureValues(types): - encoder.encodeInt32(18, forKey: "_rawValue") - encoder.encodeInt32Array(types.map { $0.rawValue }, forKey: "ty") - case .peerJoined: - encoder.encodeInt32(19, forKey: "_rawValue") - case .phoneNumberRequest: - encoder.encodeInt32(20, forKey: "_rawValue") - } - } - - public var peerIds: [PeerId] { - switch self { - case let .addedMembers(peerIds): - return peerIds - case let .removedMembers(peerIds): - return peerIds - case let .joinedByLink(inviter): - return [inviter] - case let .channelMigratedFromGroup(_, groupId): - return [groupId] - case let .groupMigratedToChannel(channelId): - return [channelId] - default: - return [] - } - } -} - -public final class TelegramMediaAction: Media { - public let id: MediaId? = nil - public var peerIds: [PeerId] { - return self.action.peerIds - } - - public let action: TelegramMediaActionType - - public init(action: TelegramMediaActionType) { - self.action = action - } - - public init(decoder: PostboxDecoder) { - self.action = TelegramMediaActionType(decoder: decoder) - } - - public func encode(_ encoder: PostboxEncoder) { - self.action.encode(encoder) - } - - public func isEqual(to other: Media) -> Bool { - if let other = other as? TelegramMediaAction { - return self.action == other.action - } - return false - } - - public func isSemanticallyEqual(to other: Media) -> Bool { - return self.isEqual(to: other) - } -} +import SyncCore func telegramMediaActionFromApiAction(_ action: Api.MessageAction) -> TelegramMediaAction? { switch action { diff --git a/submodules/TelegramCore/TelegramCore/TelegramMediaFile.swift b/submodules/TelegramCore/TelegramCore/TelegramMediaFile.swift index 21eb30bc6c..04b5b56191 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramMediaFile.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramMediaFile.swift @@ -8,199 +8,7 @@ import Foundation import TelegramApi #endif - -private let typeFileName: Int32 = 0 -private let typeSticker: Int32 = 1 -private let typeImageSize: Int32 = 2 -private let typeAnimated: Int32 = 3 -private let typeVideo: Int32 = 4 -private let typeAudio: Int32 = 5 -private let typeHasLinkedStickers: Int32 = 6 - -public enum StickerPackReference: PostboxCoding, Hashable, Equatable { - case id(id: Int64, accessHash: Int64) - case name(String) - case animatedEmoji - - public init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("r", orElse: 0) { - case 0: - self = .id(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0)) - case 1: - self = .name(decoder.decodeStringForKey("n", orElse: "")) - case 2: - self = .animatedEmoji - default: - self = .name("") - assertionFailure() - } - } - - public func encode(_ encoder: PostboxEncoder) { - switch self { - case let .id(id, accessHash): - encoder.encodeInt32(0, forKey: "r") - encoder.encodeInt64(id, forKey: "i") - encoder.encodeInt64(accessHash, forKey: "h") - case let .name(name): - encoder.encodeInt32(1, forKey: "r") - encoder.encodeString(name, forKey: "n") - case .animatedEmoji: - encoder.encodeInt32(2, forKey: "r") - } - } - - public static func ==(lhs: StickerPackReference, rhs: StickerPackReference) -> Bool { - switch lhs { - case let .id(id, accessHash): - if case .id(id, accessHash) = rhs { - return true - } else { - return false - } - case let .name(name): - if case .name(name) = rhs { - return true - } else { - return false - } - case .animatedEmoji: - if case .animatedEmoji = rhs { - return true - } else { - return false - } - } - } -} - -public struct TelegramMediaVideoFlags: OptionSet { - public var rawValue: Int32 - - public init() { - self.rawValue = 0 - } - - public init(rawValue: Int32) { - self.rawValue = rawValue - } - - public static let instantRoundVideo = TelegramMediaVideoFlags(rawValue: 1 << 0) - public static let supportsStreaming = TelegramMediaVideoFlags(rawValue: 1 << 1) -} - -public struct StickerMaskCoords: PostboxCoding { - public let n: Int32 - public let x: Double - public let y: Double - public let zoom: Double - - public init(n: Int32, x: Double, y: Double, zoom: Double) { - self.n = n - self.x = x - self.y = y - self.zoom = zoom - } - - public init(decoder: PostboxDecoder) { - self.n = decoder.decodeInt32ForKey("n", orElse: 0) - self.x = decoder.decodeDoubleForKey("x", orElse: 0.0) - self.y = decoder.decodeDoubleForKey("y", orElse: 0.0) - self.zoom = decoder.decodeDoubleForKey("z", orElse: 0.0) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.n, forKey: "n") - encoder.encodeDouble(self.x, forKey: "x") - encoder.encodeDouble(self.y, forKey: "y") - encoder.encodeDouble(self.zoom, forKey: "z") - } -} - -public enum TelegramMediaFileAttribute: PostboxCoding { - case FileName(fileName: String) - case Sticker(displayText: String, packReference: StickerPackReference?, maskData: StickerMaskCoords?) - case ImageSize(size: CGSize) - case Animated - case Video(duration: Int, size: CGSize, flags: TelegramMediaVideoFlags) - case Audio(isVoice: Bool, duration: Int, title: String?, performer: String?, waveform: MemoryBuffer?) - case HasLinkedStickers - - public init(decoder: PostboxDecoder) { - let type: Int32 = decoder.decodeInt32ForKey("t", orElse: 0) - switch type { - case typeFileName: - self = .FileName(fileName: decoder.decodeStringForKey("fn", orElse: "")) - case typeSticker: - self = .Sticker(displayText: decoder.decodeStringForKey("dt", orElse: ""), packReference: decoder.decodeObjectForKey("pr", decoder: { StickerPackReference(decoder: $0) }) as? StickerPackReference, maskData: decoder.decodeObjectForKey("mc", decoder: { StickerMaskCoords(decoder: $0) }) as? StickerMaskCoords) - case typeImageSize: - self = .ImageSize(size: CGSize(width: CGFloat(decoder.decodeInt32ForKey("w", orElse: 0)), height: CGFloat(decoder.decodeInt32ForKey("h", orElse: 0)))) - case typeAnimated: - self = .Animated - case typeVideo: - self = .Video(duration: Int(decoder.decodeInt32ForKey("du", orElse: 0)), size: CGSize(width: CGFloat(decoder.decodeInt32ForKey("w", orElse: 0)), height: CGFloat(decoder.decodeInt32ForKey("h", orElse: 0))), flags: TelegramMediaVideoFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0))) - case typeAudio: - let waveformBuffer = decoder.decodeBytesForKeyNoCopy("wf") - var waveform: MemoryBuffer? - if let waveformBuffer = waveformBuffer { - waveform = MemoryBuffer(copyOf: waveformBuffer) - } - self = .Audio(isVoice: decoder.decodeInt32ForKey("iv", orElse: 0) != 0, duration: Int(decoder.decodeInt32ForKey("du", orElse: 0)), title: decoder.decodeOptionalStringForKey("ti"), performer: decoder.decodeOptionalStringForKey("pe"), waveform: waveform) - case typeHasLinkedStickers: - self = .HasLinkedStickers - default: - preconditionFailure() - } - } - - public func encode(_ encoder: PostboxEncoder) { - switch self { - case let .FileName(fileName): - encoder.encodeInt32(typeFileName, forKey: "t") - encoder.encodeString(fileName, forKey: "fn") - case let .Sticker(displayText, packReference, maskCoords): - encoder.encodeInt32(typeSticker, forKey: "t") - encoder.encodeString(displayText, forKey: "dt") - if let packReference = packReference { - encoder.encodeObject(packReference, forKey: "pr") - } else { - encoder.encodeNil(forKey: "pr") - } - if let maskCoords = maskCoords { - encoder.encodeObject(maskCoords, forKey: "mc") - } else { - encoder.encodeNil(forKey: "mc") - } - case let .ImageSize(size): - encoder.encodeInt32(typeImageSize, forKey: "t") - encoder.encodeInt32(Int32(size.width), forKey: "w") - encoder.encodeInt32(Int32(size.height), forKey: "h") - case .Animated: - encoder.encodeInt32(typeAnimated, forKey: "t") - case let .Video(duration, size, flags): - encoder.encodeInt32(typeVideo, forKey: "t") - encoder.encodeInt32(Int32(duration), forKey: "du") - encoder.encodeInt32(Int32(size.width), forKey: "w") - encoder.encodeInt32(Int32(size.height), forKey: "h") - encoder.encodeInt32(flags.rawValue, forKey: "f") - case let .Audio(isVoice, duration, title, performer, waveform): - encoder.encodeInt32(typeAudio, forKey: "t") - encoder.encodeInt32(isVoice ? 1 : 0, forKey: "iv") - encoder.encodeInt32(Int32(duration), forKey: "du") - if let title = title { - encoder.encodeString(title, forKey: "ti") - } - if let performer = performer { - encoder.encodeString(performer, forKey: "pe") - } - if let waveform = waveform { - encoder.encodeBytes(waveform, forKey: "wf") - } - case .HasLinkedStickers: - encoder.encodeInt32(typeHasLinkedStickers, forKey: "t") - } - } -} +import SyncCore func dimensionsForFileAttributes(_ attributes: [TelegramMediaFileAttribute]) -> CGSize? { for attribute in attributes { @@ -230,187 +38,8 @@ func durationForFileAttributes(_ attributes: [TelegramMediaFileAttribute]) -> In return nil } -public enum TelegramMediaFileReference: PostboxCoding, Equatable { - case cloud(fileId: Int64, accessHash: Int64, fileReference: Data?) - - public init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("_v", orElse: 0) { - case 0: - self = .cloud(fileId: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0), fileReference: decoder.decodeBytesForKey("fr")?.makeData()) - default: - self = .cloud(fileId: 0, accessHash: 0, fileReference: nil) - assertionFailure() - } - } - - public func encode(_ encoder: PostboxEncoder) { - switch self { - case let .cloud(imageId, accessHash, fileReference): - encoder.encodeInt32(0, forKey: "_v") - encoder.encodeInt64(imageId, forKey: "i") - encoder.encodeInt64(accessHash, forKey: "h") - if let fileReference = fileReference { - encoder.encodeBytes(MemoryBuffer(data: fileReference), forKey: "fr") - } else { - encoder.encodeNil(forKey: "fr") - } - } - } -} - -public final class TelegramMediaFile: Media, Equatable { - public let fileId: MediaId - public let partialReference: PartialMediaReference? - public let resource: TelegramMediaResource - public let previewRepresentations: [TelegramMediaImageRepresentation] - public let immediateThumbnailData: Data? - public let mimeType: String - public let size: Int? - public let attributes: [TelegramMediaFileAttribute] - public let peerIds: [PeerId] = [] - - public var id: MediaId? { - return self.fileId - } - - public init(fileId: MediaId, partialReference: PartialMediaReference?, resource: TelegramMediaResource, previewRepresentations: [TelegramMediaImageRepresentation], immediateThumbnailData: Data?, mimeType: String, size: Int?, attributes: [TelegramMediaFileAttribute]) { - self.fileId = fileId - self.partialReference = partialReference - self.resource = resource - self.previewRepresentations = previewRepresentations - self.immediateThumbnailData = immediateThumbnailData - self.mimeType = mimeType - self.size = size - self.attributes = attributes - } - - public init(decoder: PostboxDecoder) { - self.fileId = MediaId(decoder.decodeBytesForKeyNoCopy("i")!) - self.partialReference = decoder.decodeAnyObjectForKey("prf", decoder: { PartialMediaReference(decoder: $0) }) as? PartialMediaReference - self.resource = decoder.decodeObjectForKey("r") as? TelegramMediaResource ?? EmptyMediaResource() - self.previewRepresentations = decoder.decodeObjectArrayForKey("pr") - self.immediateThumbnailData = decoder.decodeDataForKey("itd") - self.mimeType = decoder.decodeStringForKey("mt", orElse: "") - if let size = decoder.decodeOptionalInt32ForKey("s") { - self.size = Int(size) - } else { - self.size = nil - } - self.attributes = decoder.decodeObjectArrayForKey("at") - } - - public func encode(_ encoder: PostboxEncoder) { - let buffer = WriteBuffer() - self.fileId.encodeToBuffer(buffer) - encoder.encodeBytes(buffer, forKey: "i") - if let partialReference = self.partialReference { - encoder.encodeObjectWithEncoder(partialReference, encoder: partialReference.encode, forKey: "prf") - } else { - encoder.encodeNil(forKey: "prf") - } - encoder.encodeObject(self.resource, forKey: "r") - encoder.encodeObjectArray(self.previewRepresentations, forKey: "pr") - if let immediateThumbnailData = self.immediateThumbnailData { - encoder.encodeData(immediateThumbnailData, forKey: "itd") - } else { - encoder.encodeNil(forKey: "itd") - } - encoder.encodeString(self.mimeType, forKey: "mt") - if let size = self.size { - encoder.encodeInt32(Int32(size), forKey: "s") - } else { - encoder.encodeNil(forKey: "s") - } - encoder.encodeObjectArray(self.attributes, forKey: "at") - } - - public var fileName: String? { - get { - for attribute in self.attributes { - switch attribute { - case let .FileName(fileName): - return fileName - case _: - break - } - } - return nil - } - } - - public var isSticker: Bool { - for attribute in self.attributes { - if case .Sticker = attribute { - return true - } - } - return false - } - - public var isStaticSticker: Bool { - for attribute in self.attributes { - if case .Sticker = attribute { - if let s = self.size, s < 200 * 1024 { - return !isAnimatedSticker - } - } - } - return false - } - - public var isVideo: Bool { - for attribute in self.attributes { - if case .Video = attribute { - return true - } - } - return false - } - - public var isInstantVideo: Bool { - for attribute in self.attributes { - if case .Video(_, _, let flags) = attribute { - return flags.contains(.instantRoundVideo) - } - } - return false - } - - public var isAnimated: Bool { - for attribute in self.attributes { - if case .Animated = attribute { - return true - } - } - return false - } - - public var isAnimatedSticker: Bool { - if let _ = self.fileName, self.mimeType == "application/x-tgsticker" { - return true - } - return false - } - - public var isMusic: Bool { - for attribute in self.attributes { - if case .Audio(false, _, _, _, _) = attribute { - return true - } - } - return false - } - - public var isVoice: Bool { - for attribute in self.attributes { - if case .Audio(true, _, _, _, _) = attribute { - return true - } - } - return false - } - - public var dimensions: CGSize? { +public extension TelegramMediaFile { + var dimensions: CGSize? { if let value = dimensionsForFileAttributes(self.attributes) { return value } else if self.isAnimatedSticker { @@ -420,107 +49,9 @@ public final class TelegramMediaFile: Media, Equatable { } } - public var duration: Int32? { + var duration: Int32? { return durationForFileAttributes(self.attributes) } - - public func isEqual(to other: Media) -> Bool { - guard let other = other as? TelegramMediaFile else { - return false - } - - if self.fileId != other.fileId { - return false - } - - if self.partialReference != other.partialReference { - return false - } - - if !self.resource.isEqual(to: other.resource) { - return false - } - - if self.previewRepresentations != other.previewRepresentations { - return false - } - - if self.immediateThumbnailData != other.immediateThumbnailData { - return false - } - - if self.size != other.size { - return false - } - - if self.mimeType != other.mimeType { - return false - } - - return true - } - - public func isSemanticallyEqual(to other: Media) -> Bool { - guard let other = other as? TelegramMediaFile else { - return false - } - - if self.fileId != other.fileId { - return false - } - - if self.partialReference != other.partialReference { - return false - } - - if !self.resource.id.isEqual(to: other.resource.id) { - return false - } - - if self.previewRepresentations.count != other.previewRepresentations.count { - return false - } - - for i in 0 ..< self.previewRepresentations.count { - if !self.previewRepresentations[i].isSemanticallyEqual(to: other.previewRepresentations[i]) { - return false - } - } - - if self.immediateThumbnailData != other.immediateThumbnailData { - return false - } - - if self.size != other.size { - return false - } - - if self.mimeType != other.mimeType { - return false - } - - return true - } - - public func withUpdatedPartialReference(_ partialReference: PartialMediaReference?) -> TelegramMediaFile { - return TelegramMediaFile(fileId: self.fileId, partialReference: partialReference, resource: self.resource, previewRepresentations: self.previewRepresentations, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: self.size, attributes: self.attributes) - } - - public func withUpdatedSize(_ size: Int?) -> TelegramMediaFile { - return TelegramMediaFile(fileId: self.fileId, partialReference: self.partialReference, resource: self.resource, previewRepresentations: self.previewRepresentations, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: size, attributes: self.attributes) - } - - public func withUpdatedPreviewRepresentations(_ previewRepresentations: [TelegramMediaImageRepresentation]) -> TelegramMediaFile { - return TelegramMediaFile(fileId: self.fileId, partialReference: self.partialReference, resource: self.resource, previewRepresentations: previewRepresentations, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: self.size, attributes: self.attributes) - } - - public func withUpdatedAttributes(_ attributes: [TelegramMediaFileAttribute]) -> TelegramMediaFile { - return TelegramMediaFile(fileId: self.fileId, partialReference: self.partialReference, resource: self.resource, previewRepresentations: self.previewRepresentations, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: self.size, attributes: attributes) - } -} - -public func ==(lhs: TelegramMediaFile, rhs: TelegramMediaFile) -> Bool { - return lhs.isEqual(to: rhs) } extension StickerPackReference { diff --git a/submodules/TelegramCore/TelegramCore/TelegramMediaGame.swift b/submodules/TelegramCore/TelegramCore/TelegramMediaGame.swift index bbf2b1a1ee..667f9c84dc 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramMediaGame.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramMediaGame.swift @@ -7,106 +7,7 @@ import Foundation import TelegramApi #endif -public final class TelegramMediaGame: Media { - public let gameId: Int64 - public let accessHash: Int64 - public let name: String - public let title: String - public let description: String - public let image: TelegramMediaImage? - public let file: TelegramMediaFile? - - public var id: MediaId? { - return MediaId(namespace: Namespaces.Media.CloudGame, id: self.gameId) - } - public let peerIds: [PeerId] = [] - - init(gameId: Int64, accessHash: Int64, name: String, title: String, description: String, image: TelegramMediaImage?, file: TelegramMediaFile?) { - self.gameId = gameId - self.accessHash = accessHash - self.name = name - self.title = title - self.description = description - self.image = image - self.file = file - } - - public init(decoder: PostboxDecoder) { - self.gameId = decoder.decodeInt64ForKey("i", orElse: 0) - self.accessHash = decoder.decodeInt64ForKey("h", orElse: 0) - self.name = decoder.decodeStringForKey("n", orElse: "") - self.title = decoder.decodeStringForKey("t", orElse: "") - self.description = decoder.decodeStringForKey("d", orElse: "") - self.image = decoder.decodeObjectForKey("p") as? TelegramMediaImage - self.file = decoder.decodeObjectForKey("f") as? TelegramMediaFile - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt64(self.gameId, forKey: "i") - encoder.encodeInt64(self.accessHash, forKey: "h") - encoder.encodeString(self.name, forKey: "n") - encoder.encodeString(self.title, forKey: "t") - encoder.encodeString(self.description, forKey: "d") - if let image = self.image { - encoder.encodeObject(image, forKey: "p") - } else { - encoder.encodeNil(forKey: "p") - } - if let file = self.file { - encoder.encodeObject(file, forKey: "f") - } else { - encoder.encodeNil(forKey: "f") - } - } - - public func isEqual(to other: Media) -> Bool { - guard let other = other as? TelegramMediaGame else { - return false - } - - if self.gameId != other.gameId { - return false - } - - if self.accessHash != other.accessHash { - return false - } - - if self.name != other.name { - return false - } - - if self.title != other.title { - return false - } - - if self.description != other.description { - return false - } - - if let lhsImage = self.image, let rhsImage = other.image { - if !lhsImage.isEqual(to: rhsImage) { - return false - } - } else if (self.image != nil) != (other.image != nil) { - return false - } - - if let lhsFile = self.file, let rhsFile = other.file { - if !lhsFile.isEqual(to: rhsFile) { - return false - } - } else if (self.file != nil) != (other.file != nil) { - return false - } - - return true - } - - public func isSemanticallyEqual(to other: Media) -> Bool { - return self.isEqual(to: other) - } -} +import SyncCore extension TelegramMediaGame { convenience init(apiGame: Api.Game) { diff --git a/submodules/TelegramCore/TelegramCore/TelegramMediaImage.swift b/submodules/TelegramCore/TelegramCore/TelegramMediaImage.swift index 310f7249d8..37fe0616ab 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramMediaImage.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramMediaImage.swift @@ -8,216 +8,7 @@ import Foundation import TelegramApi #endif -public enum TelegramMediaImageReference: PostboxCoding, Equatable { - case cloud(imageId: Int64, accessHash: Int64, fileReference: Data?) - - public init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("_v", orElse: 0) { - case 0: - self = .cloud(imageId: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0), fileReference: decoder.decodeBytesForKey("fr")?.makeData()) - default: - self = .cloud(imageId: 0, accessHash: 0, fileReference: nil) - assertionFailure() - } - } - - public func encode(_ encoder: PostboxEncoder) { - switch self { - case let .cloud(imageId, accessHash, fileReference): - encoder.encodeInt32(0, forKey: "_v") - encoder.encodeInt64(imageId, forKey: "i") - encoder.encodeInt64(accessHash, forKey: "h") - if let fileReference = fileReference { - encoder.encodeBytes(MemoryBuffer(data: fileReference), forKey: "fr") - } else { - encoder.encodeNil(forKey: "fr") - } - } - } - - public static func ==(lhs: TelegramMediaImageReference, rhs: TelegramMediaImageReference) -> Bool { - switch lhs { - case let .cloud(imageId, accessHash, fileReference): - if case .cloud(imageId, accessHash, fileReference) = rhs { - return true - } else { - return false - } - } - } -} - -public final class TelegramMediaImage: Media, Equatable { - public let imageId: MediaId - public let representations: [TelegramMediaImageRepresentation] - public let immediateThumbnailData: Data? - public let reference: TelegramMediaImageReference? - public let partialReference: PartialMediaReference? - public let peerIds: [PeerId] = [] - - public var id: MediaId? { - return self.imageId - } - - public init(imageId: MediaId, representations: [TelegramMediaImageRepresentation], immediateThumbnailData: Data?, reference: TelegramMediaImageReference?, partialReference: PartialMediaReference?) { - self.imageId = imageId - self.representations = representations - self.immediateThumbnailData = immediateThumbnailData - self.reference = reference - self.partialReference = partialReference - } - - public init(decoder: PostboxDecoder) { - self.imageId = MediaId(decoder.decodeBytesForKeyNoCopy("i")!) - self.representations = decoder.decodeObjectArrayForKey("r") - self.immediateThumbnailData = decoder.decodeDataForKey("itd") - self.reference = decoder.decodeObjectForKey("rf", decoder: { TelegramMediaImageReference(decoder: $0) }) as? TelegramMediaImageReference - self.partialReference = decoder.decodeAnyObjectForKey("prf", decoder: { PartialMediaReference(decoder: $0) }) as? PartialMediaReference - } - - public func encode(_ encoder: PostboxEncoder) { - let buffer = WriteBuffer() - self.imageId.encodeToBuffer(buffer) - encoder.encodeBytes(buffer, forKey: "i") - encoder.encodeObjectArray(self.representations, forKey: "r") - if let immediateThumbnailData = self.immediateThumbnailData { - encoder.encodeData(immediateThumbnailData, forKey: "itd") - } else { - encoder.encodeNil(forKey: "itd") - } - if let reference = self.reference { - encoder.encodeObject(reference, forKey: "rf") - } else { - encoder.encodeNil(forKey: "rf") - } - if let partialReference = self.partialReference { - encoder.encodeObjectWithEncoder(partialReference, encoder: partialReference.encode, forKey: "prf") - } else { - encoder.encodeNil(forKey: "prf") - } - } - - public func representationForDisplayAtSize(_ size: CGSize) -> TelegramMediaImageRepresentation? { - if self.representations.count == 0 { - return nil - } else { - var dimensions = self.representations[0].dimensions - var index = 0 - - for i in 0 ..< self.representations.count { - let representationDimensions = self.representations[i].dimensions - - if dimensions.width >= size.width - CGFloat.ulpOfOne && dimensions.height >= size.height - CGFloat.ulpOfOne { - if representationDimensions.width >= size.width && representationDimensions.height >= dimensions.height && representationDimensions.width < dimensions.width && representationDimensions.height < dimensions.height { - dimensions = representationDimensions - index = i - } - } else { - if representationDimensions.width >= dimensions.width && representationDimensions.height >= dimensions.height { - dimensions = representationDimensions - index = i - } - } - } - - return self.representations[index] - } - } - - public func isEqual(to other: Media) -> Bool { - if let other = other as? TelegramMediaImage { - if other.imageId != self.imageId { - return false - } - if other.representations != self.representations { - return false - } - if other.immediateThumbnailData != self.immediateThumbnailData { - return false - } - if self.partialReference != other.partialReference { - return false - } - return true - } - return false - } - - public func isSemanticallyEqual(to other: Media) -> Bool { - if let other = other as? TelegramMediaImage { - if other.imageId != self.imageId { - return false - } - if other.representations.count != self.representations.count { - return false - } - for i in 0 ..< self.representations.count { - if !self.representations[i].isSemanticallyEqual(to: other.representations[i]) { - return false - } - } - - if self.partialReference != other.partialReference { - return false - } - return true - } - return false - } - - public static func ==(lhs: TelegramMediaImage, rhs: TelegramMediaImage) -> Bool { - return lhs.isEqual(to: rhs) - } - - public func withUpdatedPartialReference(_ partialReference: PartialMediaReference?) -> TelegramMediaImage { - return TelegramMediaImage(imageId: self.imageId, representations: self.representations, immediateThumbnailData: self.immediateThumbnailData, reference: self.reference, partialReference: partialReference) - } -} - -public final class TelegramMediaImageRepresentation: PostboxCoding, Equatable, CustomStringConvertible { - public let dimensions: CGSize - public let resource: TelegramMediaResource - - public init(dimensions: CGSize, resource: TelegramMediaResource) { - self.dimensions = dimensions - self.resource = resource - } - - public init(decoder: PostboxDecoder) { - self.dimensions = CGSize(width: CGFloat(decoder.decodeInt32ForKey("dx", orElse: 0)), height: CGFloat(decoder.decodeInt32ForKey("dy", orElse: 0))) - self.resource = decoder.decodeObjectForKey("r") as? TelegramMediaResource ?? EmptyMediaResource() - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(Int32(self.dimensions.width), forKey: "dx") - encoder.encodeInt32(Int32(self.dimensions.height), forKey: "dy") - encoder.encodeObject(self.resource, forKey: "r") - } - - public var description: String { - return "(\(Int(dimensions.width))x\(Int(dimensions.height)))" - } - - public func isSemanticallyEqual(to other: TelegramMediaImageRepresentation) -> Bool { - if self.dimensions != other.dimensions { - return false - } - if !self.resource.id.isEqual(to: other.resource.id) { - return false - } - return true - } -} - -public func ==(lhs: TelegramMediaImageRepresentation, rhs: TelegramMediaImageRepresentation) -> Bool { - if lhs.dimensions != rhs.dimensions { - return false - } - if !lhs.resource.isEqual(to: rhs.resource) { - return false - } - return true -} +import SyncCore func telegramMediaImageRepresentationsFromApiSizes(datacenterId: Int32, photoId: Int64, accessHash: Int64, fileReference: Data?, sizes: [Api.PhotoSize]) -> (immediateThumbnail: Data?, representations: [TelegramMediaImageRepresentation]) { var immediateThumbnailData: Data? diff --git a/submodules/TelegramCore/TelegramCore/TelegramMediaMap.swift b/submodules/TelegramCore/TelegramCore/TelegramMediaMap.swift index c06b658f11..4ba223ba83 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramMediaMap.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramMediaMap.swift @@ -7,205 +7,7 @@ import Foundation import TelegramApi #endif -public final class NamedGeoPlace: PostboxCoding, Equatable { - public let country: String? - public let state: String? - public let city: String? - public let district: String? - public let street: String? - - public init(country: String?, state: String?, city: String?, district: String?, street: String?) { - self.country = country - self.state = state - self.city = city - self.district = district - self.street = street - } - - public init(decoder: PostboxDecoder) { - self.country = decoder.decodeOptionalStringForKey("gp_co") - self.state = decoder.decodeOptionalStringForKey("gp_sta") - self.city = decoder.decodeOptionalStringForKey("gp_ci") - self.district = decoder.decodeOptionalStringForKey("gp_dis") - self.street = decoder.decodeOptionalStringForKey("gp_str") - } - - public func encode(_ encoder: PostboxEncoder) { - if let country = self.country { - encoder.encodeString(country, forKey: "gp_co") - } - - if let state = self.state { - encoder.encodeString(state, forKey: "gp_sta") - } - - if let city = self.city { - encoder.encodeString(city, forKey: "gp_ci") - } - - if let district = self.district { - encoder.encodeString(district, forKey: "gp_dis") - } - - if let street = self.street { - encoder.encodeString(street, forKey: "gp_str") - } - } - - public static func ==(lhs: NamedGeoPlace, rhs: NamedGeoPlace) -> Bool { - if lhs.country != rhs.country { - return false - } - if lhs.state != rhs.state { - return false - } - if lhs.city != rhs.city { - return false - } - if lhs.district != rhs.district { - return false - } - if lhs.street != rhs.street { - return false - } - return true - } -} - -public final class MapVenue: PostboxCoding, Equatable { - public let title: String - public let address: String? - public let provider: String? - public let id: String? - public let type: String? - - public init(title: String, address: String?, provider: String?, id: String?, type: String?) { - self.title = title - self.address = address - self.provider = provider - self.id = id - self.type = type - } - - public init(decoder: PostboxDecoder) { - self.title = decoder.decodeStringForKey("ti", orElse: "") - self.address = decoder.decodeOptionalStringForKey("ad") - self.provider = decoder.decodeOptionalStringForKey("pr") - self.id = decoder.decodeOptionalStringForKey("id") - self.type = decoder.decodeOptionalStringForKey("ty") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.title, forKey: "ti") - - if let address = self.address { - encoder.encodeString(address, forKey: "ad") - } else { - encoder.encodeNil(forKey: "ad") - } - if let provider = self.provider { - encoder.encodeString(provider, forKey: "pr") - } else { - encoder.encodeNil(forKey: "pr") - } - if let id = self.id { - encoder.encodeString(id, forKey: "id") - } else { - encoder.encodeNil(forKey: "id") - } - if let type = self.type { - encoder.encodeString(type, forKey: "ty") - } else { - encoder.encodeNil(forKey: "ty") - } - } - - public static func ==(lhs: MapVenue, rhs: MapVenue) -> Bool { - if lhs.address != rhs.address { - return false - } - if lhs.provider != rhs.provider { - return false - } - if lhs.id != rhs.id { - return false - } - if lhs.type != rhs.type { - return false - } - return true - } -} - -public final class TelegramMediaMap: Media { - public let latitude: Double - public let longitude: Double - public let geoPlace: NamedGeoPlace? - public let venue: MapVenue? - public let liveBroadcastingTimeout: Int32? - - public let id: MediaId? = nil - public let peerIds: [PeerId] = [] - - public init(latitude: Double, longitude: Double, geoPlace: NamedGeoPlace?, venue: MapVenue?, liveBroadcastingTimeout: Int32?) { - self.latitude = latitude - self.longitude = longitude - self.geoPlace = geoPlace - self.venue = venue - self.liveBroadcastingTimeout = liveBroadcastingTimeout - } - - public init(decoder: PostboxDecoder) { - self.latitude = decoder.decodeDoubleForKey("la", orElse: 0.0) - self.longitude = decoder.decodeDoubleForKey("lo", orElse: 0.0) - self.geoPlace = decoder.decodeObjectForKey("gp", decoder: { NamedGeoPlace(decoder: $0) }) as? NamedGeoPlace - self.venue = decoder.decodeObjectForKey("ve", decoder: { MapVenue(decoder: $0) }) as? MapVenue - self.liveBroadcastingTimeout = decoder.decodeOptionalInt32ForKey("bt") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeDouble(self.latitude, forKey: "la") - encoder.encodeDouble(self.longitude, forKey: "lo") - if let geoPlace = self.geoPlace { - encoder.encodeObject(geoPlace, forKey: "gp") - } else { - encoder.encodeNil(forKey: "gp") - } - if let venue = self.venue { - encoder.encodeObject(venue, forKey: "ve") - } else { - encoder.encodeNil(forKey: "ve") - } - if let liveBroadcastingTimeout = self.liveBroadcastingTimeout { - encoder.encodeInt32(liveBroadcastingTimeout, forKey: "bt") - } else { - encoder.encodeNil(forKey: "bt") - } - } - - public func isEqual(to other: Media) -> Bool { - if let other = other as? TelegramMediaMap { - if self.latitude != other.latitude || self.longitude != other.longitude { - return false - } - if self.geoPlace != other.geoPlace { - return false - } - if self.venue != other.venue { - return false - } - if self.liveBroadcastingTimeout != other.liveBroadcastingTimeout { - return false - } - return true - } - return false - } - - public func isSemanticallyEqual(to other: Media) -> Bool { - return self.isEqual(to: other) - } -} +import SyncCore func telegramMediaMapFromApiGeoPoint(_ geo: Api.GeoPoint, title: String?, address: String?, provider: String?, venueId: String?, venueType: String?, liveBroadcastingTimeout: Int32?) -> TelegramMediaMap { var venue: MapVenue? diff --git a/submodules/TelegramCore/TelegramCore/TelegramMediaPoll.swift b/submodules/TelegramCore/TelegramCore/TelegramMediaPoll.swift index 348a91a29a..6567b5bfc5 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramMediaPoll.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramMediaPoll.swift @@ -7,25 +7,7 @@ import Postbox import TelegramApi #endif -public struct TelegramMediaPollOption: Equatable, PostboxCoding { - public let text: String - public let opaqueIdentifier: Data - - public init(text: String, opaqueIdentifier: Data) { - self.text = text - self.opaqueIdentifier = opaqueIdentifier - } - - public init(decoder: PostboxDecoder) { - self.text = decoder.decodeStringForKey("t", orElse: "") - self.opaqueIdentifier = decoder.decodeDataForKey("i") ?? Data() - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.text, forKey: "t") - encoder.encodeData(self.opaqueIdentifier, forKey: "i") - } -} +import SyncCore extension TelegramMediaPollOption { init(apiOption: Api.PollAnswer) { @@ -40,30 +22,6 @@ extension TelegramMediaPollOption { } } -public struct TelegramMediaPollOptionVoters: Equatable, PostboxCoding { - public let selected: Bool - public let opaqueIdentifier: Data - public let count: Int32 - - public init(selected: Bool, opaqueIdentifier: Data, count: Int32) { - self.selected = selected - self.opaqueIdentifier = opaqueIdentifier - self.count = count - } - - public init(decoder: PostboxDecoder) { - self.selected = decoder.decodeInt32ForKey("s", orElse: 0) != 0 - self.opaqueIdentifier = decoder.decodeDataForKey("i") ?? Data() - self.count = decoder.decodeInt32ForKey("c", orElse: 0) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.selected ? 1 : 0, forKey: "s") - encoder.encodeData(self.opaqueIdentifier, forKey: "i") - encoder.encodeInt32(self.count, forKey: "c") - } -} - extension TelegramMediaPollOptionVoters { init(apiVoters: Api.PollAnswerVoters) { switch apiVoters { @@ -73,34 +31,6 @@ extension TelegramMediaPollOptionVoters { } } -public struct TelegramMediaPollResults: Equatable, PostboxCoding { - public let voters: [TelegramMediaPollOptionVoters]? - public let totalVoters: Int32? - - public init(voters: [TelegramMediaPollOptionVoters]?, totalVoters: Int32?) { - self.voters = voters - self.totalVoters = totalVoters - } - - public init(decoder: PostboxDecoder) { - self.voters = decoder.decodeOptionalObjectArrayWithDecoderForKey("v") - self.totalVoters = decoder.decodeOptionalInt32ForKey("t") - } - - public func encode(_ encoder: PostboxEncoder) { - if let voters = self.voters { - encoder.encodeObjectArray(voters, forKey: "v") - } else { - encoder.encodeNil(forKey: "v") - } - if let totalVoters = self.totalVoters { - encoder.encodeInt32(totalVoters, forKey: "t") - } else { - encoder.encodeNil(forKey: "t") - } - } -} - extension TelegramMediaPollResults { init(apiResults: Api.PollResults) { switch apiResults { @@ -109,98 +39,3 @@ extension TelegramMediaPollResults { } } } - -public final class TelegramMediaPoll: Media, Equatable { - public var id: MediaId? { - return self.pollId - } - public let pollId: MediaId - public let peerIds: [PeerId] = [] - - public let text: String - public let options: [TelegramMediaPollOption] - public let results: TelegramMediaPollResults - public let isClosed: Bool - - public init(pollId: MediaId, text: String, options: [TelegramMediaPollOption], results: TelegramMediaPollResults, isClosed: Bool) { - self.pollId = pollId - self.text = text - self.options = options - self.results = results - self.isClosed = isClosed - } - - public init(decoder: PostboxDecoder) { - if let idBytes = decoder.decodeBytesForKeyNoCopy("i") { - self.pollId = MediaId(idBytes) - } else { - self.pollId = MediaId(namespace: Namespaces.Media.LocalPoll, id: 0) - } - self.text = decoder.decodeStringForKey("t", orElse: "") - self.options = decoder.decodeObjectArrayWithDecoderForKey("os") - self.results = decoder.decodeObjectForKey("rs", decoder: { TelegramMediaPollResults(decoder: $0) }) as? TelegramMediaPollResults ?? TelegramMediaPollResults(voters: nil, totalVoters: nil) - self.isClosed = decoder.decodeInt32ForKey("ic", orElse: 0) != 0 - } - - public func encode(_ encoder: PostboxEncoder) { - let buffer = WriteBuffer() - self.pollId.encodeToBuffer(buffer) - encoder.encodeBytes(buffer, forKey: "i") - encoder.encodeString(self.text, forKey: "t") - encoder.encodeObjectArray(self.options, forKey: "os") - encoder.encodeObject(results, forKey: "rs") - encoder.encodeInt32(self.isClosed ? 1 : 0, forKey: "ic") - } - - public func isEqual(to other: Media) -> Bool { - guard let other = other as? TelegramMediaPoll else { - return false - } - return self == other - } - - public func isSemanticallyEqual(to other: Media) -> Bool { - return self.isEqual(to: other) - } - - public static func ==(lhs: TelegramMediaPoll, rhs: TelegramMediaPoll) -> Bool { - if lhs.pollId != rhs.pollId { - return false - } - if lhs.text != rhs.text { - return false - } - if lhs.options != rhs.options { - return false - } - if lhs.results != rhs.results { - return false - } - if lhs.isClosed != rhs.isClosed { - return false - } - return true - } - - func withUpdatedResults(_ results: TelegramMediaPollResults, min: Bool) -> TelegramMediaPoll { - let updatedResults: TelegramMediaPollResults - if min { - if let currentVoters = self.results.voters, let updatedVoters = results.voters { - var selectedOpaqueIdentifiers = Set() - for voters in currentVoters { - if voters.selected { - selectedOpaqueIdentifiers.insert(voters.opaqueIdentifier) - } - } - updatedResults = TelegramMediaPollResults(voters: updatedVoters.map({ voters in - return TelegramMediaPollOptionVoters(selected: selectedOpaqueIdentifiers.contains(voters.opaqueIdentifier), opaqueIdentifier: voters.opaqueIdentifier, count: voters.count) - }), totalVoters: results.totalVoters) - } else { - updatedResults = TelegramMediaPollResults(voters: self.results.voters, totalVoters: results.totalVoters) - } - } else { - updatedResults = results - } - return TelegramMediaPoll(pollId: self.pollId, text: self.text, options: self.options, results: updatedResults, isClosed: self.isClosed) - } -} diff --git a/submodules/TelegramCore/TelegramCore/TelegramMediaWebDocument.swift b/submodules/TelegramCore/TelegramCore/TelegramMediaWebDocument.swift index a49a6dec59..acd4a64b39 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramMediaWebDocument.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramMediaWebDocument.swift @@ -8,71 +8,7 @@ import Foundation import TelegramApi #endif - -public class TelegramMediaWebFile: Media { - public let resource: TelegramMediaResource - public let mimeType: String - public let size: Int32 - public let attributes: [TelegramMediaFileAttribute] - public let peerIds: [PeerId] = [] - - public var id: MediaId? { - return nil - } - - public init(resource: TelegramMediaResource, mimeType: String, size: Int32, attributes: [TelegramMediaFileAttribute]) { - self.resource = resource - self.mimeType = mimeType - self.size = size - self.attributes = attributes - } - - public required init(decoder: PostboxDecoder) { - self.resource = decoder.decodeObjectForKey("r") as! TelegramMediaResource - self.mimeType = decoder.decodeStringForKey("mt", orElse: "") - self.size = decoder.decodeInt32ForKey("s", orElse: 0) - self.attributes = decoder.decodeObjectArrayForKey("at") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeObject(self.resource, forKey: "r") - encoder.encodeString(self.mimeType, forKey: "mt") - encoder.encodeInt32(self.size, forKey: "s") - encoder.encodeObjectArray(self.attributes, forKey: "at") - } - - public func isEqual(to other: Media) -> Bool { - guard let other = other as? TelegramMediaWebFile else { - return false - } - - if !self.resource.isEqual(to: other.resource) { - return false - } - - if self.size != other.size { - return false - } - - if self.mimeType != other.mimeType { - return false - } - - return true - } - - public func isSemanticallyEqual(to other: Media) -> Bool { - return self.isEqual(to: other) - } - - public var dimensions: CGSize? { - return dimensionsForFileAttributes(self.attributes) - } - - public var duration: Int32? { - return durationForFileAttributes(self.attributes) - } -} +import SyncCore extension TelegramMediaWebFile { convenience init(_ document: Api.WebDocument) { diff --git a/submodules/TelegramCore/TelegramCore/TelegramMediaWebFile.swift b/submodules/TelegramCore/TelegramCore/TelegramMediaWebFile.swift new file mode 100644 index 0000000000..0c147a9b57 --- /dev/null +++ b/submodules/TelegramCore/TelegramCore/TelegramMediaWebFile.swift @@ -0,0 +1,13 @@ +import Postbox +import SyncCore +import UIKit + +public extension TelegramMediaWebFile { + public var dimensions: CGSize? { + return dimensionsForFileAttributes(self.attributes) + } + + public var duration: Int32? { + return durationForFileAttributes(self.attributes) + } +} diff --git a/submodules/TelegramCore/TelegramCore/TelegramMediaWebpage.swift b/submodules/TelegramCore/TelegramCore/TelegramMediaWebpage.swift index 3df9e9b6a4..fa97738796 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramMediaWebpage.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramMediaWebpage.swift @@ -8,305 +8,7 @@ import Foundation import TelegramApi #endif -public final class TelegramMediaWebpageLoadedContent: PostboxCoding, Equatable { - public let url: String - public let displayUrl: String - public let hash: Int32 - public let type: String? - public let websiteName: String? - public let title: String? - public let text: String? - public let embedUrl: String? - public let embedType: String? - public let embedSize: CGSize? - public let duration: Int? - public let author: String? - - public let image: TelegramMediaImage? - public let file: TelegramMediaFile? - public let files: [TelegramMediaFile]? - public let instantPage: InstantPage? - - public init(url: String, displayUrl: String, hash: Int32, type: String?, websiteName: String?, title: String?, text: String?, embedUrl: String?, embedType: String?, embedSize: CGSize?, duration: Int?, author: String?, image: TelegramMediaImage?, file: TelegramMediaFile?, files: [TelegramMediaFile]?, instantPage: InstantPage?) { - self.url = url - self.displayUrl = displayUrl - self.hash = hash - self.type = type - self.websiteName = websiteName - self.title = title - self.text = text - self.embedUrl = embedUrl - self.embedType = embedType - self.embedSize = embedSize - self.duration = duration - self.author = author - self.image = image - self.file = file - self.files = files - self.instantPage = instantPage - } - - public init(decoder: PostboxDecoder) { - self.url = decoder.decodeStringForKey("u", orElse: "") - self.displayUrl = decoder.decodeStringForKey("d", orElse: "") - self.hash = decoder.decodeInt32ForKey("ha", orElse: 0) - self.type = decoder.decodeOptionalStringForKey("ty") - self.websiteName = decoder.decodeOptionalStringForKey("ws") - self.title = decoder.decodeOptionalStringForKey("ti") - self.text = decoder.decodeOptionalStringForKey("tx") - self.embedUrl = decoder.decodeOptionalStringForKey("eu") - self.embedType = decoder.decodeOptionalStringForKey("et") - if let embedSizeWidth = decoder.decodeOptionalInt32ForKey("esw"), let embedSizeHeight = decoder.decodeOptionalInt32ForKey("esh") { - self.embedSize = CGSize(width: CGFloat(embedSizeWidth), height: CGFloat(embedSizeHeight)) - } else { - self.embedSize = nil - } - if let duration = decoder.decodeOptionalInt32ForKey("du") { - self.duration = Int(duration) - } else { - self.duration = nil - } - self.author = decoder.decodeOptionalStringForKey("au") - - if let image = decoder.decodeObjectForKey("im") as? TelegramMediaImage { - self.image = image - } else { - self.image = nil - } - - if let file = decoder.decodeObjectForKey("fi") as? TelegramMediaFile { - self.file = file - } else { - self.file = nil - } - - self.files = decoder.decodeOptionalObjectArrayWithDecoderForKey("fis") - - if let instantPage = decoder.decodeObjectForKey("ip", decoder: { InstantPage(decoder: $0) }) as? InstantPage { - self.instantPage = instantPage - } else { - self.instantPage = nil - } - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeString(self.url, forKey: "u") - encoder.encodeString(self.displayUrl, forKey: "d") - encoder.encodeInt32(self.hash, forKey: "ha") - if let type = self.type { - encoder.encodeString(type, forKey: "ty") - } else { - encoder.encodeNil(forKey: "ty") - } - if let websiteName = self.websiteName { - encoder.encodeString(websiteName, forKey: "ws") - } else { - encoder.encodeNil(forKey: "ws") - } - if let title = self.title { - encoder.encodeString(title, forKey: "ti") - } else { - encoder.encodeNil(forKey: "ti") - } - if let text = self.text { - encoder.encodeString(text, forKey: "tx") - } else { - encoder.encodeNil(forKey: "tx") - } - if let embedUrl = self.embedUrl { - encoder.encodeString(embedUrl, forKey: "eu") - } else { - encoder.encodeNil(forKey: "eu") - } - if let embedType = self.embedType { - encoder.encodeString(embedType, forKey: "et") - } else { - encoder.encodeNil(forKey: "et") - } - if let embedSize = self.embedSize { - encoder.encodeInt32(Int32(embedSize.width), forKey: "esw") - encoder.encodeInt32(Int32(embedSize.height), forKey: "esh") - } else { - encoder.encodeNil(forKey: "esw") - encoder.encodeNil(forKey: "esh") - } - if let duration = self.duration { - encoder.encodeInt32(Int32(duration), forKey: "du") - } else { - encoder.encodeNil(forKey: "du") - } - if let author = self.author { - encoder.encodeString(author, forKey: "au") - } else { - encoder.encodeNil(forKey: "au") - } - if let image = self.image { - encoder.encodeObject(image, forKey: "im") - } else { - encoder.encodeNil(forKey: "im") - } - if let file = self.file { - encoder.encodeObject(file, forKey: "fi") - } else { - encoder.encodeNil(forKey: "fi") - } - if let files = self.files { - encoder.encodeObjectArray(files, forKey: "fis") - } else { - encoder.encodeNil(forKey: "fis") - } - if let instantPage = self.instantPage { - encoder.encodeObject(instantPage, forKey: "ip") - } else { - encoder.encodeNil(forKey: "ip") - } - } -} - -public func ==(lhs: TelegramMediaWebpageLoadedContent, rhs: TelegramMediaWebpageLoadedContent) -> Bool { - if lhs.url != rhs.url - || lhs.displayUrl != rhs.displayUrl - || lhs.hash != rhs.hash - || lhs.type != rhs.type - || lhs.websiteName != rhs.websiteName - || lhs.title != rhs.title - || lhs.text != rhs.text - || lhs.embedUrl != rhs.embedUrl - || lhs.embedType != rhs.embedType - || lhs.embedSize != rhs.embedSize - || lhs.duration != rhs.duration - || lhs.author != rhs.author { - return false - } - - if let lhsImage = lhs.image, let rhsImage = rhs.image { - if !lhsImage.isEqual(to: rhsImage) { - return false - } - } else if (lhs.image == nil) != (rhs.image == nil) { - return false - } - - if let lhsFile = lhs.file, let rhsFile = rhs.file { - if !lhsFile.isEqual(to: rhsFile) { - return false - } - } else if (lhs.file == nil) != (rhs.file == nil) { - return false - } - - if let lhsFiles = lhs.files, let rhsFiles = rhs.files { - if lhsFiles.count != rhsFiles.count { - return false - } else { - for i in 0 ..< lhsFiles.count { - if !lhsFiles[i].isEqual(to: rhsFiles[i]) { - return false - } - } - } - } else if (lhs.files == nil) != (rhs.files == nil) { - return false - } - - if lhs.instantPage != rhs.instantPage { - return false - } - - return true -} - -public enum TelegramMediaWebpageContent { - case Pending(Int32, String?) - case Loaded(TelegramMediaWebpageLoadedContent) -} - -public final class TelegramMediaWebpage: Media, Equatable { - public var id: MediaId? { - return self.webpageId - } - public let peerIds: [PeerId] = [] - - public let webpageId: MediaId - public let content: TelegramMediaWebpageContent - - public init(webpageId: MediaId, content: TelegramMediaWebpageContent) { - self.webpageId = webpageId - self.content = content - } - - public init(decoder: PostboxDecoder) { - self.webpageId = MediaId(decoder.decodeBytesForKeyNoCopy("i")!) - - if decoder.decodeInt32ForKey("ct", orElse: 0) == 0 { - self.content = .Pending(decoder.decodeInt32ForKey("pendingDate", orElse: 0), decoder.decodeOptionalStringForKey("pendingUrl")) - } else { - self.content = .Loaded(TelegramMediaWebpageLoadedContent(decoder: decoder)) - } - } - - public func encode(_ encoder: PostboxEncoder) { - let buffer = WriteBuffer() - self.webpageId.encodeToBuffer(buffer) - encoder.encodeBytes(buffer, forKey: "i") - - switch self.content { - case let .Pending(date, url): - encoder.encodeInt32(0, forKey: "ct") - encoder.encodeInt32(date, forKey: "pendingDate") - if let url = url { - encoder.encodeString(url, forKey: "pendingUrl") - } else { - encoder.encodeNil(forKey: "pendingUrl") - } - case let .Loaded(loadedContent): - encoder.encodeInt32(1, forKey: "ct") - loadedContent.encode(encoder) - } - } - - public func isLikelyToBeUpdated() -> Bool { - return true - } - - public func isEqual(to other: Media) -> Bool { - if let other = other as? TelegramMediaWebpage, self.webpageId == other.webpageId { - return self == other - } - return false - } - - public func isSemanticallyEqual(to other: Media) -> Bool { - return self.isEqual(to: other) - } - - public static func ==(lhs: TelegramMediaWebpage, rhs: TelegramMediaWebpage) -> Bool { - if lhs.webpageId != rhs.webpageId { - return false - } - - switch lhs.content { - case let .Pending(lhsDate, lhsUrl): - switch rhs.content { - case let .Pending(rhsDate, rhsUrl): - if lhsDate == rhsDate, lhsUrl == rhsUrl { - return true - } else { - return false - } - default: - return false - } - case let .Loaded(lhsContent): - switch rhs.content { - case let .Loaded(rhsContent) where lhsContent == rhsContent: - return true - default: - return false - } - } - } -} +import SyncCore func telegramMediaWebpageFromApiWebpage(_ webpage: Api.WebPage, url: String?) -> TelegramMediaWebpage? { switch webpage { diff --git a/submodules/TelegramCore/TelegramCore/TelegramPeerNotificationSettings.swift b/submodules/TelegramCore/TelegramCore/TelegramPeerNotificationSettings.swift index 67597f2ed2..2ae5ad8c36 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramPeerNotificationSettings.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramPeerNotificationSettings.swift @@ -7,212 +7,7 @@ import Foundation import TelegramApi #endif -public enum PeerMuteState: Equatable { - case `default` - case unmuted - case muted(until: Int32) - - fileprivate static func decodeInline(_ decoder: PostboxDecoder) -> PeerMuteState { - switch decoder.decodeInt32ForKey("m.v", orElse: 0) { - case 0: - return .default - case 1: - return .muted(until: decoder.decodeInt32ForKey("m.u", orElse: 0)) - case 2: - return .unmuted - default: - return .default - } - } - - fileprivate func encodeInline(_ encoder: PostboxEncoder) { - switch self { - case .default: - encoder.encodeInt32(0, forKey: "m.v") - case let .muted(until): - encoder.encodeInt32(1, forKey: "m.v") - encoder.encodeInt32(until, forKey: "m.u") - case .unmuted: - encoder.encodeInt32(2, forKey: "m.v") - } - } -} - -private enum PeerMessageSoundValue: Int32 { - case none - case bundledModern - case bundledClassic - case `default` -} - -public enum PeerMessageSound: Equatable { - case none - case `default` - case bundledModern(id: Int32) - case bundledClassic(id: Int32) - - static func decodeInline(_ decoder: PostboxDecoder) -> PeerMessageSound { - switch decoder.decodeInt32ForKey("s.v", orElse: 0) { - case PeerMessageSoundValue.none.rawValue: - return .none - case PeerMessageSoundValue.bundledModern.rawValue: - return .bundledModern(id: decoder.decodeInt32ForKey("s.i", orElse: 0)) - case PeerMessageSoundValue.bundledClassic.rawValue: - return .bundledClassic(id: decoder.decodeInt32ForKey("s.i", orElse: 0)) - case PeerMessageSoundValue.default.rawValue: - return .default - default: - assertionFailure() - return .bundledModern(id: 0) - } - } - - func encodeInline(_ encoder: PostboxEncoder) { - switch self { - case .none: - encoder.encodeInt32(PeerMessageSoundValue.none.rawValue, forKey: "s.v") - case let .bundledModern(id): - encoder.encodeInt32(PeerMessageSoundValue.bundledModern.rawValue, forKey: "s.v") - encoder.encodeInt32(id, forKey: "s.i") - case let .bundledClassic(id): - encoder.encodeInt32(PeerMessageSoundValue.bundledClassic.rawValue, forKey: "s.v") - encoder.encodeInt32(id, forKey: "s.i") - case .default: - encoder.encodeInt32(PeerMessageSoundValue.default.rawValue, forKey: "s.v") - } - } - - public static func ==(lhs: PeerMessageSound, rhs: PeerMessageSound) -> Bool { - switch lhs { - case .none: - if case .none = rhs { - return true - } else { - return false - } - case let .bundledModern(id): - if case .bundledModern(id) = rhs { - return true - } else { - return false - } - case let .bundledClassic(id): - if case .bundledClassic(id) = rhs { - return true - } else { - return false - } - case .default: - if case .default = rhs { - return true - } else { - return false - } - } - } -} - -public enum PeerNotificationDisplayPreviews { - case `default` - case show - case hide - - static func decodeInline(_ decoder: PostboxDecoder) -> PeerNotificationDisplayPreviews { - switch decoder.decodeInt32ForKey("p.v", orElse: 0) { - case 0: - return .default - case 1: - return .show - case 2: - return .hide - default: - assertionFailure() - return .default - } - } - - func encodeInline(_ encoder: PostboxEncoder) { - switch self { - case .default: - encoder.encodeInt32(0, forKey: "p.v") - case .show: - encoder.encodeInt32(1, forKey: "p.v") - case .hide: - encoder.encodeInt32(2, forKey: "p.v") - } - } -} - -public final class TelegramPeerNotificationSettings: PeerNotificationSettings, Equatable { - public let muteState: PeerMuteState - public let messageSound: PeerMessageSound - public let displayPreviews: PeerNotificationDisplayPreviews - - public static var defaultSettings: TelegramPeerNotificationSettings { - return TelegramPeerNotificationSettings(muteState: .unmuted, messageSound: .default, displayPreviews: .default) - } - - public var isRemovedFromTotalUnreadCount: Bool { - switch self.muteState { - case .unmuted: - return false - case .muted: - return true - case .default: - return false - } - } - - public var behavior: PeerNotificationSettingsBehavior { - if case let .muted(untilTimestamp) = self.muteState, untilTimestamp < Int32.max { - return .reset(atTimestamp: untilTimestamp, toValue: self.withUpdatedMuteState(.unmuted)) - } else { - return .none - } - } - - public init(muteState: PeerMuteState, messageSound: PeerMessageSound, displayPreviews: PeerNotificationDisplayPreviews) { - self.muteState = muteState - self.messageSound = messageSound - self.displayPreviews = displayPreviews - } - - public init(decoder: PostboxDecoder) { - self.muteState = PeerMuteState.decodeInline(decoder) - self.messageSound = PeerMessageSound.decodeInline(decoder) - self.displayPreviews = PeerNotificationDisplayPreviews.decodeInline(decoder) - } - - public func encode(_ encoder: PostboxEncoder) { - self.muteState.encodeInline(encoder) - self.messageSound.encodeInline(encoder) - self.displayPreviews.encodeInline(encoder) - } - - public func isEqual(to: PeerNotificationSettings) -> Bool { - if let to = to as? TelegramPeerNotificationSettings { - return self == to - } else { - return false - } - } - - public func withUpdatedMuteState(_ muteState: PeerMuteState) -> TelegramPeerNotificationSettings { - return TelegramPeerNotificationSettings(muteState: muteState, messageSound: self.messageSound, displayPreviews: self.displayPreviews) - } - - public func withUpdatedMessageSound(_ messageSound: PeerMessageSound) -> TelegramPeerNotificationSettings { - return TelegramPeerNotificationSettings(muteState: self.muteState, messageSound: messageSound, displayPreviews: self.displayPreviews) - } - - public func withUpdatedDisplayPreviews(_ displayPreviews: PeerNotificationDisplayPreviews) -> TelegramPeerNotificationSettings { - return TelegramPeerNotificationSettings(muteState: self.muteState, messageSound: self.messageSound, displayPreviews: displayPreviews) - } - - public static func ==(lhs: TelegramPeerNotificationSettings, rhs: TelegramPeerNotificationSettings) -> Bool { - return lhs.muteState == rhs.muteState && lhs.messageSound == rhs.messageSound && lhs.displayPreviews == rhs.displayPreviews - } -} +import SyncCore extension TelegramPeerNotificationSettings { convenience init(apiSettings: Api.PeerNotifySettings) { diff --git a/submodules/TelegramCore/TelegramCore/TelegramUser.swift b/submodules/TelegramCore/TelegramCore/TelegramUser.swift index f23265ce6c..f70325fd3d 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramUser.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramUser.swift @@ -8,259 +8,7 @@ import Foundation import TelegramApi #endif -public struct UserInfoFlags: OptionSet { - public var rawValue: Int32 - - public init() { - self.rawValue = 0 - } - - public init(rawValue: Int32) { - self.rawValue = rawValue - } - - public static let isVerified = UserInfoFlags(rawValue: (1 << 0)) - public static let isSupport = UserInfoFlags(rawValue: (1 << 1)) - public static let isScam = UserInfoFlags(rawValue: (1 << 2)) -} - -public struct BotUserInfoFlags: OptionSet { - public var rawValue: Int32 - - public init() { - self.rawValue = 0 - } - - public init(rawValue: Int32) { - self.rawValue = rawValue - } - - public static let hasAccessToChatHistory = BotUserInfoFlags(rawValue: (1 << 0)) - public static let worksWithGroups = BotUserInfoFlags(rawValue: (1 << 1)) - public static let requiresGeolocationForInlineRequests = BotUserInfoFlags(rawValue: (1 << 2)) -} - -public struct BotUserInfo: PostboxCoding, Equatable { - public let flags: BotUserInfoFlags - public let inlinePlaceholder: String? - - init(flags: BotUserInfoFlags, inlinePlaceholder: String?) { - self.flags = flags - self.inlinePlaceholder = inlinePlaceholder - } - - public init(decoder: PostboxDecoder) { - self.flags = BotUserInfoFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0)) - self.inlinePlaceholder = decoder.decodeOptionalStringForKey("ip") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.flags.rawValue, forKey: "f") - if let inlinePlaceholder = self.inlinePlaceholder { - encoder.encodeString(inlinePlaceholder, forKey: "ip") - } else { - encoder.encodeNil(forKey: "ip") - } - } -} - -public final class TelegramUser: Peer { - public let id: PeerId - public let accessHash: TelegramPeerAccessHash? - public let firstName: String? - public let lastName: String? - public let username: String? - public let phone: String? - public let photo: [TelegramMediaImageRepresentation] - public let botInfo: BotUserInfo? - public let restrictionInfo: PeerAccessRestrictionInfo? - public let flags: UserInfoFlags - - public var nameOrPhone: String { - if let firstName = self.firstName { - if let lastName = self.lastName { - return "\(firstName) \(lastName)" - } else { - return firstName - } - } else if let lastName = self.lastName { - return lastName - } else if let phone = self.phone, !phone.isEmpty { - return phone - } else { - return "" - } - } - - public var shortNameOrPhone: String { - if let firstName = self.firstName { - return firstName - } else if let lastName = self.lastName { - return lastName - } else if let phone = self.phone, !phone.isEmpty { - return phone - } else { - return "" - } - } - - public var indexName: PeerIndexNameRepresentation { - return .personName(first: self.firstName ?? "", last: self.lastName ?? "", addressName: self.username, phoneNumber: self.phone) - } - - public let associatedPeerId: PeerId? = nil - public let notificationSettingsPeerId: PeerId? = nil - - public init(id: PeerId, accessHash: TelegramPeerAccessHash?, firstName: String?, lastName: String?, username: String?, phone: String?, photo: [TelegramMediaImageRepresentation], botInfo: BotUserInfo?, restrictionInfo: PeerAccessRestrictionInfo?, flags: UserInfoFlags) { - self.id = id - self.accessHash = accessHash - self.firstName = firstName - self.lastName = lastName - self.username = username - self.phone = phone - self.photo = photo - self.botInfo = botInfo - self.restrictionInfo = restrictionInfo - self.flags = flags - } - - public init(decoder: PostboxDecoder) { - self.id = PeerId(decoder.decodeInt64ForKey("i", orElse: 0)) - - let accessHash: Int64 = decoder.decodeInt64ForKey("ah", orElse: 0) - let accessHashType: Int32 = decoder.decodeInt32ForKey("aht", orElse: 0) - if accessHash != 0 { - if accessHashType == 0 { - self.accessHash = .personal(accessHash) - } else { - self.accessHash = .genericPublic(accessHash) - } - } else { - self.accessHash = nil - } - - self.firstName = decoder.decodeOptionalStringForKey("fn") - self.lastName = decoder.decodeOptionalStringForKey("ln") - - self.username = decoder.decodeOptionalStringForKey("un") - self.phone = decoder.decodeOptionalStringForKey("p") - - self.photo = decoder.decodeObjectArrayForKey("ph") - - if let botInfo = decoder.decodeObjectForKey("bi", decoder: { return BotUserInfo(decoder: $0) }) as? BotUserInfo { - self.botInfo = botInfo - } else { - self.botInfo = nil - } - - self.restrictionInfo = decoder.decodeObjectForKey("ri") as? PeerAccessRestrictionInfo - - self.flags = UserInfoFlags(rawValue: decoder.decodeInt32ForKey("fl", orElse: 0)) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt64(self.id.toInt64(), forKey: "i") - - if let accessHash = self.accessHash { - switch accessHash { - case let .personal(value): - encoder.encodeInt64(value, forKey: "ah") - encoder.encodeInt32(0, forKey: "aht") - case let .genericPublic(value): - encoder.encodeInt64(value, forKey: "ah") - encoder.encodeInt32(1, forKey: "aht") - } - } - - if let firstName = self.firstName { - encoder.encodeString(firstName, forKey: "fn") - } - if let lastName = self.lastName { - encoder.encodeString(lastName, forKey: "ln") - } - - if let username = self.username { - encoder.encodeString(username, forKey: "un") - } - if let phone = self.phone { - encoder.encodeString(phone, forKey: "p") - } - - encoder.encodeObjectArray(self.photo, forKey: "ph") - - if let botInfo = self.botInfo { - encoder.encodeObject(botInfo, forKey: "bi") - } else { - encoder.encodeNil(forKey: "bi") - } - - if let restrictionInfo = self.restrictionInfo { - encoder.encodeObject(restrictionInfo, forKey: "ri") - } else { - encoder.encodeNil(forKey: "ri") - } - - encoder.encodeInt32(self.flags.rawValue, forKey: "fl") - } - - public func isEqual(_ other: Peer) -> Bool { - if let other = other as? TelegramUser { - if self.id != other.id { - return false - } - if self.accessHash != other.accessHash { - return false - } - if self.firstName != other.firstName { - return false - } - if self.lastName != other.lastName { - return false - } - if self.phone != other.phone { - return false - } - if self.photo.count != other.photo.count { - return false - } - for i in 0 ..< self.photo.count { - if self.photo[i] != other.photo[i] { - return false - } - } - if self.botInfo != other.botInfo { - return false - } - if self.restrictionInfo != other.restrictionInfo { - return false - } - - if self.flags != other.flags { - return false - } - - return true - } else { - return false - } - } - - func withUpdatedUsername(_ username:String?) -> TelegramUser { - return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: self.firstName, lastName: self.lastName, username: username, phone: self.phone, photo: self.photo, botInfo: self.botInfo, restrictionInfo: self.restrictionInfo, flags: self.flags) - } - - func withUpdatedNames(firstName: String?, lastName: String?) -> TelegramUser { - return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: firstName, lastName: lastName, username: self.username, phone: self.phone, photo: self.photo, botInfo: self.botInfo, restrictionInfo: self.restrictionInfo, flags: self.flags) - } - - func withUpdatedPhone(_ phone: String?) -> TelegramUser { - return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: self.firstName, lastName: self.lastName, username: self.username, phone: phone, photo: self.photo, botInfo: self.botInfo, restrictionInfo: self.restrictionInfo, flags: self.flags) - } - - func withUpdatedPhoto(_ representations: [TelegramMediaImageRepresentation]) -> TelegramUser { - return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: self.firstName, lastName: self.lastName, username: self.username, phone: phone, photo: representations, botInfo: self.botInfo, restrictionInfo: self.restrictionInfo, flags: self.flags) - } -} +import SyncCore func parsedTelegramProfilePhoto(_ photo: Api.UserProfilePhoto) -> [TelegramMediaImageRepresentation] { var representations: [TelegramMediaImageRepresentation] = [] diff --git a/submodules/TelegramCore/TelegramCore/TelegramUserPresence.swift b/submodules/TelegramCore/TelegramCore/TelegramUserPresence.swift index 937f102c01..785772cfec 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramUserPresence.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramUserPresence.swift @@ -7,120 +7,7 @@ import Foundation import TelegramApi #endif -public enum UserPresenceStatus: Comparable, PostboxCoding { - case none - case present(until: Int32) - case recently - case lastWeek - case lastMonth - - public static func <(lhs: UserPresenceStatus, rhs: UserPresenceStatus) -> Bool { - switch lhs { - case .none: - switch rhs { - case .none: - return false - case .lastMonth, .lastWeek, .recently, .present: - return true - } - case let .present(until): - switch rhs { - case .none: - return false - case let .present(rhsUntil): - return until < rhsUntil - case .lastWeek, .lastMonth, .recently: - return false - } - case .recently: - switch rhs { - case .none, .lastWeek, .lastMonth, .recently: - return false - case .present: - return true - } - case .lastWeek: - switch rhs { - case .none, .lastMonth, .lastWeek: - return false - case .present, .recently: - return true - } - case .lastMonth: - switch rhs { - case .none, .lastMonth: - return false - case .present, .recently, lastWeek: - return true - } - } - } - - public init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("v", orElse: 0) { - case 0: - self = .none - case 1: - self = .present(until: decoder.decodeInt32ForKey("t", orElse: 0)) - case 2: - self = .recently - case 3: - self = .lastWeek - case 4: - self = .lastMonth - default: - self = .none - } - } - - public func encode(_ encoder: PostboxEncoder) { - switch self { - case .none: - encoder.encodeInt32(0, forKey: "v") - case let .present(timestamp): - encoder.encodeInt32(1, forKey: "v") - encoder.encodeInt32(timestamp, forKey: "t") - case .recently: - encoder.encodeInt32(2, forKey: "v") - case .lastWeek: - encoder.encodeInt32(3, forKey: "v") - case .lastMonth: - encoder.encodeInt32(4, forKey: "v") - } - } -} - -public final class TelegramUserPresence: PeerPresence, Equatable { - public let status: UserPresenceStatus - public let lastActivity: Int32 - - public init(status: UserPresenceStatus, lastActivity: Int32) { - self.status = status - self.lastActivity = lastActivity - } - - public init(decoder: PostboxDecoder) { - self.status = UserPresenceStatus(decoder: decoder) - self.lastActivity = decoder.decodeInt32ForKey("la", orElse: 0) - } - - public func encode(_ encoder: PostboxEncoder) { - self.status.encode(encoder) - encoder.encodeInt32(self.lastActivity, forKey: "la") - } - - public static func ==(lhs: TelegramUserPresence, rhs: TelegramUserPresence) -> Bool { - return lhs.status == rhs.status && lhs.lastActivity == rhs.lastActivity - } - - public func isEqual(to: PeerPresence) -> Bool { - if let to = to as? TelegramUserPresence { - return self == to - } else { - return false - } - } -} +import SyncCore extension TelegramUserPresence { convenience init(apiStatus: Api.UserStatus) { diff --git a/submodules/TelegramCore/TelegramCore/TermsOfService.swift b/submodules/TelegramCore/TelegramCore/TermsOfService.swift index f375589b24..5d512d6b71 100644 --- a/submodules/TelegramCore/TelegramCore/TermsOfService.swift +++ b/submodules/TelegramCore/TelegramCore/TermsOfService.swift @@ -15,6 +15,8 @@ import SwiftSignalKit #endif #endif +import SyncCore + public struct TermsOfServiceUpdate: Equatable { public let id: String public let text: String diff --git a/submodules/TelegramCore/TelegramCore/TextEntitiesMessageAttribute.swift b/submodules/TelegramCore/TelegramCore/TextEntitiesMessageAttribute.swift index e6c04ed113..dc82936033 100644 --- a/submodules/TelegramCore/TelegramCore/TextEntitiesMessageAttribute.swift +++ b/submodules/TelegramCore/TelegramCore/TextEntitiesMessageAttribute.swift @@ -7,266 +7,7 @@ import Foundation import TelegramApi #endif -public enum MessageTextEntityType: Equatable { - public typealias CustomEntityType = Int32 - - case Unknown - case Mention - case Hashtag - case BotCommand - case Url - case Email - case Bold - case Italic - case Code - case Pre - case TextUrl(url: String) - case TextMention(peerId: PeerId) - case PhoneNumber - case Strikethrough - case BlockQuote - case Underline - case Custom(type: CustomEntityType) - - public static func ==(lhs: MessageTextEntityType, rhs: MessageTextEntityType) -> Bool { - switch lhs { - case .Unknown: - if case .Unknown = rhs { - return true - } else { - return false - } - case .Mention: - if case .Mention = rhs { - return true - } else { - return false - } - case .Hashtag: - if case .Hashtag = rhs { - return true - } else { - return false - } - case .BotCommand: - if case .BotCommand = rhs { - return true - } else { - return false - } - case .Url: - if case .Url = rhs { - return true - } else { - return false - } - case .Email: - if case .Email = rhs { - return true - } else { - return false - } - case .Bold: - if case .Bold = rhs { - return true - } else { - return false - } - case .Italic: - if case .Italic = rhs { - return true - } else { - return false - } - case .Code: - if case .Code = rhs { - return true - } else { - return false - } - case .Pre: - if case .Pre = rhs { - return true - } else { - return false - } - case let .TextUrl(url): - if case .TextUrl(url) = rhs { - return true - } else { - return false - } - case let .TextMention(peerId): - if case .TextMention(peerId) = rhs { - return true - } else { - return false - } - case .PhoneNumber: - if case .PhoneNumber = rhs { - return true - } else { - return false - } - case .Strikethrough: - if case .Strikethrough = rhs { - return true - } else { - return false - } - case .BlockQuote: - if case .BlockQuote = rhs { - return true - } else { - return false - } - case .Underline: - if case .Underline = rhs { - return true - } else { - return false - } - case let .Custom(type): - if case .Custom(type) = rhs { - return true - } else { - return false - } - } - } -} - -public struct MessageTextEntity: PostboxCoding, Equatable { - public let range: Range - public let type: MessageTextEntityType - - public init(range: Range, type: MessageTextEntityType) { - self.range = range - self.type = type - } - - public init(decoder: PostboxDecoder) { - self.range = Int(decoder.decodeInt32ForKey("start", orElse: 0)) ..< Int(decoder.decodeInt32ForKey("end", orElse: 0)) - let type: Int32 = decoder.decodeInt32ForKey("_rawValue", orElse: 0) - switch type { - case 1: - self.type = .Mention - case 2: - self.type = .Hashtag - case 3: - self.type = .BotCommand - case 4: - self.type = .Url - case 5: - self.type = .Email - case 6: - self.type = .Bold - case 7: - self.type = .Italic - case 8: - self.type = .Code - case 9: - self.type = .Pre - case 10: - self.type = .TextUrl(url: decoder.decodeStringForKey("url", orElse: "")) - case 11: - self.type = .TextMention(peerId: PeerId(decoder.decodeInt64ForKey("peerId", orElse: 0))) - case 12: - self.type = .PhoneNumber - case 13: - self.type = .Strikethrough - case 14: - self.type = .BlockQuote - case 15: - self.type = .Underline - case Int32.max: - self.type = .Custom(type: decoder.decodeInt32ForKey("type", orElse: 0)) - default: - self.type = .Unknown - } - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(Int32(self.range.lowerBound), forKey: "start") - encoder.encodeInt32(Int32(self.range.upperBound), forKey: "end") - switch self.type { - case .Unknown: - encoder.encodeInt32(0, forKey: "_rawValue") - case .Mention: - encoder.encodeInt32(1, forKey: "_rawValue") - case .Hashtag: - encoder.encodeInt32(2, forKey: "_rawValue") - case .BotCommand: - encoder.encodeInt32(3, forKey: "_rawValue") - case .Url: - encoder.encodeInt32(4, forKey: "_rawValue") - case .Email: - encoder.encodeInt32(5, forKey: "_rawValue") - case .Bold: - encoder.encodeInt32(6, forKey: "_rawValue") - case .Italic: - encoder.encodeInt32(7, forKey: "_rawValue") - case .Code: - encoder.encodeInt32(8, forKey: "_rawValue") - case .Pre: - encoder.encodeInt32(9, forKey: "_rawValue") - case let .TextUrl(url): - encoder.encodeInt32(10, forKey: "_rawValue") - encoder.encodeString(url, forKey: "url") - case let .TextMention(peerId): - encoder.encodeInt32(11, forKey: "_rawValue") - encoder.encodeInt64(peerId.toInt64(), forKey: "peerId") - case .PhoneNumber: - encoder.encodeInt32(12, forKey: "_rawValue") - case .Strikethrough: - encoder.encodeInt32(13, forKey: "_rawValue") - case .BlockQuote: - encoder.encodeInt32(14, forKey: "_rawValue") - case .Underline: - encoder.encodeInt32(15, forKey: "_rawValue") - case let .Custom(type): - encoder.encodeInt32(Int32.max, forKey: "_rawValue") - encoder.encodeInt32(type, forKey: "type") - } - } - - public static func ==(lhs: MessageTextEntity, rhs: MessageTextEntity) -> Bool { - return lhs.range == rhs.range && lhs.type == rhs.type - } -} - -public class TextEntitiesMessageAttribute: MessageAttribute, Equatable { - public let entities: [MessageTextEntity] - - public var associatedPeerIds: [PeerId] { - var result: [PeerId] = [] - for entity in entities { - switch entity.type { - case let .TextMention(peerId): - result.append(peerId) - default: - break - } - } - return result - } - - public init(entities: [MessageTextEntity]) { - self.entities = entities - } - - required public init(decoder: PostboxDecoder) { - self.entities = decoder.decodeObjectArrayWithDecoderForKey("entities") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeObjectArray(self.entities, forKey: "entities") - } - - public static func ==(lhs: TextEntitiesMessageAttribute, rhs: TextEntitiesMessageAttribute) -> Bool { - return lhs.entities == rhs.entities - } -} +import SyncCore func apiEntitiesFromMessageTextEntities(_ entities: [MessageTextEntity], associatedPeers: SimpleDictionary) -> [Api.MessageEntity] { var apiEntities: [Api.MessageEntity] = [] diff --git a/submodules/TelegramCore/TelegramCore/Theme.swift b/submodules/TelegramCore/TelegramCore/Theme.swift index 2f184f058a..558693608a 100644 --- a/submodules/TelegramCore/TelegramCore/Theme.swift +++ b/submodules/TelegramCore/TelegramCore/Theme.swift @@ -9,81 +9,7 @@ import SwiftSignalKit import TelegramApi #endif -public final class TelegramTheme: OrderedItemListEntryContents, Equatable { - public let id: Int64 - public let accessHash: Int64 - public let slug: String - public let title: String - public let file: TelegramMediaFile? - public let isCreator: Bool - public let isDefault: Bool - public let installCount: Int32 - - public init(id: Int64, accessHash: Int64, slug: String, title: String, file: TelegramMediaFile?, isCreator: Bool, isDefault: Bool, installCount: Int32) { - self.id = id - self.accessHash = accessHash - self.slug = slug - self.title = title - self.file = file - self.isCreator = isCreator - self.isDefault = isDefault - self.installCount = installCount - } - - public init(decoder: PostboxDecoder) { - self.id = decoder.decodeInt64ForKey("id", orElse: 0) - self.accessHash = decoder.decodeInt64ForKey("accessHash", orElse: 0) - self.slug = decoder.decodeStringForKey("slug", orElse: "") - self.title = decoder.decodeStringForKey("title", orElse: "") - self.file = decoder.decodeObjectForKey("file", decoder: { TelegramMediaFile(decoder: $0) }) as? TelegramMediaFile - self.isCreator = decoder.decodeInt32ForKey("isCreator", orElse: 0) != 0 - self.isDefault = decoder.decodeInt32ForKey("isDefault", orElse: 0) != 0 - self.installCount = decoder.decodeInt32ForKey("installCount", orElse: 0) - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt64(self.id, forKey: "id") - encoder.encodeInt64(self.accessHash, forKey: "accessHash") - encoder.encodeString(self.slug, forKey: "slug") - encoder.encodeString(self.title, forKey: "title") - if let file = self.file { - encoder.encodeObject(file, forKey: "file") - } else { - encoder.encodeNil(forKey: "file") - } - encoder.encodeInt32(self.isCreator ? 1 : 0, forKey: "isCreator") - encoder.encodeInt32(self.isDefault ? 1 : 0, forKey: "isDefault") - encoder.encodeInt32(self.installCount, forKey: "installCount") - } - - public static func ==(lhs: TelegramTheme, rhs: TelegramTheme) -> Bool { - if lhs.id != rhs.id { - return false - } - if lhs.accessHash != rhs.accessHash { - return false - } - if lhs.slug != rhs.slug { - return false - } - if lhs.title != rhs.title { - return false - } - if lhs.file?.id != rhs.file?.id { - return false - } - if lhs.isCreator != rhs.isCreator { - return false - } - if lhs.isDefault != rhs.isDefault { - return false - } - if lhs.installCount != rhs.installCount { - return false - } - return true - } -} +import SyncCore extension TelegramTheme { convenience init?(apiTheme: Api.Theme) { diff --git a/submodules/TelegramCore/TelegramCore/Themes.swift b/submodules/TelegramCore/TelegramCore/Themes.swift index 66733278c9..c7d25416b3 100644 --- a/submodules/TelegramCore/TelegramCore/Themes.swift +++ b/submodules/TelegramCore/TelegramCore/Themes.swift @@ -9,21 +9,7 @@ import Foundation import TelegramApi #endif -final class CachedThemesConfiguration: PostboxCoding { - let hash: Int32 - - init(hash: Int32) { - self.hash = hash - } - - init(decoder: PostboxDecoder) { - self.hash = decoder.decodeInt32ForKey("hash", orElse: 0) - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.hash, forKey: "hash") - } -} +import SyncCore #if os(macOS) let telegramThemeFormat = "macos" @@ -434,38 +420,6 @@ public func updateTheme(account: Account, accountManager: AccountManager, theme: } } -public final class ThemeSettings: PreferencesEntry, Equatable { - public let currentTheme: TelegramTheme? - - public init(currentTheme: TelegramTheme?) { - self.currentTheme = currentTheme - } - - public init(decoder: PostboxDecoder) { - self.currentTheme = decoder.decodeObjectForKey("t", decoder: { TelegramTheme(decoder: $0) }) as? TelegramTheme - } - - public func encode(_ encoder: PostboxEncoder) { - if let currentTheme = currentTheme { - encoder.encodeObject(currentTheme, forKey: "t") - } else { - encoder.encodeNil(forKey: "t") - } - } - - public func isEqual(to: PreferencesEntry) -> Bool { - if let to = to as? ThemeSettings { - return self == to - } else { - return false - } - } - - public static func ==(lhs: ThemeSettings, rhs: ThemeSettings) -> Bool { - return lhs.currentTheme == rhs.currentTheme - } -} - public func saveThemeInteractively(account: Account, accountManager: AccountManager, theme: TelegramTheme) -> Signal { return saveUnsaveTheme(account: account, accountManager: accountManager, theme: theme, unsave: false) } diff --git a/submodules/TelegramCore/TelegramCore/ToggleChannelSignatures.swift b/submodules/TelegramCore/TelegramCore/ToggleChannelSignatures.swift index 74c1bba7dd..753848fffd 100644 --- a/submodules/TelegramCore/TelegramCore/ToggleChannelSignatures.swift +++ b/submodules/TelegramCore/TelegramCore/ToggleChannelSignatures.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public func toggleShouldChannelMessagesSignatures(account:Account, peerId:PeerId, enabled: Bool) -> Signal { return account.postbox.transaction { transaction -> Signal in if let peer = transaction.getPeer(peerId) as? TelegramChannel, let inputChannel = apiInputChannel(peer) { diff --git a/submodules/TelegramCore/TelegramCore/TogglePeerChatPinned.swift b/submodules/TelegramCore/TelegramCore/TogglePeerChatPinned.swift index baf042ea55..697bc6074a 100644 --- a/submodules/TelegramCore/TelegramCore/TogglePeerChatPinned.swift +++ b/submodules/TelegramCore/TelegramCore/TogglePeerChatPinned.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public enum TogglePeerChatPinnedResult { case done case limitExceeded(Int) diff --git a/submodules/TelegramCore/TelegramCore/TwoStepVerification.swift b/submodules/TelegramCore/TelegramCore/TwoStepVerification.swift index 510bc507d9..d8686345b4 100644 --- a/submodules/TelegramCore/TelegramCore/TwoStepVerification.swift +++ b/submodules/TelegramCore/TelegramCore/TwoStepVerification.swift @@ -8,13 +8,11 @@ import Foundation import Postbox import SwiftSignalKit import TelegramApi - #if BUCK - import MtProtoKit - #else - import MtProtoKitDynamic - #endif + import MtProtoKit #endif +import SyncCore + public enum TwoStepVerificationConfiguration { case notSet(pendingEmail: TwoStepVerificationPendingEmail?) case set(hint: String, hasRecoveryEmail: Bool, pendingEmail: TwoStepVerificationPendingEmail?, hasSecureValues: Bool) @@ -361,34 +359,6 @@ public func recoverTwoStepVerificationPassword(network: Network, code: String) - } } -public struct TemporaryTwoStepPasswordToken: PostboxCoding, Equatable { - public let token: Data - public let validUntilDate: Int32 - public let requiresBiometrics: Bool - - public init(token: Data, validUntilDate: Int32, requiresBiometrics: Bool) { - self.token = token - self.validUntilDate = validUntilDate - self.requiresBiometrics = requiresBiometrics - } - - public init(decoder: PostboxDecoder) { - self.token = decoder.decodeBytesForKey("t")!.makeData() - self.validUntilDate = decoder.decodeInt32ForKey("d", orElse: 0) - self.requiresBiometrics = decoder.decodeInt32ForKey("b", orElse: 0) != 0 - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeBytes(MemoryBuffer(data: self.token), forKey: "t") - encoder.encodeInt32(self.validUntilDate, forKey: "d") - encoder.encodeInt32(self.requiresBiometrics ? 1 : 0, forKey: "b") - } - - public static func ==(lhs: TemporaryTwoStepPasswordToken, rhs: TemporaryTwoStepPasswordToken) -> Bool { - return lhs.token == rhs.token && lhs.validUntilDate == rhs.validUntilDate && lhs.requiresBiometrics == rhs.requiresBiometrics - } -} - public func cachedTwoStepPasswordToken(postbox: Postbox) -> Signal { return postbox.transaction { transaction -> TemporaryTwoStepPasswordToken? in let key = ValueBoxKey(length: 1) diff --git a/submodules/TelegramCore/TelegramCore/UpdateAccountPeerName.swift b/submodules/TelegramCore/TelegramCore/UpdateAccountPeerName.swift index 83513b3018..dd76c4d9b8 100644 --- a/submodules/TelegramCore/TelegramCore/UpdateAccountPeerName.swift +++ b/submodules/TelegramCore/TelegramCore/UpdateAccountPeerName.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public func updateAccountPeerName(account: Account, firstName: String, lastName: String) -> Signal { return account.network.request(Api.functions.account.updateProfile(flags: (1 << 0) | (1 << 1), firstName: firstName, lastName: lastName, about: nil)) |> map { result -> Api.User? in diff --git a/submodules/TelegramCore/TelegramCore/UpdateCachedPeerData.swift b/submodules/TelegramCore/TelegramCore/UpdateCachedPeerData.swift index 7722753bdc..6987139d95 100644 --- a/submodules/TelegramCore/TelegramCore/UpdateCachedPeerData.swift +++ b/submodules/TelegramCore/TelegramCore/UpdateCachedPeerData.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + func fetchAndUpdateSupplementalCachedPeerData(peerId rawPeerId: PeerId, network: Network, postbox: Postbox) -> Signal { return postbox.transaction { transaction -> Signal in guard let rawPeer = transaction.getPeer(rawPeerId) else { diff --git a/submodules/TelegramCore/TelegramCore/UpdateContactName.swift b/submodules/TelegramCore/TelegramCore/UpdateContactName.swift index c917657f3b..23435bf431 100644 --- a/submodules/TelegramCore/TelegramCore/UpdateContactName.swift +++ b/submodules/TelegramCore/TelegramCore/UpdateContactName.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public enum UpdateContactNameError { case generic } diff --git a/submodules/TelegramCore/TelegramCore/UpdateGroupSpecificStickerset.swift b/submodules/TelegramCore/TelegramCore/UpdateGroupSpecificStickerset.swift index da6c323690..1c3aa09d5f 100644 --- a/submodules/TelegramCore/TelegramCore/UpdateGroupSpecificStickerset.swift +++ b/submodules/TelegramCore/TelegramCore/UpdateGroupSpecificStickerset.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public enum UpdateGroupSpecificStickersetError { case generic } diff --git a/submodules/TelegramCore/TelegramCore/UpdateMessageMedia.swift b/submodules/TelegramCore/TelegramCore/UpdateMessageMedia.swift index acc02d00cf..21c0a6f562 100644 --- a/submodules/TelegramCore/TelegramCore/UpdateMessageMedia.swift +++ b/submodules/TelegramCore/TelegramCore/UpdateMessageMedia.swift @@ -7,6 +7,8 @@ import Postbox import TelegramApi #endif +import SyncCore + func updateMessageMedia(transaction: Transaction, id: MediaId, media: Media?) { let updatedMessageIndices = transaction.updateMedia(id, update: media) for index in updatedMessageIndices { diff --git a/submodules/TelegramCore/TelegramCore/UpdatePeerChatInterfaceState.swift b/submodules/TelegramCore/TelegramCore/UpdatePeerChatInterfaceState.swift index 21cbfda09f..c6f7aa2d72 100644 --- a/submodules/TelegramCore/TelegramCore/UpdatePeerChatInterfaceState.swift +++ b/submodules/TelegramCore/TelegramCore/UpdatePeerChatInterfaceState.swift @@ -7,6 +7,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public func updatePeerChatInterfaceState(account: Account, peerId: PeerId, state: SynchronizeableChatInterfaceState) -> Signal { return account.postbox.transaction { transaction -> Void in let currentInputState = (transaction.getPeerChatInterfaceState(peerId) as? SynchronizeableChatInterfaceState)?.synchronizeableInputState diff --git a/submodules/TelegramCore/TelegramCore/UpdatePeerInfo.swift b/submodules/TelegramCore/TelegramCore/UpdatePeerInfo.swift index aa395f18af..70504e31da 100644 --- a/submodules/TelegramCore/TelegramCore/UpdatePeerInfo.swift +++ b/submodules/TelegramCore/TelegramCore/UpdatePeerInfo.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public enum UpdatePeerTitleError { case generic } diff --git a/submodules/TelegramCore/TelegramCore/UpdatePeers.swift b/submodules/TelegramCore/TelegramCore/UpdatePeers.swift index 3b94506f7b..bacf0de4ad 100644 --- a/submodules/TelegramCore/TelegramCore/UpdatePeers.swift +++ b/submodules/TelegramCore/TelegramCore/UpdatePeers.swift @@ -7,6 +7,8 @@ import Foundation import TelegramApi #endif +import SyncCore + func updatePeerChatInclusionWithMinTimestamp(transaction: Transaction, id: PeerId, minTimestamp: Int32, forceRootGroupIfNotExists: Bool) { let currentInclusion = transaction.getPeerChatListInclusion(id) var updatedInclusion: PeerChatListInclusion? diff --git a/submodules/TelegramCore/TelegramCore/UpdatePinnedMessage.swift b/submodules/TelegramCore/TelegramCore/UpdatePinnedMessage.swift index b48242cfc2..88fcbe0299 100644 --- a/submodules/TelegramCore/TelegramCore/UpdatePinnedMessage.swift +++ b/submodules/TelegramCore/TelegramCore/UpdatePinnedMessage.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public enum UpdatePinnedMessageError { case generic } diff --git a/submodules/TelegramCore/TelegramCore/UpdateSecretChat.swift b/submodules/TelegramCore/TelegramCore/UpdateSecretChat.swift index 698ebfbec2..a20fcd13d5 100644 --- a/submodules/TelegramCore/TelegramCore/UpdateSecretChat.swift +++ b/submodules/TelegramCore/TelegramCore/UpdateSecretChat.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + struct SecretChatRequestData { let g: Int32 let p: MemoryBuffer diff --git a/submodules/TelegramCore/TelegramCore/UpdatedAccountPrivacySettings.swift b/submodules/TelegramCore/TelegramCore/UpdatedAccountPrivacySettings.swift index ef4e05aca9..f9bdf7a095 100644 --- a/submodules/TelegramCore/TelegramCore/UpdatedAccountPrivacySettings.swift +++ b/submodules/TelegramCore/TelegramCore/UpdatedAccountPrivacySettings.swift @@ -9,6 +9,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public func requestAccountPrivacySettings(account: Account) -> Signal { let lastSeenPrivacy = account.network.request(Api.functions.account.getPrivacy(key: .inputPrivacyKeyStatusTimestamp)) let groupPrivacy = account.network.request(Api.functions.account.getPrivacy(key: .inputPrivacyKeyChatInvite)) diff --git a/submodules/TelegramCore/TelegramCore/UpdatesApiUtils.swift b/submodules/TelegramCore/TelegramCore/UpdatesApiUtils.swift index 2bfba3dcce..414151e066 100644 --- a/submodules/TelegramCore/TelegramCore/UpdatesApiUtils.swift +++ b/submodules/TelegramCore/TelegramCore/UpdatesApiUtils.swift @@ -7,6 +7,8 @@ import Foundation import TelegramApi #endif +import SyncCore + private func collectPreCachedResources(for photo: Api.Photo) -> [(MediaResource, Data)]? { switch photo { case let .photo(_, id, accessHash, fileReference, _, sizes, dcId): diff --git a/submodules/TelegramCore/TelegramCore/VerifySecureIdValue.swift b/submodules/TelegramCore/TelegramCore/VerifySecureIdValue.swift index 79cb21e5a6..aa5942dd64 100644 --- a/submodules/TelegramCore/TelegramCore/VerifySecureIdValue.swift +++ b/submodules/TelegramCore/TelegramCore/VerifySecureIdValue.swift @@ -15,6 +15,8 @@ import Foundation import SwiftSignalKit #endif +import SyncCore + public enum SecureIdPreparePhoneVerificationError { case generic case flood diff --git a/submodules/TelegramCore/TelegramCore/VoipConfiguration.swift b/submodules/TelegramCore/TelegramCore/VoipConfiguration.swift index 089134eded..dfe85231fc 100644 --- a/submodules/TelegramCore/TelegramCore/VoipConfiguration.swift +++ b/submodules/TelegramCore/TelegramCore/VoipConfiguration.swift @@ -1,46 +1,5 @@ -import Foundation -#if os(macOS) -import PostboxMac -#else import Postbox -#endif - -public enum VoiceCallP2PMode: Int32 { - case never = 0 - case contacts = 1 - case always = 2 -} - -public struct VoipConfiguration: PreferencesEntry, Equatable { - public var serializedData: String? - - public static var defaultValue: VoipConfiguration { - return VoipConfiguration(serializedData: nil) - } - - init(serializedData: String?) { - self.serializedData = serializedData - } - - public init(decoder: PostboxDecoder) { - self.serializedData = decoder.decodeOptionalStringForKey("serializedData") - } - - public func encode(_ encoder: PostboxEncoder) { - if let serializedData = self.serializedData { - encoder.encodeString(serializedData, forKey: "serializedData") - } else { - encoder.encodeNil(forKey: "serializedData") - } - } - - public func isEqual(to: PreferencesEntry) -> Bool { - guard let to = to as? VoipConfiguration else { - return false - } - return self == to - } -} +import SyncCore public func currentVoipConfiguration(transaction: Transaction) -> VoipConfiguration { if let entry = transaction.getPreferencesEntry(key: PreferencesKeys.voipConfiguration) as? VoipConfiguration { diff --git a/submodules/TelegramCore/TelegramCore/Wallets.swift b/submodules/TelegramCore/TelegramCore/Wallets.swift index 89a6c35f35..6d9dad4113 100644 --- a/submodules/TelegramCore/TelegramCore/Wallets.swift +++ b/submodules/TelegramCore/TelegramCore/Wallets.swift @@ -28,35 +28,6 @@ public func getServerWalletSalt(network: Network) -> Signal Signal Bool { - guard let other = to as? WalletCollection else { - return false - } - if self.wallets != other.wallets { - return false - } - return true - } -} diff --git a/submodules/TelegramCore/TelegramCore/Wallpaper.swift b/submodules/TelegramCore/TelegramCore/Wallpaper.swift index b88fe3c6fa..5a6a1c7cfb 100644 --- a/submodules/TelegramCore/TelegramCore/Wallpaper.swift +++ b/submodules/TelegramCore/TelegramCore/Wallpaper.swift @@ -9,158 +9,7 @@ import SwiftSignalKit import TelegramApi #endif -public struct WallpaperSettings: PostboxCoding, Equatable { - public let blur: Bool - public let motion: Bool - public let color: Int32? - public let intensity: Int32? - - public init(blur: Bool = false, motion: Bool = false, color: Int32? = nil, intensity: Int32? = nil) { - self.blur = blur - self.motion = motion - self.color = color - self.intensity = intensity - } - - public init(decoder: PostboxDecoder) { - self.blur = decoder.decodeInt32ForKey("b", orElse: 0) != 0 - self.motion = decoder.decodeInt32ForKey("m", orElse: 0) != 0 - self.color = decoder.decodeOptionalInt32ForKey("c") - self.intensity = decoder.decodeOptionalInt32ForKey("i") - } - - public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.blur ? 1 : 0, forKey: "b") - encoder.encodeInt32(self.motion ? 1 : 0, forKey: "m") - if let color = self.color { - encoder.encodeInt32(color, forKey: "c") - } else { - encoder.encodeNil(forKey: "c") - } - if let intensity = self.intensity { - encoder.encodeInt32(intensity, forKey: "i") - } else { - encoder.encodeNil(forKey: "i") - } - } -} - -public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { - case builtin(WallpaperSettings) - case color(Int32) - case image([TelegramMediaImageRepresentation], WallpaperSettings) - case file(id: Int64, accessHash: Int64, isCreator: Bool, isDefault: Bool, isPattern: Bool, isDark: Bool, slug: String, file: TelegramMediaFile, settings: WallpaperSettings) - - public init(decoder: PostboxDecoder) { - switch decoder.decodeInt32ForKey("v", orElse: 0) { - case 0: - let settings = decoder.decodeObjectForKey("settings", decoder: { WallpaperSettings(decoder: $0) }) as? WallpaperSettings ?? WallpaperSettings() - self = .builtin(settings) - case 1: - self = .color(decoder.decodeInt32ForKey("c", orElse: 0)) - case 2: - let settings = decoder.decodeObjectForKey("settings", decoder: { WallpaperSettings(decoder: $0) }) as? WallpaperSettings ?? WallpaperSettings() - self = .image(decoder.decodeObjectArrayWithDecoderForKey("i"), settings) - case 3: - let settings = decoder.decodeObjectForKey("settings", decoder: { WallpaperSettings(decoder: $0) }) as? WallpaperSettings ?? WallpaperSettings() - if let file = decoder.decodeObjectForKey("file", decoder: { TelegramMediaFile(decoder: $0) }) as? TelegramMediaFile { - self = .file(id: decoder.decodeInt64ForKey("id", orElse: 0), accessHash: decoder.decodeInt64ForKey("accessHash", orElse: 0), isCreator: decoder.decodeInt32ForKey("isCreator", orElse: 0) != 0, isDefault: decoder.decodeInt32ForKey("isDefault", orElse: 0) != 0, isPattern: decoder.decodeInt32ForKey("isPattern", orElse: 0) != 0, isDark: decoder.decodeInt32ForKey("isDark", orElse: 0) != 0, slug: decoder.decodeStringForKey("slug", orElse: ""), file: file, settings: settings) - } else { - self = .color(0xffffff) - } - - default: - assertionFailure() - self = .color(0xffffff) - } - } - - public var hasWallpaper: Bool { - switch self { - case .color: - return false - default: - return true - } - } - - public func encode(_ encoder: PostboxEncoder) { - switch self { - case let .builtin(settings): - encoder.encodeInt32(0, forKey: "v") - encoder.encodeObject(settings, forKey: "settings") - case let .color(color): - encoder.encodeInt32(1, forKey: "v") - encoder.encodeInt32(color, forKey: "c") - case let .image(representations, settings): - encoder.encodeInt32(2, forKey: "v") - encoder.encodeObjectArray(representations, forKey: "i") - encoder.encodeObject(settings, forKey: "settings") - case let .file(id, accessHash, isCreator, isDefault, isPattern, isDark, slug, file, settings): - encoder.encodeInt32(3, forKey: "v") - encoder.encodeInt64(id, forKey: "id") - encoder.encodeInt64(accessHash, forKey: "accessHash") - encoder.encodeInt32(isCreator ? 1 : 0, forKey: "isCreator") - encoder.encodeInt32(isDefault ? 1 : 0, forKey: "isDefault") - encoder.encodeInt32(isPattern ? 1 : 0, forKey: "isPattern") - encoder.encodeInt32(isDark ? 1 : 0, forKey: "isDark") - encoder.encodeString(slug, forKey: "slug") - encoder.encodeObject(file, forKey: "file") - encoder.encodeObject(settings, forKey: "settings") - } - } - - public static func ==(lhs: TelegramWallpaper, rhs: TelegramWallpaper) -> Bool { - switch lhs { - case let .builtin(settings): - if case .builtin(settings) = rhs { - return true - } else { - return false - } - case let .color(color): - if case .color(color) = rhs { - return true - } else { - return false - } - case let .image(representations, settings): - if case .image(representations, settings) = rhs { - return true - } else { - return false - } - case let .file(lhsId, _, lhsIsCreator, lhsIsDefault, lhsIsPattern, lhsIsDark, lhsSlug, lhsFile, lhsSettings): - if case let .file(rhsId, _, rhsIsCreator, rhsIsDefault, rhsIsPattern, rhsIsDark, rhsSlug, rhsFile, rhsSettings) = rhs, lhsId == rhsId, lhsIsCreator == rhsIsCreator, lhsIsDefault == rhsIsDefault, lhsIsPattern == rhsIsPattern, lhsIsDark == rhsIsDark, lhsSlug == rhsSlug, lhsFile == rhsFile, lhsSettings == rhsSettings { - return true - } else { - return false - } - } - } - - public var settings: WallpaperSettings? { - switch self { - case let .builtin(settings), let .image(_, settings), let .file(_, _, _, _, _, _, _, _, settings): - return settings - default: - return nil - } - } - - public func withUpdatedSettings(_ settings: WallpaperSettings) -> TelegramWallpaper { - switch self { - case .builtin: - return .builtin(settings) - case .color: - return self - case let .image(representations, _): - return .image(representations, settings) - case let .file(id, accessHash, isCreator, isDefault, isPattern, isDark, slug, file, _): - return .file(id: id, accessHash: accessHash, isCreator: isCreator, isDefault: isDefault, isPattern: settings.color != nil ? true : isPattern, isDark: isDark, slug: slug, file: file, settings: settings) - } - } -} +import SyncCore extension WallpaperSettings { init(apiWallpaperSettings: Api.WallPaperSettings) { diff --git a/submodules/TelegramCore/TelegramCore/Wallpapers.swift b/submodules/TelegramCore/TelegramCore/Wallpapers.swift index 565dce34e7..3bc8eff506 100644 --- a/submodules/TelegramCore/TelegramCore/Wallpapers.swift +++ b/submodules/TelegramCore/TelegramCore/Wallpapers.swift @@ -9,21 +9,7 @@ import SwiftSignalKit import TelegramApi #endif -final class CachedWallpapersConfiguration: PostboxCoding { - let hash: Int32 - - init(hash: Int32) { - self.hash = hash - } - - init(decoder: PostboxDecoder) { - self.hash = decoder.decodeInt32ForKey("hash", orElse: 0) - } - - func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.hash, forKey: "hash") - } -} +import SyncCore public func telegramWallpapers(postbox: Postbox, network: Network, forceUpdate: Bool = false) -> Signal<[TelegramWallpaper], NoError> { let fetch: ([TelegramWallpaper]?, Int32?) -> Signal<[TelegramWallpaper], NoError> = { current, hash in diff --git a/submodules/TelegramCore/TelegramCore/WebpagePreview.swift b/submodules/TelegramCore/TelegramCore/WebpagePreview.swift index 8a52f77688..5b7b842b4d 100644 --- a/submodules/TelegramCore/TelegramCore/WebpagePreview.swift +++ b/submodules/TelegramCore/TelegramCore/WebpagePreview.swift @@ -15,6 +15,8 @@ import Foundation #endif #endif +import SyncCore + public func webpagePreview(account: Account, url: String, webpageId: MediaId? = nil) -> Signal { return webpagePreviewWithProgress(account: account, url: url) |> mapToSignal { next -> Signal in diff --git a/submodules/TelegramPermissions/BUCK b/submodules/TelegramPermissions/BUCK index c0082babff..f7f575af60 100644 --- a/submodules/TelegramPermissions/BUCK +++ b/submodules/TelegramPermissions/BUCK @@ -8,6 +8,7 @@ static_library( deps = [ "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/AccountContext:AccountContext", "//submodules/DeviceAccess:DeviceAccess", diff --git a/submodules/TelegramPermissions/Sources/Permission.swift b/submodules/TelegramPermissions/Sources/Permission.swift index dc7a30d5cc..78d90058cd 100644 --- a/submodules/TelegramPermissions/Sources/Permission.swift +++ b/submodules/TelegramPermissions/Sources/Permission.swift @@ -2,6 +2,7 @@ import Foundation import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import DeviceAccess import AccountContext diff --git a/submodules/TelegramPermissionsUI/BUCK b/submodules/TelegramPermissionsUI/BUCK index c966bce116..291a9e9997 100644 --- a/submodules/TelegramPermissionsUI/BUCK +++ b/submodules/TelegramPermissionsUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/AccountContext:AccountContext", "//submodules/TextFormat:TextFormat", diff --git a/submodules/TelegramPermissionsUI/Sources/PermissionController.swift b/submodules/TelegramPermissionsUI/Sources/PermissionController.swift index 7620502820..b8e7e2853c 100644 --- a/submodules/TelegramPermissionsUI/Sources/PermissionController.swift +++ b/submodules/TelegramPermissionsUI/Sources/PermissionController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import DeviceAccess import AccountContext diff --git a/submodules/TelegramPermissionsUI/Sources/PermissionControllerNode.swift b/submodules/TelegramPermissionsUI/Sources/PermissionControllerNode.swift index 313306012c..b3c1b501c2 100644 --- a/submodules/TelegramPermissionsUI/Sources/PermissionControllerNode.swift +++ b/submodules/TelegramPermissionsUI/Sources/PermissionControllerNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import TelegramPermissions diff --git a/submodules/TelegramPermissionsUI/Sources/PermissionSplitTest.swift b/submodules/TelegramPermissionsUI/Sources/PermissionSplitTest.swift index 19cb69e699..c10048d219 100644 --- a/submodules/TelegramPermissionsUI/Sources/PermissionSplitTest.swift +++ b/submodules/TelegramPermissionsUI/Sources/PermissionSplitTest.swift @@ -3,6 +3,7 @@ import UIKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPermissions extension PermissionKind { diff --git a/submodules/TelegramPresentationData/BUCK b/submodules/TelegramPresentationData/BUCK index 1e48e2b9e0..65db87edf5 100644 --- a/submodules/TelegramPresentationData/BUCK +++ b/submodules/TelegramPresentationData/BUCK @@ -14,6 +14,7 @@ static_library( ], exclude = ["Sources/TelegramPresentationData.h"]), deps = [ "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/Postbox:Postbox#shared", "//submodules/Display:Display#shared", "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", diff --git a/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift b/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift index 914406bd5a..5375ddab1b 100644 --- a/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift +++ b/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import AsyncDisplayKit import TelegramCore +import SyncCore import Display import SwiftSignalKit import Postbox diff --git a/submodules/TelegramPresentationData/Sources/ChatMessageBubbleImages.swift b/submodules/TelegramPresentationData/Sources/ChatMessageBubbleImages.swift index a20f6152de..2ccebc9c4f 100644 --- a/submodules/TelegramPresentationData/Sources/ChatMessageBubbleImages.swift +++ b/submodules/TelegramPresentationData/Sources/ChatMessageBubbleImages.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore public enum MessageBubbleImageNeighbors { case none diff --git a/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift b/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift index 40a6a838cb..8c04bcd836 100644 --- a/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import TelegramUIPreferences private func makeDefaultDayPresentationTheme(accentColor: UIColor, serviceBackgroundColor: UIColor, baseColor: PresentationThemeBaseColor?, day: Bool, preview: Bool) -> PresentationTheme { diff --git a/submodules/TelegramPresentationData/Sources/PresentationData.swift b/submodules/TelegramPresentationData/Sources/PresentationData.swift index 350da3c0e2..7c57936c23 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationData.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationData.swift @@ -3,6 +3,7 @@ import UIKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import Contacts import AddressBook import Display diff --git a/submodules/TelegramPresentationData/Sources/PresentationTheme.swift b/submodules/TelegramPresentationData/Sources/PresentationTheme.swift index 8e3dc3f8c7..d5030c9cbb 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationTheme.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import TelegramUIPreferences public final class PresentationThemeGradientColors { diff --git a/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift b/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift index 9e0b451141..84fa353262 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import TelegramUIPreferences private func decodeColor(_ values: KeyedDecodingContainer, _ key: Key) throws -> UIColor { diff --git a/submodules/TelegramPresentationData/Sources/PresentationThemeCoder.swift b/submodules/TelegramPresentationData/Sources/PresentationThemeCoder.swift index 612a1e0278..057a3e1d4c 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationThemeCoder.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationThemeCoder.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore public func encodePresentationTheme(_ theme: PresentationTheme) -> String? { let encoding = PresentationThemeEncoding() diff --git a/submodules/TelegramPresentationData/Sources/PresentationThemeEssentialGraphics.swift b/submodules/TelegramPresentationData/Sources/PresentationThemeEssentialGraphics.swift index c825b31b52..7f9e7971d0 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationThemeEssentialGraphics.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationThemeEssentialGraphics.swift @@ -3,6 +3,7 @@ import UIKit import Display import Postbox import TelegramCore +import SyncCore import TelegramUIPreferences import AppBundle diff --git a/submodules/TelegramPresentationData/Sources/Resources/PresentationResourcesChat.swift b/submodules/TelegramPresentationData/Sources/Resources/PresentationResourcesChat.swift index 903f3c4419..f21b719d48 100644 --- a/submodules/TelegramPresentationData/Sources/Resources/PresentationResourcesChat.swift +++ b/submodules/TelegramPresentationData/Sources/Resources/PresentationResourcesChat.swift @@ -3,6 +3,7 @@ import UIKit import Display import Postbox import TelegramCore +import SyncCore import AppBundle private func generateLineImage(color: UIColor) -> UIImage? { diff --git a/submodules/TelegramPresentationData/Sources/WallpaperUtils.swift b/submodules/TelegramPresentationData/Sources/WallpaperUtils.swift index 643d8de83e..6e2a569957 100644 --- a/submodules/TelegramPresentationData/Sources/WallpaperUtils.swift +++ b/submodules/TelegramPresentationData/Sources/WallpaperUtils.swift @@ -1,5 +1,6 @@ import Foundation import TelegramCore +import SyncCore public extension TelegramWallpaper { var isEmpty: Bool { diff --git a/submodules/TelegramStringFormatting/BUCK b/submodules/TelegramStringFormatting/BUCK index a0437f7beb..95f01d60cd 100644 --- a/submodules/TelegramStringFormatting/BUCK +++ b/submodules/TelegramStringFormatting/BUCK @@ -7,6 +7,7 @@ static_library( ]), deps = [ "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/Postbox:Postbox#shared", "//submodules/Display:Display#shared", "//submodules/PlatformRestrictionMatching:PlatformRestrictionMatching", diff --git a/submodules/TelegramStringFormatting/Sources/MessageContentKind.swift b/submodules/TelegramStringFormatting/Sources/MessageContentKind.swift index fe4df58980..b0b628d0fe 100644 --- a/submodules/TelegramStringFormatting/Sources/MessageContentKind.swift +++ b/submodules/TelegramStringFormatting/Sources/MessageContentKind.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import PlatformRestrictionMatching diff --git a/submodules/TelegramStringFormatting/Sources/PeerNotificationSoundStrings.swift b/submodules/TelegramStringFormatting/Sources/PeerNotificationSoundStrings.swift index b968ba58b2..6891d3d69b 100644 --- a/submodules/TelegramStringFormatting/Sources/PeerNotificationSoundStrings.swift +++ b/submodules/TelegramStringFormatting/Sources/PeerNotificationSoundStrings.swift @@ -1,5 +1,6 @@ import Foundation import TelegramCore +import SyncCore import TelegramPresentationData private let modernSoundsNamePaths: [KeyPath] = [ diff --git a/submodules/TelegramStringFormatting/Sources/PresenceStrings.swift b/submodules/TelegramStringFormatting/Sources/PresenceStrings.swift index ad1458ec0c..b7bdd08a48 100644 --- a/submodules/TelegramStringFormatting/Sources/PresenceStrings.swift +++ b/submodules/TelegramStringFormatting/Sources/PresenceStrings.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import TelegramPresentationData public func stringForTimestamp(day: Int32, month: Int32, year: Int32, dateTimeFormat: PresentationDateTimeFormat) -> String { diff --git a/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift b/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift index 21ab40a1be..9e7e862c6f 100644 --- a/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift +++ b/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import TextFormat diff --git a/submodules/TelegramUI/BUCK b/submodules/TelegramUI/BUCK index 3005230bb2..5e87c42598 100644 --- a/submodules/TelegramUI/BUCK +++ b/submodules/TelegramUI/BUCK @@ -29,6 +29,7 @@ framework( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/MtProtoKit:MtProtoKit#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/AccountContext:AccountContext", @@ -48,6 +49,7 @@ framework( "//submodules/LightweightAccountData:LightweightAccountData", "//submodules/HockeySDK-iOS:HockeySDK", "//submodules/BuildConfig:BuildConfig", + "//submodules/BuildConfigExtra:BuildConfigExtra", "//submodules/rlottie:RLottieBinding", "//submodules/TelegramUpdateUI:TelegramUpdateUI", "//submodules/MergeLists:MergeLists", diff --git a/submodules/TelegramUI/TelegramUI/AccountContext.swift b/submodules/TelegramUI/TelegramUI/AccountContext.swift index 3b8eea3591..5e0eb615b2 100644 --- a/submodules/TelegramUI/TelegramUI/AccountContext.swift +++ b/submodules/TelegramUI/TelegramUI/AccountContext.swift @@ -3,6 +3,7 @@ import SwiftSignalKit import UIKit import Postbox import TelegramCore +import SyncCore import Display import DeviceAccess import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/AppDelegate.swift b/submodules/TelegramUI/TelegramUI/AppDelegate.swift index ba27cfd557..2190ce4852 100644 --- a/submodules/TelegramUI/TelegramUI/AppDelegate.swift +++ b/submodules/TelegramUI/TelegramUI/AppDelegate.swift @@ -2,6 +2,7 @@ import UIKit import SwiftSignalKit import Display import TelegramCore +import SyncCore import UserNotifications import Intents import HockeySDK @@ -14,6 +15,7 @@ import TelegramPresentationData import TelegramCallsUI import TelegramVoip import BuildConfig +import BuildConfigExtra import DeviceCheck import AccountContext import OverlayStatusController @@ -379,13 +381,14 @@ final class SharedApplicationContext { let maybeAppGroupUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupName) let buildConfig = BuildConfig(baseAppBundleId: baseAppBundleId) + let signatureDict = BuildConfigExtra.signatureDict() let apiId: Int32 = buildConfig.apiId let languagesCategory = "ios" let networkArguments = NetworkInitializationArguments(apiId: apiId, languagesCategory: languagesCategory, appVersion: appVersion, voipMaxLayer: PresentationCallManagerImpl.voipMaxLayer, appData: self.deviceToken.get() |> map { token in - let data = buildConfig.bundleData(withAppToken: token) + let data = buildConfig.bundleData(withAppToken: token, signatureDict: signatureDict) if let data = data, let jsonString = String(data: data, encoding: .utf8) { //Logger.shared.log("data", "\(jsonString)") } else { diff --git a/submodules/TelegramUI/TelegramUI/ApplicationContext.swift b/submodules/TelegramUI/TelegramUI/ApplicationContext.swift index db88e74862..2438cc6ccf 100644 --- a/submodules/TelegramUI/TelegramUI/ApplicationContext.swift +++ b/submodules/TelegramUI/TelegramUI/ApplicationContext.swift @@ -5,6 +5,7 @@ import TelegramUIPreferences import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import Display import LegacyComponents import DeviceAccess diff --git a/submodules/TelegramUI/TelegramUI/AuthorizationSequenceCodeEntryController.swift b/submodules/TelegramUI/TelegramUI/AuthorizationSequenceCodeEntryController.swift index f82156a376..c830768a85 100644 --- a/submodules/TelegramUI/TelegramUI/AuthorizationSequenceCodeEntryController.swift +++ b/submodules/TelegramUI/TelegramUI/AuthorizationSequenceCodeEntryController.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import TelegramPresentationData import ProgressNavigationButtonNode diff --git a/submodules/TelegramUI/TelegramUI/AuthorizationSequenceCodeEntryControllerNode.swift b/submodules/TelegramUI/TelegramUI/AuthorizationSequenceCodeEntryControllerNode.swift index 562e8e05ea..6a13e9ac2d 100644 --- a/submodules/TelegramUI/TelegramUI/AuthorizationSequenceCodeEntryControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/AuthorizationSequenceCodeEntryControllerNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import TextFormat diff --git a/submodules/TelegramUI/TelegramUI/AuthorizationSequenceController.swift b/submodules/TelegramUI/TelegramUI/AuthorizationSequenceController.swift index 9d38bff36d..04fdfb0121 100644 --- a/submodules/TelegramUI/TelegramUI/AuthorizationSequenceController.swift +++ b/submodules/TelegramUI/TelegramUI/AuthorizationSequenceController.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit #if BUCK import MtProtoKit diff --git a/submodules/TelegramUI/TelegramUI/AuthorizationSequencePhoneEntryController.swift b/submodules/TelegramUI/TelegramUI/AuthorizationSequencePhoneEntryController.swift index ee85a6e938..4cdfacc1a9 100644 --- a/submodules/TelegramUI/TelegramUI/AuthorizationSequencePhoneEntryController.swift +++ b/submodules/TelegramUI/TelegramUI/AuthorizationSequencePhoneEntryController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import ProgressNavigationButtonNode diff --git a/submodules/TelegramUI/TelegramUI/AuthorizationSequencePhoneEntryControllerNode.swift b/submodules/TelegramUI/TelegramUI/AuthorizationSequencePhoneEntryControllerNode.swift index 060c75354b..ab4ed4921b 100644 --- a/submodules/TelegramUI/TelegramUI/AuthorizationSequencePhoneEntryControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/AuthorizationSequencePhoneEntryControllerNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import TelegramPresentationData import PhoneInputNode import CountrySelectionUI diff --git a/submodules/TelegramUI/TelegramUI/AuthorizationSequenceSignUpController.swift b/submodules/TelegramUI/TelegramUI/AuthorizationSequenceSignUpController.swift index 11ccd23f80..fa85d1cd79 100644 --- a/submodules/TelegramUI/TelegramUI/AuthorizationSequenceSignUpController.swift +++ b/submodules/TelegramUI/TelegramUI/AuthorizationSequenceSignUpController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import LegacyComponents import ProgressNavigationButtonNode diff --git a/submodules/TelegramUI/TelegramUI/AuthorizationSequenceSplashController.swift b/submodules/TelegramUI/TelegramUI/AuthorizationSequenceSplashController.swift index 182365e79a..184601231f 100644 --- a/submodules/TelegramUI/TelegramUI/AuthorizationSequenceSplashController.swift +++ b/submodules/TelegramUI/TelegramUI/AuthorizationSequenceSplashController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import LegacyComponents diff --git a/submodules/TelegramUI/TelegramUI/ChatBotInfoItem.swift b/submodules/TelegramUI/TelegramUI/ChatBotInfoItem.swift index 4e57b48327..e2c856eeb3 100644 --- a/submodules/TelegramUI/TelegramUI/ChatBotInfoItem.swift +++ b/submodules/TelegramUI/TelegramUI/ChatBotInfoItem.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TextFormat import UrlEscaping diff --git a/submodules/TelegramUI/TelegramUI/ChatBotStartInputPanelNode.swift b/submodules/TelegramUI/TelegramUI/ChatBotStartInputPanelNode.swift index e72895bc29..75e3b5baf7 100644 --- a/submodules/TelegramUI/TelegramUI/ChatBotStartInputPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatBotStartInputPanelNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatButtonKeyboardInputNode.swift b/submodules/TelegramUI/TelegramUI/ChatButtonKeyboardInputNode.swift index 767403dada..c061e21e35 100644 --- a/submodules/TelegramUI/TelegramUI/ChatButtonKeyboardInputNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatButtonKeyboardInputNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatChannelSubscriberInputPanelNode.swift b/submodules/TelegramUI/TelegramUI/ChatChannelSubscriberInputPanelNode.swift index 5df01fafc6..abe3761c10 100644 --- a/submodules/TelegramUI/TelegramUI/ChatChannelSubscriberInputPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatChannelSubscriberInputPanelNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatContextResultPeekContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatContextResultPeekContentNode.swift index 22afefe400..33493ee366 100644 --- a/submodules/TelegramUI/TelegramUI/ChatContextResultPeekContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatContextResultPeekContentNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import AVFoundation import PhotoResources diff --git a/submodules/TelegramUI/TelegramUI/ChatController.swift b/submodules/TelegramUI/TelegramUI/ChatController.swift index 87183a8830..5ac0cfa5ba 100644 --- a/submodules/TelegramUI/TelegramUI/ChatController.swift +++ b/submodules/TelegramUI/TelegramUI/ChatController.swift @@ -5,6 +5,7 @@ import SwiftSignalKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SafariServices import MobileCoreServices import Intents diff --git a/submodules/TelegramUI/TelegramUI/ChatControllerInteraction.swift b/submodules/TelegramUI/TelegramUI/ChatControllerInteraction.swift index c415320a3a..ffc9670b72 100644 --- a/submodules/TelegramUI/TelegramUI/ChatControllerInteraction.swift +++ b/submodules/TelegramUI/TelegramUI/ChatControllerInteraction.swift @@ -3,6 +3,7 @@ import UIKit import Postbox import AsyncDisplayKit import TelegramCore +import SyncCore import Display import TelegramUIPreferences import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatControllerNode.swift b/submodules/TelegramUI/TelegramUI/ChatControllerNode.swift index 100a1fd6dd..148bde606c 100644 --- a/submodules/TelegramUI/TelegramUI/ChatControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatControllerNode.swift @@ -5,6 +5,7 @@ import Postbox import SwiftSignalKit import Display import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import TextFormat diff --git a/submodules/TelegramUI/TelegramUI/ChatEditInterfaceMessageState.swift b/submodules/TelegramUI/TelegramUI/ChatEditInterfaceMessageState.swift index c272bfb5eb..b83b3cd9fc 100644 --- a/submodules/TelegramUI/TelegramUI/ChatEditInterfaceMessageState.swift +++ b/submodules/TelegramUI/TelegramUI/ChatEditInterfaceMessageState.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore enum ChatEditInterfaceMessageStateContent: Equatable { case plaintext diff --git a/submodules/TelegramUI/TelegramUI/ChatEmptyNode.swift b/submodules/TelegramUI/TelegramUI/ChatEmptyNode.swift index af2532e26e..57b0fef12d 100644 --- a/submodules/TelegramUI/TelegramUI/ChatEmptyNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatEmptyNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AppBundle import LocalizedPeerData diff --git a/submodules/TelegramUI/TelegramUI/ChatFeedNavigationInputPanelNode.swift b/submodules/TelegramUI/TelegramUI/ChatFeedNavigationInputPanelNode.swift index 2002703f21..0fadbb4b0d 100644 --- a/submodules/TelegramUI/TelegramUI/ChatFeedNavigationInputPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatFeedNavigationInputPanelNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatHistoryEntriesForView.swift b/submodules/TelegramUI/TelegramUI/ChatHistoryEntriesForView.swift index ea19b9cb12..42c04af47e 100644 --- a/submodules/TelegramUI/TelegramUI/ChatHistoryEntriesForView.swift +++ b/submodules/TelegramUI/TelegramUI/ChatHistoryEntriesForView.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import TemporaryCachedPeerDataManager import Emoji diff --git a/submodules/TelegramUI/TelegramUI/ChatHistoryEntry.swift b/submodules/TelegramUI/TelegramUI/ChatHistoryEntry.swift index 460a99e826..89a6fb2242 100644 --- a/submodules/TelegramUI/TelegramUI/ChatHistoryEntry.swift +++ b/submodules/TelegramUI/TelegramUI/ChatHistoryEntry.swift @@ -1,5 +1,6 @@ import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import MergeLists import TemporaryCachedPeerDataManager diff --git a/submodules/TelegramUI/TelegramUI/ChatHistoryGridNode.swift b/submodules/TelegramUI/TelegramUI/ChatHistoryGridNode.swift index 5bf7b86f9c..725d90456c 100644 --- a/submodules/TelegramUI/TelegramUI/ChatHistoryGridNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatHistoryGridNode.swift @@ -5,6 +5,7 @@ import SwiftSignalKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatHistoryListNode.swift b/submodules/TelegramUI/TelegramUI/ChatHistoryListNode.swift index 387ebebb9f..250f459485 100644 --- a/submodules/TelegramUI/TelegramUI/ChatHistoryListNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatHistoryListNode.swift @@ -5,6 +5,7 @@ import SwiftSignalKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import MediaResources diff --git a/submodules/TelegramUI/TelegramUI/ChatHistorySearchContainerNode.swift b/submodules/TelegramUI/TelegramUI/ChatHistorySearchContainerNode.swift index d350cb3424..974e57853c 100644 --- a/submodules/TelegramUI/TelegramUI/ChatHistorySearchContainerNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatHistorySearchContainerNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import MergeLists import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatHistoryViewForLocation.swift b/submodules/TelegramUI/TelegramUI/ChatHistoryViewForLocation.swift index dd2d20405c..e2e0b3f3e5 100644 --- a/submodules/TelegramUI/TelegramUI/ChatHistoryViewForLocation.swift +++ b/submodules/TelegramUI/TelegramUI/ChatHistoryViewForLocation.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Display import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatInfo.swift b/submodules/TelegramUI/TelegramUI/ChatInfo.swift index 26afc6f80b..0ddd82763a 100644 --- a/submodules/TelegramUI/TelegramUI/ChatInfo.swift +++ b/submodules/TelegramUI/TelegramUI/ChatInfo.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import Display import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatInfoTitlePanelNode.swift b/submodules/TelegramUI/TelegramUI/ChatInfoTitlePanelNode.swift index 41e38db37b..8cf501d61b 100644 --- a/submodules/TelegramUI/TelegramUI/ChatInfoTitlePanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatInfoTitlePanelNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData private enum ChatInfoTitleButton { diff --git a/submodules/TelegramUI/TelegramUI/ChatInputContextPanelNode.swift b/submodules/TelegramUI/TelegramUI/ChatInputContextPanelNode.swift index 57fb47a57c..db70caeb37 100644 --- a/submodules/TelegramUI/TelegramUI/ChatInputContextPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatInputContextPanelNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatInputPanelNode.swift b/submodules/TelegramUI/TelegramUI/ChatInputPanelNode.swift index eb4914d024..d3ea2d179f 100644 --- a/submodules/TelegramUI/TelegramUI/ChatInputPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatInputPanelNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import AccountContext class ChatInputPanelNode: ASDisplayNode { diff --git a/submodules/TelegramUI/TelegramUI/ChatInterfaceInputContextPanels.swift b/submodules/TelegramUI/TelegramUI/ChatInterfaceInputContextPanels.swift index 547cba4f8e..56b2bd8bca 100644 --- a/submodules/TelegramUI/TelegramUI/ChatInterfaceInputContextPanels.swift +++ b/submodules/TelegramUI/TelegramUI/ChatInterfaceInputContextPanels.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import AccountContext private func inputQueryResultPriority(_ result: ChatPresentationInputQueryResult) -> (Int, Bool) { diff --git a/submodules/TelegramUI/TelegramUI/ChatInterfaceInputContexts.swift b/submodules/TelegramUI/TelegramUI/ChatInterfaceInputContexts.swift index a7345909f0..e219fad30a 100644 --- a/submodules/TelegramUI/TelegramUI/ChatInterfaceInputContexts.swift +++ b/submodules/TelegramUI/TelegramUI/ChatInterfaceInputContexts.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import Postbox import Display import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatInterfaceInputNodes.swift b/submodules/TelegramUI/TelegramUI/ChatInterfaceInputNodes.swift index f9101fb299..5aefaec90a 100644 --- a/submodules/TelegramUI/TelegramUI/ChatInterfaceInputNodes.swift +++ b/submodules/TelegramUI/TelegramUI/ChatInterfaceInputNodes.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import AsyncDisplayKit import TelegramCore +import SyncCore import Postbox import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatInterfaceState.swift b/submodules/TelegramUI/TelegramUI/ChatInterfaceState.swift index b788ea5bc3..2b9f4e221d 100644 --- a/submodules/TelegramUI/TelegramUI/ChatInterfaceState.swift +++ b/submodules/TelegramUI/TelegramUI/ChatInterfaceState.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import TextFormat import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatInterfaceStateAccessoryPanels.swift b/submodules/TelegramUI/TelegramUI/ChatInterfaceStateAccessoryPanels.swift index 07615f91e9..38957c8645 100644 --- a/submodules/TelegramUI/TelegramUI/ChatInterfaceStateAccessoryPanels.swift +++ b/submodules/TelegramUI/TelegramUI/ChatInterfaceStateAccessoryPanels.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import AsyncDisplayKit import TelegramCore +import SyncCore import AccountContext func accessoryPanelForChatPresentationIntefaceState(_ chatPresentationInterfaceState: ChatPresentationInterfaceState, context: AccountContext, currentPanel: AccessoryPanelNode?, interfaceInteraction: ChatPanelInterfaceInteraction?) -> AccessoryPanelNode? { diff --git a/submodules/TelegramUI/TelegramUI/ChatInterfaceStateContextMenus.swift b/submodules/TelegramUI/TelegramUI/ChatInterfaceStateContextMenus.swift index ebfe162245..5a3ec081ac 100644 --- a/submodules/TelegramUI/TelegramUI/ChatInterfaceStateContextMenus.swift +++ b/submodules/TelegramUI/TelegramUI/ChatInterfaceStateContextMenus.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import Display import UIKit import SwiftSignalKit diff --git a/submodules/TelegramUI/TelegramUI/ChatInterfaceStateContextQueries.swift b/submodules/TelegramUI/TelegramUI/ChatInterfaceStateContextQueries.swift index 1294e0a49a..57b4e5930a 100644 --- a/submodules/TelegramUI/TelegramUI/ChatInterfaceStateContextQueries.swift +++ b/submodules/TelegramUI/TelegramUI/ChatInterfaceStateContextQueries.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import SwiftSignalKit import TelegramCore +import SyncCore import Postbox import TelegramUIPreferences import LegacyComponents diff --git a/submodules/TelegramUI/TelegramUI/ChatInterfaceStateInputPanels.swift b/submodules/TelegramUI/TelegramUI/ChatInterfaceStateInputPanels.swift index c96a939a1c..9f7c2a2f19 100644 --- a/submodules/TelegramUI/TelegramUI/ChatInterfaceStateInputPanels.swift +++ b/submodules/TelegramUI/TelegramUI/ChatInterfaceStateInputPanels.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import AsyncDisplayKit import TelegramCore +import SyncCore import AccountContext func inputPanelForChatPresentationIntefaceState(_ chatPresentationInterfaceState: ChatPresentationInterfaceState, context: AccountContext, currentPanel: ChatInputPanelNode?, textInputPanelNode: ChatTextInputPanelNode?, interfaceInteraction: ChatPanelInterfaceInteraction?) -> ChatInputPanelNode? { diff --git a/submodules/TelegramUI/TelegramUI/ChatInterfaceStateNavigationButtons.swift b/submodules/TelegramUI/TelegramUI/ChatInterfaceStateNavigationButtons.swift index 695aa3d006..5c8fb99623 100644 --- a/submodules/TelegramUI/TelegramUI/ChatInterfaceStateNavigationButtons.swift +++ b/submodules/TelegramUI/TelegramUI/ChatInterfaceStateNavigationButtons.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatInterfaceTitlePanelNodes.swift b/submodules/TelegramUI/TelegramUI/ChatInterfaceTitlePanelNodes.swift index bc45a9c560..27a5c40448 100644 --- a/submodules/TelegramUI/TelegramUI/ChatInterfaceTitlePanelNodes.swift +++ b/submodules/TelegramUI/TelegramUI/ChatInterfaceTitlePanelNodes.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import AccountContext func titlePanelForChatPresentationInterfaceState(_ chatPresentationInterfaceState: ChatPresentationInterfaceState, context: AccountContext, currentPanel: ChatTitleAccessoryPanelNode?, interfaceInteraction: ChatPanelInterfaceInteraction?) -> ChatTitleAccessoryPanelNode? { diff --git a/submodules/TelegramUI/TelegramUI/ChatLoadingNode.swift b/submodules/TelegramUI/TelegramUI/ChatLoadingNode.swift index 87c93ef9c4..e2280941f0 100644 --- a/submodules/TelegramUI/TelegramUI/ChatLoadingNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatLoadingNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import TelegramPresentationData import ActivityIndicator diff --git a/submodules/TelegramUI/TelegramUI/ChatMediaInputGifPane.swift b/submodules/TelegramUI/TelegramUI/ChatMediaInputGifPane.swift index 13c5324388..8c3ff74e11 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMediaInputGifPane.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMediaInputGifPane.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatMediaInputGridEntries.swift b/submodules/TelegramUI/TelegramUI/ChatMediaInputGridEntries.swift index b65b496c43..9ca8ec1163 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMediaInputGridEntries.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMediaInputGridEntries.swift @@ -1,6 +1,7 @@ import Postbox import UIKit import TelegramCore +import SyncCore import SwiftSignalKit import Display import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatMediaInputMetaSectionItemNode.swift b/submodules/TelegramUI/TelegramUI/ChatMediaInputMetaSectionItemNode.swift index 01c1f9b9ae..c30486cd36 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMediaInputMetaSectionItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMediaInputMetaSectionItemNode.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatMediaInputNode.swift b/submodules/TelegramUI/TelegramUI/ChatMediaInputNode.swift index d2293c60ab..30ddd714ff 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMediaInputNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMediaInputNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import MergeLists diff --git a/submodules/TelegramUI/TelegramUI/ChatMediaInputPanelEntries.swift b/submodules/TelegramUI/TelegramUI/ChatMediaInputPanelEntries.swift index 7b240c8657..7e5537aba7 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMediaInputPanelEntries.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMediaInputPanelEntries.swift @@ -1,6 +1,7 @@ import Postbox import UIKit import TelegramCore +import SyncCore import SwiftSignalKit import Display import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatMediaInputPeerSpecificItem.swift b/submodules/TelegramUI/TelegramUI/ChatMediaInputPeerSpecificItem.swift index 9162d17f04..0559145cf9 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMediaInputPeerSpecificItem.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMediaInputPeerSpecificItem.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatMediaInputRecentGifsItem.swift b/submodules/TelegramUI/TelegramUI/ChatMediaInputRecentGifsItem.swift index 2b2910cbde..d0926be1a2 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMediaInputRecentGifsItem.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMediaInputRecentGifsItem.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatMediaInputSettingsItem.swift b/submodules/TelegramUI/TelegramUI/ChatMediaInputSettingsItem.swift index c2ba57037b..15a69c1d51 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMediaInputSettingsItem.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMediaInputSettingsItem.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatMediaInputStickerGridItem.swift b/submodules/TelegramUI/TelegramUI/ChatMediaInputStickerGridItem.swift index d6fafc4731..20a21a8a5e 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMediaInputStickerGridItem.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMediaInputStickerGridItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import AsyncDisplayKit import Postbox diff --git a/submodules/TelegramUI/TelegramUI/ChatMediaInputStickerPackItem.swift b/submodules/TelegramUI/TelegramUI/ChatMediaInputStickerPackItem.swift index 406910bbbf..8564d3e216 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMediaInputStickerPackItem.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMediaInputStickerPackItem.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatMediaInputStickerPane.swift b/submodules/TelegramUI/TelegramUI/ChatMediaInputStickerPane.swift index 1629717a22..8d6ab03042 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMediaInputStickerPane.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMediaInputStickerPane.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatMediaInputTrendingItem.swift b/submodules/TelegramUI/TelegramUI/ChatMediaInputTrendingItem.swift index c8fda5be13..4b25c0ab63 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMediaInputTrendingItem.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMediaInputTrendingItem.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatMediaInputTrendingPane.swift b/submodules/TelegramUI/TelegramUI/ChatMediaInputTrendingPane.swift index 86df700927..2e95ed5193 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMediaInputTrendingPane.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMediaInputTrendingPane.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import MergeLists diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageActionButtonsNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageActionButtonsNode.swift index 97d3659fe1..af96c3b8f2 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageActionButtonsNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageActionButtonsNode.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import AsyncDisplayKit import TelegramCore +import SyncCore import Postbox import Display import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageActionItemNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageActionItemNode.swift index ccd0f8c9c7..f39d214451 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageActionItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageActionItemNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import TextFormat diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageActionUrlAuthController.swift b/submodules/TelegramUI/TelegramUI/ChatMessageActionUrlAuthController.swift index a227b5b9f4..7d6c017dbb 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageActionUrlAuthController.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageActionUrlAuthController.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import CheckNode diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageAnimatedStickerItemNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageAnimatedStickerItemNode.swift index 8278ac82c7..86a712dd9b 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageAnimatedStickerItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageAnimatedStickerItemNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import CoreImage import TelegramPresentationData import Compression diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageAttachedContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageAttachedContentNode.swift index b4bbe046a8..b844de27dd 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageAttachedContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageAttachedContentNode.swift @@ -5,6 +5,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageAvatarAccessoryItem.swift b/submodules/TelegramUI/TelegramUI/ChatMessageAvatarAccessoryItem.swift index 21477ded25..1b14067218 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageAvatarAccessoryItem.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageAvatarAccessoryItem.swift @@ -3,6 +3,7 @@ import UIKit import Postbox import Display import TelegramCore +import SyncCore import TelegramPresentationData import AvatarNode import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageBubbleContentNode.swift index c2b15b9669..a13e437b08 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageBubbleContentNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramUIPreferences import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift index a84362dfeb..9060653648 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import TextFormat diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageCallBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageCallBubbleContentNode.swift index f7d145cb86..1a667442e5 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageCallBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageCallBubbleContentNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import AppBundle diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageContactBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageContactBubbleContentNode.swift index 3800b24bec..da8fa477f0 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageContactBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageContactBubbleContentNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AvatarNode import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageDateAndStatusNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageDateAndStatusNode.swift index 60208d0478..38cf1fb2e6 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageDateAndStatusNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageDateAndStatusNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import Display import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousDescriptionContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousDescriptionContentNode.swift index f4a99d18ca..2a2a51fff0 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousDescriptionContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousDescriptionContentNode.swift @@ -5,6 +5,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore final class ChatMessageEventLogPreviousDescriptionContentNode: ChatMessageBubbleContentNode { private let contentNode: ChatMessageAttachedContentNode diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousLinkContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousLinkContentNode.swift index cc1e8c6e2f..975026d312 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousLinkContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousLinkContentNode.swift @@ -5,6 +5,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore final class ChatMessageEventLogPreviousLinkContentNode: ChatMessageBubbleContentNode { private let contentNode: ChatMessageAttachedContentNode diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousMessageContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousMessageContentNode.swift index b1df5559bf..bb9ea516dd 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousMessageContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousMessageContentNode.swift @@ -5,6 +5,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore final class ChatMessageEventLogPreviousMessageContentNode: ChatMessageBubbleContentNode { private let contentNode: ChatMessageAttachedContentNode diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageFileBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageFileBubbleContentNode.swift index c82890b1ed..e36825afab 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageFileBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageFileBubbleContentNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramUIPreferences class ChatMessageFileBubbleContentNode: ChatMessageBubbleContentNode { diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageForwardInfoNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageForwardInfoNode.swift index 23bfb7462d..ad44989da9 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageForwardInfoNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageForwardInfoNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import LocalizedPeerData diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageGameBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageGameBubbleContentNode.swift index 74edfa23c4..2c178e673d 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageGameBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageGameBubbleContentNode.swift @@ -5,6 +5,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore final class ChatMessageGameBubbleContentNode: ChatMessageBubbleContentNode { private var game: TelegramMediaGame? diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageInstantVideoItemNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageInstantVideoItemNode.swift index 4d5c154f50..6bff72df76 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageInstantVideoItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageInstantVideoItemNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import TextFormat diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveFileNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveFileNode.swift index 87d4caf3a1..e55d712ebd 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveFileNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveFileNode.swift @@ -5,6 +5,7 @@ import Postbox import SwiftSignalKit import Display import TelegramCore +import SyncCore import UniversalMediaPlayer import TelegramPresentationData import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveInstantVideoNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveInstantVideoNode.swift index 4dd27ddb77..8791948699 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveInstantVideoNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveInstantVideoNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import UniversalMediaPlayer import TelegramPresentationData import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveMediaNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveMediaNode.swift index e2a7ebf344..1607aee70f 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveMediaNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveMediaNode.swift @@ -5,6 +5,7 @@ import Postbox import SwiftSignalKit import Display import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import UniversalMediaPlayer diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageInvoiceBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageInvoiceBubbleContentNode.swift index 9451371c86..467e78d1b3 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageInvoiceBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageInvoiceBubbleContentNode.swift @@ -5,6 +5,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramUIPreferences import TelegramStringFormatting diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageItem.swift b/submodules/TelegramUI/TelegramUI/ChatMessageItem.swift index 5d39e2bc3a..a46bf3c758 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageItem.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageItem.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import Display import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageItemView.swift b/submodules/TelegramUI/TelegramUI/ChatMessageItemView.swift index a240c4e5da..1f3972d0f3 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageItemView.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageItemView.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import AccountContext import LocalizedPeerData import ContextUI diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageMapBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageMapBubbleContentNode.swift index e784f9d292..d9a6074e55 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageMapBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageMapBubbleContentNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import LiveLocationTimerNode import PhotoResources import MediaResources diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageMediaBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageMediaBubbleContentNode.swift index 4c0b023338..8fda443f1f 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageMediaBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageMediaBubbleContentNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramUIPreferences import TelegramPresentationData import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageNotificationItem.swift b/submodules/TelegramUI/TelegramUI/ChatMessageNotificationItem.swift index 04d4516392..21187109ce 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageNotificationItem.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageNotificationItem.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/TelegramUI/TelegramUI/ChatMessagePollBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessagePollBubbleContentNode.swift index 2946be7120..d0d9942b2e 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessagePollBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessagePollBubbleContentNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import TextFormat import UrlEscaping diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageReplyInfoNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageReplyInfoNode.swift index e444e12548..8e60c150b0 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageReplyInfoNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageReplyInfoNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Postbox import Display import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageRestrictedBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageRestrictedBubbleContentNode.swift index 744de6bcf4..218cb6c4ef 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageRestrictedBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageRestrictedBubbleContentNode.swift @@ -5,6 +5,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import TextFormat diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageSelectionInputPanelNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageSelectionInputPanelNode.swift index 7266c79424..7fdea70b64 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageSelectionInputPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageSelectionInputPanelNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageStickerItemNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageStickerItemNode.swift index 1533bdb7e1..fcb7c67c01 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageStickerItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageStickerItemNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TextFormat import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageTextBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageTextBubbleContentNode.swift index eb8b40049c..ee8f9339ad 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageTextBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageTextBubbleContentNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import TextFormat import UrlEscaping diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageUnsupportedBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageUnsupportedBubbleContentNode.swift index 031622b96d..d5f3b64ed0 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageUnsupportedBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageUnsupportedBubbleContentNode.swift @@ -5,6 +5,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData final class ChatMessageUnsupportedBubbleContentNode: ChatMessageBubbleContentNode { diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageWebpageBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageWebpageBubbleContentNode.swift index 33b52082df..f4cf2803f1 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageWebpageBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageWebpageBubbleContentNode.swift @@ -5,6 +5,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramUIPreferences import TextFormat import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatOverlayNavigationBar.swift b/submodules/TelegramUI/TelegramUI/ChatOverlayNavigationBar.swift index e474570e89..a19a48aa66 100644 --- a/submodules/TelegramUI/TelegramUI/ChatOverlayNavigationBar.swift +++ b/submodules/TelegramUI/TelegramUI/ChatOverlayNavigationBar.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/TelegramUI/TelegramUI/ChatPanelInterfaceInteraction.swift b/submodules/TelegramUI/TelegramUI/ChatPanelInterfaceInteraction.swift index 47663594cf..ee7ed6b3e3 100644 --- a/submodules/TelegramUI/TelegramUI/ChatPanelInterfaceInteraction.swift +++ b/submodules/TelegramUI/TelegramUI/ChatPanelInterfaceInteraction.swift @@ -3,6 +3,7 @@ import UIKit import Postbox import SwiftSignalKit import TelegramCore +import SyncCore import Display import AccountContext import ContextUI diff --git a/submodules/TelegramUI/TelegramUI/ChatPinnedMessageTitlePanelNode.swift b/submodules/TelegramUI/TelegramUI/ChatPinnedMessageTitlePanelNode.swift index 68a08104a1..84a3eb30be 100644 --- a/submodules/TelegramUI/TelegramUI/ChatPinnedMessageTitlePanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatPinnedMessageTitlePanelNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/TelegramUI/TelegramUI/ChatPresentationData.swift b/submodules/TelegramUI/TelegramUI/ChatPresentationData.swift index d708d0b888..6d601590aa 100644 --- a/submodules/TelegramUI/TelegramUI/ChatPresentationData.swift +++ b/submodules/TelegramUI/TelegramUI/ChatPresentationData.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/TelegramUI/TelegramUI/ChatPresentationInterfaceState.swift b/submodules/TelegramUI/TelegramUI/ChatPresentationInterfaceState.swift index aa3ba14034..3848c0c89f 100644 --- a/submodules/TelegramUI/TelegramUI/ChatPresentationInterfaceState.swift +++ b/submodules/TelegramUI/TelegramUI/ChatPresentationInterfaceState.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatRecentActionsController.swift b/submodules/TelegramUI/TelegramUI/ChatRecentActionsController.swift index a10a9b21dc..8d372b0713 100644 --- a/submodules/TelegramUI/TelegramUI/ChatRecentActionsController.swift +++ b/submodules/TelegramUI/TelegramUI/ChatRecentActionsController.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatRecentActionsControllerNode.swift b/submodules/TelegramUI/TelegramUI/ChatRecentActionsControllerNode.swift index 3544ecf744..55fd66e5c7 100644 --- a/submodules/TelegramUI/TelegramUI/ChatRecentActionsControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatRecentActionsControllerNode.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import AsyncDisplayKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import Display diff --git a/submodules/TelegramUI/TelegramUI/ChatRecentActionsControllerState.swift b/submodules/TelegramUI/TelegramUI/ChatRecentActionsControllerState.swift index 2aaff1ac9f..bf8b62e26a 100644 --- a/submodules/TelegramUI/TelegramUI/ChatRecentActionsControllerState.swift +++ b/submodules/TelegramUI/TelegramUI/ChatRecentActionsControllerState.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/TelegramUI/TelegramUI/ChatRecentActionsEmptyNode.swift b/submodules/TelegramUI/TelegramUI/ChatRecentActionsEmptyNode.swift index 29809d97fe..3d45cd250d 100644 --- a/submodules/TelegramUI/TelegramUI/ChatRecentActionsEmptyNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatRecentActionsEmptyNode.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import TelegramPresentationData private let titleFont = Font.medium(16.0) diff --git a/submodules/TelegramUI/TelegramUI/ChatRecentActionsFilterController.swift b/submodules/TelegramUI/TelegramUI/ChatRecentActionsFilterController.swift index 0952085ce9..f3b8b97688 100644 --- a/submodules/TelegramUI/TelegramUI/ChatRecentActionsFilterController.swift +++ b/submodules/TelegramUI/TelegramUI/ChatRecentActionsFilterController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import ItemListUI diff --git a/submodules/TelegramUI/TelegramUI/ChatRecentActionsHistoryTransition.swift b/submodules/TelegramUI/TelegramUI/ChatRecentActionsHistoryTransition.swift index 5ccbfa8fda..4bb05c55c0 100644 --- a/submodules/TelegramUI/TelegramUI/ChatRecentActionsHistoryTransition.swift +++ b/submodules/TelegramUI/TelegramUI/ChatRecentActionsHistoryTransition.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import MergeLists diff --git a/submodules/TelegramUI/TelegramUI/ChatRecentActionsSearchNavigationContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatRecentActionsSearchNavigationContentNode.swift index 5d85b5ad79..7b7f7eef1a 100644 --- a/submodules/TelegramUI/TelegramUI/ChatRecentActionsSearchNavigationContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatRecentActionsSearchNavigationContentNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import SearchBarNode diff --git a/submodules/TelegramUI/TelegramUI/ChatRecordingPreviewInputPanelNode.swift b/submodules/TelegramUI/TelegramUI/ChatRecordingPreviewInputPanelNode.swift index 14a9db6411..d2b2509ad3 100644 --- a/submodules/TelegramUI/TelegramUI/ChatRecordingPreviewInputPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatRecordingPreviewInputPanelNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatReportPeerTitlePanelNode.swift b/submodules/TelegramUI/TelegramUI/ChatReportPeerTitlePanelNode.swift index 8a0deb2a6f..df0528f89e 100644 --- a/submodules/TelegramUI/TelegramUI/ChatReportPeerTitlePanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatReportPeerTitlePanelNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import LocalizedPeerData diff --git a/submodules/TelegramUI/TelegramUI/ChatRestrictedInputPanelNode.swift b/submodules/TelegramUI/TelegramUI/ChatRestrictedInputPanelNode.swift index 799682520b..11764aa82e 100644 --- a/submodules/TelegramUI/TelegramUI/ChatRestrictedInputPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatRestrictedInputPanelNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramStringFormatting diff --git a/submodules/TelegramUI/TelegramUI/ChatScheduleTimeController.swift b/submodules/TelegramUI/TelegramUI/ChatScheduleTimeController.swift index 6d3c765d1b..a64cbdcb42 100644 --- a/submodules/TelegramUI/TelegramUI/ChatScheduleTimeController.swift +++ b/submodules/TelegramUI/TelegramUI/ChatScheduleTimeController.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatScheduleTimeControllerNode.swift b/submodules/TelegramUI/TelegramUI/ChatScheduleTimeControllerNode.swift index dce43d01f9..a6959444b5 100644 --- a/submodules/TelegramUI/TelegramUI/ChatScheduleTimeControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatScheduleTimeControllerNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramStringFormatting import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatSearchInputPanelNode.swift b/submodules/TelegramUI/TelegramUI/ChatSearchInputPanelNode.swift index 68badf64fd..47974bf129 100644 --- a/submodules/TelegramUI/TelegramUI/ChatSearchInputPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatSearchInputPanelNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatSearchNavigationContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatSearchNavigationContentNode.swift index 8700928a5d..1d1523fc78 100644 --- a/submodules/TelegramUI/TelegramUI/ChatSearchNavigationContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatSearchNavigationContentNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import SearchBarNode import LocalizedPeerData diff --git a/submodules/TelegramUI/TelegramUI/ChatSearchResultsContollerNode.swift b/submodules/TelegramUI/TelegramUI/ChatSearchResultsContollerNode.swift index 552d6f4d36..b5f82bd021 100644 --- a/submodules/TelegramUI/TelegramUI/ChatSearchResultsContollerNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatSearchResultsContollerNode.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramStringFormatting import MergeLists diff --git a/submodules/TelegramUI/TelegramUI/ChatSearchResultsController.swift b/submodules/TelegramUI/TelegramUI/ChatSearchResultsController.swift index 528cf9c479..fc3a3c14c4 100644 --- a/submodules/TelegramUI/TelegramUI/ChatSearchResultsController.swift +++ b/submodules/TelegramUI/TelegramUI/ChatSearchResultsController.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import Postbox import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ChatSearchState.swift b/submodules/TelegramUI/TelegramUI/ChatSearchState.swift index bf886b8000..c41271a3a5 100644 --- a/submodules/TelegramUI/TelegramUI/ChatSearchState.swift +++ b/submodules/TelegramUI/TelegramUI/ChatSearchState.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore struct ChatSearchState: Equatable { let query: String diff --git a/submodules/TelegramUI/TelegramUI/ChatSecretAutoremoveTimerActionSheet.swift b/submodules/TelegramUI/TelegramUI/ChatSecretAutoremoveTimerActionSheet.swift index 6dd5289115..c51fa40377 100644 --- a/submodules/TelegramUI/TelegramUI/ChatSecretAutoremoveTimerActionSheet.swift +++ b/submodules/TelegramUI/TelegramUI/ChatSecretAutoremoveTimerActionSheet.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import UIKit import TelegramCore +import SyncCore import SwiftSignalKit import Photos import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatSendMessageActionSheetControllerNode.swift b/submodules/TelegramUI/TelegramUI/ChatSendMessageActionSheetControllerNode.swift index 69758f4339..8b9b07248d 100644 --- a/submodules/TelegramUI/TelegramUI/ChatSendMessageActionSheetControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatSendMessageActionSheetControllerNode.swift @@ -5,6 +5,7 @@ import SwiftSignalKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import AppBundle diff --git a/submodules/TelegramUI/TelegramUI/ChatTextInputMediaRecordingButton.swift b/submodules/TelegramUI/TelegramUI/ChatTextInputMediaRecordingButton.swift index c13c723532..086b2f4183 100644 --- a/submodules/TelegramUI/TelegramUI/ChatTextInputMediaRecordingButton.swift +++ b/submodules/TelegramUI/TelegramUI/ChatTextInputMediaRecordingButton.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import LegacyComponents diff --git a/submodules/TelegramUI/TelegramUI/ChatTextInputPanelNode.swift b/submodules/TelegramUI/TelegramUI/ChatTextInputPanelNode.swift index 571889e880..13dca0bb62 100644 --- a/submodules/TelegramUI/TelegramUI/ChatTextInputPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatTextInputPanelNode.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import MobileCoreServices import TelegramPresentationData import TextFormat diff --git a/submodules/TelegramUI/TelegramUI/ChatTextLinkEditController.swift b/submodules/TelegramUI/TelegramUI/ChatTextLinkEditController.swift index cdfa370b54..cb22e5ca92 100644 --- a/submodules/TelegramUI/TelegramUI/ChatTextLinkEditController.swift +++ b/submodules/TelegramUI/TelegramUI/ChatTextLinkEditController.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import UrlEscaping diff --git a/submodules/TelegramUI/TelegramUI/ChatTitleView.swift b/submodules/TelegramUI/TelegramUI/ChatTitleView.swift index a9d06171f1..04ae85c66b 100644 --- a/submodules/TelegramUI/TelegramUI/ChatTitleView.swift +++ b/submodules/TelegramUI/TelegramUI/ChatTitleView.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import LegacyComponents import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ChatUnblockInputPanelNode.swift b/submodules/TelegramUI/TelegramUI/ChatUnblockInputPanelNode.swift index 7bcc64806e..f549a5e64c 100644 --- a/submodules/TelegramUI/TelegramUI/ChatUnblockInputPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatUnblockInputPanelNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/CheckDiskSpace.swift b/submodules/TelegramUI/TelegramUI/CheckDiskSpace.swift index 383f224b79..4d0ae940cc 100644 --- a/submodules/TelegramUI/TelegramUI/CheckDiskSpace.swift +++ b/submodules/TelegramUI/TelegramUI/CheckDiskSpace.swift @@ -1,6 +1,7 @@ import Foundation import Display import TelegramCore +import SyncCore import AccountContext import AlertUI import PresentationDataUtils diff --git a/submodules/TelegramUI/TelegramUI/CommandChatInputContextPanelNode.swift b/submodules/TelegramUI/TelegramUI/CommandChatInputContextPanelNode.swift index d4e97f075b..64f424a6f0 100644 --- a/submodules/TelegramUI/TelegramUI/CommandChatInputContextPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/CommandChatInputContextPanelNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import Display import TelegramPresentationData import MergeLists diff --git a/submodules/TelegramUI/TelegramUI/CommandChatInputPanelItem.swift b/submodules/TelegramUI/TelegramUI/CommandChatInputPanelItem.swift index c1350cc9bc..2701dcea01 100644 --- a/submodules/TelegramUI/TelegramUI/CommandChatInputPanelItem.swift +++ b/submodules/TelegramUI/TelegramUI/CommandChatInputPanelItem.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ComposeController.swift b/submodules/TelegramUI/TelegramUI/ComposeController.swift index 0b12197fd0..3b90b76cc6 100644 --- a/submodules/TelegramUI/TelegramUI/ComposeController.swift +++ b/submodules/TelegramUI/TelegramUI/ComposeController.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import Postbox import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import AlertUI diff --git a/submodules/TelegramUI/TelegramUI/ComposeControllerNode.swift b/submodules/TelegramUI/TelegramUI/ComposeControllerNode.swift index acf0778355..3ed319633c 100644 --- a/submodules/TelegramUI/TelegramUI/ComposeControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/ComposeControllerNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ContactMultiselectionController.swift b/submodules/TelegramUI/TelegramUI/ContactMultiselectionController.swift index fd3b076927..0e48b3d6f4 100644 --- a/submodules/TelegramUI/TelegramUI/ContactMultiselectionController.swift +++ b/submodules/TelegramUI/TelegramUI/ContactMultiselectionController.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import Postbox import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import ProgressNavigationButtonNode import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ContactMultiselectionControllerNode.swift b/submodules/TelegramUI/TelegramUI/ContactMultiselectionControllerNode.swift index 51c5af78ef..c77bb99064 100644 --- a/submodules/TelegramUI/TelegramUI/ContactMultiselectionControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/ContactMultiselectionControllerNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import MergeLists diff --git a/submodules/TelegramUI/TelegramUI/ContactSelectionController.swift b/submodules/TelegramUI/TelegramUI/ContactSelectionController.swift index 5f24ca4799..90604e4c49 100644 --- a/submodules/TelegramUI/TelegramUI/ContactSelectionController.swift +++ b/submodules/TelegramUI/TelegramUI/ContactSelectionController.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import Postbox import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import ProgressNavigationButtonNode import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/ContactSelectionControllerNode.swift b/submodules/TelegramUI/TelegramUI/ContactSelectionControllerNode.swift index 57101e0684..b0920be509 100644 --- a/submodules/TelegramUI/TelegramUI/ContactSelectionControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/ContactSelectionControllerNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/CreateChannelController.swift b/submodules/TelegramUI/TelegramUI/CreateChannelController.swift index 1f0270c5dc..ed917eada3 100644 --- a/submodules/TelegramUI/TelegramUI/CreateChannelController.swift +++ b/submodules/TelegramUI/TelegramUI/CreateChannelController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import LegacyComponents import ItemListUI diff --git a/submodules/TelegramUI/TelegramUI/CreateGroupController.swift b/submodules/TelegramUI/TelegramUI/CreateGroupController.swift index 7ab5bce3f7..e28f14603a 100644 --- a/submodules/TelegramUI/TelegramUI/CreateGroupController.swift +++ b/submodules/TelegramUI/TelegramUI/CreateGroupController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import LegacyComponents diff --git a/submodules/TelegramUI/TelegramUI/DeleteChatInputPanelNode.swift b/submodules/TelegramUI/TelegramUI/DeleteChatInputPanelNode.swift index d1df998767..9223a84239 100644 --- a/submodules/TelegramUI/TelegramUI/DeleteChatInputPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/DeleteChatInputPanelNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit diff --git a/submodules/TelegramUI/TelegramUI/DeviceContactDataManager.swift b/submodules/TelegramUI/TelegramUI/DeviceContactDataManager.swift index 294c75187e..82ea24f4a1 100644 --- a/submodules/TelegramUI/TelegramUI/DeviceContactDataManager.swift +++ b/submodules/TelegramUI/TelegramUI/DeviceContactDataManager.swift @@ -2,6 +2,7 @@ import Foundation import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import Contacts import AddressBook import TelegramUIPreferences diff --git a/submodules/TelegramUI/TelegramUI/DisabledContextResultsChatInputContextPanelNode.swift b/submodules/TelegramUI/TelegramUI/DisabledContextResultsChatInputContextPanelNode.swift index 6b2d3743cb..8d8b412d1e 100644 --- a/submodules/TelegramUI/TelegramUI/DisabledContextResultsChatInputContextPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/DisabledContextResultsChatInputContextPanelNode.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import AsyncDisplayKit import Display import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/DocumentPreviewController.swift b/submodules/TelegramUI/TelegramUI/DocumentPreviewController.swift index b35497d69f..c389573d96 100644 --- a/submodules/TelegramUI/TelegramUI/DocumentPreviewController.swift +++ b/submodules/TelegramUI/TelegramUI/DocumentPreviewController.swift @@ -3,6 +3,7 @@ import UIKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import QuickLook import Display import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/EditAccessoryPanelNode.swift b/submodules/TelegramUI/TelegramUI/EditAccessoryPanelNode.swift index 7cf219a885..6ac41409ce 100644 --- a/submodules/TelegramUI/TelegramUI/EditAccessoryPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/EditAccessoryPanelNode.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import AsyncDisplayKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import Display diff --git a/submodules/TelegramUI/TelegramUI/EmojiResources.swift b/submodules/TelegramUI/TelegramUI/EmojiResources.swift index a33de50839..d93a9da021 100644 --- a/submodules/TelegramUI/TelegramUI/EmojiResources.swift +++ b/submodules/TelegramUI/TelegramUI/EmojiResources.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Display #if BUCK diff --git a/submodules/TelegramUI/TelegramUI/EmojisChatInputContextPanelNode.swift b/submodules/TelegramUI/TelegramUI/EmojisChatInputContextPanelNode.swift index 71eca67836..2ab319c268 100644 --- a/submodules/TelegramUI/TelegramUI/EmojisChatInputContextPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/EmojisChatInputContextPanelNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import Display import TelegramPresentationData import MergeLists diff --git a/submodules/TelegramUI/TelegramUI/EmojisChatInputPanelItem.swift b/submodules/TelegramUI/TelegramUI/EmojisChatInputPanelItem.swift index 7fdb8192a5..6b4da52b89 100644 --- a/submodules/TelegramUI/TelegramUI/EmojisChatInputPanelItem.swift +++ b/submodules/TelegramUI/TelegramUI/EmojisChatInputPanelItem.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/FetchCachedRepresentations.swift b/submodules/TelegramUI/TelegramUI/FetchCachedRepresentations.swift index d9bcde2d84..c7fd5b5340 100644 --- a/submodules/TelegramUI/TelegramUI/FetchCachedRepresentations.swift +++ b/submodules/TelegramUI/TelegramUI/FetchCachedRepresentations.swift @@ -3,6 +3,7 @@ import UIKit import Postbox import SwiftSignalKit import TelegramCore +import SyncCore import ImageIO import MobileCoreServices import Display diff --git a/submodules/TelegramUI/TelegramUI/FetchManager.swift b/submodules/TelegramUI/TelegramUI/FetchManager.swift index 17c80f8b0e..f8fe6683a2 100644 --- a/submodules/TelegramUI/TelegramUI/FetchManager.swift +++ b/submodules/TelegramUI/TelegramUI/FetchManager.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramUIPreferences diff --git a/submodules/TelegramUI/TelegramUI/FetchResource.swift b/submodules/TelegramUI/TelegramUI/FetchResource.swift index 0210791a26..3b436baf37 100644 --- a/submodules/TelegramUI/TelegramUI/FetchResource.swift +++ b/submodules/TelegramUI/TelegramUI/FetchResource.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit func fetchResource(account: Account, resource: MediaResource, intervals: Signal<[(Range, MediaBoxFetchPriority)], NoError>) -> Signal? { diff --git a/submodules/TelegramUI/TelegramUI/FetchVideoMediaResource.swift b/submodules/TelegramUI/TelegramUI/FetchVideoMediaResource.swift index b68e828e8b..4dec4a0d84 100644 --- a/submodules/TelegramUI/TelegramUI/FetchVideoMediaResource.swift +++ b/submodules/TelegramUI/TelegramUI/FetchVideoMediaResource.swift @@ -3,6 +3,7 @@ import UIKit import Postbox import SwiftSignalKit import TelegramCore +import SyncCore import LegacyComponents import FFMpeg import LocalMediaResources diff --git a/submodules/TelegramUI/TelegramUI/FileMediaResourceStatus.swift b/submodules/TelegramUI/TelegramUI/FileMediaResourceStatus.swift index 3267a245de..df635fa8b4 100644 --- a/submodules/TelegramUI/TelegramUI/FileMediaResourceStatus.swift +++ b/submodules/TelegramUI/TelegramUI/FileMediaResourceStatus.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import UniversalMediaPlayer diff --git a/submodules/TelegramUI/TelegramUI/ForwardAccessoryPanelNode.swift b/submodules/TelegramUI/TelegramUI/ForwardAccessoryPanelNode.swift index 22942e4ebe..af121a5a9d 100644 --- a/submodules/TelegramUI/TelegramUI/ForwardAccessoryPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/ForwardAccessoryPanelNode.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import AsyncDisplayKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import Display diff --git a/submodules/TelegramUI/TelegramUI/GifPaneSearchContentNode.swift b/submodules/TelegramUI/TelegramUI/GifPaneSearchContentNode.swift index 2ae027995f..48c50b6f43 100644 --- a/submodules/TelegramUI/TelegramUI/GifPaneSearchContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/GifPaneSearchContentNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import WebSearchUI diff --git a/submodules/TelegramUI/TelegramUI/GridMessageItem.swift b/submodules/TelegramUI/TelegramUI/GridMessageItem.swift index 485dd4c83d..8f55965731 100644 --- a/submodules/TelegramUI/TelegramUI/GridMessageItem.swift +++ b/submodules/TelegramUI/TelegramUI/GridMessageItem.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/HashtagChatInputContextPanelNode.swift b/submodules/TelegramUI/TelegramUI/HashtagChatInputContextPanelNode.swift index b61f4ba0ee..b39be5bc2a 100644 --- a/submodules/TelegramUI/TelegramUI/HashtagChatInputContextPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/HashtagChatInputContextPanelNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import Display import TelegramPresentationData import MergeLists diff --git a/submodules/TelegramUI/TelegramUI/HashtagChatInputPanelItem.swift b/submodules/TelegramUI/TelegramUI/HashtagChatInputPanelItem.swift index aedfdb11bf..9af929732a 100644 --- a/submodules/TelegramUI/TelegramUI/HashtagChatInputPanelItem.swift +++ b/submodules/TelegramUI/TelegramUI/HashtagChatInputPanelItem.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/HorizontalListContextResultsChatInputContextPanelNode.swift b/submodules/TelegramUI/TelegramUI/HorizontalListContextResultsChatInputContextPanelNode.swift index f8bd4cfb7f..83cc958b92 100644 --- a/submodules/TelegramUI/TelegramUI/HorizontalListContextResultsChatInputContextPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/HorizontalListContextResultsChatInputContextPanelNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import Display import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/HorizontalListContextResultsChatInputPanelItem.swift b/submodules/TelegramUI/TelegramUI/HorizontalListContextResultsChatInputPanelItem.swift index 5ae3c07858..80a217b92d 100644 --- a/submodules/TelegramUI/TelegramUI/HorizontalListContextResultsChatInputPanelItem.swift +++ b/submodules/TelegramUI/TelegramUI/HorizontalListContextResultsChatInputPanelItem.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import AVFoundation diff --git a/submodules/TelegramUI/TelegramUI/HorizontalStickerGridItem.swift b/submodules/TelegramUI/TelegramUI/HorizontalStickerGridItem.swift index 996aa3603e..6f7e7325eb 100755 --- a/submodules/TelegramUI/TelegramUI/HorizontalStickerGridItem.swift +++ b/submodules/TelegramUI/TelegramUI/HorizontalStickerGridItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import AsyncDisplayKit import Postbox diff --git a/submodules/TelegramUI/TelegramUI/HorizontalStickersChatContextPanelNode.swift b/submodules/TelegramUI/TelegramUI/HorizontalStickersChatContextPanelNode.swift index 32cf8b9290..45973f089f 100755 --- a/submodules/TelegramUI/TelegramUI/HorizontalStickersChatContextPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/HorizontalStickersChatContextPanelNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import Display import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ICloudResources.swift b/submodules/TelegramUI/TelegramUI/ICloudResources.swift index b9dff88e0d..d009949616 100644 --- a/submodules/TelegramUI/TelegramUI/ICloudResources.swift +++ b/submodules/TelegramUI/TelegramUI/ICloudResources.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Display import Pdf diff --git a/submodules/TelegramUI/TelegramUI/InChatPrefetchManager.swift b/submodules/TelegramUI/TelegramUI/InChatPrefetchManager.swift index c82356c5da..ad8384ef9e 100644 --- a/submodules/TelegramUI/TelegramUI/InChatPrefetchManager.swift +++ b/submodules/TelegramUI/TelegramUI/InChatPrefetchManager.swift @@ -2,6 +2,7 @@ import Foundation import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramUIPreferences import AccountContext import PhotoResources diff --git a/submodules/TelegramUI/TelegramUI/LegacyCamera.swift b/submodules/TelegramUI/TelegramUI/LegacyCamera.swift index 855c868b68..10b972611e 100644 --- a/submodules/TelegramUI/TelegramUI/LegacyCamera.swift +++ b/submodules/TelegramUI/TelegramUI/LegacyCamera.swift @@ -3,6 +3,7 @@ import UIKit import LegacyComponents import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/LegacyInstantVideoController.swift b/submodules/TelegramUI/TelegramUI/LegacyInstantVideoController.swift index ac6853ea1a..e6db48481b 100644 --- a/submodules/TelegramUI/TelegramUI/LegacyInstantVideoController.swift +++ b/submodules/TelegramUI/TelegramUI/LegacyInstantVideoController.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/LegacyLiveUploadInterface.swift b/submodules/TelegramUI/TelegramUI/LegacyLiveUploadInterface.swift index 979d945e27..82c7b859f7 100644 --- a/submodules/TelegramUI/TelegramUI/LegacyLiveUploadInterface.swift +++ b/submodules/TelegramUI/TelegramUI/LegacyLiveUploadInterface.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import LegacyComponents import SwiftSignalKit diff --git a/submodules/TelegramUI/TelegramUI/ListMessageFileItemNode.swift b/submodules/TelegramUI/TelegramUI/ListMessageFileItemNode.swift index 92906e045d..338763c2d3 100644 --- a/submodules/TelegramUI/TelegramUI/ListMessageFileItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ListMessageFileItemNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import ItemListUI diff --git a/submodules/TelegramUI/TelegramUI/ListMessageHoleItem.swift b/submodules/TelegramUI/TelegramUI/ListMessageHoleItem.swift index bb3e062657..c81cffa44f 100644 --- a/submodules/TelegramUI/TelegramUI/ListMessageHoleItem.swift +++ b/submodules/TelegramUI/TelegramUI/ListMessageHoleItem.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import Postbox diff --git a/submodules/TelegramUI/TelegramUI/ListMessageItem.swift b/submodules/TelegramUI/TelegramUI/ListMessageItem.swift index d05359c7ee..fdeebefad1 100644 --- a/submodules/TelegramUI/TelegramUI/ListMessageItem.swift +++ b/submodules/TelegramUI/TelegramUI/ListMessageItem.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/ListMessageSnippetItemNode.swift b/submodules/TelegramUI/TelegramUI/ListMessageSnippetItemNode.swift index c078e9eead..d8edb70306 100644 --- a/submodules/TelegramUI/TelegramUI/ListMessageSnippetItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ListMessageSnippetItemNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import ItemListUI diff --git a/submodules/TelegramUI/TelegramUI/ManageSharedAccountInfo.swift b/submodules/TelegramUI/TelegramUI/ManageSharedAccountInfo.swift index 0d5dc1072b..49ee068a3a 100644 --- a/submodules/TelegramUI/TelegramUI/ManageSharedAccountInfo.swift +++ b/submodules/TelegramUI/TelegramUI/ManageSharedAccountInfo.swift @@ -1,6 +1,7 @@ import Foundation import SwiftSignalKit import TelegramCore +import SyncCore import Postbox import LightweightAccountData diff --git a/submodules/TelegramUI/TelegramUI/ManagedAudioRecorder.swift b/submodules/TelegramUI/TelegramUI/ManagedAudioRecorder.swift index 5ad0a214b4..aac10f44be 100644 --- a/submodules/TelegramUI/TelegramUI/ManagedAudioRecorder.swift +++ b/submodules/TelegramUI/TelegramUI/ManagedAudioRecorder.swift @@ -3,6 +3,7 @@ import SwiftSignalKit import CoreMedia import AVFoundation import TelegramCore +import SyncCore import TelegramAudio import UniversalMediaPlayer import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/MediaInputPaneTrendingItem.swift b/submodules/TelegramUI/TelegramUI/MediaInputPaneTrendingItem.swift index 1b5d3c2ee3..34d4ac0dca 100644 --- a/submodules/TelegramUI/TelegramUI/MediaInputPaneTrendingItem.swift +++ b/submodules/TelegramUI/TelegramUI/MediaInputPaneTrendingItem.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import StickerResources import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/MediaManager.swift b/submodules/TelegramUI/TelegramUI/MediaManager.swift index 757b670ea3..36e254b065 100644 --- a/submodules/TelegramUI/TelegramUI/MediaManager.swift +++ b/submodules/TelegramUI/TelegramUI/MediaManager.swift @@ -4,6 +4,7 @@ import AVFoundation import MobileCoreServices import Postbox import TelegramCore +import SyncCore import MediaPlayer import TelegramAudio import UniversalMediaPlayer diff --git a/submodules/TelegramUI/TelegramUI/MediaPlaybackStoredState.swift b/submodules/TelegramUI/TelegramUI/MediaPlaybackStoredState.swift index c3fb8009c6..09a48aadd4 100644 --- a/submodules/TelegramUI/TelegramUI/MediaPlaybackStoredState.swift +++ b/submodules/TelegramUI/TelegramUI/MediaPlaybackStoredState.swift @@ -3,6 +3,7 @@ import UIKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramUIPreferences public final class MediaPlaybackStoredState: PostboxCoding { diff --git a/submodules/TelegramUI/TelegramUI/MentionChatInputContextPanelNode.swift b/submodules/TelegramUI/TelegramUI/MentionChatInputContextPanelNode.swift index 1ba7d57003..a299957806 100644 --- a/submodules/TelegramUI/TelegramUI/MentionChatInputContextPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/MentionChatInputContextPanelNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import Display import TelegramPresentationData import MergeLists diff --git a/submodules/TelegramUI/TelegramUI/MentionChatInputPanelItem.swift b/submodules/TelegramUI/TelegramUI/MentionChatInputPanelItem.swift index d5f7f18afb..600e3654aa 100644 --- a/submodules/TelegramUI/TelegramUI/MentionChatInputPanelItem.swift +++ b/submodules/TelegramUI/TelegramUI/MentionChatInputPanelItem.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/MultiplexedSoftwareVideoSourceManager.swift b/submodules/TelegramUI/TelegramUI/MultiplexedSoftwareVideoSourceManager.swift index deff80076a..8ab299393c 100644 --- a/submodules/TelegramUI/TelegramUI/MultiplexedSoftwareVideoSourceManager.swift +++ b/submodules/TelegramUI/TelegramUI/MultiplexedSoftwareVideoSourceManager.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import CoreMedia import UniversalMediaPlayer diff --git a/submodules/TelegramUI/TelegramUI/MultiplexedVideoNode.swift b/submodules/TelegramUI/TelegramUI/MultiplexedVideoNode.swift index 16e897f26e..77175e452c 100644 --- a/submodules/TelegramUI/TelegramUI/MultiplexedVideoNode.swift +++ b/submodules/TelegramUI/TelegramUI/MultiplexedVideoNode.swift @@ -5,6 +5,7 @@ import SwiftSignalKit import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import AVFoundation private final class MultiplexedVideoTrackingNode: ASDisplayNode { diff --git a/submodules/TelegramUI/TelegramUI/NavigateToChatController.swift b/submodules/TelegramUI/TelegramUI/NavigateToChatController.swift index efb449495c..5b05789afd 100644 --- a/submodules/TelegramUI/TelegramUI/NavigateToChatController.swift +++ b/submodules/TelegramUI/TelegramUI/NavigateToChatController.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import Postbox import AccountContext import GalleryUI diff --git a/submodules/TelegramUI/TelegramUI/NotificationContainerController.swift b/submodules/TelegramUI/TelegramUI/NotificationContainerController.swift index bf8dd951d1..0bbadaa6b2 100644 --- a/submodules/TelegramUI/TelegramUI/NotificationContainerController.swift +++ b/submodules/TelegramUI/TelegramUI/NotificationContainerController.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/NotificationContentContext.swift b/submodules/TelegramUI/TelegramUI/NotificationContentContext.swift index 98bc190b6f..8d3ac76c50 100644 --- a/submodules/TelegramUI/TelegramUI/NotificationContentContext.swift +++ b/submodules/TelegramUI/TelegramUI/NotificationContentContext.swift @@ -3,6 +3,7 @@ import UserNotifications import UserNotificationsUI import Display import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/OpenAddContact.swift b/submodules/TelegramUI/TelegramUI/OpenAddContact.swift index 684c21af92..ee8e6c9ce1 100644 --- a/submodules/TelegramUI/TelegramUI/OpenAddContact.swift +++ b/submodules/TelegramUI/TelegramUI/OpenAddContact.swift @@ -1,6 +1,7 @@ import Foundation import SwiftSignalKit import TelegramCore +import SyncCore import Display import DeviceAccess import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/OpenChatMessage.swift b/submodules/TelegramUI/TelegramUI/OpenChatMessage.swift index 75658d2f7c..7a5bd10655 100644 --- a/submodules/TelegramUI/TelegramUI/OpenChatMessage.swift +++ b/submodules/TelegramUI/TelegramUI/OpenChatMessage.swift @@ -3,6 +3,7 @@ import Display import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import PassKit import Lottie diff --git a/submodules/TelegramUI/TelegramUI/OpenResolvedUrl.swift b/submodules/TelegramUI/TelegramUI/OpenResolvedUrl.swift index 1457103b97..b0e5ba1b9a 100644 --- a/submodules/TelegramUI/TelegramUI/OpenResolvedUrl.swift +++ b/submodules/TelegramUI/TelegramUI/OpenResolvedUrl.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import Postbox import Display import SwiftSignalKit diff --git a/submodules/TelegramUI/TelegramUI/OpenUrl.swift b/submodules/TelegramUI/TelegramUI/OpenUrl.swift index 5519bf9769..8262f50f8b 100644 --- a/submodules/TelegramUI/TelegramUI/OpenUrl.swift +++ b/submodules/TelegramUI/TelegramUI/OpenUrl.swift @@ -2,6 +2,7 @@ import Foundation import Display import SafariServices import TelegramCore +import SyncCore import Postbox import SwiftSignalKit #if BUCK diff --git a/submodules/TelegramUI/TelegramUI/OverlayAudioPlayerController.swift b/submodules/TelegramUI/TelegramUI/OverlayAudioPlayerController.swift index 49468c7175..d1f106392e 100644 --- a/submodules/TelegramUI/TelegramUI/OverlayAudioPlayerController.swift +++ b/submodules/TelegramUI/TelegramUI/OverlayAudioPlayerController.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import Postbox import Display import SwiftSignalKit diff --git a/submodules/TelegramUI/TelegramUI/OverlayInstantVideoNode.swift b/submodules/TelegramUI/TelegramUI/OverlayInstantVideoNode.swift index b837d81a20..e452d618e2 100644 --- a/submodules/TelegramUI/TelegramUI/OverlayInstantVideoNode.swift +++ b/submodules/TelegramUI/TelegramUI/OverlayInstantVideoNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import SwiftSignalKit import Display import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import UniversalMediaPlayer diff --git a/submodules/TelegramUI/TelegramUI/OverlayPlayerControllerNode.swift b/submodules/TelegramUI/TelegramUI/OverlayPlayerControllerNode.swift index 890ab1ff82..6cc0532fe0 100644 --- a/submodules/TelegramUI/TelegramUI/OverlayPlayerControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/OverlayPlayerControllerNode.swift @@ -5,6 +5,7 @@ import AsyncDisplayKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/OverlayPlayerControlsNode.swift b/submodules/TelegramUI/TelegramUI/OverlayPlayerControlsNode.swift index 4925214b7a..95921c753e 100644 --- a/submodules/TelegramUI/TelegramUI/OverlayPlayerControlsNode.swift +++ b/submodules/TelegramUI/TelegramUI/OverlayPlayerControlsNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import UniversalMediaPlayer diff --git a/submodules/TelegramUI/TelegramUI/PaneSearchContainerNode.swift b/submodules/TelegramUI/TelegramUI/PaneSearchContainerNode.swift index ece3b008e0..21acd7a3e7 100644 --- a/submodules/TelegramUI/TelegramUI/PaneSearchContainerNode.swift +++ b/submodules/TelegramUI/TelegramUI/PaneSearchContainerNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/Pasteboard.swift b/submodules/TelegramUI/TelegramUI/Pasteboard.swift index a33c873b5b..a2a76295aa 100644 --- a/submodules/TelegramUI/TelegramUI/Pasteboard.swift +++ b/submodules/TelegramUI/TelegramUI/Pasteboard.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import MobileCoreServices import TextFormat diff --git a/submodules/TelegramUI/TelegramUI/PeerMediaCollectionController.swift b/submodules/TelegramUI/TelegramUI/PeerMediaCollectionController.swift index 05c1cb865f..7bb46ba00a 100644 --- a/submodules/TelegramUI/TelegramUI/PeerMediaCollectionController.swift +++ b/submodules/TelegramUI/TelegramUI/PeerMediaCollectionController.swift @@ -5,6 +5,7 @@ import SwiftSignalKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SafariServices import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/TelegramUI/TelegramUI/PeerMediaCollectionControllerNode.swift b/submodules/TelegramUI/TelegramUI/PeerMediaCollectionControllerNode.swift index 1829c2283a..f83818d8fd 100644 --- a/submodules/TelegramUI/TelegramUI/PeerMediaCollectionControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/PeerMediaCollectionControllerNode.swift @@ -5,6 +5,7 @@ import Postbox import SwiftSignalKit import Display import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import SearchBarNode diff --git a/submodules/TelegramUI/TelegramUI/PeerMediaCollectionSectionsNode.swift b/submodules/TelegramUI/TelegramUI/PeerMediaCollectionSectionsNode.swift index 1aee8717c2..536bab0372 100644 --- a/submodules/TelegramUI/TelegramUI/PeerMediaCollectionSectionsNode.swift +++ b/submodules/TelegramUI/TelegramUI/PeerMediaCollectionSectionsNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import TelegramPresentationData import SegmentedControlNode diff --git a/submodules/TelegramUI/TelegramUI/PeerMessagesMediaPlaylist.swift b/submodules/TelegramUI/TelegramUI/PeerMessagesMediaPlaylist.swift index 4027d3d731..b8be00a33d 100644 --- a/submodules/TelegramUI/TelegramUI/PeerMessagesMediaPlaylist.swift +++ b/submodules/TelegramUI/TelegramUI/PeerMessagesMediaPlaylist.swift @@ -3,6 +3,7 @@ import UIKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramUIPreferences import AccountContext import MusicAlbumArtResources diff --git a/submodules/TelegramUI/TelegramUI/PeerSelectionController.swift b/submodules/TelegramUI/TelegramUI/PeerSelectionController.swift index 244cb01ba1..feb988676a 100644 --- a/submodules/TelegramUI/TelegramUI/PeerSelectionController.swift +++ b/submodules/TelegramUI/TelegramUI/PeerSelectionController.swift @@ -3,6 +3,7 @@ import UIKit import SwiftSignalKit import Display import TelegramCore +import SyncCore import Postbox import TelegramPresentationData import ProgressNavigationButtonNode diff --git a/submodules/TelegramUI/TelegramUI/PeerSelectionControllerNode.swift b/submodules/TelegramUI/TelegramUI/PeerSelectionControllerNode.swift index 2a225c2207..a8236e890c 100644 --- a/submodules/TelegramUI/TelegramUI/PeerSelectionControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/PeerSelectionControllerNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/PrefetchManager.swift b/submodules/TelegramUI/TelegramUI/PrefetchManager.swift index da6d49999d..f95df18e5b 100644 --- a/submodules/TelegramUI/TelegramUI/PrefetchManager.swift +++ b/submodules/TelegramUI/TelegramUI/PrefetchManager.swift @@ -2,6 +2,7 @@ import Foundation import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramUIPreferences import AccountContext import PhotoResources diff --git a/submodules/TelegramUI/TelegramUI/PreparedChatHistoryViewTransition.swift b/submodules/TelegramUI/TelegramUI/PreparedChatHistoryViewTransition.swift index e78538264f..41732298c8 100644 --- a/submodules/TelegramUI/TelegramUI/PreparedChatHistoryViewTransition.swift +++ b/submodules/TelegramUI/TelegramUI/PreparedChatHistoryViewTransition.swift @@ -2,6 +2,7 @@ import Foundation import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import Display import MergeLists diff --git a/submodules/TelegramUI/TelegramUI/ReplyAccessoryPanelNode.swift b/submodules/TelegramUI/TelegramUI/ReplyAccessoryPanelNode.swift index e829817bb0..0f84596d69 100644 --- a/submodules/TelegramUI/TelegramUI/ReplyAccessoryPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/ReplyAccessoryPanelNode.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import AsyncDisplayKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import Display diff --git a/submodules/TelegramUI/TelegramUI/SecretChatHandshakeStatusInputPanelNode.swift b/submodules/TelegramUI/TelegramUI/SecretChatHandshakeStatusInputPanelNode.swift index 64da067476..4533f217fd 100644 --- a/submodules/TelegramUI/TelegramUI/SecretChatHandshakeStatusInputPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/SecretChatHandshakeStatusInputPanelNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import LocalizedPeerData diff --git a/submodules/TelegramUI/TelegramUI/ShareExtensionContext.swift b/submodules/TelegramUI/TelegramUI/ShareExtensionContext.swift index 19c6deeb6e..562cc6e740 100644 --- a/submodules/TelegramUI/TelegramUI/ShareExtensionContext.swift +++ b/submodules/TelegramUI/TelegramUI/ShareExtensionContext.swift @@ -1,6 +1,7 @@ import UIKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift b/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift index dfc4d08f06..51bf9f087b 100644 --- a/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift +++ b/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Display import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/SharedMediaPlayer.swift b/submodules/TelegramUI/TelegramUI/SharedMediaPlayer.swift index 7dc2940c87..1d3dbfbe20 100644 --- a/submodules/TelegramUI/TelegramUI/SharedMediaPlayer.swift +++ b/submodules/TelegramUI/TelegramUI/SharedMediaPlayer.swift @@ -3,6 +3,7 @@ import UIKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramUIPreferences import UniversalMediaPlayer import TelegramAudio diff --git a/submodules/TelegramUI/TelegramUI/SharedNotificationManager.swift b/submodules/TelegramUI/TelegramUI/SharedNotificationManager.swift index 93069fed16..d36c721f01 100644 --- a/submodules/TelegramUI/TelegramUI/SharedNotificationManager.swift +++ b/submodules/TelegramUI/TelegramUI/SharedNotificationManager.swift @@ -4,6 +4,7 @@ import UserNotifications import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import TelegramCallsUI diff --git a/submodules/TelegramUI/TelegramUI/SharedWakeupManager.swift b/submodules/TelegramUI/TelegramUI/SharedWakeupManager.swift index 2abd8eed61..c6e42eb86c 100644 --- a/submodules/TelegramUI/TelegramUI/SharedWakeupManager.swift +++ b/submodules/TelegramUI/TelegramUI/SharedWakeupManager.swift @@ -3,6 +3,7 @@ import UIKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramCallsUI import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/SoftwareVideoLayerFrameManager.swift b/submodules/TelegramUI/TelegramUI/SoftwareVideoLayerFrameManager.swift index 7385a10619..a4eda40927 100644 --- a/submodules/TelegramUI/TelegramUI/SoftwareVideoLayerFrameManager.swift +++ b/submodules/TelegramUI/TelegramUI/SoftwareVideoLayerFrameManager.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import CoreMedia import UniversalMediaPlayer diff --git a/submodules/TelegramUI/TelegramUI/SoftwareVideoThumbnailLayer.swift b/submodules/TelegramUI/TelegramUI/SoftwareVideoThumbnailLayer.swift index c1047b23e4..370bbfec1f 100644 --- a/submodules/TelegramUI/TelegramUI/SoftwareVideoThumbnailLayer.swift +++ b/submodules/TelegramUI/TelegramUI/SoftwareVideoThumbnailLayer.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import Display diff --git a/submodules/TelegramUI/TelegramUI/StickerPanePeerSpecificSetupGridItem.swift b/submodules/TelegramUI/TelegramUI/StickerPanePeerSpecificSetupGridItem.swift index 7cfe2605cf..dfe5ac122b 100644 --- a/submodules/TelegramUI/TelegramUI/StickerPanePeerSpecificSetupGridItem.swift +++ b/submodules/TelegramUI/TelegramUI/StickerPanePeerSpecificSetupGridItem.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/StickerPaneSearchContentNode.swift b/submodules/TelegramUI/TelegramUI/StickerPaneSearchContentNode.swift index bcdf908070..44de43fd83 100644 --- a/submodules/TelegramUI/TelegramUI/StickerPaneSearchContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/StickerPaneSearchContentNode.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import LegacyComponents import MergeLists diff --git a/submodules/TelegramUI/TelegramUI/StickerPaneSearchGlobaltem.swift b/submodules/TelegramUI/TelegramUI/StickerPaneSearchGlobaltem.swift index 87814071e8..fe3343d2f0 100644 --- a/submodules/TelegramUI/TelegramUI/StickerPaneSearchGlobaltem.swift +++ b/submodules/TelegramUI/TelegramUI/StickerPaneSearchGlobaltem.swift @@ -3,6 +3,7 @@ import UIKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/StickerPaneSearchStickerItem.swift b/submodules/TelegramUI/TelegramUI/StickerPaneSearchStickerItem.swift index 86881e0b42..010d3aa9fc 100644 --- a/submodules/TelegramUI/TelegramUI/StickerPaneSearchStickerItem.swift +++ b/submodules/TelegramUI/TelegramUI/StickerPaneSearchStickerItem.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import AsyncDisplayKit import Postbox diff --git a/submodules/TelegramUI/TelegramUI/StickersChatInputContextPanelItem.swift b/submodules/TelegramUI/TelegramUI/StickersChatInputContextPanelItem.swift index 87302c1b54..461fcc2281 100644 --- a/submodules/TelegramUI/TelegramUI/StickersChatInputContextPanelItem.swift +++ b/submodules/TelegramUI/TelegramUI/StickersChatInputContextPanelItem.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/StickersChatInputContextPanelNode.swift b/submodules/TelegramUI/TelegramUI/StickersChatInputContextPanelNode.swift index 1b64b3631a..9d1bef1ad8 100644 --- a/submodules/TelegramUI/TelegramUI/StickersChatInputContextPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/StickersChatInputContextPanelNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import Display import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/StoreDownloadedMedia.swift b/submodules/TelegramUI/TelegramUI/StoreDownloadedMedia.swift index cde6ba0158..c223c40284 100644 --- a/submodules/TelegramUI/TelegramUI/StoreDownloadedMedia.swift +++ b/submodules/TelegramUI/TelegramUI/StoreDownloadedMedia.swift @@ -1,6 +1,7 @@ import Foundation import SwiftSignalKit import TelegramCore +import SyncCore import Postbox import Photos import TelegramUIPreferences diff --git a/submodules/TelegramUI/TelegramUI/StringForMessageTimestampStatus.swift b/submodules/TelegramUI/TelegramUI/StringForMessageTimestampStatus.swift index 30d0fe4a60..d54a11875b 100644 --- a/submodules/TelegramUI/TelegramUI/StringForMessageTimestampStatus.swift +++ b/submodules/TelegramUI/TelegramUI/StringForMessageTimestampStatus.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import TelegramUIPreferences import TelegramStringFormatting diff --git a/submodules/TelegramUI/TelegramUI/SuppressContactsWarning.swift b/submodules/TelegramUI/TelegramUI/SuppressContactsWarning.swift index daccca51c3..fb07862963 100644 --- a/submodules/TelegramUI/TelegramUI/SuppressContactsWarning.swift +++ b/submodules/TelegramUI/TelegramUI/SuppressContactsWarning.swift @@ -3,6 +3,7 @@ import AsyncDisplayKit import Display import SwiftSignalKit import TelegramCore +import SyncCore import DeviceAccess import AccountContext import AlertUI diff --git a/submodules/TelegramUI/TelegramUI/TelegramAccountAuxiliaryMethods.swift b/submodules/TelegramUI/TelegramUI/TelegramAccountAuxiliaryMethods.swift index ead9c783c1..5307e47aaf 100644 --- a/submodules/TelegramUI/TelegramUI/TelegramAccountAuxiliaryMethods.swift +++ b/submodules/TelegramUI/TelegramUI/TelegramAccountAuxiliaryMethods.swift @@ -1,5 +1,6 @@ import Foundation import TelegramCore +import SyncCore import Postbox import MediaResources import PassportUI diff --git a/submodules/TelegramUI/TelegramUI/TelegramRootController.swift b/submodules/TelegramUI/TelegramUI/TelegramRootController.swift index 20b8de99e5..1e93467e36 100644 --- a/submodules/TelegramUI/TelegramUI/TelegramRootController.swift +++ b/submodules/TelegramUI/TelegramUI/TelegramRootController.swift @@ -3,6 +3,7 @@ import UIKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import AccountContext diff --git a/submodules/TelegramUI/TelegramUI/TextLinkHandling.swift b/submodules/TelegramUI/TelegramUI/TextLinkHandling.swift index cf65db921c..378c50f0d0 100644 --- a/submodules/TelegramUI/TelegramUI/TextLinkHandling.swift +++ b/submodules/TelegramUI/TelegramUI/TextLinkHandling.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import Postbox import Display import SwiftSignalKit diff --git a/submodules/TelegramUI/TelegramUI/ThemeUpdateManager.swift b/submodules/TelegramUI/TelegramUI/ThemeUpdateManager.swift index be6dc72e98..9d5f935e7b 100644 --- a/submodules/TelegramUI/TelegramUI/ThemeUpdateManager.swift +++ b/submodules/TelegramUI/TelegramUI/ThemeUpdateManager.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/TelegramUI/TelegramUI/TimeBasedVideoPreload.swift b/submodules/TelegramUI/TelegramUI/TimeBasedVideoPreload.swift index f2e4a3003c..6205787284 100644 --- a/submodules/TelegramUI/TelegramUI/TimeBasedVideoPreload.swift +++ b/submodules/TelegramUI/TelegramUI/TimeBasedVideoPreload.swift @@ -3,6 +3,7 @@ import UIKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import FFMpeg import UniversalMediaPlayer diff --git a/submodules/TelegramUI/TelegramUI/TransformOutgoingMessageMedia.swift b/submodules/TelegramUI/TelegramUI/TransformOutgoingMessageMedia.swift index ac7c45df45..5d15da6546 100644 --- a/submodules/TelegramUI/TelegramUI/TransformOutgoingMessageMedia.swift +++ b/submodules/TelegramUI/TelegramUI/TransformOutgoingMessageMedia.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import Display diff --git a/submodules/TelegramUI/TelegramUI/UpgradedAccounts.swift b/submodules/TelegramUI/TelegramUI/UpgradedAccounts.swift index f70b37718e..72f5efb54f 100644 --- a/submodules/TelegramUI/TelegramUI/UpgradedAccounts.swift +++ b/submodules/TelegramUI/TelegramUI/UpgradedAccounts.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import TelegramUIPreferences diff --git a/submodules/TelegramUI/TelegramUI/VerticalListContextResultsChatInputContextPanelNode.swift b/submodules/TelegramUI/TelegramUI/VerticalListContextResultsChatInputContextPanelNode.swift index 15d402a5ca..8b9ae73ea9 100644 --- a/submodules/TelegramUI/TelegramUI/VerticalListContextResultsChatInputContextPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/VerticalListContextResultsChatInputContextPanelNode.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Postbox import TelegramCore +import SyncCore import Display import TelegramPresentationData import MergeLists diff --git a/submodules/TelegramUI/TelegramUI/VerticalListContextResultsChatInputPanelButtonItem.swift b/submodules/TelegramUI/TelegramUI/VerticalListContextResultsChatInputPanelButtonItem.swift index 4180031e25..ff9d5a3af7 100644 --- a/submodules/TelegramUI/TelegramUI/VerticalListContextResultsChatInputPanelButtonItem.swift +++ b/submodules/TelegramUI/TelegramUI/VerticalListContextResultsChatInputPanelButtonItem.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/VerticalListContextResultsChatInputPanelItem.swift b/submodules/TelegramUI/TelegramUI/VerticalListContextResultsChatInputPanelItem.swift index 1affd6ebd8..67dc9f0c28 100644 --- a/submodules/TelegramUI/TelegramUI/VerticalListContextResultsChatInputPanelItem.swift +++ b/submodules/TelegramUI/TelegramUI/VerticalListContextResultsChatInputPanelItem.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/WalletContextImpl.swift b/submodules/TelegramUI/TelegramUI/WalletContextImpl.swift index d4ce18d8fd..a334debd0b 100644 --- a/submodules/TelegramUI/TelegramUI/WalletContextImpl.swift +++ b/submodules/TelegramUI/TelegramUI/WalletContextImpl.swift @@ -4,6 +4,7 @@ import Display import WalletUI import Postbox import TelegramCore +import SyncCore import AccountContext import SwiftSignalKit import TelegramPresentationData diff --git a/submodules/TelegramUI/TelegramUI/WallpaperPreviewMedia.swift b/submodules/TelegramUI/TelegramUI/WallpaperPreviewMedia.swift index 1feb8f0c2f..15f80886af 100644 --- a/submodules/TelegramUI/TelegramUI/WallpaperPreviewMedia.swift +++ b/submodules/TelegramUI/TelegramUI/WallpaperPreviewMedia.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore enum WallpaperPreviewMediaContent: Equatable { case file(TelegramMediaFile, UIColor?, Bool, Bool) diff --git a/submodules/TelegramUI/TelegramUI/WallpaperUploadManager.swift b/submodules/TelegramUI/TelegramUI/WallpaperUploadManager.swift index cf3072bc8a..8bbdb76129 100644 --- a/submodules/TelegramUI/TelegramUI/WallpaperUploadManager.swift +++ b/submodules/TelegramUI/TelegramUI/WallpaperUploadManager.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/TelegramUI/TelegramUI/WatchManager.swift b/submodules/TelegramUI/TelegramUI/WatchManager.swift index a1ddbcdd11..a3a9b13d1e 100644 --- a/submodules/TelegramUI/TelegramUI/WatchManager.swift +++ b/submodules/TelegramUI/TelegramUI/WatchManager.swift @@ -2,6 +2,7 @@ import Foundation import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import AccountContext import WatchBridge diff --git a/submodules/TelegramUI/TelegramUI/WebpagePreviewAccessoryPanelNode.swift b/submodules/TelegramUI/TelegramUI/WebpagePreviewAccessoryPanelNode.swift index 569304e5e4..8518d7a1e4 100644 --- a/submodules/TelegramUI/TelegramUI/WebpagePreviewAccessoryPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/WebpagePreviewAccessoryPanelNode.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import AsyncDisplayKit import TelegramCore +import SyncCore import Postbox import SwiftSignalKit import Display diff --git a/submodules/TelegramUI/TelegramUI/WidgetDataContext.swift b/submodules/TelegramUI/TelegramUI/WidgetDataContext.swift index 0c96ef9a34..472f1f43c2 100644 --- a/submodules/TelegramUI/TelegramUI/WidgetDataContext.swift +++ b/submodules/TelegramUI/TelegramUI/WidgetDataContext.swift @@ -2,6 +2,7 @@ import Foundation import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import WidgetItems final class WidgetDataContext { diff --git a/submodules/TelegramUIPreferences/BUCK b/submodules/TelegramUIPreferences/BUCK index 8bb03414dc..a74fe185d2 100644 --- a/submodules/TelegramUIPreferences/BUCK +++ b/submodules/TelegramUIPreferences/BUCK @@ -7,6 +7,7 @@ static_library( ]), deps = [ "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/Postbox:Postbox#shared", "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Display:Display#shared", diff --git a/submodules/TelegramUIPreferences/Sources/LegacyAutomaticMediaDownloadSettings.swift b/submodules/TelegramUIPreferences/Sources/LegacyAutomaticMediaDownloadSettings.swift index 7a767be22d..38342c0547 100644 --- a/submodules/TelegramUIPreferences/Sources/LegacyAutomaticMediaDownloadSettings.swift +++ b/submodules/TelegramUIPreferences/Sources/LegacyAutomaticMediaDownloadSettings.swift @@ -2,6 +2,7 @@ import Foundation import Postbox import SwiftSignalKit import TelegramCore +import SyncCore public struct AutomaticMediaDownloadCategory: PostboxCoding, Equatable { public var cellular: Bool diff --git a/submodules/TelegramUIPreferences/Sources/MediaAutoDownloadSettings.swift b/submodules/TelegramUIPreferences/Sources/MediaAutoDownloadSettings.swift index 4240e5768f..543a981aa8 100644 --- a/submodules/TelegramUIPreferences/Sources/MediaAutoDownloadSettings.swift +++ b/submodules/TelegramUIPreferences/Sources/MediaAutoDownloadSettings.swift @@ -3,6 +3,7 @@ import UIKit import Postbox import SwiftSignalKit import TelegramCore +import SyncCore public enum MediaAutoDownloadNetworkType { case wifi diff --git a/submodules/TelegramUIPreferences/Sources/PostboxKeys.swift b/submodules/TelegramUIPreferences/Sources/PostboxKeys.swift index d5918a2475..b970d6f3c0 100644 --- a/submodules/TelegramUIPreferences/Sources/PostboxKeys.swift +++ b/submodules/TelegramUIPreferences/Sources/PostboxKeys.swift @@ -1,5 +1,6 @@ import Foundation import TelegramCore +import SyncCore import Postbox private enum ApplicationSpecificPreferencesKeyValues: Int32 { diff --git a/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift b/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift index b3d2a9cde4..51a5a9e0d7 100644 --- a/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift +++ b/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import Display diff --git a/submodules/TelegramUIPreferences/Sources/VoiceCallSettings.swift b/submodules/TelegramUIPreferences/Sources/VoiceCallSettings.swift index 91f87db642..22ce711ce3 100644 --- a/submodules/TelegramUIPreferences/Sources/VoiceCallSettings.swift +++ b/submodules/TelegramUIPreferences/Sources/VoiceCallSettings.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit public func effectiveDataSaving(for settings: VoiceCallSettings?, autodownloadSettings: AutodownloadSettings) -> VoiceCallDataSaving { diff --git a/submodules/TelegramUniversalVideoContent/BUCK b/submodules/TelegramUniversalVideoContent/BUCK index 6269fbe9c4..e8c9d6e379 100644 --- a/submodules/TelegramUniversalVideoContent/BUCK +++ b/submodules/TelegramUniversalVideoContent/BUCK @@ -10,6 +10,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/MediaPlayer:UniversalMediaPlayer", "//submodules/AccountContext:AccountContext", diff --git a/submodules/TelegramUniversalVideoContent/Sources/NativeVideoContent.swift b/submodules/TelegramUniversalVideoContent/Sources/NativeVideoContent.swift index da69224dfe..a051cf7d17 100644 --- a/submodules/TelegramUniversalVideoContent/Sources/NativeVideoContent.swift +++ b/submodules/TelegramUniversalVideoContent/Sources/NativeVideoContent.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramAudio import UniversalMediaPlayer import AccountContext diff --git a/submodules/TelegramUniversalVideoContent/Sources/OverlayUniversalVideoNode.swift b/submodules/TelegramUniversalVideoContent/Sources/OverlayUniversalVideoNode.swift index 99928d3f97..c85eb935ed 100644 --- a/submodules/TelegramUniversalVideoContent/Sources/OverlayUniversalVideoNode.swift +++ b/submodules/TelegramUniversalVideoContent/Sources/OverlayUniversalVideoNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import SwiftSignalKit import Display import TelegramCore +import SyncCore import Postbox import TelegramAudio import AccountContext diff --git a/submodules/TelegramUniversalVideoContent/Sources/PlatformVideoContent.swift b/submodules/TelegramUniversalVideoContent/Sources/PlatformVideoContent.swift index c502d86b2d..1b0c887eaa 100644 --- a/submodules/TelegramUniversalVideoContent/Sources/PlatformVideoContent.swift +++ b/submodules/TelegramUniversalVideoContent/Sources/PlatformVideoContent.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import AVFoundation import UniversalMediaPlayer import TelegramAudio diff --git a/submodules/TelegramUniversalVideoContent/Sources/SystemVideoContent.swift b/submodules/TelegramUniversalVideoContent/Sources/SystemVideoContent.swift index 153ade57f3..77d17d9814 100644 --- a/submodules/TelegramUniversalVideoContent/Sources/SystemVideoContent.swift +++ b/submodules/TelegramUniversalVideoContent/Sources/SystemVideoContent.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramAudio import LegacyComponents import UniversalMediaPlayer diff --git a/submodules/TelegramUniversalVideoContent/Sources/WebEmbedPlayerNode.swift b/submodules/TelegramUniversalVideoContent/Sources/WebEmbedPlayerNode.swift index 6420056f7d..5ebd43ed5d 100644 --- a/submodules/TelegramUniversalVideoContent/Sources/WebEmbedPlayerNode.swift +++ b/submodules/TelegramUniversalVideoContent/Sources/WebEmbedPlayerNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import SwiftSignalKit import WebKit import TelegramCore +import SyncCore import UniversalMediaPlayer protocol WebEmbedImplementation { diff --git a/submodules/TelegramUniversalVideoContent/Sources/WebEmbedVideoContent.swift b/submodules/TelegramUniversalVideoContent/Sources/WebEmbedVideoContent.swift index eda6252517..1f676cf4ee 100644 --- a/submodules/TelegramUniversalVideoContent/Sources/WebEmbedVideoContent.swift +++ b/submodules/TelegramUniversalVideoContent/Sources/WebEmbedVideoContent.swift @@ -5,6 +5,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramAudio import UniversalMediaPlayer import LegacyComponents diff --git a/submodules/TelegramUpdateUI/BUCK b/submodules/TelegramUpdateUI/BUCK index 1a6144eb08..0d8ad6cce8 100644 --- a/submodules/TelegramUpdateUI/BUCK +++ b/submodules/TelegramUpdateUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/ItemListUI:ItemListUI", "//submodules/PresentationDataUtils:PresentationDataUtils", diff --git a/submodules/TelegramUpdateUI/Sources/UpdateInfoController.swift b/submodules/TelegramUpdateUI/Sources/UpdateInfoController.swift index a4bcb58f66..4ffa10b036 100644 --- a/submodules/TelegramUpdateUI/Sources/UpdateInfoController.swift +++ b/submodules/TelegramUpdateUI/Sources/UpdateInfoController.swift @@ -4,6 +4,7 @@ import Display import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import AccountContext import ItemListUI diff --git a/submodules/TelegramUpdateUI/Sources/UpdateInfoItem.swift b/submodules/TelegramUpdateUI/Sources/UpdateInfoItem.swift index 46bd04d02b..191872e8b7 100644 --- a/submodules/TelegramUpdateUI/Sources/UpdateInfoItem.swift +++ b/submodules/TelegramUpdateUI/Sources/UpdateInfoItem.swift @@ -4,6 +4,7 @@ import Display import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/TelegramVoip/BUCK b/submodules/TelegramVoip/BUCK index 4e59ef3bf9..862593d529 100644 --- a/submodules/TelegramVoip/BUCK +++ b/submodules/TelegramVoip/BUCK @@ -15,6 +15,7 @@ static_library( deps = [ "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramUIPreferences:TelegramUIPreferences", "//submodules/libtgvoip:libtgvoip", diff --git a/submodules/TelegramVoip/Sources/OngoingCallContext.swift b/submodules/TelegramVoip/Sources/OngoingCallContext.swift index c633873966..0ed0ed551e 100644 --- a/submodules/TelegramVoip/Sources/OngoingCallContext.swift +++ b/submodules/TelegramVoip/Sources/OngoingCallContext.swift @@ -1,6 +1,7 @@ import Foundation import SwiftSignalKit import TelegramCore +import SyncCore import Postbox import TelegramUIPreferences import libtgvoip diff --git a/submodules/TemporaryCachedPeerDataManager/BUCK b/submodules/TemporaryCachedPeerDataManager/BUCK index 373333ce0f..ee728d71c6 100644 --- a/submodules/TemporaryCachedPeerDataManager/BUCK +++ b/submodules/TemporaryCachedPeerDataManager/BUCK @@ -7,9 +7,10 @@ static_library( ]), deps = [ "//submodules/TelegramStringFormatting:TelegramStringFormatting", - "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#dynamic", - "//submodules/TelegramCore:TelegramCore#dynamic", - "//submodules/Postbox:Postbox#dynamic", + "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", + "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", + "//submodules/Postbox:Postbox#shared", ], frameworks = [ "$SDKROOT/System/Library/Frameworks/Foundation.framework", diff --git a/submodules/TemporaryCachedPeerDataManager/Sources/CachedChannelAdmins.swift b/submodules/TemporaryCachedPeerDataManager/Sources/CachedChannelAdmins.swift index 65f2c6b33b..84f2ae814d 100644 --- a/submodules/TemporaryCachedPeerDataManager/Sources/CachedChannelAdmins.swift +++ b/submodules/TemporaryCachedPeerDataManager/Sources/CachedChannelAdmins.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit public enum CachedChannelAdminRank: PostboxCoding, Equatable { diff --git a/submodules/TemporaryCachedPeerDataManager/Sources/ChannelMemberCategoryListContext.swift b/submodules/TemporaryCachedPeerDataManager/Sources/ChannelMemberCategoryListContext.swift index 4ccf68bca9..a21ed2c762 100644 --- a/submodules/TemporaryCachedPeerDataManager/Sources/ChannelMemberCategoryListContext.swift +++ b/submodules/TemporaryCachedPeerDataManager/Sources/ChannelMemberCategoryListContext.swift @@ -1,5 +1,6 @@ import Foundation import TelegramCore +import SyncCore import Postbox import SwiftSignalKit diff --git a/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift b/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift index e7a6db92f3..a1e70f6726 100644 --- a/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift +++ b/submodules/TemporaryCachedPeerDataManager/Sources/PeerChannelMemberCategoriesContextsManager.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import TelegramStringFormatting diff --git a/submodules/TextFormat/BUCK b/submodules/TextFormat/BUCK index 7f3a987751..a5feabed0b 100644 --- a/submodules/TextFormat/BUCK +++ b/submodules/TextFormat/BUCK @@ -6,8 +6,9 @@ static_library( "Sources/**/*.swift", ]), deps = [ - "//submodules/TelegramCore:TelegramCore#dynamic", - "//submodules/Display:Display#dynamic", + "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", + "//submodules/Display:Display#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/Markdown:Markdown", ], diff --git a/submodules/TextFormat/Sources/GenerateTextEntities.swift b/submodules/TextFormat/Sources/GenerateTextEntities.swift index b28f98aa21..e6ed9b7734 100644 --- a/submodules/TextFormat/Sources/GenerateTextEntities.swift +++ b/submodules/TextFormat/Sources/GenerateTextEntities.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore private let dataDetector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType([.link]).rawValue) private let dataAndPhoneNumberDetector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType([.link, .phoneNumber]).rawValue) diff --git a/submodules/TextFormat/Sources/StringWithAppliedEntities.swift b/submodules/TextFormat/Sources/StringWithAppliedEntities.swift index 89a92e0a1a..476efa7ddf 100644 --- a/submodules/TextFormat/Sources/StringWithAppliedEntities.swift +++ b/submodules/TextFormat/Sources/StringWithAppliedEntities.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import TelegramCore +import SyncCore public func chatInputStateStringWithAppliedEntities(_ text: String, entities: [MessageTextEntity]) -> NSAttributedString { var nsString: NSString? diff --git a/submodules/UndoUI/BUCK b/submodules/UndoUI/BUCK index 0855d5c103..5170abfb5a 100644 --- a/submodules/UndoUI/BUCK +++ b/submodules/UndoUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/TextFormat:TextFormat", "//submodules/Markdown:Markdown", diff --git a/submodules/UrlHandling/BUCK b/submodules/UrlHandling/BUCK index 6023479e72..b676eb77ce 100644 --- a/submodules/UrlHandling/BUCK +++ b/submodules/UrlHandling/BUCK @@ -9,6 +9,7 @@ static_library( "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/MtProtoKit:MtProtoKit#shared", "//submodules/AccountContext:AccountContext", "//submodules/TelegramUIPreferences:TelegramUIPreferences", diff --git a/submodules/UrlHandling/Sources/UrlHandling.swift b/submodules/UrlHandling/Sources/UrlHandling.swift index ae5bd673d3..75f53c78ae 100644 --- a/submodules/UrlHandling/Sources/UrlHandling.swift +++ b/submodules/UrlHandling/Sources/UrlHandling.swift @@ -3,6 +3,7 @@ import UIKit import SwiftSignalKit import Postbox import TelegramCore +import SyncCore #if BUCK import MtProtoKit #else diff --git a/submodules/WallpaperResources/BUCK b/submodules/WallpaperResources/BUCK index 6d1177da31..c00518c487 100644 --- a/submodules/WallpaperResources/BUCK +++ b/submodules/WallpaperResources/BUCK @@ -7,6 +7,7 @@ static_library( ]), deps = [ "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/Postbox:Postbox#shared", "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit#shared", "//submodules/Display:Display#shared", diff --git a/submodules/WallpaperResources/Sources/WallpaperCache.swift b/submodules/WallpaperResources/Sources/WallpaperCache.swift index 4b8495c4a5..ac5557bf32 100644 --- a/submodules/WallpaperResources/Sources/WallpaperCache.swift +++ b/submodules/WallpaperResources/Sources/WallpaperCache.swift @@ -4,6 +4,7 @@ import SwiftSignalKit import Postbox import TelegramApi import TelegramCore +import SyncCore import TelegramUIPreferences import PersistentStringHash diff --git a/submodules/WallpaperResources/Sources/WallpaperResources.swift b/submodules/WallpaperResources/Sources/WallpaperResources.swift index ef7a6a1696..5147587ddc 100644 --- a/submodules/WallpaperResources/Sources/WallpaperResources.swift +++ b/submodules/WallpaperResources/Sources/WallpaperResources.swift @@ -4,6 +4,7 @@ import SwiftSignalKit import Display import Postbox import TelegramCore +import SyncCore import MediaResources import ImageBlur import TinyThumbnail diff --git a/submodules/WatchBridge/BUCK b/submodules/WatchBridge/BUCK index b9ca11be66..db0cc53f52 100644 --- a/submodules/WatchBridge/BUCK +++ b/submodules/WatchBridge/BUCK @@ -17,6 +17,7 @@ static_library( "//submodules/SSignalKit/SSignalKit:SSignalKit", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/WatchCommon/Host:WatchCommon", "//submodules/WatchBridgeAudio:WatchBridgeAudio", "//submodules/TelegramPresentationData:TelegramPresentationData", diff --git a/submodules/WatchBridge/Sources/WatchBridge.swift b/submodules/WatchBridge/Sources/WatchBridge.swift index 58f88b68b0..74a15df4f6 100644 --- a/submodules/WatchBridge/Sources/WatchBridge.swift +++ b/submodules/WatchBridge/Sources/WatchBridge.swift @@ -1,6 +1,7 @@ import Foundation import Postbox import TelegramCore +import SyncCore import WatchCommon import TelegramPresentationData import LegacyUI diff --git a/submodules/WatchBridge/Sources/WatchCommunicationManager.swift b/submodules/WatchBridge/Sources/WatchCommunicationManager.swift index 00167aa04d..55ed7a862a 100644 --- a/submodules/WatchBridge/Sources/WatchCommunicationManager.swift +++ b/submodules/WatchBridge/Sources/WatchCommunicationManager.swift @@ -2,6 +2,7 @@ import Foundation import SwiftSignalKit import Postbox import TelegramCore +import SyncCore import WatchCommon import SSignalKit import TelegramUIPreferences diff --git a/submodules/WatchBridge/Sources/WatchRequestHandlers.swift b/submodules/WatchBridge/Sources/WatchRequestHandlers.swift index 5cf315186e..559faaf7b2 100644 --- a/submodules/WatchBridge/Sources/WatchRequestHandlers.swift +++ b/submodules/WatchBridge/Sources/WatchRequestHandlers.swift @@ -3,6 +3,7 @@ import SwiftSignalKit import Postbox import Display import TelegramCore +import SyncCore import LegacyComponents import WatchCommon import TelegramPresentationData diff --git a/submodules/WebSearchUI/BUCK b/submodules/WebSearchUI/BUCK index 3ff9abbe7e..53ad3af445 100644 --- a/submodules/WebSearchUI/BUCK +++ b/submodules/WebSearchUI/BUCK @@ -11,6 +11,7 @@ static_library( "//submodules/Display:Display#shared", "//submodules/Postbox:Postbox#shared", "//submodules/TelegramCore:TelegramCore#shared", + "//submodules/SyncCore:SyncCore#shared", "//submodules/TelegramPresentationData:TelegramPresentationData", "//submodules/AccountContext:AccountContext", "//submodules/LegacyComponents:LegacyComponents", diff --git a/submodules/WebSearchUI/Sources/LegacyWebSearchEditor.swift b/submodules/WebSearchUI/Sources/LegacyWebSearchEditor.swift index a27dea3ff7..5fb3ac16d1 100644 --- a/submodules/WebSearchUI/Sources/LegacyWebSearchEditor.swift +++ b/submodules/WebSearchUI/Sources/LegacyWebSearchEditor.swift @@ -3,6 +3,7 @@ import UIKit import LegacyComponents import SwiftSignalKit import TelegramCore +import SyncCore import Postbox import SSignalKit import Display diff --git a/submodules/WebSearchUI/Sources/LegacyWebSearchGallery.swift b/submodules/WebSearchUI/Sources/LegacyWebSearchGallery.swift index 5803478fbc..9f97cfb4bd 100644 --- a/submodules/WebSearchUI/Sources/LegacyWebSearchGallery.swift +++ b/submodules/WebSearchUI/Sources/LegacyWebSearchGallery.swift @@ -3,6 +3,7 @@ import UIKit import LegacyComponents import SwiftSignalKit import TelegramCore +import SyncCore import Postbox import SSignalKit import UIKit diff --git a/submodules/WebSearchUI/Sources/WebSearchController.swift b/submodules/WebSearchUI/Sources/WebSearchController.swift index 9d636caffc..9bb973d8d7 100644 --- a/submodules/WebSearchUI/Sources/WebSearchController.swift +++ b/submodules/WebSearchUI/Sources/WebSearchController.swift @@ -5,6 +5,7 @@ import SwiftSignalKit import Display import AsyncDisplayKit import TelegramCore +import SyncCore import LegacyComponents import TelegramUIPreferences import AccountContext diff --git a/submodules/WebSearchUI/Sources/WebSearchControllerNode.swift b/submodules/WebSearchUI/Sources/WebSearchControllerNode.swift index a7edcf2165..98e38298cf 100644 --- a/submodules/WebSearchUI/Sources/WebSearchControllerNode.swift +++ b/submodules/WebSearchUI/Sources/WebSearchControllerNode.swift @@ -5,6 +5,7 @@ import Postbox import SwiftSignalKit import Display import TelegramCore +import SyncCore import LegacyComponents import TelegramPresentationData import TelegramUIPreferences diff --git a/submodules/WebSearchUI/Sources/WebSearchGalleryController.swift b/submodules/WebSearchUI/Sources/WebSearchGalleryController.swift index 9e38774c0b..ccf8804fdb 100644 --- a/submodules/WebSearchUI/Sources/WebSearchGalleryController.swift +++ b/submodules/WebSearchUI/Sources/WebSearchGalleryController.swift @@ -6,6 +6,7 @@ import Postbox import SwiftSignalKit import AsyncDisplayKit import TelegramCore +import SyncCore import LegacyComponents import TelegramPresentationData import AccountContext diff --git a/submodules/WebSearchUI/Sources/WebSearchGalleryFooterContentNode.swift b/submodules/WebSearchUI/Sources/WebSearchGalleryFooterContentNode.swift index 7ae115385e..39656af3aa 100644 --- a/submodules/WebSearchUI/Sources/WebSearchGalleryFooterContentNode.swift +++ b/submodules/WebSearchUI/Sources/WebSearchGalleryFooterContentNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import SwiftSignalKit import LegacyComponents import TelegramPresentationData diff --git a/submodules/WebSearchUI/Sources/WebSearchItem.swift b/submodules/WebSearchUI/Sources/WebSearchItem.swift index b1592d3779..00a4ca76c4 100644 --- a/submodules/WebSearchUI/Sources/WebSearchItem.swift +++ b/submodules/WebSearchUI/Sources/WebSearchItem.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import Display import TelegramCore +import SyncCore import SwiftSignalKit import Postbox import TelegramPresentationData diff --git a/submodules/WebSearchUI/Sources/WebSearchNavigationContentNode.swift b/submodules/WebSearchUI/Sources/WebSearchNavigationContentNode.swift index 0b59b3bada..b50c59dc6f 100644 --- a/submodules/WebSearchUI/Sources/WebSearchNavigationContentNode.swift +++ b/submodules/WebSearchUI/Sources/WebSearchNavigationContentNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import Display import Postbox import TelegramCore +import SyncCore import TelegramPresentationData import SearchBarNode diff --git a/submodules/WebSearchUI/Sources/WebSearchRecentQueryItem.swift b/submodules/WebSearchUI/Sources/WebSearchRecentQueryItem.swift index e59a6f6a00..2ee0f99011 100644 --- a/submodules/WebSearchUI/Sources/WebSearchRecentQueryItem.swift +++ b/submodules/WebSearchUI/Sources/WebSearchRecentQueryItem.swift @@ -5,6 +5,7 @@ import Postbox import Display import SwiftSignalKit import TelegramCore +import SyncCore import TelegramPresentationData import ItemListUI import PresentationDataUtils diff --git a/submodules/WebSearchUI/Sources/WebSearchVideoGalleryItem.swift b/submodules/WebSearchUI/Sources/WebSearchVideoGalleryItem.swift index f6b3fdb528..ee199f8778 100644 --- a/submodules/WebSearchUI/Sources/WebSearchVideoGalleryItem.swift +++ b/submodules/WebSearchUI/Sources/WebSearchVideoGalleryItem.swift @@ -3,6 +3,7 @@ import UIKit import AsyncDisplayKit import SwiftSignalKit import TelegramCore +import SyncCore import Display import Postbox import TelegramPresentationData