Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

reminder: Generate accurate `with` topic link.

PieterCK856dcb1e6053
diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py
index fa880f4ad14..3fb4567b135 100644
--- a/zerver/lib/markdown/__init__.py
+++ b/zerver/lib/markdown/__init__.py
@@ -63,6 +63,7 @@ from zerver.lib.thumbnail import (
)
from zerver.lib.timeout import unsafe_timeout
from zerver.lib.timezone import common_timezones
+from zerver.lib.topic_link_util import TOPIC_LINK_SYNTAX_FOR_DISPLAY
from zerver.lib.types import LinkifierDict
from zerver.lib.url_encoding import encode_channel, encode_hash_component
from zerver.lib.url_preview.types import UrlEmbedData, UrlOEmbedData
@@ -1879,7 +1880,9 @@ class StreamTopicPattern(StreamTopicMessageProcessor):
el.text = markdown.util.AtomicString(f"#{stream_name} > ")
el.append(topic_el)
else:
- text = f"#{stream_name} > {topic_name}"
+ text = TOPIC_LINK_SYNTAX_FOR_DISPLAY.format(
+ channel_name=stream_name, topic_name=topic_name
+ )
el.text = markdown.util.AtomicString(text)
return el, m.start(), m.end()
diff --git a/zerver/lib/reminders.py b/zerver/lib/reminders.py
index 3be51f3dff9..6656ce4b4ba 100644
--- a/zerver/lib/reminders.py
+++ b/zerver/lib/reminders.py
@@ -9,9 +9,12 @@ from zerver.lib.markdown.fenced_code import get_unused_fence
from zerver.lib.mention import silent_mention_syntax_for_user
from zerver.lib.message import get_user_mentions_for_display, truncate_content
from zerver.lib.message_cache import MessageDict
-from zerver.lib.topic_link_util import get_stream_topic_link_syntax
+from zerver.lib.topic_link_util import (
+ TOPIC_LINK_SYNTAX_FOR_DISPLAY,
+ escape_invalid_stream_topic_characters,
+)
from zerver.lib.types import UserDisplayRecipient
-from zerver.lib.url_encoding import message_link_url
+from zerver.lib.url_encoding import message_link_url, stream_message_url
from zerver.models import Message, Stream, UserProfile
from zerver.models.scheduled_jobs import ScheduledMessage
from zerver.tornado.django_api import send_event_on_commit
@@ -54,10 +57,21 @@ def get_reminder_formatted_content(
id=message.recipient.type_id,
realm=current_user.realm,
)
- topic_pretty_link = get_stream_topic_link_syntax(
- stream_id=stream.id,
- stream_name=stream.name,
- topic_name=message.topic_name(),
+ url = stream_message_url(
+ realm=None,
+ message={
+ "id": message.id,
+ "stream_id": stream.id,
+ "display_recipient": stream.name,
+ "topic": message.topic_name(),
+ },
+ conversation_link=True,
+ include_base_url=False,
+ )
+ escape = escape_invalid_stream_topic_characters
+ topic_pretty_link = TOPIC_LINK_SYNTAX_FOR_DISPLAY.format(
+ channel_name=escape(stream.name),
+ topic_name=escape(message.topic_name()),
)
if note:
content = _(
@@ -72,7 +86,7 @@ def get_reminder_formatted_content(
context = dict(
user_silent_mention=user_silent_mention,
conversation_url=conversation_url,
- topic_pretty_link=topic_pretty_link,
+ topic_pretty_link=f"[{topic_pretty_link}]({url})",
)
else:
if note:
diff --git a/zerver/lib/topic_link_util.py b/zerver/lib/topic_link_util.py
index 912d6d4fe84..3010a40015b 100644
--- a/zerver/lib/topic_link_util.py
+++ b/zerver/lib/topic_link_util.py
@@ -14,6 +14,8 @@ def will_produce_broken_stream_topic_link(word: str) -> bool:
return bool(invalid_stream_topic_regex.search(word))
+TOPIC_LINK_SYNTAX_FOR_DISPLAY = "#{channel_name} > {topic_name}"
+
escape_mapping = {
"`": "`",
">": ">",
diff --git a/zerver/tests/test_reminders.py b/zerver/tests/test_reminders.py
index 26458c3a240..113e324ceb3 100644
--- a/zerver/tests/test_reminders.py
+++ b/zerver/tests/test_reminders.py
@@ -73,7 +73,7 @@ class RemindersTest(ZulipTestCase):
def get_channel_message_reminder_content(self, msg_content: str, msg_id: int) -> str:
return (
f"You requested a reminder for the following message.\n\n"
- f"@_**King Hamlet|10** [said](http://zulip.testserver/#narrow/channel/3-Verona/topic/test/near/{msg_id}) in #**Verona>test**:\n```quote\n{msg_content}\n```"
+ f"@_**King Hamlet|10** [said](http://zulip.testserver/#narrow/channel/3-Verona/topic/test/near/{msg_id}) in [#Verona > test](#narrow/channel/3-Verona/topic/test/with/{msg_id}):\n```quote\n{msg_content}\n```"
)
def test_schedule_reminder(self) -> None:
@@ -485,7 +485,7 @@ class RemindersTest(ZulipTestCase):
self.assertEqual(
scheduled_message.content,
f"You requested a reminder for the following message. Note:\n > {note}\n\n"
- f"@_**King Hamlet|10** [said](http://zulip.testserver/#narrow/channel/3-Verona/topic/test/near/{message_id}) in #**Verona>test**:\n```quote\n{content}\n```",
+ f"@_**King Hamlet|10** [said](http://zulip.testserver/#narrow/channel/3-Verona/topic/test/near/{message_id}) in [#Verona > test](#narrow/channel/3-Verona/topic/test/with/{message_id}):\n```quote\n{content}\n```",
)
message_id = self.send_dm_from_hamlet_to_othello(content)
@@ -531,7 +531,9 @@ class RemindersTest(ZulipTestCase):
scheduled_message.content,
"You requested a reminder for the following message. Note:\n > {123}\n\n"
f"@_**King Hamlet|10** [said](http://zulip.testserver/#narrow/channel/3-Verona/topic/.7B789.7D/near/{message_id})"
- " in #**Verona>{789}**:\n" + f"```quote\n{content}\n```",
+ " in [#Verona > {789}](#narrow/channel/3-Verona/topic/.7B789.7D/with/"
+ f"{message_id}):\n"
+ f"```quote\n{content}\n```",
)
def test_schedule_reminder_ones_own_message(self) -> None: