mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-05 05:51:42 +00:00
no message
This commit is contained in:
parent
2734a8a2ad
commit
4190cf8759
@ -1940,6 +1940,14 @@ func replayFinalState(accountPeerId: PeerId, mediaBox: MediaBox, transaction: Tr
|
|||||||
transaction.applyMarkUnread(peerId: peerId, namespace: namespace, value: value, interactive: false)
|
transaction.applyMarkUnread(peerId: peerId, namespace: namespace, value: value, interactive: false)
|
||||||
case let .ResetMessageTagSummary(peerId, namespace, count, range):
|
case let .ResetMessageTagSummary(peerId, namespace, count, range):
|
||||||
transaction.replaceMessageTagSummary(peerId: peerId, tagMask: .unseenPersonalMessage, namespace: namespace, count: count, maxId: range.maxId)
|
transaction.replaceMessageTagSummary(peerId: peerId, tagMask: .unseenPersonalMessage, namespace: namespace, count: count, maxId: range.maxId)
|
||||||
|
if count == 0 {
|
||||||
|
let ids = transaction.getMessageIndicesWithTag(peerId: peerId, tag: .unseenPersonalMessage).map({ $0.id })
|
||||||
|
for id in ids {
|
||||||
|
if id.namespace == namespace {
|
||||||
|
markUnseenPersonalMessage(transaction: transaction, id: id, addSynchronizeAction: false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
case let .UpdateState(state):
|
case let .UpdateState(state):
|
||||||
let currentState = transaction.getState() as! AuthorizedAccountState
|
let currentState = transaction.getState() as! AuthorizedAccountState
|
||||||
transaction.setState(currentState.changedState(state))
|
transaction.setState(currentState.changedState(state))
|
||||||
|
|||||||
@ -465,7 +465,12 @@ public final class AccountViewTracker {
|
|||||||
let _ = (account.postbox.transaction { transaction -> Set<MessageId> in
|
let _ = (account.postbox.transaction { transaction -> Set<MessageId> in
|
||||||
let ids = Set(transaction.getMessageIndicesWithTag(peerId: peerId, tag: .unseenPersonalMessage).map({ $0.id }))
|
let ids = Set(transaction.getMessageIndicesWithTag(peerId: peerId, tag: .unseenPersonalMessage).map({ $0.id }))
|
||||||
if let summary = transaction.getMessageTagSummary(peerId: peerId, tagMask: .unseenPersonalMessage, namespace: Namespaces.Message.Cloud), summary.count > 0 {
|
if let summary = transaction.getMessageTagSummary(peerId: peerId, tagMask: .unseenPersonalMessage, namespace: Namespaces.Message.Cloud), summary.count > 0 {
|
||||||
transaction.replaceMessageTagSummary(peerId: peerId, tagMask: .unseenPersonalMessage, namespace: Namespaces.Message.Cloud, count: 0, maxId: summary.range.maxId)
|
var maxId: Int32 = summary.range.maxId
|
||||||
|
if let index = transaction.getTopPeerMessageIndex(peerId: peerId, namespace: Namespaces.Message.Cloud) {
|
||||||
|
maxId = index.id.id
|
||||||
|
}
|
||||||
|
|
||||||
|
transaction.replaceMessageTagSummary(peerId: peerId, tagMask: .unseenPersonalMessage, namespace: Namespaces.Message.Cloud, count: 0, maxId: maxId)
|
||||||
addSynchronizeMarkAllUnseenPersonalMessagesOperation(transaction: transaction, peerId: peerId, maxId: summary.range.maxId)
|
addSynchronizeMarkAllUnseenPersonalMessagesOperation(transaction: transaction, peerId: peerId, maxId: summary.range.maxId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -125,50 +125,70 @@ private func synchronizeMarkAllUnseen(transaction: Transaction, postbox: Postbox
|
|||||||
return .complete()
|
return .complete()
|
||||||
}
|
}
|
||||||
let inputChannel = transaction.getPeer(peerId).flatMap(apiInputChannel)
|
let inputChannel = transaction.getPeer(peerId).flatMap(apiInputChannel)
|
||||||
let oneOperation: Signal<Bool, MTRpcError> = network.request(Api.functions.messages.getUnreadMentions(peer: inputPeer, offsetId: 0, addOffset: 0, limit: 100, maxId: 0, minId: 0))
|
let limit: Int32 = 100
|
||||||
|> mapToSignal { result -> Signal<[MessageId], MTRpcError> in
|
let oneOperation: (Int32) -> Signal<Int32?, MTRpcError> = { maxId in
|
||||||
switch result {
|
return network.request(Api.functions.messages.getUnreadMentions(peer: inputPeer, offsetId: maxId, addOffset: maxId == 0 ? 0 : -1, limit: limit, maxId: maxId == 0 ? 0 : (maxId + 1), minId: 1))
|
||||||
case let .messages(messages, _, _):
|
|> mapToSignal { result -> Signal<[MessageId], MTRpcError> in
|
||||||
return .single(messages.compactMap({ $0.id }))
|
switch result {
|
||||||
case let .channelMessages(channelMessages):
|
case let .messages(messages, _, _):
|
||||||
return .single(channelMessages.messages.compactMap({ $0.id }))
|
return .single(messages.compactMap({ $0.id }))
|
||||||
case .messagesNotModified:
|
case let .channelMessages(channelMessages):
|
||||||
return .single([])
|
return .single(channelMessages.messages.compactMap({ $0.id }))
|
||||||
case let .messagesSlice(messagesSlice):
|
case .messagesNotModified:
|
||||||
return .single(messagesSlice.messages.compactMap({ $0.id }))
|
return .single([])
|
||||||
|
case let .messagesSlice(messagesSlice):
|
||||||
|
return .single(messagesSlice.messages.compactMap({ $0.id }))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|> mapToSignal { ids -> Signal<Int32?, MTRpcError> in
|
||||||
|> mapToSignal { ids -> Signal<Bool, MTRpcError> in
|
let filteredIds = ids.filter { $0.id <= operation.maxId }
|
||||||
if peerId.namespace == Namespaces.Peer.CloudChannel {
|
if filteredIds.isEmpty {
|
||||||
guard let inputChannel = inputChannel else {
|
return .single(ids.min()?.id)
|
||||||
return .single(true)
|
|
||||||
}
|
}
|
||||||
return network.request(Api.functions.channels.readMessageContents(channel: inputChannel, id: ids.map { $0.id }))
|
if peerId.namespace == Namespaces.Peer.CloudChannel {
|
||||||
|> mapToSignal { result -> Signal<Bool, MTRpcError> in
|
guard let inputChannel = inputChannel else {
|
||||||
return .single(true)
|
return .single(nil)
|
||||||
}
|
}
|
||||||
} else {
|
return network.request(Api.functions.channels.readMessageContents(channel: inputChannel, id: filteredIds.map { $0.id }))
|
||||||
return network.request(Api.functions.messages.readMessageContents(id: ids.map { $0.id }))
|
|> map { result -> Int32? in
|
||||||
|> mapToSignal { result -> Signal<Bool, MTRpcError> in
|
if ids.count < limit {
|
||||||
switch result {
|
return nil
|
||||||
case let .affectedMessages(pts, ptsCount):
|
} else {
|
||||||
stateManager.addUpdateGroups([.updatePts(pts: pts, ptsCount: ptsCount)])
|
return ids.min()?.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return network.request(Api.functions.messages.readMessageContents(id: filteredIds.map { $0.id }))
|
||||||
|
|> map { result -> Int32? in
|
||||||
|
switch result {
|
||||||
|
case let .affectedMessages(pts, ptsCount):
|
||||||
|
stateManager.addUpdateGroups([.updatePts(pts: pts, ptsCount: ptsCount)])
|
||||||
|
}
|
||||||
|
if ids.count < limit {
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return ids.min()?.id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return .single(true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let currentMaxId = Atomic<Int32>(value: 0)
|
||||||
let loopOperations: Signal<Void, GetUnseenIdsError> = (
|
let loopOperations: Signal<Void, GetUnseenIdsError> = (
|
||||||
(oneOperation
|
(
|
||||||
|> `catch` { error -> Signal<Bool, GetUnseenIdsError> in
|
deferred {
|
||||||
|
return oneOperation(currentMaxId.with { $0 })
|
||||||
|
}
|
||||||
|
|> `catch` { error -> Signal<Int32?, GetUnseenIdsError> in
|
||||||
return .fail(.error(error))
|
return .fail(.error(error))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|> mapToSignal { result -> Signal<Void, GetUnseenIdsError> in
|
|> mapToSignal { resultId -> Signal<Void, GetUnseenIdsError> in
|
||||||
if result {
|
if let resultId = resultId {
|
||||||
return .fail(.done)
|
let _ = currentMaxId.swap(resultId)
|
||||||
} else {
|
|
||||||
return .complete()
|
return .complete()
|
||||||
|
} else {
|
||||||
|
return .fail(.done)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|> `catch` { error -> Signal<Void, GetUnseenIdsError> in
|
|> `catch` { error -> Signal<Void, GetUnseenIdsError> in
|
||||||
@ -184,3 +204,31 @@ private func synchronizeMarkAllUnseen(transaction: Transaction, postbox: Postbox
|
|||||||
return .complete()
|
return .complete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func markUnseenPersonalMessage(transaction: Transaction, id: MessageId, addSynchronizeAction: Bool) {
|
||||||
|
if let message = transaction.getMessage(id) {
|
||||||
|
var consume = false
|
||||||
|
inner: for attribute in message.attributes {
|
||||||
|
if let attribute = attribute as? ConsumablePersonalMentionMessageAttribute, !attribute.consumed, !attribute.pending {
|
||||||
|
consume = true
|
||||||
|
break inner
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if consume {
|
||||||
|
transaction.updateMessage(id, update: { currentMessage in
|
||||||
|
var attributes = currentMessage.attributes
|
||||||
|
loop: for j in 0 ..< attributes.count {
|
||||||
|
if let attribute = attributes[j] as? ConsumablePersonalMentionMessageAttribute {
|
||||||
|
attributes[j] = ConsumablePersonalMentionMessageAttribute(consumed: attribute.consumed, pending: true)
|
||||||
|
break loop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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: currentMessage.forwardInfo.flatMap(StoreMessageForwardInfo.init), authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media))
|
||||||
|
})
|
||||||
|
|
||||||
|
if addSynchronizeAction {
|
||||||
|
transaction.setPendingMessageAction(type: .consumeUnseenPersonalMessage, id: id, action: ConsumePersonalMessageAction())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user