Clear the reading panel when its last message leaves
"Mark as Spam" moved the message but left it on screen. Two causes, both fixed generally rather than for this one action. `move_job` published message.changed without a thread_id, so the WS handler invalidated the message list but never the thread the user was reading — the panel had no reason to refetch. It now names the thread. And a thread whose last visible message has gone should not linger. MailLayout closes the panel when the open thread comes back empty, whoever emptied it — core action or plugin. `move_to_special` now also publishes the move immediately rather than waiting for the IMAP job, since a plugin acting on the user's behalf has no client-side handle to update optimistically the way the core endpoint's caller does. That exposed an ordering bug: the optimistic event reaches the passive-learning hook, which would re-teach the lesson /learn had just taught. /learn now records `learned` before moving, so the hook's dedup stands down — and records it with an upsert, because provider-filed spam has no verdict row of ours to update. One real mistake on the way: the event first reported the destination folder as the source, which would have made every move look like a no-op to anything reading the pair. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018SqJYt7jD7oUEkoY68sBZo
This commit is contained in:
@@ -254,10 +254,34 @@ class PluginActions:
|
||||
if dst is None or dst.id == msg.mailbox_id:
|
||||
return False
|
||||
dst_id, src_id = dst.id, msg.mailbox_id
|
||||
# The SOURCE folder's special-use, not the destination parameter:
|
||||
# consumers of message.changed read the pair as a transition, and
|
||||
# reporting them equal would erase the move.
|
||||
src_special = await session.scalar(
|
||||
select(Mailbox.special_use).where(Mailbox.id == src_id)
|
||||
)
|
||||
thread_id, dst_special = msg.thread_id, dst.special_use
|
||||
msg.mailbox_id = dst_id # optimistic, as the core endpoint does
|
||||
await session.commit()
|
||||
|
||||
await enqueue_job("move_job", str(message_id), str(dst_id), str(src_id))
|
||||
# Announce the optimistic state now rather than waiting for the IMAP move
|
||||
# to finish. The core's own move endpoint gets this for free — its caller
|
||||
# updates the UI from the response — but a plugin acting on the user's
|
||||
# behalf has no client-side handle, so without this the message lingers on
|
||||
# screen until the job lands. move_job publishes again when it does.
|
||||
await get_event_bus().publish(
|
||||
"message.changed",
|
||||
{
|
||||
"user_id": str(user_id),
|
||||
"message_id": str(message_id),
|
||||
"thread_id": str(thread_id) if thread_id else None,
|
||||
"mailbox_id": str(dst_id),
|
||||
"previous_mailbox_id": str(src_id),
|
||||
"special_use": dst_special,
|
||||
"previous_special_use": src_special,
|
||||
},
|
||||
)
|
||||
return True
|
||||
|
||||
async def trash(self, user_id: uuid.UUID, message_id: uuid.UUID) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user