util: Move is_pm_recipient to compose_fade_helper.

"is_pm_recipient" is not supposed to be called with an arbitrary
recipient object which might have "to_user_ids" being undefined.
Since this helper is only used with focused_recipient in
compose_fade_helper, we move it there.

Note that the helper is no longer separately tested. It is now covered
by the test case of "compose_fade_helper.would_receive_message".

(See
5e74a8d0cc/static/js/compose.js (L156-L162))

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
Zixuan James Li
2022-12-05 16:56:24 -05:00
committed by Tim Abbott
parent 55793cb4d5
commit b757c1a9b6
3 changed files with 6 additions and 12 deletions

View File

@@ -32,13 +32,6 @@ run_test("extract_pm_recipients", () => {
assert.equal(util.extract_pm_recipients("bob@foo.com, ").length, 1);
});
run_test("is_pm_recipient", () => {
const message = {to_user_ids: "31,32,33"};
assert.ok(util.is_pm_recipient(31, message));
assert.ok(util.is_pm_recipient(32, message));
assert.ok(!util.is_pm_recipient(34, message));
});
run_test("lower_bound", () => {
const arr = [{x: 10}, {x: 20}, {x: 30}, {x: 40}, {x: 50}];

View File

@@ -16,6 +16,11 @@ export function set_focused_recipient(recipient) {
focused_recipient = recipient;
}
function is_pm_recipient(user_id) {
const recipients = focused_recipient.to_user_ids.split(",");
return recipients.includes(user_id.toString());
}
export function would_receive_message(user_id) {
if (focused_recipient.type === "stream") {
const sub = sub_store.get(focused_recipient.stream_id);
@@ -30,7 +35,7 @@ export function would_receive_message(user_id) {
}
// PM, so check if the given email is in the recipients list.
return util.is_pm_recipient(user_id, focused_recipient);
return is_pm_recipient(user_id);
}
export function want_normal_display() {

View File

@@ -55,10 +55,6 @@ export const same_stream_and_topic = function util_same_stream_and_topic(a, b) {
return a.stream_id === b.stream_id && lower_same(a.topic, b.topic);
};
export function is_pm_recipient(user_id, message) {
const recipients = message.to_user_ids.split(",");
return recipients.includes(user_id.toString());
}
export function extract_pm_recipients(recipients) {
return recipients.split(/\s*[,;]\s*/).filter((recipient) => recipient.trim() !== "");