({
channelId,
anonymizeUsers,
anonymize,
page,
}: {
channelId: string;
anonymizeUsers: boolean;
anonymize: AnonymizeType;
page?: string;
})
| 97 | ); |
| 98 | |
| 99 | async function getThreads({ |
| 100 | channelId, |
| 101 | anonymizeUsers, |
| 102 | anonymize, |
| 103 | page, |
| 104 | }: { |
| 105 | channelId: string; |
| 106 | anonymizeUsers: boolean; |
| 107 | anonymize: AnonymizeType; |
| 108 | page?: string; |
| 109 | }) { |
| 110 | if (!!page) { |
| 111 | const threads = ( |
| 112 | await findThreadsByCursor({ |
| 113 | channelIds: [channelId], |
| 114 | page: parsePage(page), |
| 115 | anonymize, |
| 116 | anonymizeUsers, |
| 117 | }) |
| 118 | ).sort(sortBySentAtAsc); |
| 119 | |
| 120 | return { |
| 121 | nextCursor: { |
| 122 | next: null, |
| 123 | prev: null, |
| 124 | }, |
| 125 | threads, |
| 126 | }; |
| 127 | } |
| 128 | |
| 129 | const { sort, direction, sentAt } = decodeCursor(undefined); |
| 130 | |
| 131 | const threads = ( |
| 132 | await findThreadsByCursor({ |
| 133 | channelIds: [channelId], |
| 134 | sentAt, |
| 135 | sort, |
| 136 | direction, |
| 137 | anonymize, |
| 138 | anonymizeUsers, |
| 139 | }) |
| 140 | ).sort(sortBySentAtAsc); |
| 141 | |
| 142 | const nextCursor = await buildCursor({ |
| 143 | sort, |
| 144 | direction, |
| 145 | sentAt, |
| 146 | pathCursor: page, |
| 147 | total: threads.length, |
| 148 | prevDate: threads[0].sentAt, |
| 149 | nextDate: threads[threads.length - 1].sentAt, |
| 150 | }); |
| 151 | return { nextCursor, threads }; |
| 152 | } |
| 153 | |
| 154 | function parsePage(page: string): number | undefined { |
| 155 | try { |
no test coverage detected