|
|
@@ -545,7 +545,7 @@ export default {
|
|
|
|
|
|
// 导入当前用户(确保userId是字符串)
|
|
|
const currentUserRes = await uni.request({
|
|
|
- url: 'http://localhost:1004/api/im/importUser',
|
|
|
+ url: 'http://localhost:8083/api/im/importUser',
|
|
|
method: 'POST',
|
|
|
data: {
|
|
|
userId: String(this.userId),
|
|
|
@@ -560,7 +560,7 @@ export default {
|
|
|
|
|
|
// 导入目标用户(确保userId是字符串)
|
|
|
const targetUserRes = await uni.request({
|
|
|
- url: 'http://localhost:1004/api/im/importUser',
|
|
|
+ url: 'http://localhost:8083/api/im/importUser',
|
|
|
method: 'POST',
|
|
|
data: {
|
|
|
userId: String(this.targetUserId),
|
|
|
@@ -585,7 +585,7 @@ export default {
|
|
|
async getUserSig() {
|
|
|
try {
|
|
|
const [err, res] = await uni.request({
|
|
|
- url: 'http://localhost:1004/api/im/getUserSig',
|
|
|
+ url: 'http://localhost:8083/api/im/getUserSig',
|
|
|
method: 'GET',
|
|
|
data: {
|
|
|
userId: this.userId
|
|
|
@@ -771,15 +771,16 @@ export default {
|
|
|
|
|
|
// 通过WebSocket发送已读回执
|
|
|
const message = {
|
|
|
- type: 'read', // 已读回执类型
|
|
|
+ type: 'READ_RECEIPT', // 已读回执类型
|
|
|
fromUserId: parseInt(this.userId),
|
|
|
toUserId: parseInt(this.targetUserId),
|
|
|
timestamp: Date.now()
|
|
|
};
|
|
|
|
|
|
- // 发送WebSocket消息
|
|
|
- if (timManager.websocket && timManager.websocket.readyState === 1) {
|
|
|
- timManager.websocket.send(JSON.stringify(message));
|
|
|
+ // 使用presenceManager的WebSocket发送
|
|
|
+ const presenceManager = require('@/utils/presence-manager.js').default;
|
|
|
+ if (presenceManager.isConnected) {
|
|
|
+ presenceManager.sendMessage(message);
|
|
|
console.log('✅ 已读回执发送成功');
|
|
|
} else {
|
|
|
console.warn('⚠️ WebSocket未连接,无法发送已读回执');
|
|
|
@@ -1138,7 +1139,7 @@ export default {
|
|
|
|
|
|
// 调用后端同步接口
|
|
|
const res = await uni.request({
|
|
|
- url: 'http://localhost:1004/api/chat/syncTIMMessage',
|
|
|
+ url: 'http://localhost:8083/api/chat/syncTIMMessage',
|
|
|
method: 'POST',
|
|
|
data: syncData,
|
|
|
header: {
|
|
|
@@ -1540,26 +1541,20 @@ export default {
|
|
|
console.log('✅ 已订阅对方用户状态');
|
|
|
|
|
|
// 4. 监听已读回执(通过WebSocket)
|
|
|
- if (presenceManager.websocket) {
|
|
|
- const originalOnMessage = presenceManager.websocket.onmessage;
|
|
|
- presenceManager.websocket.onmessage = (event) => {
|
|
|
- // 先调用原有的消息处理
|
|
|
- if (originalOnMessage) {
|
|
|
- originalOnMessage.call(presenceManager.websocket, event);
|
|
|
- }
|
|
|
-
|
|
|
- // 处理已读回执
|
|
|
- try {
|
|
|
- const data = JSON.parse(event.data);
|
|
|
- if (data.type === 'read' && data.fromUserId == this.targetUserId) {
|
|
|
- this.handleReadReceipt(data);
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- console.error('❌ 解析WebSocket消息失败:', error);
|
|
|
- }
|
|
|
- };
|
|
|
- console.log('✅ 已监听已读回执');
|
|
|
+ // 注册已读回执的回调
|
|
|
+ this.readReceiptCallback = (data) => {
|
|
|
+ if (data.type === 'READ_RECEIPT' && data.fromUserId == this.targetUserId) {
|
|
|
+ console.log('📬 收到已读回执:', data);
|
|
|
+ this.handleReadReceipt(data);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 将回调添加到presenceManager的消息处理中
|
|
|
+ if (!presenceManager.messageCallbacks) {
|
|
|
+ presenceManager.messageCallbacks = [];
|
|
|
}
|
|
|
+ presenceManager.messageCallbacks.push(this.readReceiptCallback);
|
|
|
+ console.log('✅ 已监听已读回执');
|
|
|
|
|
|
// 4. 定期轮询在线状态(作为补充,每30秒查询一次)
|
|
|
this.onlineStatusPollingTimer = setInterval(async () => {
|
|
|
@@ -1603,17 +1598,30 @@ export default {
|
|
|
cleanupPresence() {
|
|
|
console.log('🔌 清理在线状态监听');
|
|
|
|
|
|
+ const presenceManager = require('@/utils/presence-manager.js').default;
|
|
|
+
|
|
|
// 清除轮询定时器
|
|
|
if (this.onlineStatusPollingTimer) {
|
|
|
clearInterval(this.onlineStatusPollingTimer);
|
|
|
this.onlineStatusPollingTimer = null;
|
|
|
}
|
|
|
|
|
|
+ // 移除在线状态监听
|
|
|
if (this.handleStatusChange) {
|
|
|
presenceManager.offStatusChange(this.targetUserId, this.handleStatusChange);
|
|
|
this.handleStatusChange = null;
|
|
|
}
|
|
|
|
|
|
+ // 移除已读回执回调
|
|
|
+ if (this.readReceiptCallback && presenceManager.messageCallbacks) {
|
|
|
+ const index = presenceManager.messageCallbacks.indexOf(this.readReceiptCallback);
|
|
|
+ if (index > -1) {
|
|
|
+ presenceManager.messageCallbacks.splice(index, 1);
|
|
|
+ console.log('✅ 已移除已读回执监听');
|
|
|
+ }
|
|
|
+ this.readReceiptCallback = null;
|
|
|
+ }
|
|
|
+
|
|
|
// 注意:不要断开WebSocket连接,因为其他页面可能还在使用
|
|
|
// presenceManager.disconnect();
|
|
|
},
|
|
|
@@ -1937,7 +1945,7 @@ export default {
|
|
|
|
|
|
// 使用uni.uploadFile上传到后端MinIO接口
|
|
|
const [err, res] = await uni.uploadFile({
|
|
|
- url: 'http://localhost:1004/api/voice/upload',
|
|
|
+ url: 'http://localhost:8083/api/voice/upload',
|
|
|
filePath: this.voiceTempPath,
|
|
|
name: 'file',
|
|
|
header: {
|
|
|
@@ -2142,7 +2150,7 @@ export default {
|
|
|
async getUserMessageLimit() {
|
|
|
try {
|
|
|
const [err, res] = await uni.request({
|
|
|
- url: 'http://localhost:1004/api/chat/getUserMessageLimit',
|
|
|
+ url: 'http://localhost:8083/api/chat/getUserMessageLimit',
|
|
|
method: 'GET',
|
|
|
data: {
|
|
|
userId: this.userId ,// 已在onLoad中初始化的当前用户ID
|