Add Matrix->WhatsApp room name changes
This commit is contained in:
parent
0d45b5b857
commit
9da7f15e8f
@ -16,7 +16,7 @@
|
||||
* [ ] Leave
|
||||
* [ ] Kick
|
||||
* [ ] Room metadata changes
|
||||
* [ ] Name
|
||||
* [x] Name
|
||||
* [ ] Avatar
|
||||
* [ ] Topic
|
||||
* [ ] Initial room metadata
|
||||
|
41
matrix.go
41
matrix.go
@ -17,11 +17,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"maunium.net/go/gomatrix"
|
||||
"maunium.net/go/mautrix-whatsapp/types"
|
||||
"maunium.net/go/mautrix-appservice"
|
||||
"maunium.net/go/maulogger"
|
||||
"strings"
|
||||
|
||||
"maunium.net/go/gomatrix"
|
||||
"maunium.net/go/maulogger"
|
||||
"maunium.net/go/mautrix-appservice"
|
||||
"maunium.net/go/mautrix-whatsapp/types"
|
||||
)
|
||||
|
||||
type MatrixHandler struct {
|
||||
@ -40,6 +41,9 @@ func NewMatrixHandler(bridge *Bridge) *MatrixHandler {
|
||||
}
|
||||
bridge.EventProcessor.On(gomatrix.EventMessage, handler.HandleMessage)
|
||||
bridge.EventProcessor.On(gomatrix.StateMember, handler.HandleMembership)
|
||||
bridge.EventProcessor.On(gomatrix.StateRoomName, handler.HandleRoomMetadata)
|
||||
bridge.EventProcessor.On(gomatrix.StateRoomAvatar, handler.HandleRoomMetadata)
|
||||
bridge.EventProcessor.On(gomatrix.StateTopic, handler.HandleRoomMetadata)
|
||||
return handler
|
||||
}
|
||||
|
||||
@ -94,6 +98,35 @@ func (mx *MatrixHandler) HandleMembership(evt *gomatrix.Event) {
|
||||
}
|
||||
}
|
||||
|
||||
func (mx *MatrixHandler) HandleRoomMetadata(evt *gomatrix.Event) {
|
||||
user := mx.bridge.GetUser(types.MatrixUserID(evt.Sender))
|
||||
if user == nil {
|
||||
return
|
||||
}
|
||||
|
||||
portal := user.GetPortalByMXID(evt.RoomID)
|
||||
if portal == nil || portal.IsPrivateChat() {
|
||||
return
|
||||
}
|
||||
|
||||
var resp <-chan string
|
||||
var err error
|
||||
switch evt.Type {
|
||||
case gomatrix.StateRoomName:
|
||||
resp, err = user.Conn.UpdateGroupSubject(evt.Content.Name, portal.JID)
|
||||
case gomatrix.StateRoomAvatar:
|
||||
return
|
||||
case gomatrix.StateTopic:
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
mx.log.Errorln(err)
|
||||
} else {
|
||||
out := <-resp
|
||||
mx.log.Infoln(out)
|
||||
}
|
||||
}
|
||||
|
||||
func (mx *MatrixHandler) HandleMessage(evt *gomatrix.Event) {
|
||||
roomID := types.MatrixRoomID(evt.RoomID)
|
||||
user := mx.bridge.GetUser(types.MatrixUserID(evt.Sender))
|
||||
|
Loading…
Reference in New Issue
Block a user