no message

This commit is contained in:
Peter Iakovlev 2018-01-18 11:06:44 +04:00
parent 43043843b2
commit b6a7cc8eb0
4 changed files with 122 additions and 105 deletions

View File

@ -1320,7 +1320,14 @@ private func resetChannels(_ account: Account, peers: [Peer], state: AccountMuta
}
}
return account.network.request(Api.functions.messages.getPeerDialogs(peers: inputPeers))
|> retryRequest
|> map(Optional.init)
|> `catch` { error -> Signal<Api.messages.PeerDialogs?, Void> in
if error.errorDescription == "CHANNEL_PRIVATE" && inputPeers.count == 1 {
return .single(nil)
} else {
return .single(nil)
}
}
|> map { result -> AccountMutableState in
var updatedState = state
@ -1333,6 +1340,7 @@ private func resetChannels(_ account: Account, peers: [Peer], state: AccountMuta
var channelStates: [PeerId: ChannelState] = [:]
var notificationSettings: [PeerId: PeerNotificationSettings] = [:]
if let result = result {
switch result {
case let .peerDialogs(dialogs, messages, chats, users, _):
dialogsChats.append(contentsOf: chats)
@ -1402,6 +1410,7 @@ private func resetChannels(_ account: Account, peers: [Peer], state: AccountMuta
}
}
}
}
updatedState.mergeChats(dialogsChats)
updatedState.mergeUsers(dialogsUsers)
@ -1776,10 +1785,16 @@ func replayFinalState(accountPeerId: PeerId, mediaBox: MediaBox, modifier: Modif
modifier.deleteMessagesInRange(peerId: id.peerId, namespace: id.namespace, minId: 1, maxId: id.id)
case let .EditMessage(id, message):
modifier.updateMessage(id, update: { previousMessage in
var updatedFlags = message.flags
var updatedLocalTags = message.localTags
if previousMessage.localTags.contains(.OutgoingLiveLocation) {
updatedLocalTags.insert(.OutgoingLiveLocation)
}
if message.flags.contains(.Incoming) {
updatedFlags.insert(.Incoming)
} else {
updatedFlags.remove(.Incoming)
}
return .update(message.withUpdatedLocalTags(updatedLocalTags))
})
case let .UpdateMedia(id, media):

View File

@ -132,7 +132,7 @@ final class HistoryViewChannelStateValidationContexts {
}
}
if !addedRanges.isEmpty && addedRanges[rangesToInvalidate.count - 1].isEmpty {
if !addedRanges.isEmpty && addedRanges[addedRanges.count - 1].isEmpty {
addedRanges.removeLast()
}
@ -318,7 +318,7 @@ private func validateBatch(postbox: Postbox, network: Network, messageIds: [Mess
}
}
attributes.append(ChannelMessageStateVersionAttribute(pts: validatePts))
return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media))
return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media))
})
}
return
@ -380,7 +380,7 @@ private func validateBatch(postbox: Postbox, network: Network, messageIds: [Mess
}
attributes.append(ChannelMessageStateVersionAttribute(pts: channelPts))
}
return .update(StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media))
return .update(StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media))
}
})
}

View File

@ -119,8 +119,8 @@ private func synchronizePinnedChats(modifier: Modifier, postbox: Postbox, networ
switch item {
case let .peer(peerId):
return peerId.namespace != Namespaces.Peer.SecretChat
case .group:
return false
default:
return true
}
}
let localItemIds = modifier.getPinnedItemIds()
@ -128,17 +128,14 @@ private func synchronizePinnedChats(modifier: Modifier, postbox: Postbox, networ
switch item {
case let .peer(peerId):
return peerId.namespace != Namespaces.Peer.SecretChat
case .group:
return false
default:
return true
}
}
return network.request(Api.functions.messages.getPinnedDialogs())
|> retryRequest
|> mapToSignal { dialogs -> Signal<Void, NoError> in
let dialogsChats: [Api.Chat]
let dialogsUsers: [Api.User]
var storeMessages: [StoreMessage] = []
var readStates: [PeerId: [MessageId.Namespace: PeerReadState]] = [:]
var chatStates: [PeerId: PeerChatState] = [:]
@ -146,10 +143,27 @@ private func synchronizePinnedChats(modifier: Modifier, postbox: Postbox, networ
var remoteItemIds: [PinnedItemId] = []
var peers: [Peer] = []
var peerPresences: [PeerId: PeerPresence] = [:]
switch dialogs {
case let .peerDialogs(dialogs, messages, chats, users, _):
dialogsChats = chats
dialogsUsers = users
var channelGroupIds: [PeerId: PeerGroupId] = [:]
for chat in chats {
if let groupOrChannel = parseTelegramGroupOrChannel(chat: chat) {
peers.append(groupOrChannel)
if let channel = groupOrChannel as? TelegramChannel, let peerGroupId = channel.peerGroupId {
channelGroupIds[channel.id] = peerGroupId
}
}
}
for user in users {
let telegramUser = TelegramUser(user: user)
peers.append(telegramUser)
if let presence = TelegramUserPresence(apiUser: user) {
peerPresences[telegramUser.id] = presence
}
}
loop: for dialog in dialogs {
let apiPeer: Api.Peer
@ -161,6 +175,9 @@ private func synchronizePinnedChats(modifier: Modifier, postbox: Postbox, networ
let apiNotificationSettings: Api.PeerNotifySettings
switch dialog {
case let .dialog(_, peer, topMessage, readInboxMaxId, readOutboxMaxId, unreadCount, unreadMentionsCount, peerNotificationSettings, pts, _):
if channelGroupIds[peer.peerId] != nil {
continue loop
}
apiPeer = peer
apiTopMessage = topMessage
apiReadInboxMaxId = readInboxMaxId
@ -204,21 +221,6 @@ private func synchronizePinnedChats(modifier: Modifier, postbox: Postbox, networ
}
}
var peers: [Peer] = []
var peerPresences: [PeerId: PeerPresence] = [:]
for chat in dialogsChats {
if let groupOrChannel = parseTelegramGroupOrChannel(chat: chat) {
peers.append(groupOrChannel)
}
}
for user in dialogsUsers {
let telegramUser = TelegramUser(user: user)
peers.append(telegramUser)
if let presence = TelegramUserPresence(apiUser: user) {
peerPresences[telegramUser.id] = presence
}
}
let locallyRemovedFromRemoteItemIds = Set(initialRemoteItemIdsWithoutSecretChats).subtracting(Set(localItemIdsWithoutSecretChats))
let remotelyRemovedItemIds = Set(initialRemoteItemIdsWithoutSecretChats).subtracting(Set(remoteItemIds))