Browse Source

Merge remote-tracking branch 'origin/v_2.0.0' into v_2.0.0

master
xsx 2 years ago
parent
commit
e7e3bbcc8a
  1. 1
      im-client/src/main/java/com/bx/imclient/listener/MessageListenerMulticaster.java
  2. 4
      im-client/src/main/java/com/bx/imclient/task/GroupMessageResultResultTask.java
  3. 4
      im-client/src/main/java/com/bx/imclient/task/PrivateMessageResultResultTask.java
  4. 6
      im-commom/src/main/java/com/bx/imcommon/enums/IMTerminalType.java
  5. 6
      im-platform/src/main/java/com/bx/implatform/dto/LoginDTO.java
  6. 31
      im-platform/src/main/java/com/bx/implatform/service/impl/GroupMessageServiceImpl.java
  7. 1
      im-platform/src/main/resources/application.yml
  8. 2
      im-ui/src/api/date.js
  9. 2
      im-uniapp/common/date.js
  10. 2
      im-uniapp/components/chat-item/chat-item.vue

1
im-client/src/main/java/com/bx/imclient/listener/MessageListenerMulticaster.java

@ -27,7 +27,6 @@ public class MessageListenerMulticaster {
for(MessageListener listener:messageListeners){ for(MessageListener listener:messageListeners){
IMListener annotation = listener.getClass().getAnnotation(IMListener.class); IMListener annotation = listener.getClass().getAnnotation(IMListener.class);
if(annotation!=null && (annotation.type().equals(IMListenerType.ALL) || annotation.type().equals(listenerType))){ if(annotation!=null && (annotation.type().equals(IMListenerType.ALL) || annotation.type().equals(listenerType))){
results.forEach(result->{ results.forEach(result->{
// 将data转回对象类型 // 将data转回对象类型
if(result.getData() instanceof JSONObject){ if(result.getData() instanceof JSONObject){

4
im-client/src/main/java/com/bx/imclient/task/GroupMessageResultResultTask.java

@ -40,13 +40,13 @@ public class GroupMessageResultResultTask extends AbstractMessageResultTask {
if(!results.isEmpty()){ if(!results.isEmpty()){
listenerMulticaster.multicast(IMListenerType.GROUP_MESSAGE, results); listenerMulticaster.multicast(IMListenerType.GROUP_MESSAGE, results);
} }
} while (results.size() < batchSize); } while (results.size() >= batchSize);
} }
List<IMSendResult> loadBatch() { List<IMSendResult> loadBatch() {
String key = StrUtil.join(":", IMRedisKey.IM_RESULT_GROUP_QUEUE, appName); String key = StrUtil.join(":", IMRedisKey.IM_RESULT_GROUP_QUEUE, appName);
//这个接口redis6.2以上才支持 //这个接口redis6.2以上才支持
//List<Object> list = redisTemplate.opsForList().leftPop(key, 100); //List<Object> list = redisTemplate.opsForList().leftPop(key, batchSize);
List<IMSendResult> results = new LinkedList<>(); List<IMSendResult> results = new LinkedList<>();
JSONObject jsonObject = (JSONObject) redisTemplate.opsForList().leftPop(key); JSONObject jsonObject = (JSONObject) redisTemplate.opsForList().leftPop(key);
while (!Objects.isNull(jsonObject) && results.size() < batchSize) { while (!Objects.isNull(jsonObject) && results.size() < batchSize) {

4
im-client/src/main/java/com/bx/imclient/task/PrivateMessageResultResultTask.java

@ -41,13 +41,13 @@ public class PrivateMessageResultResultTask extends AbstractMessageResultTask {
if(!results.isEmpty()){ if(!results.isEmpty()){
listenerMulticaster.multicast(IMListenerType.PRIVATE_MESSAGE, results); listenerMulticaster.multicast(IMListenerType.PRIVATE_MESSAGE, results);
} }
} while (results.size() < batchSize); } while (results.size() >= batchSize);
} }
List<IMSendResult> loadBatch() { List<IMSendResult> loadBatch() {
String key = StrUtil.join(":", IMRedisKey.IM_RESULT_PRIVATE_QUEUE, appName); String key = StrUtil.join(":", IMRedisKey.IM_RESULT_PRIVATE_QUEUE, appName);
//这个接口redis6.2以上才支持 //这个接口redis6.2以上才支持
//List<Object> list = redisTemplate.opsForList().leftPop(key, 100); //List<Object> list = redisTemplate.opsForList().leftPop(key, batchSize);
List<IMSendResult> results = new LinkedList<>(); List<IMSendResult> results = new LinkedList<>();
JSONObject jsonObject = (JSONObject) redisTemplate.opsForList().leftPop(key); JSONObject jsonObject = (JSONObject) redisTemplate.opsForList().leftPop(key);
while (!Objects.isNull(jsonObject) && results.size() < batchSize) { while (!Objects.isNull(jsonObject) && results.size() < batchSize) {

6
im-commom/src/main/java/com/bx/imcommon/enums/IMTerminalType.java

@ -16,7 +16,11 @@ public enum IMTerminalType {
/** /**
* app * app
*/ */
APP(1, "app"); APP(1, "app"),
/**
* pc
*/
PC(2, "pc");
private final Integer code; private final Integer code;

6
im-platform/src/main/java/com/bx/implatform/dto/LoginDTO.java

@ -13,10 +13,10 @@ import javax.validation.constraints.NotNull;
@ApiModel("用户登录DTO") @ApiModel("用户登录DTO")
public class LoginDTO { public class LoginDTO {
@Max(value = 1, message = "登录终端类型取值范围:0,1") @Max(value = 2, message = "登录终端类型取值范围:0,2")
@Min(value = 0, message = "登录终端类型取值范围:0,1") @Min(value = 0, message = "登录终端类型取值范围:0,2")
@NotNull(message = "登录终端类型不可为空") @NotNull(message = "登录终端类型不可为空")
@ApiModelProperty(value = "登录终端 0:web 1:app") @ApiModelProperty(value = "登录终端 0:web 1:app 2:pc")
private Integer terminal; private Integer terminal;
@NotEmpty(message = "用户名不可为空") @NotEmpty(message = "用户名不可为空")

31
im-platform/src/main/java/com/bx/implatform/service/impl/GroupMessageServiceImpl.java

@ -1,6 +1,8 @@
package com.bx.implatform.service.impl; package com.bx.implatform.service.impl;
import cn.hutool.core.collection.CollStreamUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -146,10 +148,11 @@ public class GroupMessageServiceImpl extends ServiceImpl<GroupMessageMapper, Gro
public List<GroupMessageVO> loadMessage(Long minId) { public List<GroupMessageVO> loadMessage(Long minId) {
UserSession session = SessionContext.getSession(); UserSession session = SessionContext.getSession();
List<GroupMember> members = groupMemberService.findByUserId(session.getUserId()); List<GroupMember> members = groupMemberService.findByUserId(session.getUserId());
List<Long> ids = members.stream().map(GroupMember::getGroupId).collect(Collectors.toList()); if (CollectionUtil.isEmpty(members)) {
if (CollectionUtil.isEmpty(ids)) {
return new ArrayList<>(); return new ArrayList<>();
} }
Map<Long, GroupMember> groupMemberMap = CollStreamUtil.toIdentityMap(members, GroupMember::getGroupId);
Set<Long> ids = groupMemberMap.keySet();
// 只能拉取最近1个月的 // 只能拉取最近1个月的
Date minDate = DateUtils.addMonths(new Date(), -1); Date minDate = DateUtils.addMonths(new Date(), -1);
LambdaQueryWrapper<GroupMessage> wrapper = Wrappers.lambdaQuery(); LambdaQueryWrapper<GroupMessage> wrapper = Wrappers.lambdaQuery();
@ -158,15 +161,21 @@ public class GroupMessageServiceImpl extends ServiceImpl<GroupMessageMapper, Gro
List<GroupMessage> messages = this.list(wrapper); List<GroupMessage> messages = this.list(wrapper);
// 转成vo // 转成vo
List<GroupMessageVO> vos = messages.stream().map(m -> { List<GroupMessageVO> vos = messages.stream()
GroupMessageVO vo = BeanUtils.copyProperties(m, GroupMessageVO.class); .filter(m -> {
// 被@用户列表 //排除加群之前的消息
if (StringUtils.isNotBlank(m.getAtUserIds())) { GroupMember member = groupMemberMap.get(m.getGroupId());
List<String> atIds = Splitter.on(",").trimResults().splitToList(m.getAtUserIds()); return Objects.nonNull(member) && DateUtil.compare(member.getCreatedTime(), m.getSendTime()) <= 0;
vo.setAtUserIds(atIds.stream().map(Long::parseLong).collect(Collectors.toList())); })
} .map(m -> {
return vo; GroupMessageVO vo = BeanUtils.copyProperties(m, GroupMessageVO.class);
}).collect(Collectors.toList()); // 被@用户列表
if (StringUtils.isNotBlank(m.getAtUserIds()) && Objects.nonNull(vo)) {
List<String> atIds = Splitter.on(",").trimResults().splitToList(m.getAtUserIds());
vo.setAtUserIds(atIds.stream().map(Long::parseLong).collect(Collectors.toList()));
}
return vo;
}).collect(Collectors.toList());
// 消息状态,数据库没有存群聊的消息状态,需要从redis取 // 消息状态,数据库没有存群聊的消息状态,需要从redis取
List<String> keys = ids.stream().map(id -> String.join(":", RedisKey.IM_GROUP_READED_POSITION, id.toString(), session.getUserId().toString())) List<String> keys = ids.stream().map(id -> String.join(":", RedisKey.IM_GROUP_READED_POSITION, id.toString(), session.getUserId().toString()))
.collect(Collectors.toList()); .collect(Collectors.toList());

1
im-platform/src/main/resources/application.yml

@ -54,3 +54,4 @@ jwt:
refreshToken: refreshToken:
expireIn: 604800 #7天 expireIn: 604800 #7天
secret: IKDiqVmn0VFU secret: IKDiqVmn0VFU

2
im-ui/src/api/date.js

@ -21,7 +21,7 @@ let toTimeText = (timeStamp, simple) => {
//不属于今年 //不属于今年
timeText = formatDateTime(dateTime); timeText = formatDateTime(dateTime);
if(simple){ if(simple){
timeText = timeText.substring(2,5); timeText = timeText.substr(2,8);
} }
} }
return timeText; return timeText;

2
im-uniapp/common/date.js

@ -21,7 +21,7 @@ let toTimeText = (timeStamp, simple) => {
//不属于今年 //不属于今年
timeText = formatDateTime(dateTime); timeText = formatDateTime(dateTime);
if(simple){ if(simple){
timeText = timeText.substring(2,5); timeText = timeText.substr(2,8);
} }
} }
return timeText; return timeText;

2
im-uniapp/components/chat-item/chat-item.vue

@ -7,7 +7,7 @@
<view class="chat-right"> <view class="chat-right">
<view class="chat-name"> <view class="chat-name">
<view class="chat-name-text">{{chat.showName}}</view> <view class="chat-name-text">{{chat.showName}}</view>
<view class="chat-time">{{$date.toTimeText(chat.lastSendTime)}}</view> <view class="chat-time">{{$date.toTimeText(chat.lastSendTime,true)}}</view>
</view> </view>
<view class="chat-content"> <view class="chat-content">
<view class="chat-at-text">{{atText}}</view> <view class="chat-at-text">{{atText}}</view>

Loading…
Cancel
Save