mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
zcommand: Add /fluid-width and /fixed-width slash commands.
This commit is contained in:
@@ -380,6 +380,14 @@ exports.slash_commands = [
|
||||
text: i18n.t("/day (Toggle day mode)"),
|
||||
name: "day",
|
||||
},
|
||||
{
|
||||
text: i18n.t("/fixed-width (Toggle fixed width mode)"),
|
||||
name: "fixed-width",
|
||||
},
|
||||
{
|
||||
text: i18n.t("/fluid-width (Toggle fluid width mode)"),
|
||||
name: "fluid-width",
|
||||
},
|
||||
{
|
||||
text: i18n.t("/light (Toggle day mode)"),
|
||||
name: "light",
|
||||
|
||||
@@ -90,6 +90,50 @@ exports.enter_night_mode = function () {
|
||||
});
|
||||
};
|
||||
|
||||
exports.enter_fluid_mode = function () {
|
||||
exports.send({
|
||||
command: "/fluid-width",
|
||||
on_success: function (data) {
|
||||
scroll_bar.set_layout_width();
|
||||
feedback_widget.show({
|
||||
populate: function (container) {
|
||||
const rendered_msg = marked(data.msg).trim();
|
||||
container.html(rendered_msg);
|
||||
},
|
||||
on_undo: function () {
|
||||
exports.send({
|
||||
command: "/fixed-width",
|
||||
});
|
||||
},
|
||||
title_text: i18n.t("Fluid width mode"),
|
||||
undo_button_text: i18n.t("Fixed width"),
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
exports.enter_fixed_mode = function () {
|
||||
exports.send({
|
||||
command: "/fixed-width",
|
||||
on_success: function (data) {
|
||||
scroll_bar.set_layout_width();
|
||||
feedback_widget.show({
|
||||
populate: function (container) {
|
||||
const rendered_msg = marked(data.msg).trim();
|
||||
container.html(rendered_msg);
|
||||
},
|
||||
on_undo: function () {
|
||||
exports.send({
|
||||
command: "/fluid-width",
|
||||
});
|
||||
},
|
||||
title_text: i18n.t("Fixed width mode"),
|
||||
undo_button_text: i18n.t("Fluid width"),
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
exports.process = function (message_content) {
|
||||
|
||||
const content = message_content.trim();
|
||||
@@ -122,6 +166,16 @@ exports.process = function (message_content) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (content === '/fluid-width') {
|
||||
exports.enter_fluid_mode();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (content === '/fixed-width') {
|
||||
exports.enter_fixed_mode();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (content === '/settings') {
|
||||
hashchange.go_to_location('settings/your-account');
|
||||
return true;
|
||||
|
||||
@@ -38,4 +38,18 @@ def process_zcommands(content: str, user_profile: UserProfile) -> Dict[str, Any]
|
||||
switch_command='night',
|
||||
setting='night_mode',
|
||||
setting_value=False))
|
||||
elif command == 'fluid-width':
|
||||
if user_profile.fluid_layout_width:
|
||||
return dict(msg='You are still in fluid width mode.')
|
||||
return dict(msg=change_mode_setting(command=command,
|
||||
switch_command='fixed-width',
|
||||
setting='fluid_layout_width',
|
||||
setting_value=True))
|
||||
elif command == 'fixed-width':
|
||||
if not user_profile.fluid_layout_width:
|
||||
return dict(msg='You are still in fixed width mode.')
|
||||
return dict(msg=change_mode_setting(command=command,
|
||||
switch_command='fluid-width',
|
||||
setting='fluid_layout_width',
|
||||
setting_value=False))
|
||||
raise JsonableError(_('No such command: %s') % (command,))
|
||||
|
||||
@@ -53,3 +53,33 @@ class ZcommandTest(ZulipTestCase):
|
||||
result = self.client_post("/json/zcommand", payload)
|
||||
self.assert_json_success(result)
|
||||
self.assertIn('still in day mode', result.json()['msg'])
|
||||
|
||||
def test_fluid_zcommand(self) -> None:
|
||||
self.login("hamlet")
|
||||
user = self.example_user("hamlet")
|
||||
user.fluid_layout_width = False
|
||||
user.save()
|
||||
|
||||
payload = dict(command="/fluid-width")
|
||||
result = self.client_post("/json/zcommand", payload)
|
||||
self.assert_json_success(result)
|
||||
self.assert_in_response('Changed to fluid-width mode!', result)
|
||||
|
||||
result = self.client_post("/json/zcommand", payload)
|
||||
self.assert_json_success(result)
|
||||
self.assert_in_response('You are still in fluid width mode', result)
|
||||
|
||||
def test_fixed_zcommand(self) -> None:
|
||||
self.login("hamlet")
|
||||
user = self.example_user("hamlet")
|
||||
user.fluid_layout_width = True
|
||||
user.save()
|
||||
|
||||
payload = dict(command="/fixed-width")
|
||||
result = self.client_post("/json/zcommand", payload)
|
||||
self.assert_json_success(result)
|
||||
self.assert_in_response('Changed to fixed-width mode!', result)
|
||||
|
||||
result = self.client_post("/json/zcommand", payload)
|
||||
self.assert_json_success(result)
|
||||
self.assert_in_response('You are still in fixed width mode', result)
|
||||
|
||||
Reference in New Issue
Block a user