worker: Flag messages processed by outgoing bot.

This commit updates outgoing bots to mark messages they process as read.
Since the service bots have their own `UserMessage` rows, this change
enables us to track whether the bot has in fact processed the message by
adding the `read` flag to their `UserMessage`.
This commit is contained in:
PieterCK
2024-11-20 13:38:38 +07:00
committed by Tim Abbott
parent 25f64a9a67
commit cacd6bb88c
3 changed files with 39 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ from django.conf import settings
from django.utils.translation import gettext as _
from zulip_bots.lib import BotIdentity, RateLimit
from zerver.actions.message_flags import do_update_message_flags
from zerver.actions.message_send import (
internal_send_group_direct_message,
internal_send_private_message,
@@ -153,3 +154,10 @@ class EmbeddedBotHandler:
def quit(self, message: str = "") -> None:
raise EmbeddedBotQuitError(message)
def do_flag_service_bots_messages_as_processed(
bot_profile: UserProfile, message_ids: list[int]
) -> None:
assert bot_profile.is_bot is True and bot_profile.bot_type in UserProfile.SERVICE_BOT_TYPES
do_update_message_flags(bot_profile, "add", "read", message_ids)