On a chat app am making, A user can start a conversation with any other user. In order to have threaded sms view, a user clicks on one of these conversation listview to get all messages sent or received by the person they are chatting with. How do i modify the query to show the sender name if am the receiver and receiver name if am the sender?
Example table
Id sender receiver
1 1 2
2 1 3
3 4 1
4 5 1
5 8 6
QUERY
SELECT conversation.Id,
conversation.Sender,
conversation.Receiver,
users.username as NAME
FROM conversation
INNER JOIN users
ON conversation.Sender = users.id
where sender = 1 OR receiver = 1
RESULT:
Id sender receiver NAME
1 1 2 razen
2 1 3 razen
3 4 1 peter
4 5 1 john
How do i modify the query to give me the name of the sender if am the receiver and the name of the receiver if am the sender?
The listview should only show other peoples names not mine.. (Show sam and kim for id 2&3 in the table above)