mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
bots: Fix behavior for bots mentioned in PMs.
We've for a long time had the behavior that a bot mentioned in a stream message receives the notification, regardless of whether the bot was actually subscribed to the stream. Apparently, this behavior also triggered if you mentioned a bot in a private message (i.e. the bot would be delievered the private message and would probably respond unhelpfully in a new group private message thread with the PMs original recipients plus the bot). The fix for this bug is simple: To exclude this feature for private messages.
This commit is contained in:
@@ -1078,8 +1078,8 @@ def get_service_bot_events(sender: UserProfile, service_bot_tuples: List[Tuple[i
|
||||
if user_profile_id not in mentioned_user_ids and user_profile_id not in active_user_ids:
|
||||
continue
|
||||
|
||||
# Mention triggers, primarily for stream messages
|
||||
if user_profile_id in mentioned_user_ids:
|
||||
# Mention triggers, for stream messages
|
||||
if is_stream and user_profile_id in mentioned_user_ids:
|
||||
trigger = 'mention'
|
||||
# PM triggers for personal and huddle messsages
|
||||
elif (not is_stream) and (user_profile_id in active_user_ids):
|
||||
|
||||
@@ -91,6 +91,26 @@ class TestServiceBotBasics(ZulipTestCase):
|
||||
|
||||
self.assertEqual(event_dict, expected)
|
||||
|
||||
def test_service_events_for_private_mentions(self) -> None:
|
||||
"""Service bots should not get access to mentions if they aren't a
|
||||
direct recipient."""
|
||||
sender = self.example_user('hamlet')
|
||||
assert(not sender.is_bot)
|
||||
|
||||
outgoing_bot = self._get_outgoing_bot()
|
||||
|
||||
event_dict = get_service_bot_events(
|
||||
sender=sender,
|
||||
service_bot_tuples=[
|
||||
(outgoing_bot.id, outgoing_bot.bot_type),
|
||||
],
|
||||
active_user_ids=set(),
|
||||
mentioned_user_ids={outgoing_bot.id},
|
||||
recipient_type=Recipient.PERSONAL,
|
||||
)
|
||||
|
||||
self.assertEqual(len(event_dict), 0)
|
||||
|
||||
class TestServiceBotStateHandler(ZulipTestCase):
|
||||
def setUp(self) -> None:
|
||||
self.user_profile = self.example_user("othello")
|
||||
|
||||
Reference in New Issue
Block a user