"use client"; /** * The relationship block on a chat profile: how long you've been connected, * which way the follow runs, mute, and blocking. * * One-way follows are stated plainly rather than collapsed into "friends" — * "they follow you" and "you follow each other" are different facts, and the * profile is where someone goes to check exactly that. * * Centred, to sit under the avatar and name above it — which are centred too. */ import { useState } from "react"; import { BellOff, Bell, ShieldBan, ShieldCheck } from "lucide-react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { relationships } from "@/lib/social"; import { chat, followSummary, isMuted, type ConversationDetail, type MuteDuration, } from "@/lib/chat"; function friendsSinceLabel(iso?: string | null): string | null { if (!iso) return null; const d = new Date(iso); if (Number.isNaN(d.getTime())) return null; return `Connected since ${d.toLocaleDateString(undefined, { month: "long", year: "numeric", })}`; } export function ChatProfileHeader({ conversationId, detail, onChanged, }: { conversationId: string; detail: ConversationDetail; onChanged: () => void; }) { const [busy, setBusy] = useState(false); const rel = detail.relationship; const peer = detail.peer; const muted = isMuted(detail); const setMute = async (duration: MuteDuration) => { setBusy(true); try { await chat.setMute(conversationId, duration); toast.success(duration === "off" ? "Chat unmuted" : "Chat muted"); onChanged(); } catch { toast.error("Could not change mute settings"); } finally { setBusy(false); } }; const toggleBlock = async () => { if (!peer) return; const blocking = !rel?.blocked; if (blocking && !window.confirm(`Block ${peer.name}? They won't be able to message you.`)) { return; } setBusy(true); try { if (blocking) await relationships.block(peer.handle); else await relationships.unblock(peer.handle); toast.success(blocking ? `Blocked ${peer.name}` : `Unblocked ${peer.name}`); onChanged(); } catch { toast.error("Could not update block settings"); } finally { setBusy(false); } }; return (
{followSummary(rel, peer.name)}
{friendsSinceLabel(rel.friends_since) && ({friendsSinceLabel(rel.friends_since)}
)} {rel.blocked_by && ({peer.name} has blocked you.
)}