From b3376cb619006b694c853cfb69e19c237fffdbf5 Mon Sep 17 00:00:00 2001 From: overtake Date: Tue, 29 Aug 2017 17:21:04 +0300 Subject: [PATCH] no message --- TelegramCore.xcodeproj/project.pbxproj | 6 ++++ TelegramCore/CachedChannelData.swift | 1 + TelegramCore/UpdateCachedPeerData.swift | 3 ++ .../UpdateGroupSpecificStickerset.swift | 36 +++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 TelegramCore/UpdateGroupSpecificStickerset.swift diff --git a/TelegramCore.xcodeproj/project.pbxproj b/TelegramCore.xcodeproj/project.pbxproj index f4632ddae6..05ba56ee98 100644 --- a/TelegramCore.xcodeproj/project.pbxproj +++ b/TelegramCore.xcodeproj/project.pbxproj @@ -34,6 +34,8 @@ C27982541E73078400262BFD /* SecretChatStateBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = C27982521E73077800262BFD /* SecretChatStateBridge.swift */; }; C28725421EF967E700613564 /* NotificationInfoMessageAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = C28725411EF967E700613564 /* NotificationInfoMessageAttribute.swift */; }; C28725431EF967E700613564 /* NotificationInfoMessageAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = C28725411EF967E700613564 /* NotificationInfoMessageAttribute.swift */; }; + C29340F31F5080FA0074991E /* UpdateGroupSpecificStickerset.swift in Sources */ = {isa = PBXBuildFile; fileRef = C29340F21F5080FA0074991E /* UpdateGroupSpecificStickerset.swift */; }; + C29340F41F5081280074991E /* UpdateGroupSpecificStickerset.swift in Sources */ = {isa = PBXBuildFile; fileRef = C29340F21F5080FA0074991E /* UpdateGroupSpecificStickerset.swift */; }; C2A315C01E2E776A00D89000 /* RequestStartBot.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01749581E1092BC0057C89A /* RequestStartBot.swift */; }; C2E064681ECEEF0A00387BB8 /* TelegramMediaInvoice.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2E064671ECEEF0A00387BB8 /* TelegramMediaInvoice.swift */; }; C2E064691ECEEF0B00387BB8 /* TelegramMediaInvoice.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2E064671ECEEF0A00387BB8 /* TelegramMediaInvoice.swift */; }; @@ -595,6 +597,7 @@ C27982501E72C97800262BFD /* MacosLegacy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MacosLegacy.swift; sourceTree = ""; }; C27982521E73077800262BFD /* SecretChatStateBridge.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecretChatStateBridge.swift; sourceTree = ""; }; C28725411EF967E700613564 /* NotificationInfoMessageAttribute.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotificationInfoMessageAttribute.swift; sourceTree = ""; }; + C29340F21F5080FA0074991E /* UpdateGroupSpecificStickerset.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateGroupSpecificStickerset.swift; sourceTree = ""; }; C2E064671ECEEF0A00387BB8 /* TelegramMediaInvoice.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TelegramMediaInvoice.swift; sourceTree = ""; }; C2E0646C1ECF171D00387BB8 /* TelegramMediaWebDocument.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TelegramMediaWebDocument.swift; sourceTree = ""; }; C2F4ED1C1EC60064005F2696 /* RateCall.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RateCall.swift; sourceTree = ""; }; @@ -970,6 +973,7 @@ D0E23DDE1E8082A400B9B6D2 /* ArchivedStickerPacks.swift */, D0C27B3E1F4B51D000A4E170 /* CachedStickerPack.swift */, D0C27B411F4B58C000A4E170 /* PeerSpecificStickerPack.swift */, + C29340F21F5080FA0074991E /* UpdateGroupSpecificStickerset.swift */, ); name = "Sticker Management"; sourceTree = ""; @@ -1853,6 +1857,7 @@ D0DC354E1DE368F7000195EB /* RequestChatContextResults.swift in Sources */, D0BC38771E40BAAA0044D6FE /* ManagedSynchronizePinnedChatsOperations.swift in Sources */, D0B843851DA6EDC4005F29E1 /* CachedChannelData.swift in Sources */, + C29340F31F5080FA0074991E /* UpdateGroupSpecificStickerset.swift in Sources */, D01C7ED31EF5DF83008305F1 /* LimitsConfiguration.swift in Sources */, D0F02CE51E9926C40065DEE2 /* ManagedConfigurationUpdates.swift in Sources */, D0528E6A1E65DD2100E2FEF5 /* WebpagePreview.swift in Sources */, @@ -1960,6 +1965,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + C29340F41F5081280074991E /* UpdateGroupSpecificStickerset.swift in Sources */, C25638021E79E7FC00311607 /* TwoStepVerification.swift in Sources */, C27982541E73078400262BFD /* SecretChatStateBridge.swift in Sources */, D00DBBD81E64E41100DB5485 /* CreateSecretChat.swift in Sources */, diff --git a/TelegramCore/CachedChannelData.swift b/TelegramCore/CachedChannelData.swift index 8c731a9f0b..bacc55dc68 100644 --- a/TelegramCore/CachedChannelData.swift +++ b/TelegramCore/CachedChannelData.swift @@ -18,6 +18,7 @@ public struct CachedChannelFlags: OptionSet { 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 struct CachedChannelParticipantsSummary: Coding, Equatable { diff --git a/TelegramCore/UpdateCachedPeerData.swift b/TelegramCore/UpdateCachedPeerData.swift index 2150c894ef..fe85bc5939 100644 --- a/TelegramCore/UpdateCachedPeerData.swift +++ b/TelegramCore/UpdateCachedPeerData.swift @@ -225,6 +225,9 @@ func fetchAndUpdateCachedPeerData(peerId: PeerId, network: Network, postbox: Pos if (flags & (1 << 6)) != 0 { channelFlags.insert(.canChangeUsername) } + if (flags & (1 << 7)) != 0 { + channelFlags.insert(.canSetStickerSet) + } var botInfos: [CachedPeerBotInfo] = [] for botInfo in apiBotInfos { switch botInfo { diff --git a/TelegramCore/UpdateGroupSpecificStickerset.swift b/TelegramCore/UpdateGroupSpecificStickerset.swift new file mode 100644 index 0000000000..8f608ef5c1 --- /dev/null +++ b/TelegramCore/UpdateGroupSpecificStickerset.swift @@ -0,0 +1,36 @@ +import Foundation +#if os(macOS) + import PostboxMac + import SwiftSignalKitMac +#else + import Postbox + import SwiftSignalKit +#endif + + +public func updateGroupSpecificStickerset(postbox: Postbox, network: Network, peerId:PeerId, info:StickerPackCollectionInfo?) -> Signal { + return postbox.loadedPeerWithId(peerId) |> mapToSignal { peer in + let inputStickerset: Api.InputStickerSet + if let info = info { + inputStickerset = Api.InputStickerSet.inputStickerSetShortName(shortName: info.shortName) + } else { + inputStickerset = Api.InputStickerSet.inputStickerSetEmpty + } + if let inputChannel = apiInputChannel(peer) { + let api = Api.functions.channels.setStickers(channel: inputChannel, stickerset: inputStickerset) + return network.request(api) |> retryRequest |> mapToSignal { value in + switch value { + case .boolTrue: + return postbox.modify { modifier -> Void in + return modifier.updatePeerCachedData(peerIds: [peerId], update: { _, current -> CachedPeerData? in + return (current as? CachedChannelData)?.withUpdatedStickerPack(info) + }) + } + default: + return .complete() + } + } + } + return .complete() + } +}