Skip to content

🎨 [Frontend] Avatar for users with hidden email #6952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ qx.Class.define("osparc.data.model.User", {
if (userData["login"]) {
description += userData["login"];
}
const thumbnail = osparc.utils.Avatar.emailToThumbnail(userData["login"]);
const thumbnail = osparc.utils.Avatar.emailToThumbnail(userData["login"], userData["userName"]);
this.set({
userId: parseInt(userData["id"]),
groupId: parseInt(userData["gid"]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ qx.Class.define("osparc.desktop.account.MyAccount", {
});

const authData = osparc.auth.Data.getInstance();

const username = authData.getUsername();
const email = authData.getEmail();
const avatarSize = 80;
const img = new qx.ui.basic.Image().set({
source: osparc.utils.Avatar.getUrl(email, avatarSize),
source: osparc.utils.Avatar.emailToThumbnail(email, username, avatarSize),
maxWidth: avatarSize,
maxHeight: avatarSize,
scale: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ qx.Class.define("osparc.info.CommentAdd", {
maxHeight: 32,
decorator: "rounded",
});
const myEmail = osparc.auth.Data.getInstance().getEmail();
const authData = osparc.auth.Data.getInstance();
const myUsername = authData.getUsername();
const myEmail = authData.getEmail();
control.set({
source: osparc.utils.Avatar.getUrl(myEmail, 32)
source: osparc.utils.Avatar.emailToThumbnail(myEmail, myUsername, 32)
});
const layout = this.getChildControl("add-comment-layout");
layout.add(control, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ qx.Class.define("osparc.info.CommentUI", {

__buildLayout: function() {
const thumbnail = this.getChildControl("thumbnail");
thumbnail.setSource(osparc.utils.Avatar.getUrl("", 32));
thumbnail.setSource(osparc.utils.Avatar.emailToThumbnail("", "", 32));

const userName = this.getChildControl("user-name");
userName.setValue("Unknown");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ qx.Class.define("osparc.navigation.UserMenuButton", {
const preferencesSettings = osparc.Preferences.getInstance();
preferencesSettings.addListener("changeCreditsWarningThreshold", () => this.__updateHaloColor());

const myUsername = authData.getUsername() || "Username";
const myEmail = authData.getEmail() || "[email protected]";
const icon = this.getChildControl("icon");
authData.bind("role", this, "icon", {
Expand All @@ -64,7 +65,7 @@ qx.Class.define("osparc.navigation.UserMenuButton", {
icon.getContentElement().setStyles({
"margin-left": "-4px"
});
return osparc.utils.Avatar.getUrl(myEmail, 32);
return osparc.utils.Avatar.emailToThumbnail(myEmail, myUsername, 32);
}
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ qx.Class.define("osparc.store.Groups", {
groupMe.set({
label: myAuthData.getUsername(),
description: `${myAuthData.getFirstName()} ${myAuthData.getLastName()} - ${myAuthData.getEmail()}`,
thumbnail: osparc.utils.Avatar.emailToThumbnail(myAuthData.getEmail()),
thumbnail: osparc.utils.Avatar.emailToThumbnail(myAuthData.getEmail(), myAuthData.getUsername()),
})
return orgs;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ qx.Class.define("osparc.store.Store", {
check: "Array",
init: []
},
market: {
licensedItems: {
check: "Array",
init: []
},
Expand Down Expand Up @@ -618,7 +618,7 @@ qx.Class.define("osparc.store.Store", {
__getOrgClassifiers: function(orgId, useCache = false) {
const params = {
url: {
"gid": orgId
"gid": parseInt(orgId)
}
};
return osparc.data.Resources.get("classifiers", params, useCache);
Expand All @@ -640,7 +640,7 @@ qx.Class.define("osparc.store.Store", {
}
const classifierPromises = [];
orgs.forEach(org => {
classifierPromises.push(this.__getOrgClassifiers(org["gid"], !reload));
classifierPromises.push(this.__getOrgClassifiers(org.getGroupId(), !reload));
});
Promise.all(classifierPromises)
.then(orgsClassifiersMD => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,22 @@
* Here is a little example of how to use the widget.
*
* <pre class='javascript'>
* let image = osparc.utils.Avatar.getUrl(userEmail);
* let image = osparc.utils.Avatar.emailToThumbnail(userEmail);
* </pre>
*/

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

statics: {
emailToThumbnail: function(email) {
return this.getUrl(email, 32)
emailToThumbnail: function(email, username) {
return this.__getUrl(email, username, 32);
},

getUrl: function(email = "", size = 100, defIcon = "identicon", rating = "g") {
__getUrl: function(email, username, size = 100) {
email = email || "";
// MD5 (Message-Digest Algorithm) by WebToolkit
let MD5 = function(s) {
const MD5 = function(s) {
function L(k, d) {
return (k << d) | (k >>> (32 - d));
}
Expand Down Expand Up @@ -257,8 +258,9 @@ qx.Class.define("osparc.utils.Avatar", {
return i.toLowerCase();
};

return "https://secure.gravatar.com/avatar/" + MD5(email) + "?s=" + size + "&d=" + defIcon + "&r=" + rating;
}

const emailHash = MD5(email);
const defaultImageUrl = `https://ui-avatars.com/api/${username}/${size}`;
return `https://www.gravatar.com/avatar/${emailHash}?d=${defaultImageUrl}&s=${size}&r=g`;
},
}
});
Loading