import{Q as f,l as g,k as M,P as v,I as c}from"./index-ae60edf9.js";import{d as D}from"./open-im-sdk-wasm-f19f04ec.js";const u=f(),t=g(),C=M();function p(){const I=async({recvID:e,groupID:r,message:s,needOpreateMessage:n})=>{var i;n=n??S(e||r),n&&(u.pushNewMessage(s),v.emit("CHAT_MAIN_SCROLL_TO_BOTTOM",!1),l());const a={recvID:e??t.storeCurrentConversation.userID??"",groupID:r??t.storeCurrentConversation.groupID??"",message:s};try{const{data:o}=await c.sendMessage(a);u.updateOneMessage(o,!0)}catch(o){console.error(o),u.updateOneMessage({...s,errCode:o.errCode,status:D.Failed}),c.setMessageLocalEx({conversationID:((i=t.storeCurrentConversation)==null?void 0:i.conversationID)??"",clientMsgID:s.clientMsgID,localEx:String(o.errCode)})}},l=()=>{if(!t.storeCurrentConversation.userID)return;let e=[],r={};const s={userID:t.storeCurrentConversation.userID,nickname:t.storeCurrentConversation.showName,faceURL:t.storeCurrentConversation.faceURL};try{r=JSON.parse(localStorage.getItem("IMFrequentContacts_H5")||"{}"),e=r[C.storeSelfInfo.userID]??[]}catch{}e.find(a=>a.userID===s.userID)||(e.unshift({...s}),r[C.storeSelfInfo.userID]=e,localStorage.setItem("IMFrequentContacts_H5",JSON.stringify(r)))},S=e=>e?t.storeCurrentConversation.userID===e||t.storeCurrentConversation.groupID===e:!0;return{sendMessage:I}}export{p as u};
