* Handle a thread reply on a digest review message. * Processes editorial feedback and updates the draft. * Returns true if this was a digest review thread (handled), false otherwise.
( channelId: string, threadTs: string, messageText: string, userId: string, )
| 4493 | * Returns true if this was a digest review thread (handled), false otherwise. |
| 4494 | */ |
| 4495 | async function handleDigestEditReply( |
| 4496 | channelId: string, |
| 4497 | threadTs: string, |
| 4498 | messageText: string, |
| 4499 | userId: string, |
| 4500 | ): Promise<boolean> { |
| 4501 | const digest = await getDigestByReviewMessage(channelId, threadTs); |
| 4502 | if (!digest) { |
| 4503 | return false; |
| 4504 | } |
| 4505 | |
| 4506 | // Verify editor is an Editorial working group leader or member before any state changes |
| 4507 | const editorial = await workingGroupDb.getWorkingGroupBySlug('editorial'); |
| 4508 | if (!editorial) { |
| 4509 | logger.warn('Editorial working group not found for digest edit'); |
| 4510 | return true; |
| 4511 | } |
| 4512 | const isLeader = (editorial.leaders || []).some( |
| 4513 | (l) => l.user_id === userId || l.canonical_user_id === userId, |
| 4514 | ); |
| 4515 | const isMember = isLeader || await workingGroupDb.isMember(editorial.id, userId); |
| 4516 | if (!isMember) { |
| 4517 | if (boltApp) { |
| 4518 | await boltApp.client.chat.postMessage({ |
| 4519 | channel: channelId, |
| 4520 | thread_ts: threadTs, |
| 4521 | text: 'Only Editorial working group members can edit the digest.', |
| 4522 | }); |
| 4523 | } |
| 4524 | return true; |
| 4525 | } |
| 4526 | |
| 4527 | if (digest.status === 'skipped') { |
| 4528 | // Revive skipped digest so editorial can continue collaborating |
| 4529 | const revived = await revertToDraft(digest.id); |
| 4530 | if (!revived) { |
| 4531 | if (boltApp) { |
| 4532 | await boltApp.client.chat.postMessage({ |
| 4533 | channel: channelId, |
| 4534 | thread_ts: threadTs, |
| 4535 | text: `Could not reopen this digest. It may have already been sent.`, |
| 4536 | }); |
| 4537 | } |
| 4538 | return true; |
| 4539 | } |
| 4540 | if (boltApp) { |
| 4541 | await boltApp.client.chat.postMessage({ |
| 4542 | channel: channelId, |
| 4543 | thread_ts: threadTs, |
| 4544 | text: `Digest reopened as a draft. Applying your edit...`, |
| 4545 | }); |
| 4546 | } |
| 4547 | } else if (digest.status !== 'draft') { |
| 4548 | if (boltApp) { |
| 4549 | await boltApp.client.chat.postMessage({ |
| 4550 | channel: channelId, |
| 4551 | thread_ts: threadTs, |
| 4552 | text: `This digest has already been sent. Edits can only be made to drafts.`, |
no test coverage detected