bug fix: Prefer person.avatar_url to message.avatar_url.

This change is a partial bug fix for avatar live updates.
It makes it so that we prefer the person.avatar_url to
the message.avatar_url when rendering messages.  Our live
update code was already populating person.avatar_url, but
we were ignoring it until now.

This commit does not affect messages that were already
rendered with the old url.
This commit is contained in:
Steve Howell 2017-01-21 12:34:27 -08:00 committed by Tim Abbott
parent e7e2e388c5
commit f75af94984
1 changed files with 28 additions and 4 deletions

View File

@ -128,14 +128,38 @@ exports.small_avatar_url = function (message) {
// //
// We actually request these at s=50, so that we look better // We actually request these at s=50, so that we look better
// on retina displays. // on retina displays.
if (message.avatar_url) {
var url = message.avatar_url + "&s=50"; var url = "";
var person;
if (message.sender_id) {
// We should always have message.sender_id, except for in the
// tutorial, where it's ok to fall back to the url in the fake
// messages.
person = exports.get_person_from_user_id(message.sender_id);
}
// The first time we encounter a sender in a message, we may
// not have person.avatar_url set, but if we do, then use that.
if (person && person.avatar_url) {
url = person.avatar_url;
} else if (message.avatar_url) {
// Here we fall back to using the avatar_url from the message
// itself.
url = message.avatar_url;
if (person) {
person.avatar_url = url;
}
}
if (url) {
url += "&s=50";
if (message.sent_by_me) { if (message.sent_by_me) {
url += "&stamp=" + settings.avatar_stamp; url += "&stamp=" + settings.avatar_stamp;
} }
return url;
} }
return "";
return url;
}; };
exports.realm_get = function realm_get(email) { exports.realm_get = function realm_get(email) {