2021-11-12 01:17:29 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import type { FunctionComponent } from 'react';
|
2022-04-05 00:38:22 +00:00
|
|
|
import React, { useCallback } from 'react';
|
2021-11-12 01:17:29 +00:00
|
|
|
|
|
|
|
import { BaseConversationListItem } from './BaseConversationListItem';
|
|
|
|
|
|
|
|
import type { LocalizerType } from '../../types/Util';
|
2022-04-05 00:38:22 +00:00
|
|
|
import type { LookupConversationWithoutUuidActionsType } from '../../util/lookupConversationWithoutUuid';
|
2022-06-16 19:12:50 +00:00
|
|
|
import type { ShowConversationType } from '../../state/ducks/conversations';
|
2021-11-12 01:17:29 +00:00
|
|
|
|
|
|
|
type PropsData = {
|
|
|
|
username: string;
|
|
|
|
isFetchingUsername: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
type PropsHousekeeping = {
|
|
|
|
i18n: LocalizerType;
|
2022-06-16 19:12:50 +00:00
|
|
|
showConversation: ShowConversationType;
|
2022-04-05 00:38:22 +00:00
|
|
|
} & LookupConversationWithoutUuidActionsType;
|
2021-11-12 01:17:29 +00:00
|
|
|
|
|
|
|
export type Props = PropsData & PropsHousekeeping;
|
|
|
|
|
|
|
|
export const UsernameSearchResultListItem: FunctionComponent<Props> = ({
|
|
|
|
i18n,
|
|
|
|
isFetchingUsername,
|
2022-10-24 20:46:36 +00:00
|
|
|
lookupConversationWithoutUuid,
|
2021-11-12 01:17:29 +00:00
|
|
|
username,
|
2022-04-05 00:38:22 +00:00
|
|
|
showUserNotFoundModal,
|
|
|
|
setIsFetchingUUID,
|
|
|
|
showConversation,
|
2021-11-12 01:17:29 +00:00
|
|
|
}) => {
|
|
|
|
const usernameText = i18n('at-username', { username });
|
2022-04-05 00:38:22 +00:00
|
|
|
const boundOnClick = useCallback(async () => {
|
|
|
|
if (isFetchingUsername) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const conversationId = await lookupConversationWithoutUuid({
|
|
|
|
showUserNotFoundModal,
|
|
|
|
setIsFetchingUUID,
|
|
|
|
|
|
|
|
type: 'username',
|
|
|
|
username,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (conversationId !== undefined) {
|
2022-06-16 19:12:50 +00:00
|
|
|
showConversation({ conversationId });
|
2022-04-05 00:38:22 +00:00
|
|
|
}
|
|
|
|
}, [
|
2022-10-24 20:46:36 +00:00
|
|
|
isFetchingUsername,
|
|
|
|
lookupConversationWithoutUuid,
|
2022-04-05 00:38:22 +00:00
|
|
|
setIsFetchingUUID,
|
|
|
|
showConversation,
|
2022-10-24 20:46:36 +00:00
|
|
|
showUserNotFoundModal,
|
|
|
|
username,
|
2022-04-05 00:38:22 +00:00
|
|
|
]);
|
2021-11-12 01:17:29 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<BaseConversationListItem
|
|
|
|
acceptedMessageRequest={false}
|
|
|
|
conversationType="direct"
|
|
|
|
headerName={usernameText}
|
|
|
|
i18n={i18n}
|
|
|
|
isMe={false}
|
|
|
|
isSelected={false}
|
|
|
|
isUsernameSearchResult
|
|
|
|
shouldShowSpinner={isFetchingUsername}
|
|
|
|
onClick={boundOnClick}
|
|
|
|
sharedGroupNames={[]}
|
|
|
|
title={usernameText}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|