Procházet zdrojové kódy

优化聊天功能

fangzhen před 6 měsíci
rodič
revize
999a6a086e

+ 10 - 10
ruoyi-framework/src/main/java/com/ruoyi/framework/webSocket/WebSocketServer.java

@@ -95,7 +95,7 @@ public class WebSocketServer {
             this.session = session;
             //如果存在就先删除一个,防止重复推送消息
             for (WebSocketServer webSocket : webSocketSet) {
-                if (webSocket.sid.equals(userId)) {
+                if (webSocket.sid.equals(String.valueOf(userId))) {
                     webSocketSet.remove(webSocket);
                     count.getAndDecrement();
                 }
@@ -249,7 +249,7 @@ public class WebSocketServer {
         Long receiveUserId = jsonObject.getLong("receiveUserId");
         String type = jsonObject.getString("type");     //消息分类 chat
         int messageType = jsonObject.getInteger("messageType");     //消息类型
-        JSONObject sendText = jsonObject.getJSONObject("sendText");
+//        JSONObject sendText = jsonObject.getJSONObject("sendText");
         CommunityChatMsg chatMsg = null;
         if (type.equals(MessageType.CHAT.getType())) {
             LOGGER.debug("聊天消息推送");
@@ -265,31 +265,31 @@ public class WebSocketServer {
             switch (messageType) {
                 case 0:
                     //文字
-                    String context = sendText.getString("context");
+                    String context = jsonObject.getString("context");
                     //存储历史消息
                     chatMsg.setContent(context);
                     break;
                 case 1:
                     //图片
-                    chatMsg.setFileUrl(sendText.getString("fileUrl"));
+                    chatMsg.setFileUrl(jsonObject.getString("fileUrl"));
                     break;
                 case 2:
                     //语音
-                    chatMsg.setFileUrl(sendText.getString("fileUrl"));
-                    chatMsg.setTime(sendText.getInteger("time"));
+                    chatMsg.setFileUrl(jsonObject.getString("fileUrl"));
+                    chatMsg.setTime(jsonObject.getInteger("time"));
                     break;
                 case 3:
                     //定位
-                    String address = sendText.getString("address");
-                    Double latitude = sendText.getDouble("latitude");       //纬度
-                    Double longitude = sendText.getDouble("longitude");     //经度
+                    String address = jsonObject.getString("address");
+                    Double latitude = jsonObject.getDouble("latitude");       //纬度
+                    Double longitude = jsonObject.getDouble("longitude");     //经度
                     chatMsg.setAddress(address);
                     chatMsg.setLatitude(latitude);
                     chatMsg.setLongitude(longitude);
                     break;
                 case 4:
                     //视频
-                    chatMsg.setFileUrl(sendText.getString("fileUrl"));
+                    chatMsg.setFileUrl(jsonObject.getString("fileUrl"));
                     break;
 
             }

+ 16 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/AnonymousUser.java

@@ -0,0 +1,16 @@
+package com.ruoyi.system.domain.vo;
+
+import lombok.Data;
+
+@Data
+public class AnonymousUser {
+    private String alias;  // 自定义“我是谁”
+    private String remark; // 对对方的备注
+    private String targetSid; // 对方用户的 sid
+
+    public AnonymousUser(String alias, String remark, String targetSid) {
+        this.alias = alias;
+        this.remark = remark;
+        this.targetSid = targetSid;
+    }
+}