mirror of
https://github.com/zulip/zulip.git
synced 2025-10-25 09:03:57 +00:00
people: Remove is_current_user legacy helper.
This does lookups by email address, which is very much a legacy way to do things, and could throw exceptions if trying to lookup details on an unknown user ID.
This commit is contained in:
@@ -89,7 +89,7 @@ export function notifies(message: Message): boolean {
|
|||||||
// alert words into a message, just because that can be annoying for
|
// alert words into a message, just because that can be annoying for
|
||||||
// certain types of workflows where everybody on your team, including
|
// certain types of workflows where everybody on your team, including
|
||||||
// yourself, sets up an alert word to effectively mention the team.
|
// yourself, sets up an alert word to effectively mention the team.
|
||||||
return !people.is_current_user(message.sender_email) && message.alerted;
|
return !people.is_my_user_id(message.sender_id) && message.alerted;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const initialize = (params: StateData["alert_words"]): void => {
|
export const initialize = (params: StateData["alert_words"]): void => {
|
||||||
|
|||||||
@@ -119,6 +119,9 @@ function get_message_recipient(message: Message): MessageRecipient {
|
|||||||
};
|
};
|
||||||
return channel_message_recipient;
|
return channel_message_recipient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only the stream format uses a string for this.
|
||||||
|
assert(typeof message.display_recipient !== "string");
|
||||||
const direct_message_recipient: MessageRecipient = {
|
const direct_message_recipient: MessageRecipient = {
|
||||||
message_type: "direct",
|
message_type: "direct",
|
||||||
recipient_text: "",
|
recipient_text: "",
|
||||||
@@ -130,7 +133,10 @@ function get_message_recipient(message: Message): MessageRecipient {
|
|||||||
);
|
);
|
||||||
return direct_message_recipient;
|
return direct_message_recipient;
|
||||||
}
|
}
|
||||||
if (people.is_current_user(message.reply_to)) {
|
if (
|
||||||
|
message.display_recipient.length === 1 &&
|
||||||
|
people.is_my_user_id(util.the(message.display_recipient).id)
|
||||||
|
) {
|
||||||
direct_message_recipient.recipient_text = $t({
|
direct_message_recipient.recipient_text = $t({
|
||||||
defaultMessage: "direct messages with yourself",
|
defaultMessage: "direct messages with yourself",
|
||||||
});
|
});
|
||||||
@@ -322,7 +328,7 @@ function get_above_composebox_narrow_url(message: Message): string {
|
|||||||
// the message_lists.current (!can_apply_locally; a.k.a. "a search").
|
// the message_lists.current (!can_apply_locally; a.k.a. "a search").
|
||||||
export function notify_messages_outside_current_search(messages: Message[]): void {
|
export function notify_messages_outside_current_search(messages: Message[]): void {
|
||||||
for (const message of messages) {
|
for (const message of messages) {
|
||||||
if (!people.is_current_user(message.sender_email)) {
|
if (!people.is_my_user_id(message.sender_id)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const above_composebox_narrow_url = get_above_composebox_narrow_url(message);
|
const above_composebox_narrow_url = get_above_composebox_narrow_url(message);
|
||||||
|
|||||||
@@ -1523,7 +1523,7 @@ export function initialize({
|
|||||||
// filter out inactive users, inserted users and current user
|
// filter out inactive users, inserted users and current user
|
||||||
// from pill insertion
|
// from pill insertion
|
||||||
const inserted_users = user_pill.get_user_ids(compose_pm_pill.widget);
|
const inserted_users = user_pill.get_user_ids(compose_pm_pill.widget);
|
||||||
const current_user = people.is_current_user(user.email);
|
const current_user = people.is_my_user_id(user.user_id);
|
||||||
if (
|
if (
|
||||||
people.is_person_active(user_id) &&
|
people.is_person_active(user_id) &&
|
||||||
!inserted_users.includes(user.user_id) &&
|
!inserted_users.includes(user.user_id) &&
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export function process_new_message(raw_message: RawMessage, deliver_locally = f
|
|||||||
message_store.convert_raw_message_to_message_with_booleans(raw_message);
|
message_store.convert_raw_message_to_message_with_booleans(raw_message);
|
||||||
people.extract_people_from_message(message_with_booleans);
|
people.extract_people_from_message(message_with_booleans);
|
||||||
|
|
||||||
const sent_by_me = people.is_current_user(message_with_booleans.sender_email);
|
const sent_by_me = people.is_my_user_id(message_with_booleans.sender_id);
|
||||||
people.maybe_incr_recipient_count({...message_with_booleans, sent_by_me});
|
people.maybe_incr_recipient_count({...message_with_booleans, sent_by_me});
|
||||||
|
|
||||||
let status_emoji_info;
|
let status_emoji_info;
|
||||||
|
|||||||
@@ -352,7 +352,7 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDa
|
|||||||
if (!first_operand.includes(",")) {
|
if (!first_operand.includes(",")) {
|
||||||
const recipient_user = people.get_by_user_id(user_ids[0]);
|
const recipient_user = people.get_by_user_id(user_ids[0]);
|
||||||
// You have no direct messages with this person
|
// You have no direct messages with this person
|
||||||
if (people.is_current_user(recipient_user.email)) {
|
if (people.is_my_user_id(recipient_user.user_id)) {
|
||||||
return {
|
return {
|
||||||
title: $t({
|
title: $t({
|
||||||
defaultMessage:
|
defaultMessage:
|
||||||
@@ -456,7 +456,7 @@ export function pick_empty_narrow_banner(current_filter: Filter): NarrowBannerDa
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (people.is_current_user(first_operand)) {
|
if (people.is_my_user_id(person_in_dms.user_id)) {
|
||||||
return {
|
return {
|
||||||
title: $t({
|
title: $t({
|
||||||
defaultMessage: "You don't have any direct message conversations yet.",
|
defaultMessage: "You don't have any direct message conversations yet.",
|
||||||
|
|||||||
@@ -1716,14 +1716,6 @@ export function set_custom_profile_field_data(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function is_current_user(email?: string | null): boolean {
|
|
||||||
if (email === null || email === undefined || page_params.is_spectator) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return email.toLowerCase() === my_current_email().toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function initialize_current_user(user_id: number): void {
|
export function initialize_current_user(user_id: number): void {
|
||||||
my_user_id = user_id;
|
my_user_id = user_id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -664,7 +664,7 @@ export function show_user_profile(user: User, default_tab_key = "profile-tab"):
|
|||||||
full_name: user.full_name,
|
full_name: user.full_name,
|
||||||
is_active: people.is_person_active(user.user_id),
|
is_active: people.is_person_active(user.user_id),
|
||||||
is_bot: user.is_bot,
|
is_bot: user.is_bot,
|
||||||
is_me: people.is_current_user(user.email),
|
is_me: people.is_my_user_id(user.user_id),
|
||||||
last_seen: buddy_data.user_last_seen_time_status(user.user_id),
|
last_seen: buddy_data.user_last_seen_time_status(user.user_id),
|
||||||
profile_data,
|
profile_data,
|
||||||
should_add_guest_user_indicator: people.should_add_guest_user_indicator(user.user_id),
|
should_add_guest_user_indicator: people.should_add_guest_user_indicator(user.user_id),
|
||||||
|
|||||||
@@ -38,65 +38,65 @@ people.add_active_user({
|
|||||||
people.initialize_current_user(42);
|
people.initialize_current_user(42);
|
||||||
|
|
||||||
const regular_message = {
|
const regular_message = {
|
||||||
sender_email: "another@zulip.com",
|
sender_id: 15,
|
||||||
content: "<p>a message</p>",
|
content: "<p>a message</p>",
|
||||||
};
|
};
|
||||||
const own_message = {
|
const own_message = {
|
||||||
sender_email: "tester@zulip.com",
|
sender_id: 42,
|
||||||
content: "<p>hey this message alertone</p>",
|
content: "<p>hey this message alertone</p>",
|
||||||
alerted: true,
|
alerted: true,
|
||||||
};
|
};
|
||||||
const other_message = {
|
const other_message = {
|
||||||
sender_email: "another@zulip.com",
|
sender_id: 15,
|
||||||
content: "<p>another alertone message</p>",
|
content: "<p>another alertone message</p>",
|
||||||
alerted: true,
|
alerted: true,
|
||||||
};
|
};
|
||||||
const caps_message = {
|
const caps_message = {
|
||||||
sender_email: "another@zulip.com",
|
sender_id: 15,
|
||||||
content: "<p>another ALERTtwo message</p>",
|
content: "<p>another ALERTtwo message</p>",
|
||||||
alerted: true,
|
alerted: true,
|
||||||
};
|
};
|
||||||
const alertwordboundary_message = {
|
const alertwordboundary_message = {
|
||||||
sender_email: "another@zulip.com",
|
sender_id: 15,
|
||||||
content: "<p>another alertthreemessage</p>",
|
content: "<p>another alertthreemessage</p>",
|
||||||
alerted: false,
|
alerted: false,
|
||||||
};
|
};
|
||||||
const multialert_message = {
|
const multialert_message = {
|
||||||
sender_email: "another@zulip.com",
|
sender_id: 15,
|
||||||
content: "<p>another emoji alertone and then alerttwo</p>",
|
content: "<p>another emoji alertone and then alerttwo</p>",
|
||||||
alerted: true,
|
alerted: true,
|
||||||
};
|
};
|
||||||
const unsafe_word_message = {
|
const unsafe_word_message = {
|
||||||
sender_email: "another@zulip.com",
|
sender_id: 15,
|
||||||
content: "<p>gotta al*rt.*s all</p>",
|
content: "<p>gotta al*rt.*s all</p>",
|
||||||
alerted: true,
|
alerted: true,
|
||||||
};
|
};
|
||||||
const alert_in_url_message = {
|
const alert_in_url_message = {
|
||||||
sender_email: "another@zulip.com",
|
sender_id: 15,
|
||||||
content: "<p>http://www.google.com/alertone/me</p>",
|
content: "<p>http://www.google.com/alertone/me</p>",
|
||||||
alerted: true,
|
alerted: true,
|
||||||
};
|
};
|
||||||
const question_word_message = {
|
const question_word_message = {
|
||||||
sender_email: "another@zulip.com",
|
sender_id: 15,
|
||||||
content: "<p>still alertone? me</p>",
|
content: "<p>still alertone? me</p>",
|
||||||
alerted: true,
|
alerted: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const typo_word_message = {
|
const typo_word_message = {
|
||||||
sender_email: "another@zulip.com",
|
sender_id: 15,
|
||||||
content: "<p>alertones alerttwo alerttwo alertthreez</p>",
|
content: "<p>alertones alerttwo alerttwo alertthreez</p>",
|
||||||
alerted: true,
|
alerted: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const alert_domain_message = {
|
const alert_domain_message = {
|
||||||
sender_email: "another@zulip.com",
|
sender_id: 15,
|
||||||
content:
|
content:
|
||||||
'<p>now with link <a href="http://www.alerttwo.us/foo/bar" target="_blank" title="http://www.alerttwo.us/foo/bar">www.alerttwo.us/foo/bar</a></p>',
|
'<p>now with link <a href="http://www.alerttwo.us/foo/bar" target="_blank" title="http://www.alerttwo.us/foo/bar">www.alerttwo.us/foo/bar</a></p>',
|
||||||
alerted: true,
|
alerted: true,
|
||||||
};
|
};
|
||||||
// This test ensure we are not mucking up rendered HTML content.
|
// This test ensure we are not mucking up rendered HTML content.
|
||||||
const message_with_emoji = {
|
const message_with_emoji = {
|
||||||
sender_email: "another@zulip.com",
|
sender_id: 15,
|
||||||
content:
|
content:
|
||||||
'<p>I <img alt=":heart:" class="emoji" src="/static/generated/emoji/images/emoji/unicode/2764.png" title="heart"> emoji!</p>',
|
'<p>I <img alt=":heart:" class="emoji" src="/static/generated/emoji/images/emoji/unicode/2764.png" title="heart"> emoji!</p>',
|
||||||
alerted: true,
|
alerted: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user