mirror of https://github.com/xwiki-labs/cryptpad
Broadcast update
This commit is contained in:
parent
08073f4853
commit
8f679c141c
|
@ -400,7 +400,7 @@
|
|||
|
||||
button {
|
||||
.toolbar_button;
|
||||
&.cp-notifications-bell {
|
||||
&.cp-notifications-bell, &.cp-maintenance-wrench {
|
||||
color: @cryptpad_text_col;
|
||||
}
|
||||
}
|
||||
|
@ -506,7 +506,7 @@
|
|||
}
|
||||
.cp-toolbar-user {
|
||||
height: @toolbar_line-height;
|
||||
.cp-toolbar-notifications {
|
||||
.cp-toolbar-notifications, .cp-toolbar-maintenance {
|
||||
height: @toolbar_line-height;
|
||||
width: @toolbar_line-height;
|
||||
margin-left: 0;
|
||||
|
@ -709,7 +709,7 @@
|
|||
height: 43px;
|
||||
}
|
||||
}
|
||||
.cp-toolbar-link, .cp-toolbar-notifications {
|
||||
.cp-toolbar-link, .cp-toolbar-notifications, .cp-toolbar-maintenance {
|
||||
line-height: @toolbar_top-height;
|
||||
width: @toolbar_top-height;
|
||||
height: @toolbar_top-height;
|
||||
|
@ -717,7 +717,7 @@
|
|||
box-sizing: border-box;
|
||||
display: inline-block;
|
||||
}
|
||||
.cp-toolbar-notifications {
|
||||
.cp-toolbar-notifications, .cp-toolbar-maintenance {
|
||||
text-align: center;
|
||||
font-size: 32px;
|
||||
margin-left: 10px;
|
||||
|
|
|
@ -128,10 +128,13 @@ commands.SET_ACCOUNT_RETENTION_TIME = makeIntegerSetter('accountRetentionTime');
|
|||
var args_isString = function (args) {
|
||||
return Array.isArray(args) && typeof(args[0]) === "string";
|
||||
};
|
||||
var args_isMaintenance = function (args) {
|
||||
return Array.isArray(args) && args[0] && args[0].end && args[0].start;
|
||||
};
|
||||
|
||||
var makeBroadcastSetter = function (attr) {
|
||||
return function (Env, args) {
|
||||
if (!args_isString(args)) {
|
||||
if (!args_isString(args) && !args_isMaintenance(args)) {
|
||||
throw new Error('INVALID_ARGS');
|
||||
}
|
||||
var str = args[0];
|
||||
|
@ -148,6 +151,10 @@ commands.SET_LAST_BROADCAST_HASH = makeBroadcastSetter('lastBroadcastHash');
|
|||
// CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['SET_SURVEY_URL', [url]]], console.log)
|
||||
commands.SET_SURVEY_URL = makeBroadcastSetter('surveyURL');
|
||||
|
||||
// CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['SET_MAINTENANCE', [{start: +Date, end: +Date}]]], console.log)
|
||||
// CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['SET_MAINTENANCE', [""]]], console.log)
|
||||
commands.SET_MAINTENANCE = makeBroadcastSetter('maintenance');
|
||||
|
||||
var Quota = require("./commands/quota");
|
||||
var Keys = require("./keys");
|
||||
var Util = require("./common-util");
|
||||
|
|
|
@ -70,6 +70,7 @@ module.exports.create = function (config) {
|
|||
// /api/broadcast
|
||||
lastBroadcastHash: '',
|
||||
surveyURL: undefined,
|
||||
maintenance: undefined,
|
||||
|
||||
netfluxUsers: {},
|
||||
|
||||
|
|
|
@ -279,11 +279,16 @@ var serveBroadcast = (function () {
|
|||
};
|
||||
|
||||
var template = function (host) {
|
||||
var maintenance = Env.maintenance;
|
||||
if (maintenance && maintenance.end && maintenance.end < (+new Date())) {
|
||||
maintenance = undefined;
|
||||
}
|
||||
return [
|
||||
'define(function(){',
|
||||
'return ' + JSON.stringify({
|
||||
lastBroadcastHash: Env.lastBroadcastHash,
|
||||
surveyURL: Env.surveyURL
|
||||
surveyURL: Env.surveyURL,
|
||||
maintenance: maintenance
|
||||
}, null, '\t'),
|
||||
'});'
|
||||
].join(';\n')
|
||||
|
|
|
@ -200,10 +200,20 @@
|
|||
}
|
||||
|
||||
.cp-admin-broadcast-form {
|
||||
margin-top: 30px;
|
||||
input.flatpickr-input {
|
||||
width: 307.875px !important; // same width as flatpickr calendar
|
||||
}
|
||||
.cp-broadcast-active {
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
align-items: start;
|
||||
padding: 10px;
|
||||
background-color: @cp_sidebar-left-bg;
|
||||
color: @cp_sidebar-left-fg;
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
.cp-broadcast-form-submit {
|
||||
margin-top: 30px;
|
||||
button {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,7 @@
|
|||
define([
|
||||
'jquery',
|
||||
'/api/config',
|
||||
'/api/broadcast',
|
||||
'/common/common-util.js',
|
||||
'/common/common-hash.js',
|
||||
'/common/common-language.js',
|
||||
|
@ -17,7 +18,7 @@ define([
|
|||
'/common/visible.js',
|
||||
|
||||
'css!/customize/fonts/cptools/style.css',
|
||||
], function ($, Config, Util, Hash, Language, UI, Constants, Feedback, h, Clipboard,
|
||||
], function ($, Config, Broadcast, Util, Hash, Language, UI, Constants, Feedback, h, Clipboard,
|
||||
Messages, AppConfig, Pages, NThen, InviteInner, Visible) {
|
||||
var UIElements = {};
|
||||
var urlArgs = Config.requireConf.urlArgs;
|
||||
|
@ -1762,23 +1763,20 @@ define([
|
|||
});
|
||||
}
|
||||
|
||||
// XXX Admin panel overrides AppConfig
|
||||
// If you set "" in the admin panel, it will remove the AppConfig survey
|
||||
var surveyURL = typeof(Config.surveyURL) !== "undefined" ? Config.surveyURL
|
||||
var surveyURL = typeof(Broadcast.surveyURL) !== "undefined" ? Broadcast.surveyURL
|
||||
: AppConfig.surveyURL;
|
||||
if (surveyURL) {
|
||||
options.push({
|
||||
tag: 'a',
|
||||
attributes: {
|
||||
'class': 'cp-toolbar-survey fa fa-graduation-cap'
|
||||
},
|
||||
content: h('span', Messages.survey),
|
||||
action: function () {
|
||||
Common.openUnsafeURL(surveyURL);
|
||||
Feedback.send('SURVEY_CLICKED');
|
||||
},
|
||||
});
|
||||
}
|
||||
options.push({
|
||||
tag: 'a',
|
||||
attributes: {
|
||||
'class': 'cp-toolbar-survey fa fa-graduation-cap'
|
||||
},
|
||||
content: h('span', Messages.survey),
|
||||
action: function () {
|
||||
Common.openUnsafeURL(surveyURL);
|
||||
Feedback.send('SURVEY_CLICKED');
|
||||
},
|
||||
});
|
||||
|
||||
options.push({ tag: 'hr' });
|
||||
// Add login or logout button depending on the current status
|
||||
|
@ -1845,6 +1843,24 @@ define([
|
|||
};
|
||||
var $userAdmin = UIElements.createDropdown(dropdownConfigUser);
|
||||
|
||||
var $survey = $userAdmin.find('.cp-toolbar-survey');
|
||||
if (!surveyURL) { $survey.hide(); }
|
||||
Common.makeUniversal('broadcast', {
|
||||
onEvent: function (obj) {
|
||||
var cmd = obj.ev;
|
||||
if (cmd !== "SURVEY") { return; }
|
||||
var url = obj.data;
|
||||
if (url === surveyURL) { return; }
|
||||
if (url && !Util.isValidURL(url)) { return; }
|
||||
surveyURL = url;
|
||||
if (!url) {
|
||||
$survey.hide();
|
||||
return;
|
||||
}
|
||||
$survey.show();
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
// Uncomment these lines to have a language selector in the admin menu
|
||||
// FIXME clicking on the inner menu hides the outer one
|
||||
|
|
|
@ -422,32 +422,6 @@ define([
|
|||
}
|
||||
};
|
||||
|
||||
Messages.broadcast_newMaintenance = "A maintenance is planned between <b>{0}</b> and <b>{1}</b>"; // XXX
|
||||
handlers['BROADCAST_MAINTENANCE'] = function (common, data) {
|
||||
var content = data.content;
|
||||
var msg = content.msg.content;
|
||||
content.getFormatText = function () {
|
||||
return Messages._getKey('broadcast_newMaintenance', [
|
||||
new Date(msg.start).toLocaleString(),
|
||||
new Date(msg.end).toLocaleString(),
|
||||
]);
|
||||
};
|
||||
if (!content.archived) {
|
||||
content.dismissHandler = defaultDismiss(common, data);
|
||||
}
|
||||
};
|
||||
|
||||
Messages.broadcast_newVersion = "A new version is available. Reload the page to discover the new features!"; // XXX
|
||||
handlers['BROADCAST_VERSION'] = function (common, data) {
|
||||
var content = data.content;
|
||||
content.getFormatText = function () {
|
||||
return Messages.broadcast_newVersion;
|
||||
};
|
||||
if (!content.archived) {
|
||||
content.dismissHandler = defaultDismiss(common, data);
|
||||
}
|
||||
};
|
||||
|
||||
Messages.broadcast_newCustom = "Message from the administrators"; // XXX
|
||||
handlers['BROADCAST_CUSTOM'] = function (common, data) {
|
||||
var content = data.content;
|
||||
|
|
|
@ -626,6 +626,33 @@ define([
|
|||
cb(JSON.parse(JSON.stringify(metadata)));
|
||||
};
|
||||
|
||||
Store.onMaintenanceUpdate = function (uid) {
|
||||
// use uid in /api/broadcast so that all connected users will use the same cached
|
||||
// version on the server
|
||||
require(['/api/broadcast?'+uid], function (Broadcast) {
|
||||
broadcast([], 'UNIVERSAL_EVENT', {
|
||||
type: 'broadcast',
|
||||
data: {
|
||||
ev: 'MAINTENANCE',
|
||||
data: Broadcast.maintenance
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
Store.onSurveyUpdate = function (uid) {
|
||||
// use uid in /api/broadcast so that all connected users will use the same cached
|
||||
// version on the server
|
||||
require(['/api/broadcast?'+uid], function (Broadcast) {
|
||||
broadcast([], 'UNIVERSAL_EVENT', {
|
||||
type: 'broadcast',
|
||||
data: {
|
||||
ev: 'SURVEY',
|
||||
data: Broadcast.surveyURL
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var makePad = function (href, roHref, title) {
|
||||
var now = +new Date();
|
||||
return {
|
||||
|
|
|
@ -690,74 +690,47 @@ define([
|
|||
var broadcasts = {};
|
||||
handlers['BROADCAST_MAINTENANCE'] = function (ctx, box, data, cb) {
|
||||
var msg = data.msg;
|
||||
var content = msg.content;
|
||||
if (content.end < (+new Date())) {
|
||||
// Expired maintenance: dismiss
|
||||
return void cb(true);
|
||||
}
|
||||
var uid = msg.uid;
|
||||
broadcasts[uid] = {
|
||||
type: box.type,
|
||||
hash: data.hash
|
||||
};
|
||||
cb(false);
|
||||
};
|
||||
handlers['BROADCAST_VERSION'] = function (ctx, box, data, cb) {
|
||||
var msg = data.msg;
|
||||
var content = msg.content;
|
||||
if (!box.ready) {
|
||||
// This is an old version message: dismiss
|
||||
return void cb(true);
|
||||
}
|
||||
if (content.reload) {
|
||||
// We're going to force a disconnect, dismiss
|
||||
ctx.Store.newVersionReload();
|
||||
return; // This message will be removed when reloading the worker
|
||||
}
|
||||
var uid = msg.uid;
|
||||
broadcasts[uid] = {
|
||||
type: box.type,
|
||||
hash: data.hash
|
||||
};
|
||||
cb(false);
|
||||
ctx.Store.onMaintenanceUpdate(uid);
|
||||
cb(true);
|
||||
};
|
||||
var activeSurvey;
|
||||
handlers['BROADCAST_SURVEY'] = function (ctx, box, data, cb) {
|
||||
var msg = data.msg;
|
||||
var uid = msg.uid;
|
||||
broadcasts[uid] = {
|
||||
var old = activeSurvey;
|
||||
activeSurvey = {
|
||||
type: box.type,
|
||||
hash: data.hash
|
||||
};
|
||||
cb(false);
|
||||
ctx.Store.onSurveyUpdate(uid);
|
||||
cb(false, old);
|
||||
};
|
||||
var activeCustom
|
||||
handlers['BROADCAST_CUSTOM'] = function (ctx, box, data, cb) {
|
||||
var msg = data.msg;
|
||||
var uid = msg.uid;
|
||||
broadcasts[uid] = {
|
||||
var old = activeCustom;
|
||||
activeCustom = {
|
||||
uid: uid,
|
||||
type: box.type,
|
||||
hash: data.hash
|
||||
};
|
||||
cb(false);
|
||||
cb(false, old);
|
||||
};
|
||||
handlers['BROADCAST_DELETE'] = function (ctx, box, data, cb) {
|
||||
var msg = data.msg;
|
||||
var content = msg.content;
|
||||
|
||||
// If this is a "clear all" message, empty the box and update lkh
|
||||
if (content.all) {
|
||||
// 3rd argument of callback: clear the mailbox
|
||||
return void cb(null, null, true);
|
||||
}
|
||||
|
||||
var uid = content.uid; // uid of the message to delete
|
||||
if (!broadcasts[uid]) {
|
||||
// We don't have this message in memory, nothing to delete
|
||||
return void cb(true);
|
||||
if (activeCustom && activeCustom.uid === uid) {
|
||||
// We have the message in memory, remove it and don't keep the DELETE msg
|
||||
cb(true, activeCustom);
|
||||
activeCustom = undefined;
|
||||
return;
|
||||
}
|
||||
|
||||
// We have the message in memory, remove it and don't keep the DELETE msg
|
||||
cb(true, broadcasts[uid]);
|
||||
delete broadcasts[uid];
|
||||
// We don't have this message in memory, nothing to delete
|
||||
cb(true);
|
||||
};
|
||||
|
||||
return {
|
||||
|
|
|
@ -219,8 +219,8 @@ define([
|
|||
|
||||
var historyState = false;
|
||||
var onHistory = function () {};
|
||||
mailbox.getMoreHistory = function (type, count, lastKnownHash, cb) {
|
||||
if (historyState) { return void cb("ALREADY_CALLED"); }
|
||||
mailbox.getMoreHistory = function (type, count, lastKnownHash, cb) {
|
||||
if (type !== "broadcast" && historyState) { return void cb("ALREADY_CALLED"); }
|
||||
historyState = true;
|
||||
var txid = Util.uid();
|
||||
execCommand('LOAD_HISTORY', {
|
||||
|
|
|
@ -2,6 +2,7 @@ define([
|
|||
'jquery',
|
||||
'/customize/application_config.js',
|
||||
'/api/config',
|
||||
'/api/broadcast',
|
||||
'/common/common-ui-elements.js',
|
||||
'/common/common-interface.js',
|
||||
'/common/common-hash.js',
|
||||
|
@ -11,7 +12,7 @@ define([
|
|||
'/common/hyperscript.js',
|
||||
'/common/messenger-ui.js',
|
||||
'/customize/messages.js',
|
||||
], function ($, Config, ApiConfig, UIElements, UI, Hash, Util, Feedback, MT, h,
|
||||
], function ($, Config, ApiConfig, Broadcast, UIElements, UI, Hash, Util, Feedback, MT, h,
|
||||
MessengerUI, Messages) {
|
||||
var Common;
|
||||
|
||||
|
@ -45,6 +46,7 @@ MessengerUI, Messages) {
|
|||
var TITLE_CLS = Bar.constants.title = "cp-toolbar-title";
|
||||
var LINK_CLS = Bar.constants.link = "cp-toolbar-link";
|
||||
var NOTIFICATIONS_CLS = Bar.constants.user = 'cp-toolbar-notifications';
|
||||
var MAINTENANCE_CLS = Bar.constants.user = 'cp-toolbar-maintenance';
|
||||
|
||||
// User admin menu
|
||||
var USERADMIN_CLS = Bar.constants.user = 'cp-toolbar-user-dropdown';
|
||||
|
@ -78,6 +80,7 @@ MessengerUI, Messages) {
|
|||
'class': USER_CLS
|
||||
}).appendTo($topContainer);
|
||||
$('<span>', {'class': LIMIT_CLS}).hide().appendTo($userContainer);
|
||||
$('<span>', {'class': MAINTENANCE_CLS + ' cp-dropdown-container'}).hide().appendTo($userContainer);
|
||||
$('<span>', {'class': NOTIFICATIONS_CLS + ' cp-dropdown-container'}).hide().appendTo($userContainer);
|
||||
$('<span>', {'class': USERADMIN_CLS + ' cp-dropdown-container'}).hide().appendTo($userContainer);
|
||||
|
||||
|
@ -1026,6 +1029,42 @@ MessengerUI, Messages) {
|
|||
return $userAdmin;
|
||||
};
|
||||
|
||||
Messages.broadcast_maintenance = "A maintenance is planned between <b>{0}</b> and <b>{1}</b>"; // XXX
|
||||
var createMaintenance = function (toolbar, config) {
|
||||
var $notif = toolbar.$top.find('.'+MAINTENANCE_CLS);
|
||||
var button = h('button.cp-maintenance-wrench.fa.fa-wrench');
|
||||
$notif.append(button);
|
||||
|
||||
|
||||
var m = Broadcast.maintenance;
|
||||
$(button).click(function () {
|
||||
if (!m || !m.start || !m.end) { return; }
|
||||
UI.alert(Messages._getKey('broadcast_maintenance', [
|
||||
new Date(m.start).toLocaleString(),
|
||||
new Date(m.end).toLocaleString(),
|
||||
]), null, true);
|
||||
});
|
||||
|
||||
Common.makeUniversal('broadcast', {
|
||||
onEvent: function (obj) {
|
||||
var cmd = obj.ev;
|
||||
if (cmd !== "MAINTENANCE") { return; }
|
||||
var data = obj.data;
|
||||
if (!data) {
|
||||
return void $notif.hide();
|
||||
}
|
||||
m = data;
|
||||
$notif.css('display', '');
|
||||
}
|
||||
});
|
||||
|
||||
if (m && m.start && m.end) {
|
||||
$notif.css('display', '');
|
||||
} else {
|
||||
$notif.hide();
|
||||
}
|
||||
};
|
||||
|
||||
var createNotifications = function (toolbar, config) {
|
||||
var $notif = toolbar.$top.find('.'+NOTIFICATIONS_CLS).show();
|
||||
var openNotifsApp = h('div.cp-notifications-gotoapp', h('p', Messages.openNotificationsApp || "Open notifications App"));
|
||||
|
@ -1287,6 +1326,7 @@ MessengerUI, Messages) {
|
|||
tb['useradmin'] = createUserAdmin;
|
||||
tb['unpinnedWarning'] = createUnpinnedWarning;
|
||||
tb['notifications'] = createNotifications;
|
||||
tb['maintenance'] = createMaintenance;
|
||||
|
||||
tb['pad'] = function () {
|
||||
toolbar.$file.show();
|
||||
|
@ -1323,6 +1363,7 @@ MessengerUI, Messages) {
|
|||
};
|
||||
|
||||
addElement(config.displayed, {}, true);
|
||||
addElement(['maintenance'], {}, true);
|
||||
|
||||
|
||||
toolbar['linkToMain'] = createLinkToMain(toolbar, config);
|
||||
|
|
Loading…
Reference in New Issue