** There many changes to come as this package is 1% of what it can be, but currently it works for me, so I decided to share it and may get some help from others.
I am trying to build this in a very generic way so it could be easilly implemented for each framework or project. Currently I'll try to build with laravel and eloquent as this is the project I'm currently building.
- Message status for each user: deleted, read, unread, archived
- multipile conversations for each user
- each conversation has 2 or more users
- ability to have 1 unique conversation for each 2 users
- Get all users conversations with last message in conversation
- get all conversations messages for a specific user
users: id
messages: id, sender_id, conv_id, content, updated_at, created_at
messages_status: id, user_id, msg_id, self, status
conversations: id, updated_at, created_at
conv_users: conv_id, user_id
simply hold the users that use the messages contains the message itself, who sent it, to which conversation, the content and the dates. this is the "magic" it has a row for each user that got a message in a specific conversation. IE if I send a message to conversation with 4 users, we will have 5 rows in this table, the sender and the other 4 recipents, it will contains the specific user message status, as is it deleted, read, unread... currently only has an id, and dates holds the users in conversation relationships- Add this: '"tzookb/tbmsg": "dev-master"' to your composer.json file
- run: "composer update tzookb/tbmsg"
- Now add the service provider to your app.php file: "'Tzookb\TBMsg\TBMsgServiceProvider'"
- It would be best if you register the Facade in your app.php file: "'TBMsg' => 'Tzookb\TBMsg\Facade\TBMsg'"
- run the migrations: "php artisan migrate --package=tzookb/tbmsg"
- TBMsg::getUserConversations($user_id);
- TBMsg::getConversationMessages($conv_id, $user_id); TBMsg::getConversationByTwoUsers($userA_id, $userB_id);
- TBMsg::addMessageToConversation($conv_id, $user_id, $content);
- TBMsg::createConversation($users_ids=array());
- TBMsg::getUsersInConversation($conv_id);
- TBMsg::deleteConversation($conv_id, $user_id);
- TBMsg::isUserInConversation($conv_id, $user_id);
- TBMsg::getNumOfUnreadMsgs($users_ids=array());