Réglages : choisir ses notifications ; journal de la console lisible
deploy / deploy (push) Successful in 1m12s
deploy / deploy (push) Successful in 1m12s
- Réglages → Notifications (comptes connectés) : un interrupteur par type, en 3 groupes (abonnements, mes avis, activité des comptes suivis), 18 langues. Choix synchronisé (settings.notifOff). - Serveur (20261201110000, appliquée) : une notification d'un type désactivé n'est pas créée (trigger notifications_wanted) ; celles déjà reçues sont masquées de la liste et du compteur. - Console : les détails des connexions étaient enregistrés comme texte JSON et affichés lettre par lettre. Enregistrement corrigé (sql.json), anciennes lignes remises en forme à la lecture (20261201100000), appareil affiché en clair (« Chrome · Windows »). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
This commit is contained in:
28 files changed
+432
-10
No files matched your search
@@ -0,0 +1,25 @@
|
||||
-- Journal de la console : les détails des connexions avaient été enregistrés comme texte JSON (et non objet),
|
||||
-- affichés lettre par lettre. Le journal ne peut pas être modifié : la lecture les remet en forme. Idempotent.
|
||||
create or replace function admin.as_object(d jsonb)
|
||||
returns jsonb language plpgsql immutable set search_path = '' as $$
|
||||
begin
|
||||
if jsonb_typeof(d) = 'string' then
|
||||
d := (d #>> '{}')::jsonb;
|
||||
end if;
|
||||
return case when jsonb_typeof(d) = 'object' then d else '{}'::jsonb end;
|
||||
exception when others then
|
||||
return '{}'::jsonb;
|
||||
end;
|
||||
$$;
|
||||
comment on function admin.as_object(jsonb) is 'Détails du journal toujours sous forme d''objet (anciennes lignes enregistrées en texte).';
|
||||
|
||||
create or replace function admin.journal_list(p_offset integer)
|
||||
returns jsonb language sql stable set search_path = '' as $$
|
||||
select coalesce(jsonb_agg(j.row order by j.id desc), '[]'::jsonb) from (
|
||||
select j.id, jsonb_build_object('id', j.id, 'at', j.at, 'action', j.action, 'target', j.target, 'details', admin.as_object(j.details),
|
||||
'admin', (select username from public.profiles where id = j.admin_id)) as row
|
||||
from admin.journal j order by j.id desc
|
||||
limit 50 offset greatest(coalesce(p_offset, 0), 0)
|
||||
) j;
|
||||
$$;
|
||||
revoke all on function admin.as_object(jsonb) from public, anon, authenticated, service_role;
|
||||
@@ -0,0 +1,72 @@
|
||||
-- Choix des notifications (Réglages → Notifications, 01/12/2026). Idempotent.
|
||||
-- Les types désactivés sont dans les réglages synchronisés du compte : settings.data->'notifOff' (liste de types).
|
||||
-- Une notification d'un type désactivé n'est jamais créée (trigger), et celles déjà reçues sont masquées
|
||||
-- de la liste et du compteur.
|
||||
|
||||
create or replace function public.azuu_notif_wanted(p_user uuid, p_kind text)
|
||||
returns boolean language sql stable security definer set search_path = '' as $$
|
||||
select not coalesce((
|
||||
select jsonb_typeof(s.data->'notifOff') = 'array' and (s.data->'notifOff') ? p_kind
|
||||
from public.settings s where s.user_id = p_user
|
||||
), false);
|
||||
$$;
|
||||
revoke all on function public.azuu_notif_wanted(uuid, text) from public, anon, authenticated;
|
||||
comment on function public.azuu_notif_wanted(uuid, text) is 'Règle : ce compte veut-il ce type de notification (Réglages → Notifications) ?';
|
||||
|
||||
create or replace function public.azuu_notif_filter()
|
||||
returns trigger language plpgsql security definer set search_path = '' as $$
|
||||
begin
|
||||
if not public.azuu_notif_wanted(new.user_id, new.kind) then
|
||||
return null;
|
||||
end if;
|
||||
return new;
|
||||
end;
|
||||
$$;
|
||||
revoke all on function public.azuu_notif_filter() from public, anon, authenticated;
|
||||
comment on function public.azuu_notif_filter() is 'Trigger (notifications) : une notification d''un type désactivé par son destinataire n''est pas créée.';
|
||||
|
||||
drop trigger if exists notifications_wanted on public.notifications;
|
||||
create trigger notifications_wanted before insert on public.notifications
|
||||
for each row execute function public.azuu_notif_filter();
|
||||
|
||||
create or replace function public.get_notifications()
|
||||
returns jsonb language sql stable security definer set search_path = '' as $$
|
||||
with off as (
|
||||
select coalesce(case when jsonb_typeof(s.data->'notifOff') = 'array' then s.data->'notifOff' end, '[]'::jsonb) as kinds
|
||||
from public.settings s where s.user_id = auth.uid()
|
||||
)
|
||||
select coalesce(jsonb_agg(jsonb_build_object(
|
||||
'id', n.id, 'kind', n.kind, 'created_at', n.created_at, 'read', n.read_at is not null,
|
||||
'emoji', n.emoji, 'actor', public.profile_card(p), 'item', it.item) order by n.id desc), '[]'::jsonb)
|
||||
from (
|
||||
select * from public.notifications nn
|
||||
where nn.user_id = auth.uid() and public.azuu_mfa_ok()
|
||||
and not exists (select 1 from off where off.kinds ? nn.kind)
|
||||
order by nn.id desc limit 100
|
||||
) n
|
||||
join public.profiles p on p.id = n.actor_id and not p.suspended
|
||||
left join lateral (
|
||||
select public.public_item(i.data) as item
|
||||
from public.items i
|
||||
where n.item_id is not null and not i.deleted and i.id = n.item_id
|
||||
and i.user_id = case when n.kind in ('reaction', 'review_comment') then n.user_id else n.actor_id end
|
||||
and (n.kind in ('reaction', 'review_comment') or public.can_view(n.actor_id))
|
||||
) it on true
|
||||
where not exists (select 1 from public.blocks b
|
||||
where (b.blocker_id = auth.uid() and b.blocked_id = n.actor_id)
|
||||
or (b.blocker_id = n.actor_id and b.blocked_id = auth.uid()))
|
||||
and (n.item_id is null or it.item is not null)
|
||||
$$;
|
||||
comment on function public.get_notifications() is 'App : mes notifications, avec le titre lié (sans les types que j''ai désactivés).';
|
||||
|
||||
create or replace function public.unread_notifications()
|
||||
returns integer language sql stable security definer set search_path = '' as $$
|
||||
select count(*)::int from public.notifications n
|
||||
join public.profiles p on p.id = n.actor_id and not p.suspended
|
||||
where n.user_id = auth.uid() and public.azuu_mfa_ok() and n.read_at is null
|
||||
and public.azuu_notif_wanted(auth.uid(), n.kind)
|
||||
and not exists (select 1 from public.blocks b
|
||||
where (b.blocker_id = auth.uid() and b.blocked_id = n.actor_id)
|
||||
or (b.blocker_id = n.actor_id and b.blocked_id = auth.uid()))
|
||||
$$;
|
||||
comment on function public.unread_notifications() is 'App : nombre de notifications non lues (sans les types que j''ai désactivés).';
|
||||
Reference in new issue
Block a user