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:
Adam Van Ymeren
2025-06-27 20:03:37 -07:00
committed by GitHub
parent 0952df0244
commit 7a04f298d2
19264 changed files with 1539697 additions and 84 deletions
@@ -0,0 +1,149 @@
package peers
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
)
func TestMemoryStorage(t *testing.T) {
ctx := context.Background()
a := require.New(t)
k := Key{
Prefix: usersPrefix,
ID: 1,
}
v := Value{
AccessHash: 10,
}
phone := "phone"
var m InmemoryStorage
_, found, err := m.Find(ctx, k)
a.NoError(err)
a.False(found)
a.NoError(m.Save(ctx, k, v))
v2, found, err := m.Find(ctx, k)
a.NoError(err)
a.True(found)
a.Equal(v, v2)
_, _, found, err = m.FindPhone(ctx, phone)
a.NoError(err)
a.False(found)
a.NoError(m.SavePhone(ctx, phone, k))
k2, v2, found, err := m.FindPhone(ctx, phone)
a.NoError(err)
a.True(found)
a.Equal(k, k2)
a.Equal(v, v2)
hash, err := m.GetContactsHash(ctx)
a.NoError(err)
a.Zero(hash)
a.NoError(m.SaveContactsHash(ctx, 1))
hash, err = m.GetContactsHash(ctx)
a.NoError(err)
a.Equal(int64(1), hash)
}
func TestInmemoryCache(t *testing.T) {
ctx := context.Background()
a := require.New(t)
var m InmemoryCache
{
value := &tg.User{ID: 10}
_, found, err := m.FindUser(ctx, value.GetID())
a.NoError(err)
a.False(found)
a.NoError(m.SaveUsers(ctx, value))
r, found, err := m.FindUser(ctx, value.GetID())
a.NoError(err)
a.True(found)
a.Equal(value, r)
}
{
value := &tg.UserFull{ID: 10}
_, found, err := m.FindUserFull(ctx, value.GetID())
a.NoError(err)
a.False(found)
a.NoError(m.SaveUserFulls(ctx, value))
r, found, err := m.FindUserFull(ctx, value.GetID())
a.NoError(err)
a.True(found)
a.Equal(value, r)
}
{
value := &tg.Chat{ID: 10}
_, found, err := m.FindChat(ctx, value.GetID())
a.NoError(err)
a.False(found)
a.NoError(m.SaveChats(ctx, value))
r, found, err := m.FindChat(ctx, value.GetID())
a.NoError(err)
a.True(found)
a.Equal(value, r)
}
{
value := &tg.ChatFull{ID: 10}
_, found, err := m.FindChatFull(ctx, value.GetID())
a.NoError(err)
a.False(found)
a.NoError(m.SaveChatFulls(ctx, value))
r, found, err := m.FindChatFull(ctx, value.GetID())
a.NoError(err)
a.True(found)
a.Equal(value, r)
}
{
value := &tg.Channel{ID: 10}
_, found, err := m.FindChannel(ctx, value.GetID())
a.NoError(err)
a.False(found)
a.NoError(m.SaveChannels(ctx, value))
r, found, err := m.FindChannel(ctx, value.GetID())
a.NoError(err)
a.True(found)
a.Equal(value, r)
}
{
value := &tg.ChannelFull{ID: 10}
_, found, err := m.FindChannelFull(ctx, value.GetID())
a.NoError(err)
a.False(found)
a.NoError(m.SaveChannelFulls(ctx, value))
r, found, err := m.FindChannelFull(ctx, value.GetID())
a.NoError(err)
a.True(found)
a.Equal(value, r)
}
}