Skip to content

Commit c0101d6

Browse files
committed
recipient.js [nfc]: Add documentation for normalizeRecipients.
1 parent d885c07 commit c0101d6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/utils/recipient.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,22 @@ import type { PmRecipientUser, Message, Outbox, User } from '../types';
1212
const filterRecipients = (recipients: PmRecipientUser[], ownUserId: number): PmRecipientUser[] =>
1313
recipients.length === 1 ? recipients : recipients.filter(r => r.id !== ownUserId);
1414

15+
/**
16+
* "Hash" a set of recipients, represented as an unsorted list, into a string.
17+
* (A "recipient" is usually either a `User` or a `PmRecipientUser`.)
18+
*
19+
* Considered as a map from sets of users to strings, this function is
20+
* injective. Do not rely on any other property of its output.
21+
*/
22+
// Unfortunately we do exactly that in a lot of places.
23+
//
24+
// TODO: fix that. Then, possibly, make this function nontrivial to invert, so
25+
// that we can't accidentally do that again.
1526
export const normalizeRecipients = (recipients: $ReadOnlyArray<{ email: string, ... }>): string =>
1627
recipients
28+
// The purpose of the `trim` and `filter` below are obscure; they've been
29+
// present without explanation since antiquity (commit a2419662d4,
30+
// 0.7.1~251). As of 2020-05, they're believed to be superfluous.
1731
.map(s => s.email.trim())
1832
.filter(x => x.length > 0)
1933
.sort()

0 commit comments

Comments
 (0)