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

+24 -2
View File
@@ -1,5 +1,6 @@
import { createContext, useCallback, useContext, useEffect, useMemo, useState, type ReactNode } from 'react'
import { getFollowRequests, getMyProfile, type Profile, type ProfileCard } from '../../lib/cloud/social'
import { getFollowRequests, getMyProfile, unreadNotifications, type Profile, type ProfileCard } from '../../lib/cloud/social'
import NotificationsSheet from './NotificationsSheet'
import { useMedia } from '../../store'
import type { MediaItem } from '../../types'
import EditProfile from './EditProfile'
@@ -20,6 +21,9 @@ interface SocialApi {
enabled: boolean
me: Profile | null
requests: ProfileCard[]
/** Notifications d'abonnement non lues */
unread: number
openNotifications: () => void
refresh: () => Promise<void>
openProfile: (username: string) => void
openSearch: () => void
@@ -44,6 +48,8 @@ const SocialContext = createContext<SocialApi>({
enabled: false,
me: null,
requests: [],
unread: 0,
openNotifications: () => {},
refresh: async () => {},
openProfile: () => {},
openSearch: () => {},
@@ -70,6 +76,7 @@ type Overlay =
| { kind: 'reviews'; externalId: string; title: string }
| { kind: 'sharedList'; id: string }
| { kind: 'invite'; listId: string; listName: string }
| { kind: 'notifications' }
/** Profils, recherche et aperçus : affichés par-dessus l'app, empilés (le bouton fermer revient au précédent). */
export function SocialProvider({
@@ -86,6 +93,7 @@ export function SocialProvider({
const enabled = !!account
const [me, setMe] = useState<Profile | null>(null)
const [requests, setRequests] = useState<ProfileCard[]>([])
const [unread, setUnread] = useState(0)
const [stack, setStack] = useState<(Overlay & { uid: number })[]>([])
const [peeked, setPeeked] = useState<{ item: MediaItem; owner?: PeekOwner }>()
const [sharedTick, setSharedTick] = useState(0)
@@ -116,6 +124,8 @@ export function SocialProvider({
} catch {
/* hors-ligne / serveur pas encore à jour : le reste de l'app fonctionne */
}
// À part : un serveur sans notifications ne doit pas empêcher le reste
unreadNotifications().then(setUnread, () => {})
}, [enabled])
useEffect(() => {
@@ -123,6 +133,14 @@ export function SocialProvider({
}, [refresh])
// Nouvelles demandes d'abonnement, compteurs… mis à jour au retour sur l'app
useOnResume(() => void refresh(), enabled)
// Pendant que l'app reste ouverte : nouvelles notifications d'abonnement toutes les 2 minutes
useEffect(() => {
if (!enabled) return
const id = setInterval(() => {
if (document.visibilityState === 'visible' && navigator.onLine) unreadNotifications().then(setUnread, () => {})
}, 120_000)
return () => clearInterval(id)
}, [enabled])
// Clé stable par écran (et non sa place dans la pile, qui change quand la pile est écourtée)
const push = useCallback((o: Overlay) => setStack((s) => [...s.slice(-8), { ...o, uid: ++overlayUid }]), [])
@@ -181,6 +199,8 @@ export function SocialProvider({
enabled,
me,
requests,
unread,
openNotifications: () => push({ kind: 'notifications' }),
refresh,
openProfile: (username) => push({ kind: 'profile', username }),
openSearch: () => push({ kind: 'search' }),
@@ -194,7 +214,7 @@ export function SocialProvider({
sharedTick,
bumpShared,
}),
[enabled, me, requests, refresh, push, openItem, openTitle, sharedTick, bumpShared],
[enabled, me, requests, unread, refresh, push, openItem, openTitle, sharedTick, bumpShared],
)
return (
@@ -214,6 +234,8 @@ export function SocialProvider({
<TitleReviews key={o.uid} externalId={o.externalId} title={o.title} onClose={() => close(o.uid)} onOpenProfile={(u) => push({ kind: 'profile', username: u })} />
) : o.kind === 'sharedList' ? (
<SharedListSheet key={o.uid} id={o.id} onClose={() => close(o.uid)} />
) : o.kind === 'notifications' ? (
<NotificationsSheet key={o.uid} onClose={() => close(o.uid)} onSeen={() => setUnread(0)} />
) : (
<InvitePeople key={o.uid} listId={o.listId} listName={o.listName} onClose={() => close(o.uid)} />
),