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);
        }
Пример #2
0
 public Task <Conversation> GetConversation(string username, string conversationId)
 {
     return(getConversationMetric.TrackTime(() => store.GetConversation(username, conversationId)));
 }
 public Task <Conversation> GetConversation(string username, string conversationId)
 {
     return(faultTolerancePolicy.Execute(
                async() => await store.GetConversation(username, conversationId)
                ));
 }