private void FillFields(ConversationDto dto, IList <Message> messages) { if (dto == null) { return; } if (messages != null && messages.Any()) { messages = messages.OrderByDescending(t => t.Id).ToList(); dto.LastMessage = messages.First().Content; dto.OriginalLink = messages.Last().OriginalLink; var lastMessageSendByCustomer = messages.FirstOrDefault(t => t.Sender.IsCustomer); if (lastMessageSendByCustomer != null) { dto.CustomerId = lastMessageSendByCustomer.SenderId; dto.CustomerName = lastMessageSendByCustomer.Sender.ScreenNameOrNormalName; dto.CustomerAvatar = lastMessageSendByCustomer.Sender.Avatar; } var lastMessageByIntegrationAccount = messages.FirstOrDefault(t => t.IntegrationAccount != null); if (lastMessageByIntegrationAccount != null) { dto.LastIntegrationAccountId = lastMessageByIntegrationAccount.IntegrationAccountId; dto.LastIntegrationAccountName = lastMessageByIntegrationAccount.IntegrationAccount.ScreenNameOrNormalName; dto.LastIntegrationAccountAvatar = lastMessageByIntegrationAccount.IntegrationAccount.Avatar; } } }
public async Task <IActionResult> Join(long id = 1) { var user = await this.GetCurrentUser(); System.Console.WriteLine($"Fetching presentation {id}"); var presentation = await retrievePresentationToViewQuery.Fetch(id); long conversationId = presentation.ConversationId; System.Console.WriteLine($"Fetching conversation {conversationId}"); var conversation = await conversations.GetConversation(conversationId); var conversationDto = new ConversationDto { Id = conversation.Id, Topic = conversation.Topic, CreatedAt = conversation.CreatedAt, CreatedBy = conversation.CreatedBy.Name, CurrentUserIsMod = await CurrentUserIsMod(user, conversationId), Schema = currentSchema.Name }; var viewModel = new DeckDto { Presentation = presentation, Conversation = conversationDto }; return(View(viewModel)); }
public bool CreateConversation(ConversationDto conversation) { string prepareQuery = $@"insert into {DalCostants.TABLE_SCHEMA}.{DalCostants.CONVERSATION_TABLE} (TYPE,USERID,MESSAGE,CONVERSDATETIME) values('{conversation.TYPE}', {conversation.USERID}, '{conversation.MESSAGE}', '{conversation.CONVERSDATETIME}')"; return(_dataManager.InsertData(prepareQuery)); }
public async Task <ConversationDto> GetAsync(int tripId, int userId) { if (tripId <= 0) { throw new ArgumentOutOfRangeException(nameof(tripId)); } if (userId <= 0) { throw new ArgumentOutOfRangeException(nameof(userId)); } var conversation = await _conversationStorage.GetAsync(tripId, userId); if (conversation == null) { return(null); } var conversationDto = new ConversationDto { Id = conversation.Id, TripId = conversation.TripId, UserId = conversation.UserId, CreatedDate = conversation.CreatedDate, IsDeleted = conversation.IsDeleted }; return(conversationDto); }
public async Task Enqueue(ConversationDto conversation, MoveResultDtoBase message) { if (message is not null && message is not NoReplyDto) { await GetInstance(conversation.HostPhoneNumber).Enqueue(conversation, message); } }
private void FillFields(ConversationDto conversationDto) { var messages = _messageService .FindAllByConversationId(conversationDto.Id).ToList(); FillFields(conversationDto, messages); }
public async Task <ServiceResult <int> > CreateNewConversation(ConversationDto conversationDto) { if (string.IsNullOrWhiteSpace(conversationDto.Title)) { return(new ServiceResult <int>(false, "Conversation title cannot be empty. Please specify the title")); } if (conversationDto.Participants.Count < 2) { return(new ServiceResult <int>(false, "Conversation must have at least 2 participants")); } var participatingUsers = conversationDto.Participants.Select(u => new ConversationParticipant() { ParticipantId = u.Id }).ToList(); var conversation = new Conversation() { Title = conversationDto.Title, Participants = new Collection <ConversationParticipant>(participatingUsers) }; await _unitOfWork.ConversationRepository.CreateNewConversationAsync(conversation); await _unitOfWork.CompleteTransactionAsync(); int id = conversation.Id; return(new ServiceResult <int>(true, "Conversation created successfully", id)); }
public async Task <IActionResult> Post([FromBody] ConversationDto conversationDto) { //Get header token if (Request.Headers.TryGetValue("Authorization", out StringValues headerValues)) { var token = _customEncoder.DecodeBearerAuth(headerValues.First()); if (token != null) { //Verify if the token exist and is not expire if (await _authenticationService.CheckIfTokenIsValidAsync(token)) { var conversation = await _conversationService.AddConversationAsync(conversationDto); if (conversation == null) { return(StatusCode(404, "Unable to create conversation.")); } return(Ok(conversation)); } return(StatusCode(401, "Invalid Token.")); } return(StatusCode(401, "Invalid Authorization.")); } return(StatusCode(401, "Invalid Authorization.")); }
public async Task UpdateAsync(ConversationDto entity) { var conversation = await conversationRepo.FindByIdAsync(entity.ConversationId); conversation.Message = entity.Message; conversation.Date = entity.Date; await conversationRepo.UpdateAsync(conversation); }
public async Task Post(string message) { ConversationDto conDto = new ConversationDto() { Message = message, Date = DateTime.Now }; await conversationService.CreateAsync(conDto); }
public static ConversationModel ToModel(this ConversationDto dto) { return(new ConversationModel { Id = dto.Id, Title = dto.Title, LastMessage = dto.LastMessage }); }
public async Task <ConversationDto> Put(int id, [FromBody] ConversationDto conversationDto) { await Task.Delay(1); var conversation = new Conversation(conversationDto.Name, conversationDto.Language); var sentence = SentenceBuilder.BuildSentence(conversationDto.SentenceId, conversationDto.DisplayText); var nextSentence = sentence.GetNextSentence(conversationDto.UserResponse); return(conversation.GetConversationDto(nextSentence)); }
public async Task UpdateConversation(ConversationDto conversation) { var result = await _conversationService.UpdateConversationAsync(conversation.Id, conversation); if (result.Success) { await Clients.Group(conversation.Id.ToString()).SendAsync("conversationUpdated", conversation); return; } await Clients.Caller.SendAsync("conversationUpdateError", result.FailCause); }
public async Task Enqueue(ConversationDto conversation, ushort conversationMessageId) { var queue = await StateManager.GetOrAddAsync <IReliableQueue <MessageModel> >("MoveQueue"); using var tx = StateManager.CreateTransaction(); await queue.EnqueueAsync(tx, new MessageModel { Conversation = conversation, ConversationMessageId = conversationMessageId }); await tx.CommitAsync(); }
public async Task Enqueue(ConversationDto conversation, MessageDto message) { var queue = await StateManager.GetOrAddAsync <IReliableQueue <SmsModel> >("SMSQueue"); using var tx = StateManager.CreateTransaction(); await queue.EnqueueAsync(tx, new SmsModel { Conversation = conversation, Message = message }); await tx.CommitAsync(); }
public ActionResult Conversation(ConversationDto conversationDto) { if (ModelState.IsValid) { var currentUser = (User)Session["CurrentUser"]; this.conversationService.AddMessageToConversation(conversationDto.NewMessage, currentUser.Identity, conversationDto.ConversationId); TempData["message"] = "Message sent successfully"; return(RedirectToAction("Conversation", new { conversationId = conversationDto.ConversationId })); } return(Conversation(conversationDto)); }
public ConversationDto CreateConversation(ConversationDto conv) { var id = Guid.Parse(conv.Id); var cv = new Conversation(); cv.Id = id; cv.PartyId1 = Convert.ToInt32(conv.partyId1); cv.PartyId2 = Convert.ToInt32(conv.partyId2); _context.Conversations.Add(cv); _context.SaveChanges(); return(conv); }
public async Task ClearConversation(ConversationDto conversation) { var user = (Identity.UserIdentity)Context.User.Identity; var result = await _conversationService.ClearConversationAsync(user.UserId, conversation.Id); if (result.Success) { await Clients.Group(conversation.Id.ToString()).SendAsync("conversationCleared", conversation); return; } await Clients.Caller.SendAsync("conversationClearError", result.FailCause); }
public ConversationDto GetConversation(string conversationId) { var id = Guid.Parse(conversationId); var cv = _context.Conversations.Where(x => x.Id == id).FirstOrDefault(); ConversationDto conversation = new ConversationDto(); conversation.Id = cv.Id.ToString(); conversation.partyId1 = cv.PartyId1; conversation.partyId2 = cv.PartyId2; conversation.messages = GetMessagesForConversation(conversationId); return(conversation); }
public Task <IConversation> GetConversation(ConversationDto conversation) { var phoneUtil = PhoneNumberUtil.GetInstance(); var host = phoneUtil.Format(conversation.HostPhoneNumber, PhoneNumberFormat.INTERNATIONAL); var recipients = conversation.PhoneNumbers .OrderBy(p => p.CountryCode) .ThenBy(p => p.NationalNumber) .Select(p => phoneUtil.Format(p, PhoneNumberFormat.INTERNATIONAL)); var actor = ActorProxy.Create <IConversation>( new ActorId($"conversation/{host}/{string.Join("/", recipients)}")); return(Task.FromResult(actor)); }
public IHttpActionResult PostConversation(ConversationDto conversationDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Conversation conversation = Mapper.Map <ConversationDto, Conversation>(conversationDto); db.Conversations.Add(conversation); db.SaveChanges(); Mapper.Map(conversation, conversationDto); return(CreatedAtRoute("DefaultApi", new { id = conversationDto.Id }, conversationDto)); }
public async Task <IActionResult> CreateConversation(ConversationDto conversation) { conversation.Participants.Add(new UserDto() { Id = User.GetUserId() }); var result = await _conversationService.CreateNewConversation(conversation); if (result.Success) { return(Ok(new { conversationId = result.Data })); } else { return(BadRequest(result.Message)); } }
public async Task <IConversation> GetConversation(ConversationDto conversation) { var phoneUtil = PhoneNumberUtil.GetInstance(); using var tx = StateManager.CreateTransaction(); var conversations = await StateManager.GetOrAddAsync <IReliableDictionary <string, ActorId> >(tx, phoneUtil.Format(conversation.HostPhoneNumber, PhoneNumberFormat.E164)); var actorId = string.Join("/", conversation.PhoneNumbers .Select(p => phoneUtil.Format(p, PhoneNumberFormat.E164)) .OrderBy(p => p)); var conversationId = await conversations.GetOrAddAsync(tx, actorId, key => new ActorId(key)); await tx.CommitAsync(); return(ActorProxy.Create <IConversation>(conversationId)); }
public async Task <ConversationDto> GetChatAsync(string userLogin, string contactLogin) { var user = await _userRepository.GetAsync(userLogin); var contact = await _userRepository.GetAsync(contactLogin); if (user == null || contact == null) { throw new System.Exception("User not found."); } var chat = await _chatRepository.GetSingleChat(user.Id, contact.Id); var chatDto = new ConversationDto() { Contact = _mapper.Map <ContactDto>(contact), Messages = _mapper.Map <List <MessageDto> >(chat.Messages) }; return(chatDto); }
public async Task <List <ConversationDto> > GetAllChatsAsync(string userLogin) { var user = await _userRepository.GetAsync(userLogin); var chats = await _chatRepository.GetAllChats(user.Id); var chatsDto = new List <ConversationDto>(); foreach (var chat in chats) { var contact = chat.Participant1.Login == userLogin ? chat.Participant2 : chat.Participant1; var chatDto = new ConversationDto() { Contact = _mapper.Map <ContactDto>(contact), Messages = _mapper.Map <List <MessageDto> >(chat.Messages) }; chatsDto.Add(chatDto); } return(chatsDto); }
public ConversationDto GetConversationForContact(int currentUserId, int contactId) { var cv = _context.Conversations.Where(x => (x.PartyId1 == contactId && x.PartyId2 == currentUserId) || (x.PartyId1 == currentUserId && x.PartyId2 == contactId) ).FirstOrDefault(); ConversationDto dto = null; if (cv != null) { dto = new ConversationDto(); dto.Id = cv.Id.ToString(); dto.messages = GetMessagesForConversation(cv.Id.ToString()); dto.partyId1 = cv.PartyId1; dto.partyId2 = cv.PartyId2; } return(dto); }
public async Task <JsonResult> ConversationData(Guid id) { var userId = this.User.Identity.GetUserIdGuid().Value; var conversation = await _conversationService .QueryConversation() .Include(c => c.Messages) .Include(c => c.Users) .SingleAsync(c => c.Id == id); var interlocutorId = conversation.Users.First(u => u.Id != userId).Id; ConversationDto conversationDto = new ConversationDto { ConversationId = conversation.Id, Title = conversation.Users.Single(u => u.Id != userId).Name, Messages = conversation.Messages.OrderByDescending(m => m.SentOn) .Take(20) .Select(m => new MessageDto { SentByUserId = m.SentByUserId, SentOn = m.SentOn, Text = m.Text, IsSentByUser = m.SentByUserId == userId }) .OrderBy(m => m.SentOn) .ToList(), Users = conversation.Users.Select(u => new UserViewDto { Gender = u.Gender, Name = u.Name, ProfilePhoto = PhotoUrlService.GetPhotoDto(u.ProfilePhotoUrl), UserId = u.Id }).ToList(), IsInterlocutorOnline = _onlineUserService.GetOnlineUsers() .Any(u => u.Id == interlocutorId), InterlocutorId = interlocutorId }; return(Json(conversationDto, JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> GetConversationById([FromRoute] Guid id) { var conversation = await _context.Conversations.FirstOrDefaultAsync(x => x.Id == id); if (conversation == null) { return(NotFound()); } var conversationDto = new ConversationDto() { Id = conversation.Id, Author = await _context.Users .Where(x => x.Id == conversation.AuthorId) .Select(x => x.UserName).FirstOrDefaultAsync(), Content = conversation.Content, CreatedDate = conversation.CreatedDate }; return(Ok(conversationDto)); }
public ConversationDto GetConversationDto(int conversationId) { var conversation = this.conversationRepository.GetConversation(conversationId); var conversationDto = new ConversationDto { ConversationId = conversation.ConversationID, ConversationTitle = conversation.Title, Messages = new List <MessageDto>() }; var messages = this.messageRepository.GetConversationMessagesWithUsers(conversationId); conversationDto.Messages.AddRange(messages.Select(m => new MessageDto { MessageId = m.MessageID, DisplayedSenderName = m.User.FirstName + " " + m.User.LastName, MessageContent = m.MessageContent, SenderId = m.User.Identity })); return(conversationDto); }
public async Task CreateConversation(ConversationDto conversationDto) { var user = (Identity.UserIdentity)Context.User.Identity; var result = await _conversationService.CreateConversationAsync(user.UserId, conversationDto.Users.Select(u => u.Id), conversationDto.Name); if (result.Success) { var conversationUsers = result.Entity.Users; foreach (var cu in conversationUsers) { var connections = _connectionMapping.GetConnections(cu.Id); var tasks = new List <Task>(); foreach (var connection in connections) { tasks.Add(Clients.Client(connection).SendAsync("conversationCreated", result.Entity)); } Task.WaitAll(tasks.ToArray()); } return; } await Clients.Caller.SendAsync("conversationCreationError", result.FailCause); }