Update PM unread counts more dynamically in the client.

When we process messages for unread counts, we now call
people.pm_reply_user_string() to get a string of user ids,
rather than using emails that may have changed since the
message was originally created.
This commit is contained in:
Steve Howell
2017-02-13 16:15:26 -08:00
committed by Tim Abbott
parent ed4adc5650
commit 4c53ad59f2
3 changed files with 31 additions and 10 deletions

View File

@@ -38,6 +38,14 @@ global.current_msg_list = current_msg_list;
var home_msg_list = {}; var home_msg_list = {};
global.home_msg_list = home_msg_list; global.home_msg_list = home_msg_list;
var me = {
email: 'me@example.com',
user_id: 30,
full_name: 'Me Myself',
};
people.add(me);
people.initialize_current_user(me.user_id);
var zero_counts = { var zero_counts = {
private_message_count: 0, private_message_count: 0,
home_unread_messages: 0, home_unread_messages: 0,
@@ -276,12 +284,6 @@ var zero_counts = {
var counts = unread.get_counts(); var counts = unread.get_counts();
assert.equal(counts.private_message_count, 0); assert.equal(counts.private_message_count, 0);
var message = {
id: 15,
type: 'private',
reply_to: 'anybody@example.com',
};
var anybody = { var anybody = {
email: 'anybody@example.com', email: 'anybody@example.com',
user_id: 999, user_id: 999,
@@ -289,6 +291,15 @@ var zero_counts = {
}; };
people.add_in_realm(anybody); people.add_in_realm(anybody);
var message = {
id: 15,
type: 'private',
display_recipient: [
{user_id: anybody.user_id},
{id: me.user_id},
],
};
unread.process_loaded_messages([message]); unread.process_loaded_messages([message]);
counts = unread.get_counts(); counts = unread.get_counts();
@@ -320,7 +331,7 @@ var zero_counts = {
var message = { var message = {
id: 15, id: 15,
reply_to: 'alice@example.com', display_recipient: [{id: alice.user_id}],
type: 'private', type: 'private',
}; };
@@ -406,7 +417,7 @@ var zero_counts = {
var message = { var message = {
id: 9, id: 9,
type: 'private', type: 'private',
reply_to: 'unknown@zulip.com', display_recipient: [{id: 9999}],
}; };
unread.process_read_message(message); unread.process_read_message(message);

View File

@@ -188,6 +188,16 @@ exports.get_recipients = function (user_ids_string) {
return names.join(', '); return names.join(', ');
}; };
exports.pm_reply_user_string = function (message) {
var user_ids = people.pm_with_user_ids(message);
if (!user_ids) {
return;
}
return user_ids.join(',');
};
exports.pm_reply_to = function (message) { exports.pm_reply_to = function (message) {
var user_ids = people.pm_with_user_ids(message); var user_ids = people.pm_with_user_ids(message);

View File

@@ -151,7 +151,7 @@ exports.process_loaded_messages = function (messages) {
} }
if (message.type === 'private') { if (message.type === 'private') {
var user_ids_string = people.emails_strings_to_user_ids_string(message.reply_to); var user_ids_string = people.pm_reply_user_string(message);
if (user_ids_string) { if (user_ids_string) {
unread_privates.setdefault(user_ids_string, new Dict()); unread_privates.setdefault(user_ids_string, new Dict());
unread_privates.get(user_ids_string).set(message.id, true); unread_privates.get(user_ids_string).set(message.id, true);
@@ -175,7 +175,7 @@ exports.process_loaded_messages = function (messages) {
exports.process_read_message = function (message) { exports.process_read_message = function (message) {
if (message.type === 'private') { if (message.type === 'private') {
var user_ids_string = people.emails_strings_to_user_ids_string(message.reply_to); var user_ids_string = people.pm_reply_user_string(message);
if (user_ids_string) { if (user_ids_string) {
var dict = unread_privates.get(user_ids_string); var dict = unread_privates.get(user_ids_string);
if (dict) { if (dict) {