mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-06-20 18:24:43 +00:00
Migrate RenderedChannelParticipant.peers from [PeerId: Peer] to
[EnginePeer.Id: EnginePeer]. Closes the wave-41 ratchet — the public
struct no longer leaks raw Peer types in any field (presences stays
Postbox-typed; separate migration).
Consumer-surface: -10 bridges. Dropped 6 EnginePeer(peer) read-wraps
at participant.peers[...] extraction sites across
ChannelAdminsController, ChannelMembersSearchContainerNode,
ChannelBlacklistController. Dropped 5 .mapValues({ $0._asPeer() })
constructor-unwrap transforms in ChannelAdminsController,
ChannelMembersSearchContainerNode, ChannelMembersSearchControllerNode.
Added 2 ._asPeer() unwraps in ChatRecentActionsHistoryTransition at
the two iteration sites (line 673 via participant.peers, line 2273
via new.peers in participantSubscriptionExtended) where the iterated
value is inserted into a raw-Peer SimpleDictionary.
TelegramCore producers: 8 files build the local peers dict inside
postbox.transaction and wrap at the insertion point. ChannelMembers,
RequestStartBot, ChannelOwnershipTransfer, JoinChannel, AddPeerMember,
PeerAdmins, ChannelBlacklist, Ranks.
2-iteration build convergence. Iteration-1 surfaced new.peers at
ChatRecentActionsHistoryTransition:2272 that the plan's participant.peers
pre-flight grep missed; wider grep now confirms the two iteration sites
are the complete surface.
No unit tests in this project; full Telegram/Telegram build verified
under configuration=debug_sim_arm64.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
129 lines
6.7 KiB
Swift
129 lines
6.7 KiB
Swift
import Foundation
|
|
import Postbox
|
|
import SwiftSignalKit
|
|
import TelegramApi
|
|
import MtProtoKit
|
|
|
|
|
|
public enum ChannelMembersCategoryFilter {
|
|
case all
|
|
case search(String)
|
|
}
|
|
|
|
public enum ChannelMembersCategory {
|
|
case recent(ChannelMembersCategoryFilter)
|
|
case admins
|
|
case contacts(ChannelMembersCategoryFilter)
|
|
case bots(ChannelMembersCategoryFilter)
|
|
case restricted(ChannelMembersCategoryFilter)
|
|
case banned(ChannelMembersCategoryFilter)
|
|
case mentions(threadId: MessageId?, filter: ChannelMembersCategoryFilter)
|
|
}
|
|
|
|
func _internal_channelMembers(postbox: Postbox, network: Network, accountPeerId: PeerId, peerId: PeerId, category: ChannelMembersCategory = .recent(.all), offset: Int32 = 0, limit: Int32 = 64, hash: Int64 = 0) -> Signal<[RenderedChannelParticipant]?, NoError> {
|
|
return postbox.transaction { transaction -> Signal<[RenderedChannelParticipant]?, NoError> in
|
|
if let peer = transaction.getPeer(peerId) as? TelegramChannel, let inputChannel = apiInputChannel(peer) {
|
|
if case .broadcast = peer.info {
|
|
if let _ = peer.adminRights {
|
|
} else {
|
|
return .single(nil)
|
|
}
|
|
}
|
|
if peer.flags.contains(.isMonoforum) {
|
|
return .single(nil)
|
|
}
|
|
|
|
let apiFilter: Api.ChannelParticipantsFilter
|
|
switch category {
|
|
case let .recent(filter):
|
|
switch filter {
|
|
case .all:
|
|
apiFilter = .channelParticipantsRecent
|
|
case let .search(query):
|
|
apiFilter = .channelParticipantsSearch(Api.ChannelParticipantsFilter.Cons_channelParticipantsSearch(q: query))
|
|
}
|
|
case let .mentions(threadId, filter):
|
|
switch filter {
|
|
case .all:
|
|
var flags: Int32 = 0
|
|
if threadId != nil {
|
|
flags |= 1 << 1
|
|
}
|
|
apiFilter = .channelParticipantsMentions(Api.ChannelParticipantsFilter.Cons_channelParticipantsMentions(flags: flags, q: nil, topMsgId: threadId?.id))
|
|
case let .search(query):
|
|
var flags: Int32 = 0
|
|
if threadId != nil {
|
|
flags |= 1 << 1
|
|
}
|
|
if !query.isEmpty {
|
|
flags |= 1 << 0
|
|
}
|
|
apiFilter = .channelParticipantsMentions(Api.ChannelParticipantsFilter.Cons_channelParticipantsMentions(flags: flags, q: query.isEmpty ? nil : query, topMsgId: threadId?.id))
|
|
}
|
|
case .admins:
|
|
apiFilter = .channelParticipantsAdmins
|
|
case let .contacts(filter):
|
|
switch filter {
|
|
case .all:
|
|
apiFilter = .channelParticipantsContacts(Api.ChannelParticipantsFilter.Cons_channelParticipantsContacts(q: ""))
|
|
case let .search(query):
|
|
apiFilter = .channelParticipantsContacts(Api.ChannelParticipantsFilter.Cons_channelParticipantsContacts(q: query))
|
|
}
|
|
case .bots:
|
|
apiFilter = .channelParticipantsBots
|
|
case let .restricted(filter):
|
|
switch filter {
|
|
case .all:
|
|
apiFilter = .channelParticipantsBanned(Api.ChannelParticipantsFilter.Cons_channelParticipantsBanned(q: ""))
|
|
case let .search(query):
|
|
apiFilter = .channelParticipantsBanned(Api.ChannelParticipantsFilter.Cons_channelParticipantsBanned(q: query))
|
|
}
|
|
case let .banned(filter):
|
|
switch filter {
|
|
case .all:
|
|
apiFilter = .channelParticipantsKicked(Api.ChannelParticipantsFilter.Cons_channelParticipantsKicked(q: ""))
|
|
case let .search(query):
|
|
apiFilter = .channelParticipantsKicked(Api.ChannelParticipantsFilter.Cons_channelParticipantsKicked(q: query))
|
|
}
|
|
}
|
|
return network.request(Api.functions.channels.getParticipants(channel: inputChannel, filter: apiFilter, offset: offset, limit: limit, hash: hash))
|
|
|> retryRequestIfNotFrozen
|
|
|> mapToSignal { result -> Signal<[RenderedChannelParticipant]?, NoError> in
|
|
guard let result else {
|
|
return .single(nil)
|
|
}
|
|
return postbox.transaction { transaction -> [RenderedChannelParticipant]? in
|
|
var items: [RenderedChannelParticipant] = []
|
|
switch result {
|
|
case let .channelParticipants(channelParticipantsData):
|
|
let (participants, chats, users) = (channelParticipantsData.participants, channelParticipantsData.chats, channelParticipantsData.users)
|
|
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
|
|
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
|
|
var peers: [EnginePeer.Id: EnginePeer] = [:]
|
|
for id in parsedPeers.allIds {
|
|
if let peer = transaction.getPeer(id) {
|
|
peers[peer.id] = EnginePeer(peer)
|
|
}
|
|
}
|
|
|
|
for participant in CachedChannelParticipants(apiParticipants: participants).participants {
|
|
if let peer = parsedPeers.get(participant.peerId) {
|
|
var renderedPresences: [PeerId: PeerPresence] = [:]
|
|
if let presence = transaction.getPeerPresence(peerId: participant.peerId) {
|
|
renderedPresences[participant.peerId] = presence
|
|
}
|
|
items.append(RenderedChannelParticipant(participant: participant, peer: EnginePeer(peer), peers: peers, presences: renderedPresences))
|
|
}
|
|
}
|
|
case .channelParticipantsNotModified:
|
|
return nil
|
|
}
|
|
return items
|
|
}
|
|
}
|
|
} else {
|
|
return .single([])
|
|
}
|
|
} |> switchToLatest
|
|
}
|