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 bf89bd0..0de5a1f 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 @@ -18,8 +18,10 @@ import com.abin.mallchat.custom.chat.domain.vo.response.ChatMemberStatisticResp; import com.abin.mallchat.custom.chat.domain.vo.response.ChatMessageResp; import com.abin.mallchat.custom.chat.domain.vo.response.ChatRoomResp; import com.abin.mallchat.custom.chat.service.ChatService; +import com.abin.mallchat.custom.user.service.impl.UserServiceImpl; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -39,6 +41,7 @@ import java.util.Set; @RestController @RequestMapping("/capi/chat") @Api(tags = "聊天室相关接口") +@Slf4j public class ChatController { @Autowired private ChatService chatService; @@ -53,7 +56,9 @@ public class ChatController { @GetMapping("/public/member/page") @ApiOperation("群成员列表") + @FrequencyControl(time = 120, count = 10, target = FrequencyControl.Target.IP) public ApiResult> getMemberPage(@Valid CursorPageBaseReq request) { + black(request); CursorPageBaseResp memberPage = chatService.getMemberPage(request); filterBlackMember(memberPage); return ApiResult.success(memberPage); @@ -74,14 +79,28 @@ public class ChatController { return ApiResult.success(chatService.getMemberStatistic()); } + @Autowired + private UserServiceImpl userService; + @GetMapping("/public/msg/page") @ApiOperation("消息列表") + @FrequencyControl(time = 120, count = 10, target = FrequencyControl.Target.IP) public ApiResult> getMsgPage(@Valid ChatMessagePageReq request) { + black(request); CursorPageBaseResp msgPage = chatService.getMsgPage(request, RequestHolder.get().getUid()); filterBlackMsg(msgPage); return ApiResult.success(msgPage); } + private void black(CursorPageBaseReq baseReq) { + if (baseReq.getPageSize() > 50) { + log.info("limit request:{}", baseReq); + baseReq.setPageSize(10); + userService.blackIp(RequestHolder.get().getIp()); + } + + } + private void filterBlackMsg(CursorPageBaseResp memberPage) { Set blackMembers = getBlackUidSet(); memberPage.getList().removeIf(a -> blackMembers.contains(a.getFromUser().getUid().toString())); diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/UserServiceImpl.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/UserServiceImpl.java index 2ddde78..53811fa 100644 --- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/UserServiceImpl.java +++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/UserServiceImpl.java @@ -128,7 +128,7 @@ public class UserServiceImpl implements UserService { applicationEventPublisher.publishEvent(new UserBlackEvent(this, byId)); } - private void blackIp(String ip) { + public void blackIp(String ip) { if (StrUtil.isBlank(ip)) { return; }