|
@@ -44,48 +44,41 @@ public class InitRoomProcessor extends WebSoketSupport implements ProcessorInter
|
|
|
|
|
|
String SESSION_ID = request.getSessionid();
|
|
|
String USER_ID = request.getUserId();
|
|
|
- /*
|
|
|
- 在出诊问诊,附近的人做业务操作的时候,会再redis中生成房间
|
|
|
- //如果聊天室不存在,就生成聊天室,并把当前用户放入到聊天室中
|
|
|
- boolean roomExists = redis.exists("ROOM:" + SESSION_ID);
|
|
|
- if(!roomExists){
|
|
|
- List list1 = new ArrayList<>();
|
|
|
- Map newUser = new HashMap();
|
|
|
- newUser.put("userId", USER_ID);
|
|
|
- list1.add(newUser);
|
|
|
- redis.setValue("ROOM:" + SESSION_ID, list1);
|
|
|
- }*/
|
|
|
- //如果聊天室存在,并且当前用户没有在聊天室中,把用户添加到聊天室中
|
|
|
+ //聊天室不存在返回消息
|
|
|
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);
|
|
|
+ return;
|
|
|
}
|
|
|
- RoomInfo roomInfo = redis.get("ROOM:" + SESSION_ID, RoomInfo.class);
|
|
|
|
|
|
- //list1 防止用户重复添加到房间
|
|
|
- Set<String> list1 = new HashSet<>();
|
|
|
+ //用户每次进来更新自己的信息
|
|
|
+ //如果自己的信息不存在就把用户添加到聊天室中
|
|
|
+ //如果聊天室存在,并且当前用户没有在聊天室中,把用户添加到聊天室中------start
|
|
|
+ RoomInfo roomInfo = redis.get("ROOM:" + SESSION_ID, RoomInfo.class);
|
|
|
+ boolean userExists = false;
|
|
|
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 (currentUserId.equals(roomInfo.getUserLIst().get(i).getUserId())){
|
|
|
+ userExists = true;
|
|
|
+ roomInfo.getUserLIst().get(i).setAvatarUrl(currentUserHead);
|
|
|
+ roomInfo.getUserLIst().get(i).setUserName(currentUserName);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- if (!list1.contains(currentUserId)) {
|
|
|
+ if (!userExists) {
|
|
|
UserInfo userInfo = new UserInfo();
|
|
|
userInfo.setUserId(currentUserId);
|
|
|
userInfo.setUserName(currentUserName);
|
|
|
userInfo.setAvatarUrl(currentUserHead);
|
|
|
roomInfo.getUserLIst().add(userInfo);
|
|
|
- redis.setValue("ROOM:" + SESSION_ID, roomInfo);
|
|
|
}
|
|
|
+ redis.setValue("ROOM:" + SESSION_ID, roomInfo);
|
|
|
+ //如果聊天室存在,并且当前用户没有在聊天室中,把用户添加到聊天室中------end
|
|
|
|
|
|
-
|
|
|
- //用户每日次进来把聊天记录通过后台全部推送过去
|
|
|
+ //用户每次进来把当天聊天记录通过后台全部推送过去
|
|
|
List charts = redis.get("ALLCHATS:" + SESSION_ID, List.class);
|
|
|
IMMessage im = new IMMessage();
|
|
|
im.setCmd(IMP.INITROOM.getName());
|