示例#1
0
        public void Notify(NotifierData data)
        {
            var isCommunicationSettings = data.NotificationType.In(
                NotificationTypeEnum.CommentLikeAdded,
                NotificationTypeEnum.MonthlyMail) || //TODO: temporary for communication settings
                                          data.ActivityType.In(
                IntranetActivityTypeEnum.ContentPage,
                IntranetActivityTypeEnum.PagePromotion);

            var identity = new ActivityEventIdentity(isCommunicationSettings
                    ? CommunicationTypeEnum.CommunicationSettings
                    : data.ActivityType, data.NotificationType)
                           .AddNotifierIdentity(Type);

            var settings = _notificationSettingsService.Get <UiNotifierTemplate>(identity);

            if (settings == null || !settings.IsEnabled)
            {
                return;
            }
            var receivers = _intranetUserService.GetMany(data.ReceiverIds);

            var messages = receivers.Select(r => _notificationModelMapper.Map(data.Value, settings.Template, r));

            _notificationsService.Notify(messages);
        }
        public void Notify(NotifierData data)
        {
            var isCommunicationSettings = data.NotificationType.In(
                NotificationTypeEnum.CommentLikeAdded,
                NotificationTypeEnum.MonthlyMail); //TODO: temporary for communication settings

            var identity = new ActivityEventIdentity(isCommunicationSettings
                    ? CommunicationTypeEnum.CommunicationSettings
                    : data.ActivityType, data.NotificationType)
                           .AddNotifierIdentity(Type);

            var settings = _notificationSettingsService.Get <EmailNotifierTemplate>(identity);

            if (settings == null || !settings.IsEnabled)
            {
                return;
            }
            var receivers = _intranetUserService.GetMany(data.ReceiverIds).ToList();

            foreach (var receiverId in data.ReceiverIds)
            {
                var user = receivers.Find(receiver => receiver.Id == receiverId);

                var message = _notificationModelMapper.Map(data.Value, settings.Template, user);
                _mailService.Send(message);
            }
        }
        public async Task NotifyAsync(NotifierData data)
        {
            var identity = new ActivityEventIdentity(CommunicationTypeEnum.Member, data.NotificationType).AddNotifierIdentity(Type);
            var settings = await _notificationSettingsService.GetAsync <PopupNotifierTemplate>(identity);

            if (settings != null && settings.IsEnabled)
            {
                var receivers = await _intranetMemberService.GetManyAsync(data.ReceiverIds);

                var messages = receivers.Select(r => _notificationModelMapper.Map(data.Value, settings.Template, r));
                await _notificationsService.NotifyAsync(messages);
            }
        }
示例#4
0
        public void Notify(NotifierData data)
        {
            var identity = new ActivityEventIdentity(CommunicationTypeEnum.Member, data.NotificationType).AddNotifierIdentity(Type);
            var settings = _notificationSettingsService.Get <PopupNotifierTemplate>(identity);

            if (settings == null || !settings.IsEnabled)
            {
                return;
            }
            var receivers = _intranetUserService.GetMany(data.ReceiverIds);

            var messages = receivers.Select(r => _notificationModelMapper.Map(data.Value, settings.Template, r));

            _notificationsService.Notify(messages);
        }
示例#5
0
        public async Task SaveAsync <T>(NotifierSettingModel <T> settingModel) where T : INotifierTemplate
        {
            var identity = new ActivityEventIdentity(settingModel.ActivityType, settingModel.NotificationType)
                           .AddNotifierIdentity(settingModel.NotifierType);

            var(setting, isCreated) = await FindOrCreateSettingAsync <T>(identity);

            var updatedSetting = GetUpdatedSetting(setting, settingModel);

            if (isCreated)
            {
                await _repository.AddAsync(updatedSetting);
            }
            else
            {
                await _repository.UpdateAsync(updatedSetting);
            }
        }
示例#6
0
        public void Notify(NotifierData data)
        {
            var isCommunicationSettings = data.NotificationType.In(
                NotificationTypeEnum.CommentLikeAdded,
                NotificationTypeEnum.MonthlyMail,
                IntranetActivityTypeEnum.ContentPage);

            var identity = new ActivityEventIdentity(isCommunicationSettings
                    ? CommunicationTypeEnum.CommunicationSettings
                    : data.ActivityType, data.NotificationType)
                           .AddNotifierIdentity(Type);
            var settings = _notificationSettingsService.Get <UiNotifierTemplate>(identity);

            var desktopSettingsIdentity = new ActivityEventIdentity(settings.ActivityType, settings.NotificationType)
                                          .AddNotifierIdentity(NotifierTypeEnum.DesktopNotifier);
            var desktopSettings = _notificationSettingsService.Get <DesktopNotifierTemplate>(desktopSettingsIdentity);

            if (!settings.IsEnabled && !desktopSettings.IsEnabled)
            {
                return;
            }

            var receivers = _intranetMemberService.GetMany(data.ReceiverIds).ToList();

            var messages = receivers.Select(receiver =>
            {
                var uiMsg = _notificationModelMapper.Map(data.Value, settings.Template, receiver);
                if (desktopSettings.IsEnabled)
                {
                    var desktopMsg       = _desktopNotificationModelMapper.Map(data.Value, desktopSettings.Template, receiver);
                    uiMsg.DesktopTitle   = desktopMsg.Title;
                    uiMsg.DesktopMessage = desktopMsg.Message;
                    uiMsg.IsDesktopNotificationEnabled = true;
                    if (uiMsg.NotifierId.HasValue)
                    {
                        uiMsg.NotifierPhotoUrl = _intranetMemberService.Get(uiMsg.NotifierId.Value)?.Photo;
                    }
                }
                return(uiMsg);
            });

            _notificationsService.Notify(messages);
        }
        public void CreateAndSendMail()
        {
            var currentDate = DateTime.UtcNow;

            var allUsers     = _intranetMemberService.GetAll();
            var monthlyMails = allUsers
                               .Select(user =>
                                       user.Id.Pipe(GetUserActivitiesFilteredByUserTags)
                                       .Pipe(userActivities => TryGetMonthlyMail(userActivities, user)))
                               .ToList();

            var identity = new ActivityEventIdentity(
                CommunicationTypeEnum.CommunicationSettings,
                NotificationTypeEnum.MonthlyMail)
                           .AddNotifierIdentity(NotifierTypeEnum.EmailNotifier);

            var settings = _notificationSettingsService.Get <EmailNotifierTemplate>(identity);

            if (!settings.IsEnabled)
            {
                return;
            }

            foreach (var monthlyMail in monthlyMails)
            {
                monthlyMail.Do(some: mail =>
                {
                    var mailModel = GetMonthlyMailModel(mail.user, mail.monthlyMail, settings.Template);
                    try
                    {
                        _mailService.SendMailByTypeAndDay(
                            mailModel,
                            mail.user.Email,
                            currentDate,
                            NotificationTypeEnum.MonthlyMail);
                    }
                    catch (Exception ex)
                    {
                        _logger.Error <MonthlyEmailServiceBase>(ex);
                    }
                });
            }
        }
示例#8
0
        public async Task <NotifierSettingsModel> GetSettingsAsync(ActivityEventIdentity activityEventIdentity)
        {
            var emailNotifierSetting = await GetAsync <EmailNotifierTemplate>(activityEventIdentity.AddNotifierIdentity(NotifierTypeEnum.EmailNotifier));

            var uiNotifierSetting = await GetAsync <UiNotifierTemplate>(activityEventIdentity.AddNotifierIdentity(NotifierTypeEnum.UiNotifier));

            var popupNotifierSetting = await GetAsync <PopupNotifierTemplate>(activityEventIdentity.AddNotifierIdentity(NotifierTypeEnum.PopupNotifier));

            var desktopNotifierSetting = await GetAsync <DesktopNotifierTemplate>(activityEventIdentity.AddNotifierIdentity(NotifierTypeEnum.DesktopNotifier));

            var notifierSettings = new NotifierSettingsModel
            {
                EmailNotifierSetting   = emailNotifierSetting,
                UiNotifierSetting      = uiNotifierSetting,
                PopupNotifierSetting   = popupNotifierSetting,
                DesktopNotifierSetting = desktopNotifierSetting
            };

            return(notifierSettings);
        }
        public virtual NotifierSettingsModel Get(int activityType, int notificationType)
        {
            ActivityEventIdentity activityEventIdentity;
            NotifierSettingsModel settings;
            var actType = _activityTypeProvider[activityType];

            if (activityType == CommunicationTypeEnum.CommunicationSettings.ToInt())
            {
                actType = CommunicationTypeEnum.CommunicationSettings;
                activityEventIdentity = new ActivityEventIdentity(actType, _notificationTypeProvider[notificationType]);
                settings = _notificationSettingsService.GetSettings(activityEventIdentity);
                if (notificationType.In(NotificationTypeEnum.MonthlyMail.ToInt()))
                {
                    settings.UiNotifierSetting    = null;
                    settings.PopupNotifierSetting = null;
                }

                return(settings);
            }

            if (activityType == CommunicationTypeEnum.Member.ToInt())
            {
                actType = CommunicationTypeEnum.Member;
                activityEventIdentity = new ActivityEventIdentity(actType, _notificationTypeProvider[notificationType]);
                settings = _notificationSettingsService.GetSettings(activityEventIdentity);
                if (notificationType.In(NotificationTypeEnum.Welcome.ToInt()))
                {
                    settings.UiNotifierSetting    = null;
                    settings.EmailNotifierSetting = null;
                }

                return(settings);
            }

            activityEventIdentity = new ActivityEventIdentity(actType, _notificationTypeProvider[notificationType]);

            settings = _notificationSettingsService.GetSettings(activityEventIdentity);
            settings.PopupNotifierSetting = null;

            return(settings);
        }
示例#10
0
        private ActivityEventNotifierIdentity GetActivityEventNotifierIdentity(Enum notifierType, Enum activityType, Enum notificationType)
        {
            var activityEventIdentity = new ActivityEventIdentity(activityType, notificationType);

            return(new ActivityEventNotifierIdentity(activityEventIdentity, notifierType));
        }