Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios

This commit is contained in:
Mike Renoir
2023-09-01 17:05:22 +04:00
60 changed files with 1905 additions and 301 deletions

View File

@@ -56,7 +56,11 @@ public class AutoclearTimeoutMessageAttribute: MessageAttribute {
self.countdownBeginTime = countdownBeginTime
if let countdownBeginTime = countdownBeginTime {
self.automaticTimestampBasedAttribute = (1, countdownBeginTime + timeout)
if self.timeout == viewOnceTimeout {
self.automaticTimestampBasedAttribute = (1, countdownBeginTime)
} else {
self.automaticTimestampBasedAttribute = (1, countdownBeginTime + timeout)
}
} else {
self.automaticTimestampBasedAttribute = nil
}
@@ -67,7 +71,11 @@ public class AutoclearTimeoutMessageAttribute: MessageAttribute {
self.countdownBeginTime = decoder.decodeOptionalInt32ForKey("c")
if let countdownBeginTime = self.countdownBeginTime {
self.automaticTimestampBasedAttribute = (1, countdownBeginTime + self.timeout)
if self.timeout == viewOnceTimeout {
self.automaticTimestampBasedAttribute = (1, countdownBeginTime)
} else {
self.automaticTimestampBasedAttribute = (1, countdownBeginTime + self.timeout)
}
} else {
self.automaticTimestampBasedAttribute = nil
}

View File

@@ -1,7 +1,7 @@
import Postbox
import TelegramApi
public struct MessageReaction: Equatable, PostboxCoding {
public struct MessageReaction: Equatable, PostboxCoding, Codable {
public enum Reaction: Hashable, Codable, PostboxCoding {
case builtin(String)
case custom(Int64)
@@ -75,6 +75,24 @@ public struct MessageReaction: Equatable, PostboxCoding {
}
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: StringCodingKey.self)
if let value = try container.decodeIfPresent(String.self, forKey: "v") {
self.value = .builtin(value)
} else {
self.value = .custom(try container.decode(Int64.self, forKey: "cfid"))
}
self.count = try container.decode(Int32.self, forKey: "c")
if let chosenOrder = try container.decodeIfPresent(Int32.self, forKey: "s") {
self.chosenOrder = Int(chosenOrder)
} else if let isSelected = try container.decodeIfPresent(Int32.self, forKey: "s"), isSelected != 0 {
self.chosenOrder = 0
} else {
self.chosenOrder = nil
}
}
public func encode(_ encoder: PostboxEncoder) {
switch self.value {
case let .builtin(value):
@@ -89,6 +107,19 @@ public struct MessageReaction: Equatable, PostboxCoding {
encoder.encodeNil(forKey: "cord")
}
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: StringCodingKey.self)
switch self.value {
case let .builtin(value):
try container.encode(value, forKey: "v")
case let .custom(fileId):
try container.encode(fileId, forKey: "cfid")
}
try container.encode(self.count, forKey: "c")
try container.encodeIfPresent(self.chosenOrder.flatMap(Int32.init), forKey: "cord")
}
}
extension MessageReaction.Reaction {

View File

@@ -91,7 +91,7 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
case paymentSent(currency: String, totalAmount: Int64, invoiceSlug: String?, isRecurringInit: Bool, isRecurringUsed: Bool)
case customText(text: String, entities: [MessageTextEntity])
case botDomainAccessGranted(domain: String)
case botAppAccessGranted(appName: String, type: BotSendMessageAccessGrantedType?)
case botAppAccessGranted(appName: String?, type: BotSendMessageAccessGrantedType?)
case botSentSecureValues(types: [SentSecureValueType])
case peerJoined
case phoneNumberRequest
@@ -202,7 +202,7 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
self = .unknown
}
case 35:
self = .botAppAccessGranted(appName: decoder.decodeStringForKey("app", orElse: ""), type: decoder.decodeOptionalInt32ForKey("atp").flatMap { BotSendMessageAccessGrantedType(rawValue: $0) })
self = .botAppAccessGranted(appName: decoder.decodeOptionalStringForKey("app"), type: decoder.decodeOptionalInt32ForKey("atp").flatMap { BotSendMessageAccessGrantedType(rawValue: $0) })
default:
self = .unknown
}
@@ -372,7 +372,11 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
encoder.encode(TelegramWallpaperNativeCodable(wallpaper), forKey: "wallpaper")
case let .botAppAccessGranted(appName, type):
encoder.encodeInt32(35, forKey: "_rawValue")
encoder.encodeString(appName, forKey: "app")
if let appName = appName {
encoder.encodeString(appName, forKey: "app")
} else {
encoder.encodeNil(forKey: "app")
}
if let type = type {
encoder.encodeInt32(type.rawValue, forKey: "atp")
} else {