Repository navigation
handle*: implement time-limited media with new interface - #1107
Conversation
|
|
||
| func (tc *TelegramClient) viewLimitedFileCaps(base event.FileFeatureMap) event.FileFeatureMap { | ||
| limits := make([]*event.BeeperViewLimitedMedia, 0, 61) | ||
| if !tc.main.Config.DisableViewOnce { |
There was a problem hiding this comment.
This config option doesn't need to be considered anywhere
| "go.mau.fi/mautrix-telegram/pkg/connector/ids" | ||
| ) | ||
|
|
||
| const telegramViewOnceTTL = 2147483647 |
There was a problem hiding this comment.
The telegram docs define this as 0x7FFFFFFF, better to use that literal so it's obvious it's the same value
| const telegramViewOnceTTL = 2147483647 | |
| const telegramViewOnceTTL = 0x7FFFFFFF |
| return telegramViewOnceTTL, nil | ||
| } | ||
| if limit.Type == "time" && limit.Count == 0 && limit.Time.Duration >= time.Second && limit.Time.Duration <= time.Minute && limit.Time.Duration%time.Second == 0 { | ||
| return int(limit.Time.Duration / time.Second), nil |
There was a problem hiding this comment.
| return int(limit.Time.Duration / time.Second), nil | |
| return int(limit.Time.Duration.Seconds()), nil |
| StreamOrder: int64(tgMessageID), | ||
| PostSave: func(ctx context.Context, _ *database.Message) { | ||
| tc.applyViewLimitedMediaRead(ctx, msg.Portal, messageID) | ||
| }, |
There was a problem hiding this comment.
Outgoing view limited media isn't limited
| case event.MsgAudio: | ||
| if msg.Content.MSC3245Voice == nil { | ||
| return 0, bridgev2.ErrUnsupportedViewLimitedType | ||
| } |
There was a problem hiding this comment.
These checks look unnecessary since bridgev2 already does them. (force_document is an edge case, but I don't think anything uses that anyway, sending as m.file is the recommended way to force a document)
| } | ||
| pending := &pendingViewLimitedRead{} | ||
| tc.viewLimitedReads[messageID] = pending | ||
| // Difference updates may report reads before new messages; uploads may also still be running. |
There was a problem hiding this comment.
The first sentence sounds extremely sus. The second sentence is a matter of using the existing portal event queue instead of inventing a new one (and even that isn't actually necessary when the portal event buffer is disabled).
| var viewLimitedTTL int | ||
| if msg.Content.BeeperViewLimited != nil { | ||
| if viewLimitedTTL, err = telegramMediaTTL(msg.Content.BeeperViewLimited); err != nil { | ||
| return nil, err | ||
| } | ||
| } |
There was a problem hiding this comment.
| var viewLimitedTTL int | |
| if msg.Content.BeeperViewLimited != nil { | |
| if viewLimitedTTL, err = telegramMediaTTL(msg.Content.BeeperViewLimited); err != nil { | |
| return nil, err | |
| } | |
| } | |
| viewLimitedTTL, err := telegramMediaTTL(msg.Content.BeeperViewLimited) | |
| if err != nil { | |
| return nil, err | |
| } |
|
|
||
| func (tc *TelegramClient) HandleMatrixEdit(ctx context.Context, msg *bridgev2.MatrixEdit) error { | ||
| if msg.Content.BeeperViewLimited != nil || msg.EditTarget.Metadata.(*MessageMetadata).ViewLimited != nil { | ||
| return bridgev2.ErrUnsupportedViewLimitedType |
There was a problem hiding this comment.
| return bridgev2.ErrUnsupportedViewLimitedType | |
| return fmt.Errorf("%w: edits not allowed", bridgev2.ErrUnsupportedViewLimitedType) |
| cfg.Height+cfg.Width > 10000 | ||
| } | ||
| if forceDocument && content.MsgType == event.MsgImage && content.BeeperViewLimited != nil { | ||
| return bridgev2.ErrUnsupportedViewLimitedType |
There was a problem hiding this comment.
| return bridgev2.ErrUnsupportedViewLimitedType | |
| return fmt.Errorf("%w: force_document not allowed", bridgev2.ErrUnsupportedViewLimitedType) |
| } | ||
|
|
||
| topicID := tc.getTopicID(ctx, msg.PeerID, msg.ReplyTo) | ||
| tc.recentMessageRooms.Push(ids.GetMessageIDFromMessage(msg), tc.makePortalKeyFromPeer(msg.PeerID, topicID)) |
There was a problem hiding this comment.
This is a merge conflict with main
There was a problem hiding this comment.
This file is now short enough that it could just be a part of handlematrix and handletelegram where all the other event handlers are
tulir
left a comment
There was a problem hiding this comment.
Code looks good, still has some merge conflicts (should rebase properly, the current diff shows some changes that are already on main)
|
|
||
| func (tc *TelegramClient) GetCapabilities(ctx context.Context, portal *bridgev2.Portal) *event.RoomFeatures { | ||
| baseID := "fi.mau.telegram.capabilities.2026_05_27" | ||
| baseID := "fi.mau.telegram.capabilities.2026_10_01" |
There was a problem hiding this comment.
This and GetBridgeInfoVersion will need to be bumped since that's one of the new merge conflicts
72bbbfd to
4a8b2ea
Compare
Supports view once and view X seconds photos and videos
Checklist