mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
[WIP] Business
This commit is contained in:
@@ -196,18 +196,28 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
|
||||
} else {
|
||||
editableBotInfo = .single(nil)
|
||||
}
|
||||
|
||||
var additionalConnectedBots: Signal<Api.account.ConnectedBots?, NoError> = .single(nil)
|
||||
if rawPeerId == accountPeerId {
|
||||
additionalConnectedBots = network.request(Api.functions.account.getConnectedBots())
|
||||
|> map(Optional.init)
|
||||
|> `catch` { _ -> Signal<Api.account.ConnectedBots?, NoError> in
|
||||
return .single(nil)
|
||||
}
|
||||
}
|
||||
|
||||
return combineLatest(
|
||||
network.request(Api.functions.users.getFullUser(id: inputUser))
|
||||
|> retryRequest,
|
||||
editableBotInfo
|
||||
editableBotInfo,
|
||||
additionalConnectedBots
|
||||
)
|
||||
|> mapToSignal { result, editableBotInfo -> Signal<Bool, NoError> in
|
||||
|> mapToSignal { result, editableBotInfo, additionalConnectedBots -> Signal<Bool, NoError> in
|
||||
return postbox.transaction { transaction -> Bool in
|
||||
switch result {
|
||||
case let .userFull(fullUser, chats, users):
|
||||
var accountUser: Api.User?
|
||||
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
|
||||
var parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
|
||||
for user in users {
|
||||
if user.peerId == accountPeerId {
|
||||
accountUser = user
|
||||
@@ -215,6 +225,26 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
|
||||
}
|
||||
let _ = accountUser
|
||||
|
||||
var mappedConnectedBot: TelegramAccountConnectedBot?
|
||||
|
||||
if let additionalConnectedBots {
|
||||
switch additionalConnectedBots {
|
||||
case let .connectedBots(connectedBots, users):
|
||||
parsedPeers = parsedPeers.union(with: AccumulatedPeers(transaction: transaction, chats: [], users: users))
|
||||
|
||||
if let apiBot = connectedBots.first {
|
||||
switch apiBot {
|
||||
case let .connectedBot(flags, botId, recipients):
|
||||
mappedConnectedBot = TelegramAccountConnectedBot(
|
||||
id: PeerId(botId),
|
||||
recipients: TelegramBusinessRecipients(apiValue: recipients),
|
||||
canReply: (flags & (1 << 0)) != 0
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch fullUser {
|
||||
case let .userFull(_, _, _, _, _, _, _, _, userFullNotifySettings, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _):
|
||||
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
|
||||
@@ -228,7 +258,7 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
|
||||
previous = CachedUserData()
|
||||
}
|
||||
switch fullUser {
|
||||
case let .userFull(userFullFlags, _, _, userFullAbout, userFullSettings, personalPhoto, profilePhoto, fallbackPhoto, _, userFullBotInfo, userFullPinnedMsgId, userFullCommonChatsCount, _, userFullTtlPeriod, userFullThemeEmoticon, _, _, _, userPremiumGiftOptions, userWallpaper, stories, businessWorkHours, businessLocation, _, _):
|
||||
case let .userFull(userFullFlags, _, _, userFullAbout, userFullSettings, personalPhoto, profilePhoto, fallbackPhoto, _, userFullBotInfo, userFullPinnedMsgId, userFullCommonChatsCount, _, userFullTtlPeriod, userFullThemeEmoticon, _, _, _, userPremiumGiftOptions, userWallpaper, stories, businessWorkHours, businessLocation, greetingMessage, awayMessage):
|
||||
let _ = stories
|
||||
let botInfo = userFullBotInfo.flatMap(BotInfo.init(apiBotInfo:))
|
||||
let isBlocked = (userFullFlags & (1 << 0)) != 0
|
||||
@@ -296,6 +326,16 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
|
||||
mappedBusinessLocation = TelegramBusinessLocation(apiLocation: businessLocation)
|
||||
}
|
||||
|
||||
var mappedGreetingMessage: TelegramBusinessGreetingMessage?
|
||||
if let greetingMessage {
|
||||
mappedGreetingMessage = TelegramBusinessGreetingMessage(apiGreetingMessage: greetingMessage)
|
||||
}
|
||||
|
||||
var mappedAwayMessage: TelegramBusinessAwayMessage?
|
||||
if let awayMessage {
|
||||
mappedAwayMessage = TelegramBusinessAwayMessage(apiAwayMessage: awayMessage)
|
||||
}
|
||||
|
||||
return previous.withUpdatedAbout(userFullAbout)
|
||||
.withUpdatedBotInfo(botInfo)
|
||||
.withUpdatedEditableBotInfo(editableBotInfo)
|
||||
@@ -319,6 +359,9 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
|
||||
.withUpdatedFlags(flags)
|
||||
.withUpdatedBusinessHours(mappedBusinessHours)
|
||||
.withUpdatedBusinessLocation(mappedBusinessLocation)
|
||||
.withUpdatedGreetingMessage(mappedGreetingMessage)
|
||||
.withUpdatedAwayMessage(mappedAwayMessage)
|
||||
.withUpdatedConnectedBot(mappedConnectedBot)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user