refactor: Have pm_conversations take user_ids.

Instead of having our callers pass in a possibly
non-canonical version of a user_ids_string, just
have them pass in a list.

The next commit will canonicalize the sort.
This commit is contained in:
Steve Howell 2020-01-01 14:42:46 +00:00 committed by Tim Abbott
parent ab6f4af33a
commit 0e68387975
4 changed files with 13 additions and 19 deletions

View File

@ -38,12 +38,12 @@ run_test('insert_recent_private_message', () => {
{user_ids_string: '15', max_message_id: 7}, {user_ids_string: '15', max_message_id: 7},
]); ]);
pmc.recent.insert('1', 1001); pmc.recent.insert([1], 1001);
pmc.recent.insert('2', 2001); pmc.recent.insert([2], 2001);
pmc.recent.insert('1', 3001); pmc.recent.insert([1], 3001);
// try to backdate user1's latest message // try to backdate user1's latest message
pmc.recent.insert('1', 555); pmc.recent.insert([1], 555);
assert.deepEqual(pmc.recent.get(), [ assert.deepEqual(pmc.recent.get(), [
{user_ids_string: '1', max_message_id: 3001}, {user_ids_string: '1', max_message_id: 3001},

View File

@ -73,9 +73,8 @@ run_test('build_private_messages_list', () => {
const active_conversation_2 = 'me@zulip.com,alice@zulip.com'; const active_conversation_2 = 'me@zulip.com,alice@zulip.com';
let max_conversations = 5; let max_conversations = 5;
const user_ids_string = '101,102';
const timestamp = 0; const timestamp = 0;
pm_conversations.recent.insert(user_ids_string, timestamp); pm_conversations.recent.insert([101, 102], timestamp);
global.unread.num_unread_for_person = function () { global.unread.num_unread_for_person = function () {
return 1; return 1;
@ -125,9 +124,8 @@ run_test('build_private_messages_list_bot', () => {
const active_conversation_1 = 'outgoingwebhook@zulip.com'; const active_conversation_1 = 'outgoingwebhook@zulip.com';
const max_conversations = 5; const max_conversations = 5;
const user_ids_string = '314';
const timestamp = 0; const timestamp = 0;
pm_conversations.recent.insert(user_ids_string, timestamp); pm_conversations.recent.insert([314], timestamp);
global.unread.num_unread_for_person = function () { global.unread.num_unread_for_person = function () {
return 1; return 1;

View File

@ -54,9 +54,7 @@ exports.process_message_for_recent_private_messages = function (message) {
pm_conversations.set_partner(user_id); pm_conversations.set_partner(user_id);
}); });
const user_ids_string = user_ids.join(','); pm_conversations.recent.insert(user_ids, message.id);
pm_conversations.recent.insert(user_ids_string, message.id);
}; };
exports.set_message_booleans = function (message) { exports.set_message_booleans = function (message) {

View File

@ -18,13 +18,12 @@ exports.recent = (function () {
const recent_message_ids = new Dict({fold_case: true}); // key is user_ids_string const recent_message_ids = new Dict({fold_case: true}); // key is user_ids_string
const recent_private_messages = []; const recent_private_messages = [];
self.insert = function (user_ids_string, message_id) { self.insert = function (user_ids, message_id) {
if (user_ids_string === '') { if (user_ids.length === 0) {
// The API uses '' for self-PMs; convert it to the string // The server sends [] for self-PMs.
// containing the current user's ID, which is the format user_ids = [people.my_current_user_id()];
// the webapp expects.
user_ids_string = people.my_current_user_id().toString();
} }
const user_ids_string = user_ids.join(',');
let conversation = recent_message_ids.get(user_ids_string); let conversation = recent_message_ids.get(user_ids_string);
if (conversation === undefined) { if (conversation === undefined) {
@ -71,8 +70,7 @@ exports.recent = (function () {
self.initialize = function () { self.initialize = function () {
_.each(page_params.recent_private_conversations, function (conversation) { _.each(page_params.recent_private_conversations, function (conversation) {
const user_ids_string = conversation.user_ids.join(","); self.insert(conversation.user_ids, conversation.max_message_id);
self.insert(user_ids_string, conversation.max_message_id);
}); });
delete page_params.recent_private_messages; delete page_params.recent_private_messages;
}; };