Пример #1
0
        public async Task SendMessage(MessageViewModel message)
        {
            var sender = AllConnectedParticipants.Find(x => x.Participant.Id == message.FromId);

            if (sender != null)
            {
                var destinataryProfile = await _profileRepository.GetDestinataryProfileByAuth0Id(message.ToId);

                var currentUserProfileId = await _profileRepository.GetCurrentProfileIdByAuth0Id(Context.UserIdentifier);

                // If currentUser is on the destinataryProfile's ChatMemberslist AND is blocked then do not go any further.
                if (!destinataryProfile.ChatMemberslist.Any(m => m.ProfileId == currentUserProfileId && m.Blocked == true))
                {
                    var encryptedMessage = _cryptography.Encrypt(message.Message);
                    message.Message = encryptedMessage;

                    await _profileRepository.SaveMessage(message);

                    await _profileRepository.NotifyNewChatMember(Context.UserIdentifier, destinataryProfile.Auth0Id);

                    await Clients.Group(message.ToId).SendAsync("messageReceived", sender.Participant, message);
                }
            }
        }