mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-14 06:03:42 +08:00
私下调整频控
This commit is contained in:
@@ -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.ChatMessageResp;
|
||||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatRoomResp;
|
import com.abin.mallchat.custom.chat.domain.vo.response.ChatRoomResp;
|
||||||
import com.abin.mallchat.custom.chat.service.ChatService;
|
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.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@@ -39,6 +41,7 @@ import java.util.Set;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/capi/chat")
|
@RequestMapping("/capi/chat")
|
||||||
@Api(tags = "聊天室相关接口")
|
@Api(tags = "聊天室相关接口")
|
||||||
|
@Slf4j
|
||||||
public class ChatController {
|
public class ChatController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ChatService chatService;
|
private ChatService chatService;
|
||||||
@@ -53,7 +56,9 @@ public class ChatController {
|
|||||||
|
|
||||||
@GetMapping("/public/member/page")
|
@GetMapping("/public/member/page")
|
||||||
@ApiOperation("群成员列表")
|
@ApiOperation("群成员列表")
|
||||||
|
@FrequencyControl(time = 120, count = 10, target = FrequencyControl.Target.IP)
|
||||||
public ApiResult<CursorPageBaseResp<ChatMemberResp>> getMemberPage(@Valid CursorPageBaseReq request) {
|
public ApiResult<CursorPageBaseResp<ChatMemberResp>> getMemberPage(@Valid CursorPageBaseReq request) {
|
||||||
|
black(request);
|
||||||
CursorPageBaseResp<ChatMemberResp> memberPage = chatService.getMemberPage(request);
|
CursorPageBaseResp<ChatMemberResp> memberPage = chatService.getMemberPage(request);
|
||||||
filterBlackMember(memberPage);
|
filterBlackMember(memberPage);
|
||||||
return ApiResult.success(memberPage);
|
return ApiResult.success(memberPage);
|
||||||
@@ -74,14 +79,28 @@ public class ChatController {
|
|||||||
return ApiResult.success(chatService.getMemberStatistic());
|
return ApiResult.success(chatService.getMemberStatistic());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserServiceImpl userService;
|
||||||
|
|
||||||
@GetMapping("/public/msg/page")
|
@GetMapping("/public/msg/page")
|
||||||
@ApiOperation("消息列表")
|
@ApiOperation("消息列表")
|
||||||
|
@FrequencyControl(time = 120, count = 10, target = FrequencyControl.Target.IP)
|
||||||
public ApiResult<CursorPageBaseResp<ChatMessageResp>> getMsgPage(@Valid ChatMessagePageReq request) {
|
public ApiResult<CursorPageBaseResp<ChatMessageResp>> getMsgPage(@Valid ChatMessagePageReq request) {
|
||||||
|
black(request);
|
||||||
CursorPageBaseResp<ChatMessageResp> msgPage = chatService.getMsgPage(request, RequestHolder.get().getUid());
|
CursorPageBaseResp<ChatMessageResp> msgPage = chatService.getMsgPage(request, RequestHolder.get().getUid());
|
||||||
filterBlackMsg(msgPage);
|
filterBlackMsg(msgPage);
|
||||||
return ApiResult.success(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<ChatMessageResp> memberPage) {
|
private void filterBlackMsg(CursorPageBaseResp<ChatMessageResp> memberPage) {
|
||||||
Set<String> blackMembers = getBlackUidSet();
|
Set<String> blackMembers = getBlackUidSet();
|
||||||
memberPage.getList().removeIf(a -> blackMembers.contains(a.getFromUser().getUid().toString()));
|
memberPage.getList().removeIf(a -> blackMembers.contains(a.getFromUser().getUid().toString()));
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
applicationEventPublisher.publishEvent(new UserBlackEvent(this, byId));
|
applicationEventPublisher.publishEvent(new UserBlackEvent(this, byId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void blackIp(String ip) {
|
public void blackIp(String ip) {
|
||||||
if (StrUtil.isBlank(ip)) {
|
if (StrUtil.isBlank(ip)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user