From 3b0ad98fc813458df11074383a58cf643a42d6ef Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 12 Dec 2025 16:06:49 +0100 Subject: [PATCH] Add custom Support message --- www/common/sframe-common-mailbox.js | 65 +++++++++++++---------------- www/common/sframe-common.js | 13 ++++++ www/support/app-support.less | 2 +- www/support/inner.js | 13 ++++++ 4 files changed, 57 insertions(+), 36 deletions(-) diff --git a/www/common/sframe-common-mailbox.js b/www/common/sframe-common-mailbox.js index 7d8e164c9..dd5469fc5 100644 --- a/www/common/sframe-common-mailbox.js +++ b/www/common/sframe-common-mailbox.js @@ -207,12 +207,38 @@ define([ onMessageHandlers.forEach(todo); }; + var onViewed = function (data) { + // data = { type: 'type', hash: 'hash' } + onViewedHandlers.forEach(function (f) { + try { + f(data); + if (isNotification(data.type)) { + Notifications.remove(Common, data); + } + } catch (e) { + console.error(e); + } + }); + removeFromHistory(data.type, data.hash); + }; + + var onMessage = mailbox.onMessage = function (data, cb) { + // data = { type: 'type', content: {msg: 'msg', hash: 'hash'} } + pushMessage(data); + if (data.content && typeof (data.content.getFormatText) === "function") { + var text = $('
').html(data.content.getFormatText()).text(); + cb({ + msg: text + }); + } + if (!history[data.type]) { history[data.type] = []; } + history[data.type].push(data.content); + }; + const custom = AppConfig.customBroadcast; if (Array.isArray(custom)) { - const metadataMgr = Common.getMetadataMgr(); - const customBcast = () => { + Common.onAccountOnline(metadataMgr => { const priv = metadataMgr.getPrivateData(); - if (priv.offline !== false) { return; } // reject undefined/true const dismissed = priv.settings?.broadcast?.viewed || []; const lang = Messages._getLanguage(); custom.forEach(obj => { @@ -245,42 +271,11 @@ define([ }; mailbox.onMessage(data, () => {}); }); - - metadataMgr.off('change', customBcast); - }; - metadataMgr.onChange(customBcast); + }); } - var onViewed = function (data) { - // data = { type: 'type', hash: 'hash' } - onViewedHandlers.forEach(function (f) { - try { - f(data); - if (isNotification(data.type)) { - Notifications.remove(Common, data); - } - } catch (e) { - console.error(e); - } - }); - removeFromHistory(data.type, data.hash); - }; - - var onMessage = mailbox.onMessage = function (data, cb) { - // data = { type: 'type', content: {msg: 'msg', hash: 'hash'} } - pushMessage(data); - if (data.content && typeof (data.content.getFormatText) === "function") { - var text = $('
').html(data.content.getFormatText()).text(); - cb({ - msg: text - }); - } - if (!history[data.type]) { history[data.type] = []; } - history[data.type].push(data.content); - }; - mailbox.dismiss = function (data, cb) { var dataObj = { hash: data.content.hash, diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index c3013b35d..320140d9c 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -92,6 +92,19 @@ define([ funcs.getSframeChannel = function () { return ctx.sframeChan; }; funcs.getAppConfig = function () { return AppConfig; }; + funcs.onAccountOnline = function (f) { + const metadataMgr = ctx.metadataMgr; + const cb = Util.once(f); + const todo = () => { + const priv = metadataMgr.getPrivateData(); + if (priv.offline !== false) { return; } + cb(metadataMgr); + metadataMgr.off('change', todo); + }; + metadataMgr.onChange(todo); + todo(); + }; + funcs.isLoggedIn = function () { return ctx.metadataMgr.getPrivateData().loggedIn; }; diff --git a/www/support/app-support.less b/www/support/app-support.less index 25ca71074..f15f11e02 100644 --- a/www/support/app-support.less +++ b/www/support/app-support.less @@ -44,7 +44,7 @@ color: @cryptpad_color_link; text-decoration: underline; } - .alert-info { + .alert-info, .alert-warning { font-size: 16px; margin-top: 15px; margin-bottom: 15px; diff --git a/www/support/inner.js b/www/support/inner.js index 7cf3ae87a..2ae73e10a 100644 --- a/www/support/inner.js +++ b/www/support/inner.js @@ -50,6 +50,7 @@ define([ 'cp-support-list', ], 'new': [ // Msg.support_cat_new + 'cp-support-custom', 'cp-support-subscribe', 'cp-support-language', 'cp-support-form', @@ -220,6 +221,18 @@ define([ return $(content); }; + create['custom'] = function () { + const msg = AppConfig.customSupportMsg; + if (!msg) { return $(); } + const lang = Messages._getLanguage(); + const text = msg[lang] || msg['default']; + if (!text) { return $(); } + const div = h('div.cp-support-subscribe.cp-sidebarlayout-element', [ + h('div.alert.alert-warning', text) + ]); + return $(div); + }; + // Create a new tickets create['form'] = function () { var key = 'form';