MCPcopy Create free account
hub / github.com/sourcebot-dev/sourcebot / claimAnonymousChats

Function claimAnonymousChats

packages/web/src/features/chat/actions.ts:222–250  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

220 * Visibility is preserved so shared links continue to work.
221 */
222export const claimAnonymousChats = async () => sew(() =>
223 withAuth(async ({ org, user, prisma }) => {
224 const anonymousId = await getAnonymousId();
225
226 if (!anonymousId) {
227 return { claimed: 0 };
228 }
229
230 const result = await prisma.chat.updateMany({
231 where: {
232 orgId: org.id,
233 anonymousCreatorId: anonymousId,
234 createdById: null,
235 },
236 data: {
237 createdById: user.id,
238 anonymousCreatorId: null,
239 },
240 });
241
242 if (result.count > 0) {
243 captureEvent('wa_anonymous_chats_claimed', {
244 claimedCount: result.count,
245 });
246 }
247
248 return { claimed: result.count };
249 })
250);
251
252/**
253 * Duplicates a chat with all its messages.

Callers

nothing calls this directly

Calls 4

sewFunction · 0.90
withAuthFunction · 0.90
getAnonymousIdFunction · 0.90
captureEventFunction · 0.90

Tested by

no test coverage detected