()
| 220 | * Visibility is preserved so shared links continue to work. |
| 221 | */ |
| 222 | export 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. |
nothing calls this directly
no test coverage detected