diff --git a/app/Bots/NerdBot.php b/app/Bots/NerdBot.php index b02b195d8..d20717d69 100644 --- a/app/Bots/NerdBot.php +++ b/app/Bots/NerdBot.php @@ -307,7 +307,7 @@ class NerdBot $audibles->push(UserAudible::create([ 'user_id' => $target->id, 'bot_id' => $this->bot->id, - 'status' => 0, + 'status' => false, ])); cache()->put('user-audibles'.$target->id, $audibles, 3600); diff --git a/app/Bots/SystemBot.php b/app/Bots/SystemBot.php index f0b6cc657..5de11035c 100644 --- a/app/Bots/SystemBot.php +++ b/app/Bots/SystemBot.php @@ -193,7 +193,7 @@ class SystemBot $audibles->push(UserAudible::create([ 'user_id' => $target->id, 'bot_id' => $this->bot->id, - 'status' => 0, + 'status' => false, ])); cache()->put('user-audibles'.$target->id, $audibles, 3600); diff --git a/app/Http/Controllers/API/ChatController.php b/app/Http/Controllers/API/ChatController.php index 0560b5c99..ab7443d69 100644 --- a/app/Http/Controllers/API/ChatController.php +++ b/app/Http/Controllers/API/ChatController.php @@ -158,7 +158,7 @@ class ChatController extends Controller $audibles->push(UserAudible::create([ 'user_id' => $user->id, 'bot_id' => $bot->id, - 'status' => 0, + 'status' => false, ])); cache()->put('user-audibles'.$user->id, $audibles, 3600); @@ -252,7 +252,7 @@ class ChatController extends Controller $audibles->push(UserAudible::create([ 'user_id' => $user1Id, 'target_id' => $user2Id, - 'status' => 1, + 'status' => true, ])); cache()->put('user-audibles'.$user1Id, $audibles, 3600); diff --git a/app/Http/Resources/UserAudibleResource.php b/app/Http/Resources/UserAudibleResource.php index 8ed0fa794..1977667d3 100644 --- a/app/Http/Resources/UserAudibleResource.php +++ b/app/Http/Resources/UserAudibleResource.php @@ -34,7 +34,7 @@ class UserAudibleResource extends JsonResource * target: ChatUserResource, * room: \App\Models\Chatroom|null, * bot: \App\Models\Bot|null, - * status: int, + * status: bool, * } */ public function toArray(Request $request): array diff --git a/app/Models/UserAudible.php b/app/Models/UserAudible.php index 4d7207111..7773c4d8f 100644 --- a/app/Models/UserAudible.php +++ b/app/Models/UserAudible.php @@ -28,7 +28,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; * @property int|null $room_id * @property int|null $target_id * @property int|null $bot_id - * @property int $status + * @property bool $status * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at */ @@ -44,6 +44,20 @@ class UserAudible extends Model */ protected $guarded = []; + /** + * Get the attributes that should be cast. + * + * @return array{ + * status: 'bool', + * } + */ + protected function casts(): array + { + return [ + 'status' => 'bool', + ]; + } + /** * Get the user that owns the audible. * diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 060c9f414..feddf4d58 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -300,12 +300,6 @@ parameters: count: 1 path: app/Http/Controllers/API/BaseController.php - - - message: '#^Property App\\Models\\UserAudible\:\:\$status \(int\) does not accept bool\.$#' - identifier: assign.propertyType - count: 3 - path: app/Http/Controllers/API/ChatController.php - - message: '#^Parameter \#3 \$callback of method Illuminate\\Cache\\Repository\:\:flexible\(\) contains unresolvable type\.$#' identifier: argument.unresolvableType diff --git a/resources/js/components/alpine/chatbox.js b/resources/js/components/alpine/chatbox.js index 0aa77796b..c5fe7c85b 100644 --- a/resources/js/components/alpine/chatbox.js +++ b/resources/js/components/alpine/chatbox.js @@ -394,7 +394,7 @@ document.addEventListener('alpine:init', () => { } let currentAudio = this.audibles.find((o) => o.room && o.room.id == newVal); - this.state.chat.listening = currentAudio && currentAudio.status == 1 ? 1 : 0; + this.state.chat.listening = currentAudio && currentAudio.status ? 1 : 0; } else if (typeVal == 'target') { this.state.chat.bot = 0; this.state.chat.tab = newVal; @@ -410,7 +410,7 @@ document.addEventListener('alpine:init', () => { } let currentAudio = this.audibles.find((o) => o.target && o.target.id == newVal); - this.state.chat.listening = currentAudio && currentAudio.status == 1 ? 1 : 0; + this.state.chat.listening = currentAudio && currentAudio.status ? 1 : 0; } else if (typeVal == 'bot') { this.state.chat.target = 0; this.state.chat.tab = newVal; @@ -426,7 +426,7 @@ document.addEventListener('alpine:init', () => { } let currentAudio = this.audibles.find((o) => o.bot && o.bot.id == newVal); - this.state.chat.listening = currentAudio && currentAudio.status == 1 ? 1 : 0; + this.state.chat.listening = currentAudio && currentAudio.status ? 1 : 0; } },