Search in sources :

Example 11 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class ApiGroupService method setting.

/**
 * 获取个人对群的设置
 *
 * @param command
 * @return
 */
public CommandResponse setting(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiGroupSettingProto.ApiGroupSettingRequest request = ApiGroupSettingProto.ApiGroupSettingRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        String groupId = request.getGroupId();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNoneEmpty(siteUserId, groupId)) {
            UserGroupBean bean = UserGroupDao.getInstance().getUserGroupSetting(siteUserId, groupId);
            if (bean != null) {
                ApiGroupSettingProto.ApiGroupSettingResponse response = ApiGroupSettingProto.ApiGroupSettingResponse.newBuilder().setMessageMute(bean.isMute()).build();
                commandResponse.setParams(response.toByteArray());
                errCode = ErrorCode2.SUCCESS;
            } else {
                errCode = ErrorCode2.ERROR_DATABASE_EXECUTE;
            }
        } else {
            errCode = ErrorCode2.ERROR_PARAMETER;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ErrorCode2(com.akaxin.common.constant.ErrorCode2) UserGroupBean(com.akaxin.site.storage.bean.UserGroupBean) CommandResponse(com.akaxin.common.command.CommandResponse) ApiGroupSettingProto(com.akaxin.proto.site.ApiGroupSettingProto)

Example 12 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class ApiGroupService method addMember.

/**
 * 添加群成员,支持群成员拉取好友进群,因此无群主权限限制<br>
 * 无管理员权限限制 -> 添加群资料中是否允许添加成员
 *
 * @param command
 * @return
 */
public CommandResponse addMember(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiGroupAddMemberProto.ApiGroupAddMemberRequest request = ApiGroupAddMemberProto.ApiGroupAddMemberRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        String groupId = request.getGroupId();
        ProtocolStringList addMemberList = request.getUserListList();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(siteUserId) && StringUtils.isNotBlank(groupId) && addMemberList != null) {
            GroupProfileBean bean = UserGroupDao.getInstance().getGroupProfile(groupId);
            // 先校验权限
            if (checkAddMemberPermission(siteUserId, bean)) {
                int currentSize = UserGroupDao.getInstance().getGroupMemberCount(groupId);
                int maxSize = SiteConfig.getMaxGroupMemberSize();
                if (currentSize + addMemberList.size() <= maxSize) {
                    if (UserGroupDao.getInstance().addGroupMember(siteUserId, groupId, addMemberList)) {
                        errCode = ErrorCode2.SUCCESS;
                    }
                } else {
                    errCode = ErrorCode2.ERROR_GROUP_MAXMEMBERCOUNT;
                }
            } else {
                errCode = ErrorCode2.ERROR_GROUP_INVITE_CHAT_CLOSE;
            }
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ApiGroupAddMemberProto(com.akaxin.proto.site.ApiGroupAddMemberProto) ErrorCode2(com.akaxin.common.constant.ErrorCode2) CommandResponse(com.akaxin.common.command.CommandResponse) GroupProfileBean(com.akaxin.site.storage.bean.GroupProfileBean) ProtocolStringList(com.google.protobuf.ProtocolStringList)

Example 13 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class ApiGroupService method updateMute.

/**
 * 个人更新群设置信息
 *
 * @param command
 * @return
 */
public CommandResponse updateMute(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiGroupUpdateSettingProto.ApiGroupUpdateSettingRequest request = ApiGroupUpdateSettingProto.ApiGroupUpdateSettingRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        String groupId = request.getGroupId();
        boolean isMute = request.getMessageMute();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNoneEmpty(siteUserId, groupId)) {
            UserGroupBean bean = new UserGroupBean();
            bean.setSiteGroupId(groupId);
            bean.setMute(isMute);
            if (UserGroupDao.getInstance().updateUserGroupSetting(siteUserId, bean)) {
                errCode = ErrorCode2.SUCCESS;
            } else {
                errCode = ErrorCode2.ERROR_DATABASE_EXECUTE;
            }
        } else {
            errCode = ErrorCode2.ERROR_PARAMETER;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ErrorCode2(com.akaxin.common.constant.ErrorCode2) UserGroupBean(com.akaxin.site.storage.bean.UserGroupBean) CommandResponse(com.akaxin.common.command.CommandResponse) ApiGroupUpdateSettingProto(com.akaxin.proto.site.ApiGroupUpdateSettingProto)

Example 14 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class ApiGroupService method quit.

/**
 * 用户退群 <br>
 * 无权限限制
 *
 * @param command
 * @return
 */
public CommandResponse quit(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiGroupQuitProto.ApiGroupQuitRequest request = ApiGroupQuitProto.ApiGroupQuitRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        String groupId = request.getGroupId();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(siteUserId) && StringUtils.isNotBlank(groupId)) {
            if (UserGroupDao.getInstance().quitGroup(groupId, siteUserId)) {
                errCode = ErrorCode2.SUCCESS;
            }
        } else {
            errCode = ErrorCode2.ERROR_PARAMETER;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ErrorCode2(com.akaxin.common.constant.ErrorCode2) CommandResponse(com.akaxin.common.command.CommandResponse) ApiGroupQuitProto(com.akaxin.proto.site.ApiGroupQuitProto)

Example 15 with CommandResponse

use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.

the class ApiGroupService method create.

/**
 * 用户创建群,并添加初始群成员 <br>
 * 无权限限制
 *
 * @param command
 * @return
 */
public CommandResponse create(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiGroupCreateProto.ApiGroupCreateRequest request = ApiGroupCreateProto.ApiGroupCreateRequest.parseFrom(command.getParams());
        String groupName = request.getGroupName();
        ProtocolStringList groupMemberIds = request.getSiteUserIdsList();
        String createUserId = command.getSiteUserId();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotEmpty(createUserId) && groupMemberIds != null) {
            if (groupMemberIds.size() >= 3) {
                if (!groupMemberIds.contains(createUserId)) {
                    groupMemberIds.add(createUserId);
                }
                GroupProfileBean groupBean = UserGroupDao.getInstance().createGroup(createUserId, groupName, groupMemberIds);
                if (StringUtils.isNotEmpty(groupBean.getGroupId())) {
                    GroupProto.GroupProfile.Builder groupProfileBuilder = GroupProto.GroupProfile.newBuilder();
                    groupProfileBuilder.setId(String.valueOf(groupBean.getGroupId()));
                    groupProfileBuilder.setName(String.valueOf(groupBean.getGroupName()));
                    groupProfileBuilder.setIcon(String.valueOf(groupBean.getGroupPhoto()));
                    ApiGroupCreateProto.ApiGroupCreateResponse response = ApiGroupCreateProto.ApiGroupCreateResponse.newBuilder().setProfile(groupProfileBuilder.build()).build();
                    commandResponse.setParams(response.toByteArray());
                    errCode = ErrorCode2.SUCCESS;
                }
            } else {
                errCode = ErrorCode2.ERROR_GROUP_MEMBERLESS3;
            }
        } else {
            errCode = ErrorCode2.ERROR_PARAMETER;
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ErrorCode2(com.akaxin.common.constant.ErrorCode2) CommandResponse(com.akaxin.common.command.CommandResponse) ApiGroupCreateProto(com.akaxin.proto.site.ApiGroupCreateProto) GroupProfileBean(com.akaxin.site.storage.bean.GroupProfileBean) ProtocolStringList(com.google.protobuf.ProtocolStringList)

Aggregations

CommandResponse (com.akaxin.common.command.CommandResponse)82 ErrorCode2 (com.akaxin.common.constant.ErrorCode2)68 UserProto (com.akaxin.proto.core.UserProto)12 PluginBean (com.akaxin.site.storage.bean.PluginBean)7 ByteString (com.google.protobuf.ByteString)7 GroupProto (com.akaxin.proto.core.GroupProto)6 GroupProfileBean (com.akaxin.site.storage.bean.GroupProfileBean)6 SimpleUserBean (com.akaxin.site.storage.bean.SimpleUserBean)6 UserProfileBean (com.akaxin.site.storage.bean.UserProfileBean)6 UserDeviceBean (com.akaxin.site.storage.bean.UserDeviceBean)5 Command (com.akaxin.common.command.Command)4 DeviceProto (com.akaxin.proto.core.DeviceProto)4 ProtocolStringList (com.google.protobuf.ProtocolStringList)4 ConfigProto (com.akaxin.proto.core.ConfigProto)3 GroupMemberBean (com.akaxin.site.storage.bean.GroupMemberBean)3 UserGroupBean (com.akaxin.site.storage.bean.UserGroupBean)3 RedisCommand (com.akaxin.common.command.RedisCommand)2 ImStcPsnProto (com.akaxin.proto.client.ImStcPsnProto)2 CoreProto (com.akaxin.proto.core.CoreProto)2 FileProto (com.akaxin.proto.core.FileProto)2