From 18557fa0f1c416cfd6e6aefc955edc76bece2560 Mon Sep 17 00:00:00 2001 From: Peter <> Date: Fri, 8 Mar 2019 11:23:18 +0000 Subject: [PATCH 1/4] Update API --- .../AccountStateManagementUtils.swift | 2 +- TelegramCore/Api0.swift | 9 +- TelegramCore/Api1.swift | 148 ++++++++++++++++-- TelegramCore/Api3.swift | 29 ++++ TelegramCore/LoadedStickerPack.swift | 2 +- TelegramCore/Serialization.swift | 2 +- TelegramCore/StickerPack.swift | 16 +- TelegramCore/TelegramChannel.swift | 2 +- TelegramCore/UpdateCachedPeerData.swift | 2 +- 9 files changed, 193 insertions(+), 19 deletions(-) diff --git a/TelegramCore/AccountStateManagementUtils.swift b/TelegramCore/AccountStateManagementUtils.swift index 776afd60d8..44f3fc861f 100644 --- a/TelegramCore/AccountStateManagementUtils.swift +++ b/TelegramCore/AccountStateManagementUtils.swift @@ -2442,7 +2442,7 @@ func replayFinalState(accountManager: AccountManager, postbox: Postbox, accountP } switch set { - case let .stickerSet(flags, _, _, _, _, _, _, _): + case let .stickerSet(flags, _, _, _, _, _, _, _, _): if (flags & (1 << 3)) != 0 { namespace = Namespaces.ItemCollection.CloudMaskPacks } else { diff --git a/TelegramCore/Api0.swift b/TelegramCore/Api0.swift index 669e4e01a3..2b08d0108f 100644 --- a/TelegramCore/Api0.swift +++ b/TelegramCore/Api0.swift @@ -286,7 +286,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[1098628881] = { return Api.InputBotInlineMessage.parse_inputBotInlineMessageMediaVenue($0) } dict[-1494368259] = { return Api.InputBotInlineMessage.parse_inputBotInlineMessageMediaContact($0) } dict[2002815875] = { return Api.KeyboardButtonRow.parse_keyboardButtonRow($0) } - dict[1434820921] = { return Api.StickerSet.parse_stickerSet($0) } + dict[1787870391] = { return Api.StickerSet.parse_stickerSet($0) } dict[354925740] = { return Api.SecureSecretSettings.parse_secureSecretSettings($0) } dict[539045032] = { return Api.photos.Photo.parse_photo($0) } dict[-208488460] = { return Api.InputContact.parse_inputPhoneContact($0) } @@ -418,6 +418,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-200242528] = { return Api.ReplyMarkup.parse_replyKeyboardForceReply($0) } dict[889353612] = { return Api.ReplyMarkup.parse_replyKeyboardMarkup($0) } dict[1218642516] = { return Api.ReplyMarkup.parse_replyInlineMarkup($0) } + dict[2147310185] = { return Api.EmojiKeywordsDifference.parse_emojiKeywordsDifference($0) } dict[1493171408] = { return Api.HighScore.parse_highScore($0) } dict[-305282981] = { return Api.TopPeer.parse_topPeer($0) } dict[986597452] = { return Api.contacts.Link.parse_link($0) } @@ -587,6 +588,8 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[364538944] = { return Api.messages.Dialogs.parse_dialogs($0) } dict[1910543603] = { return Api.messages.Dialogs.parse_dialogsSlice($0) } dict[-253500010] = { return Api.messages.Dialogs.parse_dialogsNotModified($0) } + dict[-709641735] = { return Api.EmojiKeyword.parse_emojiKeyword($0) } + dict[594408994] = { return Api.EmojiKeyword.parse_emojiKeywordDeleted($0) } dict[-290921362] = { return Api.upload.CdnFile.parse_cdnFileReuploadNeeded($0) } dict[-1449145777] = { return Api.upload.CdnFile.parse_cdnFile($0) } dict[415997816] = { return Api.help.InviteText.parse_inviteText($0) } @@ -1024,6 +1027,8 @@ struct Api { _1.serialize(buffer, boxed) case let _1 as Api.ReplyMarkup: _1.serialize(buffer, boxed) + case let _1 as Api.EmojiKeywordsDifference: + _1.serialize(buffer, boxed) case let _1 as Api.HighScore: _1.serialize(buffer, boxed) case let _1 as Api.TopPeer: @@ -1184,6 +1189,8 @@ struct Api { _1.serialize(buffer, boxed) case let _1 as Api.messages.Dialogs: _1.serialize(buffer, boxed) + case let _1 as Api.EmojiKeyword: + _1.serialize(buffer, boxed) case let _1 as Api.upload.CdnFile: _1.serialize(buffer, boxed) case let _1 as Api.help.InviteText: diff --git a/TelegramCore/Api1.swift b/TelegramCore/Api1.swift index b26a451de3..6ba5357258 100644 --- a/TelegramCore/Api1.swift +++ b/TelegramCore/Api1.swift @@ -7296,13 +7296,13 @@ extension Api { } enum StickerSet: TypeConstructorDescription { - case stickerSet(flags: Int32, installedDate: Int32?, id: Int64, accessHash: Int64, title: String, shortName: String, count: Int32, hash: Int32) + case stickerSet(flags: Int32, installedDate: Int32?, id: Int64, accessHash: Int64, title: String, shortName: String, thumb: Api.PhotoSize?, count: Int32, hash: Int32) func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { - case .stickerSet(let flags, let installedDate, let id, let accessHash, let title, let shortName, let count, let hash): + case .stickerSet(let flags, let installedDate, let id, let accessHash, let title, let shortName, let thumb, let count, let hash): if boxed { - buffer.appendInt32(1434820921) + buffer.appendInt32(1787870391) } serializeInt32(flags, buffer: buffer, boxed: false) if Int(flags) & Int(1 << 0) != 0 {serializeInt32(installedDate!, buffer: buffer, boxed: false)} @@ -7310,6 +7310,7 @@ extension Api { serializeInt64(accessHash, buffer: buffer, boxed: false) serializeString(title, buffer: buffer, boxed: false) serializeString(shortName, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 4) != 0 {thumb!.serialize(buffer, true)} serializeInt32(count, buffer: buffer, boxed: false) serializeInt32(hash, buffer: buffer, boxed: false) break @@ -7318,8 +7319,8 @@ extension Api { func descriptionFields() -> (String, [(String, Any)]) { switch self { - case .stickerSet(let flags, let installedDate, let id, let accessHash, let title, let shortName, let count, let hash): - return ("stickerSet", [("flags", flags), ("installedDate", installedDate), ("id", id), ("accessHash", accessHash), ("title", title), ("shortName", shortName), ("count", count), ("hash", hash)]) + case .stickerSet(let flags, let installedDate, let id, let accessHash, let title, let shortName, let thumb, let count, let hash): + return ("stickerSet", [("flags", flags), ("installedDate", installedDate), ("id", id), ("accessHash", accessHash), ("title", title), ("shortName", shortName), ("thumb", thumb), ("count", count), ("hash", hash)]) } } @@ -7336,20 +7337,25 @@ extension Api { _5 = parseString(reader) var _6: String? _6 = parseString(reader) - var _7: Int32? - _7 = reader.readInt32() + var _7: Api.PhotoSize? + if Int(_1!) & Int(1 << 4) != 0 {if let signature = reader.readInt32() { + _7 = Api.parse(reader, signature: signature) as? Api.PhotoSize + } } var _8: Int32? _8 = reader.readInt32() + var _9: Int32? + _9 = reader.readInt32() let _c1 = _1 != nil let _c2 = (Int(_1!) & Int(1 << 0) == 0) || _2 != nil let _c3 = _3 != nil let _c4 = _4 != nil let _c5 = _5 != nil let _c6 = _6 != nil - let _c7 = _7 != nil + let _c7 = (Int(_1!) & Int(1 << 4) == 0) || _7 != nil let _c8 = _8 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 { - return Api.StickerSet.stickerSet(flags: _1!, installedDate: _2, id: _3!, accessHash: _4!, title: _5!, shortName: _6!, count: _7!, hash: _8!) + let _c9 = _9 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 { + return Api.StickerSet.stickerSet(flags: _1!, installedDate: _2, id: _3!, accessHash: _4!, title: _5!, shortName: _6!, thumb: _7, count: _8!, hash: _9!) } else { return nil @@ -10260,6 +10266,54 @@ extension Api { } } + } + enum EmojiKeywordsDifference: TypeConstructorDescription { + case emojiKeywordsDifference(fromVersion: Int32, version: Int32, keywords: [Api.EmojiKeyword]) + + func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .emojiKeywordsDifference(let fromVersion, let version, let keywords): + if boxed { + buffer.appendInt32(2147310185) + } + serializeInt32(fromVersion, buffer: buffer, boxed: false) + serializeInt32(version, buffer: buffer, boxed: false) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(keywords.count)) + for item in keywords { + item.serialize(buffer, true) + } + break + } + } + + func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .emojiKeywordsDifference(let fromVersion, let version, let keywords): + return ("emojiKeywordsDifference", [("fromVersion", fromVersion), ("version", version), ("keywords", keywords)]) + } + } + + static func parse_emojiKeywordsDifference(_ reader: BufferReader) -> EmojiKeywordsDifference? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + _2 = reader.readInt32() + var _3: [Api.EmojiKeyword]? + if let _ = reader.readInt32() { + _3 = Api.parseVector(reader, elementSignature: 0, elementType: Api.EmojiKeyword.self) + } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + if _c1 && _c2 && _c3 { + return Api.EmojiKeywordsDifference.emojiKeywordsDifference(fromVersion: _1!, version: _2!, keywords: _3!) + } + else { + return nil + } + } + } enum HighScore: TypeConstructorDescription { case highScore(pos: Int32, userId: Int32, score: Int32) @@ -14826,6 +14880,80 @@ extension Api { return Api.MessagesFilter.inputMessagesFilterContacts } + } + enum EmojiKeyword: TypeConstructorDescription { + case emojiKeyword(keyword: String, emoticons: [String]) + case emojiKeywordDeleted(keyword: String, emoticons: [String]) + + func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .emojiKeyword(let keyword, let emoticons): + if boxed { + buffer.appendInt32(-709641735) + } + serializeString(keyword, buffer: buffer, boxed: false) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(emoticons.count)) + for item in emoticons { + serializeString(item, buffer: buffer, boxed: false) + } + break + case .emojiKeywordDeleted(let keyword, let emoticons): + if boxed { + buffer.appendInt32(594408994) + } + serializeString(keyword, buffer: buffer, boxed: false) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(emoticons.count)) + for item in emoticons { + serializeString(item, buffer: buffer, boxed: false) + } + break + } + } + + func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .emojiKeyword(let keyword, let emoticons): + return ("emojiKeyword", [("keyword", keyword), ("emoticons", emoticons)]) + case .emojiKeywordDeleted(let keyword, let emoticons): + return ("emojiKeywordDeleted", [("keyword", keyword), ("emoticons", emoticons)]) + } + } + + static func parse_emojiKeyword(_ reader: BufferReader) -> EmojiKeyword? { + var _1: String? + _1 = parseString(reader) + var _2: [String]? + if let _ = reader.readInt32() { + _2 = Api.parseVector(reader, elementSignature: -1255641564, elementType: String.self) + } + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return Api.EmojiKeyword.emojiKeyword(keyword: _1!, emoticons: _2!) + } + else { + return nil + } + } + static func parse_emojiKeywordDeleted(_ reader: BufferReader) -> EmojiKeyword? { + var _1: String? + _1 = parseString(reader) + var _2: [String]? + if let _ = reader.readInt32() { + _2 = Api.parseVector(reader, elementSignature: -1255641564, elementType: String.self) + } + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return Api.EmojiKeyword.emojiKeywordDeleted(keyword: _1!, emoticons: _2!) + } + else { + return nil + } + } + } enum BotInlineMessage: TypeConstructorDescription { case botInlineMessageText(flags: Int32, message: String, entities: [Api.MessageEntity]?, replyMarkup: Api.ReplyMarkup?) diff --git a/TelegramCore/Api3.swift b/TelegramCore/Api3.swift index 76f81b6890..5090fa9f97 100644 --- a/TelegramCore/Api3.swift +++ b/TelegramCore/Api3.swift @@ -2846,6 +2846,35 @@ extension Api { return result }) } + + static func getEmojiKeywords(langCode: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(899735650) + serializeString(langCode, buffer: buffer, boxed: false) + return (FunctionDescription(name: "messages.getEmojiKeywords", parameters: [("langCode", langCode)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.EmojiKeywordsDifference? in + let reader = BufferReader(buffer) + var result: Api.EmojiKeywordsDifference? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.EmojiKeywordsDifference + } + return result + }) + } + + static func getEmojiKeywordsDifference(langCode: String, fromVersion: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(352892591) + serializeString(langCode, buffer: buffer, boxed: false) + serializeInt32(fromVersion, buffer: buffer, boxed: false) + return (FunctionDescription(name: "messages.getEmojiKeywordsDifference", parameters: [("langCode", langCode), ("fromVersion", fromVersion)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.EmojiKeywordsDifference? in + let reader = BufferReader(buffer) + var result: Api.EmojiKeywordsDifference? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.EmojiKeywordsDifference + } + return result + }) + } } struct channels { static func readHistory(channel: Api.InputChannel, maxId: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { diff --git a/TelegramCore/LoadedStickerPack.swift b/TelegramCore/LoadedStickerPack.swift index 74f5b12c34..7e832668a3 100644 --- a/TelegramCore/LoadedStickerPack.swift +++ b/TelegramCore/LoadedStickerPack.swift @@ -45,7 +45,7 @@ func updatedRemoteStickerPack(postbox: Postbox, network: Network, reference: Sti case let .stickerSet(set, packs, documents): let namespace: ItemCollectionId.Namespace switch set { - case let .stickerSet(flags, _, _, _, _, _, _, _): + case let .stickerSet(flags, _, _, _, _, _, _, _, _): if (flags & (1 << 3)) != 0 { namespace = Namespaces.ItemCollection.CloudMaskPacks } else { diff --git a/TelegramCore/Serialization.swift b/TelegramCore/Serialization.swift index dea744de05..cf1525c38c 100644 --- a/TelegramCore/Serialization.swift +++ b/TelegramCore/Serialization.swift @@ -202,7 +202,7 @@ public class BoxedMessage: NSObject { public class Serialization: NSObject, MTSerialization { public func currentLayer() -> UInt { - return 96 + return 97 } public func parseMessage(_ data: Data!) -> Any! { diff --git a/TelegramCore/StickerPack.swift b/TelegramCore/StickerPack.swift index f9fa1a35c3..b2d1006cfb 100644 --- a/TelegramCore/StickerPack.swift +++ b/TelegramCore/StickerPack.swift @@ -41,15 +41,17 @@ public final class StickerPackCollectionInfo: ItemCollectionInfo, Equatable { 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, hash: Int32, 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 } @@ -59,6 +61,7 @@ public final class StickerPackCollectionInfo: ItemCollectionInfo, Equatable { 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) @@ -70,6 +73,11 @@ public final class StickerPackCollectionInfo: ItemCollectionInfo, Equatable { 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") @@ -148,7 +156,7 @@ public final class StickerPackItem: ItemCollectionItem, Equatable { extension StickerPackCollectionInfo { convenience init(apiSet: Api.StickerSet, namespace: ItemCollectionId.Namespace) { switch apiSet { - case let .stickerSet(flags, _, id, accessHash, title, shortName, count, nHash): + case let .stickerSet(flags, _, id, accessHash, title, shortName, thumb, count, nHash): var setFlags: StickerPackCollectionInfoFlags = StickerPackCollectionInfoFlags() if (flags & (1 << 2)) != 0 { setFlags.insert(.official) @@ -156,7 +164,9 @@ extension StickerPackCollectionInfo { if (flags & (1 << 3)) != 0 { setFlags.insert(.masks) } - self.init(id: ItemCollectionId(namespace: namespace, id: id), flags: setFlags, accessHash: accessHash, title: title, shortName: shortName, hash: nHash, count: count) + self.init(id: ItemCollectionId(namespace: namespace, id: id), flags: setFlags, accessHash: accessHash, title: title, shortName: shortName, thumbnail: thumb.flatMap({ thumb in + return telegramMediaImageRepresentationsFromApiSizes([thumb]).representations.first + }), hash: nHash, count: count) } } } diff --git a/TelegramCore/TelegramChannel.swift b/TelegramCore/TelegramChannel.swift index deec792f09..5564b0d7b1 100644 --- a/TelegramCore/TelegramChannel.swift +++ b/TelegramCore/TelegramChannel.swift @@ -168,7 +168,7 @@ public final class TelegramChannel: Peer { public let associatedPeerId: PeerId? = nil public let notificationSettingsPeerId: PeerId? = nil - public init(id: PeerId, accessHash: Int64?, title: String, username: String?, photo: [TelegramMediaImageRepresentation], creationDate: Int32, version: Int32, participationStatus: TelegramChannelParticipationStatus, info: TelegramChannelInfo, flags: TelegramChannelFlags, restrictionInfo: PeerAccessRestrictionInfo?, adminRights: TelegramChatAdminRights?, bannedRights: TelegramChatBannedRights?, defaultBannedRights: TelegramChatBannedRights?, peerGroupId: PeerGroupId?) { + public init(id: PeerId, accessHash: Int64?, title: String, username: String?, photo: [TelegramMediaImageRepresentation], creationDate: Int32, version: Int32, participationStatus: TelegramChannelParticipationStatus, info: TelegramChannelInfo, flags: TelegramChannelFlags, restrictionInfo: PeerAccessRestrictionInfo?, adminRights: TelegramChatAdminRights?, bannedRights: TelegramChatBannedRights?, defaultBannedRights: TelegramChatBannedRights?, peerGroupId: PeerGroupId? = nil) { self.id = id self.accessHash = accessHash self.title = title diff --git a/TelegramCore/UpdateCachedPeerData.swift b/TelegramCore/UpdateCachedPeerData.swift index 2ad8bd64d9..6b96e042cd 100644 --- a/TelegramCore/UpdateCachedPeerData.swift +++ b/TelegramCore/UpdateCachedPeerData.swift @@ -324,7 +324,7 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId: PeerId, network let stickerPack: StickerPackCollectionInfo? = stickerSet.flatMap { apiSet -> StickerPackCollectionInfo in let namespace: ItemCollectionId.Namespace switch apiSet { - case let .stickerSet(flags, _, _, _, _, _, _, _): + case let .stickerSet(flags, _, _, _, _, _, _, _, _): if (flags & (1 << 3)) != 0 { namespace = Namespaces.ItemCollection.CloudMaskPacks } else { From 621f52fcf410379a2b663577d9895b83231acaf4 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sat, 9 Mar 2019 22:03:00 +0300 Subject: [PATCH 2/4] Data Size String: fixed remainder calculation and added customizable decimal separator --- TelegramCore/StringFormat.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/TelegramCore/StringFormat.swift b/TelegramCore/StringFormat.swift index 0165737708..3b58878fcd 100644 --- a/TelegramCore/StringFormat.swift +++ b/TelegramCore/StringFormat.swift @@ -1,26 +1,26 @@ -public func dataSizeString(_ size: Int, forceDecimal: Bool = false) -> String { - return dataSizeString(Int64(size), forceDecimal: forceDecimal) +public func dataSizeString(_ size: Int, forceDecimal: Bool = false, decimalSeparator: String = ".") -> String { + return dataSizeString(Int64(size), forceDecimal: forceDecimal, decimalSeparator: decimalSeparator) } -public func dataSizeString(_ size: Int64, forceDecimal: Bool = false) -> String { +public func dataSizeString(_ size: Int64, forceDecimal: Bool = false, decimalSeparator: String = ".") -> String { if size >= 1024 * 1024 * 1024 { - let remainder = (size % (1024 * 1024 * 1024)) / (1024 * 1024 * 102) + let remainder = Int64((Double(size % (1024 * 1024 * 1024)) / (1024 * 1024 * 102.4)).rounded(.down)) if remainder != 0 || forceDecimal { - return "\(size / (1024 * 1024 * 1024)),\(remainder) GB" + return "\(size / (1024 * 1024 * 1024))\(decimalSeparator)\(remainder) GB" } else { return "\(size / (1024 * 1024 * 1024)) GB" } } else if size >= 1024 * 1024 { - let remainder = (size % (1024 * 1024)) / (1024 * 102) + let remainder = Int64((Double(size % (1024 * 1024)) / (1024.0 * 102.4)).rounded(.down)) if remainder != 0 || forceDecimal { - return "\(size / (1024 * 1024)),\(remainder) MB" + return "\(size / (1024 * 1024))\(decimalSeparator)\(remainder) MB" } else { return "\(size / (1024 * 1024)) MB" } } else if size >= 1024 { let remainder = (size % (1024)) / (102) if remainder != 0 || forceDecimal { - return "\(size / 1024),\(remainder) KB" + return "\(size / 1024)\(decimalSeparator)\(remainder) KB" } else { return "\(size / 1024) KB" } From d554ad5a855819a91622a8a1cbcb568363de22d9 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Wed, 13 Mar 2019 00:34:38 +0300 Subject: [PATCH 3/4] API update: profile photo and forwards privacy settings --- .../AccountStateManagementUtils.swift | 2 +- TelegramCore/Api0.swift | 16 +- TelegramCore/Api1.swift | 234 +++++++++++++++++- TelegramCore/Api3.swift | 43 ++++ TelegramCore/LoadedStickerPack.swift | 2 +- TelegramCore/NotificationExceptionsList.swift | 79 +++--- TelegramCore/PrivacySettings.swift | 13 +- TelegramCore/Serialization.swift | 2 +- TelegramCore/StickerPack.swift | 2 +- TelegramCore/UpdateCachedPeerData.swift | 2 +- .../UpdatedAccountPrivacySettings.swift | 28 ++- 11 files changed, 362 insertions(+), 61 deletions(-) diff --git a/TelegramCore/AccountStateManagementUtils.swift b/TelegramCore/AccountStateManagementUtils.swift index 776afd60d8..44f3fc861f 100644 --- a/TelegramCore/AccountStateManagementUtils.swift +++ b/TelegramCore/AccountStateManagementUtils.swift @@ -2442,7 +2442,7 @@ func replayFinalState(accountManager: AccountManager, postbox: Postbox, accountP } switch set { - case let .stickerSet(flags, _, _, _, _, _, _, _): + case let .stickerSet(flags, _, _, _, _, _, _, _, _): if (flags & (1 << 3)) != 0 { namespace = Namespaces.ItemCollection.CloudMaskPacks } else { diff --git a/TelegramCore/Api0.swift b/TelegramCore/Api0.swift index 669e4e01a3..5c4a266e3a 100644 --- a/TelegramCore/Api0.swift +++ b/TelegramCore/Api0.swift @@ -105,6 +105,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1000708810] = { return Api.help.AppUpdate.parse_noAppUpdate($0) } dict[-209337866] = { return Api.LangPackDifference.parse_langPackDifference($0) } dict[-1590738760] = { return Api.WallPaperSettings.parse_wallPaperSettings($0) } + dict[1152191385] = { return Api.EmojiURL.parse_EmojiURL($0) } dict[-791039645] = { return Api.channels.ChannelParticipant.parse_channelParticipant($0) } dict[-1736378792] = { return Api.InputCheckPasswordSRP.parse_inputCheckPasswordEmpty($0) } dict[-763367294] = { return Api.InputCheckPasswordSRP.parse_inputCheckPasswordSRP($0) } @@ -157,6 +158,8 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[1343122938] = { return Api.PrivacyKey.parse_privacyKeyChatInvite($0) } dict[1030105979] = { return Api.PrivacyKey.parse_privacyKeyPhoneCall($0) } dict[961092808] = { return Api.PrivacyKey.parse_privacyKeyPhoneP2P($0) } + dict[1777096355] = { return Api.PrivacyKey.parse_privacyKeyForwards($0) } + dict[-1777000467] = { return Api.PrivacyKey.parse_privacyKeyProfilePhoto($0) } dict[522914557] = { return Api.Update.parse_updateNewMessage($0) } dict[1318109142] = { return Api.Update.parse_updateMessageID($0) } dict[-1576161051] = { return Api.Update.parse_updateDeleteMessages($0) } @@ -286,7 +289,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[1098628881] = { return Api.InputBotInlineMessage.parse_inputBotInlineMessageMediaVenue($0) } dict[-1494368259] = { return Api.InputBotInlineMessage.parse_inputBotInlineMessageMediaContact($0) } dict[2002815875] = { return Api.KeyboardButtonRow.parse_keyboardButtonRow($0) } - dict[1434820921] = { return Api.StickerSet.parse_stickerSet($0) } + dict[1787870391] = { return Api.StickerSet.parse_stickerSet($0) } dict[354925740] = { return Api.SecureSecretSettings.parse_secureSecretSettings($0) } dict[539045032] = { return Api.photos.Photo.parse_photo($0) } dict[-208488460] = { return Api.InputContact.parse_inputPhoneContact($0) } @@ -413,11 +416,14 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1107622874] = { return Api.InputPrivacyKey.parse_inputPrivacyKeyChatInvite($0) } dict[-88417185] = { return Api.InputPrivacyKey.parse_inputPrivacyKeyPhoneCall($0) } dict[-610373422] = { return Api.InputPrivacyKey.parse_inputPrivacyKeyPhoneP2P($0) } + dict[-1529000952] = { return Api.InputPrivacyKey.parse_inputPrivacyKeyForwards($0) } + dict[1461304012] = { return Api.InputPrivacyKey.parse_inputPrivacyKeyProfilePhoto($0) } dict[235081943] = { return Api.help.RecentMeUrls.parse_recentMeUrls($0) } dict[-1606526075] = { return Api.ReplyMarkup.parse_replyKeyboardHide($0) } dict[-200242528] = { return Api.ReplyMarkup.parse_replyKeyboardForceReply($0) } dict[889353612] = { return Api.ReplyMarkup.parse_replyKeyboardMarkup($0) } dict[1218642516] = { return Api.ReplyMarkup.parse_replyInlineMarkup($0) } + dict[1556570557] = { return Api.EmojiKeywordsDifference.parse_emojiKeywordsDifference($0) } dict[1493171408] = { return Api.HighScore.parse_highScore($0) } dict[-305282981] = { return Api.TopPeer.parse_topPeer($0) } dict[986597452] = { return Api.contacts.Link.parse_link($0) } @@ -587,6 +593,8 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[364538944] = { return Api.messages.Dialogs.parse_dialogs($0) } dict[1910543603] = { return Api.messages.Dialogs.parse_dialogsSlice($0) } dict[-253500010] = { return Api.messages.Dialogs.parse_dialogsNotModified($0) } + dict[-709641735] = { return Api.EmojiKeyword.parse_emojiKeyword($0) } + dict[594408994] = { return Api.EmojiKeyword.parse_emojiKeywordDeleted($0) } dict[-290921362] = { return Api.upload.CdnFile.parse_cdnFileReuploadNeeded($0) } dict[-1449145777] = { return Api.upload.CdnFile.parse_cdnFile($0) } dict[415997816] = { return Api.help.InviteText.parse_inviteText($0) } @@ -844,6 +852,8 @@ struct Api { _1.serialize(buffer, boxed) case let _1 as Api.WallPaperSettings: _1.serialize(buffer, boxed) + case let _1 as Api.EmojiURL: + _1.serialize(buffer, boxed) case let _1 as Api.channels.ChannelParticipant: _1.serialize(buffer, boxed) case let _1 as Api.InputCheckPasswordSRP: @@ -1024,6 +1034,8 @@ struct Api { _1.serialize(buffer, boxed) case let _1 as Api.ReplyMarkup: _1.serialize(buffer, boxed) + case let _1 as Api.EmojiKeywordsDifference: + _1.serialize(buffer, boxed) case let _1 as Api.HighScore: _1.serialize(buffer, boxed) case let _1 as Api.TopPeer: @@ -1184,6 +1196,8 @@ struct Api { _1.serialize(buffer, boxed) case let _1 as Api.messages.Dialogs: _1.serialize(buffer, boxed) + case let _1 as Api.EmojiKeyword: + _1.serialize(buffer, boxed) case let _1 as Api.upload.CdnFile: _1.serialize(buffer, boxed) case let _1 as Api.help.InviteText: diff --git a/TelegramCore/Api1.swift b/TelegramCore/Api1.swift index b26a451de3..fab820b993 100644 --- a/TelegramCore/Api1.swift +++ b/TelegramCore/Api1.swift @@ -2882,6 +2882,40 @@ extension Api { } } + } + enum EmojiURL: TypeConstructorDescription { + case EmojiURL(url: String) + + func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .EmojiURL(let url): + if boxed { + buffer.appendInt32(1152191385) + } + serializeString(url, buffer: buffer, boxed: false) + break + } + } + + func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .EmojiURL(let url): + return ("EmojiURL", [("url", url)]) + } + } + + static func parse_EmojiURL(_ reader: BufferReader) -> EmojiURL? { + var _1: String? + _1 = parseString(reader) + let _c1 = _1 != nil + if _c1 { + return Api.EmojiURL.EmojiURL(url: _1!) + } + else { + return nil + } + } + } enum InputCheckPasswordSRP: TypeConstructorDescription { case inputCheckPasswordEmpty @@ -3678,6 +3712,8 @@ extension Api { case privacyKeyChatInvite case privacyKeyPhoneCall case privacyKeyPhoneP2P + case privacyKeyForwards + case privacyKeyProfilePhoto func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -3704,6 +3740,18 @@ extension Api { buffer.appendInt32(961092808) } + break + case .privacyKeyForwards: + if boxed { + buffer.appendInt32(1777096355) + } + + break + case .privacyKeyProfilePhoto: + if boxed { + buffer.appendInt32(-1777000467) + } + break } } @@ -3718,6 +3766,10 @@ extension Api { return ("privacyKeyPhoneCall", []) case .privacyKeyPhoneP2P: return ("privacyKeyPhoneP2P", []) + case .privacyKeyForwards: + return ("privacyKeyForwards", []) + case .privacyKeyProfilePhoto: + return ("privacyKeyProfilePhoto", []) } } @@ -3733,6 +3785,12 @@ extension Api { static func parse_privacyKeyPhoneP2P(_ reader: BufferReader) -> PrivacyKey? { return Api.PrivacyKey.privacyKeyPhoneP2P } + static func parse_privacyKeyForwards(_ reader: BufferReader) -> PrivacyKey? { + return Api.PrivacyKey.privacyKeyForwards + } + static func parse_privacyKeyProfilePhoto(_ reader: BufferReader) -> PrivacyKey? { + return Api.PrivacyKey.privacyKeyProfilePhoto + } } enum Update: TypeConstructorDescription { @@ -7296,13 +7354,13 @@ extension Api { } enum StickerSet: TypeConstructorDescription { - case stickerSet(flags: Int32, installedDate: Int32?, id: Int64, accessHash: Int64, title: String, shortName: String, count: Int32, hash: Int32) + case stickerSet(flags: Int32, installedDate: Int32?, id: Int64, accessHash: Int64, title: String, shortName: String, thumb: Api.PhotoSize?, count: Int32, hash: Int32) func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { - case .stickerSet(let flags, let installedDate, let id, let accessHash, let title, let shortName, let count, let hash): + case .stickerSet(let flags, let installedDate, let id, let accessHash, let title, let shortName, let thumb, let count, let hash): if boxed { - buffer.appendInt32(1434820921) + buffer.appendInt32(1787870391) } serializeInt32(flags, buffer: buffer, boxed: false) if Int(flags) & Int(1 << 0) != 0 {serializeInt32(installedDate!, buffer: buffer, boxed: false)} @@ -7310,6 +7368,7 @@ extension Api { serializeInt64(accessHash, buffer: buffer, boxed: false) serializeString(title, buffer: buffer, boxed: false) serializeString(shortName, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 4) != 0 {thumb!.serialize(buffer, true)} serializeInt32(count, buffer: buffer, boxed: false) serializeInt32(hash, buffer: buffer, boxed: false) break @@ -7318,8 +7377,8 @@ extension Api { func descriptionFields() -> (String, [(String, Any)]) { switch self { - case .stickerSet(let flags, let installedDate, let id, let accessHash, let title, let shortName, let count, let hash): - return ("stickerSet", [("flags", flags), ("installedDate", installedDate), ("id", id), ("accessHash", accessHash), ("title", title), ("shortName", shortName), ("count", count), ("hash", hash)]) + case .stickerSet(let flags, let installedDate, let id, let accessHash, let title, let shortName, let thumb, let count, let hash): + return ("stickerSet", [("flags", flags), ("installedDate", installedDate), ("id", id), ("accessHash", accessHash), ("title", title), ("shortName", shortName), ("thumb", thumb), ("count", count), ("hash", hash)]) } } @@ -7336,20 +7395,25 @@ extension Api { _5 = parseString(reader) var _6: String? _6 = parseString(reader) - var _7: Int32? - _7 = reader.readInt32() + var _7: Api.PhotoSize? + if Int(_1!) & Int(1 << 4) != 0 {if let signature = reader.readInt32() { + _7 = Api.parse(reader, signature: signature) as? Api.PhotoSize + } } var _8: Int32? _8 = reader.readInt32() + var _9: Int32? + _9 = reader.readInt32() let _c1 = _1 != nil let _c2 = (Int(_1!) & Int(1 << 0) == 0) || _2 != nil let _c3 = _3 != nil let _c4 = _4 != nil let _c5 = _5 != nil let _c6 = _6 != nil - let _c7 = _7 != nil + let _c7 = (Int(_1!) & Int(1 << 4) == 0) || _7 != nil let _c8 = _8 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 { - return Api.StickerSet.stickerSet(flags: _1!, installedDate: _2, id: _3!, accessHash: _4!, title: _5!, shortName: _6!, count: _7!, hash: _8!) + let _c9 = _9 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 { + return Api.StickerSet.stickerSet(flags: _1!, installedDate: _2, id: _3!, accessHash: _4!, title: _5!, shortName: _6!, thumb: _7, count: _8!, hash: _9!) } else { return nil @@ -10094,6 +10158,8 @@ extension Api { case inputPrivacyKeyChatInvite case inputPrivacyKeyPhoneCall case inputPrivacyKeyPhoneP2P + case inputPrivacyKeyForwards + case inputPrivacyKeyProfilePhoto func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -10120,6 +10186,18 @@ extension Api { buffer.appendInt32(-610373422) } + break + case .inputPrivacyKeyForwards: + if boxed { + buffer.appendInt32(-1529000952) + } + + break + case .inputPrivacyKeyProfilePhoto: + if boxed { + buffer.appendInt32(1461304012) + } + break } } @@ -10134,6 +10212,10 @@ extension Api { return ("inputPrivacyKeyPhoneCall", []) case .inputPrivacyKeyPhoneP2P: return ("inputPrivacyKeyPhoneP2P", []) + case .inputPrivacyKeyForwards: + return ("inputPrivacyKeyForwards", []) + case .inputPrivacyKeyProfilePhoto: + return ("inputPrivacyKeyProfilePhoto", []) } } @@ -10149,6 +10231,12 @@ extension Api { static func parse_inputPrivacyKeyPhoneP2P(_ reader: BufferReader) -> InputPrivacyKey? { return Api.InputPrivacyKey.inputPrivacyKeyPhoneP2P } + static func parse_inputPrivacyKeyForwards(_ reader: BufferReader) -> InputPrivacyKey? { + return Api.InputPrivacyKey.inputPrivacyKeyForwards + } + static func parse_inputPrivacyKeyProfilePhoto(_ reader: BufferReader) -> InputPrivacyKey? { + return Api.InputPrivacyKey.inputPrivacyKeyProfilePhoto + } } enum ReplyMarkup: TypeConstructorDescription { @@ -10260,6 +10348,58 @@ extension Api { } } + } + enum EmojiKeywordsDifference: TypeConstructorDescription { + case emojiKeywordsDifference(langCode: String, fromVersion: Int32, version: Int32, keywords: [Api.EmojiKeyword]) + + func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .emojiKeywordsDifference(let langCode, let fromVersion, let version, let keywords): + if boxed { + buffer.appendInt32(1556570557) + } + serializeString(langCode, buffer: buffer, boxed: false) + serializeInt32(fromVersion, buffer: buffer, boxed: false) + serializeInt32(version, buffer: buffer, boxed: false) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(keywords.count)) + for item in keywords { + item.serialize(buffer, true) + } + break + } + } + + func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .emojiKeywordsDifference(let langCode, let fromVersion, let version, let keywords): + return ("emojiKeywordsDifference", [("langCode", langCode), ("fromVersion", fromVersion), ("version", version), ("keywords", keywords)]) + } + } + + static func parse_emojiKeywordsDifference(_ reader: BufferReader) -> EmojiKeywordsDifference? { + var _1: String? + _1 = parseString(reader) + var _2: Int32? + _2 = reader.readInt32() + var _3: Int32? + _3 = reader.readInt32() + var _4: [Api.EmojiKeyword]? + if let _ = reader.readInt32() { + _4 = Api.parseVector(reader, elementSignature: 0, elementType: Api.EmojiKeyword.self) + } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + if _c1 && _c2 && _c3 && _c4 { + return Api.EmojiKeywordsDifference.emojiKeywordsDifference(langCode: _1!, fromVersion: _2!, version: _3!, keywords: _4!) + } + else { + return nil + } + } + } enum HighScore: TypeConstructorDescription { case highScore(pos: Int32, userId: Int32, score: Int32) @@ -14826,6 +14966,80 @@ extension Api { return Api.MessagesFilter.inputMessagesFilterContacts } + } + enum EmojiKeyword: TypeConstructorDescription { + case emojiKeyword(keyword: String, emoticons: [String]) + case emojiKeywordDeleted(keyword: String, emoticons: [String]) + + func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .emojiKeyword(let keyword, let emoticons): + if boxed { + buffer.appendInt32(-709641735) + } + serializeString(keyword, buffer: buffer, boxed: false) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(emoticons.count)) + for item in emoticons { + serializeString(item, buffer: buffer, boxed: false) + } + break + case .emojiKeywordDeleted(let keyword, let emoticons): + if boxed { + buffer.appendInt32(594408994) + } + serializeString(keyword, buffer: buffer, boxed: false) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(emoticons.count)) + for item in emoticons { + serializeString(item, buffer: buffer, boxed: false) + } + break + } + } + + func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .emojiKeyword(let keyword, let emoticons): + return ("emojiKeyword", [("keyword", keyword), ("emoticons", emoticons)]) + case .emojiKeywordDeleted(let keyword, let emoticons): + return ("emojiKeywordDeleted", [("keyword", keyword), ("emoticons", emoticons)]) + } + } + + static func parse_emojiKeyword(_ reader: BufferReader) -> EmojiKeyword? { + var _1: String? + _1 = parseString(reader) + var _2: [String]? + if let _ = reader.readInt32() { + _2 = Api.parseVector(reader, elementSignature: -1255641564, elementType: String.self) + } + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return Api.EmojiKeyword.emojiKeyword(keyword: _1!, emoticons: _2!) + } + else { + return nil + } + } + static func parse_emojiKeywordDeleted(_ reader: BufferReader) -> EmojiKeyword? { + var _1: String? + _1 = parseString(reader) + var _2: [String]? + if let _ = reader.readInt32() { + _2 = Api.parseVector(reader, elementSignature: -1255641564, elementType: String.self) + } + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return Api.EmojiKeyword.emojiKeywordDeleted(keyword: _1!, emoticons: _2!) + } + else { + return nil + } + } + } enum BotInlineMessage: TypeConstructorDescription { case botInlineMessageText(flags: Int32, message: String, entities: [Api.MessageEntity]?, replyMarkup: Api.ReplyMarkup?) diff --git a/TelegramCore/Api3.swift b/TelegramCore/Api3.swift index 76f81b6890..3fa3ec324c 100644 --- a/TelegramCore/Api3.swift +++ b/TelegramCore/Api3.swift @@ -2846,6 +2846,49 @@ extension Api { return result }) } + + static func getEmojiKeywords(langCode: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(899735650) + serializeString(langCode, buffer: buffer, boxed: false) + return (FunctionDescription(name: "messages.getEmojiKeywords", parameters: [("langCode", langCode)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.EmojiKeywordsDifference? in + let reader = BufferReader(buffer) + var result: Api.EmojiKeywordsDifference? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.EmojiKeywordsDifference + } + return result + }) + } + + static func getEmojiKeywordsDifference(langCode: String, fromVersion: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(352892591) + serializeString(langCode, buffer: buffer, boxed: false) + serializeInt32(fromVersion, buffer: buffer, boxed: false) + return (FunctionDescription(name: "messages.getEmojiKeywordsDifference", parameters: [("langCode", langCode), ("fromVersion", fromVersion)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.EmojiKeywordsDifference? in + let reader = BufferReader(buffer) + var result: Api.EmojiKeywordsDifference? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.EmojiKeywordsDifference + } + return result + }) + } + + static func getEmojiURL(langCode: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(-709817306) + serializeString(langCode, buffer: buffer, boxed: false) + return (FunctionDescription(name: "messages.getEmojiURL", parameters: [("langCode", langCode)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.EmojiURL? in + let reader = BufferReader(buffer) + var result: Api.EmojiURL? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.EmojiURL + } + return result + }) + } } struct channels { static func readHistory(channel: Api.InputChannel, maxId: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { diff --git a/TelegramCore/LoadedStickerPack.swift b/TelegramCore/LoadedStickerPack.swift index 74f5b12c34..7e832668a3 100644 --- a/TelegramCore/LoadedStickerPack.swift +++ b/TelegramCore/LoadedStickerPack.swift @@ -45,7 +45,7 @@ func updatedRemoteStickerPack(postbox: Postbox, network: Network, reference: Sti case let .stickerSet(set, packs, documents): let namespace: ItemCollectionId.Namespace switch set { - case let .stickerSet(flags, _, _, _, _, _, _, _): + case let .stickerSet(flags, _, _, _, _, _, _, _, _): if (flags & (1 << 3)) != 0 { namespace = Namespaces.ItemCollection.CloudMaskPacks } else { diff --git a/TelegramCore/NotificationExceptionsList.swift b/TelegramCore/NotificationExceptionsList.swift index 876286c6f5..2e17529bf7 100644 --- a/TelegramCore/NotificationExceptionsList.swift +++ b/TelegramCore/NotificationExceptionsList.swift @@ -7,11 +7,11 @@ import SwiftSignalKit import Postbox #endif -public final class NotificationExceptionsList : Equatable { - public let peers:[PeerId: Peer] +public final class NotificationExceptionsList: Equatable { + public let peers: [PeerId: Peer] public let settings: [PeerId: TelegramPeerNotificationSettings] - init(_ peers:[PeerId: Peer], _ settings: [PeerId : TelegramPeerNotificationSettings]) { + init(peers: [PeerId: Peer], settings: [PeerId: TelegramPeerNotificationSettings]) { self.peers = peers self.settings = settings } @@ -21,50 +21,49 @@ public final class NotificationExceptionsList : Equatable { } } - public func notificationExceptionsList(network: Network) -> Signal { return network.request(Api.functions.account.getNotifyExceptions(flags: 1 << 1, peer: nil)) |> retryRequest |> map { result in switch result { - case let .updates(updates, users, chats, _, _): - var peers:[PeerId: Peer] = [:] - var settings:[PeerId : TelegramPeerNotificationSettings] = [:] - - for user in users { - let peer = TelegramUser(user: user) - peers[peer.id] = peer - } - for chat in chats { - if let peer = parseTelegramGroupOrChannel(chat: chat) { + case let .updates(updates, users, chats, _, _): + var peers:[PeerId: Peer] = [:] + var settings:[PeerId : TelegramPeerNotificationSettings] = [:] + + for user in users { + let peer = TelegramUser(user: user) peers[peer.id] = peer } - } - - for update in updates { - switch update { - case let .updateNotifySettings(apiPeer, notifySettings): - switch apiPeer { - case let .notifyPeer(notifyPeer): - let peerId: PeerId - switch notifyPeer { - case let .peerUser(userId): - peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: userId) - case let .peerChat(chatId): - peerId = PeerId(namespace: Namespaces.Peer.CloudGroup, id: chatId) - case let .peerChannel(channelId): - peerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: channelId) - } - settings[peerId] = TelegramPeerNotificationSettings(apiSettings: notifySettings) - default: - break + for chat in chats { + if let peer = parseTelegramGroupOrChannel(chat: chat) { + peers[peer.id] = peer } - default: - break } - } - - return NotificationExceptionsList(peers, settings) - default: - return NotificationExceptionsList([:], [:]) + + for update in updates { + switch update { + case let .updateNotifySettings(apiPeer, notifySettings): + switch apiPeer { + case let .notifyPeer(notifyPeer): + let peerId: PeerId + switch notifyPeer { + case let .peerUser(userId): + peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: userId) + case let .peerChat(chatId): + peerId = PeerId(namespace: Namespaces.Peer.CloudGroup, id: chatId) + case let .peerChannel(channelId): + peerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: channelId) + } + settings[peerId] = TelegramPeerNotificationSettings(apiSettings: notifySettings) + default: + break + } + default: + break + } + } + + return NotificationExceptionsList(peers: peers, settings: settings) + default: + return NotificationExceptionsList(peers: [:], settings: [:]) } } } diff --git a/TelegramCore/PrivacySettings.swift b/TelegramCore/PrivacySettings.swift index 9cf4dd0199..2f0f5b34bc 100644 --- a/TelegramCore/PrivacySettings.swift +++ b/TelegramCore/PrivacySettings.swift @@ -61,14 +61,18 @@ public struct AccountPrivacySettings: Equatable { public let groupInvitations: SelectivePrivacySettings public let voiceCalls: SelectivePrivacySettings public let voiceCallsP2P: SelectivePrivacySettings + public let profilePhoto: SelectivePrivacySettings + public let forwards: SelectivePrivacySettings public let accountRemovalTimeout: Int32 - public init(presence: SelectivePrivacySettings, groupInvitations: SelectivePrivacySettings, voiceCalls: SelectivePrivacySettings, voiceCallsP2P: SelectivePrivacySettings, accountRemovalTimeout: Int32) { + public init(presence: SelectivePrivacySettings, groupInvitations: SelectivePrivacySettings, voiceCalls: SelectivePrivacySettings, voiceCallsP2P: SelectivePrivacySettings, profilePhoto: SelectivePrivacySettings, forwards: SelectivePrivacySettings, accountRemovalTimeout: Int32) { self.presence = presence self.groupInvitations = groupInvitations self.voiceCalls = voiceCalls self.voiceCallsP2P = voiceCallsP2P + self.profilePhoto = profilePhoto + self.forwards = forwards self.accountRemovalTimeout = accountRemovalTimeout } @@ -85,7 +89,12 @@ public struct AccountPrivacySettings: Equatable { if lhs.voiceCallsP2P != rhs.voiceCallsP2P { return false } - + if lhs.profilePhoto != rhs.profilePhoto { + return false + } + if lhs.forwards != rhs.forwards { + return false + } if lhs.accountRemovalTimeout != rhs.accountRemovalTimeout { return false } diff --git a/TelegramCore/Serialization.swift b/TelegramCore/Serialization.swift index dea744de05..cf1525c38c 100644 --- a/TelegramCore/Serialization.swift +++ b/TelegramCore/Serialization.swift @@ -202,7 +202,7 @@ public class BoxedMessage: NSObject { public class Serialization: NSObject, MTSerialization { public func currentLayer() -> UInt { - return 96 + return 97 } public func parseMessage(_ data: Data!) -> Any! { diff --git a/TelegramCore/StickerPack.swift b/TelegramCore/StickerPack.swift index f9fa1a35c3..406d7695f6 100644 --- a/TelegramCore/StickerPack.swift +++ b/TelegramCore/StickerPack.swift @@ -148,7 +148,7 @@ public final class StickerPackItem: ItemCollectionItem, Equatable { extension StickerPackCollectionInfo { convenience init(apiSet: Api.StickerSet, namespace: ItemCollectionId.Namespace) { switch apiSet { - case let .stickerSet(flags, _, id, accessHash, title, shortName, count, nHash): + case let .stickerSet(flags, _, id, accessHash, title, shortName, thumb, count, nHash): var setFlags: StickerPackCollectionInfoFlags = StickerPackCollectionInfoFlags() if (flags & (1 << 2)) != 0 { setFlags.insert(.official) diff --git a/TelegramCore/UpdateCachedPeerData.swift b/TelegramCore/UpdateCachedPeerData.swift index 2ad8bd64d9..6b96e042cd 100644 --- a/TelegramCore/UpdateCachedPeerData.swift +++ b/TelegramCore/UpdateCachedPeerData.swift @@ -324,7 +324,7 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId: PeerId, network let stickerPack: StickerPackCollectionInfo? = stickerSet.flatMap { apiSet -> StickerPackCollectionInfo in let namespace: ItemCollectionId.Namespace switch apiSet { - case let .stickerSet(flags, _, _, _, _, _, _, _): + case let .stickerSet(flags, _, _, _, _, _, _, _, _): if (flags & (1 << 3)) != 0 { namespace = Namespaces.ItemCollection.CloudMaskPacks } else { diff --git a/TelegramCore/UpdatedAccountPrivacySettings.swift b/TelegramCore/UpdatedAccountPrivacySettings.swift index 99dc63c1d2..9a2f87c514 100644 --- a/TelegramCore/UpdatedAccountPrivacySettings.swift +++ b/TelegramCore/UpdatedAccountPrivacySettings.swift @@ -12,10 +12,12 @@ public func requestAccountPrivacySettings(account: Account) -> Signal retryRequest - |> mapToSignal { lastSeenPrivacy, groupPrivacy, voiceCallPrivacy, voiceCallP2P, autoremoveTimeout -> Signal in + |> mapToSignal { lastSeenPrivacy, groupPrivacy, voiceCallPrivacy, voiceCallP2P, profilePhotoPrivacy, forwardPrivacy, autoremoveTimeout -> Signal in let accountTimeoutSeconds: Int32 switch autoremoveTimeout { case let .accountDaysTTL(days): @@ -27,6 +29,8 @@ public func requestAccountPrivacySettings(account: Account) -> Signal Signal AccountPrivacySettings in @@ -60,7 +76,7 @@ public func requestAccountPrivacySettings(account: Account) -> Signal Date: Thu, 14 Mar 2019 16:06:34 +0400 Subject: [PATCH 4/4] Support nil authorId in MessageForwardInfo --- .../AccountStateManagementUtils.swift | 2 +- TelegramCore/AccountViewTracker.swift | 4 +- TelegramCore/Api0.swift | 2 +- TelegramCore/Api1.swift | 48 ++++++++++--------- .../ApplyMaxReadIndexInteractively.swift | 4 +- TelegramCore/ApplyUpdateMessage.swift | 16 +++---- TelegramCore/EnqueueMessage.swift | 2 +- .../HistoryViewChannelStateValidation.swift | 4 +- .../ManagedAutoremoveMessageOperations.swift | 2 +- ...anagedConsumePersonalMessagesActions.swift | 4 +- .../ManagedSecretChatOutgoingOperations.swift | 4 +- ...essageContentAsConsumedInteractively.swift | 4 +- TelegramCore/PendingMessageManager.swift | 16 +++---- .../PendingMessageUploadedContent.swift | 4 +- TelegramCore/RequestEditMessage.swift | 2 +- TelegramCore/StoreMessage_Telegram.swift | 24 +++++----- TelegramCore/UpdateMessageMedia.swift | 2 +- 17 files changed, 75 insertions(+), 69 deletions(-) diff --git a/TelegramCore/AccountStateManagementUtils.swift b/TelegramCore/AccountStateManagementUtils.swift index 44f3fc861f..771bb85e5c 100644 --- a/TelegramCore/AccountStateManagementUtils.swift +++ b/TelegramCore/AccountStateManagementUtils.swift @@ -2348,7 +2348,7 @@ func replayFinalState(accountManager: AccountManager, postbox: Postbox, accountP transaction.updateMessage(id, update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author?.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } var attributes = currentMessage.attributes loop: for j in 0 ..< attributes.count { diff --git a/TelegramCore/AccountViewTracker.swift b/TelegramCore/AccountViewTracker.swift index 0135cd6dee..2a8077b0e5 100644 --- a/TelegramCore/AccountViewTracker.swift +++ b/TelegramCore/AccountViewTracker.swift @@ -339,7 +339,7 @@ public final class AccountViewTracker { transaction.updateMessage(messageId, update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author?.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } var media = currentMessage.media for i in 0 ..< media.count { @@ -528,7 +528,7 @@ public final class AccountViewTracker { transaction.updateMessage(messageIds[i], update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author?.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } var attributes = currentMessage.attributes loop: for j in 0 ..< attributes.count { diff --git a/TelegramCore/Api0.swift b/TelegramCore/Api0.swift index 5c4a266e3a..78d5661113 100644 --- a/TelegramCore/Api0.swift +++ b/TelegramCore/Api0.swift @@ -570,7 +570,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1036396922] = { return Api.InputWebFileLocation.parse_inputWebFileLocation($0) } dict[1430205163] = { return Api.InputWebFileLocation.parse_inputWebFileGeoMessageLocation($0) } dict[-1625153079] = { return Api.InputWebFileLocation.parse_inputWebFileGeoPointLocation($0) } - dict[1436466797] = { return Api.MessageFwdHeader.parse_messageFwdHeader($0) } + dict[-332168592] = { return Api.MessageFwdHeader.parse_messageFwdHeader($0) } dict[398898678] = { return Api.help.Support.parse_support($0) } dict[1474492012] = { return Api.MessagesFilter.parse_inputMessagesFilterEmpty($0) } dict[-1777752804] = { return Api.MessagesFilter.parse_inputMessagesFilterPhotos($0) } diff --git a/TelegramCore/Api1.swift b/TelegramCore/Api1.swift index fab820b993..8752e328b3 100644 --- a/TelegramCore/Api1.swift +++ b/TelegramCore/Api1.swift @@ -14666,16 +14666,17 @@ extension Api { } enum MessageFwdHeader: TypeConstructorDescription { - case messageFwdHeader(flags: Int32, fromId: Int32?, date: Int32, channelId: Int32?, channelPost: Int32?, postAuthor: String?, savedFromPeer: Api.Peer?, savedFromMsgId: Int32?) + case messageFwdHeader(flags: Int32, fromId: Int32?, fromName: String?, date: Int32, channelId: Int32?, channelPost: Int32?, postAuthor: String?, savedFromPeer: Api.Peer?, savedFromMsgId: Int32?) func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { - case .messageFwdHeader(let flags, let fromId, let date, let channelId, let channelPost, let postAuthor, let savedFromPeer, let savedFromMsgId): + case .messageFwdHeader(let flags, let fromId, let fromName, let date, let channelId, let channelPost, let postAuthor, let savedFromPeer, let savedFromMsgId): if boxed { - buffer.appendInt32(1436466797) + buffer.appendInt32(-332168592) } serializeInt32(flags, buffer: buffer, boxed: false) if Int(flags) & Int(1 << 0) != 0 {serializeInt32(fromId!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 5) != 0 {serializeString(fromName!, buffer: buffer, boxed: false)} serializeInt32(date, buffer: buffer, boxed: false) if Int(flags) & Int(1 << 1) != 0 {serializeInt32(channelId!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 2) != 0 {serializeInt32(channelPost!, buffer: buffer, boxed: false)} @@ -14688,8 +14689,8 @@ extension Api { func descriptionFields() -> (String, [(String, Any)]) { switch self { - case .messageFwdHeader(let flags, let fromId, let date, let channelId, let channelPost, let postAuthor, let savedFromPeer, let savedFromMsgId): - return ("messageFwdHeader", [("flags", flags), ("fromId", fromId), ("date", date), ("channelId", channelId), ("channelPost", channelPost), ("postAuthor", postAuthor), ("savedFromPeer", savedFromPeer), ("savedFromMsgId", savedFromMsgId)]) + case .messageFwdHeader(let flags, let fromId, let fromName, let date, let channelId, let channelPost, let postAuthor, let savedFromPeer, let savedFromMsgId): + return ("messageFwdHeader", [("flags", flags), ("fromId", fromId), ("fromName", fromName), ("date", date), ("channelId", channelId), ("channelPost", channelPost), ("postAuthor", postAuthor), ("savedFromPeer", savedFromPeer), ("savedFromMsgId", savedFromMsgId)]) } } @@ -14698,30 +14699,33 @@ extension Api { _1 = reader.readInt32() var _2: Int32? if Int(_1!) & Int(1 << 0) != 0 {_2 = reader.readInt32() } - var _3: Int32? - _3 = reader.readInt32() + var _3: String? + if Int(_1!) & Int(1 << 5) != 0 {_3 = parseString(reader) } var _4: Int32? - if Int(_1!) & Int(1 << 1) != 0 {_4 = reader.readInt32() } + _4 = reader.readInt32() var _5: Int32? - if Int(_1!) & Int(1 << 2) != 0 {_5 = reader.readInt32() } - var _6: String? - if Int(_1!) & Int(1 << 3) != 0 {_6 = parseString(reader) } - var _7: Api.Peer? + if Int(_1!) & Int(1 << 1) != 0 {_5 = reader.readInt32() } + var _6: Int32? + if Int(_1!) & Int(1 << 2) != 0 {_6 = reader.readInt32() } + var _7: String? + if Int(_1!) & Int(1 << 3) != 0 {_7 = parseString(reader) } + var _8: Api.Peer? if Int(_1!) & Int(1 << 4) != 0 {if let signature = reader.readInt32() { - _7 = Api.parse(reader, signature: signature) as? Api.Peer + _8 = Api.parse(reader, signature: signature) as? Api.Peer } } - var _8: Int32? - if Int(_1!) & Int(1 << 4) != 0 {_8 = reader.readInt32() } + var _9: Int32? + if Int(_1!) & Int(1 << 4) != 0 {_9 = reader.readInt32() } let _c1 = _1 != nil let _c2 = (Int(_1!) & Int(1 << 0) == 0) || _2 != nil - let _c3 = _3 != nil - let _c4 = (Int(_1!) & Int(1 << 1) == 0) || _4 != nil - let _c5 = (Int(_1!) & Int(1 << 2) == 0) || _5 != nil - let _c6 = (Int(_1!) & Int(1 << 3) == 0) || _6 != nil - let _c7 = (Int(_1!) & Int(1 << 4) == 0) || _7 != nil + let _c3 = (Int(_1!) & Int(1 << 5) == 0) || _3 != nil + let _c4 = _4 != nil + let _c5 = (Int(_1!) & Int(1 << 1) == 0) || _5 != nil + let _c6 = (Int(_1!) & Int(1 << 2) == 0) || _6 != nil + let _c7 = (Int(_1!) & Int(1 << 3) == 0) || _7 != nil let _c8 = (Int(_1!) & Int(1 << 4) == 0) || _8 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 { - return Api.MessageFwdHeader.messageFwdHeader(flags: _1!, fromId: _2, date: _3!, channelId: _4, channelPost: _5, postAuthor: _6, savedFromPeer: _7, savedFromMsgId: _8) + let _c9 = (Int(_1!) & Int(1 << 4) == 0) || _9 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 { + return Api.MessageFwdHeader.messageFwdHeader(flags: _1!, fromId: _2, fromName: _3, date: _4!, channelId: _5, channelPost: _6, postAuthor: _7, savedFromPeer: _8, savedFromMsgId: _9) } else { return nil diff --git a/TelegramCore/ApplyMaxReadIndexInteractively.swift b/TelegramCore/ApplyMaxReadIndexInteractively.swift index d810b6a7bc..36171dac5c 100644 --- a/TelegramCore/ApplyMaxReadIndexInteractively.swift +++ b/TelegramCore/ApplyMaxReadIndexInteractively.swift @@ -25,7 +25,7 @@ func applyMaxReadIndexInteractively(transaction: Transaction, stateManager: Acco transaction.updateMessage(message.id, update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author?.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } let updatedAttributes = currentMessage.attributes.map({ currentAttribute -> MessageAttribute in if let currentAttribute = currentAttribute as? AutoremoveTimeoutMessageAttribute { @@ -94,7 +94,7 @@ func applySecretOutgoingMessageReadActions(transaction: Transaction, id: Message transaction.updateMessage(message.id, update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author?.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } let updatedAttributes = currentMessage.attributes.map({ currentAttribute -> MessageAttribute in if let currentAttribute = currentAttribute as? AutoremoveTimeoutMessageAttribute { diff --git a/TelegramCore/ApplyUpdateMessage.swift b/TelegramCore/ApplyUpdateMessage.swift index 63f7ebdb89..34c25c2952 100644 --- a/TelegramCore/ApplyUpdateMessage.swift +++ b/TelegramCore/ApplyUpdateMessage.swift @@ -75,10 +75,12 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes let media: [Media] var attributes: [MessageAttribute] let text: String + let forwardInfo: StoreMessageForwardInfo? if let apiMessage = apiMessage, let updatedMessage = StoreMessage(apiMessage: apiMessage) { media = updatedMessage.media attributes = updatedMessage.attributes text = updatedMessage.text + forwardInfo = updatedMessage.forwardInfo } else if case let .updateShortSentMessage(_, _, _, _, _, apiMedia, entities) = result { let (mediaValue, _) = textMediaAndExpirationTimerFromApiMedia(apiMedia, currentMessage.id.peerId) if let mediaValue = mediaValue { @@ -100,10 +102,13 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes attributes = updatedAttributes text = currentMessage.text + + forwardInfo = currentMessage.forwardInfo.flatMap(StoreMessageForwardInfo.init) } else { media = currentMessage.media attributes = currentMessage.attributes text = currentMessage.text + forwardInfo = currentMessage.forwardInfo.flatMap(StoreMessageForwardInfo.init) } if let channelPts = channelPts { @@ -116,16 +121,11 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes attributes.append(ChannelMessageStateVersionAttribute(pts: channelPts)) } - var storeForwardInfo: StoreMessageForwardInfo? - if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) - } - if let fromMedia = currentMessage.media.first, let toMedia = media.first { applyMediaResourceChanges(from: fromMedia, to: toMedia, postbox: postbox) } - if storeForwardInfo == nil { + if forwardInfo == nil { for media in media { if let file = media as? TelegramMediaFile { if file.isSticker { @@ -147,7 +147,7 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes let (tags, globalTags) = tagsForStoreMessage(incoming: currentMessage.flags.contains(.Incoming), attributes: attributes, media: media, textEntities: entitiesAttribute?.entities) - return .update(StoreMessage(id: updatedId, globallyUniqueId: nil, groupingKey: currentMessage.groupingKey, timestamp: updatedTimestamp ?? currentMessage.timestamp, flags: [], tags: tags, globalTags: globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: text, attributes: attributes, media: media)) + return .update(StoreMessage(id: updatedId, globallyUniqueId: nil, groupingKey: currentMessage.groupingKey, timestamp: updatedTimestamp ?? currentMessage.timestamp, flags: [], tags: tags, globalTags: globalTags, localTags: currentMessage.localTags, forwardInfo: forwardInfo, authorId: currentMessage.author?.id, text: text, attributes: attributes, media: media)) }) for file in sentStickers { transaction.addOrMoveToFirstPositionOrderedItemListItem(collectionId: Namespaces.OrderedItemList.CloudRecentStickers, item: OrderedItemListEntry(id: RecentMediaItemId(file.fileId).rawValue, contents: RecentMediaItem(file)), removeTailIfCountExceeds: 20) @@ -229,7 +229,7 @@ func applyUpdateGroupMessages(postbox: Postbox, stateManager: AccountStateManage var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author?.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } if let fromMedia = currentMessage.media.first, let toMedia = media.first { diff --git a/TelegramCore/EnqueueMessage.swift b/TelegramCore/EnqueueMessage.swift index 906759790e..c966a8aa89 100644 --- a/TelegramCore/EnqueueMessage.swift +++ b/TelegramCore/EnqueueMessage.swift @@ -405,7 +405,7 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId, attributes.append(contentsOf: filterMessageAttributesForForwardedMessage(sourceMessage.attributes)) if let sourceForwardInfo = sourceMessage.forwardInfo { - forwardInfo = StoreMessageForwardInfo(authorId: sourceForwardInfo.author.id, sourceId: sourceForwardInfo.source?.id, sourceMessageId: sourceForwardInfo.sourceMessageId, date: sourceForwardInfo.date, authorSignature: sourceForwardInfo.authorSignature) + forwardInfo = StoreMessageForwardInfo(authorId: sourceForwardInfo.author?.id, sourceId: sourceForwardInfo.source?.id, sourceMessageId: sourceForwardInfo.sourceMessageId, date: sourceForwardInfo.date, authorSignature: sourceForwardInfo.authorSignature) } else { if sourceMessage.id.peerId != account.peerId { var hasHiddenForwardMedia = false diff --git a/TelegramCore/HistoryViewChannelStateValidation.swift b/TelegramCore/HistoryViewChannelStateValidation.swift index 6eea73fcf7..14cd422922 100644 --- a/TelegramCore/HistoryViewChannelStateValidation.swift +++ b/TelegramCore/HistoryViewChannelStateValidation.swift @@ -460,7 +460,7 @@ private func validateBatch(postbox: Postbox, network: Network, accountPeerId: Pe } else { var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author?.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } var attributes = currentMessage.attributes if let channelPts = channelPts { @@ -520,7 +520,7 @@ private func validateBatch(postbox: Postbox, network: Network, accountPeerId: Pe transaction.updateMessage(id, update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author?.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } var attributes = currentMessage.attributes for i in (0 ..< attributes.count).reversed() { diff --git a/TelegramCore/ManagedAutoremoveMessageOperations.swift b/TelegramCore/ManagedAutoremoveMessageOperations.swift index 36db665947..d9cb73930c 100644 --- a/TelegramCore/ManagedAutoremoveMessageOperations.swift +++ b/TelegramCore/ManagedAutoremoveMessageOperations.swift @@ -71,7 +71,7 @@ func managedAutoremoveMessageOperations(postbox: Postbox) -> Signal Signal [PeerId] { if let fwdHeader = fwdHeader { switch fwdHeader { - case let .messageFwdHeader(_, fromId, _, channelId, _, _, savedFromPeer, _): - if let channelId = channelId { + case let .messageFwdHeader(messageFwdHeader): + if let channelId = messageFwdHeader.channelId { result.append(PeerId(namespace: Namespaces.Peer.CloudChannel, id: channelId)) } - if let fromId = fromId { + if let fromId = messageFwdHeader.fromId { result.append(PeerId(namespace: Namespaces.Peer.CloudUser, id: fromId)) } - if let savedFromPeer = savedFromPeer { + if let savedFromPeer = messageFwdHeader.savedFromPeer { result.append(savedFromPeer.peerId) } } @@ -403,7 +403,7 @@ extension StoreMessage { var forwardInfo: StoreMessageForwardInfo? if let fwdFrom = fwdFrom { switch fwdFrom { - case let .messageFwdHeader(_, fromId, date, channelId, channelPost, postAuthor, savedFromPeer, savedFromMsgId): + case let .messageFwdHeader(_, fromId, fromName, date, channelId, channelPost, postAuthor, savedFromPeer, savedFromMsgId): var authorId: PeerId? var sourceId: PeerId? var sourceMessageId: MessageId? @@ -423,12 +423,12 @@ extension StoreMessage { if let savedFromPeer = savedFromPeer, let savedFromMsgId = savedFromMsgId { let peerId: PeerId switch savedFromPeer { - case let .peerChannel(channelId): - peerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: channelId) - case let .peerChat(chatId): - peerId = PeerId(namespace: Namespaces.Peer.CloudGroup, id: chatId) - case let .peerUser(userId): - peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: userId) + case let .peerChannel(channelId): + peerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: channelId) + case let .peerChat(chatId): + peerId = PeerId(namespace: Namespaces.Peer.CloudGroup, id: chatId) + case let .peerUser(userId): + peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: userId) } let messageId: MessageId = MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: savedFromMsgId) attributes.append(SourceReferenceMessageAttribute(messageId: messageId)) @@ -438,6 +438,8 @@ extension StoreMessage { forwardInfo = StoreMessageForwardInfo(authorId: authorId, sourceId: sourceId, sourceMessageId: sourceMessageId, date: date, authorSignature: postAuthor) } else if let sourceId = sourceId { forwardInfo = StoreMessageForwardInfo(authorId: sourceId, sourceId: sourceId, sourceMessageId: sourceMessageId, date: date, authorSignature: postAuthor) + } else if let postAuthor = postAuthor ?? fromName { + forwardInfo = StoreMessageForwardInfo(authorId: nil, sourceId: nil, sourceMessageId: sourceMessageId, date: date, authorSignature: postAuthor) } } } diff --git a/TelegramCore/UpdateMessageMedia.swift b/TelegramCore/UpdateMessageMedia.swift index b3ff13b6a3..7ec82bfdb0 100644 --- a/TelegramCore/UpdateMessageMedia.swift +++ b/TelegramCore/UpdateMessageMedia.swift @@ -23,7 +23,7 @@ func updateMessageMedia(transaction: Transaction, id: MediaId, media: Media?) { var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author?.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) })