Skip to content

Commit

Permalink
Removed type column from chats table
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasss93 committed Oct 28, 2021
1 parent ec05731 commit 3136ad3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
14 changes: 0 additions & 14 deletions app/Telegram/Middleware/CollectChat.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Models\Chat;
use Illuminate\Support\Facades\DB;
use SergiX44\Nutgram\Nutgram;
use SergiX44\Nutgram\Telegram\Attributes\UpdateTypes;

class CollectChat
{
Expand All @@ -19,23 +18,10 @@ public function __invoke(Nutgram $bot, $next): void

$chat = DB::transaction(function () use ($user, $bot) {

//get chat type
$type = match ($bot->update()?->getType()) {
UpdateTypes::MESSAGE => $bot->update()->message->chat->type,
UpdateTypes::EDITED_MESSAGE => $bot->update()->edited_message->chat->type,
UpdateTypes::INLINE_QUERY, UpdateTypes::CALLBACK_QUERY => 'private',
default => 'unknown',
};

if ($type === 'unknown') {
info('unknown', [$bot->update()]);
}

//save or update chat
$chat = Chat::updateOrCreate([
'chat_id' => $user->id,
], [
'type' => $type,
'first_name' => $user->first_name,
'last_name' => $user->last_name,
'username' => $user->username,
Expand Down
21 changes: 21 additions & 0 deletions database/migrations/2021_10_29_015610_change_chats_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
public function up(): void
{
Schema::table('chats', function (Blueprint $table) {
$table->dropColumn('type');
});
}

public function down(): void
{
Schema::table('chats', function (Blueprint $table) {
$table->string('type');
});
}
};

0 comments on commit 3136ad3

Please sign in to comment.