From dbce0fe429cb0eb7ed68dbc0d59a4d7bec8be1a6 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 16 Mar 2021 15:25:28 +0100 Subject: [PATCH] Use 33 characters admin channels --- lib/commands/channel.js | 15 +++++++++++---- lib/hk-util.js | 4 +++- www/common/outer/mailbox.js | 8 +++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/commands/channel.js b/lib/commands/channel.js index 43929a838..f4d9a84ef 100644 --- a/lib/commands/channel.js +++ b/lib/commands/channel.js @@ -255,7 +255,7 @@ Channel.writePrivateMessage = function (Env, args, _cb, Server, netfluxId) { var allowed = HK.listAllowedUsers(metadata); // Special broadcast channel - if (channelId === '00000000000000000000000000000000') { + if (channelId.length === HK.ADMIN_CHANNEL_LENGTH) { allowed = Env.admins; } @@ -283,12 +283,19 @@ Channel.writePrivateMessage = function (Env, args, _cb, Server, netfluxId) { // historyKeeper already knows how to handle metadata and message validation, so we just pass it off here // if the message isn't valid it won't be stored. - Env.historyKeeper.channelMessage(Server, channelStruct, fullMessage); + Env.historyKeeper.channelMessage(Server, channelStruct, fullMessage, function (err) { + if (err) { + // Message not stored... + return void cb(err); + } - Server.getChannelUserList(channelId).forEach(function (userId) { - Server.send(userId, fullMessage); + // Broadcast the message + Server.getChannelUserList(channelId).forEach(function (userId) { + Server.send(userId, fullMessage); + }); }); + cb(); }); }; diff --git a/lib/hk-util.js b/lib/hk-util.js index f7aee6af8..813e8179e 100644 --- a/lib/hk-util.js +++ b/lib/hk-util.js @@ -34,6 +34,7 @@ const getHash = HK.getHash = function (msg, Log) { // historyKeeper should explicitly store any channel // with a 32 character id const STANDARD_CHANNEL_LENGTH = HK.STANDARD_CHANNEL_LENGTH = 32; +const ADMIN_CHANNEL_LENGTH = HK.ADMIN_CHANNEL_LENGTH = 33; // historyKeeper should not store messages sent to any channel // with a 34 character id @@ -883,7 +884,8 @@ HK.onChannelMessage = function (Env, Server, channel, msgStruct, cb) { // don't store messages if the channel id indicates that it's an ephemeral message if (!channel.id || channel.id.length === EPHEMERAL_CHANNEL_LENGTH) { return void cb(); } - if (channel.id === '00000000000000000000000000000000' && msgStruct[1] !== null) { + // Admin channel. We can only write to this one from private message (RPC) + if (channel.id.length === ADMIN_CHANNEL_LENGTH && msgStruct[1] !== null) { return void cb('ERESTRICTED_ADMIN'); } diff --git a/www/common/outer/mailbox.js b/www/common/outer/mailbox.js index a7d936d25..31ffb8c8f 100644 --- a/www/common/outer/mailbox.js +++ b/www/common/outer/mailbox.js @@ -21,7 +21,7 @@ define([ var BLOCKING_TYPES = [ ]; - var BROADCAST_CHAN = '00000000000000000000000000000000'; + var BROADCAST_CHAN = '000000000000000000000000000000000'; // Admin channel, 33 characters var initializeMailboxes = function (ctx, mailboxes) { if (!mailboxes['notifications'] && ctx.loggedIn) { @@ -44,6 +44,12 @@ define([ if (res.error) { console.error(res); } }); } + + // XXX Debugging code to remove deprecated dev data + if (mailboxes.broadcast && mailboxes.broacast.channel && mailboxes.broadcast.channel.length === 32) { + delete mailboxes['broadcast']; + } + if (!mailboxes['broadcast']) { mailboxes.broadcast = { channel: BROADCAST_CHAN,