@@ -3,14 +3,24 @@ package constant
33const (
44 // MaxTDLibChatID is maximum chat TDLib ID.
55 MaxTDLibChatID = 999999999999
6- // MaxTDLibChannelID is maximum channel TDLib ID.
7- MaxTDLibChannelID = 1000000000000 - int64 (1 << 31 )
8- // ZeroTDLibChannelID is minimum channel TDLib ID .
6+ // MaxTDLibChannelID is maximum channel TDLib ID (non-monoforum) .
7+ MaxTDLibChannelID = 1000000000000 - int64 (1 << 31 ) // 997852516352
8+ // ZeroTDLibChannelID is base for channel IDs .
99 ZeroTDLibChannelID = - 1000000000000
1010 // ZeroTDLibSecretChatID is minimum secret chat TDLib ID.
1111 ZeroTDLibSecretChatID = - 2000000000000
1212 // MaxTDLibUserID is maximum user TDLib ID.
1313 MaxTDLibUserID = (1 << 40 ) - 1
14+
15+ // MinMTProtoMonoforumID is the minimum MTProto ID for monoforums.
16+ MinMTProtoMonoforumID = 1002147483649
17+ // MaxMTProtoMonoforumID is the maximum MTProto ID for monoforums.
18+ MaxMTProtoMonoforumID = 3000000000000
19+
20+ // MinBotAPIMonoforumID = -(1e12 + MaxMTProtoMonoforumID)
21+ MinBotAPIMonoforumID = - 4000000000000
22+ // MaxBotAPIMonoforumID = -(1e12 + MinMTProtoMonoforumID)
23+ MaxBotAPIMonoforumID = - 2002147483649
1424)
1525
1626// TDLibPeerID is TDLib's peer ID.
@@ -26,21 +36,20 @@ func (id *TDLibPeerID) Chat(p int64) {
2636 * id = TDLibPeerID (- p )
2737}
2838
29- // Channel sets TDLibPeerID value as channel.
39+ // Channel sets TDLibPeerID value as channel (including monoforum) .
3040func (id * TDLibPeerID ) Channel (p int64 ) {
31- * id = TDLibPeerID (ZeroTDLibChannelID + (p * - 1 ) )
41+ * id = TDLibPeerID (ZeroTDLibChannelID - p ) // same as ZeroTDLibChannelID + (p * -1)
3242}
3343
34- // ToPlain converts TDLib ID to plain ID.
44+ // ToPlain converts TDLib ID to plain (MTProto) ID.
3545func (id TDLibPeerID ) ToPlain () (r int64 ) {
3646 switch {
3747 case id .IsUser ():
3848 r = int64 (id )
3949 case id .IsChat ():
40- r = int64 (- id )
50+ r = - int64 (id )
4151 case id .IsChannel ():
42- r = int64 (id ) - ZeroTDLibChannelID
43- r = - r
52+ r = - (int64 (id ) - ZeroTDLibChannelID )
4453 }
4554 return r
4655}
@@ -52,13 +61,26 @@ func (id TDLibPeerID) IsUser() bool {
5261
5362// IsChat whether that given ID is chat ID.
5463func (id TDLibPeerID ) IsChat () bool {
55- return id < 0 && - MaxTDLibChatID <= id
64+ return id < 0 && id >= - MaxTDLibChatID
65+ }
66+
67+ // IsMonoforum checks if the ID belongs to a monoforum.
68+ func (id TDLibPeerID ) IsMonoforum () bool {
69+ return id >= MinBotAPIMonoforumID && id <= MaxBotAPIMonoforumID
5670}
5771
58- // IsChannel whether that given ID is channel ID.
72+ // IsChannel whether that given ID is channel ID (including monoforums) .
5973func (id TDLibPeerID ) IsChannel () bool {
60- return id < 0 &&
61- id != ZeroTDLibChannelID &&
62- ! id .IsChat () &&
63- ZeroTDLibChannelID - TDLibPeerID (MaxTDLibChannelID ) <= id
74+ if id >= 0 {
75+ return false
76+ }
77+ if id == ZeroTDLibChannelID || id .IsChat () {
78+ return false
79+ }
80+ // Regular channels: -1997852516352 to -1000000000001
81+ if id >= - 1997852516352 && id <= - 1000000000001 {
82+ return true
83+ }
84+ // Monoforums: -4000000000000 to -2002147483649
85+ return id >= MinBotAPIMonoforumID && id <= MaxBotAPIMonoforumID
6486}
0 commit comments