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:
Jason Michalski
2014-07-15 15:03:51 -04:00
committed by Steve Howell
parent 6c424e8446
commit 710a802f49
3 changed files with 49 additions and 3 deletions

View File

@@ -23,6 +23,7 @@ import zlib
from bitfield import BitField
from collections import defaultdict
from datetime import timedelta
import pylibmc
import re
import ujson
@@ -968,6 +969,15 @@ def pre_save_message(sender, **kwargs):
message = kwargs['instance']
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):
user_profile = models.ForeignKey(UserProfile)
message = models.ForeignKey(Message)