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);
            }
        }
示例#2
0
        public async Task NotifyAsync(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 = await _notificationSettingsService.GetAsync <UiNotifierTemplate>(identity);

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

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

            var receivers = (await _intranetMemberService.GetManyAsync(data.ReceiverIds));

            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;
                }
                return(uiMsg);
            });
            await _notificationsService.NotifyAsync(messages);
        }