feat(sdk): 升级HaveADrink SDK并集成邀请系统
- 将HaveADrink依赖从1.0.8升级至1.0.12版本 - 集成邀请码功能,新增common/invite.js处理邀请链路 - 实现发送好友请求返回邀请码的新流程 - 添加删除动态功能,新增DeleteFeed接口 - 集成UniAppWebSocket适配器,重构WebSocket连接管理 - 优化好友请求支持关键词搜索功能 - 在FeedCard组件中添加删除按钮和分享按钮 - 更新SDK类型定义文件以匹配新接口规范
This commit is contained in:
+39
-12
@@ -178,20 +178,30 @@ export default {
|
||||
async initChat() {
|
||||
// 如果没有传入 conversationId,通过会话列表查找
|
||||
if (!this.conversationId && this.friendId) {
|
||||
try {
|
||||
const res = await GetConversations()
|
||||
const conv = (res.data.list || []).find(c => String(c.friendId) === String(this.friendId))
|
||||
if (conv) {
|
||||
this.conversationId = conv.id
|
||||
}
|
||||
} catch (e) { /* ignore */ }
|
||||
await this.ensureConversationId()
|
||||
}
|
||||
this.loadMessages()
|
||||
this.markRead()
|
||||
this.bindWsEvents()
|
||||
},
|
||||
/** 从会话列表按 friendId 查找 conversationId(首次聊天时会话尚未创建,返回 false) */
|
||||
async ensureConversationId() {
|
||||
if (this.conversationId) return true
|
||||
if (!this.friendId) return false
|
||||
try {
|
||||
const res = await GetConversations()
|
||||
const conv = (res.data.list || []).find(c => String(c.friendId) === String(this.friendId))
|
||||
if (conv) {
|
||||
this.conversationId = conv.id
|
||||
return true
|
||||
}
|
||||
} catch (e) { /* ignore */ }
|
||||
return false
|
||||
},
|
||||
// === 数据加载 ===
|
||||
async loadMessages() {
|
||||
// 无会话ID不发请求(首次聊天无历史消息,避免空参请求)
|
||||
if (!this.conversationId) return
|
||||
try {
|
||||
const res = await GetMessages({ conversationId: this.conversationId, lastID: this.lastID, pageSize: 20 })
|
||||
this.messages = res.data.list || []
|
||||
@@ -209,6 +219,8 @@ export default {
|
||||
},
|
||||
|
||||
async markRead() {
|
||||
// 无会话ID无需标记已读
|
||||
if (!this.conversationId) return
|
||||
try {
|
||||
await MarkRead({ conversationId: this.conversationId })
|
||||
// 通过 WebSocket 发送已读回执
|
||||
@@ -238,6 +250,10 @@ export default {
|
||||
onWsMessage(data) {
|
||||
// 只处理当前会话的消息
|
||||
if (String(data.senderId) !== String(this.friendId)) return
|
||||
// 首次会话:后端创建会话后消息携带 conversationId,回填本地
|
||||
if (!this.conversationId && data.conversationId) {
|
||||
this.conversationId = data.conversationId
|
||||
}
|
||||
const msg = {
|
||||
id: data.msgId ? String(data.msgId) : 'msg_' + Date.now(),
|
||||
conversationId: data.conversationId || this.conversationId,
|
||||
@@ -251,11 +267,13 @@ export default {
|
||||
this.messages.push(msg)
|
||||
this.peerTyping = false
|
||||
this.$nextTick(() => this.scrollToBottom())
|
||||
// 发送已读回执
|
||||
wsManager.send('read', {
|
||||
conversationId: this.conversationId,
|
||||
lastMsgId: msg.id
|
||||
})
|
||||
// 发送已读回执(需已有会话ID)
|
||||
if (this.conversationId) {
|
||||
wsManager.send('read', {
|
||||
conversationId: this.conversationId,
|
||||
lastMsgId: msg.id
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
/** 对方正在输入 */
|
||||
@@ -270,6 +288,10 @@ export default {
|
||||
|
||||
/** 消息送达确认 */
|
||||
onWsAck(data) {
|
||||
// ack 若携带会话ID,回填本地(首次会话兼容)
|
||||
if (!this.conversationId && data.conversationId) {
|
||||
this.conversationId = data.conversationId
|
||||
}
|
||||
const msg = this.messages.find(m => m.id === data.clientMsgId || m.id === String(data.clientMsgId))
|
||||
if (msg) {
|
||||
msg.id = data.msgId ? String(data.msgId) : msg.id
|
||||
@@ -308,6 +330,11 @@ export default {
|
||||
msgType: 'text',
|
||||
clientMesgId: clientMsgId
|
||||
})
|
||||
|
||||
// 首次聊天无会话ID:后端收到首条消息后会创建会话,延迟查找回填
|
||||
if (!this.conversationId) {
|
||||
setTimeout(() => { this.ensureConversationId() }, 800)
|
||||
}
|
||||
},
|
||||
|
||||
/** 重发失败消息 */
|
||||
|
||||
Reference in New Issue
Block a user