easemob-websdk 4.16.0 → 4.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -422,6 +422,12 @@ export interface Contact {
422
422
  pageSize?: number;
423
423
  /** The position from which to start getting data. If you set `cursor` to an empty string (''), the SDK retrieves conversations from the latest active one.*/
424
424
  cursor?: string;
425
+ /**
426
+ * Whether to include empty conversations, default is false.
427
+ * - `true`: Yes;
428
+ * - `false`: No.
429
+ */
430
+ includeEmptyConversations?: boolean;
425
431
  }): Promise<AsyncResult<IndexTypes.ServerConversations>>;
426
432
 
427
433
  /**
@@ -438,6 +444,12 @@ export interface Contact {
438
444
  pageSize?: number;
439
445
  /** The position from which to start getting data. If you pass in an empty string (''), the SDK retrieves conversations from the latest pinned one.*/
440
446
  cursor?: string;
447
+ /**
448
+ * Whether to include empty conversations, default is false.
449
+ * - `true`: Yes;
450
+ * - `false`: No.
451
+ */
452
+ includeEmptyConversations?: boolean;
441
453
  }): Promise<AsyncResult<IndexTypes.ServerConversations>>;
442
454
 
443
455
  /**
@@ -1 +1 @@
1
- !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()}(self,(function(){return(self.webpackChunkwebsdk=self.webpackChunkwebsdk||[]).push([[77],{4490:function(e,t,r){var n=r(6518),a=r(9504),o=r(4376),i=a([].reverse),s=[1,2];n({target:"Array",proto:!0,forced:String(s)===String(s.reverse())},{reverse:function(){return o(this)&&(this.length=this.length),i(this)}})},9359:function(e,t,r){r.r(t),r.d(t,{acceptContactInvite:function(){return H},acceptInvitation:function(){return J},addContact:function(){return F},addConversationMark:function(){return me},addReaction:function(){return te},addToBlackList:function(){return V},addUsersToBlacklist:function(){return W},addUsersToBlocklist:function(){return Y},declineContactInvite:function(){return K},declineInvitation:function(){return q},deleteAllMessagesAndConversations:function(){return Ie},deleteContact:function(){return G},deleteConversation:function(){return w},deleteReaction:function(){return re},deleteSession:function(){return _},fetchHistoryMessages:function(){return B},fetchUserInfoById:function(){return P},getAllContacts:function(){return he},getBlacklist:function(){return C},getBlocklist:function(){return E},getContacts:function(){return j},getContactsWithCursor:function(){return fe},getConversationlist:function(){return N},getHistoryMessages:function(){return M},getRTCToken:function(){return be},getReactionDetail:function(){return oe},getReactionList:function(){return ne},getReactionlist:function(){return ae},getRoster:function(){return S},getSelfIdsOnOtherPlatform:function(){return Te},getServerConversations:function(){return ce},getServerConversationsByFilter:function(){return ye},getServerPinnedConversations:function(){return le},getServerPinnedMessages:function(){return je},getSessionList:function(){return R},getTokenExpireTimestamp:function(){return U},getUserIdByRTCUIds:function(){return Re},modifyMessage:function(){return ee},pinConversation:function(){return de},pinMessage:function(){return Ee},recallMessage:function(){return $},removeConversationMark:function(){return ge},removeFromBlackList:function(){return X},removeHistoryMessages:function(){return se},removeRoster:function(){return L},removeUserFromBlackList:function(){return Q},removeUserFromBlocklist:function(){return Z},reportMessage:function(){return ie},setContactRemark:function(){return pe},unbindPushToken:function(){return ke},unpinMessage:function(){return Se},updateCurrentUserNick:function(){return x},updateOwnUserInfo:function(){return A},updateUserInfo:function(){return z},uploadPushToken:function(){return b},uploadToken:function(){return k}}),r(2675),r(9463),r(2259),r(8706),r(2008),r(1629),r(4423),r(4346),r(3792),r(8598),r(2062),r(4490),r(4554),r(739),r(3288),r(2010),r(9085),r(9432),r(6099),r(3362),r(8781),r(7764),r(3500),r(2953);var n=r(1750),a=r(1531),o=r(346),i=r(8678),s=r(4723),c=r(8801),u=r(3887),l=r.n(u),d=r(2056),p=r(3893),h=r(565),f=r(8232),v=r(564),m=r(5323),g=function(){return g=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e},g.apply(this,arguments)},y=function(e,t,r,n){return new(r||(r=Promise))((function(a,o){function i(e){try{c(n.next(e))}catch(e){o(e)}}function s(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}c((n=n.apply(e,t||[])).next())}))},T=function(e,t){var r,n,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(a=2&o[0]?n.return:o[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,o[1])).done)return a;switch(n=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,n=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!((a=(a=i.trys).length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],n=0}finally{r=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}},I={singleChat:"chat",chatRoom:"chatroom",groupChat:"groupchat"};function C(e){var t=n.dO.call(this).error;if(t)return Promise.reject(t);var r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c={url:this.apiUrl+"/"+a+"/"+o+"/users/"+this.user+"/blocks/users",dataType:"json",type:"GET",headers:{Authorization:"Bearer "+s},success:function(t){var r={};t.data.forEach((function(e){r[e]={name:e}})),"function"==typeof(null==e?void 0:e.success)&&e.success(t)},error:function(t){"function"==typeof(null==e?void 0:e.error)&&e.error(t)}};return d.vF.debug("Call getBlocklist"),i.RD.call(this,c,p.jz.GET_BLACK_LIST)}var E=C,S=j;function j(e){var t=this,r=n.dO.call(this).error;if(r)return Promise.reject(r);var a=this.context,o=a.orgName,s=a.appName,c=a.accessToken,u={url:this.apiUrl+"/"+o+"/"+s+"/users/"+this.user+"/contacts/users",dataType:"json",type:"GET",headers:{Authorization:"Bearer "+c},success:function(r){var n=[];r.data.forEach((function(e){n.push({name:e,subscription:"both",jid:t.context.jid})})),"function"==typeof(null==e?void 0:e.success)&&e.success(n)},error:function(t){"function"==typeof(null==e?void 0:e.error)&&e.error(t)}};return d.vF.debug("Call getContacts"),i.RD.call(this,u,p.jz.GET_CONTACTS)}function k(e){return d.vF.debug("Call uploadPushToken"),m.B.call(this,e)}var b=k;function R(e){var t=n.dO.call(this).error;if(t)return Promise.reject(t);var r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c={url:"".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/users/").concat(this.user,"/user_channels"),type:"GET",dataType:"json",headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"},success:e&&(null==e?void 0:e.success),error:e&&(null==e?void 0:e.error)};return d.vF.debug("Call getSessionList"),i.RD.call(this,c)}function N(e){var t=this,r=n.dO.call(this).error;if(r)return Promise.reject(r);var a=this.context,o=a.orgName,s=a.appName,c=a.accessToken,u=!!(e&&"number"==typeof e.pageNum&&"number"==typeof e.pageSize&&e.pageNum>0&&e.pageSize>0),l={url:"".concat(this.apiUrl,"/").concat(o,"/").concat(s,"/users/").concat(this.user,"/user_channels").concat(u?"/page":""),type:"GET",dataType:"json",headers:{Authorization:"Bearer "+c,"Content-Type":"application/json"},success:e&&(null==e?void 0:e.success),error:e&&(null==e?void 0:e.error)};return u&&(l.data={pageNum:e.pageNum,pageSize:e.pageSize}),d.vF.debug("Call getConversationlist"),i.RD.call(this,l,p.jz.GET_SESSION_LIST).then((function(e){return O.call(t,e)}))}function O(e){var t=this,r=e.data.channel_infos;return null==r||r.forEach((function(e){e.meta&&"{}"!==JSON.stringify(e.meta)?(e.meta.payload=JSON.parse(e.meta.payload),e.lastMessage=h.h.call(t,e.meta,{formatCustomExts:!1})):e.lastMessage=e.meta,delete e.meta})),e}function _(e){if(e&&"string"!=typeof e.channel)throw Error("Invalid parameter channel: ".concat(e.channel));if(e&&"singleChat"!==e.chatType&&"groupChat"!==e.chatType)throw Error("Invalid parameter chatType: ".concat(e.chatType));if(e&&"boolean"!=typeof e.deleteRoam)throw Error("Invalid parameter deleteRoam: ".concat(e.deleteRoam));var t=n.dO.call(this).error;if(t)return Promise.reject(t);var r,a=this.context,o=a.orgName,s=a.appName,c=a.accessToken,u=a.jid;r="singleChat"===e.chatType?"chat":"groupChat";var l={url:"".concat(this.apiUrl,"/").concat(o,"/").concat(s,"/user/").concat(this.user,"/user_channel?resource=").concat(u.clientResource),dataType:"json",type:"DELETE",data:JSON.stringify({channel:e.channel,type:r,delete_roam:e.deleteRoam}),headers:{Authorization:"Bearer "+c,"Content-Type":"application/json"},success:e.success,error:e.error};return d.vF.debug("Call deleteSession",e),i.RD.call(this,l,p.jz.DELETE_SESSION)}var w=_;function A(e,t){var r=n.dO.call(this).error;if(r)return Promise.reject(r);var a=this.context,o=a.orgName,s=a.appName,c=a.accessToken,u=["nickname","avatarurl","mail","phone","gender","sign","birth","ext"],l={},h=i.Wp.getEnvInfo();if("wx"===h.platform||"qq"===h.platform)if("string"==typeof e&&void 0!==t){if(!u.includes(e))throw new Error("illegal key, only these keys: nickname, avatarurl, mail, phone, gender, sign, birth, ext are allowed");l[e]=t}else{if("[object Object]"!==Object.prototype.toString.call(e))throw new Error("illegal params");u.forEach((function(t){u.includes(t)&&void 0!==e[t]&&(l[t]=e[t])}))}else if("string"==typeof e){if(!u.includes(e))throw new Error("illegal key, only these keys: nickname, avatarurl, mail, phone, gender, sign, birth, ext are allowed");l=e+"="+t}else{if("[object Object]"!==Object.prototype.toString.call(e))throw new Error("illegal params");var f=[];u.forEach((function(t){if(u.includes(t)&&void 0!==e[t]){var r=encodeURIComponent(t),n=encodeURIComponent(e[t]);f.push(r+"="+n)}})),l=f.join("&")}var v={url:"".concat(this.apiUrl,"/").concat(o,"/").concat(s,"/metadata/user/").concat(this.user),type:"PUT",data:l,dataType:"json",headers:{Authorization:"Bearer "+c,"Content-Type":"application/x-www-form-urlencoded"}};return d.vF.debug("Call updateOwnUserInfo",e),i.RD.call(this,v,p.jz.UPDATE_USER_INFO)}var z=A;function P(e,t){var r=n.dO.call(this).error;if(r)return Promise.reject(r);var a,o=this.context,s=o.orgName,c=o.appName,u=o.accessToken,l=[];if("string"==typeof e)l=[e];else{if("[object Array]"!==Object.prototype.toString.call(e))throw new Error("illegal params");l=e}a="string"==typeof t?[t]:t&&"[object Array]"===Object.prototype.toString.call(t)?t:["nickname","avatarurl","mail","phone","gender","sign","birth","ext"];var h={url:"".concat(this.apiUrl,"/").concat(s,"/").concat(c,"/metadata/user/get"),type:"POST",data:JSON.stringify({targets:l,properties:a}),dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}};return d.vF.debug("Call fetchUserInfoById",e),i.RD.call(this,h,p.jz.GET_USER_INFO)}function x(e){var t=n.dO.call(this).error;if(t)return Promise.reject(t);var r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c={url:"".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/users/").concat(this.user),type:"PUT",dataType:"json",data:JSON.stringify({nickname:e}),headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"}};return d.vF.debug("Call updateCurrentUserNick",e),i.RD.call(this,c)}function U(e){if("string"!=typeof e||""===e)throw Error('Invalid parameter: "token"');var t=this.context,r=t.orgName,n=t.appName,a={url:"".concat(this.apiUrl,"/").concat(r,"/").concat(n,"/sdk/users/").concat(this.user,"/token/expires"),type:"GET",dataType:"json",headers:{Authorization:"Bearer "+e,"Content-Type":"application/json"}};return d.vF.debug("Call getTokenExpireTimestamp",e),i.RD.call(this,a,p.jz.SDK_INTERNAL)}function B(e){var t=this;return new Promise((function(r,a){if(!e.queue)throw Error('Invalid parameter: "specified"');var o=n.dO.call(t).error;if(o)return Promise.reject(o);(function e(t){var n=this,o=t.count||20;D.call(this,{count:o,isGroup:!!t.isGroup,queue:t.queue,start:t.start,format:t.format,success:function(a){if(a.msgs.length>=o||a.is_last){var i=a.msgs.splice(0,o).reverse();t.success&&t.success(i),r(i)}else e.call(n,g(g({},t),{start:null}))},fail:function(e){a(e),t.fail&&t.fail(e)}})}).call(t,e),d.vF.debug("Call fetchHistoryMessages",e)}))}function D(e){var t=this,r=e.queue,n=this.mr_cache[r]||(this.mr_cache[r]={msgs:[]}),s=this.context.userId,u=e.start||-1,d=e.count||20;if(n.msgs.length>=d||n.is_last)"function"==typeof e.success&&e.success(n);else{n&&n.next_key&&(u=n.next_key),e.start&&(u=e.start);var h={queue:r+(e.isGroup?"@conference.easemob.com":"@easemob.com"),start:u,end:-1},f=this.context,v=f.orgName,m=f.appName,g={url:"".concat(this.apiUrl,"/").concat(v,"/").concat(m,"/users/").concat(s,"/messageroaming"),dataType:"json",type:"POST",headers:{Authorization:"Bearer "+this.token,"Content-Type":"application/json"},data:JSON.stringify(h),success:function(r){return y(t,void 0,void 0,(function(){var t,a,o,i,s,u,d=this;return T(this,(function(p){switch(p.label){case 0:if(t=null==r?void 0:r.data,!r.data.msgs)return"function"==typeof e.success&&e.success(n),n.is_last=!0,n.next_key="",[2];a=t.msgs,o=a.length,n.is_last=t.is_last,n.next_key=t.next_key,i=function(t){return y(d,void 0,void 0,(function(){var r,n,a,o,i;return T(this,(function(s){switch(s.label){case 0:for(r=[],t=l().atob(t),n=0,a=t.length;n<a;++n)r.push(t.charCodeAt(n));return o=(o=this.context.root.lookup("easemob.pb.Meta")).decode(r),i={errorCode:0,reason:""},1!==o.ns?[3,2]:[4,c.Ay.call(this,o,i,!0,e.format)];case 1:return[2,s.sent()];case 2:return[2]}}))}))},s=0,p.label=1;case 1:return s<o?[4,i(a[s].msg)]:[3,4];case 2:(u=p.sent())&&n.msgs.push(u),p.label=3;case 3:return s++,[3,1];case 4:return"function"==typeof e.success&&e.success(n),[2]}}))}))},error:function(e){if(e.error&&e.error_description){var r=o.A.create({type:a.C.WEBIM_CONNCTION_AJAX_ERROR,message:"fetch history messages error",data:e});t.onError&&t.onError(r)}}};i.RD.call(this,g,p.jz.GET_HISTORY_MSG).catch((function(t){"function"==typeof e.fail&&e.fail(t)}))}}function M(e){var t=this;return new Promise((function(r,a){var o=e.targetId,s=e.cursor,u=void 0===s?-1:s,h=e.pageSize,f=void 0===h?20:h,v=e.chatType,m=e.searchDirection,g=e.searchOptions,I=void 0===g?{}:g,C=I.msgTypes,E=void 0===C?[]:C,S=I.startTime,j=void 0===S?null:S,k=I.endTime,b=void 0===k?null:k,R=I.from,N=void 0===R?null:R;if("string"!=typeof o||""===o)throw Error('"Invalid parameter": "targetId"');if(N&&"string"!=typeof N)throw Error('"Invalid parameter": "searchOptions.from"');if(E&&!Array.isArray(E))throw Error('"Invalid parameter": "searchOptions.msgTypes"');if(j&&"number"!=typeof j)throw Error('"Invalid parameter": "searchOptions.startTime"');if(b&&"number"!=typeof j)throw Error('"Invalid parameter": "searchOptions.endTime"');var O=n.dO.call(t).error;if(O)return Promise.reject(O);var _=t.context,w=_.orgName,A=_.appName,z=_.userId,P="singleChat"===e.chatType?"@easemob.com":"@conference.easemob.com",x={queue:"".concat(o).concat(P),start:u,pull_number:f,is_positive:"down"===m,msgType:E.join(",")||"",end:-1,startTime:j,endTime:b,userId:"singleChat"===v?null:N},U={url:"".concat(t.apiUrl,"/").concat(w,"/").concat(A,"/users/").concat(z,"/messageroaming"),dataType:"json",type:"POST",headers:{Authorization:"Bearer "+t.token,"Content-Type":"application/json"},data:JSON.stringify(x),success:function(n){return y(t,void 0,void 0,(function(){var t,a,o,i,s,u,d,p,h=this;return T(this,(function(f){switch(f.label){case 0:t=null==n?void 0:n.data,a=t.msgs||[],o=function(e){return y(h,void 0,void 0,(function(){var t,r,n,a,o;return T(this,(function(i){switch(i.label){case 0:for(t=[],e=l().atob(e),r=0,n=e.length;r<n;++r)t.push(e.charCodeAt(r));return a=(a=this.context.root.lookup("easemob.pb.Meta")).decode(t),o={errorCode:0,reason:""},1!==a.ns?[3,2]:[4,c.Ay.call(this,a,o,!0,!0)];case 1:return[2,i.sent()];case 2:return[2]}}))}))},i=[],s=0,f.label=1;case 1:return s<a.length?[4,o(a[s].msg)]:[3,4];case 2:(u=f.sent())&&i.push(u),f.label=3;case 3:return s++,[3,1];case 4:return t.msgs=i,d={cursor:t.next_key,messages:i,isLast:t.is_last},null===(p=e.success)||void 0===p||p.call(e,d),r(d),[2]}}))}))},error:e.fail};i.RD.call(t,U,p.jz.REST_FETCHHISTORYMESSAGE).catch((function(e){a(e)})),d.vF.debug("Call getHistoryMessages",e)}))}function F(e,t){return y(this,void 0,void 0,(function(){var r,a,o,s,c,u,l;return T(this,(function(h){switch(h.label){case 0:if(r=n.dO.call(this).error)return[2,Promise.reject(r)];if("string"!=typeof e||""===e)throw Error('"Invalid parameter": "to"');return d.vF.debug("Call addContact",e,t),a=this.context,o=a.orgName,s=a.appName,c=a.accessToken,u=a.jid,l={url:"".concat(this.apiUrl,"/").concat(o,"/").concat(s,"/users/").concat(this.user,"/contacts/apply?resource=").concat(u.clientResource),type:"POST",dataType:"json",data:JSON.stringify({usernames:[e],reason:t}),headers:{Authorization:"Bearer "+c,"Content-Type":"application/json"}},[4,i.RD.call(this,l,p.jz.ROSTER_ADD)];case 1:return h.sent(),[2]}}))}))}var L=G;function G(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u;return T(this,(function(l){switch(l.label){case 0:if(t=n.dO.call(this).error)return[2,Promise.reject(t)];if("string"!=typeof e||""===e)throw Error('"Invalid parameter": "to"');return d.vF.debug("Call deleteContact",e),r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c=r.jid,u={url:"".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/users/").concat(this.user,"/contacts/users/").concat(e,"?resource=").concat(c.clientResource),type:"DELETE",dataType:"json",headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"}},[4,i.RD.call(this,u,p.jz.ROSTER_REMOVE)];case 1:return l.sent(),[2]}}))}))}function J(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u;return T(this,(function(l){switch(l.label){case 0:if(t=n.dO.call(this).error)return[2,Promise.reject(t)];if("string"!=typeof e||""===e)throw Error('"Invalid parameter": "to"');return d.vF.debug("Call acceptInvitation",e),r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c=r.jid,u={url:"".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/users/").concat(this.user,"/contacts/accept/users/").concat(e,"?resource=").concat(c.clientResource),type:"POST",dataType:"json",headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"}},[4,i.RD.call(this,u,p.jz.ROSTER_ACCEPT)];case 1:return l.sent(),[2]}}))}))}var H=J;function q(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u;return T(this,(function(l){switch(l.label){case 0:if(t=n.dO.call(this).error)return[2,Promise.reject(t)];if("string"!=typeof e||""===e)throw Error('"Invalid parameter": "to"');return d.vF.debug("Call declineInvitation",e),r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c=r.jid,u={url:"".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/users/").concat(this.user,"/contacts/decline/users/").concat(e,"?resource=").concat(c.clientResource),type:"POST",dataType:"json",headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"}},[4,i.RD.call(this,u,p.jz.ROSTER_DECLINE)];case 1:return l.sent(),[2]}}))}))}var K=q;function V(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u,l,h;return T(this,(function(f){switch(f.label){case 0:if(t=n.dO.call(this).error)return[2,Promise.reject(t)];if(r=e.name,a=[],"string"==typeof r){if(""===r)throw Error('"Invalid parameter": "name"');a=[r]}else{if(!Array.isArray(r))throw Error('"Invalid parameter": "name"');a=r}return d.vF.debug("Call addToBlockList",e),o=this.context,s=o.orgName,c=o.appName,u=o.accessToken,l=o.jid,h={url:"".concat(this.apiUrl,"/").concat(s,"/").concat(c,"/sdk/user/").concat(this.user,"/blocks?resource=").concat(l.clientResource),type:"POST",dataType:"json",data:JSON.stringify({usernames:a}),headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}},[4,i.RD.call(this,h,p.jz.ROSTER_BAN).then((function(e){return{type:e.type,data:{userIds:(null==e?void 0:e.data)||[]}}}))];case 1:return[2,f.sent()]}}))}))}var W=V,Y=V;function X(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u,l,h;return T(this,(function(f){switch(f.label){case 0:if(t=n.dO.call(this).error)return[2,Promise.reject(t)];if(r=e.name,a=[],"string"==typeof r){if(""===r)throw Error('"Invalid parameter": "name"');a=[r]}else{if(!Array.isArray(r))throw Error('"Invalid parameter": "name"');a=r}return d.vF.debug("Call removeFromBlockList",e),o=this.context,s=o.orgName,c=o.appName,u=o.accessToken,l=o.jid,h={url:"".concat(this.apiUrl,"/").concat(s,"/").concat(c,"/sdk/user/").concat(this.user,"/blocks?resource=").concat(l.clientResource),type:"DELETE",dataType:"json",data:JSON.stringify({usernames:a}),headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}},[4,i.RD.call(this,h,p.jz.ROSTER_ALLOW)];case 1:return f.sent(),[2]}}))}))}var Q=X,Z=X;function $(e){var t=this,r=(null==e?void 0:e.ext)||"";if("string"!=typeof r)throw Error('"Invalid parameter": "ext"',r);var n=this.getUniqueId(),a={id:n,to:e.to};this._msgHash[n]=g({},a);var o="";void 0!==e.chatType?o=e.chatType:void 0!==e.type&&(o="chat"===e.type?"singleChat":e.type);var i={id:n,type:"recall",chatType:o,ackId:e.mid,to:e.to,isChatThread:e.isChatThread||!1,metaExt:r,success:function(r){return y(t,void 0,void 0,(function(){var t,n,a,i,s,c,u,l,d;return T(this,(function(p){switch(p.label){case 0:return p.trys.push([0,5,,6]),"singleChat"!==o&&"groupChat"!==o?[3,4]:[4,null===(a=null===(n=this._localCache)||void 0===n?void 0:n.getInstance())||void 0===a?void 0:a.removeMsgByServerMsgId(e.mid)];case 1:return p.sent(),[4,null===(s=null===(i=this._localCache)||void 0===i?void 0:i.getInstance())||void 0===s?void 0:s.getConversationLastMessage(e.to,o)];case 2:return t=p.sent(),[4,null===(u=null===(c=this._localCache)||void 0===c?void 0:c.getInstance())||void 0===u?void 0:u.updateLocalConversation((0,v.u0)({conversationId:e.to,conversationType:o}),{lastMessageId:null==t?void 0:t.serverMsgId})];case 3:p.sent(),p.label=4;case 4:return null===(l=null==e?void 0:e.success)||void 0===l||l.call(e,r),[3,6];case 5:return p.sent(),null===(d=null==e?void 0:e.success)||void 0===d||d.call(e,r),[3,6];case 6:return[2]}}))}))},fail:e.fail};return d.vF.debug("Call recallMessage",e),this.mSync.send(i,this)}function ee(e){var t=e||{},r=t.messageId,n=t.modifiedMessage;if(d.vF.debug("Call modifyMessage",r,n),""===r)throw Error('Invalid parameter: "messageId"');return this.mSync.send(g({editMessageId:r},n))}function te(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u,l,d;return T(this,(function(p){switch(p.label){case 0:if("string"!=typeof e.messageId||!e.messageId)throw Error("Invalid parameter messageId: ".concat(e.messageId));if("string"!=typeof e.reaction||!e.reaction)throw Error("Invalid parameter reaction: ".concat(e.reaction));return(t=n.dO.call(this).error)?[2,Promise.reject(t)]:(r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c=e.reaction,u=e.messageId,l={msgId:u,message:c},d={url:"".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/reaction/user/").concat(this.user),type:"POST",data:JSON.stringify(l),dataType:"json",headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"}},[4,i.RD.call(this,d)]);case 1:return p.sent(),[2]}}))}))}function re(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u,l;return T(this,(function(d){switch(d.label){case 0:if("string"!=typeof e.reaction||!e.reaction)throw Error("Invalid parameter reactionId: ".concat(e.reaction));return(t=n.dO.call(this).error)?[2,Promise.reject(t)]:(r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c=e.messageId,u=e.reaction,l={url:"".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/reaction/user/").concat(this.user,"?msgId=").concat(c,"&message=").concat(u),type:"DELETE",dataType:"json",headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"}},[4,i.RD.call(this,l)]);case 1:return d.sent(),[2]}}))}))}function ne(e){if("string"!=typeof e.chatType||!e.chatType)throw Error("Invalid parameter chatType: ".concat(e.chatType));if(!e.messageId)throw Error("Invalid parameter messageId: ".concat(e.messageId));var t=n.dO.call(this).error;if(t)return Promise.reject(t);var r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c=e.chatType,u=e.messageId,l={msgIdList:"string"==typeof u?[u]:u,msgType:"singleChat"===c?"chat":"groupchat",groupId:e.groupId||null},d={url:"".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/reaction/user/").concat(this.user),type:"GET",data:l,dataType:"json",headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"}};return i.RD.call(this,d).then((function(e){var t=e.data;return null==t||t.forEach((function(e){null==e||e.reactionList.forEach((function(e){e.isAddedBySelf=e.state,delete e.state,delete e.reactionId}))})),e}))}var ae=ne;function oe(e){if("string"!=typeof e.reaction||!e.reaction)throw Error("Invalid parameter reaction: ".concat(e.reaction));if("string"!=typeof e.messageId||!e.messageId)throw Error("Invalid parameter messageId: ".concat(e.messageId));var t=n.dO.call(this).error;if(t)return Promise.reject(t);var r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c=e.cursor,u=e.pageSize,l={msgId:e.messageId,message:e.reaction,currentPage:c||null,pageSize:u||20},d={url:"".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/reaction/user/").concat(this.user,"/detail"),type:"GET",data:l,dataType:"json",headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"}};return i.RD.call(this,d).then((function(e){return e.data.isAddedBySelf=e.data.state,delete e.data.state,delete e.data.reactionId,e}))}function ie(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u,l,d,p,h;return T(this,(function(f){switch(f.label){case 0:if("string"!=typeof e.reportType||!e.reportType)throw Error("Invalid parameter reportType: ".concat(e.reportType));if("string"!=typeof e.messageId||!e.messageId)throw Error("Invalid parameter messageId: ".concat(e.messageId));if("string"!=typeof e.reportReason||!e.reportReason)throw Error("Invalid parameter messageId: ".concat(e.reportReason));return(t=n.dO.call(this).error)?[2,Promise.reject(t)]:(r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c=e.reportType,u=e.reportReason,l=e.messageId,d={username:this.user,reportType:c,reportReason:u},p="".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/user/").concat(this.user,"/moderation/report/message/").concat(l),h={url:p,type:"POST",data:JSON.stringify(d),dataType:"json",headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"}},[4,i.RD.call(this,h)]);case 1:return f.sent(),[2]}}))}))}function se(e){var t;return y(this,void 0,void 0,(function(){var r,a,o,s,c,u,l,p,h;return T(this,(function(f){switch(f.label){case 0:if("string"!=typeof e.targetId||""===e.targetId)throw Error('"Invalid parameter targetId": '+e.targetId);if(!["singleChat","groupChat","chatRoom"].includes(e.chatType))throw Error('"Invalid parameter chatType": '+e.chatType);if(e.beforeTimeStamp&&("number"!=typeof e.beforeTimeStamp||e.beforeTimeStamp<0||(null===(t=e.beforeTimeStamp)||void 0===t?void 0:t.toString().length)>18))throw Error('"Invalid parameter beforeTimeStamp": '+e.beforeTimeStamp);if(e.messageIds&&!(Array.isArray(e.messageIds)&&e.messageIds.length>0&&e.messageIds.length<=20))throw Error('"Invalid parameter messageIds": '+e.messageIds);if(!e.messageIds&&!e.beforeTimeStamp)throw Error("messageIds or beforeTimeStamp field is required.");return(r=n.dO.call(this).error)?[2,Promise.reject(r)]:(a=this.context,o=a.orgName,s=a.appName,c=a.userId,u="singleChat"===e.chatType?"userId":"groupId",l="singleChat"===e.chatType?"chat":"group",p=e.messageIds?"".concat(this.apiUrl,"/").concat(o,"/").concat(s,"/sdk/message/roaming/").concat(l,"/user/").concat(c,"?").concat(u,"=").concat(e.targetId,"&msgIdList=").concat(e.messageIds,"&resource=").concat(this.clientResource):"".concat(this.apiUrl,"/").concat(o,"/").concat(s,"/sdk/message/roaming/").concat(l,"/user/").concat(c,"/time?").concat(u,"=").concat(e.targetId,"&delTime=").concat(e.beforeTimeStamp,"&&resource=").concat(this.clientResource),h={url:p,dataType:"json",type:"DELETE",headers:{Authorization:"Bearer "+this.token,"Content-Type":"application/json"}},d.vF.debug("Call removeHistoryMessages",e),[4,i.RD.call(this,h)]);case 1:return f.sent(),[2]}}))}))}function ce(e){var t=this,r=n.dO.call(this).error;if(r)return Promise.reject(r);if((null==e?void 0:e.pageSize)&&"number"!=typeof e.pageSize)throw Error("Invalid parameter pageSize: ".concat(e.pageSize));if((null==e?void 0:e.cursor)&&"string"!=typeof e.cursor)throw Error("Invalid parameter cursor: ".concat(e.cursor));var a=this.context,o=a.orgName,s=a.appName,c=a.accessToken,u={url:"".concat(this.apiUrl,"/").concat(o,"/").concat(s,"/sdk/user/").concat(this.user,"/user_channels/list?"),type:"GET",dataType:"json",data:{limit:(null==e?void 0:e.pageSize)||20,cursor:(null==e?void 0:e.cursor)||"",need_mark:!0},headers:{Authorization:"Bearer "+c,"Content-Type":"application/json"}};return d.vF.debug("Call getServerConversations",e),new Promise((function(e,r){i.RD.call(t,u,p.jz.REST_FETCH_CONVERSATIONS).then((function(r){return y(t,void 0,void 0,(function(){var t,n,a=this;return T(this,(function(o){switch(o.label){case 0:return t=ue.call(this,r),this._localCache?(n=t.data.conversations.map((function(e){return y(a,void 0,void 0,(function(){var t,r,n,a;return T(this,(function(o){switch(o.label){case 0:return[4,null===(r=null===(t=this._localCache)||void 0===t?void 0:t.getInstance())||void 0===r?void 0:r.storeMessage(e.lastMessage,f.q.SUCCESS,!0)];case 1:return o.sent(),[4,null===(a=null===(n=this._localCache)||void 0===n?void 0:n.getInstance())||void 0===a?void 0:a.updateLocalConversation((0,v.u0)({conversationId:e.conversationId,conversationType:e.conversationType}),{unReadCount:e.unReadCount})];case 2:return o.sent(),[2]}}))}))})),[4,Promise.all(n)]):[3,2];case 1:o.sent(),o.label=2;case 2:return e(t),[2]}}))}))})).catch((function(e){r(e)}))}))}function ue(e){var t=this,r=e.data,n=r.cursor,a=r.channel_infos,o=[];null==a||a.forEach((function(e){var r=null;(null==e?void 0:e.meta)&&"{}"!==JSON.stringify(e.meta)&&(e.meta.payload=JSON.parse(e.meta.payload),"delivery"!==(r=h.h.call(t,e.meta)).type&&"read"!==r.type&&"channel"!==r.type&&(r.chatType=h.p[r.chatType]));var n={conversationId:e.session_to,conversationType:"chat"===e.session_type?"singleChat":"groupChat",isPinned:e.is_top,pinnedTime:e.is_top?e.update_top_status_time:0,unReadCount:e.unread_num,lastMessage:r};e.marks&&(n.marks=e.marks.map((function(e){return s.s[e]}))),o.push(n)}));var i={conversations:o,cursor:n||""};return{type:e.type,data:i}}function le(e){var t=this,r=n.dO.call(this).error;if(r)return Promise.reject(r);if((null==e?void 0:e.pageSize)&&"number"!=typeof e.pageSize)throw Error("Invalid parameter pageSize: ".concat(e.pageSize));if((null==e?void 0:e.cursor)&&"string"!=typeof e.cursor)throw Error("Invalid parameter cursor: ".concat(e.cursor));var a=this.context,o=a.orgName,s=a.appName,c=a.accessToken,u={url:"".concat(this.apiUrl,"/").concat(o,"/").concat(s,"/sdk/user/").concat(this.user,"/user_channels/list?"),type:"GET",dataType:"json",data:{limit:(null==e?void 0:e.pageSize)||20,cursor:(null==e?void 0:e.cursor)||"",is_top:!0,need_mark:!0},headers:{Authorization:"Bearer "+c,"Content-Type":"application/json"}};return d.vF.debug("Call getServerPinnedConversations",e),i.RD.call(this,u,p.jz.GET_SESSION_LIST).then((function(e){return ue.call(t,e)}))}function de(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u,l,h,f,v,m,g,y;return T(this,(function(T){if(t=n.dO.call(this).error)return[2,Promise.reject(t)];if(r=e.conversationId,a=e.conversationType,o=e.isPinned,s="singleChat"===a?"chat":"groupChat","string"!=typeof r||""===r)throw Error("Invalid parameter conversationId: ".concat(r));if(!["singleChat","groupChat"].includes(a))throw Error("Invalid parameter conversationType: ".concat(a));if("boolean"!=typeof o)throw Error("Invalid parameter isPinned: ".concat(o));return c=this.context,u=c.orgName,l=c.appName,h=c.accessToken,f=c.jid,v={type:s,to:r},m=o?"":"type=".concat(s,"&to=").concat(r,"&"),g="".concat(this.apiUrl,"/").concat(u,"/").concat(l,"/sdk/user/").concat(this.user,"/user_channel/top?").concat(m,"resource=").concat(f.clientResource),y={url:g,type:o?"POST":"DELETE",dataType:"json",headers:{Authorization:"Bearer "+h,"Content-Type":"application/json"}},o&&(y.data=JSON.stringify(v)),d.vF.debug("Call pinConversation",e),[2,i.RD.call(this,y,p.jz.PIN_CONVERSATION).then((function(e){var t=e.type,r=e.data;return{type:t,data:{isPinned:r.is_top||!1,pinnedTime:r.is_top?r.update_top_status_time:0}}}))]}))}))}function pe(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u,l,h,f;return T(this,(function(v){switch(v.label){case 0:if(t=e.userId,r=e.remark,a=n.dO.call(this).error)return[2,Promise.reject(a)];if("string"!=typeof t||""===t)throw Error('Invalid parameter: "userId"');if("string"!=typeof r)throw Error('Invalid parameter: "remark"');return d.vF.debug("Call setContactRemark",e),o=this.context,s=o.orgName,c=o.appName,u=o.accessToken,l=o.jid,h="".concat(this.apiUrl,"/").concat(s,"/").concat(c,"/users/").concat(this.context.userId,"/contacts/users/").concat(t,"?resource=").concat(l.clientResource),f={url:h,type:"PUT",data:JSON.stringify({remark:r}),dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}},[4,i.RD.call(this,f,p.jz.ROSTER_SET_CONTACT_REMARK)];case 1:return v.sent(),[2]}}))}))}function he(){var e=n.dO.call(this).error;if(e)return Promise.reject(e);var t=this.context,r=t.orgName,a=t.appName,o=t.accessToken,s={url:"".concat(this.apiUrl,"/").concat(r,"/").concat(a,"/users/").concat(this.user,"/contacts/users?needReturnRemark=true"),dataType:"json",type:"GET",headers:{Authorization:"Bearer "+o}};return d.vF.debug("Call getAllContacts"),i.RD.call(this,s,p.jz.ROSTER_GET_ALL_CONTACTS_REMARKS).then((function(e){var t=((null==e?void 0:e.entities)||[]).map((function(e){return{userId:e.username,remark:e.remark}}));return{type:e.type,data:t}}))}function fe(e){var t=n.dO.call(this).error;if(t)return Promise.reject(t);d.vF.debug("Call getContactsWithCursor",e);var r=e||{},a=r.pageSize,o=void 0===a?20:a,s=r.cursor,c=void 0===s?"":s;if(o&&"number"!=typeof o)throw Error("Invalid parameter pageSize: ".concat(e.pageSize));var u=this.context,l=u.orgName,h=u.appName,f=u.accessToken,v={url:"".concat(this.apiUrl,"/").concat(l,"/").concat(h,"/users/").concat(this.user,"/contacts?needReturnRemark=true&limit=").concat(o,"&cursor=").concat(c),dataType:"json",type:"GET",headers:{Authorization:"Bearer "+f}};return i.RD.call(this,v,p.jz.ROSTER_GET_ALL_CONTACTS_REMARKS_FROM_SERVER_BY_PAGE).then((function(e){var t,r,n=(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.contacts)||[],a=(null===(r=null==e?void 0:e.data)||void 0===r?void 0:r.cursor)||"",o=n.map((function(e){return{userId:e.username,remark:e.remark}}));return{type:e.type,data:{cursor:a,contacts:o}}}))}function ve(e){return y(this,void 0,void 0,(function(){var t,r,a,o,c,u,l,f,v,m,g,y,C,E,S;return T(this,(function(T){switch(T.label){case 0:if(t=n.dO.call(this).error)return[2,Promise.reject(t)];if(d.vF.debug("Call markConversation",e),a=(r=e||{}).conversations,o=void 0===a?[]:a,c=r.mark,u=r.isMarked,!Array.isArray(o))throw Error("Invalid parameter conversations");if(l=o.map((function(e){if(!e.conversationId||!["singleChat","groupChat"].includes(e.conversationType))throw Error("Invalid parameter conversations");return{to:e.conversationId,type:I[e.conversationType]}})),"boolean"!=typeof u)throw Error("Invalid parameter isMarked: ".concat(u));if("number"!=typeof c)throw Error("Invalid parameter mark: ".concat(c));return f=this.context,v=f.orgName,m=f.appName,g=f.accessToken,y=f.userId,C=f.jid,E={mark:s.s[c],targets:l},S={url:"".concat(this.apiUrl,"/").concat(v,"/").concat(m,"/sdk/user/").concat(y,"/user_channels/mark?resource=").concat(C.clientResource),dataType:"json",data:JSON.stringify(E),type:u?"Post":"Delete",headers:{Authorization:"Bearer "+g}},[4,i.RD.call(this,S,p.jz.MARK_CONVERSATION).then((function(e){var t,r=(null===(t=e.data)||void 0===t?void 0:t.ignore)||[];r&&Array.isArray(r)&&r.length>0&&d.vF.debug("markConversation has ignored conversations",r.map((function(e){return{conversationId:e.to,conversationType:h.p[e.type]}})))}))];case 1:return T.sent(),[2]}}))}))}function me(e){return y(this,void 0,void 0,(function(){var t,r;return T(this,(function(n){return d.vF.debug("Call addConversationMark",e),t=e.conversations,r=e.mark,[2,ve.call(this,{conversations:t,mark:r,isMarked:!0})]}))}))}function ge(e){return y(this,void 0,void 0,(function(){var t,r;return T(this,(function(n){return d.vF.debug("Call removeConversationMark",e),t=e.conversations,r=e.mark,[2,ve.call(this,{conversations:t,mark:r,isMarked:!1})]}))}))}function ye(e){var t,r,a=this,o=n.dO.call(this).error;if(o)return Promise.reject(o);if(d.vF.debug("Call getServerConversationsByFilter",e),(null==e?void 0:e.pageSize)&&"number"!=typeof e.pageSize)throw Error("Invalid parameter pageSize: ".concat(e.pageSize));if((null==e?void 0:e.cursor)&&"string"!=typeof e.cursor)throw Error("Invalid parameter cursor: ".concat(e.cursor));if("number"!=typeof(null===(t=null==e?void 0:e.filter)||void 0===t?void 0:t.mark))throw Error("Invalid parameter mark: ".concat(null===(r=null==e?void 0:e.filter)||void 0===r?void 0:r.mark));var c=this.context,u=c.orgName,l=c.appName,h=c.accessToken,f="".concat(this.apiUrl,"/").concat(u,"/").concat(l,"/sdk/user/").concat(this.user,"/user_channels/mark/search?"),v=e.pageSize,m=e.cursor,g=((null==e?void 0:e.filter)||{}).mark,y={url:f,type:"GET",dataType:"json",data:{limit:v||10,cursor:m||"",need_mark:!0,mark:s.s[g]},headers:{Authorization:"Bearer "+h,"Content-Type":"application/json"}};return i.RD.call(this,y,p.jz.GET_SESSION_LIST).then((function(e){return ue.call(a,e)}))}function Te(){var e=n.dO.call(this).error;if(e)return Promise.reject(e);d.vF.debug("Call getSelfIdsOnOtherPlatform");var t=this.context,r=t.orgName,a=t.appName,o=t.accessToken,s=t.userId,c=t.jid,u={url:"".concat(this.apiUrl,"/").concat(r,"/").concat(a,"/users/").concat(s,"/resources"),type:"GET",dataType:"json",headers:{Authorization:"Bearer "+o,"Content-Type":"application/json"}};return i.RD.call(this,u,p.jz.USER_LOGGEDIN_OTHER_PLATFORM).then((function(e){var t,r=null===(t=e.data)||void 0===t?void 0:t.filter((function(e){return e.res!==c.clientResource})),n=null==r?void 0:r.map((function(e){return"".concat(s,"/").concat(e.res)}));return{type:e.type,data:n}}))}function Ie(){var e,t,r,a,o,s;return y(this,void 0,void 0,(function(){var c,u,l,h,f,v,m,g,y;return T(this,(function(T){switch(T.label){case 0:return(c=n.dO.call(this).error)?[2,Promise.reject(c)]:(d.vF.debug("Call deleteAllMessagesAndConversations"),u=this.context,l=u.orgName,h=u.appName,f=u.accessToken,v=u.userId,m=u.jid,g="".concat(this.apiUrl,"/").concat(l,"/").concat(h,"/sdk/message/roaming/user/").concat(v,"/delete/all?resource=").concat(m.clientResource),y={url:g,type:"POST",dataType:"json",headers:{Authorization:"Bearer "+f,"Content-Type":"application/json"}},[4,i.RD.call(this,y,p.jz.REST_DELETE_MESSAGES_CONVERSATIONS)]);case 1:return T.sent(),null===(t=null===(e=this._localCache)||void 0===e?void 0:e.getInstance())||void 0===t||t.clearConversationMap(),[4,null===(a=null===(r=this._localCache)||void 0===r?void 0:r.getInstance())||void 0===a?void 0:a.clearStoreData("conversationList")];case 2:return T.sent(),[4,null===(s=null===(o=this._localCache)||void 0===o?void 0:o.getInstance())||void 0===s?void 0:s.clearStoreData("message")];case 3:return T.sent(),[2]}}))}))}function Ce(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u,l,h,f,v,m,g,y,C;return T(this,(function(T){switch(T.label){case 0:if(t=n.dO.call(this).error)return[2,Promise.reject(t)];if(d.vF.debug("Call setMessagePinStatus",e),a=(r=e||{}).conversationId,o=void 0===a?"":a,s=r.conversationType,c=r.messageId,u=r.isPinned,"string"!=typeof o||""===o)throw Error("Invalid parameter conversationId");if("string"!=typeof c||""===c)throw Error("Invalid parameter messageId");if("boolean"!=typeof u)throw Error("Invalid parameter isPinned");return l=this.context,h=l.orgName,f=l.appName,v=l.accessToken,m=l.userId,g=l.jid,y={to:o,type:I[s],pin_msg_id:c},C={url:"".concat(this.apiUrl,"/").concat(h,"/").concat(f,"/sdk/user/").concat(m,"/user_channel/pin?resource=").concat(g.clientResource),dataType:"json",data:JSON.stringify(y),type:u?"Post":"Delete",headers:{Authorization:"Bearer "+v}},[4,i.RD.call(this,C,p.jz.REST_PIN_MESSAGE)];case 1:return T.sent(),[2]}}))}))}function Ee(e){return y(this,void 0,void 0,(function(){var t,r,n,a;return T(this,(function(o){return d.vF.debug("Call pinMessage",e),r=(t=e||{}).conversationType,n=t.conversationId,a=t.messageId,[2,Ce.call(this,{conversationId:n,conversationType:r,messageId:a,isPinned:!0})]}))}))}function Se(e){return y(this,void 0,void 0,(function(){var t,r,n,a;return T(this,(function(o){return d.vF.debug("Call unpinMessage",e),r=(t=e||{}).conversationType,n=t.conversationId,a=t.messageId,[2,Ce.call(this,{conversationId:n,conversationType:r,messageId:a,isPinned:!1})]}))}))}function je(e){var t=this,r=n.dO.call(this).error;if(r)return Promise.reject(r);d.vF.debug("Call getServerPinnedMessages",e);var a=e.conversationId,o=e.conversationType,s=e.pageSize,c=e.cursor;if("string"!=typeof a||""===a)throw Error("Invalid parameter conversationId");if(s&&"number"!=typeof s)throw Error("Invalid parameter pageSize: ".concat(s));if(c&&"string"!=typeof c)throw Error("Invalid parameter cursor: ".concat(c));var u=this.context,l=u.orgName,f=u.appName,v=u.accessToken,m={url:"".concat(this.apiUrl,"/").concat(l,"/").concat(f,"/sdk/user/").concat(this.user,"/user_channel/pin"),type:"GET",dataType:"json",data:{to:a,type:I[o],limit:s||10,cursor:c||""},headers:{Authorization:"Bearer "+v,"Content-Type":"application/json"}};return i.RD.call(this,m,p.jz.GET_SESSION_LIST).then((function(e){return{type:0,data:{list:e.data.msg_infos.map((function(e){e.message.payload=JSON.parse(e.message.payload);var r=e.message,n=e.pin_opt_at,a=e.pin_operator;return{message:h.h.call(t,r,{formatChatType:!0}),pinTime:n,operatorId:a}})),cursor:e.data.cursor||""}}}))}function ke(){var e=this;d.vF.debug("Call unbindPushToken");var t={deviceId:this.clientResource,deviceToken:"",notifierName:this.pushCertificateName};return m.B.call(this,t).then((function(t){return e.isRegisterPush=!1,t}))}function be(e){void 0===e&&(e="*");var t=this.context,r=t.orgName,n=t.appName,a=t.accessToken,o=t.userId,s={url:"".concat(this.apiUrl,"/").concat(r,"/").concat(n,"/users/").concat(o,"/token/rtc?channelName=").concat(e),type:"GET",dataType:"json",headers:{Authorization:"Bearer "+a,"Content-Type":"application/json"}};return i.RD.call(this,s).then((function(e){return{type:e.type,data:{appId:(null==e?void 0:e.app_id)||"",RTCToken:(null==e?void 0:e.rtc_token)||"",channelName:(null==e?void 0:e.channel_name)||"",RTCUId:(null==e?void 0:e.rtcUid)||0,expire:(null==e?void 0:e.expires_in)||0}}}))}function Re(e){if(!Array.isArray(e)||0===e.length)throw Error("Invalid parameter RTCUIds: "+e);var t=this.context,r=t.orgName,n=t.appName,a=t.accessToken,o={url:"".concat(this.apiUrl,"/").concat(r,"/").concat(n,"/rtc_mapper/batch/get"),type:"POST",dataType:"json",data:JSON.stringify({data:e}),headers:{Authorization:"Bearer "+a,"Content-Type":"application/json"}};return i.RD.call(this,o).then((function(e){return{type:e.type,data:e.data||{}}}))}}},function(e){return e(e.s=9359)}])}));
1
+ !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()}(self,(function(){return(self.webpackChunkwebsdk=self.webpackChunkwebsdk||[]).push([[77],{4490:function(e,t,r){var n=r(6518),a=r(9504),o=r(4376),i=a([].reverse),s=[1,2];n({target:"Array",proto:!0,forced:String(s)===String(s.reverse())},{reverse:function(){return o(this)&&(this.length=this.length),i(this)}})},9359:function(e,t,r){r.r(t),r.d(t,{acceptContactInvite:function(){return H},acceptInvitation:function(){return J},addContact:function(){return F},addConversationMark:function(){return me},addReaction:function(){return te},addToBlackList:function(){return V},addUsersToBlacklist:function(){return W},addUsersToBlocklist:function(){return Y},declineContactInvite:function(){return K},declineInvitation:function(){return q},deleteAllMessagesAndConversations:function(){return Ie},deleteContact:function(){return G},deleteConversation:function(){return w},deleteReaction:function(){return re},deleteSession:function(){return _},fetchHistoryMessages:function(){return B},fetchUserInfoById:function(){return P},getAllContacts:function(){return he},getBlacklist:function(){return C},getBlocklist:function(){return E},getContacts:function(){return j},getContactsWithCursor:function(){return fe},getConversationlist:function(){return N},getHistoryMessages:function(){return M},getRTCToken:function(){return ke},getReactionDetail:function(){return oe},getReactionList:function(){return ne},getReactionlist:function(){return ae},getRoster:function(){return S},getSelfIdsOnOtherPlatform:function(){return Te},getServerConversations:function(){return ce},getServerConversationsByFilter:function(){return ye},getServerPinnedConversations:function(){return le},getServerPinnedMessages:function(){return je},getSessionList:function(){return R},getTokenExpireTimestamp:function(){return U},getUserIdByRTCUIds:function(){return Re},modifyMessage:function(){return ee},pinConversation:function(){return de},pinMessage:function(){return Ee},recallMessage:function(){return $},removeConversationMark:function(){return ge},removeFromBlackList:function(){return X},removeHistoryMessages:function(){return se},removeRoster:function(){return L},removeUserFromBlackList:function(){return Q},removeUserFromBlocklist:function(){return Z},reportMessage:function(){return ie},setContactRemark:function(){return pe},unbindPushToken:function(){return be},unpinMessage:function(){return Se},updateCurrentUserNick:function(){return x},updateOwnUserInfo:function(){return A},updateUserInfo:function(){return z},uploadPushToken:function(){return k},uploadToken:function(){return b}}),r(2675),r(9463),r(2259),r(8706),r(2008),r(1629),r(4423),r(4346),r(3792),r(8598),r(2062),r(4490),r(4554),r(739),r(3288),r(2010),r(9085),r(9432),r(6099),r(3362),r(8781),r(7764),r(3500),r(2953);var n=r(1750),a=r(1531),o=r(346),i=r(8678),s=r(4723),c=r(8801),u=r(3887),l=r.n(u),d=r(2056),p=r(3893),h=r(565),f=r(8232),v=r(564),m=r(5323),g=function(){return g=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e},g.apply(this,arguments)},y=function(e,t,r,n){return new(r||(r=Promise))((function(a,o){function i(e){try{c(n.next(e))}catch(e){o(e)}}function s(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}c((n=n.apply(e,t||[])).next())}))},T=function(e,t){var r,n,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(a=2&o[0]?n.return:o[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,o[1])).done)return a;switch(n=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,n=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!((a=(a=i.trys).length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],n=0}finally{r=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}},I={singleChat:"chat",chatRoom:"chatroom",groupChat:"groupchat"};function C(e){var t=n.dO.call(this).error;if(t)return Promise.reject(t);var r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c={url:this.apiUrl+"/"+a+"/"+o+"/users/"+this.user+"/blocks/users",dataType:"json",type:"GET",headers:{Authorization:"Bearer "+s},success:function(t){var r={};t.data.forEach((function(e){r[e]={name:e}})),"function"==typeof(null==e?void 0:e.success)&&e.success(t)},error:function(t){"function"==typeof(null==e?void 0:e.error)&&e.error(t)}};return d.vF.debug("Call getBlocklist"),i.RD.call(this,c,p.jz.GET_BLACK_LIST)}var E=C,S=j;function j(e){var t=this,r=n.dO.call(this).error;if(r)return Promise.reject(r);var a=this.context,o=a.orgName,s=a.appName,c=a.accessToken,u={url:this.apiUrl+"/"+o+"/"+s+"/users/"+this.user+"/contacts/users",dataType:"json",type:"GET",headers:{Authorization:"Bearer "+c},success:function(r){var n=[];r.data.forEach((function(e){n.push({name:e,subscription:"both",jid:t.context.jid})})),"function"==typeof(null==e?void 0:e.success)&&e.success(n)},error:function(t){"function"==typeof(null==e?void 0:e.error)&&e.error(t)}};return d.vF.debug("Call getContacts"),i.RD.call(this,u,p.jz.GET_CONTACTS)}function b(e){return d.vF.debug("Call uploadPushToken"),m.B.call(this,e)}var k=b;function R(e){var t=n.dO.call(this).error;if(t)return Promise.reject(t);var r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c={url:"".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/users/").concat(this.user,"/user_channels"),type:"GET",dataType:"json",headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"},success:e&&(null==e?void 0:e.success),error:e&&(null==e?void 0:e.error)};return d.vF.debug("Call getSessionList"),i.RD.call(this,c)}function N(e){var t=this,r=n.dO.call(this).error;if(r)return Promise.reject(r);var a=this.context,o=a.orgName,s=a.appName,c=a.accessToken,u=!!(e&&"number"==typeof e.pageNum&&"number"==typeof e.pageSize&&e.pageNum>0&&e.pageSize>0),l={url:"".concat(this.apiUrl,"/").concat(o,"/").concat(s,"/users/").concat(this.user,"/user_channels").concat(u?"/page":""),type:"GET",dataType:"json",headers:{Authorization:"Bearer "+c,"Content-Type":"application/json"},success:e&&(null==e?void 0:e.success),error:e&&(null==e?void 0:e.error)};return u&&(l.data={pageNum:e.pageNum,pageSize:e.pageSize}),d.vF.debug("Call getConversationlist"),i.RD.call(this,l,p.jz.GET_SESSION_LIST).then((function(e){return O.call(t,e)}))}function O(e){var t=this,r=e.data.channel_infos;return null==r||r.forEach((function(e){e.meta&&"{}"!==JSON.stringify(e.meta)?(e.meta.payload=JSON.parse(e.meta.payload),e.lastMessage=h.h.call(t,e.meta,{formatCustomExts:!1})):e.lastMessage=e.meta,delete e.meta})),e}function _(e){if(e&&"string"!=typeof e.channel)throw Error("Invalid parameter channel: ".concat(e.channel));if(e&&"singleChat"!==e.chatType&&"groupChat"!==e.chatType)throw Error("Invalid parameter chatType: ".concat(e.chatType));if(e&&"boolean"!=typeof e.deleteRoam)throw Error("Invalid parameter deleteRoam: ".concat(e.deleteRoam));var t=n.dO.call(this).error;if(t)return Promise.reject(t);var r,a=this.context,o=a.orgName,s=a.appName,c=a.accessToken,u=a.jid;r="singleChat"===e.chatType?"chat":"groupChat";var l={url:"".concat(this.apiUrl,"/").concat(o,"/").concat(s,"/user/").concat(this.user,"/user_channel?resource=").concat(u.clientResource),dataType:"json",type:"DELETE",data:JSON.stringify({channel:e.channel,type:r,delete_roam:e.deleteRoam}),headers:{Authorization:"Bearer "+c,"Content-Type":"application/json"},success:e.success,error:e.error};return d.vF.debug("Call deleteSession",e),i.RD.call(this,l,p.jz.DELETE_SESSION)}var w=_;function A(e,t){var r=n.dO.call(this).error;if(r)return Promise.reject(r);var a=this.context,o=a.orgName,s=a.appName,c=a.accessToken,u=["nickname","avatarurl","mail","phone","gender","sign","birth","ext"],l={},h=i.Wp.getEnvInfo();if("wx"===h.platform||"qq"===h.platform)if("string"==typeof e&&void 0!==t){if(!u.includes(e))throw new Error("illegal key, only these keys: nickname, avatarurl, mail, phone, gender, sign, birth, ext are allowed");l[e]=t}else{if("[object Object]"!==Object.prototype.toString.call(e))throw new Error("illegal params");u.forEach((function(t){u.includes(t)&&void 0!==e[t]&&(l[t]=e[t])}))}else if("string"==typeof e){if(!u.includes(e))throw new Error("illegal key, only these keys: nickname, avatarurl, mail, phone, gender, sign, birth, ext are allowed");l=e+"="+t}else{if("[object Object]"!==Object.prototype.toString.call(e))throw new Error("illegal params");var f=[];u.forEach((function(t){if(u.includes(t)&&void 0!==e[t]){var r=encodeURIComponent(t),n=encodeURIComponent(e[t]);f.push(r+"="+n)}})),l=f.join("&")}var v={url:"".concat(this.apiUrl,"/").concat(o,"/").concat(s,"/metadata/user/").concat(this.user),type:"PUT",data:l,dataType:"json",headers:{Authorization:"Bearer "+c,"Content-Type":"application/x-www-form-urlencoded"}};return d.vF.debug("Call updateOwnUserInfo",e),i.RD.call(this,v,p.jz.UPDATE_USER_INFO)}var z=A;function P(e,t){var r=n.dO.call(this).error;if(r)return Promise.reject(r);var a,o=this.context,s=o.orgName,c=o.appName,u=o.accessToken,l=[];if("string"==typeof e)l=[e];else{if("[object Array]"!==Object.prototype.toString.call(e))throw new Error("illegal params");l=e}a="string"==typeof t?[t]:t&&"[object Array]"===Object.prototype.toString.call(t)?t:["nickname","avatarurl","mail","phone","gender","sign","birth","ext"];var h={url:"".concat(this.apiUrl,"/").concat(s,"/").concat(c,"/metadata/user/get"),type:"POST",data:JSON.stringify({targets:l,properties:a}),dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}};return d.vF.debug("Call fetchUserInfoById",e),i.RD.call(this,h,p.jz.GET_USER_INFO)}function x(e){var t=n.dO.call(this).error;if(t)return Promise.reject(t);var r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c={url:"".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/users/").concat(this.user),type:"PUT",dataType:"json",data:JSON.stringify({nickname:e}),headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"}};return d.vF.debug("Call updateCurrentUserNick",e),i.RD.call(this,c)}function U(e){if("string"!=typeof e||""===e)throw Error('Invalid parameter: "token"');var t=this.context,r=t.orgName,n=t.appName,a={url:"".concat(this.apiUrl,"/").concat(r,"/").concat(n,"/sdk/users/").concat(this.user,"/token/expires"),type:"GET",dataType:"json",headers:{Authorization:"Bearer "+e,"Content-Type":"application/json"}};return d.vF.debug("Call getTokenExpireTimestamp",e),i.RD.call(this,a,p.jz.SDK_INTERNAL)}function B(e){var t=this;return new Promise((function(r,a){if(!e.queue)throw Error('Invalid parameter: "specified"');var o=n.dO.call(t).error;if(o)return Promise.reject(o);(function e(t){var n=this,o=t.count||20;D.call(this,{count:o,isGroup:!!t.isGroup,queue:t.queue,start:t.start,format:t.format,success:function(a){if(a.msgs.length>=o||a.is_last){var i=a.msgs.splice(0,o).reverse();t.success&&t.success(i),r(i)}else e.call(n,g(g({},t),{start:null}))},fail:function(e){a(e),t.fail&&t.fail(e)}})}).call(t,e),d.vF.debug("Call fetchHistoryMessages",e)}))}function D(e){var t=this,r=e.queue,n=this.mr_cache[r]||(this.mr_cache[r]={msgs:[]}),s=this.context.userId,u=e.start||-1,d=e.count||20;if(n.msgs.length>=d||n.is_last)"function"==typeof e.success&&e.success(n);else{n&&n.next_key&&(u=n.next_key),e.start&&(u=e.start);var h={queue:r+(e.isGroup?"@conference.easemob.com":"@easemob.com"),start:u,end:-1},f=this.context,v=f.orgName,m=f.appName,g={url:"".concat(this.apiUrl,"/").concat(v,"/").concat(m,"/users/").concat(s,"/messageroaming"),dataType:"json",type:"POST",headers:{Authorization:"Bearer "+this.token,"Content-Type":"application/json"},data:JSON.stringify(h),success:function(r){return y(t,void 0,void 0,(function(){var t,a,o,i,s,u,d=this;return T(this,(function(p){switch(p.label){case 0:if(t=null==r?void 0:r.data,!r.data.msgs)return"function"==typeof e.success&&e.success(n),n.is_last=!0,n.next_key="",[2];a=t.msgs,o=a.length,n.is_last=t.is_last,n.next_key=t.next_key,i=function(t){return y(d,void 0,void 0,(function(){var r,n,a,o,i;return T(this,(function(s){switch(s.label){case 0:for(r=[],t=l().atob(t),n=0,a=t.length;n<a;++n)r.push(t.charCodeAt(n));return o=(o=this.context.root.lookup("easemob.pb.Meta")).decode(r),i={errorCode:0,reason:""},1!==o.ns?[3,2]:[4,c.Ay.call(this,o,i,!0,e.format)];case 1:return[2,s.sent()];case 2:return[2]}}))}))},s=0,p.label=1;case 1:return s<o?[4,i(a[s].msg)]:[3,4];case 2:(u=p.sent())&&n.msgs.push(u),p.label=3;case 3:return s++,[3,1];case 4:return"function"==typeof e.success&&e.success(n),[2]}}))}))},error:function(e){if(e.error&&e.error_description){var r=o.A.create({type:a.C.WEBIM_CONNCTION_AJAX_ERROR,message:"fetch history messages error",data:e});t.onError&&t.onError(r)}}};i.RD.call(this,g,p.jz.GET_HISTORY_MSG).catch((function(t){"function"==typeof e.fail&&e.fail(t)}))}}function M(e){var t=this;return new Promise((function(r,a){var o=e.targetId,s=e.cursor,u=void 0===s?-1:s,h=e.pageSize,f=void 0===h?20:h,v=e.chatType,m=e.searchDirection,g=e.searchOptions,I=void 0===g?{}:g,C=I.msgTypes,E=void 0===C?[]:C,S=I.startTime,j=void 0===S?null:S,b=I.endTime,k=void 0===b?null:b,R=I.from,N=void 0===R?null:R;if("string"!=typeof o||""===o)throw Error('"Invalid parameter": "targetId"');if(N&&"string"!=typeof N)throw Error('"Invalid parameter": "searchOptions.from"');if(E&&!Array.isArray(E))throw Error('"Invalid parameter": "searchOptions.msgTypes"');if(j&&"number"!=typeof j)throw Error('"Invalid parameter": "searchOptions.startTime"');if(k&&"number"!=typeof j)throw Error('"Invalid parameter": "searchOptions.endTime"');var O=n.dO.call(t).error;if(O)return Promise.reject(O);var _=t.context,w=_.orgName,A=_.appName,z=_.userId,P="singleChat"===e.chatType?"@easemob.com":"@conference.easemob.com",x={queue:"".concat(o).concat(P),start:u,pull_number:f,is_positive:"down"===m,msgType:E.join(",")||"",end:-1,startTime:j,endTime:k,userId:"singleChat"===v?null:N},U={url:"".concat(t.apiUrl,"/").concat(w,"/").concat(A,"/users/").concat(z,"/messageroaming"),dataType:"json",type:"POST",headers:{Authorization:"Bearer "+t.token,"Content-Type":"application/json"},data:JSON.stringify(x),success:function(n){return y(t,void 0,void 0,(function(){var t,a,o,i,s,u,d,p,h=this;return T(this,(function(f){switch(f.label){case 0:t=null==n?void 0:n.data,a=t.msgs||[],o=function(e){return y(h,void 0,void 0,(function(){var t,r,n,a,o;return T(this,(function(i){switch(i.label){case 0:for(t=[],e=l().atob(e),r=0,n=e.length;r<n;++r)t.push(e.charCodeAt(r));return a=(a=this.context.root.lookup("easemob.pb.Meta")).decode(t),o={errorCode:0,reason:""},1!==a.ns?[3,2]:[4,c.Ay.call(this,a,o,!0,!0)];case 1:return[2,i.sent()];case 2:return[2]}}))}))},i=[],s=0,f.label=1;case 1:return s<a.length?[4,o(a[s].msg)]:[3,4];case 2:(u=f.sent())&&i.push(u),f.label=3;case 3:return s++,[3,1];case 4:return t.msgs=i,d={cursor:t.next_key,messages:i,isLast:t.is_last},null===(p=e.success)||void 0===p||p.call(e,d),r(d),[2]}}))}))},error:e.fail};i.RD.call(t,U,p.jz.REST_FETCHHISTORYMESSAGE).catch((function(e){a(e)})),d.vF.debug("Call getHistoryMessages",e)}))}function F(e,t){return y(this,void 0,void 0,(function(){var r,a,o,s,c,u,l;return T(this,(function(h){switch(h.label){case 0:if(r=n.dO.call(this).error)return[2,Promise.reject(r)];if("string"!=typeof e||""===e)throw Error('"Invalid parameter": "to"');return d.vF.debug("Call addContact",e,t),a=this.context,o=a.orgName,s=a.appName,c=a.accessToken,u=a.jid,l={url:"".concat(this.apiUrl,"/").concat(o,"/").concat(s,"/users/").concat(this.user,"/contacts/apply?resource=").concat(u.clientResource),type:"POST",dataType:"json",data:JSON.stringify({usernames:[e],reason:t}),headers:{Authorization:"Bearer "+c,"Content-Type":"application/json"}},[4,i.RD.call(this,l,p.jz.ROSTER_ADD)];case 1:return h.sent(),[2]}}))}))}var L=G;function G(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u;return T(this,(function(l){switch(l.label){case 0:if(t=n.dO.call(this).error)return[2,Promise.reject(t)];if("string"!=typeof e||""===e)throw Error('"Invalid parameter": "to"');return d.vF.debug("Call deleteContact",e),r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c=r.jid,u={url:"".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/users/").concat(this.user,"/contacts/users/").concat(e,"?resource=").concat(c.clientResource),type:"DELETE",dataType:"json",headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"}},[4,i.RD.call(this,u,p.jz.ROSTER_REMOVE)];case 1:return l.sent(),[2]}}))}))}function J(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u;return T(this,(function(l){switch(l.label){case 0:if(t=n.dO.call(this).error)return[2,Promise.reject(t)];if("string"!=typeof e||""===e)throw Error('"Invalid parameter": "to"');return d.vF.debug("Call acceptInvitation",e),r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c=r.jid,u={url:"".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/users/").concat(this.user,"/contacts/accept/users/").concat(e,"?resource=").concat(c.clientResource),type:"POST",dataType:"json",headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"}},[4,i.RD.call(this,u,p.jz.ROSTER_ACCEPT)];case 1:return l.sent(),[2]}}))}))}var H=J;function q(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u;return T(this,(function(l){switch(l.label){case 0:if(t=n.dO.call(this).error)return[2,Promise.reject(t)];if("string"!=typeof e||""===e)throw Error('"Invalid parameter": "to"');return d.vF.debug("Call declineInvitation",e),r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c=r.jid,u={url:"".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/users/").concat(this.user,"/contacts/decline/users/").concat(e,"?resource=").concat(c.clientResource),type:"POST",dataType:"json",headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"}},[4,i.RD.call(this,u,p.jz.ROSTER_DECLINE)];case 1:return l.sent(),[2]}}))}))}var K=q;function V(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u,l,h;return T(this,(function(f){switch(f.label){case 0:if(t=n.dO.call(this).error)return[2,Promise.reject(t)];if(r=e.name,a=[],"string"==typeof r){if(""===r)throw Error('"Invalid parameter": "name"');a=[r]}else{if(!Array.isArray(r))throw Error('"Invalid parameter": "name"');a=r}return d.vF.debug("Call addToBlockList",e),o=this.context,s=o.orgName,c=o.appName,u=o.accessToken,l=o.jid,h={url:"".concat(this.apiUrl,"/").concat(s,"/").concat(c,"/sdk/user/").concat(this.user,"/blocks?resource=").concat(l.clientResource),type:"POST",dataType:"json",data:JSON.stringify({usernames:a}),headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}},[4,i.RD.call(this,h,p.jz.ROSTER_BAN).then((function(e){return{type:e.type,data:{userIds:(null==e?void 0:e.data)||[]}}}))];case 1:return[2,f.sent()]}}))}))}var W=V,Y=V;function X(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u,l,h;return T(this,(function(f){switch(f.label){case 0:if(t=n.dO.call(this).error)return[2,Promise.reject(t)];if(r=e.name,a=[],"string"==typeof r){if(""===r)throw Error('"Invalid parameter": "name"');a=[r]}else{if(!Array.isArray(r))throw Error('"Invalid parameter": "name"');a=r}return d.vF.debug("Call removeFromBlockList",e),o=this.context,s=o.orgName,c=o.appName,u=o.accessToken,l=o.jid,h={url:"".concat(this.apiUrl,"/").concat(s,"/").concat(c,"/sdk/user/").concat(this.user,"/blocks?resource=").concat(l.clientResource),type:"DELETE",dataType:"json",data:JSON.stringify({usernames:a}),headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}},[4,i.RD.call(this,h,p.jz.ROSTER_ALLOW)];case 1:return f.sent(),[2]}}))}))}var Q=X,Z=X;function $(e){var t=this,r=(null==e?void 0:e.ext)||"";if("string"!=typeof r)throw Error('"Invalid parameter": "ext"',r);var n=this.getUniqueId(),a={id:n,to:e.to};this._msgHash[n]=g({},a);var o="";void 0!==e.chatType?o=e.chatType:void 0!==e.type&&(o="chat"===e.type?"singleChat":e.type);var i={id:n,type:"recall",chatType:o,ackId:e.mid,to:e.to,isChatThread:e.isChatThread||!1,metaExt:r,success:function(r){return y(t,void 0,void 0,(function(){var t,n,a,i,s,c,u,l,d;return T(this,(function(p){switch(p.label){case 0:return p.trys.push([0,5,,6]),"singleChat"!==o&&"groupChat"!==o?[3,4]:[4,null===(a=null===(n=this._localCache)||void 0===n?void 0:n.getInstance())||void 0===a?void 0:a.removeMsgByServerMsgId(e.mid)];case 1:return p.sent(),[4,null===(s=null===(i=this._localCache)||void 0===i?void 0:i.getInstance())||void 0===s?void 0:s.getConversationLastMessage(e.to,o)];case 2:return t=p.sent(),[4,null===(u=null===(c=this._localCache)||void 0===c?void 0:c.getInstance())||void 0===u?void 0:u.updateLocalConversation((0,v.u0)({conversationId:e.to,conversationType:o}),{lastMessageId:null==t?void 0:t.serverMsgId})];case 3:p.sent(),p.label=4;case 4:return null===(l=null==e?void 0:e.success)||void 0===l||l.call(e,r),[3,6];case 5:return p.sent(),null===(d=null==e?void 0:e.success)||void 0===d||d.call(e,r),[3,6];case 6:return[2]}}))}))},fail:e.fail};return d.vF.debug("Call recallMessage",e),this.mSync.send(i,this)}function ee(e){var t=e||{},r=t.messageId,n=t.modifiedMessage;if(d.vF.debug("Call modifyMessage",r,n),""===r)throw Error('Invalid parameter: "messageId"');return this.mSync.send(g({editMessageId:r},n))}function te(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u,l,d;return T(this,(function(p){switch(p.label){case 0:if("string"!=typeof e.messageId||!e.messageId)throw Error("Invalid parameter messageId: ".concat(e.messageId));if("string"!=typeof e.reaction||!e.reaction)throw Error("Invalid parameter reaction: ".concat(e.reaction));return(t=n.dO.call(this).error)?[2,Promise.reject(t)]:(r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c=e.reaction,u=e.messageId,l={msgId:u,message:c},d={url:"".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/reaction/user/").concat(this.user),type:"POST",data:JSON.stringify(l),dataType:"json",headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"}},[4,i.RD.call(this,d)]);case 1:return p.sent(),[2]}}))}))}function re(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u,l;return T(this,(function(d){switch(d.label){case 0:if("string"!=typeof e.reaction||!e.reaction)throw Error("Invalid parameter reactionId: ".concat(e.reaction));return(t=n.dO.call(this).error)?[2,Promise.reject(t)]:(r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c=e.messageId,u=e.reaction,l={url:"".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/reaction/user/").concat(this.user,"?msgId=").concat(c,"&message=").concat(u),type:"DELETE",dataType:"json",headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"}},[4,i.RD.call(this,l)]);case 1:return d.sent(),[2]}}))}))}function ne(e){if("string"!=typeof e.chatType||!e.chatType)throw Error("Invalid parameter chatType: ".concat(e.chatType));if(!e.messageId)throw Error("Invalid parameter messageId: ".concat(e.messageId));var t=n.dO.call(this).error;if(t)return Promise.reject(t);var r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c=e.chatType,u=e.messageId,l={msgIdList:"string"==typeof u?[u]:u,msgType:"singleChat"===c?"chat":"groupchat",groupId:e.groupId||null},d={url:"".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/reaction/user/").concat(this.user),type:"GET",data:l,dataType:"json",headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"}};return i.RD.call(this,d).then((function(e){var t=e.data;return null==t||t.forEach((function(e){null==e||e.reactionList.forEach((function(e){e.isAddedBySelf=e.state,delete e.state,delete e.reactionId}))})),e}))}var ae=ne;function oe(e){if("string"!=typeof e.reaction||!e.reaction)throw Error("Invalid parameter reaction: ".concat(e.reaction));if("string"!=typeof e.messageId||!e.messageId)throw Error("Invalid parameter messageId: ".concat(e.messageId));var t=n.dO.call(this).error;if(t)return Promise.reject(t);var r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c=e.cursor,u=e.pageSize,l={msgId:e.messageId,message:e.reaction,currentPage:c||null,pageSize:u||20},d={url:"".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/reaction/user/").concat(this.user,"/detail"),type:"GET",data:l,dataType:"json",headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"}};return i.RD.call(this,d).then((function(e){return e.data.isAddedBySelf=e.data.state,delete e.data.state,delete e.data.reactionId,e}))}function ie(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u,l,d,p,h;return T(this,(function(f){switch(f.label){case 0:if("string"!=typeof e.reportType||!e.reportType)throw Error("Invalid parameter reportType: ".concat(e.reportType));if("string"!=typeof e.messageId||!e.messageId)throw Error("Invalid parameter messageId: ".concat(e.messageId));if("string"!=typeof e.reportReason||!e.reportReason)throw Error("Invalid parameter messageId: ".concat(e.reportReason));return(t=n.dO.call(this).error)?[2,Promise.reject(t)]:(r=this.context,a=r.orgName,o=r.appName,s=r.accessToken,c=e.reportType,u=e.reportReason,l=e.messageId,d={username:this.user,reportType:c,reportReason:u},p="".concat(this.apiUrl,"/").concat(a,"/").concat(o,"/user/").concat(this.user,"/moderation/report/message/").concat(l),h={url:p,type:"POST",data:JSON.stringify(d),dataType:"json",headers:{Authorization:"Bearer "+s,"Content-Type":"application/json"}},[4,i.RD.call(this,h)]);case 1:return f.sent(),[2]}}))}))}function se(e){var t;return y(this,void 0,void 0,(function(){var r,a,o,s,c,u,l,p,h;return T(this,(function(f){switch(f.label){case 0:if("string"!=typeof e.targetId||""===e.targetId)throw Error('"Invalid parameter targetId": '+e.targetId);if(!["singleChat","groupChat","chatRoom"].includes(e.chatType))throw Error('"Invalid parameter chatType": '+e.chatType);if(e.beforeTimeStamp&&("number"!=typeof e.beforeTimeStamp||e.beforeTimeStamp<0||(null===(t=e.beforeTimeStamp)||void 0===t?void 0:t.toString().length)>18))throw Error('"Invalid parameter beforeTimeStamp": '+e.beforeTimeStamp);if(e.messageIds&&!(Array.isArray(e.messageIds)&&e.messageIds.length>0&&e.messageIds.length<=20))throw Error('"Invalid parameter messageIds": '+e.messageIds);if(!e.messageIds&&!e.beforeTimeStamp)throw Error("messageIds or beforeTimeStamp field is required.");return(r=n.dO.call(this).error)?[2,Promise.reject(r)]:(a=this.context,o=a.orgName,s=a.appName,c=a.userId,u="singleChat"===e.chatType?"userId":"groupId",l="singleChat"===e.chatType?"chat":"group",p=e.messageIds?"".concat(this.apiUrl,"/").concat(o,"/").concat(s,"/sdk/message/roaming/").concat(l,"/user/").concat(c,"?").concat(u,"=").concat(e.targetId,"&msgIdList=").concat(e.messageIds,"&resource=").concat(this.clientResource):"".concat(this.apiUrl,"/").concat(o,"/").concat(s,"/sdk/message/roaming/").concat(l,"/user/").concat(c,"/time?").concat(u,"=").concat(e.targetId,"&delTime=").concat(e.beforeTimeStamp,"&&resource=").concat(this.clientResource),h={url:p,dataType:"json",type:"DELETE",headers:{Authorization:"Bearer "+this.token,"Content-Type":"application/json"}},d.vF.debug("Call removeHistoryMessages",e),[4,i.RD.call(this,h)]);case 1:return f.sent(),[2]}}))}))}function ce(e){var t=this,r=n.dO.call(this).error;if(r)return Promise.reject(r);if((null==e?void 0:e.pageSize)&&"number"!=typeof e.pageSize)throw Error("Invalid parameter pageSize: ".concat(e.pageSize));if((null==e?void 0:e.cursor)&&"string"!=typeof e.cursor)throw Error("Invalid parameter cursor: ".concat(e.cursor));if((null==e?void 0:e.includeEmptyConversations)&&"boolean"!=typeof e.includeEmptyConversations)throw Error("Invalid parameter includeEmptyConversations: ".concat(e.includeEmptyConversations));var a=this.context,o=a.orgName,s=a.appName,c=a.accessToken,u={url:"".concat(this.apiUrl,"/").concat(o,"/").concat(s,"/sdk/user/").concat(this.user,"/user_channels/list?"),type:"GET",dataType:"json",data:{limit:(null==e?void 0:e.pageSize)||20,cursor:(null==e?void 0:e.cursor)||"",need_mark:!0,needEmptySession:(null==e?void 0:e.includeEmptyConversations)||!1},headers:{Authorization:"Bearer "+c,"Content-Type":"application/json"}};return d.vF.debug("Call getServerConversations",e),new Promise((function(e,r){i.RD.call(t,u,p.jz.REST_FETCH_CONVERSATIONS).then((function(r){return y(t,void 0,void 0,(function(){var t,n,a=this;return T(this,(function(o){switch(o.label){case 0:return t=ue.call(this,r),this._localCache?(n=t.data.conversations.map((function(e){return y(a,void 0,void 0,(function(){var t,r,n,a;return T(this,(function(o){switch(o.label){case 0:return[4,null===(r=null===(t=this._localCache)||void 0===t?void 0:t.getInstance())||void 0===r?void 0:r.storeMessage(e.lastMessage,f.q.SUCCESS,!0)];case 1:return o.sent(),[4,null===(a=null===(n=this._localCache)||void 0===n?void 0:n.getInstance())||void 0===a?void 0:a.updateLocalConversation((0,v.u0)({conversationId:e.conversationId,conversationType:e.conversationType}),{unReadCount:e.unReadCount})];case 2:return o.sent(),[2]}}))}))})),[4,Promise.all(n)]):[3,2];case 1:o.sent(),o.label=2;case 2:return e(t),[2]}}))}))})).catch((function(e){r(e)}))}))}function ue(e){var t=this,r=e.data,n=r.cursor,a=r.channel_infos,o=[];null==a||a.forEach((function(e){var r=null;(null==e?void 0:e.meta)&&"{}"!==JSON.stringify(e.meta)&&(e.meta.payload=JSON.parse(e.meta.payload),"delivery"!==(r=h.h.call(t,e.meta)).type&&"read"!==r.type&&"channel"!==r.type&&(r.chatType=h.p[r.chatType]));var n={conversationId:e.session_to,conversationType:"chat"===e.session_type?"singleChat":"groupChat",isPinned:e.is_top,pinnedTime:e.is_top?e.update_top_status_time:0,unReadCount:e.unread_num,lastMessage:r};e.marks&&(n.marks=e.marks.map((function(e){return s.s[e]}))),o.push(n)}));var i={conversations:o,cursor:n||""};return{type:e.type,data:i}}function le(e){var t=this,r=n.dO.call(this).error;if(r)return Promise.reject(r);if((null==e?void 0:e.pageSize)&&"number"!=typeof e.pageSize)throw Error("Invalid parameter pageSize: ".concat(e.pageSize));if((null==e?void 0:e.cursor)&&"string"!=typeof e.cursor)throw Error("Invalid parameter cursor: ".concat(e.cursor));if((null==e?void 0:e.includeEmptyConversations)&&"boolean"!=typeof e.includeEmptyConversations)throw Error("Invalid parameter includeEmptyConversations: ".concat(e.includeEmptyConversations));var a=this.context,o=a.orgName,s=a.appName,c=a.accessToken,u={url:"".concat(this.apiUrl,"/").concat(o,"/").concat(s,"/sdk/user/").concat(this.user,"/user_channels/list?"),type:"GET",dataType:"json",data:{limit:(null==e?void 0:e.pageSize)||20,cursor:(null==e?void 0:e.cursor)||"",is_top:!0,need_mark:!0,needEmptySession:(null==e?void 0:e.includeEmptyConversations)||!1},headers:{Authorization:"Bearer "+c,"Content-Type":"application/json"}};return d.vF.debug("Call getServerPinnedConversations",e),i.RD.call(this,u,p.jz.GET_SESSION_LIST).then((function(e){return ue.call(t,e)}))}function de(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u,l,h,f,v,m,g,y;return T(this,(function(T){if(t=n.dO.call(this).error)return[2,Promise.reject(t)];if(r=e.conversationId,a=e.conversationType,o=e.isPinned,s="singleChat"===a?"chat":"groupChat","string"!=typeof r||""===r)throw Error("Invalid parameter conversationId: ".concat(r));if(!["singleChat","groupChat"].includes(a))throw Error("Invalid parameter conversationType: ".concat(a));if("boolean"!=typeof o)throw Error("Invalid parameter isPinned: ".concat(o));return c=this.context,u=c.orgName,l=c.appName,h=c.accessToken,f=c.jid,v={type:s,to:r},m=o?"":"type=".concat(s,"&to=").concat(r,"&"),g="".concat(this.apiUrl,"/").concat(u,"/").concat(l,"/sdk/user/").concat(this.user,"/user_channel/top?").concat(m,"resource=").concat(f.clientResource),y={url:g,type:o?"POST":"DELETE",dataType:"json",headers:{Authorization:"Bearer "+h,"Content-Type":"application/json"}},o&&(y.data=JSON.stringify(v)),d.vF.debug("Call pinConversation",e),[2,i.RD.call(this,y,p.jz.PIN_CONVERSATION).then((function(e){var t=e.type,r=e.data;return{type:t,data:{isPinned:r.is_top||!1,pinnedTime:r.is_top?r.update_top_status_time:0}}}))]}))}))}function pe(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u,l,h,f;return T(this,(function(v){switch(v.label){case 0:if(t=e.userId,r=e.remark,a=n.dO.call(this).error)return[2,Promise.reject(a)];if("string"!=typeof t||""===t)throw Error('Invalid parameter: "userId"');if("string"!=typeof r)throw Error('Invalid parameter: "remark"');return d.vF.debug("Call setContactRemark",e),o=this.context,s=o.orgName,c=o.appName,u=o.accessToken,l=o.jid,h="".concat(this.apiUrl,"/").concat(s,"/").concat(c,"/users/").concat(this.context.userId,"/contacts/users/").concat(t,"?resource=").concat(l.clientResource),f={url:h,type:"PUT",data:JSON.stringify({remark:r}),dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}},[4,i.RD.call(this,f,p.jz.ROSTER_SET_CONTACT_REMARK)];case 1:return v.sent(),[2]}}))}))}function he(){var e=n.dO.call(this).error;if(e)return Promise.reject(e);var t=this.context,r=t.orgName,a=t.appName,o=t.accessToken,s={url:"".concat(this.apiUrl,"/").concat(r,"/").concat(a,"/users/").concat(this.user,"/contacts/users?needReturnRemark=true"),dataType:"json",type:"GET",headers:{Authorization:"Bearer "+o}};return d.vF.debug("Call getAllContacts"),i.RD.call(this,s,p.jz.ROSTER_GET_ALL_CONTACTS_REMARKS).then((function(e){var t=((null==e?void 0:e.entities)||[]).map((function(e){return{userId:e.username,remark:e.remark}}));return{type:e.type,data:t}}))}function fe(e){var t=n.dO.call(this).error;if(t)return Promise.reject(t);d.vF.debug("Call getContactsWithCursor",e);var r=e||{},a=r.pageSize,o=void 0===a?20:a,s=r.cursor,c=void 0===s?"":s;if(o&&"number"!=typeof o)throw Error("Invalid parameter pageSize: ".concat(e.pageSize));var u=this.context,l=u.orgName,h=u.appName,f=u.accessToken,v={url:"".concat(this.apiUrl,"/").concat(l,"/").concat(h,"/users/").concat(this.user,"/contacts?needReturnRemark=true&limit=").concat(o,"&cursor=").concat(c),dataType:"json",type:"GET",headers:{Authorization:"Bearer "+f}};return i.RD.call(this,v,p.jz.ROSTER_GET_ALL_CONTACTS_REMARKS_FROM_SERVER_BY_PAGE).then((function(e){var t,r,n=(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.contacts)||[],a=(null===(r=null==e?void 0:e.data)||void 0===r?void 0:r.cursor)||"",o=n.map((function(e){return{userId:e.username,remark:e.remark}}));return{type:e.type,data:{cursor:a,contacts:o}}}))}function ve(e){return y(this,void 0,void 0,(function(){var t,r,a,o,c,u,l,f,v,m,g,y,C,E,S;return T(this,(function(T){switch(T.label){case 0:if(t=n.dO.call(this).error)return[2,Promise.reject(t)];if(d.vF.debug("Call markConversation",e),a=(r=e||{}).conversations,o=void 0===a?[]:a,c=r.mark,u=r.isMarked,!Array.isArray(o))throw Error("Invalid parameter conversations");if(l=o.map((function(e){if(!e.conversationId||!["singleChat","groupChat"].includes(e.conversationType))throw Error("Invalid parameter conversations");return{to:e.conversationId,type:I[e.conversationType]}})),"boolean"!=typeof u)throw Error("Invalid parameter isMarked: ".concat(u));if("number"!=typeof c)throw Error("Invalid parameter mark: ".concat(c));return f=this.context,v=f.orgName,m=f.appName,g=f.accessToken,y=f.userId,C=f.jid,E={mark:s.s[c],targets:l},S={url:"".concat(this.apiUrl,"/").concat(v,"/").concat(m,"/sdk/user/").concat(y,"/user_channels/mark?resource=").concat(C.clientResource),dataType:"json",data:JSON.stringify(E),type:u?"Post":"Delete",headers:{Authorization:"Bearer "+g}},[4,i.RD.call(this,S,p.jz.MARK_CONVERSATION).then((function(e){var t,r=(null===(t=e.data)||void 0===t?void 0:t.ignore)||[];r&&Array.isArray(r)&&r.length>0&&d.vF.debug("markConversation has ignored conversations",r.map((function(e){return{conversationId:e.to,conversationType:h.p[e.type]}})))}))];case 1:return T.sent(),[2]}}))}))}function me(e){return y(this,void 0,void 0,(function(){var t,r;return T(this,(function(n){return d.vF.debug("Call addConversationMark",e),t=e.conversations,r=e.mark,[2,ve.call(this,{conversations:t,mark:r,isMarked:!0})]}))}))}function ge(e){return y(this,void 0,void 0,(function(){var t,r;return T(this,(function(n){return d.vF.debug("Call removeConversationMark",e),t=e.conversations,r=e.mark,[2,ve.call(this,{conversations:t,mark:r,isMarked:!1})]}))}))}function ye(e){var t,r,a=this,o=n.dO.call(this).error;if(o)return Promise.reject(o);if(d.vF.debug("Call getServerConversationsByFilter",e),(null==e?void 0:e.pageSize)&&"number"!=typeof e.pageSize)throw Error("Invalid parameter pageSize: ".concat(e.pageSize));if((null==e?void 0:e.cursor)&&"string"!=typeof e.cursor)throw Error("Invalid parameter cursor: ".concat(e.cursor));if("number"!=typeof(null===(t=null==e?void 0:e.filter)||void 0===t?void 0:t.mark))throw Error("Invalid parameter mark: ".concat(null===(r=null==e?void 0:e.filter)||void 0===r?void 0:r.mark));var c=this.context,u=c.orgName,l=c.appName,h=c.accessToken,f="".concat(this.apiUrl,"/").concat(u,"/").concat(l,"/sdk/user/").concat(this.user,"/user_channels/mark/search?"),v=e.pageSize,m=e.cursor,g=((null==e?void 0:e.filter)||{}).mark,y={url:f,type:"GET",dataType:"json",data:{limit:v||10,cursor:m||"",need_mark:!0,mark:s.s[g]},headers:{Authorization:"Bearer "+h,"Content-Type":"application/json"}};return i.RD.call(this,y,p.jz.GET_SESSION_LIST).then((function(e){return ue.call(a,e)}))}function Te(){var e=n.dO.call(this).error;if(e)return Promise.reject(e);d.vF.debug("Call getSelfIdsOnOtherPlatform");var t=this.context,r=t.orgName,a=t.appName,o=t.accessToken,s=t.userId,c=t.jid,u={url:"".concat(this.apiUrl,"/").concat(r,"/").concat(a,"/users/").concat(s,"/resources"),type:"GET",dataType:"json",headers:{Authorization:"Bearer "+o,"Content-Type":"application/json"}};return i.RD.call(this,u,p.jz.USER_LOGGEDIN_OTHER_PLATFORM).then((function(e){var t,r=null===(t=e.data)||void 0===t?void 0:t.filter((function(e){return e.res!==c.clientResource})),n=null==r?void 0:r.map((function(e){return"".concat(s,"/").concat(e.res)}));return{type:e.type,data:n}}))}function Ie(){var e,t,r,a,o,s;return y(this,void 0,void 0,(function(){var c,u,l,h,f,v,m,g,y;return T(this,(function(T){switch(T.label){case 0:return(c=n.dO.call(this).error)?[2,Promise.reject(c)]:(d.vF.debug("Call deleteAllMessagesAndConversations"),u=this.context,l=u.orgName,h=u.appName,f=u.accessToken,v=u.userId,m=u.jid,g="".concat(this.apiUrl,"/").concat(l,"/").concat(h,"/sdk/message/roaming/user/").concat(v,"/delete/all?resource=").concat(m.clientResource),y={url:g,type:"POST",dataType:"json",headers:{Authorization:"Bearer "+f,"Content-Type":"application/json"}},[4,i.RD.call(this,y,p.jz.REST_DELETE_MESSAGES_CONVERSATIONS)]);case 1:return T.sent(),null===(t=null===(e=this._localCache)||void 0===e?void 0:e.getInstance())||void 0===t||t.clearConversationMap(),[4,null===(a=null===(r=this._localCache)||void 0===r?void 0:r.getInstance())||void 0===a?void 0:a.clearStoreData("conversationList")];case 2:return T.sent(),[4,null===(s=null===(o=this._localCache)||void 0===o?void 0:o.getInstance())||void 0===s?void 0:s.clearStoreData("message")];case 3:return T.sent(),[2]}}))}))}function Ce(e){return y(this,void 0,void 0,(function(){var t,r,a,o,s,c,u,l,h,f,v,m,g,y,C;return T(this,(function(T){switch(T.label){case 0:if(t=n.dO.call(this).error)return[2,Promise.reject(t)];if(d.vF.debug("Call setMessagePinStatus",e),a=(r=e||{}).conversationId,o=void 0===a?"":a,s=r.conversationType,c=r.messageId,u=r.isPinned,"string"!=typeof o||""===o)throw Error("Invalid parameter conversationId");if("string"!=typeof c||""===c)throw Error("Invalid parameter messageId");if("boolean"!=typeof u)throw Error("Invalid parameter isPinned");return l=this.context,h=l.orgName,f=l.appName,v=l.accessToken,m=l.userId,g=l.jid,y={to:o,type:I[s],pin_msg_id:c},C={url:"".concat(this.apiUrl,"/").concat(h,"/").concat(f,"/sdk/user/").concat(m,"/user_channel/pin?resource=").concat(g.clientResource),dataType:"json",data:JSON.stringify(y),type:u?"Post":"Delete",headers:{Authorization:"Bearer "+v}},[4,i.RD.call(this,C,p.jz.REST_PIN_MESSAGE)];case 1:return T.sent(),[2]}}))}))}function Ee(e){return y(this,void 0,void 0,(function(){var t,r,n,a;return T(this,(function(o){return d.vF.debug("Call pinMessage",e),r=(t=e||{}).conversationType,n=t.conversationId,a=t.messageId,[2,Ce.call(this,{conversationId:n,conversationType:r,messageId:a,isPinned:!0})]}))}))}function Se(e){return y(this,void 0,void 0,(function(){var t,r,n,a;return T(this,(function(o){return d.vF.debug("Call unpinMessage",e),r=(t=e||{}).conversationType,n=t.conversationId,a=t.messageId,[2,Ce.call(this,{conversationId:n,conversationType:r,messageId:a,isPinned:!1})]}))}))}function je(e){var t=this,r=n.dO.call(this).error;if(r)return Promise.reject(r);d.vF.debug("Call getServerPinnedMessages",e);var a=e.conversationId,o=e.conversationType,s=e.pageSize,c=e.cursor;if("string"!=typeof a||""===a)throw Error("Invalid parameter conversationId");if(s&&"number"!=typeof s)throw Error("Invalid parameter pageSize: ".concat(s));if(c&&"string"!=typeof c)throw Error("Invalid parameter cursor: ".concat(c));var u=this.context,l=u.orgName,f=u.appName,v=u.accessToken,m={url:"".concat(this.apiUrl,"/").concat(l,"/").concat(f,"/sdk/user/").concat(this.user,"/user_channel/pin"),type:"GET",dataType:"json",data:{to:a,type:I[o],limit:s||10,cursor:c||""},headers:{Authorization:"Bearer "+v,"Content-Type":"application/json"}};return i.RD.call(this,m,p.jz.GET_SESSION_LIST).then((function(e){return{type:0,data:{list:e.data.msg_infos.map((function(e){e.message.payload=JSON.parse(e.message.payload);var r=e.message,n=e.pin_opt_at,a=e.pin_operator;return{message:h.h.call(t,r,{formatChatType:!0}),pinTime:n,operatorId:a}})),cursor:e.data.cursor||""}}}))}function be(){var e=this;d.vF.debug("Call unbindPushToken");var t={deviceId:this.clientResource,deviceToken:"",notifierName:this.pushCertificateName};return m.B.call(this,t).then((function(t){return e.isRegisterPush=!1,t}))}function ke(e){void 0===e&&(e="*");var t=this.context,r=t.orgName,n=t.appName,a=t.accessToken,o=t.userId,s={url:"".concat(this.apiUrl,"/").concat(r,"/").concat(n,"/users/").concat(o,"/token/rtc?channelName=").concat(e),type:"GET",dataType:"json",headers:{Authorization:"Bearer "+a,"Content-Type":"application/json"}};return i.RD.call(this,s).then((function(e){return{type:e.type,data:{appId:(null==e?void 0:e.app_id)||"",RTCToken:(null==e?void 0:e.rtc_token)||"",channelName:(null==e?void 0:e.channel_name)||"",RTCUId:(null==e?void 0:e.rtcUid)||0,expire:(null==e?void 0:e.expires_in)||0}}}))}function Re(e){if(!Array.isArray(e)||0===e.length)throw Error("Invalid parameter RTCUIds: "+e);var t=this.context,r=t.orgName,n=t.appName,a=t.accessToken,o={url:"".concat(this.apiUrl,"/").concat(r,"/").concat(n,"/rtc_mapper/batch/get"),type:"POST",dataType:"json",data:JSON.stringify({data:e}),headers:{Authorization:"Bearer "+a,"Content-Type":"application/json"}};return i.RD.call(this,o).then((function(e){return{type:e.type,data:e.data||{}}}))}}},function(e){return e(e.s=9359)}])}));
@@ -1 +1 @@
1
- !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()}(self,(function(){return(self.webpackChunkwebsdk=self.webpackChunkwebsdk||[]).push([[226],{5658:function(e,t,n){n.r(t),n.d(t,{LocalCache:function(){return D},LocalCacheApi:function(){return r}});var r={};let o,s;n.r(r),n.d(r,{clearConversationUnreadCount:function(){return U},getLocalConversation:function(){return j},getLocalConversations:function(){return R},removeLocalConversation:function(){return N},setLocalConversationCustomField:function(){return P}}),n(2675),n(9463),n(2259),n(4423),n(3792),n(2062),n(3288),n(6099),n(3362),n(7764),n(2953),n(5276),n(9085);const a=new WeakMap,i=new WeakMap,c=new WeakMap,u=new WeakMap,l=new WeakMap;let d={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return i.get(e);if("objectStoreNames"===t)return e.objectStoreNames||c.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return p(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 v(e){return"function"==typeof e?(t=e)!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(s||(s=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(t)?function(...e){return t.apply(h(this),e),p(a.get(this))}:function(...e){return p(t.apply(h(this),e))}:function(e,...n){const r=t.call(h(this),e,...n);return c.set(r,e.sort?e.sort():[e]),p(r)}:(e instanceof IDBTransaction&&function(e){if(i.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)}));i.set(e,t)}(e),n=e,(o||(o=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])).some((e=>n instanceof e))?new Proxy(e,d):e);var t,n}function p(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(p(e.result)),r()},s=()=>{n(e.error),r()};e.addEventListener("success",o),e.addEventListener("error",s)}));return t.then((t=>{t instanceof IDBCursor&&a.set(t,e)})).catch((()=>{})),l.set(t,e),t}(e);if(u.has(e))return u.get(e);const t=v(e);return t!==e&&(u.set(e,t),l.set(t,e)),t}const h=e=>l.get(e);function f(e,t,{blocked:n,upgrade:r,blocking:o,terminated:s}={}){const a=indexedDB.open(e,t),i=p(a);return r&&a.addEventListener("upgradeneeded",(e=>{r(p(a.result),e.oldVersion,e.newVersion,p(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 y=["get","getKey","getAll","getAllKeys","count"],g=["put","add","delete","clear"],b=new Map;function m(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=g.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!o&&!y.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 I;I=d,d={...I,get:(e,t,n)=>m(e,t)||I.get(e,t,n),has:(e,t)=>!!m(e,t)||I.has(e,t)};var C=n(2056),w=n(564),T=n(8232),S=function(){return S=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},S.apply(this,arguments)},M=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])}}},B=new Date("2023/01/01"),D=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 M(this,void 0,void 0,(function(){var n,r,o,s;return L(this,(function(a){switch(a.label){case 0:C.vF.debug("init local cache",t),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,f(n,r,{upgrade:function(e,t,n,r){if(t<1){C.vF.debug("IndexedDB oldVersion",t);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")}if(t<2){C.vF.debug("IndexedDB version",2);var s=r.objectStore("message");s.deleteIndex("sessionTime"),s.createIndex("sessionTime",["sessionId","time"])}}})];case 2:return s=a.sent(),this.localCache=s,e.instance||(e.instance=this,this.onInit()),[3,4];case 3:return a.sent(),C.vF.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.clearConversationMap(),e.instance=void 0,C.vF.debug("close db success")},e.prototype.storeConversation=function(e,t,n,r){return M(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,w.u0)({conversationId:e,conversationType:t}),s=S({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=S(S({},a),s)),[4,this.putConversationToDB(s)];case 3:return u.sent(),[3,5];case 4:return c=u.sent(),C.vF.debug("store conversation error",c),[3,5];case 5:return[2]}}))}))},e.prototype.putConversationToDB=function(e){var t;return M(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(),C.vF.debug("put conversation to local error",n),[3,3];case 3:return[2]}}))}))},e.prototype.getConversationBySessionId=function(e){var t;return M(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(),C.vF.debug("get conversation by sessionId error",n),[3,3];case 3:return[2]}}))}))},e.prototype.removeConversationBySessionId=function(e){var t;return M(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){C.vF.debug("remove conversation by sessionId error",e)}return[2]}))}))},e.prototype.getConversationList=function(){var e;return M(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(),C.vF.debug("get local conversationList error",r),[3,7];case 7:return[2]}}))}))},e.prototype.storeMessage=function(e,t,n){return M(this,void 0,void 0,(function(){var r,o,s,a,i,c,u,l,d;return L(this,(function(v){switch(v.label){case 0:return v.trys.push([0,5,,6]),r=S({},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&&(c=r.to.indexOf("/"),u=c>-1?r.to.substring(0,c):r.to,this.user===u&&r.from&&r.from!==this.user&&(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,w.u0)({conversationId:a,conversationType:null==r?void 0:r.chatType}),status:t,serverMsgId:r.id}),[4,this.getMessageByServerMsgId(r.id)]);case 1:return(null==(l=v.sent())?void 0:l.status)===T.q.SUCCESS?[3,3]:[4,this.putMessageToDB(r)];case 2:v.sent(),v.label=3;case 3:return t>T.q.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 v.sent(),[3,6];case 5:return d=v.sent(),C.vF.debug("store message error",d),[3,6];case 6:return[2]}}))}))},e.prototype.updateLocalMessage=function(e,t){return void 0===t&&(t={}),M(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(S(S({},n),t))]:[3,4];case 2:return o.sent(),[4,this.updateLocalConversation((0,w.u0)({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(),C.vF.debug("update local message error",r),[3,6];case 6:return[2]}}))}))},e.prototype.updateLocalConversation=function(e,t){return M(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=S(S({},r),t);n.putConversationToDB(o),n.conversationMap[e]=o}}))]}catch(e){C.vF.debug("update local conversation error",e)}return[2]}))}))},e.prototype.removeMsgByServerMsgId=function(e){var t,n;return M(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(),C.vF.debug("remove msg by serverId error",o),[3,3];case 3:return[2]}}))}))},e.prototype.removeMsgBySessionId=function(e){var t;return M(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(),C.vF.debug("remove msg by sessionId",r),[3,7];case 7:return[2]}}))}))},e.prototype.putMessageToDB=function(e){var t;return M(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(),C.vF.debug("put msg to local error",n),[3,3];case 3:return[2]}}))}))},e.prototype.getConversationLastMessage=function(e,t){var n,r;return M(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,w.u0)({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,B.getTime()],[o,(new Date).getTime()]),"prev")];case 1:return(s=i.sent())?[2,s.value]:[2,void 0];case 2:return a=i.sent(),C.vF.debug("get conversation last msg error",a),[3,3];case 3:return[2]}}))}))},e.prototype.getMessageByServerMsgId=function(e){var t;return M(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(),C.vF.debug("get msg by serverId error",n),[3,3];case 3:return[2]}}))}))},e.prototype.clearStoreData=function(e){var t;return M(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.clear(e)];case 1:return[2,r.sent()];case 2:return n=r.sent(),C.vF.debug("clear store data error",n),[3,3];case 3:return[2]}}))}))},e.prototype.clearConversationMap=function(){this.conversationMap={}},e}(),E=n(346),F=n(1750),A=n(1531);function k(e){return k="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},k(e)}var x=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())}))},O=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])}}},_=["singleChat","groupChat"];function R(){var e,t;return x(this,void 0,void 0,(function(){var n,r,o,s=this;return O(this,(function(a){switch(a.label){case 0:if(C.vF.debug("Call getLocalConversations"),!F.dO.call(this))return n=E.A.create({type:A.C.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 x(s,void 0,void 0,(function(){var e,s,i,c;return O(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(),E.A.create({type:A.C.LOCAL_DB_OPERATION_FAILED,message:"getLocalConversations is failed",data:o});case 5:return[2]}}))}))}function P(e){var t,n;return x(this,void 0,void 0,(function(){var r,o,s,a,i;return O(this,(function(c){switch(c.label){case 0:if(C.vF.debug("Call setLocalConversationCustomField",e),!F.dO.call(this))return r=E.A.create({type:A.C.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(r)];if(o=e.conversationType,s=e.conversationId,a=e.customField,!_.includes(o))throw Error('"Invalid parameter conversationType": '+o);if("string"!=typeof s||""===s)throw Error('Invalid parameter: "conversationId"');if("object"!==k(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,w.u0)({conversationId:s,conversationType:o}),{customField:a})];case 2:return c.sent(),[3,4];case 3:throw i=c.sent(),E.A.create({type:A.C.LOCAL_DB_OPERATION_FAILED,message:"setLocalConversationCustomField is failed",data:i});case 4:return[2]}}))}))}function j(e){var t,n,r,o;return x(this,void 0,void 0,(function(){var s,a,i,c,u,l,d,v,p;return O(this,(function(h){switch(h.label){case 0:if(C.vF.debug("Call getLocalConversation",e),!F.dO.call(this))return s=E.A.create({type:A.C.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(s)];if(a=e.conversationType,i=e.conversationId,!_.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,w.u0)({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(),E.A.create({type:A.C.LOCAL_DB_OPERATION_FAILED,message:"getLocalConversation is failed",data:d});case 9:return[2]}}))}))}function N(e){var t,n,r,o;return x(this,void 0,void 0,(function(){var s,a,i,c,u,l,d;return O(this,(function(v){switch(v.label){case 0:if(C.vF.debug("Call removeLocalConversation",e),!F.dO.call(this))return s=E.A.create({type:A.C.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,!_.includes(a))throw Error('"Invalid parameter conversationType": '+a);if("string"!=typeof i||""===i)throw Error('Invalid parameter: "conversationId"');l=(0,w.u0)({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(),E.A.create({type:A.C.LOCAL_DB_OPERATION_FAILED,message:"removeLocalConversation is failed",data:d});case 6:return[2]}}))}))}function U(e){var t,n;return x(this,void 0,void 0,(function(){var r,o,s,a;return O(this,(function(i){switch(i.label){case 0:if(C.vF.debug("Call clearConversationUnreadCount",e),!F.dO.call(this))return r=E.A.create({type:A.C.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(r)];if(o=e.conversationType,s=e.conversationId,!_.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,w.u0)({conversationId:s,conversationType:o}),{unReadCount:0,unreadCountClearTimestamp:(new Date).getTime()})];case 2:return i.sent(),[3,4];case 3:throw a=i.sent(),E.A.create({type:A.C.LOCAL_DB_OPERATION_FAILED,message:"clearConversationUnreadCount is failed",data:a});case 4:return[2]}}))}))}}},function(e){return e(e.s=5658)}])}));
1
+ !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()}(self,(function(){return(self.webpackChunkwebsdk=self.webpackChunkwebsdk||[]).push([[226],{5658:function(e,t,n){n.r(t),n.d(t,{LocalCache:function(){return D},LocalCacheApi:function(){return r}});var r={};let o,s;n.r(r),n.d(r,{clearConversationUnreadCount:function(){return U},getLocalConversation:function(){return j},getLocalConversations:function(){return R},removeLocalConversation:function(){return N},setLocalConversationCustomField:function(){return P}}),n(2675),n(9463),n(2259),n(4423),n(3792),n(2062),n(3288),n(6099),n(3362),n(7764),n(2953),n(5276),n(9085);const a=new WeakMap,i=new WeakMap,c=new WeakMap,u=new WeakMap,l=new WeakMap;let d={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return i.get(e);if("objectStoreNames"===t)return e.objectStoreNames||c.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return p(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 v(e){return"function"==typeof e?(t=e)!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(s||(s=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(t)?function(...e){return t.apply(h(this),e),p(a.get(this))}:function(...e){return p(t.apply(h(this),e))}:function(e,...n){const r=t.call(h(this),e,...n);return c.set(r,e.sort?e.sort():[e]),p(r)}:(e instanceof IDBTransaction&&function(e){if(i.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)}));i.set(e,t)}(e),n=e,(o||(o=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])).some((e=>n instanceof e))?new Proxy(e,d):e);var t,n}function p(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(p(e.result)),r()},s=()=>{n(e.error),r()};e.addEventListener("success",o),e.addEventListener("error",s)}));return t.then((t=>{t instanceof IDBCursor&&a.set(t,e)})).catch((()=>{})),l.set(t,e),t}(e);if(u.has(e))return u.get(e);const t=v(e);return t!==e&&(u.set(e,t),l.set(t,e)),t}const h=e=>l.get(e);function f(e,t,{blocked:n,upgrade:r,blocking:o,terminated:s}={}){const a=indexedDB.open(e,t),i=p(a);return r&&a.addEventListener("upgradeneeded",(e=>{r(p(a.result),e.oldVersion,e.newVersion,p(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 y=["get","getKey","getAll","getAllKeys","count"],g=["put","add","delete","clear"],b=new Map;function m(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=g.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!o&&!y.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 I;I=d,d={...I,get:(e,t,n)=>m(e,t)||I.get(e,t,n),has:(e,t)=>!!m(e,t)||I.has(e,t)};var C=n(2056),w=n(564),T=n(8232),S=function(){return S=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},S.apply(this,arguments)},M=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])}}},B=new Date("2023/01/01"),D=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 M(this,void 0,void 0,(function(){var n,r,o,s;return L(this,(function(a){switch(a.label){case 0:C.vF.debug("init local cache",t),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,f(n,r,{upgrade:function(e,t,n,r){if(t<1){C.vF.debug("IndexedDB oldVersion",t);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")}if(t<2){C.vF.debug("IndexedDB version",2);var s=r.objectStore("message");s.deleteIndex("sessionTime"),s.createIndex("sessionTime",["sessionId","time"])}}})];case 2:return s=a.sent(),this.localCache=s,e.instance||(e.instance=this,this.onInit()),[3,4];case 3:return a.sent(),C.vF.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.clearConversationMap(),e.instance=void 0,C.vF.debug("close db success")},e.prototype.storeConversation=function(e,t,n,r){return M(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,w.u0)({conversationId:e,conversationType:t}),s=S({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=S(S({},a),s)),[4,this.putConversationToDB(s)];case 3:return u.sent(),[3,5];case 4:return c=u.sent(),C.vF.debug("store conversation error",c),[3,5];case 5:return[2]}}))}))},e.prototype.putConversationToDB=function(e){var t;return M(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(),C.vF.debug("put conversation to local error",n),[3,3];case 3:return[2]}}))}))},e.prototype.getConversationBySessionId=function(e){var t;return M(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(),C.vF.debug("get conversation by sessionId error",n),[3,3];case 3:return[2]}}))}))},e.prototype.removeConversationBySessionId=function(e){var t;return M(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){C.vF.debug("remove conversation by sessionId error",e)}return[2]}))}))},e.prototype.getConversationList=function(){var e;return M(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(),C.vF.debug("get local conversationList error",r),[3,7];case 7:return[2]}}))}))},e.prototype.storeMessage=function(e,t,n){return M(this,void 0,void 0,(function(){var r,o,s,a,i,c,u,l,d;return L(this,(function(v){switch(v.label){case 0:if(!e||!e.id)return[2];v.label=1;case 1:return v.trys.push([1,6,,7]),r=S({},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&&(c=r.to.indexOf("/"),u=c>-1?r.to.substring(0,c):r.to,this.user===u&&r.from&&r.from!==this.user&&(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,w.u0)({conversationId:a,conversationType:null==r?void 0:r.chatType}),status:t,serverMsgId:r.id}),[4,this.getMessageByServerMsgId(r.id)]);case 2:return(null==(l=v.sent())?void 0:l.status)===T.q.SUCCESS?[3,4]:[4,this.putMessageToDB(r)];case 3:v.sent(),v.label=4;case 4:return t>T.q.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 5:return v.sent(),[3,7];case 6:return d=v.sent(),C.vF.debug("store message error",d),[3,7];case 7:return[2]}}))}))},e.prototype.updateLocalMessage=function(e,t){return void 0===t&&(t={}),M(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(S(S({},n),t))]:[3,4];case 2:return o.sent(),[4,this.updateLocalConversation((0,w.u0)({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(),C.vF.debug("update local message error",r),[3,6];case 6:return[2]}}))}))},e.prototype.updateLocalConversation=function(e,t){return M(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=S(S({},r),t);n.putConversationToDB(o),n.conversationMap[e]=o}}))]}catch(e){C.vF.debug("update local conversation error",e)}return[2]}))}))},e.prototype.removeMsgByServerMsgId=function(e){var t,n;return M(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(),C.vF.debug("remove msg by serverId error",o),[3,3];case 3:return[2]}}))}))},e.prototype.removeMsgBySessionId=function(e){var t;return M(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(),C.vF.debug("remove msg by sessionId",r),[3,7];case 7:return[2]}}))}))},e.prototype.putMessageToDB=function(e){var t;return M(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(),C.vF.debug("put msg to local error",n),[3,3];case 3:return[2]}}))}))},e.prototype.getConversationLastMessage=function(e,t){var n,r;return M(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,w.u0)({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,B.getTime()],[o,(new Date).getTime()]),"prev")];case 1:return(s=i.sent())?[2,s.value]:[2,void 0];case 2:return a=i.sent(),C.vF.debug("get conversation last msg error",a),[3,3];case 3:return[2]}}))}))},e.prototype.getMessageByServerMsgId=function(e){var t;return M(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(),C.vF.debug("get msg by serverId error",n),[3,3];case 3:return[2]}}))}))},e.prototype.clearStoreData=function(e){var t;return M(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.clear(e)];case 1:return[2,r.sent()];case 2:return n=r.sent(),C.vF.debug("clear store data error",n),[3,3];case 3:return[2]}}))}))},e.prototype.clearConversationMap=function(){this.conversationMap={}},e}(),E=n(346),F=n(1750),A=n(1531);function k(e){return k="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},k(e)}var x=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())}))},O=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])}}},_=["singleChat","groupChat"];function R(){var e,t;return x(this,void 0,void 0,(function(){var n,r,o,s=this;return O(this,(function(a){switch(a.label){case 0:if(C.vF.debug("Call getLocalConversations"),!F.dO.call(this))return n=E.A.create({type:A.C.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 x(s,void 0,void 0,(function(){var e,s,i,c;return O(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(),E.A.create({type:A.C.LOCAL_DB_OPERATION_FAILED,message:"getLocalConversations is failed",data:o});case 5:return[2]}}))}))}function P(e){var t,n;return x(this,void 0,void 0,(function(){var r,o,s,a,i;return O(this,(function(c){switch(c.label){case 0:if(C.vF.debug("Call setLocalConversationCustomField",e),!F.dO.call(this))return r=E.A.create({type:A.C.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(r)];if(o=e.conversationType,s=e.conversationId,a=e.customField,!_.includes(o))throw Error('"Invalid parameter conversationType": '+o);if("string"!=typeof s||""===s)throw Error('Invalid parameter: "conversationId"');if("object"!==k(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,w.u0)({conversationId:s,conversationType:o}),{customField:a})];case 2:return c.sent(),[3,4];case 3:throw i=c.sent(),E.A.create({type:A.C.LOCAL_DB_OPERATION_FAILED,message:"setLocalConversationCustomField is failed",data:i});case 4:return[2]}}))}))}function j(e){var t,n,r,o;return x(this,void 0,void 0,(function(){var s,a,i,c,u,l,d,v,p;return O(this,(function(h){switch(h.label){case 0:if(C.vF.debug("Call getLocalConversation",e),!F.dO.call(this))return s=E.A.create({type:A.C.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(s)];if(a=e.conversationType,i=e.conversationId,!_.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,w.u0)({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(),E.A.create({type:A.C.LOCAL_DB_OPERATION_FAILED,message:"getLocalConversation is failed",data:d});case 9:return[2]}}))}))}function N(e){var t,n,r,o;return x(this,void 0,void 0,(function(){var s,a,i,c,u,l,d;return O(this,(function(v){switch(v.label){case 0:if(C.vF.debug("Call removeLocalConversation",e),!F.dO.call(this))return s=E.A.create({type:A.C.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,!_.includes(a))throw Error('"Invalid parameter conversationType": '+a);if("string"!=typeof i||""===i)throw Error('Invalid parameter: "conversationId"');l=(0,w.u0)({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(),E.A.create({type:A.C.LOCAL_DB_OPERATION_FAILED,message:"removeLocalConversation is failed",data:d});case 6:return[2]}}))}))}function U(e){var t,n;return x(this,void 0,void 0,(function(){var r,o,s,a;return O(this,(function(i){switch(i.label){case 0:if(C.vF.debug("Call clearConversationUnreadCount",e),!F.dO.call(this))return r=E.A.create({type:A.C.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(r)];if(o=e.conversationType,s=e.conversationId,!_.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,w.u0)({conversationId:s,conversationType:o}),{unReadCount:0,unreadCountClearTimestamp:(new Date).getTime()})];case 2:return i.sent(),[3,4];case 3:throw a=i.sent(),E.A.create({type:A.C.LOCAL_DB_OPERATION_FAILED,message:"clearConversationUnreadCount is failed",data:a});case 4:return[2]}}))}))}}},function(e){return e(e.s=5658)}])}));