no message

This commit is contained in:
Peter
2017-03-20 18:34:28 +03:00
parent ee7d69819c
commit 1d730c968d
9 changed files with 206 additions and 36 deletions

View File

@@ -987,7 +987,7 @@ private func finalStateWithUpdates(account: Account, state: AccountMutableState,
} }
} }
var pollChannelSignals: [Signal<(AccountMutableState, Bool), NoError>] = [] var pollChannelSignals: [Signal<(AccountMutableState, Bool, Int32?), NoError>] = []
for peerId in channelsToPoll { for peerId in channelsToPoll {
if let peer = updatedState.peers[peerId] { if let peer = updatedState.peers[peerId] {
pollChannelSignals.append(pollChannel(account, peer: peer, state: updatedState.branch())) pollChannelSignals.append(pollChannel(account, peer: peer, state: updatedState.branch()))
@@ -999,7 +999,7 @@ private func finalStateWithUpdates(account: Account, state: AccountMutableState,
return combineLatest(pollChannelSignals) |> mapToSignal { states -> Signal<AccountFinalState, NoError> in return combineLatest(pollChannelSignals) |> mapToSignal { states -> Signal<AccountFinalState, NoError> in
var finalState = updatedState var finalState = updatedState
var hadError = false var hadError = false
for (state, success) in states { for (state, success, _) in states {
finalState.merge(state) finalState.merge(state)
if !success { if !success {
hadError = true hadError = true
@@ -1123,7 +1123,42 @@ private func resolveMissingPeerNotificationSettings(account: Account, state: Acc
} }
} }
private func pollChannel(_ account: Account, peer: Peer, state: AccountMutableState) -> Signal<(AccountMutableState, Bool), NoError> { func keepPollingChannel(account: Account, peerId: PeerId, stateManager: AccountStateManager) -> Signal<Void, NoError> {
return account.postbox.modify { modifier -> Signal<Void, NoError> in
if let accountState = (modifier.getState() as? AuthorizedAccountState)?.state, let peer = modifier.getPeer(peerId) {
var channelStates: [PeerId: ChannelState] = [:]
if let channelState = modifier.getPeerChatState(peerId) as? ChannelState {
channelStates[peerId] = channelState
}
let initialPeers: [PeerId: Peer] = [peerId: peer]
var peerNotificationSettings: [PeerId: TelegramPeerNotificationSettings] = [:]
if let notificationSettings = modifier.getPeerNotificationSettings(peerId) as? TelegramPeerNotificationSettings {
peerNotificationSettings[peerId] = notificationSettings
}
let initialState = AccountMutableState(initialState: AccountInitialState(state: accountState, peerIds: Set(), messageIds: Set(), peerIdsWithNewMessages: Set(), channelStates: channelStates, peerNotificationSettings: peerNotificationSettings, locallyGeneratedMessageTimestamps: [:]), initialPeers: initialPeers, initialStoredMessages: Set(), initialReadInboxMaxIds: [:], storedMessagesByPeerIdAndTimestamp: [:])
return pollChannel(account, peer: peer, state: initialState)
|> mapToSignal { (finalState, _, timeout) -> Signal<Void, NoError> in
return resolveAssociatedMessages(account: account, state: finalState)
|> mapToSignal { resultingState -> Signal<AccountFinalState, NoError> in
return resolveMissingPeerNotificationSettings(account: account, state: resultingState)
|> map { resultingState -> AccountFinalState in
return AccountFinalState(state: resultingState, shouldPoll: false, incomplete: false)
}
}
|> mapToSignal { finalState -> Signal<Void, NoError> in
return stateManager.addReplayAsynchronouslyBuiltFinalState(finalState)
|> mapToSignal { _ -> Signal<Void, NoError> in
return .complete() |> delay(Double(timeout ?? 30), queue: Queue.concurrentDefaultQueue())
}
}
}
} else {
return .complete() |> delay(30.0, queue: Queue.concurrentDefaultQueue())
}
} |> switchToLatest |> restart
}
private func pollChannel(_ account: Account, peer: Peer, state: AccountMutableState) -> Signal<(AccountMutableState, Bool, Int32?), NoError> {
if let inputChannel = apiInputChannel(peer) { if let inputChannel = apiInputChannel(peer) {
return (account.network.request(Api.functions.updates.getChannelDifference(flags: 0, channel: inputChannel, filter: .channelMessagesFilterEmpty, pts: state.channelStates[peer.id]?.pts ?? 1, limit: 20)) return (account.network.request(Api.functions.updates.getChannelDifference(flags: 0, channel: inputChannel, filter: .channelMessagesFilterEmpty, pts: state.channelStates[peer.id]?.pts ?? 1, limit: 20))
|> map { Optional($0) } |> map { Optional($0) }
@@ -1135,11 +1170,13 @@ private func pollChannel(_ account: Account, peer: Peer, state: AccountMutableSt
} }
}) })
|> retryRequest |> retryRequest
|> map { difference -> (AccountMutableState, Bool) in |> map { difference -> (AccountMutableState, Bool, Int32?) in
var updatedState = state var updatedState = state
var apiTimeout: Int32?
if let difference = difference { if let difference = difference {
switch difference { switch difference {
case let .channelDifference(_, pts, _, newMessages, otherUpdates, chats, users): case let .channelDifference(_, pts, timeout, newMessages, otherUpdates, chats, users):
apiTimeout = timeout
let channelState: ChannelState let channelState: ChannelState
if let previousState = updatedState.channelStates[peer.id] { if let previousState = updatedState.channelStates[peer.id] {
channelState = previousState.setPts(pts) channelState = previousState.setPts(pts)
@@ -1170,7 +1207,9 @@ private func pollChannel(_ account: Account, peer: Peer, state: AccountMutableSt
break break
} }
} }
case let .channelDifferenceEmpty(_, pts, _): case let .channelDifferenceEmpty(_, pts, timeout):
apiTimeout = timeout
let channelState: ChannelState let channelState: ChannelState
if let previousState = updatedState.channelStates[peer.id] { if let previousState = updatedState.channelStates[peer.id] {
channelState = previousState.setPts(pts) channelState = previousState.setPts(pts)
@@ -1178,7 +1217,9 @@ private func pollChannel(_ account: Account, peer: Peer, state: AccountMutableSt
channelState = ChannelState(pts: pts) channelState = ChannelState(pts: pts)
} }
updatedState.updateChannelState(peer.id, state: channelState) updatedState.updateChannelState(peer.id, state: channelState)
case let .channelDifferenceTooLong(_, pts, _, topMessage, readInboxMaxId, readOutboxMaxId, unreadCount, messages, chats, users): case let .channelDifferenceTooLong(_, pts, timeout, topMessage, readInboxMaxId, readOutboxMaxId, unreadCount, messages, chats, users):
apiTimeout = timeout
let channelState: ChannelState let channelState: ChannelState
if let previousState = updatedState.channelStates[peer.id] { if let previousState = updatedState.channelStates[peer.id] {
channelState = previousState.setPts(pts) channelState = previousState.setPts(pts)
@@ -1213,11 +1254,11 @@ private func pollChannel(_ account: Account, peer: Peer, state: AccountMutableSt
updatedState.resetReadState(peer.id, namespace: Namespaces.Message.Cloud, maxIncomingReadId: readInboxMaxId, maxOutgoingReadId: readOutboxMaxId, maxKnownId: topMessage, count: unreadCount) updatedState.resetReadState(peer.id, namespace: Namespaces.Message.Cloud, maxIncomingReadId: readInboxMaxId, maxOutgoingReadId: readOutboxMaxId, maxKnownId: topMessage, count: unreadCount)
} }
} }
return (updatedState, difference != nil) return (updatedState, difference != nil, apiTimeout)
} }
} else { } else {
Logger.shared.log("State", "can't poll channel \(peer.id): can't create inputChannel") Logger.shared.log("State", "can't poll channel \(peer.id): can't create inputChannel")
return single((state, true), NoError.self) return single((state, true, nil), NoError.self)
} }
} }
@@ -1387,7 +1428,7 @@ func replayFinalState(accountPeerId: PeerId, mediaBox: MediaBox, modifier: Modif
case let .DeleteMessages(ids): case let .DeleteMessages(ids):
modifier.deleteMessages(ids) modifier.deleteMessages(ids)
case let .EditMessage(id, message): case let .EditMessage(id, message):
modifier.updateMessage(id, update: { _ in message }) modifier.updateMessage(id, update: { _ in .update(message) })
case let .UpdateMedia(id, media): case let .UpdateMedia(id, media):
modifier.updateMedia(id, update: media) modifier.updateMedia(id, update: media)
if let media = media as? TelegramMediaWebpage { if let media = media as? TelegramMediaWebpage {
@@ -1507,7 +1548,7 @@ func replayFinalState(accountPeerId: PeerId, mediaBox: MediaBox, modifier: Modif
break loop break loop
} }
} }
return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media) return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media))
}) })
case let .UpdateInstalledStickerPacks(operation): case let .UpdateInstalledStickerPacks(operation):
stickerPackOperations.append(operation) stickerPackOperations.append(operation)

View File

@@ -16,6 +16,7 @@ private enum AccountStateManagerOperation {
case custom(Int32, Signal<Void, NoError>) case custom(Int32, Signal<Void, NoError>)
case pollCompletion(Int32, [MessageId], [(Int32, ([MessageId]) -> Void)]) case pollCompletion(Int32, [MessageId], [(Int32, ([MessageId]) -> Void)])
case processEvents(Int32, AccountFinalStateEvents) case processEvents(Int32, AccountFinalStateEvents)
case replayAsynchronouslyBuiltFinalState(AccountFinalState, () -> Void)
} }
#if os(macOS) #if os(macOS)
@@ -117,7 +118,7 @@ public final class AccountStateManager {
self.queue.async { self.queue.async {
if let last = self.operations.last { if let last = self.operations.last {
switch last { switch last {
case .pollDifference, .processUpdateGroups, .custom, .pollCompletion, .processEvents: case .pollDifference, .processUpdateGroups, .custom, .pollCompletion, .processEvents, .replayAsynchronouslyBuiltFinalState:
self.operations.append(.collectUpdateGroups(groups, 0.0)) self.operations.append(.collectUpdateGroups(groups, 0.0))
case let .collectUpdateGroups(currentGroups, timestamp): case let .collectUpdateGroups(currentGroups, timestamp):
if timestamp.isEqual(to: 0.0) { if timestamp.isEqual(to: 0.0) {
@@ -134,6 +135,22 @@ public final class AccountStateManager {
} }
} }
func addReplayAsynchronouslyBuiltFinalState(_ finalState: AccountFinalState) -> Signal<Bool, NoError> {
return Signal { subscriber in
self.queue.async {
let begin = self.operations.isEmpty
self.operations.append(.replayAsynchronouslyBuiltFinalState(finalState, {
subscriber.putNext(true)
subscriber.putCompletion()
}))
if begin {
self.startFirstOperation()
}
}
return EmptyDisposable
}
}
func addCustomOperation<T, E>(_ f: Signal<T, E>) -> Signal<T, E> { func addCustomOperation<T, E>(_ f: Signal<T, E>) -> Signal<T, E> {
let pipe = ValuePipe<CustomOperationEvent<T, E>>() let pipe = ValuePipe<CustomOperationEvent<T, E>>()
return Signal<T, E> { subscriber in return Signal<T, E> { subscriber in
@@ -169,13 +186,17 @@ public final class AccountStateManager {
private func replaceOperations(with operation: AccountStateManagerOperation) { private func replaceOperations(with operation: AccountStateManagerOperation) {
var collectedMessageIds: [MessageId] = [] var collectedMessageIds: [MessageId] = []
var collectedPollCompletionSubscribers: [(Int32, ([MessageId]) -> Void)] = [] var collectedPollCompletionSubscribers: [(Int32, ([MessageId]) -> Void)] = []
var collectedReplayAsynchronouslyBuiltFinalState: [(AccountFinalState, () -> Void)] = []
if !self.operations.isEmpty {
for operation in self.operations { for operation in self.operations {
if case let .pollCompletion(_, messageIds, subscribers) = operation { switch operation {
case let .pollCompletion(_, messageIds, subscribers):
collectedMessageIds.append(contentsOf: messageIds) collectedMessageIds.append(contentsOf: messageIds)
collectedPollCompletionSubscribers.append(contentsOf: subscribers) collectedPollCompletionSubscribers.append(contentsOf: subscribers)
} case let .replayAsynchronouslyBuiltFinalState(finalState, completion):
collectedReplayAsynchronouslyBuiltFinalState.append((finalState, completion))
default:
break
} }
} }
@@ -185,6 +206,10 @@ public final class AccountStateManager {
if !collectedPollCompletionSubscribers.isEmpty || !collectedMessageIds.isEmpty { if !collectedPollCompletionSubscribers.isEmpty || !collectedMessageIds.isEmpty {
self.operations.append(.pollCompletion(self.getNextId(), collectedMessageIds, collectedPollCompletionSubscribers)) self.operations.append(.pollCompletion(self.getNextId(), collectedMessageIds, collectedPollCompletionSubscribers))
} }
for (finalState, completion) in collectedReplayAsynchronouslyBuiltFinalState {
self.operations.append(.replayAsynchronouslyBuiltFinalState(finalState, completion))
}
} }
private func addOperation(_ operation: AccountStateManagerOperation) { private func addOperation(_ operation: AccountStateManagerOperation) {
@@ -477,6 +502,41 @@ public final class AccountStateManager {
completed() completed()
}) })
} }
case let .replayAsynchronouslyBuiltFinalState(finalState, completion):
if !finalState.state.preCachedResources.isEmpty {
for (resource, data) in finalState.state.preCachedResources {
self.account.postbox.mediaBox.storeResourceData(resource.id, data: data)
}
}
let accountPeerId = self.account.peerId
let mediaBox = self.account.postbox.mediaBox
let signal = self.account.postbox.modify { modifier -> AccountReplayedFinalState? in
return replayFinalState(accountPeerId: accountPeerId, mediaBox: mediaBox, modifier: modifier, finalState: finalState)
}
|> map({ ($0, finalState) })
|> deliverOn(self.queue)
let _ = signal.start(next: { [weak self] replayedState, finalState in
if let strongSelf = self {
if case .replayAsynchronouslyBuiltFinalState = strongSelf.operations.removeFirst() {
if let replayedState = replayedState {
let events = AccountFinalStateEvents(state: replayedState)
if !events.isEmpty {
strongSelf.insertProcessEvents(events)
}
}
strongSelf.startFirstOperation()
} else {
assertionFailure()
}
completion()
}
}, error: { _ in
assertionFailure()
Logger.shared.log("AccountStateManager", "processUpdateGroups signal completed with error")
completion()
})
} }
} }

View File

@@ -132,6 +132,15 @@ private final class CachedChannelParticipantsContext {
} }
} }
private final class ChannelPollingContext {
var subscribers = Bag<Void>()
let disposable = MetaDisposable()
deinit {
self.disposable.dispose()
}
}
public final class AccountViewTracker { public final class AccountViewTracker {
weak var account: Account? weak var account: Account?
private let queue = Queue() private let queue = Queue()
@@ -148,6 +157,8 @@ public final class AccountViewTracker {
private var cachedDataContexts: [PeerId: PeerCachedDataContext] = [:] private var cachedDataContexts: [PeerId: PeerCachedDataContext] = [:]
private var cachedChannelParticipantsContexts: [PeerId: CachedChannelParticipantsContext] = [:] private var cachedChannelParticipantsContexts: [PeerId: CachedChannelParticipantsContext] = [:]
private var channelPollingContexts: [PeerId: ChannelPollingContext] = [:]
init(account: Account) { init(account: Account) {
self.account = account self.account = account
} }
@@ -216,7 +227,7 @@ public final class AccountViewTracker {
} }
} }
public func updatedViewCountMessageIds(messageIds: Set<MessageId>) { public func updateViewCountForMessageIds(messageIds: Set<MessageId>) {
self.queue.async { self.queue.async {
var addedMessageIds: [MessageId] = [] var addedMessageIds: [MessageId] = []
let timestamp = Int32(CFAbsoluteTimeGetCurrent()) let timestamp = Int32(CFAbsoluteTimeGetCurrent())
@@ -253,11 +264,14 @@ public final class AccountViewTracker {
var attributes = currentMessage.attributes var attributes = currentMessage.attributes
loop: for j in 0 ..< attributes.count { loop: for j in 0 ..< attributes.count {
if let attribute = attributes[j] as? ViewCountMessageAttribute { if let attribute = attributes[j] as? ViewCountMessageAttribute {
if attribute.count >= Int(viewCounts[i]) {
return .skip
}
attributes[j] = ViewCountMessageAttribute(count: max(attribute.count, Int(viewCounts[i]))) attributes[j] = ViewCountMessageAttribute(count: max(attribute.count, Int(viewCounts[i])))
break loop break loop
} }
} }
return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media) return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media))
}) })
} }
} }
@@ -323,8 +337,44 @@ public final class AccountViewTracker {
} }
} }
func wrappedMessageHistorySignal(_ signal: Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError>) -> Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError> { private func polledChannel(peerId: PeerId) -> Signal<Void, NoError> {
return withState(signal, { [weak self] () -> Int32 in return Signal { subscriber in
let disposable = MetaDisposable()
self.queue.async {
let context: ChannelPollingContext
if let current = self.channelPollingContexts[peerId] {
context = current
} else {
context = ChannelPollingContext()
self.channelPollingContexts[peerId] = context
}
if context.subscribers.isEmpty {
if let account = self.account {
context.disposable.set(keepPollingChannel(account: account, peerId: peerId, stateManager: account.stateManager).start())
}
}
let index = context.subscribers.add(Void())
disposable.set(ActionDisposable {
self.queue.async {
if let context = self.channelPollingContexts[peerId] {
context.subscribers.remove(index)
if context.subscribers.isEmpty {
context.disposable.set(nil)
}
}
}
})
}
return disposable
}
}
func wrappedMessageHistorySignal(peerId: PeerId, signal: Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError>) -> Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError> {
let history = withState(signal, { [weak self] () -> Int32 in
if let strongSelf = self { if let strongSelf = self {
return OSAtomicIncrement32(&strongSelf.nextViewId) return OSAtomicIncrement32(&strongSelf.nextViewId)
} else { } else {
@@ -340,12 +390,31 @@ public final class AccountViewTracker {
strongSelf.updatePendingWebpages(viewId: viewId, messageIds: []) strongSelf.updatePendingWebpages(viewId: viewId, messageIds: [])
} }
}) })
if peerId.namespace == Namespaces.Peer.CloudChannel {
return Signal { subscriber in
let disposable = history.start(next: { next in
subscriber.putNext(next)
}, error: { error in
subscriber.putError(error)
}, completed: {
subscriber.putCompletion()
})
let polled = self.polledChannel(peerId: peerId).start()
return ActionDisposable {
disposable.dispose()
polled.dispose()
}
}
} else {
return history
}
} }
public func aroundUnreadMessageHistoryViewForPeerId(_ peerId: PeerId, count: Int, tagMask: MessageTags? = nil, additionalData: [AdditionalMessageHistoryViewData] = []) -> Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError> { public func aroundUnreadMessageHistoryViewForPeerId(_ peerId: PeerId, count: Int, tagMask: MessageTags? = nil, additionalData: [AdditionalMessageHistoryViewData] = []) -> Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError> {
if let account = self.account { if let account = self.account {
let signal = account.postbox.aroundUnreadMessageHistoryViewForPeerId(peerId, count: count, topTaggedMessageIdNamespaces: [Namespaces.Message.Cloud], tagMask: tagMask, additionalData: additionalData) let signal = account.postbox.aroundUnreadMessageHistoryViewForPeerId(peerId, count: count, topTaggedMessageIdNamespaces: [Namespaces.Message.Cloud], tagMask: tagMask, additionalData: additionalData)
return wrappedMessageHistorySignal(signal) return wrappedMessageHistorySignal(peerId: peerId, signal: signal)
} else { } else {
return .never() return .never()
} }
@@ -354,7 +423,7 @@ public final class AccountViewTracker {
public func aroundIdMessageHistoryViewForPeerId(_ peerId: PeerId, count: Int, messageId: MessageId, tagMask: MessageTags? = nil, additionalData: [AdditionalMessageHistoryViewData] = []) -> Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError> { public func aroundIdMessageHistoryViewForPeerId(_ peerId: PeerId, count: Int, messageId: MessageId, tagMask: MessageTags? = nil, additionalData: [AdditionalMessageHistoryViewData] = []) -> Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError> {
if let account = self.account { if let account = self.account {
let signal = account.postbox.aroundIdMessageHistoryViewForPeerId(peerId, count: count, messageId: messageId, topTaggedMessageIdNamespaces: [Namespaces.Message.Cloud], tagMask: tagMask, additionalData: additionalData) let signal = account.postbox.aroundIdMessageHistoryViewForPeerId(peerId, count: count, messageId: messageId, topTaggedMessageIdNamespaces: [Namespaces.Message.Cloud], tagMask: tagMask, additionalData: additionalData)
return wrappedMessageHistorySignal(signal) return wrappedMessageHistorySignal(peerId: peerId, signal: signal)
} else { } else {
return .never() return .never()
} }
@@ -363,7 +432,7 @@ public final class AccountViewTracker {
public func aroundMessageHistoryViewForPeerId(_ peerId: PeerId, index: MessageIndex, count: Int, anchorIndex: MessageIndex, fixedCombinedReadState: CombinedPeerReadState?, tagMask: MessageTags? = nil, additionalData: [AdditionalMessageHistoryViewData] = []) -> Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError> { public func aroundMessageHistoryViewForPeerId(_ peerId: PeerId, index: MessageIndex, count: Int, anchorIndex: MessageIndex, fixedCombinedReadState: CombinedPeerReadState?, tagMask: MessageTags? = nil, additionalData: [AdditionalMessageHistoryViewData] = []) -> Signal<(MessageHistoryView, ViewUpdateType, InitialMessageHistoryData?), NoError> {
if let account = self.account { if let account = self.account {
let signal = account.postbox.aroundMessageHistoryViewForPeerId(peerId, index: index, count: count, anchorIndex: anchorIndex, fixedCombinedReadState: fixedCombinedReadState, topTaggedMessageIdNamespaces: [Namespaces.Message.Cloud], tagMask: tagMask, additionalData: additionalData) let signal = account.postbox.aroundMessageHistoryViewForPeerId(peerId, index: index, count: count, anchorIndex: anchorIndex, fixedCombinedReadState: fixedCombinedReadState, topTaggedMessageIdNamespaces: [Namespaces.Message.Cloud], tagMask: tagMask, additionalData: additionalData)
return wrappedMessageHistorySignal(signal) return wrappedMessageHistorySignal(peerId: peerId, signal: signal)
} else { } else {
return .never() return .never()
} }

View File

@@ -29,7 +29,7 @@ public func applyMaxReadIndexInteractively(postbox: Postbox, network: Network, i
return currentAttribute return currentAttribute
} }
}) })
return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media) return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media))
}) })
modifier.addTimestampBasedMessageAttribute(tag: 0, timestamp: timestamp + attribute.timeout, messageId: id) modifier.addTimestampBasedMessageAttribute(tag: 0, timestamp: timestamp + attribute.timeout, messageId: id)
} }
@@ -62,7 +62,7 @@ func applyOutgoingReadMaxIndex(modifier: Modifier, index: MessageIndex, beginAt
return currentAttribute return currentAttribute
} }
}) })
return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media) return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media))
}) })
modifier.addTimestampBasedMessageAttribute(tag: 0, timestamp: timestamp + attribute.timeout, messageId: id) modifier.addTimestampBasedMessageAttribute(tag: 0, timestamp: timestamp + attribute.timeout, messageId: id)
} }

View File

@@ -115,7 +115,7 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes
} }
} }
return StoreMessage(id: updatedId, globallyUniqueId: nil, timestamp: updatedTimestamp ?? currentMessage.timestamp, flags: [], tags: tagsForStoreMessage(media: media, textEntities: entitiesAttribute?.entities), forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: text, attributes: attributes, media: media) return .update(StoreMessage(id: updatedId, globallyUniqueId: nil, timestamp: updatedTimestamp ?? currentMessage.timestamp, flags: [], tags: tagsForStoreMessage(media: media, textEntities: entitiesAttribute?.entities), forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: text, attributes: attributes, media: media))
}) })
if let updatedTimestamp = updatedTimestamp { if let updatedTimestamp = updatedTimestamp {
modifier.offsetPendingMessagesTimestamps(lowerBound: message.id, timestamp: updatedTimestamp) modifier.offsetPendingMessagesTimestamps(lowerBound: message.id, timestamp: updatedTimestamp)

View File

@@ -669,7 +669,7 @@ private func sendMessage(postbox: Postbox, network: Network, messageId: MessageI
if let forwardInfo = currentMessage.forwardInfo { if let forwardInfo = currentMessage.forwardInfo {
storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date)
} }
return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: timestamp, flags: flags, tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media) return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: timestamp, flags: flags, tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media))
}) })
} }
} }
@@ -711,7 +711,7 @@ private func sendServiceActionMessage(postbox: Postbox, network: Network, peerId
if let forwardInfo = currentMessage.forwardInfo { if let forwardInfo = currentMessage.forwardInfo {
storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date)
} }
return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: timestamp, flags: flags, tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media) return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: timestamp, flags: flags, tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media))
}) })
} }
} }

View File

@@ -66,7 +66,7 @@ public func markMessageContentAsConsumedInteractively(postbox: Postbox, network:
if let forwardInfo = currentMessage.forwardInfo { if let forwardInfo = currentMessage.forwardInfo {
storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date)
} }
return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media) return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media))
}) })
} }
} }
@@ -108,7 +108,7 @@ func markMessageContentAsConsumedRemotely(modifier: Modifier, messageId: Message
if let forwardInfo = currentMessage.forwardInfo { if let forwardInfo = currentMessage.forwardInfo {
storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date)
} }
return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media) return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media))
}) })
} }
} }

View File

@@ -270,7 +270,7 @@ public final class PendingMessageManager {
if let forwardInfo = currentMessage.forwardInfo { if let forwardInfo = currentMessage.forwardInfo {
storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date)
} }
return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: flags, tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media) return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: flags, tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media))
}) })
} }
break break
@@ -291,7 +291,7 @@ public final class PendingMessageManager {
if let forwardInfo = currentMessage.forwardInfo { if let forwardInfo = currentMessage.forwardInfo {
storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date)
} }
return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: flags, tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media) return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: flags, tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media))
}) })
} }
} else { } else {
@@ -300,7 +300,7 @@ public final class PendingMessageManager {
if let forwardInfo = currentMessage.forwardInfo { if let forwardInfo = currentMessage.forwardInfo {
storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date)
} }
return StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media) return .update(StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media))
}) })
} }
return .complete() return .complete()
@@ -383,7 +383,7 @@ public final class PendingMessageManager {
if let forwardInfo = currentMessage.forwardInfo { if let forwardInfo = currentMessage.forwardInfo {
storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date)
} }
return StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media) return .update(StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media))
}) })
} }
@@ -396,7 +396,7 @@ public final class PendingMessageManager {
if let forwardInfo = currentMessage.forwardInfo { if let forwardInfo = currentMessage.forwardInfo {
storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date)
} }
return StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media) return .update(StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media))
}) })
} }
} }

View File

@@ -195,7 +195,7 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, transf
} else { } else {
updatedAttributes.append(OutgoingMessageInfoAttribute(uniqueId: arc4random64(), flags: [.transformedMedia])) updatedAttributes.append(OutgoingMessageInfoAttribute(uniqueId: arc4random64(), flags: [.transformedMedia]))
} }
return StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media) return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media))
}) })
} }
return .done(media) return .done(media)