mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: show best & latest posts on profile
This commit is contained in:
@@ -49,6 +49,7 @@
|
|||||||
"account/following": "People %1 follows",
|
"account/following": "People %1 follows",
|
||||||
"account/followers": "People who follow %1",
|
"account/followers": "People who follow %1",
|
||||||
"account/posts": "Posts made by %1",
|
"account/posts": "Posts made by %1",
|
||||||
|
"account/latest-posts": "Latest posts made by %1",
|
||||||
"account/topics": "Topics created by %1",
|
"account/topics": "Topics created by %1",
|
||||||
"account/groups": "%1's Groups",
|
"account/groups": "%1's Groups",
|
||||||
"account/watched_categories": "%1's Watched Categories",
|
"account/watched_categories": "%1's Watched Categories",
|
||||||
|
|||||||
@@ -3,27 +3,19 @@
|
|||||||
|
|
||||||
define('forum/account/profile', [
|
define('forum/account/profile', [
|
||||||
'forum/account/header',
|
'forum/account/header',
|
||||||
'forum/infinitescroll',
|
|
||||||
'components',
|
'components',
|
||||||
], function (header, infinitescroll) {
|
], function (header) {
|
||||||
var Account = {};
|
var Account = {};
|
||||||
var theirid;
|
|
||||||
|
|
||||||
Account.init = function () {
|
Account.init = function () {
|
||||||
header.init();
|
header.init();
|
||||||
|
|
||||||
theirid = ajaxify.data.theirid;
|
app.enterRoom('user/' + ajaxify.data.theirid);
|
||||||
|
|
||||||
app.enterRoom('user/' + theirid);
|
|
||||||
|
|
||||||
processPage();
|
processPage();
|
||||||
|
|
||||||
socket.removeListener('event:user_status_change', onUserStatusChange);
|
socket.removeListener('event:user_status_change', onUserStatusChange);
|
||||||
socket.on('event:user_status_change', onUserStatusChange);
|
socket.on('event:user_status_change', onUserStatusChange);
|
||||||
|
|
||||||
if (!config.usePagination) {
|
|
||||||
infinitescroll.init(loadMorePosts);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function processPage() {
|
function processPage() {
|
||||||
@@ -38,43 +30,5 @@ define('forum/account/profile', [
|
|||||||
app.updateUserStatus($('.account [data-uid="' + data.uid + '"] [component="user/status"]'), data.status);
|
app.updateUserStatus($('.account [data-uid="' + data.uid + '"] [component="user/status"]'), data.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadMorePosts(direction) {
|
|
||||||
if (direction < 0 || !$('[component="posts"]').length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$('[component="posts/loading"]').removeClass('hidden');
|
|
||||||
|
|
||||||
infinitescroll.loadMore('posts.loadMoreUserPosts', {
|
|
||||||
after: $('[component="posts"]').attr('data-nextstart'),
|
|
||||||
uid: theirid,
|
|
||||||
}, function (data, done) {
|
|
||||||
if (data.posts && data.posts.length) {
|
|
||||||
onPostsLoaded(data.posts, done);
|
|
||||||
} else {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
$('[component="posts"]').attr('data-nextstart', data.nextStart);
|
|
||||||
$('[component="posts/loading"]').addClass('hidden');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function onPostsLoaded(posts, callback) {
|
|
||||||
posts = posts.filter(function (post) {
|
|
||||||
return !$('[component="posts"] [data-pid=' + post.pid + ']').length;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!posts.length) {
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
app.parseAndTranslate('account/profile', 'posts', { posts: posts }, function (html) {
|
|
||||||
$('[component="posts"]').append(html);
|
|
||||||
html.find('.timeago').timeago();
|
|
||||||
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return Account;
|
return Account;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
process.profile = function (operation, start) {
|
process.profile = function (operation, start) {
|
||||||
winston.log('%s took %d milliseconds', operation, process.elapsedTimeSince(start));
|
console.log('%s took %d milliseconds', operation, process.elapsedTimeSince(start));
|
||||||
};
|
};
|
||||||
|
|
||||||
process.elapsedTimeSince = function (start) {
|
process.elapsedTimeSince = function (start) {
|
||||||
|
|||||||
@@ -3,13 +3,14 @@
|
|||||||
var nconf = require('nconf');
|
var nconf = require('nconf');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
|
||||||
|
const db = require('../../database');
|
||||||
|
const privileges = require('../../privileges');
|
||||||
var user = require('../../user');
|
var user = require('../../user');
|
||||||
var posts = require('../../posts');
|
var posts = require('../../posts');
|
||||||
var plugins = require('../../plugins');
|
var plugins = require('../../plugins');
|
||||||
var meta = require('../../meta');
|
var meta = require('../../meta');
|
||||||
var accountHelpers = require('./helpers');
|
var accountHelpers = require('./helpers');
|
||||||
var helpers = require('../helpers');
|
var helpers = require('../helpers');
|
||||||
var pagination = require('../../pagination');
|
|
||||||
var messaging = require('../../messaging');
|
var messaging = require('../../messaging');
|
||||||
var translator = require('../../translator');
|
var translator = require('../../translator');
|
||||||
var utils = require('../../utils');
|
var utils = require('../../utils');
|
||||||
@@ -26,10 +27,7 @@ profileController.get = function (req, res, callback) {
|
|||||||
return res.redirect(nconf.get('relative_path') + '/user/' + lowercaseSlug);
|
return res.redirect(nconf.get('relative_path') + '/user/' + lowercaseSlug);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var page = Math.max(1, parseInt(req.query.page, 10) || 1);
|
|
||||||
var itemsPerPage = 10;
|
|
||||||
var start = (page - 1) * itemsPerPage;
|
|
||||||
var stop = start + itemsPerPage - 1;
|
|
||||||
var userData;
|
var userData;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
@@ -54,8 +52,11 @@ profileController.get = function (req, res, callback) {
|
|||||||
hasPrivateChat: function (next) {
|
hasPrivateChat: function (next) {
|
||||||
messaging.hasPrivateChat(req.uid, userData.uid, next);
|
messaging.hasPrivateChat(req.uid, userData.uid, next);
|
||||||
},
|
},
|
||||||
posts: function (next) {
|
latestPosts: function (next) {
|
||||||
posts.getPostSummariesFromSet('uid:' + userData.theirid + ':posts', req.uid, start, stop, next);
|
getLatestPosts(req.uid, userData, next);
|
||||||
|
},
|
||||||
|
bestPosts: function (next) {
|
||||||
|
getBestPosts(req.uid, userData, next);
|
||||||
},
|
},
|
||||||
signature: function (next) {
|
signature: function (next) {
|
||||||
posts.parseSignature(userData, req.uid, next);
|
posts.parseSignature(userData, req.uid, next);
|
||||||
@@ -74,55 +75,20 @@ profileController.get = function (req, res, callback) {
|
|||||||
delete userData.reputation;
|
delete userData.reputation;
|
||||||
}
|
}
|
||||||
|
|
||||||
userData.posts = results.posts.posts.filter(p => p && !p.deleted);
|
userData.posts = results.latestPosts; // for backwards compat.
|
||||||
|
userData.latestPosts = results.latestPosts;
|
||||||
|
userData.bestPosts = results.bestPosts;
|
||||||
userData.hasPrivateChat = results.hasPrivateChat;
|
userData.hasPrivateChat = results.hasPrivateChat;
|
||||||
userData.aboutme = translator.escape(results.aboutme);
|
userData.aboutme = translator.escape(results.aboutme);
|
||||||
userData.nextStart = results.posts.nextStart;
|
|
||||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username }]);
|
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username }]);
|
||||||
userData.title = userData.username;
|
userData.title = userData.username;
|
||||||
userData.allowCoverPicture = !userData.isSelf || userData.reputation >= (meta.config['min:rep:cover-picture'] || 0);
|
userData.allowCoverPicture = !userData.isSelf || userData.reputation >= (meta.config['min:rep:cover-picture'] || 0);
|
||||||
var pageCount = Math.ceil(userData.postcount / itemsPerPage);
|
|
||||||
userData.pagination = pagination.create(page, pageCount, req.query);
|
|
||||||
|
|
||||||
if (!userData.profileviews) {
|
if (!userData.profileviews) {
|
||||||
userData.profileviews = 1;
|
userData.profileviews = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var plainAboutMe = userData.aboutme ? utils.stripHTMLTags(utils.decodeHTMLEntities(userData.aboutme)) : '';
|
addMetaTags(res, userData);
|
||||||
|
|
||||||
res.locals.metaTags = [
|
|
||||||
{
|
|
||||||
name: 'title',
|
|
||||||
content: userData.fullname || userData.username,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'description',
|
|
||||||
content: plainAboutMe,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
property: 'og:title',
|
|
||||||
content: userData.fullname || userData.username,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
property: 'og:description',
|
|
||||||
content: plainAboutMe,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
if (userData.picture) {
|
|
||||||
res.locals.metaTags.push(
|
|
||||||
{
|
|
||||||
property: 'og:image',
|
|
||||||
content: userData.picture,
|
|
||||||
noEscape: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
property: 'og:image:url',
|
|
||||||
content: userData.picture,
|
|
||||||
noEscape: true,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
userData.selectedGroup = userData.groups.filter(function (group) {
|
userData.selectedGroup = userData.groups.filter(function (group) {
|
||||||
return group && userData.groupTitleArray.includes(group.name);
|
return group && userData.groupTitleArray.includes(group.name);
|
||||||
@@ -135,3 +101,74 @@ profileController.get = function (req, res, callback) {
|
|||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getLatestPosts(callerUid, userData, callback) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
db.getSortedSetRevRange('uid:' + userData.uid + ':posts', 0, 99, next);
|
||||||
|
},
|
||||||
|
function (pids, next) {
|
||||||
|
getPosts(callerUid, pids, next);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getBestPosts(callerUid, userData, callback) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
db.getSortedSetRevRange('uid:' + userData.uid + ':posts:votes', 0, 99, next);
|
||||||
|
},
|
||||||
|
function (pids, next) {
|
||||||
|
getPosts(callerUid, pids, next);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPosts(callerUid, pids, callback) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
privileges.posts.filter('topics:read', pids, callerUid, next);
|
||||||
|
},
|
||||||
|
function (pids, next) {
|
||||||
|
pids = pids.slice(0, 10);
|
||||||
|
posts.getPostSummaryByPids(pids, callerUid, { stripTags: false }, next);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addMetaTags(res, userData) {
|
||||||
|
var plainAboutMe = userData.aboutme ? utils.stripHTMLTags(utils.decodeHTMLEntities(userData.aboutme)) : '';
|
||||||
|
res.locals.metaTags = [
|
||||||
|
{
|
||||||
|
name: 'title',
|
||||||
|
content: userData.fullname || userData.username,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'description',
|
||||||
|
content: plainAboutMe,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: 'og:title',
|
||||||
|
content: userData.fullname || userData.username,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: 'og:description',
|
||||||
|
content: plainAboutMe,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
if (userData.picture) {
|
||||||
|
res.locals.metaTags.push(
|
||||||
|
{
|
||||||
|
property: 'og:image',
|
||||||
|
content: userData.picture,
|
||||||
|
noEscape: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: 'og:image:url',
|
||||||
|
content: userData.picture,
|
||||||
|
noEscape: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user