Update user data in comments in realtime

pull/1/head
yflory 5 years ago
parent 8e08f1b3e5
commit e71a6fb1e2

@ -68,17 +68,21 @@ define([
// Return the author ID and add/update the data for registered users // Return the author ID and add/update the data for registered users
// Return the username for unregistered users // Return the username for unregistered users
var updateAuthorData = function (Env) { var updateAuthorData = function (Env, onChange) {
var userData = Env.metadataMgr.getUserData(); var userData = Env.metadataMgr.getUserData();
if (!Env.common.isLoggedIn()) { if (!Env.common.isLoggedIn()) {
return userData.name; return userData.name;
} }
var myAuthorId = getAuthorId(Env, userData.curvePublic); var myAuthorId = getAuthorId(Env, userData.curvePublic);
var data = Env.comments.authors[myAuthorId] = Env.comments.authors[myAuthorId] || {}; var data = Env.comments.authors[myAuthorId] = Env.comments.authors[myAuthorId] || {};
var old = Sortify(data);
data.name = userData.name; data.name = userData.name;
data.avatar = userData.avatar; data.avatar = userData.avatar;
data.profile = userData.profile; data.profile = userData.profile;
data.curvePublic = userData.curvePublic; data.curvePublic = userData.curvePublic;
if (typeof(onChange) === "function" && Sortify(data) !== old) {
onChange();
}
return myAuthorId; return myAuthorId;
}; };
@ -154,7 +158,7 @@ define([
var redrawComments = function (Env) { var redrawComments = function (Env) {
// Don't redraw if there were no change // Don't redraw if there were no change
var str = Sortify((Env.comments || {}).data || {}); var str = Sortify(Env.comments || {});
if (str === Env.oldComments) { return; } if (str === Env.oldComments) { return; }
Env.oldComments = str; Env.oldComments = str;
@ -341,10 +345,22 @@ define([
} }
if (Env.ready === 0) { if (Env.ready === 0) {
Env.ready = true; Env.ready = true;
updateAuthorData(Env, function () {
changed = true;
});
// On ready, if our user data have changed or if we've added the initial structure
// of the comments, push the changes
if (changed) { if (changed) {
updateMetadata(Env); updateMetadata(Env);
Env.framework.localChange(); Env.framework.localChange();
} }
} else if (Env.ready) {
// Everytime there is a metadata change, check if our user data have changed
// and puhs the update sif necessary
updateAuthorData(Env, function () {
updateMetadata(Env);
Env.framework.localChange();
});
} }
redrawComments(Env); redrawComments(Env);
}; };

Loading…
Cancel
Save