Skip to content

Commit

Permalink
compose: Allow the user to direct message bots despite of policy.
Browse files Browse the repository at this point in the history
After the changes in zulip#25572, users were no longer able to start a direct
message with bots if the organization disabled direct messages. However,
we should allow direct messages to bots regardless of the policy because
it's a useful interface for users to interact with various classes of
bots.

user_ids_string_to_ids_array was also modified to prevent cases where
the split function returned an array of [0] rather than [] when dealing
with a empty id string of "".

Fixes: zulip#21896.
  • Loading branch information
Joelute committed Sep 7, 2023
1 parent fdd811b commit b5074ad
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
7 changes: 3 additions & 4 deletions web/src/compose_recipient.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as dropdown_widget from "./dropdown_widget";
import {$t} from "./i18n";
import * as narrow_state from "./narrow_state";
import {page_params} from "./page_params";
import * as people from "./people";
import * as settings_config from "./settings_config";
import * as stream_bar from "./stream_bar";
import * as stream_data from "./stream_data";
Expand Down Expand Up @@ -110,10 +111,8 @@ export function update_on_recipient_change() {

export function get_posting_policy_error_message() {
if (selected_recipient_id === "direct") {
if (
page_params.realm_private_message_policy ===
settings_config.private_message_policy_values.disabled.code
) {
const recipients = compose_pm_pill.get_user_ids_string();
if (!people.user_can_direct_message(recipients)) {
return $t({
defaultMessage: "Direct messages are disabled in this organization.",
});
Expand Down
2 changes: 1 addition & 1 deletion web/src/people.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export function user_ids_string_to_emails_string(user_ids_string: string): strin
}

export function user_ids_string_to_ids_array(user_ids_string: string): number[] {
const user_ids = user_ids_string.split(",");
const user_ids = user_ids_string.length === 0 ? [] : user_ids_string.split(",");
const ids = user_ids.map(Number);
return ids;
}
Expand Down
4 changes: 3 additions & 1 deletion web/tests/compose_actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const compose_fade = mock_esm("../src/compose_fade", {
set_focused_recipient: noop,
update_all: noop,
});
const compose_pm_pill = mock_esm("../src/compose_pm_pill");
const compose_pm_pill = mock_esm("../src/compose_pm_pill", {
get_user_ids_string: ()=> ""
});
const compose_ui = mock_esm("../src/compose_ui", {
autosize_textarea: noop,
is_full_size: () => false,
Expand Down

0 comments on commit b5074ad

Please sign in to comment.