MCPcopy Index your code
hub / github.com/AnswerOverflow/AnswerOverflow / findManyChannelsById

Function findManyChannelsById

packages/core/src/channel.ts:178–218  ·  view source on GitHub ↗
(
	ids: string[],
	opts: {
		includeMessageCount?: boolean;
	} = {},
)

Source from the content-addressed store, hash-verified

176}
177
178export async function findManyChannelsById(
179 ids: string[],
180 opts: {
181 includeMessageCount?: boolean;
182 } = {},
183): Promise<ChannelWithFlags[]> {
184 if (ids.length === 0) return Promise.resolve([]);
185 const data = await dbReplica.query.dbChannels.findMany({
186 where: inArray(dbChannels.id, ids),
187 });
188 const withFlags = data.map(addFlagsToChannel);
189 let threadMessageCountLookup: Map<string, number | undefined> | undefined =
190 undefined;
191 const isThreadType = (t: ChannelType) =>
192 t === ChannelType.PublicThread ||
193 t === ChannelType.PrivateThread ||
194 t === ChannelType.AnnouncementThread;
195 if (opts.includeMessageCount) {
196 const threadIds = withFlags
197 .filter((c) => isThreadType(c.type))
198 .map((c) => c.id);
199 const threadMessageCounts = await findManyChannelMessagesCounts(threadIds);
200 threadMessageCountLookup = new Map(
201 threadMessageCounts.map((x) => [x.channelId, x.count]),
202 );
203 }
204 return withFlags.map((c) => {
205 let messageCount: number | undefined = undefined;
206 if (opts.includeMessageCount) {
207 if (isThreadType(c.type)) {
208 messageCount = threadMessageCountLookup?.get(c.id);
209 } else {
210 messageCount = NUMBER_OF_CHANNEL_MESSAGES_TO_LOAD;
211 }
212 }
213 return {
214 ...c,
215 messageCount,
216 };
217 });
218}
219
220export async function createChannel(data: z.infer<typeof zChannelCreate>) {
221 const combinedData = applyChannelSettingsChangesSideEffects({

Callers 5

channel.test.tsFile · 0.90
listPublicThreadsFunction · 0.90
searchMessagesFunction · 0.90
dashboard.tsFile · 0.90
upsertManyChannelsFunction · 0.85

Calls 2

isThreadTypeFunction · 0.85

Tested by

no test coverage detected