From 77ae23ce117365cd399b96f281879f9d8f941812 Mon Sep 17 00:00:00 2001 From: Friederich Loheide Date: Tue, 29 Sep 2026 19:50:21 +0000 Subject: [PATCH 1/3] =?UTF-8?q?Gruppen=201.3.0:=20Beitr=C3=A4ge=20im=20Fee?= =?UTF-8?q?d,=20Einladungen=20und=20Anfragen=20als=20Aufgaben?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 (1M context) --- plugin.json | 2 +- src/GruppenPlugin.php | 55 +++++++++++++++++++++++++++++++++++++++++++ tests/GruppenTest.php | 26 ++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/plugin.json b/plugin.json index 2068b20..5be33a8 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "slug": "gruppen", "name": "Gruppen", - "version": "1.2.1", + "version": "1.3.0", "description": "Diskussionsgruppen wie bei Facebook: offen, geschlossen (Beitritt auf Anfrage) oder privat (nur auf Einladung). Beiträge mit Fotos, Dateien und Umfragen, Reaktionen, Kommentare mit Antworten, Anpinnen, Melden und Moderation.", "author": "Loheide", "namespace": "Inhaus\\Plugins\\Gruppen\\", diff --git a/src/GruppenPlugin.php b/src/GruppenPlugin.php index c27928e..9c7cf11 100644 --- a/src/GruppenPlugin.php +++ b/src/GruppenPlugin.php @@ -4,12 +4,15 @@ namespace Inhaus\Plugins\Gruppen; use App\Dashboard\Widgets; use App\Digest\Digest; +use App\Feed\Feed; use App\Models\User; use App\Plugins\Plugin; use App\Search\GlobalSearch; use App\Support\Abilities; use App\Support\Navigation; +use App\Tasks\Tasks; use Carbon\CarbonImmutable; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; use Inhaus\Plugins\Gruppen\Models\Group; @@ -40,6 +43,58 @@ class GruppenPlugin extends Plugin ])->all(); }, sort: 45); + // Feed der Mitarbeiter-App (Inhaus ab 0.54): Beiträge aus den eigenen Gruppen + if (class_exists(Feed::class)) { + $this->app->make(Feed::class)->add('gruppen', function (User $user, ?CarbonImmutable $before, int $limit) { + $ids = Member::query()->where('user_id', $user->id)->where('status', 'active')->pluck('group_id'); + + return Post::query()->with(['user', 'group', 'attachments'])->withCount('comments') + ->addSelect(['reactions_count' => DB::table('gruppen_reactions')->selectRaw('count(*)')->whereColumn('post_id', 'gruppen_posts.id')]) + ->whereIn('group_id', $ids->all() ?: [0]) + ->when($before, fn ($query) => $query->where('created_at', '<', $before)) + ->latest('id')->limit($limit)->get() + ->map(fn (Post $post) => [ + 'id' => 'gruppen-'.$post->id, + 'kind' => 'group-post', + 'time' => $post->created_at, + 'actor' => Feed::person($post->user), + 'context' => ['label' => $post->group->name, 'url' => route('gruppen.show', $post->group)], + 'text' => (string) ($post->body ?: ($post->poll ? 'Umfrage in der Gruppe' : '')), + 'images' => $post->attachments->filter->isImage()->take(4)->map(fn ($a) => route('gruppen.file', [$a, 'thumb']))->values()->all(), + 'url' => route('gruppen.post', [$post->group, $post]), + 'stats' => ['likes' => (int) $post->reactions_count, 'comments' => (int) $post->comments_count], + ]); + }); + } + + // Meine Aufgaben: Einladungen annehmen, Beitrittsanfragen beantworten + if (class_exists(Tasks::class)) { + $this->app->make(Tasks::class)->add('gruppen', function (User $user) { + $mine = Member::query()->with('group')->where('user_id', $user->id)->whereIn('status', ['invited', 'active'])->get(); + $tasks = $mine->where('status', 'invited')->map(fn (Member $m) => [ + 'title' => 'Einladung in „'.$m->group->name.'“ annehmen', + 'meta' => 'Gruppen', + 'url' => route('gruppen.show', $m->group), + 'icon' => 'users-round', + ])->values()->all(); + + $moderated = $mine->filter(fn (Member $m) => $m->isActive() && in_array($m->role, ['admin', 'moderator'], true))->pluck('group', 'group_id'); + $pending = Member::query()->whereIn('group_id', $moderated->keys()->all() ?: [0])->where('status', 'pending') + ->selectRaw('group_id, count(*) as total')->groupBy('group_id')->pluck('total', 'group_id'); + + foreach ($pending as $groupId => $count) { + $tasks[] = [ + 'title' => $count === 1 ? '1 Beitrittsanfrage in „'.$moderated[$groupId]->name.'“' : $count.' Beitrittsanfragen in „'.$moderated[$groupId]->name.'“', + 'meta' => 'Gruppen', + 'url' => route('gruppen.show', $moderated[$groupId]).'?tab=mitglieder', + 'icon' => 'user-plus', + ]; + } + + return $tasks; + }, sort: 40); + } + // Startseite: Neues aus den eigenen Gruppen $this->app->make(Widgets::class)->add('gruppen.feed', 'gruppen::Recent', 'aside', sort: 35, props: function (User $user) { $ids = Member::query()->where('user_id', $user->id)->where('status', 'active')->pluck('group_id'); diff --git a/tests/GruppenTest.php b/tests/GruppenTest.php index 5fd47b8..2269842 100644 --- a/tests/GruppenTest.php +++ b/tests/GruppenTest.php @@ -2,8 +2,10 @@ namespace Tests\Plugins\Gruppen; +use App\Feed\Feed; use App\Models\User; use App\Notifications\PortalNotification; +use App\Tasks\Tasks; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Notification; @@ -193,4 +195,28 @@ class GruppenTest extends TestCase $closedPost = Post::query()->where('group_id', $closed->id)->firstOrFail(); $this->getJson("/api/v1/gruppen/beitraege/{$closedPost->id}")->assertNotFound(); } + + public function test_posts_reach_the_feed_and_invitations_and_requests_become_tasks(): void + { + if (! class_exists(Feed::class)) { + $this->markTestSkipped('Inhaus ohne Feed'); + } + + [$ada, $bob, $eve] = User::factory()->count(3)->create()->all(); + $group = $this->group($ada, 'closed'); + $this->actingAs($ada)->postJson("/gruppen/{$group->slug}/beitraege", ['body' => 'Mittwoch 17 Uhr am Haupteingang?'])->assertCreated(); + + $feed = collect(app(Feed::class)->page($ada)['items'])->firstWhere('kind', 'group-post'); + $this->assertSame('Mittwoch 17 Uhr am Haupteingang?', $feed['text']); + $this->assertSame('Laufgruppe', $feed['context']['label']); + // Nicht-Mitglieder sehen den Beitrag nicht + $this->assertNull(collect(app(Feed::class)->page($eve)['items'])->firstWhere('kind', 'group-post')); + + // Einladung → Aufgabe für Bob; Beitrittsanfrage von Eve → Aufgabe für Ada + $this->actingAs($ada)->post("/gruppen/{$group->slug}/einladen", ['users' => [$bob->id]]); + $this->actingAs($eve)->post("/gruppen/{$group->slug}/beitreten"); + + $this->assertContains('Einladung in „Laufgruppe“ annehmen', array_column(app(Tasks::class)->forUser($bob), 'title')); + $this->assertContains('1 Beitrittsanfrage in „Laufgruppe“', array_column(app(Tasks::class)->forUser($ada), 'title')); + } } From 0056241eb37a2caa2dfc31f996d5edba8585a19b Mon Sep 17 00:00:00 2001 From: Friederich Loheide Date: Thu, 1 Oct 2026 14:44:45 +0000 Subject: [PATCH 2/3] Gruppen 1.3.1: Herz direkt im Feed Co-Authored-By: Claude Opus 5.5 (1M context) --- plugin.json | 2 +- src/GruppenPlugin.php | 7 ++++++- tests/GruppenTest.php | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/plugin.json b/plugin.json index 5be33a8..12e710f 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "slug": "gruppen", "name": "Gruppen", - "version": "1.3.0", + "version": "1.3.1", "description": "Diskussionsgruppen wie bei Facebook: offen, geschlossen (Beitritt auf Anfrage) oder privat (nur auf Einladung). Beiträge mit Fotos, Dateien und Umfragen, Reaktionen, Kommentare mit Antworten, Anpinnen, Melden und Moderation.", "author": "Loheide", "namespace": "Inhaus\\Plugins\\Gruppen\\", diff --git a/src/GruppenPlugin.php b/src/GruppenPlugin.php index 9c7cf11..3f59fc8 100644 --- a/src/GruppenPlugin.php +++ b/src/GruppenPlugin.php @@ -49,7 +49,10 @@ class GruppenPlugin extends Plugin $ids = Member::query()->where('user_id', $user->id)->where('status', 'active')->pluck('group_id'); return Post::query()->with(['user', 'group', 'attachments'])->withCount('comments') - ->addSelect(['reactions_count' => DB::table('gruppen_reactions')->selectRaw('count(*)')->whereColumn('post_id', 'gruppen_posts.id')]) + ->addSelect([ + 'reactions_count' => DB::table('gruppen_reactions')->selectRaw('count(*)')->whereColumn('post_id', 'gruppen_posts.id'), + 'my_reaction' => DB::table('gruppen_reactions')->select('emoji')->whereColumn('post_id', 'gruppen_posts.id')->where('user_id', $user->id)->limit(1), + ]) ->whereIn('group_id', $ids->all() ?: [0]) ->when($before, fn ($query) => $query->where('created_at', '<', $before)) ->latest('id')->limit($limit)->get() @@ -63,6 +66,8 @@ class GruppenPlugin extends Plugin 'images' => $post->attachments->filter->isImage()->take(4)->map(fn ($a) => route('gruppen.file', [$a, 'thumb']))->values()->all(), 'url' => route('gruppen.post', [$post->group, $post]), 'stats' => ['likes' => (int) $post->reactions_count, 'comments' => (int) $post->comments_count], + // Herz im Feed = Reaktion ❤️ (jede eigene Reaktion zählt als „gefällt mir“) + 'like' => ['liked' => $post->my_reaction !== null, 'url' => route('gruppen.posts.react', $post, absolute: false), 'mode' => 'reaction'], ]); }); } diff --git a/tests/GruppenTest.php b/tests/GruppenTest.php index 2269842..89af257 100644 --- a/tests/GruppenTest.php +++ b/tests/GruppenTest.php @@ -209,6 +209,13 @@ class GruppenTest extends TestCase $feed = collect(app(Feed::class)->page($ada)['items'])->firstWhere('kind', 'group-post'); $this->assertSame('Mittwoch 17 Uhr am Haupteingang?', $feed['text']); $this->assertSame('Laufgruppe', $feed['context']['label']); + // Herz direkt im Feed = Reaktion + $this->assertSame('reaction', $feed['like']['mode']); + $this->actingAs($ada)->postJson($feed['like']['url'], ['emoji' => '❤️'])->assertOk(); + $liked = collect(app(Feed::class)->page($ada)['items'])->firstWhere('kind', 'group-post'); + $this->assertTrue($liked['like']['liked']); + $this->assertSame(1, $liked['stats']['likes']); + // Nicht-Mitglieder sehen den Beitrag nicht $this->assertNull(collect(app(Feed::class)->page($eve)['items'])->firstWhere('kind', 'group-post')); From ec6f0b0323bf1db8bd5bf10014763472bc699ef3 Mon Sep 17 00:00:00 2001 From: Friederich Loheide Date: Tue, 6 Oct 2026 19:34:08 +0000 Subject: [PATCH 3/3] =?UTF-8?q?Gruppen=201.3.2:=20Feed=20in=20der=20App=20?= =?UTF-8?q?(Bilder=20und=20Herz=20=C3=BCber=20die=20Schnittstelle)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 (1M context) --- plugin.json | 2 +- src/GruppenPlugin.php | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/plugin.json b/plugin.json index 12e710f..c1fbb53 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "slug": "gruppen", "name": "Gruppen", - "version": "1.3.1", + "version": "1.3.2", "description": "Diskussionsgruppen wie bei Facebook: offen, geschlossen (Beitritt auf Anfrage) oder privat (nur auf Einladung). Beiträge mit Fotos, Dateien und Umfragen, Reaktionen, Kommentare mit Antworten, Anpinnen, Melden und Moderation.", "author": "Loheide", "namespace": "Inhaus\\Plugins\\Gruppen\\", diff --git a/src/GruppenPlugin.php b/src/GruppenPlugin.php index 3f59fc8..5da8409 100644 --- a/src/GruppenPlugin.php +++ b/src/GruppenPlugin.php @@ -46,6 +46,8 @@ class GruppenPlugin extends Plugin // Feed der Mitarbeiter-App (Inhaus ab 0.54): Beiträge aus den eigenen Gruppen if (class_exists(Feed::class)) { $this->app->make(Feed::class)->add('gruppen', function (User $user, ?CarbonImmutable $before, int $limit) { + // Die App lädt über die API (Token), der Browser über die Sitzung + $api = request()->is('api/*'); $ids = Member::query()->where('user_id', $user->id)->where('status', 'active')->pluck('group_id'); return Post::query()->with(['user', 'group', 'attachments'])->withCount('comments') @@ -63,11 +65,11 @@ class GruppenPlugin extends Plugin 'actor' => Feed::person($post->user), 'context' => ['label' => $post->group->name, 'url' => route('gruppen.show', $post->group)], 'text' => (string) ($post->body ?: ($post->poll ? 'Umfrage in der Gruppe' : '')), - 'images' => $post->attachments->filter->isImage()->take(4)->map(fn ($a) => route('gruppen.file', [$a, 'thumb']))->values()->all(), + 'images' => $post->attachments->filter->isImage()->take(4)->map(fn ($a) => route($api ? 'gruppen.app.file' : 'gruppen.file', [$a, 'thumb']))->values()->all(), 'url' => route('gruppen.post', [$post->group, $post]), 'stats' => ['likes' => (int) $post->reactions_count, 'comments' => (int) $post->comments_count], // Herz im Feed = Reaktion ❤️ (jede eigene Reaktion zählt als „gefällt mir“) - 'like' => ['liked' => $post->my_reaction !== null, 'url' => route('gruppen.posts.react', $post, absolute: false), 'mode' => 'reaction'], + 'like' => ['liked' => $post->my_reaction !== null, 'url' => route($api ? 'gruppen.app.posts.react' : 'gruppen.posts.react', $post, absolute: false), 'mode' => 'reaction'], ]); }); }