metko / galera by metko

Messaging/chatting package for laravel
17
0
1
Package Data
Maintainer Username: metko
Maintainer Contact: thomas.moiluiavon@gmail.com (Thomas Moiluiavon)
Package Create Date: 2019-07-02
Package Last Update: 2019-12-06
Language: PHP
License: MIT
Last Refreshed: 2024-05-11 03:23:24
Package Statistics
Total Downloads: 17
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

galera

Galera is small package to handle conversation between two or multiple user.

Installations


Step 1
composer require metko/galera 
Step 2

Publish the config file and the asset

php artisan pusblish --tag:galera

How to use it

Usage

Use the trait

Use the trait Galerable in your user model

// Metko\Galera\Galerable;
use Galerable;

Conversation

Create a conversation
Galera::participants($user1, $user2)->make();
*// Or pass an array of multiple user*
Galera::addParticipants([1,2,3,'10'])->make();
Get a conversation
Galera::conversation($id);
// Or with the messages
Galera::conversation($id, true);

*Return a conversation with [‘messages_count’, ’unread_messages_count’] by default *

Clear a conversation
Galera::conversation($id)->clear();

Will soft delete all the message of the given conversation

Close a conversation
Galera::conversation($id)->close(); return Metko\Galera\Conversation

Nobody can submit a message in a close conversation

Check if a conversation is closed
Galera::conversation($id)->isCLosed(); // return bool
Add participants in a conversation
Galera::conversation($id)->add(1);
// Or many user at the same time
Galera::conversation($id)->addMany([1, $user2, '3']); 
A Conversation can remove a participant
Galera::conversation($id)->remove(1); 

A conversation must have at least 2 participants. It will return an error if you try to do it.

Read all message of a conversation
Galera::conversation($id)->readAll(); 

A conversation must have at least 2 participants. It will return an error if you try to do it.

User

A user can write a message
$user->write(‘My message’, $conversationId); // You can pass a model or an id for the conversation 
Delete a message
Galera::message(1)->delete(); // You can pass a model or an id for the conversation param*
Write a message refering another
$user->write(‘My message’, $conversationId, $message->id); // You can pass a model or an id for the message param*
Check if a user has unread message on a specific conversation
$user->hasUnreadMessage($convzersationId); // Return bool
//Or in all conversation where he is participant
$user->hasUnreadMessage(); // Return bool
Get unread messages for user
$user->unreadMessages(); 
Read all the message unread for a user in a conversation
$user->readAll($convzersationId); // Return Collection

Return a list of all conversation ordered by updated_at, count of message, and unread_message_count

Get the last conversation of a user
$user->getLastConversation($withMessage = false, $nbMessage = 25); // Return Collection

Return a list of all conversation ordered by updated_at, count of message, and unread_message_count

Messagess

Get messages from a conversation
Galera::ofConversation($conversationId)->get(); 
Get a unread_message count in conversation
Galera::conversation($id)->unread_messages_count; 
Get a total_message count n conversation
Galera::conversation($id)->messages_count; 

Test cases

The package includes three test cases:

  • TestCase - Effectively the normal Laravel test case. Use it the same way you would your normal Laravel test case
  • SimpleTestCase - Extends the default PHPUnit test case, so it doesn’t set up a Laravel application, making it quicker and well-suited to properly isolated unit tests
  • BrowserKitTestCase - Sets up BrowserKit