public async Task PostMessage(string conversationIdentifier, string schema, string text) { var user = await GetCurrentUser(); currentSchema.Name = schema; Console.WriteLine($"Message posted by {user.Name}: {text}"); var conversationId = long.Parse(conversationIdentifier); var messageId = await conversations.AddMessage(conversationId, text, user.Id); await SendMessage(messageId, user.Id, conversationIdentifier); }
public bool SendMessage(int friendId, MessageDTO msg) { if (msg == null) { throw new ArgumentException("Message is null"); } if (string.IsNullOrWhiteSpace(msg.Message)) { throw new ArgumentException("Message is empty"); } var conv = _convRepository.GetConversationBetween(msg.ProfileId, friendId); if (conv == null) { if (!_profileService.ProfileExists(friendId) || !_profileService.AreFriends(msg.ProfileId, friendId)) { throw new ArgumentException("Cannot send message to this person"); } conv = new Conversation { Member1Id = msg.ProfileId, Member2Id = friendId, Messages = new List <Message>() }; conv = _convRepository.AddConversaion(conv); if (conv == null) { return(false); } } Message message = new Message { ProfileId = msg.ProfileId, Body = msg.Message, Date = DateTime.UtcNow, ConversationId = conv.Id, }; var dbMessage = _convRepository.AddMessage(message); _notificationService.SendMessageNotification(friendId, dbMessage.Id); return(true); }