Просмотр исходного кода

!23 readme更新
Merge pull request !23 from blue/v_2.0.0

blue 2 лет назад
Родитель
Сommit
011065a10f

+ 9 - 3
README.md

@@ -13,8 +13,7 @@
 - 支持移动端和web端同时在线,多端消息同步
 - 目前仅兼容h5和微信小程序,后续会继续兼容更多终端类型
 
-感兴趣的小伙伴,可在下方扫码抢先体验微信小程序
-
+感兴趣的小伙伴,可在下方扫码体验微信小程序
 
 
 
@@ -226,7 +225,14 @@ wsApi.onmessage((cmd,msgInfo) => {
 
 ![输入图片说明](%E6%88%AA%E5%9B%BE/%E4%BA%A4%E6%B5%81%E7%BE%A4.png)
 
-欢迎进群与小伙们一起交流,加群前记得要先star哦,申请加群时请备注您的gitee账号
+欢迎进群与小伙们一起交流,加群前务必要先star哦
+
+
+#### 嘿嘿
+![输入图片说明](%E6%88%AA%E5%9B%BE/%E5%BE%AE%E4%BF%A1%E6%94%B6%E6%AC%BE%E7%A0%81.png)
+
+悄悄放个二维码在这,宝子们..你懂我意思吧
+
 
 
 #### 点下star吧

+ 20 - 16
im-client/src/main/java/com/bx/imclient/sender/IMSender.java

@@ -12,10 +12,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 
 @Service
@@ -81,22 +78,29 @@ public class IMSender {
 
     public<T> void sendGroupMessage(IMGroupMessage<T> message) {
         // 根据群聊每个成员所连的IM-server,进行分组
-        List<IMUserInfo> offLineUsers = Collections.synchronizedList(new LinkedList<>());
-        // 格式:map<服务器id,list<接收方>>
-        Map<Integer, List<IMUserInfo>> serverMap = new ConcurrentHashMap<>();
+        Map<String, IMUserInfo> sendMap = new HashMap<>();
         for (Integer terminal : message.getRecvTerminals()) {
-            message.getRecvIds().parallelStream().forEach(id -> {
+            message.getRecvIds().stream().forEach(id -> {
                 String key = String.join(":", IMRedisKey.IM_USER_SERVER_ID, id.toString(), terminal.toString());
-                Integer serverId = (Integer)redisTemplate.opsForValue().get(key);
-                if (serverId != null) {
-                    List<IMUserInfo> list = serverMap.computeIfAbsent(serverId, o -> Collections.synchronizedList(new LinkedList<>()));
-                    list.add(new IMUserInfo(id, terminal));
-                } else {
-                    // 加入离线列表
-                    offLineUsers.add(new IMUserInfo(id, terminal));
-                }
+                sendMap.put(key,new IMUserInfo(id, terminal));
             });
         }
+        // 批量拉取
+        List<Object> serverIds = redisTemplate.opsForValue().multiGet(sendMap.keySet());
+        // 格式:map<服务器id,list<接收方>>
+        Map<Integer, List<IMUserInfo>> serverMap = new HashMap<>();
+        List<IMUserInfo> offLineUsers = Collections.synchronizedList(new LinkedList<>());
+        int idx = 0;
+        for (Map.Entry<String,IMUserInfo> entry : sendMap.entrySet()) {
+            Integer serverId = (Integer)serverIds.get(idx++);
+            if (serverId != null) {
+                List<IMUserInfo> list = serverMap.computeIfAbsent(serverId, o -> Collections.synchronizedList(new LinkedList<>()));
+                list.add(entry.getValue());
+            } else {
+                // 加入离线列表
+                offLineUsers.add(entry.getValue());
+            }
+        };
         // 逐个server发送
         for (Map.Entry<Integer, List<IMUserInfo>> entry : serverMap.entrySet()) {
             IMRecvInfo recvInfo = new IMRecvInfo();

+ 1 - 1
im-platform/src/main/java/com/bx/implatform/service/impl/GroupServiceImpl.java

@@ -203,7 +203,7 @@ public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements
             throw  new GlobalException(ResultCode.PROGRAM_ERROR,"群组不存在");
         }
         if(group.getDeleted()){
-            throw  new GlobalException(ResultCode.PROGRAM_ERROR,"群组已解散");
+            throw  new GlobalException(ResultCode.PROGRAM_ERROR,"群组'"+group.getName()+"'已解散");
         }
         return group;
     }

+ 6 - 1
im-platform/src/main/java/com/bx/implatform/service/impl/PrivateMessageServiceImpl.java

@@ -9,6 +9,7 @@ import com.bx.imcommon.contant.IMConstant;
 import com.bx.imcommon.enums.IMTerminalType;
 import com.bx.imcommon.model.IMPrivateMessage;
 import com.bx.imcommon.model.IMUserInfo;
+import com.bx.implatform.entity.Friend;
 import com.bx.implatform.vo.PrivateMessageVO;
 import com.bx.implatform.entity.PrivateMessage;
 import com.bx.implatform.enums.MessageStatus;
@@ -169,10 +170,14 @@ public class PrivateMessageServiceImpl extends ServiceImpl<PrivateMessageMapper,
         if (!imClient.isOnline(session.getUserId())) {
             throw new GlobalException(ResultCode.PROGRAM_ERROR, "用户未建立连接");
         }
+
+        List<Friend> friends = friendService.findFriendByUserId(session.getUserId());
+        List<Long> friendIds = friends.stream().map(Friend::getFriendId).collect(Collectors.toList());
         // 获取当前用户所有未读消息
         LambdaQueryWrapper<PrivateMessage> queryWrapper = Wrappers.lambdaQuery();
         queryWrapper.eq(PrivateMessage::getRecvId, session.getUserId())
-                .eq(PrivateMessage::getStatus, MessageStatus.UNREAD);
+                .eq(PrivateMessage::getStatus, MessageStatus.UNREAD)
+                .in(PrivateMessage::getSendId,friendIds);
         List<PrivateMessage> messages = this.list(queryWrapper);
         // 上传至redis,等待推送
         for(PrivateMessage message:messages){

BIN
截图/微信收款码.jpg


BIN
截图/微信收款码.png