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);
        }
Beispiel #2
0
 public Task <(bool found, Message message)> TryGetMessage(string conversationId, string messageId)
 {
     return(getMessageMetric.TrackTime(() => store.TryGetMessage(conversationId, messageId)));
 }
 public Task <(bool found, Message message)> TryGetMessage(string conversationId, string messageId)
 {
     return(faultTolerancePolicy.Execute(
                async() => await store.TryGetMessage(conversationId, messageId)
                ));
 }