mirror of https://github.com/mautrix/go.git
Add handler for power levels in bridges (#189)
parent
a6b4b3bf34
commit
b8e4202c0f
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue