Reaction improvements

This commit is contained in:
Ali
2022-09-01 03:31:48 +04:00
parent dfb03c5e99
commit c2834b175a
5 changed files with 57 additions and 25 deletions

View File

@@ -894,6 +894,7 @@ public class Account {
private let becomeMasterDisposable = MetaDisposable()
private let managedServiceViewsDisposable = MetaDisposable()
private let managedOperationsDisposable = DisposableSet()
private let managedTopReactionsDisposable = MetaDisposable()
private var storageSettingsDisposable: Disposable?
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(managedFeaturedStatusEmoji(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 {
@@ -1205,6 +1207,13 @@ public class Account {
}
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
self.managedOperationsDisposable.add(debugFetchAllStickers(account: self).start(completed: {
print("debugFetchAllStickers done")

View File

@@ -656,6 +656,7 @@ struct AccountReplayedFinalState {
let updatedIncomingThreadReadStates: [MessageId: MessageId.Id]
let updatedOutgoingThreadReadStates: [MessageId: MessageId.Id]
let updateConfig: Bool
let isPremiumUpdated: Bool
}
struct AccountFinalStateEvents {
@@ -680,12 +681,13 @@ struct AccountFinalStateEvents {
let updatedIncomingThreadReadStates: [MessageId: MessageId.Id]
let updatedOutgoingThreadReadStates: [MessageId: MessageId.Id]
let updateConfig: Bool
let isPremiumUpdated: 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.addedReactionEvents = addedReactionEvents
self.wasScheduledMessageIds = wasScheduledMessageIds
@@ -707,6 +709,7 @@ struct AccountFinalStateEvents {
self.updatedIncomingThreadReadStates = updatedIncomingThreadReadStates
self.updatedOutgoingThreadReadStates = updatedOutgoingThreadReadStates
self.updateConfig = updateConfig
self.isPremiumUpdated = isPremiumUpdated
}
init(state: AccountReplayedFinalState) {
@@ -731,6 +734,7 @@ struct AccountFinalStateEvents {
self.updatedIncomingThreadReadStates = state.updatedIncomingThreadReadStates
self.updatedOutgoingThreadReadStates = state.updatedOutgoingThreadReadStates
self.updateConfig = state.updateConfig
self.isPremiumUpdated = state.isPremiumUpdated
}
func union(with other: AccountFinalStateEvents) -> AccountFinalStateEvents {
@@ -758,6 +762,8 @@ struct AccountFinalStateEvents {
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)
}
}

View File

@@ -2591,6 +2591,8 @@ func replayFinalState(
}
}
var isPremiumUpdated = false
for operation in optimizedOperations(finalState.state.operations) {
switch operation {
case let .AddMessages(messages, location):
@@ -3067,12 +3069,25 @@ func replayFinalState(
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
return updated
})
updateContacts(transaction: transaction, apiUsers: users)
case let .UpdatePeer(id, f):
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
return updated
})
@@ -3865,5 +3880,5 @@ func replayFinalState(
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)
}

View File

@@ -177,6 +177,7 @@ public final class AccountStateManager {
private let appliedQtsDisposable = MetaDisposable()
var updateConfigRequested: (() -> Void)?
var isPremiumUpdated: (() -> Void)?
init(
accountPeerId: PeerId,
@@ -785,6 +786,10 @@ public final class AccountStateManager {
if events.updateConfig {
self.updateConfigRequested?()
}
if events.isPremiumUpdated {
self.isPremiumUpdated?()
}
case let .pollCompletion(pollId, preMessageIds, preSubscribers):
if self.operations.count > 1 {
self.operations.removeFirst()

View File

@@ -58,10 +58,9 @@ public func updateMessageReactionsInteractively(account: Account, messageId: Mes
}
if storeAsRecentlyUsed {
for attribute in currentMessage.attributes {
if let attribute = attribute as? ReactionsMessageAttribute {
let effectiveReactions = currentMessage.effectiveReactions ?? []
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
switch updatedReaction {
case let .builtin(value):
@@ -81,8 +80,6 @@ public func updateMessageReactionsInteractively(account: Account, messageId: Mes
}
}
}
}
}
var mappedReactions = mappedReactions