Browse Source

发送消息接口将整个vo返回

master
xsx 2 years ago
parent
commit
3c708f07ef
  1. 2
      im-platform/src/main/java/com/bx/implatform/controller/GroupMessageController.java
  2. 2
      im-platform/src/main/java/com/bx/implatform/controller/PrivateMessageController.java
  3. 2
      im-platform/src/main/java/com/bx/implatform/dto/GroupMessageDTO.java
  4. 2
      im-platform/src/main/java/com/bx/implatform/dto/PrivateMessageDTO.java
  5. 2
      im-platform/src/main/java/com/bx/implatform/service/GroupMessageService.java
  6. 2
      im-platform/src/main/java/com/bx/implatform/service/PrivateMessageService.java
  7. 11
      im-platform/src/main/java/com/bx/implatform/service/impl/GroupMessageServiceImpl.java
  8. 11
      im-platform/src/main/java/com/bx/implatform/service/impl/PrivateMessageServiceImpl.java
  9. 30
      im-ui/src/components/chat/ChatBox.vue
  10. 30
      im-uniapp/pages/chat/chat-box.vue

2
im-platform/src/main/java/com/bx/implatform/controller/GroupMessageController.java

@ -24,7 +24,7 @@ public class GroupMessageController {
@PostMapping("/send")
@Operation(summary = "发送群聊消息", description = "发送群聊消息")
public Result<Long> sendMessage(@Valid @RequestBody GroupMessageDTO vo) {
public Result<GroupMessageVO> sendMessage(@Valid @RequestBody GroupMessageDTO vo) {
return ResultUtils.success(groupMessageService.sendMessage(vo));
}

2
im-platform/src/main/java/com/bx/implatform/controller/PrivateMessageController.java

@ -24,7 +24,7 @@ public class PrivateMessageController {
@PostMapping("/send")
@Operation(summary = "发送消息", description = "发送私聊消息")
public Result<Long> sendMessage(@Valid @RequestBody PrivateMessageDTO vo) {
public Result<PrivateMessageVO> sendMessage(@Valid @RequestBody PrivateMessageDTO vo) {
return ResultUtils.success(privateMessageService.sendMessage(vo));
}

2
im-platform/src/main/java/com/bx/implatform/dto/GroupMessageDTO.java

@ -23,7 +23,7 @@ public class GroupMessageDTO {
private String content;
@NotNull(message = "消息类型不可为空")
@Schema(description = "消息类型")
@Schema(description = "消息类型 0:文字 1:图片 2:文件 3:语音 4:视频")
private Integer type;
@Schema(description = "是否回执消息")

2
im-platform/src/main/java/com/bx/implatform/dto/PrivateMessageDTO.java

@ -21,7 +21,7 @@ public class PrivateMessageDTO {
private String content;
@NotNull(message = "消息类型不可为空")
@Schema(description = "消息类型")
@Schema(description = "消息类型 0:文字 1:图片 2:文件 3:语音 4:视频")
private Integer type;
}

2
im-platform/src/main/java/com/bx/implatform/service/GroupMessageService.java

@ -15,7 +15,7 @@ public interface GroupMessageService extends IService<GroupMessage> {
* @param dto 群聊消息
* @return 群聊id
*/
Long sendMessage(GroupMessageDTO dto);
GroupMessageVO sendMessage(GroupMessageDTO dto);
/**
* 撤回消息

2
im-platform/src/main/java/com/bx/implatform/service/PrivateMessageService.java

@ -15,7 +15,7 @@ public interface PrivateMessageService extends IService<PrivateMessage> {
* @param dto 私聊消息
* @return 消息id
*/
Long sendMessage(PrivateMessageDTO dto);
PrivateMessageVO sendMessage(PrivateMessageDTO dto);
/**

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

@ -55,7 +55,7 @@ public class GroupMessageServiceImpl extends ServiceImpl<GroupMessageMapper, Gro
private final SensitiveFilterUtil sensitiveFilterUtil;
@Override
public Long sendMessage(GroupMessageDTO dto) {
public GroupMessageVO sendMessage(GroupMessageDTO dto) {
UserSession session = SessionContext.getSession();
Group group = groupService.getAndCheckById(dto.getGroupId());
// 是否在群聊里面
@ -76,9 +76,10 @@ public class GroupMessageServiceImpl extends ServiceImpl<GroupMessageMapper, Gro
msg.setAtUserIds(StrUtil.join(",", dto.getAtUserIds()));
}
this.save(msg);
// 过滤消息内容
String content = sensitiveFilterUtil.filter(dto.getContent());
msg.setContent(content);
// 过滤内容中的敏感词
if(MessageType.TEXT.code().equals(dto.getType())){
msg.setContent(sensitiveFilterUtil.filter(dto.getContent()));
}
// 群发
GroupMessageVO msgInfo = BeanUtils.copyProperties(msg, GroupMessageVO.class);
msgInfo.setAtUserIds(dto.getAtUserIds());
@ -89,7 +90,7 @@ public class GroupMessageServiceImpl extends ServiceImpl<GroupMessageMapper, Gro
sendMessage.setData(msgInfo);
imClient.sendGroupMessage(sendMessage);
log.info("发送群聊消息,发送id:{},群聊id:{},内容:{}", session.getUserId(), dto.getGroupId(), dto.getContent());
return msg.getId();
return msgInfo;
}
@Override

11
im-platform/src/main/java/com/bx/implatform/service/impl/PrivateMessageServiceImpl.java

@ -45,7 +45,7 @@ public class PrivateMessageServiceImpl extends ServiceImpl<PrivateMessageMapper,
private final SensitiveFilterUtil sensitiveFilterUtil;
@Override
public Long sendMessage(PrivateMessageDTO dto) {
public PrivateMessageVO sendMessage(PrivateMessageDTO dto) {
UserSession session = SessionContext.getSession();
Boolean isFriends = friendService.isFriend(session.getUserId(), dto.getRecvId());
if (Boolean.FALSE.equals(isFriends)) {
@ -57,9 +57,10 @@ public class PrivateMessageServiceImpl extends ServiceImpl<PrivateMessageMapper,
msg.setStatus(MessageStatus.UNSEND.code());
msg.setSendTime(new Date());
this.save(msg);
// 过滤消息内容
String content = sensitiveFilterUtil.filter(dto.getContent());
msg.setContent(content);
// 过滤内容中的敏感词
if(MessageType.TEXT.code().equals(dto.getType())){
msg.setContent(sensitiveFilterUtil.filter(dto.getContent()));
}
// 推送消息
PrivateMessageVO msgInfo = BeanUtils.copyProperties(msg, PrivateMessageVO.class);
IMPrivateMessage<PrivateMessageVO> sendMessage = new IMPrivateMessage<>();
@ -70,7 +71,7 @@ public class PrivateMessageServiceImpl extends ServiceImpl<PrivateMessageMapper,
sendMessage.setSendResult(true);
imClient.sendPrivateMessage(sendMessage);
log.info("发送私聊消息,发送id:{},接收id:{},内容:{}", session.getUserId(), dto.getRecvId(), dto.getContent());
return msg.getId();
return msgInfo;
}
@Override

30
im-ui/src/components/chat/ChatBox.vue

@ -316,9 +316,9 @@
url: this.messageAction,
method: 'post',
data: msgInfo
}).then((id) => {
}).then((m) => {
msgInfo.loadStatus = 'ok';
msgInfo.id = id;
msgInfo.id = m.id;
this.isReceipt = false;
this.$store.commit("insertMessage", msgInfo);
})
@ -371,9 +371,9 @@
url: this.messageAction,
method: 'post',
data: msgInfo
}).then((id) => {
}).then((m) => {
msgInfo.loadStatus = 'ok';
msgInfo.id = id;
msgInfo.id = m.id;
this.isReceipt = false;
this.$store.commit("insertMessage", msgInfo);
})
@ -528,14 +528,9 @@
url: this.messageAction,
method: 'post',
data: msgInfo
}).then((id) => {
msgInfo.id = id;
msgInfo.sendTime = new Date().getTime();
msgInfo.sendId = this.$store.state.userStore.userInfo.id;
msgInfo.selfSend = true;
msgInfo.status = this.$enums.MESSAGE_STATUS.UNSEND;
msgInfo.readedCount = 0;
this.$store.commit("insertMessage", msgInfo);
}).then((m) => {
m.selfSend = true;
this.$store.commit("insertMessage", m);
//
this.moveChatToTop();
//
@ -605,14 +600,9 @@
url: this.messageAction,
method: 'post',
data: msgInfo
}).then((id) => {
msgInfo.id = id;
msgInfo.sendTime = new Date().getTime();
msgInfo.sendId = this.$store.state.userStore.userInfo.id;
msgInfo.selfSend = true;
msgInfo.readedCount = 0;
msgInfo.status = this.$enums.MESSAGE_STATUS.UNSEND;
this.$store.commit("insertMessage", msgInfo);
}).then((m) => {
m.selfSend = true;
this.$store.commit("insertMessage", m);
//
this.moveChatToTop();
}).finally(() => {

30
im-uniapp/pages/chat/chat-box.vue

@ -157,14 +157,9 @@
url: this.messageAction,
method: 'POST',
data: msgInfo
}).then((id) => {
msgInfo.id = id;
msgInfo.sendTime = new Date().getTime();
msgInfo.sendId = this.$store.state.userStore.userInfo.id;
msgInfo.selfSend = true;
msgInfo.status = this.$enums.MESSAGE_STATUS.UNSEND;
msgInfo.readedCount = 0;
this.$store.commit("insertMessage", msgInfo);
}).then((m) => {
m.selfSend = true;
this.$store.commit("insertMessage", m);
//
this.moveChatToTop();
//
@ -289,14 +284,9 @@
url: this.messageAction,
method: 'POST',
data: msgInfo
}).then((id) => {
msgInfo.id = id;
msgInfo.sendTime = new Date().getTime();
msgInfo.sendId = this.$store.state.userStore.userInfo.id;
msgInfo.selfSend = true;
msgInfo.readedCount = 0,
msgInfo.status = this.$enums.MESSAGE_STATUS.UNSEND;
this.$store.commit("insertMessage", msgInfo);
}).then((m) => {
m.selfSend = true;
this.$store.commit("insertMessage", m);
//
this.moveChatToTop();
this.sendText = "";
@ -421,9 +411,9 @@
url: this.messageAction,
method: 'POST',
data: msgInfo
}).then((id) => {
}).then((m) => {
msgInfo.loadStatus = 'ok';
msgInfo.id = id;
msgInfo.id = m.id;
this.isReceipt = false;
this.$store.commit("insertMessage", msgInfo);
})
@ -476,9 +466,9 @@
url: this.messageAction,
method: 'POST',
data: msgInfo
}).then((id) => {
}).then((m) => {
msgInfo.loadStatus = 'ok';
msgInfo.id = id;
msgInfo.id = m.id;
this.isReceipt = false;
this.$store.commit("insertMessage", msgInfo);
})

Loading…
Cancel
Save