mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-08 08:31:13 +00:00
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
This commit is contained in:
commit
c0248b4ac5
@ -312,19 +312,16 @@ func chatContextMenuItems(context: AccountContext, peerId: PeerId, promoInfo: Ch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if case let .channel(channel) = peer, channel.flags.contains(.isForum) {
|
if isUnread {
|
||||||
|
items.append(.action(ContextMenuActionItem(text: strings.ChatList_Context_MarkAsRead, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/MarkAsRead"), color: theme.contextMenu.primaryColor) }, action: { _, f in
|
||||||
|
let _ = context.engine.messages.togglePeersUnreadMarkInteractively(peerIds: [peerId], setToValue: nil).start()
|
||||||
|
f(.default)
|
||||||
|
})))
|
||||||
} else {
|
} else {
|
||||||
if isUnread {
|
items.append(.action(ContextMenuActionItem(text: strings.ChatList_Context_MarkAsUnread, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/MarkAsUnread"), color: theme.contextMenu.primaryColor) }, action: { _, f in
|
||||||
items.append(.action(ContextMenuActionItem(text: strings.ChatList_Context_MarkAsRead, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/MarkAsRead"), color: theme.contextMenu.primaryColor) }, action: { _, f in
|
let _ = context.engine.messages.togglePeersUnreadMarkInteractively(peerIds: [peerId], setToValue: nil).start()
|
||||||
let _ = context.engine.messages.togglePeersUnreadMarkInteractively(peerIds: [peerId], setToValue: nil).start()
|
f(.default)
|
||||||
f(.default)
|
})))
|
||||||
})))
|
|
||||||
} else {
|
|
||||||
items.append(.action(ContextMenuActionItem(text: strings.ChatList_Context_MarkAsUnread, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/MarkAsUnread"), color: theme.contextMenu.primaryColor) }, action: { _, f in
|
|
||||||
let _ = context.engine.messages.togglePeersUnreadMarkInteractively(peerIds: [peerId], setToValue: nil).start()
|
|
||||||
f(.default)
|
|
||||||
})))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let archiveEnabled = !isSavedMessages && peerId != PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(777000)) && peerId == context.account.peerId
|
let archiveEnabled = !isSavedMessages && peerId != PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(777000)) && peerId == context.account.peerId
|
||||||
|
@ -67,7 +67,7 @@ final class MutableUnreadMessageCountsView: MutablePostboxView {
|
|||||||
if handleThreads, let peer = postbox.peerTable.get(peerId), postbox.seedConfiguration.peerSummaryIsThreadBased(peer) {
|
if handleThreads, let peer = postbox.peerTable.get(peerId), postbox.seedConfiguration.peerSummaryIsThreadBased(peer) {
|
||||||
var count: Int32 = 0
|
var count: Int32 = 0
|
||||||
if let summary = postbox.peerThreadsSummaryTable.get(peerId: peerId) {
|
if let summary = postbox.peerThreadsSummaryTable.get(peerId: peerId) {
|
||||||
count = summary.effectiveUnreadCount
|
count = summary.totalUnreadCount
|
||||||
}
|
}
|
||||||
return .peer(peerId, handleThreads, CombinedPeerReadState(states: [(0, .idBased(maxIncomingReadId: 1, maxOutgoingReadId: 1, maxKnownId: 1, count: count, markedUnread: false))]))
|
return .peer(peerId, handleThreads, CombinedPeerReadState(states: [(0, .idBased(maxIncomingReadId: 1, maxOutgoingReadId: 1, maxKnownId: 1, count: count, markedUnread: false))]))
|
||||||
} else {
|
} else {
|
||||||
@ -117,7 +117,7 @@ final class MutableUnreadMessageCountsView: MutablePostboxView {
|
|||||||
if transaction.updatedPeerThreadsSummaries.contains(peerId) {
|
if transaction.updatedPeerThreadsSummaries.contains(peerId) {
|
||||||
var count: Int32 = 0
|
var count: Int32 = 0
|
||||||
if let summary = postbox.peerThreadsSummaryTable.get(peerId: peerId) {
|
if let summary = postbox.peerThreadsSummaryTable.get(peerId: peerId) {
|
||||||
count = summary.effectiveUnreadCount
|
count = summary.totalUnreadCount
|
||||||
}
|
}
|
||||||
self.entries[i] = .peer(peerId, handleThreads, CombinedPeerReadState(states: [(0, .idBased(maxIncomingReadId: 1, maxOutgoingReadId: 1, maxKnownId: 1, count: count, markedUnread: false))]))
|
self.entries[i] = .peer(peerId, handleThreads, CombinedPeerReadState(states: [(0, .idBased(maxIncomingReadId: 1, maxOutgoingReadId: 1, maxKnownId: 1, count: count, markedUnread: false))]))
|
||||||
updated = true
|
updated = true
|
||||||
@ -146,7 +146,7 @@ final class MutableUnreadMessageCountsView: MutablePostboxView {
|
|||||||
if handleThreads, let peer = postbox.peerTable.get(peerId), postbox.seedConfiguration.peerSummaryIsThreadBased(peer) {
|
if handleThreads, let peer = postbox.peerTable.get(peerId), postbox.seedConfiguration.peerSummaryIsThreadBased(peer) {
|
||||||
var count: Int32 = 0
|
var count: Int32 = 0
|
||||||
if let summary = postbox.peerThreadsSummaryTable.get(peerId: peerId) {
|
if let summary = postbox.peerThreadsSummaryTable.get(peerId: peerId) {
|
||||||
count = summary.effectiveUnreadCount
|
count = summary.totalUnreadCount
|
||||||
}
|
}
|
||||||
return .peer(peerId, handleThreads, CombinedPeerReadState(states: [(0, .idBased(maxIncomingReadId: 1, maxOutgoingReadId: 1, maxKnownId: 1, count: count, markedUnread: false))]))
|
return .peer(peerId, handleThreads, CombinedPeerReadState(states: [(0, .idBased(maxIncomingReadId: 1, maxOutgoingReadId: 1, maxKnownId: 1, count: count, markedUnread: false))]))
|
||||||
} else {
|
} else {
|
||||||
@ -212,21 +212,32 @@ public final class UnreadMessageCountsView: PostboxView {
|
|||||||
|
|
||||||
final class MutableCombinedReadStateView: MutablePostboxView {
|
final class MutableCombinedReadStateView: MutablePostboxView {
|
||||||
private let peerId: PeerId
|
private let peerId: PeerId
|
||||||
|
private let handleThreads: Bool
|
||||||
fileprivate var state: CombinedPeerReadState?
|
fileprivate var state: CombinedPeerReadState?
|
||||||
|
|
||||||
init(postbox: PostboxImpl, peerId: PeerId) {
|
init(postbox: PostboxImpl, peerId: PeerId, handleThreads: Bool) {
|
||||||
self.peerId = peerId
|
self.peerId = peerId
|
||||||
self.state = postbox.readStateTable.getCombinedState(peerId)
|
self.handleThreads = handleThreads
|
||||||
|
|
||||||
|
let _ = self.refreshDueToExternalTransaction(postbox: postbox)
|
||||||
}
|
}
|
||||||
|
|
||||||
func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool {
|
func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool {
|
||||||
var updated = false
|
var updated = false
|
||||||
|
|
||||||
if transaction.alteredInitialPeerCombinedReadStates[self.peerId] != nil {
|
if transaction.alteredInitialPeerCombinedReadStates[self.peerId] != nil || transaction.updatedPeerThreadCombinedStates.contains(self.peerId) {
|
||||||
let state = postbox.readStateTable.getCombinedState(peerId)
|
if self.handleThreads, let peer = postbox.peerTable.get(self.peerId), postbox.seedConfiguration.peerSummaryIsThreadBased(peer) {
|
||||||
if state != self.state {
|
var count: Int32 = 0
|
||||||
self.state = state
|
if let summary = postbox.peerThreadsSummaryTable.get(peerId: peerId) {
|
||||||
updated = true
|
count = summary.totalUnreadCount
|
||||||
|
}
|
||||||
|
self.state = CombinedPeerReadState(states: [(0, .idBased(maxIncomingReadId: 1, maxOutgoingReadId: 1, maxKnownId: 1, count: count, markedUnread: false))])
|
||||||
|
} else {
|
||||||
|
let state = postbox.readStateTable.getCombinedState(peerId)
|
||||||
|
if state != self.state {
|
||||||
|
self.state = state
|
||||||
|
updated = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +245,17 @@ final class MutableCombinedReadStateView: MutablePostboxView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func refreshDueToExternalTransaction(postbox: PostboxImpl) -> Bool {
|
func refreshDueToExternalTransaction(postbox: PostboxImpl) -> Bool {
|
||||||
let state = postbox.readStateTable.getCombinedState(self.peerId)
|
let state: CombinedPeerReadState?
|
||||||
|
if handleThreads, let peer = postbox.peerTable.get(peerId), postbox.seedConfiguration.peerSummaryIsThreadBased(peer) {
|
||||||
|
var count: Int32 = 0
|
||||||
|
if let summary = postbox.peerThreadsSummaryTable.get(peerId: peerId) {
|
||||||
|
count = summary.totalUnreadCount
|
||||||
|
}
|
||||||
|
state = CombinedPeerReadState(states: [(0, .idBased(maxIncomingReadId: 1, maxOutgoingReadId: 1, maxKnownId: 1, count: count, markedUnread: false))])
|
||||||
|
} else {
|
||||||
|
state = postbox.readStateTable.getCombinedState(peerId)
|
||||||
|
}
|
||||||
|
|
||||||
if state != self.state {
|
if state != self.state {
|
||||||
self.state = state
|
self.state = state
|
||||||
return true
|
return true
|
||||||
|
@ -15,7 +15,7 @@ public enum PostboxViewKey: Hashable {
|
|||||||
case historyTagSummaryView(tag: MessageTags, peerId: PeerId, threadId: Int64?, namespace: MessageId.Namespace)
|
case historyTagSummaryView(tag: MessageTags, peerId: PeerId, threadId: Int64?, namespace: MessageId.Namespace)
|
||||||
case cachedPeerData(peerId: PeerId)
|
case cachedPeerData(peerId: PeerId)
|
||||||
case unreadCounts(items: [UnreadMessageCountsItem])
|
case unreadCounts(items: [UnreadMessageCountsItem])
|
||||||
case combinedReadState(peerId: PeerId)
|
case combinedReadState(peerId: PeerId, handleThreads: Bool)
|
||||||
case peerNotificationSettings(peerIds: Set<PeerId>)
|
case peerNotificationSettings(peerIds: Set<PeerId>)
|
||||||
case pendingPeerNotificationSettings
|
case pendingPeerNotificationSettings
|
||||||
case messageOfInterestHole(location: MessageOfInterestViewLocation, namespace: MessageId.Namespace, count: Int)
|
case messageOfInterestHole(location: MessageOfInterestViewLocation, namespace: MessageId.Namespace, count: Int)
|
||||||
@ -221,8 +221,8 @@ public enum PostboxViewKey: Hashable {
|
|||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
case let .combinedReadState(peerId):
|
case let .combinedReadState(peerId, handleThreads):
|
||||||
if case .combinedReadState(peerId) = rhs {
|
if case .combinedReadState(peerId, handleThreads) = rhs {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
@ -405,8 +405,8 @@ func postboxViewForKey(postbox: PostboxImpl, key: PostboxViewKey) -> MutablePost
|
|||||||
return MutableCachedPeerDataView(postbox: postbox, peerId: peerId)
|
return MutableCachedPeerDataView(postbox: postbox, peerId: peerId)
|
||||||
case let .unreadCounts(items):
|
case let .unreadCounts(items):
|
||||||
return MutableUnreadMessageCountsView(postbox: postbox, items: items)
|
return MutableUnreadMessageCountsView(postbox: postbox, items: items)
|
||||||
case let .combinedReadState(peerId):
|
case let .combinedReadState(peerId, handleThreads):
|
||||||
return MutableCombinedReadStateView(postbox: postbox, peerId: peerId)
|
return MutableCombinedReadStateView(postbox: postbox, peerId: peerId, handleThreads: handleThreads)
|
||||||
case let .peerNotificationSettings(peerIds):
|
case let .peerNotificationSettings(peerIds):
|
||||||
return MutablePeerNotificationSettingsView(postbox: postbox, peerIds: peerIds)
|
return MutablePeerNotificationSettingsView(postbox: postbox, peerIds: peerIds)
|
||||||
case .pendingPeerNotificationSettings:
|
case .pendingPeerNotificationSettings:
|
||||||
|
@ -169,7 +169,7 @@ public extension TelegramEngine.EngineData.Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var key: PostboxViewKey {
|
var key: PostboxViewKey {
|
||||||
return .combinedReadState(peerId: self.id)
|
return .combinedReadState(peerId: self.id, handleThreads: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(id: EnginePeer.Id) {
|
public init(id: EnginePeer.Id) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user