vns / chatting
api for make chatting easy
0.3.0
2022-10-18 14:15 UTC
Requires
- php: ^7.4|^8.0
- illuminate/support: ^9.0
- spatie/laravel-medialibrary: ^9.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
small package to do task of any chatting task like manage conversations, messages, participants, ...
Installation
You can install the package via composer:
composer require vns/chatting-api
Usage
First You Must Publish migrations
php artisan vendor:publish --provider="VnsChattingApi\ChattingApiServiceProvider" --tag="migrations"
Publish config file
php artisan vendor:publish --provider="VnsChattingApi\ChattingApiServiceProvider" --tag="config"
Add Messageable Trait for participant model
use VnsChattingApi\Traits\Messageable;
Manage Conversation
// Create new Conversation ChattingApiFacade::createConversation([$model1,$model2]); // create un-direct conversation ChattingApiFacade::createDirectConversation([$model1,$model2]); // create direct conversation // Get conversation by id ChattingApiFacade::conversations()->getById($conversation_id); // Get conversation messages ChattingApiFacade::conversation($conversation)->setParticipant($participant) ->setPaginationParams([ 'page' => 1, 'perPage' => 25, 'sorting' => "desc", 'columns' => [ '*' ], 'pageName' => 'page' ]) ->page($page) ->getMessages(); // OR $participant->conversations; // Get Count of unread messages for conversations for specific participant ChattingApiFacade::conversation($conversation)->setParticipant($participant)->unreadCount(); // Get Conversation between two participant ChattingApiFacade::conversations()->between( $participantOne, $participantTwo); // Clear all message notifications for one participant ChattingApiFacade::conversations()->setParticipant($participant)->clear(); // Make all Messages as read by specific participant ChattingApiFacade::conversations()->setParticipant($participant)->readAll(); // Add new participants for conversation ChattingApiFacade::conversation($conversation)->addParticipants($participants); // Remove participants from conversation ChattingApiFacade::conversation($conversation)->removeParticipants($participants);
conversations api
Manage Participant
// added Messageable Trait for participant model use VnsChattingApi\Traits\Messageable; // Get all conversations for participant $participant->conversations(); // Join Conversation $participant->joinConversation($conversation); // leave Conversation $participant->leaveConversation($conversation);
Manage Message
// Create new Message ChattingApiFacade::message('message content') ->from($participant) ->to($conversation) ->send(); // Or ChattingApiFacade::message('message content') ->from($participant) ->to($conversation) ->type('text') ->send(); // Delete Message For Specific Participant ChattingApiFacade::messages()->getById($message_id)->trash($participant);