Skip to content

Clouthr/tbmsg

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PHP User Messaging system:

PHP multi user multi conversations messaging system, just like facebook :)
** 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.

Description:

I decided to create this package because of the lack of real good messaging systems in php with the proper features like, deleting archiving messages for each specific user, multipile users in conversations and more.

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.

Would be happy to get help and ideas on the bad practices I do :)

Features:

  • 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

How is it built?

this are tables needed:

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

users
simply hold the users that use the messages
messages
contains the message itself, who sent it, to which conversation, the content and the dates.
messages_status
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...
conversations
currently only has an id, and dates
conv_users
holds the users in conversation relationships

How to install it?

  • 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"

How to use it?

  • Get User conversations:

    TBMsg::getUserConversations($user_id);
  • Get User full conversation:

    TBMsg::getConversationMessages($conv_id, $user_id);
  • Get the conversation id of two users:

    TBMsg::getConversationByTwoUsers($userA_id, $userB_id);
  • add a new message to conversation:

    TBMsg::addMessageToConversation($conv_id, $user_id, $content);
  • Create a new conversation:

    TBMsg::createConversation($users_ids=array());
  • Get all users in conversation:

    TBMsg::getUsersInConversation($conv_id);
  • Delete conversation to a specific user:

    TBMsg::deleteConversation($conv_id, $user_id);
  • Check if user is in conversation:

    TBMsg::isUserInConversation($conv_id, $user_id);
  • Get number of unread messages for specific user:

    TBMsg::getNumOfUnreadMsgs($users_ids=array());

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published