Enhance chat functionality: add support for vendor-specific chat channels, implement methods for managing conversations with admin and store owners, and improve conversation payload structure. Update middleware and policies for better access control, and refine chat UI to indicate view-only status for store owner replies.
This commit is contained in:
@@ -46,10 +46,22 @@ class Channel extends Model implements HasMedia, Sortable
|
||||
'sort_order',
|
||||
'is_default',
|
||||
'is_visible',
|
||||
'chatting',
|
||||
'channelables_type',
|
||||
'channelables_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'is_default' => 'boolean',
|
||||
'is_visible' => 'boolean',
|
||||
'chatting' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Sortable attributes
|
||||
*
|
||||
@@ -158,6 +170,26 @@ class Channel extends Model implements HasMedia, Sortable
|
||||
return $this->belongsTo(User::class, 'channelables_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores that visitors may start a chat with.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder<static> $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder<static>
|
||||
*/
|
||||
public function scopeChatTargets($query, ?User $viewer = null)
|
||||
{
|
||||
$supportId = (int) config('chat.support_user_id');
|
||||
|
||||
return $query
|
||||
->where('is_visible', true)
|
||||
->where('chatting', true)
|
||||
->where('channelables_type', User::class)
|
||||
->whereNotNull('channelables_id')
|
||||
->whereHas('user')
|
||||
->when($viewer, fn ($query) => $query->where('channelables_id', '!=', $viewer->id))
|
||||
->when($supportId > 0, fn ($query) => $query->where('channelables_id', '!=', $supportId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Default tmpost inventory
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user