diff --git a/bridgev2/database/portal.go b/bridgev2/database/portal.go index 0c7bc667..c3aa7121 100644 --- a/bridgev2/database/portal.go +++ b/bridgev2/database/portal.go @@ -35,9 +35,20 @@ type PortalQuery struct { *dbutil.QueryHelper[*Portal] } +type CapStateFlags uint32 + +func (csf CapStateFlags) Has(flag CapStateFlags) bool { + return csf&flag != 0 +} + +const ( + CapStateFlagDisappearingTimerSet CapStateFlags = 1 << iota +) + type CapabilityState struct { Source networkid.UserLoginID `json:"source"` ID string `json:"id"` + Flags CapStateFlags `json:"flags"` } type Portal struct { diff --git a/bridgev2/portal.go b/bridgev2/portal.go index a8c83dbd..7c3a56c2 100644 --- a/bridgev2/portal.go +++ b/bridgev2/portal.go @@ -3649,6 +3649,15 @@ func (portal *Portal) UpdateCapabilities(ctx context.Context, source *UserLogin, portal.CapState = database.CapabilityState{ Source: source.ID, ID: capID, + Flags: portal.CapState.Flags, + } + if caps.DisappearingTimer != nil && !portal.CapState.Flags.Has(database.CapStateFlagDisappearingTimerSet) { + zerolog.Ctx(ctx).Debug().Msg("Disappearing timer capability was added, sending disappearing timer state event") + success = portal.sendRoomMeta(ctx, nil, time.Now(), event.StateBeeperDisappearingTimer, "", portal.Disappear.ToEventContent()) + if !success { + return false + } + portal.CapState.Flags |= database.CapStateFlagDisappearingTimerSet } portal.lastCapUpdate = time.Now() if implicit { @@ -4342,6 +4351,7 @@ func (portal *Portal) createMatrixRoomInLoop(ctx context.Context, source *UserLo Type: event.StateBeeperDisappearingTimer, Content: event.Content{Parsed: portal.Disappear.ToEventContent()}, }) + portal.CapState.Flags |= database.CapStateFlagDisappearingTimerSet } if req.Topic == "" { // Add explicit topic event if topic is empty to ensure the event is set.