aboutsummaryrefslogtreecommitdiff
path: root/appservice
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-17 15:30:01 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-17 15:30:01 +0100
commit584312f30805680711557ff6fbe291d2404367fb (patch)
treec1d7993200ad500003026b77b79f234d79a01981 /appservice
parentc740f76826c0291005111c8554c256e8f491e7b9 (diff)
downloadeasybridge-584312f30805680711557ff6fbe291d2404367fb.tar.gz
easybridge-584312f30805680711557ff6fbe291d2404367fb.zip
Correctly update room topics (works on irc)
Diffstat (limited to 'appservice')
-rw-r--r--appservice/account.go18
-rw-r--r--appservice/matrix.go38
-rw-r--r--appservice/server.go9
3 files changed, 57 insertions, 8 deletions
diff --git a/appservice/account.go b/appservice/account.go
index faf491d..ae9716f 100644
--- a/appservice/account.go
+++ b/appservice/account.go
@@ -92,7 +92,23 @@ func (a *Account) UserInfoUpdated(user UserID, info *UserInfo) {
// TODO
}
-func (a *Account) RoomInfoUpdated(roomId RoomID, info *RoomInfo) {
+func (a *Account) RoomInfoUpdated(roomId RoomID, author UserID, info *RoomInfo) {
+ mx_room_id, err := dbGetMxRoom(a.Protocol, roomId)
+ if err != nil {
+ return
+ }
+
+ as_mxid := fmt.Sprintf("@%s:%s", registration.SenderLocalpart, config.MatrixDomain)
+ if len(author) > 0 {
+ mx_user_id, err := dbGetMxUser(a.Protocol, author)
+ if err == nil {
+ as_mxid = mx_user_id
+ }
+ }
+
+ if info.Topic != "" {
+ mxRoomTopicAs(mx_room_id, info.Topic, as_mxid)
+ }
// TODO
}
diff --git a/appservice/matrix.go b/appservice/matrix.go
index 88c4b5d..75bcaa1 100644
--- a/appservice/matrix.go
+++ b/appservice/matrix.go
@@ -138,6 +138,10 @@ func mxCreateRoom(name string, alias string, invite []string) (string, error) {
},
PowerLevels: map[string]interface{} {
"invite": 100,
+ "events": map[string]interface{} {
+ "m.room.topic": 0,
+ "m.room.avatar": 0,
+ },
},
}
var rep CreateRoomResponse
@@ -203,16 +207,36 @@ func mxRoomLeaveAs(room string, user string) error {
return err
}
-func mxSendMessageAs(room string, typ string, body string, user string) error {
+func mxSendAs(room string, event_type string, content map[string]interface{}, user string) error {
txn_id := time.Now().UnixNano()
- rq := RoomSendMessageRequest{
- MsgType: typ,
- Body: body,
+ var rep RoomSendResponse
+ err := mxPutApiCall(fmt.Sprintf(
+ "/_matrix/client/r0/rooms/%s/send/%s/%d?user_id=%s",
+ url.QueryEscape(room), event_type, txn_id, url.QueryEscape(user)),
+ &content, &rep)
+ return err
+}
+
+func mxSendMessageAs(room string, typ string, body string, user string) error {
+ content := map[string]interface{} {
+ "msgtype": typ,
+ "body": body,
}
+ return mxSendAs(room, "m.room.message", content, user)
+}
+
+func mxPutStateAs(room string, event_type string, key string, content map[string]interface{}, as_user string) error {
var rep RoomSendResponse
err := mxPutApiCall(fmt.Sprintf(
- "/_matrix/client/r0/rooms/%s/send/m.room.message/%d?user_id=%s",
- url.QueryEscape(room), txn_id, url.QueryEscape(user)),
- &rq, &rep)
+ "/_matrix/client/r0/rooms/%s/state/%s/%s?user_id=%s",
+ url.QueryEscape(room), event_type, key, url.QueryEscape(as_user)),
+ &content, &rep)
return err
}
+
+func mxRoomTopicAs(room string, topic string, as_user string) error {
+ content := map[string]interface{} {
+ "topic": topic,
+ }
+ return mxPutStateAs(room, "m.room.topic", "", content, as_user)
+}
diff --git a/appservice/server.go b/appservice/server.go
index 00f23f1..2690e58 100644
--- a/appservice/server.go
+++ b/appservice/server.go
@@ -144,5 +144,14 @@ func handleTxnEvent(e *mxlib.Event) {
}
}
}
+ } else if e.Type == "m.room.topic" {
+ if room := dbIsPublicRoom(e.RoomId); room != nil {
+ acct := FindJoinedAccount(e.Sender, room.Protocol, room.RoomID)
+ if acct != nil {
+ acct.Conn.SetRoomInfo(room.RoomID, &connector.RoomInfo{
+ Topic: e.Content["topic"].(string),
+ })
+ }
+ }
}
}