diff options
author | Alexander <papatutuwawa@polynom.me> | 2020-04-16 22:16:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-16 22:16:25 +0200 |
commit | 7183095a28661fc113887a034ae1ff13eb06d0c6 (patch) | |
tree | 227b06e79e2de48989eeffe1fad408a630430355 /bridge/xmpp/helpers.go | |
parent | 13c90893c7d3b757eb77541c5ec44489fde5661e (diff) | |
download | matterbridge-msglm-7183095a28661fc113887a034ae1ff13eb06d0c6.tar.gz matterbridge-msglm-7183095a28661fc113887a034ae1ff13eb06d0c6.tar.bz2 matterbridge-msglm-7183095a28661fc113887a034ae1ff13eb06d0c6.zip |
Implement User Avatar spoofing of XMPP users (#1090)
* Implement User Avatar spoofing of XMPP users
Diffstat (limited to 'bridge/xmpp/helpers.go')
-rw-r--r-- | bridge/xmpp/helpers.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/bridge/xmpp/helpers.go b/bridge/xmpp/helpers.go new file mode 100644 index 00000000..eb6a5366 --- /dev/null +++ b/bridge/xmpp/helpers.go @@ -0,0 +1,30 @@ +package bxmpp + +import ( + "regexp" + + "github.com/42wim/matterbridge/bridge/config" +) + +var pathRegex = regexp.MustCompile("[^a-zA-Z0-9]+") + +// GetAvatar constructs a URL for a given user-avatar if it is available in the cache. +func getAvatar(av map[string]string, userid string, general *config.Protocol) string { + if hash, ok := av[userid]; ok { + // NOTE: This does not happen in bridge/helper/helper.go but messes up XMPP + id := pathRegex.ReplaceAllString(userid, "_") + return general.MediaServerDownload + "/" + hash + "/" + id + ".png" + } + return "" +} + +func (b *Bxmpp) cacheAvatar(msg *config.Message) string { + fi := msg.Extra["file"][0].(config.FileInfo) + /* if we have a sha we have successfully uploaded the file to the media server, + so we can now cache the sha */ + if fi.SHA != "" { + b.Log.Debugf("Added %s to %s in avatarMap", fi.SHA, msg.UserID) + b.avatarMap[msg.UserID] = fi.SHA + } + return "" +} |