Skip to content

Commit 6f24677

Browse files
committed
refactor: rename getIsConnectedViaSockets to isConnectedViaSockets for consistency and clarity
chore: update version to 0.3.0 in composer.json docs: clarify message lifecycle and connection methods in documentation
1 parent e45ca74 commit 6f24677

File tree

7 files changed

+14
-12
lines changed

7 files changed

+14
-12
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mmedia/le-chat",
33
"type": "library",
4-
"version": "0.2.1",
4+
"version": "0.3.0",
55
"description": "Add chat functionality to your Laravel application.",
66
"keywords": [
77
"Michal",

docs/src/content/docs/broadcasting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ $yourModel = YourModel::find($id);
123123

124124
$yourModel->is_connected; // Returns true if connected to own private channel
125125
// OR
126-
$yourModel->getIsConnectedViaSockets(); // True if connected, otherwise false. If the connection could not be determined, it will return null.
126+
$yourModel->isConnectedViaSockets(); // True if connected, otherwise false. If the connection could not be determined, it will return null.
127127
```
128128

129129
The default channel is the private channel for the model as defined by the native Laravel `broadcastChannel()` method.
@@ -132,7 +132,7 @@ The default channel is the private channel for the model as defined by the nativ
132132
If you want to check for a specific channel, you can pass the channel name as an argument:
133133

134134
```php
135-
if ($yourModel->getIsConnectedViaSockets('your.channel.name', 'private')) {
135+
if ($yourModel->isConnectedViaSockets('your.channel.name', 'private')) {
136136
// The model is connected to the specified private channel
137137
} else {
138138
// The model is not connected to the specified channel

docs/src/content/docs/participants.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ $teacher->sendMessageTo($chatroom, 'Hi class!');
2828
### The message lifecycle
2929
When you send a message, Le Chat will automatically create a chatroom if one doesn't already exist between only the participants and the sender.
3030

31-
If you send a message to a single participant, Le Chat will create a chatroom with just those two participants (the sender and the recipient). If you add another participant to the chatroom, the next time you `sendMessageTo` the original participant and NOT an array of all the participants, Le Chat will create a new private chatroom with just the sender and the participant.
31+
If you send a message to a single participant, Le Chat will create a chatroom with just those two participants (the sender and the recipient). If you add another participant to the chatroom, the next time you call `sendMessageTo` with only the original participant and NOT an array of all the participants, Le Chat will create a new private chatroom with just the sender and the participant.
3232

3333
```php
3434
$firstMessage = $teacher->sendMessageTo($student, 'Hello!');

src/Models/ChatParticipant.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function scopeOfParticipant(
121121
protected function isConnected(): CastsAttribute
122122
{
123123
return CastsAttribute::make(
124-
get: fn () => $this->getIsConnectedViaSockets(
124+
get: fn () => $this->isConnectedViaSockets(
125125
localId: 'participant_id',
126126
channelName: $this->chatroom->broadcastChannel(),
127127
type: 'presence'

src/Notifications/NewMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function via(object $notifiable): array
4242
$connected = false;
4343

4444
// Check if notifiable has ConnectsToBroadcast trait
45-
if (method_exists($notifiable, 'getIsConnectedViaSockets')) {
45+
if (method_exists($notifiable, 'isConnectedViaSockets')) {
4646
$connected = $notifiable->is_connected;
4747
} else {
4848
$connected = $this->participant->is_connected;

src/Traits/ConnectsToBroadcast.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ trait ConnectsToBroadcast
3232
* @throws \RuntimeException if the broadcast driver is not set or is not supported.
3333
* @throws \Exception if there is an error checking the participant connection status.
3434
*/
35-
public function getIsConnectedViaSockets(?string $channelName = null, string $type = 'private', ?string $localId = null): ?bool
35+
public function isConnectedViaSockets(?string $channelName = null, string $type = 'private', ?string $localId = null): ?bool
3636
{
3737
if (! $channelName && $this instanceof HasBroadcastChannel) {
3838
$channelName = $this->broadcastChannel();
@@ -97,7 +97,7 @@ public function getIsConnectedViaSockets(?string $channelName = null, string $ty
9797
protected function isConnected(): CastsAttribute
9898
{
9999
return CastsAttribute::make(
100-
get: fn () => $this->getIsConnectedViaSockets()
100+
get: fn () => $this->isConnectedViaSockets()
101101
)->shouldCache();
102102
}
103103
}

usage.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ $users = User::whereHasUnreadMessages(7, true)->get(); // unread messages sent i
277277
$users = User::whereHasUnreadMessagesToday(true)->get(); // unread messages sent today, including system messages
278278
```
279279

280+
Le Chat will not consider deleted messages as unread, so if a message was deleted, it will not be counted as unread.
281+
280282
#### Loading unread messages count
281283
You can load the unread messages count for a participant in a chatroom using the `loadUnreadMessagesCount` method. This will load the `unread_messages_count` attribute on the participant model.
282284

@@ -355,10 +357,10 @@ $user->isConnectedToChatroomViaSockets($chatroom);
355357
$chatParticipant->is_connected;
356358

357359
# OR, if using the trait (note, this will check the model-specific broadcasting channel, not the chatroom channel)
358-
$user->getIsConnectedViaSockets();
360+
$user->isConnectedViaSockets();
359361
```
360362

361-
If you want to use this feature for your own models, you can use the `ConnectsToBroadcast` trait, which will provide the `getIsConnectedViaSockets` method. This method will return true if the participant is connected to the chatroom via sockets, false if they are not, and null if the connection could not be determined (e.g. if the broadcast driver does not support it).
363+
If you want to use this feature for your own models, you can use the `ConnectsToBroadcast` trait, which will provide the `isConnectedViaSockets` method. This method will return true if the participant is connected to the chatroom via sockets, false if they are not, and null if the connection could not be determined (e.g. if the broadcast driver does not support it).
362364

363365
Under the hood, it makes an API call to the websocket server to check if the participant is connected to the chatroom.
364366

@@ -368,7 +370,7 @@ use Illuminate\Database\Eloquent\Casts\Attribute as CastsAttribute;
368370
protected function isConnected(): CastsAttribute
369371
{
370372
return CastsAttribute::make(
371-
get: fn() => $this->getIsConnectedViaSockets()
373+
get: fn() => $this->isConnectedViaSockets()
372374
)->shouldCache();
373375
}
374376
```
@@ -377,7 +379,7 @@ This will check using the `broadcastChannel` of the model, if the user is curren
377379

378380
If you want to check if the model is connected to a presence channel, you can pass the chatroom name and type as parameters to the method:
379381
```php
380-
$chatParticipant->getIsConnectedViaSockets(
382+
$chatParticipant->isConnectedViaSockets(
381383
type: 'presence',
382384
channelName: $this->broadcastChannel(), // or any other chatroom name
383385
localId: 'id' // the local ID of the model, defaults to 'id'. This is the ID column on the model that will be used to check if the participant is connected to the chatroom - this is only relevant in presence channels. In private channels, we can only determine if the participant is connected or not, not which participant is connected.

0 commit comments

Comments
 (0)