WireChat provides a flexible action system for managing chat interactions. You can enable or disable built-in actions and implement custom actions for your specific use cases.
public function deleteConversation(){ abort_unless(auth()->check(), 401); // Delete conversation for the authenticated user $this->conversation->deleteFor($this->auth); $this->handleComponentTermination( redirectRoute: $this->panel()->chatsRoute(), events: [ 'close-chat', Chats::class => ['chat-deleted', [$this->conversation->id]], ] );}
Allow any participant to hide messages from their view:
src/Livewire/Chat/Chat.php
public function deleteForMe(string $id): void{ $messageId = decrypt($id); $message = Message::where('id', $messageId)->firstOrFail(); // Verify user belongs to conversation abort_unless(auth()->check(), 401); abort_unless($this->auth->belongsToConversation($message->conversation), 403); // Remove from UI $this->removeMessage($message); // Soft delete for user $message->deleteFor($this->auth); // Refresh chat list $this->dispatch('refresh')->to(Chats::class);}
Allow message owners or admins to delete messages for all participants:
src/Livewire/Chat/Chat.php
public function deleteForEveryone(string $id): void{ $messageId = decrypt($id); $message = Message::where('id', $messageId)->firstOrFail(); $authParticipant = $this->conversation->participant($this->auth); abort_unless(auth()->check(), 401); // Allow if user owns message OR is admin in group abort_unless( $message->ownedBy($this->auth) || ($authParticipant->isAdmin() && $this->conversation->isGroup()), 403 ); // Remove from UI $this->removeMessage($message); // Broadcast deletion event MessageDeleted::dispatch($message); // Soft delete if has replies, otherwise force delete if ($message->hasReply()) { $message->delete(); } else { $message->forceDelete(); }}
WireChat includes an Action model for tracking user activities:
src/Models/Action.php
namespace Wirechat\Wirechat\Models;use Illuminate\Database\Eloquent\Model;use Wirechat\Wirechat\Enums\Actions;class Action extends Model{ protected $fillable = [ 'actor_id', 'actor_type', 'actionable_id', 'actionable_type', 'type', 'data', ]; protected $casts = [ 'type' => Actions::class, ]; // Polymorphic relationship to the entity being acted upon public function actionable(): MorphTo { return $this->morphTo(null, 'actionable_type', 'actionable_id', 'id'); } // Polymorphic relationship to the actor public function actor(): MorphTo { return $this->morphTo('actor', 'actor_type', 'actor_id', 'id'); } // Scope by actor public function scopeWhereActor(Builder $query, Model $actor) { $query->where('actor_id', $actor->getKey()) ->where('actor_type', $actor->getMorphClass()); }}