| 2 | import { TypesenseThread } from './types'; |
| 3 | |
| 4 | export function serializer({ |
| 5 | thread, |
| 6 | is_public, |
| 7 | is_restrict, |
| 8 | accessible_to, |
| 9 | }: { |
| 10 | thread: SerializedThread; |
| 11 | is_public: boolean; |
| 12 | is_restrict: boolean; |
| 13 | accessible_to: string[]; |
| 14 | }): TypesenseThread { |
| 15 | return { |
| 16 | author_name: thread.messages.at(0)?.author?.displayName!, |
| 17 | body: thread.messages |
| 18 | .map((m) => m.body) |
| 19 | .filter((e) => !!e) |
| 20 | .join('\n'), |
| 21 | channel_name: thread.channel?.channelName!, |
| 22 | id: thread.id, |
| 23 | last_reply_at: Number(thread.lastReplyAt), |
| 24 | mentions_name: [ |
| 25 | ...new Set( |
| 26 | thread.messages |
| 27 | .map((m) => m.mentions.map((me) => me.displayName!).flat()) |
| 28 | .flat() |
| 29 | ), |
| 30 | ], |
| 31 | accountId: thread.channel?.accountId!, |
| 32 | is_public, |
| 33 | accessible_to, |
| 34 | is_restrict, |
| 35 | // on disk |
| 36 | thread: JSON.stringify(thread), |
| 37 | }; |
| 38 | } |