media: make all media direct downloadable

The only exception is emojis.

Also changed direct download encoding field names to be more generic
when used in mixed manner depending on peer type.

Direct downloads are still somewhat inefficient as they require an API
round trip to succeed but we can cache things in the database if needed.
This commit is contained in:
Toni Spets
2025-05-05 17:01:31 +03:00
parent 9d3e9df57e
commit 7e75c8ef83
8 changed files with 341 additions and 150 deletions
+7 -7
View File
@@ -181,7 +181,6 @@ func (t *TelegramClient) onUpdateNewMessage(ctx context.Context, entities tg.Ent
},
StreamOrder: int64(msg.GetID()),
}
switch action := msg.Action.(type) {
case *tg.MessageActionChatEditTitle:
t.main.Bridge.QueueRemoteEvent(t.userLogin, &simplevent.ChatInfoChange{
@@ -189,9 +188,12 @@ func (t *TelegramClient) onUpdateNewMessage(ctx context.Context, entities tg.Ent
ChatInfoChange: &bridgev2.ChatInfoChange{ChatInfo: &bridgev2.ChatInfo{Name: &action.Title}},
})
case *tg.MessageActionChatEditPhoto:
// FIXME
chatID := msg.PeerID.(*tg.PeerChat).ChatID
t.main.Bridge.QueueRemoteEvent(t.userLogin, &simplevent.ChatInfoChange{
EventMeta: eventMeta.WithType(bridgev2.RemoteEventChatInfoChange),
ChatInfoChange: &bridgev2.ChatInfoChange{ChatInfo: &bridgev2.ChatInfo{Avatar: t.avatarFromPhoto(ctx, action.Photo)}},
ChatInfoChange: &bridgev2.ChatInfoChange{ChatInfo: &bridgev2.ChatInfo{Avatar: t.avatarFromPhoto(ctx, ids.PeerTypeChat, chatID, action.Photo)}},
})
case *tg.MessageActionChatDeletePhoto:
t.main.Bridge.QueueRemoteEvent(t.userLogin, &simplevent.ChatInfoChange{
@@ -689,11 +691,9 @@ func (t *TelegramClient) updateChannel(ctx context.Context, channel *tg.Channel)
var avatar *bridgev2.Avatar
if photo, ok := channel.GetPhoto().(*tg.ChatPhoto); ok {
avatar = &bridgev2.Avatar{
ID: ids.MakeAvatarID(photo.PhotoID),
Get: func(ctx context.Context) (data []byte, err error) {
return media.NewTransferer(t.client.API()).WithChannelPhoto(channel.ID, channel.AccessHash, photo.PhotoID).DownloadBytes(ctx)
},
avatar, err = t.convertChatPhoto(ctx, channel.ID, channel.AccessHash, photo)
if err != nil {
return nil, err
}
}