Skip to content

Commit eaa8944

Browse files
committed
avatar with initials
1 parent 9012c4d commit eaa8944

File tree

7 files changed

+24
-16
lines changed

7 files changed

+24
-16
lines changed

services/static-webserver/client/source/class/osparc/data/model/User.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ qx.Class.define("osparc.data.model.User", {
3939
if (userData["login"]) {
4040
description += userData["login"];
4141
}
42-
const thumbnail = osparc.utils.Avatar.emailToThumbnail(userData["login"]);
42+
const thumbnail = osparc.utils.Avatar.emailToThumbnail(userData["login"], userData["userName"]);
4343
this.set({
4444
userId: parseInt(userData["id"]),
4545
groupId: parseInt(userData["gid"]),

services/static-webserver/client/source/class/osparc/desktop/account/MyAccount.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ qx.Class.define("osparc.desktop.account.MyAccount", {
4242
});
4343

4444
const authData = osparc.auth.Data.getInstance();
45-
45+
const username = authData.getUsername();
4646
const email = authData.getEmail();
4747
const avatarSize = 80;
4848
const img = new qx.ui.basic.Image().set({
49-
source: osparc.utils.Avatar.getUrl(email, avatarSize),
49+
source: osparc.utils.Avatar.emailToThumbnail(email, username, avatarSize),
5050
maxWidth: avatarSize,
5151
maxHeight: avatarSize,
5252
scale: true,

services/static-webserver/client/source/class/osparc/info/CommentAdd.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ qx.Class.define("osparc.info.CommentAdd", {
6868
maxHeight: 32,
6969
decorator: "rounded",
7070
});
71-
const myEmail = osparc.auth.Data.getInstance().getEmail();
71+
const authData = osparc.auth.Data.getInstance();
72+
const myUsername = authData.getUsername();
73+
const myEmail = authData.getEmail();
7274
control.set({
73-
source: osparc.utils.Avatar.getUrl(myEmail, 32)
75+
source: osparc.utils.Avatar.emailToThumbnail(myEmail, myUsername, 32)
7476
});
7577
const layout = this.getChildControl("add-comment-layout");
7678
layout.add(control, {

services/static-webserver/client/source/class/osparc/info/CommentUI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ qx.Class.define("osparc.info.CommentUI", {
104104

105105
__buildLayout: function() {
106106
const thumbnail = this.getChildControl("thumbnail");
107-
thumbnail.setSource(osparc.utils.Avatar.getUrl("", 32));
107+
thumbnail.setSource(osparc.utils.Avatar.emailToThumbnail("", "", 32));
108108

109109
const userName = this.getChildControl("user-name");
110110
userName.setValue("Unknown");

services/static-webserver/client/source/class/osparc/navigation/UserMenuButton.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ qx.Class.define("osparc.navigation.UserMenuButton", {
5151
const preferencesSettings = osparc.Preferences.getInstance();
5252
preferencesSettings.addListener("changeCreditsWarningThreshold", () => this.__updateHaloColor());
5353

54+
const myUsername = authData.getUsername() || "Username";
5455
const myEmail = authData.getEmail() || "[email protected]";
5556
const icon = this.getChildControl("icon");
5657
authData.bind("role", this, "icon", {
@@ -64,7 +65,7 @@ qx.Class.define("osparc.navigation.UserMenuButton", {
6465
icon.getContentElement().setStyles({
6566
"margin-left": "-4px"
6667
});
67-
return osparc.utils.Avatar.getUrl(myEmail, 32);
68+
return osparc.utils.Avatar.emailToThumbnail(myEmail, myUsername, 32);
6869
}
6970
});
7071
},

services/static-webserver/client/source/class/osparc/store/Groups.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ qx.Class.define("osparc.store.Groups", {
9696
groupMe.set({
9797
label: myAuthData.getUsername(),
9898
description: `${myAuthData.getFirstName()} ${myAuthData.getLastName()} - ${myAuthData.getEmail()}`,
99-
thumbnail: osparc.utils.Avatar.emailToThumbnail(myAuthData.getEmail()),
99+
thumbnail: osparc.utils.Avatar.emailToThumbnail(myAuthData.getEmail(), myAuthData.getUsername()),
100100
})
101101
return orgs;
102102
});

services/static-webserver/client/source/class/osparc/utils/Avatar.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,24 @@
2626
* Here is a little example of how to use the widget.
2727
*
2828
* <pre class='javascript'>
29-
* let image = osparc.utils.Avatar.getUrl(userEmail);
29+
* let image = osparc.utils.Avatar.emailToThumbnail(userEmail);
3030
* </pre>
3131
*/
3232

3333
qx.Class.define("osparc.utils.Avatar", {
3434
type: "static",
3535

3636
statics: {
37-
emailToThumbnail: function(email) {
38-
return this.getUrl(email, 32)
37+
emailToThumbnail: function(email, username) {
38+
return this.__getUrl(email, username, 32);
3939
},
4040

41-
getUrl: function(email = "", size = 100, defIcon = "identicon", rating = "g") {
41+
__getUrl: function(email, username, size = 100) {
42+
if (email == null) {
43+
return `https://ui-avatars.com/api/${username}/${size}`;
44+
}
4245
// MD5 (Message-Digest Algorithm) by WebToolkit
43-
let MD5 = function(s) {
46+
const MD5 = function(s) {
4447
function L(k, d) {
4548
return (k << d) | (k >>> (32 - d));
4649
}
@@ -257,8 +260,10 @@ qx.Class.define("osparc.utils.Avatar", {
257260
return i.toLowerCase();
258261
};
259262

260-
return "https://secure.gravatar.com/avatar/" + MD5(email) + "?s=" + size + "&d=" + defIcon + "&r=" + rating;
261-
}
262-
263+
const emailHash = MD5(email);
264+
const defaultImageUrl = `https://ui-avatars.com/api/${username}/${size}/`;
265+
// return `https://www.gravatar.com/avatar/${emailHash}?d=${defaultImageUrl}&s=${size}&r=g`;
266+
return `https://www.gravatar.com/avatar/${emailHash}?d=${defaultImageUrl}&s=${size}`;
267+
},
263268
}
264269
});

0 commit comments

Comments
 (0)