Commit bd2e5899 by Future

未读消息添加在线用户未读消息数量添加

parent 0401697b
......@@ -32,6 +32,7 @@ import com.wecloud.im.service.ImInboxService;
import com.wecloud.im.service.ImMessageService;
import com.wecloud.im.ws.enums.MsgTypeEnum;
import com.wecloud.im.ws.enums.WsResponseCmdEnum;
import com.wecloud.im.ws.manager.ChannelManager;
import com.wecloud.im.ws.model.WsResponse;
import com.wecloud.im.ws.model.request.PushVO;
import com.wecloud.im.ws.sender.ChannelSender;
......@@ -293,6 +294,11 @@ public class NormalChatAction {
if (clientSender.getClientId().equals(member.getClientId())) {
continue;
}
Integer count = ChannelManager.ONLINE_USER_MAP.get(String.valueOf(member.getFkClientId()));
if (count == null) {
continue;
}
ImInbox imInbox = new ImInbox();
imInbox.setId(SnowflakeUtil.getId());
imInbox.setCreateTime(new Date());
......
......@@ -56,6 +56,7 @@ import com.wecloud.im.vo.ReaderList;
import com.wecloud.im.vo.ReaderVo;
import com.wecloud.im.ws.enums.MsgTypeEnum;
import com.wecloud.im.ws.enums.WsResponseCmdEnum;
import com.wecloud.im.ws.manager.ChannelManager;
import com.wecloud.im.ws.model.WsResponse;
import com.wecloud.im.ws.model.request.PushVO;
import com.wecloud.im.ws.sender.ChannelSender;
......@@ -654,6 +655,10 @@ public class ImMessageServiceImpl extends BaseServiceImpl<ImMessageMapper, ImMes
if (senderClientId.equals(member.getClientId())) {
continue;
}
Integer count = ChannelManager.ONLINE_USER_MAP.get(String.valueOf(member.getFkClientId()));
if (count == null) {
continue;
}
ImInbox imInbox = new ImInbox();
imInbox.setId(SnowflakeUtil.getId());
imInbox.setCreateTime(new Date());
......
......@@ -30,6 +30,12 @@ public class ChannelManager {
public static final Map<String, ClientInfo> SESSION_INFO_MAP = new ConcurrentHashMap<>();
/**
* 在线用户map 用于控制inbox表插入
* key: clientId
* value: 当天接收消息数量
*/
public static final Map<String, Integer> ONLINE_USER_MAP = new ConcurrentHashMap<>();
/**
* CLIENT_ID,是客户端的字符串id
*/
public static final AttributeKey<Long> CLIENT_ID = AttributeKey.valueOf("ci");
......@@ -62,6 +68,7 @@ public class ChannelManager {
String longChannelId = channel.id().asLongText();
log.info("保存本地连接clientId {} platform {}", clientId, platform);
this.putSessionInfoMap(clientId, platform, channel);
ChannelManager.ONLINE_USER_MAP.put(String.valueOf(clientId), 1);
UserStateListener.triggerOnlineEvent(clientId, platform, longChannelId);
}
......@@ -90,6 +97,7 @@ public class ChannelManager {
// 移除本地维护的channel
delSessionInfoMap(clientId, platform);
ChannelManager.ONLINE_USER_MAP.remove(String.valueOf(clientId));
UserStateListener.triggerOfflineEvent(clientId, platform, longChannelId);
}
......
......@@ -30,23 +30,16 @@ public class MessageScheduled {
/**
* 离线消息处理定时器
* 15之前的离线消息直接删除
* 一星期前的已读消息 删除
* 7之前的离线消息直接删除
* 一天执行一次 凌晨3点执行
*/
@Scheduled(cron = "0 0 3 * * ?")
public void inboxDelete() {
log.info("离线消息处理定时器处理开始...");
// 15天之前数据, 直接删除
Date allDeleteTime = DateUtils.addDays(new Date(), -15);
// 7天之前数据, 直接删除
Date allDeleteTime = DateUtils.addDays(new Date(), -7);
imInboxService.remove(new QueryWrapper<ImInbox>().lambda()
.lt(ImInbox::getCreateTime, allDeleteTime));
// 7天之前数据, 删除已读消息
Date readTime = DateUtils.addDays(new Date(), -7);
imInboxService.remove(new QueryWrapper<ImInbox>().lambda()
.eq(ImInbox::getReadMsgStatus, 1)
.lt(ImInbox::getCreateTime, readTime));
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment