mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-08 08:31:13 +00:00
Update contact management
This commit is contained in:
parent
5603d1fc09
commit
9cfe296c53
@ -108,8 +108,8 @@ func syncContactsOnce(network: Network, postbox: Postbox, accountPeerId: PeerId)
|
|||||||
return appliedUpdatedPeers
|
return appliedUpdatedPeers
|
||||||
}
|
}
|
||||||
|
|
||||||
public func deleteContactPeerInteractively(account: Account, peerId: PeerId) -> Signal<Void, NoError> {
|
public func deleteContactPeerInteractively(account: Account, peerId: PeerId) -> Signal<Never, NoError> {
|
||||||
return account.postbox.transaction { transaction -> Signal<Void, NoError> in
|
return account.postbox.transaction { transaction -> Signal<Never, NoError> in
|
||||||
if let peer = transaction.getPeer(peerId), let inputUser = apiInputUser(peer) {
|
if let peer = transaction.getPeer(peerId), let inputUser = apiInputUser(peer) {
|
||||||
return account.network.request(Api.functions.contacts.deleteContacts(id: [inputUser]))
|
return account.network.request(Api.functions.contacts.deleteContacts(id: [inputUser]))
|
||||||
|> map(Optional.init)
|
|> map(Optional.init)
|
||||||
@ -128,6 +128,7 @@ public func deleteContactPeerInteractively(account: Account, peerId: PeerId) ->
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|> ignoreValues
|
||||||
} else {
|
} else {
|
||||||
return .complete()
|
return .complete()
|
||||||
}
|
}
|
||||||
|
@ -104,65 +104,180 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId: PeerId, network: Network,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId: PeerId, network: Network, postbox: Postbox) -> Signal<Void, NoError> {
|
func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId: PeerId, network: Network, postbox: Postbox) -> Signal<Void, NoError> {
|
||||||
return postbox.loadedPeerWithId(peerId)
|
return postbox.transaction { transaction -> (Api.InputUser?, Peer?) in
|
||||||
|> mapToSignal { peer -> Signal<Void, NoError> in
|
if peerId == accountPeerId {
|
||||||
if let inputUser = apiInputUser(peer) {
|
return (.inputUserSelf, transaction.getPeer(peerId))
|
||||||
return network.request(Api.functions.users.getFullUser(id: inputUser))
|
} else {
|
||||||
|> retryRequest
|
let peer = transaction.getPeer(peerId)
|
||||||
|> mapToSignal { result -> Signal<Void, NoError> in
|
return (peer.flatMap(apiInputUser), peer)
|
||||||
return postbox.transaction { transaction -> Void in
|
}
|
||||||
|
}
|
||||||
|
|> mapToSignal { inputUser, maybePeer -> Signal<Void, NoError> in
|
||||||
|
if let inputUser = inputUser {
|
||||||
|
return network.request(Api.functions.users.getFullUser(id: inputUser))
|
||||||
|
|> retryRequest
|
||||||
|
|> mapToSignal { result -> Signal<Void, NoError> in
|
||||||
|
return postbox.transaction { transaction -> Void in
|
||||||
|
switch result {
|
||||||
|
case let .userFull(userFull):
|
||||||
|
let telegramUser = TelegramUser(user: userFull.user)
|
||||||
|
updatePeers(transaction: transaction, peers: [telegramUser], update: { _, updated -> Peer in
|
||||||
|
return updated
|
||||||
|
})
|
||||||
|
transaction.updateCurrentPeerNotificationSettings([peerId: TelegramPeerNotificationSettings(apiSettings: userFull.notifySettings)])
|
||||||
|
if let presence = TelegramUserPresence(apiUser: userFull.user) {
|
||||||
|
updatePeerPresences(transaction: transaction, accountPeerId: accountPeerId, peerPresences: [telegramUser.id: presence])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
transaction.updatePeerCachedData(peerIds: [peerId], update: { peerId, current in
|
||||||
|
let previous: CachedUserData
|
||||||
|
if let current = current as? CachedUserData {
|
||||||
|
previous = current
|
||||||
|
} else {
|
||||||
|
previous = CachedUserData()
|
||||||
|
}
|
||||||
switch result {
|
switch result {
|
||||||
case let .userFull(userFull):
|
case let .userFull(userFull):
|
||||||
let telegramUser = TelegramUser(user: userFull.user)
|
let botInfo = userFull.botInfo.flatMap(BotInfo.init(apiBotInfo:))
|
||||||
updatePeers(transaction: transaction, peers: [telegramUser], update: { _, updated -> Peer in
|
let isBlocked = (userFull.flags & (1 << 0)) != 0
|
||||||
return updated
|
let callsAvailable = (userFull.flags & (1 << 4)) != 0
|
||||||
})
|
let callsPrivate = (userFull.flags & (1 << 5)) != 0
|
||||||
transaction.updateCurrentPeerNotificationSettings([peerId: TelegramPeerNotificationSettings(apiSettings: userFull.notifySettings)])
|
let canPinMessages = (userFull.flags & (1 << 7)) != 0
|
||||||
if let presence = TelegramUserPresence(apiUser: userFull.user) {
|
let pinnedMessageId = userFull.pinnedMsgId.flatMap({ MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: $0) })
|
||||||
updatePeerPresences(transaction: transaction, accountPeerId: accountPeerId, peerPresences: [peer.id: presence])
|
|
||||||
}
|
let peerStatusSettings = PeerStatusSettings(apiSettings: userFull.settings)
|
||||||
|
|
||||||
|
return previous.withUpdatedAbout(userFull.about).withUpdatedBotInfo(botInfo).withUpdatedCommonGroupCount(userFull.commonChatsCount).withUpdatedIsBlocked(isBlocked).withUpdatedCallsAvailable(callsAvailable).withUpdatedCallsPrivate(callsPrivate).withUpdatedCanPinMessages(canPinMessages).withUpdatedPeerStatusSettings(peerStatusSettings).withUpdatedPinnedMessageId(pinnedMessageId)
|
||||||
}
|
}
|
||||||
transaction.updatePeerCachedData(peerIds: [peerId], update: { peerId, current in
|
})
|
||||||
let previous: CachedUserData
|
}
|
||||||
if let current = current as? CachedUserData {
|
}
|
||||||
previous = current
|
} else if peerId.namespace == Namespaces.Peer.CloudGroup {
|
||||||
} else {
|
return network.request(Api.functions.messages.getFullChat(chatId: peerId.id))
|
||||||
previous = CachedUserData()
|
|> retryRequest
|
||||||
|
|> mapToSignal { result -> Signal<Void, NoError> in
|
||||||
|
return postbox.transaction { transaction -> Void in
|
||||||
|
switch result {
|
||||||
|
case let .chatFull(fullChat, chats, users):
|
||||||
|
switch fullChat {
|
||||||
|
case let .chatFull(chatFull):
|
||||||
|
transaction.updateCurrentPeerNotificationSettings([peerId: TelegramPeerNotificationSettings(apiSettings: chatFull.notifySettings)])
|
||||||
|
case .channelFull:
|
||||||
|
break
|
||||||
}
|
}
|
||||||
switch result {
|
|
||||||
case let .userFull(userFull):
|
|
||||||
let botInfo = userFull.botInfo.flatMap(BotInfo.init(apiBotInfo:))
|
|
||||||
let isBlocked = (userFull.flags & (1 << 0)) != 0
|
|
||||||
let callsAvailable = (userFull.flags & (1 << 4)) != 0
|
|
||||||
let callsPrivate = (userFull.flags & (1 << 5)) != 0
|
|
||||||
let canPinMessages = (userFull.flags & (1 << 7)) != 0
|
|
||||||
let pinnedMessageId = userFull.pinnedMsgId.flatMap({ MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: $0) })
|
|
||||||
|
|
||||||
let peerStatusSettings = PeerStatusSettings(apiSettings: userFull.settings)
|
switch fullChat {
|
||||||
|
case let .chatFull(chatFull):
|
||||||
|
var botInfos: [CachedPeerBotInfo] = []
|
||||||
|
for botInfo in chatFull.botInfo ?? [] {
|
||||||
|
switch botInfo {
|
||||||
|
case let .botInfo(userId, _, _):
|
||||||
|
let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: userId)
|
||||||
|
let parsedBotInfo = BotInfo(apiBotInfo: botInfo)
|
||||||
|
botInfos.append(CachedPeerBotInfo(peerId: peerId, botInfo: parsedBotInfo))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let participants = CachedGroupParticipants(apiParticipants: chatFull.participants)
|
||||||
|
let exportedInvitation = ExportedInvitation(apiExportedInvite: chatFull.exportedInvite)
|
||||||
|
let pinnedMessageId = chatFull.pinnedMsgId.flatMap({ MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: $0) })
|
||||||
|
|
||||||
return previous.withUpdatedAbout(userFull.about).withUpdatedBotInfo(botInfo).withUpdatedCommonGroupCount(userFull.commonChatsCount).withUpdatedIsBlocked(isBlocked).withUpdatedCallsAvailable(callsAvailable).withUpdatedCallsPrivate(callsPrivate).withUpdatedCanPinMessages(canPinMessages).withUpdatedPeerStatusSettings(peerStatusSettings).withUpdatedPinnedMessageId(pinnedMessageId)
|
var peers: [Peer] = []
|
||||||
|
var peerPresences: [PeerId: PeerPresence] = [:]
|
||||||
|
for chat in chats {
|
||||||
|
if let groupOrChannel = parseTelegramGroupOrChannel(chat: chat) {
|
||||||
|
peers.append(groupOrChannel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for user in users {
|
||||||
|
let telegramUser = TelegramUser(user: user)
|
||||||
|
peers.append(telegramUser)
|
||||||
|
if let presence = TelegramUserPresence(apiUser: user) {
|
||||||
|
peerPresences[telegramUser.id] = presence
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updatePeers(transaction: transaction, peers: peers, update: { _, updated -> Peer in
|
||||||
|
return updated
|
||||||
|
})
|
||||||
|
|
||||||
|
updatePeerPresences(transaction: transaction, accountPeerId: accountPeerId, peerPresences: peerPresences)
|
||||||
|
|
||||||
|
var flags = CachedGroupFlags()
|
||||||
|
if (chatFull.flags & 1 << 7) != 0 {
|
||||||
|
flags.insert(.canChangeUsername)
|
||||||
|
}
|
||||||
|
|
||||||
|
transaction.updatePeerCachedData(peerIds: [peerId], update: { _, current in
|
||||||
|
let previous: CachedGroupData
|
||||||
|
if let current = current as? CachedGroupData {
|
||||||
|
previous = current
|
||||||
|
} else {
|
||||||
|
previous = CachedGroupData()
|
||||||
|
}
|
||||||
|
|
||||||
|
return previous.withUpdatedParticipants(participants)
|
||||||
|
.withUpdatedExportedInvitation(exportedInvitation)
|
||||||
|
.withUpdatedBotInfos(botInfos)
|
||||||
|
.withUpdatedPinnedMessageId(pinnedMessageId)
|
||||||
|
.withUpdatedAbout(chatFull.about)
|
||||||
|
.withUpdatedFlags(flags)
|
||||||
|
})
|
||||||
|
case .channelFull:
|
||||||
|
break
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let _ = peer as? TelegramGroup {
|
}
|
||||||
return network.request(Api.functions.messages.getFullChat(chatId: peerId.id))
|
} else if let inputChannel = maybePeer.flatMap(apiInputChannel) {
|
||||||
|> retryRequest
|
return network.request(Api.functions.channels.getFullChannel(channel: inputChannel))
|
||||||
|> mapToSignal { result -> Signal<Void, NoError> in
|
|> map(Optional.init)
|
||||||
return postbox.transaction { transaction -> Void in
|
|> `catch` { error -> Signal<Api.messages.ChatFull?, NoError> in
|
||||||
|
if error.errorDescription == "CHANNEL_PRIVATE" {
|
||||||
|
return .single(nil)
|
||||||
|
}
|
||||||
|
return .complete()
|
||||||
|
}
|
||||||
|
|> mapToSignal { result -> Signal<Void, NoError> in
|
||||||
|
return postbox.transaction { transaction -> Void in
|
||||||
|
if let result = result {
|
||||||
switch result {
|
switch result {
|
||||||
case let .chatFull(fullChat, chats, users):
|
case let .chatFull(fullChat, chats, users):
|
||||||
switch fullChat {
|
switch fullChat {
|
||||||
case let .chatFull(chatFull):
|
case let .channelFull(channelFull):
|
||||||
transaction.updateCurrentPeerNotificationSettings([peerId: TelegramPeerNotificationSettings(apiSettings: chatFull.notifySettings)])
|
transaction.updateCurrentPeerNotificationSettings([peerId: TelegramPeerNotificationSettings(apiSettings: channelFull.notifySettings)])
|
||||||
case .channelFull:
|
case .chatFull:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
switch fullChat {
|
switch fullChat {
|
||||||
case let .chatFull(chatFull):
|
case let .channelFull(flags, _, about, participantsCount, adminsCount, kickedCount, bannedCount, _, _, _, _, _, _, apiExportedInvite, apiBotInfos, migratedFromChatId, migratedFromMaxId, pinnedMsgId, stickerSet, minAvailableMsgId, folderId, linkedChatId, pts):
|
||||||
|
var channelFlags = CachedChannelFlags()
|
||||||
|
if (flags & (1 << 3)) != 0 {
|
||||||
|
channelFlags.insert(.canDisplayParticipants)
|
||||||
|
}
|
||||||
|
if (flags & (1 << 6)) != 0 {
|
||||||
|
channelFlags.insert(.canChangeUsername)
|
||||||
|
}
|
||||||
|
if (flags & (1 << 10)) == 0 {
|
||||||
|
channelFlags.insert(.preHistoryEnabled)
|
||||||
|
}
|
||||||
|
if (flags & (1 << 12)) != 0 {
|
||||||
|
channelFlags.insert(.canViewStats)
|
||||||
|
}
|
||||||
|
if (flags & (1 << 7)) != 0 {
|
||||||
|
channelFlags.insert(.canSetStickerSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
let linkedDiscussionPeerId: PeerId?
|
||||||
|
|
||||||
|
if let linkedChatId = linkedChatId, linkedChatId != 0 {
|
||||||
|
linkedDiscussionPeerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: linkedChatId)
|
||||||
|
} else {
|
||||||
|
linkedDiscussionPeerId = nil
|
||||||
|
}
|
||||||
|
|
||||||
var botInfos: [CachedPeerBotInfo] = []
|
var botInfos: [CachedPeerBotInfo] = []
|
||||||
for botInfo in chatFull.botInfo ?? [] {
|
for botInfo in apiBotInfos {
|
||||||
switch botInfo {
|
switch botInfo {
|
||||||
case let .botInfo(userId, _, _):
|
case let .botInfo(userId, _, _):
|
||||||
let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: userId)
|
let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: userId)
|
||||||
@ -170,9 +285,25 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId: PeerId, network
|
|||||||
botInfos.append(CachedPeerBotInfo(peerId: peerId, botInfo: parsedBotInfo))
|
botInfos.append(CachedPeerBotInfo(peerId: peerId, botInfo: parsedBotInfo))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let participants = CachedGroupParticipants(apiParticipants: chatFull.participants)
|
|
||||||
let exportedInvitation = ExportedInvitation(apiExportedInvite: chatFull.exportedInvite)
|
var pinnedMessageId: MessageId?
|
||||||
let pinnedMessageId = chatFull.pinnedMsgId.flatMap({ MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: $0) })
|
if let pinnedMsgId = pinnedMsgId {
|
||||||
|
pinnedMessageId = MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: pinnedMsgId)
|
||||||
|
}
|
||||||
|
|
||||||
|
var minAvailableMessageId: MessageId?
|
||||||
|
if let minAvailableMsgId = minAvailableMsgId {
|
||||||
|
minAvailableMessageId = MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: minAvailableMsgId)
|
||||||
|
|
||||||
|
if let pinnedMsgId = pinnedMsgId, pinnedMsgId < minAvailableMsgId {
|
||||||
|
pinnedMessageId = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var migrationReference: ChannelMigrationReference?
|
||||||
|
if let migratedFromChatId = migratedFromChatId, let migratedFromMaxId = migratedFromMaxId {
|
||||||
|
migrationReference = ChannelMigrationReference(maxMessageId: MessageId(peerId: PeerId(namespace: Namespaces.Peer.CloudGroup, id: migratedFromChatId), namespace: Namespaces.Message.Cloud, id: migratedFromMaxId))
|
||||||
|
}
|
||||||
|
|
||||||
var peers: [Peer] = []
|
var peers: [Peer] = []
|
||||||
var peerPresences: [PeerId: PeerPresence] = [:]
|
var peerPresences: [PeerId: PeerPresence] = [:]
|
||||||
@ -195,187 +326,63 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId: PeerId, network
|
|||||||
|
|
||||||
updatePeerPresences(transaction: transaction, accountPeerId: accountPeerId, peerPresences: peerPresences)
|
updatePeerPresences(transaction: transaction, accountPeerId: accountPeerId, peerPresences: peerPresences)
|
||||||
|
|
||||||
var flags = CachedGroupFlags()
|
let stickerPack: StickerPackCollectionInfo? = stickerSet.flatMap { apiSet -> StickerPackCollectionInfo in
|
||||||
if (chatFull.flags & 1 << 7) != 0 {
|
let namespace: ItemCollectionId.Namespace
|
||||||
flags.insert(.canChangeUsername)
|
switch apiSet {
|
||||||
}
|
case let .stickerSet(flags, _, _, _, _, _, _, _, _, _):
|
||||||
|
if (flags & (1 << 3)) != 0 {
|
||||||
transaction.updatePeerCachedData(peerIds: [peerId], update: { _, current in
|
namespace = Namespaces.ItemCollection.CloudMaskPacks
|
||||||
let previous: CachedGroupData
|
} else {
|
||||||
if let current = current as? CachedGroupData {
|
namespace = Namespaces.ItemCollection.CloudStickerPacks
|
||||||
previous = current
|
}
|
||||||
} else {
|
|
||||||
previous = CachedGroupData()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return previous.withUpdatedParticipants(participants)
|
return StickerPackCollectionInfo(apiSet: apiSet, namespace: namespace)
|
||||||
.withUpdatedExportedInvitation(exportedInvitation)
|
}
|
||||||
|
|
||||||
|
var minAvailableMessageIdUpdated = false
|
||||||
|
transaction.updatePeerCachedData(peerIds: [peerId], update: { _, current in
|
||||||
|
var previous: CachedChannelData
|
||||||
|
if let current = current as? CachedChannelData {
|
||||||
|
previous = current
|
||||||
|
} else {
|
||||||
|
previous = CachedChannelData()
|
||||||
|
}
|
||||||
|
|
||||||
|
previous = previous.withUpdatedIsNotAccessible(false)
|
||||||
|
|
||||||
|
minAvailableMessageIdUpdated = previous.minAvailableMessageId != minAvailableMessageId
|
||||||
|
|
||||||
|
return previous.withUpdatedFlags(channelFlags)
|
||||||
|
.withUpdatedAbout(about)
|
||||||
|
.withUpdatedParticipantsSummary(CachedChannelParticipantsSummary(memberCount: participantsCount, adminCount: adminsCount, bannedCount: bannedCount, kickedCount: kickedCount))
|
||||||
|
.withUpdatedExportedInvitation(ExportedInvitation(apiExportedInvite: apiExportedInvite))
|
||||||
.withUpdatedBotInfos(botInfos)
|
.withUpdatedBotInfos(botInfos)
|
||||||
.withUpdatedPinnedMessageId(pinnedMessageId)
|
.withUpdatedPinnedMessageId(pinnedMessageId)
|
||||||
.withUpdatedAbout(chatFull.about)
|
.withUpdatedStickerPack(stickerPack)
|
||||||
.withUpdatedFlags(flags)
|
.withUpdatedMinAvailableMessageId(minAvailableMessageId)
|
||||||
|
.withUpdatedMigrationReference(migrationReference)
|
||||||
|
.withUpdatedLinkedDiscussionPeerId(linkedDiscussionPeerId)
|
||||||
})
|
})
|
||||||
case .channelFull:
|
|
||||||
|
if let minAvailableMessageId = minAvailableMessageId, minAvailableMessageIdUpdated {
|
||||||
|
transaction.deleteMessagesInRange(peerId: peerId, namespace: minAvailableMessageId.namespace, minId: 1, maxId: minAvailableMessageId.id)
|
||||||
|
}
|
||||||
|
case .chatFull:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
transaction.updatePeerCachedData(peerIds: [peerId], update: { _, _ in
|
||||||
|
var updated = CachedChannelData()
|
||||||
|
updated = updated.withUpdatedIsNotAccessible(true)
|
||||||
|
return updated
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let inputChannel = apiInputChannel(peer) {
|
|
||||||
return network.request(Api.functions.channels.getFullChannel(channel: inputChannel))
|
|
||||||
|> map(Optional.init)
|
|
||||||
|> `catch` { error -> Signal<Api.messages.ChatFull?, NoError> in
|
|
||||||
if error.errorDescription == "CHANNEL_PRIVATE" {
|
|
||||||
return .single(nil)
|
|
||||||
}
|
|
||||||
return .complete()
|
|
||||||
}
|
|
||||||
|> mapToSignal { result -> Signal<Void, NoError> in
|
|
||||||
return postbox.transaction { transaction -> Void in
|
|
||||||
if let result = result {
|
|
||||||
switch result {
|
|
||||||
case let .chatFull(fullChat, chats, users):
|
|
||||||
switch fullChat {
|
|
||||||
case let .channelFull(channelFull):
|
|
||||||
transaction.updateCurrentPeerNotificationSettings([peerId: TelegramPeerNotificationSettings(apiSettings: channelFull.notifySettings)])
|
|
||||||
case .chatFull:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
switch fullChat {
|
|
||||||
case let .channelFull(flags, _, about, participantsCount, adminsCount, kickedCount, bannedCount, _, _, _, _, _, _, apiExportedInvite, apiBotInfos, migratedFromChatId, migratedFromMaxId, pinnedMsgId, stickerSet, minAvailableMsgId, folderId, linkedChatId, pts):
|
|
||||||
var channelFlags = CachedChannelFlags()
|
|
||||||
if (flags & (1 << 3)) != 0 {
|
|
||||||
channelFlags.insert(.canDisplayParticipants)
|
|
||||||
}
|
|
||||||
if (flags & (1 << 6)) != 0 {
|
|
||||||
channelFlags.insert(.canChangeUsername)
|
|
||||||
}
|
|
||||||
if (flags & (1 << 10)) == 0 {
|
|
||||||
channelFlags.insert(.preHistoryEnabled)
|
|
||||||
}
|
|
||||||
if (flags & (1 << 12)) != 0 {
|
|
||||||
channelFlags.insert(.canViewStats)
|
|
||||||
}
|
|
||||||
if (flags & (1 << 7)) != 0 {
|
|
||||||
channelFlags.insert(.canSetStickerSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
let linkedDiscussionPeerId: PeerId?
|
|
||||||
|
|
||||||
if let linkedChatId = linkedChatId, linkedChatId != 0 {
|
|
||||||
linkedDiscussionPeerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: linkedChatId)
|
|
||||||
} else {
|
|
||||||
linkedDiscussionPeerId = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var botInfos: [CachedPeerBotInfo] = []
|
|
||||||
for botInfo in apiBotInfos {
|
|
||||||
switch botInfo {
|
|
||||||
case let .botInfo(userId, _, _):
|
|
||||||
let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: userId)
|
|
||||||
let parsedBotInfo = BotInfo(apiBotInfo: botInfo)
|
|
||||||
botInfos.append(CachedPeerBotInfo(peerId: peerId, botInfo: parsedBotInfo))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var pinnedMessageId: MessageId?
|
|
||||||
if let pinnedMsgId = pinnedMsgId {
|
|
||||||
pinnedMessageId = MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: pinnedMsgId)
|
|
||||||
}
|
|
||||||
|
|
||||||
var minAvailableMessageId: MessageId?
|
|
||||||
if let minAvailableMsgId = minAvailableMsgId {
|
|
||||||
minAvailableMessageId = MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: minAvailableMsgId)
|
|
||||||
|
|
||||||
if let pinnedMsgId = pinnedMsgId, pinnedMsgId < minAvailableMsgId {
|
|
||||||
pinnedMessageId = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var migrationReference: ChannelMigrationReference?
|
|
||||||
if let migratedFromChatId = migratedFromChatId, let migratedFromMaxId = migratedFromMaxId {
|
|
||||||
migrationReference = ChannelMigrationReference(maxMessageId: MessageId(peerId: PeerId(namespace: Namespaces.Peer.CloudGroup, id: migratedFromChatId), namespace: Namespaces.Message.Cloud, id: migratedFromMaxId))
|
|
||||||
}
|
|
||||||
|
|
||||||
var peers: [Peer] = []
|
|
||||||
var peerPresences: [PeerId: PeerPresence] = [:]
|
|
||||||
for chat in chats {
|
|
||||||
if let groupOrChannel = parseTelegramGroupOrChannel(chat: chat) {
|
|
||||||
peers.append(groupOrChannel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for user in users {
|
|
||||||
let telegramUser = TelegramUser(user: user)
|
|
||||||
peers.append(telegramUser)
|
|
||||||
if let presence = TelegramUserPresence(apiUser: user) {
|
|
||||||
peerPresences[telegramUser.id] = presence
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePeers(transaction: transaction, peers: peers, update: { _, updated -> Peer in
|
|
||||||
return updated
|
|
||||||
})
|
|
||||||
|
|
||||||
updatePeerPresences(transaction: transaction, accountPeerId: accountPeerId, peerPresences: peerPresences)
|
|
||||||
|
|
||||||
let stickerPack: StickerPackCollectionInfo? = stickerSet.flatMap { apiSet -> StickerPackCollectionInfo in
|
|
||||||
let namespace: ItemCollectionId.Namespace
|
|
||||||
switch apiSet {
|
|
||||||
case let .stickerSet(flags, _, _, _, _, _, _, _, _, _):
|
|
||||||
if (flags & (1 << 3)) != 0 {
|
|
||||||
namespace = Namespaces.ItemCollection.CloudMaskPacks
|
|
||||||
} else {
|
|
||||||
namespace = Namespaces.ItemCollection.CloudStickerPacks
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return StickerPackCollectionInfo(apiSet: apiSet, namespace: namespace)
|
|
||||||
}
|
|
||||||
|
|
||||||
var minAvailableMessageIdUpdated = false
|
|
||||||
transaction.updatePeerCachedData(peerIds: [peerId], update: { _, current in
|
|
||||||
var previous: CachedChannelData
|
|
||||||
if let current = current as? CachedChannelData {
|
|
||||||
previous = current
|
|
||||||
} else {
|
|
||||||
previous = CachedChannelData()
|
|
||||||
}
|
|
||||||
|
|
||||||
previous = previous.withUpdatedIsNotAccessible(false)
|
|
||||||
|
|
||||||
minAvailableMessageIdUpdated = previous.minAvailableMessageId != minAvailableMessageId
|
|
||||||
|
|
||||||
return previous.withUpdatedFlags(channelFlags)
|
|
||||||
.withUpdatedAbout(about)
|
|
||||||
.withUpdatedParticipantsSummary(CachedChannelParticipantsSummary(memberCount: participantsCount, adminCount: adminsCount, bannedCount: bannedCount, kickedCount: kickedCount))
|
|
||||||
.withUpdatedExportedInvitation(ExportedInvitation(apiExportedInvite: apiExportedInvite))
|
|
||||||
.withUpdatedBotInfos(botInfos)
|
|
||||||
.withUpdatedPinnedMessageId(pinnedMessageId)
|
|
||||||
.withUpdatedStickerPack(stickerPack)
|
|
||||||
.withUpdatedMinAvailableMessageId(minAvailableMessageId)
|
|
||||||
.withUpdatedMigrationReference(migrationReference)
|
|
||||||
.withUpdatedLinkedDiscussionPeerId(linkedDiscussionPeerId)
|
|
||||||
})
|
|
||||||
|
|
||||||
if let minAvailableMessageId = minAvailableMessageId, minAvailableMessageIdUpdated {
|
|
||||||
transaction.deleteMessagesInRange(peerId: peerId, namespace: minAvailableMessageId.namespace, minId: 1, maxId: minAvailableMessageId.id)
|
|
||||||
}
|
|
||||||
case .chatFull:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
transaction.updatePeerCachedData(peerIds: [peerId], update: { _, _ in
|
|
||||||
var updated = CachedChannelData()
|
|
||||||
updated = updated.withUpdatedIsNotAccessible(true)
|
|
||||||
return updated
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return .complete()
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return .complete()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user