mirror of https://github.com/zulip/zulip.git
people: Add `make_user` helper function.
Made this function to avoid having incomplete `people` objects floating around resulting in better type safety when using TypeScript. This function has three required parameters - `user_id`, `email` and `full_name` and adds default values to all other required properties.
This commit is contained in:
parent
21ec6ff97f
commit
9b0e7a3eae
|
@ -1285,6 +1285,47 @@ export function report_late_add(user_id, email) {
|
|||
}
|
||||
}
|
||||
|
||||
function make_user(user_id, email, full_name) {
|
||||
// Used to create fake user objects for users who we see via some
|
||||
// API call, such as fetching a message sent by the user, before
|
||||
// we receive a full user object for the user via the events
|
||||
// system.
|
||||
//
|
||||
// This function is an ugly hack in that it makes up a lot of
|
||||
// values, but usually thesefake user objects only persist for
|
||||
// less than a second before being replaced by a real user when
|
||||
// the events system receives the user-created event for the new
|
||||
// or newly visible user.
|
||||
return {
|
||||
user_id,
|
||||
email,
|
||||
full_name,
|
||||
role: settings_config.user_role_values.member.code,
|
||||
is_active: true,
|
||||
is_admin: false,
|
||||
is_owner: false,
|
||||
is_guest: false,
|
||||
is_bot: false,
|
||||
is_moderator: false,
|
||||
is_billing_admin: false,
|
||||
// We explicitly don't set `avatar_url` for fake person objects so that fallback code
|
||||
// will ask the server or compute a gravatar URL only once we need the avatar URL,
|
||||
// it's important for performance that we not hash every user's email to get gravatar URLs.
|
||||
avatar_url: undefined,
|
||||
avatar_version: 0,
|
||||
timezone: "",
|
||||
date_joined: "",
|
||||
delivery_email: null,
|
||||
profile_data: {},
|
||||
bot_owner_id: undefined,
|
||||
bot_type: null,
|
||||
|
||||
// This property allows us to distinguish actual server person
|
||||
// objects from fake person objects generated by this function.
|
||||
is_missing_server_data: true,
|
||||
};
|
||||
}
|
||||
|
||||
function get_involved_people(message) {
|
||||
let involved_people;
|
||||
|
||||
|
@ -1327,13 +1368,7 @@ export function extract_people_from_message(message) {
|
|||
|
||||
report_late_add(user_id, person.email);
|
||||
|
||||
_add_user({
|
||||
email: person.email,
|
||||
user_id,
|
||||
full_name: person.full_name,
|
||||
is_admin: person.is_realm_admin || false,
|
||||
is_bot: person.is_bot || false,
|
||||
});
|
||||
_add_user(make_user(user_id, person.email, person.full_name));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -243,7 +243,10 @@ function render_user_info_popover(
|
|||
const show_manage_menu = !spectator_view && !is_me;
|
||||
|
||||
let date_joined;
|
||||
if (spectator_view) {
|
||||
|
||||
// Some users might not have `date_joined` field because of the missing server data.
|
||||
// These users are added late in `people.js` via `extract_people_from_message`.
|
||||
if (spectator_view && !user.is_missing_server_data) {
|
||||
date_joined = timerender.get_localized_date_or_time_for_format(
|
||||
parseISO(user.date_joined),
|
||||
"dayofyear_year",
|
||||
|
|
Loading…
Reference in New Issue