mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Refactoring
This commit is contained in:
40
submodules/TelegramCore/Sources/State/ChannelState.swift
Normal file
40
submodules/TelegramCore/Sources/State/ChannelState.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
import TelegramApi
|
||||
|
||||
import SyncCore
|
||||
|
||||
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(message, _, _):
|
||||
peerId = apiMessagePeerId(message)
|
||||
case let .updateDeleteChannelMessages(channelId, _, _, _):
|
||||
peerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: channelId)
|
||||
case let .updateEditChannelMessage(message, _, _):
|
||||
peerId = apiMessagePeerId(message)
|
||||
case let .updateChannelWebPage(channelId, _, _, _):
|
||||
peerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: channelId)
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
if let peerId = peerId {
|
||||
if grouped[peerId] == nil {
|
||||
grouped[peerId] = [update]
|
||||
} else {
|
||||
grouped[peerId]!.append(update)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return grouped
|
||||
}
|
||||
Reference in New Issue
Block a user