Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios

This commit is contained in:
Ilya Laktyushin
2023-07-11 18:35:31 +02:00
50 changed files with 1916 additions and 719 deletions

View File

@@ -607,7 +607,11 @@ private func prepareUploadStoryContent(account: Account, media: EngineStoryInput
if let firstFrameFile = firstFrameFile {
account.postbox.mediaBox.storeCachedResourceRepresentation(resource.id.stringRepresentation, representationId: "first-frame", keepDuration: .general, tempFile: firstFrameFile)
previewRepresentations.append(TelegramMediaImageRepresentation(dimensions: dimensions, resource: resource, progressiveSizes: [], immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
if let data = try? Data(contentsOf: URL(fileURLWithPath: firstFrameFile.path), options: .mappedIfSafe) {
let localResource = LocalFileMediaResource(fileId: Int64.random(in: Int64.min ... Int64.max), size: nil, isSecretRelated: false)
account.postbox.mediaBox.storeResourceData(localResource.id, data: data)
previewRepresentations.append(TelegramMediaImageRepresentation(dimensions: dimensions, resource: localResource, progressiveSizes: [], immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
}
}
let fileMedia = TelegramMediaFile(

View File

@@ -544,9 +544,9 @@ public final class PeerStoryListContext {
self.requestDisposable = (self.account.postbox.transaction { transaction -> Api.InputUser? in
return transaction.getPeer(peerId).flatMap(apiInputUser)
}
|> mapToSignal { inputUser -> Signal<([EngineStoryItem], Int, PeerReference?), NoError> in
|> mapToSignal { inputUser -> Signal<([EngineStoryItem], Int, PeerReference?, Bool), NoError> in
guard let inputUser = inputUser else {
return .single(([], 0, nil))
return .single(([], 0, nil, false))
}
let signal: Signal<Api.stories.Stories, MTRpcError>
@@ -562,18 +562,20 @@ public final class PeerStoryListContext {
|> `catch` { _ -> Signal<Api.stories.Stories?, NoError> in
return .single(nil)
}
|> mapToSignal { result -> Signal<([EngineStoryItem], Int, PeerReference?), NoError> in
|> mapToSignal { result -> Signal<([EngineStoryItem], Int, PeerReference?, Bool), NoError> in
guard let result = result else {
return .single(([], 0, nil))
return .single(([], 0, nil, false))
}
return account.postbox.transaction { transaction -> ([EngineStoryItem], Int, PeerReference?) in
return account.postbox.transaction { transaction -> ([EngineStoryItem], Int, PeerReference?, Bool) in
var storyItems: [EngineStoryItem] = []
var totalCount: Int = 0
var hasMore: Bool = false
switch result {
case let .stories(count, stories, users):
totalCount = Int(count)
hasMore = stories.count >= 100
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: AccumulatedPeers(users: users))
@@ -619,11 +621,11 @@ public final class PeerStoryListContext {
}
}
return (storyItems, totalCount, transaction.getPeer(peerId).flatMap(PeerReference.init))
return (storyItems, totalCount, transaction.getPeer(peerId).flatMap(PeerReference.init), hasMore)
}
}
}
|> deliverOn(self.queue)).start(next: { [weak self] storyItems, totalCount, peerReference in
|> deliverOn(self.queue)).start(next: { [weak self] storyItems, totalCount, peerReference, hasMore in
guard let `self` = self else {
return
}
@@ -650,7 +652,11 @@ public final class PeerStoryListContext {
updatedState.peerReference = peerReference
}
updatedState.loadMoreToken = (storyItems.last?.id).flatMap(Int.init)
if hasMore {
updatedState.loadMoreToken = (storyItems.last?.id).flatMap(Int.init)
} else {
updatedState.loadMoreToken = nil
}
if updatedState.loadMoreToken != nil {
updatedState.totalCount = max(totalCount, updatedState.items.count)
} else {