public FollowedArtistNotifier(IEntryLinkFactory entryLinkFactory, IUserMessageMailer mailer,
                               IEnumTranslations enumTranslations, IEntrySubTypeNameFactory entrySubTypeNameFactory)
 {
     this.entryLinkFactory        = entryLinkFactory;
     this.mailer                  = mailer;
     this.enumTranslations        = enumTranslations;
     this.entrySubTypeNameFactory = entrySubTypeNameFactory;
 }
Esempio n. 2
0
 public AlbumQueries(IAlbumRepository repository, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory,
                     IEntryThumbPersister imagePersister, IUserMessageMailer mailer)
     : base(repository, permissionContext)
 {
     this.entryLinkFactory = entryLinkFactory;
     this.imagePersister   = imagePersister;
     this.mailer           = mailer;
 }
Esempio n. 3
0
 public SongQueries(ISongRepository repository, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory, IPVParser pvParser, IUserMessageMailer mailer,
                    ILanguageDetector languageDetector)
     : base(repository, permissionContext)
 {
     this.entryLinkFactory = entryLinkFactory;
     this.pvParser         = pvParser;
     this.mailer           = mailer;
     this.languageDetector = languageDetector;
 }
Esempio n. 4
0
 public EventQueries(IEventRepository eventRepository, IEntryLinkFactory entryLinkFactory, IUserPermissionContext permissionContext,
                     IEntryThumbPersister imagePersister, IUserIconFactory userIconFactory, IEnumTranslations enumTranslations, IUserMessageMailer mailer)
     : base(eventRepository, permissionContext)
 {
     this.entryLinkFactory = entryLinkFactory;
     this.imagePersister   = imagePersister;
     this.userIconFactory  = userIconFactory;
     this.enumTranslations = enumTranslations;
     this.mailer           = mailer;
 }
Esempio n. 5
0
 public UserService(
     IUserRepository sessionFactory,
     IUserPermissionContext permissionContext,
     IEntryLinkFactory entryLinkFactory,
     IUserMessageMailer userMessageMailer,
     IUserIconFactory userIconFactory)
     : base(sessionFactory, permissionContext)
 {
     EntryLinkFactory = entryLinkFactory;
     _userIconFactory = userIconFactory;
 }
Esempio n. 6
0
 public AlbumQueries(IAlbumRepository repository, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory,
                     IEntryThumbPersister imagePersister, IEntryPictureFilePersister pictureFilePersister, IUserMessageMailer mailer,
                     IUserIconFactory userIconFactory, IEnumTranslations enumTranslations)
     : base(repository, permissionContext)
 {
     this.entryLinkFactory     = entryLinkFactory;
     this.imagePersister       = imagePersister;
     this.pictureFilePersister = pictureFilePersister;
     this.mailer           = mailer;
     this.userIconFactory  = userIconFactory;
     this.enumTranslations = enumTranslations;
 }
Esempio n. 7
0
 public SongQueries(ISongRepository repository, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory, IPVParser pvParser, IUserMessageMailer mailer,
                    ILanguageDetector languageDetector, IUserIconFactory userIconFactory, IEnumTranslations enumTranslations, ObjectCache cache, VdbConfigManager config)
     : base(repository, permissionContext)
 {
     this.entryLinkFactory = entryLinkFactory;
     this.pvParser         = pvParser;
     this.mailer           = mailer;
     this.languageDetector = languageDetector;
     this.userIconFactory  = userIconFactory;
     this.enumTranslations = enumTranslations;
     this.cache            = cache;
     this.config           = config;
 }
Esempio n. 8
0
 public EventQueries(IEventRepository eventRepository, IEntryLinkFactory entryLinkFactory, IUserPermissionContext permissionContext,
                     IEntryThumbPersister imagePersister, IUserIconFactory userIconFactory, IEnumTranslations enumTranslations,
                     IUserMessageMailer mailer, IFollowedArtistNotifier followedArtistNotifier, IAggregatedEntryImageUrlFactory imageUrlFactory)
     : base(eventRepository, permissionContext)
 {
     this.entryLinkFactory       = entryLinkFactory;
     this.imagePersister         = imagePersister;
     this.userIconFactory        = userIconFactory;
     this.enumTranslations       = enumTranslations;
     this.mailer                 = mailer;
     this.followedArtistNotifier = followedArtistNotifier;
     this.imageUrlFactory        = imageUrlFactory;
 }
Esempio n. 9
0
        public UserQueries(IUserRepository repository, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory, IStopForumSpamClient sfsClient,
                           IUserMessageMailer mailer, IUserIconFactory userIconFactory, ObjectCache cache)
            : base(repository, permissionContext)
        {
            ParamIs.NotNull(() => repository);
            ParamIs.NotNull(() => permissionContext);
            ParamIs.NotNull(() => entryLinkFactory);
            ParamIs.NotNull(() => sfsClient);
            ParamIs.NotNull(() => mailer);

            this.entryLinkFactory = entryLinkFactory;
            this.sfsClient        = sfsClient;
            this.mailer           = mailer;
            this.userIconFactory  = userIconFactory;
            this.cache            = cache;
        }
Esempio n. 10
0
 public AlbumQueries(IAlbumRepository repository, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory,
                     IEntryThumbPersister imagePersister, IEntryPictureFilePersister pictureFilePersister, IUserMessageMailer mailer,
                     IUserIconFactory userIconFactory, IEnumTranslations enumTranslations, IPVParser pvParser,
                     IFollowedArtistNotifier followedArtistNotifier, IAggregatedEntryImageUrlFactory entryThumbPersister, ObjectCache cache)
     : base(repository, permissionContext)
 {
     this.entryLinkFactory     = entryLinkFactory;
     this.imagePersister       = imagePersister;
     this.pictureFilePersister = pictureFilePersister;
     this.mailer                 = mailer;
     this.userIconFactory        = userIconFactory;
     this.enumTranslations       = enumTranslations;
     this.pvParser               = pvParser;
     this.followedArtistNotifier = followedArtistNotifier;
     this.imageUrlFactory        = entryThumbPersister;
     this.cache = cache;
 }
Esempio n. 11
0
 public EventQueries(
     IEventRepository eventRepository,
     IEntryLinkFactory entryLinkFactory,
     IUserPermissionContext permissionContext,
     IEntryThumbPersister imagePersister,
     IUserIconFactory userIconFactory,
     IEnumTranslations enumTranslations,
     IUserMessageMailer mailer,
     IFollowedArtistNotifier followedArtistNotifier,
     IAggregatedEntryImageUrlFactory imageUrlFactory,
     IDiscordWebhookNotifier discordWebhookNotifier)
     : base(eventRepository, permissionContext)
 {
     _entryLinkFactory       = entryLinkFactory;
     _imagePersister         = imagePersister;
     _userIconFactory        = userIconFactory;
     _enumTranslations       = enumTranslations;
     _mailer                 = mailer;
     _followedArtistNotifier = followedArtistNotifier;
     _imageUrlFactory        = imageUrlFactory;
     _discordWebhookNotifier = discordWebhookNotifier;
 }
		/// <summary>
		/// Sends notifications
		/// </summary>
		/// <param name="ctx">Repository context. Cannot be null.</param>
		/// <param name="entry">Entry that was created. Cannot be null.</param>
		/// <param name="artists">List of artists for the entry. Cannot be null.</param>
		/// <param name="creator">User who created the entry. The creator will be excluded from all notifications. Cannot be null.</param>
		/// <param name="entryLinkFactory">Factory for creating links to entries. Cannot be null.</param>
		/// <param name="mailer">Mailer for user email messages. Cannot be null.</param>
		public void SendNotifications(IRepositoryContext<UserMessage> ctx, IEntryWithNames entry, 
			IEnumerable<Artist> artists, IUser creator, IEntryLinkFactory entryLinkFactory,
			IUserMessageMailer mailer) {

			ParamIs.NotNull(() => ctx);
			ParamIs.NotNull(() => entry);
			ParamIs.NotNull(() => artists);
			ParamIs.NotNull(() => creator);
			ParamIs.NotNull(() => entryLinkFactory);
			ParamIs.NotNull(() => mailer);

			var coll = artists.ToArray();
			var artistIds = coll.Select(a => a.Id).ToArray();

			// Get users with 3 or less unread messages, following any of the artists
			var usersWithArtists = ctx.OfType<ArtistForUser>()
				.Query()
				.Where(afu => 
					artistIds.Contains(afu.Artist.Id) 
					&& afu.User.Id != creator.Id && afu.User.Active
					&& afu.SiteNotifications
					&& afu.User.ReceivedMessages.Count(m => !m.Read) <= 9)
				.Select(afu => new {
					UserId = afu.User.Id, 
					ArtistId = afu.Artist.Id
				})
				.ToArray()
				.GroupBy(afu => afu.UserId)
				.ToDictionary(afu => afu.Key, afu => afu.Select(a => a.ArtistId));

			var userIds = usersWithArtists.Keys;

			if (!userIds.Any())
				return;

			var users = ctx.OfType<User>().Query().Where(u => userIds.Contains(u.Id)).ToArray();

			foreach (var user in users) {

				var artistIdsForUser = new HashSet<int>(usersWithArtists[user.Id]);
				var followedArtists = coll.Where(a => artistIdsForUser.Contains(a.Id)).ToArray();

				if (followedArtists.Length == 0)
					continue;

				string title;

				var entryTypeName = entry.EntryType.ToString().ToLowerInvariant();
				var msg = CreateMessageBody(followedArtists, user, entry, entryLinkFactory, true);

				if (followedArtists.Length == 1) {

					var artistName = followedArtists.First().TranslatedName[user.DefaultLanguageSelection];
					title = string.Format("New {0} by {1}", entryTypeName, artistName);

				} else {

					title = string.Format("New {0}", entryTypeName);

				}

				var notification = new UserMessage(user, title, msg, false);
				ctx.Save(notification);

				if (user.EmailOptions != UserEmailOptions.NoEmail && !string.IsNullOrEmpty(user.Email) 
					&& followedArtists.Any(a => a.Users.Any(u => u.User.Equals(user) && u.EmailNotifications))) {
					
					mailer.SendEmail(user.Email, user.Name, title, CreateMessageBody(followedArtists, user, entry, entryLinkFactory, false));

				}

			}

		}
Esempio n. 13
0
        /// <summary>
        /// Sends notifications
        /// </summary>
        /// <param name="ctx">Repository context. Cannot be null.</param>
        /// <param name="entry">Entry that was created. Cannot be null.</param>
        /// <param name="artists">List of artists for the entry. Cannot be null.</param>
        /// <param name="creator">User who created the entry. The creator will be excluded from all notifications. Cannot be null.</param>
        /// <param name="entryLinkFactory">Factory for creating links to entries. Cannot be null.</param>
        /// <param name="mailer">Mailer for user email messages. Cannot be null.</param>
        public void SendNotifications(IDatabaseContext <UserMessage> ctx, IEntryWithNames entry,
                                      IEnumerable <Artist> artists, IUser creator, IEntryLinkFactory entryLinkFactory,
                                      IUserMessageMailer mailer)
        {
            ParamIs.NotNull(() => ctx);
            ParamIs.NotNull(() => entry);
            ParamIs.NotNull(() => artists);
            ParamIs.NotNull(() => creator);
            ParamIs.NotNull(() => entryLinkFactory);
            ParamIs.NotNull(() => mailer);

            var coll      = artists.ToArray();
            var artistIds = coll.Select(a => a.Id).ToArray();

            // Get users with 3 or less unread messages, following any of the artists
            var usersWithArtists = ctx.OfType <ArtistForUser>()
                                   .Query()
                                   .Where(afu =>
                                          artistIds.Contains(afu.Artist.Id) &&
                                          afu.User.Id != creator.Id && afu.User.Active &&
                                          afu.SiteNotifications &&
                                          afu.User.ReceivedMessages.Count(m => m.Inbox == UserInboxType.Notifications && !m.Read) < afu.User.Options.UnreadNotificationsToKeep)
                                   .Select(afu => new {
                UserId   = afu.User.Id,
                ArtistId = afu.Artist.Id
            })
                                   .ToArray()
                                   .GroupBy(afu => afu.UserId)
                                   .ToDictionary(afu => afu.Key, afu => afu.Select(a => a.ArtistId));

            var userIds = usersWithArtists.Keys;

            if (!userIds.Any())
            {
                return;
            }

            var users = ctx.OfType <User>().Query().Where(u => userIds.Contains(u.Id)).ToArray();

            foreach (var user in users)
            {
                var artistIdsForUser = new HashSet <int>(usersWithArtists[user.Id]);
                var followedArtists  = coll.Where(a => artistIdsForUser.Contains(a.Id)).ToArray();

                if (followedArtists.Length == 0)
                {
                    continue;
                }

                string title;

                var entryTypeName = entry.EntryType.ToString().ToLowerInvariant();
                var msg           = CreateMessageBody(followedArtists, user, entry, entryLinkFactory, true);

                if (followedArtists.Length == 1)
                {
                    var artistName = followedArtists.First().TranslatedName[user.DefaultLanguageSelection];
                    title = string.Format("New {0} by {1}", entryTypeName, artistName);
                }
                else
                {
                    title = string.Format("New {0}", entryTypeName);
                }

                var notification = new UserMessage(user, title, msg, false);
                user.Messages.Add(notification);
                ctx.Save(notification);

                if (user.EmailOptions != UserEmailOptions.NoEmail && !string.IsNullOrEmpty(user.Email) &&
                    followedArtists.Any(a => a.Users.Any(u => u.User.Equals(user) && u.EmailNotifications)))
                {
                    mailer.SendEmail(user.Email, user.Name, title, CreateMessageBody(followedArtists, user, entry, entryLinkFactory, false));
                }
            }
        }
Esempio n. 14
0
 public UserService(ISessionFactory sessionFactory, IUserPermissionContext permissionContext, IEntryLinkFactory entryLinkFactory,
                    IUserMessageMailer userMessageMailer)
     : base(sessionFactory, permissionContext, entryLinkFactory)
 {
     this.userMessageMailer = userMessageMailer;
 }