({
channelId,
anonymize,
anonymizeUsers,
page,
}: {
channelId: string;
anonymize: AnonymizeType;
anonymizeUsers: boolean;
page?: string;
})
| 127 | } |
| 128 | |
| 129 | async function getThreads({ |
| 130 | channelId, |
| 131 | anonymize, |
| 132 | anonymizeUsers, |
| 133 | page, |
| 134 | }: { |
| 135 | channelId: string; |
| 136 | anonymize: AnonymizeType; |
| 137 | anonymizeUsers: boolean; |
| 138 | page?: string; |
| 139 | }) { |
| 140 | if (!!page) { |
| 141 | const threads = ( |
| 142 | await findThreadsByCursor({ |
| 143 | channelIds: [channelId], |
| 144 | page: parsePage(page), |
| 145 | anonymize, |
| 146 | anonymizeUsers, |
| 147 | }) |
| 148 | ).sort(sortBySentAtAsc); |
| 149 | |
| 150 | return { |
| 151 | nextCursor: { |
| 152 | next: null, |
| 153 | prev: null, |
| 154 | }, |
| 155 | threads, |
| 156 | }; |
| 157 | } |
| 158 | |
| 159 | const { sort, direction, sentAt } = decodeCursor(undefined); |
| 160 | |
| 161 | const threads = ( |
| 162 | await findThreadsByCursor({ |
| 163 | channelIds: [channelId], |
| 164 | sentAt, |
| 165 | sort, |
| 166 | direction, |
| 167 | anonymize, |
| 168 | anonymizeUsers, |
| 169 | }) |
| 170 | ).sort(sortBySentAtAsc); |
| 171 | |
| 172 | const nextCursor = await buildCursor({ |
| 173 | sort, |
| 174 | direction, |
| 175 | sentAt, |
| 176 | pathCursor: page, |
| 177 | total: threads.length, |
| 178 | prevDate: threads[0]?.sentAt, |
| 179 | nextDate: threads[threads.length - 1]?.sentAt, |
| 180 | }); |
| 181 | return { nextCursor, threads }; |
| 182 | } |
| 183 | |
| 184 | function isPageNotValid(page: string, pages: number | null) { |
| 185 | return !isPageValid(page, pages); |
no test coverage detected