mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
Update portal.go
This commit is contained in:
parent
fa7c1ae2bc
commit
d598515bae
1 changed files with 39 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue