Skip to content

Commit

Permalink
Custom notifications, broadcast (#44) (#45)
Browse files Browse the repository at this point in the history
* check for notifications config

* add broadcasting option

* return unread messages count
  • Loading branch information
musonza authored Feb 2, 2018
1 parent b2b42c0 commit 8ecb182
Show file tree
Hide file tree
Showing 16 changed files with 4,042 additions and 64 deletions.
37 changes: 34 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ This will publish database migrations and a configuration file `musonza_chat.php
> **Note:** This package takes advantage of Laravel Notifications.
If you have already setup Laravel notifications you can delete the `2017_07_12_034227_create_notifications_table.php` migration file.

## Configuration

```php
[
'user_model' => 'App\User',

/**
* This will allow you to broadcast an event when a message is sent
* Example:
* Channel: private-mc-chat-conversation.2,
* Event: Musonza\Chat\Messages\MessageWasSent
*/
'broadcasts' => false,

/**
* If set to true, this will use Laravel notifications table to store each
* user message notification.
* Otherwise it will use mc_message_notification table.
* If your database doesn't support JSON columns you will need to set this to false.
*/
'laravel_notifications' => true,
];
```

Run the migrations:

```
Expand All @@ -80,19 +104,20 @@ By default the package assumes you have a User model in the App namespace.
However, you can update the user model in `musonza_chat.php` published in the `config` folder.

#### Creating a conversation
```
```php
$participants = [$userId, $userId2,...];

$conversation = Chat::createConversation($participants);
```

#### Get a conversation by id
```
```php
$conversation = Chat::conversation($conversation_id);
```

#### Update conversation details
```

```php
$data = ['title' => 'PHP Channel', 'description' => 'PHP Channel Description'];
$conversation->update(['data' => $data]);
```
Expand Down Expand Up @@ -130,6 +155,12 @@ Chat::messages($message)->for($user)->markRead();
Chat::conversations($conversation)->for($user)->readAll();
```

### Unread messages count

```php
$unreadCount = Chat::for($user)->unreadCount();
```

#### Delete a message

```php
Expand Down
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"illuminate/config": "^5.3"
},
"require-dev": {
"phpunit/phpunit": "^4.8 || ^5.0"
"phpunit/phpunit": "~6.0",
"orchestra/testbench": "3.5.*",
"orchestra/database": "3.5.*"
},
"license": "MIT",
"authors": [
Expand All @@ -29,6 +31,11 @@
"Musonza\\Chat\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Musonza\\Chat\\Tests\\": "tests"
}
},
"extra": {
"laravel": {
"providers": [
Expand Down
Loading

0 comments on commit 8ecb182

Please sign in to comment.