feat:bug修改
This commit is contained in:
1 parent
a8dbb37867
commit
a2bf33874d
3 files changed
+51
-28
No files matched your search
@@ -29,13 +29,13 @@ public class IMSender {
|
||||
private final MessageListenerMulticaster listenerMulticaster;
|
||||
|
||||
|
||||
public<T> void sendSystemMessage(IMSystemMessage<T> message){
|
||||
public <T> void sendSystemMessage(IMSystemMessage<T> message) {
|
||||
// 根据群聊每个成员所连的IM-server,进行分组
|
||||
Map<String, IMUserInfo> sendMap = new HashMap<>();
|
||||
for (Integer terminal : message.getRecvTerminals()) {
|
||||
message.getRecvIds().forEach(id -> {
|
||||
String key = String.join(":", IMRedisKey.IM_USER_SERVER_ID, id.toString(), terminal.toString());
|
||||
sendMap.put(key,new IMUserInfo(id, terminal));
|
||||
sendMap.put(key, new IMUserInfo(id, terminal));
|
||||
});
|
||||
}
|
||||
// 批量拉取
|
||||
@@ -44,8 +44,8 @@ public class IMSender {
|
||||
Map<Integer, List<IMUserInfo>> serverMap = new HashMap<>();
|
||||
List<IMUserInfo> offLineUsers = new LinkedList<>();
|
||||
int idx = 0;
|
||||
for (Map.Entry<String,IMUserInfo> entry : sendMap.entrySet()) {
|
||||
Integer serverId = (Integer)serverIds.get(idx++);
|
||||
for (Map.Entry<String, IMUserInfo> entry : sendMap.entrySet()) {
|
||||
Integer serverId = (Integer) serverIds.get(idx++);
|
||||
if (!Objects.isNull(serverId)) {
|
||||
List<IMUserInfo> list = serverMap.computeIfAbsent(serverId, o -> new LinkedList<>());
|
||||
list.add(entry.getValue());
|
||||
@@ -67,7 +67,7 @@ public class IMSender {
|
||||
redisMQTemplate.opsForList().rightPush(key, recvInfo);
|
||||
}
|
||||
// 对离线用户回复消息状态
|
||||
if(message.getSendResult() && !offLineUsers.isEmpty()){
|
||||
if (message.getSendResult() && !offLineUsers.isEmpty()) {
|
||||
List<IMSendResult> results = new LinkedList<>();
|
||||
for (IMUserInfo offLineUser : offLineUsers) {
|
||||
IMSendResult result = new IMSendResult();
|
||||
@@ -81,13 +81,13 @@ public class IMSender {
|
||||
}
|
||||
|
||||
|
||||
public<T> void sendPrivateMessage(IMPrivateMessage<T> message) {
|
||||
public <T> void sendPrivateMessage(IMPrivateMessage<T> message) {
|
||||
List<IMSendResult> results = new LinkedList<>();
|
||||
if(!Objects.isNull(message.getRecvId())){
|
||||
if (!Objects.isNull(message.getRecvId())) {
|
||||
for (Integer terminal : message.getRecvTerminals()) {
|
||||
// 获取对方连接的channelId
|
||||
String key = String.join(":", IMRedisKey.IM_USER_SERVER_ID, message.getRecvId().toString(), terminal.toString());
|
||||
Integer serverId = (Integer)redisMQTemplate.opsForValue().get(key);
|
||||
Integer serverId = (Integer) redisMQTemplate.opsForValue().get(key);
|
||||
// 如果对方在线,将数据存储至redis,等待拉取推送
|
||||
if (serverId != null) {
|
||||
String sendKey = String.join(":", IMRedisKey.IM_MESSAGE_PRIVATE_QUEUE, serverId.toString());
|
||||
@@ -111,14 +111,14 @@ public class IMSender {
|
||||
}
|
||||
|
||||
// 推送给自己的其他终端
|
||||
if(message.getSendToSelf()){
|
||||
if (message.getSendToSelf()) {
|
||||
for (Integer terminal : IMTerminalType.codes()) {
|
||||
if (message.getSender().getTerminal().equals(terminal)) {
|
||||
continue;
|
||||
}
|
||||
// 获取终端连接的channelId
|
||||
String key = String.join(":", IMRedisKey.IM_USER_SERVER_ID, message.getSender().getId().toString(), terminal.toString());
|
||||
Integer serverId = (Integer)redisMQTemplate.opsForValue().get(key);
|
||||
Integer serverId = (Integer) redisMQTemplate.opsForValue().get(key);
|
||||
// 如果终端在线,将数据存储至redis,等待拉取推送
|
||||
if (serverId != null) {
|
||||
String sendKey = String.join(":", IMRedisKey.IM_MESSAGE_PRIVATE_QUEUE, serverId.toString());
|
||||
@@ -134,19 +134,19 @@ public class IMSender {
|
||||
}
|
||||
}
|
||||
// 对离线用户回复消息状态
|
||||
if(message.getSendResult() && !results.isEmpty()){
|
||||
if (message.getSendResult() && !results.isEmpty()) {
|
||||
listenerMulticaster.multicast(IMListenerType.PRIVATE_MESSAGE, results);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public<T> void sendGroupMessage(IMGroupMessage<T> message) {
|
||||
public <T> void sendGroupMessage(IMGroupMessage<T> message) {
|
||||
// 根据群聊每个成员所连的IM-server,进行分组
|
||||
Map<String, IMUserInfo> sendMap = new HashMap<>();
|
||||
for (Integer terminal : message.getRecvTerminals()) {
|
||||
message.getRecvIds().forEach(id -> {
|
||||
String key = String.join(":", IMRedisKey.IM_USER_SERVER_ID, id.toString(), terminal.toString());
|
||||
sendMap.put(key,new IMUserInfo(id, terminal));
|
||||
sendMap.put(key, new IMUserInfo(id, terminal));
|
||||
});
|
||||
}
|
||||
// 批量拉取
|
||||
@@ -155,8 +155,8 @@ public class IMSender {
|
||||
Map<Integer, List<IMUserInfo>> serverMap = new HashMap<>();
|
||||
List<IMUserInfo> offLineUsers = new LinkedList<>();
|
||||
int idx = 0;
|
||||
for (Map.Entry<String,IMUserInfo> entry : sendMap.entrySet()) {
|
||||
Integer serverId = (Integer)serverIds.get(idx++);
|
||||
for (Map.Entry<String, IMUserInfo> entry : sendMap.entrySet()) {
|
||||
Integer serverId = (Integer) serverIds.get(idx++);
|
||||
if (!Objects.isNull(serverId)) {
|
||||
List<IMUserInfo> list = serverMap.computeIfAbsent(serverId, o -> new LinkedList<>());
|
||||
list.add(entry.getValue());
|
||||
@@ -187,7 +187,7 @@ public class IMSender {
|
||||
}
|
||||
// 获取终端连接的channelId
|
||||
String key = String.join(":", IMRedisKey.IM_USER_SERVER_ID, message.getSender().getId().toString(), terminal.toString());
|
||||
Integer serverId = (Integer)redisMQTemplate.opsForValue().get(key);
|
||||
Integer serverId = (Integer) redisMQTemplate.opsForValue().get(key);
|
||||
// 如果终端在线,将数据存储至redis,等待拉取推送
|
||||
if (!Objects.isNull(serverId)) {
|
||||
IMRecvInfo recvInfo = new IMRecvInfo();
|
||||
@@ -203,7 +203,7 @@ public class IMSender {
|
||||
}
|
||||
}
|
||||
// 对离线用户回复消息状态
|
||||
if(message.getSendResult() && !offLineUsers.isEmpty()){
|
||||
if (message.getSendResult() && !offLineUsers.isEmpty()) {
|
||||
List<IMSendResult> results = new LinkedList<>();
|
||||
for (IMUserInfo offLineUser : offLineUsers) {
|
||||
IMSendResult result = new IMSendResult();
|
||||
@@ -218,25 +218,25 @@ public class IMSender {
|
||||
|
||||
}
|
||||
|
||||
public Map<Long,List<IMTerminalType>> getOnlineTerminal(List<Long> userIds){
|
||||
if(CollUtil.isEmpty(userIds)){
|
||||
public Map<Long, List<IMTerminalType>> getOnlineTerminal(List<Long> userIds) {
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
// 把所有用户的key都存起来
|
||||
Map<String,IMUserInfo> userMap = new HashMap<>();
|
||||
for(Long id:userIds){
|
||||
Map<String, IMUserInfo> userMap = new HashMap<>();
|
||||
for (Long id : userIds) {
|
||||
for (Integer terminal : IMTerminalType.codes()) {
|
||||
String key = String.join(":", IMRedisKey.IM_USER_SERVER_ID, id.toString(), terminal.toString());
|
||||
userMap.put(key,new IMUserInfo(id,terminal));
|
||||
userMap.put(key, new IMUserInfo(id, terminal));
|
||||
}
|
||||
}
|
||||
// 批量拉取
|
||||
List<Object> serverIds = redisMQTemplate.opsForValue().multiGet(userMap.keySet());
|
||||
int idx = 0;
|
||||
Map<Long,List<IMTerminalType>> onlineMap = new HashMap<>();
|
||||
for (Map.Entry<String,IMUserInfo> entry : userMap.entrySet()) {
|
||||
Map<Long, List<IMTerminalType>> onlineMap = new HashMap<>();
|
||||
for (Map.Entry<String, IMUserInfo> entry : userMap.entrySet()) {
|
||||
// serverid有值表示用户在线
|
||||
if(serverIds.get(idx++) != null){
|
||||
if (serverIds.get(idx++) != null) {
|
||||
IMUserInfo userInfo = entry.getValue();
|
||||
List<IMTerminalType> terminals = onlineMap.computeIfAbsent(userInfo.getId(), o -> new LinkedList<>());
|
||||
terminals.add(IMTerminalType.fromCode(userInfo.getTerminal()));
|
||||
@@ -256,7 +256,7 @@ public class IMSender {
|
||||
return !Objects.requireNonNull(redisMQTemplate.keys(key)).isEmpty();
|
||||
}
|
||||
|
||||
public List<Long> getOnlineUser(List<Long> userIds){
|
||||
public List<Long> getOnlineUser(List<Long> userIds) {
|
||||
return new LinkedList<>(getOnlineTerminal(userIds).keySet());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.bx.implatform.contant;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class Constant {
|
||||
|
||||
/**
|
||||
@@ -30,4 +32,22 @@ public final class Constant {
|
||||
*/
|
||||
public static final Long MAX_NORMAL_GROUP_MEMBER = 500L;
|
||||
|
||||
/**
|
||||
* 消息通知用户id
|
||||
*/
|
||||
public static final Long COM_MESSAGE_USER_ID = -100L;
|
||||
public static final String COM_MESSAGE_USER_NAME = "消息通知";
|
||||
public static final String COM_MESSAGE_USER_AVATAR = "https://chatapi.zianxin.com/admin-api/infra/file/4/get/3dab7a0921d4d2ea6f7daee399114e9241145e754f7a1e4e1a955fada4542116.png";
|
||||
|
||||
/**
|
||||
* 客服用户id
|
||||
*/
|
||||
public static final Long COM_SERVICE_USER_ID = -200L;
|
||||
public static final String COM_SERVICE_USER_NAME = "荷塘月色客服";
|
||||
public static final String COM_SERVICE_USER_AVATAR = "https://chatapi.zianxin.com/admin-api/infra/file/4/get/b85e0bc2e4338c9919ac13e1f12cb3ac40dc7ba807a0e65ef83c822ef7d2f1a2.png";
|
||||
|
||||
/**
|
||||
* 忽略的用户id
|
||||
*/
|
||||
public static final List<Long> IGNORE_USER_IDS = List.of(SYS_USER_ID, COM_MESSAGE_USER_ID, COM_SERVICE_USER_ID);
|
||||
}
|
||||
+5
-2
@@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bx.imclient.IMClient;
|
||||
import com.bx.imcommon.model.IMPrivateMessage;
|
||||
import com.bx.imcommon.model.IMUserInfo;
|
||||
import com.bx.implatform.contant.Constant;
|
||||
import com.bx.implatform.dto.MessageTotalDto;
|
||||
import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageCountDTO;
|
||||
import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageDTO;
|
||||
@@ -70,8 +71,10 @@ public class ThirdPrivateMsgServiceImpl extends ServiceImpl<PrivateMessageMapper
|
||||
msg.setStatus(MessageStatus.PENDING.code());
|
||||
msg.setSendTime(new Date());
|
||||
// 过滤内容中的敏感词
|
||||
if (MessageType.TEXT.code().equals(dto.getType())) {
|
||||
msg.setContent(sensitiveFilterUtil.filter(dto.getContent()));
|
||||
if (!Constant.IGNORE_USER_IDS.contains(dto.getSendId())) {
|
||||
if (MessageType.TEXT.code().equals(dto.getType())) {
|
||||
msg.setContent(sensitiveFilterUtil.filter(dto.getContent()));
|
||||
}
|
||||
}
|
||||
this.save(msg);
|
||||
// 推送消息
|
||||
|
||||
Reference in new issue
Block a user