deploy / deploy (push) Successful in 46s
- Écran d'administration supprimé (page, onglets de modération, alertes, appels admin). - « Signaler » (avis, commentaire, profil, liste) et « Signaler un bug » ouvrent un e-mail pré-rempli vers contact@bobinoo.org (motifs en rappel, références du contenu ; version et appareil pour un bug). - Remontée automatique des erreurs supprimée. À la place : une ancienne version ouverte qui ne trouve plus un fichier après une mise à jour se recharge d'elle-même (« Importing a module script failed »). - Base (20261130120000_remove_admin, appliquée) : 20 fonctions et 5 tables d'administration supprimées (admins, reports, bug_reports, client_errors, moderation_log) ; get_profile, get_review_comments, delete_review_comment, delete_shared_list et la garde de suspension réécrites sans « admin ». Suspension d'un compte : à la main dans Supabase. - 116 textes inutilisés retirés dans chacune des 18 langues. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
115 lines
4.1 KiB
TypeScript
115 lines
4.1 KiB
TypeScript
import { useEffect, useState } from 'react'
|
|
import { t } from '../../i18n'
|
|
import { cleanText, isPlainObject } from '../security'
|
|
import { cloudFetch } from './api'
|
|
import { getSession } from './auth'
|
|
import { safeMediaUrl } from './social'
|
|
|
|
/**
|
|
* Blocages entre membres, et ce qu'on peut signaler (le signalement lui-même part par e-mail,
|
|
* voir components/moderation/ReportButton.tsx). Les blocages passent par des fonctions SQL `security definer`.
|
|
*/
|
|
|
|
/** Types de contenus signalables. */
|
|
export type ReportTargetType = 'review' | 'profile' | 'comment' | 'list'
|
|
|
|
export interface ReportTarget {
|
|
type: ReportTargetType
|
|
/** Identifiant du contenu : id de la fiche (avis), id du compte (profil), id du commentaire / de la liste */
|
|
id: string
|
|
/** Auteur du contenu */
|
|
userId: string
|
|
}
|
|
|
|
export const REPORT_REASONS = ['spoiler', 'harassment', 'hate', 'sexual', 'spam', 'impersonation', 'other'] as const
|
|
export type ReportReason = (typeof REPORT_REASONS)[number]
|
|
|
|
async function rpc<T>(name: string, args: Record<string, unknown> = {}): Promise<T> {
|
|
const res = await cloudFetch(`/rest/v1/rpc/${name}`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(args),
|
|
})
|
|
if (!res.ok) {
|
|
await res.body?.cancel()
|
|
throw new Error(t('social.err.server', { status: res.status }))
|
|
}
|
|
const text = await res.text()
|
|
return (text ? JSON.parse(text) : null) as T
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ Blocages */
|
|
|
|
export interface BlockedUser {
|
|
id: string
|
|
username: string
|
|
displayName: string
|
|
avatarUrl?: string
|
|
}
|
|
|
|
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
|
|
|
|
let blocked: BlockedUser[] = []
|
|
let loaded: Promise<void> | null = null
|
|
/** Compte pour lequel la liste a été chargée (changement de compte = rechargement) */
|
|
let loadedFor: string | undefined
|
|
const listeners = new Set<() => void>()
|
|
const emit = () => listeners.forEach((fn) => fn())
|
|
|
|
/** Charge (une fois par session) la liste des comptes que j'ai bloqués. Silencieux si le serveur n'est pas à jour. */
|
|
export function loadBlocks(): Promise<void> {
|
|
const uid = getSession()?.user.id
|
|
if (loaded && loadedFor === uid) return loaded
|
|
if (loadedFor !== uid) blocked = []
|
|
loadedFor = uid
|
|
const p: Promise<void> = rpc<unknown>('my_blocks')
|
|
.then((rows) => {
|
|
// Réponse arrivée après un changement de compte : elle ne concerne plus le compte ouvert
|
|
if (loadedFor !== uid || getSession()?.user.id !== uid) {
|
|
if (loaded === p) loaded = null
|
|
return
|
|
}
|
|
blocked = (Array.isArray(rows) ? rows : []).flatMap((r) => {
|
|
if (!isPlainObject(r) || typeof r.id !== 'string' || !UUID.test(r.id)) return []
|
|
const username = cleanText(r.username, 20) ?? ''
|
|
return [{ id: r.id, username, displayName: cleanText(r.display_name, 40) ?? username, avatarUrl: safeMediaUrl(r.avatar_url) }]
|
|
})
|
|
emit()
|
|
})
|
|
.catch(() => {
|
|
/* fonction pas encore déployée / hors-ligne : rien n'est masqué, on réessaiera au prochain affichage */
|
|
if (loaded === p) loaded = null
|
|
})
|
|
loaded = p
|
|
return p
|
|
}
|
|
|
|
export const isBlocked = (userId: string | undefined | null) => !!userId && loadedFor === getSession()?.user.id && blocked.some((b) => b.id === userId)
|
|
|
|
/** Liste des comptes bloqués, tenue à jour (pour masquer avis / commentaires). */
|
|
export function useBlocked(enabled = true): { blocked: BlockedUser[]; isBlocked: (userId: string | undefined | null) => boolean } {
|
|
const [, setTick] = useState(0)
|
|
useEffect(() => {
|
|
if (!enabled) return
|
|
const fn = () => setTick((n) => n + 1)
|
|
listeners.add(fn)
|
|
void loadBlocks()
|
|
return () => {
|
|
listeners.delete(fn)
|
|
}
|
|
}, [enabled])
|
|
return { blocked: enabled ? blocked : [], isBlocked: (id) => enabled && isBlocked(id) }
|
|
}
|
|
|
|
export async function blockUser(user: BlockedUser): Promise<void> {
|
|
await rpc('block_user', { p_user: user.id })
|
|
if (!isBlocked(user.id)) blocked = [user, ...blocked]
|
|
emit()
|
|
}
|
|
|
|
export async function unblockUser(userId: string): Promise<void> {
|
|
await rpc('unblock_user', { p_user: userId })
|
|
blocked = blocked.filter((b) => b.id !== userId)
|
|
emit()
|
|
}
|