Notifications d'abonnement (et rien d'autre)

- Cloche sur l'accueil (avec le nombre non lu) : qui s'abonne, demande à s'abonner,
  se désabonne, ou accepte ma demande ; accepter/refuser une demande directement depuis la liste
- Serveur (migration 20261127120000, déjà appliquée) : déclencheur sur follows, une ligne par
  personne et par sens, 200 max par compte ; rien entre comptes bloqués ou suspendus ;
  retirer un abonné, bloquer ou supprimer un compte ne notifie pas
- Fonctions get_notifications / unread_notifications / mark_notifications_read (comptes connectés seulement)
- Textes dans les 18 langues

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
This commit is contained in:
Claude committed 2026-11-27 16:09:55 +00:00
1 parent 62e04bd67a
commit c66f0f62a6
23 files changed
+444 -3

No files matched your search

+35
View File
@@ -218,6 +218,41 @@ export async function getFollowList(userId: string, kind: 'followers' | 'followi
}
export const getFollowRequests = async () => toCards(await rpc('get_follow_requests'))
// ─── Notifications (abonnements uniquement) ───
export type NotificationKind = 'new_follower' | 'follow_request' | 'unfollow' | 'follow_accepted'
const NOTIFICATION_KINDS: NotificationKind[] = ['new_follower', 'follow_request', 'unfollow', 'follow_accepted']
export interface FollowNotification {
id: number
kind: NotificationKind
createdAt: string
read: boolean
actor: ProfileCard
}
export async function getNotifications(): Promise<FollowNotification[]> {
const raw = await rpc('get_notifications')
if (!Array.isArray(raw)) return []
return raw.slice(0, 100).flatMap((n): FollowNotification[] => {
if (!isPlainObject(n) || typeof n.id !== 'number' || !NOTIFICATION_KINDS.includes(n.kind as NotificationKind)) return []
const actor = toCard(n.actor)
const createdAt = safeIso(n.created_at)
return actor && createdAt ? [{ id: n.id, kind: n.kind as NotificationKind, createdAt, read: n.read === true, actor }] : []
})
}
export async function unreadNotifications(): Promise<number> {
const n = await rpc('unread_notifications')
return typeof n === 'number' && Number.isFinite(n) ? Math.max(0, Math.min(999, Math.round(n))) : 0
}
/** Tout marquer comme lu (la fonction ne renvoie rien : pas de JSON à lire). */
export async function markNotificationsRead() {
const res = await cloudFetch('/rest/v1/rpc/mark_notifications_read', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' })
if (!res.ok) throw new Error(t('social.err.server', { status: res.status }))
}
// ─── Abonnements ───
async function ok(res: Response) {