!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.websdk=t():e.websdk=t()}(this,(function(){return(this.webpackChunkwebsdk=this.webpackChunkwebsdk||[]).push([[653],{3246:function(e,t,n){n.d(t,{H7:function(){return u},XZ:function(){return i},_W:function(){return c}}),n(7941),n(9554),n(1539),n(4747),n(6699),n(2023);var r=n(5531),o=n(7252);function s(){var e=this.context.appName,t=this.context.orgName;return!(!e||!t)||(this.onError&&this.onError({type:r.E.WEBIM_CONNCTION_AUTH_ERROR,message:"appName or orgName is illegal"}),!1)}function a(){var e;if(!this.context.accessToken){var t=o.Z.create({type:r.E.WEBIM_CONNCTION_TOKEN_NOT_ASSIGN_ERROR,message:"token not assign error"});return this.onError&&this.onError(t),null===(e=this.eventHandler)||void 0===e||e.dispatch("onError",t),!1}return!0}function i(){return a.call(this)&&s.call(this)}function c(e){var t=e.data,n=e.type;return{data:{status:Object.keys(t.errorKeys).length>0?"fail":"success",errorKeys:t.errorKeys,successKeys:t.successKeys},type:n}}function u(e){var t=e.data,n=void 0;return Object.keys(t.errorKeys).length>0&&Object.keys(t.errorKeys).forEach((function(e){var s=t.errorKeys[e];n=s.includes("is not part of you")?o.Z.create({type:r.E.NO_PERMISSION,message:s}):s.includes("size of metadata for this single chatroom exceeds the user defined limit")||s.includes("total size of chatroom metadata for this app exceeds the user defined limit")||s.includes("is exceeding maximum limit")?o.Z.create({type:r.E.MAX_LIMIT,message:s}):s.includes("is not Legal")?o.Z.create({type:r.E.REQUEST_PARAMETER_ERROR,message:s}):s.includes("Failed to update userMetadata. Concurrent updates not allowed")?o.Z.create({type:r.E.OPERATION_NOT_ALLOWED,message:s}):o.Z.create({type:r.E.WEBIM_CONNCTION_AJAX_ERROR,message:s})})),n}},6007:function(e,t,n){n.r(t),n.d(t,{LocalCache:function(){return _},LocalCacheApi:function(){return r}});var r={};n.r(r),n.d(r,{clearConversationUnreadCount:function(){return K},getLocalConversation:function(){return F},getLocalConversations:function(){return P},removeLocalConversation:function(){return Z},setLocalConversationCustomField:function(){return j}}),n(1539),n(8674),n(2526),n(1817),n(2165),n(6992),n(8783),n(3948),n(1249),n(6699),n(3710),n(9601);const o=(e,t)=>t.some((t=>e instanceof t));let s,a;const i=new WeakMap,c=new WeakMap,u=new WeakMap,l=new WeakMap,d=new WeakMap;let v={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return c.get(e);if("objectStoreNames"===t)return e.objectStoreNames||u.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return h(e[t])},set(e,t,n){return e[t]=n,!0},has(e,t){return e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e}};function p(e){return"function"==typeof e?(t=e)!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(a||(a=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(t)?function(...e){return t.apply(f(this),e),h(i.get(this))}:function(...e){return h(t.apply(f(this),e))}:function(e,...n){const r=t.call(f(this),e,...n);return u.set(r,e.sort?e.sort():[e]),h(r)}:(e instanceof IDBTransaction&&function(e){if(c.has(e))return;const t=new Promise(((t,n)=>{const r=()=>{e.removeEventListener("complete",o),e.removeEventListener("error",s),e.removeEventListener("abort",s)},o=()=>{t(),r()},s=()=>{n(e.error||new DOMException("AbortError","AbortError")),r()};e.addEventListener("complete",o),e.addEventListener("error",s),e.addEventListener("abort",s)}));c.set(e,t)}(e),o(e,s||(s=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,v):e);var t}function h(e){if(e instanceof IDBRequest)return function(e){const t=new Promise(((t,n)=>{const r=()=>{e.removeEventListener("success",o),e.removeEventListener("error",s)},o=()=>{t(h(e.result)),r()},s=()=>{n(e.error),r()};e.addEventListener("success",o),e.addEventListener("error",s)}));return t.then((t=>{t instanceof IDBCursor&&i.set(t,e)})).catch((()=>{})),d.set(t,e),t}(e);if(l.has(e))return l.get(e);const t=p(e);return t!==e&&(l.set(e,t),d.set(t,e)),t}const f=e=>d.get(e);function y(e,t,{blocked:n,upgrade:r,blocking:o,terminated:s}={}){const a=indexedDB.open(e,t),i=h(a);return r&&a.addEventListener("upgradeneeded",(e=>{r(h(a.result),e.oldVersion,e.newVersion,h(a.transaction),e)})),n&&a.addEventListener("blocked",(e=>n(e.oldVersion,e.newVersion,e))),i.then((e=>{s&&e.addEventListener("close",(()=>s())),o&&e.addEventListener("versionchange",(e=>o(e.oldVersion,e.newVersion,e)))})).catch((()=>{})),i}const g=["get","getKey","getAll","getAllKeys","count"],m=["put","add","delete","clear"],b=new Map;function I(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(b.get(t))return b.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,o=m.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!o&&!g.includes(n))return;const s=async function(e,...t){const s=this.transaction(e,o?"readwrite":"readonly");let a=s.store;return r&&(a=a.index(t.shift())),(await Promise.all([a[n](...t),o&&s.done]))[0]};return b.set(t,s),s}var C;C=v,v={...C,get:(e,t,n)=>I(e,t)||C.get(e,t,n),has:(e,t)=>!!I(e,t)||C.has(e,t)};var E=n(7360),T=n(9743),w=n(7288),M=function(){return M=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]w.r.INPROGRESS&&Object.assign(o,{updateTime:r.time,lastMessageId:r.id}),s&&(i=!0,Object.assign(o,{lastMessageFromOtherId:r.id})),[4,this.storeConversation(a,r.chatType,o,!n&&i)];case 4:return l.sent(),[3,6];case 5:return u=l.sent(),E.kg.debug("store message error",u),[3,6];case 6:return[2]}}))}))},e.prototype.updateLocalMessage=function(e,t){return void 0===t&&(t={}),S(this,void 0,void 0,(function(){var n,r;return L(this,(function(o){switch(o.label){case 0:return o.trys.push([0,5,,6]),[4,this.getMessageByServerMsgId(e)];case 1:return(n=o.sent())?[4,this.putMessageToDB(M(M({},n),t))]:[3,4];case 2:return o.sent(),[4,this.updateLocalConversation((0,T.MQ)({conversationId:n.to,conversationType:n.chatType}),{lastMessageId:t.serverMsgId,updateTime:n.time})];case 3:o.sent(),o.label=4;case 4:return[3,6];case 5:return r=o.sent(),E.kg.debug("update local message error",r),[3,6];case 6:return[2]}}))}))},e.prototype.updateLocalConversation=function(e,t){return S(this,void 0,void 0,(function(){var n=this;return L(this,(function(r){try{return[2,this.getConversationBySessionId(e).then((function(r){if(r){var o=M(M({},r),t);n.putConversationToDB(o),n.conversationMap[e]=o}}))]}catch(e){E.kg.debug("update local conversation error",e)}return[2]}))}))},e.prototype.removeMsgByServerMsgId=function(e){var t,n;return S(this,void 0,void 0,(function(){var r,o;return L(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,null===(t=this.localCache)||void 0===t?void 0:t.getFromIndex("message","serverMsgId",e)];case 1:return r=s.sent(),[2,null===(n=this.localCache)||void 0===n?void 0:n.delete("message",(null==r?void 0:r.id)||"")];case 2:return o=s.sent(),E.kg.debug("remove msg by serverId error",o),[3,3];case 3:return[2]}}))}))},e.prototype.removeMsgBySessionId=function(e){var t;return S(this,void 0,void 0,(function(){var n,r;return L(this,(function(o){switch(o.label){case 0:return o.trys.push([0,6,,7]),[4,null===(t=this.localCache)||void 0===t?void 0:t.transaction("message","readwrite").store.index("sessionId").openCursor(IDBKeyRange.only(e))];case 1:n=o.sent(),o.label=2;case 2:return n?[4,n.delete()]:[3,5];case 3:return o.sent(),[4,n.continue()];case 4:return n=o.sent(),[3,2];case 5:return[3,7];case 6:return r=o.sent(),E.kg.debug("remove msg by sessionId",r),[3,7];case 7:return[2]}}))}))},e.prototype.putMessageToDB=function(e){var t;return S(this,void 0,void 0,(function(){var n;return L(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,null===(t=this.localCache)||void 0===t?void 0:t.put("message",e)];case 1:return[2,r.sent()];case 2:return n=r.sent(),E.kg.debug("put msg to local error",n),[3,3];case 3:return[2]}}))}))},e.prototype.getConversationLastMessage=function(e,t){var n,r;return S(this,void 0,void 0,(function(){var o,s,a;return L(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),o=(0,T.MQ)({conversationId:e,conversationType:t}),[4,null===(r=null===(n=this.localCache)||void 0===n?void 0:n.transaction("message").store)||void 0===r?void 0:r.index("sessionTime").openCursor(IDBKeyRange.bound([o,k.getTime()],[o,(new Date).getTime()]),"prev")];case 1:return(s=i.sent())?[2,s.value]:[2,void 0];case 2:return a=i.sent(),E.kg.debug("get conversation last msg error",a),[3,3];case 3:return[2]}}))}))},e.prototype.getMessageByServerMsgId=function(e){var t;return S(this,void 0,void 0,(function(){var n;return L(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,null===(t=this.localCache)||void 0===t?void 0:t.getFromIndex("message","serverMsgId",e)];case 1:return[2,r.sent()];case 2:return n=r.sent(),E.kg.debug("get msg by serverId error",n),[3,3];case 3:return[2]}}))}))},e}(),B=n(7252),O=n(3246),R=n(5531);function D(e){return D="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},D(e)}var A=function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function a(e){try{c(r.next(e))}catch(e){s(e)}}function i(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,i)}c((r=r.apply(e,t||[])).next())}))},x=function(e,t){var n,r,o,s,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function i(s){return function(i){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]