Home telegram - messageHistoryMetadataTable
Post
Cancel

telegram - messageHistoryMetadataTable

MessageHistoryMetadataTable

class MessageHistoryMetadataTable:Table

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
static func tableSpec(_ id: Int32) -> ValueBoxTable {
    return ValueBoxTable(id: id, keyType: .binary, compactValuesOnCreation: true)
}

// peer history intialized key
let sharedPeerHistoryInitializedKey = ValueBoxKey(length: 8 + 1)
// peer thread hole index initialized key
let sharedPeerThreadHoleIndexInitializedKey = ValueBoxKey(length: 8 + 1 + 8)
// group feed index initialized key
let sharedGroupFeedIndexInitializedKey = ValueBoxKey(length: 4 + 1)
// chat list group history initialized key
let sharedChatListGroupHistoryInitializedKey = ValueBoxKey(length: 4 + 1)
// peer next messageId by namespace
let sharedPeerNextMessageIdByNamespaceKey = ValueBoxKey(length: 8 + 1 + 4)

// shared buffer
let sharedBuffer = WriteBuffer()

// initialized chat list
private var initializedChatList = Set<InitializedChatListKey>()

// initialized history peer ids
private var initializedHistoryPeerIds = Set<PeerId>()

// initialized history (peer id, Set<MessageTags>
private var initializedHistoryPeerIdTags: [PeerId: Set<MessageTags>] = [:]

// initialized group feed index ids
private var initializedGroupFeedIndexIds = Set<PeerGroupId>()

// peer next message id by namespace
private var peerNextMessageIdByNamespace: [PeerId: [MessageId.Namespace: MessageId.Id]] = [:]

// update peer next message id by namespace
private var updatedPeerNextMessageIdByNamespace: [PeerId: Set<MessageId.Namespace>] = [:]

// next message stable id
private var nextMessageStableId: UInt32?
// next message stable id updated
private var nextMessageStableIdUpdated = false

// current pinned chat peerIds
private var currentPinnedChatPeerIds: Set<PeerId>?
// current pinned chat peer ids updated
private var currentPinnedChatPeerIdsUpdated = false

private func peerHistoryInitializedKey(_ id: PeerId) -> ValueBoxKey {
    self.sharedPeerHistoryInitializedKey.setInt64(0, value: id.toInt64())
    self.sharedPeerHistoryInitializedKey.setInt8(8, value: MetadataPrefix.PeerHistoryInitialized.rawValue)
    return self.sharedPeerHistoryInitializedKey
}

private func peerThreadHoleIndexInitializedKey(peerId: PeerId, threadId: Int64) -> ValueBoxKey {
    self.sharedPeerThreadHoleIndexInitializedKey.setInt64(0, value: peerId.toInt64())
    self.sharedPeerThreadHoleIndexInitializedKey.setInt8(8, value: MetadataPrefix.PeerHistoryThreadHoleIndexInitialized.rawValue)
    self.sharedPeerThreadHoleIndexInitializedKey.setInt64(0, value: threadId)
    return self.sharedPeerThreadHoleIndexInitializedKey
}
This post is licensed under CC BY 4.0 by the author.