0.11.4 : change on feed and save/hide
This commit is contained in:
@@ -177,20 +177,15 @@ export default factories.createCoreController(
|
||||
.findMany({
|
||||
where: {
|
||||
$or: [
|
||||
// Posts réguliers (amis, follows, groupes, système, mes propres posts) - exclure les cachés
|
||||
// Posts réguliers (amis, follows, groupes, système, mes propres posts)
|
||||
{
|
||||
$and: [
|
||||
{
|
||||
$or: [
|
||||
{ author: { id: friendIds } }, // Posts de mes amis
|
||||
{ author: { id: followIds } }, // Posts des contacts que je suis
|
||||
{ author: { id: parseInt(userId) }, relation: "owner" }, // Mes propres posts
|
||||
{ contextType: "group", contextId: groupIds }, // Posts de mes groupes
|
||||
{ contextType: "group", contextId: friendsGroupIds }, // Posts des groupes de mes amis
|
||||
{ contextType: "system" }, // Posts système
|
||||
],
|
||||
},
|
||||
{ relation: { $ne: "hidden" } }, // exclure les posts masqués pour les posts réguliers
|
||||
$or: [
|
||||
{ author: { id: friendIds } }, // Posts de mes amis
|
||||
{ author: { id: followIds } }, // Posts des contacts que je suis
|
||||
{ author: { id: parseInt(userId) }, relation: "owner" }, // Mes propres posts
|
||||
{ contextType: "group", contextId: groupIds }, // Posts de mes groupes
|
||||
{ contextType: "group", contextId: friendsGroupIds }, // Posts des groupes de mes amis
|
||||
{ contextType: "system" }, // Posts système
|
||||
],
|
||||
},
|
||||
// Posts sauvés par l'utilisateur
|
||||
@@ -199,17 +194,43 @@ export default factories.createCoreController(
|
||||
contextId: parseInt(userId),
|
||||
relation: "saved",
|
||||
},
|
||||
// Posts cachés par l'utilisateur
|
||||
{
|
||||
contextType: "user",
|
||||
contextId: parseInt(userId),
|
||||
relation: "hidden",
|
||||
},
|
||||
],
|
||||
},
|
||||
...queryParams,
|
||||
});
|
||||
|
||||
// 4.1️⃣ Récupérer tous les posts cachés par l'utilisateur
|
||||
const hiddenPosts = await strapi.db
|
||||
.query("api::post-ownership.post-ownership")
|
||||
.findMany({
|
||||
where: {
|
||||
contextType: "user",
|
||||
contextId: parseInt(userId),
|
||||
relation: "hidden",
|
||||
},
|
||||
populate: {
|
||||
post: true,
|
||||
},
|
||||
});
|
||||
const hiddenPostIds = hiddenPosts
|
||||
.map((hp) => hp.post?.id)
|
||||
.filter(Boolean);
|
||||
|
||||
console.log("🔍 Hidden posts found:", hiddenPostIds);
|
||||
console.log("📊 Feed before filtering:", feed.length);
|
||||
|
||||
// 4.2️⃣ Filtrer le feed pour exclure les posts cachés
|
||||
const filteredFeed = feed.filter((postOwnership) => {
|
||||
const postId = postOwnership.post?.id;
|
||||
const isHidden = hiddenPostIds.includes(postId);
|
||||
if (isHidden) {
|
||||
console.log(`🚫 Filtering out hidden post ID: ${postId}`);
|
||||
}
|
||||
return !isHidden;
|
||||
});
|
||||
|
||||
console.log("📊 Feed after filtering:", filteredFeed.length);
|
||||
|
||||
// 5️⃣ Récupérer tous les groupes mentionnés dans le feed pour les populer
|
||||
const allGroupIds = [...new Set([...groupIds, ...friendsGroupIds])];
|
||||
const allGroups = await strapi.db.query("api::group.group").findMany({
|
||||
@@ -220,7 +241,7 @@ export default factories.createCoreController(
|
||||
const groupsMap = new Map(allGroups.map((group) => [group.id, group]));
|
||||
|
||||
// 6️⃣ Enrichir le feed avec les propriétés friend, member, contactFollow et group
|
||||
const enrichedFeed = feed.map((postOwnership) => {
|
||||
const enrichedFeed = filteredFeed.map((postOwnership) => {
|
||||
const authorId = postOwnership.author?.id;
|
||||
const contextType = postOwnership.contextType;
|
||||
const contextId = postOwnership.contextId;
|
||||
@@ -346,16 +367,22 @@ export default factories.createCoreController(
|
||||
}
|
||||
|
||||
// Check if post is already saved by this user
|
||||
const whereClause: any = {
|
||||
post: postId,
|
||||
contextType: "user",
|
||||
contextId: user.id,
|
||||
relation: "saved",
|
||||
};
|
||||
|
||||
// Only add author filter if authorId is valid (not 0 for system posts)
|
||||
if (authorId && authorId !== 0) {
|
||||
whereClause.author = authorId;
|
||||
}
|
||||
|
||||
const existingSavedPost = await strapi.db
|
||||
.query("api::post-ownership.post-ownership")
|
||||
.findOne({
|
||||
where: {
|
||||
post: postId,
|
||||
author: authorId,
|
||||
contextType: "user",
|
||||
contextId: user.id,
|
||||
relation: "saved",
|
||||
},
|
||||
where: whereClause,
|
||||
});
|
||||
|
||||
if (existingSavedPost) {
|
||||
@@ -364,26 +391,31 @@ export default factories.createCoreController(
|
||||
}
|
||||
|
||||
// Create postOwnership entry to mark post as saved
|
||||
const savedPostData: any = {
|
||||
post: postId,
|
||||
contextType: "user",
|
||||
contextId: user.id,
|
||||
relation: "saved",
|
||||
};
|
||||
|
||||
// Only add author if authorId is valid (not 0 for system posts)
|
||||
if (authorId && authorId !== 0) {
|
||||
savedPostData.author = authorId;
|
||||
}
|
||||
|
||||
const savedPostOwnership = await strapi.db
|
||||
.query("api::post-ownership.post-ownership")
|
||||
.create({
|
||||
data: {
|
||||
post: postId,
|
||||
author: authorId,
|
||||
contextType: "user",
|
||||
contextId: user.id,
|
||||
relation: "saved",
|
||||
},
|
||||
data: savedPostData,
|
||||
});
|
||||
|
||||
console.log("✅ Post marked as saved:", savedPostOwnership);
|
||||
|
||||
// Get count of saved posts for this user
|
||||
// Get count of saved posts for this user (all saved posts, regardless of author)
|
||||
const savedPostsCount = await strapi.db
|
||||
.query("api::post-ownership.post-ownership")
|
||||
.count({
|
||||
where: {
|
||||
author: authorId,
|
||||
contextType: "user",
|
||||
contextId: user.id,
|
||||
relation: "saved",
|
||||
@@ -444,12 +476,11 @@ export default factories.createCoreController(
|
||||
|
||||
console.log("✅ Post removed from saved posts successfully");
|
||||
|
||||
// Get updated count of saved posts for this user
|
||||
// Get updated count of saved posts for this user (all saved posts, regardless of author)
|
||||
const savedPostsCount = await strapi.db
|
||||
.query("api::post-ownership.post-ownership")
|
||||
.count({
|
||||
where: {
|
||||
author: user.id,
|
||||
contextType: "user",
|
||||
contextId: user.id,
|
||||
relation: "saved",
|
||||
@@ -475,6 +506,7 @@ export default factories.createCoreController(
|
||||
|
||||
console.log("✅ User authenticated:", user.id);
|
||||
const postId = parseInt(String(ctx.params.id));
|
||||
const authorId = parseInt(String(ctx.query.authorId));
|
||||
|
||||
if (isNaN(postId)) {
|
||||
return ctx.badRequest("Invalid post ID");
|
||||
@@ -487,16 +519,22 @@ export default factories.createCoreController(
|
||||
}
|
||||
|
||||
// Check if post is already hidden by this user
|
||||
const whereClauseHidden: any = {
|
||||
post: postId,
|
||||
contextType: "user",
|
||||
contextId: user.id,
|
||||
relation: "hidden",
|
||||
};
|
||||
|
||||
// Only add author filter if authorId is valid (not 0 for system posts)
|
||||
if (authorId && authorId !== 0) {
|
||||
whereClauseHidden.author = authorId;
|
||||
}
|
||||
|
||||
const existingHiddenPost = await strapi.db
|
||||
.query("api::post-ownership.post-ownership")
|
||||
.findOne({
|
||||
where: {
|
||||
post: postId,
|
||||
author: user.id,
|
||||
contextType: "user",
|
||||
contextId: user.id,
|
||||
relation: "hidden",
|
||||
},
|
||||
where: whereClauseHidden,
|
||||
});
|
||||
|
||||
if (existingHiddenPost) {
|
||||
@@ -505,16 +543,22 @@ export default factories.createCoreController(
|
||||
}
|
||||
|
||||
// Create postOwnership entry to mark post as hidden
|
||||
const hiddenPostData: any = {
|
||||
post: postId,
|
||||
contextType: "user",
|
||||
contextId: user.id,
|
||||
relation: "hidden",
|
||||
};
|
||||
|
||||
// Only add author if authorId is valid (not 0 for system posts)
|
||||
if (authorId && authorId !== 0) {
|
||||
hiddenPostData.author = authorId;
|
||||
}
|
||||
|
||||
const hiddenPostOwnership = await strapi.db
|
||||
.query("api::post-ownership.post-ownership")
|
||||
.create({
|
||||
data: {
|
||||
post: postId,
|
||||
author: user.id,
|
||||
contextType: "user",
|
||||
contextId: user.id,
|
||||
relation: "hidden",
|
||||
},
|
||||
data: hiddenPostData,
|
||||
});
|
||||
|
||||
console.log("✅ Post marked as hidden:", hiddenPostOwnership);
|
||||
@@ -550,12 +594,12 @@ export default factories.createCoreController(
|
||||
}
|
||||
|
||||
// Find the hidden post ownership entry
|
||||
// Note: We search by contextId (the user who hid the post), not by author (the post's author)
|
||||
const hiddenPostOwnership = await strapi.db
|
||||
.query("api::post-ownership.post-ownership")
|
||||
.findOne({
|
||||
where: {
|
||||
post: postId,
|
||||
author: user.id,
|
||||
contextType: "user",
|
||||
contextId: user.id,
|
||||
relation: "hidden",
|
||||
|
||||
@@ -20,7 +20,7 @@ export default {
|
||||
handler: "post.hidePost",
|
||||
},
|
||||
{
|
||||
method: "DELETE",
|
||||
method: "POST",
|
||||
path: "/posts/:id/hide",
|
||||
handler: "post.removeHiddenPost",
|
||||
},
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"name": "Apache 2.0",
|
||||
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
},
|
||||
"x-generation-date": "2025-10-03T20:42:58.084Z"
|
||||
"x-generation-date": "2025-10-05T19:46:56.298Z"
|
||||
},
|
||||
"x-strapi-config": {
|
||||
"plugins": [
|
||||
|
||||
Reference in New Issue
Block a user