Fix user map

This commit is contained in:
Ali 2023-06-20 14:09:24 +03:00
parent 7e93b86a8b
commit 53949c8b52
3 changed files with 19 additions and 10 deletions

View File

@ -2098,7 +2098,7 @@ func resolveForumThreads(postbox: Postbox, network: Network, fetchedChatList: Fe
} }
} }
func resolveStories<T>(postbox: Postbox, source: FetchMessageHistoryHoleSource, accountPeerId: PeerId, storyIds: Set<StoryId>, result: T) -> Signal<T, NoError> { func resolveStories<T>(postbox: Postbox, source: FetchMessageHistoryHoleSource, accountPeerId: PeerId, storyIds: Set<StoryId>, additionalPeers: [PeerId: Peer], result: T) -> Signal<T, NoError> {
var storyBuckets: [PeerId: [Int32]] = [:] var storyBuckets: [PeerId: [Int32]] = [:]
for id in storyIds { for id in storyIds {
if storyBuckets[id.peerId] == nil { if storyBuckets[id.peerId] == nil {
@ -2113,7 +2113,7 @@ func resolveStories<T>(postbox: Postbox, source: FetchMessageHistoryHoleSource,
while idOffset < allIds.count { while idOffset < allIds.count {
let bucketLength = min(100, allIds.count - idOffset) let bucketLength = min(100, allIds.count - idOffset)
let ids = Array(allIds[idOffset ..< (idOffset + bucketLength)]) let ids = Array(allIds[idOffset ..< (idOffset + bucketLength)])
signals.append(_internal_getStoriesById(accountPeerId: accountPeerId, postbox: postbox, source: source, peerId: peerId, ids: ids) signals.append(_internal_getStoriesById(accountPeerId: accountPeerId, postbox: postbox, source: source, peerId: peerId, peerReference: additionalPeers[peerId].flatMap(PeerReference.init), ids: ids)
|> mapToSignal { result -> Signal<Never, NoError> in |> mapToSignal { result -> Signal<Never, NoError> in
return postbox.transaction { transaction -> Void in return postbox.transaction { transaction -> Void in
for id in ids { for id in ids {
@ -2166,7 +2166,7 @@ func resolveAssociatedStories(postbox: Postbox, network: Network, accountPeerId:
} }
if !missingStoryIds.isEmpty { if !missingStoryIds.isEmpty {
return resolveStories(postbox: postbox, source: .network(network), accountPeerId: accountPeerId, storyIds: missingStoryIds, result: state) return resolveStories(postbox: postbox, source: .network(network), accountPeerId: accountPeerId, storyIds: missingStoryIds, additionalPeers: state.insertedPeers, result: state)
} else { } else {
return .single(state) return .single(state)
} }
@ -2174,7 +2174,7 @@ func resolveAssociatedStories(postbox: Postbox, network: Network, accountPeerId:
|> switchToLatest |> switchToLatest
} }
func resolveAssociatedStories<T>(postbox: Postbox, source: FetchMessageHistoryHoleSource, accountPeerId: PeerId, messages: [StoreMessage], result: T) -> Signal<T, NoError> { func resolveAssociatedStories<T>(postbox: Postbox, source: FetchMessageHistoryHoleSource, accountPeerId: PeerId, messages: [StoreMessage], additionalPeers: [PeerId: Peer], 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>() var missingStoryIds = Set<StoryId>()
@ -2190,7 +2190,7 @@ func resolveAssociatedStories<T>(postbox: Postbox, source: FetchMessageHistoryHo
} }
if !missingStoryIds.isEmpty { if !missingStoryIds.isEmpty {
return resolveStories(postbox: postbox, source: source, accountPeerId: accountPeerId, storyIds: missingStoryIds, result: result) return resolveStories(postbox: postbox, source: source, accountPeerId: accountPeerId, storyIds: missingStoryIds, additionalPeers: additionalPeers, result: result)
} else { } else {
return .single(result) return .single(result)
} }
@ -3298,6 +3298,8 @@ func replayFinalState(
if let entry = CodableEntry(storyItem) { if let entry = CodableEntry(storyItem) {
transaction.setStory(id: id, value: entry) transaction.setStory(id: id, value: entry)
} }
} else {
transaction.setStory(id: id, value: CodableEntry(data: Data()))
} }
} }

View File

@ -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, accountPeerId: accountPeerId, messages: storeMessages, result: Void()) return resolveAssociatedStories(postbox: postbox, source: source, accountPeerId: accountPeerId, messages: storeMessages, additionalPeers: peers, 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,14 @@ 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, accountPeerId: accountPeerId, messages: storeMessages + additionalMessages, result: Void()) var additionalPeerMap: [PeerId: Peer] = [:]
for (_, peer) in peers {
additionalPeerMap[peer.id] = peer
}
for peer in additionalPeers {
additionalPeerMap[peer.id] = peer
}
return resolveAssociatedStories(postbox: postbox, source: source, accountPeerId: accountPeerId, messages: storeMessages + additionalMessages, additionalPeers: additionalPeerMap, 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)

View File

@ -1263,12 +1263,12 @@ func _internal_getStoriesById(accountPeerId: PeerId, postbox: Postbox, network:
} }
} }
func _internal_getStoriesById(accountPeerId: PeerId, postbox: Postbox, source: FetchMessageHistoryHoleSource, peerId: PeerId, ids: [Int32]) -> Signal<[Stories.StoredItem], NoError> { func _internal_getStoriesById(accountPeerId: PeerId, postbox: Postbox, source: FetchMessageHistoryHoleSource, peerId: PeerId, peerReference: PeerReference?, 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)
} }
|> mapToSignal { inputUser -> Signal<[Stories.StoredItem], NoError> in |> mapToSignal { inputUser -> Signal<[Stories.StoredItem], NoError> in
guard let inputUser = inputUser else { guard let inputUser = inputUser ?? peerReference?.inputUser else {
return .single([]) return .single([])
} }
@ -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, source: .network(account.network), peerId: peerId, ids: ids) return _internal_getStoriesById(accountPeerId: account.peerId, postbox: account.postbox, source: .network(account.network), peerId: peerId, peerReference: nil, 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)