mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-04-24 03:59:08 -05:00
refactor: chatbox user chat status
Only save the user's chat status in one place, and sync it with the server when it's updated.
This commit is contained in:
@@ -420,7 +420,7 @@ class ChatController extends Controller
|
||||
}
|
||||
|
||||
/* USERS */
|
||||
public function updateUserChatStatus(Request $request): \Illuminate\Http\JsonResponse
|
||||
public function updateUserChatStatus(Request $request): \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
|
||||
{
|
||||
$user = $request->user();
|
||||
$user->load(['chatStatus', 'chatroom', 'group', 'echoes']);
|
||||
@@ -432,7 +432,7 @@ class ChatController extends Controller
|
||||
$user->chatStatus()->associate($status);
|
||||
$user->save();
|
||||
|
||||
return response()->json($user);
|
||||
return response('success');
|
||||
}
|
||||
|
||||
public function updateUserRoom(Request $request): \Illuminate\Http\JsonResponse
|
||||
|
||||
@@ -158,7 +158,6 @@ document.addEventListener('alpine:init', () => {
|
||||
|
||||
auth: user,
|
||||
statuses: [],
|
||||
status: 0,
|
||||
echoes: [],
|
||||
chatrooms: [],
|
||||
messages: [],
|
||||
@@ -208,6 +207,8 @@ document.addEventListener('alpine:init', () => {
|
||||
this.state.ui.loading = false;
|
||||
});
|
||||
|
||||
this.$watch('auth.chat_status_id', (status) => this.syncStatus());
|
||||
|
||||
this.$cleanup = () => {
|
||||
if (this.channel) {
|
||||
window.Echo.leave(`chatroom.${this.state.chat.room}`);
|
||||
@@ -676,18 +677,12 @@ document.addEventListener('alpine:init', () => {
|
||||
this.state.chat.showWhispers = !this.state.chat.showWhispers;
|
||||
},
|
||||
|
||||
changeStatus(status_id) {
|
||||
this.status = status_id;
|
||||
if (this.auth.chat_status.id !== status_id) {
|
||||
axios
|
||||
.post(`/api/chat/user/status`, { status_id })
|
||||
.then((response) => {
|
||||
this.auth = response.data;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error changing status:', error);
|
||||
});
|
||||
}
|
||||
syncStatus() {
|
||||
axios
|
||||
.post(`/api/chat/user/status`, { status_id: this.auth.chat_status_id })
|
||||
.catch((error) => {
|
||||
console.error('Error changing status:', error);
|
||||
});
|
||||
},
|
||||
|
||||
startBot() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@php
|
||||
$user = App\Models\User::with(['chatStatus', 'chatroom', 'group'])->find(auth()->id());
|
||||
$user = App\Models\User::with(['chatroom', 'group'])->find(auth()->id());
|
||||
@endphp
|
||||
|
||||
<section
|
||||
@@ -99,7 +99,6 @@
|
||||
id="currentChatroom"
|
||||
class="form__select"
|
||||
x-model.number="state.chat.room"
|
||||
@change="changeRoom(state.chat.room)"
|
||||
>
|
||||
<template x-for="chatroom in chatrooms" :key="chatroom.id">
|
||||
<option :value="chatroom.id" x-text="chatroom.name"></option>
|
||||
@@ -115,11 +114,14 @@
|
||||
<select
|
||||
id="currentChatstatus"
|
||||
class="form__select"
|
||||
x-model.number="status"
|
||||
@change="changeStatus(status)"
|
||||
x-model.number="auth.chat_status_id"
|
||||
>
|
||||
<template x-for="chatstatus in statuses" :key="chatstatus.id">
|
||||
<option :value="chatstatus.id" x-text="chatstatus.name"></option>
|
||||
<option
|
||||
:value="chatstatus.id"
|
||||
:selected="chatstatus.id === auth.chat_status_id"
|
||||
x-text="chatstatus.name"
|
||||
></option>
|
||||
</template>
|
||||
</select>
|
||||
<label class="form__label form__label--floating" for="currentChatstatus">
|
||||
|
||||
Reference in New Issue
Block a user