Nachrichten-Plugin 1.0.0: Direktnachrichten, Gruppen, Anhänge, GIFs, Emojis
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
2844452002
55 changed files with 5448 additions and 0 deletions
153
src/Filament/Pages/ChatSettings.php
Normal file
153
src/Filament/Pages/ChatSettings.php
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Chat\Filament\Pages;
|
||||
|
||||
use App\Support\Audit;
|
||||
use App\Support\Settings;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Text;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* Nachrichten: GIPHY, Echtzeit (Pusher-kompatibel) und Größe von Anhängen.
|
||||
*/
|
||||
class ChatSettings extends Page
|
||||
{
|
||||
protected string $view = 'filament.pages.settings-form';
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedChatBubbleLeftRight;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Portal';
|
||||
|
||||
protected static ?int $navigationSort = 40;
|
||||
|
||||
protected static ?string $navigationLabel = 'Nachrichten';
|
||||
|
||||
protected static ?string $title = 'Nachrichten';
|
||||
|
||||
protected static ?string $slug = 'nachrichten';
|
||||
|
||||
/** @var array<string, mixed>|null */
|
||||
public ?array $data = [];
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return auth()->user()?->can('chat.manage') ?? false;
|
||||
}
|
||||
|
||||
public function mount(Settings $settings): void
|
||||
{
|
||||
$this->form->fill([
|
||||
'max_upload_mb' => (int) $settings->get('chat.max_upload_mb', 25),
|
||||
'giphy_key' => null,
|
||||
'giphy_rating' => $settings->get('chat.giphy_rating', 'g'),
|
||||
'realtime_enabled' => (bool) $settings->get('chat.realtime.enabled'),
|
||||
'realtime_app_id' => $settings->get('chat.realtime.app_id'),
|
||||
'realtime_key' => $settings->get('chat.realtime.key'),
|
||||
'realtime_secret' => null,
|
||||
'realtime_host' => $settings->get('chat.realtime.host'),
|
||||
'realtime_port' => $settings->get('chat.realtime.port'),
|
||||
'realtime_scheme' => $settings->get('chat.realtime.scheme', 'https'),
|
||||
'realtime_cluster' => $settings->get('chat.realtime.cluster', 'mt1'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
$settings = app(Settings::class);
|
||||
$realtime = fn (Get $get) => (bool) $get('realtime_enabled');
|
||||
|
||||
return $schema->components([
|
||||
Section::make('Allgemein')->schema([
|
||||
Text::make('Direktnachrichten dürfen alle schreiben; Gruppen anlegen nur, wer das Recht „Gruppenchats anlegen“ hat (Rollen). Die Administration kann Gespräche nicht mitlesen.'),
|
||||
TextInput::make('max_upload_mb')->label('Größe je Anhang (MB)')->numeric()->minValue(1)->maxValue(200)->required()
|
||||
->helperText('Der Server begrenzt Uploads zusätzlich (upload_max_filesize: '.ini_get('upload_max_filesize').').'),
|
||||
]),
|
||||
Section::make('GIFs')->columns(2)->schema([
|
||||
Text::make('Die eigene GIF-Sammlung pflegen Sie unter „Chat-GIFs“ – sie bleibt im Haus. Zusätzlich lässt sich die Suche bei GIPHY einschalten: Dann gehen Suchbegriffe an GIPHY, und die Bilder werden von dort geladen.')->columnSpanFull(),
|
||||
TextInput::make('giphy_key')->label('GIPHY API-Schlüssel')->password()->revealable()->maxLength(100)->autocomplete('new-password')
|
||||
->helperText(filled($settings->get('chat.giphy_key')) ? 'Gespeichert. Leer lassen, um ihn zu behalten.' : 'Kostenlos unter developers.giphy.com. Leer = GIPHY aus.'),
|
||||
Select::make('giphy_rating')->label('Jugendschutz')->native(false)->selectablePlaceholder(false)
|
||||
->options(['g' => 'G – für alle', 'pg' => 'PG', 'pg-13' => 'PG-13']),
|
||||
]),
|
||||
Section::make('Echtzeit (optional)')->columns(2)->schema([
|
||||
Text::make('Ohne Einrichtung fragt der Chat alle paar Sekunden nach neuen Nachrichten – das funktioniert überall. Mit einem Pusher-kompatiblen Dienst (Laravel Reverb, Soketi oder pusher.com) kommen Nachrichten sofort. Über den Dienst geht nur ein Signal „es gibt Neues“, keine Inhalte.')->columnSpanFull(),
|
||||
Toggle::make('realtime_enabled')->label('Echtzeit einschalten')->live()->columnSpanFull(),
|
||||
TextInput::make('realtime_app_id')->label('App-ID')->maxLength(100)->required($realtime)->visible($realtime),
|
||||
TextInput::make('realtime_key')->label('Key')->maxLength(100)->required($realtime)->visible($realtime),
|
||||
TextInput::make('realtime_secret')->label('Secret')->password()->revealable()->maxLength(200)->autocomplete('new-password')->visible($realtime)
|
||||
->helperText(filled($settings->get('chat.realtime.secret')) ? 'Gespeichert. Leer lassen, um es zu behalten.' : null),
|
||||
TextInput::make('realtime_host')->label('Server (leer = pusher.com)')->maxLength(200)->visible($realtime)->placeholder('ws.example.org'),
|
||||
TextInput::make('realtime_port')->label('Port')->numeric()->visible($realtime)->placeholder('443'),
|
||||
Select::make('realtime_scheme')->label('Verbindung')->options(['https' => 'Verschlüsselt (https/wss)', 'http' => 'Unverschlüsselt (nur intern)'])->native(false)->selectablePlaceholder(false)->visible($realtime),
|
||||
TextInput::make('realtime_cluster')->label('Cluster (nur pusher.com)')->maxLength(20)->visible($realtime)->placeholder('eu'),
|
||||
]),
|
||||
])->statePath('data');
|
||||
}
|
||||
|
||||
public function save(Settings $settings): void
|
||||
{
|
||||
$s = $this->form->getState();
|
||||
$enabled = (bool) $s['realtime_enabled'];
|
||||
|
||||
if ($enabled && blank($s['realtime_secret']) && blank($settings->get('chat.realtime.secret'))) {
|
||||
throw ValidationException::withMessages(['data.realtime_secret' => 'Bitte das Secret eingeben.']);
|
||||
}
|
||||
|
||||
// Secret gilt nur für denselben Server
|
||||
if ($enabled && blank($s['realtime_secret']) && ($s['realtime_host'] ?? null) !== $settings->get('chat.realtime.host')) {
|
||||
throw ValidationException::withMessages(['data.realtime_secret' => 'Der Server wurde geändert – bitte das Secret erneut eingeben.']);
|
||||
}
|
||||
|
||||
$values = [
|
||||
'chat.max_upload_mb' => (int) $s['max_upload_mb'],
|
||||
'chat.giphy_rating' => $s['giphy_rating'] ?? 'g',
|
||||
'chat.realtime.enabled' => $enabled,
|
||||
'chat.realtime.app_id' => $s['realtime_app_id'] ?? null,
|
||||
'chat.realtime.key' => $s['realtime_key'] ?? null,
|
||||
'chat.realtime.host' => $s['realtime_host'] ?? null,
|
||||
'chat.realtime.port' => $s['realtime_port'] ?? null,
|
||||
'chat.realtime.scheme' => $s['realtime_scheme'] ?? 'https',
|
||||
'chat.realtime.cluster' => $s['realtime_cluster'] ?? 'mt1',
|
||||
];
|
||||
|
||||
if (filled($s['giphy_key'])) {
|
||||
$values['chat.giphy_key'] = Crypt::encryptString(trim($s['giphy_key']));
|
||||
}
|
||||
|
||||
if (filled($s['realtime_secret'])) {
|
||||
$values['chat.realtime.secret'] = Crypt::encryptString(trim($s['realtime_secret']));
|
||||
}
|
||||
|
||||
$settings->setMany($values);
|
||||
$this->data['giphy_key'] = $this->data['realtime_secret'] = null;
|
||||
Audit::log('chat.settings_updated', ['realtime' => $enabled, 'giphy' => filled($settings->get('chat.giphy_key'))]);
|
||||
|
||||
Notification::make()->success()->title('Gespeichert')->send();
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('forgetGiphy')->label('GIPHY ausschalten')->color('gray')
|
||||
->visible(fn () => filled(app(Settings::class)->get('chat.giphy_key')))
|
||||
->requiresConfirmation()
|
||||
->action(function () {
|
||||
app(Settings::class)->set('chat.giphy_key', null);
|
||||
Notification::make()->success()->title('GIPHY ausgeschaltet')->send();
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
79
src/Filament/Resources/Gifs/GifResource.php
Normal file
79
src/Filament/Resources/Gifs/GifResource.php
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Chat\Filament\Resources\Gifs;
|
||||
|
||||
use App\Filament\Components\SafeUpload;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\ImageColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Inhaus\Plugins\Chat\Filament\Resources\Gifs\Pages\ManageGifs;
|
||||
use Inhaus\Plugins\Chat\Gifs;
|
||||
use Inhaus\Plugins\Chat\Models\Gif;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* Eigene GIF-Sammlung für den Chat – bleibt im Haus, ohne externen Dienst.
|
||||
*/
|
||||
class GifResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Gif::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedGif;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Portal';
|
||||
|
||||
protected static ?int $navigationSort = 41;
|
||||
|
||||
protected static ?string $navigationLabel = 'Chat-GIFs';
|
||||
|
||||
protected static ?string $modelLabel = 'GIF';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'GIFs';
|
||||
|
||||
protected static ?string $slug = 'chat-gifs';
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return auth()->user()?->can('chat.manage') ?? false;
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
SafeUpload::apply(FileUpload::make('path'))
|
||||
->label('GIF')
|
||||
->disk(Gifs::DISK)->directory(Gifs::FOLDER)->visibility('public')
|
||||
->acceptedFileTypes(['image/gif', 'image/webp'])
|
||||
->maxSize(8 * 1024)
|
||||
->required()
|
||||
->columnSpanFull(),
|
||||
TextInput::make('title')->label('Titel')->required()->maxLength(100)->placeholder('z. B. Daumen hoch'),
|
||||
TextInput::make('tags')->label('Suchbegriffe')->maxLength(300)->placeholder('super, danke, klasse'),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('created_at', 'desc')
|
||||
->columns([
|
||||
ImageColumn::make('path')->label('')->disk(Gifs::DISK)->height(56),
|
||||
TextColumn::make('title')->label('Titel')->searchable(),
|
||||
TextColumn::make('tags')->label('Suchbegriffe')->color('gray')->searchable(),
|
||||
])
|
||||
->recordActions([EditAction::make(), DeleteAction::make()]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return ['index' => ManageGifs::route('/')];
|
||||
}
|
||||
}
|
||||
17
src/Filament/Resources/Gifs/Pages/ManageGifs.php
Normal file
17
src/Filament/Resources/Gifs/Pages/ManageGifs.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Chat\Filament\Resources\Gifs\Pages;
|
||||
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
use Inhaus\Plugins\Chat\Filament\Resources\Gifs\GifResource;
|
||||
|
||||
class ManageGifs extends ManageRecords
|
||||
{
|
||||
protected static string $resource = GifResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [CreateAction::make()->label('GIF hinzufügen')];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue