Exemple #1
0
        private EntryWithCommentsContract[] GetRecentComments(ISession session, int maxComments, bool ssl)
        {
            var albumComments      = GetComments <Album, AlbumComment>(session, maxComments, true);
            var artistComments     = GetComments <Artist, ArtistComment>(session, maxComments, true);
            var songComments       = GetComments <Song, SongComment>(session, maxComments, true);
            var discussionComments = GetComments <DiscussionTopic, DiscussionComment>(session, maxComments, true);
            var songListComments   = GetComments <SongList, SongListComment>(session, maxComments, false);
            var tagComments        = GetComments <Tag, TagComment>(session, maxComments, true);
            var eventComments      = GetComments <ReleaseEvent, ReleaseEventComment>(session, maxComments, true);

            // Discussion topics aren't actually comments but we want to show them in the recent comments list anyway
            var discussionTopics           = session.Query <DiscussionTopic>().Where(c => !c.Deleted).OrderByDescending(c => c.Created).Take(maxComments).ToArray();
            var discussionTopicsAsComments = discussionTopics.Select(t => new DiscussionComment(t, t.Content, new AgentLoginData(t.Author, t.AuthorName ?? t.Author.Name))
            {
                Created = t.Created
            });

            var combined = albumComments
                           .Concat(artistComments)
                           .Concat(songComments)
                           .Concat(songListComments)
                           .Concat(discussionComments)
                           .Concat(discussionTopicsAsComments)
                           .Concat(tagComments)
                           .Concat(eventComments)
                           .OrderByDescending(c => c.Created)
                           .Take(maxComments);

            var contracts = CreateEntryWithCommentsContract(combined, c => entryForApiContractFactory.Create(c.Entry, EntryOptionalFields.AdditionalNames | EntryOptionalFields.MainPicture, LanguagePreference, ssl))
                            .ToArray();

            return(contracts);
        }
        public PartialFindResult <ActivityEntryForApiContract> GetFollowedArtistActivity(int maxEntries)
        {
            if (!PermissionContext.IsLoggedIn)
            {
                return(new PartialFindResult <ActivityEntryForApiContract>());
            }

            return(HandleQuery(session => {
                var userId = PermissionContext.LoggedUserId;

                var albumEntries = session.Query <AlbumActivityEntry>()
                                   .Where(a => !a.Entry.Deleted && a.EditEvent == EntryEditEvent.Created && a.Entry.AllArtists.Any(r => r.Artist.Users.Any(u => u.User.Id == userId)))
                                   .OrderByDescending(a => a.CreateDate)
                                   .Take(maxEntries)
                                   .ToArray();

                var songEntries = session.Query <SongActivityEntry>()
                                  .Where(a => !a.Entry.Deleted && a.EditEvent == EntryEditEvent.Created && a.Entry.AllArtists.Any(r => r.Artist.Users.Any(u => u.User.Id == userId)))
                                  .OrderByDescending(a => a.CreateDate)
                                  .Take(maxEntries)
                                  .ToArray();

                var contracts = albumEntries.Cast <ActivityEntry>()
                                .Concat(songEntries)
                                .OrderByDescending(a => a.CreateDate)
                                .Take(maxEntries)
                                .Select(e => new ActivityEntryForApiContract(e, entryForApiContractFactory.Create(e.EntryBase, EntryOptionalFields.AdditionalNames | EntryOptionalFields.MainPicture,
                                                                                                                  LanguagePreference), userIconFactory,
                                                                             PermissionContext, ActivityEntryOptionalFields.None))
                                .ToArray();

                return new PartialFindResult <ActivityEntryForApiContract>(contracts, 0);
            }));
        }
Exemple #3
0
        public EntryReportContract[] GetEntryReports()
        {
            PermissionContext.VerifyPermission(PermissionToken.ManageEntryReports);

            return(HandleQuery(session => {
                var reports = session.Query <EntryReport>().OrderByDescending(r => r.Created).Take(200).ToArray();
                var fac = new EntryForApiContractFactory(null, null);
                return reports.Select(r => new EntryReportContract(r, fac.Create(r.EntryBase, EntryOptionalFields.AdditionalNames, LanguagePreference, false), enumTranslations)).ToArray();
            }));
        }
Exemple #4
0
        private EntryForApiContract[] GetRecentEvents(ISession session, bool ssl)
        {
            var count    = 3;
            var cacheKey = string.Format("OtherService.RecentEvents.{0}.{1}", LanguagePreference, ssl);

            return(cache.GetOrInsert(cacheKey, CachePolicy.AbsoluteExpiration(24), () => {
                var minDate = DateTime.Now - TimeSpan.FromDays(2);
                var maxDate = DateTime.Now + TimeSpan.FromDays(14);

                var recentEvents = session.Query <ReleaseEvent>()
                                   .WhereDateIsBetween(minDate, maxDate)
                                   .OrderByDate(SortDirection.Descending)
                                   .Take(count)
                                   .ToArray();

                var entryContracts = recentEvents.Select(i => entryForApiContractFactory.Create(i, EntryOptionalFields.MainPicture, LanguagePreference, ssl));

                return entryContracts.ToArray();
            }));
        }
Exemple #5
0
        private EntryForApiContract[] GetRecentEvents(ISession session, bool ssl)
        {
            var count    = 3;
            var cacheKey = string.Format("OtherService.RecentEvents.{0}.{1}", LanguagePreference, ssl);

            return(cache.GetOrInsert(cacheKey, CachePolicy.AbsoluteExpiration(24), () => {
                var minDate = DateTime.Now - TimeSpan.FromDays(2);
                var maxDate = DateTime.Now + TimeSpan.FromDays(14);

                var recentEvents = session.Query <ReleaseEvent>()
                                   .WhereDateIsBetween(minDate, maxDate)
                                   .OrderByDate(SortDirection.Descending)
                                   .Take(count)
                                   .ToArray();

                var recentConcerts = session.Query <SongList>()
                                     .Where(s => s.FeaturedCategory == SongListFeaturedCategory.Concerts)
                                     .WhereEventDateIsBetween(minDate, maxDate)
                                     .OrderByDate(SortDirection.Descending)
                                     .Take(count)
                                     .ToArray();

                var items = recentEvents.Select(e => new {
                    Entry = (IEntryWithNames)e,
                    e.Date
                }).Concat(recentConcerts.Select(e => new {
                    Entry = (IEntryWithNames)e,
                    Date = e.EventDate
                }))
                            .OrderByDescending(e => e.Date.DateTime)
                            .Take(count);

                var entryContracts = items.Select(i => entryForApiContractFactory.Create(i.Entry, EntryOptionalFields.MainPicture, LanguagePreference, ssl));

                return entryContracts.ToArray();
            }));
        }
Exemple #6
0
        private async Task <EntryWithCommentsContract[]> GetRecentCommentsAsync(ISession session, int maxComments)
        {
            // FIXME: this returns less comments if there are deleted entries.
            // See also: https://github.com/VocaDB/vocadb/pull/663#pullrequestreview-545596680
            var comments = (await session.Query <Comment>()
                            .WhereNotDeleted()
                            .Where(c => !(c is UserComment))
                            .OrderByDescending(c => c.Created)
                            .Take(maxComments)
                            .ToListAsync())
                           .Where(c => !c.Entry.Deleted);

            var combined = comments
                           .OrderByDescending(c => c.Created)
                           .Take(maxComments);

            var contracts = CreateEntryWithCommentsContract(combined, c => _entryForApiContractFactory.Create(c.Entry, EntryOptionalFields.AdditionalNames | EntryOptionalFields.MainPicture, LanguagePreference))
                            .ToArray();

            return(contracts);
        }
Exemple #7
0
        public FrontPageContract(IEnumerable <ActivityEntry> activityEntries,
                                 AlbumForApiContract[] newAlbums,
                                 ReleaseEventForApiContract[] newEvents,
                                 IEnumerable <EntryWithCommentsContract> recentComments,
                                 AlbumForApiContract[] topAlbums, Song[] newSongs,
                                 SongVoteRating firstSongRating,
                                 ContentLanguagePreference languagePreference, IUserIconFactory userIconFactory, IUserPermissionContext permissionContext,
                                 EntryForApiContractFactory entryForApiContractFactory)
        {
            ActivityEntries = activityEntries.Select(e => new ActivityEntryForApiContract(e,
                                                                                          entryForApiContractFactory.Create(e.EntryBase, EntryOptionalFields.AdditionalNames | EntryOptionalFields.MainPicture, languagePreference),
                                                                                          userIconFactory, permissionContext, ActivityEntryOptionalFields.None)).ToArray();
            NewAlbums      = newAlbums;
            NewSongs       = newSongs.Select(s => new SongWithPVAndVoteContract(s, SongVoteRating.Nothing, languagePreference)).ToArray();
            RecentComments = recentComments.ToArray();
            TopAlbums      = topAlbums;
            NewEvents      = newEvents;

            FirstSong = (newSongs.Any() ? new SongWithPVAndVoteContract(newSongs.First(), firstSongRating, languagePreference) : null);
        }
Exemple #8
0
        public PartialFindResult <ActivityEntryForApiContract> GetList(
            DateTime?before                    = null,
            DateTime?since                     = null,
            int?userId                         = null,
            EntryEditEvent?editEvent           = null,
            int maxResults                     = defaultMax,
            bool getTotalCount                 = false,
            ActivityEntryOptionalFields fields = ActivityEntryOptionalFields.None,
            EntryOptionalFields entryFields    = EntryOptionalFields.None,
            ContentLanguagePreference lang     = ContentLanguagePreference.Default)
        {
            maxResults = Math.Min(maxResults, absoluteMax);

            return(repository.HandleQuery(ctx => {
                var query = ctx.Query <ActivityEntry>();

                if (before.HasValue && !since.HasValue)
                {
                    query = query.Where(a => a.CreateDate < before.Value);
                }

                if (!before.HasValue && since.HasValue)
                {
                    query = query.Where(a => a.CreateDate > since.Value);
                }

                if (before.HasValue && since.HasValue)
                {
                    query = query.Where(a => a.CreateDate > since.Value && a.CreateDate < before.Value);
                }

                if (userId.HasValue)
                {
                    query = query.Where(a => a.Author.Id == userId.Value);
                }

                if (editEvent.HasValue)
                {
                    query = query.Where(a => a.EditEvent == editEvent.Value);
                }

                var activityEntries = query
                                      .OrderByDescending(a => a.CreateDate)
                                      .Take(maxResults)
                                      .ToArray()
                                      .Where(a => !a.EntryBase.Deleted)
                                      .Select(a => new ActivityEntryForApiContract(a,
                                                                                   fields.HasFlag(ActivityEntryOptionalFields.Entry) ? entryForApiContractFactory.Create(a.EntryBase, entryFields, lang) : null,
                                                                                   userIconFactory, permissionContext, fields))
                                      .ToArray();

                var count = getTotalCount ? query.Count() : 0;

                return PartialFindResult.Create(activityEntries, count);
            }));
        }