@@ -3,6 +3,7 @@ import { z } from "zod";
3
3
import { LocalFileData , RemoteFileData , ZodRemoteFileData } from "./files" ;
4
4
import { Post } from "../../api/feed/v1/feed" ;
5
5
import { PostResult } from "../../contracts-clients/teritori-social-feed/TeritoriSocialFeed.types" ;
6
+ import { zodTryParseJSON } from "../sanitize" ;
6
7
7
8
export type OnPressReplyType = ( replyTo : ReplyToType ) => void ;
8
9
@@ -135,3 +136,38 @@ export type ReplyToType = {
135
136
yOffsetValue ?: number ;
136
137
parentId ?: string ;
137
138
} ;
139
+
140
+ type GroupPostCategoryType = Omit <
141
+ PostCategory ,
142
+ PostCategory . Video | PostCategory . Article | PostCategory . MusicAudio
143
+ > ;
144
+
145
+ const postCategoriesGrouped : GroupPostCategoryType [ ] = [
146
+ PostCategory . Reaction ,
147
+ PostCategory . Comment ,
148
+ PostCategory . Normal ,
149
+ PostCategory . Picture ,
150
+ PostCategory . Question ,
151
+ PostCategory . BriefForStableDiffusion ,
152
+ PostCategory . Flagged ,
153
+ PostCategory . VideoNote ,
154
+ PostCategory . Audio ,
155
+ ] ;
156
+
157
+ const socialFeedSchemaMap : Record < PostCategory , z . ZodTypeAny > = {
158
+ [ PostCategory . Video ] : ZodSocialFeedVideoMetadata ,
159
+ [ PostCategory . Article ] : ZodSocialFeedArticleMetadata ,
160
+ [ PostCategory . MusicAudio ] : ZodSocialFeedTrackMetadata ,
161
+ ...Object . fromEntries (
162
+ postCategoriesGrouped . map ( ( cat ) => [ cat , ZodSocialFeedPostMetadata ] ) ,
163
+ ) ,
164
+ } ;
165
+
166
+ export const parseSocialFeedMetadata = (
167
+ category : PostCategory ,
168
+ metadata : string ,
169
+ ) => {
170
+ const zodType = socialFeedSchemaMap [ category ] ;
171
+
172
+ return zodTryParseJSON ( zodType , metadata ) ;
173
+ } ;
0 commit comments