From 9b5104c59ef89aae22844ef50041f259d564482e Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 5 Jun 2019 18:23:15 +0200 Subject: [PATCH] Update the friends when changing the username or avatar --- www/common/common-messaging.js | 22 ++++++++++++++++++++++ www/common/outer/async-store.js | 4 ++-- www/common/outer/mailbox-handlers.js | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/www/common/common-messaging.js b/www/common/common-messaging.js index d8cf76c43..3e673b1e9 100644 --- a/www/common/common-messaging.js +++ b/www/common/common-messaging.js @@ -78,5 +78,27 @@ define([ }); }; + Msg.updateMyData = function (store, curve) { + if (store.messenger) { + store.messenger.updateMyData(); + } + var myData = createData(store.proxy); + var todo = function (friend) { + if (!friend || !friend.notifications) { return; } + myData.channel = friend.channel; + store.mailbox.sendTo('UPDATE_DATA', myData, { + channel: friend.notifications, + curvePublic: friend.curvePublic + }, function (obj) { + if (obj && obj.error) { console.error(obj); } + }); + }; + if (curve) { + var friend = getFriend(store.proxy, curve); + return void todo(friend); + } + eachFriend(store.proxy.friends || {}, todo); + }; + return Msg; }); diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 8df78f11c..037def149 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -66,7 +66,7 @@ define([ } broadcast([clientId], "UPDATE_METADATA"); if (Array.isArray(path) && path[0] === 'profile' && store.messenger) { - store.messenger.updateMyData(); + Messaging.updateMyData(store); } onSync(cb); }; @@ -644,7 +644,7 @@ define([ } store.proxy[Constants.displayNameKey] = value; broadcast([clientId], "UPDATE_METADATA"); - if (store.messenger) { store.messenger.updateMyData(); } + Messaging.updateMyData(store); onSync(cb); }; diff --git a/www/common/outer/mailbox-handlers.js b/www/common/outer/mailbox-handlers.js index ddf316fb1..0ab804dcf 100644 --- a/www/common/outer/mailbox-handlers.js +++ b/www/common/outer/mailbox-handlers.js @@ -152,6 +152,7 @@ define([ Object.keys(msg.content).forEach(function (key) { friend[key] = msg.content[key]; }); + ctx.updateMetadata(); cb(true); };