diff --git a/TelegramCore/AccountStateManagementUtils.swift b/TelegramCore/AccountStateManagementUtils.swift index ce21670d05..06be7ad1d0 100644 --- a/TelegramCore/AccountStateManagementUtils.swift +++ b/TelegramCore/AccountStateManagementUtils.swift @@ -2044,6 +2044,16 @@ func replayFinalState(accountPeerId: PeerId, mediaBox: MediaBox, transaction: Tr } } + if case let .Id(id) = message.id { + for media in message.media { + if let action = media as? TelegramMediaAction, case .groupCreated = action.action { + if let hole = transaction.getHole(messageId: MessageId(peerId: chatPeerId, namespace: Namespaces.Message.Cloud, id: id.id - 1)) { + transaction.fillHole(hole, fillType: HoleFill(complete: true, direction: .UpperToLower(updatedMinIndex: nil, clippingMaxIndex: nil)), tagMask: nil, messages: []) + } + } + } + } + if !message.flags.contains(.Incoming), message.forwardInfo == nil { inner: for media in message.media { if let file = media as? TelegramMediaFile { diff --git a/TelegramCore/CachedGroupData.swift b/TelegramCore/CachedGroupData.swift index f4c3e98863..77f1f84bf9 100644 --- a/TelegramCore/CachedGroupData.swift +++ b/TelegramCore/CachedGroupData.swift @@ -36,6 +36,7 @@ public final class CachedGroupData: CachedPeerData { public let reportStatus: PeerReportStatus public let pinnedMessageId: MessageId? public let defaultBannedRights: TelegramChatBannedRights? + public let about: String? public let peerIds: Set public let messageIds: Set @@ -50,9 +51,10 @@ public final class CachedGroupData: CachedPeerData { self.messageIds = Set() self.peerIds = Set() self.defaultBannedRights = nil + self.about = nil } - public init(participants: CachedGroupParticipants?, exportedInvitation: ExportedInvitation?, botInfos: [CachedPeerBotInfo], reportStatus: PeerReportStatus, pinnedMessageId: MessageId?, defaultBannedRights: TelegramChatBannedRights?) { + public init(participants: CachedGroupParticipants?, exportedInvitation: ExportedInvitation?, botInfos: [CachedPeerBotInfo], reportStatus: PeerReportStatus, pinnedMessageId: MessageId?, defaultBannedRights: TelegramChatBannedRights?, about: String?) { self.participants = participants self.exportedInvitation = exportedInvitation self.botInfos = botInfos @@ -76,6 +78,7 @@ public final class CachedGroupData: CachedPeerData { peerIds.insert(botInfo.peerId) } self.peerIds = peerIds + self.about = about } public init(decoder: PostboxDecoder) { @@ -90,6 +93,7 @@ public final class CachedGroupData: CachedPeerData { self.pinnedMessageId = nil } self.defaultBannedRights = decoder.decodeObjectForKey("defbr", decoder: { TelegramChatBannedRights(decoder: $0) }) as? TelegramChatBannedRights + self.about = decoder.decodeOptionalStringForKey("ab") var messageIds = Set() if let pinnedMessageId = self.pinnedMessageId { @@ -137,6 +141,11 @@ public final class CachedGroupData: CachedPeerData { } else { encoder.encodeNil(forKey: "defbr") } + if let about = self.about { + encoder.encodeString(about, forKey: "ab") + } else { + encoder.encodeNil(forKey: "ab") + } } public func isEqual(to: CachedPeerData) -> Bool { @@ -144,30 +153,34 @@ public final class CachedGroupData: CachedPeerData { return false } - return self.participants == other.participants && self.exportedInvitation == other.exportedInvitation && self.botInfos == other.botInfos && self.reportStatus == other.reportStatus && self.pinnedMessageId == other.pinnedMessageId && self.defaultBannedRights == other.defaultBannedRights + return self.participants == other.participants && self.exportedInvitation == other.exportedInvitation && self.botInfos == other.botInfos && self.reportStatus == other.reportStatus && self.pinnedMessageId == other.pinnedMessageId && self.defaultBannedRights == other.defaultBannedRights && self.about == other.about } func withUpdatedParticipants(_ participants: CachedGroupParticipants?) -> CachedGroupData { - return CachedGroupData(participants: participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: self.defaultBannedRights) + return CachedGroupData(participants: participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: self.defaultBannedRights, about: self.about) } func withUpdatedExportedInvitation(_ exportedInvitation: ExportedInvitation?) -> CachedGroupData { - return CachedGroupData(participants: self.participants, exportedInvitation: exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: self.defaultBannedRights) + return CachedGroupData(participants: self.participants, exportedInvitation: exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: self.defaultBannedRights, about: self.about) } func withUpdatedBotInfos(_ botInfos: [CachedPeerBotInfo]) -> CachedGroupData { - return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: self.defaultBannedRights) + return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: self.defaultBannedRights, about: self.about) } func withUpdatedReportStatus(_ reportStatus: PeerReportStatus) -> CachedGroupData { - return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: self.defaultBannedRights) + return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: self.defaultBannedRights, about: self.about) } func withUpdatedPinnedMessageId(_ pinnedMessageId: MessageId?) -> CachedGroupData { - return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: pinnedMessageId, defaultBannedRights: self.defaultBannedRights) + return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: pinnedMessageId, defaultBannedRights: self.defaultBannedRights, about: self.about) } func withUpdatedDefaultBannedRights(_ defaultBannedRights: TelegramChatBannedRights?) -> CachedGroupData { - return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: defaultBannedRights) + return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: defaultBannedRights, about: self.about) + } + + func withUpdatedAbout(_ about: String?) -> CachedGroupData { + return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: self.defaultBannedRights, about: about) } } diff --git a/TelegramCore/CreateGroup.swift b/TelegramCore/CreateGroup.swift index e656106d6a..7376cb88c4 100644 --- a/TelegramCore/CreateGroup.swift +++ b/TelegramCore/CreateGroup.swift @@ -20,28 +20,29 @@ public func createGroup(account: Account, title: String, peerIds: [PeerId]) -> S } } return account.network.request(Api.functions.messages.createChat(users: inputUsers, title: title)) - |> map(Optional.init) - |> `catch` { _ in - return Signal.single(nil) - } - |> mapToSignal { updates -> Signal in - if let updates = updates { - account.stateManager.addUpdates(updates) - if let message = updates.messages.first, let peerId = apiMessagePeerId(message) { - return account.postbox.multiplePeersView([peerId]) - |> filter { view in - return view.peers[peerId] != nil - } - |> take(1) - |> map { _ in - return peerId - } - |> timeout(5.0, queue: Queue.concurrentDefaultQueue(), alternate: .single(nil)) + |> map(Optional.init) + |> `catch` { _ in + return Signal.single(nil) + } + |> mapToSignal { updates -> Signal in + if let updates = updates { + account.stateManager.addUpdates(updates) + if let message = updates.messages.first, let peerId = apiMessagePeerId(message) { + return account.postbox.multiplePeersView([peerId]) + |> filter { view in + return view.peers[peerId] != nil } - return .single(nil) - } else { - return .single(nil) + |> take(1) + |> map { _ in + return peerId + } + |> timeout(5.0, queue: Queue.concurrentDefaultQueue(), alternate: .single(nil)) } + return .single(nil) + } else { + return .single(nil) } - } |> switchToLatest + } + } + |> switchToLatest } diff --git a/TelegramCore/UpdateCachedPeerData.swift b/TelegramCore/UpdateCachedPeerData.swift index da8b7c8d08..585ba6aef8 100644 --- a/TelegramCore/UpdateCachedPeerData.swift +++ b/TelegramCore/UpdateCachedPeerData.swift @@ -220,6 +220,7 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId: PeerId, network .withUpdatedBotInfos(botInfos) .withUpdatedPinnedMessageId(pinnedMessageId) .withUpdatedDefaultBannedRights(defaultBannedRights) + .withUpdatedAbout(chatFull.about) }) case .channelFull: break diff --git a/TelegramCore/UpdatePeerInfo.swift b/TelegramCore/UpdatePeerInfo.swift index 7d2753391e..015feafacc 100644 --- a/TelegramCore/UpdatePeerInfo.swift +++ b/TelegramCore/UpdatePeerInfo.swift @@ -75,6 +75,8 @@ public func updatePeerDescription(account: Account, peerId: PeerId, description: transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in if let current = current as? CachedChannelData { return current.withUpdatedAbout(description) + } else if let current = current as? CachedGroupData { + return current.withUpdatedAbout(description) } else { return current }