Skip to content

Commit

Permalink
improved whereNotPaticipant query
Browse files Browse the repository at this point in the history
  • Loading branch information
myckhel committed Sep 25, 2021
1 parent 0cc4f1b commit c05e3a7
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/Models/Conversation.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ public function last_message(){
* @param Myckhel\ChatSystem\Contarcts\ChatEventMaker $user
* @return QueryBuilder
*/
function scopeWhereNotParticipant($q, $user) {
$q->whereHas('participants', fn ($q) => $q->where('user_id', '!=', $user->id ?? $user));
function scopeWhereNotParticipant($q, ChatEventMaker|int $user) {
$q->whereDoesntHave('participants', fn ($q) => $q->whereUserId($user->id ?? $user));
}

public function participants(): HasMany {
Expand Down Expand Up @@ -222,16 +222,7 @@ public function newCollection(array $models = Array()){

class ConversationCollection extends Collection {
function makeDelivered(ChatEventMaker $user){
$user = $user ?? null;
MakeEvent::dispatch($user, 'deliver', $this)->afterResponse();
return $this;
}

// TODO investigate use
function undelivered($user = null){
$user_id = $user->id ?? $user ?? auth()->user()->id;

return $this->notMsgEvents($user_id, 'deliver')
->where('user_id', '!=', $user_id);
}
}

0 comments on commit c05e3a7

Please sign in to comment.