diff --git a/TelegramCore.xcodeproj/project.pbxproj b/TelegramCore.xcodeproj/project.pbxproj index 06ac99647e..d39ea0659b 100644 --- a/TelegramCore.xcodeproj/project.pbxproj +++ b/TelegramCore.xcodeproj/project.pbxproj @@ -739,6 +739,8 @@ D0F3CC7D1DDE289E008148FA /* ResolvePeerByName.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0F3CC7C1DDE289E008148FA /* ResolvePeerByName.swift */; }; D0F53BE91E784A4800117362 /* ChangeAccountPhoneNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0F53BE81E784A4800117362 /* ChangeAccountPhoneNumber.swift */; }; D0F53BEA1E784A4800117362 /* ChangeAccountPhoneNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0F53BE81E784A4800117362 /* ChangeAccountPhoneNumber.swift */; }; + D0F760D822202FE20074F7E5 /* ChannelStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0F760D722202FE20074F7E5 /* ChannelStats.swift */; }; + D0F760D922202FE20074F7E5 /* ChannelStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0F760D722202FE20074F7E5 /* ChannelStats.swift */; }; D0F7AB2C1DCE889D009AD9A1 /* EditedMessageAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0F7AB2B1DCE889D009AD9A1 /* EditedMessageAttribute.swift */; }; D0F7AB2D1DCE889D009AD9A1 /* EditedMessageAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0F7AB2B1DCE889D009AD9A1 /* EditedMessageAttribute.swift */; }; D0F7AB2F1DCF507E009AD9A1 /* ReplyMarkupMessageAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0F7AB2E1DCF507E009AD9A1 /* ReplyMarkupMessageAttribute.swift */; }; @@ -1200,6 +1202,7 @@ D0F3A8A71E82CD7D00B4C64C /* UpdatePeerChatInterfaceState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdatePeerChatInterfaceState.swift; sourceTree = ""; }; D0F3CC7C1DDE289E008148FA /* ResolvePeerByName.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResolvePeerByName.swift; sourceTree = ""; }; D0F53BE81E784A4800117362 /* ChangeAccountPhoneNumber.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChangeAccountPhoneNumber.swift; sourceTree = ""; }; + D0F760D722202FE20074F7E5 /* ChannelStats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelStats.swift; sourceTree = ""; }; D0F7AB2B1DCE889D009AD9A1 /* EditedMessageAttribute.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditedMessageAttribute.swift; sourceTree = ""; }; D0F7AB2E1DCF507E009AD9A1 /* ReplyMarkupMessageAttribute.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReplyMarkupMessageAttribute.swift; sourceTree = ""; }; D0F8C39C20178B9B00236FC5 /* GroupFeedPeers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupFeedPeers.swift; sourceTree = ""; }; @@ -1962,6 +1965,7 @@ D0F8C39C20178B9B00236FC5 /* GroupFeedPeers.swift */, D018EE042045E95000CBB130 /* CheckPeerChatServiceActions.swift */, 9F06830F21A40DEC001D8EDB /* NotificationExceptionsList.swift */, + D0F760D722202FE20074F7E5 /* ChannelStats.swift */, ); name = Peers; sourceTree = ""; @@ -2469,6 +2473,7 @@ D0CA3F84207391560042D2B6 /* SecureIdPadding.swift in Sources */, D0FA8BB61E223C16001E855B /* SecretApiLayer8.swift in Sources */, D0B843C71DA7FF30005F29E1 /* NBPhoneNumberDefines.m in Sources */, + D0F760D822202FE20074F7E5 /* ChannelStats.swift in Sources */, 0962E66921B5A11100245FD9 /* SynchronizeAppLogEventsOperation.swift in Sources */, D049EAF51E44DF3300A2CD3A /* AccountState.swift in Sources */, C28725421EF967E700613564 /* NotificationInfoMessageAttribute.swift in Sources */, @@ -2861,6 +2866,7 @@ D0F7B1E41E045C7B007EB8A5 /* InstantPage.swift in Sources */, D03E5E0D1E55E02D0029569A /* LoggedOutAccountAttribute.swift in Sources */, D0B418AD1D7E0597004562A4 /* Serialization.swift in Sources */, + D0F760D922202FE20074F7E5 /* ChannelStats.swift in Sources */, D0ADF912212B00DD00310BBC /* SecureIdConfiguration.swift in Sources */, C28725431EF967E700613564 /* NotificationInfoMessageAttribute.swift in Sources */, D0A89990217A37A000759EE6 /* NotificationAutolockReportManager.swift in Sources */, diff --git a/TelegramCore/Api3.swift b/TelegramCore/Api3.swift index df2263a878..39bcc227d9 100644 --- a/TelegramCore/Api3.swift +++ b/TelegramCore/Api3.swift @@ -2740,11 +2740,12 @@ extension Api { }) } - static func getStatsURL(peer: Api.InputPeer) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + static func getStatsURL(peer: Api.InputPeer, params: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(-2080980787) + buffer.appendInt32(-338326349) peer.serialize(buffer, true) - return (FunctionDescription(name: "messages.getStatsURL", parameters: [("peer", peer)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.StatsURL? in + serializeString(params, buffer: buffer, boxed: false) + return (FunctionDescription(name: "messages.getStatsURL", parameters: [("peer", peer), ("params", params)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.StatsURL? in let reader = BufferReader(buffer) var result: Api.StatsURL? if let signature = reader.readInt32() { diff --git a/TelegramCore/CachedChannelData.swift b/TelegramCore/CachedChannelData.swift index 171693fd33..61e0082da4 100644 --- a/TelegramCore/CachedChannelData.swift +++ b/TelegramCore/CachedChannelData.swift @@ -20,6 +20,7 @@ public struct CachedChannelFlags: OptionSet { 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 struct CachedChannelParticipantsSummary: PostboxCoding, Equatable { diff --git a/TelegramCore/ChannelStats.swift b/TelegramCore/ChannelStats.swift new file mode 100644 index 0000000000..460007169c --- /dev/null +++ b/TelegramCore/ChannelStats.swift @@ -0,0 +1,34 @@ +import Foundation +#if os(macOS) +import SwiftSignalKitMac +import PostboxMac +#else +import SwiftSignalKit +import Postbox +#endif + +public enum ChannelStatsUrlError { + case generic +} + +public func channelStatsUrl(postbox: Postbox, network: Network, peerId: PeerId, params: String) -> Signal { + return postbox.transaction { transaction -> Api.InputPeer? in + return transaction.getPeer(peerId).flatMap(apiInputPeer) + } + |> introduceError(ChannelStatsUrlError.self) + |> mapToSignal { inputPeer -> Signal in + guard let inputPeer = inputPeer else { + return .fail(.generic) + } + return network.request(Api.functions.messages.getStatsURL(peer: inputPeer, params: params)) + |> map { result -> String in + switch result { + case let .statsURL(url): + return url + } + } + |> `catch` { _ -> Signal in + return .fail(.generic) + } + } +} diff --git a/TelegramCore/RemovePeerChat.swift b/TelegramCore/RemovePeerChat.swift index a4c2eaa6b0..5f58f1b641 100644 --- a/TelegramCore/RemovePeerChat.swift +++ b/TelegramCore/RemovePeerChat.swift @@ -7,13 +7,22 @@ import Foundation import SwiftSignalKit #endif -public func removePeerChat(postbox: Postbox, peerId: PeerId, reportChatSpam: Bool, deleteGloballyIfPossible: Bool = false) -> Signal { - return postbox.transaction { transaction -> Void in - removePeerChat(transaction: transaction, mediaBox: postbox.mediaBox, peerId: peerId, reportChatSpam: reportChatSpam, deleteGloballyIfPossible: deleteGloballyIfPossible) +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) } } -public func removePeerChat(transaction: Transaction, mediaBox: MediaBox, peerId: PeerId, reportChatSpam: Bool, deleteGloballyIfPossible: Bool) { +public func removePeerChat(account: Account, transaction: Transaction, mediaBox: MediaBox, peerId: PeerId, reportChatSpam: Bool, deleteGloballyIfPossible: Bool) { + if let _ = transaction.getPeerChatInterfaceState(peerId) { + transaction.updatePeerChatInterfaceState(peerId, update: { current in + if let current = current { + return account.auxiliaryMethods.updatePeerChatInputState(current, nil) + } else { + return nil + } + }) + } if peerId.namespace == Namespaces.Peer.SecretChat { if let state = transaction.getPeerChatState(peerId) as? SecretChatState { diff --git a/TelegramCore/UpdateCachedPeerData.swift b/TelegramCore/UpdateCachedPeerData.swift index 0180152fbf..2ad8bd64d9 100644 --- a/TelegramCore/UpdateCachedPeerData.swift +++ b/TelegramCore/UpdateCachedPeerData.swift @@ -265,6 +265,9 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId: PeerId, network if (flags & (1 << 10)) == 0 { channelFlags.insert(.preHistoryEnabled) } + if (flags & (1 << 12)) != 0 { + channelFlags.insert(.canViewStats) + } if (flags & (1 << 7)) != 0 { channelFlags.insert(.canSetStickerSet) }