1import{j as e,u as Ge,eZ as Ke,cw as Ye,e_ as ye,cS as Ze,e$ as we,aw as Xe,cL as je,ca as Je,at as et,b6 as Ne,ce as tt,d0 as st,cm as at,f0 as be,b5 as rt,f1 as nt,b4 as lt,f2 as it,f3 as ot,f4 as dt,f5 as ct,f6 as ut,f7 as xt,f8 as mt}from"./vendor-data-eBPZki-Z.js";import{r,f as se,L as ee,o as ft,k as gt}from"./vendor-react-BgtJhS2O.js";import{d6 as bt,t as S,bv as pt,at as Ce,a_ as Me,u as V,d7 as ht,Z as te,_ as Se,d8 as vt,bL as kt,d9 as yt,a7 as Re,cJ as wt,bp as jt,b3 as Nt,da as Ct,db as Mt,ak as St,b6 as Rt,aX as Tt,aZ as Lt,dc as Pt,dd as Et,de as $t,df as Dt}from"./index-DTQGL8n8.js";import{eQ as At,cB as pe,eR as Bt,eS as Ut,eT as qt,eU as he,eV as It,eW as Ot,eX as _t,ef as Ft,eY as Ht,eZ as Vt,e_ as zt,dv as Qt,e$ as Wt,f0 as Gt}from"./vendor-zod-Bei2Z9MS.js";import{u as Kt}from"./useTrackScreen-BLOOZkQ_.js";import{u as Yt}from"./useUserSettingValue-BuB0sMd0.js";import{E as Zt,S as Xt}from"./ExpandableBody-DWLBBjw0.js";import{S as Jt}from"./lock-square-DNvVRpgy.js";import{L as es,a as ts}from"./loungeMemberMetaIcons-bk96OcQw.js";import{S as ss}from"./StoryUnavailableModal-BRXawH9o.js";import{D as as,a as rs,b as ns}from"./DmReplyWarningBanner-BK4vqg_I.js";import"./StatusPill-D1LA3ydS.js";const ls=3e3,is=4e3;function os(t,s){const[m,n]=r.useState(!1),o=bt(),c=r.useRef(0),d=r.useRef(void 0),u=r.useCallback(()=>{if(!o||!t||!s)return;const x=Date.now();if(x-c.current<ls)return;c.current=x;const i=`private-dm.conversation.${t}`;o.trigger(i,"client-typing",{user_ulid:s.id,username:s.username})},[o,t,s]);return r.useEffect(()=>{if(!o||!t)return;const x=`private-dm.conversation.${t}`,i=o.on(x,"client-typing",l=>{l.user_ulid!==s?.id&&(n(!0),clearTimeout(d.current),d.current=setTimeout(()=>n(!1),is))});return()=>{i(),clearTimeout(d.current),n(!1)}},[o,t,s?.id]),{isOtherTyping:m,sendTyping:u}}const ds=[{side:"left",width:"w-2/5"},{side:"right",width:"w-1/2"},{side:"left",width:"w-1/3"},{side:"right",width:"w-3/5"},{side:"left",width:"w-1/2"},{side:"right",width:"w-1/4"}];function cs(){return e.jsx("ul",{"aria-label":"Loading conversation",className:"flex flex-col gap-2 p-4 animate-pulse",children:ds.map(({side:t,width:s},m)=>e.jsx("li",{className:`flex ${t==="right"?"justify-end":"justify-start"}`,children:e.jsx("div",{className:`h-9 ${s} rounded-2xl bg-bg-elevated dark:bg-bg-elevated-dark`,"aria-hidden":"true"})},m))})}function us(){return e.jsxs("div",{role:"status","aria-label":"Loading shared profile","data-testid":"shared-profile-loading",className:"mt-1 flex min-h-[257.5px] w-[244px] max-w-full min-w-0 flex-col items-center justify-center gap-2.5 rounded-2xl border border-system-grey4 bg-surface-elevated p-4 animate-pulse dark:border-system-grey4-dark dark:bg-surface-elevated-dark",children:[e.jsx("div",{className:"h-24 w-24 rounded-full bg-bg-elevated dark:bg-bg-elevated-dark","aria-hidden":"true"}),e.jsxs("div",{className:"flex w-full max-w-[193px] flex-col items-center gap-2",children:[e.jsx("div",{className:"h-[18px] w-2/3 rounded bg-bg-elevated dark:bg-bg-elevated-dark","aria-hidden":"true"}
1),e.jsx("div",{className:"h-4 w-1/2 rounded bg-bg-elevated dark:bg-bg-elevated-dark","aria-hidden":"true"}),e.jsx("div",{className:"h-4 w-3/4 rounded bg-bg-elevated dark:bg-bg-elevated-dark","aria-hidden":"true"})]}),e.jsxs("div",{className:"mt-1 flex w-full justify-center gap-2",children:[e.jsx("div",{className:"h-[34px] w-[100px] rounded-lg bg-bg-elevated dark:bg-bg-elevated-dark","aria-hidden":"true"}),e.jsx("div",{className:"h-[34px] w-[100px] rounded-lg bg-bg-elevated dark:bg-bg-elevated-dark","aria-hidden":"true"})]})]})}function xs(){return e.jsxs("div",{role:"status","aria-label":"Loading shared lounge","data-testid":"shared-lounge-loading",className:"mt-1 w-[244px] max-w-full min-w-0 overflow-hidden rounded-2xl border border-system-grey4 bg-surface-elevated animate-pulse dark:border-system-grey4-dark dark:bg-surface-elevated-dark",children:[e.jsx("div",{className:"aspect-[1.91/1] w-full bg-bg-elevated dark:bg-bg-elevated-dark","aria-hidden":"true"}),e.jsxs("div",{className:"flex flex-col gap-2 p-3",children:[e.jsx("div",{className:"h-5 w-2/3 rounded bg-bg-elevated dark:bg-bg-elevated-dark","aria-hidden":"true"}),e.jsx("div",{className:"h-4 w-full rounded bg-bg-elevated dark:bg-bg-elevated-dark","aria-hidden":"true"}),e.jsx("div",{className:"h-4 w-4/5 rounded bg-bg-elevated dark:bg-bg-elevated-dark","aria-hidden":"true"}),e.jsx("div",{className:"mt-1 h-[34px] w-full rounded-lg bg-bg-elevated dark:bg-bg-elevated-dark","aria-hidden":"true"})]})]})}function ms(t,s){const m=Ge(),n=r.useRef(new Set);r.useEffect(()=>{n.current.clear()},[t]),r.useEffect(()=>{if(s.length===0)return;const o=n.current;for(const c of s){const d=c.text;if(!d)continue;const x=d.match(At)?.[1];!x||o.has(x)||(o.add(x),m.prefetchQuery({queryKey:Ye.detail(x),queryFn:()=>Ke(x,{requirePlayableMedia:!1})}))}},[s,m])}function fs({conversationId:t,otherUser:s,enabled:m}){const n=se(),o=ye(),c=Ze(),[d,u]=r.useState(!1),[x,i]=r.useState(!1),[l,k]=r.useState(!1),b=r.useRef(!1);r.useEffect(()=>{u(!1),i(!1),k(!1),b.current=!1},[m,t]);const h=r.useCallback(async()=>{if(t)try{await o.mutateAsync(t)}catch(N){N instanceof we||S.error("Couldn't remove the message request. It may still appear in Requests.")}n("/messages?tab=requests",{replace:!0})},[t,o,n]),y=r.useCallback(async()=>{const N=s?.username;if(!N){S.error("Couldn't block this user. Try again.");return}try{await c.mutateAsync(N),S.success("User blocked"),await h()}catch{S.error("Couldn't block this user. Try again.")}},[s,c,h]),R=r.useCallback(()=>{if(!s?.username){S.error("Couldn't block this user. Try again.");return}u(!0)},[s]),j=r.useCallback(N=>{u(N)},[]),w=r.useCallback(N=>{i(N)},[]),v=r.useCallback(N=>{N||(b.current=!1,k(!1))},[]),T=r.useCallback(()=>{v(!1)},[v]),C=r.useCallback(async()=>{const N=b.current;if(b.current=!1,N){const q=s?.username;if(!q){S.error("Couldn't block this user. Try again.");return}try{await c.mutateAsync(q),S.success("User blocked")}catch{S.error("Couldn't block this user. Try again.");return}}await h()},[s,c,h]),g=r.useCallback(()=>{C()},[C]),p=r.useCallback(()=>i(!0),[]),L=r.useCallback(()=>{if(!s?.id||!s?.username){S.error("Couldn't report this user. Try again.");return}b.current=!0,k(!0)},[s]),E=r.useMemo(()=>[{id:"block",label:"Block",destructive:!0,onPress:p},{id:"block-and-report",label:"Block and Report",destructive:!0,onPress:L}],[p,L]),M=s?.username,A=e.jsxs(e.Fragment,{children:[e.jsx(pt,{open:d,onOpenChange:j,title:M?`Block @${M}`:"Block user",options:E}),e.jsx(Ce,{open:x,onOpenChange:w,title:M?`Block @${M}?`:"Block this user?",description:"They won't be able to message you or see your content, and this request will be removed.",confirmLabel:"Block",destructive:!0,onConfirm:y,isPending:c.isPending||o.isPending}),m&&s?.id&&s?.username?e.jsx(Me,{open:l,onClose:T,targetId:s.id,targetType:"user",onReportSubmitted:g}):null]});return{onBlockRequest:R,isBlockPending:c.isPending,isLeavePending:o.isPending,overlays:A}}function gs(t){return t?"bg-white/20":"bg-bg-elevated dark:bg-bg-elevated-dark"}function bs({postUlid:t,isOwn:s}){const m=se(),{data:n,isLoading:o,isError:c}=Xe(t,{requirePlayableMedia:!1}),d=V(T=>T.user),u=je(n?.creator??null,d?.id),x=r.useMemo(()=>n&&!u.isChecking&&!u.isLocked?Je(n):null,[n,u.isChecking,u.isLocked]),i=et(x),l=r.useMemo(()=>x&&!i?x.media:[],[x,i]),k=s?"bg-brand border-white/20 text-white":"bg-surface dark:bg-bg-dark border-border-light/60 dark:border-border-dark/60",b=s?"text-white":"text-text dark:text-text-dark",h=s?"text-white/75":"text-text-secondary dark:text-text-secondary-dark",y=gs(s);if(o||u.isChecking)return e.jsxs("div",{className:`mt-1 max-w-full overflow-hidden rounded-xl border animate-pulse ${k}`,role:"status","aria-label":"Loading shared post",children:[e.jsx("div",{className:`h-40 w-full ${y}`}),e.jsxs("div",{className:"p-3 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`w-9 h-9 rounded-full flex-shrink-0 ${y}`}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-1.5",children:[e.jsx("div",{className:`h-3.5 w-28 rounded ${y}`}),e.jsx("div",{className:`h-3 w-20 rounded ${y}`})]})]}),e.jsx("div",{className:`h-3 w-full rounded ${y}`}),e.jsx("div",{className:`h-3 w-3/4 rounded ${y}`})]})]});if(c||!n)return e.jsx("div",{className:`mt-1 max-w-full overflow-hidden rounded-xl border ${k}`,children:e.jsx("div",{className:`p-3 text-xs ${h}`,children:"Post no longer available"})});if(u.isLocked)return e.jsx("div",{className:`mt-1 max-w-full overflow-hidden rounded-xl border ${k}`,children:e.jsx("div",{className:`p-3 text-xs ${h}`,children:"Post from a private account"})});const R=i?(n.title||"").slice(0,140):(n.description||n.title||"").slice(0,140),j=n.creator,w=j.displayName||j.username,v=()=>{m(`/post/${n.id}`)};return e.jsxs("button",{type:"button",onClick:v,className:`mt-1 max-w-full overflow-hidden rounded-xl border text-left transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand ${k}`,"aria-label":`Shared post by ${w}`,children:[i?null:e.jsx(ht,{media:l,preserveSingleMediaAspect:!0,
1compact:!0}),e.jsxs("div",{className:"p-3 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[j.avatarUrl?e.jsx("img",{src:j.avatarUrl,alt:"",className:"w-9 h-9 rounded-full object-cover flex-shrink-0",loading:"lazy"}):e.jsx("div",{className:`w-9 h-9 rounded-full flex items-center justify-center text-sm font-semibold flex-shrink-0 ${s?"bg-white/20 text-white":"bg-bg-elevated dark:bg-bg-elevated-dark text-text-secondary dark:text-text-secondary-dark"}`,children:(w||"?")[0]?.toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:`flex items-center gap-1 text-sm min-w-0 ${b}`,children:[e.jsx(te,{className:"font-semibold",children:w}),e.jsx("span",{className:"flex-shrink-0",children:e.jsx(Se,{badges:j.badges,size:12})})]}),e.jsxs(te,{as:"div",className:`text-xs ${h}`,children:["@",j.username]})]})]}),i?e.jsx("p",{className:`text-xs font-semibold ${h}`,children:"Members only"}):null,R&&e.jsx("p",{className:`text-sm line-clamp-3 break-words ${b}`,children:R})]})]})}const ps="mt-1 flex min-h-[257.5px] w-[244px] max-w-full min-w-0 items-center justify-center rounded-2xl border border-system-grey4 bg-surface-elevated dark:border-system-grey4-dark dark:bg-surface-elevated-dark",Te="inline-flex h-[34px] w-[100px] max-w-full min-w-0 items-center justify-center rounded-lg px-3 py-2 text-[13px] font-semibold leading-[18px] tracking-[-0.23px] text-center disabled:opacity-50",Le=`${Te} bg-bg dark:bg-bg-dark border border-system-grey4 dark:border-system-grey4-dark text-text dark:text-text-dark`,hs=`${Te} bg-text dark:bg-text-dark text-bg dark:text-bg-dark border border-transparent`;function vs(t){return t==="follow"?hs:Le}function ks({username:t}){const s=V(l=>l.isLoggedIn),m=V(l=>l.user?.id),{data:n,isLoading:o,isError:c}=Ne(t,{refetchOnMount:!1});if(o)return e.jsx(us,{});if(c||!n||n.isBlockedByYou||n.isBanned)return e.jsxs("div",{className:"flex items-center gap-2 p-3 text-[13px] text-text-dim dark:text-text-dim-dark","data-testid":"shared-profile-unavailable",children:[e.jsx(vt,{className:"flex-shrink-0",size:18,"aria-hidden":"true"}),e.jsx("span",{children:"Profile not available"})]});const d=n.displayName||n.username,u=`/${n.username}`,x=s&&!m,i=m!==n.id&&!x;return e.jsxs("div",{className:`${ps} flex-col gap-2.5 p-4`,"data-testid":"shared-profile-preview",children:[e.jsxs(ee,{to:u,className:"flex min-w-0 w-full flex-col items-center gap-2.5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand rounded-lg","aria-label":`View ${d}'s profile`,children:[e.jsx("div",{className:"rounded-full border border-system-grey4 dark:border-system-grey4-dark",children:e.jsx("div",{className:"h-24 w-24 overflow-hidden rounded-full border-4 border-bg dark:border-bg-dark",children:n.avatarUrl?e.jsx("img",{src:n.avatarUrl,alt:"",className:"h-full w-full object-cover",loading:"lazy"}):e.jsx("div",{className:"flex h-full w-full items-center justify-center bg-bg-elevated text-2xl font-semibold text-text-secondary dark:bg-bg-elevated-dark dark:text-text-secondary-dark",children:d[0]?.toUpperCase()??"?"})})}),e.jsxs("div",{className:"flex min-h-[63.5px] w-full max-w-[193px] min-w-0 flex-col items-center justify-between",children:[e.jsxs("div",{className:"flex h-[18px] w-full min-w-0 items-center justify-center gap-0.5",children:[e.jsx(te,{className:"text-lg font-bold leading-[18px] tracking-[-0.26px] text-text dark:text-text-dark",children:d}),e.jsx("span",{className:"flex-shrink-0",children:e.jsx(Se,{badges:n.badges,size:12})})]}),e.jsxs(te,{className:"text-[15px] font-normal leading-[22.5px] tracking-[-0.23px] text-text-secondary dark:text-text-secondary-dark",children:["@",n.username]}),e.jsxs("p",{className:"max-w-full truncate text-sm font-medium leading-[22.5px] tracking-[-0.23px] text-text-dim dark:text-text-dim-dark",children:[pe(n.followers)," Followers ⢠",pe(n.postCount)," Posts"]})]})]}),e.jsxs("div",{className:"flex w-full min-w-0 flex-wrap justify-center gap-2","data-testid":"shared-profile-actions",children:[i&&e.jsx(kt,{username:n.username,initialFollowing:n.isFollowing,initialRequested:n.hasPendingFollowRequest,isPrivate:n.isPrivate,confirmUnfollow:"private-only",className:vs}),e.jsx(ee,{to:u,className:Le,"aria-label":`View @${n.username}'s profile`,children:"View Profile"})]})]})}const ys="mt-1 w-[244px] max-w-full min-w-0 overflow-hidden rounded-2xl border border-system-grey4 bg-surface-elevated dark:border-system-grey4-d
1ark dark:bg-surface-elevated-dark",ws="inline-flex h-[34px] w-full items-center justify-center rounded-lg border border-system-grey4 bg-bg px-3 py-2 text-[13px] font-semibold leading-[18px] tracking-[-0.23px] text-center text-text dark:border-system-grey4-dark dark:bg-bg-dark dark:text-text-dark";function js(){return e.jsxs("div",{className:"flex items-center gap-2 p-3 text-[13px] text-text-dim dark:text-text-dim-dark","data-testid":"shared-lounge-unavailable",children:[e.jsx(Re,{className:"flex-shrink-0",size:18,"aria-hidden":"true"}),e.jsx("span",{children:"Lounge not available"})]})}function Ns({spaceId:t,channelId:s,channelType:m}){const{data:n,isLoading:o,isError:c}=tt(t,{retry:!1}),d=n?.data;if(o)return e.jsx(xs,{});if(c||!d||d.isBanned||!Bt(d))return e.jsx(js,{});const u=d.displayName||d.name||"Lounge",x=Ut(d),i=qt(d),l=x?`View ${u} lounge, ${he(d)}`:`View ${u} lounge`,k=s?.trim();let b=`/lounges/${d.ulid}`;if(k){const h=new URLSearchParams;h.set("channel",k);const y=m?.trim();y&&h.set("channelType",y),b=yt(d.ulid,`?${h.toString()}`)}return e.jsxs("div",{className:ys,"data-testid":"shared-lounge-preview",children:[e.jsxs(ee,{to:b,className:"block focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand","aria-label":l,children:[e.jsx("div",{className:"relative aspect-[1.91/1] w-full bg-brand",children:d.bannerUrl?e.jsx("img",{src:d.bannerUrl,alt:"",className:"absolute inset-0 h-full w-full object-cover",loading:"lazy"}):e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:d.iconUrl?e.jsx("img",{src:d.iconUrl,alt:"",className:"h-14 w-14 rounded-xl object-cover",loading:"lazy"}):e.jsx(Re,{size:32,className:"text-text-on-brand","aria-hidden":"true"})})}),e.jsxs("div",{className:"flex flex-col gap-2 p-3",children:[e.jsx("p",{className:"text-base font-bold leading-5 tracking-[-0.26px] text-text dark:text-text-dark line-clamp-2",children:u}),i?e.jsxs("p",{className:"flex items-start gap-1 text-[13px] font-normal leading-[18px] tracking-[-0.08px] text-text-secondary dark:text-text-secondary-dark",children:[x&&e.jsx(wt,{as:Jt,width:ts,height:es,className:"mt-0.5 flex-none",role:"img","aria-hidden":!1,"aria-label":he(d)}),e.jsx("span",{className:"line-clamp-3",children:i})]}):null]})]}),e.jsx("div",{className:"px-3 pb-3",children:e.jsx(ee,{to:b,className:ws,"aria-label":l,children:"View Lounge"})})]})}const Cs=6e4;function ve({containerClasses:t}){return e.jsx("div",{className:`mt-1 max-w-full overflow-hidden rounded-xl border animate-pulse ${t}`,role:"status","aria-label":"Loading shared story",children:e.jsx("div",{className:"p-3 h-16"})})}function Ms({storyUlid:t,isOwn:s,expired:m}){const{data:n,isLoading:o}=st(m?null:t,{refetchInterval:g=>{const p=g.state.data?.data;return!p||p.expiresAt&&Date.parse(p.expiresAt)<=Date.now()?!1:Cs}}),c=It(n?.data?.expiresAt),d=!!m||c,[u,x]=r.useState(null),[i,l]=r.useState(!1),k=g=>x(g),b=()=>x(null),h=()=>l(!0),y=V(g=>g.user),R=je(n?.author?{id:n.author.ulid,username:n.author.username}:null,y?.id),j=s?"bg-brand border-white/20 text-white":"bg-surface dark:bg-bg-dark border-border-light/60 dark:border-border-dark/60",w=s?"text-white":"text-text dark:text-text-dark",v=s?"text-white/75":"text-text-secondary dark:text-text-secondary-dark",T=`mt-1 flex w-full max-w-full items-center gap-2 overflow-hidden rounded-xl border p-3 text-left text-xs transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand ${j} ${v}`;let C;if(o)C=e.jsx(ve,{containerClasses:j});else if(d||!n?.data){const g=d?"Story has expired":"Story no longer available";C=e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:h,className:T,"aria-label":`${g} â open details`,children:[e.jsx(Ct,{className:"flex-shrink-0",size:14,"aria-hidden":"true"}),e.jsx("span",{children:g})]}),e.jsx(ss,{open:i,onOpenChange:l})]})}else if(R.isChecking)C=e.jsx(ve,{containerClasses:j});else if(R.isLocked)C=e.jsxs("div",{className:`mt-1 flex max-w-full items-center gap-2 overflow-hidden rounded-xl border p-3 text-xs ${j} ${v}`,children:[e.jsx(Mt,{className:"flex-shrink-0",size:14,"aria-hidden":"true"}),e.jsx("span",{children:"Story from a private account"})]});else{const g=n.data,p=n.author,L=g.thumbnailUrl||(g.mediaType==="image"?g.mediaUrl:null),E={ulid:p.ulid,username:p.username,name:p.name,avatar:p.avatar,verified:!1,badges:[],hasUnviewed:!g.isViewed,storyCount:1,latestStoryAt:g.createdAt,hasCloseFriendsStory:g.audience==="close_friends"},M=()=>k({users:[E],initialUserId:p.ulid,initialStoryId:g.ulid});C=e.jsxs("button",{type:"button",onClick:M,className:`mt-1 max-w-full overflow-hidden rounded-xl border text-left transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand ${j}`,"aria-label":`Story by ${p.name||p.username}`,children:[L&&e.jsx(jt,{src:L,containerClassName:"w-full h-40",imageClassName:"w-full h-full object-cover"}),e.jsxs("div",{className:"p-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[p.avatar?e.jsx("img",{src:p.avatar,alt:"",className:"w-9 h-9 rounded-full object-cover flex-shrink-0",loading:"lazy"}):e.jsx("div",{className:`w-9 h-9 rounded-full flex items-center justify-center text-sm font-semibold flex-shrink-0 ${s?"bg-white/20 text-white":"bg-bg-elevated dark:bg-bg-elevated-dark text-text-secondary dark:text-text-secondary-dark"}`,children:(p.name||p.username||"?")[0]?.toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:`flex items-center gap-1 text-sm ${w}`,children:e.jsx("span",{className:"font-semibold truncate",children:p.name||p.username})}),e.jsx("div",{className:`text-xs ${v}`,children:"Story"})]})]}),g.caption?e.jsx("p",{className:`mt-2 text-sm line-clamp-2 ${w}`,children:g.caption}):null]})]})}return e.jsxs(e.Fragment,{children:[C,u&&e.jsx(Nt,{users:u.users,initialUserId:u.initialUserId,initialStoryId:u.initialStoryId,onClose:b})]})}function Ss(t){const s=new Date(t);return Number.isNaN(s.getTime())?"":s.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}function Rs({message:t,isOwn:s,showAvatar:m,pending:n,onOpenActions:o}){const c=se(),d=!!t.unsentAt,u=Ss(t.createdAt),x=t.sender?.displayName||t.sender?.username||"",i=t.sender?.avatarUrl??null,l=r.useMemo(()=>Ot(t.text??""),[t.text]),k=l.kind==="post"?l.id:null,b=l.kind==="story"?l.
1id:null,h=l.kind==="profile"?l.id:null,y=l.kind==="lounge"?l.id:null,R=l.kind==="lounge"?l.channelId:void 0,j=l.kind==="lounge"?l.channelType:void 0,w=l.kind==="product"?t.text??"":l.commentary,v=k!==null,T=b!==null,C=h!==null,g=y!==null,p=T&&_t(t.createdAt),{detectedUrl:L,urlPreview:E}=at(w,{enabled:!d&&!v&&!T&&!C&&!g}),M=!!L&&!!E,A=Ft(w,L??"",M),N=A.length>0,q=r.useCallback(U=>{U.stopPropagation(),o(t,U.currentTarget)},[t,o]),Z=r.useCallback(U=>c(`/${U}`),[c]),I=r.useCallback(U=>c(`/topic/${encodeURIComponent(U)}`),[c]),$=C||g,O=s&&!$,ae=$?"text-text dark:text-text-dark":s?"bg-brand text-white rounded-2xl rounded-br-sm":"bg-bg-elevated dark:bg-bg-elevated-dark text-text dark:text-text-dark rounded-2xl rounded-bl-sm";return e.jsxs("li",{className:`group flex items-end gap-2 px-3 ${s?"flex-row-reverse":"flex-row"}`,children:[!s&&e.jsx("div",{className:"w-8 flex-shrink-0",children:m?i?e.jsx("img",{src:i,alt:"",className:"w-8 h-8 rounded-full object-cover",loading:"lazy"}):e.jsx("div",{className:"w-8 h-8 rounded-full bg-bg-elevated dark:bg-bg-elevated-dark flex items-center justify-center text-text-secondary dark:text-text-secondary-dark text-xs font-semibold",children:x[0]?.toUpperCase()??"?"}):null}),e.jsxs("div",{className:`flex flex-col max-w-[75%] min-w-0 ${s?"items-end":"items-start"}`,children:[d?e.jsx("div",{className:"px-3 py-2 rounded-2xl border border-border-light/60 dark:border-border-dark/60 text-xs italic text-text-secondary dark:text-text-secondary-dark",children:s?"You unsent a message":x?`${x} unsent a message`:"Message unsent"}):e.jsxs(e.Fragment,{children:[C&&h&&e.jsx("div",{className:`max-w-full min-w-0 ${s?"self-end":"self-start"}`,children:e.jsx(ks,{username:h})}),y&&e.jsx("div",{className:`max-w-full min-w-0 ${s?"self-end":"self-start"}`,children:e.jsx(Ns,{spaceId:y,channelId:R,channelType:j})}),(N||M)&&e.jsxs("div",{className:`${ae} text-sm [overflow-wrap:anywhere] ${$?"":"overflow-hidden"}`,children:[L&&E&&e.jsx("div",{className:N?"p-1.5 pb-0":"p-1.5",children:e.jsx(St,{url:L,preview:E,onBrand:O})}),N&&e.jsx("div",{className:"px-3 py-2 whitespace-pre-wrap",children:e.jsx(Zt,{lineClamp:10,linkClassName:O?`${Xt} text-white/90`:void 0,children:e.jsx(Rt,{tokenClassName:O?"text-white":"text-brand dark:text-brand-dark",linkClassName:O?"text-white":"text-info dark:text-info-dark",onMentionClick:Z,onHashtagClick:I,children:A})})})]}),v&&k&&e.jsx("div",{className:`max-w-full ${s?"self-end":"self-start"}`,children:e.jsx(bs,{postUlid:k,isOwn:s})}),T&&b&&e.jsx("div",{className:`max-w-full ${s?"self-end":"self-start"}`,children:e.jsx(Ms,{storyUlid:b,isOwn:s,expired:p})})]}),e.jsxs("div",{className:`flex items-center gap-1.5 mt-0.5 text-[11px] text-text-secondary dark:text-text-secondary-dark ${s?"flex-row-reverse":""}`,children:[e.jsx("span",{children:u}),n&&e.jsx("span",{"aria-live":"polite",children:"Sendingâ¦"})]})]}),!d&&e.jsx("button",{type:"button",onClick:q,"aria-label":"Message actions",className:"self-center p-1 rounded-full text-text-secondary dark:text-text-secondary-dark hover:bg-border-light/40 dark:hover:bg-border-dark/40 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity flex-shrink-0",children:e.jsx(Tt,{width:16,height:16})})]})}function Ts({message:t,isOwn:s,onDelete:m,onUnsend:n,onReport:o}){const c=[];return n&&s&&!t.unsentAt&&c.push({id:"unsend",label:"Unsend",onPress:()=>n(t.id)}),o&&!s&&!t.unsentAt&&c.push({id:"report",label:"Report",destructive:!0,onPress:o}),c.push({id:"delete",label:"Delete for me",destructive:!0,onPress:()=>m(t.id)}),c}function Ls({open:t,onOpenChange:s,options:m,triggerEl:n}){return e.jsx(Lt,{open:t,onOpenChange:s,options:m,triggerEl:n})}const ke=200;function Qs(){Kt("DMThread");const{conversationId:t=""}=ft(),s=se(),[m]=gt(),n=m.get("tab")==="requests"?"/messages?tab=requests":"/messages",o=V(a=>a.user?.id??null),c=V(a=>a.user?.username??null),d=be(),u=be({folder:"requests"}),x=r.useMemo(()=>{const f=(d.data?.pages.flatMap(P=>P.data)??[]).find(P=>P.id===t);return f||(u.data?.pages.flatMap(P=>P.data)??[]).find(P=>P.id===t)},[d.data,u.data,t]),i=x?.otherUser,l=x?.requestStatus==="pending",k=rt(l?null:i?.id??null),b=Ne(i?.username??null),h=i?.isBanned===!0||b.data?.isBanned===!0;Pt(o,t,{skipUserChannelListener:!0});const y=r.useMemo(()=>o&&c?{id:o,username:c}:null,[o,c]),{isOtherTyping:R,sendTyping:j}=os(t||null,y),w=nt(t),v=r.useMemo(()=>w.data?.pages.flatMap(a=>a.data)??[],[w.data]);ms(t,v);
1const T=lt(),C=it(),g=ot(),p=ye(),L=dt(t||null),E=ct(t||null),[M,A]=r.useState(null),N=r.useCallback(a=>{a||A(null)},[]),q=r.useCallback(()=>{if(!M)return;const a=M;A(null),E.mutate(a,{onError:f=>{f instanceof ut?S.error(f.userMessage):S.error("Couldn't unsend. Try again.")}})},[M,E]),Z=r.useRef(null),I=r.useMemo(()=>{const a=v[0];return!a||a.sender?.id===o?null:a.id},[v,o]);r.useEffect(()=>{!t||!I||Z.current!==I&&(Z.current=I,C.mutate(t))},[t,I,C]);const[$,O]=r.useState(null),[ae,U]=r.useState(null),[Pe,re]=r.useState(!1),[_,oe]=r.useState(null),de=xt(),[X,ce]=r.useState(new Set);r.useEffect(()=>{let a=!1;return Et().then(f=>{a||f.size>0&&ce(B=>B.size===0?f:new Set([...B,...f]))}),()=>{a=!0}},[]);const Ee=r.useCallback((a,f)=>{O(a),U(f),re(!0)},[]),z=r.useCallback(()=>{re(!1)},[]),$e=r.useCallback(async a=>{if(!_)throw new Error("Cannot report without a target message");await de.mutateAsync({messageUlid:_.id,violationType:a});const f=$t(X,_.id);ce(f),await Dt(f)},[_,de,X]),ue=r.useCallback(()=>{$&&(oe($),z())},[$,z]),De=r.useMemo(()=>{if(!$)return[];const a=$.sender?.id===o;return Ts({message:$,isOwn:a,onDelete:f=>{L.mutate(f),z()},onUnsend:f=>{z(),A(f)},onReport:a?void 0:ue})},[$,o,L,z,ue]),[ne,xe]=r.useState(""),F=l?"Accept this message request to reply.":Ht(h,k.data&&!k.data.allowed?k.data.reason??Vt:null),me=Yt("dm_permission","following"),Ae=typeof me=="string"?me:"following",Be=i?.displayName||i?.username||"This user",Ue=!F&&!l&&b.data?zt(Ae,b.data.isFollowingYou??!1,Be):null,qe=r.useCallback(()=>{t&&g.mutate({conversationUlid:t,partnerUlid:i?.id},{onSuccess:()=>{S.success("Message request accepted"),s(`/messages/${t}`,{replace:!0})},onError:a=>{if(a instanceof mt&&a.alreadyAccepted){s(`/messages/${t}`,{replace:!0});return}S.error("Couldn't accept the request. Try again.")}})},[t,i?.id,g,s]),Ie=r.useCallback(()=>{t&&p.mutate(t,{onSuccess:()=>{s("/messages?tab=requests",{replace:!0})},onError:a=>{if(a instanceof we&&a.alreadyHandled){s("/messages?tab=requests",{replace:!0});return}S.error("Couldn't delete the request. Try again.")}})},[t,p,s]),{onBlockRequest:Oe,isBlockPending:_e,isLeavePending:Fe,overlays:He}=fs({conversationId:t,otherUser:i,enabled:l}),Ve=r.useCallback(a=>
1{if(a.key==="Enter"&&!a.shiftKey){if(a.preventDefault(),F)return;a.currentTarget.form?.requestSubmit()}},[F]),ze=r.useCallback(a=>{a.preventDefault();const f=ne.trim();!f||!t||F||Qt(f)||(xe(""),T.mutate({text:f,conversation_ulid:t}))},[ne,t,F,T]),fe=r.useMemo(()=>v.filter(a=>!X.has(a.id)),[v,X]),Qe=r.useMemo(()=>[...fe].reverse(),[fe]),Q=r.useRef(null),J=r.useRef(0),le=r.useRef({id:null,senderId:null}),W=r.useRef(!1),D=r.useRef(null),G=r.useRef(!1),ge=v.length>0;return r.useLayoutEffect(()=>{J.current=0,le.current={id:null,senderId:null},W.current=!1,G.current=!1,D.current&&clearTimeout(D.current),Q.current&&(Q.current.scrollTop=0),A(null)},[t]),r.useEffect(()=>{const a=f=>{f.persisted!==!1&&document.visibilityState!=="hidden"&&(W.current=!0,D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{W.current=!1,D.current=null},8e3))};return document.addEventListener("visibilitychange",a),window.addEventListener("focus",a),window.addEventListener("pageshow",a),()=>{document.removeEventListener("visibilitychange",a),window.removeEventListener("focus",a),window.removeEventListener("pageshow",a),D.current&&clearTimeout(D.current)}},[]),r.useLayoutEffect(()=>{const a=Q.current;if(!a||!t||!ge)return;G.current=!0;const f=()=>{G.current&&(typeof a.scrollTo=="function"?a.scrollTo({top:a.scrollHeight,behavior:"auto"}):a.scrollTop=a.scrollHeight)};f();const B=[150,500,1500].map(Y=>setTimeout(f,Y)),P=a.firstElementChild??a,H=typeof ResizeObserver<"u"?new ResizeObserver(f):null;H?.observe(P);const K=()=>{a.scrollHeight-a.scrollTop-a.clientHeight>ke&&(G.current=!1,H?.disconnect())};a.addEventListener("scroll",K,{passive:!0});const ie=setTimeout(()=>{G.current=!1,H?.disconnect()},3e3);return()=>{B.forEach(clearTimeout),clearTimeout(ie),a.removeEventListener("scroll",K),H?.disconnect()}},[t,ge]),r.useEffect(()=>{const a=Q.current;if(!a||v.length===0)return;const f=v[0]??null,B=f?.id??null,P=f?.sender?.id??null,H=B!==null&&B!==le.current.id&&P===o,K=J.current===0,ie=v.length>J.current,Y=W.current&&ie,We=a.scrollHeight-a.scrollTop-a.clientHeight<ke;(H||K||We||Y)&&(requestAnimationFrame(()=>{typeof a.scrollTo=="function"?a.scrollTo({top:a.scrollHeight,behavior:K?"auto":"smooth"}):a.scrollTop=a.scrollHeight}),Y&&(W.current=!1,D.current&&(clearTimeout(D.current),D.current=null))),J.current=v.length,le.current={id:B,senderId:P}},[v,o]),e.jsxs("div",{className:"flex flex-col h-[calc(100dvh-3.5rem)] md:h-dvh min-h-0 overflow-hidden",children:[e.jsx(as,{otherUser:i?{...i,isBanned:h}:null,backTo:n}),e.jsx(Es,{scrollContainerRef:Q,isLoading:w.isLoading,isError:w.isError,messages:v,orderedMessages:Qe,currentUserId:o,hasOlderMessages:!!w.hasNextPage,isLoadingOlder:w.isFetchingNextPage,onLoadOlder:()=>w.fetchNextPage(),onOpenActions:Ee}),R&&i&&!l&&e.jsxs("div",{"aria-live":"polite",className:"px-4 py-1 text-xs italic text-text-secondary dark:text-text-secondary-dark border-t border-border-light/60 dark:border-border-dark/60",children:[i.displayName||i.username," is typingâ¦"]}),!l&&e.jsx(rs,{warning:Ue}),l?e.jsx(Ps,{otherUserDisplayName:i?.displayName||i?.username||"this user",otherUserUsername:i?.username,onAccept:qe,onDecline:Ie,onBlock:Oe,isAcceptPending:g.isPending,isDeclinePending:p.isPending,isBlockPending:_e,isLeavePending:Fe}):e.jsx(ns,{input:ne,onInputChange:xe,onInputKeyDown:Ve,onSubmit:ze,onTyping:j,isPending:T.isPending,disabledReason:F}),e.jsx(Ls,{open:Pe,onOpenChange:re,options:De,triggerEl:ae}),e.jsx(Me,{open:!!_,onClose:()=>oe(null),targetId:_?.id??"",targetType:"post",subjectLabel:"message",submitOverride:$e}),e.jsx(Ce,{open:M!==null,onOpenChange:N,title:"Delete this message for everyone?",description:"They won't be able to see it anymore.",confirmLabel:"Delete for everyone",onConfirm:q,isPending:E.isPending}),He]})}function Ps({otherUserDisplayName:t,otherUserUsername:s,onAccept:m,onDecline:n,onBlock:o,isAcceptPending:c,isDeclinePending:d,isBlockPending:u,isLeavePending:x}){const i=c||d||u||x,l=s&&s!==t?`Message request from ${t} (@${s})`:`Message request from ${t}`;return e.jsxs("div",{className:"px-4 py-3 border-t border-border-light/60 dark:border-border-dark/60 bg-bg-elevated dark:bg-bg-elevated-dark",children:[e.jsx("p",{className:"text-sm font-semibold text-text dark:text-text-dark text-center mb-1",children:l}),e.jsx("p",{className:"text-xs text-text-secondary dark:text-text-secondary-dark text-center mb-3",children:"If you accept, they will be able to see info such as your activity status and when you've read messages."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:o,disabled:i,className:"flex-1 py-2.5 text-sm font-semibold rounded-lg border border-border-light dark:border-border-dark text-error hover:bg-bg-elevated dark:hover:bg-bg-elevated-dark disabled:opacity-50",children:u?"Blockingâ¦":"Block"}),e.jsx("button",{type:"button",onClick:n,disabled:i,className:"flex-1 py-2.5 text-sm font-semibold rounded-lg border border-border-light dark:border-border-dark text-error hover:bg-bg-elevated dark:hover:bg-bg-elevated-dark disabled:opacity-50",children:d?"Deletingâ¦":"Delete"}),e.jsx("button",{type:"button",onClick:m,disabled:i,className:"flex-1 py-2.5 text-sm font-semibold rounded-lg bg-text text-bg dark:bg-text-dark dark:text-bg-dark hover:opacity-90 disabled:opacity-50",children:c?"Acceptingâ¦":"Accept"})]})]})}
1function Es({scrollContainerRef:t,isLoading:s,isError:m,messages:n,orderedMessages:o,currentUserId:c,hasOlderMessages:d,isLoadingOlder:u,onLoadOlder:x,onOpenActions:i}){return e.jsx("div",{ref:t,className:"flex-1 min-h-0 overflow-y-auto customScroll","aria-live":"polite","aria-relevant":"additions",children:s&&n.length===0?e.jsx(cs,{}):m?e.jsx("div",{className:"p-8 text-center text-text-secondary dark:text-text-secondary-dark",children:e.jsx("p",{children:"Couldn't load this conversation. Try refreshing."})}):n.length===0?e.jsx("div",{className:"p-8 text-center text-text-secondary dark:text-text-secondary-dark",children:e.jsx("p",{children:"No messages yet â say hi."})}):e.jsxs("ul",{className:"flex flex-col gap-0.5 py-3",children:[d&&e.jsx("li",{className:"flex justify-center px-4 py-3",children:e.jsx("button",{type:"button",onClick:x,disabled:u,className:"text-sm font-semibold text-brand hover:opacity-80 disabled:opacity-50 disabled:cursor-not-allowed",children:u?"Loading older messagesâ¦":"Load older messages"})}),o.map((l,k)=>{const b=o[k-1]??null,h=l.sender?.id===c,y=!b||b.sender?.id!==l.sender?.id,R=Wt(b?.createdAt,l.createdAt);return e.jsxs("div",{children:[R&&e.jsx("div",{className:"text-center text-[11px] uppercase tracking-wide text-text-secondary dark:text-text-secondary-dark py-2",children:Gt(l.createdAt)}),e.jsx(Rs,{message:l,isOwn:h,showAvatar:y,onOpenActions:i})]},l.id)})]})})}export{Qs as default};
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.