cmgmyr / laravel-messenger

Simple user messaging package for Laravel
MIT License
2.46k stars 517 forks source link

One-to-one facebook style messaging. #29

Closed naneri closed 9 years ago

naneri commented 9 years ago

How can this be performed? I have went through the methods, but still had to implement my own (i needed to users have only single thread between each other).

ryross commented 9 years ago

You can just create a Thread with one participant instead of many. See:

https://github.com/cmgmyr/laravel-messenger/blob/master/src/Cmgmyr/Messenger/examples/MessagesController.php#L91

cmgmyr commented 9 years ago

That is correct just add the recipient's user id here. You'll have to use this in order to only show threads that the current user is a part of.

You'll also have to implement some sort of check in the show() method in order to make sure the user is really a participant of the thread.

dorinniscu commented 8 years ago

How do I get the conversation in case of a chat? I have a list of users, I select one and start or continue a conversation so I need to create a thread if not exists.

I suppose I need to get the thread knowing the participants (me and the other person) but we can participate to other threads too so I need to match that specific thread.

Is there an easier way to do that or I have to do other check to get the thread with two persons that are not participating to other threads? something like: "find or create between".

Gummibeer commented 8 years ago

@dorin-niscu here you go: https://github.com/cmgmyr/laravel-messenger/blob/master/src/Cmgmyr/Messenger/Models/Thread.php#L173

With the Thread::between([user_ids])->first() you should get the thread, if exists, with the two participants. If not you can simply create a new thread.

dorinniscu commented 8 years ago

@Gummibeer Thanks. I should have studied the model :)