Skip to content

handle*: implement time-limited media with new interface - #1107

Merged
highesttt merged 4 commits into
mainfrom
highest/plat-38977
Oct 6, 2026
Merged

highesttt merged 4 commits into
mainfrom
highest/plat-38977

Conversation

@highesttt

@highesttt highesttt commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Supports view once and view X seconds photos and videos

Checklist

@highesttt
highesttt requested a review from tulir October 1, 2026 22:10
Comment thread pkg/connector/capabilities.go Outdated

func (tc *TelegramClient) viewLimitedFileCaps(base event.FileFeatureMap) event.FileFeatureMap {
limits := make([]*event.BeeperViewLimitedMedia, 0, 61)
if !tc.main.Config.DisableViewOnce {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This config option doesn't need to be considered anywhere

Comment thread pkg/connector/capabilities.go
Comment thread pkg/connector/viewlimited.go Outdated
"go.mau.fi/mautrix-telegram/pkg/connector/ids"
)

const telegramViewOnceTTL = 2147483647

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The telegram docs define this as 0x7FFFFFFF, better to use that literal so it's obvious it's the same value

Suggested change
const telegramViewOnceTTL = 2147483647
const telegramViewOnceTTL = 0x7FFFFFFF

Comment thread pkg/connector/viewlimited.go Outdated
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return int(limit.Time.Duration / time.Second), nil
return int(limit.Time.Duration.Seconds()), nil

Comment thread pkg/connector/handlematrix.go Outdated
StreamOrder: int64(tgMessageID),
PostSave: func(ctx context.Context, _ *database.Message) {
tc.applyViewLimitedMediaRead(ctx, msg.Portal, messageID)
},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outgoing view limited media isn't limited

Comment thread pkg/connector/viewlimited.go Outdated
case event.MsgAudio:
if msg.Content.MSC3245Voice == nil {
return 0, bridgev2.ErrUnsupportedViewLimitedType
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread pkg/connector/viewlimited.go Outdated
}
pending := &pendingViewLimitedRead{}
tc.viewLimitedReads[messageID] = pending
// Difference updates may report reads before new messages; uploads may also still be running.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@highesttt
highesttt requested a review from tulir October 2, 2026 02:03
Comment thread pkg/connector/handlematrix.go Outdated
Comment on lines +466 to +471
var viewLimitedTTL int
if msg.Content.BeeperViewLimited != nil {
if viewLimitedTTL, err = telegramMediaTTL(msg.Content.BeeperViewLimited); err != nil {
return nil, err
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
}

Comment thread pkg/connector/handlematrix.go Outdated

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return bridgev2.ErrUnsupportedViewLimitedType
return fmt.Errorf("%w: edits not allowed", bridgev2.ErrUnsupportedViewLimitedType)

Comment thread pkg/connector/handlematrix.go Outdated
cfg.Height+cfg.Width > 10000
}
if forceDocument && content.MsgType == event.MsgImage && content.BeeperViewLimited != nil {
return bridgev2.ErrUnsupportedViewLimitedType

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return bridgev2.ErrUnsupportedViewLimitedType
return fmt.Errorf("%w: force_document not allowed", bridgev2.ErrUnsupportedViewLimitedType)

Comment thread pkg/connector/handletelegram.go Outdated
}

topicID := tc.getTopicID(ctx, msg.PeerID, msg.ReplyTo)
tc.recentMessageRooms.Push(ids.GetMessageIDFromMessage(msg), tc.makePortalKeyFromPeer(msg.PeerID, topicID))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a merge conflict with main

Comment thread pkg/connector/viewlimited.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is now short enough that it could just be a part of handlematrix and handletelegram where all the other event handlers are

@highesttt
highesttt requested a review from tulir October 5, 2026 13:55
@tulir tulir changed the title media: implement view limited media handle*: implement time-limited media Oct 5, 2026
@tulir tulir changed the title handle*: implement time-limited media handle*: implement time-limited media with new interface Oct 5, 2026

@tulir tulir left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good, still has some merge conflicts (should rebase properly, the current diff shows some changes that are already on main)

Comment thread pkg/connector/capabilities.go Outdated

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"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and GetBridgeInfoVersion will need to be bumped since that's one of the new merge conflicts

@highesttt
highesttt merged commit 9b2a6e3 into main Oct 6, 2026
11 checks passed
@highesttt
highesttt deleted the highest/plat-38977 branch October 6, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants