From 7886f05e881e45303087a5ae116657f0f6164d81 Mon Sep 17 00:00:00 2001 From: Wim Date: Tue, 20 Feb 2018 00:54:35 +0100 Subject: Download (and upload) avatar images from mattermost and telegram when mediaserver is configured. Closes #362 An extra avatarMap (cache) is created for mattermost and telegram. If MediaServerUpload is configured, the avatar images of users are downloaded the first time a user sends a message. If this download succeeds a message with EVENT_AVATAR_DOWNLOAD is sent to the originating protocol. This message also contains a SHA field (in msg.Extra["file"]), if this is not empty, the sha will be added to the avatarMap. (so we now have a userid-sha cache) Next time this user sends a message, the MediaServerUpload/sha/userid.png URL will be used as the avatar field. --- bridge/helper/helper.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'bridge/helper/helper.go') diff --git a/bridge/helper/helper.go b/bridge/helper/helper.go index 10c3647a..44052e11 100644 --- a/bridge/helper/helper.go +++ b/bridge/helper/helper.go @@ -54,3 +54,10 @@ func HandleExtra(msg *config.Message, general *config.Protocol) []config.Message } return rmsg } + +func GetAvatar(av map[string]string, userid string, general *config.Protocol) string { + if sha, ok := av[userid]; ok { + return general.MediaServerUpload + "/" + sha + "/" + userid + ".png" + } + return "" +} -- cgit v1.2.3