Calculate gravatar hashes on the webapp client.

This change prepares us to have the server send avatar_url
of None when somebody wants a gravatar avatar (as opposed
to a user-uploaded one).

Subsequent commits will change behavior on both the server
and client to have this happen.  So this commit has no-op
code for now, but it will soon use the fallback-to-gravatar
logic.
This commit is contained in:
Steve Howell 2017-11-03 09:25:47 -07:00 committed by Tim Abbott
parent 3462127ddb
commit f105c480b3
6 changed files with 48 additions and 8 deletions

View File

@ -18,6 +18,7 @@
"Dropbox": false, "Dropbox": false,
"SockJS": false, "SockJS": false,
"marked": false, "marked": false,
"md5": false,
"moment": false, "moment": false,
"i18n": false, "i18n": false,
"DynamicText": false, "DynamicText": false,

View File

@ -1,12 +1,13 @@
add_dependencies({ zrequire('util');
util: 'js/util.js', zrequire('people');
});
var people = require("js/people.js");
set_global('blueslip', { set_global('blueslip', {
error: function () { return undefined; }, error: function () { return undefined; },
}); });
set_global('page_params', {}); set_global('page_params', {});
set_global('md5', function (s) {
return 'md5-' + s;
});
var _ = global._; var _ = global._;
@ -393,6 +394,23 @@ initialize();
assert.equal(people.small_avatar_url(message), assert.equal(people.small_avatar_url(message),
'legacy.png&s=50'); 'legacy.png&s=50');
message = {
avatar_url: undefined,
sender_id: maria.user_id,
};
assert.equal(people.small_avatar_url(message),
'https://secure.gravatar.com/avatar/md5-athens@example.com?d=identicon&s=50'
);
message = {
avatar_url: undefined,
sender_email: 'foo@example.com',
sender_id: 9999999,
};
assert.equal(people.small_avatar_url(message),
'https://secure.gravatar.com/avatar/md5-foo@example.com?d=identicon&s=50'
);
message = { message = {
type: 'private', type: 'private',
display_recipient: [ display_recipient: [

View File

@ -7,6 +7,7 @@
"dependencies": { "dependencies": {
"@types/node": "8.0.34", "@types/node": "8.0.34",
"@types/webpack": "3.0.13", "@types/webpack": "3.0.13",
"blueimp-md5": "2.10.0",
"clipboard": "1.5.16", "clipboard": "1.5.16",
"emoji-datasource": "3.0.0", "emoji-datasource": "3.0.0",
"emoji-datasource-apple": "3.0.0", "emoji-datasource-apple": "3.0.0",

View File

@ -508,16 +508,31 @@ exports.small_avatar_url = function (message) {
person = exports.get_person_from_user_id(message.sender_id); person = exports.get_person_from_user_id(message.sender_id);
} }
var email;
// The first time we encounter a sender in a message, we may // 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. // not have person.avatar_url set, but if we do, then use that.
if (person && person.avatar_url) { if (person) {
url = person.avatar_url; url = person.avatar_url;
} else if (message.avatar_url) { email = person.email;
// Here we fall back to using the avatar_url from the message }
// itself.
// Try to get info from the message if we didn't have a `person` object
// or if the avatar was missing. We do this verbosely to avoid false
// positives on line coverage (we don't do branch checking).
if (!url) {
url = message.avatar_url; url = message.avatar_url;
} }
if (!email) {
email = message.sender_email;
}
if (!url) {
var hash = md5(email);
url = 'https://secure.gravatar.com/avatar/' + hash + '?d=identicon';
}
if (url) { if (url) {
url = exports.format_small_avatar_url(url); url = exports.format_small_avatar_url(url);
} }

View File

@ -412,6 +412,10 @@ block-stream@*:
dependencies: dependencies:
inherits "~2.0.0" inherits "~2.0.0"
blueimp-md5@2.10.0:
version "2.10.0"
resolved "https://registry.yarnpkg.com/blueimp-md5/-/blueimp-md5-2.10.0.tgz#02f0843921f90dca14f5b8920a38593201d6964d"
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.11.6, bn.js@^4.4.0: bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.11.6, bn.js@^4.4.0:
version "4.11.6" version "4.11.6"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.6.tgz#53344adb14617a13f6e8dd2ce28905d1c0ba3215" resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.6.tgz#53344adb14617a13f6e8dd2ce28905d1c0ba3215"

View File

@ -894,6 +894,7 @@ JS_SPECS = {
'third/bootstrap-notify/js/bootstrap-notify.js', 'third/bootstrap-notify/js/bootstrap-notify.js',
'third/html5-formdata/formdata.js', 'third/html5-formdata/formdata.js',
'node_modules/jquery-validation/dist/jquery.validate.js', 'node_modules/jquery-validation/dist/jquery.validate.js',
'node_modules/blueimp-md5/js/md5.js',
'node_modules/clipboard/dist/clipboard.js', 'node_modules/clipboard/dist/clipboard.js',
'third/jquery-form/jquery.form.js', 'third/jquery-form/jquery.form.js',
'third/jquery-filedrop/jquery.filedrop.js', 'third/jquery-filedrop/jquery.filedrop.js',