> evictBlackMap() {
+ return null;
+ }
}
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/controller/ChatController.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/controller/ChatController.java
index 86412cf..d23af39 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/controller/ChatController.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/controller/ChatController.java
@@ -7,6 +7,9 @@ import com.abin.mallchat.common.common.domain.vo.request.CursorPageBaseReq;
import com.abin.mallchat.common.common.domain.vo.response.ApiResult;
import com.abin.mallchat.common.common.domain.vo.response.CursorPageBaseResp;
import com.abin.mallchat.common.common.domain.vo.response.IdRespVO;
+import com.abin.mallchat.common.user.dao.UserDao;
+import com.abin.mallchat.common.user.domain.enums.BlackTypeEnum;
+import com.abin.mallchat.common.user.service.cache.UserCache;
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageMarkReq;
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessagePageReq;
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageReq;
@@ -22,6 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
+import java.util.Map;
+import java.util.Set;
/**
*
@@ -37,6 +42,8 @@ import javax.validation.Valid;
public class ChatController {
@Autowired
private ChatService chatService;
+ @Autowired
+ private UserCache userCache;
@GetMapping("/public/room/page")
@ApiOperation("会话列表")
@@ -47,7 +54,16 @@ public class ChatController {
@GetMapping("/public/member/page")
@ApiOperation("群成员列表")
public ApiResult> getMemberPage(CursorPageBaseReq request) {
- return ApiResult.success(chatService.getMemberPage(request));
+ CursorPageBaseResp memberPage = chatService.getMemberPage(request);
+ filterBlackMember(memberPage);
+ return ApiResult.success(memberPage);
+ }
+
+ private void filterBlackMember(CursorPageBaseResp memberPage) {
+ memberPage.getList().removeIf(a->getBlackUidSet().contains(a.getUid().toString()));
+ }
+ private Set getBlackUidSet(){
+ return userCache.getBlackMap().get(BlackTypeEnum.UID.getType());
}
@GetMapping("/public/member/statistic")
@@ -59,9 +75,14 @@ public class ChatController {
@GetMapping("/public/msg/page")
@ApiOperation("消息列表")
public ApiResult> getMsgPage(ChatMessagePageReq request) {
- return ApiResult.success(chatService.getMsgPage(request, RequestHolder.get().getUid()));
+ CursorPageBaseResp msgPage = chatService.getMsgPage(request, RequestHolder.get().getUid());
+ filterBlackMsg(msgPage);
+ return ApiResult.success(msgPage);
+ }
+ private void filterBlackMsg(CursorPageBaseResp memberPage) {
+ memberPage.getList().removeIf(a->getBlackUidSet().contains(a.getFromUser().getUid().toString()));
+ System.out.println(1);
}
-
@PostMapping("/msg")
@ApiOperation("发送消息")
@FrequencyControl(time = 5, count = 2, target = FrequencyControl.Target.UID)
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/config/InterceptorConfig.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/config/InterceptorConfig.java
index 09bf88e..ad55fbe 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/config/InterceptorConfig.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/config/InterceptorConfig.java
@@ -1,5 +1,6 @@
package com.abin.mallchat.custom.common.config;
+import com.abin.mallchat.custom.common.intecepter.BlackInterceptor;
import com.abin.mallchat.custom.common.intecepter.CollectorInterceptor;
import com.abin.mallchat.custom.common.intecepter.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
@@ -19,11 +20,15 @@ public class InterceptorConfig implements WebMvcConfigurer {
private TokenInterceptor tokenInterceptor;
@Autowired
private CollectorInterceptor collectorInterceptor;
+ @Autowired
+ private BlackInterceptor blackInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(tokenInterceptor)
.addPathPatterns("/capi/**");
registry.addInterceptor(collectorInterceptor)
.addPathPatterns("/capi/**");
+ registry.addInterceptor(blackInterceptor)
+ .addPathPatterns("/capi/**");
}
}
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/intecepter/BlackInterceptor.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/intecepter/BlackInterceptor.java
new file mode 100644
index 0000000..bc2b704
--- /dev/null
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/intecepter/BlackInterceptor.java
@@ -0,0 +1,56 @@
+package com.abin.mallchat.custom.common.intecepter;
+
+import cn.hutool.extra.servlet.ServletUtil;
+import com.abin.mallchat.common.common.domain.dto.RequestInfo;
+import com.abin.mallchat.common.common.exception.HttpErrorEnum;
+import com.abin.mallchat.common.common.utils.RequestHolder;
+import com.abin.mallchat.common.user.domain.enums.BlackTypeEnum;
+import com.abin.mallchat.common.user.service.cache.UserCache;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+import org.springframework.web.servlet.HandlerInterceptor;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * 黑名单拦截
+ */
+@Order(2)
+@Slf4j
+@Component
+public class BlackInterceptor implements HandlerInterceptor{
+
+ @Autowired
+ private UserCache userCache;
+
+ @Override
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+ Map> blackMap = userCache.getBlackMap();
+ RequestInfo requestInfo = RequestHolder.get();
+ if(inBlackList(requestInfo.getUid(),blackMap.get(BlackTypeEnum.UID.getType()))){
+ HttpErrorEnum.ACCESS_DENIED.sendHttpError(response);
+ return false;
+ }
+ if(inBlackList(requestInfo.getIp(),blackMap.get(BlackTypeEnum.IP.getType()))){
+ HttpErrorEnum.ACCESS_DENIED.sendHttpError(response);
+ return false;
+ }
+ return true;
+ }
+ private boolean inBlackList(Object target, Set blackSet){
+ if(Objects.isNull(target)||Objects.isNull(blackSet)){
+ return false;
+ }
+ return blackSet.contains(target.toString());
+ }
+
+}
\ No newline at end of file
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/intecepter/CollectorInterceptor.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/intecepter/CollectorInterceptor.java
index c81294a..2fb8d6e 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/intecepter/CollectorInterceptor.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/common/intecepter/CollectorInterceptor.java
@@ -17,16 +17,10 @@ import java.util.Optional;
/**
* 信息收集的拦截器
*/
-@Order
+@Order(1)
@Slf4j
@Component
-public class CollectorInterceptor implements HandlerInterceptor, WebMvcConfigurer {
-
- @Override
- public void addInterceptors(InterceptorRegistry registry) {
- registry.addInterceptor(this)
- .addPathPatterns("/**");
- }
+public class CollectorInterceptor implements HandlerInterceptor{
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/domain/enums/WSRespTypeEnum.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/domain/enums/WSRespTypeEnum.java
index 6fa7453..c0d0f2a 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/domain/enums/WSRespTypeEnum.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/domain/enums/WSRespTypeEnum.java
@@ -1,9 +1,6 @@
package com.abin.mallchat.custom.user.domain.enums;
-import com.abin.mallchat.custom.user.domain.vo.response.ws.WSLoginSuccess;
-import com.abin.mallchat.custom.user.domain.vo.response.ws.WSLoginUrl;
-import com.abin.mallchat.custom.user.domain.vo.response.ws.WSMessage;
-import com.abin.mallchat.custom.user.domain.vo.response.ws.WSOnlineOfflineNotify;
+import com.abin.mallchat.custom.user.domain.vo.response.ws.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -26,6 +23,7 @@ public enum WSRespTypeEnum {
MESSAGE(4, "新消息", WSMessage.class),
ONLINE_OFFLINE_NOTIFY(5, "上下线通知", WSOnlineOfflineNotify.class),
INVALIDATE_TOKEN(6, "使前端的token失效,意味着前端需要重新登录", null),
+ BLACK(7, "拉黑用户", WSBlack.class),
;
private final Integer type;
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/domain/vo/response/ws/WSBlack.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/domain/vo/response/ws/WSBlack.java
new file mode 100644
index 0000000..8619c01
--- /dev/null
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/domain/vo/response/ws/WSBlack.java
@@ -0,0 +1,19 @@
+package com.abin.mallchat.custom.user.domain.vo.response.ws;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * Description:
+ * Author: abin
+ * Date: 2023-03-19
+ */
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class WSBlack {
+ private Long uid;
+}