public ApiResult <AddUserGroupResponse> Add(AddUserGroupRequest request)
        {
            var response = new AddUserGroupResponse();
            var entity   = _userGroupService.FindUserGroup(request.ImUserId.ToGuid(), request.GroupId.ToGuid());

            if (entity == null)
            {
                //新增
                var guid = _userGroupService.SaveUserGroup(request.GroupId.ToGuid(), request.ImUserId.ToGuid(), request.NickName, request.RoleType.ToInt32());
                if (!guid.IsNullGuid())
                {
                    //新增用户通知
                    var userinfo   = _imUserInfoService.Find(request.ImUserId.ToGuid());
                    var headimg    = (userinfo == null ? "" : userinfo.UserHeadimg);
                    var msgcontent = NewsTypeHelper.ToAddUser(request.ImUserId.ToString(), "0", request.NickName, headimg);
                    var channelId  = _groupInfoService.GetChannelId(request.GroupId.ToGuid());
                    RedisHelper.Publish(channelId, msgcontent);
                }
            }
            else
            {
                //修改
                if (entity.NickName != request.NickName)
                {
                    _userGroupService.SaveUserGroup(request.GroupId.ToGuid(), request.ImUserId.ToGuid(), request.NickName, request.RoleType.ToInt32());
                }
            }

            return(Success(response));
        }
Exemple #2
0
        public ApiResult <SendMessageResponse> Send(SendGroupMessageRequest request)
        {
            var response = new SendMessageResponse();

            if (request == null)
            {
                return(Error <SendMessageResponse>("1", "参数无能为空"));
            }

            if (request.GroupId.IsNullOrEmpty())
            {
                return(Error <SendMessageResponse>("2", "组标识不能为空"));
            }

            var channelId = _groupInfoService.GetChannelId(request.GroupId.ToGuid());

            if (channelId.IsNotNullOrEmpty())
            {
                var lasttime = DateTime.Now.ToUnix();
                var data     = NewsTypeHelper.ToChat(request.ImUserId, request.SourceType, request.MsgContent, lasttime);
                RedisHelper.Publish(channelId, data);
                _channelMessageService.Add(channelId, request.ImUserId, request.MsgType, request.MsgContent, request.DeviceType, request.SourceType, RequestHelper.Ip, "", lasttime);
            }
            return(Success(response));
        }