mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 09:58:06 +00:00
compose_fade: Change would_receive_message to use user_id.
This commit changes the would_receive_message to use user_id instead of emails. This change is done because user_ids are immutable and using user_ids is the correct way of uniquely identifying user. The change in 'would_receive_message' also leads to change in util.is_pm_recipient to use a string of user_ids instead of emails. We also know that user_ids passed to 'would_receive_message' are active user_ids, since we get them from buddy_list. So we don't need to check whether the user is active, which was previously being checked by get_active_user_for_email.
This commit is contained in:
@@ -55,10 +55,9 @@ run_test('set_focused_recipient', () => {
|
|||||||
|
|
||||||
compose_fade.set_focused_recipient('stream');
|
compose_fade.set_focused_recipient('stream');
|
||||||
|
|
||||||
assert.equal(compose_fade.would_receive_message('me@example.com'), true);
|
assert.equal(compose_fade.would_receive_message(me.user_id), true);
|
||||||
assert.equal(compose_fade.would_receive_message('alice@example.com'), true);
|
assert.equal(compose_fade.would_receive_message(alice.user_id), true);
|
||||||
assert.equal(compose_fade.would_receive_message('bob@example.com'), false);
|
assert.equal(compose_fade.would_receive_message(bob.user_id), false);
|
||||||
assert.equal(compose_fade.would_receive_message('nonrealmuser@example.com'), true);
|
|
||||||
|
|
||||||
const good_msg = {
|
const good_msg = {
|
||||||
type: 'stream',
|
type: 'stream',
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ run_test('extract_pm_recipients', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
run_test('is_pm_recipient', () => {
|
run_test('is_pm_recipient', () => {
|
||||||
const message = { reply_to: 'alice@example.com,bOb@exaMple.com,fred@example.com' };
|
const message = { to_user_ids: '31,32,33' };
|
||||||
assert(util.is_pm_recipient('alice@example.com', message));
|
assert(util.is_pm_recipient(31, message));
|
||||||
assert(util.is_pm_recipient('bob@example.com', message));
|
assert(util.is_pm_recipient(32, message));
|
||||||
assert(!util.is_pm_recipient('unknown@example.com', message));
|
assert(!util.is_pm_recipient(34, message));
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test('lower_bound', () => {
|
run_test('lower_bound', () => {
|
||||||
|
|||||||
@@ -92,22 +92,21 @@ function fade_messages() {
|
|||||||
}, 0, current_msg_list, compose_state.private_message_recipient());
|
}, 0, current_msg_list, compose_state.private_message_recipient());
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.would_receive_message = function (email) {
|
exports.would_receive_message = function (user_id) {
|
||||||
if (focused_recipient.type === 'stream') {
|
if (focused_recipient.type === 'stream') {
|
||||||
const user = people.get_active_user_for_email(email);
|
|
||||||
const sub = stream_data.get_sub(focused_recipient.stream);
|
const sub = stream_data.get_sub(focused_recipient.stream);
|
||||||
if (!sub || !user) {
|
if (!sub) {
|
||||||
// If the stream or user isn't valid, there is no risk of a mix
|
// If the stream isn't valid, there is no risk of a mix
|
||||||
// yet, so we sort of "lie" and say they would receive a
|
// yet, so we sort of "lie" and say they would receive a
|
||||||
// message.
|
// message.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream_data.is_user_subscribed(focused_recipient.stream, user.user_id);
|
return stream_data.is_user_subscribed(focused_recipient.stream, user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PM, so check if the given email is in the recipients list.
|
// PM, so check if the given email is in the recipients list.
|
||||||
return util.is_pm_recipient(email, focused_recipient);
|
return util.is_pm_recipient(user_id, focused_recipient);
|
||||||
};
|
};
|
||||||
|
|
||||||
const user_fade_config = {
|
const user_fade_config = {
|
||||||
@@ -124,8 +123,7 @@ const user_fade_config = {
|
|||||||
|
|
||||||
function update_user_row_when_fading(li, conf) {
|
function update_user_row_when_fading(li, conf) {
|
||||||
const user_id = conf.get_user_id(li);
|
const user_id = conf.get_user_id(li);
|
||||||
const email = people.get_by_user_id(user_id).email;
|
const would_receive = exports.would_receive_message(user_id);
|
||||||
const would_receive = exports.would_receive_message(email);
|
|
||||||
|
|
||||||
if (would_receive || people.is_my_user_id(user_id)) {
|
if (would_receive || people.is_my_user_id(user_id)) {
|
||||||
conf.unfade(li);
|
conf.unfade(li);
|
||||||
|
|||||||
@@ -62,9 +62,9 @@ exports.same_stream_and_topic = function util_same_stream_and_topic(a, b) {
|
|||||||
lower_same(a.topic, b.topic);
|
lower_same(a.topic, b.topic);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.is_pm_recipient = function (email, message) {
|
exports.is_pm_recipient = function (user_id, message) {
|
||||||
const recipients = message.reply_to.toLowerCase().split(',');
|
const recipients = message.to_user_ids.split(',');
|
||||||
return recipients.includes(email.toLowerCase());
|
return recipients.includes(user_id.toString());
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.extract_pm_recipients = function (recipients) {
|
exports.extract_pm_recipients = function (recipients) {
|
||||||
|
|||||||
Reference in New Issue
Block a user