move gotd fork into repo. (#111)
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package constant
|
||||
|
||||
// Test-only credentials. Can be used with AddrTest and TestAuth to
|
||||
// test authentication.
|
||||
//
|
||||
// Reference:
|
||||
// - https://github.com/telegramdesktop/tdesktop/blob/5f665b8ecb48802cd13cfb48ec834b946459274a/docs/api_credentials.md
|
||||
const (
|
||||
TestAppID = 17349
|
||||
TestAppHash = "344583e45741c457fe1862106095a5eb"
|
||||
)
|
||||
@@ -0,0 +1,2 @@
|
||||
// Package constant wraps Telegram-defined constants.
|
||||
package constant
|
||||
@@ -0,0 +1,25 @@
|
||||
package constant
|
||||
|
||||
const (
|
||||
// ServiceNotificationUserID is service notification user ID.
|
||||
ServiceNotificationUserID = 777000
|
||||
// RepliesBotUserID is special user ID of Replies.
|
||||
//
|
||||
// See https://t.me/replies.
|
||||
RepliesBotUserID = 1271266957
|
||||
// TestRepliesBotUserID is RepliesBotUserID for test DCs.
|
||||
TestRepliesBotUserID = 708513
|
||||
// AnonymousBotUserID is user ID of the bot which is shown as the sender of anonymous group messages
|
||||
// when viewed from an outdated client.
|
||||
//
|
||||
// See https://t.me/GroupAnonymousBot.
|
||||
AnonymousBotUserID = 1087968824
|
||||
// TestAnonymousBotUserID is AnonymousBotUserID for test DCs.
|
||||
TestAnonymousBotUserID = 552888
|
||||
// ChannelBotUserID is user ID of sender of message which sent by anonymous user (as channel).
|
||||
//
|
||||
// See https://t.me/Channel_Bot.
|
||||
ChannelBotUserID = 136817688
|
||||
// TestChannelBotUserID is ChannelBotUserID for test DCs.
|
||||
TestChannelBotUserID = 936174
|
||||
)
|
||||
@@ -0,0 +1,64 @@
|
||||
package constant
|
||||
|
||||
const (
|
||||
// MaxTDLibChatID is maximum chat TDLib ID.
|
||||
MaxTDLibChatID = 999999999999
|
||||
// MaxTDLibChannelID is maximum channel TDLib ID.
|
||||
MaxTDLibChannelID = 1000000000000 - int64(1<<31)
|
||||
// ZeroTDLibChannelID is minimum channel TDLib ID.
|
||||
ZeroTDLibChannelID = -1000000000000
|
||||
// ZeroTDLibSecretChatID is minimum secret chat TDLib ID.
|
||||
ZeroTDLibSecretChatID = -2000000000000
|
||||
// MaxTDLibUserID is maximum user TDLib ID.
|
||||
MaxTDLibUserID = (1 << 40) - 1
|
||||
)
|
||||
|
||||
// TDLibPeerID is TDLib's peer ID.
|
||||
type TDLibPeerID int64
|
||||
|
||||
// User sets TDLibPeerID value as user.
|
||||
func (id *TDLibPeerID) User(p int64) {
|
||||
*id = TDLibPeerID(p)
|
||||
}
|
||||
|
||||
// Chat sets TDLibPeerID value as chat.
|
||||
func (id *TDLibPeerID) Chat(p int64) {
|
||||
*id = TDLibPeerID(-p)
|
||||
}
|
||||
|
||||
// Channel sets TDLibPeerID value as channel.
|
||||
func (id *TDLibPeerID) Channel(p int64) {
|
||||
*id = TDLibPeerID(ZeroTDLibChannelID + (p * -1))
|
||||
}
|
||||
|
||||
// ToPlain converts TDLib ID to plain ID.
|
||||
func (id TDLibPeerID) ToPlain() (r int64) {
|
||||
switch {
|
||||
case id.IsUser():
|
||||
r = int64(id)
|
||||
case id.IsChat():
|
||||
r = int64(-id)
|
||||
case id.IsChannel():
|
||||
r = int64(id) - ZeroTDLibChannelID
|
||||
r = -r
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// IsUser whether that given ID is user ID.
|
||||
func (id TDLibPeerID) IsUser() bool {
|
||||
return id > 0 && id <= MaxTDLibUserID
|
||||
}
|
||||
|
||||
// IsChat whether that given ID is chat ID.
|
||||
func (id TDLibPeerID) IsChat() bool {
|
||||
return id < 0 && -MaxTDLibChatID <= id
|
||||
}
|
||||
|
||||
// IsChannel whether that given ID is channel ID.
|
||||
func (id TDLibPeerID) IsChannel() bool {
|
||||
return id < 0 &&
|
||||
id != ZeroTDLibChannelID &&
|
||||
!id.IsChat() &&
|
||||
ZeroTDLibChannelID-TDLibPeerID(MaxTDLibChannelID) <= id
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package constant
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestIsID(t *testing.T) {
|
||||
tests := []struct {
|
||||
id TDLibPeerID
|
||||
user bool
|
||||
chat bool
|
||||
channel bool
|
||||
}{
|
||||
{id: 309570373, user: true},
|
||||
{id: 140267078, user: true},
|
||||
{id: -365219918, chat: true},
|
||||
{id: -1001228418968, channel: true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(strconv.FormatInt(int64(tt.id), 10), func(t *testing.T) {
|
||||
a := require.New(t)
|
||||
|
||||
a.Equal(tt.user, tt.id.IsUser())
|
||||
a.Equal(tt.chat, tt.id.IsChat())
|
||||
a.Equal(tt.channel, tt.id.IsChannel())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTDLibPeerID_ToPlain(t *testing.T) {
|
||||
tests := []struct {
|
||||
id TDLibPeerID
|
||||
wantR int64
|
||||
}{
|
||||
{309570373, 309570373},
|
||||
{140267078, 140267078},
|
||||
{-365219918, 365219918},
|
||||
{-1001228418968, 1228418968},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(strconv.FormatInt(int64(tt.id), 10), func(t *testing.T) {
|
||||
a := require.New(t)
|
||||
plain := tt.id.ToPlain()
|
||||
a.Equal(tt.wantR, plain)
|
||||
|
||||
switch {
|
||||
case tt.id.IsUser():
|
||||
var tdlibID TDLibPeerID
|
||||
tdlibID.User(plain)
|
||||
a.Equal(tt.id, tdlibID)
|
||||
case tt.id.IsChat():
|
||||
var tdlibID TDLibPeerID
|
||||
tdlibID.Chat(plain)
|
||||
a.Equal(tt.id, tdlibID)
|
||||
case tt.id.IsChannel():
|
||||
var tdlibID TDLibPeerID
|
||||
tdlibID.Channel(plain)
|
||||
a.Equal(tt.id, tdlibID)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package constant
|
||||
|
||||
// https://core.telegram.org/api/files#uploading-files
|
||||
const (
|
||||
// UploadMaxSmallSize is maximum size of small file.
|
||||
//
|
||||
// Use upload.saveBigFilePart in case the full size of the file is more than 10 MB
|
||||
// and upload.saveFilePart for smaller files
|
||||
UploadMaxSmallSize = 10 * 1024 * 1024 // 10 MB
|
||||
// UploadMaxParts is maximum parts count.
|
||||
//
|
||||
// Each part should have a sequence number, file_part, with a value ranging from 0 to 3,999.
|
||||
UploadMaxParts = 3999
|
||||
// UploadPadding is part size padding.
|
||||
//
|
||||
// `part_size % 1024 = 0` (divisible by 1KB)
|
||||
UploadPadding = 1024
|
||||
// UploadMaxPartSize is maximum size of single part.
|
||||
//
|
||||
// `524288 % part_size = 0` (512KB must be evenly divisible by part_size)
|
||||
UploadMaxPartSize = 524288
|
||||
)
|
||||
Reference in New Issue
Block a user