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
|
var options = transition.options
|
||||||
options.insert(.Synchronous)
|
//options.insert(.Synchronous)
|
||||||
if self.view.window != nil {
|
if self.view.window != nil {
|
||||||
if !options.contains(.AnimateInsertion) {
|
if !options.contains(.AnimateInsertion) {
|
||||||
options.insert(.PreferSynchronousDrawing)
|
options.insert(.PreferSynchronousDrawing)
|
||||||
|
@ -450,6 +450,8 @@ public final class PeerStoryListContext {
|
|||||||
|
|
||||||
private var updatesDisposable: Disposable?
|
private var updatesDisposable: Disposable?
|
||||||
|
|
||||||
|
private var completionCallbacksByToken: [Int: [() -> Void]] = [:]
|
||||||
|
|
||||||
init(queue: Queue, account: Account, peerId: EnginePeer.Id, isArchived: Bool) {
|
init(queue: Queue, account: Account, peerId: EnginePeer.Id, isArchived: Bool) {
|
||||||
self.queue = queue
|
self.queue = queue
|
||||||
self.account = account
|
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.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()
|
self.requestDisposable?.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadMore() {
|
func loadMore(completion: (() -> Void)?) {
|
||||||
if self.isLoadingMore {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
guard let loadMoreToken = self.stateValue.loadMoreToken else {
|
guard let loadMoreToken = self.stateValue.loadMoreToken else {
|
||||||
return
|
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
|
self.isLoadingMore = true
|
||||||
|
|
||||||
|
let limit = 100
|
||||||
|
|
||||||
let peerId = self.peerId
|
let peerId = self.peerId
|
||||||
let account = self.account
|
let account = self.account
|
||||||
let accountPeerId = account.peerId
|
let accountPeerId = account.peerId
|
||||||
@ -551,9 +563,9 @@ public final class PeerStoryListContext {
|
|||||||
|
|
||||||
let signal: Signal<Api.stories.Stories, MTRpcError>
|
let signal: Signal<Api.stories.Stories, MTRpcError>
|
||||||
if isArchived {
|
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 {
|
} 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
|
return signal
|
||||||
|> map { result -> Api.stories.Stories? in
|
|> map { result -> Api.stories.Stories? in
|
||||||
@ -575,7 +587,7 @@ public final class PeerStoryListContext {
|
|||||||
switch result {
|
switch result {
|
||||||
case let .stories(count, stories, users):
|
case let .stories(count, stories, users):
|
||||||
totalCount = Int(count)
|
totalCount = Int(count)
|
||||||
hasMore = stories.count >= 100
|
hasMore = stories.count >= limit
|
||||||
|
|
||||||
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: AccumulatedPeers(users: users))
|
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: AccumulatedPeers(users: users))
|
||||||
|
|
||||||
@ -664,6 +676,12 @@ public final class PeerStoryListContext {
|
|||||||
}
|
}
|
||||||
self.stateValue = updatedState
|
self.stateValue = updatedState
|
||||||
|
|
||||||
|
if let callbacks = self.completionCallbacksByToken.removeValue(forKey: loadMoreToken) {
|
||||||
|
for f in callbacks {
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if self.updatesDisposable == nil {
|
if self.updatesDisposable == nil {
|
||||||
self.updatesDisposable = (self.account.stateManager.storyUpdates
|
self.updatesDisposable = (self.account.stateManager.storyUpdates
|
||||||
|> deliverOn(self.queue)).start(next: { [weak self] updates in
|
|> 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
|
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)
|
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)
|
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> {
|
public func loadHole(anchor: SparseItemGrid.HoleAnchor, at location: SparseItemGrid.HoleLocation) -> Signal<Never, NoError> {
|
||||||
let listSource = self.listSource
|
let listSource = self.listSource
|
||||||
return Signal { _ in
|
return Signal { subscriber in
|
||||||
listSource.loadMore()
|
listSource.loadMore(completion: {
|
||||||
|
Queue.mainQueue().async {
|
||||||
|
subscriber.putCompletion()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
return EmptyDisposable
|
return EmptyDisposable
|
||||||
}
|
}
|
||||||
@ -1584,8 +1589,8 @@ public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScr
|
|||||||
localMonthTimestamp: Month(localTimestamp: item.timestamp + timezoneOffset).packedValue
|
localMonthTimestamp: Month(localTimestamp: item.timestamp + timezoneOffset).packedValue
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
if mappedItems.count < state.totalCount, let lastItem = state.items.last {
|
if mappedItems.count < state.totalCount, let lastItem = state.items.last, let loadMoreToken = state.loadMoreToken {
|
||||||
mappedHoles.append(VisualMediaHoleAnchor(index: mappedItems.count, storyId: 1, localMonthTimestamp: Month(localTimestamp: lastItem.timestamp + timezoneOffset).packedValue))
|
mappedHoles.append(VisualMediaHoleAnchor(index: mappedItems.count, storyId: Int32(loadMoreToken), localMonthTimestamp: Month(localTimestamp: lastItem.timestamp + timezoneOffset).packedValue))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
totalCount = state.totalCount
|
totalCount = state.totalCount
|
||||||
|
@ -125,11 +125,17 @@ public final class ArchiveInfoContentComponent: Component {
|
|||||||
contentHeight += iconSize
|
contentHeight += iconSize
|
||||||
contentHeight += 15.0
|
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
|
//TODO:localize
|
||||||
let titleSize = self.title.update(
|
let titleSize = self.title.update(
|
||||||
transition: .immediate,
|
transition: .immediate,
|
||||||
component: AnyComponent(MultilineTextComponent(
|
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
|
maximumNumberOfLines: 1
|
||||||
)),
|
)),
|
||||||
environment: {},
|
environment: {},
|
||||||
|
@ -163,7 +163,7 @@ final class StoryItemContentComponent: Component {
|
|||||||
videoNode.isHidden = true
|
videoNode.isHidden = true
|
||||||
|
|
||||||
self.videoNode = videoNode
|
self.videoNode = videoNode
|
||||||
self.addSubnode(videoNode)
|
//self.addSubview(videoNode.view)
|
||||||
|
|
||||||
videoNode.playbackCompleted = { [weak self] in
|
videoNode.playbackCompleted = { [weak self] in
|
||||||
guard let self else {
|
guard let self else {
|
||||||
|
@ -609,8 +609,8 @@ final class ChatMessageAvatarHeaderNode: ListViewItemHeaderNode {
|
|||||||
if self.storyStats != storyStats || self.presentationData.theme.theme !== theme || force {
|
if self.storyStats != storyStats || self.presentationData.theme.theme !== theme || force {
|
||||||
self.avatarNode.setStoryStats(storyStats: storyStats.flatMap { storyStats in
|
self.avatarNode.setStoryStats(storyStats: storyStats.flatMap { storyStats in
|
||||||
return AvatarNode.StoryStats(
|
return AvatarNode.StoryStats(
|
||||||
totalCount: storyStats.totalCount,
|
totalCount: storyStats.totalCount != 0 ? 1 : 0,
|
||||||
unseenCount: storyStats.unseenCount,
|
unseenCount: storyStats.unseenCount != 0 ? 1 : 0,
|
||||||
hasUnseenCloseFriendsItems: storyStats.hasUnseenCloseFriends
|
hasUnseenCloseFriendsItems: storyStats.hasUnseenCloseFriends
|
||||||
)
|
)
|
||||||
}, presentationParams: AvatarNode.StoryPresentationParams(
|
}, presentationParams: AvatarNode.StoryPresentationParams(
|
||||||
|
@ -406,12 +406,15 @@ public final class ChatMessageItem: ListViewItem, CustomStringConvertible {
|
|||||||
|
|
||||||
if hasAvatar {
|
if hasAvatar {
|
||||||
if let effectiveAuthor = effectiveAuthor {
|
if let effectiveAuthor = effectiveAuthor {
|
||||||
let storyStats: PeerStoryStats?
|
var storyStats: PeerStoryStats?
|
||||||
switch content {
|
if case .peer(id: context.account.peerId) = chatLocation {
|
||||||
case let .message(_, _, _, attributes, _):
|
} else {
|
||||||
storyStats = attributes.authorStoryStats
|
switch content {
|
||||||
case let .group(messages):
|
case let .message(_, _, _, attributes, _):
|
||||||
storyStats = messages.first?.3.authorStoryStats
|
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)
|
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