From ac084ddb0eb76aa8e65e4cc1de4582f90aa59909 Mon Sep 17 00:00:00 2001 From: roanster007 Date: Fri, 3 Nov 2023 11:40:19 +0530 Subject: [PATCH] mention_dataset: Add query to mention cross realm bots as pill. Previously, cross realm bots were not displayed as mention Pills. This is because, the data set for validating mentions considers only the realm id which is None in case of cross realm bots. Hence, adding an or Q object to it, to also check if the email is a part of the cross realm bots email, in case the realm id returns None. Fixes #26913 --- zerver/lib/mention.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zerver/lib/mention.py b/zerver/lib/mention.py index 56a4768396..8421d46e4c 100644 --- a/zerver/lib/mention.py +++ b/zerver/lib/mention.py @@ -3,6 +3,7 @@ import re from dataclasses import dataclass from typing import Dict, List, Match, Optional, Set, Tuple +from django.conf import settings from django.db.models import Q from zerver.models import UserGroup, UserProfile, get_linkable_streams @@ -91,9 +92,9 @@ class MentionBackend: rows = ( UserProfile.objects.filter( - realm_id=self.realm_id, - is_active=True, + Q(realm_id=self.realm_id) | Q(email__in=settings.CROSS_REALM_BOT_EMAILS), ) + .filter(is_active=True) .filter( functools.reduce(lambda a, b: a | b, q_list), )