Skip to content

Commit 3e50f24

Browse files
committed
docs: add optional metadata field to chatroom creation and clarify sender relationship in messages
1 parent f9c6baf commit 3e50f24

File tree

6 files changed

+29
-21
lines changed

6 files changed

+29
-21
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "mmedia/le-chat",
33
"type": "library",
4-
"version": "0.0.1",
5-
"description": "This is my package le-chat",
4+
"version": "0.1.0",
5+
"description": "Add chat functionality to your Laravel application.",
66
"keywords": [
77
"Michal",
88
"laravel",

docs/src/content/docs/chatrooms.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ use Mmedia\LeChat\Models\Chatroom;
1818
$chatroom = Chatroom::create([
1919
'name' => 'General Chat',
2020
'description' => 'A chatroom for general discussions',
21+
'metadata' => [
22+
'foo' => 'bar', // Optional metadata for the chatroom
23+
],
2124
]);
2225
```
2326

docs/src/content/docs/messages.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ $sender = $message->sender; // Returns the participant who sent the message
8181
```
8282
This returns the `ChatParticipant` morph model, which represents the participant who sent the message. This is by design, letting you work with a unified interface for all participants, regardless of their underlying model.
8383

84+
Remember that not all messages have a sender. For example, system messages do not have a sender, so the `sender` relationship may return `null` in those cases.
85+
8486
### Returning the actual model that sent the message
8587
This will return an instance of the `ChatParticipant` model, which you can then use to get the actual model that sent the message (e.g., a User model).
8688
```php

docs/src/content/docs/notifications.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ foreach ($notifiableParticipants as $participant) {
3838
## Default New Message Notification
3939
The default notification is `\Mmedia\LeChat\Notifications\NewMessage::class`, which will send a notification to each of the participants personal channels when a new message is created, except the sender of the message, via the [Broadcasting](/broadcasting) channel.
4040

41-
If you have `WebPush` channel installed, the notification will automatically be sent via web-push if the participant is not connected to the chatroom via sockets. This is useful for sending notifications to users who are not currently online in the chatroom.
41+
If you have the `WebPush` channel installed, the notification will automatically be sent via web-push if the participant is not connected to the chatroom via sockets. This is useful for sending notifications to users who are not currently online in the chatroom.
4242

4343
### Difference from the event broadcast
4444
The `NewMessage` notification is sent to the personal channel of each participant, while the event is broadcasted to the chatroom presence channel. This means that the notification will be sent to each participant individually, while the event is sent to the chatroom as a whole.

docs/src/content/docs/participants.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,25 @@ If you want to use a different date range, you can use the `whereHasUnreadMessag
110110
$users = User::whereHasUnreadMessages(7, true)->get(); // unread messages sent in the last 7 days, including system messages
111111
```
112112

113+
## Getting a personal chatroom
114+
You can retrieve a "personal chatroom" for a participant, which is a chatroom that only contains that participant. This is useful for sending notifications or system messages that are not part of any other chatroom.
115+
116+
```php
117+
$personalChatroom = $teacher->getOrCreatePersonalChatroom(); // Will return the first chatroom that only contains the teacher as a participant
118+
```
119+
120+
If you want to configure the personal chatroom if its created, you can pass an array of attributes to the `getOrCreatePersonalChatroom` method:
121+
122+
```php
123+
$teacher->getOrCreatePersonalChatroom([
124+
'name' => 'My Personal Chatroom',
125+
'description' => 'This is my personal chatroom for notifications and system messages, and sometimes notes.',
126+
'metadata' => [
127+
'foo' => 'bar', // Optional metadata for the personal chatroom
128+
],
129+
]);
130+
```
131+
113132
## Working with the intermediate morph model
114133
Le Chat uses an intermediate morph model called `ChatParticipant` to manage the relationships between your chattable models and the chatrooms they participate in.
115134

@@ -118,7 +137,7 @@ This model represents a participant in a chatroom and contains additional inform
118137
The intermediate model is more than just a pivot table; it allows you to have a unified representation of all participants in a chatroom, separate from your own models. This allows you to maximise the separation of concerns between your application logic and the chat functionality.
119138

120139
### Getting the intermediate model from your model
121-
You can retrieve the `ChatParticipant` instance for a specific participant using the `chatParticipant` method on your model:
140+
You can retrieve the `ChatParticipant` instance for a specific participant using the `asParticipantIn` method on your model:
122141
```php
123142
$chatParticipant = $teacher->asParticipantIn($chatroom);
124143
```
@@ -172,20 +191,4 @@ $chatrooms = Chatroom::hasParticipant([$teacher, $chatParticipant]); // Will ret
172191
The model itself also implements the `ChatParticipantInterface`, and uses the trait, so you can use it in the same way as your own models:
173192
```php
174193
$chatParticipant->sendMessageTo($student, 'Hello from the chat participant!');
175-
```
176-
177-
## Getting a personal chatroom
178-
You can retrieve a "personal chatroom" for a participant, which is a chatroom that only contains that participant. This is useful for sending notifications or system messages that are not part of any other chatroom.
179-
180-
```php
181-
$personalChatroom = $teacher->getOrCreatePersonalChatroom(); // Will return the first chatroom that only contains the teacher as a participant
182-
```
183-
184-
If you want to configure the personal chatroom if its created, you can pass an array of attributes to the `getOrCreatePersonalChatroom` method:
185-
186-
```php
187-
$teacher->getOrCreatePersonalChatroom([
188-
'name' => 'My Personal Chatroom',
189-
'description' => 'This is my personal chatroom for notifications and system messages, and sometimes notes.',
190-
]);
191194
```

docs/src/content/docs/routing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: Documentation for Le Chat routing.
77
Le Chat provides a powerful set of API routes for managing chatrooms and sending messages. These routes are automatically registered by the package.
88

99
## Configuration
10-
Routes are enabled by default. If you publish the package configuration file, you can customize the middleware and prefix used for the API routes in `config/chat.php`:
10+
Routes are enabled by default. You can customize the middleware and prefix used for the API routes in `config/chat.php`:
1111

1212
```php
1313
'features' => [

0 commit comments

Comments
 (0)