Commit ecedeeda by 南千昊

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

parent d3fbb3c4
......@@ -88,6 +88,7 @@ public class ImFriendController extends BaseController {
if (currentClient.getId().equals(friendClient.getId())) {
return ApiResult.fail(ApiCode.PARAMETER_EXCEPTION, null);
}
if (param.getAddFriendScene().getCode()==1){
List<ImFriendBaseDto> friends = imFriendService.getFriends(currentClient);
if (isVip){
// 是vip
......@@ -100,6 +101,7 @@ public class ImFriendController extends BaseController {
throw new BusinessException("非vip最多只能加3个好友");
}
}
}
imFriendService.applyFriend(currentClient, friendClient, param.getFriendName(), param.getRequestRemark());
log.info("申请添加好友逻辑完成");
return ApiResult.ok();
......
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;
import com.wecloud.im.friend.enums.AddFriendSceneEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -23,4 +24,7 @@ public class ImFriendApplyParam extends ImFriendBaseParam {
@ApiModelProperty("是否需要验证")
private Boolean needVerify = true;
@ApiModelProperty("加好友入口场景")
private AddFriendSceneEnum addFriendScene;
}
package com.wecloud.im.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
......@@ -10,7 +9,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Maps;
import com.wecloud.im.entity.*;
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.mapper.ImConversationMapper;
import com.wecloud.im.mapper.ImConversationMembersMapper;
......@@ -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.shiro.util.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
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
// 校验通过,调用imFriendService apply方法
ImClient initiator = imClientService.getCacheImClient(appId, param.getClientId());
ImClient recipient = imClientService.getCacheImClient(appId, param.getFriendClientId());
String senderAttributesStr = initiator.getAttributes();
JSONObject senderAttributes = new JSONObject();
if (StringUtils.isNotBlank(senderAttributesStr)) {
try {
senderAttributes = JSONObject.parseObject(senderAttributesStr);
} catch (Exception e) {
// do nothing is ok
}
}
boolean isVip = Optional.ofNullable(senderAttributes.getBoolean("isVip")).orElse(Boolean.FALSE);
List<ImFriendBaseDto> friends = imFriendService.getFriends(initiator);
if (isVip){
// 是vip
if (friends.size()>=10){
throw new BusinessException("vip最多只能加10个好友");
}
}else {
// 不是vip
if (friends.size()>=3){
throw new BusinessException("非vip最多只能加3个好友");
}
}
//String senderAttributesStr = initiator.getAttributes();
//JSONObject senderAttributes = new JSONObject();
//if (StringUtils.isNotBlank(senderAttributesStr)) {
// try {
// senderAttributes = JSONObject.parseObject(senderAttributesStr);
// } catch (Exception e) {
// // do nothing is ok
// }
//}
//boolean isVip = Optional.ofNullable(senderAttributes.getBoolean("isVip")).orElse(Boolean.FALSE);
//List<ImFriendBaseDto> friends = imFriendService.getFriends(initiator);
//if (isVip){
// // 是vip
// if (friends.size()>=10){
// throw new BusinessException("vip最多只能加10个好友");
// }
//}else {
// // 不是vip
// if (friends.size()>=3){
// throw new BusinessException("非vip最多只能加3个好友");
// }
//}
imFriendService.applyFriend(initiator, recipient, param.getFriendName(),
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