From fd768a10be36ec31f674fa291fcbe77b78a2855c Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 21 Feb 2020 18:08:40 +0100 Subject: Mattermost media objects in both ways + user/team profile pictures from MM to Matrix --- appservice/account.go | 19 ++++++++++++------- appservice/server.go | 3 +++ 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'appservice') diff --git a/appservice/account.go b/appservice/account.go index a2b95d7..2df2930 100644 --- a/appservice/account.go +++ b/appservice/account.go @@ -137,7 +137,10 @@ func (a *Account) userInfoUpdatedInternal(user UserID, info *UserInfo) error { } if info.Avatar != nil { - err = fmt.Errorf("Avatar: not implemented") + err2 := mx.ProfileAvatar(mx_user_id, info.Avatar) + if err2 != nil { + err = err2 + } } return err @@ -182,8 +185,10 @@ func (a *Account) roomInfoUpdatedInternal(roomId RoomID, author UserID, info *Ro } if info.Picture != nil { - // TODO - err = fmt.Errorf("Picture: not implemented") + err2 := mx.RoomAvatarAs(mx_room_id, info.Picture, as_mxid) + if err2 != nil { + err = err2 + } } return err @@ -254,8 +259,8 @@ func (a *Account) eventInternal(event *Event) error { return err } - if event.Attachements != nil { - for _, file := range event.Attachements { + if event.Attachments != nil { + for _, file := range event.Attachments { mxfile, err := mx.UploadMedia(file) if err != nil { return err @@ -270,8 +275,8 @@ func (a *Account) eventInternal(event *Event) error { content["info"] = map[string]interface{} { "mimetype": mxfile.Mimetype(), "size": mxfile.Size(), - "width": sz.Width, - "height": sz.Height, + "w": sz.Width, + "h": sz.Height, } } else { content["msgtype"] = "m.file" diff --git a/appservice/server.go b/appservice/server.go index 5a5cebe..d96f27c 100644 --- a/appservice/server.go +++ b/appservice/server.go @@ -123,6 +123,9 @@ func handleTxnEvent(e *mxlib.Event) error { typ := e.Content["msgtype"].(string) if typ == "m.emote" { ev.Type = connector.EVENT_MESSAGE + } else if typ == "m.file" || typ == "m.image" { + ev.Text = "" + ev.Attachments = []connector.MediaObject{mx.ParseMediaInfo(e.Content)} } if pm_room := dbIsPmRoom(e.RoomId); pm_room != nil { -- cgit v1.2.3