Repository: zulip/zulip

Issue:
Use new optimized data set for populating "private messages" in left sidebar
Since we merged https://github.com/zulip/zulip/pull/11946, it should now be easy to significantly improve the data set used for rendering of the "private messages" by using the same ~1000 recent PMs of history data set available in `/register` (`page_params` in the webapp) that we made available for mobile.

We'll need to remove this temporary block from `always_want` in `zerver/lib/events.py`:
`settings.PRODUCTION and msg_type == "recent_private_conversations":` to make this work.

And then the work should be just accessing the `recent_private_conversations` attribute in `page_params` and using that to initialize our `static/js/pm_conversations.js` library.  


Discussion:
Hello @zulip/server-sidebars members, this issue was labeled with the "area: left-sidebar" label, so you may want to check it out!

<!-- areaLabelAddition -->
@zulipbot claim
Hello @vinitS101, you have been unassigned from this issue because you have not updated this issue or any referenced pull requests for over 14 days.

You can reclaim this issue or claim any other issue by commenting `@zulipbot claim` on that issue.

Thanks for your contributions, and hope to see you again soon!
@zulipbot working on this rn.
@vinitS101 just wanted to check in on this -- did you make progress or should I find someone else to work on this?
I wasn't able to make any substantial progress on this issue. My apologies for not bringing this up before. 
OK.  @YashRE42 if you're looking for a high priority data-centric frontend issue, this could be a good thing to claim.
@zulipbot claim
Welcome to Zulip, @hashirsarwar! We just sent you an invite to collaborate on this repository at https://github.com/zulip/zulip/invitations. Please accept this invite in order to claim this issue and begin a fun, rewarding experience contributing to Zulip!

Here's some tips to get you off to a good start:
* Join me on the [Zulip developers' server](https://chat.zulip.org), to get help, chat about this issue, and meet the other developers.
* [Unwatch this repository](https://help.github.com/articles/unwatching-repositories/), so that you don't get 100 emails a day.

As you work on this issue, you'll also want to refer to the [Zulip code contribution guide](https://zulip.readthedocs.io/en/latest/contributing/index.html), as well as the rest of the developer documentation on that site.

See you on the other side (that is, the pull request side)!

Resolving patch:
diff --git a/zerver/lib/events.py b/zerver/lib/events.py
--- a/zerver/lib/events.py
+++ b/zerver/lib/events.py
@@ -145,10 +145,6 @@ def always_want(msg_type: str) -> bool:
     info for every event type.  Defining this at module
     level makes it easier to mock.
     '''
-    if settings.PRODUCTION and msg_type == "recent_private_conversations":  # nocoverage
-        # Temporary: Don't include recent_private_conversations in production
-        # by default while the feature is still experimental.
-        return False
     return True
 
 # Fetch initial data.  When event_types is not specified, clients want


Test patch:
diff --git a/frontend_tests/node_tests/pm_conversations.js b/frontend_tests/node_tests/pm_conversations.js
--- a/frontend_tests/node_tests/pm_conversations.js
+++ b/frontend_tests/node_tests/pm_conversations.js
@@ -13,18 +13,44 @@ run_test('partners', () => {
     assert.equal(pmc.is_partner(user3_id), true);
 });
 
+zrequire("people");
+
 run_test('insert_recent_private_message', () => {
+    set_global('page_params', {
+        recent_private_conversations: [
+            {user_ids: [1, 2],
+             max_message_id: 150,
+            },
+            {user_ids: [1],
+             max_message_id: 111,
+            },
+            {user_ids: [],
+             max_message_id: 7,
+            },
+        ],
+    });
+    people.initialize_current_user(15);
+    pmc.recent.initialize();
+
+    assert.deepEqual(pmc.recent.get(), [
+        {user_ids_string: '1,2', max_message_id: 150},
+        {user_ids_string: '1', max_message_id: 111},
+        {user_ids_string: '15', max_message_id: 7},
+    ]);
+
     pmc.recent.insert('1', 1001);
     pmc.recent.insert('2', 2001);
     pmc.recent.insert('1', 3001);
 
-    // try to backdate user1's timestamp
+    // try to backdate user1's latest message
     pmc.recent.insert('1', 555);
 
     assert.deepEqual(pmc.recent.get(), [
-        {user_ids_string: '1', timestamp: 3001},
-        {user_ids_string: '2', timestamp: 2001},
+        {user_ids_string: '1', max_message_id: 3001},
+        {user_ids_string: '2', max_message_id: 2001},
+        {user_ids_string: '1,2', max_message_id: 150},
+        {user_ids_string: '15', max_message_id: 7},
     ]);
 
-    assert.deepEqual(pmc.recent.get_strings(), ['1', '2']);
+    assert.deepEqual(pmc.recent.get_strings(), ['1', '2', '1,2', '15']);
 });
diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js
--- a/frontend_tests/node_tests/ui_init.js
+++ b/frontend_tests/node_tests/ui_init.js
@@ -103,6 +103,7 @@ zrequire('search');
 zrequire('tutorial');
 zrequire('notifications');
 zrequire('pointer');
+zrequire('pm_conversations');
 zrequire('compose_fade');
 zrequire('pm_list');
 zrequire('list_cursor');
@@ -140,6 +141,7 @@ page_params.unsubscribed = [];
 page_params.never_subscribed = [];
 page_params.realm_notifications_stream_id = -1;
 page_params.unread_msgs = {};
+page_params.recent_private_conversations = [];
 
 $('#tab_bar').append = () => {};
 $('#compose').filedrop = () => {};