mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 14:45:21 +00:00
Reaction improvements
This commit is contained in:
@@ -894,6 +894,7 @@ public class Account {
|
|||||||
private let becomeMasterDisposable = MetaDisposable()
|
private let becomeMasterDisposable = MetaDisposable()
|
||||||
private let managedServiceViewsDisposable = MetaDisposable()
|
private let managedServiceViewsDisposable = MetaDisposable()
|
||||||
private let managedOperationsDisposable = DisposableSet()
|
private let managedOperationsDisposable = DisposableSet()
|
||||||
|
private let managedTopReactionsDisposable = MetaDisposable()
|
||||||
private var storageSettingsDisposable: Disposable?
|
private var storageSettingsDisposable: Disposable?
|
||||||
|
|
||||||
public let importableContacts = Promise<[DeviceContactNormalizedPhoneNumber: ImportableDeviceContactData]>()
|
public let importableContacts = Promise<[DeviceContactNormalizedPhoneNumber: ImportableDeviceContactData]>()
|
||||||
@@ -1179,7 +1180,8 @@ public class Account {
|
|||||||
self.managedOperationsDisposable.add(managedRecentStatusEmoji(postbox: self.postbox, network: self.network).start())
|
self.managedOperationsDisposable.add(managedRecentStatusEmoji(postbox: self.postbox, network: self.network).start())
|
||||||
self.managedOperationsDisposable.add(managedFeaturedStatusEmoji(postbox: self.postbox, network: self.network).start())
|
self.managedOperationsDisposable.add(managedFeaturedStatusEmoji(postbox: self.postbox, network: self.network).start())
|
||||||
self.managedOperationsDisposable.add(managedRecentReactions(postbox: self.postbox, network: self.network).start())
|
self.managedOperationsDisposable.add(managedRecentReactions(postbox: self.postbox, network: self.network).start())
|
||||||
self.managedOperationsDisposable.add(managedTopReactions(postbox: self.postbox, network: self.network).start())
|
self.managedTopReactionsDisposable.set(managedTopReactions(postbox: self.postbox, network: self.network).start())
|
||||||
|
self.managedOperationsDisposable.add(self.managedTopReactionsDisposable)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !supplementary {
|
if !supplementary {
|
||||||
@@ -1205,6 +1207,13 @@ public class Account {
|
|||||||
}
|
}
|
||||||
self.restartConfigurationUpdates()
|
self.restartConfigurationUpdates()
|
||||||
|
|
||||||
|
self.stateManager.isPremiumUpdated = { [weak self] in
|
||||||
|
guard let strongSelf = self else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
strongSelf.managedTopReactionsDisposable.set(managedTopReactions(postbox: strongSelf.postbox, network: strongSelf.network).start())
|
||||||
|
}
|
||||||
|
|
||||||
/*#if DEBUG
|
/*#if DEBUG
|
||||||
self.managedOperationsDisposable.add(debugFetchAllStickers(account: self).start(completed: {
|
self.managedOperationsDisposable.add(debugFetchAllStickers(account: self).start(completed: {
|
||||||
print("debugFetchAllStickers done")
|
print("debugFetchAllStickers done")
|
||||||
|
|||||||
@@ -656,6 +656,7 @@ struct AccountReplayedFinalState {
|
|||||||
let updatedIncomingThreadReadStates: [MessageId: MessageId.Id]
|
let updatedIncomingThreadReadStates: [MessageId: MessageId.Id]
|
||||||
let updatedOutgoingThreadReadStates: [MessageId: MessageId.Id]
|
let updatedOutgoingThreadReadStates: [MessageId: MessageId.Id]
|
||||||
let updateConfig: Bool
|
let updateConfig: Bool
|
||||||
|
let isPremiumUpdated: Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AccountFinalStateEvents {
|
struct AccountFinalStateEvents {
|
||||||
@@ -680,12 +681,13 @@ struct AccountFinalStateEvents {
|
|||||||
let updatedIncomingThreadReadStates: [MessageId: MessageId.Id]
|
let updatedIncomingThreadReadStates: [MessageId: MessageId.Id]
|
||||||
let updatedOutgoingThreadReadStates: [MessageId: MessageId.Id]
|
let updatedOutgoingThreadReadStates: [MessageId: MessageId.Id]
|
||||||
let updateConfig: Bool
|
let updateConfig: Bool
|
||||||
|
let isPremiumUpdated: Bool
|
||||||
|
|
||||||
var isEmpty: Bool {
|
var isEmpty: Bool {
|
||||||
return self.addedIncomingMessageIds.isEmpty && self.addedReactionEvents.isEmpty && self.wasScheduledMessageIds.isEmpty && self.deletedMessageIds.isEmpty && self.updatedTypingActivities.isEmpty && self.updatedWebpages.isEmpty && self.updatedCalls.isEmpty && self.addedCallSignalingData.isEmpty && self.updatedGroupCallParticipants.isEmpty && self.updatedPeersNearby?.isEmpty ?? true && self.isContactUpdates.isEmpty && self.displayAlerts.isEmpty && self.dismissBotWebViews.isEmpty && self.delayNotificatonsUntil == nil && self.updatedMaxMessageId == nil && self.updatedQts == nil && self.externallyUpdatedPeerId.isEmpty && !authorizationListUpdated && self.updatedIncomingThreadReadStates.isEmpty && self.updatedOutgoingThreadReadStates.isEmpty && !self.updateConfig
|
return self.addedIncomingMessageIds.isEmpty && self.addedReactionEvents.isEmpty && self.wasScheduledMessageIds.isEmpty && self.deletedMessageIds.isEmpty && self.updatedTypingActivities.isEmpty && self.updatedWebpages.isEmpty && self.updatedCalls.isEmpty && self.addedCallSignalingData.isEmpty && self.updatedGroupCallParticipants.isEmpty && self.updatedPeersNearby?.isEmpty ?? true && self.isContactUpdates.isEmpty && self.displayAlerts.isEmpty && self.dismissBotWebViews.isEmpty && self.delayNotificatonsUntil == nil && self.updatedMaxMessageId == nil && self.updatedQts == nil && self.externallyUpdatedPeerId.isEmpty && !authorizationListUpdated && self.updatedIncomingThreadReadStates.isEmpty && self.updatedOutgoingThreadReadStates.isEmpty && !self.updateConfig && !isPremiumUpdated
|
||||||
}
|
}
|
||||||
|
|
||||||
init(addedIncomingMessageIds: [MessageId] = [], addedReactionEvents: [(reactionAuthor: Peer, reaction: MessageReaction.Reaction, message: Message, timestamp: Int32)] = [], wasScheduledMessageIds: [MessageId] = [], deletedMessageIds: [DeletedMessageId] = [], updatedTypingActivities: [PeerActivitySpace: [PeerId: PeerInputActivity?]] = [:], updatedWebpages: [MediaId: TelegramMediaWebpage] = [:], updatedCalls: [Api.PhoneCall] = [], addedCallSignalingData: [(Int64, Data)] = [], updatedGroupCallParticipants: [(Int64, GroupCallParticipantsContext.Update)] = [], updatedPeersNearby: [PeerNearby]? = nil, isContactUpdates: [(PeerId, Bool)] = [], displayAlerts: [(text: String, isDropAuth: Bool)] = [], dismissBotWebViews: [Int64] = [], delayNotificatonsUntil: Int32? = nil, updatedMaxMessageId: Int32? = nil, updatedQts: Int32? = nil, externallyUpdatedPeerId: Set<PeerId> = Set(), authorizationListUpdated: Bool = false, updatedIncomingThreadReadStates: [MessageId: MessageId.Id] = [:], updatedOutgoingThreadReadStates: [MessageId: MessageId.Id] = [:], updateConfig: Bool = false) {
|
init(addedIncomingMessageIds: [MessageId] = [], addedReactionEvents: [(reactionAuthor: Peer, reaction: MessageReaction.Reaction, message: Message, timestamp: Int32)] = [], wasScheduledMessageIds: [MessageId] = [], deletedMessageIds: [DeletedMessageId] = [], updatedTypingActivities: [PeerActivitySpace: [PeerId: PeerInputActivity?]] = [:], updatedWebpages: [MediaId: TelegramMediaWebpage] = [:], updatedCalls: [Api.PhoneCall] = [], addedCallSignalingData: [(Int64, Data)] = [], updatedGroupCallParticipants: [(Int64, GroupCallParticipantsContext.Update)] = [], updatedPeersNearby: [PeerNearby]? = nil, isContactUpdates: [(PeerId, Bool)] = [], displayAlerts: [(text: String, isDropAuth: Bool)] = [], dismissBotWebViews: [Int64] = [], delayNotificatonsUntil: Int32? = nil, updatedMaxMessageId: Int32? = nil, updatedQts: Int32? = nil, externallyUpdatedPeerId: Set<PeerId> = Set(), authorizationListUpdated: Bool = false, updatedIncomingThreadReadStates: [MessageId: MessageId.Id] = [:], updatedOutgoingThreadReadStates: [MessageId: MessageId.Id] = [:], updateConfig: Bool = false, isPremiumUpdated: Bool = false) {
|
||||||
self.addedIncomingMessageIds = addedIncomingMessageIds
|
self.addedIncomingMessageIds = addedIncomingMessageIds
|
||||||
self.addedReactionEvents = addedReactionEvents
|
self.addedReactionEvents = addedReactionEvents
|
||||||
self.wasScheduledMessageIds = wasScheduledMessageIds
|
self.wasScheduledMessageIds = wasScheduledMessageIds
|
||||||
@@ -707,6 +709,7 @@ struct AccountFinalStateEvents {
|
|||||||
self.updatedIncomingThreadReadStates = updatedIncomingThreadReadStates
|
self.updatedIncomingThreadReadStates = updatedIncomingThreadReadStates
|
||||||
self.updatedOutgoingThreadReadStates = updatedOutgoingThreadReadStates
|
self.updatedOutgoingThreadReadStates = updatedOutgoingThreadReadStates
|
||||||
self.updateConfig = updateConfig
|
self.updateConfig = updateConfig
|
||||||
|
self.isPremiumUpdated = isPremiumUpdated
|
||||||
}
|
}
|
||||||
|
|
||||||
init(state: AccountReplayedFinalState) {
|
init(state: AccountReplayedFinalState) {
|
||||||
@@ -731,6 +734,7 @@ struct AccountFinalStateEvents {
|
|||||||
self.updatedIncomingThreadReadStates = state.updatedIncomingThreadReadStates
|
self.updatedIncomingThreadReadStates = state.updatedIncomingThreadReadStates
|
||||||
self.updatedOutgoingThreadReadStates = state.updatedOutgoingThreadReadStates
|
self.updatedOutgoingThreadReadStates = state.updatedOutgoingThreadReadStates
|
||||||
self.updateConfig = state.updateConfig
|
self.updateConfig = state.updateConfig
|
||||||
|
self.isPremiumUpdated = state.isPremiumUpdated
|
||||||
}
|
}
|
||||||
|
|
||||||
func union(with other: AccountFinalStateEvents) -> AccountFinalStateEvents {
|
func union(with other: AccountFinalStateEvents) -> AccountFinalStateEvents {
|
||||||
@@ -758,6 +762,8 @@ struct AccountFinalStateEvents {
|
|||||||
|
|
||||||
let updateConfig = self.updateConfig || other.updateConfig
|
let updateConfig = self.updateConfig || other.updateConfig
|
||||||
|
|
||||||
return AccountFinalStateEvents(addedIncomingMessageIds: self.addedIncomingMessageIds + other.addedIncomingMessageIds, addedReactionEvents: self.addedReactionEvents + other.addedReactionEvents, wasScheduledMessageIds: self.wasScheduledMessageIds + other.wasScheduledMessageIds, deletedMessageIds: self.deletedMessageIds + other.deletedMessageIds, updatedTypingActivities: self.updatedTypingActivities, updatedWebpages: self.updatedWebpages, updatedCalls: self.updatedCalls + other.updatedCalls, addedCallSignalingData: self.addedCallSignalingData + other.addedCallSignalingData, updatedGroupCallParticipants: self.updatedGroupCallParticipants + other.updatedGroupCallParticipants, isContactUpdates: self.isContactUpdates + other.isContactUpdates, displayAlerts: self.displayAlerts + other.displayAlerts, dismissBotWebViews: self.dismissBotWebViews + other.dismissBotWebViews, delayNotificatonsUntil: delayNotificatonsUntil, updatedMaxMessageId: updatedMaxMessageId, updatedQts: updatedQts, externallyUpdatedPeerId: externallyUpdatedPeerId, authorizationListUpdated: authorizationListUpdated, updatedIncomingThreadReadStates: self.updatedIncomingThreadReadStates.merging(other.updatedIncomingThreadReadStates, uniquingKeysWith: { lhs, _ in lhs }), updateConfig: updateConfig)
|
let isPremiumUpdated = self.isPremiumUpdated || other.isPremiumUpdated
|
||||||
|
|
||||||
|
return AccountFinalStateEvents(addedIncomingMessageIds: self.addedIncomingMessageIds + other.addedIncomingMessageIds, addedReactionEvents: self.addedReactionEvents + other.addedReactionEvents, wasScheduledMessageIds: self.wasScheduledMessageIds + other.wasScheduledMessageIds, deletedMessageIds: self.deletedMessageIds + other.deletedMessageIds, updatedTypingActivities: self.updatedTypingActivities, updatedWebpages: self.updatedWebpages, updatedCalls: self.updatedCalls + other.updatedCalls, addedCallSignalingData: self.addedCallSignalingData + other.addedCallSignalingData, updatedGroupCallParticipants: self.updatedGroupCallParticipants + other.updatedGroupCallParticipants, isContactUpdates: self.isContactUpdates + other.isContactUpdates, displayAlerts: self.displayAlerts + other.displayAlerts, dismissBotWebViews: self.dismissBotWebViews + other.dismissBotWebViews, delayNotificatonsUntil: delayNotificatonsUntil, updatedMaxMessageId: updatedMaxMessageId, updatedQts: updatedQts, externallyUpdatedPeerId: externallyUpdatedPeerId, authorizationListUpdated: authorizationListUpdated, updatedIncomingThreadReadStates: self.updatedIncomingThreadReadStates.merging(other.updatedIncomingThreadReadStates, uniquingKeysWith: { lhs, _ in lhs }), updateConfig: updateConfig, isPremiumUpdated: isPremiumUpdated)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2591,6 +2591,8 @@ func replayFinalState(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isPremiumUpdated = false
|
||||||
|
|
||||||
for operation in optimizedOperations(finalState.state.operations) {
|
for operation in optimizedOperations(finalState.state.operations) {
|
||||||
switch operation {
|
switch operation {
|
||||||
case let .AddMessages(messages, location):
|
case let .AddMessages(messages, location):
|
||||||
@@ -3067,12 +3069,25 @@ func replayFinalState(
|
|||||||
peers.append(telegramUser)
|
peers.append(telegramUser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let updatedAccountPeer = peers.first(where: { $0.id == accountPeerId }) as? TelegramUser, let previousAccountPeer = transaction.getPeer(accountPeerId) as? TelegramUser {
|
||||||
|
if updatedAccountPeer.isPremium != previousAccountPeer.isPremium {
|
||||||
|
isPremiumUpdated = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updatePeers(transaction: transaction, peers: peers, update: { _, updated in
|
updatePeers(transaction: transaction, peers: peers, update: { _, updated in
|
||||||
return updated
|
return updated
|
||||||
})
|
})
|
||||||
updateContacts(transaction: transaction, apiUsers: users)
|
updateContacts(transaction: transaction, apiUsers: users)
|
||||||
case let .UpdatePeer(id, f):
|
case let .UpdatePeer(id, f):
|
||||||
if let peer = f(transaction.getPeer(id)) {
|
if let peer = f(transaction.getPeer(id)) {
|
||||||
|
if id == accountPeerId, let updatedAccountPeer = peer as? TelegramUser, let previousAccountPeer = transaction.getPeer(accountPeerId) as? TelegramUser {
|
||||||
|
if updatedAccountPeer.isPremium != previousAccountPeer.isPremium {
|
||||||
|
isPremiumUpdated = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updatePeers(transaction: transaction, peers: [peer], update: { _, updated in
|
updatePeers(transaction: transaction, peers: [peer], update: { _, updated in
|
||||||
return updated
|
return updated
|
||||||
})
|
})
|
||||||
@@ -3865,5 +3880,5 @@ func replayFinalState(
|
|||||||
requestChatListFiltersSync(transaction: transaction)
|
requestChatListFiltersSync(transaction: transaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
return AccountReplayedFinalState(state: finalState, addedIncomingMessageIds: addedIncomingMessageIds, addedReactionEvents: addedReactionEvents, wasScheduledMessageIds: wasScheduledMessageIds, addedSecretMessageIds: addedSecretMessageIds, deletedMessageIds: deletedMessageIds, updatedTypingActivities: updatedTypingActivities, updatedWebpages: updatedWebpages, updatedCalls: updatedCalls, addedCallSignalingData: addedCallSignalingData, updatedGroupCallParticipants: updatedGroupCallParticipants, updatedPeersNearby: updatedPeersNearby, isContactUpdates: isContactUpdates, delayNotificatonsUntil: delayNotificatonsUntil, updatedIncomingThreadReadStates: updatedIncomingThreadReadStates, updatedOutgoingThreadReadStates: updatedOutgoingThreadReadStates, updateConfig: updateConfig)
|
return AccountReplayedFinalState(state: finalState, addedIncomingMessageIds: addedIncomingMessageIds, addedReactionEvents: addedReactionEvents, wasScheduledMessageIds: wasScheduledMessageIds, addedSecretMessageIds: addedSecretMessageIds, deletedMessageIds: deletedMessageIds, updatedTypingActivities: updatedTypingActivities, updatedWebpages: updatedWebpages, updatedCalls: updatedCalls, addedCallSignalingData: addedCallSignalingData, updatedGroupCallParticipants: updatedGroupCallParticipants, updatedPeersNearby: updatedPeersNearby, isContactUpdates: isContactUpdates, delayNotificatonsUntil: delayNotificatonsUntil, updatedIncomingThreadReadStates: updatedIncomingThreadReadStates, updatedOutgoingThreadReadStates: updatedOutgoingThreadReadStates, updateConfig: updateConfig, isPremiumUpdated: isPremiumUpdated)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ public final class AccountStateManager {
|
|||||||
private let appliedQtsDisposable = MetaDisposable()
|
private let appliedQtsDisposable = MetaDisposable()
|
||||||
|
|
||||||
var updateConfigRequested: (() -> Void)?
|
var updateConfigRequested: (() -> Void)?
|
||||||
|
var isPremiumUpdated: (() -> Void)?
|
||||||
|
|
||||||
init(
|
init(
|
||||||
accountPeerId: PeerId,
|
accountPeerId: PeerId,
|
||||||
@@ -785,6 +786,10 @@ public final class AccountStateManager {
|
|||||||
if events.updateConfig {
|
if events.updateConfig {
|
||||||
self.updateConfigRequested?()
|
self.updateConfigRequested?()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if events.isPremiumUpdated {
|
||||||
|
self.isPremiumUpdated?()
|
||||||
|
}
|
||||||
case let .pollCompletion(pollId, preMessageIds, preSubscribers):
|
case let .pollCompletion(pollId, preMessageIds, preSubscribers):
|
||||||
if self.operations.count > 1 {
|
if self.operations.count > 1 {
|
||||||
self.operations.removeFirst()
|
self.operations.removeFirst()
|
||||||
|
|||||||
@@ -58,10 +58,9 @@ public func updateMessageReactionsInteractively(account: Account, messageId: Mes
|
|||||||
}
|
}
|
||||||
|
|
||||||
if storeAsRecentlyUsed {
|
if storeAsRecentlyUsed {
|
||||||
for attribute in currentMessage.attributes {
|
let effectiveReactions = currentMessage.effectiveReactions ?? []
|
||||||
if let attribute = attribute as? ReactionsMessageAttribute {
|
|
||||||
for updatedReaction in reactions {
|
for updatedReaction in reactions {
|
||||||
if !attribute.reactions.contains(where: { $0.value == updatedReaction.reaction && $0.isSelected }) {
|
if !effectiveReactions.contains(where: { $0.value == updatedReaction.reaction && $0.isSelected }) {
|
||||||
let recentReactionItem: RecentReactionItem
|
let recentReactionItem: RecentReactionItem
|
||||||
switch updatedReaction {
|
switch updatedReaction {
|
||||||
case let .builtin(value):
|
case let .builtin(value):
|
||||||
@@ -81,8 +80,6 @@ public func updateMessageReactionsInteractively(account: Account, messageId: Mes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var mappedReactions = mappedReactions
|
var mappedReactions = mappedReactions
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user