Exemple #1
0
        public async Task SendNotificationAsync(string fromUserId, string toUserId, string notificationType)
        {
            int notificationId = _notificationsRepository.SaveUserNotification(notificationType, fromUserId, toUserId);
            var connectedId    = _userRepository.GetUserConnectionId(toUserId);

            if (connectedId != null && connectedId.Count > 0)
            {
                // var userInfo = CommonFunctions.GetUserModel(fromUserID);
                int notificationCount = _notificationsRepository.GetUseNNotificationCount(toUserId);
                var notification      = new DtoNotification {
                    NotificationType  = notificationType,
                    NotificationId    = notificationId,
                    NotificationCount = notificationCount,
                    UserId            = fromUserId
                };
                await Clients.Clients(connectedId).SendAsync("ReceiveNotification", notification);
            }
        }
Exemple #2
0
        public void SendNotification(string fromUserId, string toUserId, string notificationType)
        {
            int notificationId = _notificationsRepository.SaveUserNotification(notificationType, fromUserId, toUserId);
            var connectedId    = _userRepository.GetUserConnectionId(toUserId);
            var user           = _userRepository.GetUserById(fromUserId);

            if (connectedId != null && connectedId.Count > 0)
            {
                int notificationCount = _notificationsRepository.GetUseNNotificationCount(toUserId);

                DtoNotification notificationViewModel = new DtoNotification();
                notificationViewModel.NotificationType  = notificationType;
                notificationViewModel.NotificationId    = notificationId;
                notificationViewModel.NotificationCount = notificationCount;
                notificationViewModel.UserId            = fromUserId;
                // notificationViewModel.Name = user.FirstName + " " + user.LastName;
                _hubContext.Clients.Clients(connectedId).SendAsync("SendNotification", notificationViewModel);
            }
        }
Exemple #3
0
        public IActionResult Update(DtoNotification dtoNotification)
        {
            var userEmail      = HttpContext.User.RetrieveEmailFromPrincipal();
            var userId         = _userRepository.GetUserId(userEmail);
            int notificationId = _userRepository.ResponseToFriendRequest(dtoNotification.UserId, dtoNotification.RequestResponse, userId);

            if (notificationId > 0)
            {
                var connectionId = _userRepository.GetUserConnectionId(userId);
                if (connectionId != null && connectionId.Count > 0)
                {
                    _hubContext.Clients.Clients(connectionId).SendAsync("RemoveNotification", notificationId);
                }
            }
            if (dtoNotification.RequestResponse == "Accepted")
            {
                SendNotification(userId, dtoNotification.UserId, "FriendRequestAccepted");
                List <string> connectionIds = _userRepository.GetUserConnectionId(new string[] { userId, dtoNotification.UserId });
            }
            return(Ok());
        }
        private void ProcessMessage(DtoNotification msg)
        {
            var person = msg.Person;

            //email
            if (!_dictEmailActors.TryGetValue(person.Email, out var emailActor))
            {
                emailActor = Context.ActorOf(_emailProps, $"EmailSender_{msg.Id}");

                _dictEmailActors.TryAdd(person.Email, emailActor);

                Context.Watch(emailActor);
            }

            emailActor.Tell(new DtoEmailMessage
            {
                Id    = msg.Id,
                Email = person.Email,
                Text  = $"Email for {person.LastName} {person.FirstName}: {msg.Text}"
            }, Self);

            //sms
            if (!_dictSmsActor.TryGetValue(person.Phone, out var smsActor))
            {
                smsActor = Context.ActorOf(_smsProps, $"SmsSender_{msg.Id}");

                _dictSmsActor.TryAdd(person.Phone, smsActor);

                Context.Watch(emailActor);
            }

            smsActor.Tell(new DtoSmsMessage
            {
                Id    = msg.Id,
                Phone = person.Phone,
                Text  = $"Sms for {person.LastName} {person.FirstName}: {msg.Text}"
            });
        }