Skip to content

Commit

Permalink
recipient [nfc]: Stop using email in pmUnreadsKeyFromMessage.
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice authored and rk-for-zulip committed Apr 21, 2020
1 parent 79c8671 commit d464e33
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/pm-conversations/pmConversationsSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const getRecentConversations: Selector<PmConversationData[]> = createSele
unreadHuddles: { [string]: number },
): PmConversationData[] => {
const recipients = messages.map(msg => ({
ids: pmUnreadsKeyFromMessage(msg, ownUser.email),
ids: pmUnreadsKeyFromMessage(msg, ownUser.user_id),
emails: normalizeRecipientsSansMe(msg.display_recipient, ownUser.email),
msgId: msg.id,
}));
Expand Down
12 changes: 6 additions & 6 deletions src/utils/recipient.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,29 +92,29 @@ export const pmKeyRecipientsFromMessage = (
* * `UnreadState`, the type of `state.unread`, which is the data structure
* these keys appear in.
*
* @param ownEmail - Required if the message could be a 1:1 PM; optional if
* @param ownUserId - Required if the message could be a 1:1 PM; optional if
* it is definitely a group PM.
*/
// Specifically, this includes all user IDs for group PMs and self-PMs,
// and just the other user ID for non-self 1:1s; and in each case the list
// is sorted and encoded in ASCII-decimal, comma-separated.
// See the `unread_msgs` data structure in `src/api/initialDataTypes.js`.
export const pmUnreadsKeyFromMessage = (message: Message, ownEmail?: string): string => {
export const pmUnreadsKeyFromMessage = (message: Message, ownUserId?: number): string => {
if (message.type !== 'private') {
throw new Error('pmUnreadsKeyFromMessage: expected PM, got stream message');
}
// This includes all users in the thread; see `Message#display_recipient`.
const recipients = message.display_recipient;
const recipients: PmRecipientUser[] = message.display_recipient;

if (recipients.length === 1) {
// Self-PM.
return recipients[0].id.toString();
} else if (recipients.length === 2) {
// Non-self 1:1 PM. Unlike display_recipient, leave out the self user.
if (ownEmail === undefined) {
throw new Error('getRecipientsIds: got 1:1 PM, but ownEmail omitted');
if (ownUserId === undefined) {
throw new Error('getRecipientsIds: got 1:1 PM, but ownUserId omitted');
}
return recipients.filter(r => r.email !== ownEmail)[0].id.toString();
return recipients.filter(r => r.id !== ownUserId)[0].id.toString();
} else {
// Group PM.
return recipients
Expand Down

0 comments on commit d464e33

Please sign in to comment.