Add custom Support message

This commit is contained in:
yflory 2025-12-12 16:06:49 +01:00
parent c92672eaec
commit 3b0ad98fc8
4 changed files with 57 additions and 36 deletions

View File

@ -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 = $('<div>').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 = $('<div>').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,

View File

@ -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;
};

View File

@ -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;

View File

@ -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';