Commit ecedeeda by 南千昊

添加好友限制 群聊不做限制 搜索加好友不做限制

parent d3fbb3c4
...@@ -88,16 +88,18 @@ public class ImFriendController extends BaseController { ...@@ -88,16 +88,18 @@ public class ImFriendController extends BaseController {
if (currentClient.getId().equals(friendClient.getId())) { if (currentClient.getId().equals(friendClient.getId())) {
return ApiResult.fail(ApiCode.PARAMETER_EXCEPTION, null); return ApiResult.fail(ApiCode.PARAMETER_EXCEPTION, null);
} }
List<ImFriendBaseDto> friends = imFriendService.getFriends(currentClient); if (param.getAddFriendScene().getCode()==1){
if (isVip){ List<ImFriendBaseDto> friends = imFriendService.getFriends(currentClient);
// 是vip if (isVip){
if (friends.size()>=10){ // 是vip
throw new BusinessException("vip最多只能加10个好友"); if (friends.size()>=10){
} throw new BusinessException("vip最多只能加10个好友");
}else { }
// 不是vip }else {
if (friends.size()>=3){ // 不是vip
throw new BusinessException("非vip最多只能加3个好友"); if (friends.size()>=3){
throw new BusinessException("非vip最多只能加3个好友");
}
} }
} }
imFriendService.applyFriend(currentClient, friendClient, param.getFriendName(), param.getRequestRemark()); imFriendService.applyFriend(currentClient, friendClient, param.getFriendName(), param.getRequestRemark());
......
package com.wecloud.im.friend.enums;
import io.geekidea.springbootplus.framework.common.enums.BaseEnum;
/**
* @author nanqianhao
* @date 2022/9/21
* @apiNote 加好友场景
*/
public enum AddFriendSceneEnum implements BaseEnum {
/**
* 1 - 陌生人
*/
STRANGER(1, "陌生人"),
/**
* 2 - 搜索
*/
SEARCH(2, "搜索");
AddFriendSceneEnum(int code, String desc) {
this.code = code;
this.desc = desc;
}
private final Integer code;
private final String desc;
@Override
public Integer getCode() {
return this.code;
}
@Override
public String getDesc() {
return this.desc;
}
}
package com.wecloud.im.friend.param; package com.wecloud.im.friend.param;
import com.wecloud.im.friend.enums.AddFriendSceneEnum;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
...@@ -23,4 +24,7 @@ public class ImFriendApplyParam extends ImFriendBaseParam { ...@@ -23,4 +24,7 @@ public class ImFriendApplyParam extends ImFriendBaseParam {
@ApiModelProperty("是否需要验证") @ApiModelProperty("是否需要验证")
private Boolean needVerify = true; private Boolean needVerify = true;
@ApiModelProperty("加好友入口场景")
private AddFriendSceneEnum addFriendScene;
} }
package com.wecloud.im.service.impl; package com.wecloud.im.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.baomidou.mybatisplus.core.metadata.OrderItem;
...@@ -10,7 +9,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; ...@@ -10,7 +9,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.wecloud.im.entity.*; import com.wecloud.im.entity.*;
import com.wecloud.im.friend.param.ImFriendApplyParam; import com.wecloud.im.friend.param.ImFriendApplyParam;
import com.wecloud.im.friend.param.ImFriendBaseDto;
import com.wecloud.im.friend.service.ImFriendService; import com.wecloud.im.friend.service.ImFriendService;
import com.wecloud.im.mapper.ImConversationMapper; import com.wecloud.im.mapper.ImConversationMapper;
import com.wecloud.im.mapper.ImConversationMembersMapper; import com.wecloud.im.mapper.ImConversationMembersMapper;
...@@ -34,12 +32,14 @@ import io.geekidea.springbootplus.framework.core.pagination.PageInfo; ...@@ -34,12 +32,14 @@ import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import io.geekidea.springbootplus.framework.core.pagination.Paging; import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.shiro.util.SecurityUtils; import io.geekidea.springbootplus.framework.shiro.util.SecurityUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/** /**
* 会话成员表 服务实现类 * 会话成员表 服务实现类
...@@ -304,28 +304,28 @@ public class ImConversationMembersServiceImpl extends BaseServiceImpl<ImConversa ...@@ -304,28 +304,28 @@ public class ImConversationMembersServiceImpl extends BaseServiceImpl<ImConversa
// 校验通过,调用imFriendService apply方法 // 校验通过,调用imFriendService apply方法
ImClient initiator = imClientService.getCacheImClient(appId, param.getClientId()); ImClient initiator = imClientService.getCacheImClient(appId, param.getClientId());
ImClient recipient = imClientService.getCacheImClient(appId, param.getFriendClientId()); ImClient recipient = imClientService.getCacheImClient(appId, param.getFriendClientId());
String senderAttributesStr = initiator.getAttributes(); //String senderAttributesStr = initiator.getAttributes();
JSONObject senderAttributes = new JSONObject(); //JSONObject senderAttributes = new JSONObject();
if (StringUtils.isNotBlank(senderAttributesStr)) { //if (StringUtils.isNotBlank(senderAttributesStr)) {
try { // try {
senderAttributes = JSONObject.parseObject(senderAttributesStr); // senderAttributes = JSONObject.parseObject(senderAttributesStr);
} catch (Exception e) { // } catch (Exception e) {
// do nothing is ok // // do nothing is ok
} // }
} //}
boolean isVip = Optional.ofNullable(senderAttributes.getBoolean("isVip")).orElse(Boolean.FALSE); //boolean isVip = Optional.ofNullable(senderAttributes.getBoolean("isVip")).orElse(Boolean.FALSE);
List<ImFriendBaseDto> friends = imFriendService.getFriends(initiator); //List<ImFriendBaseDto> friends = imFriendService.getFriends(initiator);
if (isVip){ //if (isVip){
// 是vip // // 是vip
if (friends.size()>=10){ // if (friends.size()>=10){
throw new BusinessException("vip最多只能加10个好友"); // throw new BusinessException("vip最多只能加10个好友");
} // }
}else { //}else {
// 不是vip // // 不是vip
if (friends.size()>=3){ // if (friends.size()>=3){
throw new BusinessException("非vip最多只能加3个好友"); // throw new BusinessException("非vip最多只能加3个好友");
} // }
} //}
imFriendService.applyFriend(initiator, recipient, param.getFriendName(), imFriendService.applyFriend(initiator, recipient, param.getFriendName(),
param.getRequestRemark()); param.getRequestRemark());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment