mirror of
https://github.com/zulip/zulip.git
synced 2025-11-16 03:41:58 +00:00
Add context to at mention missed messages
When you are at mentioned in a stream we will now send you up to the last five messages which were sent in the past 5 minutes on the same topic and stream. (imported from commit 6df6c1cf868722a7bf76e54710e38741a7ac8f31)
This commit is contained in:
committed by
Steve Howell
parent
6c424e8446
commit
710a802f49
@@ -5,13 +5,14 @@ from django.template import loader
|
|||||||
from zerver.decorator import statsd_increment, uses_mandrill
|
from zerver.decorator import statsd_increment, uses_mandrill
|
||||||
from zerver.models import Recipient, ScheduledJob, UserMessage, \
|
from zerver.models import Recipient, ScheduledJob, UserMessage, \
|
||||||
get_display_recipient, get_user_profile_by_email, get_user_profile_by_id, \
|
get_display_recipient, get_user_profile_by_email, get_user_profile_by_id, \
|
||||||
receives_offline_notifications
|
receives_offline_notifications, get_context_for_message
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import ujson
|
import ujson
|
||||||
import urllib
|
import urllib
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
def unsubscribe_token(user_profile):
|
def unsubscribe_token(user_profile):
|
||||||
# Leverage the Django confirmations framework to generate and track unique
|
# Leverage the Django confirmations framework to generate and track unique
|
||||||
@@ -258,9 +259,18 @@ def handle_missedmessage_emails(user_profile_id, missed_email_events):
|
|||||||
messages = [um.message for um in UserMessage.objects.filter(user_profile=user_profile,
|
messages = [um.message for um in UserMessage.objects.filter(user_profile=user_profile,
|
||||||
message__id__in=message_ids,
|
message__id__in=message_ids,
|
||||||
flags=~UserMessage.flags.read)]
|
flags=~UserMessage.flags.read)]
|
||||||
|
messages_by_recipient_subject = defaultdict(list)
|
||||||
|
for msg in messages:
|
||||||
|
messages_by_recipient_subject[(msg.recipient_id, msg.subject)].append(msg)
|
||||||
|
|
||||||
|
for msg_list in messages_by_recipient_subject.values():
|
||||||
|
msg = min(msg_list, key=lambda msg: msg.pub_date)
|
||||||
|
if msg.recipient.type == Recipient.STREAM:
|
||||||
|
messages.extend(get_context_for_message(msg))
|
||||||
|
|
||||||
if messages:
|
if messages:
|
||||||
do_send_missedmessage_events(user_profile, messages)
|
unique_messages = {m.id: m for m in messages}
|
||||||
|
do_send_missedmessage_events(user_profile, unique_messages.values())
|
||||||
|
|
||||||
@uses_mandrill
|
@uses_mandrill
|
||||||
def clear_followup_emails_queue(email, mail_client=None):
|
def clear_followup_emails_queue(email, mail_client=None):
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import zlib
|
|||||||
|
|
||||||
from bitfield import BitField
|
from bitfield import BitField
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from datetime import timedelta
|
||||||
import pylibmc
|
import pylibmc
|
||||||
import re
|
import re
|
||||||
import ujson
|
import ujson
|
||||||
@@ -968,6 +969,15 @@ def pre_save_message(sender, **kwargs):
|
|||||||
message = kwargs['instance']
|
message = kwargs['instance']
|
||||||
message.update_calculated_fields()
|
message.update_calculated_fields()
|
||||||
|
|
||||||
|
def get_context_for_message(message):
|
||||||
|
return Message.objects.filter(
|
||||||
|
recipient_id=message.recipient_id,
|
||||||
|
subject=message.subject,
|
||||||
|
id__lt=message.id,
|
||||||
|
pub_date__gt=message.pub_date - timedelta(minutes=5),
|
||||||
|
).order_by('-id')[:5]
|
||||||
|
|
||||||
|
|
||||||
class UserMessage(models.Model):
|
class UserMessage(models.Model):
|
||||||
user_profile = models.ForeignKey(UserProfile)
|
user_profile = models.ForeignKey(UserProfile)
|
||||||
message = models.ForeignKey(Message)
|
message = models.ForeignKey(Message)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ from zerver.lib.test_helpers import (
|
|||||||
from zerver.models import UserProfile, Recipient, \
|
from zerver.models import UserProfile, Recipient, \
|
||||||
Realm, Client, UserActivity, \
|
Realm, Client, UserActivity, \
|
||||||
get_user_profile_by_email, split_email_to_domain, get_realm, \
|
get_user_profile_by_email, split_email_to_domain, get_realm, \
|
||||||
get_client, get_stream
|
get_client, get_stream, Message
|
||||||
|
|
||||||
from zerver.lib.initial_password import initial_password
|
from zerver.lib.initial_password import initial_password
|
||||||
from zerver.lib.actions import \
|
from zerver.lib.actions import \
|
||||||
@@ -22,13 +22,16 @@ from zerver.lib.actions import \
|
|||||||
do_add_subscription, do_remove_subscription, do_make_stream_private
|
do_add_subscription, do_remove_subscription, do_make_stream_private
|
||||||
from zerver.lib.alert_words import alert_words_in_realm, user_alert_words, \
|
from zerver.lib.alert_words import alert_words_in_realm, user_alert_words, \
|
||||||
add_user_alert_words, remove_user_alert_words
|
add_user_alert_words, remove_user_alert_words
|
||||||
|
from zerver.lib.notifications import handle_missedmessage_emails
|
||||||
from zerver.middleware import is_slow_query
|
from zerver.middleware import is_slow_query
|
||||||
|
|
||||||
from zerver.worker import queue_processors
|
from zerver.worker import queue_processors
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core import mail
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import ujson
|
import ujson
|
||||||
@@ -1380,3 +1383,26 @@ class ExtractedRecipientsTest(TestCase):
|
|||||||
self.assertItemsEqual(extract_recipients(s), ['alice@zulip.com', 'bob@zulip.com'])
|
self.assertItemsEqual(extract_recipients(s), ['alice@zulip.com', 'bob@zulip.com'])
|
||||||
|
|
||||||
|
|
||||||
|
class TestMissedMessages(AuthedTestCase):
|
||||||
|
def test_extra_context_in_missed_stream_messages(self):
|
||||||
|
self.send_message("othello@zulip.com", "Denmark", Recipient.STREAM, '0')
|
||||||
|
self.send_message("othello@zulip.com", "Denmark", Recipient.STREAM, '1')
|
||||||
|
self.send_message("othello@zulip.com", "Denmark", Recipient.STREAM, '2')
|
||||||
|
self.send_message("othello@zulip.com", "Denmark", Recipient.STREAM, '3')
|
||||||
|
self.send_message("othello@zulip.com", "Denmark", Recipient.STREAM, '4')
|
||||||
|
self.send_message("othello@zulip.com", "Denmark", Recipient.STREAM, '5')
|
||||||
|
self.send_message("othello@zulip.com", "Denmark", Recipient.STREAM, '6', subject='test2')
|
||||||
|
msg_id = self.send_message("othello@zulip.com", "denmark", Recipient.STREAM, '@**hamlet**')
|
||||||
|
|
||||||
|
hamlet = get_user_profile_by_email('hamlet@zulip.com')
|
||||||
|
handle_missedmessage_emails(hamlet.id, [{'message_id': msg_id}])
|
||||||
|
|
||||||
|
def normalize_string(s):
|
||||||
|
s = s.strip()
|
||||||
|
return re.sub(r'\s+', ' ', s)
|
||||||
|
|
||||||
|
self.assertEquals(len(mail.outbox), 1)
|
||||||
|
self.assertIn(
|
||||||
|
'Denmark > test Othello, the Moor of Venice 1 2 3 4 5 @**hamlet**',
|
||||||
|
normalize_string(mail.outbox[0].body),
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user