From f2115fbe5d46d6486abc21431629d27485472d08 Mon Sep 17 00:00:00 2001 From: sujal-into Date: Wed, 20 Nov 2024 17:53:00 +0545 Subject: [PATCH 1/7] fix: made keys for social post optional while parsing except title --- packages/components/socialFeed/Map/Map.web.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/components/socialFeed/Map/Map.web.tsx b/packages/components/socialFeed/Map/Map.web.tsx index e1ef7c6534..628bdbc747 100644 --- a/packages/components/socialFeed/Map/Map.web.tsx +++ b/packages/components/socialFeed/Map/Map.web.tsx @@ -134,9 +134,11 @@ export const Map: FC = ({ const markers: MarkerPopup[] = useMemo(() => { if (!posts) return []; const results: MarkerPopup[] = []; - posts.forEach((post, index) => { + posts.forEach((post) => { const metadata = zodTryParseJSON( - ZodSocialFeedPostMetadata, + ZodSocialFeedPostMetadata.partial().merge( + ZodSocialFeedPostMetadata.pick({ title: true }), + ), post.metadata, ); if (!metadata?.location) return; From 3a16113c647d667b39245f99481859b42872c99b Mon Sep 17 00:00:00 2001 From: sujal-into Date: Thu, 21 Nov 2024 13:28:24 +0545 Subject: [PATCH 2/7] fix: added a function to parse different social feed categories metadata --- .../components/socialFeed/Map/Map.web.tsx | 10 ++---- packages/utils/types/feed.ts | 36 +++++++++++++++++++ 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/packages/components/socialFeed/Map/Map.web.tsx b/packages/components/socialFeed/Map/Map.web.tsx index 628bdbc747..df43a88c67 100644 --- a/packages/components/socialFeed/Map/Map.web.tsx +++ b/packages/components/socialFeed/Map/Map.web.tsx @@ -34,9 +34,9 @@ import { import { zodTryParseJSON } from "@/utils/sanitize"; import { CustomLatLngExpression, + parseSocialFeedMetadata, PostCategory, zodSocialFeedCommonMetadata, - ZodSocialFeedPostMetadata, } from "@/utils/types/feed"; interface MarkerPopup { @@ -135,12 +135,8 @@ export const Map: FC = ({ if (!posts) return []; const results: MarkerPopup[] = []; posts.forEach((post) => { - const metadata = zodTryParseJSON( - ZodSocialFeedPostMetadata.partial().merge( - ZodSocialFeedPostMetadata.pick({ title: true }), - ), - post.metadata, - ); + const metadata = parseSocialFeedMetadata(post.category, post.metadata); + if (!metadata?.location) return; results.push({ position: metadata.location, diff --git a/packages/utils/types/feed.ts b/packages/utils/types/feed.ts index b80f2d679b..3f1ad1fa88 100644 --- a/packages/utils/types/feed.ts +++ b/packages/utils/types/feed.ts @@ -3,6 +3,7 @@ import { z } from "zod"; import { LocalFileData, RemoteFileData, ZodRemoteFileData } from "./files"; import { Post } from "../../api/feed/v1/feed"; import { PostResult } from "../../contracts-clients/teritori-social-feed/TeritoriSocialFeed.types"; +import { zodTryParseJSON } from "../sanitize"; export type OnPressReplyType = (replyTo: ReplyToType) => void; @@ -135,3 +136,38 @@ export type ReplyToType = { yOffsetValue?: number; parentId?: string; }; + +type GroupPostCategoryType = Omit< + PostCategory, + PostCategory.Video | PostCategory.Article | PostCategory.MusicAudio +>; + +const postCategoriesGrouped: GroupPostCategoryType[] = [ + PostCategory.Reaction, + PostCategory.Comment, + PostCategory.Normal, + PostCategory.Picture, + PostCategory.Question, + PostCategory.BriefForStableDiffusion, + PostCategory.Flagged, + PostCategory.VideoNote, + PostCategory.Audio, +]; + +const socialFeedSchemaMap: Record = { + [PostCategory.Video]: ZodSocialFeedVideoMetadata, + [PostCategory.Article]: ZodSocialFeedArticleMetadata, + [PostCategory.MusicAudio]: ZodSocialFeedTrackMetadata, + ...Object.fromEntries( + postCategoriesGrouped.map((cat) => [cat, ZodSocialFeedPostMetadata]), + ), +}; + +export const parseSocialFeedMetadata = ( + category: PostCategory, + metadata: string, +) => { + const zodType = socialFeedSchemaMap[category]; + + return zodTryParseJSON(zodType, metadata); +}; From ece2bac104ffb165579f2160a7aa6398eb9b747d Mon Sep 17 00:00:00 2001 From: sujal-into Date: Thu, 21 Nov 2024 15:14:45 +0545 Subject: [PATCH 3/7] fix: used switch case to parse different social feed metadata --- packages/utils/types/feed.ts | 39 +++++++++--------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/packages/utils/types/feed.ts b/packages/utils/types/feed.ts index 3f1ad1fa88..d2616144d6 100644 --- a/packages/utils/types/feed.ts +++ b/packages/utils/types/feed.ts @@ -137,37 +137,18 @@ export type ReplyToType = { parentId?: string; }; -type GroupPostCategoryType = Omit< - PostCategory, - PostCategory.Video | PostCategory.Article | PostCategory.MusicAudio ->; - -const postCategoriesGrouped: GroupPostCategoryType[] = [ - PostCategory.Reaction, - PostCategory.Comment, - PostCategory.Normal, - PostCategory.Picture, - PostCategory.Question, - PostCategory.BriefForStableDiffusion, - PostCategory.Flagged, - PostCategory.VideoNote, - PostCategory.Audio, -]; - -const socialFeedSchemaMap: Record = { - [PostCategory.Video]: ZodSocialFeedVideoMetadata, - [PostCategory.Article]: ZodSocialFeedArticleMetadata, - [PostCategory.MusicAudio]: ZodSocialFeedTrackMetadata, - ...Object.fromEntries( - postCategoriesGrouped.map((cat) => [cat, ZodSocialFeedPostMetadata]), - ), -}; - export const parseSocialFeedMetadata = ( category: PostCategory, metadata: string, ) => { - const zodType = socialFeedSchemaMap[category]; - - return zodTryParseJSON(zodType, metadata); + switch (category) { + case PostCategory.Video: + return zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata); + case PostCategory.Article: + return zodTryParseJSON(ZodSocialFeedPostMetadata, metadata); + case PostCategory.MusicAudio: + return zodTryParseJSON(ZodSocialFeedTrackMetadata, metadata); + default: + return zodTryParseJSON(ZodSocialFeedPostMetadata, metadata); + } }; From 7a18debc2c661ff9ad620a0f31ea5963d3626f97 Mon Sep 17 00:00:00 2001 From: sujal-into <155436948+sujal-into@users.noreply.github.com> Date: Fri, 22 Nov 2024 09:42:12 +0545 Subject: [PATCH 4/7] fix: Changed to feedArticle metadata for article type Co-authored-by: n0izn0iz --- packages/utils/types/feed.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/utils/types/feed.ts b/packages/utils/types/feed.ts index d2616144d6..9007754c00 100644 --- a/packages/utils/types/feed.ts +++ b/packages/utils/types/feed.ts @@ -145,7 +145,7 @@ export const parseSocialFeedMetadata = ( case PostCategory.Video: return zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata); case PostCategory.Article: - return zodTryParseJSON(ZodSocialFeedPostMetadata, metadata); + return zodTryParseJSON(ZodSocialFeedArticleMetadata, metadata); case PostCategory.MusicAudio: return zodTryParseJSON(ZodSocialFeedTrackMetadata, metadata); default: From ac6d3b508393a16792ab2271c2ebd51cbbf191b7 Mon Sep 17 00:00:00 2001 From: sujal-into <155436948+sujal-into@users.noreply.github.com> Date: Fri, 22 Nov 2024 09:44:35 +0545 Subject: [PATCH 5/7] default social media parse to common metadata Co-authored-by: n0izn0iz --- packages/utils/types/feed.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/utils/types/feed.ts b/packages/utils/types/feed.ts index 9007754c00..828cc24eb1 100644 --- a/packages/utils/types/feed.ts +++ b/packages/utils/types/feed.ts @@ -149,6 +149,6 @@ export const parseSocialFeedMetadata = ( case PostCategory.MusicAudio: return zodTryParseJSON(ZodSocialFeedTrackMetadata, metadata); default: - return zodTryParseJSON(ZodSocialFeedPostMetadata, metadata); + return zodTryParseJSON(ZodSocialFeedCommonMetadata, metadata); } }; From 8a0ebc639cf8ad35aee3d70b4fa098f3a0bfd133 Mon Sep 17 00:00:00 2001 From: sujal-into Date: Fri, 22 Nov 2024 10:48:10 +0545 Subject: [PATCH 6/7] fix: feed post metadata check for video and article --- packages/utils/types/feed.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/utils/types/feed.ts b/packages/utils/types/feed.ts index 828cc24eb1..ef73016112 100644 --- a/packages/utils/types/feed.ts +++ b/packages/utils/types/feed.ts @@ -143,12 +143,20 @@ export const parseSocialFeedMetadata = ( ) => { switch (category) { case PostCategory.Video: - return zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata); + return ( + zodTryParseJSON(ZodSocialFeedPostMetadata, metadata) || + zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata) + ); case PostCategory.Article: - return zodTryParseJSON(ZodSocialFeedArticleMetadata, metadata); + return ( + zodTryParseJSON(ZodSocialFeedPostMetadata, metadata) || + zodTryParseJSON(ZodSocialFeedArticleMetadata, metadata) + ); case PostCategory.MusicAudio: return zodTryParseJSON(ZodSocialFeedTrackMetadata, metadata); + case PostCategory.Normal: + return zodTryParseJSON(ZodSocialFeedPostMetadata, metadata); default: - return zodTryParseJSON(ZodSocialFeedCommonMetadata, metadata); + return zodTryParseJSON(zodSocialFeedCommonMetadata, metadata); } }; From 0b9046c2de0b394297ca278952dff0b02b399731 Mon Sep 17 00:00:00 2001 From: sujal-into Date: Mon, 25 Nov 2024 09:47:46 +0545 Subject: [PATCH 7/7] fix: removed post metdata option from video and article type --- packages/utils/types/feed.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/utils/types/feed.ts b/packages/utils/types/feed.ts index ef73016112..5849da57db 100644 --- a/packages/utils/types/feed.ts +++ b/packages/utils/types/feed.ts @@ -143,15 +143,9 @@ export const parseSocialFeedMetadata = ( ) => { switch (category) { case PostCategory.Video: - return ( - zodTryParseJSON(ZodSocialFeedPostMetadata, metadata) || - zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata) - ); + return zodTryParseJSON(ZodSocialFeedVideoMetadata, metadata); case PostCategory.Article: - return ( - zodTryParseJSON(ZodSocialFeedPostMetadata, metadata) || - zodTryParseJSON(ZodSocialFeedArticleMetadata, metadata) - ); + return zodTryParseJSON(ZodSocialFeedArticleMetadata, metadata); case PostCategory.MusicAudio: return zodTryParseJSON(ZodSocialFeedTrackMetadata, metadata); case PostCategory.Normal: