Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
markdown: Set has_image to True for images with inline media syntax.
Lauryn Menard03fecc05704b
diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.pyindex 8119257327b..6acb6450e8e 100644--- a/zerver/lib/markdown/__init__.py+++ b/zerver/lib/markdown/__init__.py@@ -2177,6 +2177,10 @@ class ImageInlineProcessor(markdown.inlinepatterns.ImageInlineProcessor):metadata.original_content_type,)+ # Update message.has_image attribute.+ if self.zmd.zulip_message:+ self.zmd.zulip_message.has_image = True+return img@overridediff --git a/zerver/tests/test_message_fetch.py b/zerver/tests/test_message_fetch.pyindex 931b7b64926..13938e6a1ef 100644--- a/zerver/tests/test_message_fetch.py+++ b/zerver/tests/test_message_fetch.py@@ -50,7 +50,12 @@ from zerver.lib.narrow_predicate import build_narrow_predicatefrom zerver.lib.sqlalchemy_utils import get_sqlalchemy_connectionfrom zerver.lib.streams import StreamDict, create_streams_if_needed, get_public_streams_querysetfrom zerver.lib.test_classes import ZulipTestCase-from zerver.lib.test_helpers import HostRequestMock, get_user_messages, queries_captured+from zerver.lib.test_helpers import (+ HostRequestMock,+ get_test_image_file,+ get_user_messages,+ queries_captured,+)from zerver.lib.topic import MATCH_TOPIC, RESOLVED_TOPIC_PREFIX, TOPIC_NAME, messages_for_topicfrom zerver.lib.types import UserDisplayRecipientfrom zerver.lib.upload import create_attachment@@ -5599,6 +5604,14 @@ class MessageHasKeywordsTest(ZulipTestCase):# return path idsreturn [x[1] for x in dummy_files]+ def setup_uploaded_image_file(self, user_profile: UserProfile) -> str:+ self.login_user(user_profile)+ image_file = get_test_image_file("img.png")+ response = self.assert_json_success(+ self.client_post("/json/user_uploads", {"file": image_file})+ )+ return response["url"]+def test_claim_attachment(self) -> None:user_profile = self.example_user("hamlet")dummy_path_ids = self.setup_dummy_attachments(user_profile)@@ -5699,18 +5712,21 @@ class MessageHasKeywordsTest(ZulipTestCase):self.assertFalse(msg.has_link)def test_has_image(self) -> None:+ hamlet = self.example_user("hamlet")+ uploaded_image_url = self.setup_uploaded_image_file(hamlet)msg_contents = ["Link: foo.org","Image: https://www.google.com/images/srpr/logo4w.png","Image: https://www.google.com/images/srpr/logo4w.pdf","[Google link](https://www.google.com/images/srpr/logo4w.png)",+ f"",]msg_ids = [- self.send_stream_message(self.example_user("hamlet"), "Denmark", content=msg_content)+ self.send_stream_message(hamlet, "Denmark", content=msg_content)for msg_content in msg_contents]msgs = [Message.objects.get(id=id) for id in msg_ids]- self.assertEqual([False, True, False, True], [msg.has_image for msg in msgs])+ self.assertEqual([False, True, False, True, True], [msg.has_image for msg in msgs])self.update_message(msgs[0], "https://www.google.com/images/srpr/logo4w.png")self.assertTrue(msgs[0].has_image)