コード例 #1
0
		private string CreateMessageBody(Artist[] followedArtists, User user, IEntryWithNames entry, IEntryLinkFactory entryLinkFactory, bool markdown) {
			
			var entryTypeName = entry.EntryType.ToString().ToLowerInvariant();
			var entryName = entry.Names.SortNames[user.DefaultLanguageSelection];
			var url = entryLinkFactory.GetFullEntryUrl(entry);

			string entryLink;
			if (markdown) {
				entryLink = MarkdownHelper.CreateMarkdownLink(url, entryName);
			} else {
				entryLink = string.Format("{0} ( {1} )", entryName, url);
			}

			string msg;

			if (followedArtists.Length == 1) {

				var artistName = followedArtists.First().TranslatedName[user.DefaultLanguageSelection];
				msg = string.Format("A new {0}, '{1}', by {2} was just added.",
					entryTypeName, entryLink, artistName);

			} else {

				msg = string.Format("A new {0}, '{1}', by multiple artists you're following was just added.",
					entryTypeName, entryLink);

			}

			msg += "\nYou're receiving this notification because you're following the artist(s).";
			return msg;

		}
コード例 #2
0
        private string CreateMessageBody(Tag[] followedArtists, User user, IEntryWithNames entry, IEntryLinkFactory entryLinkFactory, bool markdown,
                                         string entryTypeName)
        {
            var entryName = entry.Names.SortNames[user.DefaultLanguageSelection];
            var url       = entryLinkFactory.GetFullEntryUrl(entry);

            string entryLink;

            if (markdown)
            {
                entryLink = MarkdownHelper.CreateMarkdownLink(url, entryName);
            }
            else
            {
                entryLink = $"{entryName} ( {url} )";
            }

            string msg;

            if (followedArtists.Length == 1)
            {
                var artistName = followedArtists.First().TranslatedName[user.DefaultLanguageSelection];
                msg = $"A new {entryTypeName}, '{entryLink}', tagged with {artistName} was just added.";
            }
            else
            {
                msg = $"A new {entryTypeName}, '{entryLink}', tagged with multiple tags you're following was just added.";
            }

            msg += "\nYou're receiving this notification because you're following the tag(s).";
            return(msg);
        }
コード例 #3
0
        private string CreateMessageBody(Artist[] followedArtists, User user, IEntryWithNames entry, bool markdown,
                                         string entryTypeName)
        {
            var entryName = entry.Names.SortNames[user.DefaultLanguageSelection];
            var url       = entryLinkFactory.GetFullEntryUrl(entry);

            string entryLink;

            if (markdown)
            {
                entryLink = MarkdownHelper.CreateMarkdownLink(url, entryName);
            }
            else
            {
                entryLink = string.Format("{0} ( {1} )", entryName, url);
            }

            string msg;

            if (followedArtists.Length == 1)
            {
                var artistName = followedArtists.First().TranslatedName[user.DefaultLanguageSelection];
                msg = string.Format("A new {0}, '{1}', by {2} was just added.",
                                    entryTypeName, entryLink, artistName);
            }
            else
            {
                msg = string.Format("A new {0}, '{1}', by multiple artists you're following was just added.",
                                    entryTypeName, entryLink);
            }

            msg += "\nYou're receiving this notification because you're following the artist(s).";
            return(msg);
        }
コード例 #4
0
        public static EntryForApiContract Create(IEntryWithNames entry, ContentLanguagePreference languagePreference,
                                                 IEntryThumbPersister thumbPersister, IEntryImagePersisterOld imagePersisterOld, bool ssl,
                                                 EntryOptionalFields includedFields)
        {
            ParamIs.NotNull(() => entry);

            switch (entry.EntryType)
            {
            case EntryType.Album:
                return(new EntryForApiContract((Album)entry, languagePreference, thumbPersister, ssl, includedFields));

            case EntryType.Artist:
                return(new EntryForApiContract((Artist)entry, languagePreference, thumbPersister, ssl, includedFields));

            case EntryType.DiscussionTopic:
                return(new EntryForApiContract((DiscussionTopic)entry, languagePreference));

            case EntryType.ReleaseEvent:
                return(new EntryForApiContract((ReleaseEvent)entry, thumbPersister, ssl, includedFields));

            case EntryType.Song:
                return(new EntryForApiContract((Song)entry, languagePreference, includedFields));

            case EntryType.SongList:
                return(new EntryForApiContract((SongList)entry, imagePersisterOld, ssl, includedFields));

            case EntryType.Tag:
                return(new EntryForApiContract((Tag)entry, languagePreference, imagePersisterOld, ssl, includedFields));
            }

            return(new EntryForApiContract(entry, languagePreference, includedFields));
        }
コード例 #5
0
        public static EntryForApiContract Create(IEntryWithNames entry, ContentLanguagePreference languagePreference,
                                                 IEntryThumbPersister thumbPersister, IEntryImagePersisterOld imagePersisterOld, bool ssl,
                                                 EntryOptionalFields includedFields)
        {
            ParamIs.NotNull(() => entry);

            if (entry is Album)
            {
                return(new EntryForApiContract((Album)entry, languagePreference, thumbPersister, ssl, includedFields));
            }
            else if (entry is Artist)
            {
                return(new EntryForApiContract((Artist)entry, languagePreference, thumbPersister, ssl, includedFields));
            }
            else if (entry is DiscussionTopic)
            {
                return(new EntryForApiContract((DiscussionTopic)entry, languagePreference));
            }
            else if (entry is Song)
            {
                return(new EntryForApiContract((Song)entry, languagePreference, includedFields));
            }
            else if (entry is Tag)
            {
                return(new EntryForApiContract((Tag)entry, imagePersisterOld, ssl, includedFields));
            }

            throw new ArgumentException("Unsupported entry type: " + entry, "entry");
        }
コード例 #6
0
        public static EntryForPictureDisplayContract Create(IEntryWithNames entry, string mime, byte[] bytes, ContentLanguagePreference languagePreference)
        {
            var name = entry.Names.SortNames[languagePreference];
            var pic  = (bytes != null ? new PictureContract(bytes, mime) : null);

            return(new EntryForPictureDisplayContract(entry.EntryType, entry.Id, name, entry.Version, pic));
        }
コード例 #7
0
		public static EntryForPictureDisplayContract Create(IEntryWithNames entry, string mime, byte[] bytes, ContentLanguagePreference languagePreference) {
			
			var name = entry.Names.SortNames[languagePreference];
			var pic = (bytes != null ? new PictureContract(bytes, mime) : null);

			return new EntryForPictureDisplayContract(entry.EntryType, entry.Id, name, entry.Version, pic);

		}
コード例 #8
0
        private EntryForApiContract(IEntryWithNames entry, ContentLanguagePreference languagePreference, EntryOptionalFields fields)
        {
            EntryType = entry.EntryType;
            Id        = entry.Id;

            DefaultName         = entry.DefaultName;
            DefaultNameLanguage = entry.Names.SortNames.DefaultLanguage;
            Name    = entry.Names.SortNames[languagePreference];
            Version = entry.Version;

            if (fields.HasFlag(EntryOptionalFields.AdditionalNames))
            {
                AdditionalNames = entry.Names.GetAdditionalNamesStringForLanguage(languagePreference);
            }
        }
コード例 #9
0
        private EntryForApiContract(IEntryWithNames entry, ContentLanguagePreference languagePreference)
        {
            EntryType = entry.EntryType;
            Id        = entry.Id;

            DefaultName         = entry.DefaultName;
            DefaultNameLanguage = entry.Names.SortNames.DefaultLanguage;
            Name    = entry.Names.SortNames[languagePreference];
            Version = entry.Version;

            if (languagePreference != ContentLanguagePreference.Default)
            {
                AdditionalNames = entry.Names.GetAdditionalNamesStringForLanguage(languagePreference);
                LocalizedName   = entry.Names.SortNames[languagePreference];
            }
        }
コード例 #10
0
		private EntryForApiContract(IEntryWithNames entry, ContentLanguagePreference languagePreference) {

			EntryType = entry.EntryType;
			Id = entry.Id;

			DefaultName = entry.DefaultName;
			DefaultNameLanguage = entry.Names.SortNames.DefaultLanguage;
			Name = entry.Names.SortNames[languagePreference];				
			Version = entry.Version;

			if (languagePreference != ContentLanguagePreference.Default) {
				AdditionalNames = entry.Names.GetAdditionalNamesStringForLanguage(languagePreference);
				LocalizedName = entry.Names.SortNames[languagePreference];					
			}

		}
コード例 #11
0
ファイル: EntryForApiContract.cs プロジェクト: AgFlore/vocadb
        public static EntryForApiContract Create(IEntryWithNames entry, ContentLanguagePreference languagePreference,
                                                 IAggregatedEntryImageUrlFactory thumbPersister,
                                                 EntryOptionalFields includedFields)
        {
            ParamIs.NotNull(() => entry);

            return(entry.EntryType switch
            {
                EntryType.Album => new EntryForApiContract((Album)entry, languagePreference, thumbPersister, includedFields),
                EntryType.Artist => new EntryForApiContract((Artist)entry, languagePreference, thumbPersister, includedFields),
                EntryType.DiscussionTopic => new EntryForApiContract((DiscussionTopic)entry, languagePreference),
                EntryType.ReleaseEvent => new EntryForApiContract((ReleaseEvent)entry, languagePreference, thumbPersister, includedFields),
                EntryType.Song => new EntryForApiContract((Song)entry, languagePreference, includedFields),
                EntryType.SongList => new EntryForApiContract((SongList)entry, thumbPersister, includedFields),
                EntryType.Tag => new EntryForApiContract((Tag)entry, languagePreference, thumbPersister, includedFields),
                _ => new EntryForApiContract(entry, languagePreference, includedFields),
            });
コード例 #12
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>
        public async Task SendNotificationsAsync(IDatabaseContext ctx, IEntryWithNames entry,
                                                 IReadOnlyCollection <Tag> tags, int[] ignoreUsers, IEntryLinkFactory entryLinkFactory,
                                                 IEnumTranslations enumTranslations)
        {
            ParamIs.NotNull(() => ctx);
            ParamIs.NotNull(() => entry);
            ParamIs.NotNull(() => tags);
            ParamIs.NotNull(() => ignoreUsers);
            ParamIs.NotNull(() => entryLinkFactory);

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

            try {
                await DoSendNotificationsAsync(ctx, entry, tags, ignoreUsers, entryLinkFactory, enumTranslations);
            } catch (GenericADOException x) {
                log.Error(x, "Unable to send notifications");
            }
        }
コード例 #13
0
 public async Task <IReadOnlyCollection <User> > SendNotificationsAsync(IDatabaseContext ctx, IEntryWithNames entry, IEnumerable <Artist> artists, IUser creator)
 {
     try {
         return(await DoSendNotificationsAsync(ctx, entry, artists, creator));
     } catch (GenericADOException x) {
         log.Error(x, "Unable to send notifications");
         return(new User[0]);
     }
 }
コード例 #14
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>
        public User[] SendNotifications(IDatabaseContext ctx, IEntryWithNames entry, IEnumerable <Artist> artists, IUser creator)
        {
            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();

            log.Info("Sending notifications for {0} artists", artistIds.Length);

            // Get users with less than maximum number of 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;

            log.Debug("Found {0} users subscribed to artists", userIds.Count);

            if (!userIds.Any())
            {
                return(new User[0]);
            }

            var entryTypeNames = enumTranslations.Translations <EntryType>();
            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 culture       = CultureHelper.GetCultureOrDefault(user.LanguageOrLastLoginCulture);
                var entryTypeName = entryTypeNames.GetName(entry.EntryType, culture).ToLowerInvariant();
                var entrySubType  = entrySubTypeNameFactory.GetEntrySubTypeName(entry, enumTranslations, culture)?.ToLowerInvariant();

                if (!string.IsNullOrEmpty(entrySubType))
                {
                    entryTypeName += $" ({entrySubType})";
                }

                var msg = CreateMessageBody(followedArtists, user, entry, true, entryTypeName);

                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, false, entryTypeName));
                }
            }

            return(users);
        }
コード例 #15
0
 public Task <IReadOnlyCollection <User> > SendNotificationsAsync(IDatabaseContext ctx, IEntryWithNames entry, IEnumerable <Artist> artists, IUser creator)
 {
     return(Task.FromResult((IReadOnlyCollection <User>) new List <User>()));
 }
コード例 #16
0
 public EntryWithImageContract(IEntryWithNames entry, string mime, ContentLanguagePreference languagePreference)
     : base(entry, languagePreference)
 {
     Mime = mime;
 }
コード例 #17
0
		public EntryWithNameAndVersionContract(IEntryWithNames entry, ContentLanguagePreference languagePreference) 
			: base(entry, languagePreference) {

			Version = entry.Version;

		}
コード例 #18
0
ファイル: OtherService.cs プロジェクト: AgFlore/vocadb
 public int GetHashCode(IEntryWithNames obj)
 {
     return(obj.Id);
 }
コード例 #19
0
        public string GetUrlFriendlyName(IEntryWithNames entry)
        {
            ParamIs.NotNull(() => entry);

            return(cachedNames.GetOrAdd(new GlobalEntryId(entry.EntryType, entry.Id), _ => entry.Names.GetUrlFriendlyName()));
        }
コード例 #20
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>
        public void SendNotifications(IDatabaseContext ctx, IEntryWithNames entry,
                                      IEnumerable <Tag> tags, int[] ignoreUsers, IEntryLinkFactory entryLinkFactory,
                                      IEnumTranslations enumTranslations)
        {
            ParamIs.NotNull(() => ctx);
            ParamIs.NotNull(() => entry);
            ParamIs.NotNull(() => tags);
            ParamIs.NotNull(() => ignoreUsers);
            ParamIs.NotNull(() => entryLinkFactory);

            var coll   = tags.Distinct().ToArray();
            var tagIds = coll.Select(a => a.Id).ToArray();

            // Get users with less than maximum number of unread messages, following any of the tags
            var usersWithTags = ctx.OfType <TagForUser>()
                                .Query()
                                .Where(afu =>
                                       tagIds.Contains(afu.Tag.Id) &&
                                       afu.User.Active &&
                                       !ignoreUsers.Contains(afu.User.Id) &&
                                       afu.User.ReceivedMessages.Count(m => m.Inbox == UserInboxType.Notifications && !m.Read) < afu.User.Options.UnreadNotificationsToKeep)
                                .Select(afu => new {
                UserId = afu.User.Id,
                TagId  = afu.Tag.Id
            })
                                .ToArray()
                                .GroupBy(afu => afu.UserId)
                                .ToDictionary(afu => afu.Key, afu => afu.Select(a => a.TagId));

            var userIds = usersWithTags.Keys;

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

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

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

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

                string title;

                var entryTypeName = entryTypeNames.GetName(entry.EntryType, CultureHelper.GetCultureOrDefault(user.LanguageOrLastLoginCulture)).ToLowerInvariant();
                var msg           = CreateMessageBody(followedTags, user, entry, entryLinkFactory, true, entryTypeName);

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

                var notification = user.CreateNotification(title, msg);
                ctx.Save(notification);
            }
        }
コード例 #21
0
        private async Task DoSendNotificationsAsync(IDatabaseContext ctx, IEntryWithNames entry,
                                                    IReadOnlyCollection <Tag> tags, int[] ignoreUsers, IEntryLinkFactory entryLinkFactory,
                                                    IEnumTranslations enumTranslations)
        {
            var coll   = tags.Distinct().ToArray();
            var tagIds = coll.Select(a => a.Id).ToArray();

            s_log.Info("Sending notifications for {0} tags", tagIds.Length);

            // Get users with less than maximum number of unread messages, following any of the tags
            var usersWithTagsArr = await ctx.Query <TagForUser>()
                                   .Where(afu =>
                                          tagIds.Contains(afu.Tag.Id))
                                   .Select(afu => new
            {
                UserId = afu.User.Id,
                TagId  = afu.Tag.Id
            })
                                   .VdbToListAsync();

            var usersWithTags = usersWithTagsArr
                                .GroupBy(afu => afu.UserId)
                                .ToDictionary(afu => afu.Key, afu => afu.Select(a => a.TagId));

            var userIds = usersWithTags.Keys.Except(ignoreUsers).ToArray();

            s_log.Debug("Found {0} users subscribed to tags", userIds.Length);

            if (!userIds.Any())
            {
                s_log.Info("No users subscribed to tags - skipping.");
                return;
            }

            var entryTypeNames = enumTranslations.Translations <EntryType>();
            var users          = await ctx.Query <User>()
                                 .WhereIsActive()
                                 .WhereIdIn(userIds)
                                 .Where(u => u.ReceivedMessages.Count(m => m.Inbox == UserInboxType.Notifications && !m.Read) < u.Options.UnreadNotificationsToKeep)
                                 .VdbToListAsync();

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

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

                string title;

                var entryTypeName = entryTypeNames.GetName(entry.EntryType, CultureHelper.GetCultureOrDefault(user.LanguageOrLastLoginCulture)).ToLowerInvariant();
                var msg           = CreateMessageBody(followedTags, user, entry, entryLinkFactory, true, entryTypeName);

                if (followedTags.Length == 1)
                {
                    var artistName = followedTags.First().TranslatedName[user.DefaultLanguageSelection];
                    title = $"New {entryTypeName} tagged with {artistName}";
                }
                else
                {
                    title = $"New {entryTypeName}";
                }

                var notification = user.CreateNotification(title, msg);
                await ctx.SaveAsync(notification);
            }

            s_log.Info($"Sent notifications to {users.Count} users");
        }
コード例 #22
0
 public EntryWithImageContract(IEntryWithNames entry, string mime, string songThumbUrl, ContentLanguagePreference languagePreference)
     : base(entry, languagePreference)
 {
     Mime         = mime;
     SongThumbUrl = songThumbUrl;
 }
コード例 #23
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(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));

				}

			}

		}
コード例 #24
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));
                }
            }
        }
コード例 #25
0
 public User[] SendNotifications(IDatabaseContext ctx, IEntryWithNames entry, IEnumerable <Artist> artists, IUser creator)
 {
     return(new User[0]);
 }
コード例 #26
0
 public EntryRefWithNameContract(IEntryWithNames entry, ContentLanguagePreference languagePreference)
     : base(entry)
 {
     Name = entry.Names.GetEntryName(languagePreference);
 }
コード例 #27
0
 public EntryForApiContract Create(IEntryWithNames entry, EntryOptionalFields includedFields, ContentLanguagePreference languagePreference, bool ssl)
 {
     return(EntryForApiContract.Create(entry, languagePreference, thumbPersister, imagePersisterOld, ssl, includedFields));
 }
コード例 #28
0
		public EntryRefWithNameContract(IEntryWithNames entry, ContentLanguagePreference languagePreference)
			: base(entry) {

			Name = entry.Names.GetEntryName(languagePreference);

		}
コード例 #29
0
 public EntryWithNameAndVersionContract(IEntryWithNames entry, ContentLanguagePreference languagePreference)
     : base(entry, languagePreference)
 {
     Version = entry.Version;
 }
コード例 #30
0
		public EntryWithImageContract(IEntryWithNames entry, string mime, ContentLanguagePreference languagePreference) 
			: base(entry, languagePreference) {
			
			Mime = mime;

		}