-
-
Notifications
You must be signed in to change notification settings - Fork 673
Add recent_private_conversations
key to /register
.
#3535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
recent_private_conversations
key to /register
.recent_private_conversations
key to /register
.
Thanks @ishammahajan ! This generally looks like the right structure. A few comments:
|
(Also note e137e29 -- I think you had a version based on before that and rebased past it, and you'll want to adjust the rebase a bit.) |
Thanks for the early review!
The
I'll add it, thanks!
Hmm. That sounds about right, but my consideration for this was that we don't really have any message data stored in the |
Ah OK, if it's just for your testing in development then never mind. What I mean is just that if you were thinking these would be part of the PR to merge, I think we can actually do without them. (We don't need that data for solving #3133 , and for showing snippets we'll get it another way that's more efficient.)
Right, so: for #3133 we don't actually need any message data! So it's fine that the message IDs in |
Ah, I thought there was something wrong about that! I was confused when the linter gave errors for the exact same lines. Turns out there was an 's' missing for each. 😄 |
(I used terms a bit loosely here, so to clarify just in case because you haven't already spent a lot of time with this part of the system: |
From that issue:
It makes sense now! Would you confirm whether the code I have written in EDIT: Now that I think of it, if the user has had conversations in the WebApp but not on mobile, and they want to have a look at the conversation from the last 101th message, they wouldn't be able to. We should add the relevant code to fetch the messages as well, I think (though perhaps in a later commit). |
Sounds good!
Well, so the first question might be: what is that function We don't seem to have any jsdoc on it, so this is a bit implicit. But you can search for where it's used:
It's used in two places. The first of those is probably used only for the PM conversations screen (I haven't looked to confirm that), and I'm guessing is the path you meant to affect. The second one, though, seems to have a different job: it's counting how many of those known PMs are unread. So for that job, it really wants a full list of private messages, or their IDs anyway -- not just the latest one message per conversation. Which does pretty well fit the name So let's leave |
One other thing I notice, looking a bit more at the existing code: We do use in a few places an unread count for each conversation. We're computing that from looking back through the actual messages we have. For now, for fixing #3133 , I think we can leave that aspect of the logic as it is: the unread count for a conversation will just count unreads in the messages we happen to have (often, just the latest 100 PMs overall). As a further improvement, we might see about getting unread counts added to the |
Oh btw, as you're writing that reducer logic -- here's a remark I made over on #3133 that may be helpful:
Basically there's a case where you may get stuck trying to see how to write the reducer logic... and I think the right answer there is to punt on it and just let the data be slightly wrong in a certain way. |
Right, so if the user goes and actually navigates to the conversation, we'll need to go fetch the messages for it. This is something we already do, though, and the existing mechanism should handle it just fine. If for example you go to the stream list, you can navigate to a stream where potentially the last message was a very long time ago, so we don't have any of those messages at all -- and we go and fetch them. Even in the PM conversations screen today, we might have only a handful of messages from any given conversation we show, so if the user navigates to it we promptly go fetch more. See |
8552b34
to
237c258
Compare
recent_private_conversations
key to /register
.recent_private_conversations
key to /register
.
237c258
to
ec4b2af
Compare
That makes sense, I think. Thanks!
Hmm. That's a good idea. Do we get something similar to show the unread counts in the streams?
Yeah, I did 'punt' on it since it's difficult to get the last message of a conversation (specially if the messages of that conversation have not been retrieved. Actually, the act of a user deleting a message should make it a more recently active conversation than others with no activity (similar for
Understood, thanks! 🙂
Thanks for that, helped a lot! |
fbaec22
to
2c793a0
Compare
So, we actually already have the |
Hmm. Now that I check up on it, we do already use this in the app. Not sure what @gnprice was referring to there. |
I was looking, I think, at the But: searching in turn for that function, it looks like we don't actually ever invoke it! And we haven't since bd88566, nearly two years ago. I'll go cut it out so it doesn't cause any further confusion. |
Thanks @ishammahajan for this update! Reading the code:
What would be appropriate behavior in that case? (I think correctly implementing appropriate behavior in that case is one of the things that becomes easier if the enclosing filter, map, map sequence is turned into simply a loop -- in addition to just understanding the code as it is.)
In particular, does that put the user IDs in the right order? What order does If logic like this is indeed needed, this line is too crowded a place for it -- this logic is too gnarly, and too interface-sensitive, to happen anonymously inside a property lookup like this. We'd want to make it its own small function with a name, and a line or two of jsdoc saying what it means.
|
Thanks for the review, @gnprice!
That makes total sense, I don't know why I didn't think of it that way. Changed the commit to reflect that. :)
I believe the first ( (next responses will be a bit out of order because of the nature of the comments.)
I had added that as a placeholder for the data in Anyway, now that I went and checked the usage of timestamp, it isn't actually used anywhere -- ...and yes! Removing the attribute from the type only results in a |
2c793a0
to
d586615
Compare
I tried to keep the tests faithful to how we would get data from the server. The server would send it with no user ID of the current user. The selector though, converts an empty field into one that contains the current user's ID, while leaving the fields with multiple user ids untouched -- this was the pattern in the previous reducer as well (
The reason I put that is because for some reason, the server was giving me a conversation with a user with user id ... this is so strange! Now that I try out the code without the line, for getting what the error exactly was, since I'm very positive that such an error existed, the error disappeared! I think this should be investigated more, but I don't know how I would do such a thing. |
(I've just rebased this branch onto master, and also fixed a couple of tests at commit 3/4.) |
88e6fd3
to
2357664
Compare
OK, and pushed a version with a number of revisions:
The remaining major thing I think it's essential to do before merging this is: In particular there's my one remaining comment from above:
The newly rewritten |
Just pushed 35be10b, which confirms that Also confirmed that, as jsdoc in this branch mentions, the user-ID lists in # Sort to prevent test flakes and client bugs.
for rec in recipient_map.values():
rec['user_ids'].sort() though that isn't a documented guarantee.) Then the third bit of API surface area involved here is the unreads data structure, which |
The server added in zulip/zulip#11944 basic support for fetching the most recent private conversations that a user was involved in. The endpoint returns the private conversations a user has had within the past 1000 private messages they have sent/recieved. The endpoint returns data in the form of `[{user_ids, max_message_id}]` where user_ids lists all the people involved in the conversation, and max_message_id returns the message_id of the most recent message in the conversation. This commit introduces the reducers required to introduce this data into the Redux state, during `doInitialFetch`. It only catches the `REALM_INIT` action at the moment, and the rest of the actions will be added in a later commit with details.
Since the `PmConversationsCard` needs to be updated when a new message comes in and the data it uses to be updated is in `recentPrivateConversations` key in the Redux state, this event catch adds/amends the data in the state to correctly match the most recent private messages. A unit test file has been created for this use-case as well. It is `strict-local`, and uses `exampleData.js` for its data source.
The parent commits introduced a new key `recent_private_conversations` which fetches the private conversations from the most recent 1000 private messages. This commit changes the aforementioned selector to use the `getRecentPrivateConversations` direct selector also introduced in the same parent commit. The effect of this is that the `PmConversationsCard` now displays all the private conversations that a person might be participating in instead of only from the last 100 messages (which was the amount of messages that the previous iteration of the code fetched in `doInitialFetch`, which directly determined the messages which were scanned -- and how many conversations were returned). `ownEmail` was removed in favor of `getOwnUser` in order to enable the usage of `currentUser.user_id`. The tests for `pmConversationsSelectors` has also been changed to reflect the new data used and the way it is used. For example: we no longer need to use the timestamps in order to sort conversations by most recent because `max_message_id` satisifes that desire by itself, and we don't need the returned conversations to have the current user's ID in every `huddle` type conversation.
The tests for `pmConversationsSelectors` are now `@flow strict-local`. To aid this process, we make use of the 'new' way of making tests, which is using `src/__tests__/exampleData.js`. A few examples of such tests include the unit tests at `src/users/__tests__/userSelectors-test.js` and `src/webview/html/__tests__/messageHeaderAsHtml-test.js`. Note that this is just a translation, and not a behavorial change.
2357664
to
8e83e98
Compare
Picking this up, as #3133 is on my plate now:
Alas, this is not quite so. The above code was only added in 2.2-dev-53-g405a529340 (zulip/zulip@405a529340), which was backported to the 2.1 branch as 2.1.1-50-gd452ad31e0 (zulip/zulip@d452ad31e0). Zulip server versions 2.1.0 and 2.1.1 will therefore not sort user IDs. |
Based closely on the tests for the old implementation. Taken with minimal changes from PR zulip#3535. Co-authored-by: Greg Price <[email protected]> [ray: ported from old PR; wrote new commit message for new context.]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just made a rebased version of this PR, but I haven't pushed it to this PR branch in case it might accidentally remove something important to the direction of the PR. You can see it at my recentprivateconvo-rebased
branch.
const oldMaxMsgId = index < 0 ? null : state[index].max_message_id; | ||
const item = { | ||
user_ids: userIds, | ||
max_message_id: Math.max(action.message.id, oldMaxMsgId ?? -Infinity), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, have we thought through storing -Infinity
in the Redux state; in particular, what happens when it's saved and then loaded from storage? It looks like it doesn't round-trip through JSON:
JSON.parse(JSON.stringify({ a: -Infinity }))
// {a: null}
Ah, and I've just come across #4104, which I'd forgotten about—it's a more recent PR that may indeed replace this one, for fixing #3133, so it may not have been super helpful for me to rebase this one (which I did in my |
Based closely on the tests for the old implementation. Taken with minimal changes from PR zulip#3535. Co-authored-by: Greg Price <[email protected]> [ray: ported from old PR; wrote new commit message for new context.]
Based closely on the tests for the old implementation. Taken with minimal changes from PR zulip#3535. Co-authored-by: Greg Price <[email protected]> [ray: ported from old PR; wrote new commit message for new context.]
Based closely on the tests for the old implementation. Taken with minimal changes from PR zulip#3535. Co-authored-by: Greg Price <[email protected]> [ray: ported from old PR; wrote new commit message for new context.]
I've just sent #4392 as a new approach to this issue. |
WIP PR. Just for review/general help.