slash commands: Add undo for /day and /night.

This also works for the synonyms /light and /dark.
This commit is contained in:
Steve Howell 2018-12-21 15:45:42 +00:00 committed by Tim Abbott
parent 995a26f4e5
commit c3a0a22661
1 changed files with 49 additions and 8 deletions

View File

@ -31,7 +31,9 @@ exports.send = function (opts) {
url: '/json/zcommand', url: '/json/zcommand',
data: data, data: data,
success: function (data) { success: function (data) {
if (on_success) {
on_success(data); on_success(data);
}
}, },
error: function () { error: function () {
exports.tell_user('server did not respond'); exports.tell_user('server did not respond');
@ -48,14 +50,47 @@ exports.tell_user = function (msg) {
$('#compose-error-msg').text(msg); $('#compose-error-msg').text(msg);
}; };
function update_setting(command) { exports.enter_day_mode = function () {
exports.send({ exports.send({
command: command, command: "/day",
on_success: function (data) { on_success: function (data) {
exports.tell_user(data.msg); night_mode.disable();
feedback_widget.show({
populate: function (container) {
container.text(data.msg);
},
on_undo: function () {
exports.send({
command: "/night",
});
},
title_text: i18n.t("Day mode"),
undo_button_text: i18n.t("Night"),
});
}, },
}); });
} };
exports.enter_night_mode = function () {
exports.send({
command: "/night",
on_success: function (data) {
night_mode.enable();
feedback_widget.show({
populate: function (container) {
container.text(data.msg);
},
on_undo: function () {
exports.send({
command: "/day",
});
},
title_text: i18n.t("Night mode"),
undo_button_text: i18n.t("Day"),
});
},
});
};
exports.process = function (message_content) { exports.process = function (message_content) {
@ -77,9 +112,15 @@ exports.process = function (message_content) {
return true; return true;
} }
var mode_commands = ['/day', '/night', '/light', '/dark']; var day_commands = ['/day', '/light'];
if (mode_commands.indexOf(content) >= 0) { if (day_commands.indexOf(content) >= 0) {
update_setting(content); exports.enter_day_mode();
return true;
}
var night_commands = ['/night', '/dark'];
if (night_commands.indexOf(content) >= 0) {
exports.enter_night_mode();
return true; return true;
} }