mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
bridgev2/networkinterface: add interface for handling disappearing timer changes from Matrix
This commit is contained in:
parent
f860b0e238
commit
a6bbe978bd
3 changed files with 24 additions and 1 deletions
|
|
@ -147,6 +147,7 @@ func (br *Connector) Init(bridge *bridgev2.Bridge) {
|
|||
br.EventProcessor.On(event.StateRoomAvatar, br.handleRoomEvent)
|
||||
br.EventProcessor.On(event.StateTopic, br.handleRoomEvent)
|
||||
br.EventProcessor.On(event.StateTombstone, br.handleRoomEvent)
|
||||
br.EventProcessor.On(event.StateBeeperDisappearingTimer, br.handleRoomEvent)
|
||||
br.EventProcessor.On(event.EphemeralEventReceipt, br.handleEphemeralEvent)
|
||||
br.EventProcessor.On(event.EphemeralEventTyping, br.handleEphemeralEvent)
|
||||
br.Bot = br.AS.BotIntent()
|
||||
|
|
|
|||
|
|
@ -683,6 +683,14 @@ type RoomTopicHandlingNetworkAPI interface {
|
|||
HandleMatrixRoomTopic(ctx context.Context, msg *MatrixRoomTopic) (bool, error)
|
||||
}
|
||||
|
||||
type DisappearTimerChangingNetworkAPI interface {
|
||||
NetworkAPI
|
||||
// HandleMatrixDisappearingTimer is called when the disappearing timer of a portal room is changed.
|
||||
// This method should update the Disappear field of the Portal with the new timer and return true
|
||||
// if the change was successful. If the change is not successful, then the field should not be updated.
|
||||
HandleMatrixDisappearingTimer(ctx context.Context, msg *MatrixDisappearingTimer) (bool, error)
|
||||
}
|
||||
|
||||
type ResolveIdentifierResponse struct {
|
||||
// Ghost is the ghost of the user that the identifier resolves to.
|
||||
// This field should be set whenever possible. However, it is not required,
|
||||
|
|
@ -1270,6 +1278,7 @@ type MatrixRoomMeta[ContentType any] struct {
|
|||
type MatrixRoomName = MatrixRoomMeta[*event.RoomNameEventContent]
|
||||
type MatrixRoomAvatar = MatrixRoomMeta[*event.RoomAvatarEventContent]
|
||||
type MatrixRoomTopic = MatrixRoomMeta[*event.TopicEventContent]
|
||||
type MatrixDisappearingTimer = MatrixRoomMeta[*event.BeeperDisappearingTimer]
|
||||
|
||||
type MatrixReadReceipt struct {
|
||||
Portal *Portal
|
||||
|
|
|
|||
|
|
@ -663,6 +663,8 @@ func (portal *Portal) handleMatrixEvent(ctx context.Context, sender *User, evt *
|
|||
return handleMatrixRoomMeta(portal, ctx, login, origSender, evt, RoomTopicHandlingNetworkAPI.HandleMatrixRoomTopic)
|
||||
case event.StateRoomAvatar:
|
||||
return handleMatrixRoomMeta(portal, ctx, login, origSender, evt, RoomAvatarHandlingNetworkAPI.HandleMatrixRoomAvatar)
|
||||
case event.StateBeeperDisappearingTimer:
|
||||
return handleMatrixRoomMeta(portal, ctx, login, origSender, evt, DisappearTimerChangingNetworkAPI.HandleMatrixDisappearingTimer)
|
||||
case event.StateEncryption:
|
||||
// TODO?
|
||||
return EventHandlingResultIgnored
|
||||
|
|
@ -1477,6 +1479,15 @@ func handleMatrixRoomMeta[APIType any, ContentType any](
|
|||
portal.sendSuccessStatus(ctx, evt, 0, "")
|
||||
return EventHandlingResultIgnored
|
||||
}
|
||||
case *event.BeeperDisappearingTimer:
|
||||
if typedContent.Type == event.DisappearingTypeNone || typedContent.Timer.Duration <= 0 {
|
||||
typedContent.Type = event.DisappearingTypeNone
|
||||
typedContent.Timer.Duration = 0
|
||||
}
|
||||
if typedContent.Type == portal.Disappear.Type && typedContent.Timer.Duration == portal.Disappear.Timer {
|
||||
portal.sendSuccessStatus(ctx, evt, 0, "")
|
||||
return EventHandlingResultIgnored
|
||||
}
|
||||
}
|
||||
var prevContent ContentType
|
||||
if evt.Unsigned.PrevContent != nil {
|
||||
|
|
@ -1500,7 +1511,9 @@ func handleMatrixRoomMeta[APIType any, ContentType any](
|
|||
return EventHandlingResultFailed.WithMSSError(err)
|
||||
}
|
||||
if changed {
|
||||
portal.UpdateBridgeInfo(ctx)
|
||||
if evt.Type != event.StateBeeperDisappearingTimer {
|
||||
portal.UpdateBridgeInfo(ctx)
|
||||
}
|
||||
err = portal.Save(ctx)
|
||||
if err != nil {
|
||||
log.Err(err).Msg("Failed to save portal after updating room metadata")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue