mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 21:13:36 +00:00
url_encoding: Update encode_stream -> encode_channel.
This commit is contained in:
@@ -65,7 +65,7 @@ from zerver.lib.thumbnail import (
|
||||
from zerver.lib.timeout import unsafe_timeout
|
||||
from zerver.lib.timezone import common_timezones
|
||||
from zerver.lib.types import LinkifierDict
|
||||
from zerver.lib.url_encoding import encode_stream, hash_util_encode
|
||||
from zerver.lib.url_encoding import encode_channel, hash_util_encode
|
||||
from zerver.lib.url_preview.types import UrlEmbedData, UrlOEmbedData
|
||||
from zerver.models import Message, Realm, UserProfile
|
||||
from zerver.models.linkifiers import linkifiers_for_realm
|
||||
@@ -2072,7 +2072,7 @@ class StreamPattern(StreamTopicMessageProcessor):
|
||||
# href when it processes a message with one of these, to
|
||||
# provide more clarity to API clients.
|
||||
# Also do the same for StreamTopicPattern.
|
||||
stream_url = encode_stream(stream_id, name)
|
||||
stream_url = encode_channel(stream_id, name)
|
||||
el.set("href", f"/#narrow/channel/{stream_url}")
|
||||
text = f"#{name}"
|
||||
el.text = markdown.util.AtomicString(text)
|
||||
@@ -2100,7 +2100,7 @@ class StreamTopicPattern(StreamTopicMessageProcessor):
|
||||
el = Element("a")
|
||||
el.set("class", "stream-topic")
|
||||
el.set("data-stream-id", str(stream_id))
|
||||
stream_url = encode_stream(stream_id, stream_name)
|
||||
stream_url = encode_channel(stream_id, stream_name)
|
||||
topic_url = hash_util_encode(topic_name)
|
||||
channel_topic_object = ChannelTopicInfo(stream_name, topic_name)
|
||||
with_operand = self.get_with_operand(channel_topic_object)
|
||||
@@ -2137,7 +2137,7 @@ class StreamTopicMessagePattern(StreamTopicMessageProcessor):
|
||||
return None, None, None
|
||||
el = Element("a")
|
||||
el.set("class", "message-link")
|
||||
stream_url = encode_stream(stream_id, stream_name)
|
||||
stream_url = encode_channel(stream_id, stream_name)
|
||||
topic_url = hash_util_encode(topic_name)
|
||||
link = f"/#narrow/channel/{stream_url}/topic/{topic_url}/near/{message_id}"
|
||||
el.set("href", link)
|
||||
|
||||
@@ -15,10 +15,10 @@ def hash_util_encode(string: str) -> str:
|
||||
return quote(string, safe=b"").replace(".", "%2E").replace("%", ".")
|
||||
|
||||
|
||||
def encode_stream(stream_id: int, stream_name: str) -> str:
|
||||
# We encode streams for urls as something like 99-Verona.
|
||||
stream_name = stream_name.replace(" ", "-")
|
||||
return str(stream_id) + "-" + hash_util_encode(stream_name)
|
||||
def encode_channel(channel_id: int, channel_name: str) -> str:
|
||||
# We encode channel for urls as something like 99-Verona.
|
||||
channel_name = channel_name.replace(" ", "-")
|
||||
return str(channel_id) + "-" + hash_util_encode(channel_name)
|
||||
|
||||
|
||||
def personal_narrow_url(*, realm: Realm, sender: UserProfile) -> str:
|
||||
@@ -40,12 +40,14 @@ def direct_message_group_narrow_url(
|
||||
|
||||
def stream_narrow_url(realm: Realm, stream: Stream) -> str:
|
||||
base_url = f"{realm.url}/#narrow/channel/"
|
||||
return base_url + encode_stream(stream.id, stream.name)
|
||||
return base_url + encode_channel(stream.id, stream.name)
|
||||
|
||||
|
||||
def topic_narrow_url(*, realm: Realm, stream: Stream, topic_name: str) -> str:
|
||||
base_url = f"{realm.url}/#narrow/channel/"
|
||||
return f"{base_url}{encode_stream(stream.id, stream.name)}/topic/{hash_util_encode(topic_name)}"
|
||||
return (
|
||||
f"{base_url}{encode_channel(stream.id, stream.name)}/topic/{hash_util_encode(topic_name)}"
|
||||
)
|
||||
|
||||
|
||||
def message_link_url(
|
||||
@@ -79,7 +81,7 @@ def stream_message_url(
|
||||
stream_name = message["display_recipient"]
|
||||
topic_name = get_topic_from_message_info(message)
|
||||
encoded_topic_name = hash_util_encode(topic_name)
|
||||
encoded_stream = encode_stream(stream_id=stream_id, stream_name=stream_name)
|
||||
encoded_stream = encode_channel(stream_id, stream_name)
|
||||
|
||||
parts = [
|
||||
realm.url,
|
||||
|
||||
Reference in New Issue
Block a user