mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Stories
This commit is contained in:
parent
c30e6f9482
commit
fec8d0b58a
@ -3197,7 +3197,7 @@ public final class ChatListNode: ListView {
|
||||
}
|
||||
|
||||
var options = transition.options
|
||||
options.insert(.Synchronous)
|
||||
//options.insert(.Synchronous)
|
||||
if self.view.window != nil {
|
||||
if !options.contains(.AnimateInsertion) {
|
||||
options.insert(.PreferSynchronousDrawing)
|
||||
|
@ -450,6 +450,8 @@ public final class PeerStoryListContext {
|
||||
|
||||
private var updatesDisposable: Disposable?
|
||||
|
||||
private var completionCallbacksByToken: [Int: [() -> Void]] = [:]
|
||||
|
||||
init(queue: Queue, account: Account, peerId: EnginePeer.Id, isArchived: Bool) {
|
||||
self.queue = queue
|
||||
self.account = account
|
||||
@ -519,7 +521,7 @@ public final class PeerStoryListContext {
|
||||
}
|
||||
|
||||
self.stateValue = State(peerReference: peerReference, items: items, totalCount: totalCount, loadMoreToken: 0, isCached: true, allEntityFiles: allEntityFiles)
|
||||
self.loadMore()
|
||||
self.loadMore(completion: nil)
|
||||
})
|
||||
}
|
||||
|
||||
@ -527,16 +529,26 @@ public final class PeerStoryListContext {
|
||||
self.requestDisposable?.dispose()
|
||||
}
|
||||
|
||||
func loadMore() {
|
||||
if self.isLoadingMore {
|
||||
return
|
||||
}
|
||||
func loadMore(completion: (() -> Void)?) {
|
||||
guard let loadMoreToken = self.stateValue.loadMoreToken else {
|
||||
return
|
||||
}
|
||||
|
||||
if let completion = completion {
|
||||
if self.completionCallbacksByToken[loadMoreToken] == nil {
|
||||
self.completionCallbacksByToken[loadMoreToken] = []
|
||||
}
|
||||
self.completionCallbacksByToken[loadMoreToken]?.append(completion)
|
||||
}
|
||||
|
||||
if self.isLoadingMore {
|
||||
return
|
||||
}
|
||||
|
||||
self.isLoadingMore = true
|
||||
|
||||
let limit = 100
|
||||
|
||||
let peerId = self.peerId
|
||||
let account = self.account
|
||||
let accountPeerId = account.peerId
|
||||
@ -551,9 +563,9 @@ public final class PeerStoryListContext {
|
||||
|
||||
let signal: Signal<Api.stories.Stories, MTRpcError>
|
||||
if isArchived {
|
||||
signal = account.network.request(Api.functions.stories.getStoriesArchive(offsetId: Int32(loadMoreToken), limit: 100))
|
||||
signal = account.network.request(Api.functions.stories.getStoriesArchive(offsetId: Int32(loadMoreToken), limit: Int32(limit)))
|
||||
} else {
|
||||
signal = account.network.request(Api.functions.stories.getPinnedStories(userId: inputUser, offsetId: Int32(loadMoreToken), limit: 100))
|
||||
signal = account.network.request(Api.functions.stories.getPinnedStories(userId: inputUser, offsetId: Int32(loadMoreToken), limit: Int32(limit)))
|
||||
}
|
||||
return signal
|
||||
|> map { result -> Api.stories.Stories? in
|
||||
@ -575,7 +587,7 @@ public final class PeerStoryListContext {
|
||||
switch result {
|
||||
case let .stories(count, stories, users):
|
||||
totalCount = Int(count)
|
||||
hasMore = stories.count >= 100
|
||||
hasMore = stories.count >= limit
|
||||
|
||||
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: AccumulatedPeers(users: users))
|
||||
|
||||
@ -664,6 +676,12 @@ public final class PeerStoryListContext {
|
||||
}
|
||||
self.stateValue = updatedState
|
||||
|
||||
if let callbacks = self.completionCallbacksByToken.removeValue(forKey: loadMoreToken) {
|
||||
for f in callbacks {
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
if self.updatesDisposable == nil {
|
||||
self.updatesDisposable = (self.account.stateManager.storyUpdates
|
||||
|> deliverOn(self.queue)).start(next: { [weak self] updates in
|
||||
@ -863,9 +881,9 @@ public final class PeerStoryListContext {
|
||||
})
|
||||
}
|
||||
|
||||
public func loadMore() {
|
||||
public func loadMore(completion: (() -> Void)? = nil) {
|
||||
self.impl.with { impl in
|
||||
impl.loadMore()
|
||||
impl.loadMore(completion : completion)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1488,7 +1488,7 @@ public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScr
|
||||
|
||||
self.requestHistoryAroundVisiblePosition(synchronous: false, reloadAtTop: false)
|
||||
|
||||
if peerId == context.account.peerId {
|
||||
if peerId == context.account.peerId && !isArchive {
|
||||
self.preloadArchiveListContext = PeerStoryListContext(account: context.account, peerId: peerId, isArchived: true)
|
||||
}
|
||||
}
|
||||
@ -1502,8 +1502,13 @@ public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScr
|
||||
|
||||
public func loadHole(anchor: SparseItemGrid.HoleAnchor, at location: SparseItemGrid.HoleLocation) -> Signal<Never, NoError> {
|
||||
let listSource = self.listSource
|
||||
return Signal { _ in
|
||||
listSource.loadMore()
|
||||
return Signal { subscriber in
|
||||
listSource.loadMore(completion: {
|
||||
Queue.mainQueue().async {
|
||||
subscriber.putCompletion()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
return EmptyDisposable
|
||||
}
|
||||
@ -1584,8 +1589,8 @@ public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScr
|
||||
localMonthTimestamp: Month(localTimestamp: item.timestamp + timezoneOffset).packedValue
|
||||
))
|
||||
}
|
||||
if mappedItems.count < state.totalCount, let lastItem = state.items.last {
|
||||
mappedHoles.append(VisualMediaHoleAnchor(index: mappedItems.count, storyId: 1, localMonthTimestamp: Month(localTimestamp: lastItem.timestamp + timezoneOffset).packedValue))
|
||||
if mappedItems.count < state.totalCount, let lastItem = state.items.last, let loadMoreToken = state.loadMoreToken {
|
||||
mappedHoles.append(VisualMediaHoleAnchor(index: mappedItems.count, storyId: Int32(loadMoreToken), localMonthTimestamp: Month(localTimestamp: lastItem.timestamp + timezoneOffset).packedValue))
|
||||
}
|
||||
}
|
||||
totalCount = state.totalCount
|
||||
|
@ -125,11 +125,17 @@ public final class ArchiveInfoContentComponent: Component {
|
||||
contentHeight += iconSize
|
||||
contentHeight += 15.0
|
||||
|
||||
let titleString = NSMutableAttributedString()
|
||||
titleString.append(NSAttributedString(string: "This is Your Archive", font: Font.semibold(19.0), textColor: component.theme.list.itemPrimaryTextColor))
|
||||
let imageAttachment = NSTextAttachment()
|
||||
imageAttachment.image = self.iconBackground.image
|
||||
titleString.append(NSAttributedString(attachment: imageAttachment))
|
||||
|
||||
//TODO:localize
|
||||
let titleSize = self.title.update(
|
||||
transition: .immediate,
|
||||
component: AnyComponent(MultilineTextComponent(
|
||||
text: .plain(NSAttributedString(string: "This is Your Archive", font: Font.semibold(19.0), textColor: component.theme.list.itemPrimaryTextColor)),
|
||||
text: .plain(titleString),
|
||||
maximumNumberOfLines: 1
|
||||
)),
|
||||
environment: {},
|
||||
|
@ -163,7 +163,7 @@ final class StoryItemContentComponent: Component {
|
||||
videoNode.isHidden = true
|
||||
|
||||
self.videoNode = videoNode
|
||||
self.addSubnode(videoNode)
|
||||
//self.addSubview(videoNode.view)
|
||||
|
||||
videoNode.playbackCompleted = { [weak self] in
|
||||
guard let self else {
|
||||
|
@ -609,8 +609,8 @@ final class ChatMessageAvatarHeaderNode: ListViewItemHeaderNode {
|
||||
if self.storyStats != storyStats || self.presentationData.theme.theme !== theme || force {
|
||||
self.avatarNode.setStoryStats(storyStats: storyStats.flatMap { storyStats in
|
||||
return AvatarNode.StoryStats(
|
||||
totalCount: storyStats.totalCount,
|
||||
unseenCount: storyStats.unseenCount,
|
||||
totalCount: storyStats.totalCount != 0 ? 1 : 0,
|
||||
unseenCount: storyStats.unseenCount != 0 ? 1 : 0,
|
||||
hasUnseenCloseFriendsItems: storyStats.hasUnseenCloseFriends
|
||||
)
|
||||
}, presentationParams: AvatarNode.StoryPresentationParams(
|
||||
|
@ -406,12 +406,15 @@ public final class ChatMessageItem: ListViewItem, CustomStringConvertible {
|
||||
|
||||
if hasAvatar {
|
||||
if let effectiveAuthor = effectiveAuthor {
|
||||
let storyStats: PeerStoryStats?
|
||||
switch content {
|
||||
case let .message(_, _, _, attributes, _):
|
||||
storyStats = attributes.authorStoryStats
|
||||
case let .group(messages):
|
||||
storyStats = messages.first?.3.authorStoryStats
|
||||
var storyStats: PeerStoryStats?
|
||||
if case .peer(id: context.account.peerId) = chatLocation {
|
||||
} else {
|
||||
switch content {
|
||||
case let .message(_, _, _, attributes, _):
|
||||
storyStats = attributes.authorStoryStats
|
||||
case let .group(messages):
|
||||
storyStats = messages.first?.3.authorStoryStats
|
||||
}
|
||||
}
|
||||
|
||||
avatarHeader = ChatMessageAvatarHeader(timestamp: content.index.timestamp, peerId: effectiveAuthor.id, peer: effectiveAuthor, messageReference: MessageReference(message), message: message, presentationData: presentationData, context: context, controllerInteraction: controllerInteraction, storyStats: storyStats)
|
||||
|
Loading…
x
Reference in New Issue
Block a user