Getting all recent topics in all available categories



  • I'm getting all available categories for a user with categories.getCategoriesByPrivilege. Then I append to it with
    categories.getRecentTopicReplies. I'm not getting what I want, only the top post (reply).

    What I want is the following; a list of all topics with recent posts (preferably with a max limit in time range), within my available categories. What the client I'm working for want is a feed type thing with all recent activity displayed in one single flow. Then I will also drill down into specific categories but I think I've got that covered.

    This is where I'm at so far:

    Controllers.renderFeedPage = function (req, res) {
    	if (!req.uid) {
    		res.render('feed', {});
    	}
    	let categoriesData;
    	let tree;
    
    	async.waterfall([
    		(next) => {
    			categories.getCategoriesByPrivilege('categories:cid', req.uid, 'find', next);
    		},
    		(_categoriesData, next) => {
    			categoriesData = _categoriesData;
    
    			tree = categories.getTree(categoriesData, 0);
    			categories.getRecentTopicReplies(categoriesData, req.uid, next);
    		},
    		() => {
    			const data = {
    				title: meta.config.homePageTitle || '[[pages:home]]',
    				categories: tree,
    			};
    			res.render('feed', data);
    		},
    	]);
    };
    

    I haven't found a good example from the forum and I'm reading source code at this point.

    If anyone has done something similar I would really appreciate the input and a nudge in the right direction.

    Thanks!



  • categories.getRecentTopicReplies only loads numRecentReplies posts. It reads that value from each category you pass to it. So it possible to increase that number to load more posts. Try this.

    Controllers.renderFeedPage = function (req, res) {
    	if (!req.uid) {
    		res.render('feed', {});
    	}
    	let categoriesData;
    	let tree;
    
    	async.waterfall([
    		(next) => {
    			categories.getCategoriesByPrivilege('categories:cid', req.uid, 'find', next);
    		},
    		(_categoriesData, next) => {
    			categoriesData = _categoriesData;
    
    			tree = categories.getTree(categoriesData, 0);
    
    			categoriesData.forEach(c => c.numRecentReplies = 4);
    
    			categories.getRecentTopicReplies(categoriesData, req.uid, next);
    		},
    		() => {
    			const data = {
    				title: meta.config.homePageTitle || '[[pages:home]]',
    				categories: tree,
    			};
    			res.render('feed', data);
    		},
    	]);
    };
    


  • Thanks for taking the time to reply. That might be a part of what I'm aiming for.

    I want to create an array of topics that I can display in my "feed". Those topics can be added to the array by two reasons.

    1. It's a recently created topic.
    2. It contains recent posts. (So maybe I can use tour suggestion here)

    The idea is just to have the new content presented when you first log in. I could look at Recent and Popular I think.

    Once again, thank you!


Log in to reply
 

Suggested Topics

| |