コード例 #1
0
ファイル: ChatService.cs プロジェクト: jorik041/CrossChat
        public DevoiceResponse Devoice(ISession session, DevoiceRequest request)
        {
            var response = request.CreateResponse<DevoiceResponse>();

            User targetUser = null;

            using (var uow = UnitOfWorkFactory.Create())
            {
                targetUser = uow.UsersRepository.FirstMatching(UserSpecification.Id(request.TargetUserId));
                if (targetUser != null)
                {
                    try
                    {
                        if (request.Devoice)
                        {
                            targetUser.Devoice(session.User);
                        }
                        else
                        {
                            targetUser.BringVoiceBack(session.User);
                        }
                        response.Result = DevoiceResponseType.Success;
                        uow.Commit();
                    }
                    catch (ModeratorsRightsRequiredException)
                    {
                        response.Result = DevoiceResponseType.Failed;
                    }
                }
            }
            
            if (response.Result == DevoiceResponseType.Success && targetUser != null)
            {
                //send a notification to everybody that we've devoiced him\her
                _sessionManager.SendToEachChatSessions(
                    new DevoiceNotification
                    {
                        ActorName = session.User.Name, 
                        Reason = request.Reason,
                        Devoice = request.Devoice,
                        TargetId = session.User.Id,
                        TargetName = targetUser.Name
                    });
            }
            return response;
        }
コード例 #2
0
		public Task<DevoiceResponse> Devoice(DevoiceRequest request)
		{
			return ConnectionManager.SendRequestAndWaitResponse<DevoiceResponse>(request);
		}