Update Ghostgram features

This commit is contained in:
ichmagmaus 812
2026-03-07 18:15:32 +01:00
parent 1a3303b059
commit 24a7ec39d9
902 changed files with 148302 additions and 62355 deletions
@@ -50,7 +50,8 @@ func _internal_searchAdPeers(account: Account, query: String) -> Signal<[AdPeer]
}
return account.postbox.transaction { transaction -> [AdPeer] in
switch result {
case let .sponsoredPeers(peers, chats, users):
case let .sponsoredPeers(sponsoredPeersData):
let (peers, chats, users) = (sponsoredPeersData.peers, sponsoredPeersData.chats, sponsoredPeersData.users)
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: parsedPeers)
@@ -58,7 +59,8 @@ func _internal_searchAdPeers(account: Account, query: String) -> Signal<[AdPeer]
for chat in chats {
if let groupOrChannel = parseTelegramGroupOrChannel(chat: chat) {
switch chat {
case let .channel(_, _, _, _, _, _, _, _, _, _, _, _, participantsCount, _, _, _, _, _, _, _, _, _, _):
case let .channel(channelData):
let participantsCount = channelData.participantsCount
if let participantsCount = participantsCount {
subscribers[groupOrChannel.id] = participantsCount
}
@@ -71,7 +73,8 @@ func _internal_searchAdPeers(account: Account, query: String) -> Signal<[AdPeer]
var result: [AdPeer] = []
for peer in peers {
switch peer {
case let .sponsoredPeer(_, randomId, apiPeer, sponsorInfo, additionalInfo):
case let .sponsoredPeer(sponsoredPeerData):
let (randomId, apiPeer, sponsorInfo, additionalInfo) = (sponsoredPeerData.randomId, sponsoredPeerData.peer, sponsoredPeerData.sponsorInfo, sponsoredPeerData.additionalInfo)
guard let peer = parsedPeers.get(apiPeer.peerId) else {
continue
}
@@ -71,7 +71,8 @@ func _internal_addGroupMember(account: Account, peerId: PeerId, memberId: PeerId
let updatesValue: Api.Updates
let missingInviteesValue: [Api.MissingInvitee]
switch result {
case let .invitedUsers(updates, missingInvitees):
case let .invitedUsers(invitedUsersData):
let (updates, missingInvitees) = (invitedUsersData.updates, invitedUsersData.missingInvitees)
updatesValue = updates
missingInviteesValue = missingInvitees
}
@@ -102,7 +103,8 @@ func _internal_addGroupMember(account: Account, peerId: PeerId, memberId: PeerId
let result = TelegramInvitePeersResult(forbiddenPeers: missingInviteesValue.compactMap { invitee -> TelegramForbiddenInvitePeer? in
switch invitee {
case let .missingInvitee(flags, userId):
case let .missingInvitee(missingInviteeData):
let (flags, userId) = (missingInviteeData.flags, missingInviteeData.userId)
guard let peer = transaction.getPeer(PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))) else {
return nil
}
@@ -188,17 +190,19 @@ func _internal_addChannelMember(account: Account, peerId: PeerId, memberId: Peer
|> mapToSignal { result -> Signal<(ChannelParticipant?, RenderedChannelParticipant), AddChannelMemberError> in
let updatesValue: Api.Updates
switch result {
case let .invitedUsers(updates, missingInvitees):
if case let .missingInvitee(flags, _) = missingInvitees.first {
case let .invitedUsers(invitedUsersData):
let (updates, missingInvitees) = (invitedUsersData.updates, invitedUsersData.missingInvitees)
if case let .missingInvitee(missingInviteeData) = missingInvitees.first {
let flags = missingInviteeData.flags
let _ = _internal_updateIsPremiumRequiredToContact(account: account, peerIds: [memberPeer.id]).startStandalone()
return .fail(.restricted(TelegramForbiddenInvitePeer(
peer: EnginePeer(memberPeer),
canInviteWithPremium: (flags & (1 << 0)) != 0,
premiumRequiredToContact: (flags & (1 << 1)) != 0
)))
}
updatesValue = updates
}
@@ -299,7 +303,8 @@ func _internal_addChannelMembers(account: Account, peerId: PeerId, memberIds: [P
let updatesValue: Api.Updates
let missingInviteesValue: [Api.MissingInvitee]
switch result {
case let .invitedUsers(updates, missingInvitees):
case let .invitedUsers(invitedUsersData):
let (updates, missingInvitees) = (invitedUsersData.updates, invitedUsersData.missingInvitees)
updatesValue = updates
missingInviteesValue = missingInvitees
}
@@ -310,7 +315,8 @@ func _internal_addChannelMembers(account: Account, peerId: PeerId, memberIds: [P
return account.postbox.transaction { transaction -> TelegramInvitePeersResult in
let result = TelegramInvitePeersResult(forbiddenPeers: missingInviteesValue.compactMap { invitee -> TelegramForbiddenInvitePeer? in
switch invitee {
case let .missingInvitee(flags, userId):
case let .missingInvitee(missingInviteeData):
let (flags, userId) = (missingInviteeData.flags, missingInviteeData.userId)
guard let peer = transaction.getPeer(PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))) else {
return nil
}
@@ -177,7 +177,7 @@ func _internal_updateAddressName(account: Account, domain: AddressNameDomain, na
return .fail(.generic)
case let .theme(theme):
let flags: Int32 = 1 << 0
return account.network.request(Api.functions.account.updateTheme(flags: flags, format: telegramThemeFormat, theme: .inputTheme(id: theme.id, accessHash: theme.accessHash), slug: nil, title: nil, document: nil, settings: nil))
return account.network.request(Api.functions.account.updateTheme(flags: flags, format: telegramThemeFormat, theme: .inputTheme(.init(id: theme.id, accessHash: theme.accessHash)), slug: nil, title: nil, document: nil, settings: nil))
|> mapError { _ -> UpdateAddressNameError in
return .generic
}
@@ -558,14 +558,17 @@ func _internal_adminedPublicChannels(account: Account, scope: AdminedPublicChann
var subscriberCounts: [PeerId: Int] = [:]
let parsedPeers: AccumulatedPeers
switch result {
case let .chats(apiChats):
case let .chats(chatsData):
let apiChats = chatsData.chats
chats = apiChats
for chat in apiChats {
if case let .channel(_, _, _, _, _, _, _, _, _, _, _, _, participantsCount, _, _, _, _, _, _, _, _, _, _) = chat {
if case let .channel(channelData) = chat {
let participantsCount = channelData.participantsCount
subscriberCounts[chat.peerId] = participantsCount.flatMap(Int.init)
}
}
case let .chatsSlice(_, apiChats):
case let .chatsSlice(chatsSliceData):
let apiChats = chatsSliceData.chats
chats = apiChats
}
parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: [])
@@ -625,9 +628,11 @@ func _internal_channelsForStories(account: Account) -> Signal<[Peer], NoError> {
let chats: [Api.Chat]
let parsedPeers: AccumulatedPeers
switch result {
case let .chats(apiChats):
case let .chats(chatsData):
let apiChats = chatsData.chats
chats = apiChats
case let .chatsSlice(_, apiChats):
case let .chatsSlice(chatsSliceData):
let apiChats = chatsSliceData.chats
chats = apiChats
}
parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: [])
@@ -637,7 +642,7 @@ func _internal_channelsForStories(account: Account) -> Signal<[Peer], NoError> {
if let peer = transaction.getPeer(chat.peerId) {
peers.append(peer)
if case let .channel(_, _, _, _, _, _, _, _, _, _, _, _, participantsCount, _, _, _, _, _, _, _, _, _, _) = chat, let participantsCount = participantsCount {
if case let .channel(channelData) = chat, let participantsCount = channelData.participantsCount {
transaction.updatePeerCachedData(peerIds: Set([peer.id]), update: { _, current in
var current = current as? CachedChannelData ?? CachedChannelData()
var participantsSummary = current.participantsSummary
@@ -687,9 +692,11 @@ func _internal_channelsForPublicReaction(account: Account, useLocalCache: Bool)
let chats: [Api.Chat]
let parsedPeers: AccumulatedPeers
switch result {
case let .chats(apiChats):
case let .chats(chatsData):
let apiChats = chatsData.chats
chats = apiChats
case let .chatsSlice(_, apiChats):
case let .chatsSlice(chatsSliceData):
let apiChats = chatsSliceData.chats
chats = apiChats
}
parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: [])
@@ -699,7 +706,7 @@ func _internal_channelsForPublicReaction(account: Account, useLocalCache: Bool)
if let peer = transaction.getPeer(chat.peerId) {
peers.append(peer)
if case let .channel(_, _, _, _, _, _, _, _, _, _, _, _, participantsCount, _, _, _, _, _, _, _, _, _, _) = chat, let participantsCount = participantsCount {
if case let .channel(channelData) = chat, let participantsCount = channelData.participantsCount {
transaction.updatePeerCachedData(peerIds: Set([peer.id]), update: { _, current in
var current = current as? CachedChannelData ?? CachedChannelData()
var participantsSummary = current.participantsSummary
@@ -59,7 +59,8 @@ public final class TelegramBirthday: Codable, Equatable {
extension TelegramBirthday {
convenience init(apiBirthday: Api.Birthday) {
switch apiBirthday {
case let .birthday(_, day, month, year):
case let .birthday(birthdayData):
let (_, day, month, year) = (birthdayData.flags, birthdayData.day, birthdayData.month, birthdayData.year)
self.init(
day: day,
month: month,
@@ -73,7 +74,7 @@ extension TelegramBirthday {
if let _ = self.year {
flags |= (1 << 0)
}
return .birthday(flags: flags, day: self.day, month: self.month, year: self.year)
return .birthday(Api.Birthday.Cons_birthday(flags: flags, day: self.day, month: self.month, year: self.year))
}
}
@@ -117,12 +118,14 @@ func managedContactBirthdays(stateManager: AccountStateManager) -> Signal<Never,
return .complete()
}
return stateManager.postbox.transaction { transaction -> Void in
if case let .contactBirthdays(contactBirthdays, users) = result {
if case let .contactBirthdays(contactBirthdaysData) = result {
let (contactBirthdays, users) = (contactBirthdaysData.contacts, contactBirthdaysData.users)
updatePeers(transaction: transaction, accountPeerId: stateManager.accountPeerId, peers: AccumulatedPeers(users: users))
var birthdays: [EnginePeer.Id: TelegramBirthday] = [:]
for contactBirthday in contactBirthdays {
if case let .contactBirthday(contactId, birthday) = contactBirthday {
if case let .contactBirthday(contactBirthdayData) = contactBirthday {
let (contactId, birthday) = (contactBirthdayData.contactId, contactBirthdayData.birthday)
let peerId = EnginePeer.Id(namespace: Namespaces.Peer.CloudUser, id: EnginePeer.Id.Id._internalFromInt64Value(contactId))
if peerId == stateManager.accountPeerId {
continue
@@ -65,12 +65,12 @@ func _internal_requestRecommendedBots(account: Account, peerId: EnginePeer.Id, f
let parsedPeers: AccumulatedPeers
var count: Int32
switch result {
case let .users(apiUsers):
users = apiUsers
count = Int32(apiUsers.count)
case let .usersSlice(apiCount, apiUsers):
users = apiUsers
count = apiCount
case let .users(usersData):
users = usersData.users
count = Int32(usersData.users.count)
case let .usersSlice(usersSliceData):
users = usersSliceData.users
count = usersSliceData.count
}
parsedPeers = AccumulatedPeers(users: users)
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: parsedPeers)
@@ -160,7 +160,7 @@ func channelAdminLogEvents(accountPeerId: PeerId, postbox: Postbox, network: Net
var eventsFilter: Api.ChannelAdminLogEventsFilter? = nil
if let filter = filter {
flags += Int32(1 << 0)
eventsFilter = Api.ChannelAdminLogEventsFilter.channelAdminLogEventsFilter(flags: Int32(filter.rawValue))
eventsFilter = Api.ChannelAdminLogEventsFilter.channelAdminLogEventsFilter(Api.ChannelAdminLogEventsFilter.Cons_channelAdminLogEventsFilter(flags: Int32(filter.rawValue)))
}
if let _ = inputAdmins {
flags += Int32(1 << 1)
@@ -168,7 +168,8 @@ func channelAdminLogEvents(accountPeerId: PeerId, postbox: Postbox, network: Net
return network.request(Api.functions.channels.getAdminLog(flags: flags, channel: inputChannel, q: query ?? "", eventsFilter: eventsFilter, admins: inputAdmins, maxId: maxId, minId: minId, limit: limit))
|> mapToSignal { result in
switch result {
case let .adminLogResults(apiEvents, apiChats, apiUsers):
case let .adminLogResults(adminLogResultsData):
let (apiEvents, apiChats, apiUsers) = (adminLogResultsData.events, adminLogResultsData.chats, adminLogResultsData.users)
return postbox.transaction { transaction -> AdminLogEventsResult in
var peers: [PeerId: Peer] = [:]
for apiChat in apiChats {
@@ -194,9 +195,11 @@ func channelAdminLogEvents(accountPeerId: PeerId, postbox: Postbox, network: Net
var foundDeletedReplyMessage = false
for event in apiEvents {
switch event {
case let .channelAdminLogEvent(_, _, _, apiAction):
case let .channelAdminLogEvent(channelAdminLogEventData):
let apiAction = channelAdminLogEventData.action
switch apiAction {
case let .channelAdminLogEventActionDeleteMessage(apiMessage):
case let .channelAdminLogEventActionDeleteMessage(channelAdminLogEventActionDeleteMessageData):
let apiMessage = channelAdminLogEventActionDeleteMessageData.message
if let messageId = apiMessage.id(namespace: Namespaces.Message.Cloud), messageId == replyAttribute.messageId, let message = StoreMessage(apiMessage: apiMessage, accountPeerId: accountPeerId, peerIsForum: peer.isForum), let replyMessage = locallyRenderedMessage(message: message, peers: peers, associatedThreadInfo: associatedThreadInfo) {
associatedMessages[replyMessage.id] = replyMessage
foundDeletedReplyMessage = true
@@ -215,163 +218,191 @@ func channelAdminLogEvents(accountPeerId: PeerId, postbox: Postbox, network: Net
for event in apiEvents {
switch event {
case let .channelAdminLogEvent(id, date, userId, apiAction):
case let .channelAdminLogEvent(channelAdminLogEventData):
let (id, date, userId, apiAction) = (channelAdminLogEventData.id, channelAdminLogEventData.date, channelAdminLogEventData.userId, channelAdminLogEventData.action)
var action: AdminLogEventAction?
switch apiAction {
case let .channelAdminLogEventActionChangeTitle(prev, new):
case let .channelAdminLogEventActionChangeTitle(channelAdminLogEventActionChangeTitleData):
let (prev, new) = (channelAdminLogEventActionChangeTitleData.prevValue, channelAdminLogEventActionChangeTitleData.newValue)
action = .changeTitle(prev: prev, new: new)
case let .channelAdminLogEventActionChangeAbout(prev, new):
case let .channelAdminLogEventActionChangeAbout(channelAdminLogEventActionChangeAboutData):
let (prev, new) = (channelAdminLogEventActionChangeAboutData.prevValue, channelAdminLogEventActionChangeAboutData.newValue)
action = .changeAbout(prev: prev, new: new)
case let .channelAdminLogEventActionChangeUsername(prev, new):
case let .channelAdminLogEventActionChangeUsername(channelAdminLogEventActionChangeUsernameData):
let (prev, new) = (channelAdminLogEventActionChangeUsernameData.prevValue, channelAdminLogEventActionChangeUsernameData.newValue)
action = .changeUsername(prev: prev, new: new)
case let .channelAdminLogEventActionChangePhoto(prev, new):
case let .channelAdminLogEventActionChangePhoto(channelAdminLogEventActionChangePhotoData):
let (prev, new) = (channelAdminLogEventActionChangePhotoData.prevPhoto, channelAdminLogEventActionChangePhotoData.newPhoto)
let previousImage = telegramMediaImageFromApiPhoto(prev)
let newImage = telegramMediaImageFromApiPhoto(new)
action = .changePhoto(prev: (previousImage?.representations ?? [], previousImage?.videoRepresentations ?? []) , new: (newImage?.representations ?? [], newImage?.videoRepresentations ?? []))
case let .channelAdminLogEventActionToggleInvites(new):
action = .toggleInvites(boolFromApiValue(new))
case let .channelAdminLogEventActionToggleSignatures(new):
action = .toggleSignatures(boolFromApiValue(new))
case let .channelAdminLogEventActionUpdatePinned(new):
switch new {
case let .channelAdminLogEventActionToggleInvites(channelAdminLogEventActionToggleInvitesData):
action = .toggleInvites(boolFromApiValue(channelAdminLogEventActionToggleInvitesData.newValue))
case let .channelAdminLogEventActionToggleSignatures(channelAdminLogEventActionToggleSignaturesData):
action = .toggleSignatures(boolFromApiValue(channelAdminLogEventActionToggleSignaturesData.newValue))
case let .channelAdminLogEventActionUpdatePinned(channelAdminLogEventActionUpdatePinnedData):
switch channelAdminLogEventActionUpdatePinnedData.message {
case .messageEmpty:
action = .updatePinned(nil)
default:
if let message = StoreMessage(apiMessage: new, accountPeerId: accountPeerId, peerIsForum: peer.isForum), let rendered = renderedMessage(message: message) {
if let message = StoreMessage(apiMessage: channelAdminLogEventActionUpdatePinnedData.message, accountPeerId: accountPeerId, peerIsForum: peer.isForum), let rendered = renderedMessage(message: message) {
action = .updatePinned(rendered)
}
}
case let .channelAdminLogEventActionEditMessage(prev, new):
case let .channelAdminLogEventActionEditMessage(channelAdminLogEventActionEditMessageData):
let (prev, new) = (channelAdminLogEventActionEditMessageData.prevMessage, channelAdminLogEventActionEditMessageData.newMessage)
if let prev = StoreMessage(apiMessage: prev, accountPeerId: accountPeerId, peerIsForum: peer.isForum), let prevRendered = renderedMessage(message: prev), let new = StoreMessage(apiMessage: new, accountPeerId: accountPeerId, peerIsForum: peer.isForum), let newRendered = renderedMessage(message: new) {
action = .editMessage(prev: prevRendered, new: newRendered)
}
case let .channelAdminLogEventActionDeleteMessage(message):
if let message = StoreMessage(apiMessage: message, accountPeerId: accountPeerId, peerIsForum: peer.isForum), let rendered = renderedMessage(message: message) {
case let .channelAdminLogEventActionDeleteMessage(channelAdminLogEventActionDeleteMessageData):
if let message = StoreMessage(apiMessage: channelAdminLogEventActionDeleteMessageData.message, accountPeerId: accountPeerId, peerIsForum: peer.isForum), let rendered = renderedMessage(message: message) {
action = .deleteMessage(rendered)
}
case .channelAdminLogEventActionParticipantJoin:
action = .participantJoin
case .channelAdminLogEventActionParticipantLeave:
action = .participantLeave
case let .channelAdminLogEventActionParticipantInvite(participant):
let participant = ChannelParticipant(apiParticipant: participant)
case let .channelAdminLogEventActionParticipantInvite(channelAdminLogEventActionParticipantInviteData):
let participant = ChannelParticipant(apiParticipant: channelAdminLogEventActionParticipantInviteData.participant)
if let peer = peers[participant.peerId] {
action = .participantInvite(RenderedChannelParticipant(participant: participant, peer: peer))
}
case let .channelAdminLogEventActionParticipantToggleBan(prev, new):
case let .channelAdminLogEventActionParticipantToggleBan(channelAdminLogEventActionParticipantToggleBanData):
let (prev, new) = (channelAdminLogEventActionParticipantToggleBanData.prevParticipant, channelAdminLogEventActionParticipantToggleBanData.newParticipant)
let prevParticipant = ChannelParticipant(apiParticipant: prev)
let newParticipant = ChannelParticipant(apiParticipant: new)
if let prevPeer = peers[prevParticipant.peerId], let newPeer = peers[newParticipant.peerId] {
action = .participantToggleBan(prev: RenderedChannelParticipant(participant: prevParticipant, peer: prevPeer), new: RenderedChannelParticipant(participant: newParticipant, peer: newPeer))
}
case let .channelAdminLogEventActionParticipantToggleAdmin(prev, new):
case let .channelAdminLogEventActionParticipantToggleAdmin(channelAdminLogEventActionParticipantToggleAdminData):
let (prev, new) = (channelAdminLogEventActionParticipantToggleAdminData.prevParticipant, channelAdminLogEventActionParticipantToggleAdminData.newParticipant)
let prevParticipant = ChannelParticipant(apiParticipant: prev)
let newParticipant = ChannelParticipant(apiParticipant: new)
if let prevPeer = peers[prevParticipant.peerId], let newPeer = peers[newParticipant.peerId] {
action = .participantToggleAdmin(prev: RenderedChannelParticipant(participant: prevParticipant, peer: prevPeer), new: RenderedChannelParticipant(participant: newParticipant, peer: newPeer))
}
case let .channelAdminLogEventActionChangeStickerSet(prevStickerset, newStickerset):
case let .channelAdminLogEventActionChangeStickerSet(channelAdminLogEventActionChangeStickerSetData):
let (prevStickerset, newStickerset) = (channelAdminLogEventActionChangeStickerSetData.prevStickerset, channelAdminLogEventActionChangeStickerSetData.newStickerset)
action = .changeStickerPack(prev: StickerPackReference(apiInputSet: prevStickerset), new: StickerPackReference(apiInputSet: newStickerset))
case let .channelAdminLogEventActionTogglePreHistoryHidden(value):
action = .togglePreHistoryHidden(value == .boolTrue)
case let .channelAdminLogEventActionDefaultBannedRights(prevBannedRights, newBannedRights):
case let .channelAdminLogEventActionTogglePreHistoryHidden(channelAdminLogEventActionTogglePreHistoryHiddenData):
action = .togglePreHistoryHidden(channelAdminLogEventActionTogglePreHistoryHiddenData.newValue == .boolTrue)
case let .channelAdminLogEventActionDefaultBannedRights(channelAdminLogEventActionDefaultBannedRightsData):
let (prevBannedRights, newBannedRights) = (channelAdminLogEventActionDefaultBannedRightsData.prevBannedRights, channelAdminLogEventActionDefaultBannedRightsData.newBannedRights)
action = .updateDefaultBannedRights(prev: TelegramChatBannedRights(apiBannedRights: prevBannedRights), new: TelegramChatBannedRights(apiBannedRights: newBannedRights))
case let .channelAdminLogEventActionStopPoll(message):
if let message = StoreMessage(apiMessage: message, accountPeerId: accountPeerId, peerIsForum: peer.isForum), let rendered = renderedMessage(message: message) {
case let .channelAdminLogEventActionStopPoll(channelAdminLogEventActionStopPollData):
if let message = StoreMessage(apiMessage: channelAdminLogEventActionStopPollData.message, accountPeerId: accountPeerId, peerIsForum: peer.isForum), let rendered = renderedMessage(message: message) {
action = .pollStopped(rendered)
}
case let .channelAdminLogEventActionChangeLinkedChat(prevValue, newValue):
case let .channelAdminLogEventActionChangeLinkedChat(channelAdminLogEventActionChangeLinkedChatData):
let (prevValue, newValue) = (channelAdminLogEventActionChangeLinkedChatData.prevValue, channelAdminLogEventActionChangeLinkedChatData.newValue)
action = .linkedPeerUpdated(previous: prevValue == 0 ? nil : peers[PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(prevValue))], updated: newValue == 0 ? nil : peers[PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(newValue))])
case let .channelAdminLogEventActionChangeLocation(prevValue, newValue):
case let .channelAdminLogEventActionChangeLocation(channelAdminLogEventActionChangeLocationData):
let (prevValue, newValue) = (channelAdminLogEventActionChangeLocationData.prevValue, channelAdminLogEventActionChangeLocationData.newValue)
action = .changeGeoLocation(previous: PeerGeoLocation(apiLocation: prevValue), updated: PeerGeoLocation(apiLocation: newValue))
case let .channelAdminLogEventActionToggleSlowMode(prevValue, newValue):
case let .channelAdminLogEventActionToggleSlowMode(channelAdminLogEventActionToggleSlowModeData):
let (prevValue, newValue) = (channelAdminLogEventActionToggleSlowModeData.prevValue, channelAdminLogEventActionToggleSlowModeData.newValue)
action = .updateSlowmode(previous: prevValue == 0 ? nil : prevValue, updated: newValue == 0 ? nil : newValue)
case .channelAdminLogEventActionStartGroupCall:
action = .startGroupCall
case .channelAdminLogEventActionDiscardGroupCall:
action = .endGroupCall
case let .channelAdminLogEventActionParticipantMute(participant):
let parsedParticipant = GroupCallParticipantsContext.Update.StateUpdate.ParticipantUpdate(participant)
case let .channelAdminLogEventActionParticipantMute(channelAdminLogEventActionParticipantMuteData):
let parsedParticipant = GroupCallParticipantsContext.Update.StateUpdate.ParticipantUpdate(channelAdminLogEventActionParticipantMuteData.participant)
action = .groupCallUpdateParticipantMuteStatus(peerId: parsedParticipant.peerId, isMuted: true)
case let .channelAdminLogEventActionParticipantUnmute(participant):
let parsedParticipant = GroupCallParticipantsContext.Update.StateUpdate.ParticipantUpdate(participant)
case let .channelAdminLogEventActionParticipantUnmute(channelAdminLogEventActionParticipantUnmuteData):
let parsedParticipant = GroupCallParticipantsContext.Update.StateUpdate.ParticipantUpdate(channelAdminLogEventActionParticipantUnmuteData.participant)
action = .groupCallUpdateParticipantMuteStatus(peerId: parsedParticipant.peerId, isMuted: false)
case let .channelAdminLogEventActionToggleGroupCallSetting(joinMuted):
action = .updateGroupCallSettings(joinMuted: joinMuted == .boolTrue)
case let .channelAdminLogEventActionExportedInviteDelete(invite):
action = .deleteExportedInvitation(ExportedInvitation(apiExportedInvite: invite))
case let .channelAdminLogEventActionExportedInviteRevoke(invite):
action = .revokeExportedInvitation(ExportedInvitation(apiExportedInvite: invite))
case let .channelAdminLogEventActionExportedInviteEdit(prevInvite, newInvite):
case let .channelAdminLogEventActionToggleGroupCallSetting(channelAdminLogEventActionToggleGroupCallSettingData):
action = .updateGroupCallSettings(joinMuted: channelAdminLogEventActionToggleGroupCallSettingData.joinMuted == .boolTrue)
case let .channelAdminLogEventActionExportedInviteDelete(channelAdminLogEventActionExportedInviteDeleteData):
action = .deleteExportedInvitation(ExportedInvitation(apiExportedInvite: channelAdminLogEventActionExportedInviteDeleteData.invite))
case let .channelAdminLogEventActionExportedInviteRevoke(channelAdminLogEventActionExportedInviteRevokeData):
action = .revokeExportedInvitation(ExportedInvitation(apiExportedInvite: channelAdminLogEventActionExportedInviteRevokeData.invite))
case let .channelAdminLogEventActionExportedInviteEdit(channelAdminLogEventActionExportedInviteEditData):
let (prevInvite, newInvite) = (channelAdminLogEventActionExportedInviteEditData.prevInvite, channelAdminLogEventActionExportedInviteEditData.newInvite)
action = .editExportedInvitation(previous: ExportedInvitation(apiExportedInvite: prevInvite), updated: ExportedInvitation(apiExportedInvite: newInvite))
case let .channelAdminLogEventActionParticipantJoinByInvite(flags, invite):
case let .channelAdminLogEventActionParticipantJoinByInvite(channelAdminLogEventActionParticipantJoinByInviteData):
let (flags, invite) = (channelAdminLogEventActionParticipantJoinByInviteData.flags, channelAdminLogEventActionParticipantJoinByInviteData.invite)
action = .participantJoinedViaInvite(invitation: ExportedInvitation(apiExportedInvite: invite), joinedViaFolderLink: (flags & (1 << 0)) != 0)
case let .channelAdminLogEventActionParticipantVolume(participant):
let parsedParticipant = GroupCallParticipantsContext.Update.StateUpdate.ParticipantUpdate(participant)
case let .channelAdminLogEventActionParticipantVolume(channelAdminLogEventActionParticipantVolumeData):
let parsedParticipant = GroupCallParticipantsContext.Update.StateUpdate.ParticipantUpdate(channelAdminLogEventActionParticipantVolumeData.participant)
action = .groupCallUpdateParticipantVolume(peerId: parsedParticipant.peerId, volume: parsedParticipant.volume ?? 10000)
case let .channelAdminLogEventActionChangeHistoryTTL(prevValue, newValue):
case let .channelAdminLogEventActionChangeHistoryTTL(channelAdminLogEventActionChangeHistoryTTLData):
let (prevValue, newValue) = (channelAdminLogEventActionChangeHistoryTTLData.prevValue, channelAdminLogEventActionChangeHistoryTTLData.newValue)
action = .changeHistoryTTL(previousValue: prevValue, updatedValue: newValue)
case let .channelAdminLogEventActionParticipantJoinByRequest(invite, approvedBy):
case let .channelAdminLogEventActionParticipantJoinByRequest(channelAdminLogEventActionParticipantJoinByRequestData):
let (invite, approvedBy) = (channelAdminLogEventActionParticipantJoinByRequestData.invite, channelAdminLogEventActionParticipantJoinByRequestData.approvedBy)
action = .participantJoinByRequest(invitation: ExportedInvitation(apiExportedInvite: invite), approvedBy: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(approvedBy)))
case let .channelAdminLogEventActionToggleNoForwards(new):
action = .toggleCopyProtection(boolFromApiValue(new))
case let .channelAdminLogEventActionSendMessage(message):
if let message = StoreMessage(apiMessage: message, accountPeerId: accountPeerId, peerIsForum: peer.isForum), let rendered = renderedMessage(message: message) {
case let .channelAdminLogEventActionToggleNoForwards(channelAdminLogEventActionToggleNoForwardsData):
action = .toggleCopyProtection(boolFromApiValue(channelAdminLogEventActionToggleNoForwardsData.newValue))
case let .channelAdminLogEventActionSendMessage(channelAdminLogEventActionSendMessageData):
if let message = StoreMessage(apiMessage: channelAdminLogEventActionSendMessageData.message, accountPeerId: accountPeerId, peerIsForum: peer.isForum), let rendered = renderedMessage(message: message) {
action = .sendMessage(rendered)
}
case let .channelAdminLogEventActionChangeAvailableReactions(prevValue, newValue):
case let .channelAdminLogEventActionChangeAvailableReactions(channelAdminLogEventActionChangeAvailableReactionsData):
let (prevValue, newValue) = (channelAdminLogEventActionChangeAvailableReactionsData.prevValue, channelAdminLogEventActionChangeAvailableReactionsData.newValue)
action = .changeAvailableReactions(previousValue: PeerAllowedReactions(apiReactions: prevValue), updatedValue: PeerAllowedReactions(apiReactions: newValue))
case let .channelAdminLogEventActionChangeUsernames(prevValue, newValue):
case let .channelAdminLogEventActionChangeUsernames(channelAdminLogEventActionChangeUsernamesData):
let (prevValue, newValue) = (channelAdminLogEventActionChangeUsernamesData.prevValue, channelAdminLogEventActionChangeUsernamesData.newValue)
action = .changeUsernames(prev: prevValue, new: newValue)
case let .channelAdminLogEventActionCreateTopic(topic):
switch topic {
case let .forumTopic(_, _, _, _, title, iconColor, iconEmojiId, _, _, _, _, _, _, _, _, _):
case let .channelAdminLogEventActionCreateTopic(channelAdminLogEventActionCreateTopicData):
switch channelAdminLogEventActionCreateTopicData.topic {
case let .forumTopic(forumTopicData):
let (title, iconColor, iconEmojiId) = (forumTopicData.title, forumTopicData.iconColor, forumTopicData.iconEmojiId)
action = .createTopic(info: EngineMessageHistoryThread.Info(title: title, icon: iconEmojiId, iconColor: iconColor))
case .forumTopicDeleted:
action = .createTopic(info: EngineMessageHistoryThread.Info(title: "", icon: nil, iconColor: 0))
}
case let .channelAdminLogEventActionDeleteTopic(topic):
case let .channelAdminLogEventActionDeleteTopic(channelAdminLogEventActionDeleteTopicData):
let topic = channelAdminLogEventActionDeleteTopicData.topic
switch topic {
case let .forumTopic(_, _, _, _, title, iconColor, iconEmojiId, _, _, _, _, _, _, _, _, _):
case let .forumTopic(forumTopicData):
let (title, iconColor, iconEmojiId) = (forumTopicData.title, forumTopicData.iconColor, forumTopicData.iconEmojiId)
action = .deleteTopic(info: EngineMessageHistoryThread.Info(title: title, icon: iconEmojiId, iconColor: iconColor))
case .forumTopicDeleted:
action = .deleteTopic(info: EngineMessageHistoryThread.Info(title: "", icon: nil, iconColor: 0))
}
case let .channelAdminLogEventActionEditTopic(prevTopic, newTopic):
case let .channelAdminLogEventActionEditTopic(channelAdminLogEventActionEditTopicData):
let (prevTopic, newTopic) = (channelAdminLogEventActionEditTopicData.prevTopic, channelAdminLogEventActionEditTopicData.newTopic)
let prevInfo: AdminLogEventAction.ForumTopicInfo
switch prevTopic {
case let .forumTopic(flags, _, _, _, title, iconColor, iconEmojiId, _, _, _, _, _, _, _, _, _):
case let .forumTopic(forumTopicData):
let (flags, title, iconColor, iconEmojiId) = (forumTopicData.flags, forumTopicData.title, forumTopicData.iconColor, forumTopicData.iconEmojiId)
prevInfo = AdminLogEventAction.ForumTopicInfo(info: EngineMessageHistoryThread.Info(title: title, icon: iconEmojiId, iconColor: iconColor), isClosed: (flags & (1 << 2)) != 0, isHidden: (flags & (1 << 6)) != 0)
case .forumTopicDeleted:
prevInfo = AdminLogEventAction.ForumTopicInfo(info: EngineMessageHistoryThread.Info(title: "", icon: nil, iconColor: 0), isClosed: false, isHidden: false)
}
let newInfo: AdminLogEventAction.ForumTopicInfo
switch newTopic {
case let .forumTopic(flags, _, _, _, title, iconColor, iconEmojiId, _, _, _, _, _, _, _, _, _):
case let .forumTopic(forumTopicData):
let (flags, title, iconColor, iconEmojiId) = (forumTopicData.flags, forumTopicData.title, forumTopicData.iconColor, forumTopicData.iconEmojiId)
newInfo = AdminLogEventAction.ForumTopicInfo(info: EngineMessageHistoryThread.Info(title: title, icon: iconEmojiId, iconColor: iconColor), isClosed: (flags & (1 << 2)) != 0, isHidden: (flags & (1 << 6)) != 0)
case .forumTopicDeleted:
newInfo = AdminLogEventAction.ForumTopicInfo(info: EngineMessageHistoryThread.Info(title: "", icon: nil, iconColor: 0), isClosed: false, isHidden: false)
}
action = .editTopic(prevInfo: prevInfo, newInfo: newInfo)
case let .channelAdminLogEventActionPinTopic(_, prevTopic, newTopic):
case let .channelAdminLogEventActionPinTopic(channelAdminLogEventActionPinTopicData):
let (prevTopic, newTopic) = (channelAdminLogEventActionPinTopicData.prevTopic, channelAdminLogEventActionPinTopicData.newTopic)
let prevInfo: EngineMessageHistoryThread.Info?
switch prevTopic {
case let .forumTopic(_, _, _, _, title, iconColor, iconEmojiId, _, _, _, _, _, _, _, _, _):
case let .forumTopic(forumTopicData):
let (title, iconColor, iconEmojiId) = (forumTopicData.title, forumTopicData.iconColor, forumTopicData.iconEmojiId)
prevInfo = EngineMessageHistoryThread.Info(title: title, icon: iconEmojiId, iconColor: iconColor)
case .forumTopicDeleted:
prevInfo = EngineMessageHistoryThread.Info(title: "", icon: nil, iconColor: 0)
case .none:
prevInfo = nil
}
let newInfo: EngineMessageHistoryThread.Info?
switch newTopic {
case let .forumTopic(_, _, _, _, title, iconColor, iconEmojiId, _, _, _, _, _, _, _, _, _):
case let .forumTopic(forumTopicData):
let (title, iconColor, iconEmojiId) = (forumTopicData.title, forumTopicData.iconColor, forumTopicData.iconEmojiId)
newInfo = EngineMessageHistoryThread.Info(title: title, icon: iconEmojiId, iconColor: iconColor)
case .forumTopicDeleted:
newInfo = EngineMessageHistoryThread.Info(title: "", icon: nil, iconColor: 0)
@@ -379,32 +410,39 @@ func channelAdminLogEvents(accountPeerId: PeerId, postbox: Postbox, network: Net
newInfo = nil
}
action = .pinTopic(prevInfo: prevInfo, newInfo: newInfo)
case let .channelAdminLogEventActionToggleForum(newValue):
action = .toggleForum(isForum: newValue == .boolTrue)
case let .channelAdminLogEventActionToggleAntiSpam(newValue):
action = .toggleAntiSpam(isEnabled: newValue == .boolTrue)
case let .channelAdminLogEventActionChangePeerColor(prevValue, newValue):
guard case let .peerColor(_, prevColor, prevBackgroundEmojiIdValue) = prevValue, case let .peerColor(_, newColor, newBackgroundEmojiIdValue) = newValue else {
case let .channelAdminLogEventActionToggleForum(channelAdminLogEventActionToggleForumData):
action = .toggleForum(isForum: channelAdminLogEventActionToggleForumData.newValue == .boolTrue)
case let .channelAdminLogEventActionToggleAntiSpam(channelAdminLogEventActionToggleAntiSpamData):
action = .toggleAntiSpam(isEnabled: channelAdminLogEventActionToggleAntiSpamData.newValue == .boolTrue)
case let .channelAdminLogEventActionChangePeerColor(channelAdminLogEventActionChangePeerColorData):
let (prevValue, newValue) = (channelAdminLogEventActionChangePeerColorData.prevValue, channelAdminLogEventActionChangePeerColorData.newValue)
guard case let .peerColor(prevPeerColorData) = prevValue, case let .peerColor(newPeerColorData) = newValue else {
continue
}
let (prevColor, prevBackgroundEmojiId) = (prevPeerColorData.color, prevPeerColorData.backgroundEmojiId)
let (newColor, newBackgroundEmojiId) = (newPeerColorData.color, newPeerColorData.backgroundEmojiId)
let prevColorIndex = prevColor ?? 0
let prevEmojiId = prevBackgroundEmojiIdValue
let prevEmojiId = prevBackgroundEmojiId
let newColorIndex = newColor ?? 0
let newEmojiId = newBackgroundEmojiIdValue
let newEmojiId = newBackgroundEmojiId
action = .changeNameColor(prevColor: PeerNameColor(rawValue: prevColorIndex), prevIcon: prevEmojiId, newColor: PeerNameColor(rawValue: newColorIndex), newIcon: newEmojiId)
case let .channelAdminLogEventActionChangeProfilePeerColor(prevValue, newValue):
guard case let .peerColor(_, prevColorIndex, prevEmojiId) = prevValue, case let .peerColor(_, newColorIndex, newEmojiId) = newValue else {
case let .channelAdminLogEventActionChangeProfilePeerColor(channelAdminLogEventActionChangeProfilePeerColorData):
guard case let .peerColor(prevPeerColorData) = channelAdminLogEventActionChangeProfilePeerColorData.prevValue, case let .peerColor(newPeerColorData) = channelAdminLogEventActionChangeProfilePeerColorData.newValue else {
continue
}
action = .changeProfileColor(prevColor: prevColorIndex.flatMap(PeerNameColor.init(rawValue:)), prevIcon: prevEmojiId, newColor: newColorIndex.flatMap(PeerNameColor.init(rawValue:)), newIcon: newEmojiId)
case let .channelAdminLogEventActionChangeWallpaper(prevValue, newValue):
let (prevColor, prevBackgroundEmojiId) = (prevPeerColorData.color, prevPeerColorData.backgroundEmojiId)
let (newColor, newBackgroundEmojiId) = (newPeerColorData.color, newPeerColorData.backgroundEmojiId)
action = .changeProfileColor(prevColor: prevColor.flatMap(PeerNameColor.init(rawValue:)), prevIcon: prevBackgroundEmojiId, newColor: newColor.flatMap(PeerNameColor.init(rawValue:)), newIcon: newBackgroundEmojiId)
case let .channelAdminLogEventActionChangeWallpaper(channelAdminLogEventActionChangeWallpaperData):
let (prevValue, newValue) = (channelAdminLogEventActionChangeWallpaperData.prevValue, channelAdminLogEventActionChangeWallpaperData.newValue)
let prev: TelegramWallpaper?
if case let .wallPaperNoFile(_, _, settings) = prevValue {
if case let .wallPaperNoFile(wallPaperNoFileData) = prevValue {
let (_, _, settings) = (wallPaperNoFileData.id, wallPaperNoFileData.flags, wallPaperNoFileData.settings)
if settings == nil {
prev = nil
} else if case let .wallPaperSettings(flags, _, _, _, _, _, _, _) = settings, flags == 0 {
} else if case let .wallPaperSettings(wallPaperSettingsData) = settings, wallPaperSettingsData.flags == 0 {
prev = nil
} else {
prev = TelegramWallpaper(apiWallpaper: prevValue)
@@ -413,10 +451,11 @@ func channelAdminLogEvents(accountPeerId: PeerId, postbox: Postbox, network: Net
prev = TelegramWallpaper(apiWallpaper: prevValue)
}
let new: TelegramWallpaper?
if case let .wallPaperNoFile(_, _, settings) = newValue {
if case let .wallPaperNoFile(wallPaperNoFileData) = newValue {
let (_, _, settings) = (wallPaperNoFileData.id, wallPaperNoFileData.flags, wallPaperNoFileData.settings)
if settings == nil {
new = nil
} else if case let .wallPaperSettings(flags, _, _, _, _, _, _, _) = settings, flags == 0 {
} else if case let .wallPaperSettings(wallPaperSettingsData) = settings, wallPaperSettingsData.flags == 0 {
new = nil
} else {
new = TelegramWallpaper(apiWallpaper: newValue)
@@ -425,20 +464,24 @@ func channelAdminLogEvents(accountPeerId: PeerId, postbox: Postbox, network: Net
new = TelegramWallpaper(apiWallpaper: newValue)
}
action = .changeWallpaper(prev: prev, new: new)
case let .channelAdminLogEventActionChangeEmojiStatus(prevValue, newValue):
case let .channelAdminLogEventActionChangeEmojiStatus(channelAdminLogEventActionChangeEmojiStatusData):
let (prevValue, newValue) = (channelAdminLogEventActionChangeEmojiStatusData.prevValue, channelAdminLogEventActionChangeEmojiStatusData.newValue)
action = .changeStatus(prev: PeerEmojiStatus(apiStatus: prevValue), new: PeerEmojiStatus(apiStatus: newValue))
case let .channelAdminLogEventActionChangeEmojiStickerSet(prevStickerset, newStickerset):
case let .channelAdminLogEventActionChangeEmojiStickerSet(channelAdminLogEventActionChangeEmojiStickerSetData):
let (prevStickerset, newStickerset) = (channelAdminLogEventActionChangeEmojiStickerSetData.prevStickerset, channelAdminLogEventActionChangeEmojiStickerSetData.newStickerset)
action = .changeEmojiPack(prev: StickerPackReference(apiInputSet: prevStickerset), new: StickerPackReference(apiInputSet: newStickerset))
case let .channelAdminLogEventActionToggleSignatureProfiles(newValue):
action = .toggleSignatureProfiles(boolFromApiValue(newValue))
case let .channelAdminLogEventActionParticipantSubExtend(prev, new):
case let .channelAdminLogEventActionToggleSignatureProfiles(channelAdminLogEventActionToggleSignatureProfilesData):
action = .toggleSignatureProfiles(boolFromApiValue(channelAdminLogEventActionToggleSignatureProfilesData.newValue))
case let .channelAdminLogEventActionParticipantSubExtend(channelAdminLogEventActionParticipantSubExtendData):
let (prev, new) = (channelAdminLogEventActionParticipantSubExtendData.prevParticipant, channelAdminLogEventActionParticipantSubExtendData.newParticipant)
let prevParticipant = ChannelParticipant(apiParticipant: prev)
let newParticipant = ChannelParticipant(apiParticipant: new)
if let prevPeer = peers[prevParticipant.peerId], let newPeer = peers[newParticipant.peerId] {
action = .participantSubscriptionExtended(prev: RenderedChannelParticipant(participant: prevParticipant, peer: prevPeer), new: RenderedChannelParticipant(participant: newParticipant, peer: newPeer))
}
case let .channelAdminLogEventActionToggleAutotranslation(newValue):
case let .channelAdminLogEventActionToggleAutotranslation(channelAdminLogEventActionToggleAutotranslationData):
let newValue = channelAdminLogEventActionToggleAutotranslationData.newValue
action = .toggleAutoTranslation(boolFromApiValue(newValue))
}
let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
@@ -32,7 +32,7 @@ func _internal_updateChannelMemberBannedRights(account: Account, peerId: PeerId,
if let rights = rights, !rights.flags.isEmpty {
apiRights = rights.apiBannedRights
} else {
apiRights = .chatBannedRights(flags: 0, untilDate: 0)
apiRights = .chatBannedRights(.init(flags: 0, untilDate: 0))
}
return account.network.request(Api.functions.channels.editBanned(channel: inputChannel, participant: inputPeer, bannedRights: apiRights))
@@ -37,7 +37,7 @@ private func createChannel(postbox: Postbox, network: Network, stateManager: Acc
var address: String?
if let location = location {
flags |= (1 << 2)
geoPoint = .inputGeoPoint(flags: 0, lat: location.latitude, long: location.longitude, accuracyRadius: nil)
geoPoint = .inputGeoPoint(.init(flags: 0, lat: location.latitude, long: location.longitude, accuracyRadius: nil))
address = location.address
}
@@ -40,7 +40,7 @@ func _internal_channelMembers(postbox: Postbox, network: Network, accountPeerId:
case .all:
apiFilter = .channelParticipantsRecent
case let .search(query):
apiFilter = .channelParticipantsSearch(q: query)
apiFilter = .channelParticipantsSearch(Api.ChannelParticipantsFilter.Cons_channelParticipantsSearch(q: query))
}
case let .mentions(threadId, filter):
switch filter {
@@ -49,7 +49,7 @@ func _internal_channelMembers(postbox: Postbox, network: Network, accountPeerId:
if threadId != nil {
flags |= 1 << 1
}
apiFilter = .channelParticipantsMentions(flags: flags, q: nil, topMsgId: threadId?.id)
apiFilter = .channelParticipantsMentions(Api.ChannelParticipantsFilter.Cons_channelParticipantsMentions(flags: flags, q: nil, topMsgId: threadId?.id))
case let .search(query):
var flags: Int32 = 0
if threadId != nil {
@@ -58,32 +58,32 @@ func _internal_channelMembers(postbox: Postbox, network: Network, accountPeerId:
if !query.isEmpty {
flags |= 1 << 0
}
apiFilter = .channelParticipantsMentions(flags: flags, q: query.isEmpty ? nil : query, topMsgId: threadId?.id)
apiFilter = .channelParticipantsMentions(Api.ChannelParticipantsFilter.Cons_channelParticipantsMentions(flags: flags, q: query.isEmpty ? nil : query, topMsgId: threadId?.id))
}
case .admins:
apiFilter = .channelParticipantsAdmins
case let .contacts(filter):
switch filter {
case .all:
apiFilter = .channelParticipantsContacts(q: "")
apiFilter = .channelParticipantsContacts(Api.ChannelParticipantsFilter.Cons_channelParticipantsContacts(q: ""))
case let .search(query):
apiFilter = .channelParticipantsContacts(q: query)
apiFilter = .channelParticipantsContacts(Api.ChannelParticipantsFilter.Cons_channelParticipantsContacts(q: query))
}
case .bots:
apiFilter = .channelParticipantsBots
case let .restricted(filter):
switch filter {
case .all:
apiFilter = .channelParticipantsBanned(q: "")
apiFilter = .channelParticipantsBanned(Api.ChannelParticipantsFilter.Cons_channelParticipantsBanned(q: ""))
case let .search(query):
apiFilter = .channelParticipantsBanned(q: query)
apiFilter = .channelParticipantsBanned(Api.ChannelParticipantsFilter.Cons_channelParticipantsBanned(q: query))
}
case let .banned(filter):
switch filter {
case .all:
apiFilter = .channelParticipantsKicked(q: "")
apiFilter = .channelParticipantsKicked(Api.ChannelParticipantsFilter.Cons_channelParticipantsKicked(q: ""))
case let .search(query):
apiFilter = .channelParticipantsKicked(q: query)
apiFilter = .channelParticipantsKicked(Api.ChannelParticipantsFilter.Cons_channelParticipantsKicked(q: query))
}
}
return network.request(Api.functions.channels.getParticipants(channel: inputChannel, filter: apiFilter, offset: offset, limit: limit, hash: hash))
@@ -95,7 +95,8 @@ func _internal_channelMembers(postbox: Postbox, network: Network, accountPeerId:
return postbox.transaction { transaction -> [RenderedChannelParticipant]? in
var items: [RenderedChannelParticipant] = []
switch result {
case let .channelParticipants(_, participants, chats, users):
case let .channelParticipants(channelParticipantsData):
let (participants, chats, users) = (channelParticipantsData.participants, channelParticipantsData.chats, channelParticipantsData.users)
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
var peers: [PeerId: Peer] = [:]
@@ -101,7 +101,7 @@ func _internal_updateChannelOwnership(account: Account, channelId: PeerId, membe
guard let kdfResult = passwordKDF(encryptionProvider: account.network.encryptionProvider, password: password, derivation: currentPasswordDerivation, srpSessionData: srpSessionData) else {
return .fail(.generic)
}
return .single(.inputCheckPasswordSRP(srpId: kdfResult.id, A: Buffer(data: kdfResult.A), M1: Buffer(data: kdfResult.M1)))
return .single(.inputCheckPasswordSRP(.init(srpId: kdfResult.id, A: Buffer(data: kdfResult.A), M1: Buffer(data: kdfResult.M1))))
} else {
return .fail(.twoStepAuthMissing)
}
@@ -104,10 +104,12 @@ func _internal_requestRecommendedChannels(account: Account, peerId: EnginePeer.I
let parsedPeers: AccumulatedPeers
var count: Int32
switch result {
case let .chats(apiChats):
case let .chats(chatsData):
let apiChats = chatsData.chats
chats = apiChats
count = Int32(apiChats.count)
case let .chatsSlice(apiCount, apiChats):
case let .chatsSlice(chatsSliceData):
let (apiCount, apiChats) = (chatsSliceData.count, chatsSliceData.chats)
chats = apiChats
count = apiCount
}
@@ -117,7 +119,7 @@ func _internal_requestRecommendedChannels(account: Account, peerId: EnginePeer.I
for chat in chats {
if let peer = transaction.getPeer(chat.peerId) {
peers.append(EnginePeer(peer))
if case let .channel(_, _, _, _, _, _, _, _, _, _, _, _, participantsCount, _, _, _, _, _, _, _, _, _, _) = chat, let participantsCount = participantsCount {
if case let .channel(channelData) = chat, let participantsCount = channelData.participantsCount {
transaction.updatePeerCachedData(peerIds: Set([peer.id]), update: { _, current in
var current = current as? CachedChannelData ?? CachedChannelData()
var participantsSummary = current.participantsSummary
@@ -167,7 +169,8 @@ func _internal_requestRecommendedApps(account: Account, forceUpdate: Bool) -> Si
let users: [Api.User]
let parsedPeers: AccumulatedPeers
switch result {
case let .popularAppBots(_, nextOffset, apiUsers):
case let .popularAppBots(popularAppBotsData):
let (nextOffset, apiUsers) = (popularAppBotsData.nextOffset, popularAppBotsData.users)
let _ = nextOffset
users = apiUsers
}
@@ -1,3 +1,4 @@
import SGSimpleSettings
import Foundation
import Postbox
import SwiftSignalKit
@@ -341,11 +342,13 @@ extension ChatListFilter {
switch apiFilter {
case .dialogFilterDefault:
self = .allChats
case let .dialogFilter(flags, id, title, emoticon, color, pinnedPeers, includePeers, excludePeers):
case let .dialogFilter(dialogFilterData):
let (flags, id, title, emoticon, color, pinnedPeers, includePeers, excludePeers) = (dialogFilterData.flags, dialogFilterData.id, dialogFilterData.title, dialogFilterData.emoticon, dialogFilterData.color, dialogFilterData.pinnedPeers, dialogFilterData.includePeers, dialogFilterData.excludePeers)
let titleText: String
let titleEntities: [MessageTextEntity]
switch title {
case let .textWithEntities(text, entities):
case let .textWithEntities(textWithEntitiesData):
let (text, entities) = (textWithEntitiesData.text, textWithEntitiesData.entities)
titleText = text
titleEntities = messageTextEntitiesFromApiEntities(entities)
}
@@ -363,22 +366,28 @@ extension ChatListFilter {
excludeArchived: (flags & (1 << 13)) != 0,
includePeers: ChatListFilterIncludePeers(rawPeers: includePeers.compactMap { peer -> PeerId? in
switch peer {
case let .inputPeerUser(userId, _):
case let .inputPeerUser(inputPeerUserData):
let userId = inputPeerUserData.userId
return PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
case let .inputPeerChat(chatId):
case let .inputPeerChat(inputPeerChatData):
let chatId = inputPeerChatData.chatId
return PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(chatId))
case let .inputPeerChannel(channelId, _):
case let .inputPeerChannel(inputPeerChannelData):
let channelId = inputPeerChannelData.channelId
return PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId))
default:
return nil
}
}, rawPinnedPeers: pinnedPeers.compactMap { peer -> PeerId? in
switch peer {
case let .inputPeerUser(userId, _):
case let .inputPeerUser(inputPeerUserData):
let userId = inputPeerUserData.userId
return PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
case let .inputPeerChat(chatId):
case let .inputPeerChat(inputPeerChatData):
let chatId = inputPeerChatData.chatId
return PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(chatId))
case let .inputPeerChannel(channelId, _):
case let .inputPeerChannel(inputPeerChannelData):
let channelId = inputPeerChannelData.channelId
return PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId))
default:
return nil
@@ -386,11 +395,14 @@ extension ChatListFilter {
}),
excludePeers: excludePeers.compactMap { peer -> PeerId? in
switch peer {
case let .inputPeerUser(userId, _):
case let .inputPeerUser(inputPeerUserData):
let userId = inputPeerUserData.userId
return PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
case let .inputPeerChat(chatId):
case let .inputPeerChat(inputPeerChatData):
let chatId = inputPeerChatData.chatId
return PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(chatId))
case let .inputPeerChannel(channelId, _):
case let .inputPeerChannel(inputPeerChannelData):
let channelId = inputPeerChannelData.channelId
return PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId))
default:
return nil
@@ -399,16 +411,18 @@ extension ChatListFilter {
color: color.flatMap(PeerNameColor.init(rawValue:))
)
)
case let .dialogFilterChatlist(flags, id, title, emoticon, color, pinnedPeers, includePeers):
case let .dialogFilterChatlist(dialogFilterChatlistData):
let (flags, id, title, emoticon, color, pinnedPeers, includePeers) = (dialogFilterChatlistData.flags, dialogFilterChatlistData.id, dialogFilterChatlistData.title, dialogFilterChatlistData.emoticon, dialogFilterChatlistData.color, dialogFilterChatlistData.pinnedPeers, dialogFilterChatlistData.includePeers)
let titleText: String
let titleEntities: [MessageTextEntity]
switch title {
case let .textWithEntities(text, entities):
case let .textWithEntities(textWithEntitiesData):
let (text, entities) = (textWithEntitiesData.text, textWithEntitiesData.entities)
titleText = text
titleEntities = messageTextEntitiesFromApiEntities(entities)
}
let disableTitleAnimations = (flags & (1 << 28)) != 0
self = .filter(
id: id,
title: ChatFolderTitle(text: titleText, entities: titleEntities, enableAnimations: !disableTitleAnimations),
@@ -422,22 +436,28 @@ extension ChatListFilter {
excludeArchived: false,
includePeers: ChatListFilterIncludePeers(rawPeers: includePeers.compactMap { peer -> PeerId? in
switch peer {
case let .inputPeerUser(userId, _):
case let .inputPeerUser(inputPeerUserData):
let userId = inputPeerUserData.userId
return PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
case let .inputPeerChat(chatId):
case let .inputPeerChat(inputPeerChatData):
let chatId = inputPeerChatData.chatId
return PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(chatId))
case let .inputPeerChannel(channelId, _):
case let .inputPeerChannel(inputPeerChannelData):
let channelId = inputPeerChannelData.channelId
return PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId))
default:
return nil
}
}, rawPinnedPeers: pinnedPeers.compactMap { peer -> PeerId? in
switch peer {
case let .inputPeerUser(userId, _):
case let .inputPeerUser(inputPeerUserData):
let userId = inputPeerUserData.userId
return PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
case let .inputPeerChat(chatId):
case let .inputPeerChat(inputPeerChatData):
let chatId = inputPeerChatData.chatId
return PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(chatId))
case let .inputPeerChannel(channelId, _):
case let .inputPeerChannel(inputPeerChannelData):
let channelId = inputPeerChannelData.channelId
return PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId))
default:
return nil
@@ -449,7 +469,7 @@ extension ChatListFilter {
)
}
}
func apiFilter(transaction: Transaction) -> Api.DialogFilter? {
switch self {
case .allChats:
@@ -466,14 +486,14 @@ extension ChatListFilter {
if !title.enableAnimations {
flags |= 1 << 28
}
return .dialogFilterChatlist(flags: flags, id: id, title: .textWithEntities(text: title.text, entities: apiEntitiesFromMessageTextEntities(title.entities, associatedPeers: SimpleDictionary())), emoticon: emoticon, color: data.color?.rawValue, pinnedPeers: data.includePeers.pinnedPeers.compactMap { peerId -> Api.InputPeer? in
return .dialogFilterChatlist(.init(flags: flags, id: id, title: .textWithEntities(.init(text: title.text, entities: apiEntitiesFromMessageTextEntities(title.entities, associatedPeers: SimpleDictionary()))), emoticon: emoticon, color: data.color?.rawValue, pinnedPeers: data.includePeers.pinnedPeers.compactMap { peerId -> Api.InputPeer? in
return transaction.getPeer(peerId).flatMap(apiInputPeer)
}, includePeers: data.includePeers.peers.compactMap { peerId -> Api.InputPeer? in
if data.includePeers.pinnedPeers.contains(peerId) {
return nil
}
return transaction.getPeer(peerId).flatMap(apiInputPeer)
})
}))
} else {
var flags: Int32 = 0
if data.excludeMuted {
@@ -495,7 +515,7 @@ extension ChatListFilter {
if !title.enableAnimations {
flags |= 1 << 28
}
return .dialogFilter(flags: flags, id: id, title: .textWithEntities(text: title.text, entities: apiEntitiesFromMessageTextEntities(title.entities, associatedPeers: SimpleDictionary())), emoticon: emoticon, color: data.color?.rawValue, pinnedPeers: data.includePeers.pinnedPeers.compactMap { peerId -> Api.InputPeer? in
return .dialogFilter(.init(flags: flags, id: id, title: .textWithEntities(.init(text: title.text, entities: apiEntitiesFromMessageTextEntities(title.entities, associatedPeers: SimpleDictionary()))), emoticon: emoticon, color: data.color?.rawValue, pinnedPeers: data.includePeers.pinnedPeers.compactMap { peerId -> Api.InputPeer? in
return transaction.getPeer(peerId).flatMap(apiInputPeer)
}, includePeers: data.includePeers.peers.compactMap { peerId -> Api.InputPeer? in
if data.includePeers.pinnedPeers.contains(peerId) {
@@ -504,7 +524,7 @@ extension ChatListFilter {
return transaction.getPeer(peerId).flatMap(apiInputPeer)
}, excludePeers: data.excludePeers.compactMap { peerId -> Api.InputPeer? in
return transaction.getPeer(peerId).flatMap(apiInputPeer)
})
}))
}
}
}
@@ -560,7 +580,8 @@ private func requestChatListFilters(accountPeerId: PeerId, postbox: Postbox, net
|> mapToSignal { result -> Signal<([ChatListFilter], Bool), RequestChatListFiltersError> in
return postbox.transaction { transaction -> ([ChatListFilter], [Api.InputPeer], [Api.InputPeer], Bool) in
switch result {
case let .dialogFilters(flags, apiFilters):
case let .dialogFilters(dialogFiltersData):
let (flags, apiFilters) = (dialogFiltersData.flags, dialogFiltersData.filters)
let tagsEnabled = (flags & (1 << 0)) != 0
var filters: [ChatListFilter] = []
@@ -574,15 +595,19 @@ private func requestChatListFilters(accountPeerId: PeerId, postbox: Postbox, net
switch apiFilter {
case .dialogFilterDefault:
break
case let .dialogFilter(_, _, _, _, _, pinnedPeers, includePeers, excludePeers):
case let .dialogFilter(dialogFilterData):
let (pinnedPeers, includePeers, excludePeers) = (dialogFilterData.pinnedPeers, dialogFilterData.includePeers, dialogFilterData.excludePeers)
for peer in pinnedPeers + includePeers + excludePeers {
var peerId: PeerId?
switch peer {
case let .inputPeerUser(userId, _):
case let .inputPeerUser(inputPeerUserData):
let userId = inputPeerUserData.userId
peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
case let .inputPeerChat(chatId):
case let .inputPeerChat(inputPeerChatData):
let chatId = inputPeerChatData.chatId
peerId = PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(chatId))
case let .inputPeerChannel(channelId, _):
case let .inputPeerChannel(inputPeerChannelData):
let channelId = inputPeerChannelData.channelId
peerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId))
default:
break
@@ -594,15 +619,18 @@ private func requestChatListFilters(accountPeerId: PeerId, postbox: Postbox, net
}
}
}
for peer in pinnedPeers {
var peerId: PeerId?
switch peer {
case let .inputPeerUser(userId, _):
case let .inputPeerUser(inputPeerUserData):
let userId = inputPeerUserData.userId
peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
case let .inputPeerChat(chatId):
case let .inputPeerChat(inputPeerChatData):
let chatId = inputPeerChatData.chatId
peerId = PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(chatId))
case let .inputPeerChannel(channelId, _):
case let .inputPeerChannel(inputPeerChannelData):
let channelId = inputPeerChannelData.channelId
peerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId))
default:
break
@@ -614,15 +642,19 @@ private func requestChatListFilters(accountPeerId: PeerId, postbox: Postbox, net
}
}
}
case let .dialogFilterChatlist(_, _, _, _, _, pinnedPeers, includePeers):
case let .dialogFilterChatlist(dialogFilterChatlistData):
let (pinnedPeers, includePeers) = (dialogFilterChatlistData.pinnedPeers, dialogFilterChatlistData.includePeers)
for peer in pinnedPeers + includePeers {
var peerId: PeerId?
switch peer {
case let .inputPeerUser(userId, _):
case let .inputPeerUser(inputPeerUserData):
let userId = inputPeerUserData.userId
peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
case let .inputPeerChat(chatId):
case let .inputPeerChat(inputPeerChatData):
let chatId = inputPeerChatData.chatId
peerId = PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(chatId))
case let .inputPeerChannel(channelId, _):
case let .inputPeerChannel(inputPeerChannelData):
let channelId = inputPeerChannelData.channelId
peerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId))
default:
break
@@ -634,15 +666,18 @@ private func requestChatListFilters(accountPeerId: PeerId, postbox: Postbox, net
}
}
}
for peer in pinnedPeers {
var peerId: PeerId?
switch peer {
case let .inputPeerUser(userId, _):
case let .inputPeerUser(inputPeerUserData):
let userId = inputPeerUserData.userId
peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
case let .inputPeerChat(chatId):
case let .inputPeerChat(inputPeerChatData):
let chatId = inputPeerChatData.chatId
peerId = PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(chatId))
case let .inputPeerChannel(channelId, _):
case let .inputPeerChannel(inputPeerChannelData):
let channelId = inputPeerChannelData.channelId
peerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId))
default:
break
@@ -668,13 +703,16 @@ private func requestChatListFilters(accountPeerId: PeerId, postbox: Postbox, net
var missingGroups: [Int64] = []
for peer in missingPeers {
switch peer {
case let .inputPeerUser(userId, accessHash):
missingUsers.append(.inputUser(userId: userId, accessHash: accessHash))
case let .inputPeerUser(inputPeerUserData):
let (userId, accessHash) = (inputPeerUserData.userId, inputPeerUserData.accessHash)
missingUsers.append(.inputUser(.init(userId: userId, accessHash: accessHash)))
case .inputPeerSelf:
missingUsers.append(.inputUserSelf)
case let .inputPeerChannel(channelId, accessHash):
missingChannels.append(.inputChannel(channelId: channelId, accessHash: accessHash))
case let .inputPeerChat(id):
case let .inputPeerChannel(inputPeerChannelData):
let (channelId, accessHash) = (inputPeerChannelData.channelId, inputPeerChannelData.accessHash)
missingChannels.append(.inputChannel(.init(channelId: channelId, accessHash: accessHash)))
case let .inputPeerChat(inputPeerChatData):
let id = inputPeerChatData.chatId
missingGroups.append(id)
case .inputPeerEmpty:
break
@@ -713,7 +751,11 @@ private func requestChatListFilters(accountPeerId: PeerId, postbox: Postbox, net
if let result = result {
let parsedPeers: AccumulatedPeers
switch result {
case .chats(let chats), .chatsSlice(_, let chats):
case let .chats(chatsData):
let chats = chatsData.chats
parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: [])
case let .chatsSlice(chatsSliceData):
let chats = chatsSliceData.chats
parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: [])
}
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
@@ -737,7 +779,11 @@ private func requestChatListFilters(accountPeerId: PeerId, postbox: Postbox, net
if let result = result {
let parsedPeers: AccumulatedPeers
switch result {
case .chats(let chats), .chatsSlice(_, let chats):
case let .chats(chatsData):
let chats = chatsData.chats
parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: [])
case let .chatsSlice(chatsSliceData):
let chats = chatsSliceData.chats
parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: [])
}
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
@@ -779,7 +825,7 @@ private func requestChatListFilters(accountPeerId: PeerId, postbox: Postbox, net
}
private func loadAndStorePeerChatInfos(accountPeerId: PeerId, postbox: Postbox, network: Network, peers: [Api.InputPeer]) -> Signal<Never, NoError> {
let signal = network.request(Api.functions.messages.getPeerDialogs(peers: peers.map(Api.InputDialogPeer.inputDialogPeer(peer:))))
let signal = network.request(Api.functions.messages.getPeerDialogs(peers: peers.map { .inputDialogPeer(.init(peer: $0)) }))
|> map(Optional.init)
return signal
@@ -799,14 +845,16 @@ private func loadAndStorePeerChatInfos(accountPeerId: PeerId, postbox: Postbox,
let parsedPeers: AccumulatedPeers
switch result {
case let .peerDialogs(dialogs, messages, chats, users, _):
case let .peerDialogs(peerDialogsData):
let (dialogs, messages, chats, users, _) = (peerDialogsData.dialogs, peerDialogsData.messages, peerDialogsData.chats, peerDialogsData.users, peerDialogsData.state)
parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
var topMessageIds = Set<MessageId>()
for dialog in dialogs {
switch dialog {
case let .dialog(_, peer, topMessage, readInboxMaxId, readOutboxMaxId, unreadCount, unreadMentionsCount, unreadReactionsCount, notifySettings, pts, _, folderId, ttlPeriod):
case let .dialog(dialogData):
let (peer, topMessage, readInboxMaxId, readOutboxMaxId, unreadCount, unreadMentionsCount, unreadReactionsCount, notifySettings, pts, folderId, ttlPeriod) = (dialogData.peer, dialogData.topMessage, dialogData.readInboxMaxId, dialogData.readOutboxMaxId, dialogData.unreadCount, dialogData.unreadMentionsCount, dialogData.unreadReactionsCount, dialogData.notifySettings, dialogData.pts, dialogData.folderId, dialogData.ttlPeriod)
let peerId = peer.peerId
if topMessage != 0 {
@@ -1090,13 +1138,18 @@ func _internal_updatedChatListFilters(postbox: Postbox, hiddenIds: Signal<Set<In
)
|> map { preferences, hiddenIds -> [ChatListFilter] in
let filtersState = preferences.values[PreferencesKeys.chatListFilters]?.get(ChatListFiltersState.self) ?? ChatListFiltersState.default
return filtersState.filters.filter { filter in
var filters = filtersState.filters.filter { filter in
if hiddenIds.contains(filter.id) {
return false
} else {
return true
}
}
// MARK: Swiftgram
if filters.count > 1 && SGSimpleSettings.shared.allChatsHidden {
filters.removeAll { $0 == .allChats }
}
return filters
}
|> distinctUntilChanged
}
@@ -1269,7 +1322,8 @@ func _internal_updateChatListFeaturedFilters(postbox: Postbox, network: Network)
var state = entry?.get(ChatListFiltersFeaturedState.self) ?? ChatListFiltersFeaturedState(filters: [], isSeen: false)
state.filters = result.compactMap { item -> ChatListFeaturedFilter? in
switch item {
case let .dialogFilterSuggested(filter, description):
case let .dialogFilterSuggested(dialogFilterSuggestedData):
let (filter, description) = (dialogFilterSuggestedData.filter, dialogFilterSuggestedData.description)
let parsedFilter = ChatListFilter(apiFilter: filter)
if case let .filter(_, title, _, data) = parsedFilter {
return ChatListFeaturedFilter(title: title, description: description, data: data)
@@ -1603,4 +1657,4 @@ private func synchronizeChatListFilters(transaction: Transaction, accountPeerId:
)
}
}
}
}
@@ -14,7 +14,8 @@ func _internal_chatOnlineMembers(postbox: Postbox, network: Network, peerId: Pee
return network.request(Api.functions.messages.getOnlines(peer: inputPeer))
|> map { value -> Int32 in
switch value {
case let .chatOnlines(onlines):
case let .chatOnlines(chatOnlinesData):
let onlines = chatOnlinesData.onlines
return onlines
}
}
@@ -72,7 +72,7 @@ func _internal_exportChatFolder(account: Account, filterId: Int32, title: String
}
|> castError(ExportChatFolderError.self)
|> mapToSignal { inputPeers -> Signal<ExportedChatFolderLink, ExportChatFolderError> in
return account.network.request(Api.functions.chatlists.exportChatlistInvite(chatlist: .inputChatlistDialogFilter(filterId: filterId), title: title, peers: inputPeers))
return account.network.request(Api.functions.chatlists.exportChatlistInvite(chatlist: .inputChatlistDialogFilter(.init(filterId: filterId)), title: title, peers: inputPeers))
|> `catch` { error -> Signal<Api.chatlists.ExportedChatlistInvite, ExportChatFolderError> in
if error.errorDescription == "INVITES_TOO_MUCH" || error.errorDescription == "CHATLISTS_TOO_MUCH" {
return account.postbox.transaction { transaction -> (AppConfiguration, Bool) in
@@ -121,7 +121,8 @@ func _internal_exportChatFolder(account: Account, filterId: Int32, title: String
|> mapToSignal { result -> Signal<ExportedChatFolderLink, ExportChatFolderError> in
return account.postbox.transaction { transaction -> Signal<ExportedChatFolderLink, ExportChatFolderError> in
switch result {
case let .exportedChatlistInvite(filter, invite):
case let .exportedChatlistInvite(exportedChatlistInviteData):
let (filter, invite) = (exportedChatlistInviteData.filter, exportedChatlistInviteData.invite)
let parsedFilter = ChatListFilter(apiFilter: filter)
let _ = updateChatListFiltersState(transaction: transaction, { state in
@@ -136,7 +137,8 @@ func _internal_exportChatFolder(account: Account, filterId: Int32, title: String
})
switch invite {
case let .exportedChatlistInvite(flags, title, url, peers):
case let .exportedChatlistInvite(exportedChatlistInviteData):
let (flags, title, url, peers) = (exportedChatlistInviteData.flags, exportedChatlistInviteData.title, exportedChatlistInviteData.url, exportedChatlistInviteData.peers)
return .single(ExportedChatFolderLink(
title: title,
link: url,
@@ -154,7 +156,7 @@ func _internal_exportChatFolder(account: Account, filterId: Int32, title: String
func _internal_getExportedChatFolderLinks(account: Account, id: Int32) -> Signal<[ExportedChatFolderLink]?, NoError> {
let accountPeerId = account.peerId
return account.network.request(Api.functions.chatlists.getExportedInvites(chatlist: .inputChatlistDialogFilter(filterId: id)))
return account.network.request(Api.functions.chatlists.getExportedInvites(chatlist: .inputChatlistDialogFilter(.init(filterId: id))))
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.chatlists.ExportedInvites?, NoError> in
return .single(nil)
@@ -165,14 +167,16 @@ func _internal_getExportedChatFolderLinks(account: Account, id: Int32) -> Signal
}
return account.postbox.transaction { transaction -> [ExportedChatFolderLink]? in
switch result {
case let .exportedInvites(invites, chats, users):
case let .exportedInvites(exportedInvitesData):
let (invites, chats, users) = (exportedInvitesData.invites, exportedInvitesData.chats, exportedInvitesData.users)
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
var result: [ExportedChatFolderLink] = []
for invite in invites {
switch invite {
case let .exportedChatlistInvite(flags, title, url, peers):
case let .exportedChatlistInvite(exportedChatlistInviteData):
let (flags, title, url, peers) = (exportedChatlistInviteData.flags, exportedChatlistInviteData.title, exportedChatlistInviteData.url, exportedChatlistInviteData.peers)
result.append(ExportedChatFolderLink(
title: title,
link: url,
@@ -206,13 +210,14 @@ func _internal_editChatFolderLink(account: Account, filterId: Int32, link: Expor
flags |= 1 << 2
peers = peerIds.compactMap(transaction.getPeer).compactMap(apiInputPeer)
}
return account.network.request(Api.functions.chatlists.editExportedInvite(flags: flags, chatlist: .inputChatlistDialogFilter(filterId: filterId), slug: link.slug, title: title, peers: peers))
return account.network.request(Api.functions.chatlists.editExportedInvite(flags: flags, chatlist: .inputChatlistDialogFilter(.init(filterId: filterId)), slug: link.slug, title: title, peers: peers))
|> mapError { _ -> EditChatFolderLinkError in
return .generic
}
|> map { result in
switch result {
case let .exportedChatlistInvite(flags, title, url, peers):
case let .exportedChatlistInvite(exportedChatlistInviteData):
let (flags, title, url, peers) = (exportedChatlistInviteData.flags, exportedChatlistInviteData.title, exportedChatlistInviteData.url, exportedChatlistInviteData.peers)
return ExportedChatFolderLink(
title: title,
link: url,
@@ -231,7 +236,7 @@ public enum RevokeChatFolderLinkError {
}
func _internal_deleteChatFolderLink(account: Account, filterId: Int32, link: ExportedChatFolderLink) -> Signal<Never, RevokeChatFolderLinkError> {
return account.network.request(Api.functions.chatlists.deleteExportedInvite(chatlist: .inputChatlistDialogFilter(filterId: filterId), slug: link.slug))
return account.network.request(Api.functions.chatlists.deleteExportedInvite(chatlist: .inputChatlistDialogFilter(.init(filterId: filterId)), slug: link.slug))
|> mapError { error -> RevokeChatFolderLinkError in
return .generic
}
@@ -273,7 +278,8 @@ func _internal_checkChatFolderLink(account: Account, slug: String) -> Signal<Cha
|> mapToSignal { result -> Signal<ChatFolderLinkContents, CheckChatFolderLinkError> in
return account.postbox.transaction { transaction -> ChatFolderLinkContents in
switch result {
case let .chatlistInvite(flags, title, emoticon, peers, chats, users):
case let .chatlistInvite(chatlistInviteData):
let (flags, title, emoticon, peers, chats, users) = (chatlistInviteData.flags, chatlistInviteData.title, chatlistInviteData.emoticon, chatlistInviteData.peers, chatlistInviteData.chats, chatlistInviteData.users)
let _ = emoticon
let disableTitleAnimation = (flags & (1 << 1)) != 0
@@ -282,15 +288,16 @@ func _internal_checkChatFolderLink(account: Account, slug: String) -> Signal<Cha
var memberCounts: [PeerId: Int] = [:]
for chat in chats {
if case let .channel(_, _, _, _, _, _, _, _, _, _, _, _, participantsCount, _, _, _, _, _, _, _, _, _, _) = chat {
if case let .channel(channelData) = chat {
let participantsCount = channelData.participantsCount
if let participantsCount = participantsCount {
memberCounts[chat.peerId] = Int(participantsCount)
}
}
}
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
var resultPeers: [EnginePeer] = []
var alreadyMemberPeerIds = Set<EnginePeer.Id>()
for peer in peers {
@@ -306,26 +313,29 @@ func _internal_checkChatFolderLink(account: Account, slug: String) -> Signal<Cha
let titleText: String
let titleEntities: [MessageTextEntity]
switch title {
case let .textWithEntities(text, entities):
case let .textWithEntities(textWithEntitiesData):
let (text, entities) = (textWithEntitiesData.text, textWithEntitiesData.entities)
titleText = text
titleEntities = messageTextEntitiesFromApiEntities(entities)
}
return ChatFolderLinkContents(localFilterId: nil, title: ChatFolderTitle(text: titleText, entities: titleEntities, enableAnimations: !disableTitleAnimation), peers: resultPeers, alreadyMemberPeerIds: alreadyMemberPeerIds, memberCounts: memberCounts)
case let .chatlistInviteAlready(filterId, missingPeers, alreadyPeers, chats, users):
case let .chatlistInviteAlready(chatlistInviteAlreadyData):
let (filterId, missingPeers, alreadyPeers, chats, users) = (chatlistInviteAlreadyData.filterId, chatlistInviteAlreadyData.missingPeers, chatlistInviteAlreadyData.alreadyPeers, chatlistInviteAlreadyData.chats, chatlistInviteAlreadyData.users)
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
var memberCounts: [PeerId: Int] = [:]
for chat in chats {
if case let .channel(_, _, _, _, _, _, _, _, _, _, _, _, participantsCount, _, _, _, _, _, _, _, _, _, _) = chat {
if case let .channel(channelData) = chat {
let participantsCount = channelData.participantsCount
if let participantsCount = participantsCount {
memberCounts[chat.peerId] = Int(participantsCount)
}
}
}
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
let currentFilters = _internal_currentChatListFilters(transaction: transaction)
var currentFilterTitle: ChatFolderTitle?
if let index = currentFilters.firstIndex(where: { $0.id == filterId }) {
@@ -482,7 +492,8 @@ func _internal_joinChatFolderLink(account: Account, slug: String, peerIds: [Engi
var folderResult: JoinChatFolderResult?
for update in result.allUpdates {
if case let .updateDialogFilter(_, id, data) = update {
if case let .updateDialogFilter(updateDialogFilterData) = update {
let (id, data) = (updateDialogFilterData.id, updateDialogFilterData.filter)
if let data = data, case let .filter(_, title, _, _) = ChatListFilter(apiFilter: data) {
folderResult = JoinChatFolderResult(folderId: id, title: title, newChatCount: newChatCount)
}
@@ -586,7 +597,7 @@ func _internal_pollChatFolderUpdatesOnce(account: Account, folderId: Int32) -> S
firstTimeFolderUpdates.insert(key)
}
return account.network.request(Api.functions.chatlists.getChatlistUpdates(chatlist: .inputChatlistDialogFilter(filterId: folderId)))
return account.network.request(Api.functions.chatlists.getChatlistUpdates(chatlist: .inputChatlistDialogFilter(.init(filterId: folderId))))
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.chatlists.ChatlistUpdates?, NoError> in
return .single(nil)
@@ -606,21 +617,23 @@ func _internal_pollChatFolderUpdatesOnce(account: Account, folderId: Int32) -> S
|> ignoreValues
}
switch result {
case let .chatlistUpdates(missingPeers, chats, users):
case let .chatlistUpdates(chatlistUpdatesData):
let (missingPeers, chats, users) = (chatlistUpdatesData.missingPeers, chatlistUpdatesData.chats, chatlistUpdatesData.users)
return account.postbox.transaction { transaction -> Void in
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
var memberCounts: [ChatListFiltersState.ChatListFilterUpdates.MemberCount] = []
for chat in chats {
if case let .channel(_, _, _, _, _, _, _, _, _, _, _, _, participantsCount, _, _, _, _, _, _, _, _, _, _) = chat {
if case let .channel(channelData) = chat {
let participantsCount = channelData.participantsCount
if let participantsCount = participantsCount {
memberCounts.append(ChatListFiltersState.ChatListFilterUpdates.MemberCount(id: chat.peerId, count: participantsCount))
}
}
}
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
let _ = updateChatListFiltersState(transaction: transaction, { state in
var state = state
@@ -687,7 +700,7 @@ func _internal_joinAvailableChatsInFolder(account: Account, updates: ChatFolderU
}
|> castError(JoinChatFolderLinkError.self)
|> mapToSignal { inputPeers -> Signal<Never, JoinChatFolderLinkError> in
return account.network.request(Api.functions.chatlists.joinChatlistUpdates(chatlist: .inputChatlistDialogFilter(filterId: updates.folderId), peers: inputPeers))
return account.network.request(Api.functions.chatlists.joinChatlistUpdates(chatlist: .inputChatlistDialogFilter(.init(filterId: updates.folderId)), peers: inputPeers))
|> `catch` { error -> Signal<Api.Updates, JoinChatFolderLinkError> in
if error.errorDescription == "DIALOG_FILTERS_TOO_MUCH" {
return account.postbox.transaction { transaction -> (AppConfiguration, Bool) in
@@ -742,7 +755,7 @@ func _internal_hideChatFolderUpdates(account: Account, folderId: Int32) -> Signa
})
}
|> mapToSignal { _ -> Signal<Never, NoError> in
return account.network.request(Api.functions.chatlists.hideChatlistUpdates(chatlist: .inputChatlistDialogFilter(filterId: folderId)))
return account.network.request(Api.functions.chatlists.hideChatlistUpdates(chatlist: .inputChatlistDialogFilter(.init(filterId: folderId))))
|> `catch` { _ -> Signal<Api.Bool, NoError> in
return .single(.boolFalse)
}
@@ -755,7 +768,7 @@ func _internal_leaveChatFolder(account: Account, folderId: Int32, removePeerIds:
return removePeerIds.compactMap(transaction.getPeer).compactMap(apiInputPeer)
}
|> mapToSignal { inputPeers -> Signal<Never, NoError> in
return account.network.request(Api.functions.chatlists.leaveChatlist(chatlist: .inputChatlistDialogFilter(filterId: folderId), peers: inputPeers))
return account.network.request(Api.functions.chatlists.leaveChatlist(chatlist: .inputChatlistDialogFilter(.init(filterId: folderId)), peers: inputPeers))
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.Updates?, NoError> in
return .single(nil)
@@ -772,7 +785,7 @@ func _internal_leaveChatFolder(account: Account, folderId: Int32, removePeerIds:
}
func _internal_requestLeaveChatFolderSuggestions(account: Account, folderId: Int32) -> Signal<[EnginePeer.Id], NoError> {
return account.network.request(Api.functions.chatlists.getLeaveChatlistSuggestions(chatlist: .inputChatlistDialogFilter(filterId: folderId)))
return account.network.request(Api.functions.chatlists.getLeaveChatlistSuggestions(chatlist: .inputChatlistDialogFilter(.init(filterId: folderId))))
|> map { result -> [EnginePeer.Id] in
return result.map(\.peerId)
}
@@ -26,7 +26,8 @@ func _internal_exportContactToken(account: Account) -> Signal<ExportedContactTok
return .single(nil)
}
|> map { result -> ExportedContactToken? in
if let result = result, case let .exportedContactToken(url, expires) = result {
if let result = result, case let .exportedContactToken(exportedContactTokenData) = result {
let (url, expires) = (exportedContactTokenData.url, exportedContactTokenData.expires)
return ExportedContactToken(url: url, expires: expires)
} else {
return nil
@@ -58,7 +58,8 @@ func _internal_createGroup(account: Account, title: String, peerIds: [PeerId], t
let updatesValue: Api.Updates
let missingInviteesValue: [Api.MissingInvitee]
switch result {
case let .invitedUsers(updates, missingInvitees):
case let .invitedUsers(invitedUsersData):
let (updates, missingInvitees) = (invitedUsersData.updates, invitedUsersData.missingInvitees)
updatesValue = updates
missingInviteesValue = missingInvitees
}
@@ -77,7 +78,8 @@ func _internal_createGroup(account: Account, title: String, peerIds: [PeerId], t
peerId: peerId,
result: TelegramInvitePeersResult(forbiddenPeers: missingInviteesValue.compactMap { invitee -> TelegramForbiddenInvitePeer? in
switch invitee {
case let .missingInvitee(flags, userId):
case let .missingInvitee(missingInviteeData):
let (flags, userId) = (missingInviteeData.flags, missingInviteeData.userId)
guard let peer = transaction.getPeer(PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))) else {
return nil
}
@@ -4,7 +4,7 @@ import Postbox
import TelegramApi
func _internal_findChannelById(accountPeerId: PeerId, postbox: Postbox, network: Network, channelId: Int64) -> Signal<Peer?, NoError> {
return network.request(Api.functions.channels.getChannels(id: [.inputChannel(channelId: channelId, accessHash: 0)]))
return network.request(Api.functions.channels.getChannels(id: [.inputChannel(.init(channelId: channelId, accessHash: 0))]))
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.messages.Chats?, NoError> in
return .single(nil)
@@ -16,9 +16,11 @@ func _internal_findChannelById(accountPeerId: PeerId, postbox: Postbox, network:
}
let chats: [Api.Chat]
switch result {
case let .chats(apiChats):
case let .chats(chatsData):
let apiChats = chatsData.chats
chats = apiChats
case let .chatsSlice(_, apiChats):
case let .chatsSlice(chatsSliceData):
let (_, apiChats) = (chatsSliceData.count, chatsSliceData.chats)
chats = apiChats
}
guard let id = chats.first?.peerId else {
@@ -108,10 +108,12 @@ private final class GroupsInCommonContextImpl {
let count: Int?
if let result = result {
switch result {
case let .chats(apiChats):
case let .chats(chatsData):
let apiChats = chatsData.chats
chats = apiChats
count = nil
case let .chatsSlice(apiCount, apiChats):
case let .chatsSlice(chatsSliceData):
let (apiCount, apiChats) = (chatsSliceData.count, chatsSliceData.chats)
chats = apiChats
count = Int(apiCount)
}
@@ -24,14 +24,16 @@ func _internal_inactiveChannelList(network: Network) -> Signal<[InactiveChannel]
|> retryRequest
|> map { result in
switch result {
case let .inactiveChats(dates, chats, _):
case let .inactiveChats(inactiveChatsData):
let (dates, chats) = (inactiveChatsData.dates, inactiveChatsData.chats)
let channels = chats.compactMap {
parseTelegramGroupOrChannel(chat: $0)
}
var participantsCounts: [PeerId: Int32] = [:]
for chat in chats {
switch chat {
case let .channel(_, _, _, _, _, _, _, _, _, _, _, _, participantsCountValue, _, _, _, _, _, _, _, _, _, _):
case let .channel(channelData):
let participantsCountValue = channelData.participantsCount
if let participantsCountValue = participantsCountValue {
participantsCounts[chat.peerId] = participantsCountValue
}
@@ -147,7 +147,8 @@ func _internal_editPeerExportedInvitation(account: Account, peerId: PeerId, link
|> mapError { _ in return EditPeerExportedInvitationError.generic }
|> mapToSignal { result -> Signal<ExportedInvitation?, EditPeerExportedInvitationError> in
return account.postbox.transaction { transaction in
if case let .exportedChatInvite(invite, users) = result {
if case let .exportedChatInvite(exportedChatInviteData) = result {
let (invite, users) = (exportedChatInviteData.invite, exportedChatInviteData.users)
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: AccumulatedPeers(users: users))
return ExportedInvitation(apiExportedInvite: invite)
} else {
@@ -181,10 +182,12 @@ func _internal_revokePeerExportedInvitation(account: Account, peerId: PeerId, li
|> mapError { _ in return RevokePeerExportedInvitationError.generic }
|> mapToSignal { result -> Signal<RevokeExportedInvitationResult?, RevokePeerExportedInvitationError> in
return account.postbox.transaction { transaction in
if case let .exportedChatInvite(invite, users) = result {
if case let .exportedChatInvite(exportedChatInviteData) = result {
let (invite, users) = (exportedChatInviteData.invite, exportedChatInviteData.users)
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: AccumulatedPeers(users: users))
return .update(ExportedInvitation(apiExportedInvite: invite))
} else if case let .exportedChatInviteReplaced(invite, newInvite, users) = result {
} else if case let .exportedChatInviteReplaced(exportedChatInviteReplacedData) = result {
let (invite, newInvite, users) = (exportedChatInviteReplacedData.invite, exportedChatInviteReplacedData.newInvite, exportedChatInviteReplacedData.users)
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: AccumulatedPeers(users: users))
let previous = ExportedInvitation(apiExportedInvite: invite)
@@ -243,7 +246,8 @@ func _internal_peerExportedInvitations(account: Account, peerId: PeerId, revoked
}
|> mapToSignal { result -> Signal<ExportedInvitations?, NoError> in
return account.postbox.transaction { transaction -> ExportedInvitations? in
if let result = result, case let .exportedChatInvites(count, apiInvites, users) = result {
if let result = result, case let .exportedChatInvites(exportedChatInvitesData) = result {
let (count, apiInvites, users) = (exportedChatInvitesData.count, exportedChatInvitesData.invites, exportedChatInvitesData.users)
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: [], users: users)
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
@@ -465,7 +469,8 @@ private final class PeerExportedInvitationsContextImpl {
return ([], 0)
}
switch result {
case let .exportedChatInvites(count, invites, users):
case let .exportedChatInvites(exportedChatInvitesData):
let (count, invites, users) = (exportedChatInvitesData.count, exportedChatInvitesData.invites, exportedChatInvitesData.users)
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: AccumulatedPeers(users: users))
let invitations: [ExportedInvitation] = invites.compactMap { ExportedInvitation(apiExportedInvite: $0) }
if populateCache {
@@ -948,7 +953,8 @@ private final class PeerInvitationImportersContextImpl {
return ([], 0)
}
switch result {
case let .chatInviteImporters(count, importers, users):
case let .chatInviteImporters(chatInviteImportersData):
let (count, importers, users) = (chatInviteImportersData.count, chatInviteImportersData.importers, chatInviteImportersData.users)
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: AccumulatedPeers(users: users))
var resultImporters: [PeerInvitationImportersState.Importer] = []
for importer in importers {
@@ -958,7 +964,8 @@ private final class PeerInvitationImportersContextImpl {
let approvedBy: PeerId?
let joinedViaFolderLink: Bool
switch importer {
case let .chatInviteImporter(flags, userId, dateValue, aboutValue, approvedByValue):
case let .chatInviteImporter(chatInviteImporterData):
let (flags, userId, dateValue, aboutValue, approvedByValue) = (chatInviteImporterData.flags, chatInviteImporterData.userId, chatInviteImporterData.date, chatInviteImporterData.about, chatInviteImporterData.approvedBy)
joinedViaFolderLink = (flags & (1 << 3)) != 0
peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
date = dateValue
@@ -1161,14 +1168,16 @@ func _internal_peerExportedInvitationsCreators(account: Account, peerId: PeerId)
}
|> mapToSignal { result -> Signal<[ExportedInvitationCreator], NoError> in
return account.postbox.transaction { transaction -> [ExportedInvitationCreator] in
if let result = result, case let .chatAdminsWithInvites(admins, users) = result {
if let result = result, case let .chatAdminsWithInvites(chatAdminsWithInvitesData) = result {
let (admins, users) = (chatAdminsWithInvitesData.admins, chatAdminsWithInvitesData.users)
var creators: [ExportedInvitationCreator] = []
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: [], users: users)
for admin in admins {
switch admin {
case let .chatAdminWithInvites(adminId, invitesCount, revokedInvitesCount):
case let .chatAdminWithInvites(chatAdminWithInvitesData):
let (adminId, invitesCount, revokedInvitesCount) = (chatAdminWithInvitesData.adminId, chatAdminWithInvitesData.invitesCount, chatAdminWithInvitesData.revokedInvitesCount)
let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(adminId))
if let peer = parsedPeers.get(peerId), peerId != account.peerId {
creators.append(ExportedInvitationCreator(peer: RenderedPeer(peer: peer), count: invitesCount, revokedCount: revokedInvitesCount))
@@ -67,7 +67,8 @@ func _internal_joinChannel(account: Account, peerId: PeerId, hash: String?) -> S
}
let updatedParticipant: ChannelParticipant
switch result {
case let .channelParticipant(participant, _, _):
case let .channelParticipant(channelParticipantData):
let participant = channelParticipantData.participant
updatedParticipant = ChannelParticipant(apiParticipant: participant)
}
if case let .member(_, _, maybeAdminInfo, _, _, _) = updatedParticipant {
@@ -19,9 +19,11 @@ public enum JoinLinkError {
func apiUpdatesGroups(_ updates: Api.Updates) -> [Api.Chat] {
switch updates {
case let .updates( _, _, chats, _, _):
case let .updates(updatesData):
let chats = updatesData.chats
return chats
case let .updatesCombined(_, _, chats, _, _, _):
case let .updatesCombined(updatesCombinedData):
let chats = updatesCombinedData.chats
return chats
default:
return []
@@ -110,11 +112,13 @@ func _internal_joinLinkInformation(_ hash: String, account: Account) -> Signal<E
|> mapToSignal { result -> Signal<ExternalJoiningChatState, JoinLinkInfoError> in
if let result = result {
switch result {
case let .chatInvite(flags, title, about, invitePhoto, participantsCount, participants, nameColor, subscriptionPricing, subscriptionFormId, verification):
case let .chatInvite(chatInviteData):
let (apiFlags, title, about, invitePhoto, participantsCount, participants, nameColor, subscriptionPricing, subscriptionFormId, verification) = (chatInviteData.flags, chatInviteData.title, chatInviteData.about, chatInviteData.photo, chatInviteData.participantsCount, chatInviteData.participants, chatInviteData.color, chatInviteData.subscriptionPricing, chatInviteData.subscriptionFormId, chatInviteData.botVerification)
let photo = telegramMediaImageFromApiPhoto(invitePhoto).flatMap({ smallestImageRepresentation($0.representations) })
let flags: ExternalJoiningChatState.Invite.Flags = .init(isChannel: (flags & (1 << 0)) != 0, isBroadcast: (flags & (1 << 1)) != 0, isPublic: (flags & (1 << 2)) != 0, isMegagroup: (flags & (1 << 3)) != 0, requestNeeded: (flags & (1 << 6)) != 0, isVerified: (flags & (1 << 7)) != 0, isScam: (flags & (1 << 8)) != 0, isFake: (flags & (1 << 9)) != 0, canRefulfillSubscription: (flags & (1 << 11)) != 0)
let flags: ExternalJoiningChatState.Invite.Flags = .init(isChannel: (apiFlags & (1 << 0)) != 0, isBroadcast: (apiFlags & (1 << 1)) != 0, isPublic: (apiFlags & (1 << 2)) != 0, isMegagroup: (apiFlags & (1 << 3)) != 0, requestNeeded: (apiFlags & (1 << 6)) != 0, isVerified: (apiFlags & (1 << 7)) != 0, isScam: (apiFlags & (1 << 8)) != 0, isFake: (apiFlags & (1 << 9)) != 0, canRefulfillSubscription: (apiFlags & (1 << 11)) != 0)
return .single(.invite(ExternalJoiningChatState.Invite(flags: flags, title: title, about: about, photoRepresentation: photo, participantsCount: participantsCount, participants: participants?.map({ EnginePeer(TelegramUser(user: $0)) }), nameColor: PeerNameColor(rawValue: nameColor), subscriptionPricing: subscriptionPricing.flatMap { StarsSubscriptionPricing(apiStarsSubscriptionPricing: $0) }, subscriptionFormId: subscriptionFormId, verification: verification.flatMap { PeerVerification(apiBotVerification: $0) })))
case let .chatInviteAlready(chat):
case let .chatInviteAlready(chatInviteAlreadyData):
let chat = chatInviteAlreadyData.chat
if let peer = parseTelegramGroupOrChannel(chat: chat) {
return account.postbox.transaction({ (transaction) -> ExternalJoiningChatState in
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: [chat], users: [])
@@ -124,7 +128,8 @@ func _internal_joinLinkInformation(_ hash: String, account: Account) -> Signal<E
|> castError(JoinLinkInfoError.self)
}
return .single(.invalidHash)
case let .chatInvitePeek(chat, expires):
case let .chatInvitePeek(chatInvitePeekData):
let (chat, expires) = (chatInvitePeekData.chat, chatInvitePeekData.expires)
if let peer = parseTelegramGroupOrChannel(chat: chat) {
return account.postbox.transaction({ (transaction) -> ExternalJoiningChatState in
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: [chat], users: [])
@@ -16,9 +16,11 @@ func _internal_availableGroupsForChannelDiscussion(accountPeerId: PeerId, postbo
|> mapToSignal { result -> Signal<[Peer], AvailableChannelDiscussionGroupError> in
let chats: [Api.Chat]
switch result {
case let .chats(c):
case let .chats(chatsData):
let c = chatsData.chats
chats = c
case let .chatsSlice(_, c):
case let .chatsSlice(chatsSliceData):
let c = chatsSliceData.chats
chats = c
}
@@ -34,31 +34,37 @@ func _internal_notificationExceptionsList(accountPeerId: PeerId, postbox: Postbo
}
return postbox.transaction { transaction -> NotificationExceptionsList in
switch result {
case let .updates(updates, users, chats, _, _):
case let .updates(updatesData):
let (updates, users, chats) = (updatesData.updates, updatesData.users, updatesData.chats)
var settings: [PeerId: TelegramPeerNotificationSettings] = [:]
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
updatePeers(transaction: transaction, accountPeerId: accountPeerId,peers: parsedPeers)
var peers: [PeerId: Peer] = [:]
for id in parsedPeers.allIds {
if let peer = transaction.getPeer(id) {
peers[peer.id] = peer
}
}
for update in updates {
switch update {
case let .updateNotifySettings(apiPeer, notifySettings):
case let .updateNotifySettings(updateNotifySettingsData):
let (apiPeer, notifySettings) = (updateNotifySettingsData.peer, updateNotifySettingsData.notifySettings)
switch apiPeer {
case let .notifyPeer(notifyPeer):
case let .notifyPeer(notifyPeerData):
let notifyPeer = notifyPeerData.peer
let peerId: PeerId
switch notifyPeer {
case let .peerUser(userId):
case let .peerUser(peerUserData):
let userId = peerUserData.userId
peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
case let .peerChat(chatId):
case let .peerChat(peerChatData):
let chatId = peerChatData.chatId
peerId = PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(chatId))
case let .peerChannel(channelId):
case let .peerChannel(peerChannelData):
let channelId = peerChannelData.channelId
peerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId))
}
settings[peerId] = TelegramPeerNotificationSettings(apiSettings: notifySettings)
@@ -180,7 +180,8 @@ func requestNotificationSoundList(network: Network, hash: Int64) -> Signal<Notif
}
switch result {
case let .savedRingtones(hash, ringtones):
case let .savedRingtones(savedRingtonesData):
let (hash, ringtones) = (savedRingtonesData.hash, savedRingtonesData.ringtones)
let notificationSoundList = NotificationSoundList(
hash: hash,
sounds: ringtones.compactMap(NotificationSoundList.NotificationSound.init(apiDocument:))
@@ -207,7 +208,8 @@ private func pollNotificationSoundList(postbox: Postbox, network: Network) -> Si
return .complete()
}
switch result {
case let .savedRingtones(hash, ringtones):
case let .savedRingtones(savedRingtonesData):
let (hash, ringtones) = (savedRingtonesData.hash, savedRingtonesData.ringtones)
let notificationSoundList = NotificationSoundList(
hash: hash,
sounds: ringtones.compactMap(NotificationSoundList.NotificationSound.init(apiDocument:))
@@ -269,7 +271,7 @@ func _internal_saveNotificationSound(account: Account, file: FileMediaReference,
return .fail(.generic)
}
let accountPeerId = account.peerId
return account.network.request(Api.functions.account.saveRingtone(id: .inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference)), unsave: unsave ? .boolTrue : .boolFalse))
return account.network.request(Api.functions.account.saveRingtone(id: .inputDocument(.init(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference))), unsave: unsave ? .boolTrue : .boolFalse))
|> `catch` { error -> Signal<Api.account.SavedRingtone, MTRpcError> in
if error.errorDescription == "FILE_REFERENCE_EXPIRED" {
return revalidateMediaResourceReference(accountPeerId: accountPeerId, postbox: account.postbox, network: account.network, revalidationContext: account.mediaReferenceRevalidationContext, info: TelegramCloudMediaResourceFetchInfo(reference: file.abstract.resourceReference(file.media.resource), preferBackgroundReferenceRevalidation: false, continueInBackground: false), resource: file.media.resource)
@@ -280,8 +282,8 @@ func _internal_saveNotificationSound(account: Account, file: FileMediaReference,
guard let resource = result.updatedResource as? CloudDocumentMediaResource else {
return .fail(MTRpcError(errorCode: 500, errorDescription: "Internal"))
}
return account.network.request(Api.functions.account.saveRingtone(id: .inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference)), unsave: unsave ? .boolTrue : .boolFalse))
return account.network.request(Api.functions.account.saveRingtone(id: .inputDocument(.init(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference))), unsave: unsave ? .boolTrue : .boolFalse))
}
} else {
return .fail(error)
@@ -354,7 +356,7 @@ func _internal_deleteNotificationSound(account: Account, fileId: Int64) -> Signa
return .fail(.generic)
}
return account.network.request(Api.functions.account.saveRingtone(id: .inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference)), unsave: .boolTrue))
return account.network.request(Api.functions.account.saveRingtone(id: .inputDocument(.init(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference))), unsave: .boolTrue))
|> mapError { _ -> DeleteNotificationSoundError in
return .generic
}
@@ -133,7 +133,8 @@ func _internal_fetchChannelParticipant(account: Account, peerId: PeerId, partici
return account.network.request(Api.functions.channels.getParticipant(channel: inputChannel, participant: inputPeer))
|> map { result -> ChannelParticipant? in
switch result {
case let .channelParticipant(participant, _, _):
case let .channelParticipant(channelParticipantData):
let participant = channelParticipantData.participant
return ChannelParticipant(apiParticipant: participant)
}
}
@@ -183,7 +184,7 @@ func _internal_updateChannelAdminRights(account: Account, peerId: PeerId, adminI
}
updatedParticipant = .member(id: adminId, invitedAt: Int32(Date().timeIntervalSince1970), adminInfo: adminInfo, banInfo: nil, rank: rank, subscriptionUntilDate: nil)
}
return account.network.request(Api.functions.channels.editAdmin(channel: inputChannel, userId: inputUser, adminRights: rights?.apiAdminRights ?? .chatAdminRights(flags: 0), rank: rank ?? ""))
return account.network.request(Api.functions.channels.editAdmin(channel: inputChannel, userId: inputUser, adminRights: rights?.apiAdminRights ?? .chatAdminRights(Api.ChatAdminRights.Cons_chatAdminRights(flags: 0)), rank: rank ?? ""))
|> map { [$0] }
|> `catch` { error -> Signal<[Api.Updates], UpdateChannelAdminRightsError> in
if error.errorDescription == "USER_NOT_PARTICIPANT" {
@@ -195,7 +196,7 @@ func _internal_updateChannelAdminRights(account: Account, peerId: PeerId, adminI
return .addMemberError(error)
}
|> then(
account.network.request(Api.functions.channels.editAdmin(channel: inputChannel, userId: inputUser, adminRights: rights?.apiAdminRights ?? .chatAdminRights(flags: 0), rank: rank ?? ""))
account.network.request(Api.functions.channels.editAdmin(channel: inputChannel, userId: inputUser, adminRights: rights?.apiAdminRights ?? .chatAdminRights(Api.ChatAdminRights.Cons_chatAdminRights(flags: 0)), rank: rank ?? ""))
|> mapError { error -> UpdateChannelAdminRightsError in
return .generic
}
@@ -58,7 +58,7 @@ public struct UploadedPeerPhotoData {
}
static func withResource(_ resource: MediaResource) -> UploadedPeerPhotoData {
return UploadedPeerPhotoData(resource: resource, content: .result(.inputFile(.inputFile(id: 0, parts: 0, name: "", md5Checksum: ""))), local: true)
return UploadedPeerPhotoData(resource: resource, content: .result(.inputFile(.inputFile(.init(id: 0, parts: 0, name: "", md5Checksum: "")))), local: true)
}
}
@@ -109,9 +109,9 @@ func _internal_updatePeerPhotoInternal(postbox: Postbox, network: Network, state
if let markup = markup {
switch markup {
case let .emoji(fileId, backgroundColors):
videoEmojiMarkup = .videoSizeEmojiMarkup(emojiId: fileId, backgroundColors: backgroundColors)
videoEmojiMarkup = .videoSizeEmojiMarkup(.init(emojiId: fileId, backgroundColors: backgroundColors))
case let .sticker(packReference, fileId, backgroundColors):
videoEmojiMarkup = .videoSizeStickerMarkup(stickerset: packReference.apiInputStickerSet, stickerId: fileId, backgroundColors: backgroundColors)
videoEmojiMarkup = .videoSizeStickerMarkup(.init(stickerset: packReference.apiInputStickerSet, stickerId: fileId, backgroundColors: backgroundColors))
}
}
@@ -164,8 +164,8 @@ func _internal_updatePeerPhotoInternal(postbox: Postbox, network: Network, state
case let .progress(progress):
let mappedProgress = 0.2 + progress * 0.8
return .single((.progress(mappedProgress), photoResult.resource, videoResult.resource))
case let .inputFile(file):
videoFile = file
case let .inputFile(videoInputFile):
videoFile = videoInputFile
break
default:
return .fail(.generic)
@@ -235,22 +235,26 @@ func _internal_updatePeerPhotoInternal(postbox: Postbox, network: Network, state
var videoRepresentations: [TelegramMediaImage.VideoRepresentation] = []
var image: TelegramMediaImage?
switch photo {
case let .photo(apiPhoto, _):
case let .photo(photoData):
let (apiPhoto, _) = (photoData.photo, photoData.users)
image = telegramMediaImageFromApiPhoto(apiPhoto)
switch apiPhoto {
case .photoEmpty:
break
case let .photo(_, id, accessHash, fileReference, _, sizes, videoSizes, dcId):
var sizes = sizes
case let .photo(photoData):
let (id, accessHash, fileReference, apiSizes, videoSizes, dcId) = (photoData.id, photoData.accessHash, photoData.fileReference, photoData.sizes, photoData.videoSizes, photoData.dcId)
var sizes = apiSizes
if sizes.count == 3 {
sizes.remove(at: 1)
}
for size in sizes {
switch size {
case let .photoSize(_, w, h, _):
case let .photoSize(photoSizeData):
let (w, h) = (photoSizeData.w, photoSizeData.h)
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: CloudPeerPhotoSizeMediaResource(datacenterId: dcId, photoId: id, sizeSpec: w <= 200 ? .small : .fullSize, volumeId: nil, localId: nil), progressiveSizes: [], immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
case let .photoSizeProgressive(_, w, h, sizes):
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: CloudPeerPhotoSizeMediaResource(datacenterId: dcId, photoId: id, sizeSpec: w <= 200 ? .small : .fullSize, volumeId: nil, localId: nil), progressiveSizes: sizes, immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
case let .photoSizeProgressive(photoSizeProgressiveData):
let (w, h, progressiveSizes) = (photoSizeProgressiveData.w, photoSizeProgressiveData.h, photoSizeProgressiveData.sizes)
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: CloudPeerPhotoSizeMediaResource(datacenterId: dcId, photoId: id, sizeSpec: w <= 200 ? .small : .fullSize, volumeId: nil, localId: nil), progressiveSizes: progressiveSizes, immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
default:
break
}
@@ -259,10 +263,11 @@ func _internal_updatePeerPhotoInternal(postbox: Postbox, network: Network, state
if let videoSizes = videoSizes {
for size in videoSizes {
switch size {
case let .videoSize(_, type, w, h, size, videoStartTs):
case let .videoSize(videoSizeData):
let (_, type, w, h, size, videoStartTs) = (videoSizeData.flags, videoSizeData.type, videoSizeData.w, videoSizeData.h, videoSizeData.size, videoSizeData.videoStartTs)
let resource: TelegramMediaResource
resource = CloudPhotoSizeMediaResource(datacenterId: dcId, photoId: id, accessHash: accessHash, sizeSpec: type, size: Int64(size), fileReference: fileReference.makeData())
videoRepresentations.append(TelegramMediaImage.VideoRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: resource, startTimestamp: videoStartTs))
case .videoSizeEmojiMarkup, .videoSizeStickerMarkup:
break
@@ -339,9 +344,9 @@ func _internal_updatePeerPhotoInternal(postbox: Postbox, network: Network, state
let request: Signal<Api.Updates, MTRpcError>
if let peer = peer as? TelegramGroup {
request = network.request(Api.functions.messages.editChatPhoto(chatId: peer.id.id._internalGetInt64Value(), photo: .inputChatUploadedPhoto(flags: flags, file: file, video: videoFile, videoStartTs: videoStartTimestamp, videoEmojiMarkup: videoEmojiMarkup)))
request = network.request(Api.functions.messages.editChatPhoto(chatId: peer.id.id._internalGetInt64Value(), photo: .inputChatUploadedPhoto(.init(flags: flags, file: file, video: videoFile, videoStartTs: videoStartTimestamp, videoEmojiMarkup: videoEmojiMarkup))))
} else if let peer = peer as? TelegramChannel, let inputChannel = apiInputChannel(peer) {
request = network.request(Api.functions.channels.editPhoto(channel: inputChannel, photo: .inputChatUploadedPhoto(flags: flags, file: file, video: videoFile, videoStartTs: videoStartTimestamp, videoEmojiMarkup: videoEmojiMarkup)))
request = network.request(Api.functions.channels.editPhoto(channel: inputChannel, photo: .inputChatUploadedPhoto(.init(flags: flags, file: file, video: videoFile, videoStartTs: videoStartTimestamp, videoEmojiMarkup: videoEmojiMarkup))))
} else {
assertionFailure()
request = .complete()
@@ -447,22 +452,26 @@ func _internal_updatePeerPhotoInternal(postbox: Postbox, network: Network, state
var updatedImage: TelegramMediaImage?
var representations: [TelegramMediaImageRepresentation] = []
switch photo {
case let .photo(apiPhoto, _):
case let .photo(photoData):
let (apiPhoto, _) = (photoData.photo, photoData.users)
updatedImage = telegramMediaImageFromApiPhoto(apiPhoto)
switch apiPhoto {
case .photoEmpty:
break
case let .photo(_, id, _, _, _, sizes, _, dcId):
var sizes = sizes
case let .photo(photoData):
let (id, apiSizes, dcId) = (photoData.id, photoData.sizes, photoData.dcId)
var sizes = apiSizes
if sizes.count == 3 {
sizes.remove(at: 1)
}
for size in sizes {
switch size {
case let .photoSize(_, w, h, _):
case let .photoSize(photoSizeData):
let (w, h) = (photoSizeData.w, photoSizeData.h)
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: CloudPeerPhotoSizeMediaResource(datacenterId: dcId, photoId: id, sizeSpec: w <= 200 ? .small : .fullSize, volumeId: nil, localId: nil), progressiveSizes: [], immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
case let .photoSizeProgressive(_, w, h, sizes):
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: CloudPeerPhotoSizeMediaResource(datacenterId: dcId, photoId: id, sizeSpec: w <= 200 ? .small : .fullSize, volumeId: nil, localId: nil), progressiveSizes: sizes, immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
case let .photoSizeProgressive(photoSizeProgressiveData):
let (w, h, progressiveSizes) = (photoSizeProgressiveData.w, photoSizeProgressiveData.h, photoSizeProgressiveData.sizes)
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: CloudPeerPhotoSizeMediaResource(datacenterId: dcId, photoId: id, sizeSpec: w <= 200 ? .small : .fullSize, volumeId: nil, localId: nil), progressiveSizes: progressiveSizes, immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
default:
break
}
@@ -495,7 +504,8 @@ func _internal_updatePeerPhotoInternal(postbox: Postbox, network: Network, state
} else {
var updatedUsers: [TelegramUser] = []
switch photo {
case let .photo(_, apiUsers):
case let .photo(photoData):
let (_, apiUsers) = (photoData.photo, photoData.users)
updatedUsers = apiUsers.map { TelegramUser(user: $0) }
}
return postbox.transaction { transaction -> UpdatePeerPhotoStatus in
@@ -573,12 +583,13 @@ func _internal_updatePeerPhotoInternal(postbox: Postbox, network: Network, state
func _internal_updatePeerPhotoExisting(network: Network, reference: TelegramMediaImageReference) -> Signal<TelegramMediaImage?, NoError> {
switch reference {
case let .cloud(imageId, accessHash, fileReference):
return network.request(Api.functions.photos.updateProfilePhoto(flags: 0, bot: nil, id: .inputPhoto(id: imageId, accessHash: accessHash, fileReference: Buffer(data: fileReference))))
return network.request(Api.functions.photos.updateProfilePhoto(flags: 0, bot: nil, id: .inputPhoto(.init(id: imageId, accessHash: accessHash, fileReference: Buffer(data: fileReference)))))
|> `catch` { _ -> Signal<Api.photos.Photo, NoError> in
return .complete()
}
|> mapToSignal { photo -> Signal<TelegramMediaImage?, NoError> in
if case let .photo(photo, _) = photo {
if case let .photo(photoData) = photo {
let (photo, _) = (photoData.photo, photoData.users)
return .single(telegramMediaImageFromApiPhoto(photo))
} else {
return .complete()
@@ -592,7 +603,7 @@ func _internal_removeAccountPhoto(account: Account, reference: TelegramMediaImag
switch reference {
case let .cloud(imageId, accessHash, fileReference):
if let fileReference = fileReference {
return account.network.request(Api.functions.photos.deletePhotos(id: [.inputPhoto(id: imageId, accessHash: accessHash, fileReference: Buffer(data: fileReference))]))
return account.network.request(Api.functions.photos.deletePhotos(id: [.inputPhoto(.init(id: imageId, accessHash: accessHash, fileReference: Buffer(data: fileReference)))]))
|> `catch` { _ -> Signal<[Int64], NoError> in
return .single([])
}
@@ -68,7 +68,8 @@ public func _internal_managedUpdatedRecentPeers(accountPeerId: PeerId, postbox:
|> mapToSignal { result -> Signal<Void, NoError> in
return postbox.transaction { transaction -> Void in
switch result {
case let .topPeers(_, _, users):
case let .topPeers(topPeersData):
let users = topPeersData.users
let parsedPeers = AccumulatedPeers(users: users)
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
@@ -156,16 +157,19 @@ func _internal_managedRecentlyUsedInlineBots(postbox: Postbox, network: Network,
switch result {
case .topPeersDisabled:
break
case let .topPeers(categories, _, users):
case let .topPeers(topPeersData):
let (categories, users) = (topPeersData.categories, topPeersData.users)
let parsedPeers = AccumulatedPeers(users: users)
var peersWithRating: [(PeerId, Double)] = []
for category in categories {
switch category {
case let .topPeerCategoryPeers(_, _, topPeers):
case let .topPeerCategoryPeers(topPeerCategoryPeersData):
let (_, _, topPeers) = (topPeerCategoryPeersData.category, topPeerCategoryPeersData.count, topPeerCategoryPeersData.peers)
for topPeer in topPeers {
switch topPeer {
case let .topPeer(apiPeer, rating):
case let .topPeer(topPeerData):
let (apiPeer, rating) = (topPeerData.peer, topPeerData.rating)
peersWithRating.append((apiPeer.peerId, rating))
}
}
@@ -287,7 +291,8 @@ public func _internal_managedUpdatedRecentApps(accountPeerId: PeerId, postbox: P
|> mapToSignal { result -> Signal<Void, NoError> in
return postbox.transaction { transaction -> Void in
switch result {
case let .topPeers(_, _, users):
case let .topPeers(topPeersData):
let users = topPeersData.users
let parsedPeers = AccumulatedPeers(users: users)
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
@@ -1,7 +1,8 @@
import Foundation
import Postbox
import SwiftSignalKit
import TelegramApi
import MtProtoKit
func _internal_removePeerChat(account: Account, peerId: PeerId, reportChatSpam: Bool, deleteGloballyIfPossible: Bool = false) -> Signal<Void, NoError> {
return account.postbox.transaction { transaction -> Void in
@@ -79,3 +80,22 @@ func _internal_removePeerChat(account: Account, transaction: Transaction, mediaB
transaction.clearItemCacheCollection(collectionId: Namespaces.CachedItemCollection.cachedGroupCallDisplayAsPeers)
}
}
func _internal_getFutureCreatorAfterLeave(account: Account, peerId: EnginePeer.Id) -> Signal<EnginePeer?, NoError> {
return account.postbox.transaction { transaction in
return transaction.getPeer(peerId).flatMap(apiInputChannel)
}
|> mapToSignal { channel in
guard let channel else {
return .single(nil)
}
return account.network.request(Api.functions.channels.getFutureCreatorAfterLeave(channel: channel))
|> map(Optional.init)
|> `catch` { _ in
return .single(nil)
}
|> map { user in
return user.flatMap { TelegramUser(user: $0) }.map(EnginePeer.init)
}
}
}
@@ -9,7 +9,7 @@ func _internal_reportPeer(account: Account, peerId: PeerId) -> Signal<Void, NoEr
return account.postbox.transaction { transaction -> Signal<Void, NoError> in
if let peer = transaction.getPeer(peerId) {
if let peer = peer as? TelegramSecretChat {
return account.network.request(Api.functions.messages.reportEncryptedSpam(peer: Api.InputEncryptedChat.inputEncryptedChat(chatId: Int32(peer.id.id._internalGetInt64Value()), accessHash: peer.accessHash)))
return account.network.request(Api.functions.messages.reportEncryptedSpam(peer: Api.InputEncryptedChat.inputEncryptedChat(.init(chatId: Int32(peer.id.id._internalGetInt64Value()), accessHash: peer.accessHash))))
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.Bool?, NoError> in
return .single(nil)
@@ -40,10 +40,12 @@ func _internal_requestPeerPhotos(accountPeerId: PeerId, postbox: Postbox, networ
let totalCount:Int
let photos: [Api.Photo]
switch result {
case let .photos(photosValue, _):
case let .photos(photosData):
let (photosValue, _) = (photosData.photos, photosData.users)
photos = photosValue
totalCount = photos.count
case let .photosSlice(count, photosValue, _):
case let .photosSlice(photosSliceData):
let (count, photosValue, _) = (photosSliceData.count, photosSliceData.photos, photosSliceData.users)
photos = photosValue
totalCount = Int(count)
}
@@ -53,7 +55,8 @@ func _internal_requestPeerPhotos(accountPeerId: PeerId, postbox: Postbox, networ
if let image = telegramMediaImageFromApiPhoto(photos[i]), let reference = image.reference {
var date: Int32 = 0
switch photos[i] {
case let .photo(_, _, _, _, apiDate, _, _, _):
case let .photo(photoData):
let apiDate = photoData.date
date = apiDate
case .photoEmpty:
break
@@ -79,15 +82,18 @@ func _internal_requestPeerPhotos(accountPeerId: PeerId, postbox: Postbox, networ
let chats: [Api.Chat]
let users: [Api.User]
switch result {
case let .channelMessages(_, _, _, _, apiMessages, _, apiChats, apiUsers):
case let .channelMessages(channelMessagesData):
let (apiMessages, apiChats, apiUsers) = (channelMessagesData.messages, channelMessagesData.chats, channelMessagesData.users)
messages = apiMessages
chats = apiChats
users = apiUsers
case let .messages(apiMessages, _, apiChats, apiUsers):
case let .messages(messagesData):
let (apiMessages, apiChats, apiUsers) = (messagesData.messages, messagesData.chats, messagesData.users)
messages = apiMessages
chats = apiChats
users = apiUsers
case let .messagesSlice(_, _, _, _, _, apiMessages, _, apiChats, apiUsers):
case let .messagesSlice(messagesSliceData):
let (apiMessages, apiChats, apiUsers) = (messagesSliceData.messages, messagesSliceData.chats, messagesSliceData.users)
messages = apiMessages
chats = apiChats
users = apiUsers
@@ -56,7 +56,8 @@ func _internal_resolvePeerByName(postbox: Postbox, network: Network, accountPeer
var peerId: PeerId? = nil
switch result {
case let .resolvedPeer(apiPeer, chats, users):
case let .resolvedPeer(resolvedPeerData):
let (apiPeer, chats, users) = (resolvedPeerData.peer, resolvedPeerData.chats, resolvedPeerData.users)
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
if let peer = parsedPeers.get(apiPeer.peerId) {
@@ -105,7 +106,8 @@ func _internal_resolvePeerByPhone(account: Account, phone: String, ageLimit: Int
var peerId: PeerId? = nil
switch result {
case let .resolvedPeer(apiPeer, chats, users):
case let .resolvedPeer(resolvedPeerData):
let (apiPeer, chats, users) = (resolvedPeerData.peer, resolvedPeerData.chats, resolvedPeerData.users)
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
if let peer = parsedPeers.get(apiPeer.peerId) {
@@ -54,7 +54,7 @@ func _internal_getSavedMusicById(postbox: Postbox, network: Network, peer: PeerR
guard let inputUser, let resource = file.resource as? CloudDocumentMediaResource else {
return .single(nil)
}
return network.request(Api.functions.users.getSavedMusicByID(id: inputUser, documents: [.inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference))]))
return network.request(Api.functions.users.getSavedMusicByID(id: inputUser, documents: [.inputDocument(.init(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference)))]))
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.users.SavedMusic?, NoError> in
return .single(nil)
@@ -62,8 +62,8 @@ func _internal_getSavedMusicById(postbox: Postbox, network: Network, peer: PeerR
|> map { result -> TelegramMediaFile? in
if let result {
switch result {
case let .savedMusic(_, documents):
if let file = documents.first.flatMap({ telegramMediaFileFromApiDocument($0, altDocuments: nil) }) {
case let .savedMusic(savedMusicData):
if let file = savedMusicData.documents.first.flatMap({ telegramMediaFileFromApiDocument($0, altDocuments: nil) }) {
return file
}
default:
@@ -104,7 +104,8 @@ func _internal_keepSavedMusicIdsUpdated(postbox: Postbox, network: Network, acco
}
return postbox.transaction { transaction in
switch result {
case let .savedMusicIds(ids):
case let .savedMusicIds(savedMusicIdsData):
let ids = savedMusicIdsData.ids
let savedMusicIdsList = SavedMusicIdsList(items: ids)
transaction.setPreferencesEntry(key: PreferencesKeys.savedMusicIds(), value: PreferencesEntry(savedMusicIdsList))
case .savedMusicIdsNotModified:
@@ -188,9 +189,9 @@ func _internal_addSavedMusic(account: Account, file: FileMediaReference, afterFi
var afterId: Api.InputDocument?
if let afterFile, let resource = afterFile.media.resource as? CloudDocumentMediaResource {
flags = 1 << 1
afterId = .inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference))
afterId = .inputDocument(.init(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference)))
}
return account.network.request(Api.functions.account.saveMusic(flags: flags, id: .inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference)), afterId: afterId))
return account.network.request(Api.functions.account.saveMusic(flags: flags, id: .inputDocument(.init(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference))), afterId: afterId))
})
|> mapError { _ -> AddSavedMusicError in
return .generic
@@ -233,7 +234,7 @@ func _internal_removeSavedMusic(account: Account, file: FileMediaReference) -> S
}
let flags: Int32 = 1 << 0
return revalidatedMusic(account: account, file: file, signal: { resource in
return account.network.request(Api.functions.account.saveMusic(flags: flags, id: .inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference)), afterId: nil))
return account.network.request(Api.functions.account.saveMusic(flags: flags, id: .inputDocument(.init(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference))), afterId: nil))
})
|> `catch` { _ -> Signal<Api.Bool, NoError> in
return .complete()
@@ -365,10 +366,10 @@ public final class ProfileSavedMusicContext {
return network.request(Api.functions.users.getSavedMusic(id: inputUser, offset: offset, limit: 32, hash: 0))
|> map { result -> ([TelegramMediaFile], Int32) in
switch result {
case let .savedMusic(count, documents):
return (documents.compactMap { telegramMediaFileFromApiDocument($0, altDocuments: nil) }, count)
case let .savedMusicNotModified(count):
return ([], count)
case let .savedMusic(savedMusicData):
return (savedMusicData.documents.compactMap { telegramMediaFileFromApiDocument($0, altDocuments: nil) }, savedMusicData.count)
case let .savedMusicNotModified(savedMusicNotModifiedData):
return ([], savedMusicNotModifiedData.count)
}
}
}
@@ -36,7 +36,8 @@ public func _internal_searchPeers(accountPeerId: PeerId, postbox: Postbox, netwo
|> mapToSignal { result -> Signal<([FoundPeer], [FoundPeer]), NoError> in
if let result = result {
switch result {
case let .found(myResults, results, chats, users):
case let .found(foundData):
let (myResults, results, chats, users) = (foundData.myResults, foundData.results, foundData.chats, foundData.users)
return postbox.transaction { transaction -> ([FoundPeer], [FoundPeer]) in
var subscribers: [PeerId: Int32] = [:]
@@ -45,7 +46,8 @@ public func _internal_searchPeers(accountPeerId: PeerId, postbox: Postbox, netwo
for chat in chats {
if let groupOrChannel = parseTelegramGroupOrChannel(chat: chat) {
switch chat {
case let .channel(_, _, _, _, _, _, _, _, _, _, _, _, participantsCount, _, _, _, _, _, _, _, _, _, _):
case let .channel(channelData):
let participantsCount = channelData.participantsCount
if let participantsCount = participantsCount {
subscribers[groupOrChannel.id] = participantsCount
}
@@ -15,7 +15,8 @@ func _internal_supportPeerId(account: Account) -> Signal<PeerId?, NoError> {
|> mapToSignal { support -> Signal<PeerId?, NoError> in
if let support = support {
switch support {
case let .support(_, user):
case let .support(supportData):
let user = supportData.user
return account.postbox.transaction { transaction -> PeerId in
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: [], users: [user])
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
@@ -612,6 +612,10 @@ public extension TelegramEngine {
}
|> ignoreValues
}
public func getFutureCreatorAfterLeave(peerId: EnginePeer.Id) -> Signal<EnginePeer?, NoError> {
return _internal_getFutureCreatorAfterLeave(account: self.account, peerId: peerId)
}
public func terminateSecretChat(peerId: PeerId, requestRemoteHistoryRemoval: Bool) -> Signal<Never, NoError> {
return self.account.postbox.transaction { transaction -> Void in
@@ -1648,7 +1652,7 @@ public extension TelegramEngine {
}
public func getCollectibleUsernameInfo(username: String) -> Signal<TelegramCollectibleItemInfo?, NoError> {
return self.account.network.request(Api.functions.fragment.getCollectibleInfo(collectible: .inputCollectibleUsername(username: username)))
return self.account.network.request(Api.functions.fragment.getCollectibleInfo(collectible: .inputCollectibleUsername(.init(username: username))))
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.fragment.CollectibleInfo?, NoError> in
return .single(nil)
@@ -1658,7 +1662,8 @@ public extension TelegramEngine {
return nil
}
switch result {
case let .collectibleInfo(purchaseDate, currency, amount, cryptoCurrency, cryptoAmount, url):
case let .collectibleInfo(collectibleInfoData):
let (purchaseDate, currency, amount, cryptoCurrency, cryptoAmount, url) = (collectibleInfoData.purchaseDate, collectibleInfoData.currency, collectibleInfoData.amount, collectibleInfoData.cryptoCurrency, collectibleInfoData.cryptoAmount, collectibleInfoData.url)
return TelegramCollectibleItemInfo(
subject: .username(username),
purchaseDate: purchaseDate,
@@ -1673,7 +1678,7 @@ public extension TelegramEngine {
}
public func getCollectiblePhoneNumberInfo(phoneNumber: String) -> Signal<TelegramCollectibleItemInfo?, NoError> {
return self.account.network.request(Api.functions.fragment.getCollectibleInfo(collectible: .inputCollectiblePhone(phone: phoneNumber)))
return self.account.network.request(Api.functions.fragment.getCollectibleInfo(collectible: .inputCollectiblePhone(.init(phone: phoneNumber))))
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.fragment.CollectibleInfo?, NoError> in
return .single(nil)
@@ -1683,7 +1688,8 @@ public extension TelegramEngine {
return nil
}
switch result {
case let .collectibleInfo(purchaseDate, currency, amount, cryptoCurrency, cryptoAmount, url):
case let .collectibleInfo(collectibleInfoData):
let (purchaseDate, currency, amount, cryptoCurrency, cryptoAmount, url) = (collectibleInfoData.purchaseDate, collectibleInfoData.currency, collectibleInfoData.amount, collectibleInfoData.cryptoCurrency, collectibleInfoData.cryptoAmount, collectibleInfoData.url)
return TelegramCollectibleItemInfo(
subject: .phoneNumber(phoneNumber),
purchaseDate: purchaseDate,
@@ -1741,7 +1747,8 @@ public extension TelegramEngine {
}
return self.account.postbox.transaction { transaction -> TelegramResolvedMessageLink? in
switch result {
case let .resolvedBusinessChatLinks(_, peer, message, entities, chats, users):
case let .resolvedBusinessChatLinks(resolvedBusinessChatLinksData):
let (peer, message, entities, chats, users) = (resolvedBusinessChatLinksData.peer, resolvedBusinessChatLinksData.message, resolvedBusinessChatLinksData.entities, resolvedBusinessChatLinksData.chats, resolvedBusinessChatLinksData.users)
updatePeers(transaction: transaction, accountPeerId: self.account.peerId, peers: AccumulatedPeers(transaction: transaction, chats: chats, users: users))
guard let peer = transaction.getPeer(peer.peerId) else {
@@ -90,7 +90,8 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId rawPeerId: PeerId, accountP
let peerStatusSettings: PeerStatusSettings
switch peerSettings {
case let .peerSettings(settings, chats, users):
case let .peerSettings(peerSettingsData):
let (settings, chats, users) = (peerSettingsData.settings, peerSettingsData.chats, peerSettingsData.users)
peerStatusSettings = PeerStatusSettings(apiSettings: settings)
parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
}
@@ -193,7 +194,8 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
|> mapToSignal { result -> Signal<EditableBotInfo?, NoError> in
if let result = result {
switch result {
case let .botInfo(name, about, description):
case let .botInfo(botInfoData):
let (name, about, description) = (botInfoData.name, botInfoData.about, botInfoData.description)
return .single(EditableBotInfo(name: name, about: about, description: description))
}
} else {
@@ -234,7 +236,8 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
|> mapToSignal { result, editableBotInfo, botPreview, additionalConnectedBots -> Signal<Bool, NoError> in
return postbox.transaction { transaction -> Bool in
switch result {
case let .userFull(fullUser, chats, users):
case let .userFull(userFullData):
let (fullUser, chats, users) = (userFullData.fullUser, userFullData.chats, userFullData.users)
var accountUser: Api.User?
var parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
for user in users {
@@ -248,12 +251,14 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
if let additionalConnectedBots {
switch additionalConnectedBots {
case let .connectedBots(connectedBots, users):
case let .connectedBots(connectedBotsData):
let (connectedBots, users) = (connectedBotsData.connectedBots, connectedBotsData.users)
parsedPeers = parsedPeers.union(with: AccumulatedPeers(transaction: transaction, chats: [], users: users))
if let apiBot = connectedBots.first {
switch apiBot {
case let .connectedBot(_, botId, recipients, rights):
case let .connectedBot(connectedBotData):
let (botId, recipients, rights) = (connectedBotData.botId, connectedBotData.recipients, connectedBotData.rights)
mappedConnectedBot = TelegramAccountConnectedBot(
id: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(botId)),
recipients: TelegramBusinessRecipients(apiValue: recipients),
@@ -265,7 +270,8 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
}
switch fullUser {
case let .userFull(_, _, _, _, _, _, _, _, userFullNotifySettings, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _):
case let .userFull(userFullData):
let userFullNotifySettings = userFullData.notifySettings
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
transaction.updateCurrentPeerNotificationSettings([peerId: TelegramPeerNotificationSettings(apiSettings: userFullNotifySettings)])
}
@@ -277,7 +283,8 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
previous = CachedUserData()
}
switch fullUser {
case let .userFull(userFullFlags, userFullFlags2, _, userFullAbout, userFullSettings, personalPhoto, profilePhoto, fallbackPhoto, _, userFullBotInfo, userFullPinnedMsgId, userFullCommonChatsCount, _, userFullTtlPeriod, userFullChatTheme, _, groupAdminRights, channelAdminRights, userWallpaper, _, businessWorkHours, businessLocation, greetingMessage, awayMessage, businessIntro, birthday, personalChannelId, personalChannelMessage, starGiftsCount, starRefProgram, verification, sendPaidMessageStars, disallowedStarGifts, starsRating, starsMyPendingRating, starsMyPendingRatingDate, mainTab, savedMusic, note):
case let .userFull(userFullData):
let (userFullFlags, userFullFlags2, userFullAbout, userFullSettings, apiPersonalPhoto, profilePhoto, apiFallbackPhoto, userFullBotInfo, userFullPinnedMsgId, userFullCommonChatsCount, userFullTtlPeriod, userFullChatTheme, groupAdminRights, channelAdminRights, userWallpaper, businessWorkHours, businessLocation, greetingMessage, awayMessage, businessIntro, birthday, personalChannelId, personalChannelMessage, starGiftsCount, starRefProgram, apiVerification, apiSendPaidMessageStars, disallowedStarGifts, starsRating, starsMyPendingRating, starsMyPendingRatingDate, mainTab, savedMusic, note) = (userFullData.flags, userFullData.flags2, userFullData.about, userFullData.settings, userFullData.personalPhoto, userFullData.profilePhoto, userFullData.fallbackPhoto, userFullData.botInfo, userFullData.pinnedMsgId, userFullData.commonChatsCount, userFullData.ttlPeriod, userFullData.theme, userFullData.botGroupAdminRights, userFullData.botBroadcastAdminRights, userFullData.wallpaper, userFullData.businessWorkHours, userFullData.businessLocation, userFullData.businessGreetingMessage, userFullData.businessAwayMessage, userFullData.businessIntro, userFullData.birthday, userFullData.personalChannelId, userFullData.personalChannelMessage, userFullData.stargiftsCount, userFullData.starrefProgram, userFullData.botVerification, userFullData.sendPaidMessagesStars, userFullData.disallowedGifts, userFullData.starsRating, userFullData.starsMyPendingRating, userFullData.starsMyPendingRatingDate, userFullData.mainTab, userFullData.savedMusic, userFullData.note)
let botInfo = userFullBotInfo.flatMap(BotInfo.init(apiBotInfo:))
let isBlocked = (userFullFlags & (1 << 0)) != 0
let voiceCallsAvailable = (userFullFlags & (1 << 4)) != 0
@@ -338,9 +345,9 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
let autoremoveTimeout: CachedPeerAutoremoveTimeout = .known(CachedPeerAutoremoveTimeout.Value(userFullTtlPeriod))
let personalPhoto = personalPhoto.flatMap { telegramMediaImageFromApiPhoto($0) }
let personalPhoto = apiPersonalPhoto.flatMap { telegramMediaImageFromApiPhoto($0) }
let photo = profilePhoto.flatMap { telegramMediaImageFromApiPhoto($0) }
let fallbackPhoto = fallbackPhoto.flatMap { telegramMediaImageFromApiPhoto($0) }
let fallbackPhoto = apiFallbackPhoto.flatMap { telegramMediaImageFromApiPhoto($0) }
let wallpaper = userWallpaper.flatMap { TelegramWallpaper(apiWallpaper: $0) }
@@ -381,7 +388,8 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
var subscriberCount: Int32?
for chat in chats {
if chat.peerId == channelPeerId {
if case let .channel(_, _, _, _, _, _, _, _, _, _, _, _, participantsCount, _, _, _, _, _, _, _, _, _, _) = chat {
if case let .channel(channelData) = chat {
let participantsCount = channelData.participantsCount
subscriberCount = participantsCount
}
}
@@ -399,9 +407,9 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
mappedStarRefProgram = TelegramStarRefProgram(apiStarRefProgram: starRefProgram)
}
let verification = verification.flatMap { PeerVerification(apiBotVerification: $0) }
let verification = apiVerification.flatMap { PeerVerification(apiBotVerification: $0) }
let sendPaidMessageStars = sendPaidMessageStars.flatMap { StarsAmount(value: $0, nanos: 0) }
let sendPaidMessageStars = apiSendPaidMessageStars.flatMap { StarsAmount(value: $0, nanos: 0) }
let disallowedGifts = TelegramDisallowedGifts(apiDisallowedGifts: disallowedStarGifts)
@@ -425,7 +433,8 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
var mappedNote: CachedUserData.Note?
if let note {
switch note {
case let .textWithEntities(text, entities):
case let .textWithEntities(textWithEntitiesData):
let (text, entities) = (textWithEntitiesData.text, textWithEntitiesData.entities)
mappedNote = CachedUserData.Note(text: text, entities: messageTextEntitiesFromApiEntities(entities))
}
}
@@ -486,20 +495,24 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
}
return postbox.transaction { transaction -> Bool in
switch result {
case let .chatFull(fullChat, chats, users):
case let .chatFull(messagesChatFullData):
let (fullChat, chats, users) = (messagesChatFullData.fullChat, messagesChatFullData.chats, messagesChatFullData.users)
switch fullChat {
case let .chatFull(_, _, _, _, _, notifySettings, _, _, _, _, _, _, _, _, _, _, _, _):
case let .chatFull(chatFullData):
let (notifySettings) = (chatFullData.notifySettings)
transaction.updateCurrentPeerNotificationSettings([peerId: TelegramPeerNotificationSettings(apiSettings: notifySettings)])
case .channelFull:
break
}
switch fullChat {
case let .chatFull(chatFullFlags, _, chatFullAbout, chatFullParticipants, chatFullChatPhoto, _, chatFullExportedInvite, chatFullBotInfo, chatFullPinnedMsgId, _, chatFullCall, chatTtlPeriod, chatFullGroupcallDefaultJoinAs, chatFullThemeEmoticon, chatFullRequestsPending, _, allowedReactions, reactionsLimit):
case let .chatFull(chatFullData):
let (chatFullFlags, chatFullAbout, chatFullParticipants, chatFullChatPhoto, chatFullExportedInvite, chatFullBotInfo, chatFullPinnedMsgId, chatFullCall, chatTtlPeriod, chatFullGroupcallDefaultJoinAs, chatFullThemeEmoticon, chatFullRequestsPending, allowedReactions, reactionsLimit) = (chatFullData.flags, chatFullData.about, chatFullData.participants, chatFullData.chatPhoto, chatFullData.exportedInvite, chatFullData.botInfo, chatFullData.pinnedMsgId, chatFullData.call, chatFullData.ttlPeriod, chatFullData.groupcallDefaultJoinAs, chatFullData.themeEmoticon, chatFullData.requestsPending, chatFullData.availableReactions, chatFullData.reactionsLimit)
var botInfos: [CachedPeerBotInfo] = []
for botInfo in chatFullBotInfo ?? [] {
switch botInfo {
case let .botInfo(_, userId, _, _, _, _, _, _, _, _):
case let .botInfo(botInfoData):
let (_, userId, _, _, _, _, _, _, _, _) = (botInfoData.flags, botInfoData.userId, botInfoData.description, botInfoData.descriptionPhoto, botInfoData.descriptionDocument, botInfoData.commands, botInfoData.menuButton, botInfoData.privacyPolicyUrl, botInfoData.appSettings, botInfoData.verifierSettings)
if let userId = userId {
let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
let parsedBotInfo = BotInfo(apiBotInfo: botInfo)
@@ -554,7 +567,8 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
var updatedActiveCall: CachedChannelData.ActiveCall?
if let inputCall = chatFullCall {
switch inputCall {
case let .inputGroupCall(id, accessHash):
case let .inputGroupCall(inputGroupCallData):
let (id, accessHash) = (inputGroupCallData.id, inputGroupCallData.accessHash)
updatedActiveCall = CachedChannelData.ActiveCall(id: id, accessHash: accessHash, title: previous.activeCall?.title, scheduleTimestamp: previous.activeCall?.scheduleTimestamp, subscribedToScheduled: previous.activeCall?.subscribedToScheduled ?? false, isStream: previous.activeCall?.isStream)
case .inputGroupCallSlug, .inputGroupCallInviteMessage:
break
@@ -566,7 +580,8 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
switch allowedReactions {
case .chatReactionsAll:
mappedAllowedReactions = .all
case let .chatReactionsSome(reactions):
case let .chatReactionsSome(chatReactionsSomeData):
let reactions = chatReactionsSomeData.reactions
mappedAllowedReactions = .limited(reactions.compactMap(MessageReaction.Reaction.init(apiReaction:)))
case .chatReactionsNone:
mappedAllowedReactions = .empty
@@ -629,16 +644,19 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
return postbox.transaction { transaction -> Bool in
if let result = result {
switch result {
case let .chatFull(fullChat, chats, users):
case let .chatFull(messagesChatFullData):
let (fullChat, chats, users) = (messagesChatFullData.fullChat, messagesChatFullData.chats, messagesChatFullData.users)
switch fullChat {
case let .channelFull(_, _, _, _, _, _, _, _, _, _, _, _, _, notifySettings, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _):
case let .channelFull(channelFullData):
let notifySettings = channelFullData.notifySettings
transaction.updateCurrentPeerNotificationSettings([peerId: TelegramPeerNotificationSettings(apiSettings: notifySettings)])
case .chatFull:
break
}
switch fullChat {
case let .channelFull(flags, flags2, _, about, participantsCount, adminsCount, kickedCount, bannedCount, _, _, _, _, chatPhoto, _, apiExportedInvite, apiBotInfos, migratedFromChatId, migratedFromMaxId, pinnedMsgId, stickerSet, minAvailableMsgId, _, linkedChatId, location, slowmodeSeconds, slowmodeNextSendDate, statsDc, _, inputCall, ttl, pendingSuggestions, groupcallDefaultJoinAs, themeEmoticon, requestsPending, _, defaultSendAs, allowedReactions, reactionsLimit, _, wallpaper, appliedBoosts, boostsUnrestrict, emojiSet, verification, starGiftsCount, sendPaidMessageStars, mainTab):
case let .channelFull(channelFullData):
let (flags, flags2, about, participantsCount, adminsCount, kickedCount, bannedCount, chatPhoto, apiExportedInvite, apiBotInfos, migratedFromChatId, migratedFromMaxId, pinnedMsgId, stickerSet, minAvailableMsgId, linkedChatId, location, slowmodeSeconds, slowmodeNextSendDate, statsDc, inputCall, ttl, pendingSuggestions, groupcallDefaultJoinAs, themeEmoticon, requestsPending, defaultSendAs, allowedReactions, reactionsLimit, wallpaper, appliedBoosts, boostsUnrestrict, emojiSet, verification, starGiftsCount, sendPaidMessageStars, mainTab) = (channelFullData.flags, channelFullData.flags2, channelFullData.about, channelFullData.participantsCount, channelFullData.adminsCount, channelFullData.kickedCount, channelFullData.bannedCount, channelFullData.chatPhoto, channelFullData.exportedInvite, channelFullData.botInfo, channelFullData.migratedFromChatId, channelFullData.migratedFromMaxId, channelFullData.pinnedMsgId, channelFullData.stickerset, channelFullData.availableMinId, channelFullData.linkedChatId, channelFullData.location, channelFullData.slowmodeSeconds, channelFullData.slowmodeNextSendDate, channelFullData.statsDc, channelFullData.call, channelFullData.ttlPeriod, channelFullData.pendingSuggestions, channelFullData.groupcallDefaultJoinAs, channelFullData.themeEmoticon, channelFullData.requestsPending, channelFullData.defaultSendAs, channelFullData.availableReactions, channelFullData.reactionsLimit, channelFullData.wallpaper, channelFullData.boostsApplied, channelFullData.boostsUnrestrict, channelFullData.emojiset, channelFullData.botVerification, channelFullData.stargiftsCount, channelFullData.sendPaidMessagesStars, channelFullData.mainTab)
var channelFlags = CachedChannelFlags()
if (flags & (1 << 3)) != 0 {
channelFlags.insert(.canDisplayParticipants)
@@ -707,7 +725,8 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
var botInfos: [CachedPeerBotInfo] = []
for botInfo in apiBotInfos {
switch botInfo {
case let .botInfo(_, userId, _, _, _, _, _, _, _, _):
case let .botInfo(botInfoData):
let (_, userId, _, _, _, _, _, _, _, _) = (botInfoData.flags, botInfoData.userId, botInfoData.description, botInfoData.descriptionPhoto, botInfoData.descriptionDocument, botInfoData.commands, botInfoData.menuButton, botInfoData.privacyPolicyUrl, botInfoData.appSettings, botInfoData.verifierSettings)
if let userId = userId {
let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
let parsedBotInfo = BotInfo(apiBotInfo: botInfo)
@@ -739,7 +758,8 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
if let participantResult = participantResult {
switch participantResult {
case let .channelParticipant(_, chats, users):
case let .channelParticipant(channelParticipantData):
let (chats, users) = (channelParticipantData.chats, channelParticipantData.users)
parsedPeers = parsedPeers.union(with: AccumulatedPeers(transaction: transaction, chats: chats, users: users))
}
}
@@ -749,7 +769,8 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
let stickerPack: StickerPackCollectionInfo? = stickerSet.flatMap { apiSet -> StickerPackCollectionInfo in
let namespace: ItemCollectionId.Namespace
switch apiSet {
case let .stickerSet(flags, _, _, _, _, _, _, _, _, _, _, _):
case let .stickerSet(stickerSetData):
let flags = stickerSetData.flags
if (flags & (1 << 3)) != 0 {
namespace = Namespaces.ItemCollection.CloudMaskPacks
} else if (flags & (1 << 7)) != 0 {
@@ -758,7 +779,7 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
namespace = Namespaces.ItemCollection.CloudStickerPacks
}
}
return StickerPackCollectionInfo(apiSet: apiSet, namespace: namespace)
}
@@ -771,9 +792,11 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
var invitedOn: Int32?
if let participantResult = participantResult {
switch participantResult {
case let .channelParticipant(participant, _, _):
case let .channelParticipant(channelParticipantData):
let participant = channelParticipantData.participant
switch participant {
case let .channelParticipantSelf(flags, _, inviterId, invitedDate, _):
case let .channelParticipantSelf(channelParticipantSelfData):
let (flags, inviterId, invitedDate) = (channelParticipantSelfData.flags, channelParticipantSelfData.inviterId, channelParticipantSelfData.date)
invitedBy = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(inviterId))
if (flags & (1 << 0)) != 0 {
invitedOn = invitedDate
@@ -789,7 +812,8 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
let emojiPack: StickerPackCollectionInfo? = emojiSet.flatMap { apiSet -> StickerPackCollectionInfo in
let namespace: ItemCollectionId.Namespace
switch apiSet {
case let .stickerSet(flags, _, _, _, _, _, _, _, _, _, _, _):
case let .stickerSet(stickerSetData):
let flags = stickerSetData.flags
if (flags & (1 << 3)) != 0 {
namespace = Namespaces.ItemCollection.CloudMaskPacks
} else if (flags & (1 << 7)) != 0 {
@@ -798,7 +822,7 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
namespace = Namespaces.ItemCollection.CloudStickerPacks
}
}
return StickerPackCollectionInfo(apiSet: apiSet, namespace: namespace)
}
@@ -818,7 +842,8 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
var updatedActiveCall: CachedChannelData.ActiveCall?
if let inputCall = inputCall {
switch inputCall {
case let .inputGroupCall(id, accessHash):
case let .inputGroupCall(inputGroupCallData):
let (id, accessHash) = (inputGroupCallData.id, inputGroupCallData.accessHash)
updatedActiveCall = CachedChannelData.ActiveCall(id: id, accessHash: accessHash, title: previous.activeCall?.title, scheduleTimestamp: previous.activeCall?.scheduleTimestamp, subscribedToScheduled: previous.activeCall?.subscribedToScheduled ?? false, isStream: previous.activeCall?.isStream)
case .inputGroupCallSlug, .inputGroupCallInviteMessage:
break
@@ -830,7 +855,8 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
switch allowedReactions {
case .chatReactionsAll:
mappedAllowedReactions = .all
case let .chatReactionsSome(reactions):
case let .chatReactionsSome(chatReactionsSomeData):
let reactions = chatReactionsSomeData.reactions
mappedAllowedReactions = .limited(reactions.compactMap(MessageReaction.Reaction.init(apiReaction:)))
case .chatReactionsNone:
mappedAllowedReactions = .empty
@@ -943,11 +969,13 @@ func _internal_requestBotAdminPreview(network: Network, peerId: PeerId, inputUse
return nil
}
switch result {
case let .previewInfo(media, langCodes):
case let .previewInfo(previewInfoData):
let (media, langCodes) = (previewInfoData.media, previewInfoData.langCodes)
return CachedUserData.BotPreview(
items: media.compactMap { item -> CachedUserData.BotPreview.Item? in
switch item {
case let .botPreviewMedia(date, media):
case let .botPreviewMedia(botPreviewMediaData):
let (date, media) = (botPreviewMediaData.date, botPreviewMediaData.media)
let value = textMediaAndExpirationTimerFromApiMedia(media, peerId)
if let media = value.media {
return CachedUserData.BotPreview.Item(media: media, timestamp: date)
@@ -975,7 +1003,8 @@ func _internal_requestBotUserPreview(network: Network, peerId: PeerId, inputUser
return CachedUserData.BotPreview(
items: result.compactMap { item -> CachedUserData.BotPreview.Item? in
switch item {
case let .botPreviewMedia(date, media):
case let .botPreviewMedia(botPreviewMediaData):
let (date, media) = (botPreviewMediaData.date, botPreviewMediaData.media)
let value = textMediaAndExpirationTimerFromApiMedia(media, peerId)
if let media = value.media {
return CachedUserData.BotPreview.Item(media: media, timestamp: date)
@@ -14,7 +14,7 @@ func _internal_updateGroupSpecificStickerset(postbox: Postbox, network: Network,
|> mapToSignal { peer -> Signal<Void, UpdateGroupSpecificStickersetError> in
let inputStickerset: Api.InputStickerSet
if let info = info {
inputStickerset = Api.InputStickerSet.inputStickerSetShortName(shortName: info.shortName)
inputStickerset = Api.InputStickerSet.inputStickerSetShortName(.init(shortName: info.shortName))
} else {
inputStickerset = Api.InputStickerSet.inputStickerSetEmpty
}
@@ -52,7 +52,7 @@ func _internal_updateGroupSpecificEmojiset(postbox: Postbox, network: Network, p
|> mapToSignal { peer -> Signal<Void, UpdateGroupSpecificEmojisetError> in
let inputStickerset: Api.InputStickerSet
if let info = info {
inputStickerset = Api.InputStickerSet.inputStickerSetShortName(shortName: info.shortName)
inputStickerset = Api.InputStickerSet.inputStickerSetShortName(.init(shortName: info.shortName))
} else {
inputStickerset = Api.InputStickerSet.inputStickerSetEmpty
}
@@ -293,7 +293,7 @@ func _internal_updatePeerEmojiStatus(account: Account, peerId: PeerId, fileId: I
if let _ = expirationDate {
flags |= (1 << 0)
}
mappedStatus = .emojiStatus(flags: flags, documentId: fileId, until: expirationDate)
mappedStatus = .emojiStatus(.init(flags: flags, documentId: fileId, until: expirationDate))
} else {
mappedStatus = .emojiStatusEmpty
}
@@ -322,7 +322,7 @@ func _internal_updatePeerStarGiftStatus(account: Account, peerId: PeerId, starGi
var textColor: Int32?
for attribute in starGift.attributes {
switch attribute {
case let .model(_, fileValue, _):
case let .model(_, fileValue, _, _):
file = fileValue
case let .pattern(_, patternFileValue, _):
patternFile = patternFileValue
@@ -338,7 +338,7 @@ func _internal_updatePeerStarGiftStatus(account: Account, peerId: PeerId, starGi
let apiEmojiStatus: Api.EmojiStatus
var emojiStatus: PeerEmojiStatus?
if let file, let patternFile, let innerColor, let outerColor, let patternColor, let textColor {
apiEmojiStatus = .inputEmojiStatusCollectible(flags: flags, collectibleId: starGift.id, until: expirationDate)
apiEmojiStatus = .inputEmojiStatusCollectible(.init(flags: flags, collectibleId: starGift.id, until: expirationDate))
emojiStatus = PeerEmojiStatus(content: .starGift(id: starGift.id, fileId: file.fileId.id, title: starGift.title, slug: starGift.slug, patternFileId: patternFile.fileId.id, innerColor: innerColor, outerColor: outerColor, patternColor: patternColor, textColor: textColor), expirationDate: expirationDate)
} else {
apiEmojiStatus = .emojiStatusEmpty