Files
Swiftgram/submodules/TelegramCore/Sources/State/ChannelState.swift
Isaac 9b71eb0f8f Refactor constructor use sites for types 340-359 to struct pattern
Updates TelegramCore to work with --struct-count=360. This batch includes
story types, update types, user types, theme types, and various other
constructors in the 340-359 type range.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 22:21:57 +08:00

44 lines
2.0 KiB
Swift

import Foundation
import Postbox
import TelegramApi
struct ChannelUpdate {
let update: Api.Update
let ptsRange: (Int32, Int32)?
}
func channelUpdatesByPeerId(updates: [ChannelUpdate]) -> [PeerId: [ChannelUpdate]] {
var grouped: [PeerId: [ChannelUpdate]] = [:]
for update in updates {
var peerId: PeerId?
switch update.update {
case let .updateNewChannelMessage(updateNewChannelMessageData):
let (message, _, _) = (updateNewChannelMessageData.message, updateNewChannelMessageData.pts, updateNewChannelMessageData.ptsCount)
peerId = apiMessagePeerId(message)
case let .updateDeleteChannelMessages(updateDeleteChannelMessagesData):
let (channelId, _, _, _) = (updateDeleteChannelMessagesData.channelId, updateDeleteChannelMessagesData.messages, updateDeleteChannelMessagesData.pts, updateDeleteChannelMessagesData.ptsCount)
peerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId))
case let .updateEditChannelMessage(updateEditChannelMessageData):
let (message, _, _) = (updateEditChannelMessageData.message, updateEditChannelMessageData.pts, updateEditChannelMessageData.ptsCount)
peerId = apiMessagePeerId(message)
case let .updateChannelWebPage(updateChannelWebPageData):
let (channelId, _, _, _) = (updateChannelWebPageData.channelId, updateChannelWebPageData.webpage, updateChannelWebPageData.pts, updateChannelWebPageData.ptsCount)
peerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId))
default:
break
}
if let peerId = peerId {
if grouped[peerId] == nil {
grouped[peerId] = [update]
} else {
grouped[peerId]!.append(update)
}
}
}
return grouped
}