aboutsummaryrefslogtreecommitdiff
path: root/connector/mattermost/mattermost.go
diff options
context:
space:
mode:
Diffstat (limited to 'connector/mattermost/mattermost.go')
-rw-r--r--connector/mattermost/mattermost.go52
1 files changed, 30 insertions, 22 deletions
diff --git a/connector/mattermost/mattermost.go b/connector/mattermost/mattermost.go
index 73ea66b..6282831 100644
--- a/connector/mattermost/mattermost.go
+++ b/connector/mattermost/mattermost.go
@@ -314,17 +314,21 @@ func (mm *Mattermost) handleConnected() {
} else {
room_info.Name = t.Team.Name + " / " + room_info.Name
}
- // TODO: cache last update time so we don't do this needlessly
if t.Team.LastTeamIconUpdate > 0 {
- team_img, resp := mm.conn.Client.GetTeamIcon(t.Id, "")
- if resp.Error == nil {
- room_info.Picture = &BlobMediaObject{
- ObjectFilename: t.Team.Name,
- ObjectMimetype: http.DetectContentType(team_img),
- ObjectData: team_img,
- }
- } else {
- log.Warnf("Could not get team image: %s", resp.Error)
+ room_info.Picture = &LazyBlobMediaObject{
+ ObjectFilename: fmt.Sprintf("%s-%d",
+ t.Team.Name,
+ t.Team.LastTeamIconUpdate),
+ GetFn: func(o *LazyBlobMediaObject) error {
+ team_img, resp := mm.conn.Client.GetTeamIcon(t.Id, "")
+ if resp.Error == nil {
+ log.Warnf("Could not get team image: %s", resp.Error)
+ return resp.Error
+ }
+ o.ObjectData = team_img
+ o.ObjectMimetype = http.DetectContentType(team_img)
+ return nil
+ },
}
}
break
@@ -378,20 +382,24 @@ func (mm *Mattermost) updateUserInfo(user *model.User) {
DisplayName: userDisp,
}
if user.LastPictureUpdate > 0 {
- // TODO: cache last update time so we don't do this needlessly
- img, resp := mm.conn.Client.GetProfileImage(user.Id, "")
- if resp.Error == nil {
- ui.Avatar = &BlobMediaObject{
- ObjectFilename: user.Username,
- ObjectMimetype: http.DetectContentType(img),
- ObjectData: img,
- }
- } else {
- log.Warnf("Could not get profile picture: %s", resp.Error)
+ ui.Avatar = &LazyBlobMediaObject{
+ ObjectFilename: fmt.Sprintf("%s-%d",
+ user.Username,
+ user.LastPictureUpdate),
+ GetFn: func(o *LazyBlobMediaObject) error {
+ img, resp := mm.conn.Client.GetProfileImage(user.Id, "")
+ if resp.Error == nil {
+ log.Warnf("Could not get profile picture: %s", resp.Error)
+ return resp.Error
+ }
+ o.ObjectData = img
+ o.ObjectMimetype = http.DetectContentType(img)
+ return nil
+ },
}
- mm.handler.UserInfoUpdated(userId, ui)
- mm.userdisplaynamemap[userId] = userDisp
}
+ mm.handler.UserInfoUpdated(userId, ui)
+ mm.userdisplaynamemap[userId] = userDisp
}
}