Search in sources :

Example 51 with CommandResponse

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

the class ApiFriendService method updateMute.

/**
 * 对用户设置消息免打扰功能
 *
 * @param command
 * @return
 */
public CommandResponse updateMute(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiFriendUpdateMuteProto.ApiFriendUpdateMuteRequest request = ApiFriendUpdateMuteProto.ApiFriendUpdateMuteRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        String siteFriendId = request.getSiteFriendId();
        boolean messageMute = request.getMute();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNoneBlank(siteUserId, siteFriendId)) {
            if (UserFriendDao.getInstance().updateFriendMute(siteUserId, siteFriendId, messageMute)) {
                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) CommandResponse(com.akaxin.common.command.CommandResponse) ApiFriendUpdateMuteProto(com.akaxin.proto.site.ApiFriendUpdateMuteProto)

Example 52 with CommandResponse

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

the class ApiFriendService method apply.

/**
 * A请求添加B好友
 *
 * @param command
 * @return
 */
public CommandResponse apply(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiFriendApplyProto.ApiFriendApplyRequest request = ApiFriendApplyProto.ApiFriendApplyRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        String siteFriendId = request.getSiteFriendId();
        String applyReason = request.getApplyReason();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isEmpty(siteUserId)) {
            errCode = ErrorCode2.ERROR_PARAMETER;
        } else if (siteUserId.equals(siteFriendId)) {
            errCode = ErrorCode2.ERROR2_FRIEND_APPLYSELF;
        } else if (StringUtils.isNotBlank(siteUserId) && !siteUserId.equals(siteFriendId)) {
            UserProto.UserRelation userRelation = UserFriendDao.getInstance().getUserRelation(siteUserId, siteFriendId);
            if (UserProto.UserRelation.RELATION_FRIEND == userRelation) {
                errCode = ErrorCode2.ERROR2_FRIEND_IS;
            } else {
                int applyTimes = UserFriendDao.getInstance().getApplyCount(siteFriendId, siteUserId);
                if (applyTimes >= 5) {
                    errCode = ErrorCode2.ERROR2_FRIEND_APPLYCOUNT;
                } else {
                    if (UserFriendDao.getInstance().saveFriendApply(siteUserId, siteFriendId, applyReason)) {
                        errCode = ErrorCode2.SUCCESS;
                    }
                }
            }
        }
        if (ErrorCode2.SUCCESS.equals(errCode)) {
            logger.debug("api.friend.apply notice. to siteUserId={}", siteFriendId);
            new User2Notice().applyFriendNotice(siteFriendId);
        }
    } catch (Exception e) {
        errCode = ErrorCode2.ERROR_SYSTEMERROR;
        LogUtils.requestErrorLog(logger, command, e);
    }
    return commandResponse.setErrCode2(errCode);
}
Also used : ApiFriendApplyProto(com.akaxin.proto.site.ApiFriendApplyProto) ErrorCode2(com.akaxin.common.constant.ErrorCode2) UserProto(com.akaxin.proto.core.UserProto) User2Notice(com.akaxin.site.business.impl.notice.User2Notice) CommandResponse(com.akaxin.common.command.CommandResponse)

Example 53 with CommandResponse

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

the class ApiGroupService method mute.

public CommandResponse mute(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiGroupMuteProto.ApiGroupMuteRequest request = ApiGroupMuteProto.ApiGroupMuteRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        String siteGroupId = request.getSiteGroupId();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNoneEmpty(siteGroupId, siteUserId)) {
            UserGroupBean bean = UserGroupDao.getInstance().getUserGroupSetting(siteUserId, siteGroupId);
            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) ApiGroupMuteProto(com.akaxin.proto.site.ApiGroupMuteProto) CommandResponse(com.akaxin.common.command.CommandResponse) ApiGroupSettingProto(com.akaxin.proto.site.ApiGroupSettingProto)

Example 54 with CommandResponse

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

the class ApiGroupService method list.

/**
 * 获取用户群列表 <br>
 * 无权限限制
 *
 * @param command
 * @return
 */
public CommandResponse list(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiGroupListProto.ApiGroupListRequest request = ApiGroupListProto.ApiGroupListRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(siteUserId) && siteUserId.equals(siteUserId)) {
            List<SimpleGroupBean> groupBeanList = UserGroupDao.getInstance().getUserGroups(siteUserId);
            ApiGroupListProto.ApiGroupListResponse.Builder responseBuilder = ApiGroupListProto.ApiGroupListResponse.newBuilder();
            for (SimpleGroupBean groupBean : groupBeanList) {
                GroupProto.SimpleGroupProfile groupProfile = GroupProto.SimpleGroupProfile.newBuilder().setGroupId(String.valueOf(groupBean.getGroupId())).setGroupName(String.valueOf(groupBean.getGroupName())).setGroupIcon(String.valueOf(groupBean.getGroupPhoto())).build();
                responseBuilder.addList(groupProfile);
            }
            ApiGroupListProto.ApiGroupListResponse response = responseBuilder.build();
            commandResponse.setParams(response.toByteArray());
            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 : ApiGroupListProto(com.akaxin.proto.site.ApiGroupListProto) GroupProto(com.akaxin.proto.core.GroupProto) SimpleGroupBean(com.akaxin.site.storage.bean.SimpleGroupBean) CommandResponse(com.akaxin.common.command.CommandResponse) ErrorCode2(com.akaxin.common.constant.ErrorCode2)

Example 55 with CommandResponse

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

the class ApiGroupService method members.

/**
 * 获取群成员 <br>
 * 无权限控制
 *
 * @param command
 * @return
 */
public CommandResponse members(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiGroupMembersProto.ApiGroupMembersRequest request = ApiGroupMembersProto.ApiGroupMembersRequest.parseFrom(command.getParams());
        String groupId = request.getGroupId();
        int pageNum = 1;
        int pageSize = GroupConfig.GROUP_MAX_MEMBER_COUNT;
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(groupId)) {
            List<GroupMemberBean> memberList = UserGroupDao.getInstance().getGroupMemberList(groupId, pageNum, pageSize);
            ApiGroupMembersProto.ApiGroupMembersResponse.Builder responseBuilder = ApiGroupMembersProto.ApiGroupMembersResponse.newBuilder();
            for (GroupMemberBean member : memberList) {
                GroupProto.GroupMemberRole memberRole = GroupProto.GroupMemberRole.forNumber(member.getUserRole());
                UserProto.UserProfile memberProfile = UserProto.UserProfile.newBuilder().setSiteUserId(member.getUserId()).setUserName(String.valueOf(member.getUserName())).setUserPhoto(String.valueOf(member.getUserPhoto())).build();
                GroupProto.GroupMemberProfile groupMember = GroupProto.GroupMemberProfile.newBuilder().setRole(memberRole).setProfile(memberProfile).build();
                responseBuilder.addList(groupMember);
            }
            commandResponse.setParams(responseBuilder.build().toByteArray());
            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 : ApiGroupMembersProto(com.akaxin.proto.site.ApiGroupMembersProto) GroupProto(com.akaxin.proto.core.GroupProto) UserProto(com.akaxin.proto.core.UserProto) CommandResponse(com.akaxin.common.command.CommandResponse) GroupMemberBean(com.akaxin.site.storage.bean.GroupMemberBean) ErrorCode2(com.akaxin.common.constant.ErrorCode2)

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