From 8ebefb0456b3ccbafa6cb0bd713d7c65cb38f5fa Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 12 Mar 2021 18:38:54 +0100 Subject: [PATCH] Allow anonymous notifications --- www/common/outer/async-store.js | 6 +----- www/common/outer/mailbox.js | 38 +++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index f19b11ad3..e007c4611 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -1487,7 +1487,6 @@ define([ execCommand: function (clientId, data, cb) { // The mailbox can only be used when the store is ready onReadyEvt.reg(function () { - if (!store.loggedIn) { return void cb(); } if (!store.mailbox) { return void cb ({error: 'Mailbox is disabled'}); } store.mailbox.execCommand(clientId, data, cb); }); @@ -2497,9 +2496,6 @@ define([ }; var loadMailbox = function (waitFor) { - if (!store.loggedIn || !store.proxy.edPublic) { - return; - } store.mailbox = Mailbox.init({ Store: Store, store: store, @@ -2636,7 +2632,7 @@ define([ loadUniversal(Messenger, 'messenger', waitFor); store.messenger = store.modules['messenger']; loadUniversal(Profile, 'profile', waitFor); - store.modules['team'].onReady(waitFor); + if (store.modules['team']) { store.modules['team'].onReady(waitFor); } loadUniversal(History, 'history', waitFor); }).nThen(function () { var requestLogin = function () { diff --git a/www/common/outer/mailbox.js b/www/common/outer/mailbox.js index 2c7796001..b6d02f6d9 100644 --- a/www/common/outer/mailbox.js +++ b/www/common/outer/mailbox.js @@ -24,7 +24,7 @@ define([ var BROADCAST_CHAN = '00000000000000000000000000000000'; var initializeMailboxes = function (ctx, mailboxes) { - if (!mailboxes['notifications']) { + if (!mailboxes['notifications'] && ctx.loggedIn) { mailboxes.notifications = { channel: Hash.createChannelId(), lastKnownHash: '', @@ -34,7 +34,7 @@ define([ if (res.error) { console.error(res); } }); } - if (!mailboxes['support']) { + if (!mailboxes['support'] && ctx.loggedIn) { mailboxes.support = { channel: Hash.createChannelId(), lastKnownHash: '', @@ -533,11 +533,14 @@ proxy.mailboxes = { emit: emit, clients: [], boxes: {}, - req: {} + req: {}, + loggedIn: store.loggedIn && store.proxy.edPublic }; initializeMailboxes(ctx, mailboxes); - initializeHistory(ctx); + if (ctx.loggedIn) { + initializeHistory(ctx); + } Object.keys(mailboxes).forEach(function (key) { if (TYPES.indexOf(key) === -1) { return; } @@ -554,18 +557,20 @@ proxy.mailboxes = { } }); - Object.keys(store.proxy.teams || {}).forEach(function (teamId) { - var team = store.proxy.teams[teamId]; - if (!team) { return; } - var teamMailbox = team.keys.mailbox || {}; - if (!teamMailbox.channel) { return; } - var opts = { - owners: [Util.find(team, ['keys', 'drive', 'edPublic'])] - }; - openChannel(ctx, 'team-'+teamId, teamMailbox, function () { - //console.log('Mailbox team', teamId); - }, opts); - }); + if (ctx.loggedIn) { + Object.keys(store.proxy.teams || {}).forEach(function (teamId) { + var team = store.proxy.teams[teamId]; + if (!team) { return; } + var teamMailbox = team.keys.mailbox || {}; + if (!teamMailbox.channel) { return; } + var opts = { + owners: [Util.find(team, ['keys', 'drive', 'edPublic'])] + }; + openChannel(ctx, 'team-'+teamId, teamMailbox, function () { + //console.log('Mailbox team', teamId); + }, opts); + }); + } mailbox.post = function (box, type, content) { var b = ctx.boxes[box]; @@ -590,6 +595,7 @@ proxy.mailboxes = { }; mailbox.sendTo = function (type, msg, user, cb) { + if (!ctx.loggedIn) { return void cb({error:'NOT_LOGGED_IN'}); } sendTo(ctx, type, msg, user, cb); };