0.11.4 : change on feed and save/hide
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "harmony-back",
|
"name": "harmony-back",
|
||||||
"version": "0.11.3",
|
"version": "0.11.4",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "A Strapi application",
|
"description": "A Strapi application",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -177,9 +177,7 @@ export default factories.createCoreController(
|
|||||||
.findMany({
|
.findMany({
|
||||||
where: {
|
where: {
|
||||||
$or: [
|
$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: [
|
$or: [
|
||||||
{ author: { id: friendIds } }, // Posts de mes amis
|
{ author: { id: friendIds } }, // Posts de mes amis
|
||||||
@@ -190,26 +188,49 @@ export default factories.createCoreController(
|
|||||||
{ contextType: "system" }, // Posts système
|
{ contextType: "system" }, // Posts système
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{ relation: { $ne: "hidden" } }, // exclure les posts masqués pour les posts réguliers
|
|
||||||
],
|
|
||||||
},
|
|
||||||
// Posts sauvés par l'utilisateur
|
// Posts sauvés par l'utilisateur
|
||||||
{
|
{
|
||||||
contextType: "user",
|
contextType: "user",
|
||||||
contextId: parseInt(userId),
|
contextId: parseInt(userId),
|
||||||
relation: "saved",
|
relation: "saved",
|
||||||
},
|
},
|
||||||
// Posts cachés par l'utilisateur
|
|
||||||
{
|
|
||||||
contextType: "user",
|
|
||||||
contextId: parseInt(userId),
|
|
||||||
relation: "hidden",
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
...queryParams,
|
...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
|
// 5️⃣ Récupérer tous les groupes mentionnés dans le feed pour les populer
|
||||||
const allGroupIds = [...new Set([...groupIds, ...friendsGroupIds])];
|
const allGroupIds = [...new Set([...groupIds, ...friendsGroupIds])];
|
||||||
const allGroups = await strapi.db.query("api::group.group").findMany({
|
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]));
|
const groupsMap = new Map(allGroups.map((group) => [group.id, group]));
|
||||||
|
|
||||||
// 6️⃣ Enrichir le feed avec les propriétés friend, member, contactFollow et 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 authorId = postOwnership.author?.id;
|
||||||
const contextType = postOwnership.contextType;
|
const contextType = postOwnership.contextType;
|
||||||
const contextId = postOwnership.contextId;
|
const contextId = postOwnership.contextId;
|
||||||
@@ -346,16 +367,22 @@ export default factories.createCoreController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if post is already saved by this user
|
// Check if post is already saved by this user
|
||||||
const existingSavedPost = await strapi.db
|
const whereClause: any = {
|
||||||
.query("api::post-ownership.post-ownership")
|
|
||||||
.findOne({
|
|
||||||
where: {
|
|
||||||
post: postId,
|
post: postId,
|
||||||
author: authorId,
|
|
||||||
contextType: "user",
|
contextType: "user",
|
||||||
contextId: user.id,
|
contextId: user.id,
|
||||||
relation: "saved",
|
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: whereClause,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (existingSavedPost) {
|
if (existingSavedPost) {
|
||||||
@@ -364,26 +391,31 @@ export default factories.createCoreController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create postOwnership entry to mark post as saved
|
// Create postOwnership entry to mark post as saved
|
||||||
const savedPostOwnership = await strapi.db
|
const savedPostData: any = {
|
||||||
.query("api::post-ownership.post-ownership")
|
|
||||||
.create({
|
|
||||||
data: {
|
|
||||||
post: postId,
|
post: postId,
|
||||||
author: authorId,
|
|
||||||
contextType: "user",
|
contextType: "user",
|
||||||
contextId: user.id,
|
contextId: user.id,
|
||||||
relation: "saved",
|
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: savedPostData,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("✅ Post marked as saved:", savedPostOwnership);
|
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
|
const savedPostsCount = await strapi.db
|
||||||
.query("api::post-ownership.post-ownership")
|
.query("api::post-ownership.post-ownership")
|
||||||
.count({
|
.count({
|
||||||
where: {
|
where: {
|
||||||
author: authorId,
|
|
||||||
contextType: "user",
|
contextType: "user",
|
||||||
contextId: user.id,
|
contextId: user.id,
|
||||||
relation: "saved",
|
relation: "saved",
|
||||||
@@ -444,12 +476,11 @@ export default factories.createCoreController(
|
|||||||
|
|
||||||
console.log("✅ Post removed from saved posts successfully");
|
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
|
const savedPostsCount = await strapi.db
|
||||||
.query("api::post-ownership.post-ownership")
|
.query("api::post-ownership.post-ownership")
|
||||||
.count({
|
.count({
|
||||||
where: {
|
where: {
|
||||||
author: user.id,
|
|
||||||
contextType: "user",
|
contextType: "user",
|
||||||
contextId: user.id,
|
contextId: user.id,
|
||||||
relation: "saved",
|
relation: "saved",
|
||||||
@@ -475,6 +506,7 @@ export default factories.createCoreController(
|
|||||||
|
|
||||||
console.log("✅ User authenticated:", user.id);
|
console.log("✅ User authenticated:", user.id);
|
||||||
const postId = parseInt(String(ctx.params.id));
|
const postId = parseInt(String(ctx.params.id));
|
||||||
|
const authorId = parseInt(String(ctx.query.authorId));
|
||||||
|
|
||||||
if (isNaN(postId)) {
|
if (isNaN(postId)) {
|
||||||
return ctx.badRequest("Invalid post ID");
|
return ctx.badRequest("Invalid post ID");
|
||||||
@@ -487,16 +519,22 @@ export default factories.createCoreController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if post is already hidden by this user
|
// Check if post is already hidden by this user
|
||||||
const existingHiddenPost = await strapi.db
|
const whereClauseHidden: any = {
|
||||||
.query("api::post-ownership.post-ownership")
|
|
||||||
.findOne({
|
|
||||||
where: {
|
|
||||||
post: postId,
|
post: postId,
|
||||||
author: user.id,
|
|
||||||
contextType: "user",
|
contextType: "user",
|
||||||
contextId: user.id,
|
contextId: user.id,
|
||||||
relation: "hidden",
|
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: whereClauseHidden,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (existingHiddenPost) {
|
if (existingHiddenPost) {
|
||||||
@@ -505,16 +543,22 @@ export default factories.createCoreController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create postOwnership entry to mark post as hidden
|
// Create postOwnership entry to mark post as hidden
|
||||||
const hiddenPostOwnership = await strapi.db
|
const hiddenPostData: any = {
|
||||||
.query("api::post-ownership.post-ownership")
|
|
||||||
.create({
|
|
||||||
data: {
|
|
||||||
post: postId,
|
post: postId,
|
||||||
author: user.id,
|
|
||||||
contextType: "user",
|
contextType: "user",
|
||||||
contextId: user.id,
|
contextId: user.id,
|
||||||
relation: "hidden",
|
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: hiddenPostData,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("✅ Post marked as hidden:", hiddenPostOwnership);
|
console.log("✅ Post marked as hidden:", hiddenPostOwnership);
|
||||||
@@ -550,12 +594,12 @@ export default factories.createCoreController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the hidden post ownership entry
|
// 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
|
const hiddenPostOwnership = await strapi.db
|
||||||
.query("api::post-ownership.post-ownership")
|
.query("api::post-ownership.post-ownership")
|
||||||
.findOne({
|
.findOne({
|
||||||
where: {
|
where: {
|
||||||
post: postId,
|
post: postId,
|
||||||
author: user.id,
|
|
||||||
contextType: "user",
|
contextType: "user",
|
||||||
contextId: user.id,
|
contextId: user.id,
|
||||||
relation: "hidden",
|
relation: "hidden",
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export default {
|
|||||||
handler: "post.hidePost",
|
handler: "post.hidePost",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
method: "DELETE",
|
method: "POST",
|
||||||
path: "/posts/:id/hide",
|
path: "/posts/:id/hide",
|
||||||
handler: "post.removeHiddenPost",
|
handler: "post.removeHiddenPost",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
"name": "Apache 2.0",
|
"name": "Apache 2.0",
|
||||||
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
|
"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": {
|
"x-strapi-config": {
|
||||||
"plugins": [
|
"plugins": [
|
||||||
|
|||||||
Reference in New Issue
Block a user