From 54ed6320c2cc4a9748f9faec5780603aeee3de8c Mon Sep 17 00:00:00 2001 From: Wim Date: Mon, 10 Feb 2020 00:06:54 +0100 Subject: Add support for avatars from matrix. #984 (#1007) --- bridge/matrix/matrix.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'bridge/matrix') 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 +} -- cgit v1.2.3