1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[900],{50900:(e,r,t)=>{t.r(r),t.d(r,{MessagesPage:()=>k});var s=t(95155),n=t(12115),l=t(82222),i=t(41841),a=t(73139),o=t(86478),d=t(94992),c=t(54138),p=t(4479),x=t(65851),u=t(49173),h=t(3206),f=t(94784),m=t(57128),g=t(86438),b=t(37586),v=t(91057),y=t(85626),j=t(18031),I=t(82034),w=t(6438),M=t(58411),$=t(26324);let k=({config:e})=>{let r=w.MB.colors,t=(0,l.useRouter)(),k=n.useContext(I.A),S=!!k?.user?.firstName,B=k?.person?.id,C=(0,y.jE)();n.useEffect(()=>{if(!S)return;let e="MessagesPage-list",r=()=>C.invalidateQueries({queryKey:["conversations",B]});return g.i.addHandler("privateMessage",e+"-pm",r),g.i.addHandler("privateRoomAdded",e+"-room",r),()=>{g.i.removeHandler(e+"-pm"),g.i.removeHandler(e+"-room")}},[S,B,C]);let{data:A=null,isError:P,refetch:R}=(0,j.I)({queryKey:["conversations",B],queryFn:async()=>{let e=await b.tH.get("/privateMessages","MessagingApi");if(!Array.isArray(e)||0===e.length)return[];let r=e.map(e=>{let r=B&&e.fromPersonId===B?e.toPersonId:e.fromPersonId;return{pm:e,otherId:r}}),t=Array.from(new Set(r.map(e=>e.otherId).filter(Boolean))),s={};if(t.length>0){let e=await b.tH.get(`/people/basic?ids=${t.join(",")}`,"MembershipApi");Array.isArray(e)&&(s=e.reduce((e,r)=>(r.id&&(e[r.id]=r),e),{}))}let n=new Set,l=[];return r.forEach(({pm:e,otherId:r})=>{let t=e.pmId||e.privateMessageId||e.privateMessage?.id||e.id,i=e.conversationId||e.conversation?.id||(e.pmId?e.id:void 0),a=i||t;if(!a||!r||n.has(a))return;n.add(a);let o=s[r],d=o?.name?.display||"Unknown",c="";if(o)try{c=b.gN.getPhotoUrl(o)||""}catch{c=o.photo||""}l.push({id:a,pmId:t,personId:r,conversationId:i,personName:d,personPhoto:c,preview:(e.conversation?.messages?.[0]?.content||"").replace(/<[^>]+>/g,""),lastTime:e.lastMessageTime||e.conversation?.dateCreated,unread:!!B&&e.notifyPersonId===B})}),l},enabled:S,staleTime:0}),[z,N]=n.useState(null),H=async()=>{if(N(null),z?.pmId){C.setQueryData(["conversations",B],e=>(e||[]).filter(e=>e.pmId!==z.pmId));try{await b.tH.delete(`/privateMessages/${z.pmId}`,"MessagingApi")}catch(e){console.error("Failed to delete conversation",e),C.invalidateQueries({queryKey:["conversations",B]})}}},_=e=>{let r=`/mobile/messages/${e.personId}`;t.push(e.conversationId?`${r}?conversationId=${encodeURIComponent(e.conversationId)}`:r)};return(0,s.jsxs)(i.default,{sx:{p:`${w.MB.spacing.md}px`,bgcolor:r.background,minHeight:"100%"},children:[(0,s.jsx)(i.default,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-end",mb:`${w.MB.spacing.md}px`},children:(0,s.jsx)(o.default,{"aria-label":v.h.label("mobile.screens.newMessage"),onClick:()=>t.push("/mobile/messages/new"),sx:{bgcolor:r.iconBackground,color:r.primary,"&:hover":{bgcolor:r.iconBackground}},children:(0,s.jsx)(d.default,{children:"edit"})})}),(0,s.jsxs)(i.default,{sx:{display:"flex",flexDirection:"column",gap:`${w.MB.spacing.sm}px`},children:[null===A&&P&&(0,s.jsx)($.P,{onRetry:()=>R()}),null===A&&!P&&[0,1,2].map(e=>(0,s.jsxs)(i.default,{sx:{display:"flex",alignItems:"center",gap:`${w.MB.spacing.md}px`,bgcolor:r.surface,border:`1px solid ${r.border}`,borderRadius:`${w.MB.radius.lg}px`,px:`${w.MB.spacing.md}px`,py:"12px"},children:[(0,s.jsx)(c.A,{variant:"circular",width:44,height:44}),(0,s.jsx)(i.default,{sx:{flex:1},children:(0,s.jsx)(c.A,{variant:"text",width:"50%",height:18})})]},`skeleton-${e}`)),null!==A&&0===A.length&&(0,s.jsxs)(i.default,{sx:{bgcolor:r.surface,border:`1px solid ${r.border}`,borderRadius:`${w.MB.radius.xl}px`,p:`${w.MB.spacing.lg}px`,textAlign:"center"},children:[(0,s.jsx)(i.default,{sx:{width:64,height:64,borderRadius:"19px",bgcolor:r.iconBackground,display:"inline-flex",alignItems:"center",justifyContent:"center",mb:`${w.MB.spacing.md}px`},children:(0,s.jsx)(d.default,{sx:{fontSize:32,color:r.primary},children:"chat_bubble_outline"})}),(0,s.jsx)(a.default,{sx:{fontSize:18,fontWeight:600,color:r.text,mb:`${w.MB.spacing.xs}px`},children:"No messages yet"}),(0,s.jsx)(a.default,{sx:{fontSize:14,color:r.textMuted},children:"Start a conversation with someone in your church."})]}),null!==A&&A.length>0&&A.map(e=>{let t;return(0,s.jsxs)(i.default,{"data-testid":`conversation-row-${e.pmId}`,onClick:()=>_(e),role:"button",tabIndex:0,onKeyDown:r=>{("Enter"===r.key||" "===r.key)&&(r.preventDefault(),_(e))},sx:{display:"flex",alignItems:"center",gap:`${w.MB.spacing.md}px`,bgcolor:r.surface,border:`1px solid ${r.border}`,borderRadius:`${w.MB.radius.lg}px`,px:`${w.MB.spacing.md}px`,py:"12px",cursor:"pointer",transition:"transform 150ms ease","&:active":{transform:"scale(0.995)"}},children:[(t={width:44,height:44,borderRadius:"22px",flexShrink:0,overflow:"hidden"},e.personPhoto?(0,s.jsx)(i.default,{component:"img",src:e.personPhoto,alt:e.personName,sx:{...t,objectFit:"cover"}}):(0,s.jsx)(i.default,{sx:{...t,bgcolor:r.primaryLight,color:r.primary,display:"flex",alignItems:"center",justifyContent:"center",fontWeight:700,fontSize:14},children:(0,M.IM)(e.personName)})),(0,s.jsxs)(i.default,{sx:{flex:1,minWidth:0},children:[(0,s.jsxs)(i.default,{sx:{display:"flex",alignItems:"baseline",gap:"8px"},children:[(0,s.jsx)(a.default,{sx:{flex:1,minWidth:0,fontSize:16,fontWeight:e.unread?700:600,color:r.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.personName}),(0,s.jsx)(a.default,{sx:{fontSize:12,color:r.textSecondary,flexShrink:0},children:(0,M.om)(e.lastTime)})]}),(0,s.jsx)(a.default,{sx:{fontSize:13,color:r.textSecondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.preview})]}),(0,s.jsx)(o.default,{"aria-label":v.h.label("mobile.screens.deleteConversation"),"data-testid":`conversation-delete-${e.pmId}`,size:"small",onClick:r=>{r.stopPropagation(),N(e)},sx:{color:r.disabled,flexShrink:0},children:(0,s.jsx)(d.default,{sx:{fontSize:20},children:"delete_outline"})}),e.unread&&(0,s.jsx)(i.default,{"aria-label":v.h.label("mobile.screens.unread"),"data-testid":`conversation-unread-${e.pmId}`,sx:{width:8,height:8,borderRadius:"4px",bgcolor:r.primary,flexShrink:0}}),(0,s.jsx)(d.default,{sx:{color:r.textSecondary,flexShrink:0},children:"chevron_right"})]},e.id)})]}),(0,s.jsxs)(p.default,{open:!!z,onClose:()=>N(null),children:[(0,s.jsx)(x.default,{children:v.h.label("mobile.screens.deleteConversationTitle")}),(0,s.jsx)(u.default,{children:(0,s.jsx)(h.A,{children:v.h.label("mobile.screens.deleteConversationBody")})}),(0,s.jsxs)(f.default,{children:[(0,s.jsx)(m.default,{onClick:()=>N(null),children:v.h.label("common.cancel")}),(0,s.jsx)(m.default,{color:"error",onClick:H,"data-testid":"confirm-delete-conversation",children:v.h.label("mobile.details.delete")})]})]})]})}}}]);
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.