This commit is contained in:
overtake 2017-08-29 17:21:11 +03:00
commit f2edf323c8
97 changed files with 654 additions and 406 deletions

View File

@ -360,6 +360,8 @@
D09D8C0B1D4FAB1D0081DBEC /* TelegramCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D09D8C011D4FAB1D0081DBEC /* TelegramCore.framework */; };
D09D8C101D4FAB1D0081DBEC /* TelegramCoreTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D09D8C0F1D4FAB1D0081DBEC /* TelegramCoreTests.m */; };
D09D8C121D4FAB1D0081DBEC /* TelegramCore.h in Headers */ = {isa = PBXBuildFile; fileRef = D09D8C041D4FAB1D0081DBEC /* TelegramCore.h */; settings = {ATTRIBUTES = (Public, ); }; };
D0A472B61F4CBE8B00E0EEDA /* LoadedPeer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0A472B51F4CBE8B00E0EEDA /* LoadedPeer.swift */; };
D0A472B71F4CBE8B00E0EEDA /* LoadedPeer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0A472B51F4CBE8B00E0EEDA /* LoadedPeer.swift */; };
D0AAD1A81E32602500D5B9DE /* AutoremoveTimeoutMessageAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0AAD1A71E32602500D5B9DE /* AutoremoveTimeoutMessageAttribute.swift */; };
D0AAD1AA1E32638500D5B9DE /* ApplyMaxReadIndexInteractively.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0AAD1A91E32638500D5B9DE /* ApplyMaxReadIndexInteractively.swift */; };
D0AAD1B81E326FE200D5B9DE /* ManagedAutoremoveMessageOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0AAD1B71E326FE200D5B9DE /* ManagedAutoremoveMessageOperations.swift */; };
@ -784,6 +786,7 @@
D09D8C0A1D4FAB1D0081DBEC /* TelegramCoreTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TelegramCoreTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D09D8C0F1D4FAB1D0081DBEC /* TelegramCoreTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TelegramCoreTests.m; sourceTree = "<group>"; };
D09D8C111D4FAB1D0081DBEC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D0A472B51F4CBE8B00E0EEDA /* LoadedPeer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadedPeer.swift; sourceTree = "<group>"; };
D0AAD1A71E32602500D5B9DE /* AutoremoveTimeoutMessageAttribute.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AutoremoveTimeoutMessageAttribute.swift; sourceTree = "<group>"; };
D0AAD1A91E32638500D5B9DE /* ApplyMaxReadIndexInteractively.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApplyMaxReadIndexInteractively.swift; sourceTree = "<group>"; };
D0AAD1B71E326FE200D5B9DE /* ManagedAutoremoveMessageOperations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManagedAutoremoveMessageOperations.swift; sourceTree = "<group>"; };
@ -1480,6 +1483,7 @@
C23BC3861E9BE3CA00D79F92 /* ImportContact.swift */,
C205FEA71EB3B75900455808 /* ExportMessageLink.swift */,
C230BEB51EE9A3760029586C /* ChannelAdminEventLogs.swift */,
D0A472B51F4CBE8B00E0EEDA /* LoadedPeer.swift */,
);
name = Peers;
sourceTree = "<group>";
@ -1748,6 +1752,7 @@
D0B843B71DA7FF30005F29E1 /* NBMetadataCoreMapper.m in Sources */,
D0AB0B921D65E9FA002C78E7 /* ManagedServiceViews.swift in Sources */,
D0DB7F031F43030C00591D48 /* InstallInteractiveReadMessagesAction.swift in Sources */,
D0A472B61F4CBE8B00E0EEDA /* LoadedPeer.swift in Sources */,
D0AAD1B81E326FE200D5B9DE /* ManagedAutoremoveMessageOperations.swift in Sources */,
D01A21A91F38CDDC00DDA104 /* ManagedSynchronizeSavedStickersOperations.swift in Sources */,
D099EA1C1DE72867001AF5A8 /* PeerCommands.swift in Sources */,
@ -2133,6 +2138,7 @@
D001F3EF1E128A1C007A8C60 /* AccountIntermediateState.swift in Sources */,
D0223A991EA564BD00211D94 /* MediaResourceNetworkStatsTag.swift in Sources */,
D00C7CCD1E3620C30080C3D5 /* CachedChannelParticipants.swift in Sources */,
D0A472B71F4CBE8B00E0EEDA /* LoadedPeer.swift in Sources */,
D03C536E1DAD5CA9004C17B3 /* PhoneNumber.swift in Sources */,
D0BC387C1E40D2880044D6FE /* TogglePeerChatPinned.swift in Sources */,
D0528E6B1E65DD2100E2FEF5 /* WebpagePreview.swift in Sources */,

View File

@ -10,7 +10,7 @@ import Foundation
#endif
import TelegramCorePrivateModule
public protocol AccountState: Coding {
public protocol AccountState: PostboxCoding {
func equalsTo(_ other: AccountState) -> Bool
}
@ -19,7 +19,7 @@ public func ==(lhs: AccountState, rhs: AccountState) -> Bool {
}
public class AuthorizedAccountState: AccountState {
public final class State: Coding, Equatable, CustomStringConvertible {
public final class State: PostboxCoding, Equatable, CustomStringConvertible {
let pts: Int32
let qts: Int32
let date: Int32
@ -32,14 +32,14 @@ public class AuthorizedAccountState: AccountState {
self.seq = seq
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.pts = decoder.decodeInt32ForKey("pts", orElse: 0)
self.qts = decoder.decodeInt32ForKey("qts", orElse: 0)
self.date = decoder.decodeInt32ForKey("date", orElse: 0)
self.seq = decoder.decodeInt32ForKey("seq", orElse: 0)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.pts, forKey: "pts")
encoder.encodeInt32(self.qts, forKey: "qts")
encoder.encodeInt32(self.date, forKey: "date")
@ -56,13 +56,13 @@ public class AuthorizedAccountState: AccountState {
let state: State?
public required init(decoder: Decoder) {
public required init(decoder: PostboxDecoder) {
self.masterDatacenterId = decoder.decodeInt32ForKey("masterDatacenterId", orElse: 0)
self.peerId = PeerId(decoder.decodeInt64ForKey("peerId", orElse: 0))
self.state = decoder.decodeObjectForKey("state", decoder: { return State(decoder: $0) }) as? State
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.masterDatacenterId, forKey: "masterDatacenterId")
encoder.encodeInt64(self.peerId.toInt64(), forKey: "peerId")
if let state = self.state {

View File

@ -53,6 +53,7 @@ enum AccountStateMutationOperation {
case ReadInbox(MessageId)
case ReadOutbox(MessageId)
case ResetReadState(PeerId, MessageId.Namespace, MessageId.Id, MessageId.Id, MessageId.Id, Int32)
case ResetMessageTagSummary(PeerId, MessageId.Namespace, Int32, MessageHistoryTagNamespaceCountValidityRange)
case UpdateState(AuthorizedAccountState.State)
case UpdateChannelState(PeerId, ChannelState)
case UpdatePeerNotificationSettings(PeerId, PeerNotificationSettings)
@ -169,6 +170,10 @@ struct AccountMutableState {
self.addOperation(.ResetReadState(peerId, namespace, maxIncomingReadId, maxOutgoingReadId, maxKnownId, count))
}
mutating func resetMessageTagSummary(_ peerId: PeerId, namespace: MessageId.Namespace, count: Int32, range: MessageHistoryTagNamespaceCountValidityRange) {
self.addOperation(.ResetMessageTagSummary(peerId, namespace, count, range))
}
mutating func updateState(_ state: AuthorizedAccountState.State) {
self.addOperation(.UpdateState(state))
}
@ -313,6 +318,8 @@ struct AccountMutableState {
self.readInboxMaxIds[peerId] = MessageId(peerId: peerId, namespace: namespace, id: maxIncomingReadId)
}
}
case let .ResetMessageTagSummary(peerId, namespace, count, range):
break
}
self.operations.append(operation)

View File

@ -13,13 +13,13 @@ private enum SentAuthorizationCodeTypeValue: Int32 {
case flashCall = 3
}
public enum SentAuthorizationCodeType: Coding, Equatable {
public enum SentAuthorizationCodeType: PostboxCoding, Equatable {
case otherSession(length: Int32)
case sms(length: Int32)
case call(length: Int32)
case flashCall(pattern: String)
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("v", orElse: 0) {
case SentAuthorizationCodeTypeValue.otherSession.rawValue:
self = .otherSession(length: decoder.decodeInt32ForKey("l", orElse: 0))
@ -34,7 +34,7 @@ public enum SentAuthorizationCodeType: Coding, Equatable {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
switch self {
case let .otherSession(length):
encoder.encodeInt32(SentAuthorizationCodeTypeValue.otherSession.rawValue, forKey: "v")
@ -95,14 +95,14 @@ private enum UnauthorizedAccountStateContentsValue: Int32 {
case signUp = 5
}
public enum UnauthorizedAccountStateContents: Coding, Equatable {
public enum UnauthorizedAccountStateContents: PostboxCoding, Equatable {
case empty
case phoneEntry(countryCode: Int32, number: String)
case confirmationCodeEntry(number: String, type: SentAuthorizationCodeType, hash: String, timeout: Int32?, nextType: AuthorizationCodeNextType?)
case passwordEntry(hint: String, number: String?, code: String?)
case signUp(number: String, codeHash: String, code: String, firstName: String, lastName: String)
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("v", orElse: 0) {
case UnauthorizedAccountStateContentsValue.empty.rawValue:
self = .empty
@ -124,7 +124,7 @@ public enum UnauthorizedAccountStateContents: Coding, Equatable {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
switch self {
case .empty:
encoder.encodeInt32(UnauthorizedAccountStateContentsValue.empty.rawValue, forKey: "v")
@ -230,12 +230,12 @@ public final class UnauthorizedAccountState: AccountState {
self.contents = contents
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.masterDatacenterId = decoder.decodeInt32ForKey("dc", orElse: 0)
self.contents = decoder.decodeObjectForKey("c", decoder: { UnauthorizedAccountStateContents(decoder: $0) }) as! UnauthorizedAccountStateContents
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.masterDatacenterId, forKey: "dc")
encoder.encodeObject(self.contents, forKey: "c")
}

View File

@ -1154,7 +1154,7 @@ private func resolveMissingPeerCloudReadStates(account: Account, state: AccountM
var missingPeers: [PeerId: Api.InputPeer] = [:]
for peerId in state.initialState.peerIdsWithNewMessages {
if state.initialState.cloudReadStates[peerId] == nil && (peerId.namespace == Namespaces.Peer.CloudUser || peerId.namespace == Namespaces.Peer.CloudGroup) {
if state.initialState.cloudReadStates[peerId] == nil && (peerId.namespace == Namespaces.Peer.CloudUser || peerId.namespace == Namespaces.Peer.CloudGroup) {
if let peer = state.peers[peerId], let inputPeer = apiInputPeer(peer) {
missingPeers[peerId] = inputPeer
} else {
@ -1319,6 +1319,8 @@ private func pollChannel(_ account: Account, peer: Peer, state: AccountMutableSt
}
updatedState.resetReadState(peer.id, namespace: Namespaces.Message.Cloud, maxIncomingReadId: readInboxMaxId, maxOutgoingReadId: readOutboxMaxId, maxKnownId: topMessage, count: unreadCount)
updatedState.resetMessageTagSummary(peer.id, namespace: Namespaces.Message.Cloud, count: unreadMentionsCount, range: MessageHistoryTagNamespaceCountValidityRange(maxId: topMessage))
}
}
return (updatedState, difference != nil, apiTimeout)
@ -1423,7 +1425,7 @@ private func optimizedOperations(_ operations: [AccountStateMutationOperation])
var currentAddMessages: OptimizeAddMessagesState?
for operation in operations {
switch operation {
case .AddHole, .DeleteMessages, .DeleteMessagesWithGlobalIds, .EditMessage, .UpdateMedia, .MergeApiChats, .MergeApiUsers, .MergePeerPresences, .UpdatePeer, .ReadInbox, .ReadOutbox, .ResetReadState, .UpdatePeerNotificationSettings, .UpdateSecretChat, .AddSecretMessages, .ReadSecretOutbox, .AddPeerInputActivity, .UpdateCachedPeerData, .UpdatePinnedPeerIds, .ReadMessageContents, .UpdateMessageImpressionCount, .UpdateInstalledStickerPacks, .UpdateChatInputState, .UpdateCall, .UpdateLangPack:
case .AddHole, .DeleteMessages, .DeleteMessagesWithGlobalIds, .EditMessage, .UpdateMedia, .MergeApiChats, .MergeApiUsers, .MergePeerPresences, .UpdatePeer, .ReadInbox, .ReadOutbox, .ResetReadState, .ResetMessageTagSummary, .UpdatePeerNotificationSettings, .UpdateSecretChat, .AddSecretMessages, .ReadSecretOutbox, .AddPeerInputActivity, .UpdateCachedPeerData, .UpdatePinnedPeerIds, .ReadMessageContents, .UpdateMessageImpressionCount, .UpdateInstalledStickerPacks, .UpdateChatInputState, .UpdateCall, .UpdateLangPack:
if let currentAddMessages = currentAddMessages, !currentAddMessages.messages.isEmpty {
result.append(.AddMessages(currentAddMessages.messages, currentAddMessages.location))
}
@ -1509,6 +1511,8 @@ func replayFinalState(accountPeerId: PeerId, mediaBox: MediaBox, modifier: Modif
modifier.applyOutgoingReadMaxId(messageId)
case let .ResetReadState(peerId, namespace, maxIncomingReadId, maxOutgoingReadId, maxKnownId, count):
modifier.resetIncomingReadStates([peerId: [namespace: .idBased(maxIncomingReadId: maxIncomingReadId, maxOutgoingReadId: maxOutgoingReadId, maxKnownId: maxKnownId, count: count)]])
case let .ResetMessageTagSummary(peerId, namespace, count, range):
modifier.replaceMessageTagSummary(peerId: peerId, tagMask: .unseenPersonalMessage, namespace: namespace, count: count, maxId: range.maxId)
case let .UpdateState(state):
let currentState = modifier.getState() as! AuthorizedAccountState
modifier.setState(currentState.changedState(state))

View File

@ -32,11 +32,11 @@ public final class ArchivedStickerPacksInfo: OrderedItemListEntryContents {
self.count = count
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.count = decoder.decodeInt32ForKey("c", orElse: 0)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.count, forKey: "c")
}
}

View File

@ -14,11 +14,11 @@ public class AuthorSignatureMessageAttribute: MessageAttribute {
self.signature = signature
}
required public init(decoder: Decoder) {
required public init(decoder: PostboxDecoder) {
self.signature = decoder.decodeStringForKey("s", orElse: "")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.signature, forKey: "s")
}
}

View File

@ -20,12 +20,12 @@ public class AutoremoveTimeoutMessageAttribute: MessageAttribute {
self.countdownBeginTime = countdownBeginTime
}
required public init(decoder: Decoder) {
required public init(decoder: PostboxDecoder) {
self.timeout = decoder.decodeInt32ForKey("t", orElse: 0)
self.countdownBeginTime = decoder.decodeOptionalInt32ForKey("c")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.timeout, forKey: "t")
if let countdownBeginTime = self.countdownBeginTime {
encoder.encodeInt32(countdownBeginTime, forKey: "c")

View File

@ -5,7 +5,7 @@ import Foundation
import Postbox
#endif
public struct BotCommand: Coding, Equatable {
public struct BotCommand: PostboxCoding, Equatable {
public let text: String
public let description: String
@ -14,12 +14,12 @@ public struct BotCommand: Coding, Equatable {
self.description = description
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.text = decoder.decodeStringForKey("t", orElse: "")
self.description = decoder.decodeStringForKey("d", orElse: "")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.text, forKey: "t")
encoder.encodeString(self.description, forKey: "d")
}
@ -29,7 +29,7 @@ public struct BotCommand: Coding, Equatable {
}
}
public final class BotInfo: Coding, Equatable {
public final class BotInfo: PostboxCoding, Equatable {
public let description: String
public let commands: [BotCommand]
@ -38,12 +38,12 @@ public final class BotInfo: Coding, Equatable {
self.commands = commands
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.description = decoder.decodeStringForKey("d", orElse: "")
self.commands = decoder.decodeObjectArrayWithDecoderForKey("c")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.description, forKey: "d")
encoder.encodeObjectArray(self.commands, forKey: "c")
}

View File

@ -18,11 +18,11 @@ public struct CacheStorageSettings: PreferencesEntry, Equatable {
self.defaultCacheStorageTimeout = defaultCacheStorageTimeout
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.defaultCacheStorageTimeout = decoder.decodeInt32ForKey("dt", orElse: 0)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.defaultCacheStorageTimeout, forKey: "dt")
}

View File

@ -21,7 +21,7 @@ public struct CachedChannelFlags: OptionSet {
public static let canSetStickerSet = CachedChannelFlags(rawValue: 1 << 2)
}
public struct CachedChannelParticipantsSummary: Coding, Equatable {
public struct CachedChannelParticipantsSummary: PostboxCoding, Equatable {
public let memberCount: Int32?
public let adminCount: Int32?
public let bannedCount: Int32?
@ -34,7 +34,7 @@ public struct CachedChannelParticipantsSummary: Coding, Equatable {
self.kickedCount = kickedCount
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
if let memberCount = decoder.decodeOptionalInt32ForKey("p.m") {
self.memberCount = memberCount
} else {
@ -57,7 +57,7 @@ public struct CachedChannelParticipantsSummary: Coding, Equatable {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
if let memberCount = self.memberCount {
encoder.encodeInt32(memberCount, forKey: "p.m")
} else {
@ -186,7 +186,7 @@ public final class CachedChannelData: CachedPeerData {
return CachedChannelData(flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, topParticipants: self.topParticipants, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, stickerPack: stickerPack)
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.flags = CachedChannelFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0))
self.about = decoder.decodeOptionalStringForKey("a")
self.participantsSummary = CachedChannelParticipantsSummary(decoder: decoder)
@ -219,7 +219,7 @@ public final class CachedChannelData: CachedPeerData {
self.peerIds = peerIds
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.flags.rawValue, forKey: "f")
if let about = self.about {
encoder.encodeString(about, forKey: "a")

View File

@ -12,7 +12,7 @@ private enum ChannelParticipantValue: Int32 {
case moderator = 3
}
public struct ChannelParticipantAdminInfo: Coding, Equatable {
public struct ChannelParticipantAdminInfo: PostboxCoding, Equatable {
public let rights: TelegramChannelAdminRights
public let promotedBy: PeerId
public let canBeEditedByAccountPeer: Bool
@ -23,13 +23,13 @@ public struct ChannelParticipantAdminInfo: Coding, Equatable {
self.canBeEditedByAccountPeer = canBeEditedByAccountPeer
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.rights = decoder.decodeObjectForKey("r", decoder: { TelegramChannelAdminRights(decoder: $0) }) as! TelegramChannelAdminRights
self.promotedBy = PeerId(decoder.decodeInt64ForKey("p", orElse: 0))
self.canBeEditedByAccountPeer = decoder.decodeInt32ForKey("e", orElse: 0) != 0
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeObject(self.rights, forKey: "r")
encoder.encodeInt64(self.promotedBy.toInt64(), forKey: "p")
encoder.encodeInt32(self.canBeEditedByAccountPeer ? 1 : 0, forKey: "e")
@ -40,7 +40,7 @@ public struct ChannelParticipantAdminInfo: Coding, Equatable {
}
}
public struct ChannelParticipantBannedInfo: Coding, Equatable {
public struct ChannelParticipantBannedInfo: PostboxCoding, Equatable {
public let rights: TelegramChannelBannedRights
public let restrictedBy: PeerId
public let isMember: Bool
@ -51,13 +51,13 @@ public struct ChannelParticipantBannedInfo: Coding, Equatable {
self.isMember = isMember
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.rights = decoder.decodeObjectForKey("r", decoder: { TelegramChannelBannedRights(decoder: $0) }) as! TelegramChannelBannedRights
self.restrictedBy = PeerId(decoder.decodeInt64ForKey("p", orElse: 0))
self.isMember = decoder.decodeInt32ForKey("m", orElse: 0) != 0
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeObject(self.rights, forKey: "r")
encoder.encodeInt64(self.restrictedBy.toInt64(), forKey: "p")
encoder.encodeInt32(self.isMember ? 1 : 0, forKey: "m")
@ -68,7 +68,7 @@ public struct ChannelParticipantBannedInfo: Coding, Equatable {
}
}
public enum ChannelParticipant: Coding, Equatable {
public enum ChannelParticipant: PostboxCoding, Equatable {
case creator(id: PeerId)
case member(id: PeerId, invitedAt: Int32, adminInfo: ChannelParticipantAdminInfo?, banInfo: ChannelParticipantBannedInfo?)
@ -110,7 +110,7 @@ public enum ChannelParticipant: Coding, Equatable {
}
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("r", orElse: 0) {
case ChannelParticipantValue.member.rawValue:
self = .member(id: PeerId(decoder.decodeInt64ForKey("i", orElse: 0)), invitedAt: decoder.decodeInt32ForKey("t", orElse: 0), adminInfo: decoder.decodeObjectForKey("ai", decoder: { ChannelParticipantAdminInfo(decoder: $0) }) as? ChannelParticipantAdminInfo, banInfo: decoder.decodeObjectForKey("bi", decoder: { ChannelParticipantBannedInfo(decoder: $0) }) as? ChannelParticipantBannedInfo)
@ -121,7 +121,7 @@ public enum ChannelParticipant: Coding, Equatable {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
switch self {
case let .member(id, invitedAt, adminInfo, banInfo):
encoder.encodeInt32(ChannelParticipantValue.member.rawValue, forKey: "r")
@ -144,18 +144,18 @@ public enum ChannelParticipant: Coding, Equatable {
}
}
public final class CachedChannelParticipants: Coding, Equatable {
public final class CachedChannelParticipants: PostboxCoding, Equatable {
public let participants: [ChannelParticipant]
init(participants: [ChannelParticipant]) {
self.participants = participants
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.participants = decoder.decodeObjectArrayWithDecoderForKey("p")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeObjectArray(self.participants, forKey: "p")
}

View File

@ -5,7 +5,7 @@ import Foundation
import Postbox
#endif
public final class CachedPeerBotInfo: Coding, Equatable {
public final class CachedPeerBotInfo: PostboxCoding, Equatable {
public let peerId: PeerId
public let botInfo: BotInfo
@ -14,12 +14,12 @@ public final class CachedPeerBotInfo: Coding, Equatable {
self.botInfo = botInfo
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.peerId = PeerId(decoder.decodeInt64ForKey("p", orElse: 0))
self.botInfo = decoder.decodeObjectForKey("i", decoder: { return BotInfo(decoder: $0) }) as! BotInfo
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.peerId.toInt64(), forKey: "p")
encoder.encodeObject(self.botInfo, forKey: "i")
}
@ -63,7 +63,7 @@ public final class CachedGroupData: CachedPeerData {
self.peerIds = peerIds
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
let participants = decoder.decodeObjectForKey("p", decoder: { CachedGroupParticipants(decoder: $0) }) as? CachedGroupParticipants
self.participants = participants
self.exportedInvitation = decoder.decodeObjectForKey("i", decoder: { ExportedInvitation(decoder: $0) }) as? ExportedInvitation
@ -83,7 +83,7 @@ public final class CachedGroupData: CachedPeerData {
self.peerIds = peerIds
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
if let participants = self.participants {
encoder.encodeObject(participants, forKey: "p")
} else {

View File

@ -5,7 +5,7 @@ import Foundation
import Postbox
#endif
public enum GroupParticipant: Coding, Equatable {
public enum GroupParticipant: PostboxCoding, Equatable {
case member(id: PeerId, invitedBy: PeerId, invitedAt: Int32)
case creator(id: PeerId)
case admin(id: PeerId, invitedBy: PeerId, invitedAt: Int32)
@ -21,7 +21,7 @@ public enum GroupParticipant: Coding, Equatable {
}
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("v", orElse: 0) {
case 0:
self = .member(id: PeerId(decoder.decodeInt64ForKey("i", orElse: 0)), invitedBy: PeerId(decoder.decodeInt64ForKey("b", orElse: 0)), invitedAt: decoder.decodeInt32ForKey("t", orElse: 0))
@ -34,7 +34,7 @@ public enum GroupParticipant: Coding, Equatable {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
switch self {
case let .member(id, invitedBy, invitedAt):
encoder.encodeInt32(0, forKey: "v")
@ -87,7 +87,7 @@ public enum GroupParticipant: Coding, Equatable {
}
}
public final class CachedGroupParticipants: Coding, Equatable {
public final class CachedGroupParticipants: PostboxCoding, Equatable {
public let participants: [GroupParticipant]
let version: Int32
@ -96,12 +96,12 @@ public final class CachedGroupParticipants: Coding, Equatable {
self.version = version
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.participants = decoder.decodeObjectArrayWithDecoderForKey("p")
self.version = decoder.decodeInt32ForKey("v", orElse: 0)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeObjectArray(self.participants, forKey: "p")
encoder.encodeInt32(self.version, forKey: "v")
}

View File

@ -7,7 +7,7 @@ import Foundation
import SwiftSignalKit
#endif
private final class CachedStickerPack: Coding {
private final class CachedStickerPack: PostboxCoding {
let items: [StickerPackItem]
let hash: Int32
@ -16,12 +16,12 @@ private final class CachedStickerPack: Coding {
self.hash = hash
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.items = decoder.decodeObjectArrayForKey("it").map { $0 as! StickerPackItem }
self.hash = decoder.decodeInt32ForKey("h", orElse: 0)
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeObjectArray(self.items, forKey: "it")
encoder.encodeInt32(self.hash, forKey: "h")
}

View File

@ -30,7 +30,7 @@ public final class CachedUserData: CachedPeerData {
self.commonGroupCount = commonGroupCount
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.about = decoder.decodeOptionalStringForKey("a")
self.botInfo = decoder.decodeObjectForKey("bi") as? BotInfo
self.reportStatus = PeerReportStatus(rawValue: decoder.decodeInt32ForKey("r", orElse: 0))!
@ -38,7 +38,7 @@ public final class CachedUserData: CachedPeerData {
self.commonGroupCount = decoder.decodeInt32ForKey("cg", orElse: 0)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
if let about = self.about {
encoder.encodeString(about, forKey: "a")
} else {

View File

@ -1,4 +1,3 @@
#if os(macOS)
import PostboxMac
import SwiftSignalKitMac
@ -7,7 +6,6 @@
import SwiftSignalKit
#endif
public typealias AdminLogEventId = Int64
public struct AdminLogEvent {

View File

@ -12,11 +12,11 @@ public class ChannelMessageStateVersionAttribute: MessageAttribute {
self.pts = pts
}
required public init(decoder: Decoder) {
required public init(decoder: PostboxDecoder) {
self.pts = decoder.decodeInt32ForKey("p", orElse: 0)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.pts, forKey: "p")
}
}

View File

@ -14,12 +14,12 @@ final class ChannelState: PeerChatState, Equatable, CustomStringConvertible {
self.invalidatedPts = invalidatedPts
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.pts = decoder.decodeInt32ForKey("pts", orElse: 0)
self.invalidatedPts = decoder.decodeOptionalInt32ForKey("ipts")
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.pts, forKey: "pts")
if let invalidatedPts = self.invalidatedPts {
encoder.encodeInt32(invalidatedPts, forKey: "ipts")

View File

@ -9,13 +9,13 @@ import Foundation
import MtProtoKitDynamic
#endif
public enum ChatContextResultMessage: Coding, Equatable {
public enum ChatContextResultMessage: PostboxCoding, Equatable {
case auto(caption: String, replyMarkup: ReplyMarkupMessageAttribute?)
case text(text: String, entities: TextEntitiesMessageAttribute?, disableUrlPreview: Bool, replyMarkup: ReplyMarkupMessageAttribute?)
case mapLocation(media: TelegramMediaMap, replyMarkup: ReplyMarkupMessageAttribute?)
case contact(media: TelegramMediaContact, replyMarkup: ReplyMarkupMessageAttribute?)
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("_v", orElse: 0) {
case 0:
self = .auto(caption: decoder.decodeStringForKey("c", orElse: ""), replyMarkup: decoder.decodeObjectForKey("m") as? ReplyMarkupMessageAttribute)
@ -30,7 +30,7 @@ public enum ChatContextResultMessage: Coding, Equatable {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
switch self {
case let .auto(caption, replyMarkup):
encoder.encodeInt32(0, forKey: "_v")

View File

@ -21,7 +21,7 @@ extension CloudChatRemoveMessagesType {
}
}
final class CloudChatRemoveMessagesOperation: Coding {
final class CloudChatRemoveMessagesOperation: PostboxCoding {
let messageIds: [MessageId]
let type: CloudChatRemoveMessagesType
@ -30,12 +30,12 @@ final class CloudChatRemoveMessagesOperation: Coding {
self.type = type
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.messageIds = MessageId.decodeArrayFromBuffer(decoder.decodeBytesForKeyNoCopy("i")!)
self.type = CloudChatRemoveMessagesType(rawValue: decoder.decodeInt32ForKey("t", orElse: 0))!
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
let buffer = WriteBuffer()
MessageId.encodeArrayToBuffer(self.messageIds, buffer: buffer)
encoder.encodeBytes(buffer, forKey: "i")
@ -43,7 +43,7 @@ final class CloudChatRemoveMessagesOperation: Coding {
}
}
final class CloudChatRemoveChatOperation: Coding {
final class CloudChatRemoveChatOperation: PostboxCoding {
let peerId: PeerId
let reportChatSpam: Bool
let topMessageId: MessageId?
@ -54,7 +54,7 @@ final class CloudChatRemoveChatOperation: Coding {
self.topMessageId = topMessageId
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.peerId = PeerId(decoder.decodeInt64ForKey("p", orElse: 0))
self.reportChatSpam = decoder.decodeInt32ForKey("r", orElse: 0) != 0
if let messageIdPeerId = decoder.decodeOptionalInt64ForKey("m.p"), let messageIdNamespace = decoder.decodeOptionalInt32ForKey("m.n"), let messageIdId = decoder.decodeOptionalInt32ForKey("m.i") {
@ -64,7 +64,7 @@ final class CloudChatRemoveChatOperation: Coding {
}
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.peerId.toInt64(), forKey: "p")
encoder.encodeInt32(self.reportChatSpam ? 1 : 0, forKey: "r")
if let topMessageId = self.topMessageId {
@ -79,7 +79,7 @@ final class CloudChatRemoveChatOperation: Coding {
}
}
final class CloudChatClearHistoryOperation: Coding {
final class CloudChatClearHistoryOperation: PostboxCoding {
let peerId: PeerId
let topMessageId: MessageId
@ -88,12 +88,12 @@ final class CloudChatClearHistoryOperation: Coding {
self.topMessageId = topMessageId
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.peerId = PeerId(decoder.decodeInt64ForKey("p", orElse: 0))
self.topMessageId = MessageId(peerId: PeerId(decoder.decodeInt64ForKey("m.p", orElse: 0)), namespace: decoder.decodeInt32ForKey("m.n", orElse: 0), id: decoder.decodeInt32ForKey("m.i", orElse: 0))
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.peerId.toInt64(), forKey: "p")
encoder.encodeInt64(self.topMessageId.peerId.toInt64(), forKey: "m.p")
encoder.encodeInt32(self.topMessageId.namespace, forKey: "m.n")

View File

@ -66,7 +66,7 @@ public class CloudFileMediaResource: TelegramCloudMediaResource, TelegramMultipa
self.size = size
}
public required init(decoder: Decoder) {
public required init(decoder: PostboxDecoder) {
self.datacenterId = Int(decoder.decodeInt32ForKey("d", orElse: 0))
self.volumeId = decoder.decodeInt64ForKey("v", orElse: 0)
self.localId = decoder.decodeInt32ForKey("l", orElse: 0)
@ -78,7 +78,7 @@ public class CloudFileMediaResource: TelegramCloudMediaResource, TelegramMultipa
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(Int32(self.datacenterId), forKey: "d")
encoder.encodeInt64(self.volumeId, forKey: "v")
encoder.encodeInt32(self.localId, forKey: "l")
@ -148,7 +148,7 @@ public class CloudDocumentMediaResource: TelegramCloudMediaResource, TelegramMul
self.size = size
}
public required init(decoder: Decoder) {
public required init(decoder: PostboxDecoder) {
self.datacenterId = Int(decoder.decodeInt32ForKey("d", orElse: 0))
self.fileId = decoder.decodeInt64ForKey("f", orElse: 0)
self.accessHash = decoder.decodeInt64ForKey("a", orElse: 0)
@ -159,7 +159,7 @@ public class CloudDocumentMediaResource: TelegramCloudMediaResource, TelegramMul
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(Int32(self.datacenterId), forKey: "d")
encoder.encodeInt64(self.fileId, forKey: "f")
encoder.encodeInt64(self.accessHash, forKey: "a")
@ -206,11 +206,11 @@ public class LocalFileMediaResource: TelegramMediaResource {
self.fileId = fileId
}
public required init(decoder: Decoder) {
public required init(decoder: PostboxDecoder) {
self.fileId = decoder.decodeInt64ForKey("f", orElse: 0)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.fileId, forKey: "f")
}
@ -260,14 +260,14 @@ public class LocalFileReferenceMediaResource: TelegramMediaResource {
self.size = size
}
public required init(decoder: Decoder) {
public required init(decoder: PostboxDecoder) {
self.localFilePath = decoder.decodeStringForKey("p", orElse: "")
self.randomId = decoder.decodeInt64ForKey("r", orElse: 0)
self.isUniquelyReferencedTemporaryFile = decoder.decodeInt32ForKey("t", orElse: 0) != 0
self.size = decoder.decodeOptionalInt32ForKey("s")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.localFilePath, forKey: "p")
encoder.encodeInt64(self.randomId, forKey: "r")
encoder.encodeInt32(self.isUniquelyReferencedTemporaryFile ? 1 : 0, forKey: "t")
@ -320,7 +320,7 @@ public final class HttpReferenceMediaResource: TelegramMediaResource {
self.size = size
}
public required init(decoder: Decoder) {
public required init(decoder: PostboxDecoder) {
self.url = decoder.decodeStringForKey("u", orElse: "")
if let size = decoder.decodeOptionalInt32ForKey("s") {
self.size = Int(size)
@ -329,7 +329,7 @@ public final class HttpReferenceMediaResource: TelegramMediaResource {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.url, forKey: "u")
if let size = self.size {
encoder.encodeInt32(Int32(size), forKey: "s")
@ -393,14 +393,14 @@ public final class WebFileReferenceMediaResource: TelegramMediaResource, Telegra
return Api.InputWebFileLocation.inputWebFileLocation(url: url, accessHash: accessHash)
}
public required init(decoder: Decoder) {
public required init(decoder: PostboxDecoder) {
self.url = decoder.decodeStringForKey("u", orElse: "")
self.size = decoder.decodeInt32ForKey("s", orElse: 0)
self._datacenterId = decoder.decodeInt32ForKey("d", orElse: 0)
self.accessHash = decoder.decodeInt64ForKey("h", orElse: 0)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.url, forKey: "u")
encoder.encodeInt32(self.size, forKey: "s")
encoder.encodeInt32(self._datacenterId, forKey: "d")
@ -468,7 +468,7 @@ public struct SecretFileMediaResource: TelegramCloudMediaResource, TelegramMulti
self.key = key
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.fileId = decoder.decodeInt64ForKey("i", orElse: 0)
self.accessHash = decoder.decodeInt64ForKey("a", orElse: 0)
if let size = decoder.decodeOptionalInt32ForKey("s") {
@ -481,7 +481,7 @@ public struct SecretFileMediaResource: TelegramCloudMediaResource, TelegramMulti
self.key = decoder.decodeObjectForKey("k", decoder: { SecretFileEncryptionKey(decoder: $0) }) as! SecretFileEncryptionKey
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.fileId, forKey: "i")
encoder.encodeInt64(self.accessHash, forKey: "a")
if let size = self.size {
@ -543,10 +543,10 @@ public final class EmptyMediaResource: TelegramMediaResource {
public init() {
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
}
public var id: MediaResourceId {

View File

@ -12,11 +12,11 @@ public class ConsumableContentMessageAttribute: MessageAttribute {
self.consumed = consumed
}
required public init(decoder: Decoder) {
required public init(decoder: PostboxDecoder) {
self.consumed = decoder.decodeInt32ForKey("c", orElse: 0) != 0
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.consumed ? 1 : 0, forKey: "c")
}
}

View File

@ -14,12 +14,12 @@ public class ConsumablePersonalMentionMessageAttribute: MessageAttribute {
self.pending = pending
}
required public init(decoder: Decoder) {
required public init(decoder: PostboxDecoder) {
self.consumed = decoder.decodeInt32ForKey("c", orElse: 0) != 0
self.pending = decoder.decodeInt32ForKey("p", orElse: 0) != 0
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.consumed ? 1 : 0, forKey: "c")
encoder.encodeInt32(self.pending ? 1 : 0, forKey: "p")
}

View File

@ -11,10 +11,10 @@ final class ConsumePersonalMessageAction: PendingMessageActionData {
init() {
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
}
func isEqual(to: PendingMessageActionData) -> Bool {

View File

@ -9,29 +9,81 @@ import Foundation
import MtProtoKitDynamic
#endif
public func earliestUnseenPersonalMentionMessage(postbox: Postbox, peerId: PeerId) -> Signal<MessageId?, NoError> {
return postbox.modify { modifier -> Signal<MessageId?, NoError> in
var resultMessageId: MessageId?
public enum EarliestUnseenPersonalMentionMessageResult {
case loading
case result(MessageId?)
}
public func earliestUnseenPersonalMentionMessage(postbox: Postbox, network: Network, peerId: PeerId) -> Signal<EarliestUnseenPersonalMentionMessageResult, NoError> {
return earliestUnseenPersonalMentionMessage(postbox: postbox, network: network, peerId: peerId, locally: false)
}
private func earliestUnseenPersonalMentionMessage(postbox: Postbox, network: Network, peerId: PeerId, locally: Bool) -> Signal<EarliestUnseenPersonalMentionMessageResult, NoError> {
return postbox.modify { modifier -> Signal<EarliestUnseenPersonalMentionMessageResult, NoError> in
var resultMessage: Message?
var resultHole: MessageHistoryHole?
modifier.scanMessages(peerId: peerId, tagMask: .unseenPersonalMessage, { entry in
switch entry {
case let .message(message):
for attribute in message.attributes {
if let attribute = attribute as? ConsumablePersonalMentionMessageAttribute, !attribute.pending {
resultMessageId = message.id
resultMessage = message
return false
}
}
break
case let .hole(hole):
break
resultHole = hole
return false
}
return true
})
if let resultMessageId = resultMessageId {
return .single(resultMessageId)
if let resultMessage = resultMessage {
var invalidateHistoryPts: Int32?
if peerId.namespace == Namespaces.Peer.CloudChannel {
if let channelState = modifier.getPeerChatState(peerId) as? ChannelState {
if let invalidatedPts = channelState.invalidatedPts {
var messagePts: Int32?
for attribute in resultMessage.attributes {
if let attribute = attribute as? ChannelMessageStateVersionAttribute {
messagePts = attribute.pts
break
}
}
if let messagePts = messagePts {
if messagePts < invalidatedPts {
invalidateHistoryPts = invalidatedPts
}
} else {
invalidateHistoryPts = invalidatedPts
}
}
}
}
if !locally, let _ = invalidateHistoryPts {
let validateSignal = fetchMessageHistoryHole(network: network, postbox: postbox, hole: MessageHistoryHole(stableId: UInt32.max, maxIndex: MessageIndex.upperBound(peerId: peerId), min: resultMessage.id.id - 1, tags: 0), direction: .LowerToUpper, tagMask: .unseenPersonalMessage)
|> mapToSignal { _ -> Signal<EarliestUnseenPersonalMentionMessageResult, NoError> in
return .complete()
}
|> then(earliestUnseenPersonalMentionMessage(postbox: postbox, network: network, peerId: peerId, locally: true))
return .single(.loading) |> then(validateSignal)
} else {
return .single(.result(resultMessage.id))
}
} else if let resultHole = resultHole, !locally {
let validateSignal = fetchMessageHistoryHole(network: network, postbox: postbox, hole: resultHole, direction: .LowerToUpper, tagMask: .unseenPersonalMessage)
|> mapToSignal { _ -> Signal<EarliestUnseenPersonalMentionMessageResult, NoError> in
return .complete()
}
|> then(earliestUnseenPersonalMentionMessage(postbox: postbox, network: network, peerId: peerId, locally: true))
return .single(.loading) |> then(validateSignal)
} else if let summary = modifier.getMessageTagSummary(peerId: peerId, tagMask: .unseenPersonalMessage, namespace: Namespaces.Message.Cloud), summary.count > 0 {
modifier.replaceMessageTagSummary(peerId: peerId, tagMask: .unseenPersonalMessage, namespace: Namespaces.Message.Cloud, count: 0, maxId: summary.range.maxId)
}
return .single(nil)
return .single(.result(nil))
} |> switchToLatest
}

View File

@ -12,11 +12,11 @@ public class EditedMessageAttribute: MessageAttribute {
self.date = date
}
required public init(decoder: Decoder) {
required public init(decoder: PostboxDecoder) {
self.date = decoder.decodeInt32ForKey("d", orElse: 0)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.date, forKey: "d")
}
}

View File

@ -5,18 +5,18 @@ import Foundation
import Postbox
#endif
public struct ExportedInvitation: Coding, Equatable {
public struct ExportedInvitation: PostboxCoding, Equatable {
public let link: String
init(link: String) {
self.link = link
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.link = decoder.decodeStringForKey("l", orElse: "")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.link, forKey: "l")
}

View File

@ -36,13 +36,13 @@ public final class FeaturedStickerPackItem: OrderedItemListEntryContents {
self.unread = unread
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.info = decoder.decodeObjectForKey("i") as! StickerPackCollectionInfo
self.topItems = decoder.decodeObjectArrayForKey("t")
self.unread = decoder.decodeInt32ForKey("u", orElse: 0) != 0
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeObject(self.info, forKey: "i")
encoder.encodeObjectArray(self.topItems, forKey: "t")
encoder.encodeInt32(self.unread ? 1 : 0, forKey: "u")

View File

@ -12,11 +12,11 @@ public class ForwardSourceInfoAttribute: MessageAttribute {
self.messageId = messageId
}
required public init(decoder: Decoder) {
required public init(decoder: PostboxDecoder) {
self.messageId = MessageId(peerId: PeerId(decoder.decodeInt64ForKey("p", orElse: 0)), namespace: decoder.decodeInt32ForKey("n", orElse: 0), id: decoder.decodeInt32ForKey("i", orElse: 0))
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.messageId.peerId.toInt64(), forKey: "p")
encoder.encodeInt32(self.messageId.namespace, forKey: "n")
encoder.encodeInt32(self.messageId.id, forKey: "i")

View File

@ -5,7 +5,7 @@ import Foundation
import Postbox
#endif
public struct MessageNotificationSettings: Coding, Equatable {
public struct MessageNotificationSettings: PostboxCoding, Equatable {
public let enabled: Bool
public let displayPreviews: Bool
public let sound: PeerMessageSound
@ -20,13 +20,13 @@ public struct MessageNotificationSettings: Coding, Equatable {
self.sound = sound
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.enabled = decoder.decodeInt32ForKey("e", orElse: 0) != 0
self.displayPreviews = decoder.decodeInt32ForKey("p", orElse: 0) != 0
self.sound = PeerMessageSound.decodeInline(decoder)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.enabled ? 1 : 0, forKey: "e")
encoder.encodeInt32(self.displayPreviews ? 1 : 0, forKey: "p")
self.sound.encodeInline(encoder)
@ -58,7 +58,7 @@ public struct MessageNotificationSettings: Coding, Equatable {
}
}
public struct GlobalNotificationSettingsSet: Coding, Equatable {
public struct GlobalNotificationSettingsSet: PostboxCoding, Equatable {
public let privateChats: MessageNotificationSettings
public let groupChats: MessageNotificationSettings
@ -71,12 +71,12 @@ public struct GlobalNotificationSettingsSet: Coding, Equatable {
self.groupChats = groupChats
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.privateChats = decoder.decodeObjectForKey("p", decoder: { MessageNotificationSettings(decoder: $0) }) as! MessageNotificationSettings
self.groupChats = decoder.decodeObjectForKey("g", decoder: { MessageNotificationSettings(decoder: $0) }) as! MessageNotificationSettings
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeObject(self.privateChats, forKey: "p")
encoder.encodeObject(self.groupChats, forKey: "g")
}
@ -117,12 +117,12 @@ public struct GlobalNotificationSettings: PreferencesEntry, Equatable {
self.remote = remote
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.toBeSynchronized = decoder.decodeObjectForKey("s", decoder: { GlobalNotificationSettingsSet(decoder: $0) }) as? GlobalNotificationSettingsSet
self.remote = decoder.decodeObjectForKey("r", decoder: { GlobalNotificationSettingsSet(decoder: $0) }) as! GlobalNotificationSettingsSet
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
if let toBeSynchronized = self.toBeSynchronized {
encoder.encodeObject(toBeSynchronized, forKey: "s")
} else {

View File

@ -31,10 +31,10 @@ func fetchMessageHistoryHole(network: Network, postbox: Postbox, hole: MessageHi
//|> delay(4.0, queue: Queue.concurrentDefaultQueue())
|> mapToSignal { peer in
if let inputPeer = apiInputPeer(peer) {
let limit = 100
let limit = 20
let request: Signal<Api.messages.Messages, MTRpcError>
if let tagMask = tagMask, let filter = messageFilterForTagMask(tagMask) {
if let tagMask = tagMask {
if tagMask == MessageTags.unseenPersonalMessage {
let offsetId: Int32
let addOffset: Int32
@ -60,7 +60,7 @@ func fetchMessageHistoryHole(network: Network, postbox: Postbox, hole: MessageHi
minId = 1
}
request = network.request(Api.functions.messages.getUnreadMentions(peer: inputPeer, offsetId: offsetId, addOffset: addOffset, limit: Int32(selectedLimit), maxId: maxId, minId: minId))
} else {
} else if let filter = messageFilterForTagMask(tagMask) {
let offsetId: Int32
let addOffset: Int32
let selectedLimit = limit
@ -86,6 +86,9 @@ func fetchMessageHistoryHole(network: Network, postbox: Postbox, hole: MessageHi
}
request = network.request(Api.functions.messages.search(flags: 0, peer: inputPeer, q: "", fromId: nil, filter: filter, minDate: 0, maxDate: hole.maxIndex.timestamp, offsetId: offsetId, addOffset: addOffset, limit: Int32(selectedLimit), maxId: maxId, minId: minId))
} else {
assertionFailure()
request = .never()
}
} else {
let offsetId: Int32
@ -269,7 +272,7 @@ func fetchChatListHole(network: Network, postbox: Postbox, hole: ChatListHole) -
}
readStates[peerId]![Namespaces.Message.Cloud] = .idBased(maxIncomingReadId: apiReadInboxMaxId, maxOutgoingReadId: apiReadOutboxMaxId, maxKnownId: apiTopMessage, count: apiUnreadCount)
if apiUnreadMentionsCount != 0 && apiTopMessage != 0 {
if apiTopMessage != 0 {
mentionTagSummaries[peerId] = MessageHistoryTagNamespaceSummary(version: 1, count: apiUnreadMentionsCount, range: MessageHistoryTagNamespaceCountValidityRange(maxId: apiTopMessage))
}
@ -331,8 +334,8 @@ func fetchChatListHole(network: Network, postbox: Postbox, hole: ChatListHole) -
}
readStates[peerId]![Namespaces.Message.Cloud] = .idBased(maxIncomingReadId: apiReadInboxMaxId, maxOutgoingReadId: apiReadOutboxMaxId, maxKnownId: apiTopMessage, count: apiUnreadCount)
if apiUnreadMentionsCount != 0 && apiTopMessage != 0 {
mentionTagSummaries[peerId] = MessageHistoryTagNamespaceSummary(version: 1, count: apiUnreadMentionsCount, range: MessageHistoryTagNamespaceCountValidityRange(maxId: apiTopMessage))
if apiTopMessage != 0 {
mentionTagSummaries[peerId] = MessageHistoryTagNamespaceSummary(version: 1, count: 0, range: MessageHistoryTagNamespaceCountValidityRange(maxId: apiTopMessage))
}
notificationSettings[peerId] = TelegramPeerNotificationSettings(apiSettings: apiNotificationSettings)
@ -403,7 +406,7 @@ func fetchChatListHole(network: Network, postbox: Postbox, hole: ChatListHole) -
}
readStates[peerId]![Namespaces.Message.Cloud] = .idBased(maxIncomingReadId: apiReadInboxMaxId, maxOutgoingReadId: apiReadOutboxMaxId, maxKnownId: apiTopMessage, count: apiUnreadCount)
if apiUnreadMentionsCount != 0 && apiTopMessage != 0 {
if apiTopMessage != 0 {
mentionTagSummaries[peerId] = MessageHistoryTagNamespaceSummary(version: 1, count: apiUnreadMentionsCount, range: MessageHistoryTagNamespaceCountValidityRange(maxId: apiTopMessage))
}

View File

@ -16,11 +16,11 @@ public class InlineBotMessageAttribute: MessageAttribute {
self.peerId = peerId
}
required public init(decoder: Decoder) {
required public init(decoder: PostboxDecoder) {
self.peerId = PeerId(decoder.decodeInt64ForKey("i", orElse: 0))
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.peerId.toInt64(), forKey: "i")
}
}

View File

@ -31,7 +31,7 @@ private enum InstantPageBlockType: Int32 {
case audio = 22
}
public indirect enum InstantPageBlock: Coding, Equatable {
public indirect enum InstantPageBlock: PostboxCoding, Equatable {
case unsupported
case title(RichText)
case subtitle(RichText)
@ -56,7 +56,7 @@ public indirect enum InstantPageBlock: Coding, Equatable {
case slideshow(items: [InstantPageBlock], caption: RichText)
case channelBanner(TelegramChannel?)
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("r", orElse: 0) {
case InstantPageBlockType.unsupported.rawValue:
self = .unsupported
@ -119,7 +119,7 @@ public indirect enum InstantPageBlock: Coding, Equatable {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
switch self {
case .unsupported:
encoder.encodeInt32(InstantPageBlockType.unsupported.rawValue, forKey: "r")
@ -399,14 +399,14 @@ public indirect enum InstantPageBlock: Coding, Equatable {
}
}
private final class MediaDictionary: Coding {
private final class MediaDictionary: PostboxCoding {
let dict: [MediaId: Media]
init(dict: [MediaId: Media]) {
self.dict = dict
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
let idsBufer = decoder.decodeBytesForKey("i")!
let mediaIds = MediaId.decodeArrayFromBuffer(idsBufer)
let medias = decoder.decodeObjectArrayForKey("m")
@ -420,9 +420,9 @@ private final class MediaDictionary: Coding {
self.dict = dict
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
var mediaIds: [MediaId] = []
var medias: [Coding] = []
var medias: [PostboxCoding] = []
for mediaId in self.dict.keys {
mediaIds.append(mediaId)
medias.append(self.dict[mediaId]!)
@ -434,7 +434,7 @@ private final class MediaDictionary: Coding {
}
}
public final class InstantPage: Coding, Equatable {
public final class InstantPage: PostboxCoding, Equatable {
public let blocks: [InstantPageBlock]
public let media: [MediaId: Media]
public let isComplete: Bool
@ -445,13 +445,13 @@ public final class InstantPage: Coding, Equatable {
self.isComplete = isComplete
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.blocks = decoder.decodeObjectArrayWithDecoderForKey("b")
self.media = MediaDictionary(decoder: decoder).dict
self.isComplete = decoder.decodeInt32ForKey("c", orElse: 0) != 0
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeObjectArray(self.blocks, forKey: "b")
MediaDictionary(dict: self.media).encode(encoder)
encoder.encodeInt32(self.isComplete ? 1 : 0, forKey: "c")

View File

@ -26,7 +26,7 @@ public final class LimitsConfiguration: PreferencesEntry {
self.maxMessageEditingInterval = maxMessageEditingInterval
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.maxGroupMemberCount = decoder.decodeInt32ForKey("maxGroupMemberCount", orElse: 200)
self.maxSupergroupMemberCount = decoder.decodeInt32ForKey("maxSupergroupMemberCount", orElse: 5000)
self.maxMessageForwardBatchSize = decoder.decodeInt32ForKey("maxMessageForwardBatchSize", orElse: 50)
@ -35,7 +35,7 @@ public final class LimitsConfiguration: PreferencesEntry {
self.maxMessageEditingInterval = decoder.decodeInt32ForKey("maxMessageEditingInterval", orElse: 2 * 24 * 60 * 60)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.maxGroupMemberCount, forKey: "maxGroupMemberCount")
encoder.encodeInt32(self.maxSupergroupMemberCount, forKey: "maxSupergroupMemberCount")
encoder.encodeInt32(self.maxMessageForwardBatchSize, forKey: "maxMessageForwardBatchSize")

View File

@ -0,0 +1,75 @@
#if os(macOS)
import PostboxMac
import SwiftSignalKitMac
#else
import Postbox
import SwiftSignalKit
#endif
public func actualizedPeer(postbox: Postbox, network: Network, peer: Peer) -> Signal<Peer, NoError> {
return postbox.modify { modifier -> Signal<Peer, NoError> in
var signal: Signal<Peer, NoError>
var actualizeChannel: Api.InputChannel?
if let currentPeer = modifier.getPeer(peer.id) {
signal = .single(currentPeer)
if let currentPeer = currentPeer as? TelegramChannel {
switch currentPeer.participationStatus {
case .left, .kicked:
actualizeChannel = apiInputChannel(currentPeer)
default:
break
}
}
} else {
signal = .single(peer)
if let peer = peer as? TelegramChannel {
actualizeChannel = apiInputChannel(peer)
}
}
if let actualizeChannel = actualizeChannel {
let remote = network.request(Api.functions.channels.getChannels(id: [actualizeChannel]))
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.messages.Chats?, NoError> in
return .single(nil)
}
|> mapToSignal { result -> Signal<Peer, NoError> in
var remotePeer: Peer?
if let result = result {
let chats: [Api.Chat]
switch result {
case let .chats(apiChats):
chats = apiChats
case let .chatsSlice(_, apiChats):
chats = apiChats
}
for chat in chats {
if let parsedPeer = parseTelegramGroupOrChannel(chat: chat), parsedPeer.id == peer.id {
remotePeer = parsedPeer
}
}
}
if let remotePeer = remotePeer {
return postbox.modify { modifier -> Peer in
updatePeers(modifier: modifier, peers: [remotePeer], update: { _, updated in
return updated
})
return remotePeer
}
} else {
return .complete()
}
}
signal = signal |> then(remote)
}
let updatedView: Signal<Peer, NoError> = postbox.combinedView(keys: [.peer(peerId: peer.id)])
|> mapToSignal { view -> Signal<Peer, NoError> in
if let peerView = view.views[.peer(peerId: peer.id)] as? PeerView, let peer = peerView.peers[peerView.peerId] {
return .single(peer)
}
return .complete()
}
return (signal |> then(updatedView)) |> distinctUntilChanged(isEqual: { $0.isEqual($1) })
} |> switchToLatest
}

View File

@ -87,7 +87,7 @@ private func writeString(_ buffer: WriteBuffer, _ string: String) {
}
}
public final class Localization: Coding, Equatable {
public final class Localization: PostboxCoding, Equatable {
public let version: Int32
public let entries: [LocalizationEntry]
@ -96,7 +96,7 @@ public final class Localization: Coding, Equatable {
self.entries = entries
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.version = decoder.decodeInt32ForKey("v", orElse: 0)
let count = decoder.decodeInt32ForKey("c", orElse: 0)
var entries: [LocalizationEntry] = []
@ -192,7 +192,7 @@ public final class Localization: Coding, Equatable {
self.entries = entries
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(Int32(self.entries.count), forKey: "c")
let buffer = WriteBuffer()

View File

@ -14,12 +14,12 @@ public final class LocalizationSettings: PreferencesEntry, Equatable {
self.localization = localization
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.languageCode = decoder.decodeStringForKey("lc", orElse: "en")
self.localization = decoder.decodeObjectForKey("loc", decoder: { Localization(decoder: $0) }) as! Localization
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.languageCode, forKey: "lc")
encoder.encodeObject(self.localization, forKey: "loc")
}

View File

@ -9,10 +9,10 @@ public final class LoggedOutAccountAttribute: AccountRecordAttribute {
public init() {
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
}
public func isEqual(to: AccountRecordAttribute) -> Bool {

View File

@ -11,10 +11,12 @@ import Foundation
private final class ManagedConsumePersonalMessagesActionsHelper {
var operationDisposables: [MessageId: Disposable] = [:]
var validateDisposables: [InvalidatedMessageHistoryTagsSummaryEntry: Disposable] = [:]
func update(_ entries: [PendingMessageActionsEntry]) -> (disposeOperations: [Disposable], beginOperations: [(PendingMessageActionsEntry, MetaDisposable)]) {
func update(entries: [PendingMessageActionsEntry], invalidateEntries: Set<InvalidatedMessageHistoryTagsSummaryEntry>) -> (disposeOperations: [Disposable], beginOperations: [(PendingMessageActionsEntry, MetaDisposable)], beginValidateOperations: [(InvalidatedMessageHistoryTagsSummaryEntry, MetaDisposable)]) {
var disposeOperations: [Disposable] = []
var beginOperations: [(PendingMessageActionsEntry, MetaDisposable)] = []
var beginValidateOperations: [(InvalidatedMessageHistoryTagsSummaryEntry, MetaDisposable)] = []
var hasRunningOperationForPeerId = Set<PeerId>()
var validIds = Set<MessageId>()
@ -43,7 +45,32 @@ private final class ManagedConsumePersonalMessagesActionsHelper {
self.operationDisposables.removeValue(forKey: id)
}
return (disposeOperations, beginOperations)
var validInvalidateEntries = Set<InvalidatedMessageHistoryTagsSummaryEntry>()
for entry in invalidateEntries {
if !hasRunningOperationForPeerId.contains(entry.key.peerId) {
validInvalidateEntries.insert(entry)
if self.validateDisposables[entry] == nil {
let disposable = MetaDisposable()
beginValidateOperations.append((entry, disposable))
self.validateDisposables[entry] = disposable
}
}
}
var removeValidateEntries: [InvalidatedMessageHistoryTagsSummaryEntry] = []
for (entry, disposable) in self.validateDisposables {
if !validInvalidateEntries.contains(entry) {
removeValidateEntries.append(entry)
disposeOperations.append(disposable)
}
}
for entry in removeValidateEntries {
self.validateDisposables.removeValue(forKey: entry)
}
return (disposeOperations, beginOperations, beginValidateOperations)
}
func reset() -> [Disposable] {
@ -65,20 +92,24 @@ private func withTakenAction(postbox: Postbox, type: PendingMessageActionType, i
} |> switchToLatest
}
func managedConsumePersonalMessagesActions(postbox: Postbox, network: Network, stateManager: AccountStateManager) -> Signal<Void, NoError> {
return Signal { _ in
let helper = Atomic<ManagedConsumePersonalMessagesActionsHelper>(value: ManagedConsumePersonalMessagesActionsHelper())
let key = PostboxViewKey.pendingMessageActions(type: .consumeUnseenPersonalMessage)
let disposable = postbox.combinedView(keys: [key]).start(next: { view in
let actionsKey = PostboxViewKey.pendingMessageActions(type: .consumeUnseenPersonalMessage)
let invalidateKey = PostboxViewKey.invalidatedMessageHistoryTagSummaries(tagMask: .unseenPersonalMessage, namespace: Namespaces.Message.Cloud)
let disposable = postbox.combinedView(keys: [actionsKey, invalidateKey]).start(next: { view in
var entries: [PendingMessageActionsEntry] = []
if let v = view.views[key] as? PendingMessageActionsView {
var invalidateEntries = Set<InvalidatedMessageHistoryTagsSummaryEntry>()
if let v = view.views[actionsKey] as? PendingMessageActionsView {
entries = v.entries
}
if let v = view.views[invalidateKey] as? InvalidatedMessageHistoryTagSummariesView {
invalidateEntries = v.entries
}
let (disposeOperations, beginOperations) = helper.with { helper -> (disposeOperations: [Disposable], beginOperations: [(PendingMessageActionsEntry, MetaDisposable)]) in
return helper.update(entries)
let (disposeOperations, beginOperations, beginValidateOperations) = helper.with { helper -> (disposeOperations: [Disposable], beginOperations: [(PendingMessageActionsEntry, MetaDisposable)], beginValidateOperations: [(InvalidatedMessageHistoryTagsSummaryEntry, MetaDisposable)]) in
return helper.update(entries: entries, invalidateEntries: invalidateEntries)
}
for disposable in disposeOperations {
@ -102,6 +133,14 @@ func managedConsumePersonalMessagesActions(postbox: Postbox, network: Network, s
disposable.set(signal.start())
}
for (entry, disposable) in beginValidateOperations {
let signal = synchronizeUnseenPersonalMentionsTag(postbox: postbox, network: network, entry: entry)
|> then(postbox.modify { modifier -> Void in
modifier.removeInvalidatedMessageHistoryTagsSummaryEntry(entry)
})
disposable.set(signal.start())
}
})
return ActionDisposable {
@ -183,3 +222,41 @@ private func synchronizeConsumeMessageContents(modifier: Modifier, postbox: Post
return .complete()
}
}
private func synchronizeUnseenPersonalMentionsTag(postbox: Postbox, network: Network, entry: InvalidatedMessageHistoryTagsSummaryEntry) -> Signal<Void, NoError> {
return postbox.modify { modifier -> Signal<Void, NoError> in
if let peer = modifier.getPeer(entry.key.peerId), let inputPeer = apiInputPeer(peer) {
return network.request(Api.functions.messages.getPeerDialogs(peers: [inputPeer]))
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.messages.PeerDialogs?, NoError> in
return .single(nil)
}
|> mapToSignal { result -> Signal<Void, NoError> in
if let result = result {
switch result {
case let .peerDialogs(dialogs, _, _, _, _):
if let dialog = dialogs.filter({ $0.peerId == entry.key.peerId }).first {
let apiTopMessage: Int32
let apiUnreadMentionsCount: Int32
switch dialog {
case let .dialog(_, _, topMessage, _, _, _, unreadMentionsCount, _, _, _):
apiTopMessage = topMessage
apiUnreadMentionsCount = unreadMentionsCount
}
return postbox.modify { modifier -> Void in
modifier.replaceMessageTagSummary(peerId: entry.key.peerId, tagMask: entry.key.tagMask, namespace: entry.key.namespace, count: apiUnreadMentionsCount, maxId: apiTopMessage)
}
} else {
return .complete()
}
}
} else {
return .complete()
}
}
} else {
return .complete()
}
} |> switchToLatest
}

View File

@ -15,11 +15,11 @@ final class ManagedDeviceContactsMetaInfo: UnorderedItemListTagMetaInfo {
self.version = version
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.version = decoder.decodeInt32ForKey("v", orElse: 0)
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.version, forKey: "v")
}
@ -32,7 +32,7 @@ final class ManagedDeviceContactsMetaInfo: UnorderedItemListTagMetaInfo {
}
}
final class ManagedDeviceContactEntryContents: Coding {
final class ManagedDeviceContactEntryContents: PostboxCoding {
let firstName: String
let lastName: String
let phoneNumber: String
@ -47,7 +47,7 @@ final class ManagedDeviceContactEntryContents: Coding {
self.importDelayedUntil = importDelayedUntil
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.firstName = decoder.decodeStringForKey("f", orElse: "")
self.lastName = decoder.decodeStringForKey("l", orElse: "")
self.phoneNumber = decoder.decodeStringForKey("n", orElse: "")
@ -59,7 +59,7 @@ final class ManagedDeviceContactEntryContents: Coding {
self.importDelayedUntil = decoder.decodeOptionalInt32ForKey("dt")
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.firstName, forKey: "f")
encoder.encodeString(self.lastName, forKey: "l")
encoder.encodeString(self.phoneNumber, forKey: "n")

View File

@ -94,6 +94,7 @@ func markMessageContentAsConsumedRemotely(modifier: Modifier, messageId: Message
}
updatedAttributes[i] = ConsumablePersonalMentionMessageAttribute(consumed: true, pending: false)
updatedTags.remove(.unseenPersonalMessage)
updateMessage = true
}
}

View File

@ -16,7 +16,7 @@ import TelegramCorePrivateModule
private typealias SignalKitTimer = SwiftSignalKit.Timer
#endif
public final class SecretFileEncryptionKey: Coding, Equatable {
public final class SecretFileEncryptionKey: PostboxCoding, Equatable {
public let aesKey: Data
public let aesIv: Data
@ -25,12 +25,12 @@ public final class SecretFileEncryptionKey: Coding, Equatable {
self.aesIv = aesIv
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.aesKey = decoder.decodeBytesForKey("k")!.makeData()
self.aesIv = decoder.decodeBytesForKey("i")!.makeData()
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeBytes(MemoryBuffer(data: self.aesKey), forKey: "k")
encoder.encodeBytes(MemoryBuffer(data: self.aesIv), forKey: "i")
}

View File

@ -30,11 +30,11 @@ public class NotificationInfoMessageAttribute: MessageAttribute {
self.flags = flags
}
required public init(decoder: Decoder) {
required public init(decoder: PostboxDecoder) {
self.flags = NotificationInfoMessageAttributeFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0))
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.flags.rawValue, forKey: "f")
}
}

View File

@ -14,12 +14,12 @@ public class OutgoingChatContextResultMessageAttribute: MessageAttribute {
self.id = id
}
required public init(decoder: Decoder) {
required public init(decoder: PostboxDecoder) {
self.queryId = decoder.decodeInt64ForKey("q", orElse: 0)
self.id = decoder.decodeStringForKey("i", orElse: "")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.queryId, forKey: "q")
encoder.encodeString(self.id, forKey: "i")
}

View File

@ -26,11 +26,11 @@ public class OutgoingContentInfoMessageAttribute: MessageAttribute {
self.flags = flags
}
required public init(decoder: Decoder) {
required public init(decoder: PostboxDecoder) {
self.flags = OutgoingContentInfoFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0))
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.flags.rawValue, forKey: "f")
}

View File

@ -28,12 +28,12 @@ public class OutgoingMessageInfoAttribute: MessageAttribute {
self.flags = flags
}
required public init(decoder: Decoder) {
required public init(decoder: PostboxDecoder) {
self.uniqueId = decoder.decodeInt64ForKey("u", orElse: 0)
self.flags = OutgoingMessageInfoFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0))
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.uniqueId, forKey: "u")
encoder.encodeInt32(self.flags.rawValue, forKey: "f")
}

View File

@ -5,18 +5,18 @@ import Foundation
import Postbox
#endif
public final class PeerAccessRestrictionInfo: Coding, Equatable {
public final class PeerAccessRestrictionInfo: PostboxCoding, Equatable {
public let reason: String
init(reason: String) {
self.reason = reason
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.reason = decoder.decodeStringForKey("rsn", orElse: "")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.reason, forKey: "rsn")
}

View File

@ -22,14 +22,14 @@ public final class ProxySettings: PreferencesEntry {
self.password = password
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.host = decoder.decodeStringForKey("host", orElse: "")
self.port = decoder.decodeInt32ForKey("port", orElse: 0)
self.username = decoder.decodeOptionalStringForKey("username")
self.password = decoder.decodeOptionalStringForKey("password")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.host, forKey: "host")
encoder.encodeInt32(self.port, forKey: "port")
if let username = self.username {

View File

@ -36,11 +36,11 @@ public final class RecentMediaItem: OrderedItemListEntryContents, Equatable {
self.media = media
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.media = decoder.decodeObjectForKey("m") as! Media
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeObject(self.media, forKey: "m")
}

View File

@ -32,11 +32,11 @@ public final class RecentPeerItem: OrderedItemListEntryContents {
self.rating = rating
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.rating = decoder.decodeDoubleForKey("r", orElse: 0.0)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeDouble(self.rating, forKey: "r")
}
}

View File

@ -5,7 +5,7 @@ import Foundation
import Postbox
#endif
public enum ReplyMarkupButtonAction: Coding, Equatable {
public enum ReplyMarkupButtonAction: PostboxCoding, Equatable {
case text
case url(String)
case callback(MemoryBuffer)
@ -15,7 +15,7 @@ public enum ReplyMarkupButtonAction: Coding, Equatable {
case openWebApp
case payment
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("v", orElse: 0) {
case 0:
self = .text
@ -38,7 +38,7 @@ public enum ReplyMarkupButtonAction: Coding, Equatable {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
switch self {
case .text:
encoder.encodeInt32(0, forKey: "v")
@ -117,7 +117,7 @@ public enum ReplyMarkupButtonAction: Coding, Equatable {
}
}
public struct ReplyMarkupButton: Coding, Equatable {
public struct ReplyMarkupButton: PostboxCoding, Equatable {
public let title: String
public let action: ReplyMarkupButtonAction
@ -126,12 +126,12 @@ public struct ReplyMarkupButton: Coding, Equatable {
self.action = action
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.title = decoder.decodeStringForKey(".t", orElse: "")
self.action = ReplyMarkupButtonAction(decoder: decoder)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.title, forKey: ".t")
self.action.encode(encoder)
}
@ -141,18 +141,18 @@ public struct ReplyMarkupButton: Coding, Equatable {
}
}
public struct ReplyMarkupRow: Coding, Equatable {
public struct ReplyMarkupRow: PostboxCoding, Equatable {
public let buttons: [ReplyMarkupButton]
init(buttons: [ReplyMarkupButton]) {
self.buttons = buttons
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.buttons = decoder.decodeObjectArrayWithDecoderForKey("b")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeObjectArray(self.buttons, forKey: "b")
}
@ -188,12 +188,12 @@ public class ReplyMarkupMessageAttribute: MessageAttribute, Equatable {
self.flags = flags
}
public required init(decoder: Decoder) {
public required init(decoder: PostboxDecoder) {
self.rows = decoder.decodeObjectArrayWithDecoderForKey("r")
self.flags = ReplyMarkupMessageFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0))
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeObjectArray(self.rows, forKey: "r")
encoder.encodeInt32(self.flags.rawValue, forKey: "f")
}

View File

@ -16,12 +16,12 @@ public class ReplyMessageAttribute: MessageAttribute {
self.messageId = messageId
}
required public init(decoder: Decoder) {
required public init(decoder: PostboxDecoder) {
let namespaceAndId: Int64 = decoder.decodeInt64ForKey("i", orElse: 0)
self.messageId = MessageId(peerId: PeerId(decoder.decodeInt64ForKey("p", orElse: 0)), namespace: Int32(namespaceAndId & 0xffffffff), id: Int32((namespaceAndId >> 32) & 0xffffffff))
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
let namespaceAndId = Int64(self.messageId.namespace) | (Int64(self.messageId.id) << 32)
encoder.encodeInt64(namespaceAndId, forKey: "i")
encoder.encodeInt64(self.messageId.peerId.toInt64(), forKey: "p")

View File

@ -7,7 +7,7 @@ import Foundation
import SwiftSignalKit
#endif
final class CachedResolvedByNamePeer: Coding {
final class CachedResolvedByNamePeer: PostboxCoding {
let peerId: PeerId?
let timestamp: Int32
@ -29,7 +29,7 @@ final class CachedResolvedByNamePeer: Coding {
self.timestamp = timestamp
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
if let peerId = decoder.decodeOptionalInt64ForKey("p") {
self.peerId = PeerId(peerId)
} else {
@ -38,7 +38,7 @@ final class CachedResolvedByNamePeer: Coding {
self.timestamp = decoder.decodeInt32ForKey("t", orElse: 0)
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
if let peerId = self.peerId {
encoder.encodeInt64(peerId.toInt64(), forKey: "p")
} else {

View File

@ -18,7 +18,7 @@ private enum RichTextTypes: Int32 {
case concat = 9
}
public indirect enum RichText: Coding, Equatable {
public indirect enum RichText: PostboxCoding, Equatable {
case empty
case plain(String)
case bold(RichText)
@ -30,7 +30,7 @@ public indirect enum RichText: Coding, Equatable {
case email(text: RichText, email: String)
case concat([RichText])
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("r", orElse: 0) {
case RichTextTypes.empty.rawValue:
self = .empty
@ -63,7 +63,7 @@ public indirect enum RichText: Coding, Equatable {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
switch self {
case .empty:
encoder.encodeInt32(RichTextTypes.empty.rawValue, forKey: "r")

View File

@ -14,12 +14,12 @@ public final class SavedStickerItem: OrderedItemListEntryContents, Equatable {
self.stringRepresentations = stringRepresentations
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.file = decoder.decodeObjectForKey("f") as! TelegramMediaFile
self.stringRepresentations = decoder.decodeStringArrayForKey("sr")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeObject(self.file, forKey: "f")
encoder.encodeStringArray(self.stringRepresentations, forKey: "sr")
}

View File

@ -9,7 +9,7 @@ import Foundation
import MtProtoKitDynamic
#endif
final class SecretChatEncryptionConfig: Coding {
final class SecretChatEncryptionConfig: PostboxCoding {
let g: Int32
let p: MemoryBuffer
let version: Int32
@ -20,13 +20,13 @@ final class SecretChatEncryptionConfig: Coding {
self.version = version
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.g = decoder.decodeInt32ForKey("g", orElse: 0)
self.p = decoder.decodeBytesForKey("p")!
self.version = decoder.decodeInt32ForKey("v", orElse: 0)
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.g, forKey: "g")
encoder.encodeBytes(self.p, forKey: "p")
encoder.encodeInt32(self.version, forKey: "v")

View File

@ -5,7 +5,7 @@ import Foundation
import Postbox
#endif
final class SecretChatFileReference: Coding {
final class SecretChatFileReference: PostboxCoding {
let id: Int64
let accessHash: Int64
let size: Int32
@ -20,7 +20,7 @@ final class SecretChatFileReference: Coding {
self.keyFingerprint = keyFingerprint
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.id = decoder.decodeInt64ForKey("i", orElse: 0)
self.accessHash = decoder.decodeInt64ForKey("a", orElse: 0)
self.size = decoder.decodeInt32ForKey("s", orElse: 0)
@ -28,7 +28,7 @@ final class SecretChatFileReference: Coding {
self.keyFingerprint = decoder.decodeInt32ForKey("f", orElse: 0)
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.id, forKey: "i")
encoder.encodeInt64(self.accessHash, forKey: "a")
encoder.encodeInt32(self.size, forKey: "s")

View File

@ -5,7 +5,7 @@ import Foundation
import Postbox
#endif
struct SecretChatOperationSequenceInfo: Coding {
struct SecretChatOperationSequenceInfo: PostboxCoding {
let topReceivedOperationIndex: Int32
let operationIndex: Int32
@ -14,18 +14,18 @@ struct SecretChatOperationSequenceInfo: Coding {
self.operationIndex = operationIndex
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.topReceivedOperationIndex = decoder.decodeInt32ForKey("r", orElse: 0)
self.operationIndex = decoder.decodeInt32ForKey("o", orElse: 0)
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.topReceivedOperationIndex, forKey: "r")
encoder.encodeInt32(self.operationIndex, forKey: "o")
}
}
final class SecretChatIncomingDecryptedOperation: Coding {
final class SecretChatIncomingDecryptedOperation: PostboxCoding {
let timestamp: Int32
let layer: Int32
let sequenceInfo: SecretChatOperationSequenceInfo?
@ -40,7 +40,7 @@ final class SecretChatIncomingDecryptedOperation: Coding {
self.file = file
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.timestamp = decoder.decodeInt32ForKey("t", orElse: 0)
self.layer = decoder.decodeInt32ForKey("l", orElse: 0)
self.sequenceInfo = decoder.decodeObjectForKey("s", decoder: { SecretChatOperationSequenceInfo(decoder: $0) }) as? SecretChatOperationSequenceInfo
@ -48,7 +48,7 @@ final class SecretChatIncomingDecryptedOperation: Coding {
self.file = decoder.decodeObjectForKey("f", decoder: { SecretChatFileReference(decoder: $0) }) as? SecretChatFileReference
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.timestamp, forKey: "t")
encoder.encodeInt32(self.layer, forKey: "l")
if let sequenceInfo = self.sequenceInfo {

View File

@ -27,7 +27,7 @@ enum SecretChatIncomingEncryptedOperationType: Int32 {
}
}
final class SecretChatIncomingEncryptedOperation: Coding {
final class SecretChatIncomingEncryptedOperation: PostboxCoding {
let peerId: PeerId
let globallyUniqueId: Int64
let timestamp: Int32
@ -46,7 +46,7 @@ final class SecretChatIncomingEncryptedOperation: Coding {
self.mediaFileReference = mediaFileReference
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.peerId = PeerId(decoder.decodeInt64ForKey("p", orElse: 0))
self.globallyUniqueId = decoder.decodeInt64ForKey("u", orElse: 0)
self.timestamp = decoder.decodeInt32ForKey("t", orElse: 0)
@ -56,7 +56,7 @@ final class SecretChatIncomingEncryptedOperation: Coding {
self.mediaFileReference = decoder.decodeObjectForKey("m", decoder: { SecretChatFileReference(decoder: $0) }) as? SecretChatFileReference
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.peerId.toInt64(), forKey: "p")
encoder.encodeInt64(self.globallyUniqueId, forKey: "u")
encoder.encodeInt32(self.timestamp, forKey: "t")

View File

@ -5,11 +5,11 @@ import Foundation
import Postbox
#endif
enum SecretChatKeyValidity: Coding, Equatable {
enum SecretChatKeyValidity: PostboxCoding, Equatable {
case indefinite
case sequenceBasedIndexRange(fromCanonicalIndex: Int32)
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("r", orElse: 0) {
case 0:
self = .indefinite
@ -21,7 +21,7 @@ enum SecretChatKeyValidity: Coding, Equatable {
}
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
switch self {
case .indefinite:
encoder.encodeInt32(0, forKey: "r")
@ -49,7 +49,7 @@ enum SecretChatKeyValidity: Coding, Equatable {
}
}
final class SecretChatKey: Coding, Equatable {
final class SecretChatKey: PostboxCoding, Equatable {
let fingerprint: Int64
let key: MemoryBuffer
let validity: SecretChatKeyValidity
@ -62,14 +62,14 @@ final class SecretChatKey: Coding, Equatable {
self.useCount = useCount
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.fingerprint = decoder.decodeInt64ForKey("f", orElse: 0)
self.key = decoder.decodeBytesForKey("k")!
self.validity = decoder.decodeObjectForKey("v", decoder: { SecretChatKeyValidity(decoder: $0) }) as! SecretChatKeyValidity
self.useCount = decoder.decodeInt32ForKey("u", orElse: 0)
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.fingerprint, forKey: "f")
encoder.encodeBytes(self.key, forKey: "k")
encoder.encodeObject(self.validity, forKey: "v")
@ -94,18 +94,18 @@ final class SecretChatKey: Coding, Equatable {
}
}
final class SecretChatKeychain: Coding, Equatable {
final class SecretChatKeychain: PostboxCoding, Equatable {
let keys: [SecretChatKey]
init(keys: [SecretChatKey]) {
self.keys = keys
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.keys = decoder.decodeObjectArrayWithDecoderForKey("k")
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeObjectArray(self.keys, forKey: "k")
}

View File

@ -11,12 +11,12 @@ private enum SecretChatOutgoingFileValue: Int32 {
case uploadedLarge = 2
}
enum SecretChatOutgoingFileReference: Coding {
enum SecretChatOutgoingFileReference: PostboxCoding {
case remote(id: Int64, accessHash: Int64)
case uploadedRegular(id: Int64, partCount: Int32, md5Digest: String, keyFingerprint: Int32)
case uploadedLarge(id: Int64, partCount: Int32, keyFingerprint: Int32)
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("v", orElse: 0) {
case SecretChatOutgoingFileValue.remote.rawValue:
self = .remote(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("a", orElse: 0))
@ -30,7 +30,7 @@ enum SecretChatOutgoingFileReference: Coding {
}
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
switch self {
case let .remote(id, accessHash):
encoder.encodeInt32(SecretChatOutgoingFileValue.remote.rawValue, forKey: "v")
@ -51,7 +51,7 @@ enum SecretChatOutgoingFileReference: Coding {
}
}
struct SecretChatOutgoingFile: Coding {
struct SecretChatOutgoingFile: PostboxCoding {
let reference: SecretChatOutgoingFileReference
let size: Int32
let key: SecretFileEncryptionKey
@ -62,13 +62,13 @@ struct SecretChatOutgoingFile: Coding {
self.key = key
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.reference = decoder.decodeObjectForKey("r", decoder: { SecretChatOutgoingFileReference(decoder: $0) }) as! SecretChatOutgoingFileReference
self.size = decoder.decodeInt32ForKey("s", orElse: 0)
self.key = SecretFileEncryptionKey(aesKey: decoder.decodeBytesForKey("k")!.makeData(), aesIv: decoder.decodeBytesForKey("i")!.makeData())
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeObject(self.reference, forKey: "r")
encoder.encodeInt32(self.size, forKey: "s")
encoder.encodeBytes(MemoryBuffer(data: self.key.aesKey), forKey: "k")
@ -98,7 +98,7 @@ private enum SecretChatOutgoingOperationValue: Int32 {
case terminate = 14
}
enum SecretChatOutgoingOperationContents: Coding {
enum SecretChatOutgoingOperationContents: PostboxCoding {
case initialHandshakeAccept(gA: MemoryBuffer, accessHash: Int64, b: MemoryBuffer)
case sendMessage(layer: SecretChatLayer, id: MessageId, file: SecretChatOutgoingFile?)
case readMessagesContent(layer: SecretChatLayer, actionGloballyUniqueId: Int64, globallyUniqueIds: [Int64])
@ -115,7 +115,7 @@ enum SecretChatOutgoingOperationContents: Coding {
case setMessageAutoremoveTimeout(layer: SecretChatLayer, actionGloballyUniqueId: Int64, timeout: Int32, messageId: MessageId)
case terminate(reportSpam: Bool)
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("r", orElse: 0) {
case SecretChatOutgoingOperationValue.initialHandshakeAccept.rawValue:
self = .initialHandshakeAccept(gA: decoder.decodeBytesForKey("g")!, accessHash: decoder.decodeInt64ForKey("h", orElse: 0), b: decoder.decodeBytesForKey("b")!)
@ -153,7 +153,7 @@ enum SecretChatOutgoingOperationContents: Coding {
}
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
switch self {
case let .initialHandshakeAccept(gA, accessHash, b):
encoder.encodeInt32(SecretChatOutgoingOperationValue.initialHandshakeAccept.rawValue, forKey: "r")
@ -244,7 +244,7 @@ enum SecretChatOutgoingOperationContents: Coding {
}
}
final class SecretChatOutgoingOperation: Coding {
final class SecretChatOutgoingOperation: PostboxCoding {
let contents: SecretChatOutgoingOperationContents
let mutable: Bool
let delivered: Bool
@ -255,13 +255,13 @@ final class SecretChatOutgoingOperation: Coding {
self.delivered = delivered
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.contents = decoder.decodeObjectForKey("c", decoder: { SecretChatOutgoingOperationContents(decoder: $0) }) as! SecretChatOutgoingOperationContents
self.mutable = decoder.decodeInt32ForKey("m", orElse: 0) != 0
self.delivered = decoder.decodeInt32ForKey("d", orElse: 0) != 0
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeObject(self.contents, forKey: "c")
encoder.encodeInt32(self.mutable ? 1 : 0, forKey: "m")
encoder.encodeInt32(self.delivered ? 1 : 0, forKey: "d")

View File

@ -15,7 +15,7 @@ enum SecretChatLayer: Int32 {
case layer46 = 46
}
public struct SecretChatKeySha1Fingerprint: Coding, Equatable {
public struct SecretChatKeySha1Fingerprint: PostboxCoding, Equatable {
public let k0: Int64
public let k1: Int64
public let k2: Int32
@ -43,13 +43,13 @@ public struct SecretChatKeySha1Fingerprint: Coding, Equatable {
self.k2 = k2
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.k0 = decoder.decodeInt64ForKey("k0", orElse: 0)
self.k1 = decoder.decodeInt64ForKey("k1", orElse: 0)
self.k2 = decoder.decodeInt32ForKey("k2", orElse: 0)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.k0, forKey: "k0")
encoder.encodeInt64(self.k1, forKey: "k1")
encoder.encodeInt32(self.k2, forKey: "k2")
@ -82,7 +82,7 @@ public struct SecretChatKeySha1Fingerprint: Coding, Equatable {
}
}
public struct SecretChatKeySha256Fingerprint: Coding, Equatable {
public struct SecretChatKeySha256Fingerprint: PostboxCoding, Equatable {
public let k0: Int64
public let k1: Int64
public let k2: Int64
@ -113,14 +113,14 @@ public struct SecretChatKeySha256Fingerprint: Coding, Equatable {
self.k3 = k3
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.k0 = decoder.decodeInt64ForKey("k0", orElse: 0)
self.k1 = decoder.decodeInt64ForKey("k1", orElse: 0)
self.k2 = decoder.decodeInt64ForKey("k2", orElse: 0)
self.k3 = decoder.decodeInt64ForKey("k3", orElse: 0)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.k0, forKey: "k0")
encoder.encodeInt64(self.k1, forKey: "k1")
encoder.encodeInt64(self.k2, forKey: "k2")
@ -156,7 +156,7 @@ public struct SecretChatKeySha256Fingerprint: Coding, Equatable {
}
}
public struct SecretChatKeyFingerprint: Coding, Equatable {
public struct SecretChatKeyFingerprint: PostboxCoding, Equatable {
public let sha1: SecretChatKeySha1Fingerprint
public let sha256: SecretChatKeySha256Fingerprint
@ -165,12 +165,12 @@ public struct SecretChatKeyFingerprint: Coding, Equatable {
self.sha256 = sha256
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.sha1 = decoder.decodeObjectForKey("1", decoder: { SecretChatKeySha1Fingerprint(decoder: $0) }) as! SecretChatKeySha1Fingerprint
self.sha256 = decoder.decodeObjectForKey("2", decoder: { SecretChatKeySha256Fingerprint(decoder: $0) }) as! SecretChatKeySha256Fingerprint
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeObject(self.sha1, forKey: "1")
encoder.encodeObject(self.sha256, forKey: "2")
}
@ -193,11 +193,11 @@ private enum SecretChatEmbeddedStateValue: Int32 {
case sequenceBasedLayer = 3
}
enum SecretChatHandshakeState: Coding, Equatable {
enum SecretChatHandshakeState: PostboxCoding, Equatable {
case accepting
case requested(g: Int32, p: MemoryBuffer, a: MemoryBuffer)
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("r", orElse: 0) {
case 0:
self = .accepting
@ -209,7 +209,7 @@ enum SecretChatHandshakeState: Coding, Equatable {
}
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
switch self {
case .accepting:
encoder.encodeInt32(0, forKey: "r")
@ -239,7 +239,7 @@ enum SecretChatHandshakeState: Coding, Equatable {
}
}
struct SecretChatLayerNegotiationState: Coding, Equatable {
struct SecretChatLayerNegotiationState: PostboxCoding, Equatable {
let activeLayer: Int32
let locallyRequestedLayer: Int32?
let remotelyRequestedLayer: Int32?
@ -250,13 +250,13 @@ struct SecretChatLayerNegotiationState: Coding, Equatable {
self.remotelyRequestedLayer = remotelyRequestedLayer
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.activeLayer = decoder.decodeInt32ForKey("a", orElse: 0)
self.locallyRequestedLayer = decoder.decodeOptionalInt32ForKey("lr")
self.remotelyRequestedLayer = decoder.decodeOptionalInt32ForKey("rr")
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.activeLayer, forKey: "a")
if let locallyRequestedLayer = self.locallyRequestedLayer {
encoder.encodeInt32(locallyRequestedLayer, forKey: "lr")
@ -295,13 +295,13 @@ private enum SecretChatRekeySessionDataValue: Int32 {
case accepted = 3
}
enum SecretChatRekeySessionData: Coding, Equatable {
enum SecretChatRekeySessionData: PostboxCoding, Equatable {
case requesting
case requested(a: MemoryBuffer, config: SecretChatEncryptionConfig)
case accepting
case accepted(key: MemoryBuffer, keyFingerprint: Int64)
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("r", orElse: 0) {
case SecretChatRekeySessionDataValue.requesting.rawValue:
self = .requesting
@ -316,7 +316,7 @@ enum SecretChatRekeySessionData: Coding, Equatable {
}
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
switch self {
case .requesting:
encoder.encodeInt32(SecretChatRekeySessionDataValue.requesting.rawValue, forKey: "r")
@ -363,7 +363,7 @@ enum SecretChatRekeySessionData: Coding, Equatable {
}
}
struct SecretChatRekeySessionState: Coding, Equatable {
struct SecretChatRekeySessionState: PostboxCoding, Equatable {
let id: Int64
let data: SecretChatRekeySessionData
@ -372,12 +372,12 @@ struct SecretChatRekeySessionState: Coding, Equatable {
self.data = data
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.id = decoder.decodeInt64ForKey("i", orElse: 0)
self.data = decoder.decodeObjectForKey("d", decoder: { SecretChatRekeySessionData(decoder: $0) }) as! SecretChatRekeySessionData
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.id, forKey: "i")
encoder.encodeObject(self.data, forKey: "d")
}
@ -393,7 +393,7 @@ struct SecretChatRekeySessionState: Coding, Equatable {
}
}
struct SecretChatSequenceBasedLayerState: Coding, Equatable {
struct SecretChatSequenceBasedLayerState: PostboxCoding, Equatable {
let layerNegotiationState: SecretChatLayerNegotiationState
let rekeyState: SecretChatRekeySessionState?
let baseIncomingOperationIndex: Int32
@ -408,7 +408,7 @@ struct SecretChatSequenceBasedLayerState: Coding, Equatable {
self.topProcessedCanonicalIncomingOperationIndex = topProcessedCanonicalIncomingOperationIndex
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.layerNegotiationState = decoder.decodeObjectForKey("ln", decoder: { SecretChatLayerNegotiationState(decoder: $0) }) as! SecretChatLayerNegotiationState
self.rekeyState = decoder.decodeObjectForKey("rs", decoder: { SecretChatRekeySessionState(decoder: $0) }) as? SecretChatRekeySessionState
self.baseIncomingOperationIndex = decoder.decodeInt32ForKey("bi", orElse: 0)
@ -420,7 +420,7 @@ struct SecretChatSequenceBasedLayerState: Coding, Equatable {
}
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeObject(self.layerNegotiationState, forKey: "ln")
if let rekeyState = self.rekeyState {
encoder.encodeObject(rekeyState, forKey: "rs")
@ -477,7 +477,7 @@ struct SecretChatSequenceBasedLayerState: Coding, Equatable {
}
}
enum SecretChatEmbeddedState: Coding, Equatable {
enum SecretChatEmbeddedState: PostboxCoding, Equatable {
case terminated
case handshake(SecretChatHandshakeState)
case basicLayer
@ -494,7 +494,7 @@ enum SecretChatEmbeddedState: Coding, Equatable {
}
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("r", orElse: 0) {
case SecretChatEmbeddedStateValue.terminated.rawValue:
self = .terminated
@ -510,7 +510,7 @@ enum SecretChatEmbeddedState: Coding, Equatable {
}
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
switch self {
case .terminated:
encoder.encodeInt32(SecretChatEmbeddedStateValue.terminated.rawValue, forKey: "r")
@ -574,7 +574,7 @@ final class SecretChatState: PeerChatState, SecretChatKeyState, Equatable {
self.messageAutoremoveTimeout = messageAutoremoveTimeout
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.role = SecretChatRole(rawValue: decoder.decodeInt32ForKey("r", orElse: 0))!
self.embeddedState = decoder.decodeObjectForKey("s", decoder: { return SecretChatEmbeddedState(decoder: $0) }) as! SecretChatEmbeddedState
self.keychain = decoder.decodeObjectForKey("k", decoder: { return SecretChatKeychain(decoder: $0) }) as! SecretChatKeychain
@ -582,7 +582,7 @@ final class SecretChatState: PeerChatState, SecretChatKeyState, Equatable {
self.messageAutoremoveTimeout = decoder.decodeOptionalInt32ForKey("a")
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.role.rawValue, forKey: "r")
encoder.encodeObject(self.embeddedState, forKey: "s")
encoder.encodeObject(self.keychain, forKey: "k")

View File

@ -54,7 +54,7 @@ public final class StickerPackCollectionInfo: ItemCollectionInfo, Equatable {
self.count = count
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.id = ItemCollectionId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0))
self.accessHash = decoder.decodeInt64ForKey("a", orElse: 0)
self.title = decoder.decodeStringForKey("t", orElse: "")
@ -64,7 +64,7 @@ public final class StickerPackCollectionInfo: ItemCollectionInfo, Equatable {
self.count = decoder.decodeInt32ForKey("n", orElse: 0)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.id.namespace, forKey: "i.n")
encoder.encodeInt64(self.id.id, forKey: "i.i")
encoder.encodeInt64(self.accessHash, forKey: "a")
@ -115,13 +115,13 @@ public final class StickerPackItem: ItemCollectionItem, Equatable {
self.indexKeys = indexKeys
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.index = ItemCollectionItemIndex(index: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0))
self.file = decoder.decodeObjectForKey("f") as! TelegramMediaFile
self.indexKeys = decoder.decodeBytesArrayForKey("s")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.index.index, forKey: "i.n")
encoder.encodeInt64(self.index.id, forKey: "i.i")
encoder.encodeObject(self.file, forKey: "f")

View File

@ -16,12 +16,12 @@ public final class SuggestedLocalizationEntry: PreferencesEntry {
self.isSeen = isSeen
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.languageCode = decoder.decodeStringForKey("lc", orElse: "en")
self.isSeen = decoder.decodeInt32ForKey("s", orElse: 0) != 0
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.languageCode, forKey: "lc")
encoder.encodeInt32(self.isSeen ? 1 : 0, forKey: "s")
}

View File

@ -5,18 +5,18 @@ import Foundation
import Postbox
#endif
final class SynchronizeChatInputStateOperation: Coding {
final class SynchronizeChatInputStateOperation: PostboxCoding {
let previousState: SynchronizeableChatInputState?
init(previousState: SynchronizeableChatInputState?) {
self.previousState = previousState
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.previousState = decoder.decodeObjectForKey("p", decoder: { SynchronizeableChatInputState(decoder: $0) }) as? SynchronizeableChatInputState
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
if let previousState = self.previousState {
encoder.encodeObject(previousState, forKey: "p")
} else {

View File

@ -5,18 +5,18 @@ import Foundation
import Postbox
#endif
final class SynchronizeConsumeMessageContentsOperation: Coding {
final class SynchronizeConsumeMessageContentsOperation: PostboxCoding {
let messageIds: [MessageId]
init(messageIds: [MessageId]) {
self.messageIds = messageIds
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.messageIds = MessageId.decodeArrayFromBuffer(decoder.decodeBytesForKeyNoCopy("i")!)
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
let buffer = WriteBuffer()
MessageId.encodeArrayToBuffer(self.messageIds, buffer: buffer)
encoder.encodeBytes(buffer, forKey: "i")

View File

@ -10,36 +10,36 @@ enum SynchronizeInstalledStickerPacksOperationNamespace: Int32 {
case masks = 1
}
final class SynchronizeInstalledStickerPacksOperation: Coding {
final class SynchronizeInstalledStickerPacksOperation: PostboxCoding {
let previousPacks: [ItemCollectionId]
init(previousPacks: [ItemCollectionId]) {
self.previousPacks = previousPacks
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.previousPacks = ItemCollectionId.decodeArrayFromBuffer(decoder.decodeBytesForKey("p")!)
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
let buffer = WriteBuffer()
ItemCollectionId.encodeArrayToBuffer(self.previousPacks, buffer: buffer)
encoder.encodeBytes(buffer, forKey: "p")
}
}
final class SynchronizeMarkFeaturedStickerPacksAsSeenOperation: Coding {
final class SynchronizeMarkFeaturedStickerPacksAsSeenOperation: PostboxCoding {
let ids: [ItemCollectionId]
init(ids: [ItemCollectionId]) {
self.ids = ids
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.ids = ItemCollectionId.decodeArrayFromBuffer(decoder.decodeBytesForKey("p")!)
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
let buffer = WriteBuffer()
ItemCollectionId.encodeArrayToBuffer(self.ids, buffer: buffer)
encoder.encodeBytes(buffer, forKey: "p")

View File

@ -7,14 +7,14 @@ import Foundation
import SwiftSignalKit
#endif
final class SynchronizeLocalizationUpdatesOperation: Coding {
final class SynchronizeLocalizationUpdatesOperation: PostboxCoding {
init() {
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
}
}

View File

@ -5,18 +5,18 @@ import Foundation
import Postbox
#endif
final class SynchronizePinnedChatsOperation: Coding {
final class SynchronizePinnedChatsOperation: PostboxCoding {
let previousPeerIds: [PeerId]
init(previousPeerIds: [PeerId]) {
self.previousPeerIds = previousPeerIds
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.previousPeerIds = PeerId.decodeArrayFromBuffer(decoder.decodeBytesForKey("p")!)
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
let buffer = WriteBuffer()
PeerId.encodeArrayToBuffer(self.previousPeerIds, buffer: buffer)
encoder.encodeBytes(buffer, forKey: "p")

View File

@ -13,12 +13,12 @@ private enum SynchronizeSavedGifsOperationContentType: Int32 {
case sync
}
enum SynchronizeSavedGifsOperationContent: Coding {
enum SynchronizeSavedGifsOperationContent: PostboxCoding {
case add(id: Int64, accessHash: Int64)
case remove(id: Int64, accessHash: Int64)
case sync
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("r", orElse: 0) {
case SynchronizeSavedGifsOperationContentType.add.rawValue:
self = .add(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0))
@ -32,7 +32,7 @@ enum SynchronizeSavedGifsOperationContent: Coding {
}
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
switch self {
case let .add(id, accessHash):
encoder.encodeInt32(SynchronizeSavedGifsOperationContentType.add.rawValue, forKey: "r")
@ -48,18 +48,18 @@ enum SynchronizeSavedGifsOperationContent: Coding {
}
}
final class SynchronizeSavedGifsOperation: Coding {
final class SynchronizeSavedGifsOperation: PostboxCoding {
let content: SynchronizeSavedGifsOperationContent
init(content: SynchronizeSavedGifsOperationContent) {
self.content = content
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.content = decoder.decodeObjectForKey("c", decoder: { SynchronizeSavedGifsOperationContent(decoder: $0) }) as! SynchronizeSavedGifsOperationContent
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeObject(self.content, forKey: "c")
}
}

View File

@ -13,12 +13,12 @@ private enum SynchronizeSavedStickersOperationContentType: Int32 {
case sync
}
enum SynchronizeSavedStickersOperationContent: Coding {
enum SynchronizeSavedStickersOperationContent: PostboxCoding {
case add(id: Int64, accessHash: Int64)
case remove(id: Int64, accessHash: Int64)
case sync
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("r", orElse: 0) {
case SynchronizeSavedStickersOperationContentType.add.rawValue:
self = .add(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0))
@ -32,7 +32,7 @@ enum SynchronizeSavedStickersOperationContent: Coding {
}
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
switch self {
case let .add(id, accessHash):
encoder.encodeInt32(SynchronizeSavedStickersOperationContentType.add.rawValue, forKey: "r")
@ -48,18 +48,18 @@ enum SynchronizeSavedStickersOperationContent: Coding {
}
}
final class SynchronizeSavedStickersOperation: Coding {
final class SynchronizeSavedStickersOperation: PostboxCoding {
let content: SynchronizeSavedStickersOperationContent
init(content: SynchronizeSavedStickersOperationContent) {
self.content = content
}
init(decoder: Decoder) {
init(decoder: PostboxDecoder) {
self.content = decoder.decodeObjectForKey("c", decoder: { SynchronizeSavedStickersOperationContent(decoder: $0) }) as! SynchronizeSavedStickersOperationContent
}
func encode(_ encoder: Encoder) {
func encode(_ encoder: PostboxEncoder) {
encoder.encodeObject(self.content, forKey: "c")
}
}

View File

@ -5,7 +5,7 @@ import Foundation
import Postbox
#endif
public struct SynchronizeableChatInputState: Coding, Equatable {
public struct SynchronizeableChatInputState: PostboxCoding, Equatable {
public let replyToMessageId: MessageId?
public let text: String
public let timestamp: Int32
@ -16,7 +16,7 @@ public struct SynchronizeableChatInputState: Coding, Equatable {
self.timestamp = timestamp
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.text = decoder.decodeStringForKey("t", orElse: "")
self.timestamp = decoder.decodeInt32ForKey("s", orElse: 0)
if let messageIdPeerId = decoder.decodeOptionalInt64ForKey("m.p"), let messageIdNamespace = decoder.decodeOptionalInt32ForKey("m.n"), let messageIdId = decoder.decodeOptionalInt32ForKey("m.i") {
@ -26,7 +26,7 @@ public struct SynchronizeableChatInputState: Coding, Equatable {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.text, forKey: "t")
encoder.encodeInt32(self.timestamp, forKey: "s")
if let replyToMessageId = self.replyToMessageId {

View File

@ -102,7 +102,7 @@ public enum TelegramChannelInfo: Equatable {
}
}
fileprivate func encode(encoder: Encoder) {
fileprivate func encode(encoder: PostboxEncoder) {
switch self {
case let .broadcast(info):
encoder.encodeInt32(0, forKey: "i.t")
@ -113,7 +113,7 @@ public enum TelegramChannelInfo: Equatable {
}
}
fileprivate static func decode(decoder: Decoder) -> TelegramChannelInfo {
fileprivate static func decode(decoder: PostboxDecoder) -> TelegramChannelInfo {
let type: Int32 = decoder.decodeInt32ForKey("i.t", orElse: 0)
if type == 0 {
return .broadcast(TelegramChannelBroadcastInfo(flags: TelegramChannelBroadcastFlags(rawValue: decoder.decodeInt32ForKey("i.f", orElse: 0))))
@ -176,7 +176,7 @@ public final class TelegramChannel: Peer {
self.bannedRights = bannedRights
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.id = PeerId(decoder.decodeInt64ForKey("i", orElse: 0))
self.accessHash = decoder.decodeOptionalInt64ForKey("ah")
self.title = decoder.decodeStringForKey("t", orElse: "")
@ -192,7 +192,7 @@ public final class TelegramChannel: Peer {
self.bannedRights = decoder.decodeObjectForKey("br", decoder: { TelegramChannelBannedRights(decoder: $0) }) as? TelegramChannelBannedRights
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.id.toInt64(), forKey: "i")
if let accessHash = self.accessHash {
encoder.encodeInt64(accessHash, forKey: "ah")

View File

@ -63,18 +63,18 @@ public struct TelegramChannelAdminRightsFlags: OptionSet {
}
}
public struct TelegramChannelAdminRights: Coding, Equatable {
public struct TelegramChannelAdminRights: PostboxCoding, Equatable {
public let flags: TelegramChannelAdminRightsFlags
public init(flags: TelegramChannelAdminRightsFlags) {
self.flags = flags
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.flags = TelegramChannelAdminRightsFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0))
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.flags.rawValue, forKey: "f")
}

View File

@ -26,7 +26,7 @@ public struct TelegramChannelBannedRightsFlags: OptionSet {
public static let banEmbedLinks = TelegramChannelBannedRightsFlags(rawValue: 1 << 7)
}
public struct TelegramChannelBannedRights: Coding, Equatable {
public struct TelegramChannelBannedRights: PostboxCoding, Equatable {
public let flags: TelegramChannelBannedRightsFlags
public let untilDate: Int32
@ -35,12 +35,12 @@ public struct TelegramChannelBannedRights: Coding, Equatable {
self.untilDate = untilDate
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.flags = TelegramChannelBannedRightsFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0))
self.untilDate = decoder.decodeInt32ForKey("d", orElse: 0)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.flags.rawValue, forKey: "f")
encoder.encodeInt32(self.untilDate, forKey: "d")
}

View File

@ -73,7 +73,7 @@ public final class TelegramGroup: Peer {
self.version = version
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.id = PeerId(decoder.decodeInt64ForKey("i", orElse: 0))
self.title = decoder.decodeStringForKey("t", orElse: "")
self.photo = decoder.decodeObjectArrayForKey("ph")
@ -92,7 +92,7 @@ public final class TelegramGroup: Peer {
self.version = Int(decoder.decodeInt32ForKey("v", orElse: 0))
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.id.toInt64(), forKey: "i")
encoder.encodeString(self.title, forKey: "t")
encoder.encodeObjectArray(self.photo, forKey: "ph")

View File

@ -12,7 +12,7 @@ public enum PhoneCallDiscardReason: Int32 {
case busy = 3
}
public enum TelegramMediaActionType: Coding, Equatable {
public enum TelegramMediaActionType: PostboxCoding, Equatable {
case unknown
case groupCreated(title: String)
case addedMembers(peerIds: [PeerId])
@ -29,7 +29,7 @@ public enum TelegramMediaActionType: Coding, Equatable {
case gameScore(gameId: Int64, score: Int32)
case phoneCall(callId: Int64, discardReason: PhoneCallDiscardReason?, duration: Int32?)
case paymentSent(currency: String, totalAmount: Int64)
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
let rawValue: Int32 = decoder.decodeInt32ForKey("_rawValue", orElse: 0)
switch rawValue {
case 1:
@ -72,7 +72,7 @@ public enum TelegramMediaActionType: Coding, Equatable {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
switch self {
case .unknown:
break
@ -272,11 +272,11 @@ public final class TelegramMediaAction: Media {
self.action = action
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.action = TelegramMediaActionType(decoder: decoder)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
self.action.encode(encoder)
}

View File

@ -25,7 +25,7 @@ public final class TelegramMediaContact: Media {
}
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.firstName = decoder.decodeStringForKey("n.f", orElse: "")
self.lastName = decoder.decodeStringForKey("n.l", orElse: "")
self.phoneNumber = decoder.decodeStringForKey("pn", orElse: "")
@ -38,7 +38,7 @@ public final class TelegramMediaContact: Media {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.firstName, forKey: "n.f")
encoder.encodeString(self.lastName, forKey: "n.l")
encoder.encodeString(self.phoneNumber, forKey: "pn")

View File

@ -20,11 +20,11 @@ public final class TelegramMediaExpiredContent: Media {
self.data = data
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.data = TelegramMediaExpiredContentData(rawValue: decoder.decodeInt32ForKey("d", orElse: 0))!
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.data.rawValue, forKey: "d")
}

View File

@ -13,11 +13,11 @@ private let typeVideo: Int32 = 4
private let typeAudio: Int32 = 5
private let typeHasLinkedStickers: Int32 = 6
public enum StickerPackReference: Coding, Equatable {
public enum StickerPackReference: PostboxCoding, Equatable {
case id(id: Int64, accessHash: Int64)
case name(String)
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("r", orElse: 0) {
case 0:
self = .id(id: decoder.decodeInt64ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0))
@ -29,7 +29,7 @@ public enum StickerPackReference: Coding, Equatable {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
switch self {
case let .id(id, accessHash):
encoder.encodeInt32(0, forKey: "r")
@ -73,7 +73,7 @@ public struct TelegramMediaVideoFlags: OptionSet {
public static let instantRoundVideo = TelegramMediaVideoFlags(rawValue: 1 << 0)
}
public struct StickerMaskCoords: Coding {
public struct StickerMaskCoords: PostboxCoding {
public let n: Int32
public let x: Double
public let y: Double
@ -86,14 +86,14 @@ public struct StickerMaskCoords: Coding {
self.zoom = zoom
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.n = decoder.decodeInt32ForKey("n", orElse: 0)
self.x = decoder.decodeDoubleForKey("x", orElse: 0.0)
self.y = decoder.decodeDoubleForKey("y", orElse: 0.0)
self.zoom = decoder.decodeDoubleForKey("z", orElse: 0.0)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.n, forKey: "n")
encoder.encodeDouble(self.x, forKey: "x")
encoder.encodeDouble(self.y, forKey: "y")
@ -101,7 +101,7 @@ public struct StickerMaskCoords: Coding {
}
}
public enum TelegramMediaFileAttribute: Coding {
public enum TelegramMediaFileAttribute: PostboxCoding {
case FileName(fileName: String)
case Sticker(displayText: String, packReference: StickerPackReference?, maskData: StickerMaskCoords?)
case ImageSize(size: CGSize)
@ -110,7 +110,7 @@ public enum TelegramMediaFileAttribute: Coding {
case Audio(isVoice: Bool, duration: Int, title: String?, performer: String?, waveform: MemoryBuffer?)
case HasLinkedStickers
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
let type: Int32 = decoder.decodeInt32ForKey("t", orElse: 0)
switch type {
case typeFileName:
@ -137,7 +137,7 @@ public enum TelegramMediaFileAttribute: Coding {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
switch self {
case let .FileName(fileName):
encoder.encodeInt32(typeFileName, forKey: "t")
@ -222,7 +222,7 @@ public final class TelegramMediaFile: Media, Equatable {
self.attributes = attributes
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.fileId = MediaId(decoder.decodeBytesForKeyNoCopy("i")!)
self.resource = decoder.decodeObjectForKey("r") as! TelegramMediaResource
self.previewRepresentations = decoder.decodeObjectArrayForKey("pr")
@ -235,7 +235,7 @@ public final class TelegramMediaFile: Media, Equatable {
self.attributes = decoder.decodeObjectArrayForKey("at")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
let buffer = WriteBuffer()
self.fileId.encodeToBuffer(buffer)
encoder.encodeBytes(buffer, forKey: "i")

View File

@ -29,7 +29,7 @@ public final class TelegramMediaGame: Media {
self.file = file
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.gameId = decoder.decodeInt64ForKey("i", orElse: 0)
self.accessHash = decoder.decodeInt64ForKey("h", orElse: 0)
self.name = decoder.decodeStringForKey("n", orElse: "")
@ -39,7 +39,7 @@ public final class TelegramMediaGame: Media {
self.file = decoder.decodeObjectForKey("f") as? TelegramMediaFile
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.gameId, forKey: "i")
encoder.encodeInt64(self.accessHash, forKey: "h")
encoder.encodeString(self.name, forKey: "n")

View File

@ -23,12 +23,12 @@ public final class TelegramMediaImage: Media, Equatable {
self.representations = representations
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.imageId = MediaId(decoder.decodeBytesForKeyNoCopy("i")!)
self.representations = decoder.decodeObjectArrayForKey("r")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
let buffer = WriteBuffer()
self.imageId.encodeToBuffer(buffer)
encoder.encodeBytes(buffer, forKey: "i")
@ -80,7 +80,7 @@ public func ==(lhs: TelegramMediaImage, rhs: TelegramMediaImage) -> Bool {
return lhs.isEqual(rhs)
}
public final class TelegramMediaImageRepresentation: Coding, Equatable, CustomStringConvertible {
public final class TelegramMediaImageRepresentation: PostboxCoding, Equatable, CustomStringConvertible {
public let dimensions: CGSize
public let resource: TelegramMediaResource
@ -89,12 +89,12 @@ public final class TelegramMediaImageRepresentation: Coding, Equatable, CustomSt
self.resource = resource
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.dimensions = CGSize(width: CGFloat(decoder.decodeInt32ForKey("dx", orElse: 0)), height: CGFloat(decoder.decodeInt32ForKey("dy", orElse: 0)))
self.resource = decoder.decodeObjectForKey("r") as! TelegramMediaResource
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(Int32(self.dimensions.width), forKey: "dx")
encoder.encodeInt32(Int32(self.dimensions.height), forKey: "dy")
encoder.encodeObject(self.resource, forKey: "r")

View File

@ -48,7 +48,7 @@ public final class TelegramMediaInvoice: Media {
self.flags = flags
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.title = decoder.decodeStringForKey("t", orElse: "")
self.description = decoder.decodeStringForKey("d", orElse: "")
self.currency = decoder.decodeStringForKey("c", orElse: "")
@ -64,7 +64,7 @@ public final class TelegramMediaInvoice: Media {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.title, forKey: "t")
encoder.encodeString(self.description, forKey: "d")
encoder.encodeString(self.currency, forKey: "nc")

View File

@ -5,7 +5,7 @@ import Foundation
import Postbox
#endif
public final class NamedGeoPlace: Coding {
public final class NamedGeoPlace: PostboxCoding {
public let country: String?
public let state: String?
public let city: String?
@ -20,7 +20,7 @@ public final class NamedGeoPlace: Coding {
self.street = street
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.country = decoder.decodeOptionalStringForKey("gp_co")
self.state = decoder.decodeOptionalStringForKey("gp_sta")
self.city = decoder.decodeOptionalStringForKey("gp_ci")
@ -28,7 +28,7 @@ public final class NamedGeoPlace: Coding {
self.street = decoder.decodeOptionalStringForKey("gp_str")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
if let country = self.country {
encoder.encodeString(country, forKey: "gp_co")
}
@ -51,7 +51,7 @@ public final class NamedGeoPlace: Coding {
}
}
public final class MapVenue: Coding {
public final class MapVenue: PostboxCoding {
public let title: String
public let address: String?
public let provider: String?
@ -64,14 +64,14 @@ public final class MapVenue: Coding {
self.id = id
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.title = decoder.decodeStringForKey("ti", orElse: "")
self.address = decoder.decodeOptionalStringForKey("ad")
self.provider = decoder.decodeOptionalStringForKey("pr")
self.id = decoder.decodeOptionalStringForKey("id")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.title, forKey: "ti")
if let address = self.address {
@ -102,14 +102,14 @@ public final class TelegramMediaMap: Media {
self.venue = venue
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.latitude = decoder.decodeDoubleForKey("la", orElse: 0.0)
self.longitude = decoder.decodeDoubleForKey("lo", orElse: 0.0)
self.geoPlace = decoder.decodeObjectForKey("gp", decoder: { NamedGeoPlace(decoder: $0) }) as? NamedGeoPlace
self.venue = decoder.decodeObjectForKey("ve", decoder: { MapVenue(decoder: $0) }) as? MapVenue
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeDouble(self.latitude, forKey: "la")
encoder.encodeDouble(self.longitude, forKey: "lo")
if let geoPlace = self.geoPlace {

View File

@ -5,7 +5,7 @@ import Foundation
import Postbox
#endif
public protocol TelegramMediaResource: MediaResource, Coding {
public protocol TelegramMediaResource: MediaResource, PostboxCoding {
func isEqual(to: TelegramMediaResource) -> Bool
}

View File

@ -23,14 +23,14 @@ public class TelegramMediaWebFile: Media {
self.attributes = attributes
}
public required init(decoder: Decoder) {
public required init(decoder: PostboxDecoder) {
self.resource = decoder.decodeObjectForKey("r") as! TelegramMediaResource
self.mimeType = decoder.decodeStringForKey("mt", orElse: "")
self.size = decoder.decodeInt32ForKey("s", orElse: 0)
self.attributes = decoder.decodeObjectArrayForKey("at")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeObject(self.resource, forKey: "r")
encoder.encodeString(self.mimeType, forKey: "mt")
encoder.encodeInt32(self.size, forKey: "s")

View File

@ -5,9 +5,10 @@ import Foundation
import Postbox
#endif
public final class TelegramMediaWebpageLoadedContent: Coding, Equatable {
public final class TelegramMediaWebpageLoadedContent: PostboxCoding, Equatable {
public let url: String
public let displayUrl: String
public let hash: Int32
public let type: String?
public let websiteName: String?
public let title: String?
@ -22,9 +23,10 @@ public final class TelegramMediaWebpageLoadedContent: Coding, Equatable {
public let file: TelegramMediaFile?
public let instantPage: InstantPage?
public init(url: String, displayUrl: String, type: String?, websiteName: String?, title: String?, text: String?, embedUrl: String?, embedType: String?, embedSize: CGSize?, duration: Int?, author: String?, image: TelegramMediaImage?, file: TelegramMediaFile?, instantPage: InstantPage?) {
public init(url: String, displayUrl: String, hash: Int32, type: String?, websiteName: String?, title: String?, text: String?, embedUrl: String?, embedType: String?, embedSize: CGSize?, duration: Int?, author: String?, image: TelegramMediaImage?, file: TelegramMediaFile?, instantPage: InstantPage?) {
self.url = url
self.displayUrl = displayUrl
self.hash = hash
self.type = type
self.websiteName = websiteName
self.title = title
@ -39,9 +41,10 @@ public final class TelegramMediaWebpageLoadedContent: Coding, Equatable {
self.instantPage = instantPage
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.url = decoder.decodeStringForKey("u", orElse: "")
self.displayUrl = decoder.decodeStringForKey("d", orElse: "")
self.hash = decoder.decodeInt32ForKey("ha", orElse: 0)
self.type = decoder.decodeOptionalStringForKey("ty")
self.websiteName = decoder.decodeOptionalStringForKey("ws")
self.title = decoder.decodeOptionalStringForKey("ti")
@ -79,9 +82,10 @@ public final class TelegramMediaWebpageLoadedContent: Coding, Equatable {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.url, forKey: "u")
encoder.encodeString(self.displayUrl, forKey: "d")
encoder.encodeInt32(self.hash, forKey: "ha")
if let type = self.type {
encoder.encodeString(type, forKey: "ty")
} else {
@ -204,7 +208,7 @@ public final class TelegramMediaWebpage: Media, Equatable {
self.content = content
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.webpageId = MediaId(decoder.decodeBytesForKeyNoCopy("i")!)
if decoder.decodeInt32ForKey("ct", orElse: 0) == 0 {
@ -214,7 +218,7 @@ public final class TelegramMediaWebpage: Media, Equatable {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
let buffer = WriteBuffer()
self.webpageId.encodeToBuffer(buffer)
encoder.encodeBytes(buffer, forKey: "i")
@ -287,7 +291,7 @@ func telegramMediaWebpageFromApiWebpage(_ webpage: Api.WebPage) -> TelegramMedia
if let cachedPage = cachedPage {
instantPage = InstantPage(apiPage: cachedPage)
}
return TelegramMediaWebpage(webpageId: MediaId(namespace: Namespaces.Media.CloudWebpage, id: id), content: .Loaded(TelegramMediaWebpageLoadedContent(url: url, displayUrl: displayUrl, type: type, websiteName: siteName, title: title, text: description, embedUrl: embedUrl, embedType: embedType, embedSize: embedSize, duration: webpageDuration, author: author, image: image, file: file, instantPage: instantPage)))
return TelegramMediaWebpage(webpageId: MediaId(namespace: Namespaces.Media.CloudWebpage, id: id), content: .Loaded(TelegramMediaWebpageLoadedContent(url: url, displayUrl: displayUrl, hash: hash, type: type, websiteName: siteName, title: title, text: description, embedUrl: embedUrl, embedType: embedType, embedSize: embedSize, duration: webpageDuration, author: author, image: image, file: file, instantPage: instantPage)))
case .webPageEmpty:
return nil
}

View File

@ -9,7 +9,7 @@ public enum PeerMuteState: Equatable {
case unmuted
case muted(until: Int32)
fileprivate static func decodeInline(_ decoder: Decoder) -> PeerMuteState {
fileprivate static func decodeInline(_ decoder: PostboxDecoder) -> PeerMuteState {
switch decoder.decodeInt32ForKey("m.v", orElse: 0) {
case 0:
return .unmuted
@ -20,7 +20,7 @@ public enum PeerMuteState: Equatable {
}
}
fileprivate func encodeInline(_ encoder: Encoder) {
fileprivate func encodeInline(_ encoder: PostboxEncoder) {
switch self {
case .unmuted:
encoder.encodeInt32(0, forKey: "m.v")
@ -61,7 +61,7 @@ public enum PeerMessageSound: Equatable {
case bundledModern(id: Int32)
case bundledClassic(id: Int32)
static func decodeInline(_ decoder: Decoder) -> PeerMessageSound {
static func decodeInline(_ decoder: PostboxDecoder) -> PeerMessageSound {
switch decoder.decodeInt32ForKey("s.v", orElse: 0) {
case PeerMessageSoundValue.none.rawValue:
return .none
@ -75,7 +75,7 @@ public enum PeerMessageSound: Equatable {
}
}
func encodeInline(_ encoder: Encoder) {
func encodeInline(_ encoder: PostboxEncoder) {
switch self {
case .none:
encoder.encodeInt32(PeerMessageSoundValue.none.rawValue, forKey: "s.v")
@ -134,12 +134,12 @@ public final class TelegramPeerNotificationSettings: PeerNotificationSettings, E
self.messageSound = messageSound
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.muteState = PeerMuteState.decodeInline(decoder)
self.messageSound = PeerMessageSound.decodeInline(decoder)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
self.muteState.encodeInline(encoder)
self.messageSound.encodeInline(encoder)
}

View File

@ -33,7 +33,7 @@ public final class TelegramSecretChat: Peer {
self.messageAutoremoveTimeout = messageAutoremoveTimeout
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.id = PeerId(decoder.decodeInt64ForKey("i", orElse: 0))
self.regularPeerId = PeerId(decoder.decodeInt64ForKey("r", orElse: 0))
self.notificationSettingsPeerId = self.regularPeerId
@ -45,7 +45,7 @@ public final class TelegramSecretChat: Peer {
self.messageAutoremoveTimeout = decoder.decodeOptionalInt32ForKey("at")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.id.toInt64(), forKey: "i")
encoder.encodeInt64(self.regularPeerId.toInt64(), forKey: "r")
encoder.encodeInt64(self.accessHash, forKey: "h")
@ -85,11 +85,11 @@ public final class CachedSecretChatData: CachedPeerData {
self.reportStatus = reportStatus
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.reportStatus = PeerReportStatus(rawValue: decoder.decodeInt32ForKey("rs", orElse: 0))!
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.reportStatus.rawValue, forKey: "rs")
}

View File

@ -35,7 +35,7 @@ public struct BotUserInfoFlags: OptionSet {
public static let requiresGeolocationForInlineRequests = BotUserInfoFlags(rawValue: (1 << 2))
}
public struct BotUserInfo: Coding, Equatable {
public struct BotUserInfo: PostboxCoding, Equatable {
public let flags: BotUserInfoFlags
public let inlinePlaceholder: String?
@ -44,12 +44,12 @@ public struct BotUserInfo: Coding, Equatable {
self.inlinePlaceholder = inlinePlaceholder
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.flags = BotUserInfoFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0))
self.inlinePlaceholder = decoder.decodeOptionalStringForKey("ip")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.flags.rawValue, forKey: "f")
if let inlinePlaceholder = self.inlinePlaceholder {
encoder.encodeString(inlinePlaceholder, forKey: "ip")
@ -107,7 +107,7 @@ public final class TelegramUser: Peer {
self.flags = flags
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.id = PeerId(decoder.decodeInt64ForKey("i", orElse: 0))
let accessHash: Int64 = decoder.decodeInt64ForKey("ah", orElse: 0)
@ -134,7 +134,7 @@ public final class TelegramUser: Peer {
self.flags = UserInfoFlags(rawValue: decoder.decodeInt32ForKey("fl", orElse: 0))
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt64(self.id.toInt64(), forKey: "i")
if let accessHash = self.accessHash {

View File

@ -5,7 +5,7 @@ import Foundation
import Postbox
#endif
public enum UserPresenceStatus: Comparable, Coding {
public enum UserPresenceStatus: Comparable, PostboxCoding {
case none
case present(until: Int32)
case recently
@ -89,7 +89,7 @@ public enum UserPresenceStatus: Comparable, Coding {
}
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("v", orElse: 0) {
case 0:
self = .none
@ -106,7 +106,7 @@ public enum UserPresenceStatus: Comparable, Coding {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
switch self {
case .none:
encoder.encodeInt32(0, forKey: "v")
@ -130,11 +130,11 @@ public final class TelegramUserPresence: PeerPresence, Equatable {
self.status = status
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.status = UserPresenceStatus(decoder: decoder)
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
self.status.encode(encoder)
}

View File

@ -12,10 +12,10 @@ public final class TelegramMediaUnsupported: Media {
init() {
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
}
public func isEqual(_ other: Media) -> Bool {

View File

@ -97,7 +97,7 @@ public enum MessageTextEntityType: Equatable {
}
}
public struct MessageTextEntity: Coding, Equatable {
public struct MessageTextEntity: PostboxCoding, Equatable {
public let range: Range<Int>
public let type: MessageTextEntityType
@ -106,7 +106,7 @@ public struct MessageTextEntity: Coding, Equatable {
self.type = type
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.range = Int(decoder.decodeInt32ForKey("start", orElse: 0)) ..< Int(decoder.decodeInt32ForKey("end", orElse: 0))
let type: Int32 = decoder.decodeInt32ForKey("_rawValue", orElse: 0)
switch type {
@ -137,7 +137,7 @@ public struct MessageTextEntity: Coding, Equatable {
}
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(Int32(self.range.lowerBound), forKey: "start")
encoder.encodeInt32(Int32(self.range.upperBound), forKey: "end")
switch self.type {
@ -195,11 +195,11 @@ public class TextEntitiesMessageAttribute: MessageAttribute, Equatable {
self.entities = entities
}
required public init(decoder: Decoder) {
required public init(decoder: PostboxDecoder) {
self.entities = decoder.decodeObjectArrayWithDecoderForKey("entities")
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeObjectArray(self.entities, forKey: "entities")
}

View File

@ -236,7 +236,7 @@ public func recoverTwoStepVerificationPassword(account: Account, code: String) -
}
}
public struct TemporaryTwoStepPasswordToken: Coding, Equatable {
public struct TemporaryTwoStepPasswordToken: PostboxCoding, Equatable {
public let token: Data
public let validUntilDate: Int32
public let requiresBiometrics: Bool
@ -247,13 +247,13 @@ public struct TemporaryTwoStepPasswordToken: Coding, Equatable {
self.requiresBiometrics = requiresBiometrics
}
public init(decoder: Decoder) {
public init(decoder: PostboxDecoder) {
self.token = decoder.decodeBytesForKey("t")!.makeData()
self.validUntilDate = decoder.decodeInt32ForKey("d", orElse: 0)
self.requiresBiometrics = decoder.decodeInt32ForKey("b", orElse: 0) != 0
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeBytes(MemoryBuffer(data: self.token), forKey: "t")
encoder.encodeInt32(self.validUntilDate, forKey: "d")
encoder.encodeInt32(self.requiresBiometrics ? 1 : 0, forKey: "b")

View File

@ -14,11 +14,11 @@ public class ViewCountMessageAttribute: MessageAttribute {
self.count = count
}
required public init(decoder: Decoder) {
required public init(decoder: PostboxDecoder) {
self.count = Int(decoder.decodeInt32ForKey("c", orElse: 0))
}
public func encode(_ encoder: Encoder) {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(Int32(self.count), forKey: "c")
}
}

View File

@ -31,3 +31,24 @@ public func webpagePreview(account: Account, url: String) -> Signal<TelegramMedi
}
}
}
public func actualizedWebpage(postbox: Postbox, network: Network, webpage: TelegramMediaWebpage) -> Signal<TelegramMediaWebpage, NoError> {
if case let .Loaded(content) = webpage.content {
return network.request(Api.functions.messages.getWebPage(url: content.url, hash: content.hash))
|> `catch` { _ -> Signal<Api.WebPage, NoError> in
return .single(.webPageNotModified)
}
|> mapToSignal { result -> Signal<TelegramMediaWebpage, NoError> in
if let updatedWebpage = telegramMediaWebpageFromApiWebpage(result), case .Loaded = updatedWebpage.content {
return postbox.modify { modifier -> TelegramMediaWebpage in
modifier.updateMedia(updatedWebpage.webpageId, update: updatedWebpage)
return updatedWebpage
}
} else {
return .complete()
}
}
} else {
return .complete()
}
}