mirror of https://github.com/zulip/zulip.git
Use modern PM URLs in digest emails.
This commit is contained in:
parent
6a89446e80
commit
e79e0018f7
|
@ -11,7 +11,8 @@ from zerver.decorator import statsd_increment
|
|||
from zerver.lib.message import bulk_access_messages
|
||||
from zerver.lib.queue import queue_json_publish
|
||||
from zerver.lib.send_email import send_future_email, FromAddress
|
||||
from zerver.lib.url_encoding import pm_narrow_url, stream_narrow_url, topic_narrow_url
|
||||
from zerver.lib.url_encoding import personal_narrow_url, pm_narrow_url, \
|
||||
stream_narrow_url, topic_narrow_url
|
||||
from zerver.models import (
|
||||
Recipient,
|
||||
ScheduledEmail,
|
||||
|
@ -168,7 +169,10 @@ def build_message_list(user_profile: UserProfile, messages: List[Message]) -> Li
|
|||
def message_header(user_profile: UserProfile, message: Message) -> Dict[str, Any]:
|
||||
if message.recipient.type == Recipient.PERSONAL:
|
||||
header = "You and %s" % (message.sender.full_name,)
|
||||
html_link = pm_narrow_url(user_profile.realm, [message.sender.email])
|
||||
html_link = personal_narrow_url(
|
||||
realm=user_profile.realm,
|
||||
sender=message.sender,
|
||||
)
|
||||
header_html = "<a style='color: #ffffff;' href='%s'>%s</a>" % (html_link, header)
|
||||
elif message.recipient.type == Recipient.HUDDLE:
|
||||
disp_recipient = get_display_recipient(message.recipient)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import urllib
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from zerver.models import Realm, Stream
|
||||
from zerver.models import Realm, Stream, UserProfile
|
||||
|
||||
def hash_util_encode(string: str) -> str:
|
||||
# Do the same encoding operation as hash_util.encodeHashComponent on the
|
||||
|
@ -15,6 +15,12 @@ def encode_stream(stream_id: int, stream_name: str) -> str:
|
|||
stream_name = stream_name.replace(' ', '-')
|
||||
return str(stream_id) + '-' + hash_util_encode(stream_name)
|
||||
|
||||
def personal_narrow_url(realm: Realm, sender: UserProfile) -> str:
|
||||
base_url = "%s/#narrow/pm-with/" % (realm.uri,)
|
||||
email_user = sender.email.split('@')[0].lower()
|
||||
pm_slug = str(sender.id) + '-' + hash_util_encode(email_user)
|
||||
return base_url + pm_slug
|
||||
|
||||
def pm_narrow_url(realm: Realm, participants: List[str]) -> str:
|
||||
participants.sort()
|
||||
base_url = "%s/#narrow/pm-with/" % (realm.uri,)
|
||||
|
|
|
@ -23,8 +23,8 @@ class TestDigestEmailMessages(ZulipTestCase):
|
|||
# build dummy messages for missed messages email reply
|
||||
# have Hamlet send Othello a PM. Othello will reply via email
|
||||
# Hamlet will receive the message.
|
||||
email = self.example_email('hamlet')
|
||||
self.login(email)
|
||||
hamlet = self.example_user('hamlet')
|
||||
self.login(hamlet.email)
|
||||
result = self.client_post("/json/messages", {"type": "private",
|
||||
"content": "test_receive_missed_message_email_messages",
|
||||
"client": "test suite",
|
||||
|
@ -40,7 +40,8 @@ class TestDigestEmailMessages(ZulipTestCase):
|
|||
kwargs = mock_send_future_email.call_args[1]
|
||||
self.assertEqual(kwargs['to_user_id'], user_profile.id)
|
||||
html = kwargs['context']['unread_pms'][0]['header']['html']
|
||||
self.assertIn("'http://zulip.testserver/#narrow/pm-with/hamlet.40zulip.2Ecom'", html)
|
||||
expected_url = "'http://zulip.testserver/#narrow/pm-with/{id}-hamlet'".format(id=hamlet.id)
|
||||
self.assertIn(expected_url, html)
|
||||
|
||||
@mock.patch('zerver.lib.digest.enough_traffic')
|
||||
@mock.patch('zerver.lib.digest.send_future_email')
|
||||
|
|
Loading…
Reference in New Issue