( parentCommentId: CommentId, text: string, authorId: UserId, )
| 790 | } |
| 791 | |
| 792 | export async function insertNoteChildComment( |
| 793 | parentCommentId: CommentId, |
| 794 | text: string, |
| 795 | authorId: UserId, |
| 796 | ) { |
| 797 | const parentCommentDbId = fromBase64Url(parentCommentId) |
| 798 | const parent = await db |
| 799 | .selectFrom('noteComment') |
| 800 | .select(['level', 'noteId']) |
| 801 | .where('id', '=', parentCommentDbId) |
| 802 | .executeTakeFirst() |
| 803 | if (parent == null) throwExp(`Comment ${parentCommentId} not found.`) |
| 804 | await db.transaction().execute( |
| 805 | async (tx) => |
| 806 | await Promise.all([ |
| 807 | tx |
| 808 | .updateTable('note') |
| 809 | .set({ |
| 810 | commentsCount: (x) => sql`${x.ref('commentsCount')} + 1`, |
| 811 | }) |
| 812 | .where('note.id', '=', parent.noteId) |
| 813 | .execute(), |
| 814 | await tx |
| 815 | .insertInto('noteComment') |
| 816 | .values({ |
| 817 | id: unhex(hexId()), |
| 818 | authorId, |
| 819 | level: parent.level + 1, |
| 820 | noteId: parent.noteId, |
| 821 | votes: '', |
| 822 | text, |
| 823 | parentId: parentCommentDbId, |
| 824 | }) |
| 825 | .execute(), |
| 826 | ]), |
| 827 | ) |
| 828 | } |
| 829 | |
| 830 | export async function userOwnsNoteAndHasMedia( |
| 831 | ids: RemoteNoteId[], |
no test coverage detected