diff --git a/.eslintrc.json b/.eslintrc.json index 9694032bcf..eb72aff5ec 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -136,6 +136,7 @@ "current_msg_list": true, "home_msg_list": false, "pm_list": false, + "pm_conversations": false, "recent_senders": false, "unread_ui": false, "unread_ops": false, diff --git a/frontend_tests/node_tests/message_store.js b/frontend_tests/node_tests/message_store.js index 8e1b0d5847..9faf59a086 100644 --- a/frontend_tests/node_tests/message_store.js +++ b/frontend_tests/node_tests/message_store.js @@ -1,6 +1,7 @@ add_dependencies({ people: 'js/people.js', util: 'js/util.js', + pm_conversations: 'js/pm_conversations.js', }); var noop = function () {}; diff --git a/frontend_tests/node_tests/pm_conversations.js b/frontend_tests/node_tests/pm_conversations.js new file mode 100644 index 0000000000..943acbbc3f --- /dev/null +++ b/frontend_tests/node_tests/pm_conversations.js @@ -0,0 +1,15 @@ +var assert = require('assert'); +var pmc = require('js/pm_conversations.js'); + +(function test_partners() { + var user1_id = 1; + var user2_id = 2; + var user3_id = 3; + + pmc.set_partner(user1_id); + pmc.set_partner(user3_id); + + assert.equal(pmc.is_partner(user1_id), true); + assert.equal(pmc.is_partner(user2_id), false); + assert.equal(pmc.is_partner(user3_id), true); +}()); diff --git a/static/js/message_store.js b/static/js/message_store.js index 9e783815a7..227d6d3f46 100644 --- a/static/js/message_store.js +++ b/static/js/message_store.js @@ -49,6 +49,10 @@ exports.process_message_for_recent_private_messages = function (message) { return; } + _.each(user_ids, function (user_id) { + pm_conversations.set_partner(user_id); + }); + var user_ids_string = user_ids.join(','); if (!user_ids_string) { diff --git a/static/js/pm_conversations.js b/static/js/pm_conversations.js new file mode 100644 index 0000000000..1d787e13b1 --- /dev/null +++ b/static/js/pm_conversations.js @@ -0,0 +1,20 @@ +var pm_conversations = (function () { + +var exports = {}; + +var partners = new Dict(); + +exports.set_partner = function (user_id) { + partners.set(user_id, true); +}; + +exports.is_partner = function (user_id) { + return partners.get(user_id) || false; +}; + +return exports; +}()); + +if (typeof module !== 'undefined') { + module.exports = pm_conversations; +} diff --git a/zproject/settings.py b/zproject/settings.py index 114af82d02..bc39acd247 100644 --- a/zproject/settings.py +++ b/zproject/settings.py @@ -875,6 +875,7 @@ JS_SPECS = { 'js/unread.js', 'js/topic_list.js', 'js/pm_list.js', + 'js/pm_conversations.js', 'js/recent_senders.js', 'js/stream_sort.js', 'js/topic_generator.js',