jiuyiUniapp/jiuyi/node_modules/.ignored/easemob-websdk/localCache/localCache.js

1 line
22 KiB
JavaScript

!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;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},M.apply(this,arguments)},S=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())}))},L=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]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,i])}}},k=new Date("2023/01/01"),_=function(){function e(e){var t=e.user,n=e.dbName,r=e.version,o=e.onInit;this.localCache=void 0,this.user="",this.conversationMap={},this.onInit=o,this.init({user:t,dbName:n,version:r})}return e.prototype.init=function(t){return S(this,void 0,void 0,(function(){var n,r,o,s;return L(this,(function(a){switch(a.label){case 0:n=t.dbName,r=t.version,o=t.user,this.user=o,a.label=1;case 1:return a.trys.push([1,3,,4]),[4,y(n,r,{upgrade:function(e,t,n,r){if(t<1){var o=e.createObjectStore("message",{keyPath:"id"});o.createIndex("sessionId","sessionId"),o.createIndex("time","time"),o.createIndex("serverMsgId","serverMsgId",{unique:!0}),o.createIndex("sessionTime",["sessionId","time"],{unique:!0}),e.createObjectStore("conversationList",{keyPath:"sessionId"}).createIndex("updateTime","updateTime")}}})];case 2:return s=a.sent(),this.localCache=s,e.instance||(e.instance=this,this.onInit()),[3,4];case 3:return a.sent(),E.kg.debug("open db error"),[3,4];case 4:return[2]}}))}))},e.getInstance=function(){return e.instance},e.prototype.close=function(){var t;null===(t=this.localCache)||void 0===t||t.close(),this.conversationMap={},e.instance=void 0,E.kg.debug("close db success")},e.prototype.storeConversation=function(e,t,n,r){return S(this,void 0,void 0,(function(){var o,s,a,i,c;return L(this,(function(u){switch(u.label){case 0:return u.trys.push([0,4,,5]),o=(0,T.MQ)({conversationId:e,conversationType:t}),s=M({conversationId:e,conversationType:t,sessionId:o},n),(i=this.conversationMap[o])?[3,2]:[4,this.getConversationBySessionId(o)];case 1:i=u.sent(),u.label=2;case 2:return a=i||s,this.conversationMap[o]||(this.conversationMap[o]=a),a&&(r&&(this.conversationMap[o].unReadCount=(a.unReadCount||0)+1,s.unReadCount=this.conversationMap[o].unReadCount||0),s=M(M({},a),s)),[4,this.putConversationToDB(s)];case 3:return u.sent(),[3,5];case 4:return c=u.sent(),E.kg.debug("store conversation error",c),[3,5];case 5:return[2]}}))}))},e.prototype.putConversationToDB=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("conversationList",e)];case 1:return r.sent(),[3,3];case 2:return n=r.sent(),E.kg.debug("put conversation to local error",n),[3,3];case 3:return[2]}}))}))},e.prototype.getConversationBySessionId=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.get("conversationList",e)];case 1:return[2,r.sent()];case 2:return n=r.sent(),E.kg.debug("get conversation by sessionId error",n),[3,3];case 3:return[2]}}))}))},e.prototype.removeConversationBySessionId=function(e){var t;return S(this,void 0,void 0,(function(){return L(this,(function(n){try{return this.conversationMap[e]&&delete this.conversationMap[e],[2,null===(t=this.localCache)||void 0===t?void 0:t.delete("conversationList",e)]}catch(e){E.kg.debug("remove conversation by sessionId error",e)}return[2]}))}))},e.prototype.getConversationList=function(){var e;return S(this,void 0,void 0,(function(){var t,n,r;return L(this,(function(o){switch(o.label){case 0:t=[],o.label=1;case 1:return o.trys.push([1,6,,7]),[4,null===(e=this.localCache)||void 0===e?void 0:e.transaction("conversationList").store.index("updateTime").openCursor(null,"prev")];case 2:n=o.sent(),o.label=3;case 3:return n?(t.push(n.value),[4,n.continue()]):[3,5];case 4:return n=o.sent(),[3,3];case 5:return[2,t];case 6:return r=o.sent(),E.kg.debug("get local conversationList error",r),[3,7];case 7:return[2]}}))}))},e.prototype.storeMessage=function(e,t,n){return S(this,void 0,void 0,(function(){var r,o,s,a,i,c,u;return L(this,(function(l){switch(l.label){case 0:return l.trys.push([0,5,,6]),r=M({},e),o={},s=!1,a=r.to,i=!1,"chatRoom"===r.chatType||r.chatThread||r.isChatThread?[2]:("groupChat"===r.chatType?s=Boolean(r.from&&r.from!==this.user):"singleChat"===r.chatType&&this.user===r.to&&(s=!0,a=r.from||r.to),"audio"!==r.type&&"video"!==r.type&&"file"!==r.type&&"combine"!==r.type&&"img"!==r.type||(delete r.onFileUploadComplete,delete r.onFileUploadError,delete r.onFileUploadProgress),"combine"!==r.type&&(delete r.success,delete r.fail),Object.assign(r,{sessionId:(0,T.MQ)({conversationId:a,conversationType:null==r?void 0:r.chatType}),status:t,serverMsgId:r.id}),[4,this.getMessageByServerMsgId(r.id)]);case 1:return(null==(c=l.sent())?void 0:c.status)===w.r.SUCCESS?[3,3]:[4,this.putMessageToDB(r)];case 2:l.sent(),l.label=3;case 3:return t>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]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,i])}}},N=["singleChat","groupChat"];function P(){var e,t;return A(this,void 0,void 0,(function(){var n,r,o,s=this;return x(this,(function(a){switch(a.label){case 0:if(E.kg.debug("Call getLocalConversations"),!O.XZ.call(this))return n=B.Z.create({type:R.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(n)];a.label=1;case 1:return a.trys.push([1,4,,5]),[4,null===(t=null===(e=this._localCache)||void 0===e?void 0:e.getInstance())||void 0===t?void 0:t.getConversationList()];case 2:return r=a.sent()||[],[4,Promise.all(r.map((function(e){var t=e.conversationId,n=e.lastMessageId,r=e.unReadCount,o=e.conversationType,a=e.customField;return A(s,void 0,void 0,(function(){var e,s,i,c;return x(this,(function(u){switch(u.label){case 0:return s={conversationId:t,conversationType:o,unReadCount:r||0,customField:a},n?[4,null===(c=null===(i=this._localCache)||void 0===i?void 0:i.getInstance())||void 0===c?void 0:c.getMessageByServerMsgId(n)]:[3,2];case 1:return e=u.sent(),[3,3];case 2:e=void 0,u.label=3;case 3:return[2,(s.lastMessage=e,s)]}}))}))})))];case 3:return[2,{type:0,data:a.sent()}];case 4:throw o=a.sent(),B.Z.create({type:R.E.LOCAL_DB_OPERATION_FAILED,message:"getLocalConversations is failed",data:o});case 5:return[2]}}))}))}function j(e){var t,n;return A(this,void 0,void 0,(function(){var r,o,s,a,i;return x(this,(function(c){switch(c.label){case 0:if(E.kg.debug("Call setLocalConversationCustomField",e),!O.XZ.call(this))return r=B.Z.create({type:R.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(r)];if(o=e.conversationType,s=e.conversationId,a=e.customField,!N.includes(o))throw Error('"Invalid parameter conversationType": '+o);if("string"!=typeof s||""===s)throw Error('Invalid parameter: "conversationId"');if("object"!==D(a))throw Error('Invalid parameter: "customField"');c.label=1;case 1:return c.trys.push([1,3,,4]),[4,null===(n=null===(t=this._localCache)||void 0===t?void 0:t.getInstance())||void 0===n?void 0:n.updateLocalConversation((0,T.MQ)({conversationId:s,conversationType:o}),{customField:a})];case 2:return c.sent(),[3,4];case 3:throw i=c.sent(),B.Z.create({type:R.E.LOCAL_DB_OPERATION_FAILED,message:"setLocalConversationCustomField is failed",data:i});case 4:return[2]}}))}))}function F(e){var t,n,r,o;return A(this,void 0,void 0,(function(){var s,a,i,c,u,l,d,v,p;return x(this,(function(h){switch(h.label){case 0:if(E.kg.debug("Call getLocalConversation",e),!O.XZ.call(this))return s=B.Z.create({type:R.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(s)];if(a=e.conversationType,i=e.conversationId,!N.includes(a))throw Error('"Invalid parameter conversationType": '+a);if("string"!=typeof i||""===i)throw Error('Invalid parameter: "conversationId"');h.label=1;case 1:return h.trys.push([1,8,,9]),[4,null===(n=null===(t=this._localCache)||void 0===t?void 0:t.getInstance())||void 0===n?void 0:n.getConversationBySessionId((0,T.MQ)({conversationId:i,conversationType:a}))];case 2:return c=h.sent(),v={type:0},c?(p={conversationId:c.conversationId,conversationType:a,unReadCount:c.unReadCount||0,customField:c.customField},c.lastMessageId?[4,null===(o=null===(r=this._localCache)||void 0===r?void 0:r.getInstance())||void 0===o?void 0:o.getMessageByServerMsgId(c.lastMessageId)]:[3,4]):[3,6];case 3:return l=h.sent(),[3,5];case 4:l=void 0,h.label=5;case 5:return p.lastMessage=l,u=p,[3,7];case 6:u=void 0,h.label=7;case 7:return[2,(v.data=u,v)];case 8:throw d=h.sent(),B.Z.create({type:R.E.LOCAL_DB_OPERATION_FAILED,message:"getLocalConversation is failed",data:d});case 9:return[2]}}))}))}function Z(e){var t,n,r,o;return A(this,void 0,void 0,(function(){var s,a,i,c,u,l,d;return x(this,(function(v){switch(v.label){case 0:if(E.kg.debug("Call removeLocalConversation",e),!O.XZ.call(this))return s=B.Z.create({type:R.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(s)];if(a=e.conversationType,i=e.conversationId,c=e.isRemoveLocalMessage,u=void 0===c||c,!N.includes(a))throw Error('"Invalid parameter conversationType": '+a);if("string"!=typeof i||""===i)throw Error('Invalid parameter: "conversationId"');l=(0,T.MQ)({conversationId:i,conversationType:a}),v.label=1;case 1:return v.trys.push([1,5,,6]),[4,null===(n=null===(t=this._localCache)||void 0===t?void 0:t.getInstance())||void 0===n?void 0:n.removeConversationBySessionId(l)];case 2:return v.sent(),u?[4,null===(o=null===(r=this._localCache)||void 0===r?void 0:r.getInstance())||void 0===o?void 0:o.removeMsgBySessionId(l)]:[3,4];case 3:v.sent(),v.label=4;case 4:return[3,6];case 5:throw d=v.sent(),B.Z.create({type:R.E.LOCAL_DB_OPERATION_FAILED,message:"removeLocalConversation is failed",data:d});case 6:return[2]}}))}))}function K(e){var t,n;return A(this,void 0,void 0,(function(){var r,o,s,a;return x(this,(function(i){switch(i.label){case 0:if(E.kg.debug("Call clearConversationUnreadCount",e),!O.XZ.call(this))return r=B.Z.create({type:R.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(r)];if(o=e.conversationType,s=e.conversationId,!N.includes(o))throw Error('"Invalid parameter conversationType": '+o);if("string"!=typeof s||""===s)throw Error('Invalid parameter: "conversationId"');i.label=1;case 1:return i.trys.push([1,3,,4]),[4,null===(n=null===(t=this._localCache)||void 0===t?void 0:t.getInstance())||void 0===n?void 0:n.updateLocalConversation((0,T.MQ)({conversationId:s,conversationType:o}),{unReadCount:0,unreadCountClearTimestamp:(new Date).getTime()})];case 2:return i.sent(),[3,4];case 3:throw a=i.sent(),B.Z.create({type:R.E.LOCAL_DB_OPERATION_FAILED,message:"clearConversationUnreadCount is failed",data:a});case 4:return[2]}}))}))}}},function(e){return 6007,e(e.s=6007)}])}));