mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Support reaction timestamps
This commit is contained in:
parent
11409151df
commit
270d49557c
@ -514,7 +514,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[-1618676578] = { return Api.MessageMedia.parse_messageMediaUnsupported($0) }
|
||||
dict[784356159] = { return Api.MessageMedia.parse_messageMediaVenue($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[1328256121] = { return Api.MessageReactions.parse_messageReactions($0) }
|
||||
dict[-2083123262] = { return Api.MessageReplies.parse_messageReplies($0) }
|
||||
|
@ -1,15 +1,16 @@
|
||||
public extension Api {
|
||||
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) {
|
||||
switch self {
|
||||
case .messagePeerReaction(let flags, let peerId, let reaction):
|
||||
case .messagePeerReaction(let flags, let peerId, let date, let reaction):
|
||||
if boxed {
|
||||
buffer.appendInt32(-1319698788)
|
||||
buffer.appendInt32(-1938180548)
|
||||
}
|
||||
serializeInt32(flags, buffer: buffer, boxed: false)
|
||||
peerId.serialize(buffer, true)
|
||||
serializeInt32(date, buffer: buffer, boxed: false)
|
||||
reaction.serialize(buffer, true)
|
||||
break
|
||||
}
|
||||
@ -17,8 +18,8 @@ public extension Api {
|
||||
|
||||
public func descriptionFields() -> (String, [(String, Any)]) {
|
||||
switch self {
|
||||
case .messagePeerReaction(let flags, let peerId, let reaction):
|
||||
return ("messagePeerReaction", [("flags", flags as Any), ("peerId", peerId as Any), ("reaction", reaction as Any)])
|
||||
case .messagePeerReaction(let flags, let peerId, let date, let reaction):
|
||||
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() {
|
||||
_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() {
|
||||
_3 = Api.parse(reader, signature: signature) as? Api.Reaction
|
||||
_4 = Api.parse(reader, signature: signature) as? Api.Reaction
|
||||
}
|
||||
let _c1 = _1 != nil
|
||||
let _c2 = _2 != nil
|
||||
let _c3 = _3 != nil
|
||||
if _c1 && _c2 && _c3 {
|
||||
return Api.MessagePeerReaction.messagePeerReaction(flags: _1!, peerId: _2!, reaction: _3!)
|
||||
let _c4 = _4 != nil
|
||||
if _c1 && _c2 && _c3 && _c4 {
|
||||
return Api.MessagePeerReaction.messagePeerReaction(flags: _1!, peerId: _2!, date: _3!, reaction: _4!)
|
||||
}
|
||||
else {
|
||||
return nil
|
||||
|
@ -22,11 +22,11 @@ extension ReactionsMessageAttribute {
|
||||
if let recentReactions = recentReactions {
|
||||
parsedRecentReactions = recentReactions.compactMap { recentReaction -> ReactionsMessageAttribute.RecentPeer? in
|
||||
switch recentReaction {
|
||||
case let .messagePeerReaction(flags, peerId, reaction):
|
||||
case let .messagePeerReaction(flags, peerId, date, reaction):
|
||||
let isLarge = (flags & (1 << 0)) != 0
|
||||
let isUnseen = (flags & (1 << 1)) != 0
|
||||
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 {
|
||||
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 }) {
|
||||
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() {
|
||||
@ -184,11 +184,11 @@ extension ReactionsMessageAttribute {
|
||||
if let recentReactions = recentReactions {
|
||||
parsedRecentReactions = recentReactions.compactMap { recentReaction -> ReactionsMessageAttribute.RecentPeer? in
|
||||
switch recentReaction {
|
||||
case let .messagePeerReaction(flags, peerId, reaction):
|
||||
case let .messagePeerReaction(flags, peerId, date, reaction):
|
||||
let isLarge = (flags & (1 << 0)) != 0
|
||||
let isUnseen = (flags & (1 << 1)) != 0
|
||||
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 {
|
||||
return nil
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ public extension EngineMessageReactionListContext.State {
|
||||
for recentPeer in reactionsAttribute.recentPeers {
|
||||
if let peer = message.peers[recentPeer.peerId] {
|
||||
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] = []
|
||||
for reaction in reactions {
|
||||
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) {
|
||||
items.append(EngineMessageReactionListContext.Item(peer: EnginePeer(peer), reaction: reaction, timestamp: nil))
|
||||
items.append(EngineMessageReactionListContext.Item(peer: EnginePeer(peer), reaction: reaction, timestamp: date))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ public class BoxedMessage: NSObject {
|
||||
|
||||
public class Serialization: NSObject, MTSerialization {
|
||||
public func currentLayer() -> UInt {
|
||||
return 154
|
||||
return 155
|
||||
}
|
||||
|
||||
public func parseMessage(_ data: Data!) -> Any! {
|
||||
|
@ -119,12 +119,14 @@ public final class ReactionsMessageAttribute: Equatable, MessageAttribute {
|
||||
public var isLarge: Bool
|
||||
public var isUnseen: Bool
|
||||
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.isLarge = isLarge
|
||||
self.isUnseen = isUnseen
|
||||
self.peerId = peerId
|
||||
self.timestamp = timestamp
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
@ -136,6 +138,7 @@ public final class ReactionsMessageAttribute: Equatable, MessageAttribute {
|
||||
self.isLarge = decoder.decodeInt32ForKey("l", orElse: 0) != 0
|
||||
self.isUnseen = decoder.decodeInt32ForKey("u", orElse: 0) != 0
|
||||
self.peerId = PeerId(decoder.decodeInt64ForKey("p", orElse: 0))
|
||||
self.timestamp = decoder.decodeOptionalInt32ForKey("ts")
|
||||
}
|
||||
|
||||
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.isUnseen ? 1 : 0, forKey: "u")
|
||||
encoder.encodeInt64(self.peerId.toInt64(), forKey: "p")
|
||||
if let timestamp = self.timestamp {
|
||||
encoder.encodeInt32(timestamp, forKey: "ts")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "ts")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user