-
-
Notifications
You must be signed in to change notification settings - Fork 677
msglist: Offer bulk-mark-as-read button for PM conversations #5164
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
73973d5
to
cccca48
Compare
Also posted a thing I noticed while working on this. |
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.
Thanks @chrisbobbe! Comments below.
src/chat/MarkAsReadButton.js
Outdated
const userIds = userIdsOfPmNarrow(narrow); | ||
let messageIds = undefined; | ||
const key = pmUnreadsKeyFromPmKeyIds(userIds, ownUserId); | ||
if (userIds.length > 1) { | ||
messageIds = unreadHuddles.find(x => x.user_ids_string === key)?.unread_message_ids ?? []; | ||
} else { | ||
messageIds = unreadPms.find(x => x.sender_id.toString() === key)?.unread_message_ids ?? []; | ||
} |
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.
Yikes, this is kind of messy, isn't it. Particularly that gotcha commented on in the first commit.
I'd like to have this kind of code, dealing with the messy structure inside a data model, be located inside that model's code. So e.g. a getUnreadIdsForPmNarrow
, located among the selectors at the top of unreadModel.js
.
There's an existing spot where we do something similar, in getUnreadCountForNarrow
in unreadSelectors.js
:
pm: ids => {
if (ids.length > 1) {
const unreadsKey = pmUnreadsKeyFromPmKeyIds(ids, ownUserId);
const unreadItem = unread.huddles.find(x => x.user_ids_string === unreadsKey);
return unreadItem?.unread_message_ids.length ?? 0;
} else {
const senderId = ids[0];
const unreadItem = unread.pms.find(x => x.sender_id === senderId);
return unreadItem?.unread_message_ids.length ?? 0;
}
},
So a good structure would be to factor that logic out of there, and then that case of getUnreadCountForNarrow
just looks like ids => getUnreadIdsForPmNarrow(ids).length
.
Note that that also has a variation of how to deal with the string/number thing, that's perhaps a bit cleaner.
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.
Note that that also has a variation of how to deal with the string/number thing, that's perhaps a bit cleaner.
Yeah, maybe. It's not a biggie, but that one doesn't use pmUnreadsKeyFromPmKeyIds
at all in the 1:1 pm case, even though it's written to be able to handle it.
// initialized with "only" the most recent 50K unread messages. So | ||
// we'll occasionally, but rarely, miss some messages here; see #5156. | ||
// TODO(?): Should we use `queueMarkAsRead` here? | ||
api.messagesFlags(auth, messageIds, 'add', 'read'); |
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.
Should probably skip this if messageIds
is empty.
src/chat/MarkAsReadButton.js
Outdated
// The message IDs come from our unread-messages data, which is | ||
// initialized with "only" the most recent 50K unread messages. So | ||
// we'll occasionally, but rarely, miss some messages here; see #5156. | ||
// TODO(?): Should we use `queueMarkAsRead` here? |
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.
No need for that, I think; the job of that queue is when you're scrolling and have lots of frequent little batches to mark as read.
cccca48
to
bd021f6
Compare
Thanks! Revision pushed. |
Thanks for the revision! Looks good. One nit: - invariant(isPmNarrow(narrow)); This gets added with the surrounding code, then removed in the subsequent commit. Did you intend to take it out? (I think it's fine to either have it or not have it; the next line will throw an error if it's not a PM narrow anyway.) |
bd021f6
to
a456550
Compare
Eep, thanks for catching this! Yeah, I think I was doing a complicated reordering of commits, and this fell through. Agreed that we don't need the invariant here.
Small correction: at the commit that includes that invariant line, the function ( |
Merged, with the invariant line taken out. |
Ha, I see.
Could try that. Though I'm not sure a libdef (or that So this is likely a bug in that logic in Flow… that or a divergence between the Related Flow issue, with background on why it's special: https://github.com/facebook/flow/issues/ 112 From back-links in that thread, a possible form of a solution if the NPM package and what's inside Facebook have diverged (other than the solution of making the package align with the Facebook version): I haven't really been bothered by the fact that |
Fixes: #5156