mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-15 23:23:43 +08:00
feat:
1.消息撤回功能 2.管理员拉黑功能 3.管理员撤回消息功能 4.消息类型可扩展
This commit is contained in:
@@ -42,7 +42,7 @@ public class MessageMarkListener {
|
||||
public void changeMsgType(MessageMarkEvent event) {
|
||||
ChatMessageMarkDTO dto = event.getDto();
|
||||
Message msg = messageDao.getById(dto.getMsgId());
|
||||
if (!Objects.equals(msg.getType(), MessageTypeEnum.NORMAL.getType())) {//普通消息才需要升级
|
||||
if (!Objects.equals(msg.getType(), MessageTypeEnum.TEXT.getType())) {//普通消息才需要升级
|
||||
return;
|
||||
}
|
||||
//消息被标记次数
|
||||
@@ -51,8 +51,7 @@ public class MessageMarkListener {
|
||||
if (markCount < markTypeEnum.getRiseNum()) {
|
||||
return;
|
||||
}
|
||||
boolean updateSuccess = messageDao.riseOptimistic(msg.getId(), msg.getType(), markTypeEnum.getRiseEnum().getType());
|
||||
if (MessageMarkTypeEnum.LIKE.getType().equals(dto.getMarkType()) && updateSuccess) {//尝试给用户发送一张徽章
|
||||
if (MessageMarkTypeEnum.LIKE.getType().equals(dto.getMarkType())) {//尝试给用户发送一张徽章
|
||||
iUserBackpackService.acquireItem(msg.getFromUid(), ItemEnum.LIKE_BADGE.getId(), IdempotentEnum.MSG_ID, msg.getId().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.abin.mallchat.custom.common.event.listener;
|
||||
|
||||
import com.abin.mallchat.common.chat.domain.dto.ChatMsgRecallDTO;
|
||||
import com.abin.mallchat.common.chat.service.cache.MsgCache;
|
||||
import com.abin.mallchat.common.common.event.MessageRecallEvent;
|
||||
import com.abin.mallchat.custom.chat.service.ChatService;
|
||||
import com.abin.mallchat.custom.user.service.WebSocketService;
|
||||
import com.abin.mallchat.custom.user.service.adapter.WSAdapter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.event.TransactionalEventListener;
|
||||
|
||||
/**
|
||||
* 消息撤回监听器
|
||||
*
|
||||
* @author zhongzb create on 2022/08/26
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class MessageRecallListener {
|
||||
@Autowired
|
||||
private WebSocketService webSocketService;
|
||||
@Autowired
|
||||
private ChatService chatService;
|
||||
@Autowired
|
||||
private MsgCache msgCache;
|
||||
|
||||
@Async
|
||||
@TransactionalEventListener(classes = MessageRecallEvent.class, fallbackExecution = true)
|
||||
public void evictMsg(MessageRecallEvent event) {
|
||||
ChatMsgRecallDTO recallDTO = event.getRecallDTO();
|
||||
msgCache.evictMsg(recallDTO.getMsgId());
|
||||
}
|
||||
|
||||
@Async
|
||||
@TransactionalEventListener(classes = MessageRecallEvent.class, fallbackExecution = true)
|
||||
public void sendToAll(MessageRecallEvent event) {
|
||||
webSocketService.sendToAllOnline(WSAdapter.buildMsgRecall(event.getRecallDTO()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.abin.mallchat.custom.common.event.listener;
|
||||
|
||||
import com.abin.mallchat.common.chat.dao.MessageDao;
|
||||
import com.abin.mallchat.common.common.event.UserBlackEvent;
|
||||
import com.abin.mallchat.common.user.service.cache.UserCache;
|
||||
import com.abin.mallchat.custom.user.domain.enums.WSRespTypeEnum;
|
||||
import com.abin.mallchat.custom.user.domain.vo.response.ws.WSBaseResp;
|
||||
import com.abin.mallchat.custom.user.domain.vo.response.ws.WSBlack;
|
||||
import com.abin.mallchat.custom.user.service.WebSocketService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 用户拉黑监听器
|
||||
*
|
||||
* @author zhongzb create on 2022/08/26
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class UserBlackListener {
|
||||
@Autowired
|
||||
private MessageDao messageDao;
|
||||
@Autowired
|
||||
private WebSocketService webSocketService;
|
||||
@Autowired
|
||||
private UserCache userCache;
|
||||
|
||||
@Async
|
||||
@EventListener(classes = UserBlackEvent.class)
|
||||
public void refreshRedis(UserBlackEvent event) {
|
||||
userCache.evictBlackMap();
|
||||
userCache.remove(event.getUser().getId());
|
||||
}
|
||||
|
||||
@Async
|
||||
@EventListener(classes = UserBlackEvent.class)
|
||||
public void deleteMsg(UserBlackEvent event) {
|
||||
messageDao.invalidByUid(event.getUser().getId());
|
||||
}
|
||||
|
||||
@Async
|
||||
@EventListener(classes = UserBlackEvent.class)
|
||||
public void sendPush(UserBlackEvent event) {
|
||||
Long uid = event.getUser().getId();
|
||||
WSBaseResp<WSBlack> resp = new WSBaseResp<>();
|
||||
WSBlack black = new WSBlack(uid);
|
||||
resp.setData(black);
|
||||
resp.setType(WSRespTypeEnum.BLACK.getType());
|
||||
webSocketService.sendToAllOnline(resp, uid);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user