Reaction improvements

This commit is contained in:
Ali 2022-08-29 04:05:31 +04:00
parent d3c47d286d
commit 5ca7417ee1
3 changed files with 32 additions and 26 deletions

View File

@ -489,7 +489,7 @@ public final class DefaultAnimatedStickerNodeImpl: ASDisplayNode, AnimatedSticke
let duration: Double = frameSource.frameRate > 0 ? Double(frameSource.frameCount) / Double(frameSource.frameRate) : 0 let duration: Double = frameSource.frameRate > 0 ? Double(frameSource.frameCount) / Double(frameSource.frameRate) : 0
let frameRate = frameSource.frameRate let frameRate = frameSource.frameRate
let timer = SwiftSignalKit.Timer(timeout: 1.0 / Double(frameRate), repeat: !firstFrame, completion: { let timerEvent: () -> Void = {
let frame = frameQueue.syncWith { frameQueue in let frame = frameQueue.syncWith { frameQueue in
return frameQueue.take(draw: true) return frameQueue.take(draw: true)
} }
@ -544,8 +544,13 @@ public final class DefaultAnimatedStickerNodeImpl: ASDisplayNode, AnimatedSticke
frameQueue.with { frameQueue in frameQueue.with { frameQueue in
frameQueue.generateFramesIfNeeded() frameQueue.generateFramesIfNeeded()
} }
}
let timer = SwiftSignalKit.Timer(timeout: 1.0 / Double(frameRate), repeat: !firstFrame, completion: {
timerEvent()
}, queue: queue) }, queue: queue)
let _ = timerHolder.swap(timer) let _ = timerHolder.swap(timer)
timerEvent()
timer.start() timer.start()
} }
} else { } else {

View File

@ -43,15 +43,13 @@ func _internal_messageReadStats(account: Account, id: MessageId) -> Signal<Messa
return combineLatest(readPeers, reactionCount) return combineLatest(readPeers, reactionCount)
|> mapToSignal { result, reactionCount -> Signal<MessageReadStats?, NoError> in |> mapToSignal { result, reactionCount -> Signal<MessageReadStats?, NoError> in
guard let result = result else {
return .single(nil)
}
return account.postbox.transaction { transaction -> (peerIds: [PeerId], missingPeerIds: [PeerId]) in return account.postbox.transaction { transaction -> (peerIds: [PeerId], missingPeerIds: [PeerId]) in
var peerIds: [PeerId] = [] var peerIds: [PeerId] = []
var missingPeerIds: [PeerId] = [] var missingPeerIds: [PeerId] = []
let authorId = transaction.getMessage(id)?.author?.id let authorId = transaction.getMessage(id)?.author?.id
if let result = result {
for id in result { for id in result {
let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(id)) let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(id))
if peerId == account.peerId { if peerId == account.peerId {
@ -65,6 +63,7 @@ func _internal_messageReadStats(account: Account, id: MessageId) -> Signal<Messa
missingPeerIds.append(peerId) missingPeerIds.append(peerId)
} }
} }
}
return (peerIds: peerIds, missingPeerIds: missingPeerIds) return (peerIds: peerIds, missingPeerIds: missingPeerIds)
} }

View File

@ -211,13 +211,15 @@ private func canViewReadStats(message: Message, participantCount: Int?, isMessag
case let channel as TelegramChannel: case let channel as TelegramChannel:
if case .broadcast = channel.info { if case .broadcast = channel.info {
return false return false
} else if let participantCount = participantCount { } else {
if let participantCount = participantCount {
if participantCount > maxParticipantCount { if participantCount > maxParticipantCount {
return false return false
} }
} else { } else {
return false return false
} }
}
case let group as TelegramGroup: case let group as TelegramGroup:
if group.participantCount > maxParticipantCount { if group.participantCount > maxParticipantCount {
return false return false
@ -1571,19 +1573,17 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState
reactionCount = 0 reactionCount = 0
} }
var readStats = readStats /*var readStats = readStats
if !canViewStats { if !canViewStats {
readStats = MessageReadStats(reactionCount: 0, peers: []) readStats = MessageReadStats(reactionCount: 0, peers: [])
} }*/
let reactionCount = readStats?.reactionCount ?? 0
if hasReadReports || reactionCount != 0 { if hasReadReports || reactionCount != 0 {
if !actions.isEmpty { if !actions.isEmpty {
actions.insert(.separator, at: 0) actions.insert(.separator, at: 0)
} }
actions.insert(.custom(ChatReadReportContextItem(context: context, message: message, stats: readStats, action: { c, f, stats, customReactionEmojiPacks, firstCustomEmojiReaction in actions.insert(.custom(ChatReadReportContextItem(context: context, message: message, hasReadReports: hasReadReports, stats: readStats, action: { c, f, stats, customReactionEmojiPacks, firstCustomEmojiReaction in
if reactionCount == 0, let stats = stats, stats.peers.count == 1 { if reactionCount == 0, let stats = stats, stats.peers.count == 1 {
c.dismiss(completion: { c.dismiss(completion: {
controllerInteraction.openPeer(stats.peers[0].id, .default, nil, false, nil) controllerInteraction.openPeer(stats.peers[0].id, .default, nil, false, nil)
@ -2162,12 +2162,14 @@ private final class ChatDeleteMessageContextItemNode: ASDisplayNode, ContextMenu
final class ChatReadReportContextItem: ContextMenuCustomItem { final class ChatReadReportContextItem: ContextMenuCustomItem {
fileprivate let context: AccountContext fileprivate let context: AccountContext
fileprivate let message: Message fileprivate let message: Message
fileprivate let hasReadReports: Bool
fileprivate let stats: MessageReadStats? fileprivate let stats: MessageReadStats?
fileprivate let action: (ContextControllerProtocol, @escaping (ContextMenuActionResult) -> Void, MessageReadStats?, [StickerPackCollectionInfo], TelegramMediaFile?) -> Void fileprivate let action: (ContextControllerProtocol, @escaping (ContextMenuActionResult) -> Void, MessageReadStats?, [StickerPackCollectionInfo], TelegramMediaFile?) -> Void
init(context: AccountContext, message: Message, stats: MessageReadStats?, action: @escaping (ContextControllerProtocol, @escaping (ContextMenuActionResult) -> Void, MessageReadStats?, [StickerPackCollectionInfo], TelegramMediaFile?) -> Void) { init(context: AccountContext, message: Message, hasReadReports: Bool, stats: MessageReadStats?, action: @escaping (ContextControllerProtocol, @escaping (ContextMenuActionResult) -> Void, MessageReadStats?, [StickerPackCollectionInfo], TelegramMediaFile?) -> Void) {
self.context = context self.context = context
self.message = message self.message = message
self.hasReadReports = hasReadReports
self.stats = stats self.stats = stats
self.action = action self.action = action
} }
@ -2380,7 +2382,7 @@ private final class ChatReadReportContextItemNode: ASDisplayNode, ContextMenuCus
private var validLayout: (calculatedWidth: CGFloat, size: CGSize)? private var validLayout: (calculatedWidth: CGFloat, size: CGSize)?
func updateStats(stats: MessageReadStats, transition: ContainedViewLayoutTransition) { func updateStats(stats: MessageReadStats, transition: ContainedViewLayoutTransition) {
self.buttonNode.isUserInteractionEnabled = !stats.peers.isEmpty self.buttonNode.isUserInteractionEnabled = !stats.peers.isEmpty || stats.reactionCount != 0
guard let (calculatedWidth, size) = self.validLayout else { guard let (calculatedWidth, size) = self.validLayout else {
return return