diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index d8c3351aea..a5165b9222 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -6914,6 +6914,7 @@ Sorry for the inconvenience."; "MemberRequests.RequestToJoinSentDescriptionGroup" = "You will be added to the group once it admins approve your request."; "MemberRequests.RequestToJoinSentDescriptionChannel" = "You will be added to the channel once it admins approve your request."; +"Notification.JoinedChatByRequestYou" = "Your request to join the channel was approved"; "Notification.JoinedGroupByRequestYou" = "Your request to join the group was approved"; "Notification.JoinedGroupByRequest" = "%@ was accepted to the group chat"; diff --git a/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramGroup.swift b/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramGroup.swift index 686ed9353f..5205dd0350 100644 --- a/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramGroup.swift +++ b/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramGroup.swift @@ -209,4 +209,8 @@ public final class TelegramGroup: Peer, Equatable { public func updateDefaultBannedRights(_ defaultBannedRights: TelegramChatBannedRights?, version: Int) -> TelegramGroup { return TelegramGroup(id: self.id, title: self.title, photo: self.photo, participantCount: self.participantCount, role: self.role, membership: self.membership, flags: self.flags, defaultBannedRights: defaultBannedRights, migrationReference: self.migrationReference, creationDate: self.creationDate, version: version) } + + public func updateParticipantCount(_ participantCount: Int) -> TelegramGroup { + return TelegramGroup(id: self.id, title: self.title, photo: self.photo, participantCount: participantCount, role: self.role, membership: self.membership, flags: self.flags, defaultBannedRights: self.defaultBannedRights, migrationReference: self.migrationReference, creationDate: self.creationDate, version: version) + } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/InvitationLinks.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/InvitationLinks.swift index ffed92623c..de2726ea62 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/InvitationLinks.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/InvitationLinks.swift @@ -660,8 +660,33 @@ public struct PeerInvitationImportersState: Equatable { } final class CachedPeerInvitationImporters: Codable { + private struct DictionaryPair: Codable, Hashable { + var key: Int64 + var value: String + + init(_ key: Int64, value: String) { + self.key = key + self.value = value + } + + init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: StringCodingKey.self) + + self.key = try container.decode(Int64.self, forKey: "k") + self.value = try container.decode(String.self, forKey: "v") + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: StringCodingKey.self) + + try container.encode(self.key, forKey: "k") + try container.encode(self.value, forKey: "v") + } + } + let peerIds: [PeerId] let dates: [PeerId: Int32] + let abouts: [PeerId: String] let count: Int32 static func key(peerId: PeerId, link: String, requested: Bool) -> ValueBoxKey { @@ -676,12 +701,18 @@ final class CachedPeerInvitationImporters: Codable { self.dates = importers.reduce(into: [PeerId: Int32]()) { $0[$1.peer.peerId] = $1.date } + self.abouts = importers.reduce(into: [PeerId: String]()) { + if let about = $1.about { + $0[$1.peer.peerId] = about + } + } self.count = count } - init(peerIds: [PeerId], dates: [PeerId: Int32], count: Int32) { + init(peerIds: [PeerId], dates: [PeerId: Int32], abouts: [PeerId: String], count: Int32) { self.peerIds = peerIds self.dates = dates + self.abouts = abouts self.count = count } @@ -700,6 +731,14 @@ final class CachedPeerInvitationImporters: Codable { } self.dates = dates + var abouts: [PeerId: String] = [:] + let aboutsArray = try container.decode([DictionaryPair].self, forKey: "abouts") + for aboutPair in aboutsArray { + let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(aboutPair.key)) + abouts[peerId] = aboutPair.value + } + self.abouts = abouts + self.count = try container.decode(Int32.self, forKey: "count") } @@ -715,6 +754,12 @@ final class CachedPeerInvitationImporters: Codable { } try container.encode(dates, forKey: "dates") + var abouts: [DictionaryPair] = [] + for (peerId, about) in self.abouts { + abouts.append(DictionaryPair(peerId.id._internalGetInt64Value(), value: about)) + } + try container.encode(abouts, forKey: "abouts") + try container.encode(self.count, forKey: "count") } } @@ -727,7 +772,7 @@ private final class PeerInvitationImportersContextImpl { private let requested: Bool private let query: String? private let disposable = MetaDisposable() - private let updateDisposable = MetaDisposable() + private let updateDisposables = DisposableSet() private let actionDisposables = DisposableSet() private var isLoadingMore: Bool = false private var hasLoadedOnce: Bool = false @@ -771,7 +816,7 @@ private final class PeerInvitationImportersContextImpl { var result: [PeerInvitationImportersState.Importer] = [] for peerId in cachedResult.peerIds { if let peer = transaction.getPeer(peerId), let date = cachedResult.dates[peerId] { - result.append(PeerInvitationImportersState.Importer(peer: RenderedPeer(peer: peer), date: date)) + result.append(PeerInvitationImportersState.Importer(peer: RenderedPeer(peer: peer), date: date, about: cachedResult.abouts[peerId])) } else { return nil } @@ -801,7 +846,7 @@ private final class PeerInvitationImportersContextImpl { deinit { self.disposable.dispose() - self.updateDisposable.dispose() + self.updateDisposables.dispose() self.actionDisposables.dispose() } @@ -931,6 +976,30 @@ private final class PeerInvitationImportersContextImpl { self.count = max(0, self.count - 1) self.updateState() self.updateCache() + + if case .approve = action { + self.updateDisposables.add(self.account.postbox.transaction({ transaction in + let peer = transaction.getPeer(self.peerId) + if let peer = peer as? TelegramGroup { + updatePeers(transaction: transaction, peers: [peer], update: { current, _ in + var updated = current + if let current = current as? TelegramGroup { + updated = current.updateParticipantCount(current.participantCount + 1) + } + return updated + }) + } else if let _ = peer as? TelegramChannel { + transaction.updatePeerCachedData(peerIds: Set([self.peerId]), update: { _, current in + var updated = current + if let current = current as? CachedChannelData, let currentMemberCount = current.participantsSummary.memberCount { + let updatedParticipantsSummary = current.participantsSummary.withUpdatedMemberCount(currentMemberCount + 1) + updated = current.withUpdatedParticipantsSummary(updatedParticipantsSummary) + } + return updated + }) + } + }).start()) + } } private func updateCache() { @@ -942,7 +1011,7 @@ private final class PeerInvitationImportersContextImpl { let resultImporters = Array(self.results.prefix(50)) let count = self.count let link = self.link - self.updateDisposable.set(self.account.postbox.transaction({ transaction in + self.updateDisposables.add(self.account.postbox.transaction({ transaction in if let entry = CodableEntry(CachedPeerInvitationImporters(importers: resultImporters, count: count)) { transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedPeerInvitationImporters, key: CachedPeerInvitationImporters.key(peerId: peerId, link: link ?? "requests", requested: self.requested)), entry: entry, collectionSpec: cachedPeerInvitationImportersCollectionSpec) }