aboutsummaryrefslogtreecommitdiff
path: root/appservice
diff options
context:
space:
mode:
Diffstat (limited to 'appservice')
-rw-r--r--appservice/account.go23
-rw-r--r--appservice/matrix.go13
-rw-r--r--appservice/server.go7
3 files changed, 38 insertions, 5 deletions
diff --git a/appservice/account.go b/appservice/account.go
index ae9716f..a20751f 100644
--- a/appservice/account.go
+++ b/appservice/account.go
@@ -89,7 +89,17 @@ func (a *Account) Left(roomId RoomID) {
}
func (a *Account) UserInfoUpdated(user UserID, info *UserInfo) {
- // TODO
+ mx_user_id, err := dbGetMxUser(a.Protocol, user)
+ if err != nil {
+ return
+ }
+
+ if info.DisplayName != "" {
+ mxProfileDisplayname(mx_user_id, fmt.Sprintf("%s (%s)", info.DisplayName, a.Protocol))
+ }
+ if info.Avatar != nil {
+ // TODO
+ }
}
func (a *Account) RoomInfoUpdated(roomId RoomID, author UserID, info *RoomInfo) {
@@ -98,7 +108,7 @@ func (a *Account) RoomInfoUpdated(roomId RoomID, author UserID, info *RoomInfo)
return
}
- as_mxid := fmt.Sprintf("@%s:%s", registration.SenderLocalpart, config.MatrixDomain)
+ as_mxid := ezbrMxId()
if len(author) > 0 {
mx_user_id, err := dbGetMxUser(a.Protocol, author)
if err == nil {
@@ -109,7 +119,14 @@ func (a *Account) RoomInfoUpdated(roomId RoomID, author UserID, info *RoomInfo)
if info.Topic != "" {
mxRoomTopicAs(mx_room_id, info.Topic, as_mxid)
}
- // TODO
+
+ if info.Name != "" {
+ mxRoomNameAs(mx_room_id, info.Name, as_mxid)
+ }
+
+ if info.Picture != nil {
+ // TODO
+ }
}
func (a *Account) Event(event *Event) {
diff --git a/appservice/matrix.go b/appservice/matrix.go
index 75bcaa1..2c4562e 100644
--- a/appservice/matrix.go
+++ b/appservice/matrix.go
@@ -13,6 +13,12 @@ import (
. "git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
)
+func ezbrMxId() string {
+ return fmt.Sprintf("@%s:%s", registration.SenderLocalpart, config.MatrixDomain)
+}
+
+// ----
+
var httpClient *http.Client
func init() {
@@ -234,6 +240,13 @@ func mxPutStateAs(room string, event_type string, key string, content map[string
return err
}
+func mxRoomNameAs(room string, name string, as_user string) error {
+ content := map[string]interface{} {
+ "name": name,
+ }
+ return mxPutStateAs(room, "m.room.name", "", content, as_user)
+}
+
func mxRoomTopicAs(room string, topic string, as_user string) error {
content := map[string]interface{} {
"topic": topic,
diff --git a/appservice/server.go b/appservice/server.go
index 2690e58..b67e813 100644
--- a/appservice/server.go
+++ b/appservice/server.go
@@ -34,12 +34,11 @@ func Start(r *mxlib.Registration, c *Config) (chan error, error) {
return nil, err
}
- svc_mxid := fmt.Sprintf("@%s:%s", registration.SenderLocalpart, config.MatrixDomain)
err = mxRegisterUser(registration.SenderLocalpart)
if mxe, ok := err.(*mxlib.MxError); !ok || mxe.ErrCode != "M_USER_IN_USE" {
return nil, err
}
- err = mxProfileDisplayname(svc_mxid, "Easybridge")
+ err = mxProfileDisplayname(ezbrMxId(), "Easybridge")
if err != nil {
return nil, err
}
@@ -123,6 +122,8 @@ func handleTxnEvent(e *mxlib.Event) {
ev.Author = acct.Conn.User()
ev.Room = room.RoomID
acct.Conn.Send(ev)
+ } else {
+ log.Debugf("Could not find room account for %s %s %s", e.Sender, room.Protocol, room.RoomID)
}
}
} else if e.Type == "m.room.member" {
@@ -141,6 +142,8 @@ func handleTxnEvent(e *mxlib.Event) {
if acct != nil {
acct.Conn.Leave(room.RoomID)
// TODO: manage autojoin list, remove this room
+ } else {
+ log.Debugf("Could not find room account for %s %s %s", e.Sender, room.Protocol, room.RoomID)
}
}
}