mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
compose-actions: Load compose box for PMs based on org policy.
If an organization has disabled sending private messages, we do not want to load the compose box automatically for "pm-with" narrows. We still open the compose box for private messages narrows with a single bot user as this is not limited by this organization setting. Also, if the compose box was active/started in a narrow with a bot user, but had no content, then we want to close/cancel that in a new narrow with a person or group.
This commit is contained in:
committed by
Tim Abbott
parent
836db701aa
commit
09c4e2f662
@@ -5,6 +5,9 @@ const {strict: assert} = require("assert");
|
||||
const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
const {page_params} = require("../zjsunit/zpage_params");
|
||||
|
||||
const settings_config = zrequire("settings_config");
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
@@ -443,6 +446,22 @@ test("on_narrow", ({override, override_rewire}) => {
|
||||
let narrowed_by_pm_reply;
|
||||
override(narrow_state, "narrowed_by_pm_reply", () => narrowed_by_pm_reply);
|
||||
|
||||
const steve = {
|
||||
user_id: 90,
|
||||
email: "steve@example.com",
|
||||
full_name: "Steve Stephenson",
|
||||
is_bot: false,
|
||||
};
|
||||
people.add_active_user(steve);
|
||||
|
||||
const bot = {
|
||||
user_id: 91,
|
||||
email: "bot@example.com",
|
||||
full_name: "Steve's bot",
|
||||
is_bot: true,
|
||||
};
|
||||
people.add_active_user(bot);
|
||||
|
||||
let cancel_called = false;
|
||||
override_rewire(compose_actions, "cancel", () => {
|
||||
cancel_called = true;
|
||||
@@ -479,6 +498,24 @@ test("on_narrow", ({override, override_rewire}) => {
|
||||
start_called = true;
|
||||
});
|
||||
narrowed_by_pm_reply = true;
|
||||
page_params.realm_private_message_policy =
|
||||
settings_config.private_message_policy_values.disabled.code;
|
||||
compose_actions.on_narrow({
|
||||
force_close: false,
|
||||
trigger: "not-search",
|
||||
private_message_recipient: "steve@example.com",
|
||||
});
|
||||
assert.ok(!start_called);
|
||||
|
||||
compose_actions.on_narrow({
|
||||
force_close: false,
|
||||
trigger: "not-search",
|
||||
private_message_recipient: "bot@example.com",
|
||||
});
|
||||
assert.ok(start_called);
|
||||
|
||||
page_params.realm_private_message_policy =
|
||||
settings_config.private_message_policy_values.by_anyone.code;
|
||||
compose_actions.on_narrow({
|
||||
force_close: false,
|
||||
trigger: "not-search",
|
||||
|
||||
@@ -25,6 +25,7 @@ import * as recent_topics_ui from "./recent_topics_ui";
|
||||
import * as recent_topics_util from "./recent_topics_util";
|
||||
import * as reload_state from "./reload_state";
|
||||
import * as resize from "./resize";
|
||||
import * as settings_config from "./settings_config";
|
||||
import * as spectators from "./spectators";
|
||||
import * as stream_bar from "./stream_bar";
|
||||
import * as stream_data from "./stream_data";
|
||||
@@ -636,6 +637,23 @@ export function on_narrow(opts) {
|
||||
if (opts.trigger === "search" && !opts.private_message_recipient) {
|
||||
return;
|
||||
}
|
||||
// Do not open compose box if organization has disabled sending
|
||||
// private messages and recipient is not a bot.
|
||||
if (
|
||||
page_params.realm_private_message_policy ===
|
||||
settings_config.private_message_policy_values.disabled.code &&
|
||||
opts.private_message_recipient
|
||||
) {
|
||||
const emails = opts.private_message_recipient.split(",");
|
||||
if (emails.length !== 1 || !people.get_by_email(emails[0]).is_bot) {
|
||||
// If we are navigating between private message conversations,
|
||||
// we want the compose box to close for non-bot users.
|
||||
if (compose_state.composing()) {
|
||||
cancel();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
start("private");
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user