Besides the normal private message functionality I am sending predefined private messages to users, i.e. the user can't change the text, but simply has a button that sends a predefined fixed message (invitation, etc). When doing this, the user is not redirected to the chat.
In this case a notification is shown about new private messages (notification block). But the new message is the one send by the user itself.
The same occurs if I'm using a modal to send a private message and afterwards do not redirect the user to the thread.
How can this be avoided and the thread be marked as read? (Of course only if it does not contain messages from the other thread members.)
Maybe it would be even better to exclude messages send by the current user in getUnreadThreadCount() in PrivateMessageService.php. I don't see any case where it makes sense to count the own messages send to others as new ones for oneself.
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | interdiff-2977310-19-20.txt | 1.24 KB | eelkeblok |
| #20 | private_message-message_count-2977310-20-d8.patch | 2.49 KB | eelkeblok |
| #6 | private_message-message_count-2977310-6.patch | 1.83 KB | ohorbatiuk |
| #5 | private_message-message_count-2977310-5.patch | 1.16 KB | lamp5 |
Comments
Comment #2
mike82 commentedComment #3
mike82 commentedComment #4
jochemvn commentedI think another reason for this to happen is the fact that 'unread' is determined wrong.
It compares the last created message in the thread with the last time I've accessed the thread
1. Like you mentioned it's weird that it does that for my own messages
2. If the time of creating that message is the same as the last time I've accessed the thread, which is obviously true... the thread is marked as read.
I think
if ($last_access_time <= $newest_message_timestamp) {should be changed to
if ($last_access_time < $newest_message_timestamp) {Comment #5
lamp5I can confirm that @mike82 code from #3 fixed this issue on branch 8.1 and 8.2. I prepared a patch.
Comment #6
ohorbatiukContain solutions from #3 and #4.
Comment #7
ohorbatiukShow thread as read when it contains few messages and the last message is own.
Comment #8
zenimagine commentedIs this patch related to this problem that there is no solution:
https://www.drupal.org/project/private_message/issues/2984799
Comment #9
zenimagine commentedComment #10
mike82 commentedLooks good.
It can be still corrected so that is also fixes Unread Thread Count not updated correctly.
Comment #11
zenimagine commented@mike82 Hello, would it be possible to have a patch and close the other problem if the patch solves
Comment #12
mike82 commentedhere you go. Please test it.
Comment #13
zenimagine commented@mike82 Thank you, but I have not managed to apply the patch :
Comment #14
mike82 commentedComment #15
zenimagine commented@mike82 Thank you, I managed to apply your last patch and it seems to work. I think you can close the other problem and review this one
Comment #16
phjouWhen I was sending a message and leaving the page, I had a notification even when it was me that sent the message. With the patch it looks to be fixed, thanks.
Comment #17
mike82 commentedComment #18
eelkeblokWe are seeing some issues with the unread count for newly created threads. We need to do some more investigating (most likely tomorrow), but chances are this is in scope for this patch. I hope to be able to provide some input and possibly an update to the patch (or a "false alarm") tomorrow by the end of the day (CET).
Comment #19
eelkeblokOK, turned out to be an easy one. The query checks whether the last access time for the current user is smaller than the time it was updated. Fortunately, a foreseeing soul already made sure the user has an access time for the newly created thread at all, so we don't need to mess with LEFT JOINs, but the access time registered for the target user is set to the creation time, which obviously is not smaller than itself... So without further ado, here's the updated patch.
Comment #20
eelkeblokHere's an updated patch. It occured to me that the way the unread status of a thread was determined is a bit convoluted. The getNewestMessageCreationTimestamp() loops over all messages in the thread, after which - in this patch - the view method in the ThreadViewBuilder also loops over them. I personally also think this is a bit more intuitive, but that might just be personal preference.
Comment #21
anmolgoyal74 commentedThe patch works for me.
Let's wait for others to review the patch. Then I will move forward with the patch.
Comment #22
phjouIt seems to be working for me too.
Comment #24
anmolgoyal74 commentedThanks for the patch.
Fixed.