diff --git a/app/controllers/home.js b/app/controllers/home.js index b3cd781..6c459cb 100644 --- a/app/controllers/home.js +++ b/app/controllers/home.js @@ -63,9 +63,13 @@ class HomeController extends SiteController { } async getHome (req, res, next) { - const { announcement: announcementService } = this.dtp.services; + const { announcement: announcementService, hive: hiveService } = this.dtp.services; try { res.locals.announcements = await announcementService.getLatest(req.user); + + res.locals.pagination = this.getPaginationParameters(req, 20); + res.locals.constellationTimeline = await hiveService.getConstellationTimeline(req.user, res.locals.pagination); + res.render('index'); } catch (error) { this.log.error('failed to render home view', { error }); diff --git a/app/services/hive.js b/app/services/hive.js index 79a45db..3b3007d 100644 --- a/app/services/hive.js +++ b/app/services/hive.js @@ -251,6 +251,28 @@ class HiveService extends SiteService { return event.toObject(); } + + async getConstellationTimeline (user, pagination) { + const totalEventCount = await KaleidoscopeEvent.estimatedDocumentCount(); + const job = { }; + if (user) { + job.search = { + $or: [ + { recipient: { $exists: false } }, + { recipient: user._id }, + ], + }; + } else { + job.search = { recipient: { $exists: false } }; + } + const events = await KaleidoscopeEvent + .find(job.search) + .sort({ created: -1 }) + .skip(pagination.skip) + .limit(pagination.cpp) + .lean(); + return { events, totalEventCount }; + } } module.exports = {