mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Merge commit '5fb5c433bcd9c6b96f91f3ff25e3cec296906eed' into postbox-refactoring-1
This commit is contained in:
@@ -1254,7 +1254,7 @@ private func finalStateWithUpdatesAndServerTime(postbox: Postbox, network: Netwo
|
||||
updatedState.readSecretOutbox(peerId: PeerId(namespace: Namespaces.Peer.SecretChat, id: PeerId.Id._internalFromInt64Value(Int64(chatId))), timestamp: maxDate, actionTimestamp: date)
|
||||
case let .updateUserTyping(userId, type):
|
||||
if let date = updatesDate, date + 60 > serverTime {
|
||||
let activity = PeerInputActivity(apiType: type, timestamp: date)
|
||||
let activity = PeerInputActivity(apiType: type, peerId: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId)), timestamp: date)
|
||||
var category: PeerActivitySpace.Category = .global
|
||||
if case .speakingInGroupCall = activity {
|
||||
category = .voiceChat
|
||||
@@ -1264,7 +1264,7 @@ private func finalStateWithUpdatesAndServerTime(postbox: Postbox, network: Netwo
|
||||
}
|
||||
case let .updateChatUserTyping(chatId, userId, type):
|
||||
if let date = updatesDate, date + 60 > serverTime {
|
||||
let activity = PeerInputActivity(apiType: type, timestamp: date)
|
||||
let activity = PeerInputActivity(apiType: type, peerId: nil, timestamp: date)
|
||||
var category: PeerActivitySpace.Category = .global
|
||||
if case .speakingInGroupCall = activity {
|
||||
category = .voiceChat
|
||||
@@ -1277,7 +1277,7 @@ private func finalStateWithUpdatesAndServerTime(postbox: Postbox, network: Netwo
|
||||
let channelPeerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId))
|
||||
let threadId = topMsgId.flatMap { makeMessageThreadId(MessageId(peerId: channelPeerId, namespace: Namespaces.Message.Cloud, id: $0)) }
|
||||
|
||||
let activity = PeerInputActivity(apiType: type, timestamp: date)
|
||||
let activity = PeerInputActivity(apiType: type, peerId: nil, timestamp: date)
|
||||
var category: PeerActivitySpace.Category = .global
|
||||
if case .speakingInGroupCall = activity {
|
||||
category = .voiceChat
|
||||
|
||||
@@ -131,8 +131,8 @@ private func actionFromActivity(_ activity: PeerInputActivity?) -> Api.SendMessa
|
||||
return .speakingInGroupCallAction
|
||||
case .choosingSticker:
|
||||
return .sendMessageChooseStickerAction
|
||||
case let .interactingWithEmoji(emoticon, interaction):
|
||||
return .sendMessageEmojiInteraction(emoticon: emoticon, interaction: interaction?.apiDataJson ?? .dataJSON(data: ""))
|
||||
case let .interactingWithEmoji(emoticon, messageId, interaction):
|
||||
return .sendMessageEmojiInteraction(emoticon: emoticon, msgId: messageId.id, interaction: interaction?.apiDataJson ?? .dataJSON(data: ""))
|
||||
case let .seeingEmojiInteraction(emoticon):
|
||||
return .sendMessageEmojiInteractionSeen(emoticon: emoticon)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
import TelegramApi
|
||||
|
||||
public struct EmojiInteraction: Equatable {
|
||||
@@ -31,8 +32,8 @@ public struct EmojiInteraction: Equatable {
|
||||
var animations: [EmojiInteraction.Animation] = []
|
||||
for animationDict in animationsArray {
|
||||
if let animationDict = animationDict as? [String: Any] {
|
||||
if let index = animationDict["i"] as? Int, let timeOffset = animationDict["t"] as? Float {
|
||||
animations.append(EmojiInteraction.Animation(index: index, timeOffset: timeOffset))
|
||||
if let index = animationDict["i"] as? Int, let timeOffset = animationDict["t"] as? Double {
|
||||
animations.append(EmojiInteraction.Animation(index: index, timeOffset: Float(timeOffset)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,8 +46,10 @@ public struct EmojiInteraction: Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate let roundingBehavior = NSDecimalNumberHandler(roundingMode: .plain, scale: 2, raiseOnExactness: false, raiseOnOverflow: false, raiseOnUnderflow: false, raiseOnDivideByZero: true)
|
||||
|
||||
public var apiDataJson: Api.DataJSON {
|
||||
let dict = ["v": 1, "a": self.animations.map({ ["i": $0.index, "t": $0.timeOffset] })] as [String : Any]
|
||||
let dict = ["v": 1, "a": self.animations.map({ ["i": $0.index, "t": NSDecimalNumber(value: $0.timeOffset).rounding(accordingToBehavior: roundingBehavior)] })] as [String : Any]
|
||||
if let data = try? JSONSerialization.data(withJSONObject: dict, options: []), let dataString = String(data: data, encoding: .utf8) {
|
||||
return .dataJSON(data: dataString)
|
||||
} else {
|
||||
@@ -66,7 +69,7 @@ public enum PeerInputActivity: Comparable {
|
||||
case uploadingInstantVideo(progress: Int32)
|
||||
case speakingInGroupCall(timestamp: Int32)
|
||||
case choosingSticker
|
||||
case interactingWithEmoji(emoticon: String, interaction: EmojiInteraction?)
|
||||
case interactingWithEmoji(emoticon: String, messageId: MessageId, interaction: EmojiInteraction?)
|
||||
case seeingEmojiInteraction(emoticon: String)
|
||||
|
||||
public var key: Int32 {
|
||||
@@ -104,7 +107,7 @@ public enum PeerInputActivity: Comparable {
|
||||
}
|
||||
|
||||
extension PeerInputActivity {
|
||||
init?(apiType: Api.SendMessageAction, timestamp: Int32) {
|
||||
init?(apiType: Api.SendMessageAction, peerId: PeerId?, timestamp: Int32) {
|
||||
switch apiType {
|
||||
case .sendMessageCancelAction, .sendMessageChooseContactAction, .sendMessageGeoLocationAction, .sendMessageRecordVideoAction:
|
||||
return nil
|
||||
@@ -130,8 +133,12 @@ extension PeerInputActivity {
|
||||
self = .choosingSticker
|
||||
case .sendMessageHistoryImportAction:
|
||||
return nil
|
||||
case let .sendMessageEmojiInteraction(emoticon, interaction):
|
||||
self = .interactingWithEmoji(emoticon: emoticon, interaction: EmojiInteraction(apiDataJson: interaction))
|
||||
case let .sendMessageEmojiInteraction(emoticon, messageId, interaction):
|
||||
if let peerId = peerId {
|
||||
self = .interactingWithEmoji(emoticon: emoticon, messageId: MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: messageId), interaction: EmojiInteraction(apiDataJson: interaction))
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
case let .sendMessageEmojiInteractionSeen(emoticon):
|
||||
self = .seeingEmojiInteraction(emoticon: emoticon)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user