metko / galera
laravel 的消息/聊天包
v1.0.0
2019-12-06 01:04 UTC
Requires (Dev)
- matthewbdaly/artisan-standalone: dev-master
- mockery/mockery: ~1.0
- orchestra/testbench: ^3.7
- orchestra/testbench-browser-kit: ^3.7
- php-coveralls/php-coveralls: ^2.1
- phpstan/phpstan: ^0.10.5
- phpunit/phpunit: ^7.0
- psy/psysh: ^0.9.8
- sebastian/phpcpd: ^4.0
- squizlabs/php_codesniffer: ^3.3
This package is auto-updated.
Last update: 2024-09-06 13:18:08 UTC
README
Galera 是一个处理两个或多个用户之间对话的小型包。
安装步骤
步骤 1
composer require metko/galera
步骤 2
发布配置文件和资源
php artisan pusblish --tag:galera
如何使用它
用法
使用特性
在用户模型中使用 Galerable 特性
// Metko\Galera\Galerable; use Galerable;
对话
创建对话
Galera::participants($user1, $user2)->make(); *// Or pass an array of multiple user* Galera::addParticipants([1,2,3,'10'])->make();
获取对话
Galera::conversation($id); // Or with the messages Galera::conversation($id, true);
默认返回包含 [‘messages_count’,’unread_messages_count’] 的对话 *
清除对话
Galera::conversation($id)->clear();
将软删除给定对话中的所有消息
关闭对话
Galera::conversation($id)->close(); return Metko\Galera\Conversation
没有人可以在已关闭的对话中提交消息
检查对话是否已关闭
Galera::conversation($id)->isCLosed(); // return bool
在对话中添加参与者
Galera::conversation($id)->add(1); // Or many user at the same time Galera::conversation($id)->addMany([1, $user2, '3']);
对话可以移除参与者
Galera::conversation($id)->remove(1);
对话必须至少有 2 个参与者。如果您尝试这样做,将返回错误。
阅读对话中的所有消息
Galera::conversation($id)->readAll();
对话必须至少有 2 个参与者。如果您尝试这样做,将返回错误。
用户
用户可以写消息
$user->write(‘My message’, $conversationId); // You can pass a model or an id for the conversation
删除消息
Galera::message(1)->delete(); // You can pass a model or an id for the conversation param*
写一条引用另一条消息的消息
$user->write(‘My message’, $conversationId, $message->id); // You can pass a model or an id for the message param*
检查用户在特定对话中是否有未读消息
$user->hasUnreadMessage($convzersationId); // Return bool //Or in all conversation where he is participant $user->hasUnreadMessage(); // Return bool
获取用户的未读消息
$user->unreadMessages();
阅读用户在对话中的所有未读消息
$user->readAll($convzersationId); // Return Collection
返回按 updated_at、消息数量和未读消息数量排序的所有对话列表
获取用户的最后一个对话
$user->getLastConversation($withMessage = false, $nbMessage = 25); // Return Collection
返回按 updated_at、消息数量和未读消息数量排序的所有对话列表
消息
从对话中获取消息
Galera::ofConversation($conversationId)->get();
获取对话中的未读消息数量
Galera::conversation($id)->unread_messages_count;
获取对话中的总消息数量
Galera::conversation($id)->messages_count;
测试用例
该包包括三个测试用例
TestCase- 实际上是普通的 Laravel 测试用例。以与您的普通 Laravel 测试用例相同的方式使用它SimpleTestCase- 扩展默认的 PHPUnit 测试用例,因此它不会设置 Laravel 应用程序,使其更快,非常适合进行正确的单元测试BrowserKitTestCase- 设置 BrowserKit