people: Make get_by_user_id type-safe.

We should make `get_by_user_id` type-safe in the sense that it's caller
should not expect undefined values and hence it's caller should not
need to validate the user ids.

To do this I extracted a method `maybe_get_user_by_id` which is
type-unsafe version of this function which will allow undefined values
and will behave exactly the same as the previous version. So the callers
which expects the undefined values from this function should use this
new function `maybe_get_user_by_id`.

Probably about half of these callers are implicitly iterating through
all users in the people.js data set and thus by construction should
never fail, but it's simpler to just convert all existing callers than
do that audit.
This commit is contained in:
Lalit
2023-06-16 18:53:45 +05:30
committed by Tim Abbott
parent 9b0e7a3eae
commit 1c8bf4f050
23 changed files with 41 additions and 31 deletions

View File

@@ -39,7 +39,7 @@ export function needs_subscribe_warning(user_id, stream_id) {
// We expect the caller to already have verified that we're
// sending to a valid stream and trying to mention the user.
const user = people.get_by_user_id(user_id);
const user = people.maybe_get_user_by_id(user_id);
if (!user) {
return false;