diff options
author | Wim <wim@42.be> | 2020-02-10 00:06:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-10 00:06:54 +0100 |
commit | 54ed6320c2cc4a9748f9faec5780603aeee3de8c (patch) | |
tree | e4fdf6173492533d44b46946dfd825d966ab2a17 /bridge | |
parent | 23083f3ae0ffd28ca4094c75c90ba45fc57bd523 (diff) | |
download | matterbridge-msglm-54ed6320c2cc4a9748f9faec5780603aeee3de8c.tar.gz matterbridge-msglm-54ed6320c2cc4a9748f9faec5780603aeee3de8c.tar.bz2 matterbridge-msglm-54ed6320c2cc4a9748f9faec5780603aeee3de8c.zip |
Add support for avatars from matrix. #984 (#1007)
Diffstat (limited to 'bridge')
-rw-r--r-- | bridge/matrix/matrix.go | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/bridge/matrix/matrix.go b/bridge/matrix/matrix.go index 16562c79..824870cf 100644 --- a/bridge/matrix/matrix.go +++ b/bridge/matrix/matrix.go @@ -172,10 +172,15 @@ func (b *Bmatrix) handleEvent(ev *matrix.Event) { return } - // TODO download avatar - // Create our message - rmsg := config.Message{Username: ev.Sender[1:], Channel: channel, Account: b.Account, UserID: ev.Sender, ID: ev.ID} + rmsg := config.Message{ + Username: ev.Sender[1:], + Channel: channel, + Account: b.Account, + UserID: ev.Sender, + ID: ev.ID, + Avatar: b.getAvatarURL(ev.Sender), + } // Text must be a string if rmsg.Text, ok = ev.Content["body"].(string); !ok { @@ -358,3 +363,15 @@ func (b *Bmatrix) containsAttachment(content map[string]interface{}) bool { } return true } + +// getAvatarURL returns the avatar URL of the specified sender +func (b *Bmatrix) getAvatarURL(sender string) string { + mxcURL, err := b.mc.GetSenderAvatarURL(sender) + if err != nil { + b.Log.Errorf("getAvatarURL failed: %s", err) + return "" + } + url := strings.ReplaceAll(mxcURL, "mxc://", b.GetString("Server")+"/_matrix/media/r0/thumbnail/") + url += "?width=37&height=37&method=crop" + return url +} |