Exemplo n.º 1
0
        public async Task <ChatModel> GetChatWithUserAsync(Guid myId, Guid anotherUserId)
        {
            var chat = await _chatRepository.GetPrivateChatAsync(myId, anotherUserId);

            if (chat == null)
            {
                var anotherUser = await _accountService.GetUserByIdAsync(anotherUserId);

                var chatEntity = _mapper.Map <ChatModel>(new List <Guid>()
                {
                    myId, anotherUser.Id
                });
                chat = await _chatRepository.CreateChatAsync(_mapper.Map <Chat>(chatEntity));
            }

            //Delete this, when ef core fix stupid bug
            chat = await _chatRepository.GetPrivateChatAsync(myId, anotherUserId);

            var chatModel = _mapper.Map <ChatModel>(chat);

            _chatHelper.GetChatDefinition(chatModel, myId);
            return(chatModel);
        }
Exemplo n.º 2
0
        public async Task <Guid> CreateChatAsync(CreateChatRequest request, Guid userId)
        {
            var chat = await _repository.CreateChatAsync(request.Name);

            foreach (var memberId in request.MemberIds)
            {
                await _repository.CreateChatMemberAsync(chat.Id, memberId);
            }

            // Add creator as a member
            await _repository.CreateChatMemberAsync(chat.Id, userId, ChatMemberStatus.Active, request.CreatorPublicKey);

            return(chat.Id);
        }
Exemplo n.º 3
0
        public override async Task <Reply> CreateChat(ChatCreate request, ServerCallContext context)
        {
            if (request?.Chat is null)
            {
                _logger.LogError("Request is null");
                return(new Reply
                {
                    Response = Response.Error
                });
            }

            _logger.LogInformation("Starting creating Chat");

            await _chatRepository.CreateChatAsync(request.Chat);

            _logger.LogInformation("Chat created successfully ");

            return(new Reply
            {
                Response = Response.Ok
            });
        }