db: add telegram_file table
Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
@@ -101,7 +101,7 @@ func NewTelegramClient(ctx context.Context, tc *TelegramConnector, login *bridge
|
||||
dispatcher.OnDeleteMessages(client.onDeleteMessages)
|
||||
dispatcher.OnEditMessage(client.onMessageEdit)
|
||||
|
||||
store := tc.store.GetScopedStore(loginID)
|
||||
store := tc.Store.GetScopedStore(loginID)
|
||||
|
||||
updatesManager := updates.New(updates.Config{
|
||||
OnChannelTooLong: func(channelID int64) {
|
||||
|
||||
@@ -36,8 +36,8 @@ type TelegramConfig struct {
|
||||
type TelegramConnector struct {
|
||||
Bridge *bridgev2.Bridge
|
||||
Config *TelegramConfig
|
||||
Store *store.Container
|
||||
|
||||
store *store.Container
|
||||
useDirectMedia bool
|
||||
}
|
||||
|
||||
@@ -54,12 +54,12 @@ func NewConnector() *TelegramConnector {
|
||||
|
||||
func (tg *TelegramConnector) Init(bridge *bridgev2.Bridge) {
|
||||
// TODO
|
||||
tg.store = store.NewStore(bridge.DB.Database, dbutil.ZeroLogger(bridge.Log.With().Str("db_section", "telegram").Logger()))
|
||||
tg.Store = store.NewStore(bridge.DB.Database, dbutil.ZeroLogger(bridge.Log.With().Str("db_section", "telegram").Logger()))
|
||||
tg.Bridge = bridge
|
||||
}
|
||||
|
||||
func (tg *TelegramConnector) Start(ctx context.Context) error {
|
||||
return tg.store.Upgrade(ctx)
|
||||
return tg.Store.Upgrade(ctx)
|
||||
}
|
||||
|
||||
func (tc *TelegramConnector) LoadUserLogin(ctx context.Context, login *bridgev2.UserLogin) (err error) {
|
||||
|
||||
@@ -8,14 +8,13 @@ import (
|
||||
"github.com/gotd/td/tg"
|
||||
)
|
||||
|
||||
func DownloadDocument(ctx context.Context, client downloader.Client, document *tg.Document) (data []byte, err error) {
|
||||
func DownloadDocument(ctx context.Context, client downloader.Client, document *tg.Document) ([]byte, error) {
|
||||
file := tg.InputDocumentFileLocation{
|
||||
ID: document.GetID(),
|
||||
AccessHash: document.GetAccessHash(),
|
||||
FileReference: document.GetFileReference(),
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
_, err = downloader.NewDownloader().Download(client, &file).Stream(ctx, &buf)
|
||||
data = buf.Bytes()
|
||||
return
|
||||
_, err := downloader.NewDownloader().Download(client, &file).Stream(ctx, &buf)
|
||||
return buf.Bytes(), err
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ func (p *PhoneLogin) SubmitUserInput(ctx context.Context, input map[string]strin
|
||||
func (p *PhoneLogin) handleAuthSuccess(ctx context.Context, authorization *tg.AuthAuthorization) (*bridgev2.LoginStep, error) {
|
||||
// Now that we have the Telegram user ID, store it in the database and
|
||||
// close the login client.
|
||||
sessionStore := p.main.store.GetScopedStore(authorization.User.GetID())
|
||||
sessionStore := p.main.Store.GetScopedStore(authorization.User.GetID())
|
||||
var sessionData []byte
|
||||
sessionData, err := p.storage.Bytes(sessionData)
|
||||
if err != nil {
|
||||
|
||||
@@ -134,9 +134,8 @@ func (mc *MessageConverter) webpageToBeeperLinkPreview(ctx context.Context, inte
|
||||
}
|
||||
|
||||
if pc, ok := webpage.GetPhoto(); ok && pc.TypeID() == tg.PhotoTypeID {
|
||||
photo := pc.(*tg.Photo)
|
||||
var data []byte
|
||||
data, preview.ImageWidth, preview.ImageHeight, preview.ImageType, err = download.DownloadPhoto(ctx, mc.client.API(), photo)
|
||||
data, preview.ImageWidth, preview.ImageHeight, preview.ImageType, err = download.DownloadPhoto(ctx, mc.client.API(), pc.(*tg.Photo))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -328,13 +328,22 @@ func (t *TelegramClient) getReactionLimit(ctx context.Context, sender networkid.
|
||||
// TODO move this to emojis package
|
||||
func (t *TelegramClient) transferEmojisToMatrix(ctx context.Context, customEmojiIDs []int64) (result map[networkid.EmojiID]string, err error) {
|
||||
result, customEmojiIDs = emojis.ConvertKnownEmojis(customEmojiIDs)
|
||||
fmt.Printf("leftover custom emoji ids %+v\n", customEmojiIDs)
|
||||
for _, customEmojiID := range customEmojiIDs {
|
||||
fmt.Printf("customEmojiID %d\n", customEmojiID)
|
||||
locationID := fmt.Sprintf("%d", customEmojiID)
|
||||
if file, err := t.main.Store.TelegramFile.GetByLocationID(ctx, locationID); err != nil {
|
||||
return nil, fmt.Errorf("failed to search for Telegram file by location ID")
|
||||
} else if file == nil {
|
||||
// TODO download shit
|
||||
} else {
|
||||
result[ids.MakeEmojiIDFromDocumentID(customEmojiID)] = file.MXC
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (t *TelegramClient) handleTelegramParsedReactionsLocked(ctx context.Context, msg *database.Message, reactions map[networkid.UserID][]tg.MessagePeerReaction, customEmojiIDs []int64, isFull bool, onlyUserID *networkid.UserID, timestamp *time.Time) error {
|
||||
// TODO deal with the custom emoji IDs
|
||||
fmt.Printf("custom emoji IDs %v\n", customEmojiIDs)
|
||||
customEmojis, err := t.transferEmojisToMatrix(ctx, customEmojiIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user