summaryrefslogtreecommitdiffstats
path: root/bridge/matrix/matrix.go
diff options
context:
space:
mode:
Diffstat (limited to 'bridge/matrix/matrix.go')
-rw-r--r--bridge/matrix/matrix.go23
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
+}