Skip to content

Commit

Permalink
renamed withTrashed to withAll
Browse files Browse the repository at this point in the history
  • Loading branch information
myckhel committed Oct 16, 2021
1 parent 466055d commit e4d2516
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/Http/Controllers/ConversationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ public function index(PaginableRequest $request)
])
->orderByDesc('latest_message_at')
->with([
// 'chatEvents' => fn ($q) => $q->groupBy('chat_events.id', 'chat_events.maker_type', 'chat_events.maker_id', 'chat_events.made_type', 'chat_events.made_id', 'chat_events.all', 'chat_events.created_at', 'chat_events.updated_at'),
'delivery' => fn ($q) => $queryEvent($q)->where('maker_id', '!=', $user->id),
'read' => fn ($q) => $queryEvent($q)->where('maker_id', '!=', $user->id),
'trashed' => $queryEvent,
'last_message' => fn ($q) => $q->select(['id','user_id','message','conversation_id', 'created_at'])
->with([
// 'latestMedia' => fn ($q) => $q->select('id', 'model_type', 'model_id', 'name'),
'trashed' => fn ($q) => $q->withTrashed($user)
'trashed' => fn ($q) => $q->withAll($user)
]),
'participant' => fn ($q) => $q->select('id', 'user_id', 'conversation_id')->where('user_id', '!=', $user->id),
'participant.user' => fn ($q) => $q,//->withUrls(['avatar']),
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/MessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function index(PaginableRequest $request)
$reply = [];
$with = [
'reply',
'trashed' => fn ($q) => $q->withTrashed($user),
'trashed' => fn ($q) => $q->withAll($user),
'sender',
];

Expand Down
10 changes: 4 additions & 6 deletions src/Models/ChatEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,20 @@ protected static function newFactory(){
return ChatEventFactory::new();
}

function scopeWithTrashed($q, ChatEventMaker $user) {
$q->select('id', 'maker_id', 'maker_type', 'made_id', 'made_type', 'all')->whereMakerId($user->id)->orWhere('all', true);
function scopeWithAll($q, ChatEventMaker $user) {
$q->select('*')->whereMakerId($user->id)->orWhere('all', true);
}

function scopeNotMessanger($q, ChatEventMaker|int $user) {
$q->whereDoesntHave('message', fn($q) => $q->whereUserId($user->id ?? $user));
}

function message(): BelongsTo {
$message = self::config('models.message');
return $this->belongsTo($message, 'made_id')->whereMadeType($message);
return $this->belongsTo(self::config('models.message'), 'made_id');
}

function conversation(): BelongsTo {
$conversation = self::config('models.conversation');
return $this->belongsTo($conversation, 'made_id')->whereMadeType($conversation);
return $this->belongsTo(self::config('models.conversation'), 'made_id');
}

function maker(): MorphTo{
Expand Down

0 comments on commit e4d2516

Please sign in to comment.