Notifications phase 2 (Gitea #10): share triggers, targeted people, Signal, managed-by footer
- share_received trigger: scanner fires when a bookmark, tag or collection
is shared with the rule owner (same dedupe discipline; sharer name and
item title in the message)
- config.targetUserIds on rules: same-tenant targets (<=20, validated at
write time); each targeted Notification row carries recipientId and is
delivered through the RECIPIENT's own enabled channel of the rule's kind,
gated by the recipient's tenant plan (no channel => suppressed, visible
in history); history lists rows you own or were targeted on
- signal channel kind: signal-cli REST bridge (POST {restUrl}/v2/send with
account query param and recipients array); account encrypted + masked
like every other credential; netguard-dialed like every webhook
- 'Managed by David's Superbrain.' footer is plan DATA: entitlements
ManagedFooter (free hosted plan only; managed_footer override key),
appended at delivery time - paying plans, core and self-hosted never
carry it
- catalog: signal joins standard/premium/core/selfhosted channel lists
- migration 019 + schema.sql (trigger/kind CHECKs, Notification.recipientId)
- UI: trigger option, same-tenant target picker via /api/users/search,
signal channel fields, targeted-count badge on rules
- tests: share/target/footer/signal legs against fake webhook, fake SMTP
and a fake signal-cli bridge; entitlements footer assertions
This commit is contained in:
@@ -12,7 +12,7 @@ import { Input } from '@/components/ui/input'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { Bell, Mail, Slack, MessageSquare, Send, Trash2, Loader2 } from 'lucide-react'
|
||||
import { Bell, Mail, Slack, MessageSquare, Send, Trash2, Loader2, Smartphone, X } from 'lucide-react'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
type Channel = {
|
||||
@@ -20,7 +20,7 @@ type Channel = {
|
||||
config: Record<string, string>; createdAt: string
|
||||
}
|
||||
type Rule = {
|
||||
id: string; name: string; trigger: string; config: { leadHours?: number }
|
||||
id: string; name: string; trigger: string; config: { leadHours?: number; targetUserIds?: string[] }
|
||||
channelId: string; channelKind: string; channelName: string
|
||||
cooldownMinutes: number; enabled: boolean; lastFiredAt: string | null; version: number
|
||||
}
|
||||
@@ -47,11 +47,19 @@ const KIND_META: Record<string, { label: string; icon: typeof Mail; fields: { ke
|
||||
{ key: 'chatId', label: 'Chat ID' },
|
||||
],
|
||||
},
|
||||
signal: {
|
||||
label: 'Signal', icon: Smartphone, fields: [
|
||||
{ key: 'restUrl', label: 'signal-cli REST bridge URL', placeholder: 'https://signal-rest.example.org' },
|
||||
{ key: 'account', label: 'Sender account (phone or uuid)', secret: true },
|
||||
{ key: 'recipient', label: 'Recipient (phone or uuid)' },
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
const TRIGGER_LABELS: Record<string, string> = {
|
||||
signal_created: 'New signal matches a mailbox watcher',
|
||||
bookmark_due: 'A bookmark is due soon or overdue',
|
||||
share_received: 'Someone shares a bookmark, tag or collection with you',
|
||||
}
|
||||
|
||||
async function api(path: string, init?: RequestInit): Promise<Response> {
|
||||
@@ -74,6 +82,11 @@ export function NotificationsSettings() {
|
||||
const [rTrigger, setRTrigger] = useState('bookmark_due')
|
||||
const [rChannel, setRChannel] = useState('')
|
||||
const [rLead, setRLead] = useState(24)
|
||||
// Targeted recipients (same-tenant users); deliveries ride each target's
|
||||
// own channel of the rule's kind.
|
||||
const [rTargets, setRTargets] = useState<{ id: string; name: string | null; email: string | null }[]>([])
|
||||
const [targetQuery, setTargetQuery] = useState('')
|
||||
const [targetResults, setTargetResults] = useState<{ id: string; name: string | null; email: string | null }[]>([])
|
||||
const [savingR, setSavingR] = useState(false)
|
||||
const [testingId, setTestingId] = useState<string | null>(null)
|
||||
|
||||
@@ -153,12 +166,17 @@ export function NotificationsSettings() {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
name: rName.trim(), trigger: rTrigger, channelId: rChannel,
|
||||
config: rTrigger === 'bookmark_due' ? { leadHours: rLead } : {},
|
||||
config: {
|
||||
...(rTrigger === 'bookmark_due' ? { leadHours: rLead } : {}),
|
||||
...(rTargets.length ? { targetUserIds: rTargets.map(t => t.id) } : {}),
|
||||
},
|
||||
}),
|
||||
})
|
||||
if (res.ok) {
|
||||
toast.success('Rule created')
|
||||
setRName('')
|
||||
setRTargets([])
|
||||
setTargetQuery('')
|
||||
await reload()
|
||||
} else await reportError(res, 'Could not create the rule')
|
||||
} finally { setSavingR(false) }
|
||||
@@ -259,6 +277,7 @@ export function NotificationsSettings() {
|
||||
<p className="text-xs text-muted-foreground truncate">
|
||||
{TRIGGER_LABELS[rule.trigger] ?? rule.trigger}
|
||||
{rule.trigger === 'bookmark_due' && rule.config?.leadHours != null ? ` (within ${rule.config.leadHours}h)` : ''}
|
||||
{Array.isArray(rule.config?.targetUserIds) && rule.config.targetUserIds.length > 0 ? ` (+${rule.config.targetUserIds.length} targeted)` : ''}
|
||||
{' → '}
|
||||
<span className="inline-flex items-center gap-1">{kindIcon(rule.channelKind)}{rule.channelName}</span>
|
||||
</p>
|
||||
@@ -299,6 +318,43 @@ export function NotificationsSettings() {
|
||||
hours of the due date
|
||||
</label>
|
||||
)}
|
||||
<div className="space-y-1.5">
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{rTargets.map(tgt => (
|
||||
<span key={tgt.id} className="inline-flex items-center gap-1 rounded-full border bg-muted/50 px-2 py-0.5 text-xs">
|
||||
{tgt.name ?? tgt.email ?? tgt.id.slice(0, 8)}
|
||||
<button type="button" aria-label={`Remove ${tgt.name ?? 'target'}`} onClick={() => setRTargets(prev => prev.filter(x => x.id !== tgt.id))}>
|
||||
<X className="h-3 w-3 text-muted-foreground" />
|
||||
</button>
|
||||
</span>
|
||||
))}
|
||||
{rTargets.length > 0 && <span className="text-xs text-muted-foreground">also notify (via their own channels)</span>}
|
||||
</div>
|
||||
<Input
|
||||
placeholder="Also notify someone in your organization (search by name or exact email)"
|
||||
value={targetQuery}
|
||||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const q = e.target.value
|
||||
setTargetQuery(q)
|
||||
if (q.trim().length < 2) { setTargetResults([]); return }
|
||||
api(`/api/users/search?q=${encodeURIComponent(q)}`)
|
||||
.then(r => (r.ok ? r.json() : []))
|
||||
.then((rows: { id: string; name: string | null; email: string | null }[]) =>
|
||||
setTargetResults(rows.filter(u => !rTargets.some(t => t.id === u.id)).slice(0, 6)))
|
||||
.catch(() => setTargetResults([]))
|
||||
}}
|
||||
/>
|
||||
{targetResults.map(u => (
|
||||
<button
|
||||
key={u.id} type="button"
|
||||
className="flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-xs hover:bg-muted"
|
||||
onClick={() => { setRTargets(prev => [...prev, u]); setTargetQuery(''); setTargetResults([]) }}
|
||||
>
|
||||
<span className="font-medium">{u.name ?? 'Unnamed'}</span>
|
||||
<span className="text-muted-foreground">{u.email ?? ''}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<Button onClick={addRule} loading={savingR} size="sm">Create rule</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user