django-messages icon indicating copy to clipboard operation
django-messages copied to clipboard

Issue With Same Inbox Subject as Multiple Objects

Open bobozar opened this issue 6 years ago • 4 comments

Messages in the inbox with the same subject keeps showing up more than once depending on the number of times a sender and the recipient receives messages. I want a situation whereby messages with the same subject will only show up once in the inbox and not twice or thrice. Kindly check the attached image for what I mean.

[url=https://ibb.co/b3AGQ7][img]https://thumb.ibb.co/b3AGQ7/Screenshot_35.png[/img][/url]

I've looked into the code and I did this

     message_list = Message.objects.inbox_for(request.user).values('subject').distinct()

But still not working.

bobozar avatar Mar 08 '18 23:03 bobozar

To show messages as threads, try to filter like this:

Message.objects.inbox_for(request.user).filter(parent_msg__isnull=True)

All messages where parent_msg is not null are replys in a thread.

You might need to replace the inbox_for filter with something like filter(Q(sender=user) || Q(recipient=user)) so that outgoing threads are also displayed.

arneb avatar Mar 09 '18 08:03 arneb

@arneb, I tried this.. but it's not working fine. When I check my inbox [/messages/inbox] as the sender, no message will show up. But when I check as the receiver, I will see the message in my inbox and it won't show up multiple times. It's working for the receiver and not the sender.

What am I missing?

bobozar avatar Mar 09 '18 16:03 bobozar

did you replace the inbox_for filter with two or'ed Q queries?

with inbox_for it will only work for the receiver, because inbox_for does a receiver=user filter. you want receiver=user || sender=user

arneb avatar Mar 09 '18 16:03 arneb

@arneb Thanks!

Now working. I did this.

messageo = Message.objects.filter(Q(sender=request.user) | Q(recipient=request.user)).filter(parent_msg__isnull=True) So far, it's working fine.

Another issue I have is how to make 1. a message that has not been read and replied have the em tag. 2, message that has been replied and not read have the em tag. So I did this.

{% for mvg in messageo %}

     <p>
		 {% if mvg.new %}
		       <p>From: {{ mvg.sender|capfirst }} To: {{ mvg.recipient|capfirst }}</p>
             <strong> <a href="{{mvg.get_absolute_url }}">{{ mvg.subject }}</a> </strong>
				 <p>{{ mvg.sent_at|date:_("DATETIME_FORMAT") }} </p>
		
		 {% elif mvg.replied_at is None %}		 
		        <p>From: {{ mvg.sender|capfirst }} To: {{ mvg.recipient|capfirst }}</p>
	            <em> <a href="{{mvg.get_absolute_url }}">{{ mvg.subject }}</a> </em>
				 <p>{{ mvg.sent_at|date:_("DATETIME_FORMAT") }} </p>
				
      {% elif mvg.replied_at %}
            {% if not mvg.read_at %}	
             <p>From: {{ mvg.sender|capfirst }} To: {{ mvg.recipient|capfirst }}</p>			   
	            <em> <a href="{{mvg.get_absolute_url }}">{{ mvg.subject }}</a> </em>
				 <p>{{ mvg.sent_at|date:_("DATETIME_FORMAT") }} </p>
			   {% endif %}	   
      {% endif %}
		</p>
{% endfor %}
		

But not working! I'm on Django 1.11 . What am I missing?

bobozar avatar Mar 09 '18 19:03 bobozar