UNPKG

softchatjs-core

Version:
2 lines 4.67 kB
"use strict";var l=Object.create;var B=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var x=(t,i)=>{for(var e in i)B(t,e,{get:i[e],enumerable:!0})},E=(t,i,e,n)=>{if(i&&typeof i=="object"||typeof i=="function")for(let r of C(i))!A.call(t,r)&&r!==e&&B(t,r,{get:()=>i[r],enumerable:!(n=M(i,r))||n.enumerable});return t};var y=(t,i,e)=>(e=t!=null?l(f(t)):{},E(i||!t||!t.__esModule?B(e,"default",{value:t,enumerable:!0}):e,t)),T=t=>E(B({},"__esModule",{value:!0}),t);var k={};x(k,{formatConversationTime:()=>v,formatMessageTime:()=>U,generateConversationId:()=>S,generateFillerTimestamps:()=>L,generateId:()=>_,getConversationTitle:()=>b,getQuotedMessage:()=>G,getUnreadMessageIds:()=>O,getUserInfoWithId:()=>h,getUsernameInitials:()=>R,truncate:()=>N});module.exports=T(k);var u=y(require("moment"));function D(t,i=0){let e=BigInt(i),n=BigInt(i),r=BigInt("0x87c37b91114253d5"),d=BigInt("0x4cf5ad432745937f"),p=t.length,m=p&15,a=p-m;for(let o=0;o<a;o+=16){let c=BigInt(t.charCodeAt(o))|BigInt(t.charCodeAt(o+1))<<BigInt(8)|BigInt(t.charCodeAt(o+2))<<BigInt(16)|BigInt(t.charCodeAt(o+3))<<BigInt(24)|BigInt(t.charCodeAt(o+4))<<BigInt(32)|BigInt(t.charCodeAt(o+5))<<BigInt(40)|BigInt(t.charCodeAt(o+6))<<BigInt(48)|BigInt(t.charCodeAt(o+7))<<BigInt(56),I=BigInt(t.charCodeAt(o+8))|BigInt(t.charCodeAt(o+9))<<BigInt(8)|BigInt(t.charCodeAt(o+10))<<BigInt(16)|BigInt(t.charCodeAt(o+11))<<BigInt(24)|BigInt(t.charCodeAt(o+12))<<BigInt(32)|BigInt(t.charCodeAt(o+13))<<BigInt(40)|BigInt(t.charCodeAt(o+14))<<BigInt(48)|BigInt(t.charCodeAt(o+15))<<BigInt(56);c=c*r,c=c<<BigInt(31)|c>>BigInt(33),c=c*d,e^=c,e=e<<BigInt(27)|e>>BigInt(37),e=e+n,e=e*BigInt(5)+BigInt("0x52dce729"),I=I*d,I=I<<BigInt(33)|I>>BigInt(31),I=I*r,n^=I,n=n<<BigInt(31)|n>>BigInt(33),n=e+n,n=n*BigInt(5)+BigInt("0x38495ab5")}let s=BigInt(0),g=BigInt(0);switch(m){case 15:g^=BigInt(t.charCodeAt(a+14))<<BigInt(48);case 14:g^=BigInt(t.charCodeAt(a+13))<<BigInt(40);case 13:g^=BigInt(t.charCodeAt(a+12))<<BigInt(32);case 12:g^=BigInt(t.charCodeAt(a+11))<<BigInt(24);case 11:g^=BigInt(t.charCodeAt(a+10))<<BigInt(16);case 10:g^=BigInt(t.charCodeAt(a+9))<<BigInt(8);case 9:g^=BigInt(t.charCodeAt(a+8)),g=g*d,g=g<<BigInt(33)|g>>BigInt(31),g=g*r,n^=g;case 8:s^=BigInt(t.charCodeAt(a+7))<<BigInt(56);case 7:s^=BigInt(t.charCodeAt(a+6))<<BigInt(48);case 6:s^=BigInt(t.charCodeAt(a+5))<<BigInt(40);case 5:s^=BigInt(t.charCodeAt(a+4))<<BigInt(32);case 4:s^=BigInt(t.charCodeAt(a+3))<<BigInt(24);case 3:s^=BigInt(t.charCodeAt(a+2))<<BigInt(16);case 2:s^=BigInt(t.charCodeAt(a+1))<<BigInt(8);case 1:s^=BigInt(t.charCodeAt(a)),s=s*r,s=s<<BigInt(31)|s>>BigInt(33),s=s*d,e^=s}return e^=BigInt(p),n^=BigInt(p),e+=n,n+=e,e^=e>>BigInt(33),e=e*BigInt("0xff51afd7ed558ccd"),e^=e>>BigInt(33),e=e*BigInt("0xc4ceb9fe1a85ec53"),e^=e>>BigInt(33),n^=n>>BigInt(33),n=n*BigInt("0xff51afd7ed558ccd"),n^=n>>BigInt(33),n=n*BigInt("0xc4ceb9fe1a85ec53"),n^=n>>BigInt(33),e+=n,n+=e,(e&BigInt("0xFFFFFFFFFFFFFFFF")).toString(16)}function S(t,i,e){let r=[t,i].sort().join("_");return D(`${e}:${r}`)}var _=()=>{let t="",i="abcdef0123456789";for(let e=0;e<32;e++){let n=Math.floor(Math.random()*i.length),r=i.charAt(n);(e===8||e===12||e===16||e===20)&&(t+="-"),t+=r}return t},h=(t,i)=>{let e=i.find(r=>r.participantId===t),n=i.filter(r=>r.participantId!==t);return{presentUser:e?.participantDetails,receivingUser:n[0]?.participantDetails}},N=(t,i)=>t.length>i?t.substring(0,i)+"...":t,b=(t,i)=>{if(i.conversationType==="private-chat"){let e=h(t,i.participantList),n=e.receivingUser?.firstname,r=e.receivingUser?.username;return n||r}if(i.conversationType==="group-chat")return i.groupMeta?.groupName||"no-groupname"},R=t=>t.substring(0,1);function U(t){return(0,u.default)(new Date(t)).format("hh:mm a")}function v(t){let i=(0,u.default)(),e=(0,u.default)(t),n=u.default.duration(i.diff(e)),r=Math.floor(n.asYears());if(r>0)return r+"yr";let d=Math.floor(n.asMonths());if(d>0)return d+"mo";let p=Math.floor(n.asWeeks());if(p>0)return p+"w";let m=Math.floor(n.asDays());if(m>0)return m+"d";let a=Math.floor(n.asHours());if(a>0)return a+"h";let s=Math.floor(n.asMinutes());return s>0?s+"m":"Just now"}var L=()=>({createdAt:new Date,updatedAt:new Date}),O=(t,i)=>{var e=[];return t.messages.map(n=>{n.messageState===3&&n.from!==i&&e.push(n.messageId)}),e},G=(t,i)=>i.find(n=>n.messageId===t);0&&(module.exports={formatConversationTime,formatMessageTime,generateConversationId,generateFillerTimestamps,generateId,getConversationTitle,getQuotedMessage,getUnreadMessageIds,getUserInfoWithId,getUsernameInitials,truncate}); //# sourceMappingURL=utils.js.map