narrow_banner: Fix message view banner for dm with deactivated user.

Previously the empty view banner for DM with any recipients
contained "Why not start the conversation".

For deactivated users/bots, we are now not displaying it.
This commit is contained in:
adnan-td 2024-08-13 23:02:06 +05:30 committed by Tim Abbott
parent 120cfa8987
commit e23d863981
4 changed files with 49 additions and 1 deletions

View File

@ -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 { return {
title: $t( title: $t(
{ {
defaultMessage: "You have no direct messages with {person} yet.", 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( 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 { return {
title: $t({defaultMessage: "You have no direct messages with these users yet."}), title: $t({defaultMessage: "You have no direct messages with these users yet."}),
html: $t_html( html: $t_html(

View File

@ -1034,6 +1034,16 @@ export function get_non_active_human_ids(): number[] {
return human_ids; 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[] { export function get_bot_ids(): number[] {
const bot_ids = []; const bot_ids = [];

View File

@ -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.add_active_user(me);
people.initialize_current_user(me.user_id); people.initialize_current_user(me.user_id);
set_filter([["dm", me.email]]); 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 // organization has disabled sending direct messages
realm.realm_direct_message_permission_group = nobody.id; realm.realm_direct_message_permission_group = nobody.id;

View File

@ -335,6 +335,7 @@ test_people("basics", ({override}) => {
// Now deactivate isaac // Now deactivate isaac
people.deactivate(isaac); people.deactivate(isaac);
assert.equal(people.get_non_active_human_ids().length, 1); 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.get_active_human_count(), 1);
assert.equal(people.is_active_user_for_popover(isaac.user_id), false); assert.equal(people.is_active_user_for_popover(isaac.user_id), false);
assert.equal(people.is_valid_email_for_compose(isaac.email), true); assert.equal(people.is_valid_email_for_compose(isaac.email), true);