Add handler for power levels in bridges (#189)

pull/194/head
Malte E 2024-03-09 15:33:09 +01:00 committed by GitHub
parent a6b4b3bf34
commit b8e4202c0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View File

@ -91,6 +91,11 @@ type DisappearingPortal interface {
ScheduleDisappearing()
}
type PowerLevelHandlingPortal interface {
Portal
HandleMatrixPowerLevels(sender User, evt *event.Event)
}
type User interface {
GetPermissionLevel() bridgeconfig.PermissionLevel
IsLoggedIn() bool

View File

@ -65,6 +65,7 @@ func NewMatrixHandler(br *Bridge) *MatrixHandler {
br.EventProcessor.On(event.StateEncryption, handler.HandleEncryption)
br.EventProcessor.On(event.EphemeralEventReceipt, handler.HandleReceipt)
br.EventProcessor.On(event.EphemeralEventTyping, handler.HandleTyping)
br.EventProcessor.On(event.StatePowerLevels, handler.HandlePowerLevels)
return handler
}
@ -686,3 +687,18 @@ func (mx *MatrixHandler) HandleTyping(_ context.Context, evt *event.Event) {
}
typingPortal.HandleMatrixTyping(evt.Content.AsTyping().UserIDs)
}
func (mx *MatrixHandler) HandlePowerLevels(_ context.Context, evt *event.Event) {
if mx.shouldIgnoreEvent(evt) {
return
}
portal := mx.bridge.Child.GetIPortal(evt.RoomID)
if portal == nil {
return
}
powerLevelPortal, ok := portal.(PowerLevelHandlingPortal)
if ok {
user := mx.bridge.Child.GetIUser(evt.Sender, true)
powerLevelPortal.HandleMatrixPowerLevels(user, evt)
}
}