mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Support bot commands update
This commit is contained in:
parent
902889795c
commit
f80b2641c3
@ -1424,6 +1424,38 @@ private func finalStateWithUpdatesAndServerTime(postbox: Postbox, network: Netwo
|
||||
updatedState.addUpdateChatListFilterOrder(order: order)
|
||||
case let .updateDialogFilter(_, id, filter):
|
||||
updatedState.addUpdateChatListFilter(id: id, filter: filter)
|
||||
case let .updateBotCommands(peer, botId, apiCommands):
|
||||
let botPeerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt32Value(botId))
|
||||
let commands: [BotCommand] = apiCommands.map { command in
|
||||
switch command {
|
||||
case let .botCommand(command, description):
|
||||
return BotCommand(text: command, description: description)
|
||||
}
|
||||
}
|
||||
updatedState.updateCachedPeerData(peer.peerId, { current in
|
||||
if peer.peerId.namespace == Namespaces.Peer.CloudUser, let previous = current as? CachedUserData {
|
||||
if let botInfo = previous.botInfo {
|
||||
return previous.withUpdatedBotInfo(BotInfo(description: botInfo.description, commands: commands))
|
||||
}
|
||||
} else if peer.peerId.namespace == Namespaces.Peer.CloudGroup, let previous = current as? CachedGroupData {
|
||||
if let index = previous.botInfos.firstIndex(where: { $0.peerId == botPeerId }) {
|
||||
var updatedBotInfos = previous.botInfos
|
||||
let previousBotInfo = updatedBotInfos[index]
|
||||
updatedBotInfos.remove(at: index)
|
||||
updatedBotInfos.insert(CachedPeerBotInfo(peerId: botPeerId, botInfo: BotInfo(description: previousBotInfo.botInfo.description, commands: commands)), at: index)
|
||||
return previous.withUpdatedBotInfos(updatedBotInfos)
|
||||
}
|
||||
} else if peer.peerId.namespace == Namespaces.Peer.CloudChannel, let previous = current as? CachedChannelData {
|
||||
if let index = previous.botInfos.firstIndex(where: { $0.peerId == botPeerId }) {
|
||||
var updatedBotInfos = previous.botInfos
|
||||
let previousBotInfo = updatedBotInfos[index]
|
||||
updatedBotInfos.remove(at: index)
|
||||
updatedBotInfos.insert(CachedPeerBotInfo(peerId: botPeerId, botInfo: BotInfo(description: previousBotInfo.botInfo.description, commands: commands)), at: index)
|
||||
return previous.withUpdatedBotInfos(updatedBotInfos)
|
||||
}
|
||||
}
|
||||
return current
|
||||
})
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user