Gruppen 1.1.0: Schnittstelle für die App, „Gefällt mir“ mit Symbol
- /api/v1/gruppen: Übersicht, entdecken, Gruppe, beitreten/verlassen, Benachrichtigungen, Beiträge, Reaktionen, Abstimmung, Kommentare, Melden, Fotos/Dateien/Titelbild mit Token - Datei- und Titelbild-Adressen zeigen bei API-Aufrufen auf die API - „Gefällt mir“ zeigt im Ruhezustand ein Daumen-Symbol statt eines Emojis (sieht auch ohne Emoji-Schrift richtig aus) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c2792f6a63
commit
b29f6ada71
12 changed files with 225 additions and 10 deletions
17
README.md
17
README.md
|
|
@ -27,6 +27,23 @@ Voraussetzung: Inhaus **0.39.0** oder neuer.
|
|||
1. `gruppen-<version>.zip` unter https://git.loheide.cloud/friloo/inhaus-plugin-gruppen/releases laden.
|
||||
2. Backend → **Plugins** → hochladen → aktivieren. Updates erscheinen danach automatisch.
|
||||
|
||||
## Schnittstelle für die App
|
||||
|
||||
Unter `/api/v1/gruppen/…` (Token nötig), dieselben Regeln wie im Portal:
|
||||
|
||||
| Methode | Pfad | Zweck |
|
||||
|---|---|---|
|
||||
| GET | `/?vor=` | eigene Gruppen, Einladungen, Beiträge aus allen eigenen Gruppen (15 je Seite) |
|
||||
| GET | `entdecken?q=&page=` | sichtbare Gruppen mit eigenem Status |
|
||||
| GET | `{slug}?vor=` | Gruppe, Mitgliedschaft, Rechte (`can`), Mitglieder, Beiträge (angepinnte zuerst) |
|
||||
| POST | `{slug}/beitreten`, `{slug}/verlassen` | beitreten bzw. Anfrage stellen, Einladung annehmen / verlassen |
|
||||
| PUT | `{slug}/benachrichtigungen {notify: all\|off}` | Benachrichtigungen zu neuen Beiträgen |
|
||||
| POST | `{slug}/beitraege {body, files[], poll[], multiple}` | Beitrag schreiben (multipart mit Dateien) |
|
||||
| GET | `beitraege/{id}` | Beitrag mit allen Kommentaren |
|
||||
| POST | `beitraege/{id}/reaktion {emoji}`, `/abstimmen {options[]}`, `/kommentare {body, parent_id}`, `/melden {reason}` | reagieren, abstimmen, kommentieren, melden |
|
||||
| DELETE | `beitraege/{id}`, `kommentare/{id}` | löschen (eigene bzw. als Moderation) |
|
||||
| GET | `dateien/{id}/{thumb\|full}`, `{slug}/titelbild` | Fotos, Dateien, Titelbild (Adressen in API-Antworten zeigen hierher) |
|
||||
|
||||
## Entwicklung
|
||||
|
||||
```bash
|
||||
|
|
|
|||
1
dist/chunks/PostCard-BrusE-7w.js
vendored
1
dist/chunks/PostCard-BrusE-7w.js
vendored
File diff suppressed because one or more lines are too long
1
dist/chunks/PostCard-ClNPcHNo.js
vendored
Normal file
1
dist/chunks/PostCard-ClNPcHNo.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2
dist/pages/Index.js
vendored
2
dist/pages/Index.js
vendored
|
|
@ -1 +1 @@
|
|||
import{n as e,t}from"../chunks/loader-circle-CxzeMpQS.js";import{n,t as r}from"../chunks/GroupCard-5fLVVVGb.js";import{t as i}from"../chunks/PostCard-BrusE-7w.js";import{r as a,t as o}from"../chunks/GroupDialog-DkTJQL7Q.js";import{Fragment as s,createBlock as c,createCommentVNode as l,createElementBlock as u,createElementVNode as d,createTextVNode as f,createVNode as p,normalizeStyle as m,openBlock as h,ref as g,renderList as _,toDisplayString as v,unref as y,watch as b,withCtx as x}from"vue";import{Link as S,usePage as C}from"@inertiajs/vue3";import{AppLayout as w,Button as T,EmptyState as E,PageHeader as D,http as O,toast as k}from"@inhaus/ui";var A=e({name:`users-round`,size:24,node:[[`path`,{d:`M18 21a8 8 0 0 0-16 0`,key:`3ypg7q`}],[`circle`,{cx:`10`,cy:`8`,r:`5`,key:`o932ke`}],[`path`,{d:`M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3`,key:`10s06x`}]],aliases:[`users-2`]}),j={class:`ih:grid ih:gap-6 ih:lg:grid-cols-[minmax(0,1fr)_20rem]`},M={class:`ih:grid ih:min-w-0 ih:content-start ih:gap-4`,"aria-label":`Neue Beiträge aus Ihren Gruppen`},N={key:1,class:`ih:rounded-xl ih:border ih:bg-card`},P={class:`ih:grid ih:content-start ih:gap-5`},F={key:0,class:`ih:rounded-xl ih:border ih:border-brand/40 ih:bg-brand-soft/40 ih:p-4`},I={class:`ih:grid ih:gap-3`},L={class:`ih:rounded-xl ih:border ih:bg-card ih:p-4`},R={key:0,class:`ih:-mx-2 ih:grid`},z={class:`ih:min-w-0`},B={class:`ih:block ih:truncate ih:text-sm ih:font-medium`},V={class:`ih:text-xs ih:text-muted-foreground`},H={key:1,class:`ih:text-sm ih:text-muted-foreground`},U={key:1,class:`ih:grid ih:gap-3`},W={__name:`Index`,props:{posts:{type:Array,required:!0},more:{type:Boolean,default:!1},groups:{type:Array,required:!0},invitations:{type:Array,default:()=>[]},suggested:{type:Array,default:()=>[]},privacy:{type:Object,required:!0},privacyHints:{type:Object,required:!0}},setup(e){let W=e,G=C();b(()=>G.props.flash?.status,e=>e&&k.success(e),{immediate:!0});let K=g(W.posts),q=g(W.more),J=g(!1),Y=g(!1),X=[`👍`,`❤️`,`😂`,`😮`,`😢`,`👏`];async function Z(){J.value=!0;let e=await O.get(`/gruppen?vor=${K.value.at(-1).id}`);K.value.push(...e.posts),q.value=e.more,J.value=!1}return(g,b)=>(h(),c(y(w),{title:`Gruppen`},{default:x(()=>[p(y(D),{title:`Gruppen`,description:`Austausch zu Themen, Hobbys und Projekten – offen, geschlossen oder privat.`},{actions:x(()=>[p(y(T),{variant:`outline`,"as-child":``},{default:x(()=>[p(y(S),{href:`/gruppen/entdecken`},{default:x(()=>[p(y(n)),b[2]||=f(` Gruppen entdecken`,-1)]),_:1})]),_:1}),p(y(T),{onClick:b[0]||=e=>Y.value=!0},{default:x(()=>[p(y(a)),b[3]||=f(` Gruppe gründen`,-1)]),_:1})]),_:1}),d(`div`,j,[d(`section`,M,[(h(!0),u(s,null,_(K.value,e=>(h(),c(i,{key:e.id,post:e,reactions:X,"show-group":``,onDeleted:t=>K.value=K.value.filter(t=>t.id!==e.id)},null,8,[`post`,`onDeleted`]))),128)),q.value?(h(),c(y(T),{key:0,variant:`outline`,disabled:J.value,onClick:Z},{default:x(()=>[J.value?(h(),c(y(t),{key:0,class:`ih:animate-spin`})):l(``,!0),b[4]||=f(` Ältere Beiträge laden`,-1)]),_:1},8,[`disabled`])):l(``,!0),K.value.length?l(``,!0):(h(),u(`div`,N,[p(y(E),{icon:y(A),title:e.groups.length?`Noch keine Beiträge`:`Sie sind noch in keiner Gruppe`,text:e.groups.length?`Schreiben Sie den ersten Beitrag in einer Ihrer Gruppen.`:`Entdecken Sie Gruppen zu Ihren Themen – oder gründen Sie selbst eine.`},null,8,[`icon`,`title`,`text`])]))]),d(`aside`,P,[e.invitations.length?(h(),u(`section`,F,[b[5]||=d(`h2`,{class:`ih:mb-2 ih:text-sm ih:font-semibold`},`Einladungen`,-1),d(`div`,I,[(h(!0),u(s,null,_(e.invitations,e=>(h(),c(r,{key:e.id,group:e},null,8,[`group`]))),128))])])):l(``,!0),d(`section`,L,[b[6]||=d(`h2`,{class:`ih:mb-2 ih:text-sm ih:font-semibold`},`Ihre Gruppen`,-1),e.groups.length?(h(),u(`ul`,R,[(h(!0),u(s,null,_(e.groups,e=>(h(),u(`li`,{key:e.id},[p(y(S),{href:e.url,class:`ih:flex ih:items-center ih:gap-3 ih:rounded-md ih:p-2 ih:hover:bg-accent/60`},{default:x(()=>[d(`span`,{class:`ih:size-10 ih:shrink-0 ih:rounded-md ih:bg-brand ih:bg-cover ih:bg-center`,style:m(e.cover_url?{backgroundImage:`url(${e.cover_url})`}:{})},null,4),d(`span`,z,[d(`span`,B,v(e.name),1),d(`span`,V,v(e.members_count)+` `+v(e.members_count===1?`Mitglied`:`Mitglieder`),1)])]),_:2},1032,[`href`])]))),128))])):(h(),u(`p`,H,`Noch keine.`))]),e.suggested.length?(h(),u(`section`,U,[b[7]||=d(`h2`,{class:`ih:text-sm ih:font-semibold`},`Vorschläge`,-1),(h(!0),u(s,null,_(e.suggested,e=>(h(),c(r,{key:e.id,group:e},null,8,[`group`]))),128))])):l(``,!0)])]),p(o,{open:Y.value,"onUpdate:open":b[1]||=e=>Y.value=e,privacy:e.privacy,"privacy-hints":e.privacyHints},null,8,[`open`,`privacy`,`privacy-hints`])]),_:1}))}};export{W as default};
|
||||
import{n as e,t}from"../chunks/loader-circle-CxzeMpQS.js";import{n,t as r}from"../chunks/GroupCard-5fLVVVGb.js";import{t as i}from"../chunks/PostCard-ClNPcHNo.js";import{r as a,t as o}from"../chunks/GroupDialog-DkTJQL7Q.js";import{Fragment as s,createBlock as c,createCommentVNode as l,createElementBlock as u,createElementVNode as d,createTextVNode as f,createVNode as p,normalizeStyle as m,openBlock as h,ref as g,renderList as _,toDisplayString as v,unref as y,watch as b,withCtx as x}from"vue";import{Link as S,usePage as C}from"@inertiajs/vue3";import{AppLayout as w,Button as T,EmptyState as E,PageHeader as D,http as O,toast as k}from"@inhaus/ui";var A=e({name:`users-round`,size:24,node:[[`path`,{d:`M18 21a8 8 0 0 0-16 0`,key:`3ypg7q`}],[`circle`,{cx:`10`,cy:`8`,r:`5`,key:`o932ke`}],[`path`,{d:`M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3`,key:`10s06x`}]],aliases:[`users-2`]}),j={class:`ih:grid ih:gap-6 ih:lg:grid-cols-[minmax(0,1fr)_20rem]`},M={class:`ih:grid ih:min-w-0 ih:content-start ih:gap-4`,"aria-label":`Neue Beiträge aus Ihren Gruppen`},N={key:1,class:`ih:rounded-xl ih:border ih:bg-card`},P={class:`ih:grid ih:content-start ih:gap-5`},F={key:0,class:`ih:rounded-xl ih:border ih:border-brand/40 ih:bg-brand-soft/40 ih:p-4`},I={class:`ih:grid ih:gap-3`},L={class:`ih:rounded-xl ih:border ih:bg-card ih:p-4`},R={key:0,class:`ih:-mx-2 ih:grid`},z={class:`ih:min-w-0`},B={class:`ih:block ih:truncate ih:text-sm ih:font-medium`},V={class:`ih:text-xs ih:text-muted-foreground`},H={key:1,class:`ih:text-sm ih:text-muted-foreground`},U={key:1,class:`ih:grid ih:gap-3`},W={__name:`Index`,props:{posts:{type:Array,required:!0},more:{type:Boolean,default:!1},groups:{type:Array,required:!0},invitations:{type:Array,default:()=>[]},suggested:{type:Array,default:()=>[]},privacy:{type:Object,required:!0},privacyHints:{type:Object,required:!0}},setup(e){let W=e,G=C();b(()=>G.props.flash?.status,e=>e&&k.success(e),{immediate:!0});let K=g(W.posts),q=g(W.more),J=g(!1),Y=g(!1),X=[`👍`,`❤️`,`😂`,`😮`,`😢`,`👏`];async function Z(){J.value=!0;let e=await O.get(`/gruppen?vor=${K.value.at(-1).id}`);K.value.push(...e.posts),q.value=e.more,J.value=!1}return(g,b)=>(h(),c(y(w),{title:`Gruppen`},{default:x(()=>[p(y(D),{title:`Gruppen`,description:`Austausch zu Themen, Hobbys und Projekten – offen, geschlossen oder privat.`},{actions:x(()=>[p(y(T),{variant:`outline`,"as-child":``},{default:x(()=>[p(y(S),{href:`/gruppen/entdecken`},{default:x(()=>[p(y(n)),b[2]||=f(` Gruppen entdecken`,-1)]),_:1})]),_:1}),p(y(T),{onClick:b[0]||=e=>Y.value=!0},{default:x(()=>[p(y(a)),b[3]||=f(` Gruppe gründen`,-1)]),_:1})]),_:1}),d(`div`,j,[d(`section`,M,[(h(!0),u(s,null,_(K.value,e=>(h(),c(i,{key:e.id,post:e,reactions:X,"show-group":``,onDeleted:t=>K.value=K.value.filter(t=>t.id!==e.id)},null,8,[`post`,`onDeleted`]))),128)),q.value?(h(),c(y(T),{key:0,variant:`outline`,disabled:J.value,onClick:Z},{default:x(()=>[J.value?(h(),c(y(t),{key:0,class:`ih:animate-spin`})):l(``,!0),b[4]||=f(` Ältere Beiträge laden`,-1)]),_:1},8,[`disabled`])):l(``,!0),K.value.length?l(``,!0):(h(),u(`div`,N,[p(y(E),{icon:y(A),title:e.groups.length?`Noch keine Beiträge`:`Sie sind noch in keiner Gruppe`,text:e.groups.length?`Schreiben Sie den ersten Beitrag in einer Ihrer Gruppen.`:`Entdecken Sie Gruppen zu Ihren Themen – oder gründen Sie selbst eine.`},null,8,[`icon`,`title`,`text`])]))]),d(`aside`,P,[e.invitations.length?(h(),u(`section`,F,[b[5]||=d(`h2`,{class:`ih:mb-2 ih:text-sm ih:font-semibold`},`Einladungen`,-1),d(`div`,I,[(h(!0),u(s,null,_(e.invitations,e=>(h(),c(r,{key:e.id,group:e},null,8,[`group`]))),128))])])):l(``,!0),d(`section`,L,[b[6]||=d(`h2`,{class:`ih:mb-2 ih:text-sm ih:font-semibold`},`Ihre Gruppen`,-1),e.groups.length?(h(),u(`ul`,R,[(h(!0),u(s,null,_(e.groups,e=>(h(),u(`li`,{key:e.id},[p(y(S),{href:e.url,class:`ih:flex ih:items-center ih:gap-3 ih:rounded-md ih:p-2 ih:hover:bg-accent/60`},{default:x(()=>[d(`span`,{class:`ih:size-10 ih:shrink-0 ih:rounded-md ih:bg-brand ih:bg-cover ih:bg-center`,style:m(e.cover_url?{backgroundImage:`url(${e.cover_url})`}:{})},null,4),d(`span`,z,[d(`span`,B,v(e.name),1),d(`span`,V,v(e.members_count)+` `+v(e.members_count===1?`Mitglied`:`Mitglieder`),1)])]),_:2},1032,[`href`])]))),128))])):(h(),u(`p`,H,`Noch keine.`))]),e.suggested.length?(h(),u(`section`,U,[b[7]||=d(`h2`,{class:`ih:text-sm ih:font-semibold`},`Vorschläge`,-1),(h(!0),u(s,null,_(e.suggested,e=>(h(),c(r,{key:e.id,group:e},null,8,[`group`]))),128))])):l(``,!0)])]),p(o,{open:Y.value,"onUpdate:open":b[1]||=e=>Y.value=e,privacy:e.privacy,"privacy-hints":e.privacyHints},null,8,[`open`,`privacy`,`privacy-hints`])]),_:1}))}};export{W as default};
|
||||
2
dist/pages/Post.js
vendored
2
dist/pages/Post.js
vendored
|
|
@ -1 +1 @@
|
|||
import{n as e}from"../chunks/loader-circle-CxzeMpQS.js";import{i as t,t as n}from"../chunks/PostCard-BrusE-7w.js";import{Fragment as r,createBlock as i,createCommentVNode as a,createElementBlock as o,createElementVNode as s,createTextVNode as c,createVNode as l,onMounted as u,openBlock as d,renderList as f,toDisplayString as p,unref as m,withCtx as h}from"vue";import{Link as g,router as _}from"@inertiajs/vue3";import{AppLayout as v,Button as y,http as b,toast as x}from"@inhaus/ui";var S=e({name:`chevron-left`,size:24,node:[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]}),C={class:`ih:mx-auto ih:grid ih:max-w-4xl ih:gap-4`},w={key:0,class:`ih:rounded-md ih:border ih:border-destructive/30 ih:bg-destructive/5 ih:p-3 ih:text-sm`},T={class:`ih:flex ih:items-center ih:gap-2 ih:font-medium`},E={class:`ih:mt-1 ih:list-disc ih:pl-6 ih:text-muted-foreground`},D={__name:`Post`,props:{group:{type:Object,required:!0},post:{type:Object,required:!0},comments:{type:Array,required:!0},reactions:{type:Array,required:!0},reports:{type:Array,default:()=>[]}},setup(e){let D=e;u(()=>{(location.hash&&document.querySelector(location.hash))?.scrollIntoView({block:`center`})});async function O(){await b.post(`/gruppen/beitraege/${D.post.id}/meldungen-erledigt`),x.success(`Meldungen erledigt`),_.reload()}return(u,b)=>(d(),i(m(v),{title:`Beitrag in ${e.group.name}`},{default:h(()=>[s(`div`,C,[l(m(g),{href:e.group.url,class:`ih:inline-flex ih:items-center ih:gap-1 ih:text-sm ih:font-medium ih:text-muted-foreground ih:hover:text-foreground`},{default:h(()=>[l(m(S),{class:`ih:size-4`}),c(` `+p(e.group.name),1)]),_:1},8,[`href`]),e.reports.length?(d(),o(`div`,w,[s(`p`,T,[l(m(t),{class:`ih:size-4 ih:text-destructive`}),c(` `+p(e.reports.length)+` `+p(e.reports.length===1?`Meldung`:`Meldungen`),1)]),s(`ul`,E,[(d(!0),o(r,null,f(e.reports,e=>(d(),o(`li`,{key:e.id},p(e.comment_id?`Kommentar: `:``)+p(e.reason),1))),128))]),l(m(y),{size:`sm`,variant:`outline`,class:`ih:mt-2`,onClick:O},{default:h(()=>[...b[1]||=[c(`In Ordnung – erledigt`,-1)]]),_:1})])):a(``,!0),l(n,{post:e.post,reactions:e.reactions,"full-comments":e.comments,onDeleted:b[0]||=t=>m(_).visit(e.group.url)},null,8,[`post`,`reactions`,`full-comments`])])]),_:1},8,[`title`]))}};export{D as default};
|
||||
import{n as e}from"../chunks/loader-circle-CxzeMpQS.js";import{i as t,t as n}from"../chunks/PostCard-ClNPcHNo.js";import{Fragment as r,createBlock as i,createCommentVNode as a,createElementBlock as o,createElementVNode as s,createTextVNode as c,createVNode as l,onMounted as u,openBlock as d,renderList as f,toDisplayString as p,unref as m,withCtx as h}from"vue";import{Link as g,router as _}from"@inertiajs/vue3";import{AppLayout as v,Button as y,http as b,toast as x}from"@inhaus/ui";var S=e({name:`chevron-left`,size:24,node:[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]}),C={class:`ih:mx-auto ih:grid ih:max-w-4xl ih:gap-4`},w={key:0,class:`ih:rounded-md ih:border ih:border-destructive/30 ih:bg-destructive/5 ih:p-3 ih:text-sm`},T={class:`ih:flex ih:items-center ih:gap-2 ih:font-medium`},E={class:`ih:mt-1 ih:list-disc ih:pl-6 ih:text-muted-foreground`},D={__name:`Post`,props:{group:{type:Object,required:!0},post:{type:Object,required:!0},comments:{type:Array,required:!0},reactions:{type:Array,required:!0},reports:{type:Array,default:()=>[]}},setup(e){let D=e;u(()=>{(location.hash&&document.querySelector(location.hash))?.scrollIntoView({block:`center`})});async function O(){await b.post(`/gruppen/beitraege/${D.post.id}/meldungen-erledigt`),x.success(`Meldungen erledigt`),_.reload()}return(u,b)=>(d(),i(m(v),{title:`Beitrag in ${e.group.name}`},{default:h(()=>[s(`div`,C,[l(m(g),{href:e.group.url,class:`ih:inline-flex ih:items-center ih:gap-1 ih:text-sm ih:font-medium ih:text-muted-foreground ih:hover:text-foreground`},{default:h(()=>[l(m(S),{class:`ih:size-4`}),c(` `+p(e.group.name),1)]),_:1},8,[`href`]),e.reports.length?(d(),o(`div`,w,[s(`p`,T,[l(m(t),{class:`ih:size-4 ih:text-destructive`}),c(` `+p(e.reports.length)+` `+p(e.reports.length===1?`Meldung`:`Meldungen`),1)]),s(`ul`,E,[(d(!0),o(r,null,f(e.reports,e=>(d(),o(`li`,{key:e.id},p(e.comment_id?`Kommentar: `:``)+p(e.reason),1))),128))]),l(m(y),{size:`sm`,variant:`outline`,class:`ih:mt-2`,onClick:O},{default:h(()=>[...b[1]||=[c(`In Ordnung – erledigt`,-1)]]),_:1})])):a(``,!0),l(n,{post:e.post,reactions:e.reactions,"full-comments":e.comments,onDeleted:b[0]||=t=>m(_).visit(e.group.url)},null,8,[`post`,`reactions`,`full-comments`])])]),_:1},8,[`title`]))}};export{D as default};
|
||||
2
dist/pages/Show.js
vendored
2
dist/pages/Show.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"slug": "gruppen",
|
||||
"name": "Gruppen",
|
||||
"version": "1.0.1",
|
||||
"version": "1.1.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\\",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<script setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import { Download, Flag, MessageCircle, MoreHorizontal, Pencil, Pin, PinOff, Trash2 } from '@lucide/vue';
|
||||
import { Download, Flag, MessageCircle, MoreHorizontal, Pencil, Pin, PinOff, ThumbsUp, Trash2 } from '@lucide/vue';
|
||||
import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, FileIcon, PersonAvatar, formatRelative, http, toast } from '@inhaus/ui';
|
||||
import Comments from './Comments.vue';
|
||||
import RichText from './RichText.vue';
|
||||
|
|
@ -176,7 +176,7 @@ const shownImages = computed(() => p.images.slice(0, 4));
|
|||
<div v-if="p.can_comment" class="ih:mx-4 ih:mt-2 ih:grid ih:grid-cols-2 ih:border-t ih:py-1 ih:sm:mx-5">
|
||||
<div class="ih:group/react ih:relative">
|
||||
<button type="button" class="ih:flex ih:w-full ih:items-center ih:justify-center ih:gap-2 ih:rounded-md ih:py-2 ih:text-sm ih:font-medium ih:hover:bg-accent" :class="p.my_reaction ? 'ih:text-brand-text' : 'ih:text-muted-foreground'" :aria-pressed="!!p.my_reaction" @click="react(p.my_reaction ?? '👍')">
|
||||
<span class="ih:text-base">{{ p.my_reaction ?? '👍' }}</span> {{ p.my_reaction ? 'Reagiert' : 'Gefällt mir' }}
|
||||
<span v-if="p.my_reaction" class="ih:text-base">{{ p.my_reaction }}</span><ThumbsUp v-else class="ih:size-4" /> {{ p.my_reaction ? 'Reagiert' : 'Gefällt mir' }}
|
||||
</button>
|
||||
<div class="ih:absolute ih:bottom-full ih:left-2 ih:z-20 ih:hidden ih:gap-0.5 ih:rounded-full ih:border ih:bg-popover ih:p-1 ih:shadow-md ih:group-focus-within/react:flex ih:group-hover/react:flex">
|
||||
<button v-for="emoji in reactions" :key="emoji" type="button" class="ih:grid ih:size-9 ih:place-items-center ih:rounded-full ih:text-xl ih:transition-transform ih:hover:scale-125" :aria-label="`Mit ${emoji} reagieren`" @click="react(emoji)">{{ emoji }}</button>
|
||||
|
|
|
|||
30
routes/api.php
Normal file
30
routes/api.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Inhaus\Plugins\Gruppen\Http\Controllers\ApiController;
|
||||
use Inhaus\Plugins\Gruppen\Http\Controllers\GroupController;
|
||||
use Inhaus\Plugins\Gruppen\Http\Controllers\PostController;
|
||||
|
||||
// /api/v1/gruppen … für die Inhaus-App (Token nötig) – dieselben Regeln wie im Portal
|
||||
Route::prefix('gruppen')->name('gruppen.app.')->group(function () {
|
||||
Route::get('/', [ApiController::class, 'home'])->name('home');
|
||||
Route::get('/entdecken', [ApiController::class, 'discover'])->name('discover');
|
||||
Route::get('/dateien/{attachment}/{size}', [PostController::class, 'file'])->whereIn('size', ['thumb', 'full'])->name('file');
|
||||
|
||||
Route::get('/beitraege/{post}', [ApiController::class, 'post'])->name('post');
|
||||
Route::put('/beitraege/{post}', [PostController::class, 'update'])->name('posts.update');
|
||||
Route::delete('/beitraege/{post}', [PostController::class, 'destroy'])->name('posts.destroy');
|
||||
Route::post('/beitraege/{post}/reaktion', [PostController::class, 'react'])->middleware('throttle:60,1')->name('posts.react');
|
||||
Route::post('/beitraege/{post}/abstimmen', [PostController::class, 'vote'])->middleware('throttle:60,1')->name('posts.vote');
|
||||
Route::get('/beitraege/{post}/kommentare', [PostController::class, 'comments'])->name('posts.comments');
|
||||
Route::post('/beitraege/{post}/kommentare', [PostController::class, 'comment'])->middleware('throttle:30,1')->name('posts.comment');
|
||||
Route::post('/beitraege/{post}/melden', [PostController::class, 'report'])->middleware('throttle:10,60')->name('posts.report');
|
||||
Route::delete('/kommentare/{comment}', [PostController::class, 'deleteComment'])->name('comments.destroy');
|
||||
|
||||
Route::get('/{group}', [ApiController::class, 'show'])->name('show');
|
||||
Route::get('/{group}/titelbild', [GroupController::class, 'cover'])->name('cover');
|
||||
Route::post('/{group}/beitreten', [ApiController::class, 'join'])->name('join');
|
||||
Route::post('/{group}/verlassen', [ApiController::class, 'leave'])->name('leave');
|
||||
Route::put('/{group}/benachrichtigungen', [ApiController::class, 'notifications'])->name('notifications');
|
||||
Route::post('/{group}/beitraege', [PostController::class, 'store'])->middleware('throttle:20,1')->name('posts.store');
|
||||
});
|
||||
127
src/Http/Controllers/ApiController.php
Normal file
127
src/Http/Controllers/ApiController.php
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Gruppen\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inhaus\Plugins\Gruppen\Groups;
|
||||
use Inhaus\Plugins\Gruppen\Models\Group;
|
||||
use Inhaus\Plugins\Gruppen\Models\Member;
|
||||
use Inhaus\Plugins\Gruppen\Models\Post;
|
||||
use Inhaus\Plugins\Gruppen\Presenter;
|
||||
|
||||
/**
|
||||
* Schnittstelle für die Inhaus-App (/api/v1/gruppen …) – dieselben Regeln wie im Portal.
|
||||
* Beiträge, Reaktionen, Umfragen und Kommentare laufen über den PostController (liefert ohnehin JSON).
|
||||
*/
|
||||
class ApiController extends Controller
|
||||
{
|
||||
public function __construct(private readonly Groups $groups) {}
|
||||
|
||||
/** Eigene Gruppen, Einladungen und Beiträge aus allen eigenen Gruppen (?vor=<id> blättert) */
|
||||
public function home(Request $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
$memberships = Member::query()->with('group')->where('user_id', $user->id)->whereIn('status', ['active', 'invited', 'pending'])->get();
|
||||
$posts = Post::query()->with(['user', 'attachments', 'group'])->whereIn('group_id', $memberships->where('status', 'active')->pluck('group_id'))
|
||||
->when($request->integer('vor'), fn ($q, $before) => $q->where('id', '<', $before))
|
||||
->latest('id')->limit(GroupController::PAGE)->get();
|
||||
|
||||
return response()->json([
|
||||
'groups' => $memberships->where('status', 'active')->sortByDesc(fn ($m) => $m->group->last_activity_at)->map(fn ($m) => Presenter::group($m->group, 'active'))->values()->all(),
|
||||
'invitations' => $memberships->where('status', 'invited')->map(fn ($m) => Presenter::group($m->group, 'invited'))->values()->all(),
|
||||
'posts' => Presenter::posts($posts, $user, $this->groups),
|
||||
'more' => $posts->count() === GroupController::PAGE,
|
||||
'reactions' => Post::REACTIONS,
|
||||
]);
|
||||
}
|
||||
|
||||
public function discover(Request $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
$q = trim((string) $request->query('q', ''));
|
||||
$statuses = Member::query()->where('user_id', $user->id)->pluck('status', 'group_id');
|
||||
$groups = Group::query()->discoverableBy($user)
|
||||
->when($q !== '', fn ($query) => $query->where(fn ($w) => $w->where('name', 'like', '%'.addcslashes($q, '%_\\').'%')->orWhere('description', 'like', '%'.addcslashes($q, '%_\\').'%')))
|
||||
->orderByDesc('last_activity_at')->paginate(24);
|
||||
|
||||
return response()->json([
|
||||
'data' => collect($groups->items())->map(fn (Group $g) => Presenter::group($g, $statuses[$g->id] ?? null))->all(),
|
||||
'meta' => ['current_page' => $groups->currentPage(), 'last_page' => $groups->lastPage(), 'total' => $groups->total()],
|
||||
]);
|
||||
}
|
||||
|
||||
/** Gruppe mit Beiträgen (angepinnte zuerst) und Mitgliedern */
|
||||
public function show(Request $request, Group $group): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
$access = $this->groups->access($group, $user);
|
||||
abort_unless($access['see'], 404);
|
||||
$before = $request->integer('vor');
|
||||
|
||||
$posts = $access['read']
|
||||
? $group->posts()->with(['user', 'attachments', 'group'])
|
||||
->when($before, fn ($q) => $q->where('id', '<', $before)->whereNull('pinned_at'))
|
||||
->orderByRaw('pinned_at IS NULL')->orderByDesc('pinned_at')->latest('id')->limit(GroupController::PAGE)->get()
|
||||
: collect();
|
||||
|
||||
if (! $before) {
|
||||
$this->groups->seen($group, $user);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'group' => Presenter::group($group, $access['member']?->status),
|
||||
'membership' => $access['member'] ? ['status' => $access['member']->status, 'role' => $access['member']->role, 'notify' => $access['member']->notify] : null,
|
||||
'can' => collect($access)->except('member')->all(),
|
||||
'members' => $access['read']
|
||||
? $group->memberships()->with('user')->where('status', 'active')->limit(200)->get()->filter(fn (Member $m) => $m->user)
|
||||
->sortBy(fn (Member $m) => [array_search($m->role, ['admin', 'moderator', 'member'], true), $m->user->name])
|
||||
->map(fn (Member $m) => [...Presenter::person($m->user), 'role' => $m->role, 'role_label' => Member::ROLES[$m->role] ?? $m->role])->values()->all()
|
||||
: [],
|
||||
'posts' => Presenter::posts($posts, $user, $this->groups),
|
||||
'more' => $posts->count() === GroupController::PAGE,
|
||||
'reactions' => Post::REACTIONS,
|
||||
]);
|
||||
}
|
||||
|
||||
/** Einzelner Beitrag mit allen Kommentaren */
|
||||
public function post(Request $request, Post $post): JsonResponse
|
||||
{
|
||||
$access = $this->groups->access($post->group, $request->user());
|
||||
abort_unless($access['read'], 404);
|
||||
$post->load(['user', 'attachments', 'group']);
|
||||
$all = $post->comments()->with('user')->orderBy('id')->limit(1000)->get();
|
||||
|
||||
return response()->json([
|
||||
'post' => Presenter::posts(collect([$post]), $request->user(), $this->groups)[0],
|
||||
'comments' => Presenter::comments($all->whereNull('parent_id')->values(), $request->user(), $access['moderate'], $all->whereNotNull('parent_id')->groupBy('parent_id')),
|
||||
]);
|
||||
}
|
||||
|
||||
public function join(Request $request, Group $group): JsonResponse
|
||||
{
|
||||
abort_unless($this->groups->access($group, $request->user())['see'], 404);
|
||||
$status = $this->groups->join($group, $request->user());
|
||||
|
||||
return response()->json([
|
||||
'status' => $status,
|
||||
'message' => $status === 'active' ? 'Willkommen in der Gruppe!' : 'Anfrage gesendet – die Gruppe entscheidet.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function leave(Request $request, Group $group): JsonResponse
|
||||
{
|
||||
$this->groups->leave($group, $request->user());
|
||||
|
||||
return response()->json(['status' => null, 'message' => 'Gruppe verlassen.']);
|
||||
}
|
||||
|
||||
public function notifications(Request $request, Group $group): JsonResponse
|
||||
{
|
||||
$data = $request->validate(['notify' => ['required', 'in:all,off']]);
|
||||
$group->memberships()->where('user_id', $request->user()->id)->update(['notify' => $data['notify']]);
|
||||
|
||||
return response()->json(['notify' => $data['notify']]);
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,12 @@ use Inhaus\Plugins\Gruppen\Models\Post;
|
|||
|
||||
class Presenter
|
||||
{
|
||||
/** Dateien und Titelbilder: die App lädt mit ihrem Token über die API, der Browser über die Sitzung */
|
||||
private static function route(string $name): string
|
||||
{
|
||||
return (request()->is('api/*') ? 'gruppen.app.' : 'gruppen.').$name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
|
|
@ -33,7 +39,7 @@ class Presenter
|
|||
'privacy' => $group->privacy,
|
||||
'privacy_label' => Group::PRIVACY[$group->privacy],
|
||||
'privacy_hint' => Group::PRIVACY_HINTS[$group->privacy],
|
||||
'cover_url' => $group->cover_path ? route('gruppen.cover', [$group, 'v' => substr(md5($group->cover_path), 0, 8)]) : null,
|
||||
'cover_url' => $group->cover_path ? route(self::route('cover'), [$group, 'v' => substr(md5($group->cover_path), 0, 8)]) : null,
|
||||
'members_count' => $group->members_count,
|
||||
'posts_count' => $group->posts_count,
|
||||
'last_activity_at' => $group->last_activity_at?->toIso8601String(),
|
||||
|
|
@ -70,10 +76,10 @@ class Presenter
|
|||
'created_at' => $post->created_at?->toIso8601String(),
|
||||
'url' => route('gruppen.post', [$post->group, $post]),
|
||||
'images' => $post->attachments->filter->isImage()->map(fn (Attachment $a) => [
|
||||
'id' => $a->id, 'url' => route('gruppen.file', [$a, 'full']), 'thumb_url' => route('gruppen.file', [$a, 'thumb']), 'width' => $a->width, 'height' => $a->height, 'name' => $a->name,
|
||||
'id' => $a->id, 'url' => route(self::route('file'), [$a, 'full']), 'thumb_url' => route(self::route('file'), [$a, 'thumb']), 'width' => $a->width, 'height' => $a->height, 'name' => $a->name,
|
||||
])->values()->all(),
|
||||
'files' => $post->attachments->reject->isImage()->map(fn (Attachment $a) => [
|
||||
'id' => $a->id, 'url' => route('gruppen.file', [$a, 'full']), 'name' => $a->name, 'size' => $a->size,
|
||||
'id' => $a->id, 'url' => route(self::route('file'), [$a, 'full']), 'name' => $a->name, 'size' => $a->size,
|
||||
])->values()->all(),
|
||||
'poll' => $post->poll ? [
|
||||
'multiple' => (bool) $post->poll['multiple'],
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use Illuminate\Support\Facades\Storage;
|
|||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Inhaus\Plugins\Gruppen\Models\Group;
|
||||
use Inhaus\Plugins\Gruppen\Models\Post;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
|
|
@ -158,4 +159,38 @@ class GruppenTest extends TestCase
|
|||
$this->actingAs($ada)->post("/gruppen/{$group->slug}/verlassen");
|
||||
$this->assertSame('admin', $group->membership($bob)->role);
|
||||
}
|
||||
|
||||
public function test_app_api_with_token(): void
|
||||
{
|
||||
[$ada, $bob, $eve] = User::factory()->count(3)->create()->all();
|
||||
$open = $this->group($ada, 'open');
|
||||
$closed = $this->group($ada, 'closed', 'Vorstand');
|
||||
$secret = $this->group($ada, 'secret', 'Geheimrat');
|
||||
|
||||
Sanctum::actingAs($ada);
|
||||
$image = $this->post("/api/v1/gruppen/{$open->slug}/beitraege", ['body' => 'Mit Foto', 'files' => [UploadedFile::fake()->image('lauf.jpg', 60, 40)]], ['Accept' => 'application/json'])
|
||||
->assertCreated()->json('post.images.0.thumb_url');
|
||||
$this->assertStringContainsString('/api/v1/gruppen/dateien/', $image);
|
||||
$this->get($image)->assertOk();
|
||||
$this->postJson("/api/v1/gruppen/{$closed->slug}/beitraege", ['body' => 'Nur für uns'])->assertCreated();
|
||||
|
||||
Sanctum::actingAs($bob);
|
||||
$this->getJson('/api/v1/gruppen/entdecken')->assertOk()->assertJsonCount(2, 'data')->assertJsonMissing(['name' => 'Geheimrat']);
|
||||
$this->getJson("/api/v1/gruppen/{$secret->slug}")->assertNotFound();
|
||||
$this->getJson("/api/v1/gruppen/{$closed->slug}")->assertOk()->assertJsonCount(0, 'posts')->assertJsonPath('can.read', false)->assertJsonPath('members', []);
|
||||
$this->postJson("/api/v1/gruppen/{$closed->slug}/beitreten")->assertJsonPath('status', 'pending');
|
||||
|
||||
$post = $this->getJson("/api/v1/gruppen/{$open->slug}")->assertOk()->assertJsonPath('can.post', false)->json('posts.0.id');
|
||||
$this->postJson("/api/v1/gruppen/{$open->slug}/beitreten")->assertJsonPath('status', 'active');
|
||||
$this->postJson("/api/v1/gruppen/beitraege/{$post}/reaktion", ['emoji' => '👍'])->assertOk();
|
||||
$this->postJson("/api/v1/gruppen/beitraege/{$post}/kommentare", ['body' => 'Bin dabei!'])->assertOk()->assertJsonPath('comments.0.body', 'Bin dabei!');
|
||||
$this->getJson("/api/v1/gruppen/beitraege/{$post}")->assertJsonPath('post.my_reaction', '👍')->assertJsonPath('comments.0.user.id', $bob->id);
|
||||
$this->getJson('/api/v1/gruppen')->assertJsonCount(1, 'groups')->assertJsonCount(1, 'posts');
|
||||
|
||||
// Bilder aus fremden, geschlossenen Gruppen bleiben zu
|
||||
Sanctum::actingAs($eve);
|
||||
$this->get($image)->assertOk();
|
||||
$closedPost = Post::query()->where('group_id', $closed->id)->firstOrFail();
|
||||
$this->getJson("/api/v1/gruppen/beitraege/{$closedPost->id}")->assertNotFound();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue