public async Task <Message> PostMessage(string conversationId, SendMessageDtoV2 messageDto) { var matchingMessage = await conversationsStore.TryGetMessage(conversationId, messageDto.MessageId); if (matchingMessage.found) // if the message was found in storage { return(matchingMessage.message); } var currentTime = DateTime.Now; var message = new Message(messageDto.Text, messageDto.SenderUsername, currentTime); await conversationsStore.AddMessage(conversationId, messageDto.MessageId, message); logger.LogInformation(Events.ConversationMessageAdded, "Message {MessageId} has been added to conversation {conversationId}, sender: {senderUsername}", messageDto.MessageId, conversationId, messageDto.SenderUsername); var conversation = await conversationsStore.GetConversation(messageDto.SenderUsername, conversationId); var usersToNotify = conversation.Participants; var newMessagePayload = new NotificationPayload(currentTime, "MessageAdded", conversationId, usersToNotify); await notificationService.SendNotificationAsync(newMessagePayload); return(message); }
public async Task <IActionResult> PostMessage(string id, [FromBody] SendMessageDto messageDto) { try { var message = new Message(messageDto.Text, messageDto.SenderUsername, DateTime.UtcNow); await conversationsStore.AddMessage(id, message); logger.LogInformation(Events.ConversationMessageAdded, "Message has been added to conversation {conversationId}, sender: {senderUsername}", id, messageDto.SenderUsername); return(Ok(message)); } catch (StorageErrorException e) { logger.LogError(Events.StorageError, e, "Could not reach storage to add message, conversationId {conversationId}", id); return(StatusCode(503)); } catch (Exception e) { logger.LogError(Events.InternalError, e, "Failed to add message to conversation, conversationId: {conversationId}", id); return(StatusCode(500)); } }
public Task AddMessage(string conversationId, string messageId, Message message) { return(addMessageMetric.TrackTime(() => store.AddMessage(conversationId, messageId, message))); }
public Task AddMessage(string conversationId, string messageId, Message message) { return(faultTolerancePolicy.Execute( async() => await store.AddMessage(conversationId, messageId, message) )); }