1import{bz as g,r as y,s as r,j as a,bA as j,R as N,a1 as I,bi as w,w as $,ad as h,b9 as k,ae as E,L as S}from"./index-BNrdOJig.js";import{M as q}from"./message-circle-CDHT5vRz.js";import{F as C}from"./file-text-av3IHVAy.js";const M={new_post:C,new_dm:k,follow:h,follow_request:h,content_removed:$,new_comment:q,submission_received:w,submission_approved:I,submission_live:N},F={follow:"started following you",follow_request:"requested to follow you",new_post:"shared a new post",new_dm:"sent you a message",new_comment:"commented on your video",content_removed:"removed your content",submission_received:"submitted a new release for review",submission_approved:"release was approved",submission_live:"release is now live on MO Streams"};function O(){const o=g(),[f,x]=y.useState([]);y.useEffect(()=>{if(!o?.id)return;let t=!0;const l=async()=>{const{data:d}=await r.from("notifications").select("id, type, actor_id, entity_type, entity_id, body, read_at, created_at").eq("user_id",o.id).order("created_at",{ascending:!1}).limit(100);if(!d||!t)return;const i=new Set;d.forEach(e=>{e.actor_id&&i.add(e.actor_id)});const n=[],c=[],p=[];d.forEach(e=>{e.actor_id||!e.entity_id||(e.entity_type==="release"?n.push(e.entity_id):e.entity_type==="video"?c.push(e.entity_id):e.entity_type==="podcast_episode"&&p.push(e.entity_id))});const u={};if(n.length){const{data:e}=await r.from("releases").select("id, artist_id").in("id",n);e?.forEach(s=>{s.artist_id&&(u[`release:${s.id}`]=s.artist_id,i.add(s.artist_id))})}if(c.length){const{data:e}=await r.from("videos").select("id, owner_id").in("id",c);e?.forEach(s=>{s.owner_id&&(u[`video:${s.id}`]=s.owner_id,i.add(s.owner_id))})}if(p.length){const{data:e}=await r.from("podcast_episodes").select("id, podcaster_id").in("id",p);e?.forEach(s=>{s.podcaster_id&&(u[`podcast_episode:${s.id}`]=s.podcaster_id,i.add(s.podcaster_id))})}const m={};if(i.size){const{data:e}=await r.from("profiles").select("id, handle, display_name, country_code").in("id",Array.from(i));e?.forEach(s=>{m[s.id]={handle:s.handle,display_name:s.display_name,country_code:s.country_code??null}})}const v={handle:o.handle,display_name:o.display_name,country_code:o.country_code??null};x(d.map(e=>{if(e.actor_id)return{...e,actor:m[e.actor_id]??null};const s=e.entity_id&&e.entity_type?u[`${e.entity_type}:${e.entity_id}`]:null;return s&&m[s]?{...e,actor:m[s]}:e.type?.startsWith("submission_")?{...e,actor:v}:{...e,actor:null}}))};l();const _=r.channel(`notif-list-${o.id}`).on("postgres_changes",{event:"*",schema:"public",table:"notifications",filter:`user_id=eq.${o.id}`},l).subscribe();return()=>{t=!1,r.removeChannel(_)}},[o?.id]);const b=async()=>{o?.id&&await r.from("notifications").update({read_at:new Date().toISOString()}).eq("user_id",o.id).is("read_at",null)};return a.jsxs(j,{profile:o,title:"Notifications",subtitle:"Follows, new posts and DMs.",children:[a.jsx("div",{className:"flex justify-end mb-4",children:a.jsx("button",{onClick:b,className:"text-xs font-bold uppercase tracking-wider px-4 py-2 rounded-full bg-secondary hover:bg-secondary/80",children:"Mark all read"})}),f.length===0&&a.jsx("p",{className:"text-muted-foreground",children:"You're all caught up."}),a.jsx("ul",{className:"space-y-2",children:f.map(t=>{const l=M[t.type]??w,_=!t.read_at,d=t.type==="new_dm"&&t.actor_id?{to:"/network/dm/$userId",params:{userId:t.actor_id}}:(t.type==="follow"||t.type==="follow_request")&&t.actor?.handle?{to:"/network/u/$handle",params:{handle:t.actor.handle}}:t.type==="new_post"&&t.actor?.handle?{to:"/network/u/$handle",params:{handle:t.actor.handle}}:t.type==="new_comment"&&t.entity_id?{to:"/watch/$videoId",params:{videoId:t.entity_id}}:null,i=F[t.type]??"sent you an update",n=t.actor?.display_name??t.actor?.handle??null,c=a.jsxs("div",{className:`flex items-start gap-3 p-4 rounded-2xl border ${_?"border-primary/40 bg-primary/5":"border-border bg-card"}`,children:[a.jsx("div",{className:"w-10 h-10 rounded-full bg-secondary flex items-center justify-center",children:a.jsx(l,{className:"w-4 h-4"})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("div",{className:"text-sm",children:n?a.jsxs(a.Fragment,{children:[a.jsxs("span",{className:"font-semibold inline-flex items-center gap-1.5",children:[n,t.actor?.country_code&&a.jsx(E,{code:t.actor.country_code,size:"xs"})]})," ",i]}):a.jsx("span",{className:"font-semibold",children:i.charAt(0).toUpperCase()+i.slice(1)})}),t.body&&a.jsx("div",{className:"text-xs text-muted-foreground mt-1 truncate",children:t.body}),a.jsx("div",{className:"text-[10px] text-muted-foreground mt-1",children:new Date(t.created_at).toLocaleStr
1ing()})]})]});return a.jsx("li",{children:d?a.jsx(S,{...d,children:c}):c},t.id)})})]})}export{O as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.