Skip to content

Commit

Permalink
changed notMsgEvents to whereDoesntHaveChatEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
myckhel committed Sep 25, 2021
1 parent c05e3a7 commit f8db80a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs
Submodule docs updated from 8df739 to 91575f
2 changes: 1 addition & 1 deletion src/Jobs/Chat/MakeEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function handle()
} else {
// get unread msg for conversations
$undelivered = Config::config('models.message')::with('conversation')
->notMsgEvents('deliver', $this->user->id, fn ($q) =>
->whereDoesntHaveChatEvents('deliver', $this->user->id, fn ($q) =>
$q->whereIn('id', $conversation->pluck('id'))
)->where('user_id', '!=', $this->user->id)->get();

Expand Down
22 changes: 14 additions & 8 deletions src/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,22 @@ protected static function newFactory(){
return MessageFactory::new();
}

function scopeNotMsgEvents($q, $type = null, ChatEventMaker|int $user = null, $conversationScope = null) {
function scopeWhereDoesntHaveChatEvents($q, $type = null, ChatEventMaker|int $user = null, $conversationScope = null) {
$user_id = $user->id ?? $user ?? auth()->user()->id;

$q->whereHas('conversation', fn ($q) =>
if ($type == 'delete') {
$q->whereDoesntHave('chatEvents', fn ($q) =>
$q->whereMakerId($user_id)
->when($type, fn ($q) => $q->whereType($type))
->whereColumn('created_at', '>', 'messages.created_at')
)->when($conversationScope, $conversationScope)
);
$q->whereMakerId($user_id)->whereType($type)
);
} else {
$q->whereHas('conversation', fn ($q) =>
$q->whereDoesntHave('chatEvents', fn ($q) =>
$q->whereMakerId($user_id)
->when($type, fn ($q) => $q->whereType($type))
->whereColumn('created_at', '>', 'messages.created_at')
)->when($conversationScope, $conversationScope)
);
}
}

function scopeWhereRelatedToUser($q, ChatEventMaker|int $user) {
Expand Down Expand Up @@ -96,7 +102,7 @@ function participantsHasDeleted(int $maker_id = null){
->when($maker_id, fn ($q) => $q->where('maker_id', '!=', $maker_id))
->count()
];
return $deleteEventsCount == $participantsCount-1;
return $deleteEventsCount == $participantsCount - 1;
}

function makeDelete(ChatEventMaker $user, $all = false) {
Expand Down

0 comments on commit f8db80a

Please sign in to comment.