Hi Guys,
I'm writing a basic messaging app. It's working pretty well, but there's something I want to change.
WHen a user views their inbox, the following sql code is used to fetch their essages. What it does it grab the NEWEST message from a specific user and it uses that message, date, and time to display that message group.
For instance say the messaging went like this.
ME - HELLO (7:51pm)
USER - How are you (7:53pm)
ME - Just fine, you? (7:55pm)
USER - I am ok. Did you get the package (7:57pm)
ME - I did (7:58pm)
ME - But it looked damaged (7:59pm)
The inbox is going to show a row that has
(pic) USER - I am ok. Did you get the package (7:57pm)
Because that was the newest message from that user. However, what I want to display is the pic/username of the other user, but the most current message in the chain, whether it's from me or the other user.
So instead, based on the conversation above, the inbox should display
(pic) USER - <reply arrow> But it looked damaged (7:59pm)
This would show a row that linked to the message chain between me and the user, but since I was the last one to say something, my message would be the one displayed. The 'reply arrow' would be a small graphic that would only be displayed IF the message was from me. If they click on the message, it takes them to the entire chain.
So I need to mod the SQL below to grab the newest message between the two users, along with the information on the other user, and determine in the newest message is from ME or the other user. Thoughts?
I'm writing a basic messaging app. It's working pretty well, but there's something I want to change.
WHen a user views their inbox, the following sql code is used to fetch their essages. What it does it grab the NEWEST message from a specific user and it uses that message, date, and time to display that message group.
For instance say the messaging went like this.
ME - HELLO (7:51pm)
USER - How are you (7:53pm)
ME - Just fine, you? (7:55pm)
USER - I am ok. Did you get the package (7:57pm)
ME - I did (7:58pm)
ME - But it looked damaged (7:59pm)
The inbox is going to show a row that has
(pic) USER - I am ok. Did you get the package (7:57pm)
Because that was the newest message from that user. However, what I want to display is the pic/username of the other user, but the most current message in the chain, whether it's from me or the other user.
So instead, based on the conversation above, the inbox should display
(pic) USER - <reply arrow> But it looked damaged (7:59pm)
This would show a row that linked to the message chain between me and the user, but since I was the last one to say something, my message would be the one displayed. The 'reply arrow' would be a small graphic that would only be displayed IF the message was from me. If they click on the message, it takes them to the entire chain.
So I need to mod the SQL below to grab the newest message between the two users, along with the information on the other user, and determine in the newest message is from ME or the other user. Thoughts?
Code:
SELECT
tmm.message_id,
tmm.content_id,
tmm.sender_id,
tmm.new,
tmm.replied,
tmm.flagged,
tmm.sent_date,
tmm.viewed_date,
tmmc.category,
tmmc.body,
tmcc.first_name,
tmcc.middle_name,
tmcc.last_name,
tmcc.name_display,
tmpt.thumbnail_url,
tmpt.thumbnail_file
FROM tbl_member_messages tmm
INNER JOIN tbl_member_messages_content tmmc on tmm.content_id = tmmc.content_id
INNER JOIN members.dbo.tbl_member_core_contact tmcc on tmm.sender_id = tmcc.member_id
INNER JOIN members.dbo.tbl_member_profile_thumbnail tmpt on tmm.sender_id = tmpt.member_id
WHERE
tmm.recipient_id = <cfqueryparam value="#session.myid#">
and recipient_archived <> 1
and recipient_deleted <> 1
and recipient_spammed <> 1
AND tmm.message_id IN
(
SELECT message_id FROM
(
SELECT MAX(tmm2.message_id) as message_id
FROM tbl_member_messages tmm2
INNER JOIN tbl_member_messages_content tmmc2 on tmm2.content_id = tmmc2.content_id
INNER JOIN members.dbo.tbl_member_core_contact tmcc on tmm2.sender_id = tmcc.member_id
WHERE
tmm2.recipient_id = <cfqueryparam value="#session.myid#">
and recipient_archived <> 1
and recipient_deleted <> 1
and recipient_spammed <> 1
GROUP BY tmm2.sender_id
)
as whoreallycares
)
ORDER BY tmm.sent_date DESC
