Proprely handle get_old_messages when narrowed to personals with yourself

(imported from commit 3ace5655d093f4568b4dea512a6e1bbbd6245f10)
This commit is contained in:
Jeff Arnold 2012-12-02 13:54:39 -05:00
parent ed0cb0a5f8
commit 5ea4e30caf
1 changed files with 7 additions and 1 deletions

View File

@ -261,7 +261,13 @@ def get_old_messages_backend(request, anchor = POST(converter=to_non_negative_in
query = query.filter(recipient__type=Recipient.PERSONAL)
recipient_user = UserProfile.objects.get(user__email = narrow['one_on_one_email'])
recipient = Recipient.objects.get(type=Recipient.PERSONAL, type_id=recipient_user.id)
query = query.filter(Q(sender__user__email=narrow['one_on_one_email']) | Q(recipient=recipient))
# If we are narrowed to personals with ourself, we want to search for personals where the user
# with address "one_on_one_email" is the sender *and* the recipient, not personals where the user
# with address "one_on_one_email is the sender *or* the recipient.
if narrow['one_on_one_email'] == user_profile.user.email:
query = query.filter(Q(sender__user__email=narrow['one_on_one_email']) & Q(recipient=recipient))
else:
query = query.filter(Q(sender__user__email=narrow['one_on_one_email']) | Q(recipient=recipient))
elif 'type' in narrow and (narrow['type'] == "huddle" or narrow['type'] == "all_huddles"):
query = query.filter(Q(recipient__type=Recipient.PERSONAL) | Q(recipient__type=Recipient.HUDDLE))