mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-02 20:55:48 +00:00
no message
This commit is contained in:
parent
f5a6cfdc1b
commit
d6025daae8
@ -110,6 +110,8 @@ public class UnauthorizedAccount {
|
||||
return Int32(self.network.mtProto.datacenterId)
|
||||
}
|
||||
|
||||
public let shouldBeServiceTaskMaster = Promise<AccountServiceTaskMasterMode>()
|
||||
|
||||
init(id: AccountRecordId, appGroupPath: String, basePath: String, testingEnvironment: Bool, postbox: Postbox, network: Network, shouldKeepAutoConnection: Bool = true) {
|
||||
self.id = id
|
||||
self.appGroupPath = appGroupPath
|
||||
@ -117,7 +119,15 @@ public class UnauthorizedAccount {
|
||||
self.testingEnvironment = testingEnvironment
|
||||
self.postbox = postbox
|
||||
self.network = network
|
||||
network.shouldKeepConnection.set(.single(shouldKeepAutoConnection))
|
||||
|
||||
network.shouldKeepConnection.set(self.shouldBeServiceTaskMaster.get() |> map { mode -> Bool in
|
||||
switch mode {
|
||||
case .now, .always:
|
||||
return true
|
||||
case .never:
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
public func changedMasterDatacenterId(_ masterDatacenterId: Int32) -> Signal<UnauthorizedAccount, NoError> {
|
||||
@ -135,7 +145,9 @@ public class UnauthorizedAccount {
|
||||
|
||||
return initializedNetwork(datacenterId: Int(masterDatacenterId), keychain: keychain, networkUsageInfoPath: accountNetworkUsageInfoPath(basePath: self.basePath), testingEnvironment: self.testingEnvironment)
|
||||
|> map { network in
|
||||
return UnauthorizedAccount(id: self.id, appGroupPath: self.appGroupPath, basePath: self.basePath, testingEnvironment: self.testingEnvironment, postbox: self.postbox, network: network)
|
||||
let updated = UnauthorizedAccount(id: self.id, appGroupPath: self.appGroupPath, basePath: self.basePath, testingEnvironment: self.testingEnvironment, postbox: self.postbox, network: network)
|
||||
updated.shouldBeServiceTaskMaster.set(self.shouldBeServiceTaskMaster.get())
|
||||
return updated
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,6 +29,13 @@ final class AccountInitialState {
|
||||
}
|
||||
}
|
||||
|
||||
enum AccountStateUpdatePinnerPeerIdsOperation {
|
||||
case pin(PeerId)
|
||||
case unpin(PeerId)
|
||||
case reorder([PeerId])
|
||||
case sync
|
||||
}
|
||||
|
||||
enum AccountStateMutationOperation {
|
||||
case AddMessages([StoreMessage], AddMessagesLocation)
|
||||
case DeleteMessagesWithGlobalIds([Int32])
|
||||
@ -51,6 +58,7 @@ enum AccountStateMutationOperation {
|
||||
case AddSecretMessages([Api.EncryptedMessage])
|
||||
case ReadSecretOutbox(peerId: PeerId, maxTimestamp: Int32, actionTimestamp: Int32)
|
||||
case AddPeerInputActivity(chatPeerId: PeerId, peerId: PeerId?, activity: PeerInputActivity?)
|
||||
case UpdatePinnedPeerIds(AccountStateUpdatePinnerPeerIdsOperation)
|
||||
}
|
||||
|
||||
struct AccountMutableState {
|
||||
@ -215,9 +223,13 @@ struct AccountMutableState {
|
||||
self.addOperation(.AddPeerInputActivity(chatPeerId: chatPeerId, peerId: peerId, activity: activity))
|
||||
}
|
||||
|
||||
mutating func addUpdatePinnedPeerIds(_ operation: AccountStateUpdatePinnerPeerIdsOperation) {
|
||||
self.addOperation(.UpdatePinnedPeerIds(operation))
|
||||
}
|
||||
|
||||
mutating func addOperation(_ operation: AccountStateMutationOperation) {
|
||||
switch operation {
|
||||
case .AddHole, .DeleteMessages, .DeleteMessagesWithGlobalIds, .EditMessage, .UpdateMedia, .ReadOutbox, .MergePeerPresences, .UpdateSecretChat, .AddSecretMessages, .ReadSecretOutbox, .AddPeerInputActivity, .UpdateCachedPeerData:
|
||||
case .AddHole, .DeleteMessages, .DeleteMessagesWithGlobalIds, .EditMessage, .UpdateMedia, .ReadOutbox, .MergePeerPresences, .UpdateSecretChat, .AddSecretMessages, .ReadSecretOutbox, .AddPeerInputActivity, .UpdateCachedPeerData, .UpdatePinnedPeerIds:
|
||||
break
|
||||
case let .AddMessages(messages, _):
|
||||
for message in messages {
|
||||
|
||||
@ -751,7 +751,7 @@ private func finalStateWithUpdates(account: Account, state: AccountMutableState,
|
||||
if updatedState.peers[peerId] == nil {
|
||||
updatedState.updatePeer(peerId, { peer in
|
||||
if peer == nil {
|
||||
return TelegramUser(id: peerId, accessHash: nil, firstName: "Telegram Notifications", lastName: nil, username: nil, phone: nil, photo: [], botInfo: BotUserInfo(flags: [], inlinePlaceholder: nil))
|
||||
return TelegramUser(id: peerId, accessHash: nil, firstName: "Telegram Notifications", lastName: nil, username: nil, phone: nil, photo: [], botInfo: BotUserInfo(flags: [], inlinePlaceholder: nil), flags: [.isVerified])
|
||||
} else {
|
||||
return peer
|
||||
}
|
||||
@ -954,6 +954,18 @@ private func finalStateWithUpdates(account: Account, state: AccountMutableState,
|
||||
updatedState.addPeerInputActivity(chatPeerId: PeerId(namespace: Namespaces.Peer.CloudChannel, id: chatId), peerId: PeerId(namespace: Namespaces.Peer.CloudUser, id: userId), activity: PeerInputActivity(apiType: type))
|
||||
case let .updateEncryptedChatTyping(chatId):
|
||||
updatedState.addPeerInputActivity(chatPeerId: PeerId(namespace: Namespaces.Peer.SecretChat, id: chatId), peerId: nil, activity: .typingText)
|
||||
case let .updateDialogPinned(flags, peer):
|
||||
if (flags & (1 << 0)) != 0 {
|
||||
updatedState.addUpdatePinnedPeerIds(.pin(peer.peerId))
|
||||
} else {
|
||||
updatedState.addUpdatePinnedPeerIds(.unpin(peer.peerId))
|
||||
}
|
||||
case let .updatePinnedDialogs(_, order):
|
||||
if let order = order {
|
||||
updatedState.addUpdatePinnedPeerIds(.reorder(order.map { $0.peerId }))
|
||||
} else {
|
||||
updatedState.addUpdatePinnedPeerIds(.sync)
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
@ -1287,7 +1299,7 @@ private func optimizedOperations(_ operations: [AccountStateMutationOperation])
|
||||
var currentAddMessages: OptimizeAddMessagesState?
|
||||
for operation in operations {
|
||||
switch operation {
|
||||
case .AddHole, .DeleteMessages, .DeleteMessagesWithGlobalIds, .EditMessage, .UpdateMedia, .MergeApiChats, .MergeApiUsers, .MergePeerPresences, .UpdatePeer, .ReadInbox, .ReadOutbox, .ResetReadState, .UpdatePeerNotificationSettings, .UpdateSecretChat, .AddSecretMessages, .ReadSecretOutbox, .AddPeerInputActivity, .UpdateCachedPeerData:
|
||||
case .AddHole, .DeleteMessages, .DeleteMessagesWithGlobalIds, .EditMessage, .UpdateMedia, .MergeApiChats, .MergeApiUsers, .MergePeerPresences, .UpdatePeer, .ReadInbox, .ReadOutbox, .ResetReadState, .UpdatePeerNotificationSettings, .UpdateSecretChat, .AddSecretMessages, .ReadSecretOutbox, .AddPeerInputActivity, .UpdateCachedPeerData, .UpdatePinnedPeerIds:
|
||||
if let currentAddMessages = currentAddMessages, !currentAddMessages.messages.isEmpty {
|
||||
result.append(.AddMessages(currentAddMessages.messages, currentAddMessages.location))
|
||||
}
|
||||
@ -1426,6 +1438,36 @@ func replayFinalState(accountPeerId: PeerId, mediaBox: MediaBox, modifier: Modif
|
||||
} else if chatPeerId.namespace == Namespaces.Peer.SecretChat {
|
||||
updatedSecretChatTypingActivities.insert(chatPeerId)
|
||||
}
|
||||
case let .UpdatePinnedPeerIds(pinnedOperation):
|
||||
switch pinnedOperation {
|
||||
case let .pin(peerId):
|
||||
if modifier.getPeer(peerId) == nil || modifier.getPeerChatListInclusion(peerId) == .notSpecified {
|
||||
addSynchronizePinnedChatsOperation(modifier: modifier)
|
||||
} else {
|
||||
var currentPeerIds = modifier.getPinnedPeerIds()
|
||||
if !currentPeerIds.contains(peerId) {
|
||||
currentPeerIds.insert(peerId, at: 0)
|
||||
modifier.setPinnedPeerIds(currentPeerIds)
|
||||
}
|
||||
}
|
||||
case let .unpin(peerId):
|
||||
var currentPeerIds = modifier.getPinnedPeerIds()
|
||||
if let index = currentPeerIds.index(of: peerId) {
|
||||
currentPeerIds.remove(at: index)
|
||||
modifier.setPinnedPeerIds(currentPeerIds)
|
||||
} else {
|
||||
addSynchronizePinnedChatsOperation(modifier: modifier)
|
||||
}
|
||||
case let .reorder(peerIds):
|
||||
let currentPeerIds = modifier.getPinnedPeerIds()
|
||||
if Set(peerIds) == Set(currentPeerIds) {
|
||||
modifier.setPinnedPeerIds(peerIds)
|
||||
} else {
|
||||
addSynchronizePinnedChatsOperation(modifier: modifier)
|
||||
}
|
||||
case .sync:
|
||||
addSynchronizePinnedChatsOperation(modifier: modifier)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -88,7 +88,7 @@ public func parseTelegramGroupOrChannel(chat: Api.Chat) -> Peer? {
|
||||
|
||||
var channelFlags = TelegramChannelFlags()
|
||||
if (flags & Int32(1 << 7)) != 0 {
|
||||
channelFlags.insert(.verified)
|
||||
channelFlags.insert(.isVerified)
|
||||
}
|
||||
|
||||
let restrictionInfo: PeerAccessRestrictionInfo?
|
||||
@ -115,21 +115,21 @@ func mergeGroupOrChannel(lhs: Peer?, rhs: Api.Chat) -> Peer? {
|
||||
switch rhs {
|
||||
case .chat, .chatEmpty, .chatForbidden, .channelForbidden:
|
||||
return parseTelegramGroupOrChannel(chat: rhs)
|
||||
case let .channel(flags, id, accessHash, title, username, photo, date, version, restrictionReason):
|
||||
case let .channel(flags, _, accessHash, title, username, photo, date, version, restrictionReason):
|
||||
if let _ = accessHash {
|
||||
return parseTelegramGroupOrChannel(chat: rhs)
|
||||
} else if let lhs = lhs as? TelegramChannel {
|
||||
var channelFlags = lhs.flags
|
||||
if (flags & Int32(1 << 7)) != 0 {
|
||||
channelFlags.insert(.verified)
|
||||
channelFlags.insert(.isVerified)
|
||||
} else {
|
||||
let _ = channelFlags.remove(.verified)
|
||||
let _ = channelFlags.remove(.isVerified)
|
||||
}
|
||||
var info = lhs.info
|
||||
switch info {
|
||||
case .broadcast:
|
||||
break
|
||||
case let .group(groupInfo):
|
||||
case .group:
|
||||
var infoFlags = TelegramChannelGroupFlags()
|
||||
if (flags & Int32(1 << 10)) != 0 {
|
||||
infoFlags.insert(.everyMemberCanInviteMembers)
|
||||
|
||||
@ -157,11 +157,20 @@ func fetchChatListHole(network: Network, postbox: Postbox, hole: ChatListHole) -
|
||||
}
|
||||
return offset
|
||||
|> mapToSignal { (timestamp, id, peer) in
|
||||
return network.request(Api.functions.messages.getDialogs(flags: 0, offsetDate: timestamp, offsetId: id, offsetPeer: peer, limit: 100))
|
||||
|> retryRequest
|
||||
|> mapToSignal { result -> Signal<Void, NoError> in
|
||||
let dialogsChats: [Api.Chat]
|
||||
let dialogsUsers: [Api.User]
|
||||
let pinnedChats: Signal<Api.messages.PeerDialogs?, NoError>
|
||||
if case .inputPeerEmpty = peer, timestamp == 0 {
|
||||
pinnedChats = network.request(Api.functions.messages.getPinnedDialogs())
|
||||
|> retryRequest
|
||||
|> map { Optional($0) }
|
||||
} else {
|
||||
pinnedChats = .single(nil)
|
||||
}
|
||||
|
||||
return combineLatest(network.request(Api.functions.messages.getDialogs(flags: 0, offsetDate: timestamp, offsetId: id, offsetPeer: peer, limit: 100))
|
||||
|> retryRequest, pinnedChats)
|
||||
|> mapToSignal { result, pinnedChats -> Signal<Void, NoError> in
|
||||
var dialogsChats: [Api.Chat] = []
|
||||
var dialogsUsers: [Api.User] = []
|
||||
|
||||
var replacementHole: ChatListHole?
|
||||
var storeMessages: [StoreMessage] = []
|
||||
@ -171,8 +180,8 @@ func fetchChatListHole(network: Network, postbox: Postbox, hole: ChatListHole) -
|
||||
|
||||
switch result {
|
||||
case let .dialogs(dialogs, messages, chats, users):
|
||||
dialogsChats = chats
|
||||
dialogsUsers = users
|
||||
dialogsChats.append(contentsOf: chats)
|
||||
dialogsUsers.append(contentsOf: users)
|
||||
|
||||
for dialog in dialogs {
|
||||
let apiPeer: Api.Peer
|
||||
@ -227,8 +236,8 @@ func fetchChatListHole(network: Network, postbox: Postbox, hole: ChatListHole) -
|
||||
}
|
||||
}
|
||||
|
||||
dialogsChats = chats
|
||||
dialogsUsers = users
|
||||
dialogsChats.append(contentsOf: chats)
|
||||
dialogsUsers.append(contentsOf: users)
|
||||
|
||||
for dialog in dialogs {
|
||||
let apiPeer: Api.Peer
|
||||
@ -237,8 +246,10 @@ func fetchChatListHole(network: Network, postbox: Postbox, hole: ChatListHole) -
|
||||
let apiReadOutboxMaxId: Int32
|
||||
let apiUnreadCount: Int32
|
||||
let apiNotificationSettings: Api.PeerNotifySettings
|
||||
let isPinned: Bool
|
||||
switch dialog {
|
||||
case let .dialog(_, peer, topMessage, readInboxMaxId, readOutboxMaxId, unreadCount, peerNotificationSettings, _, _):
|
||||
case let .dialog(flags, peer, topMessage, readInboxMaxId, readOutboxMaxId, unreadCount, peerNotificationSettings, _, _):
|
||||
isPinned = (flags & (1 << 2)) != 0
|
||||
apiPeer = peer
|
||||
apiTopMessage = topMessage
|
||||
apiReadInboxMaxId = readInboxMaxId
|
||||
@ -275,13 +286,76 @@ func fetchChatListHole(network: Network, postbox: Postbox, hole: ChatListHole) -
|
||||
|
||||
if let timestamp = timestamp {
|
||||
let index = MessageIndex(id: MessageId(peerId: topMessageId.peerId, namespace: topMessageId.namespace, id: topMessageId.id - 1), timestamp: timestamp)
|
||||
if replacementHole == nil || replacementHole!.index > index {
|
||||
if !isPinned && (replacementHole == nil || replacementHole!.index > index) {
|
||||
replacementHole = ChatListHole(index: index)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var replacePinnedPeerIds: [PeerId]?
|
||||
|
||||
if let pinnedChats = pinnedChats {
|
||||
switch pinnedChats {
|
||||
case let .peerDialogs(apiDialogs, apiMessages, apiChats, apiUsers, _):
|
||||
dialogsChats.append(contentsOf: apiChats)
|
||||
dialogsUsers.append(contentsOf: apiUsers)
|
||||
|
||||
var peerIds: [PeerId] = []
|
||||
|
||||
for dialog in apiDialogs {
|
||||
let apiPeer: Api.Peer
|
||||
let apiReadInboxMaxId: Int32
|
||||
let apiReadOutboxMaxId: Int32
|
||||
let apiTopMessage: Int32
|
||||
let apiUnreadCount: Int32
|
||||
var apiChannelPts: Int32?
|
||||
let apiNotificationSettings: Api.PeerNotifySettings
|
||||
switch dialog {
|
||||
case let .dialog(_, peer, topMessage, readInboxMaxId, readOutboxMaxId, unreadCount, peerNotificationSettings, pts, _):
|
||||
apiPeer = peer
|
||||
apiTopMessage = topMessage
|
||||
apiReadInboxMaxId = readInboxMaxId
|
||||
apiReadOutboxMaxId = readOutboxMaxId
|
||||
apiUnreadCount = unreadCount
|
||||
apiNotificationSettings = peerNotificationSettings
|
||||
apiChannelPts = pts
|
||||
}
|
||||
|
||||
let peerId: PeerId
|
||||
switch apiPeer {
|
||||
case let .peerUser(userId):
|
||||
peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: userId)
|
||||
case let .peerChat(chatId):
|
||||
peerId = PeerId(namespace: Namespaces.Peer.CloudGroup, id: chatId)
|
||||
case let .peerChannel(channelId):
|
||||
peerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: channelId)
|
||||
}
|
||||
|
||||
peerIds.append(peerId)
|
||||
|
||||
if readStates[peerId] == nil {
|
||||
readStates[peerId] = [:]
|
||||
}
|
||||
readStates[peerId]![Namespaces.Message.Cloud] = .idBased(maxIncomingReadId: apiReadInboxMaxId, maxOutgoingReadId: apiReadOutboxMaxId, maxKnownId: apiTopMessage, count: apiUnreadCount)
|
||||
|
||||
if let apiChannelPts = apiChannelPts {
|
||||
chatStates[peerId] = ChannelState(pts: apiChannelPts)
|
||||
}
|
||||
|
||||
notificationSettings[peerId] = TelegramPeerNotificationSettings(apiSettings: apiNotificationSettings)
|
||||
}
|
||||
|
||||
replacePinnedPeerIds = peerIds
|
||||
|
||||
for message in apiMessages {
|
||||
if let storeMessage = StoreMessage(apiMessage: message) {
|
||||
storeMessages.append(storeMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var peers: [Peer] = []
|
||||
var peerPresences: [PeerId: PeerPresence] = [:]
|
||||
for chat in dialogsChats {
|
||||
@ -311,7 +385,7 @@ func fetchChatListHole(network: Network, postbox: Postbox, hole: ChatListHole) -
|
||||
allPeersWithMessages.insert(message.id.peerId)
|
||||
}
|
||||
}
|
||||
modifier.addMessages(storeMessages, location: .UpperHistoryBlock)
|
||||
let _ = modifier.addMessages(storeMessages, location: .UpperHistoryBlock)
|
||||
modifier.replaceChatListHole(hole.index, hole: replacementHole)
|
||||
|
||||
modifier.resetIncomingReadStates(readStates)
|
||||
@ -319,6 +393,10 @@ func fetchChatListHole(network: Network, postbox: Postbox, hole: ChatListHole) -
|
||||
for (peerId, chatState) in chatStates {
|
||||
modifier.setPeerChatState(peerId, state: chatState)
|
||||
}
|
||||
|
||||
if let replacePinnedPeerIds = replacePinnedPeerIds {
|
||||
modifier.setPinnedPeerIds(replacePinnedPeerIds)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,17 +114,17 @@ func managedSynchronizePinnedChatsOperations(postbox: Postbox, network: Network,
|
||||
}
|
||||
|
||||
private func synchronizePinnedChats(modifier: Modifier, postbox: Postbox, network: Network, stateManager: AccountStateManager, operation: SynchronizePinnedChatsOperation) -> Signal<Void, NoError> {
|
||||
let rawPeerIds = modifier.getPinnedPeerIds()
|
||||
let peerIds = rawPeerIds.filter {
|
||||
let initialRemotePeerIds = operation.previousPeerIds
|
||||
let initialRemotePeerIdsWithoutSecretChats = initialRemotePeerIds.filter {
|
||||
$0.namespace != Namespaces.Peer.SecretChat
|
||||
}
|
||||
let localPeerIds = modifier.getPinnedPeerIds()
|
||||
let localPeerIdsWithoutSecretChats = localPeerIds.filter {
|
||||
$0.namespace != Namespaces.Peer.SecretChat
|
||||
}
|
||||
|
||||
/*let peerIdsSet = Set(peerIds)
|
||||
let previousCachedIds = Set(operation.previousPeerIds.filter { $0.namespace != Namespaces.Peer.SecretChat })
|
||||
let removedIds = previousCachedIds.subtracting(peerIdsSet)
|
||||
|
||||
//messages.peerDialogs#3371c354 dialogs:Vector<Dialog> messages:Vector<Message> chats:Vector<Chat> users:Vector<User> state:updates.State = messages.PeerDialogs;
|
||||
let s = network.request(Api.functions.messages.getPinnedDialogs())
|
||||
return network.request(Api.functions.messages.getPinnedDialogs())
|
||||
|> retryRequest
|
||||
|> mapToSignal { dialogs -> Signal<Void, NoError> in
|
||||
let dialogsChats: [Api.Chat]
|
||||
@ -135,6 +135,8 @@ private func synchronizePinnedChats(modifier: Modifier, postbox: Postbox, networ
|
||||
var chatStates: [PeerId: PeerChatState] = [:]
|
||||
var notificationSettings: [PeerId: PeerNotificationSettings] = [:]
|
||||
|
||||
var remotePeerIds: [PeerId] = []
|
||||
|
||||
switch dialogs {
|
||||
case let .peerDialogs(dialogs, messages, chats, users, _):
|
||||
dialogsChats = chats
|
||||
@ -169,6 +171,8 @@ private func synchronizePinnedChats(modifier: Modifier, postbox: Postbox, networ
|
||||
peerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: channelId)
|
||||
}
|
||||
|
||||
remotePeerIds.append(peerId)
|
||||
|
||||
if readStates[peerId] == nil {
|
||||
readStates[peerId] = [:]
|
||||
}
|
||||
@ -188,13 +192,11 @@ private func synchronizePinnedChats(modifier: Modifier, postbox: Postbox, networ
|
||||
}
|
||||
}
|
||||
|
||||
var chatPeers: [Peer] = []
|
||||
var peers: [Peer] = []
|
||||
var peerPresences: [PeerId: PeerPresence] = [:]
|
||||
for chat in dialogsChats {
|
||||
if let groupOrChannel = parseTelegramGroupOrChannel(chat: chat) {
|
||||
peers.append(groupOrChannel)
|
||||
chatPeers.append(groupOrChannel)
|
||||
}
|
||||
}
|
||||
for user in dialogsUsers {
|
||||
@ -205,18 +207,59 @@ private func synchronizePinnedChats(modifier: Modifier, postbox: Postbox, networ
|
||||
}
|
||||
}
|
||||
|
||||
let currentPeersIds = chatPeers.map({ $0.id })
|
||||
let locallyRemovedFromRemotePeerIds = Set(initialRemotePeerIdsWithoutSecretChats).subtracting(Set(localPeerIdsWithoutSecretChats))
|
||||
let remotelyRemovedPeerIds = Set(initialRemotePeerIdsWithoutSecretChats).subtracting(Set(remotePeerIds))
|
||||
|
||||
let cleanedUpPeerIds = currentPeersIds.filter { !removedIds.contains($0) }
|
||||
var resultingPeerIds = localPeerIds.filter { !remotelyRemovedPeerIds.contains($0) }
|
||||
resultingPeerIds.append(contentsOf: remotePeerIds.filter { !locallyRemovedFromRemotePeerIds.contains($0) && !resultingPeerIds.contains($0) })
|
||||
|
||||
var finalPeerIds: [PeerId] = []
|
||||
|
||||
|
||||
return .never()
|
||||
}*/
|
||||
return postbox.modify { modifier -> Signal<Void, NoError> in
|
||||
updatePeers(modifier: modifier, peers: peers, update: { _, updated -> Peer in
|
||||
return updated
|
||||
})
|
||||
modifier.updatePeerPresences(peerPresences)
|
||||
|
||||
modifier.updatePeerNotificationSettings(notificationSettings)
|
||||
|
||||
var allPeersWithMessages = Set<PeerId>()
|
||||
for message in storeMessages {
|
||||
if !allPeersWithMessages.contains(message.id.peerId) {
|
||||
allPeersWithMessages.insert(message.id.peerId)
|
||||
}
|
||||
}
|
||||
let _ = modifier.addMessages(storeMessages, location: .UpperHistoryBlock)
|
||||
|
||||
modifier.resetIncomingReadStates(readStates)
|
||||
|
||||
for (peerId, chatState) in chatStates {
|
||||
modifier.setPeerChatState(peerId, state: chatState)
|
||||
}
|
||||
|
||||
if remotePeerIds == resultingPeerIds {
|
||||
return .complete()
|
||||
} else {
|
||||
var inputPeers: [Api.InputPeer] = []
|
||||
for peerId in resultingPeerIds {
|
||||
if let peer = modifier.getPeer(peerId), let inputPeer = apiInputPeer(peer) {
|
||||
inputPeers.append(inputPeer)
|
||||
}
|
||||
}
|
||||
|
||||
return network.request(Api.functions.messages.reorderPinnedDialogs(flags: 1 << 0, order: inputPeers))
|
||||
|> `catch` { _ -> Signal<Api.Bool, NoError> in
|
||||
return .single(Api.Bool.boolFalse)
|
||||
}
|
||||
|> mapToSignal { result -> Signal<Void, NoError> in
|
||||
return postbox.modify { modifier -> Void in
|
||||
modifier.setPinnedPeerIds(resultingPeerIds)
|
||||
}
|
||||
}
|
||||
}
|
||||
} |> switchToLatest
|
||||
}
|
||||
|
||||
|
||||
var inputPeers: [Api.InputPeer] = []
|
||||
/*var inputPeers: [Api.InputPeer] = []
|
||||
for peerId in peerIds {
|
||||
if let peer = modifier.getPeer(peerId), let inputPeer = apiInputPeer(peer) {
|
||||
inputPeers.append(inputPeer)
|
||||
@ -229,5 +272,5 @@ private func synchronizePinnedChats(modifier: Modifier, postbox: Postbox, networ
|
||||
}
|
||||
|> mapToSignal { result -> Signal<Void, NoError> in
|
||||
return .complete()
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@ -169,7 +169,7 @@ public struct TelegramChannelFlags: OptionSet {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
|
||||
public static let verified = TelegramChannelFlags(rawValue: 1 << 0)
|
||||
public static let isVerified = TelegramChannelFlags(rawValue: 1 << 0)
|
||||
}
|
||||
|
||||
public final class TelegramChannel: Peer {
|
||||
|
||||
@ -5,6 +5,20 @@ import Foundation
|
||||
import Postbox
|
||||
#endif
|
||||
|
||||
public struct UserInfoFlags: OptionSet {
|
||||
public var rawValue: Int32
|
||||
|
||||
public init() {
|
||||
self.rawValue = 0
|
||||
}
|
||||
|
||||
public init(rawValue: Int32) {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
|
||||
public static let isVerified = UserInfoFlags(rawValue: (1 << 0))
|
||||
}
|
||||
|
||||
public struct BotUserInfoFlags: OptionSet {
|
||||
public var rawValue: Int32
|
||||
|
||||
@ -58,6 +72,7 @@ public final class TelegramUser: Peer {
|
||||
public let phone: String?
|
||||
public let photo: [TelegramMediaImageRepresentation]
|
||||
public let botInfo: BotUserInfo?
|
||||
public let flags: UserInfoFlags
|
||||
|
||||
public var name: String {
|
||||
if let firstName = self.firstName {
|
||||
@ -80,7 +95,7 @@ public final class TelegramUser: Peer {
|
||||
public let associatedPeerIds: [PeerId]? = nil
|
||||
public let notificationSettingsPeerId: PeerId? = nil
|
||||
|
||||
public init(id: PeerId, accessHash: Int64?, firstName: String?, lastName: String?, username: String?, phone: String?, photo: [TelegramMediaImageRepresentation], botInfo: BotUserInfo?) {
|
||||
public init(id: PeerId, accessHash: Int64?, firstName: String?, lastName: String?, username: String?, phone: String?, photo: [TelegramMediaImageRepresentation], botInfo: BotUserInfo?, flags: UserInfoFlags) {
|
||||
self.id = id
|
||||
self.accessHash = accessHash
|
||||
self.firstName = firstName
|
||||
@ -89,6 +104,7 @@ public final class TelegramUser: Peer {
|
||||
self.phone = phone
|
||||
self.photo = photo
|
||||
self.botInfo = botInfo
|
||||
self.flags = flags
|
||||
}
|
||||
|
||||
public init(decoder: Decoder) {
|
||||
@ -114,6 +130,8 @@ public final class TelegramUser: Peer {
|
||||
} else {
|
||||
self.botInfo = nil
|
||||
}
|
||||
|
||||
self.flags = UserInfoFlags(rawValue: decoder.decodeInt32ForKey("fl"))
|
||||
}
|
||||
|
||||
public func encode(_ encoder: Encoder) {
|
||||
@ -144,6 +162,8 @@ public final class TelegramUser: Peer {
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "bi")
|
||||
}
|
||||
|
||||
encoder.encodeInt32(self.flags.rawValue, forKey: "fl")
|
||||
}
|
||||
|
||||
public func isEqual(_ other: Peer) -> Bool {
|
||||
@ -175,6 +195,10 @@ public final class TelegramUser: Peer {
|
||||
return false
|
||||
}
|
||||
|
||||
if self.flags != other.flags {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
@ -182,16 +206,19 @@ public final class TelegramUser: Peer {
|
||||
}
|
||||
|
||||
func withUpdatedUsername(_ username:String?) -> TelegramUser {
|
||||
return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: self.firstName, lastName: self.lastName, username: username, phone: self.phone, photo: self.photo, botInfo: self.botInfo)
|
||||
return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: self.firstName, lastName: self.lastName, username: username, phone: self.phone, photo: self.photo, botInfo: self.botInfo, flags: self.flags)
|
||||
}
|
||||
func withUpdatedNames(firstName:String?, lastName:String?) -> TelegramUser {
|
||||
return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: firstName, lastName: lastName, username: self.username, phone: self.phone, photo: self.photo, botInfo: self.botInfo)
|
||||
|
||||
func withUpdatedNames(firstName: String?, lastName: String?) -> TelegramUser {
|
||||
return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: firstName, lastName: lastName, username: self.username, phone: self.phone, photo: self.photo, botInfo: self.botInfo, flags: self.flags)
|
||||
}
|
||||
func withUpdatedPhone(_ phone:String) -> TelegramUser {
|
||||
return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: self.firstName, lastName: self.lastName, username: self.username, phone: phone, photo: self.photo, botInfo: self.botInfo)
|
||||
|
||||
func withUpdatedPhone(_ phone: String) -> TelegramUser {
|
||||
return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: self.firstName, lastName: self.lastName, username: self.username, phone: phone, photo: self.photo, botInfo: self.botInfo, flags: self.flags)
|
||||
}
|
||||
func withUpdatedPhoto(_ representations:[TelegramMediaImageRepresentation]) -> TelegramUser {
|
||||
return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: self.firstName, lastName: self.lastName, username: self.username, phone: phone, photo: representations, botInfo: self.botInfo)
|
||||
|
||||
func withUpdatedPhoto(_ representations: [TelegramMediaImageRepresentation]) -> TelegramUser {
|
||||
return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: self.firstName, lastName: self.lastName, username: self.username, phone: phone, photo: representations, botInfo: self.botInfo, flags: self.flags)
|
||||
}
|
||||
}
|
||||
|
||||
@ -211,6 +238,12 @@ public extension TelegramUser {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
var userFlags: UserInfoFlags = []
|
||||
if (flags & (1 << 17)) != 0 {
|
||||
userFlags.insert(.isVerified)
|
||||
}
|
||||
|
||||
var botInfo: BotUserInfo?
|
||||
if (flags & (1 << 14)) != 0 {
|
||||
var botFlags = BotUserInfoFlags()
|
||||
@ -225,9 +258,9 @@ public extension TelegramUser {
|
||||
}
|
||||
botInfo = BotUserInfo(flags: botFlags, inlinePlaceholder: botInlinePlaceholder)
|
||||
}
|
||||
self.init(id: PeerId(namespace: Namespaces.Peer.CloudUser, id: id), accessHash: accessHash, firstName: firstName, lastName: lastName, username: username, phone: phone, photo: telegramPhoto, botInfo: botInfo)
|
||||
self.init(id: PeerId(namespace: Namespaces.Peer.CloudUser, id: id), accessHash: accessHash, firstName: firstName, lastName: lastName, username: username, phone: phone, photo: telegramPhoto, botInfo: botInfo, flags: userFlags)
|
||||
case let .userEmpty(id):
|
||||
self.init(id: PeerId(namespace: Namespaces.Peer.CloudUser, id: id), accessHash: nil, firstName: nil, lastName: nil, username: nil, phone: nil, photo: [], botInfo: nil)
|
||||
self.init(id: PeerId(namespace: Namespaces.Peer.CloudUser, id: id), accessHash: nil, firstName: nil, lastName: nil, username: nil, phone: nil, photo: [], botInfo: nil, flags: [])
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,6 +283,11 @@ public extension TelegramUser {
|
||||
}
|
||||
}
|
||||
if let lhs = lhs {
|
||||
var userFlags: UserInfoFlags = []
|
||||
if (flags & (1 << 17)) != 0 {
|
||||
userFlags.insert(.isVerified)
|
||||
}
|
||||
|
||||
var botInfo: BotUserInfo?
|
||||
if (flags & (1 << 14)) != 0 {
|
||||
var botFlags = BotUserInfoFlags()
|
||||
@ -265,7 +303,7 @@ public extension TelegramUser {
|
||||
botInfo = BotUserInfo(flags: botFlags, inlinePlaceholder: botInlinePlaceholder)
|
||||
}
|
||||
|
||||
return TelegramUser(id: lhs.id, accessHash: lhs.accessHash, firstName: lhs.firstName, lastName: lhs.lastName, username: username, phone: lhs.phone, photo: telegramPhoto, botInfo: botInfo)
|
||||
return TelegramUser(id: lhs.id, accessHash: lhs.accessHash, firstName: lhs.firstName, lastName: lhs.lastName, username: username, phone: lhs.phone, photo: telegramPhoto, botInfo: botInfo, flags: userFlags)
|
||||
} else {
|
||||
return TelegramUser(user: rhs)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user