Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/hooks/useShortMentionsList.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useMemo} from 'react';
import {usePersonalDetails} from '@components/OnyxListItemProvider';
import {areEmailsFromSamePrivateDomain} from '@libs/LoginUtils';
import {getEmailDomain, isDomainPublic} from '@libs/LoginUtils';
import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails';

/**
Expand All @@ -18,14 +18,20 @@ export default function useShortMentionsList() {
return [];
}

const currentUserDomain = getEmailDomain(currentUserPersonalDetails.login ?? '');
const isCurrentUserPublicDomain = isDomainPublic(currentUserDomain);

return Object.values(personalDetails)
.map((personalDetail) => {
if (!personalDetail?.login) {
if (!personalDetail?.login || isCurrentUserPublicDomain) {
return;
}

const personalDetailDomain = getEmailDomain(personalDetail.login);
const isPersonalDetailPublicDomain = isDomainPublic(personalDetailDomain);

// If the emails are not in the same private domain, we don't want to highlight them
if (!areEmailsFromSamePrivateDomain(personalDetail.login, currentUserPersonalDetails.login ?? '')) {
if (isPersonalDetailPublicDomain || personalDetailDomain !== currentUserDomain) {
return;
}

Expand Down
15 changes: 14 additions & 1 deletion src/libs/LoginUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,21 @@ function appendCountryCode(phone: string, countryCode: number): string {
* Check email is public domain or not
*/
function isEmailPublicDomain(email: string): boolean {
const emailDomain = Str.extractEmailDomain(email).toLowerCase();
const emailDomain = getEmailDomain(email);
return PUBLIC_DOMAINS_SET.has(emailDomain);
}

function isDomainPublic(domain: string): boolean {
return PUBLIC_DOMAINS_SET.has(domain);
}

/**
* Get the domain for an email
*/
function getEmailDomain(email: string): string {
return Str.extractEmailDomain(email).toLowerCase();
}

Comment on lines +42 to +52

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Albeit very simple methods, can you please add unit tests for these?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mountiny sorry I forgot about doing that in this PR, I was in a hell of switching between contexts yesterday 😄 Will open a follow up PR shortly!

/**
* Check if number is valid
* @returns a valid phone number formatted
Expand Down Expand Up @@ -114,4 +125,6 @@ export {
postSAMLLogin,
handleSAMLLoginError,
formatE164PhoneNumber,
getEmailDomain,
isDomainPublic,
};
Loading