Add Matrix->WhatsApp room name changes
This commit is contained in:
parent
0d45b5b857
commit
9da7f15e8f
@ -16,7 +16,7 @@
|
|||||||
* [ ] Leave
|
* [ ] Leave
|
||||||
* [ ] Kick
|
* [ ] Kick
|
||||||
* [ ] Room metadata changes
|
* [ ] Room metadata changes
|
||||||
* [ ] Name
|
* [x] Name
|
||||||
* [ ] Avatar
|
* [ ] Avatar
|
||||||
* [ ] Topic
|
* [ ] Topic
|
||||||
* [ ] Initial room metadata
|
* [ ] Initial room metadata
|
||||||
|
41
matrix.go
41
matrix.go
@ -17,11 +17,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"maunium.net/go/gomatrix"
|
|
||||||
"maunium.net/go/mautrix-whatsapp/types"
|
|
||||||
"maunium.net/go/mautrix-appservice"
|
|
||||||
"maunium.net/go/maulogger"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"maunium.net/go/gomatrix"
|
||||||
|
"maunium.net/go/maulogger"
|
||||||
|
"maunium.net/go/mautrix-appservice"
|
||||||
|
"maunium.net/go/mautrix-whatsapp/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MatrixHandler struct {
|
type MatrixHandler struct {
|
||||||
@ -40,6 +41,9 @@ func NewMatrixHandler(bridge *Bridge) *MatrixHandler {
|
|||||||
}
|
}
|
||||||
bridge.EventProcessor.On(gomatrix.EventMessage, handler.HandleMessage)
|
bridge.EventProcessor.On(gomatrix.EventMessage, handler.HandleMessage)
|
||||||
bridge.EventProcessor.On(gomatrix.StateMember, handler.HandleMembership)
|
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
|
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) {
|
func (mx *MatrixHandler) HandleMessage(evt *gomatrix.Event) {
|
||||||
roomID := types.MatrixRoomID(evt.RoomID)
|
roomID := types.MatrixRoomID(evt.RoomID)
|
||||||
user := mx.bridge.GetUser(types.MatrixUserID(evt.Sender))
|
user := mx.bridge.GetUser(types.MatrixUserID(evt.Sender))
|
||||||
|
@ -347,7 +347,7 @@ func (portal *Portal) CreateMatrixRoom() error {
|
|||||||
InitialState: []*gomatrix.Event{{
|
InitialState: []*gomatrix.Event{{
|
||||||
Type: gomatrix.StatePowerLevels,
|
Type: gomatrix.StatePowerLevels,
|
||||||
Content: gomatrix.Content{
|
Content: gomatrix.Content{
|
||||||
PowerLevels: portal.GetBasePowerLevels(),
|
PowerLevels: *portal.GetBasePowerLevels(),
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user