Skip to content

Commit

Permalink
user [nfc]: Document the new preference for tryGetUserForId over thro…
Browse files Browse the repository at this point in the history
…wing
  • Loading branch information
gnprice committed Nov 10, 2023
1 parent 5cde73f commit 22672cd
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/users/userSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const getOwnUser = (state: PerAccountState): User => {
*
* See `getUserForId` for a version which only ever returns a real user,
* throwing if none. That makes it a bit simpler to use in contexts where
* we assume the relevant user must exist, which is true of most of the app.
* we assume the relevant user must exist.
*/
export const tryGetUserForId = (state: PerAccountState, userId: UserId): UserOrBot | null =>
getAllUsersById(state).get(userId) ?? null;
Expand All @@ -136,9 +136,13 @@ export const tryGetUserForId = (state: PerAccountState, userId: UserId): UserOrB
* This works for any user in this Zulip org/realm, including deactivated
* users and cross-realm bots. See `getAllUsers` for details.
*
* Throws if no such user exists.
* Throws if no such user exists in our data. This is therefore only
* appropriate when we can know the given user must be one we know about,
* which is uncommon. (For example, even if we're looking at a message the
* user sent: we might be a guest with limited access to users, and the
* other user might no longer be in the stream so not be in our data.)
*
* See `tryGetUserForId` for a non-throwing version.
* Generally use `tryGetUserForId` instead.
*/
export const getUserForId = (state: PerAccountState, userId: UserId): UserOrBot => {
const user = tryGetUserForId(state, userId);
Expand Down

0 comments on commit 22672cd

Please sign in to comment.