56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Namu\WireChat\Models\Conversation;
|
|
use Namu\WireChat\Enums\ConversationType;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\Namu\WireChat\Models\Conversation>
|
|
*/
|
|
class ConversationFactory extends Factory
|
|
{
|
|
/**
|
|
* The name of the factory's corresponding model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $model = Conversation::class;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'type' => ConversationType::Private,
|
|
'disappearing_started_at' => null,
|
|
'disappearing_duration' => null,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Indicate that the conversation is a group.
|
|
*/
|
|
public function group(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'type' => ConversationType::Group,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Indicate that the conversation has disappearing messages enabled.
|
|
*/
|
|
public function withDisappearing(int $duration = 86400): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'disappearing_started_at' => now(),
|
|
'disappearing_duration' => $duration,
|
|
]);
|
|
}
|
|
}
|