diff options
author | Alex Auvolat <alex@adnab.me> | 2020-02-17 15:30:01 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-02-17 15:30:01 +0100 |
commit | 584312f30805680711557ff6fbe291d2404367fb (patch) | |
tree | c1d7993200ad500003026b77b79f234d79a01981 /appservice/matrix.go | |
parent | c740f76826c0291005111c8554c256e8f491e7b9 (diff) | |
download | easybridge-584312f30805680711557ff6fbe291d2404367fb.tar.gz easybridge-584312f30805680711557ff6fbe291d2404367fb.zip |
Correctly update room topics (works on irc)
Diffstat (limited to 'appservice/matrix.go')
-rw-r--r-- | appservice/matrix.go | 38 |
1 files changed, 31 insertions, 7 deletions
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) +} |