Skip to content

Commit 717a27e

Browse files
committed
Merge branch 'master' into v2
2 parents 3da74c4 + 2534abe commit 717a27e

File tree

7 files changed

+61
-34
lines changed

7 files changed

+61
-34
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ php:
44
- 5.6
55
- 7.0
66
- 7.1
7+
- 7.2
8+
- nightly
9+
10+
matrix:
11+
allow_failures:
12+
- php: 7.2
13+
- php: nightly
714

815
# This triggers builds to run on the new TravisCI infrastructure.
916
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014-2017 Chris Gmyr <[email protected]>
3+
Copyright (c) 2014-2018 Chris Gmyr <[email protected]>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

nitpick.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"ignore": [
3-
"tests/*",
4-
"src/migrations/*"
3+
"examples/*",
4+
"migrations/*",
5+
"tests/*"
56
]
67
}

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ If you discover any security related issues, please email [Chris Gmyr](mailto:cm
125125
## Credits
126126

127127
- [Chris Gmyr](https://github.com/cmgmyr)
128+
- [Anton Komarev](https://github.com/a-komarev)
128129
- [All Contributors](../../contributors)
129130

130131
### Special Thanks

src/MessengerServiceProvider.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ protected function offerPublishing()
6363
}
6464
}
6565

66+
/**
67+
* Define Messenger's models in registry.
68+
*
69+
* @return void
70+
*/
6671
protected function setMessengerModels()
6772
{
6873
$config = $this->app->make('config');
@@ -78,12 +83,17 @@ protected function setMessengerModels()
7883
]);
7984
}
8085

86+
/**
87+
* Define User model in Messenger's model registry.
88+
*
89+
* @return void
90+
*/
8191
protected function setUserModel()
8292
{
8393
$config = $this->app->make('config');
8494

85-
$model = $config->get('auth.providers.users.model', function () use ($config) {
86-
return $config->get('auth.model', $config->get('messenger.user_model'));
95+
$model = $config->get('messenger.user_model', function () use ($config) {
96+
return $config->get('auth.providers.users.model', $config->get('auth.model'));
8797
});
8898

8999
Models::setUserModel($model);

src/Models/Message.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Illuminate\Database\Eloquent\Builder;
66
use Illuminate\Database\Eloquent\Model as Eloquent;
77
use Illuminate\Database\Eloquent\SoftDeletes;
8-
use Illuminate\Support\Facades\DB;
98

109
class Message extends Eloquent
1110
{
@@ -98,9 +97,9 @@ public function recipients()
9897
/**
9998
* Returns unread messages given the userId.
10099
*
101-
* @param Builder $query
102-
* @param $userId
103-
* @return Builder
100+
* @param \Illuminate\Database\Eloquent\Builder $query
101+
* @param int $userId
102+
* @return \Illuminate\Database\Eloquent\Builder
104103
*/
105104
public function scopeUnreadForUser(Builder $query, $userId)
106105
{
@@ -109,7 +108,7 @@ public function scopeUnreadForUser(Builder $query, $userId)
109108
->whereHas('participants', function (Builder $query) use ($userId) {
110109
$query->where('user_id', $userId)
111110
->where(function (Builder $q) {
112-
$q->where('last_read', '<', DB::raw($this->getTable() . '.created_at'))
111+
$q->where('last_read', '<', $this->getConnection()->raw($this->getConnection()->getTablePrefix() . $this->getTable() . '.created_at'))
113112
->orWhereNull('last_read');
114113
});
115114
});

src/Models/Thread.php

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ class Thread extends Eloquent
3232
* @var array
3333
*/
3434
protected $dates = ['deleted_at'];
35-
35+
3636
/**
37-
* Internal cache for creator.
38-
*
39-
* @var null|Models::user()
40-
*/
37+
* Internal cache for creator.
38+
*
39+
* @var null|Models::user()
40+
*/
4141
protected $creatorCache = null;
4242

4343
/**
@@ -65,7 +65,7 @@ public function messages()
6565
/**
6666
* Returns the latest message from a thread.
6767
*
68-
* @return \Cmgmyr\Messenger\Models\Message
68+
* @return null|\Cmgmyr\Messenger\Models\Message
6969
*/
7070
public function getLatestMessageAttribute()
7171
{
@@ -114,22 +114,23 @@ public function creator()
114114
/**
115115
* Returns all of the latest threads by updated_at date.
116116
*
117-
* @return self
117+
* @return \Illuminate\Database\Query\Builder|static
118118
*/
119119
public static function getAllLatest()
120120
{
121-
return self::latest('updated_at');
121+
return static::latest('updated_at');
122122
}
123123

124124
/**
125125
* Returns all threads by subject.
126126
*
127127
* @param string $subject
128-
* @return self
128+
*
129+
* @return \Illuminate\Database\Eloquent\Collection|static[]
129130
*/
130131
public static function getBySubject($subject)
131132
{
132-
return self::where('subject', 'like', $subject)->get();
133+
return static::where('subject', 'like', $subject)->get();
133134
}
134135

135136
/**
@@ -155,10 +156,10 @@ public function participantsUserIds($userId = null)
155156
/**
156157
* Returns threads that the user is associated with.
157158
*
158-
* @param Builder $query
159-
* @param $userId
159+
* @param \Illuminate\Database\Eloquent\Builder $query
160+
* @param int $userId
160161
*
161-
* @return Builder
162+
* @return \Illuminate\Database\Eloquent\Builder
162163
*/
163164
public function scopeForUser(Builder $query, $userId)
164165
{
@@ -174,10 +175,10 @@ public function scopeForUser(Builder $query, $userId)
174175
/**
175176
* Returns threads with new messages that the user is associated with.
176177
*
177-
* @param Builder $query
178-
* @param $userId
178+
* @param \Illuminate\Database\Eloquent\Builder $query
179+
* @param int $userId
179180
*
180-
* @return Builder
181+
* @return \Illuminate\Database\Eloquent\Builder
181182
*/
182183
public function scopeForUserWithNewMessages(Builder $query, $userId)
183184
{
@@ -197,10 +198,10 @@ public function scopeForUserWithNewMessages(Builder $query, $userId)
197198
/**
198199
* Returns threads between given user ids.
199200
*
200-
* @param Builder $query
201+
* @param \Illuminate\Database\Eloquent\Builder $query
201202
* @param array $participants
202203
*
203-
* @return Builder
204+
* @return \Illuminate\Database\Eloquent\Builder
204205
*/
205206
public function scopeBetween(Builder $query, array $participants)
206207
{
@@ -216,6 +217,8 @@ public function scopeBetween(Builder $query, array $participants)
216217
* Add users to thread as participants.
217218
*
218219
* @param array|mixed $userId
220+
*
221+
* @return void
219222
*/
220223
public function addParticipant($userId)
221224
{
@@ -233,6 +236,8 @@ public function addParticipant($userId)
233236
* Remove participants from thread.
234237
*
235238
* @param array|mixed $userId
239+
*
240+
* @return void
236241
*/
237242
public function removeParticipant($userId)
238243
{
@@ -245,6 +250,8 @@ public function removeParticipant($userId)
245250
* Mark a thread as read for a user.
246251
*
247252
* @param int $userId
253+
*
254+
* @return void
248255
*/
249256
public function markAsRead($userId)
250257
{
@@ -286,7 +293,7 @@ public function isUnread($userId)
286293
*
287294
* @return mixed
288295
*
289-
* @throws ModelNotFoundException
296+
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
290297
*/
291298
public function getParticipantFromUser($userId)
292299
{
@@ -295,6 +302,8 @@ public function getParticipantFromUser($userId)
295302

296303
/**
297304
* Restores all participants within a thread that has a new message.
305+
*
306+
* @return void
298307
*/
299308
public function activateAllParticipants()
300309
{
@@ -307,7 +316,7 @@ public function activateAllParticipants()
307316
/**
308317
* Generates a string of participant information.
309318
*
310-
* @param null $userId
319+
* @param null|int $userId
311320
* @param array $columns
312321
*
313322
* @return string
@@ -335,7 +344,7 @@ public function participantsString($userId = null, $columns = ['name'])
335344
/**
336345
* Checks to see if a user is a current participant of the thread.
337346
*
338-
* @param $userId
347+
* @param int $userId
339348
*
340349
* @return bool
341350
*/
@@ -352,7 +361,7 @@ public function hasParticipant($userId)
352361
/**
353362
* Generates a select string used in participantsString().
354363
*
355-
* @param $columns
364+
* @param array $columns
356365
*
357366
* @return string
358367
*/
@@ -383,7 +392,7 @@ protected function createSelectString($columns)
383392
/**
384393
* Returns array of unread messages in thread for given user.
385394
*
386-
* @param $userId
395+
* @param int $userId
387396
*
388397
* @return \Illuminate\Support\Collection
389398
*/
@@ -409,7 +418,7 @@ public function userUnreadMessages($userId)
409418
/**
410419
* Returns count of unread messages in thread for given user.
411420
*
412-
* @param $userId
421+
* @param int $userId
413422
*
414423
* @return int
415424
*/

0 commit comments

Comments
 (0)