diff --git a/web/src/narrow_banner.ts b/web/src/narrow_banner.ts index 3ff5c12b0b..9405fcc632 100644 --- a/web/src/narrow_banner.ts +++ b/web/src/narrow_banner.ts @@ -346,12 +346,23 @@ export function pick_empty_narrow_banner(): NarrowBannerData { }), }; } + // If the recipient is deactivated, we cannot start the conversation. + if (!people.is_person_active(recipient_user.user_id)) { + return { + title: $t( + { + defaultMessage: "You have no direct messages with {person}.", + }, + {person: recipient_user.full_name}, + ), + }; + } return { title: $t( { defaultMessage: "You have no direct messages with {person} yet.", }, - {person: people.get_by_user_id(user_ids[0]).full_name}, + {person: recipient_user.full_name}, ), html: $t_html( { @@ -366,6 +377,11 @@ export function pick_empty_narrow_banner(): NarrowBannerData { ), }; } + if (people.get_non_active_user_ids_count(user_ids) !== 0) { + return { + title: $t({defaultMessage: "You have no direct messages with these users."}), + }; + } return { title: $t({defaultMessage: "You have no direct messages with these users yet."}), html: $t_html( diff --git a/web/src/people.ts b/web/src/people.ts index 1235205adf..37fcdb1dbe 100644 --- a/web/src/people.ts +++ b/web/src/people.ts @@ -1034,6 +1034,16 @@ export function get_non_active_human_ids(): number[] { return human_ids; } +export function get_non_active_user_ids_count(user_ids: number[]): number { + let count = 0; + for (const user_id of user_ids) { + if (non_active_user_dict.has(user_id)) { + count += 1; + } + } + return count; +} + export function get_bot_ids(): number[] { const bot_ids = []; diff --git a/web/tests/message_view.test.js b/web/tests/message_view.test.js index d3ac434fb6..6311bd4e1f 100644 --- a/web/tests/message_view.test.js +++ b/web/tests/message_view.test.js @@ -418,6 +418,17 @@ run_test("show_empty_narrow_message", ({mock_template}) => { ), ); + // sending direct messages to deactivated user + realm.realm_direct_message_permission_group = everyone.id; + people.deactivate(alice); + set_filter([["dm", alice.email]]); + narrow_banner.show_empty_narrow_message(); + assert.equal( + $(".empty_feed_notice_main").html(), + empty_narrow_html("translated: You have no direct messages with Alice Smith."), + ); + people.add_active_user(alice); + people.add_active_user(me); people.initialize_current_user(me.user_id); set_filter([["dm", me.email]]); @@ -440,6 +451,16 @@ run_test("show_empty_narrow_message", ({mock_template}) => { ), ); + // group dm with a deactivated user + people.deactivate(alice); + set_filter([["dm", ray.email + "," + alice.email]]); + narrow_banner.show_empty_narrow_message(); + assert.equal( + $(".empty_feed_notice_main").html(), + empty_narrow_html("translated: You have no direct messages with these users."), + ); + people.add_active_user(alice); + // organization has disabled sending direct messages realm.realm_direct_message_permission_group = nobody.id; diff --git a/web/tests/people.test.js b/web/tests/people.test.js index b1a9635950..d86544eb8d 100644 --- a/web/tests/people.test.js +++ b/web/tests/people.test.js @@ -335,6 +335,7 @@ test_people("basics", ({override}) => { // Now deactivate isaac people.deactivate(isaac); assert.equal(people.get_non_active_human_ids().length, 1); + assert.equal(people.get_non_active_user_ids_count([isaac.user_id]), 1); assert.equal(people.get_active_human_count(), 1); assert.equal(people.is_active_user_for_popover(isaac.user_id), false); assert.equal(people.is_valid_email_for_compose(isaac.email), true);