You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { useSelector } from 'react-redux';
|
|
import { UserUtils } from '../session/utils';
|
|
import { StateType } from '../state/reducer';
|
|
|
|
export function useAvatarPath(pubkey: string | undefined) {
|
|
return useSelector((state: StateType) => {
|
|
if (!pubkey) {
|
|
return null;
|
|
}
|
|
return state.conversations.conversationLookup[pubkey]?.avatarPath || null;
|
|
});
|
|
}
|
|
|
|
export function useOurAvatarPath() {
|
|
return useAvatarPath(UserUtils.getOurPubKeyStrFromCache());
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @returns convo.profileName || convo.name || convo.id or undefined if the convo is not found
|
|
*/
|
|
export function useConversationUsername(pubkey?: string) {
|
|
return useSelector((state: StateType) => {
|
|
if (!pubkey) {
|
|
return undefined;
|
|
}
|
|
const convo = state.conversations.conversationLookup[pubkey];
|
|
if (!convo) {
|
|
return pubkey;
|
|
}
|
|
return convo?.profileName || convo?.name || convo.id;
|
|
});
|
|
}
|
|
|
|
export function useOurConversationUsername() {
|
|
return useConversationUsername(UserUtils.getOurPubKeyStrFromCache());
|
|
}
|
|
|
|
export function useIsMe(pubkey?: string) {
|
|
return pubkey && pubkey === UserUtils.getOurPubKeyStrFromCache();
|
|
}
|