import { isValidStr } from '..' ; import { getCachedConverseInfo , getCachedUserInfo } from '../cache/cache' ; import { t } from '../i18n' ; import type { ChatConverseInfo } from '../model/converse' ; import { appendUserDMConverse } from '../model/user' ; /**
 * 确保私信会话存在
 */ export async function ensureDMConverse ( converseId ) { const converse = await getCachedConverseInfo ( converseId ) ; if ( converse === null ) { throw new Error ( t ( '找不到私信会话' ) ) ; } await appendUserDMConverse ( converseId ) ; return converse ; } param userId param converse export async function getDMConverseName ( userId , converse ) { if ( isValidStr ( converse . name ) ) { return converse . name ; } const otherConverseMembers = converse . members . filter ( ( m ) => m !== userId ) ; const len = otherConverseMembers . length ; const otherMembersInfo = await Promise . all ( otherConverseMembers . map ( ( memberId ) => getCachedUserInfo ( memberId ) ) ) ; if ( len === 1 ) { return otherMembersInfo [ 0 ] ?. nickname ?? '' ; } else if ( len === 2 ) { return `${ otherMembersInfo [ 0 ] ?. nickname }, ${ otherMembersInfo [ 1 ] ?. nickname }` ; } else { return `${ otherMembersInfo [ 0 ] ?. nickname }, ${ otherMembersInfo [ 1 ] ?. nickname } ...` ; } }