mirror of https://github.com/msgbyte/tailchat
feat: 增加会话快速切换
parent
64be97d07f
commit
c0c56734da
@ -1,26 +1,17 @@
|
|||||||
import { getCachedUserInfo, isValidStr, useAsync } from '../../index';
|
import { getDMConverseName } from '../../helper/converse-helper';
|
||||||
|
import { isValidStr, useAsync } from '../../index';
|
||||||
import type { ChatConverseState } from '../slices/chat';
|
import type { ChatConverseState } from '../slices/chat';
|
||||||
import { useUserId } from './useUserInfo';
|
import { useUserId } from './useUserInfo';
|
||||||
|
|
||||||
export function useDMConverseName(converse: ChatConverseState) {
|
export function useDMConverseName(converse: ChatConverseState) {
|
||||||
const userId = useUserId();
|
const userId = useUserId();
|
||||||
const otherConverseMembers = converse.members.filter((m) => m !== userId); // 成员Id
|
const { value: name = '' } = useAsync(async () => {
|
||||||
const len = otherConverseMembers.length;
|
if (!isValidStr(userId)) {
|
||||||
const { value: otherMembersInfo = [] } = useAsync(() => {
|
return '';
|
||||||
return Promise.all(
|
|
||||||
otherConverseMembers.map((userId) => getCachedUserInfo(userId))
|
|
||||||
);
|
|
||||||
}, [otherConverseMembers.join(',')]);
|
|
||||||
|
|
||||||
if (isValidStr(converse.name)) {
|
|
||||||
return converse.name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len === 1) {
|
return getDMConverseName(userId, converse);
|
||||||
return otherMembersInfo[0]?.nickname ?? '';
|
}, [userId, converse.name, converse.members.join(',')]);
|
||||||
} else if (len === 2) {
|
|
||||||
return `${otherMembersInfo[0]?.nickname}, ${otherMembersInfo[1]?.nickname}`;
|
return name;
|
||||||
} else {
|
|
||||||
return `${otherMembersInfo[0]?.nickname}, ${otherMembersInfo[1]?.nickname} ...`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue