mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 11:23:48 +00:00
Stories
This commit is contained in:
parent
e9e5b4c749
commit
7e93b86a8b
@ -212,6 +212,7 @@ struct AccountMutableState {
|
|||||||
var insertedPeers: [PeerId: Peer] = [:]
|
var insertedPeers: [PeerId: Peer] = [:]
|
||||||
|
|
||||||
var preCachedResources: [(MediaResource, Data)] = []
|
var preCachedResources: [(MediaResource, Data)] = []
|
||||||
|
var preCachedStories: [StoryId: Api.StoryItem] = [:]
|
||||||
|
|
||||||
var updatedMaxMessageId: Int32?
|
var updatedMaxMessageId: Int32?
|
||||||
var updatedQts: Int32?
|
var updatedQts: Int32?
|
||||||
@ -281,6 +282,11 @@ struct AccountMutableState {
|
|||||||
self.apiChats[chat.peerId] = chat
|
self.apiChats[chat.peerId] = chat
|
||||||
}
|
}
|
||||||
self.preCachedResources.append(contentsOf: other.preCachedResources)
|
self.preCachedResources.append(contentsOf: other.preCachedResources)
|
||||||
|
|
||||||
|
for (id, story) in other.preCachedStories {
|
||||||
|
self.preCachedStories[id] = story
|
||||||
|
}
|
||||||
|
|
||||||
self.externallyUpdatedPeerId.formUnion(other.externallyUpdatedPeerId)
|
self.externallyUpdatedPeerId.formUnion(other.externallyUpdatedPeerId)
|
||||||
for (peerId, namespaces) in other.namespacesWithHolesFromPreviousState {
|
for (peerId, namespaces) in other.namespacesWithHolesFromPreviousState {
|
||||||
if self.namespacesWithHolesFromPreviousState[peerId] == nil {
|
if self.namespacesWithHolesFromPreviousState[peerId] == nil {
|
||||||
@ -305,6 +311,10 @@ struct AccountMutableState {
|
|||||||
self.preCachedResources.append((resource, data))
|
self.preCachedResources.append((resource, data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutating func addPreCachedStory(id: StoryId, story: Api.StoryItem) {
|
||||||
|
self.preCachedStories[id] = story
|
||||||
|
}
|
||||||
|
|
||||||
mutating func addExternallyUpdatedPeerId(_ peerId: PeerId) {
|
mutating func addExternallyUpdatedPeerId(_ peerId: PeerId) {
|
||||||
self.externallyUpdatedPeerId.insert(peerId)
|
self.externallyUpdatedPeerId.insert(peerId)
|
||||||
}
|
}
|
||||||
|
@ -727,6 +727,11 @@ func finalStateWithDifference(accountPeerId: PeerId, postbox: Postbox, network:
|
|||||||
updatedState.addPreCachedResource(resource, data: data)
|
updatedState.addPreCachedResource(resource, data: data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let preCachedStories = message.preCachedStories {
|
||||||
|
for (id, story) in preCachedStories {
|
||||||
|
updatedState.addPreCachedStory(id: id, story: story)
|
||||||
|
}
|
||||||
|
}
|
||||||
var peerIsForum = false
|
var peerIsForum = false
|
||||||
if let peerId = message.peerId {
|
if let peerId = message.peerId {
|
||||||
peerIsForum = updatedState.isPeerForum(peerId: peerId)
|
peerIsForum = updatedState.isPeerForum(peerId: peerId)
|
||||||
@ -954,6 +959,11 @@ private func finalStateWithUpdatesAndServerTime(accountPeerId: PeerId, postbox:
|
|||||||
updatedState.addPreCachedResource(resource, data: data)
|
updatedState.addPreCachedResource(resource, data: data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let preCachedStories = apiMessage.preCachedStories {
|
||||||
|
for (id, story) in preCachedStories {
|
||||||
|
updatedState.addPreCachedStory(id: id, story: story)
|
||||||
|
}
|
||||||
|
}
|
||||||
var attributes = message.attributes
|
var attributes = message.attributes
|
||||||
attributes.append(ChannelMessageStateVersionAttribute(pts: pts))
|
attributes.append(ChannelMessageStateVersionAttribute(pts: pts))
|
||||||
updatedState.editMessage(messageId, message: message.withUpdatedAttributes(attributes))
|
updatedState.editMessage(messageId, message: message.withUpdatedAttributes(attributes))
|
||||||
@ -1020,6 +1030,11 @@ private func finalStateWithUpdatesAndServerTime(accountPeerId: PeerId, postbox:
|
|||||||
updatedState.addPreCachedResource(resource, data: data)
|
updatedState.addPreCachedResource(resource, data: data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let preCachedStories = apiMessage.preCachedStories {
|
||||||
|
for (id, story) in preCachedStories {
|
||||||
|
updatedState.addPreCachedStory(id: id, story: story)
|
||||||
|
}
|
||||||
|
}
|
||||||
updatedState.editMessage(messageId, message: message)
|
updatedState.editMessage(messageId, message: message)
|
||||||
for media in message.media {
|
for media in message.media {
|
||||||
if let media = media as? TelegramMediaAction {
|
if let media = media as? TelegramMediaAction {
|
||||||
@ -1050,6 +1065,11 @@ private func finalStateWithUpdatesAndServerTime(accountPeerId: PeerId, postbox:
|
|||||||
updatedState.addPreCachedResource(resource, data: data)
|
updatedState.addPreCachedResource(resource, data: data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let preCachedStories = apiMessage.preCachedStories {
|
||||||
|
for (id, story) in preCachedStories {
|
||||||
|
updatedState.addPreCachedStory(id: id, story: story)
|
||||||
|
}
|
||||||
|
}
|
||||||
var attributes = message.attributes
|
var attributes = message.attributes
|
||||||
attributes.append(ChannelMessageStateVersionAttribute(pts: pts))
|
attributes.append(ChannelMessageStateVersionAttribute(pts: pts))
|
||||||
updatedState.addMessages([message.withUpdatedAttributes(attributes)], location: .UpperHistoryBlock)
|
updatedState.addMessages([message.withUpdatedAttributes(attributes)], location: .UpperHistoryBlock)
|
||||||
@ -1082,6 +1102,11 @@ private func finalStateWithUpdatesAndServerTime(accountPeerId: PeerId, postbox:
|
|||||||
updatedState.addPreCachedResource(resource, data: data)
|
updatedState.addPreCachedResource(resource, data: data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let preCachedStories = apiMessage.preCachedStories {
|
||||||
|
for (id, story) in preCachedStories {
|
||||||
|
updatedState.addPreCachedStory(id: id, story: story)
|
||||||
|
}
|
||||||
|
}
|
||||||
updatedState.addMessages([message], location: .UpperHistoryBlock)
|
updatedState.addMessages([message], location: .UpperHistoryBlock)
|
||||||
}
|
}
|
||||||
case let .updateServiceNotification(flags, date, type, text, media, entities):
|
case let .updateServiceNotification(flags, date, type, text, media, entities):
|
||||||
@ -1715,7 +1740,7 @@ private func finalStateWithUpdatesAndServerTime(accountPeerId: PeerId, postbox:
|
|||||||
|> mapToSignal { finalState in
|
|> mapToSignal { finalState in
|
||||||
return resolveAssociatedMessages(postbox: postbox, network: network, state: finalState)
|
return resolveAssociatedMessages(postbox: postbox, network: network, state: finalState)
|
||||||
|> mapToSignal { resultingState -> Signal<AccountFinalState, NoError> in
|
|> mapToSignal { resultingState -> Signal<AccountFinalState, NoError> in
|
||||||
return resolveAssociatedStories(postbox: postbox, network: network, state: finalState)
|
return resolveAssociatedStories(postbox: postbox, network: network, accountPeerId: accountPeerId, state: finalState)
|
||||||
|> mapToSignal { resultingState -> Signal<AccountFinalState, NoError> in
|
|> mapToSignal { resultingState -> Signal<AccountFinalState, NoError> in
|
||||||
return resolveMissingPeerChatInfos(network: network, state: resultingState)
|
return resolveMissingPeerChatInfos(network: network, state: resultingState)
|
||||||
|> map { resultingState, resolveError -> AccountFinalState in
|
|> map { resultingState, resolveError -> AccountFinalState in
|
||||||
@ -2073,17 +2098,103 @@ func resolveForumThreads(postbox: Postbox, network: Network, fetchedChatList: Fe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveAssociatedStories(postbox: Postbox, network: Network, state: AccountMutableState) -> Signal<AccountMutableState, NoError> {
|
func resolveStories<T>(postbox: Postbox, source: FetchMessageHistoryHoleSource, accountPeerId: PeerId, storyIds: Set<StoryId>, result: T) -> Signal<T, NoError> {
|
||||||
|
var storyBuckets: [PeerId: [Int32]] = [:]
|
||||||
|
for id in storyIds {
|
||||||
|
if storyBuckets[id.peerId] == nil {
|
||||||
|
storyBuckets[id.peerId] = []
|
||||||
|
}
|
||||||
|
storyBuckets[id.peerId]?.append(id.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
var signals: [Signal<Never, NoError>] = []
|
||||||
|
for (peerId, allIds) in storyBuckets {
|
||||||
|
var idOffset = 0
|
||||||
|
while idOffset < allIds.count {
|
||||||
|
let bucketLength = min(100, allIds.count - idOffset)
|
||||||
|
let ids = Array(allIds[idOffset ..< (idOffset + bucketLength)])
|
||||||
|
signals.append(_internal_getStoriesById(accountPeerId: accountPeerId, postbox: postbox, source: source, peerId: peerId, ids: ids)
|
||||||
|
|> mapToSignal { result -> Signal<Never, NoError> in
|
||||||
|
return postbox.transaction { transaction -> Void in
|
||||||
|
for id in ids {
|
||||||
|
let current = transaction.getStory(id: StoryId(peerId: peerId, id: id))
|
||||||
|
var updated: CodableEntry?
|
||||||
|
if let updatedItem = result.first(where: { $0.id == id }) {
|
||||||
|
if let entry = CodableEntry(updatedItem) {
|
||||||
|
updated = entry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if current != updated {
|
||||||
|
transaction.setStory(id: StoryId(peerId: peerId, id: id), value: updated ?? CodableEntry(data: Data()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|> ignoreValues
|
||||||
|
})
|
||||||
|
idOffset += bucketLength
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return combineLatest(signals)
|
||||||
|
|> ignoreValues
|
||||||
|
|> map { _ -> T in
|
||||||
|
}
|
||||||
|
|> then(.single(result))
|
||||||
|
}
|
||||||
|
|
||||||
|
func resolveAssociatedStories(postbox: Postbox, network: Network, accountPeerId: PeerId, state: AccountMutableState) -> Signal<AccountMutableState, NoError> {
|
||||||
return postbox.transaction { transaction -> Signal<AccountMutableState, NoError> in
|
return postbox.transaction { transaction -> Signal<AccountMutableState, NoError> in
|
||||||
|
var missingStoryIds = Set<StoryId>()
|
||||||
|
|
||||||
|
for operation in state.operations {
|
||||||
|
switch operation {
|
||||||
|
case let .AddMessages(messages, _):
|
||||||
|
for message in messages {
|
||||||
|
for media in message.media {
|
||||||
|
for id in media.storyIds {
|
||||||
|
if let existing = transaction.getStory(id: id), case .item = existing.get(Stories.StoredItem.self) {
|
||||||
|
} else if state.preCachedStories[id] != nil {
|
||||||
|
} else {
|
||||||
|
missingStoryIds.insert(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !missingStoryIds.isEmpty {
|
||||||
|
return resolveStories(postbox: postbox, source: .network(network), accountPeerId: accountPeerId, storyIds: missingStoryIds, result: state)
|
||||||
|
} else {
|
||||||
return .single(state)
|
return .single(state)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|> switchToLatest
|
|> switchToLatest
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveAssociatedStories<T>(postbox: Postbox, source: FetchMessageHistoryHoleSource, messages: [StoreMessage], result: T) -> Signal<T, NoError> {
|
func resolveAssociatedStories<T>(postbox: Postbox, source: FetchMessageHistoryHoleSource, accountPeerId: PeerId, messages: [StoreMessage], result: T) -> Signal<T, NoError> {
|
||||||
return postbox.transaction { transaction -> Signal<T, NoError> in
|
return postbox.transaction { transaction -> Signal<T, NoError> in
|
||||||
|
var missingStoryIds = Set<StoryId>()
|
||||||
|
|
||||||
|
for message in messages {
|
||||||
|
for media in message.media {
|
||||||
|
for id in media.storyIds {
|
||||||
|
if let existing = transaction.getStory(id: id), case .item = existing.get(Stories.StoredItem.self) {
|
||||||
|
} else {
|
||||||
|
missingStoryIds.insert(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !missingStoryIds.isEmpty {
|
||||||
|
return resolveStories(postbox: postbox, source: source, accountPeerId: accountPeerId, storyIds: missingStoryIds, result: result)
|
||||||
|
} else {
|
||||||
return .single(result)
|
return .single(result)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|> switchToLatest
|
|> switchToLatest
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2420,7 +2531,7 @@ func pollChannelOnce(accountPeerId: PeerId, postbox: Postbox, network: Network,
|
|||||||
|> mapToSignal { (finalState, _, timeout) -> Signal<Int32, NoError> in
|
|> mapToSignal { (finalState, _, timeout) -> Signal<Int32, NoError> in
|
||||||
return resolveAssociatedMessages(postbox: postbox, network: network, state: finalState)
|
return resolveAssociatedMessages(postbox: postbox, network: network, state: finalState)
|
||||||
|> mapToSignal { resultingState -> Signal<AccountMutableState, NoError> in
|
|> mapToSignal { resultingState -> Signal<AccountMutableState, NoError> in
|
||||||
return resolveAssociatedStories(postbox: postbox, network: network, state: finalState)
|
return resolveAssociatedStories(postbox: postbox, network: network, accountPeerId: accountPeerId, state: finalState)
|
||||||
}
|
}
|
||||||
|> mapToSignal { resultingState -> Signal<AccountFinalState, NoError> in
|
|> mapToSignal { resultingState -> Signal<AccountFinalState, NoError> in
|
||||||
return resolveMissingPeerChatInfos(network: network, state: resultingState)
|
return resolveMissingPeerChatInfos(network: network, state: resultingState)
|
||||||
@ -2477,7 +2588,7 @@ public func standalonePollChannelOnce(accountPeerId: PeerId, postbox: Postbox, n
|
|||||||
|> mapToSignal { (finalState, _, timeout) -> Signal<Never, NoError> in
|
|> mapToSignal { (finalState, _, timeout) -> Signal<Never, NoError> in
|
||||||
return resolveAssociatedMessages(postbox: postbox, network: network, state: finalState)
|
return resolveAssociatedMessages(postbox: postbox, network: network, state: finalState)
|
||||||
|> mapToSignal { resultingState -> Signal<AccountMutableState, NoError> in
|
|> mapToSignal { resultingState -> Signal<AccountMutableState, NoError> in
|
||||||
return resolveAssociatedStories(postbox: postbox, network: network, state: finalState)
|
return resolveAssociatedStories(postbox: postbox, network: network, accountPeerId: accountPeerId, state: finalState)
|
||||||
}
|
}
|
||||||
|> mapToSignal { resultingState -> Signal<AccountFinalState, NoError> in
|
|> mapToSignal { resultingState -> Signal<AccountFinalState, NoError> in
|
||||||
return resolveMissingPeerChatInfos(network: network, state: resultingState)
|
return resolveMissingPeerChatInfos(network: network, state: resultingState)
|
||||||
@ -2687,7 +2798,7 @@ func resetChannels(accountPeerId: PeerId, postbox: Postbox, network: Network, pe
|
|||||||
// TODO: delete messages later than top
|
// TODO: delete messages later than top
|
||||||
return resolveAssociatedMessages(postbox: postbox, network: network, state: updatedState)
|
return resolveAssociatedMessages(postbox: postbox, network: network, state: updatedState)
|
||||||
|> mapToSignal { resultingState -> Signal<AccountMutableState, NoError> in
|
|> mapToSignal { resultingState -> Signal<AccountMutableState, NoError> in
|
||||||
return resolveAssociatedStories(postbox: postbox, network: network, state: updatedState)
|
return resolveAssociatedStories(postbox: postbox, network: network, accountPeerId: accountPeerId, state: updatedState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2758,6 +2869,11 @@ private func pollChannel(accountPeerId: PeerId, postbox: Postbox, network: Netwo
|
|||||||
updatedState.addPreCachedResource(resource, data: data)
|
updatedState.addPreCachedResource(resource, data: data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let preCachedStories = apiMessage.preCachedStories {
|
||||||
|
for (id, story) in preCachedStories {
|
||||||
|
updatedState.addPreCachedStory(id: id, story: story)
|
||||||
|
}
|
||||||
|
}
|
||||||
updatedState.addMessages([message], location: .UpperHistoryBlock)
|
updatedState.addMessages([message], location: .UpperHistoryBlock)
|
||||||
if case let .Id(id) = message.id {
|
if case let .Id(id) = message.id {
|
||||||
updatedState.updateChannelSynchronizedUntilMessage(id.peerId, id: id.id)
|
updatedState.updateChannelSynchronizedUntilMessage(id.peerId, id: id.id)
|
||||||
@ -2787,6 +2903,11 @@ private func pollChannel(accountPeerId: PeerId, postbox: Postbox, network: Netwo
|
|||||||
updatedState.addPreCachedResource(resource, data: data)
|
updatedState.addPreCachedResource(resource, data: data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let preCachedStories = apiMessage.preCachedStories {
|
||||||
|
for (id, story) in preCachedStories {
|
||||||
|
updatedState.addPreCachedStory(id: id, story: story)
|
||||||
|
}
|
||||||
|
}
|
||||||
var attributes = message.attributes
|
var attributes = message.attributes
|
||||||
attributes.append(ChannelMessageStateVersionAttribute(pts: pts))
|
attributes.append(ChannelMessageStateVersionAttribute(pts: pts))
|
||||||
updatedState.editMessage(messageId, message: message.withUpdatedAttributes(attributes))
|
updatedState.editMessage(messageId, message: message.withUpdatedAttributes(attributes))
|
||||||
@ -2837,7 +2958,7 @@ private func pollChannel(accountPeerId: PeerId, postbox: Postbox, network: Netwo
|
|||||||
|
|
||||||
return resolveForumThreads(postbox: postbox, network: network, state: updatedState)
|
return resolveForumThreads(postbox: postbox, network: network, state: updatedState)
|
||||||
|> mapToSignal { updatedState in
|
|> mapToSignal { updatedState in
|
||||||
return resolveAssociatedStories(postbox: postbox, network: network, state: updatedState)
|
return resolveAssociatedStories(postbox: postbox, network: network, accountPeerId: accountPeerId, state: updatedState)
|
||||||
|> map { updatedState -> (AccountMutableState, Bool, Int32?) in
|
|> map { updatedState -> (AccountMutableState, Bool, Int32?) in
|
||||||
return (updatedState, true, apiTimeout)
|
return (updatedState, true, apiTimeout)
|
||||||
}
|
}
|
||||||
@ -2904,6 +3025,11 @@ private func pollChannel(accountPeerId: PeerId, postbox: Postbox, network: Netwo
|
|||||||
updatedState.addPreCachedResource(resource, data: data)
|
updatedState.addPreCachedResource(resource, data: data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let preCachedStories = apiMessage.preCachedStories {
|
||||||
|
for (id, story) in preCachedStories {
|
||||||
|
updatedState.addPreCachedStory(id: id, story: story)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let location: AddMessagesLocation
|
let location: AddMessagesLocation
|
||||||
if case let .Id(id) = message.id, id.id == topMessage {
|
if case let .Id(id) = message.id, id.id == topMessage {
|
||||||
@ -3167,6 +3293,14 @@ func replayFinalState(
|
|||||||
var holesFromPreviousStateMessageIds: [MessageId] = []
|
var holesFromPreviousStateMessageIds: [MessageId] = []
|
||||||
var clearHolesFromPreviousStateForChannelMessagesWithPts: [PeerIdAndMessageNamespace: Int32] = [:]
|
var clearHolesFromPreviousStateForChannelMessagesWithPts: [PeerIdAndMessageNamespace: Int32] = [:]
|
||||||
|
|
||||||
|
for (id, story) in finalState.state.preCachedStories {
|
||||||
|
if let storyItem = Stories.StoredItem(apiStoryItem: story, peerId: id.peerId, transaction: transaction) {
|
||||||
|
if let entry = CodableEntry(storyItem) {
|
||||||
|
transaction.setStory(id: id, value: entry)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (peerId, namespaces) in finalState.state.namespacesWithHolesFromPreviousState {
|
for (peerId, namespaces) in finalState.state.namespacesWithHolesFromPreviousState {
|
||||||
for (namespace, namespaceState) in namespaces {
|
for (namespace, namespaceState) in namespaces {
|
||||||
if let pts = namespaceState.validateChannelPts {
|
if let pts = namespaceState.validateChannelPts {
|
||||||
|
@ -100,7 +100,7 @@ func resolveUnknownEmojiFiles<T>(postbox: Postbox, source: FetchMessageHistoryHo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func withResolvedAssociatedMessages<T>(postbox: Postbox, source: FetchMessageHistoryHoleSource, peers: [PeerId: Peer], storeMessages: [StoreMessage], _ f: @escaping (Transaction, [Peer], [StoreMessage]) -> T) -> Signal<T, NoError> {
|
func withResolvedAssociatedMessages<T>(postbox: Postbox, source: FetchMessageHistoryHoleSource, accountPeerId: PeerId, peers: [PeerId: Peer], storeMessages: [StoreMessage], _ f: @escaping (Transaction, [Peer], [StoreMessage]) -> T) -> Signal<T, NoError> {
|
||||||
return postbox.transaction { transaction -> Signal<T, NoError> in
|
return postbox.transaction { transaction -> Signal<T, NoError> in
|
||||||
var storedIds = Set<MessageId>()
|
var storedIds = Set<MessageId>()
|
||||||
var referencedReplyIds = ReferencedReplyMessageIds()
|
var referencedReplyIds = ReferencedReplyMessageIds()
|
||||||
@ -129,7 +129,7 @@ func withResolvedAssociatedMessages<T>(postbox: Postbox, source: FetchMessageHis
|
|||||||
if referencedReplyIds.isEmpty && referencedGeneralIds.isEmpty {
|
if referencedReplyIds.isEmpty && referencedGeneralIds.isEmpty {
|
||||||
return resolveUnknownEmojiFiles(postbox: postbox, source: source, messages: storeMessages, reactions: [], result: Void())
|
return resolveUnknownEmojiFiles(postbox: postbox, source: source, messages: storeMessages, reactions: [], result: Void())
|
||||||
|> mapToSignal { _ -> Signal<T, NoError> in
|
|> mapToSignal { _ -> Signal<T, NoError> in
|
||||||
return resolveAssociatedStories(postbox: postbox, source: source, messages: storeMessages, result: Void())
|
return resolveAssociatedStories(postbox: postbox, source: source, accountPeerId: accountPeerId, messages: storeMessages, result: Void())
|
||||||
|> mapToSignal { _ -> Signal<T, NoError> in
|
|> mapToSignal { _ -> Signal<T, NoError> in
|
||||||
return postbox.transaction { transaction -> T in
|
return postbox.transaction { transaction -> T in
|
||||||
return f(transaction, [], [])
|
return f(transaction, [], [])
|
||||||
@ -227,7 +227,7 @@ func withResolvedAssociatedMessages<T>(postbox: Postbox, source: FetchMessageHis
|
|||||||
|
|
||||||
return resolveUnknownEmojiFiles(postbox: postbox, source: source, messages: storeMessages + additionalMessages, reactions: [], result: Void())
|
return resolveUnknownEmojiFiles(postbox: postbox, source: source, messages: storeMessages + additionalMessages, reactions: [], result: Void())
|
||||||
|> mapToSignal { _ -> Signal<T, NoError> in
|
|> mapToSignal { _ -> Signal<T, NoError> in
|
||||||
return resolveAssociatedStories(postbox: postbox, source: source, messages: storeMessages + additionalMessages, result: Void())
|
return resolveAssociatedStories(postbox: postbox, source: source, accountPeerId: accountPeerId, messages: storeMessages + additionalMessages, result: Void())
|
||||||
|> mapToSignal { _ -> Signal<T, NoError> in
|
|> mapToSignal { _ -> Signal<T, NoError> in
|
||||||
return postbox.transaction { transaction -> T in
|
return postbox.transaction { transaction -> T in
|
||||||
return f(transaction, additionalPeers, additionalMessages)
|
return f(transaction, additionalPeers, additionalMessages)
|
||||||
@ -669,7 +669,7 @@ func fetchMessageHistoryHole(accountPeerId: PeerId, source: FetchMessageHistoryH
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return withResolvedAssociatedMessages(postbox: postbox, source: source, peers: Dictionary(peers.map({ ($0.id, $0) }), uniquingKeysWith: { lhs, _ in lhs }), storeMessages: storeMessages, { transaction, additionalPeers, additionalMessages -> FetchMessageHistoryHoleResult? in
|
return withResolvedAssociatedMessages(postbox: postbox, source: source, accountPeerId: accountPeerId, peers: Dictionary(peers.map({ ($0.id, $0) }), uniquingKeysWith: { lhs, _ in lhs }), storeMessages: storeMessages, { transaction, additionalPeers, additionalMessages -> FetchMessageHistoryHoleResult? in
|
||||||
let _ = transaction.addMessages(storeMessages, location: .Random)
|
let _ = transaction.addMessages(storeMessages, location: .Random)
|
||||||
let _ = transaction.addMessages(additionalMessages, location: .Random)
|
let _ = transaction.addMessages(additionalMessages, location: .Random)
|
||||||
var filledRange: ClosedRange<MessageId.Id>
|
var filledRange: ClosedRange<MessageId.Id>
|
||||||
@ -805,7 +805,7 @@ func fetchChatListHole(postbox: Postbox, network: Network, accountPeerId: PeerId
|
|||||||
}
|
}
|
||||||
|> ignoreValues
|
|> ignoreValues
|
||||||
}
|
}
|
||||||
return withResolvedAssociatedMessages(postbox: postbox, source: .network(network), peers: Dictionary(fetchedChats.peers.map({ ($0.id, $0) }), uniquingKeysWith: { lhs, _ in lhs }), storeMessages: fetchedChats.storeMessages, { transaction, additionalPeers, additionalMessages -> Void in
|
return withResolvedAssociatedMessages(postbox: postbox, source: .network(network), accountPeerId: accountPeerId, peers: Dictionary(fetchedChats.peers.map({ ($0.id, $0) }), uniquingKeysWith: { lhs, _ in lhs }), storeMessages: fetchedChats.storeMessages, { transaction, additionalPeers, additionalMessages -> Void in
|
||||||
updatePeers(transaction: transaction, peers: fetchedChats.peers + additionalPeers, update: { _, updated -> Peer in
|
updatePeers(transaction: transaction, peers: fetchedChats.peers + additionalPeers, update: { _, updated -> Peer in
|
||||||
return updated
|
return updated
|
||||||
})
|
})
|
||||||
|
@ -14,7 +14,7 @@ func _internal_resetAccountState(postbox: Postbox, network: Network, accountPeer
|
|||||||
guard let fetchedChats = fetchedChats else {
|
guard let fetchedChats = fetchedChats else {
|
||||||
return .never()
|
return .never()
|
||||||
}
|
}
|
||||||
return withResolvedAssociatedMessages(postbox: postbox, source: .network(network), peers: Dictionary(fetchedChats.peers.map({ ($0.id, $0) }), uniquingKeysWith: { lhs, _ in lhs }), storeMessages: fetchedChats.storeMessages, { transaction, additionalPeers, additionalMessages -> Void in
|
return withResolvedAssociatedMessages(postbox: postbox, source: .network(network), accountPeerId: accountPeerId, peers: Dictionary(fetchedChats.peers.map({ ($0.id, $0) }), uniquingKeysWith: { lhs, _ in lhs }), storeMessages: fetchedChats.storeMessages, { transaction, additionalPeers, additionalMessages -> Void in
|
||||||
for peerId in transaction.chatListGetAllPeerIds() {
|
for peerId in transaction.chatListGetAllPeerIds() {
|
||||||
if peerId.namespace != Namespaces.Peer.SecretChat {
|
if peerId.namespace != Namespaces.Peer.SecretChat {
|
||||||
transaction.updatePeerChatListInclusion(peerId, inclusion: .notIncluded)
|
transaction.updatePeerChatListInclusion(peerId, inclusion: .notIncluded)
|
||||||
|
@ -85,6 +85,19 @@ extension Api.MessageMedia {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var preCachedStories: [StoryId: Api.StoryItem]? {
|
||||||
|
switch self {
|
||||||
|
case let .messageMediaStory(_, userId, id, story):
|
||||||
|
if let story = story {
|
||||||
|
return [StoryId(peerId: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId)), id: id): story]
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Api.Message {
|
extension Api.Message {
|
||||||
@ -148,6 +161,15 @@ extension Api.Message {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var preCachedStories: [StoryId: Api.StoryItem]? {
|
||||||
|
switch self {
|
||||||
|
case let .message(_, _, _, _, _, _, _, _, _, media, _, _, _, _, _, _, _, _, _, _, _):
|
||||||
|
return media?.preCachedStories
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Api.Chat {
|
extension Api.Chat {
|
||||||
|
@ -1263,7 +1263,7 @@ func _internal_getStoriesById(accountPeerId: PeerId, postbox: Postbox, network:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func _internal_getStoriesById(accountPeerId: PeerId, postbox: Postbox, network: Network, peerId: PeerId, ids: [Int32]) -> Signal<[Stories.StoredItem], NoError> {
|
func _internal_getStoriesById(accountPeerId: PeerId, postbox: Postbox, source: FetchMessageHistoryHoleSource, peerId: PeerId, ids: [Int32]) -> Signal<[Stories.StoredItem], NoError> {
|
||||||
return postbox.transaction { transaction -> Api.InputUser? in
|
return postbox.transaction { transaction -> Api.InputUser? in
|
||||||
return transaction.getPeer(peerId).flatMap(apiInputUser)
|
return transaction.getPeer(peerId).flatMap(apiInputUser)
|
||||||
}
|
}
|
||||||
@ -1272,7 +1272,7 @@ func _internal_getStoriesById(accountPeerId: PeerId, postbox: Postbox, network:
|
|||||||
return .single([])
|
return .single([])
|
||||||
}
|
}
|
||||||
|
|
||||||
return network.request(Api.functions.stories.getStoriesByID(userId: inputUser, id: ids))
|
return source.request(Api.functions.stories.getStoriesByID(userId: inputUser, id: ids))
|
||||||
|> map(Optional.init)
|
|> map(Optional.init)
|
||||||
|> `catch` { _ -> Signal<Api.stories.Stories?, NoError> in
|
|> `catch` { _ -> Signal<Api.stories.Stories?, NoError> in
|
||||||
return .single(nil)
|
return .single(nil)
|
||||||
@ -1685,7 +1685,7 @@ func _internal_exportStoryLink(account: Account, peerId: EnginePeer.Id, id: Int3
|
|||||||
}
|
}
|
||||||
|
|
||||||
func _internal_refreshStories(account: Account, peerId: PeerId, ids: [Int32]) -> Signal<Never, NoError> {
|
func _internal_refreshStories(account: Account, peerId: PeerId, ids: [Int32]) -> Signal<Never, NoError> {
|
||||||
return _internal_getStoriesById(accountPeerId: account.peerId, postbox: account.postbox, network: account.network, peerId: peerId, ids: ids)
|
return _internal_getStoriesById(accountPeerId: account.peerId, postbox: account.postbox, source: .network(account.network), peerId: peerId, ids: ids)
|
||||||
|> mapToSignal { result -> Signal<Never, NoError> in
|
|> mapToSignal { result -> Signal<Never, NoError> in
|
||||||
return account.postbox.transaction { transaction -> Void in
|
return account.postbox.transaction { transaction -> Void in
|
||||||
var currentItems = transaction.getStoryItems(peerId: peerId)
|
var currentItems = transaction.getStoryItems(peerId: peerId)
|
||||||
|
@ -892,6 +892,8 @@ public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScr
|
|||||||
|
|
||||||
private weak var pendingOpenListContext: PeerStoryListContentContextImpl?
|
private weak var pendingOpenListContext: PeerStoryListContentContextImpl?
|
||||||
|
|
||||||
|
private var preloadArchiveListContext: PeerStoryListContext?
|
||||||
|
|
||||||
public init(context: AccountContext, peerId: PeerId, chatLocation: ChatLocation, contentType: ContentType, captureProtected: Bool, isSaved: Bool, isArchive: Bool, navigationController: @escaping () -> NavigationController?, listContext: PeerStoryListContext?) {
|
public init(context: AccountContext, peerId: PeerId, chatLocation: ChatLocation, contentType: ContentType, captureProtected: Bool, isSaved: Bool, isArchive: Bool, navigationController: @escaping () -> NavigationController?, listContext: PeerStoryListContext?) {
|
||||||
self.context = context
|
self.context = context
|
||||||
self.peerId = peerId
|
self.peerId = peerId
|
||||||
@ -1448,6 +1450,10 @@ public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScr
|
|||||||
})
|
})
|
||||||
|
|
||||||
self.requestHistoryAroundVisiblePosition(synchronous: false, reloadAtTop: false)
|
self.requestHistoryAroundVisiblePosition(synchronous: false, reloadAtTop: false)
|
||||||
|
|
||||||
|
if peerId == context.account.peerId {
|
||||||
|
self.preloadArchiveListContext = PeerStoryListContext(account: context.account, peerId: peerId, isArchived: true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user