This commit is contained in:
payacom
2026-07-11 20:52:56 +03:30
parent 3c90976f23
commit 54971578b0
6 changed files with 103 additions and 10 deletions

View File

@@ -970,10 +970,13 @@ const getPostsWeb = async (req, res, next) => {
lng,
feedMode,
seedPostId,
sort,
} = req.query;
const reelsMode = feedMode === "reels" || type === "video";
const gridMode = feedMode === "grid";
// فید اصلی صفحه پست‌ها: فقط جدیدترین‌ها (بدون شخصی‌سازی)
const latestMode = sort === "latest" && !reelsMode;
const postFilter = { status: { $ne: null } };
if (type === 'video' || type === 'image') {
@@ -1090,6 +1093,24 @@ const getPostsWeb = async (req, res, next) => {
explorePosts = await mapPostsWithUsers(explorePosts, usersMap, decodedToken);
// فید اصلی: فقط جدیدترین‌ها بر اساس تاریخ ساخت
if (latestMode) {
explorePosts.sort(
(a, b) => new Date(b.createdAt) - new Date(a.createdAt)
);
const totalItems = explorePosts.length;
const startIndex = (parseInt(page, 10) - 1) * parseInt(limit, 10);
const paginatedPosts = explorePosts.slice(
startIndex,
startIndex + parseInt(limit, 10)
);
return res.status(200).json({
posts: paginatedPosts,
totalPages: Math.ceil(totalItems / limit) || 1,
totalItems,
});
}
const { posts: paginatedPosts, totalItems } = await paginatePersonalizedExplore({
posts: explorePosts,
usersById,