From 0ce32464fdbd9773c45efea73fab3b7cc5de274d Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 30 Aug 2017 12:26:11 +0200 Subject: [PATCH] Fix flickering avatar in firefox --- www/common/common-userlist.js | 7 ++++++- www/common/cryptpad-common.js | 3 +++ www/common/metadata-manager.js | 6 ++++-- www/common/sframe-common-interface.js | 4 +++- www/common/toolbar3.js | 1 - 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/www/common/common-userlist.js b/www/common/common-userlist.js index e7f2449fa..1d80e792c 100644 --- a/www/common/common-userlist.js +++ b/www/common/common-userlist.js @@ -1,4 +1,4 @@ -define(function () { +define(['json.sortify'], function (Sortify) { var module = {}; module.create = function (info, onLocal, Cryptget, Cryptpad) { @@ -15,6 +15,7 @@ define(function () { var parsed = Cryptpad.parsePadUrl(window.location.href); var appType = parsed ? parsed.type : undefined; + var oldUserData = {}; var addToUserData = exp.addToUserData = function(data) { var users = userList.users; for (var attrname in data) { userData[attrname] = data[attrname]; } @@ -28,6 +29,10 @@ define(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); } }; diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index f5bbbef55..c5e4c02e6 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -1793,12 +1793,15 @@ define([ }; var $userAdmin = createDropdown(dropdownConfigUser); + var oldUrl; if (account && !config.static && store) { var $avatar = $userAdmin.find('.buttonTitle'); var updateButton = function (newName) { var profile = store.getProfile(); var url = profile && profile.avatar; + if (oldUrl === url) { return; } + oldUrl = url; $avatar.html(''); common.displayAvatar($avatar, url, newName, function ($img) { if ($img) { diff --git a/www/common/metadata-manager.js b/www/common/metadata-manager.js index c7fc85924..1c8994d00 100644 --- a/www/common/metadata-manager.js +++ b/www/common/metadata-manager.js @@ -1,4 +1,4 @@ -define([], function () { +define(['json.sortify'], function (Sortify) { var UNINIT = 'uninitialized'; var create = function (sframeChan) { var meta = UNINIT; @@ -102,7 +102,9 @@ define([], function () { return Object.freeze({ 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)); metadataLazyObj = JSON.parse(JSON.stringify(m)); change(false); diff --git a/www/common/sframe-common-interface.js b/www/common/sframe-common-interface.js index eb4bc35a5..f0f3a7da0 100644 --- a/www/common/sframe-common-interface.js +++ b/www/common/sframe-common-interface.js @@ -208,15 +208,17 @@ define([ var $displayName = $userAdmin.find('.'+displayNameCls); var $avatar = $userAdmin.find('.buttonTitle'); + var oldUrl; var updateButton = function () { var myData = metadataMgr.getUserData(); if (!myData) { return; } var newName = myData.name; var url = myData.avatar; $displayName.text(newName || Messages.anonymous); - if (accountName) { + if (accountName && oldUrl !== url) { $avatar.html(''); UI.displayAvatar(Common, $avatar, url, newName, function ($img) { + oldUrl = url; if ($img) { $userAdmin.find('button').addClass('avatar'); } diff --git a/www/common/toolbar3.js b/www/common/toolbar3.js index 316f4849a..fbd1dd1e0 100644 --- a/www/common/toolbar3.js +++ b/www/common/toolbar3.js @@ -188,7 +188,6 @@ define([ var $editUsersList = $('
', {'class': 'userlist-others'}); // Editors - // TODO iframe enable friends var pendingFriends = Common.getPendingFriends(); editUsersNames.forEach(function (data) { var name = data.name || Messages.anonymous;