Filtering Distinct and Ordered Data

I'm trying to create a messaging App where user can see the list of people who messaged him & also whom he messaged, so that he can click on their names & see the conversation occurred.
Problem is that I couldn't filter out the distinct & ordered list of users who messaged request.user or whom request.user messaged.