Fix flickering avatar in firefox

pull/1/head
yflory 7 years ago
parent 4db4f66786
commit 0ce32464fd

@ -1,4 +1,4 @@
define(function () { define(['json.sortify'], function (Sortify) {
var module = {}; var module = {};
module.create = function (info, onLocal, Cryptget, Cryptpad) { module.create = function (info, onLocal, Cryptget, Cryptpad) {
@ -15,6 +15,7 @@ define(function () {
var parsed = Cryptpad.parsePadUrl(window.location.href); var parsed = Cryptpad.parsePadUrl(window.location.href);
var appType = parsed ? parsed.type : undefined; var appType = parsed ? parsed.type : undefined;
var oldUserData = {};
var addToUserData = exp.addToUserData = function(data) { var addToUserData = exp.addToUserData = function(data) {
var users = userList.users; var users = userList.users;
for (var attrname in data) { userData[attrname] = data[attrname]; } for (var attrname in data) { userData[attrname] = data[attrname]; }
@ -28,6 +29,10 @@ define(function () {
} }
if(userList && typeof userList.onChange === "function") { if(userList && typeof userList.onChange === "function") {
// Make sure we don't update the userlist everytime someone makes a change to the pad
if (Sortify(oldUserData) === Sortify(userData)) { return; }
oldUserData = JSON.parse(JSON.stringify(userData));
userList.onChange(userData); userList.onChange(userData);
} }
}; };

@ -1793,12 +1793,15 @@ define([
}; };
var $userAdmin = createDropdown(dropdownConfigUser); var $userAdmin = createDropdown(dropdownConfigUser);
var oldUrl;
if (account && !config.static && store) { if (account && !config.static && store) {
var $avatar = $userAdmin.find('.buttonTitle'); var $avatar = $userAdmin.find('.buttonTitle');
var updateButton = function (newName) { var updateButton = function (newName) {
var profile = store.getProfile(); var profile = store.getProfile();
var url = profile && profile.avatar; var url = profile && profile.avatar;
if (oldUrl === url) { return; }
oldUrl = url;
$avatar.html(''); $avatar.html('');
common.displayAvatar($avatar, url, newName, function ($img) { common.displayAvatar($avatar, url, newName, function ($img) {
if ($img) { if ($img) {

@ -1,4 +1,4 @@
define([], function () { define(['json.sortify'], function (Sortify) {
var UNINIT = 'uninitialized'; var UNINIT = 'uninitialized';
var create = function (sframeChan) { var create = function (sframeChan) {
var meta = UNINIT; var meta = UNINIT;
@ -102,7 +102,9 @@ define([], function () {
return Object.freeze({ return Object.freeze({
updateMetadata: function (m) { updateMetadata: function (m) {
if (JSON.stringify(metadataObj) === JSON.stringify(m)) { return; } // JSON.parse(JSON.stringify()) reorders the json, so we have to use sortify even
// if it's on our own computer
if (Sortify(metadataLazyObj) === Sortify(m)) { return; }
metadataObj = JSON.parse(JSON.stringify(m)); metadataObj = JSON.parse(JSON.stringify(m));
metadataLazyObj = JSON.parse(JSON.stringify(m)); metadataLazyObj = JSON.parse(JSON.stringify(m));
change(false); change(false);

@ -208,15 +208,17 @@ define([
var $displayName = $userAdmin.find('.'+displayNameCls); var $displayName = $userAdmin.find('.'+displayNameCls);
var $avatar = $userAdmin.find('.buttonTitle'); var $avatar = $userAdmin.find('.buttonTitle');
var oldUrl;
var updateButton = function () { var updateButton = function () {
var myData = metadataMgr.getUserData(); var myData = metadataMgr.getUserData();
if (!myData) { return; } if (!myData) { return; }
var newName = myData.name; var newName = myData.name;
var url = myData.avatar; var url = myData.avatar;
$displayName.text(newName || Messages.anonymous); $displayName.text(newName || Messages.anonymous);
if (accountName) { if (accountName && oldUrl !== url) {
$avatar.html(''); $avatar.html('');
UI.displayAvatar(Common, $avatar, url, newName, function ($img) { UI.displayAvatar(Common, $avatar, url, newName, function ($img) {
oldUrl = url;
if ($img) { if ($img) {
$userAdmin.find('button').addClass('avatar'); $userAdmin.find('button').addClass('avatar');
} }

@ -188,7 +188,6 @@ define([
var $editUsersList = $('<div>', {'class': 'userlist-others'}); var $editUsersList = $('<div>', {'class': 'userlist-others'});
// Editors // Editors
// TODO iframe enable friends
var pendingFriends = Common.getPendingFriends(); var pendingFriends = Common.getPendingFriends();
editUsersNames.forEach(function (data) { editUsersNames.forEach(function (data) {
var name = data.name || Messages.anonymous; var name = data.name || Messages.anonymous;

Loading…
Cancel
Save