Skip to content

Commit 735b4b7

Browse files
authored
Merge pull request #5261 from Roardom/combine-chatbox-echoes-audibles
(Refactor) Combine chatbox audibles and echoes into conversations
2 parents 0496d32 + 3ff816d commit 735b4b7

File tree

19 files changed

+275
-524
lines changed

19 files changed

+275
-524
lines changed

app/Bots/NerdBot.php

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@
1717
namespace App\Bots;
1818

1919
use App\Events\Chatter;
20-
use App\Http\Resources\UserAudibleResource;
21-
use App\Http\Resources\UserEchoResource;
20+
use App\Http\Resources\ChatConversationResource;
2221
use App\Models\Ban;
2322
use App\Models\Bot;
23+
use App\Models\ChatConversation;
2424
use App\Models\Peer;
2525
use App\Models\Torrent;
2626
use App\Models\User;
27-
use App\Models\UserAudible;
28-
use App\Models\UserEcho;
2927
use App\Models\Warning;
3028
use App\Repositories\ChatRepository;
3129
use Illuminate\Support\Carbon;
@@ -282,31 +280,17 @@ public function pm(): true|\Illuminate\Http\Response
282280
$message = $this->message;
283281

284282
if ($type === 'message' || $type === 'private') {
285-
// Create echo for user if missing
286-
$affected = UserEcho::query()->upsert([[
287-
'user_id' => $target->id,
288-
'bot_id' => $this->bot->id,
289-
]], ['user_id', 'bot_id']);
283+
// Create chat conversation for user if missing
284+
$affected = ChatConversation::query()->upsert([[
285+
'user_id' => $target->id,
286+
'bot_id' => $this->bot->id,
287+
'status' => false,
288+
'deleted_at' => null,
289+
]], ['user_id', 'bot_id'], ['deleted_at']);
290290

291291
if ($affected === 1) {
292-
Chatter::dispatch('echo', $target->id, UserEchoResource::collection(
293-
UserEcho::query()
294-
->with(['user', 'room', 'target', 'bot'])
295-
->where('user_id', '=', $target->id)
296-
->get()
297-
));
298-
}
299-
300-
// Create audible for user if missing
301-
$affected = UserAudible::query()->upsert([[
302-
'user_id' => $target->id,
303-
'bot_id' => $this->bot->id,
304-
'status' => false,
305-
]], ['user_id', 'bot_id']);
306-
307-
if ($affected === 1) {
308-
Chatter::dispatch('audible', $target->id, UserAudibleResource::collection(
309-
UserAudible::query()
292+
Chatter::dispatch('conversations', $target->id, ChatConversationResource::collection(
293+
ChatConversation::query()
310294
->with(['user', 'room', 'target', 'bot'])
311295
->where('user_id', '=', $target->id)
312296
->get()

app/Bots/SystemBot.php

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
namespace App\Bots;
1818

1919
use App\Events\Chatter;
20-
use App\Http\Resources\UserAudibleResource;
21-
use App\Http\Resources\UserEchoResource;
20+
use App\Http\Resources\ChatConversationResource;
2221
use App\Models\Bot;
22+
use App\Models\ChatConversation;
2323
use App\Models\Gift;
2424
use App\Models\User;
25-
use App\Models\UserAudible;
26-
use App\Models\UserEcho;
2725
use App\Notifications\NewBon;
2826
use App\Repositories\ChatRepository;
2927

@@ -164,31 +162,17 @@ public function pm(): \Illuminate\Http\Response|true
164162
$message = $this->message;
165163

166164
if ($type === 'message' || $type === 'private') {
167-
// Create echo for user if missing
168-
$affected = UserEcho::query()->upsert([[
169-
'user_id' => $target->id,
170-
'bot_id' => $this->bot->id,
171-
]], ['user_id', 'bot_id']);
165+
// Create conversation for user if missing
166+
$affected = ChatConversation::query()->upsert([[
167+
'user_id' => $target->id,
168+
'bot_id' => $this->bot->id,
169+
'status' => false,
170+
'deleted_at' => null,
171+
]], ['user_id', 'bot_id'], ['deleted_at']);
172172

173173
if ($affected === 1) {
174-
Chatter::dispatch('echo', $target->id, UserEchoResource::collection(
175-
UserEcho::query()
176-
->with(['user', 'room', 'target', 'bot'])
177-
->where('user_id', '=', $target->id)
178-
->get()
179-
));
180-
}
181-
182-
// Create audible for user if missing
183-
$affected = UserAudible::query()->upsert([[
184-
'user_id' => $target->id,
185-
'bot_id' => $this->bot->id,
186-
'status' => false,
187-
]], ['user_id', 'bot_id']);
188-
189-
if ($affected === 1) {
190-
Chatter::dispatch('audible', $target->id, UserAudibleResource::collection(
191-
UserAudible::query()
174+
Chatter::dispatch('conversations', $target->id, ChatConversationResource::collection(
175+
ChatConversation::query()
192176
->with(['user', 'room', 'target', 'bot'])
193177
->where('user_id', '=', $target->id)
194178
->get()

app/Events/Chatter.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Chatter implements ShouldBroadcastNow
3030
use InteractsWithSockets;
3131
use SerializesModels;
3232

33-
public ?AnonymousResourceCollection $echoes = null;
33+
public ?AnonymousResourceCollection $conversations = null;
3434

3535
public ?ChatMessageResource $message = null;
3636

@@ -42,30 +42,25 @@ class Chatter implements ShouldBroadcastNow
4242
*/
4343
public ?array $ping = null;
4444

45-
public ?AnonymousResourceCollection $audibles = null;
46-
4745
/**
4846
* Chatter Constructor.
4947
*/
5048
public function __construct(
51-
/** @var 'echo'|'audible'|'new.message'|'new.bot'|'new.ping' $type */
49+
/** @var 'conversations'|'new.message'|'new.bot'|'new.ping' $type */
5250
public string $type,
5351
public int $target,
5452
/** @var (
55-
* $type is 'echo' ? AnonymousResourceCollection
56-
* : ($type is 'audible' ? AnonymousResourceCollection
57-
* : ($type is 'new.message' ? ChatMessageResource
58-
* : ($type is 'new.bot' ? ChatMessageResource
59-
* : ($type is 'new.ping' ? array{type: 'bot'|'target', id: int}
53+
* $type is 'conversations' ? AnonymousResourceCollection
54+
* : ($type is 'new.message' ? ChatMessageResource
55+
* : ($type is 'new.bot' ? ChatMessageResource
56+
* : ($type is 'new.ping' ? array{type: 'bot'|'target', id: int}
6057
* : never
61-
* ))))) $payload
58+
* )))) $payload
6259
*/
6360
mixed $payload,
6461
) {
65-
if ($type == 'echo') {
66-
$this->echoes = $payload;
67-
} elseif ($type == 'audible') {
68-
$this->audibles = $payload;
62+
if ($type == 'conversations') {
63+
$this->conversations = $payload;
6964
} elseif ($type == 'new.message') {
7065
$this->message = $payload;
7166
} elseif ($type == 'new.bot') {

0 commit comments

Comments
 (0)