diff --git a/api/src/api-utils.js b/api/src/api-utils.js index 5f4a7a5..36d7611 100644 --- a/api/src/api-utils.js +++ b/api/src/api-utils.js @@ -1,6 +1,10 @@ const crypto = require('crypto') +const mongo = require('mongodb') module.exports = { + mongo: { + getID: (str) => { return new mongo.ObjectId(str) }, + }, v1url: (path) => { return '/api/v1' + path }, isURLValid: (url) => { try { diff --git a/api/src/api/feed.js b/api/src/api/feed.js index e2a6f2d..a39eee3 100644 --- a/api/src/api/feed.js +++ b/api/src/api/feed.js @@ -1,16 +1,20 @@ const auth = require('../auth.js') const utils = require('../api-utils.js') -const FEED_LIMIT = 20 +const FEED_LIMIT = 10 module.exports = { meet: { // TODO: change algorithm later (to actually get posts instead of accounts) get: [auth.enforceSession, async (req, res) => { var results = [] + var filter = { type: 'Note', inReplyTo: undefined } + if (req.query.skip !== undefined) + filter._id = { $lt: utils.mongo.getID(req.query.skip) } const notes = await db.table.objects() - .find({ type: 'Note', inReplyTo: undefined }) + .find(filter) .sort({ _id: -1 }) + .limit(FEED_LIMIT) .toArray() for (var i = 0; i < notes.length; i++) { const note = notes[i] diff --git a/web/src/app/js/pages/meet.js b/web/src/app/js/pages/meet.js index a0b0a15..41bdf2a 100644 --- a/web/src/app/js/pages/meet.js +++ b/web/src/app/js/pages/meet.js @@ -13,6 +13,14 @@ app.pages.meet = { }); }); }, + loadMore: function() { + const skip = app.pages.meet.data[app.pages.meet.data.length-1]._id; + http.get(`/api/v1/feed/meet?skip=${skip}`, {}, function(json) { + if (json === undefined || json.length === 0) return; + app.pages.meet.data = app.pages.meet.data.concat(json); + app.pages.meet.paint(); + }); + }, paint: function(json) { json = json || app.pages.meet.data; let _; @@ -79,7 +87,12 @@ app.pages.meet = { app.pages.meet.carousel.setDragEvent(direction); }, set: function(i) { return app.carousel.set(app.pages.meet.carousel, i) }, - next: function() { return app.carousel.next(app.pages.meet.carousel) }, + next: function() { + if (app.pages.meet.carousel._current >= + app.pages.meet.carousel._size() - 2) + app.pages.meet.loadMore(); + return app.carousel.next(app.pages.meet.carousel); + }, prev: function() { return app.carousel.prev(app.pages.meet.carousel) }, setDragEvent: function(direction) { direction = direction || 'none'; @@ -88,8 +101,8 @@ app.pages.meet = { var options = { y: false, return2start: true, fadeOut: true }; if (!app.carousel.hasPrev(app.pages.meet.carousel)) options.right = false; - if (!app.carousel.hasNext(app.pages.meet.carousel)) - options.left = false; + /*if (!app.carousel.hasNext(app.pages.meet.carousel)) + options.left = false;*/ if (direction === 'left') { current.classList.add('slide-from-left'); setTimeout(function() {