From d598515bae5bdd143c71d58a1da40e9e3d7dd440 Mon Sep 17 00:00:00 2001 From: Kishan Bagaria <1093313+KishanBagaria@users.noreply.github.com> Date: Mon, 25 Aug 2025 19:43:10 +0530 Subject: [PATCH] Update portal.go --- bridgev2/portal.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/bridgev2/portal.go b/bridgev2/portal.go index 7c3a56c2..c544d517 100644 --- a/bridgev2/portal.go +++ b/bridgev2/portal.go @@ -676,6 +676,8 @@ func (portal *Portal) handleMatrixEvent(ctx context.Context, sender *User, evt * return portal.handleMatrixMembership(ctx, login, origSender, evt) case event.StatePowerLevels: return portal.handleMatrixPowerLevels(ctx, login, origSender, evt) + case event.StateBeeperDisappearingTimer: + return portal.handleMatrixDisappearingTimer(ctx, login, origSender, evt) default: return EventHandlingResultIgnored } @@ -1734,6 +1736,43 @@ func (portal *Portal) handleMatrixPowerLevels( return EventHandlingResultSuccess.WithMSS() } +func (portal *Portal) handleMatrixDisappearingTimer( + ctx context.Context, + sender *UserLogin, + origSender *OrigSender, + evt *event.Event, +) EventHandlingResult { + log := zerolog.Ctx(ctx) + content, ok := evt.Content.Parsed.(*event.BeeperDisappearingTimer) + if !ok { + log.Error().Type("content_type", evt.Content.Parsed).Msg("Unexpected parsed content type") + return EventHandlingResultFailed.WithMSSError(fmt.Errorf("%w: %T", ErrUnexpectedParsedContentType, evt.Content.Parsed)) + } + + timer := time.Duration(content.Timer) * time.Millisecond + if content.Type == event.DisappearingTypeNone { + timer = 0 + } + + setting := database.DisappearingSetting{ + Type: content.Type, + Timer: timer, + } + + changed := portal.UpdateDisappearingSetting(ctx, setting, portal.Bridge.Bot, time.UnixMilli(evt.Timestamp), false, true) + if !changed { + log.Debug().Msg("Disappearing timer setting unchanged") + return EventHandlingResultSuccess.WithMSS() + } + + log.Info(). + Str("type", string(content.Type)). + Dur("timer", timer). + Msg("Updated disappearing timer setting from Matrix") + + return EventHandlingResultSuccess.WithMSS() +} + func (portal *Portal) handleMatrixTombstone(ctx context.Context, evt *event.Event) EventHandlingResult { if evt.StateKey == nil || *evt.StateKey != "" || portal.MXID != evt.RoomID { return EventHandlingResultIgnored