修复了点击联系人信息发送消息的时候房间id绑定问题
This commit is contained in:
@@ -58,8 +58,16 @@ export function deleteGroup(id: number) {
|
||||
}
|
||||
|
||||
// 获取好友详情
|
||||
export function getContactDetail(id: string) {
|
||||
return request.get<Contact>(`/contacts/${id}`)
|
||||
export async function getContactDetail(id: string): Promise<Contact> {
|
||||
const response = await request.get<{ contact: any; user: User }>(`/contacts/${id}`)
|
||||
// 合并 contact 和 user 数据为完整的 Contact 对象
|
||||
return {
|
||||
...response.contact,
|
||||
id: response.contact.id?.toString() || response.contact.contact_id,
|
||||
user_id: response.contact.contact_id || response.contact.user_id,
|
||||
contact_user_id: response.contact.contact_id,
|
||||
user: response.user,
|
||||
} as Contact
|
||||
}
|
||||
|
||||
// 更新好友信息
|
||||
|
||||
@@ -392,6 +392,11 @@ export function useWebRTC(userId: string, onIncomingCall?: (senderUserId: string
|
||||
call.status = 'connected'
|
||||
call.statusText = '通话中'
|
||||
startCallTimer()
|
||||
// 确保 pc 已创建
|
||||
if (!pc) {
|
||||
await initMedia(call.type === 'video')
|
||||
await createPC()
|
||||
}
|
||||
const offer = await pc!.createOffer()
|
||||
await pc!.setLocalDescription(offer)
|
||||
sendSignal('offer', offer)
|
||||
@@ -412,6 +417,11 @@ export function useWebRTC(userId: string, onIncomingCall?: (senderUserId: string
|
||||
startCallTimer()
|
||||
|
||||
} else if (signal === 'answer') {
|
||||
// 确保 pc 已创建
|
||||
if (!pc) {
|
||||
await initMedia(call.type === 'video')
|
||||
await createPC()
|
||||
}
|
||||
await pc!.setRemoteDescription(content)
|
||||
processPendingCandidates()
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ export interface Contact {
|
||||
id: string
|
||||
user_id: string
|
||||
contact_user_id: string
|
||||
room_id?: string // 房间ID(雪花ID)
|
||||
remark_name?: string
|
||||
group_id?: number
|
||||
is_top: boolean
|
||||
|
||||
@@ -328,7 +328,12 @@ const currentMessages = computed(() => {
|
||||
})
|
||||
|
||||
function getRoomId(contact: Contact): string {
|
||||
const userIds = [authStore.user!.id, contact.user_id || contact.id].sort()
|
||||
// 优先使用 contact.room_id(雪花ID),如果没有则使用旧的生成方式作为后备
|
||||
if (contact.room_id) {
|
||||
return contact.room_id
|
||||
}
|
||||
// 后备方案:使用旧的格式(兼容旧数据)
|
||||
const userIds = [authStore.user!.id, contact.user_id || contact.id || contact.contact_user_id].sort()
|
||||
return userIds.join('_')
|
||||
}
|
||||
|
||||
|
||||
@@ -274,7 +274,8 @@ function handleSendMessage() {
|
||||
|
||||
function handleAudioCall() {
|
||||
if (contact.value) {
|
||||
const receiverUserId = contact.value.user_id || contact.value.id || contact.value.contact_user_id
|
||||
// contact_id 或 contact_user_id 是联系人的用户ID(接收者)
|
||||
const receiverUserId = contact.value.contact_user_id || contact.value.contact_id || contact.value.user_id || contact.value.id
|
||||
// 直接发起通话,不跳转到会话模块
|
||||
webrtc.startCall('audio', receiverUserId)
|
||||
}
|
||||
@@ -282,7 +283,8 @@ function handleAudioCall() {
|
||||
|
||||
function handleVideoCall() {
|
||||
if (contact.value) {
|
||||
const receiverUserId = contact.value.user_id || contact.value.id || contact.value.contact_user_id
|
||||
// contact_id 或 contact_user_id 是联系人的用户ID(接收者)
|
||||
const receiverUserId = contact.value.contact_user_id || contact.value.contact_id || contact.value.user_id || contact.value.id
|
||||
// 直接发起通话,不跳转到会话模块
|
||||
webrtc.startCall('video', receiverUserId)
|
||||
}
|
||||
|
||||
@@ -287,7 +287,8 @@ function handleSendMessage() {
|
||||
|
||||
function handleAudioCall() {
|
||||
if (contact.value) {
|
||||
const receiverUserId = contact.value.user_id || contact.value.id
|
||||
// contact_id 或 contact_user_id 是联系人的用户ID
|
||||
const receiverUserId = contact.value.contact_user_id || contact.value.contact_id || contact.value.user_id || contact.value.id
|
||||
// 直接发起通话,不跳转到会话模块
|
||||
webrtc.startCall('audio', receiverUserId)
|
||||
}
|
||||
@@ -295,7 +296,8 @@ function handleAudioCall() {
|
||||
|
||||
function handleVideoCall() {
|
||||
if (contact.value) {
|
||||
const receiverUserId = contact.value.user_id || contact.value.id
|
||||
// contact_id 或 contact_user_id 是联系人的用户ID
|
||||
const receiverUserId = contact.value.contact_user_id || contact.value.contact_id || contact.value.user_id || contact.value.id
|
||||
// 直接发起通话,不跳转到会话模块
|
||||
webrtc.startCall('video', receiverUserId)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user