url_encoding: Use user name instead of email in personal_narrow_url.

This commit updates the urls for personal narrow sent in email
notifications to be of form "{user_id}-{encoded_full_name}" to
make it consistent with the urls that we use for such narrows
in webapp which were recently updated in b4eddad for improving
performance. We encode the full name in the same way that we do in
webapp by replacing the url characters encoded by browser with "-".
This commit is contained in:
Sahil Batra
2022-10-27 22:51:18 +05:30
committed by Tim Abbott
parent a410f6b241
commit 2a8b7412ff
2 changed files with 19 additions and 3 deletions

View File

@@ -1,7 +1,8 @@
from email.headerregistry import Address
from typing import Any, Dict, List
from urllib.parse import quote, urlsplit
import re2
from zerver.lib.topic import get_topic_from_message_info
from zerver.models import Realm, Stream, UserProfile
@@ -21,8 +22,8 @@ def encode_stream(stream_id: int, stream_name: str) -> str:
def personal_narrow_url(realm: Realm, sender: UserProfile) -> str:
base_url = f"{realm.uri}/#narrow/pm-with/"
email_user = Address(addr_spec=sender.email).username.lower()
pm_slug = str(sender.id) + "-" + hash_util_encode(email_user)
encoded_user_name = re2.sub(r'[ "%\/<>`\p{C}]+', "-", sender.full_name)
pm_slug = str(sender.id) + "-" + encoded_user_name
return base_url + pm_slug