mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Stories
This commit is contained in:
@@ -11,8 +11,9 @@ public struct PeerViewComponents: OptionSet {
|
||||
public static let subPeers = PeerViewComponents(rawValue: 1 << 1)
|
||||
public static let messages = PeerViewComponents(rawValue: 1 << 2)
|
||||
public static let groupId = PeerViewComponents(rawValue: 1 << 3)
|
||||
public static let storyStats = PeerViewComponents(rawValue: 1 << 4)
|
||||
|
||||
public static let all: PeerViewComponents = [.cachedData, .subPeers, .messages, .groupId]
|
||||
public static let all: PeerViewComponents = [.cachedData, .subPeers, .messages, .groupId, .storyStats]
|
||||
}
|
||||
|
||||
final class MutablePeerView: MutablePostboxView {
|
||||
@@ -27,6 +28,8 @@ final class MutablePeerView: MutablePostboxView {
|
||||
var media: [MediaId: Media] = [:]
|
||||
var peerIsContact: Bool
|
||||
var groupId: PeerGroupId?
|
||||
var storyStats: PeerStoryStats?
|
||||
var memberStoryStats: [PeerId: PeerStoryStats] = [:]
|
||||
|
||||
init(postbox: PostboxImpl, peerId: PeerId, components: PeerViewComponents) {
|
||||
self.components = components
|
||||
@@ -54,8 +57,10 @@ final class MutablePeerView: MutablePostboxView {
|
||||
}
|
||||
self.cachedData = postbox.cachedPeerDataTable.get(contactPeerId)
|
||||
self.peerIsContact = postbox.contactsTable.isContact(peerId: self.contactPeerId)
|
||||
var cachedDataPeerIds = Set<PeerId>()
|
||||
if let cachedData = self.cachedData {
|
||||
peerIds.formUnion(cachedData.peerIds)
|
||||
cachedDataPeerIds = cachedData.peerIds
|
||||
peerIds.formUnion(cachedDataPeerIds)
|
||||
messageIds.formUnion(cachedData.messageIds)
|
||||
}
|
||||
for id in peerIds {
|
||||
@@ -66,6 +71,11 @@ final class MutablePeerView: MutablePostboxView {
|
||||
self.peerPresences[id] = presence
|
||||
}
|
||||
}
|
||||
for id in cachedDataPeerIds {
|
||||
if let value = fetchPeerStoryStats(postbox: postbox, peerId: id) {
|
||||
self.memberStoryStats[id] = value
|
||||
}
|
||||
}
|
||||
if let peer = self.peers[peerId], let associatedPeerId = peer.associatedPeerId {
|
||||
if let peer = getPeer(associatedPeerId) {
|
||||
self.peers[associatedPeerId] = peer
|
||||
@@ -83,6 +93,10 @@ final class MutablePeerView: MutablePostboxView {
|
||||
}
|
||||
}
|
||||
self.media = renderAssociatedMediaForPeers(postbox: postbox, peers: self.peers)
|
||||
|
||||
if components.contains(.storyStats) {
|
||||
self.storyStats = fetchPeerStoryStats(postbox: postbox, peerId: self.peerId)
|
||||
}
|
||||
}
|
||||
|
||||
func reset(postbox: PostboxImpl) -> Bool {
|
||||
@@ -260,6 +274,53 @@ final class MutablePeerView: MutablePostboxView {
|
||||
}
|
||||
}
|
||||
|
||||
if self.components.contains(.storyStats) {
|
||||
var refreshStoryStats = false
|
||||
for event in transaction.currentStoryTopItemEvents {
|
||||
if case .replace(peerId: self.peerId) = event {
|
||||
refreshStoryStats = true
|
||||
}
|
||||
}
|
||||
if !refreshStoryStats {
|
||||
for event in transaction.storyPeerStatesEvents {
|
||||
if case .set(.peer(self.peerId)) = event {
|
||||
refreshStoryStats = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if refreshStoryStats {
|
||||
self.storyStats = fetchPeerStoryStats(postbox: postbox, peerId: self.peerId)
|
||||
}
|
||||
}
|
||||
|
||||
if !transaction.storyPeerStatesEvents.isEmpty || !transaction.currentStoryTopItemEvents.isEmpty {
|
||||
if let cachedData = self.cachedData {
|
||||
var updatedPeerIds = Set<PeerId>()
|
||||
let cachedDataPeerIds = cachedData.peerIds
|
||||
for event in transaction.currentStoryTopItemEvents {
|
||||
if case let .replace(id) = event, cachedDataPeerIds.contains(id) {
|
||||
updatedPeerIds.insert(id)
|
||||
}
|
||||
}
|
||||
for event in transaction.storyPeerStatesEvents {
|
||||
if case let .set(key) = event, case let .peer(id) = key, cachedDataPeerIds.contains(id) {
|
||||
updatedPeerIds.insert(id)
|
||||
}
|
||||
}
|
||||
for id in updatedPeerIds {
|
||||
let value = fetchPeerStoryStats(postbox: postbox, peerId: id)
|
||||
if self.memberStoryStats[id] != value {
|
||||
updated = true
|
||||
if let value = value {
|
||||
self.memberStoryStats[id] = value
|
||||
} else {
|
||||
self.memberStoryStats.removeValue(forKey: id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return updated
|
||||
}
|
||||
|
||||
@@ -282,6 +343,8 @@ public final class PeerView: PostboxView {
|
||||
public let media: [MediaId: Media]
|
||||
public let peerIsContact: Bool
|
||||
public let groupId: PeerGroupId?
|
||||
public let storyStats: PeerStoryStats?
|
||||
public let memberStoryStats: [PeerId: PeerStoryStats]
|
||||
|
||||
init(_ mutableView: MutablePeerView) {
|
||||
self.peerId = mutableView.peerId
|
||||
@@ -293,5 +356,7 @@ public final class PeerView: PostboxView {
|
||||
self.media = mutableView.media
|
||||
self.peerIsContact = mutableView.peerIsContact
|
||||
self.groupId = mutableView.groupId
|
||||
self.storyStats = mutableView.storyStats
|
||||
self.memberStoryStats = mutableView.memberStoryStats
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user