|
@@ -9,6 +9,8 @@ import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import cn.com.ty.lift.ud.neety.protocol.ChatMsgDTO;
|
|
|
+import cn.com.ty.lift.ud.neety.task.RoomInfo;
|
|
|
+import cn.com.ty.lift.ud.neety.task.UserInfo;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
@@ -37,9 +39,13 @@ public class InitRoomProcessor extends WebSoketSupport implements ProcessorInter
|
|
|
@Override
|
|
|
public void process(Channel client, IMMessage request) {
|
|
|
String currentUserId = client.attr(USERID).get();
|
|
|
+ String currentUserHead = client.attr(HEAD_PIC).get();
|
|
|
+ String currentUserName = client.attr(USERNAME).get();
|
|
|
|
|
|
String SESSION_ID = request.getSessionid();
|
|
|
String USER_ID = request.getUserId();
|
|
|
+ /*
|
|
|
+ 在出诊问诊,附近的人做业务操作的时候,会再redis中生成房间
|
|
|
//如果聊天室不存在,就生成聊天室,并把当前用户放入到聊天室中
|
|
|
boolean roomExists = redis.exists("ROOM:" + SESSION_ID);
|
|
|
if(!roomExists){
|
|
@@ -48,20 +54,34 @@ public class InitRoomProcessor extends WebSoketSupport implements ProcessorInter
|
|
|
newUser.put("userId", USER_ID);
|
|
|
list1.add(newUser);
|
|
|
redis.setValue("ROOM:" + SESSION_ID, list1);
|
|
|
- }
|
|
|
+ }*/
|
|
|
//如果聊天室存在,并且当前用户没有在聊天室中,把用户添加到聊天室中
|
|
|
- List list = redis.get("ROOM:" + SESSION_ID, List.class);
|
|
|
- List<String> list1 = new ArrayList<>();
|
|
|
- for (int i = 0; list != null && i < list.size(); i++) {
|
|
|
- Map ob = (Map) list.get(i);
|
|
|
- String userId = ob.get("userId").toString();
|
|
|
+ boolean exists = redis.exists("ROOM:" + SESSION_ID);
|
|
|
+ if (!exists){
|
|
|
+ IMMessage im = new IMMessage();
|
|
|
+ im.setCmd(IMP.CHAT.getName());
|
|
|
+ im.setMsg("房间不存在");
|
|
|
+ sendMessage(client, im);
|
|
|
+ logout(client);
|
|
|
+ }
|
|
|
+ RoomInfo roomInfo = redis.get("ROOM:" + SESSION_ID, RoomInfo.class);
|
|
|
+
|
|
|
+ //list1 防止用户重复添加到房间
|
|
|
+ Set<String> list1 = new HashSet<>();
|
|
|
+ for (int i = 0; roomInfo.getUserLIst() != null
|
|
|
+ && !roomInfo.getUserLIst().isEmpty()
|
|
|
+ && i < roomInfo.getUserLIst().size(); i++) {
|
|
|
+ String userId = roomInfo.getUserLIst().get(i).getUserId();
|
|
|
list1.add(userId);
|
|
|
}
|
|
|
- if (!list1.contains(USER_ID)) {
|
|
|
- Map newUser = new HashMap();
|
|
|
- newUser.put("userId", USER_ID);
|
|
|
- list.add(newUser);
|
|
|
- redis.setValue("ROOM:" + SESSION_ID, list);
|
|
|
+
|
|
|
+ if (!list1.contains(currentUserId)) {
|
|
|
+ UserInfo userInfo = new UserInfo();
|
|
|
+ userInfo.setUserId(currentUserId);
|
|
|
+ userInfo.setUserName(currentUserName);
|
|
|
+ userInfo.setAvatarUrl(currentUserHead);
|
|
|
+ roomInfo.getUserLIst().add(userInfo);
|
|
|
+ redis.setValue("ROOM:" + SESSION_ID, roomInfo);
|
|
|
}
|
|
|
|
|
|
|