Support reaction timestamps

This commit is contained in:
Ali
2023-03-07 15:59:14 +04:00
parent 11409151df
commit 270d49557c
6 changed files with 32 additions and 20 deletions

View File

@@ -514,7 +514,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[-1618676578] = { return Api.MessageMedia.parse_messageMediaUnsupported($0) } dict[-1618676578] = { return Api.MessageMedia.parse_messageMediaUnsupported($0) }
dict[784356159] = { return Api.MessageMedia.parse_messageMediaVenue($0) } dict[784356159] = { return Api.MessageMedia.parse_messageMediaVenue($0) }
dict[-1557277184] = { return Api.MessageMedia.parse_messageMediaWebPage($0) } dict[-1557277184] = { return Api.MessageMedia.parse_messageMediaWebPage($0) }
dict[-1319698788] = { return Api.MessagePeerReaction.parse_messagePeerReaction($0) } dict[-1938180548] = { return Api.MessagePeerReaction.parse_messagePeerReaction($0) }
dict[182649427] = { return Api.MessageRange.parse_messageRange($0) } dict[182649427] = { return Api.MessageRange.parse_messageRange($0) }
dict[1328256121] = { return Api.MessageReactions.parse_messageReactions($0) } dict[1328256121] = { return Api.MessageReactions.parse_messageReactions($0) }
dict[-2083123262] = { return Api.MessageReplies.parse_messageReplies($0) } dict[-2083123262] = { return Api.MessageReplies.parse_messageReplies($0) }

View File

@@ -1,15 +1,16 @@
public extension Api { public extension Api {
enum MessagePeerReaction: TypeConstructorDescription { enum MessagePeerReaction: TypeConstructorDescription {
case messagePeerReaction(flags: Int32, peerId: Api.Peer, reaction: Api.Reaction) case messagePeerReaction(flags: Int32, peerId: Api.Peer, date: Int32, reaction: Api.Reaction)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self { switch self {
case .messagePeerReaction(let flags, let peerId, let reaction): case .messagePeerReaction(let flags, let peerId, let date, let reaction):
if boxed { if boxed {
buffer.appendInt32(-1319698788) buffer.appendInt32(-1938180548)
} }
serializeInt32(flags, buffer: buffer, boxed: false) serializeInt32(flags, buffer: buffer, boxed: false)
peerId.serialize(buffer, true) peerId.serialize(buffer, true)
serializeInt32(date, buffer: buffer, boxed: false)
reaction.serialize(buffer, true) reaction.serialize(buffer, true)
break break
} }
@@ -17,8 +18,8 @@ public extension Api {
public func descriptionFields() -> (String, [(String, Any)]) { public func descriptionFields() -> (String, [(String, Any)]) {
switch self { switch self {
case .messagePeerReaction(let flags, let peerId, let reaction): case .messagePeerReaction(let flags, let peerId, let date, let reaction):
return ("messagePeerReaction", [("flags", flags as Any), ("peerId", peerId as Any), ("reaction", reaction as Any)]) return ("messagePeerReaction", [("flags", flags as Any), ("peerId", peerId as Any), ("date", date as Any), ("reaction", reaction as Any)])
} }
} }
@@ -29,15 +30,18 @@ public extension Api {
if let signature = reader.readInt32() { if let signature = reader.readInt32() {
_2 = Api.parse(reader, signature: signature) as? Api.Peer _2 = Api.parse(reader, signature: signature) as? Api.Peer
} }
var _3: Api.Reaction? var _3: Int32?
_3 = reader.readInt32()
var _4: Api.Reaction?
if let signature = reader.readInt32() { if let signature = reader.readInt32() {
_3 = Api.parse(reader, signature: signature) as? Api.Reaction _4 = Api.parse(reader, signature: signature) as? Api.Reaction
} }
let _c1 = _1 != nil let _c1 = _1 != nil
let _c2 = _2 != nil let _c2 = _2 != nil
let _c3 = _3 != nil let _c3 = _3 != nil
if _c1 && _c2 && _c3 { let _c4 = _4 != nil
return Api.MessagePeerReaction.messagePeerReaction(flags: _1!, peerId: _2!, reaction: _3!) if _c1 && _c2 && _c3 && _c4 {
return Api.MessagePeerReaction.messagePeerReaction(flags: _1!, peerId: _2!, date: _3!, reaction: _4!)
} }
else { else {
return nil return nil

View File

@@ -22,11 +22,11 @@ extension ReactionsMessageAttribute {
if let recentReactions = recentReactions { if let recentReactions = recentReactions {
parsedRecentReactions = recentReactions.compactMap { recentReaction -> ReactionsMessageAttribute.RecentPeer? in parsedRecentReactions = recentReactions.compactMap { recentReaction -> ReactionsMessageAttribute.RecentPeer? in
switch recentReaction { switch recentReaction {
case let .messagePeerReaction(flags, peerId, reaction): case let .messagePeerReaction(flags, peerId, date, reaction):
let isLarge = (flags & (1 << 0)) != 0 let isLarge = (flags & (1 << 0)) != 0
let isUnseen = (flags & (1 << 1)) != 0 let isUnseen = (flags & (1 << 1)) != 0
if let reaction = MessageReaction.Reaction(apiReaction: reaction) { if let reaction = MessageReaction.Reaction(apiReaction: reaction) {
return ReactionsMessageAttribute.RecentPeer(value: reaction, isLarge: isLarge, isUnseen: isUnseen, peerId: peerId.peerId) return ReactionsMessageAttribute.RecentPeer(value: reaction, isLarge: isLarge, isUnseen: isUnseen, peerId: peerId.peerId, timestamp: date)
} else { } else {
return nil return nil
} }
@@ -117,7 +117,7 @@ private func mergeReactions(reactions: [MessageReaction], recentPeers: [Reaction
if let index = recentPeers.firstIndex(where: { $0.value == pendingReaction.value && $0.peerId == accountPeerId }) { if let index = recentPeers.firstIndex(where: { $0.value == pendingReaction.value && $0.peerId == accountPeerId }) {
recentPeers.remove(at: index) recentPeers.remove(at: index)
} }
recentPeers.append(ReactionsMessageAttribute.RecentPeer(value: pendingReaction.value, isLarge: false, isUnseen: false, peerId: accountPeerId)) recentPeers.append(ReactionsMessageAttribute.RecentPeer(value: pendingReaction.value, isLarge: false, isUnseen: false, peerId: accountPeerId, timestamp: Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970)))
} }
for i in (0 ..< result.count).reversed() { for i in (0 ..< result.count).reversed() {
@@ -184,11 +184,11 @@ extension ReactionsMessageAttribute {
if let recentReactions = recentReactions { if let recentReactions = recentReactions {
parsedRecentReactions = recentReactions.compactMap { recentReaction -> ReactionsMessageAttribute.RecentPeer? in parsedRecentReactions = recentReactions.compactMap { recentReaction -> ReactionsMessageAttribute.RecentPeer? in
switch recentReaction { switch recentReaction {
case let .messagePeerReaction(flags, peerId, reaction): case let .messagePeerReaction(flags, peerId, date, reaction):
let isLarge = (flags & (1 << 0)) != 0 let isLarge = (flags & (1 << 0)) != 0
let isUnseen = (flags & (1 << 1)) != 0 let isUnseen = (flags & (1 << 1)) != 0
if let reaction = MessageReaction.Reaction(apiReaction: reaction) { if let reaction = MessageReaction.Reaction(apiReaction: reaction) {
return ReactionsMessageAttribute.RecentPeer(value: reaction, isLarge: isLarge, isUnseen: isUnseen, peerId: peerId.peerId) return ReactionsMessageAttribute.RecentPeer(value: reaction, isLarge: isLarge, isUnseen: isUnseen, peerId: peerId.peerId, timestamp: date)
} else { } else {
return nil return nil
} }

View File

@@ -338,7 +338,7 @@ public extension EngineMessageReactionListContext.State {
for recentPeer in reactionsAttribute.recentPeers { for recentPeer in reactionsAttribute.recentPeers {
if let peer = message.peers[recentPeer.peerId] { if let peer = message.peers[recentPeer.peerId] {
if reaction == nil || recentPeer.value == reaction { if reaction == nil || recentPeer.value == reaction {
items.append(EngineMessageReactionListContext.Item(peer: EnginePeer(peer), reaction: recentPeer.value, timestamp: readStats?.readTimestamps[peer.id])) items.append(EngineMessageReactionListContext.Item(peer: EnginePeer(peer), reaction: recentPeer.value, timestamp: recentPeer.timestamp ?? readStats?.readTimestamps[peer.id]))
} }
} }
} }
@@ -507,9 +507,9 @@ public final class EngineMessageReactionListContext {
var items: [EngineMessageReactionListContext.Item] = [] var items: [EngineMessageReactionListContext.Item] = []
for reaction in reactions { for reaction in reactions {
switch reaction { switch reaction {
case let .messagePeerReaction(_, peer, reaction): case let .messagePeerReaction(_, peer, date, reaction):
if let peer = transaction.getPeer(peer.peerId), let reaction = MessageReaction.Reaction(apiReaction: reaction) { if let peer = transaction.getPeer(peer.peerId), let reaction = MessageReaction.Reaction(apiReaction: reaction) {
items.append(EngineMessageReactionListContext.Item(peer: EnginePeer(peer), reaction: reaction, timestamp: nil)) items.append(EngineMessageReactionListContext.Item(peer: EnginePeer(peer), reaction: reaction, timestamp: date))
} }
} }
} }

View File

@@ -210,7 +210,7 @@ public class BoxedMessage: NSObject {
public class Serialization: NSObject, MTSerialization { public class Serialization: NSObject, MTSerialization {
public func currentLayer() -> UInt { public func currentLayer() -> UInt {
return 154 return 155
} }
public func parseMessage(_ data: Data!) -> Any! { public func parseMessage(_ data: Data!) -> Any! {

View File

@@ -119,12 +119,14 @@ public final class ReactionsMessageAttribute: Equatable, MessageAttribute {
public var isLarge: Bool public var isLarge: Bool
public var isUnseen: Bool public var isUnseen: Bool
public var peerId: PeerId public var peerId: PeerId
public var timestamp: Int32?
public init(value: MessageReaction.Reaction, isLarge: Bool, isUnseen: Bool, peerId: PeerId) { public init(value: MessageReaction.Reaction, isLarge: Bool, isUnseen: Bool, peerId: PeerId, timestamp: Int32?) {
self.value = value self.value = value
self.isLarge = isLarge self.isLarge = isLarge
self.isUnseen = isUnseen self.isUnseen = isUnseen
self.peerId = peerId self.peerId = peerId
self.timestamp = timestamp
} }
public init(decoder: PostboxDecoder) { public init(decoder: PostboxDecoder) {
@@ -136,6 +138,7 @@ public final class ReactionsMessageAttribute: Equatable, MessageAttribute {
self.isLarge = decoder.decodeInt32ForKey("l", orElse: 0) != 0 self.isLarge = decoder.decodeInt32ForKey("l", orElse: 0) != 0
self.isUnseen = decoder.decodeInt32ForKey("u", orElse: 0) != 0 self.isUnseen = decoder.decodeInt32ForKey("u", orElse: 0) != 0
self.peerId = PeerId(decoder.decodeInt64ForKey("p", orElse: 0)) self.peerId = PeerId(decoder.decodeInt64ForKey("p", orElse: 0))
self.timestamp = decoder.decodeOptionalInt32ForKey("ts")
} }
public func encode(_ encoder: PostboxEncoder) { public func encode(_ encoder: PostboxEncoder) {
@@ -148,6 +151,11 @@ public final class ReactionsMessageAttribute: Equatable, MessageAttribute {
encoder.encodeInt32(self.isLarge ? 1 : 0, forKey: "l") encoder.encodeInt32(self.isLarge ? 1 : 0, forKey: "l")
encoder.encodeInt32(self.isUnseen ? 1 : 0, forKey: "u") encoder.encodeInt32(self.isUnseen ? 1 : 0, forKey: "u")
encoder.encodeInt64(self.peerId.toInt64(), forKey: "p") encoder.encodeInt64(self.peerId.toInt64(), forKey: "p")
if let timestamp = self.timestamp {
encoder.encodeInt32(timestamp, forKey: "ts")
} else {
encoder.encodeNil(forKey: "ts")
}
} }
} }