My main goal is to have it work as a 'conversation' instead of multiple inbox messages, appearing as an instant message system rather than an inbox one. When the user chooses 'compose', if they have sent a message before in the past, it will actually just send a reply to an existing message instead of create a new one. This shouldn't be a hard task, and I feel it's something that people should want, but I'm a bit clueless as how to go about it. I will try myself and see what I come up with, but I'm a bit of a newbie at coding modules.

Maybe checking to see if a message exists between the users first, if there is then send it over to reply? If not, then new message? I think this would be a nice feature to have as an option.

Comments

sgp913’s picture

I've done some digging, and have an idea about how to go about accomplishing this, but don't have the tech knowledge to go about it. I'm gonna keep working on it and post my results/progress here.

Within the DB, privatemsg has a few fields in 2 tables. The fields i'm concerned with are pm_index -> thread_id and pm_index -> recipient. Apparently it is storing each message twice in pm_index, with just the 'recipient' field changing for each user ID.

What I would like to do is when a user goes to send a message, instead of creating a new 'threadID' like it does now, I would like to somehow make query to see if in the past there has been an interaction between the two users and if there has, to use that old thread_id value for the new message, which should tag it on to the end of the thread, essentially creating a rolling conversation. I'm assuming I need to create a relationship with the messageID as the "two recipients" are disjointed as two entries.

I don't know the code for this, but the logic is:
Send message function:
1. find the thread_id that are equal when associated with both recipient values.
Found: find their thread ID and assign the new message the same thread ID
Not found: create a new thread ID (default setting now)

If anyone has any ideas on how to accomplish this, please let me know. In the meantime, I'll start working on a solution.

Berdir’s picture

Re #1: Yes, that sounds about right.

Should be possible to build something on top of Privatemsg by hiding our default link on the user profile and replacing with your compose link.

The query that you will need is not trivial that you need to find a thread between two users, but something like this should get you started:

SELECT MAX(pmi_1.thread_id) FROM {pm_index} pmi_1 INNER JOIN {pm_index} pmi_2 ON pmi_1.thread_id = pmi_2.thread_id WHERE pmi_1.recipient = :current_user AND pmi_1.type = 'user' AND pmi_2.recipient = :profile_user AND pmi_2.type = 'user'.

That should give you the highest (most recent) thread id of a conversion between the two users.

semei’s picture

Hi you two,

any progress on this? I am looking for this feature as well.

semei’s picture

Issue summary: View changes

Removed information irrelevant to the issue.

ivnish’s picture

Issue summary: View changes
Status: Active » Closed (outdated)