easemob-websdk 4.4.0 → 4.5.0-beta
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.
- package/CHANGELOG.md +13 -0
- package/Easemob-chat.d.ts +31 -9
- package/Easemob-chat.js +1 -1
- package/contact/contact.d.ts +22 -4
- package/contact/contact.js +1 -1
- package/localCache/localCache.js +1 -1
- package/miniCore/miniCore.d.ts +11 -2
- package/miniCore/miniCore.js +1 -1
- package/miniProgram/Easemob-chat.js +1 -1
- package/package.json +1 -1
- package/status.d.ts +4 -0
- package/types/common.d.ts +4 -4
- package/uniApp/Easemob-chat.js +1 -1
package/contact/contact.d.ts
CHANGED
|
@@ -38,18 +38,20 @@ export interface Contact {
|
|
|
38
38
|
}): Promise<AsyncResult<IndexTypes.UploadTokenResult>>;
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
* Gets the conversation list.
|
|
41
|
+
* Gets the conversation list and the latest message in the conversation.
|
|
42
42
|
*
|
|
43
43
|
* ```typescript
|
|
44
44
|
* connection.getConversationlist()
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
|
-
getConversationlist(
|
|
47
|
+
getConversationlist(params?: {
|
|
48
48
|
/** The current page number, starting from 1. */
|
|
49
49
|
pageNum?: number;
|
|
50
50
|
/** The number of conversations that you expect to get on each page. The value cannot exceed 20. */
|
|
51
51
|
pageSize?: number;
|
|
52
|
-
|
|
52
|
+
success?: (res: AsyncResult<IndexTypes.ConversationInfo>) => void;
|
|
53
|
+
error?: (error: ErrorEvent) => void;
|
|
54
|
+
}): Promise<AsyncResult<IndexTypes.ConversationInfo>>;
|
|
53
55
|
|
|
54
56
|
/**
|
|
55
57
|
* Deletes the conversation.
|
|
@@ -82,7 +84,7 @@ export interface Contact {
|
|
|
82
84
|
* connection.updateUserInfo('nickname', 'Tom')
|
|
83
85
|
* ```
|
|
84
86
|
*/
|
|
85
|
-
|
|
87
|
+
updateUserInfo(
|
|
86
88
|
params: IndexTypes.UpdateOwnUserInfoParams | IndexTypes.ConfigurableKey,
|
|
87
89
|
value?: string
|
|
88
90
|
): Promise<AsyncResult<IndexTypes.UpdateOwnUserInfoParams>>;
|
|
@@ -542,6 +544,22 @@ export interface Contact {
|
|
|
542
544
|
mark: IndexTypes.MarkType;
|
|
543
545
|
};
|
|
544
546
|
}): Promise<AsyncResult<IndexTypes.ServerConversations>>;
|
|
547
|
+
/**
|
|
548
|
+
* Get the unique IDs of current user on the other devices. The ID is user ID + "/" + resource.
|
|
549
|
+
*
|
|
550
|
+
* ```typescript
|
|
551
|
+
* connection.getSelfIdsOnOtherPlatform()
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
getSelfIdsOnOtherPlatform(): Promise<AsyncResult<string[]>>;
|
|
555
|
+
/**
|
|
556
|
+
* Deletes all conversations and all messages in them.
|
|
557
|
+
*
|
|
558
|
+
* ```typescript
|
|
559
|
+
* connection.deleteAllMessagesAndConversations()
|
|
560
|
+
* ```
|
|
561
|
+
*/
|
|
562
|
+
deleteAllMessagesAndConversations(): Promise<void>;
|
|
545
563
|
}
|
|
546
564
|
|
|
547
565
|
export { IndexTypes, ReactionTypes, AsyncResult, UserId, MessageType };
|
package/contact/contact.js
CHANGED
|
@@ -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([[564],{7479:function(e,t,r){r.r(t),r.d(t,{acceptContactInvite:function(){return J},acceptInvitation:function(){return G},addContact:function(){return B},addConversationMark:function(){return me},addReaction:function(){return ee},addToBlackList:function(){return H},addUsersToBlacklist:function(){return q},addUsersToBlocklist:function(){return F},declineContactInvite:function(){return K},declineInvitation:function(){return D},deleteContact:function(){return X},deleteConversation:function(){return b},deleteReaction:function(){return te},deleteSession:function(){return N},fetchHistoryMessages:function(){return Z},fetchUserInfoById:function(){return P},getAllContacts:function(){return de},getBlacklist:function(){return E},getBlocklist:function(){return k},getContacts:function(){return _},getContactsWithCursor:function(){return he},getConversationlist:function(){return j},getHistoryMessages:function(){return z},getReactionDetail:function(){return ne},getReactionList:function(){return re},getReactionlist:function(){return ae},getRoster:function(){return I},getServerConversations:function(){return ie},getServerConversationsByFilter:function(){return ve},getServerPinnedConversations:function(){return ue},getSessionList:function(){return R},getTokenExpireTimestamp:function(){return M},modifyMessage:function(){return $},pinConversation:function(){return le},recallMessage:function(){return Y},removeConversationMark:function(){return ge},removeFromBlackList:function(){return W},removeHistoryMessages:function(){return se},removeRoster:function(){return L},removeUserFromBlackList:function(){return V},removeUserFromBlocklist:function(){return Q},reportMessage:function(){return oe},setContactRemark:function(){return pe},updateCurrentUserNick:function(){return U},updateOwnUserInfo:function(){return w},updateUserInfo:function(){return O},uploadPushToken:function(){return C},uploadToken:function(){return A}}),r(9601),r(1539),r(8674),r(2526),r(1817),r(2165),r(6992),r(8783),r(3948),r(9554),r(4747),r(2222),r(7941),r(6699),r(3710),r(9714),r(9600),r(5069),r(561),r(9753),r(8309),r(1249),r(7327);var a=r(3246),n=r(5531),o=r(7252),s=r(4024),i=r(9937),c=r(8161),u=r(4188),l=r.n(u),p=r(7360),d=r(1595),h=r(4363),f=r(7288),m=r(9743),g=function(){return g=Object.assign||function(e){for(var t,r=1,a=arguments.length;r<a;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},g.apply(this,arguments)},v=function(e,t,r,a){return new(r||(r=Promise))((function(n,o){function s(e){try{c(a.next(e))}catch(e){o(e)}}function i(e){try{c(a.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,i)}c((a=a.apply(e,t||[])).next())}))},y=function(e,t){var r,a,n,o,s={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return o={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(o){return function(i){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,a&&(n=2&o[0]?a.return:o[0]?a.throw||((n=a.return)&&n.call(a),0):a.next)&&!(n=n.call(a,o[1])).done)return n;switch(a=0,n&&(o=[2&o[0],n.value]),o[0]){case 0:case 1:n=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,a=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!((n=(n=s.trys).length>0&&n[n.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!n||o[1]>n[0]&&o[1]<n[3])){s.label=o[1];break}if(6===o[0]&&s.label<n[1]){s.label=n[1],n=o;break}if(n&&s.label<n[2]){s.label=n[2],s.ops.push(o);break}n[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],a=0}finally{r=n=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,i])}}},T={chat:"singleChat",chatroom:"chatRoom",groupchat:"groupChat",singleChat:"singleChat",chatRoom:"chatRoom",groupChat:"groupChat"},S={singleChat:"chat",chatRoom:"chatroom",groupChat:"groupchat"};function E(e){if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}var r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l={url:this.apiUrl+"/"+i+"/"+c+"/users/"+this.user+"/blocks/users",dataType:"json",type:"GET",headers:{Authorization:"Bearer "+u},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 p.kg.debug("Call getBlocklist"),s.hj.call(this,l,d.fI.GET_BLACK_LIST)}var k=E,I=_;function _(e){var t=this;if(!a.XZ.call(this)){var r=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(r)}var i=this.context,c=i.orgName,u=i.appName,l=i.accessToken,h={url:this.apiUrl+"/"+c+"/"+u+"/users/"+this.user+"/contacts/users",dataType:"json",type:"GET",headers:{Authorization:"Bearer "+l},success:function(r){var a=[];r.data.forEach((function(e){a.push({name:e,subscription:"both",jid:t.context.jid})})),"function"==typeof(null==e?void 0:e.success)&&e.success(a)},error:function(t){"function"==typeof(null==e?void 0:e.error)&&e.error(t)}};return p.kg.debug("Call getContacts"),s.hj.call(this,h,d.fI.GET_CONTACTS)}function A(e){if("string"!=typeof e.deviceId||""===e.deviceId)throw Error('Invalid parameter: "deviceId"');if("string"!=typeof e.deviceToken||""===e.deviceToken)throw Error('Invalid parameter: "deviceToken"');if("string"!=typeof e.notifierName||""===e.notifierName)throw Error('Invalid parameter: "notifierName"');if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}var r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/users/").concat(this.user),type:"PUT",data:JSON.stringify({device_id:e.deviceId,device_token:e.deviceToken,notifier_name:e.notifierName}),dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"},success:e.success,error:e.error};return p.kg.debug("Call uploadPushToken",e),s.hj.call(this,l,d.fI.UPLOAD_PUSH_TOKEN)}var C=A;function R(e){if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}var r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/users/").concat(this.user,"/user_channels"),type:"GET",dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"},success:e&&(null==e?void 0:e.success),error:e&&(null==e?void 0:e.error)};return p.kg.debug("Call getSessionList"),s.hj.call(this,l,d.fI.GET_SESSION_LIST)}function j(e){if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}var r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l=!!(e&&"number"==typeof e.pageNum&&"number"==typeof e.pageSize&&e.pageNum>0&&e.pageSize>0),f={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/users/").concat(this.user,"/user_channels").concat(l?"/page":""),type:"GET",dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"},success:e&&(null==e?void 0:e.success),error:e&&(null==e?void 0:e.error)};return l&&(f.data={pageNum:e.pageNum,pageSize:e.pageSize}),p.kg.debug("Call getConversationlist"),s.hj.call(this,f,d.fI.GET_SESSION_LIST).then((function(e){return function(e){var t=e.data.channel_infos;return null==t||t.forEach((function(e){e.meta&&"{}"!==JSON.stringify(e.meta)?(e.meta.payload=JSON.parse(e.meta.payload),e.lastMessage=(0,h.w)(e.meta)):e.lastMessage=e.meta,delete e.meta})),e}(e)}))}function N(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));if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}var r,i=this.context,c=i.orgName,u=i.appName,l=i.accessToken,h=i.jid;r="singleChat"===e.chatType?"chat":"groupChat";var f={url:"".concat(this.apiUrl,"/").concat(c,"/").concat(u,"/user/").concat(this.user,"/user_channel?resource=").concat(h.clientResource),dataType:"json",type:"DELETE",data:JSON.stringify({channel:e.channel,type:r,delete_roam:e.deleteRoam}),headers:{Authorization:"Bearer "+l,"Content-Type":"application/json"},success:e.success,error:e.error};return p.kg.debug("Call deleteSession",e),s.hj.call(this,f,d.fI.DELETE_SESSION)}var b=N;function w(e,t){if(!a.XZ.call(this)){var r=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(r)}var i=this.context,c=i.orgName,u=i.appName,l=i.accessToken,h=["nickname","avatarurl","mail","phone","gender","sign","birth","ext"],f={};if("undefined"!=typeof wx||"undefined"!=typeof qq)if("string"==typeof e&&void 0!==t){if(!h.includes(e))throw new Error("illegal key, only these keys: nickname, avatarurl, mail, phone, gender, sign, birth, ext are allowed");f[e]=t}else{if("[object Object]"!==Object.prototype.toString.call(e))throw new Error("illegal params");h.forEach((function(t){h.includes(t)&&void 0!==e[t]&&(f[t]=e[t])}))}else if("string"==typeof e){if(!h.includes(e))throw new Error("illegal key, only these keys: nickname, avatarurl, mail, phone, gender, sign, birth, ext are allowed");f=e+"="+t}else{if("[object Object]"!==Object.prototype.toString.call(e))throw new Error("illegal params");var m=[];h.forEach((function(t){if(h.includes(t)&&void 0!==e[t]){var r=encodeURIComponent(t),a=encodeURIComponent(e[t]);m.push(r+"="+a)}})),f=m.join("&")}var g={url:"".concat(this.apiUrl,"/").concat(c,"/").concat(u,"/metadata/user/").concat(this.user),type:"PUT",data:f,dataType:"json",headers:{Authorization:"Bearer "+l,"Content-Type":"application/x-www-form-urlencoded"}};return p.kg.debug("Call updateOwnUserInfo",e),s.hj.call(this,g,d.fI.UPDATE_USER_INFO)}var O=w;function P(e,t){if(!a.XZ.call(this)){var r=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(r)}var i,c=this.context,u=c.orgName,l=c.appName,h=c.accessToken,f=[];if("string"==typeof e)f=[e];else{if("[object Array]"!==Object.prototype.toString.call(e))throw new Error("illegal params");f=e}i="string"==typeof t?[t]:t&&"[object Array]"===Object.prototype.toString.call(t)?t:["nickname","avatarurl","mail","phone","gender","sign","birth","ext"];var m={url:"".concat(this.apiUrl,"/").concat(u,"/").concat(l,"/metadata/user/get"),type:"POST",data:JSON.stringify({targets:f,properties:i}),dataType:"json",headers:{Authorization:"Bearer "+h,"Content-Type":"application/json"}};return p.kg.debug("Call fetchUserInfoById",e),s.hj.call(this,m,d.fI.GET_USER_INFO)}function U(e){if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}var r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/users/").concat(this.user),type:"PUT",dataType:"json",data:JSON.stringify({nickname:e}),headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}};return p.kg.debug("Call updateCurrentUserNick",e),s.hj.call(this,l)}function M(e){if("string"!=typeof e||""===e)throw Error('Invalid parameter: "token"');var t=this.context,r=t.orgName,a=t.appName,n={url:"".concat(this.apiUrl,"/").concat(r,"/").concat(a,"/sdk/users/").concat(this.user,"/token/expires"),type:"GET",dataType:"json",headers:{Authorization:"Bearer "+e,"Content-Type":"application/json"}};return p.kg.debug("Call getTokenExpireTimestamp",e),s.hj.call(this,n,d.fI.SDK_INTERNAL)}function Z(e){var t=this;return new Promise((function(r,s){if(!e.queue)throw Error('Invalid parameter: "specified"');if(!a.XZ.call(t)){var i=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(i)}(function e(t){var a=this,n=t.count||20;x.call(this,{count:n,isGroup:!!t.isGroup,queue:t.queue,start:t.start,format:t.format,success:function(o){if(o.msgs.length>=n||o.is_last){var s=o.msgs.splice(0,n).reverse();t.success&&t.success(s),r(s)}else e.call(a,g(g({},t),{start:null}))},fail:function(e){s(e),t.fail&&t.fail(e)}})}).call(t,e),p.kg.debug("Call fetchHistoryMessages",e)}))}function x(e){var t=this,r=e.queue,a=this.mr_cache[r]||(this.mr_cache[r]={msgs:[]}),i=this.context.userId,u=e.start||-1,p=e.count||20;if(a.msgs.length>=p||a.is_last)"function"==typeof e.success&&e.success(a);else{a&&a.next_key&&(u=a.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,m=f.orgName,g=f.appName,T={url:"".concat(this.apiUrl,"/").concat(m,"/").concat(g,"/users/").concat(i,"/messageroaming"),dataType:"json",type:"POST",headers:{Authorization:"Bearer "+this.token,"Content-Type":"application/json"},data:JSON.stringify(h),success:function(r){return v(t,void 0,void 0,(function(){var t,n,o,s,i,u,p=this;return y(this,(function(d){switch(d.label){case 0:if(t=null==r?void 0:r.data,!r.data.msgs)return"function"==typeof e.success&&e.success(a),a.is_last=!0,a.next_key="",[2];n=t.msgs,o=n.length,a.is_last=t.is_last,a.next_key=t.next_key,s=function(t){return v(p,void 0,void 0,(function(){var r,a,n,o,s;return y(this,(function(i){switch(i.label){case 0:for(r=[],t=l().atob(t),a=0,n=t.length;a<n;++a)r.push(t.charCodeAt(a));return o=(o=this.context.root.lookup("easemob.pb.Meta")).decode(r),s={errorCode:0,reason:""},1!==o.ns?[3,2]:[4,c.Z.call(this,o,s,!0,e.format)];case 1:return[2,i.sent()];case 2:return[2]}}))}))},i=0,d.label=1;case 1:return i<o?[4,s(n[i].msg)]:[3,4];case 2:(u=d.sent())&&a.msgs.push(u),d.label=3;case 3:return i++,[3,1];case 4:return"function"==typeof e.success&&e.success(a),[2]}}))}))},error:function(e){if(e.error&&e.error_description){var r=o.Z.create({type:n.E.WEBIM_CONNCTION_AJAX_ERROR,message:"fetch history messages error",data:e});t.onError&&t.onError(r)}}};s.hj.call(this,T,d.fI.GET_HISTORY_MSG).catch((function(t){"function"==typeof e.fail&&e.fail(t)}))}}function z(e){var t=this;return new Promise((function(r,i){var u=e.targetId,d=e.cursor,h=void 0===d?-1:d,f=e.pageSize,m=void 0===f?20:f,g=e.chatType,T=e.searchDirection,S=e.searchOptions,E=void 0===S?{}:S,k=E.msgTypes,I=void 0===k?[]:k,_=E.startTime,A=void 0===_?null:_,C=E.endTime,R=void 0===C?null:C,j=E.from,N=void 0===j?null:j;if("string"!=typeof u||""===u)throw Error('"Invalid parameter": "targetId"');if(N&&"string"!=typeof N)throw Error('"Invalid parameter": "searchOptions.from"');if(I&&!Array.isArray(I))throw Error('"Invalid parameter": "searchOptions.msgTypes"');if(A&&"number"!=typeof A)throw Error('"Invalid parameter": "searchOptions.startTime"');if(R&&"number"!=typeof A)throw Error('"Invalid parameter": "searchOptions.endTime"');if(!a.XZ.call(t)){var b=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return i(b)}var w=t.context,O=w.orgName,P=w.appName,U=w.userId,M="groupChat"===e.chatType?"@conference.easemob.com":"@easemob.com",Z={queue:"".concat(u).concat(M),start:h,pull_number:m,is_positive:"down"===T,msgType:I.join(",")||"",end:-1,startTime:A,endTime:R,userId:"singleChat"===g?null:N},x={url:"".concat(t.apiUrl,"/").concat(O,"/").concat(P,"/users/").concat(U,"/messageroaming"),dataType:"json",type:"POST",headers:{Authorization:"Bearer "+t.token,"Content-Type":"application/json"},data:JSON.stringify(Z),success:function(a){return v(t,void 0,void 0,(function(){var t,n,o,s,i,u,p,d,h=this;return y(this,(function(f){switch(f.label){case 0:t=null==a?void 0:a.data,n=t.msgs||[],o=function(e){return v(h,void 0,void 0,(function(){var t,r,a,n,o;return y(this,(function(s){switch(s.label){case 0:for(t=[],e=l().atob(e),r=0,a=e.length;r<a;++r)t.push(e.charCodeAt(r));return n=(n=this.context.root.lookup("easemob.pb.Meta")).decode(t),o={errorCode:0,reason:""},1!==n.ns?[3,2]:[4,c.Z.call(this,n,o,!0,!0)];case 1:return[2,s.sent()];case 2:return[2]}}))}))},s=[],i=0,f.label=1;case 1:return i<n.length?[4,o(n[i].msg)]:[3,4];case 2:(u=f.sent())&&s.push(u),f.label=3;case 3:return i++,[3,1];case 4:return t.msgs=s,p={cursor:t.next_key,messages:s,isLast:t.is_last},null===(d=e.success)||void 0===d||d.call(e,p),r(p),[2]}}))}))},error:e.fail};s.hj.call(t,x).catch((function(e){i(e)})),p.kg.debug("Call getHistoryMessages",e)}))}function B(e,t){return v(this,void 0,void 0,(function(){var r,i,c,u,l,h,f;return y(this,(function(m){switch(m.label){case 0:if(!a.XZ.call(this))return r=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(r)];if("string"!=typeof e||""===e)throw Error('"Invalid parameter": "to"');return p.kg.debug("Call addContact",e,t),i=this.context,c=i.orgName,u=i.appName,l=i.accessToken,h=i.jid,f={url:"".concat(this.apiUrl,"/").concat(c,"/").concat(u,"/users/").concat(this.user,"/contacts/apply?resource=").concat(h.clientResource),type:"POST",dataType:"json",data:JSON.stringify({usernames:[e],reason:t}),headers:{Authorization:"Bearer "+l,"Content-Type":"application/json"}},[4,s.hj.call(this,f,d.fI.ROSTER_ADD)];case 1:return m.sent(),[2]}}))}))}var L=X;function X(e){return v(this,void 0,void 0,(function(){var t,r,i,c,u,l,h;return y(this,(function(f){switch(f.label){case 0:if(!a.XZ.call(this))return t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)];if("string"!=typeof e||""===e)throw Error('"Invalid parameter": "to"');return p.kg.debug("Call deleteContact",e),r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l=r.jid,h={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/users/").concat(this.user,"/contacts/users/").concat(e,"?resource=").concat(l.clientResource),type:"DELETE",dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}},[4,s.hj.call(this,h,d.fI.ROSTER_REMOVE)];case 1:return f.sent(),[2]}}))}))}function G(e){return v(this,void 0,void 0,(function(){var t,r,i,c,u,l,h;return y(this,(function(f){switch(f.label){case 0:if(!a.XZ.call(this))return t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)];if("string"!=typeof e||""===e)throw Error('"Invalid parameter": "to"');return p.kg.debug("Call acceptInvitation",e),r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l=r.jid,h={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/users/").concat(this.user,"/contacts/accept/users/").concat(e,"?resource=").concat(l.clientResource),type:"POST",dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}},[4,s.hj.call(this,h,d.fI.ROSTER_ACCEPT)];case 1:return f.sent(),[2]}}))}))}var J=G;function D(e){return v(this,void 0,void 0,(function(){var t,r,i,c,u,l,h;return y(this,(function(f){switch(f.label){case 0:if(!a.XZ.call(this))return t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)];if("string"!=typeof e||""===e)throw Error('"Invalid parameter": "to"');return p.kg.debug("Call declineInvitation",e),r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l=r.jid,h={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/users/").concat(this.user,"/contacts/decline/users/").concat(e,"?resource=").concat(l.clientResource),type:"POST",dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}},[4,s.hj.call(this,h,d.fI.ROSTER_DECLINE)];case 1:return f.sent(),[2]}}))}))}var K=D;function H(e){return v(this,void 0,void 0,(function(){var t,r,i,c,u,l,h,f,m;return y(this,(function(g){switch(g.label){case 0:if(!a.XZ.call(this))return t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)];if(r=e.name,i=[],"string"==typeof r){if(""===r)throw Error('"Invalid parameter": "name"');i=[r]}else{if(!Array.isArray(r))throw Error('"Invalid parameter": "name"');i=r}return p.kg.debug("Call addToBlockList",e),c=this.context,u=c.orgName,l=c.appName,h=c.accessToken,f=c.jid,m={url:"".concat(this.apiUrl,"/").concat(u,"/").concat(l,"/sdk/user/").concat(this.user,"/blocks?resource=").concat(f.clientResource),type:"POST",dataType:"json",data:JSON.stringify({usernames:i}),headers:{Authorization:"Bearer "+h,"Content-Type":"application/json"}},[4,s.hj.call(this,m,d.fI.ROSTER_BAN).then((function(e){return{type:e.type,data:{userIds:(null==e?void 0:e.data)||[]}}}))];case 1:return[2,g.sent()]}}))}))}var q=H,F=H;function W(e){return v(this,void 0,void 0,(function(){var t,r,i,c,u,l,h,f,m;return y(this,(function(g){switch(g.label){case 0:if(!a.XZ.call(this))return t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)];if(r=e.name,i=[],"string"==typeof r){if(""===r)throw Error('"Invalid parameter": "name"');i=[r]}else{if(!Array.isArray(r))throw Error('"Invalid parameter": "name"');i=r}return p.kg.debug("Call removeFromBlockList",e),c=this.context,u=c.orgName,l=c.appName,h=c.accessToken,f=c.jid,m={url:"".concat(this.apiUrl,"/").concat(u,"/").concat(l,"/sdk/user/").concat(this.user,"/blocks?resource=").concat(f.clientResource),type:"DELETE",dataType:"json",data:JSON.stringify({usernames:i}),headers:{Authorization:"Bearer "+h,"Content-Type":"application/json"}},[4,s.hj.call(this,m,d.fI.ROSTER_ALLOW)];case 1:return g.sent(),[2]}}))}))}var V=W,Q=W;function Y(e){var t=this,r=this.getUniqueId(),a={id:r,to:e.to};this._msgHash[r]=g({},a);var n="";void 0!==e.chatType?n=e.chatType:void 0!==e.type&&(n="chat"===e.type?"singleChat":e.type);var o={id:r,type:"recall",chatType:n,ackId:e.mid,to:e.to,isChatThread:e.isChatThread||!1,success:function(r){return v(t,void 0,void 0,(function(){var t,a,o,s,i,c,u,l,p;return y(this,(function(d){switch(d.label){case 0:return d.trys.push([0,5,,6]),"singleChat"!==n&&"groupChat"!==n?[3,4]:[4,null===(o=null===(a=this._localCache)||void 0===a?void 0:a.getInstance())||void 0===o?void 0:o.removeMsgByServerMsgId(e.mid)];case 1:return d.sent(),[4,null===(i=null===(s=this._localCache)||void 0===s?void 0:s.getInstance())||void 0===i?void 0:i.getConversationLastMessage(e.to,n)];case 2:return t=d.sent(),[4,null===(u=null===(c=this._localCache)||void 0===c?void 0:c.getInstance())||void 0===u?void 0:u.updateLocalConversation((0,m.MQ)({conversationId:e.to,conversationType:n}),{lastMessageId:null==t?void 0:t.serverMsgId})];case 3:d.sent(),d.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 d.sent(),null===(p=null==e?void 0:e.success)||void 0===p||p.call(e,r),[3,6];case 6:return[2]}}))}))},fail:e.fail};return p.kg.debug("Call recallMessage",e),this.mSync.send(o,this)}function $(e){var t=e||{},r=t.messageId,a=t.modifiedMessage;if(p.kg.debug("Call modifyMessage",r,a),""===r)throw Error('Invalid parameter: "messageId"');if("txt"!==a.type)throw Error('Invalid parameter: "modifiedMessage.type"');return this.mSync.send(g({editMessageId:r},a))}function ee(e){return v(this,void 0,void 0,(function(){var t,r,i,c,u,l,p,d,h;return y(this,(function(f){switch(f.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 a.XZ.call(this)?(r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l=e.reaction,p=e.messageId,d={msgId:p,message:l},h={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/reaction/user/").concat(this.user),type:"POST",data:JSON.stringify(d),dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}},[4,s.hj.call(this,h)]):(t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)]);case 1:return f.sent(),[2]}}))}))}function te(e){return v(this,void 0,void 0,(function(){var t,r,i,c,u,l,p,d;return y(this,(function(h){switch(h.label){case 0:if("string"!=typeof e.reaction||!e.reaction)throw Error("Invalid parameter reactionId: ".concat(e.reaction));return a.XZ.call(this)?(r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l=e.messageId,p=e.reaction,d={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/reaction/user/").concat(this.user,"?msgId=").concat(l,"&message=").concat(p),type:"DELETE",dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}},[4,s.hj.call(this,d)]):(t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)]);case 1:return h.sent(),[2]}}))}))}function re(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));if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}var r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l=e.chatType,p=e.messageId,d={msgIdList:"string"==typeof p?[p]:p,msgType:"singleChat"===l?"chat":"groupchat",groupId:e.groupId||null},h={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/reaction/user/").concat(this.user),type:"GET",data:d,dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}};return s.hj.call(this,h).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=re;function ne(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));if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}var r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l=e.cursor,p=e.pageSize,d={msgId:e.messageId,message:e.reaction,currentPage:l||null,pageSize:p||20},h={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/reaction/user/").concat(this.user,"/detail"),type:"GET",data:d,dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}};return s.hj.call(this,h).then((function(e){return e.data.isAddedBySelf=e.data.state,delete e.data.state,delete e.data.reactionId,e}))}function oe(e){return v(this,void 0,void 0,(function(){var t,r,i,c,u,l,p,d,h,f,m;return y(this,(function(g){switch(g.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 a.XZ.call(this)?(r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l=e.reportType,p=e.reportReason,d=e.messageId,h={username:this.user,reportType:l,reportReason:p},f="".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/user/").concat(this.user,"/moderation/report/message/").concat(d),m={url:f,type:"POST",data:JSON.stringify(h),dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}},[4,s.hj.call(this,m)]):(t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)]);case 1:return g.sent(),[2]}}))}))}function se(e){var t;return v(this,void 0,void 0,(function(){var r,i,c,u,l,d,h,f,m;return y(this,(function(g){switch(g.label){case 0:if("string"!=typeof e.targetId||""===e.targetId)throw Error('"Invalid parameter targetId": '+e.targetId);if(!["singleChat","groupChat"].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 a.XZ.call(this)?(i=this.context,c=i.orgName,u=i.appName,l=i.userId,d="singleChat"===e.chatType?"userId":"groupId",h="singleChat"===e.chatType?"chat":"group",f=e.messageIds?"".concat(this.apiUrl,"/").concat(c,"/").concat(u,"/sdk/message/roaming/").concat(h,"/user/").concat(l,"?").concat(d,"=").concat(e.targetId,"&msgIdList=").concat(e.messageIds,"&resource=").concat(this.clientResource):"".concat(this.apiUrl,"/").concat(c,"/").concat(u,"/sdk/message/roaming/").concat(h,"/user/").concat(l,"/time?").concat(d,"=").concat(e.targetId,"&delTime=").concat(e.beforeTimeStamp,"&&resource=").concat(this.clientResource),m={url:f,dataType:"json",type:"DELETE",headers:{Authorization:"Bearer "+this.token,"Content-Type":"application/json"}},p.kg.debug("Call removeHistoryMessages",e),[4,s.hj.call(this,m)]):(r=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(r)]);case 1:return g.sent(),[2]}}))}))}function ie(e){var t=this;if(!a.XZ.call(this)){var r=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});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 i=this.context,c=i.orgName,u=i.appName,l=i.accessToken,h={url:"".concat(this.apiUrl,"/").concat(c,"/").concat(u,"/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 "+l,"Content-Type":"application/json"}};return p.kg.debug("Call getServerConversations",e),new Promise((function(e,r){s.hj.call(t,h,d.fI.GET_SESSION_LIST).then((function(r){return v(t,void 0,void 0,(function(){var t,a=this;return y(this,(function(n){switch(n.label){case 0:return t=ce(r),this._localCache?[4,Promise.all(t.data.conversations.map((function(e){return v(a,void 0,void 0,(function(){var t,r,a=this;return y(this,(function(n){return null===(r=null===(t=this._localCache)||void 0===t?void 0:t.getInstance())||void 0===r||r.storeMessage(e.lastMessage,f.r.SUCCESS,!0).then((function(){var t,r;null===(r=null===(t=a._localCache)||void 0===t?void 0:t.getInstance())||void 0===r||r.updateLocalConversation((0,m.MQ)({conversationId:e.conversationId,conversationType:e.conversationType}),{unReadCount:e.unReadCount})})),[2]}))}))})))]:[3,2];case 1:return n.sent(),e(t),[2];case 2:return e(t),[2]}}))}))})).catch((function(e){r(e)}))}))}function ce(e){var t=e.data,r=t.cursor,a=t.channel_infos,n=[];null==a||a.forEach((function(e){var t=null;(null==e?void 0:e.meta)&&"{}"!==JSON.stringify(e.meta)&&(e.meta.payload=JSON.parse(e.meta.payload),"delivery"!==(t=(0,h.w)(e.meta)).type&&"read"!==t.type&&"channel"!==t.type&&(t.chatType=T[t.chatType]));var r={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:t};e.marks&&(r.marks=e.marks.map((function(e){return i.Z[e]}))),n.push(r)}));var o={conversations:n,cursor:r||""};return{type:e.type,data:o}}function ue(e){if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}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 r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/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 "+u,"Content-Type":"application/json"}};return p.kg.debug("Call getServerConversations",e),s.hj.call(this,l,d.fI.GET_SESSION_LIST).then((function(e){return ce(e)}))}function le(e){return v(this,void 0,void 0,(function(){var t,r,i,c,u,l,h,f,m,g,v,T,S,E;return y(this,(function(y){if(!a.XZ.call(this))return t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)];if(r=e.conversationId,i=e.conversationType,c=e.isPinned,u="singleChat"===i?"chat":"groupChat","string"!=typeof r||""===r)throw Error("Invalid parameter conversationId: ".concat(r));if(!["singleChat","groupChat"].includes(i))throw Error("Invalid parameter conversationType: ".concat(i));if("boolean"!=typeof c)throw Error("Invalid parameter isPinned: ".concat(c));return l=this.context,h=l.orgName,f=l.appName,m=l.accessToken,g=l.jid,v={type:u,to:r},T=c?"":"type=".concat(u,"&to=").concat(r,"&"),S="".concat(this.apiUrl,"/").concat(h,"/").concat(f,"/sdk/user/").concat(this.user,"/user_channel/top?").concat(T,"resource=").concat(g.clientResource),E={url:S,type:c?"POST":"DELETE",dataType:"json",headers:{Authorization:"Bearer "+m,"Content-Type":"application/json"}},c&&(E.data=JSON.stringify(v)),p.kg.debug("Call pinConversation",e),[2,s.hj.call(this,E,d.fI.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 v(this,void 0,void 0,(function(){var t,r,i,c,u,l,h,f,m,g;return y(this,(function(v){switch(v.label){case 0:if(t=e.userId,r=e.remark,!a.XZ.call(this))return i=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(i)];if("string"!=typeof t||""===t)throw Error('Invalid parameter: "userId"');if("string"!=typeof r)throw Error('Invalid parameter: "remark"');return p.kg.debug("Call setContactRemark",e),c=this.context,u=c.orgName,l=c.appName,h=c.accessToken,f=c.jid,m="".concat(this.apiUrl,"/").concat(u,"/").concat(l,"/users/").concat(this.context.userId,"/contacts/users/").concat(t,"?resource=").concat(f.clientResource),g={url:m,type:"PUT",data:JSON.stringify({remark:r}),dataType:"json",headers:{Authorization:"Bearer "+h,"Content-Type":"application/json"}},[4,s.hj.call(this,g,d.fI.ROSTER_SET_CONTACT_REMARK)];case 1:return v.sent(),[2]}}))}))}function de(){if(!a.XZ.call(this)){var e=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(e)}var t=this.context,r=t.orgName,i=t.appName,c=t.accessToken,u={url:"".concat(this.apiUrl,"/").concat(r,"/").concat(i,"/users/").concat(this.user,"/contacts/users?needReturnRemark=true"),dataType:"json",type:"GET",headers:{Authorization:"Bearer "+c}};return p.kg.debug("Call getAllContacts"),s.hj.call(this,u,d.fI.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 he(e){if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}p.kg.debug("Call getContactsWithCursor",e);var r=e||{},i=r.pageSize,c=void 0===i?20:i,u=r.cursor,l=void 0===u?"":u;if(c&&"number"!=typeof c)throw Error("Invalid parameter pageSize: ".concat(e.pageSize));var h=this.context,f=h.orgName,m=h.appName,g=h.accessToken,v={url:"".concat(this.apiUrl,"/").concat(f,"/").concat(m,"/users/").concat(this.user,"/contacts?needReturnRemark=true&limit=").concat(c,"&cursor=").concat(l),dataType:"json",type:"GET",headers:{Authorization:"Bearer "+g}};return s.hj.call(this,v,d.fI.ROSTER_GET_ALL_CONTACTS_REMARKS_FROM_SERVER_BY_PAGE).then((function(e){var t,r,a=(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.contacts)||[],n=(null===(r=null==e?void 0:e.data)||void 0===r?void 0:r.cursor)||"",o=a.map((function(e){return{userId:e.username,remark:e.remark}}));return{type:e.type,data:{cursor:n,contacts:o}}}))}function fe(e){return v(this,void 0,void 0,(function(){var t,r,c,u,l,h,f,m,g,v,E,k,I,_,A;return y(this,(function(y){switch(y.label){case 0:if(!a.XZ.call(this))return t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)];if(p.kg.debug("Call markConversation",e),c=(r=e||{}).conversations,u=void 0===c?[]:c,l=r.mark,h=r.isMarked,!Array.isArray(u))throw Error("Invalid parameter conversations");if(f=u.map((function(e){if(!e.conversationId||!["singleChat","groupChat"].includes(e.conversationType))throw Error("Invalid parameter conversations");return{to:e.conversationId,type:S[e.conversationType]}})),"boolean"!=typeof h)throw Error("Invalid parameter isMarked: ".concat(h));if("number"!=typeof l)throw Error("Invalid parameter mark: ".concat(l));return m=this.context,g=m.orgName,v=m.appName,E=m.accessToken,k=m.userId,I=m.jid,_={mark:i.Z[l],targets:f},A={url:"".concat(this.apiUrl,"/").concat(g,"/").concat(v,"/sdk/user/").concat(k,"/user_channels/mark?resource=").concat(I.clientResource),dataType:"json",data:JSON.stringify(_),type:h?"Post":"Delete",headers:{Authorization:"Bearer "+E}},[4,s.hj.call(this,A,d.fI.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&&p.kg.debug("markConversation has ignored conversations",r.map((function(e){return{conversationId:e.to,conversationType:T[e.type]}})))}))];case 1:return y.sent(),[2]}}))}))}function me(e){return v(this,void 0,void 0,(function(){var t,r;return y(this,(function(a){return p.kg.debug("Call addConversationMark",e),t=e.conversations,r=e.mark,[2,fe.call(this,{conversations:t,mark:r,isMarked:!0})]}))}))}function ge(e){return v(this,void 0,void 0,(function(){var t,r;return y(this,(function(a){return p.kg.debug("Call removeConversationMark",e),t=e.conversations,r=e.mark,[2,fe.call(this,{conversations:t,mark:r,isMarked:!1})]}))}))}function ve(e){var t,r;if(!a.XZ.call(this)){var c=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(c)}if(p.kg.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 u=this.context,l=u.orgName,h=u.appName,f=u.accessToken,m="".concat(this.apiUrl,"/").concat(l,"/").concat(h,"/sdk/user/").concat(this.user,"/user_channels/mark/search?"),g=e.pageSize,v=e.cursor,y=((null==e?void 0:e.filter)||{}).mark,T={url:m,type:"GET",dataType:"json",data:{limit:g||10,cursor:v||"",need_mark:!0,mark:i.Z[y]},headers:{Authorization:"Bearer "+f,"Content-Type":"application/json"}};return s.hj.call(this,T,d.fI.GET_SESSION_LIST).then((function(e){return ce(e)}))}},3246:function(e,t,r){r.d(t,{H7:function(){return u},XZ:function(){return i},_W:function(){return c}}),r(7941),r(9554),r(1539),r(4747),r(6699),r(2023);var a=r(5531),n=r(7252);function o(){var e=this.context.appName,t=this.context.orgName;return!(!e||!t)||(this.onError&&this.onError({type:a.E.WEBIM_CONNCTION_AUTH_ERROR,message:"appName or orgName is illegal"}),!1)}function s(){var e;if(!this.context.accessToken){var t=n.Z.create({type:a.E.WEBIM_CONNCTION_TOKEN_NOT_ASSIGN_ERROR,message:"token not assign error"});return this.onError&&this.onError(t),null===(e=this.eventHandler)||void 0===e||e.dispatch("onError",t),!1}return!0}function i(){return s.call(this)&&o.call(this)}function c(e){var t=e.data,r=e.type;return{data:{status:Object.keys(t.errorKeys).length>0?"fail":"success",errorKeys:t.errorKeys,successKeys:t.successKeys},type:r}}function u(e){var t=e.data,r=void 0;return Object.keys(t.errorKeys).length>0&&Object.keys(t.errorKeys).forEach((function(e){var o=t.errorKeys[e];r=o.includes("is not part of you")?n.Z.create({type:a.E.NO_PERMISSION,message:o}):o.includes("size of metadata for this single chatroom exceeds the user defined limit")||o.includes("total size of chatroom metadata for this app exceeds the user defined limit")||o.includes("is exceeding maximum limit")?n.Z.create({type:a.E.MAX_LIMIT,message:o}):o.includes("is not Legal")?n.Z.create({type:a.E.REQUEST_PARAMETER_ERROR,message:o}):o.includes("Failed to update userMetadata. Concurrent updates not allowed")?n.Z.create({type:a.E.OPERATION_NOT_ALLOWED,message:o}):n.Z.create({type:a.E.WEBIM_CONNCTION_AJAX_ERROR,message:o})})),r}},5069:function(e,t,r){var a=r(2109),n=r(1702),o=r(3157),s=n([].reverse),i=[1,2];a({target:"Array",proto:!0,forced:String(i)===String(i.reverse())},{reverse:function(){return o(this)&&(this.length=this.length),s(this)}})}},function(e){return 7479,e(e.s=7479)}])}));
|
|
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([[564],{7479:function(e,t,r){r.r(t),r.d(t,{acceptContactInvite:function(){return D},acceptInvitation:function(){return G},addContact:function(){return B},addConversationMark:function(){return me},addReaction:function(){return ee},addToBlackList:function(){return H},addUsersToBlacklist:function(){return F},addUsersToBlocklist:function(){return q},declineContactInvite:function(){return K},declineInvitation:function(){return J},deleteAllMessagesAndConversations:function(){return Te},deleteContact:function(){return X},deleteConversation:function(){return b},deleteReaction:function(){return te},deleteSession:function(){return N},fetchHistoryMessages:function(){return Z},fetchUserInfoById:function(){return P},getAllContacts:function(){return de},getBlacklist:function(){return E},getBlocklist:function(){return k},getContacts:function(){return _},getContactsWithCursor:function(){return he},getConversationlist:function(){return j},getHistoryMessages:function(){return z},getReactionDetail:function(){return ne},getReactionList:function(){return re},getReactionlist:function(){return ae},getRoster:function(){return I},getSelfIdsOnOtherPlatform:function(){return ye},getServerConversations:function(){return ie},getServerConversationsByFilter:function(){return ve},getServerPinnedConversations:function(){return ue},getSessionList:function(){return R},getTokenExpireTimestamp:function(){return M},modifyMessage:function(){return $},pinConversation:function(){return le},recallMessage:function(){return Y},removeConversationMark:function(){return ge},removeFromBlackList:function(){return W},removeHistoryMessages:function(){return se},removeRoster:function(){return L},removeUserFromBlackList:function(){return V},removeUserFromBlocklist:function(){return Q},reportMessage:function(){return oe},setContactRemark:function(){return pe},updateCurrentUserNick:function(){return U},updateOwnUserInfo:function(){return w},updateUserInfo:function(){return O},uploadPushToken:function(){return C},uploadToken:function(){return A}}),r(9601),r(1539),r(8674),r(2526),r(1817),r(2165),r(6992),r(8783),r(3948),r(9554),r(4747),r(2222),r(7941),r(6699),r(3710),r(9714),r(9600),r(5069),r(561),r(9753),r(8309),r(1249),r(7327);var a=r(3246),n=r(5531),o=r(7252),s=r(4024),i=r(9937),c=r(8161),u=r(4188),l=r.n(u),p=r(7360),d=r(1595),h=r(4363),f=r(7288),m=r(9743),g=function(){return g=Object.assign||function(e){for(var t,r=1,a=arguments.length;r<a;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},g.apply(this,arguments)},v=function(e,t,r,a){return new(r||(r=Promise))((function(n,o){function s(e){try{c(a.next(e))}catch(e){o(e)}}function i(e){try{c(a.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,i)}c((a=a.apply(e,t||[])).next())}))},y=function(e,t){var r,a,n,o,s={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return o={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(o){return function(i){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,a&&(n=2&o[0]?a.return:o[0]?a.throw||((n=a.return)&&n.call(a),0):a.next)&&!(n=n.call(a,o[1])).done)return n;switch(a=0,n&&(o=[2&o[0],n.value]),o[0]){case 0:case 1:n=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,a=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!((n=(n=s.trys).length>0&&n[n.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!n||o[1]>n[0]&&o[1]<n[3])){s.label=o[1];break}if(6===o[0]&&s.label<n[1]){s.label=n[1],n=o;break}if(n&&s.label<n[2]){s.label=n[2],s.ops.push(o);break}n[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],a=0}finally{r=n=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,i])}}},T={chat:"singleChat",chatroom:"chatRoom",groupchat:"groupChat",singleChat:"singleChat",chatRoom:"chatRoom",groupChat:"groupChat"},S={singleChat:"chat",chatRoom:"chatroom",groupChat:"groupchat"};function E(e){if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}var r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l={url:this.apiUrl+"/"+i+"/"+c+"/users/"+this.user+"/blocks/users",dataType:"json",type:"GET",headers:{Authorization:"Bearer "+u},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 p.kg.debug("Call getBlocklist"),s.hj.call(this,l,d.fI.GET_BLACK_LIST)}var k=E,I=_;function _(e){var t=this;if(!a.XZ.call(this)){var r=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(r)}var i=this.context,c=i.orgName,u=i.appName,l=i.accessToken,h={url:this.apiUrl+"/"+c+"/"+u+"/users/"+this.user+"/contacts/users",dataType:"json",type:"GET",headers:{Authorization:"Bearer "+l},success:function(r){var a=[];r.data.forEach((function(e){a.push({name:e,subscription:"both",jid:t.context.jid})})),"function"==typeof(null==e?void 0:e.success)&&e.success(a)},error:function(t){"function"==typeof(null==e?void 0:e.error)&&e.error(t)}};return p.kg.debug("Call getContacts"),s.hj.call(this,h,d.fI.GET_CONTACTS)}function A(e){if("string"!=typeof e.deviceId||""===e.deviceId)throw Error('Invalid parameter: "deviceId"');if("string"!=typeof e.deviceToken||""===e.deviceToken)throw Error('Invalid parameter: "deviceToken"');if("string"!=typeof e.notifierName||""===e.notifierName)throw Error('Invalid parameter: "notifierName"');if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}var r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/users/").concat(this.user),type:"PUT",data:JSON.stringify({device_id:e.deviceId,device_token:e.deviceToken,notifier_name:e.notifierName}),dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"},success:e.success,error:e.error};return p.kg.debug("Call uploadPushToken",e),s.hj.call(this,l,d.fI.UPLOAD_PUSH_TOKEN)}var C=A;function R(e){if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}var r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/users/").concat(this.user,"/user_channels"),type:"GET",dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"},success:e&&(null==e?void 0:e.success),error:e&&(null==e?void 0:e.error)};return p.kg.debug("Call getSessionList"),s.hj.call(this,l,d.fI.GET_SESSION_LIST)}function j(e){if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}var r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l=!!(e&&"number"==typeof e.pageNum&&"number"==typeof e.pageSize&&e.pageNum>0&&e.pageSize>0),f={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/users/").concat(this.user,"/user_channels").concat(l?"/page":""),type:"GET",dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"},success:e&&(null==e?void 0:e.success),error:e&&(null==e?void 0:e.error)};return l&&(f.data={pageNum:e.pageNum,pageSize:e.pageSize}),p.kg.debug("Call getConversationlist"),s.hj.call(this,f,d.fI.GET_SESSION_LIST).then((function(e){return function(e){var t=e.data.channel_infos;return null==t||t.forEach((function(e){e.meta&&"{}"!==JSON.stringify(e.meta)?(e.meta.payload=JSON.parse(e.meta.payload),e.lastMessage=(0,h.w)(e.meta,!1)):e.lastMessage=e.meta,delete e.meta})),e}(e)}))}function N(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));if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}var r,i=this.context,c=i.orgName,u=i.appName,l=i.accessToken,h=i.jid;r="singleChat"===e.chatType?"chat":"groupChat";var f={url:"".concat(this.apiUrl,"/").concat(c,"/").concat(u,"/user/").concat(this.user,"/user_channel?resource=").concat(h.clientResource),dataType:"json",type:"DELETE",data:JSON.stringify({channel:e.channel,type:r,delete_roam:e.deleteRoam}),headers:{Authorization:"Bearer "+l,"Content-Type":"application/json"},success:e.success,error:e.error};return p.kg.debug("Call deleteSession",e),s.hj.call(this,f,d.fI.DELETE_SESSION)}var b=N;function w(e,t){if(!a.XZ.call(this)){var r=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(r)}var i=this.context,c=i.orgName,u=i.appName,l=i.accessToken,h=["nickname","avatarurl","mail","phone","gender","sign","birth","ext"],f={},m=s.P6.getEnvInfo();if("wx"===m.platform||"qq"===m.platform)if("string"==typeof e&&void 0!==t){if(!h.includes(e))throw new Error("illegal key, only these keys: nickname, avatarurl, mail, phone, gender, sign, birth, ext are allowed");f[e]=t}else{if("[object Object]"!==Object.prototype.toString.call(e))throw new Error("illegal params");h.forEach((function(t){h.includes(t)&&void 0!==e[t]&&(f[t]=e[t])}))}else if("string"==typeof e){if(!h.includes(e))throw new Error("illegal key, only these keys: nickname, avatarurl, mail, phone, gender, sign, birth, ext are allowed");f=e+"="+t}else{if("[object Object]"!==Object.prototype.toString.call(e))throw new Error("illegal params");var g=[];h.forEach((function(t){if(h.includes(t)&&void 0!==e[t]){var r=encodeURIComponent(t),a=encodeURIComponent(e[t]);g.push(r+"="+a)}})),f=g.join("&")}var v={url:"".concat(this.apiUrl,"/").concat(c,"/").concat(u,"/metadata/user/").concat(this.user),type:"PUT",data:f,dataType:"json",headers:{Authorization:"Bearer "+l,"Content-Type":"application/x-www-form-urlencoded"}};return p.kg.debug("Call updateOwnUserInfo",e),s.hj.call(this,v,d.fI.UPDATE_USER_INFO)}var O=w;function P(e,t){if(!a.XZ.call(this)){var r=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(r)}var i,c=this.context,u=c.orgName,l=c.appName,h=c.accessToken,f=[];if("string"==typeof e)f=[e];else{if("[object Array]"!==Object.prototype.toString.call(e))throw new Error("illegal params");f=e}i="string"==typeof t?[t]:t&&"[object Array]"===Object.prototype.toString.call(t)?t:["nickname","avatarurl","mail","phone","gender","sign","birth","ext"];var m={url:"".concat(this.apiUrl,"/").concat(u,"/").concat(l,"/metadata/user/get"),type:"POST",data:JSON.stringify({targets:f,properties:i}),dataType:"json",headers:{Authorization:"Bearer "+h,"Content-Type":"application/json"}};return p.kg.debug("Call fetchUserInfoById",e),s.hj.call(this,m,d.fI.GET_USER_INFO)}function U(e){if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}var r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/users/").concat(this.user),type:"PUT",dataType:"json",data:JSON.stringify({nickname:e}),headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}};return p.kg.debug("Call updateCurrentUserNick",e),s.hj.call(this,l)}function M(e){if("string"!=typeof e||""===e)throw Error('Invalid parameter: "token"');var t=this.context,r=t.orgName,a=t.appName,n={url:"".concat(this.apiUrl,"/").concat(r,"/").concat(a,"/sdk/users/").concat(this.user,"/token/expires"),type:"GET",dataType:"json",headers:{Authorization:"Bearer "+e,"Content-Type":"application/json"}};return p.kg.debug("Call getTokenExpireTimestamp",e),s.hj.call(this,n,d.fI.SDK_INTERNAL)}function Z(e){var t=this;return new Promise((function(r,s){if(!e.queue)throw Error('Invalid parameter: "specified"');if(!a.XZ.call(t)){var i=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(i)}(function e(t){var a=this,n=t.count||20;x.call(this,{count:n,isGroup:!!t.isGroup,queue:t.queue,start:t.start,format:t.format,success:function(o){if(o.msgs.length>=n||o.is_last){var s=o.msgs.splice(0,n).reverse();t.success&&t.success(s),r(s)}else e.call(a,g(g({},t),{start:null}))},fail:function(e){s(e),t.fail&&t.fail(e)}})}).call(t,e),p.kg.debug("Call fetchHistoryMessages",e)}))}function x(e){var t=this,r=e.queue,a=this.mr_cache[r]||(this.mr_cache[r]={msgs:[]}),i=this.context.userId,u=e.start||-1,p=e.count||20;if(a.msgs.length>=p||a.is_last)"function"==typeof e.success&&e.success(a);else{a&&a.next_key&&(u=a.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,m=f.orgName,g=f.appName,T={url:"".concat(this.apiUrl,"/").concat(m,"/").concat(g,"/users/").concat(i,"/messageroaming"),dataType:"json",type:"POST",headers:{Authorization:"Bearer "+this.token,"Content-Type":"application/json"},data:JSON.stringify(h),success:function(r){return v(t,void 0,void 0,(function(){var t,n,o,s,i,u,p=this;return y(this,(function(d){switch(d.label){case 0:if(t=null==r?void 0:r.data,!r.data.msgs)return"function"==typeof e.success&&e.success(a),a.is_last=!0,a.next_key="",[2];n=t.msgs,o=n.length,a.is_last=t.is_last,a.next_key=t.next_key,s=function(t){return v(p,void 0,void 0,(function(){var r,a,n,o,s;return y(this,(function(i){switch(i.label){case 0:for(r=[],t=l().atob(t),a=0,n=t.length;a<n;++a)r.push(t.charCodeAt(a));return o=(o=this.context.root.lookup("easemob.pb.Meta")).decode(r),s={errorCode:0,reason:""},1!==o.ns?[3,2]:[4,c.Z.call(this,o,s,!0,e.format)];case 1:return[2,i.sent()];case 2:return[2]}}))}))},i=0,d.label=1;case 1:return i<o?[4,s(n[i].msg)]:[3,4];case 2:(u=d.sent())&&a.msgs.push(u),d.label=3;case 3:return i++,[3,1];case 4:return"function"==typeof e.success&&e.success(a),[2]}}))}))},error:function(e){if(e.error&&e.error_description){var r=o.Z.create({type:n.E.WEBIM_CONNCTION_AJAX_ERROR,message:"fetch history messages error",data:e});t.onError&&t.onError(r)}}};s.hj.call(this,T,d.fI.GET_HISTORY_MSG).catch((function(t){"function"==typeof e.fail&&e.fail(t)}))}}function z(e){var t=this;return new Promise((function(r,i){var u=e.targetId,d=e.cursor,h=void 0===d?-1:d,f=e.pageSize,m=void 0===f?20:f,g=e.chatType,T=e.searchDirection,S=e.searchOptions,E=void 0===S?{}:S,k=E.msgTypes,I=void 0===k?[]:k,_=E.startTime,A=void 0===_?null:_,C=E.endTime,R=void 0===C?null:C,j=E.from,N=void 0===j?null:j;if("string"!=typeof u||""===u)throw Error('"Invalid parameter": "targetId"');if(N&&"string"!=typeof N)throw Error('"Invalid parameter": "searchOptions.from"');if(I&&!Array.isArray(I))throw Error('"Invalid parameter": "searchOptions.msgTypes"');if(A&&"number"!=typeof A)throw Error('"Invalid parameter": "searchOptions.startTime"');if(R&&"number"!=typeof A)throw Error('"Invalid parameter": "searchOptions.endTime"');if(!a.XZ.call(t)){var b=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return i(b)}var w=t.context,O=w.orgName,P=w.appName,U=w.userId,M="groupChat"===e.chatType?"@conference.easemob.com":"@easemob.com",Z={queue:"".concat(u).concat(M),start:h,pull_number:m,is_positive:"down"===T,msgType:I.join(",")||"",end:-1,startTime:A,endTime:R,userId:"singleChat"===g?null:N},x={url:"".concat(t.apiUrl,"/").concat(O,"/").concat(P,"/users/").concat(U,"/messageroaming"),dataType:"json",type:"POST",headers:{Authorization:"Bearer "+t.token,"Content-Type":"application/json"},data:JSON.stringify(Z),success:function(a){return v(t,void 0,void 0,(function(){var t,n,o,s,i,u,p,d,h=this;return y(this,(function(f){switch(f.label){case 0:t=null==a?void 0:a.data,n=t.msgs||[],o=function(e){return v(h,void 0,void 0,(function(){var t,r,a,n,o;return y(this,(function(s){switch(s.label){case 0:for(t=[],e=l().atob(e),r=0,a=e.length;r<a;++r)t.push(e.charCodeAt(r));return n=(n=this.context.root.lookup("easemob.pb.Meta")).decode(t),o={errorCode:0,reason:""},1!==n.ns?[3,2]:[4,c.Z.call(this,n,o,!0,!0)];case 1:return[2,s.sent()];case 2:return[2]}}))}))},s=[],i=0,f.label=1;case 1:return i<n.length?[4,o(n[i].msg)]:[3,4];case 2:(u=f.sent())&&s.push(u),f.label=3;case 3:return i++,[3,1];case 4:return t.msgs=s,p={cursor:t.next_key,messages:s,isLast:t.is_last},null===(d=e.success)||void 0===d||d.call(e,p),r(p),[2]}}))}))},error:e.fail};s.hj.call(t,x).catch((function(e){i(e)})),p.kg.debug("Call getHistoryMessages",e)}))}function B(e,t){return v(this,void 0,void 0,(function(){var r,i,c,u,l,h,f;return y(this,(function(m){switch(m.label){case 0:if(!a.XZ.call(this))return r=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(r)];if("string"!=typeof e||""===e)throw Error('"Invalid parameter": "to"');return p.kg.debug("Call addContact",e,t),i=this.context,c=i.orgName,u=i.appName,l=i.accessToken,h=i.jid,f={url:"".concat(this.apiUrl,"/").concat(c,"/").concat(u,"/users/").concat(this.user,"/contacts/apply?resource=").concat(h.clientResource),type:"POST",dataType:"json",data:JSON.stringify({usernames:[e],reason:t}),headers:{Authorization:"Bearer "+l,"Content-Type":"application/json"}},[4,s.hj.call(this,f,d.fI.ROSTER_ADD)];case 1:return m.sent(),[2]}}))}))}var L=X;function X(e){return v(this,void 0,void 0,(function(){var t,r,i,c,u,l,h;return y(this,(function(f){switch(f.label){case 0:if(!a.XZ.call(this))return t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)];if("string"!=typeof e||""===e)throw Error('"Invalid parameter": "to"');return p.kg.debug("Call deleteContact",e),r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l=r.jid,h={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/users/").concat(this.user,"/contacts/users/").concat(e,"?resource=").concat(l.clientResource),type:"DELETE",dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}},[4,s.hj.call(this,h,d.fI.ROSTER_REMOVE)];case 1:return f.sent(),[2]}}))}))}function G(e){return v(this,void 0,void 0,(function(){var t,r,i,c,u,l,h;return y(this,(function(f){switch(f.label){case 0:if(!a.XZ.call(this))return t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)];if("string"!=typeof e||""===e)throw Error('"Invalid parameter": "to"');return p.kg.debug("Call acceptInvitation",e),r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l=r.jid,h={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/users/").concat(this.user,"/contacts/accept/users/").concat(e,"?resource=").concat(l.clientResource),type:"POST",dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}},[4,s.hj.call(this,h,d.fI.ROSTER_ACCEPT)];case 1:return f.sent(),[2]}}))}))}var D=G;function J(e){return v(this,void 0,void 0,(function(){var t,r,i,c,u,l,h;return y(this,(function(f){switch(f.label){case 0:if(!a.XZ.call(this))return t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)];if("string"!=typeof e||""===e)throw Error('"Invalid parameter": "to"');return p.kg.debug("Call declineInvitation",e),r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l=r.jid,h={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/users/").concat(this.user,"/contacts/decline/users/").concat(e,"?resource=").concat(l.clientResource),type:"POST",dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}},[4,s.hj.call(this,h,d.fI.ROSTER_DECLINE)];case 1:return f.sent(),[2]}}))}))}var K=J;function H(e){return v(this,void 0,void 0,(function(){var t,r,i,c,u,l,h,f,m;return y(this,(function(g){switch(g.label){case 0:if(!a.XZ.call(this))return t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)];if(r=e.name,i=[],"string"==typeof r){if(""===r)throw Error('"Invalid parameter": "name"');i=[r]}else{if(!Array.isArray(r))throw Error('"Invalid parameter": "name"');i=r}return p.kg.debug("Call addToBlockList",e),c=this.context,u=c.orgName,l=c.appName,h=c.accessToken,f=c.jid,m={url:"".concat(this.apiUrl,"/").concat(u,"/").concat(l,"/sdk/user/").concat(this.user,"/blocks?resource=").concat(f.clientResource),type:"POST",dataType:"json",data:JSON.stringify({usernames:i}),headers:{Authorization:"Bearer "+h,"Content-Type":"application/json"}},[4,s.hj.call(this,m,d.fI.ROSTER_BAN).then((function(e){return{type:e.type,data:{userIds:(null==e?void 0:e.data)||[]}}}))];case 1:return[2,g.sent()]}}))}))}var F=H,q=H;function W(e){return v(this,void 0,void 0,(function(){var t,r,i,c,u,l,h,f,m;return y(this,(function(g){switch(g.label){case 0:if(!a.XZ.call(this))return t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)];if(r=e.name,i=[],"string"==typeof r){if(""===r)throw Error('"Invalid parameter": "name"');i=[r]}else{if(!Array.isArray(r))throw Error('"Invalid parameter": "name"');i=r}return p.kg.debug("Call removeFromBlockList",e),c=this.context,u=c.orgName,l=c.appName,h=c.accessToken,f=c.jid,m={url:"".concat(this.apiUrl,"/").concat(u,"/").concat(l,"/sdk/user/").concat(this.user,"/blocks?resource=").concat(f.clientResource),type:"DELETE",dataType:"json",data:JSON.stringify({usernames:i}),headers:{Authorization:"Bearer "+h,"Content-Type":"application/json"}},[4,s.hj.call(this,m,d.fI.ROSTER_ALLOW)];case 1:return g.sent(),[2]}}))}))}var V=W,Q=W;function Y(e){var t=this,r=this.getUniqueId(),a={id:r,to:e.to};this._msgHash[r]=g({},a);var n="";void 0!==e.chatType?n=e.chatType:void 0!==e.type&&(n="chat"===e.type?"singleChat":e.type);var o={id:r,type:"recall",chatType:n,ackId:e.mid,to:e.to,isChatThread:e.isChatThread||!1,success:function(r){return v(t,void 0,void 0,(function(){var t,a,o,s,i,c,u,l,p;return y(this,(function(d){switch(d.label){case 0:return d.trys.push([0,5,,6]),"singleChat"!==n&&"groupChat"!==n?[3,4]:[4,null===(o=null===(a=this._localCache)||void 0===a?void 0:a.getInstance())||void 0===o?void 0:o.removeMsgByServerMsgId(e.mid)];case 1:return d.sent(),[4,null===(i=null===(s=this._localCache)||void 0===s?void 0:s.getInstance())||void 0===i?void 0:i.getConversationLastMessage(e.to,n)];case 2:return t=d.sent(),[4,null===(u=null===(c=this._localCache)||void 0===c?void 0:c.getInstance())||void 0===u?void 0:u.updateLocalConversation((0,m.MQ)({conversationId:e.to,conversationType:n}),{lastMessageId:null==t?void 0:t.serverMsgId})];case 3:d.sent(),d.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 d.sent(),null===(p=null==e?void 0:e.success)||void 0===p||p.call(e,r),[3,6];case 6:return[2]}}))}))},fail:e.fail};return p.kg.debug("Call recallMessage",e),this.mSync.send(o,this)}function $(e){var t=e||{},r=t.messageId,a=t.modifiedMessage;if(p.kg.debug("Call modifyMessage",r,a),""===r)throw Error('Invalid parameter: "messageId"');if("txt"!==a.type)throw Error('Invalid parameter: "modifiedMessage.type"');return this.mSync.send(g({editMessageId:r},a))}function ee(e){return v(this,void 0,void 0,(function(){var t,r,i,c,u,l,p,d,h;return y(this,(function(f){switch(f.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 a.XZ.call(this)?(r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l=e.reaction,p=e.messageId,d={msgId:p,message:l},h={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/reaction/user/").concat(this.user),type:"POST",data:JSON.stringify(d),dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}},[4,s.hj.call(this,h)]):(t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)]);case 1:return f.sent(),[2]}}))}))}function te(e){return v(this,void 0,void 0,(function(){var t,r,i,c,u,l,p,d;return y(this,(function(h){switch(h.label){case 0:if("string"!=typeof e.reaction||!e.reaction)throw Error("Invalid parameter reactionId: ".concat(e.reaction));return a.XZ.call(this)?(r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l=e.messageId,p=e.reaction,d={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/reaction/user/").concat(this.user,"?msgId=").concat(l,"&message=").concat(p),type:"DELETE",dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}},[4,s.hj.call(this,d)]):(t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)]);case 1:return h.sent(),[2]}}))}))}function re(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));if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}var r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l=e.chatType,p=e.messageId,d={msgIdList:"string"==typeof p?[p]:p,msgType:"singleChat"===l?"chat":"groupchat",groupId:e.groupId||null},h={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/reaction/user/").concat(this.user),type:"GET",data:d,dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}};return s.hj.call(this,h).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=re;function ne(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));if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}var r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l=e.cursor,p=e.pageSize,d={msgId:e.messageId,message:e.reaction,currentPage:l||null,pageSize:p||20},h={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/reaction/user/").concat(this.user,"/detail"),type:"GET",data:d,dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}};return s.hj.call(this,h).then((function(e){return e.data.isAddedBySelf=e.data.state,delete e.data.state,delete e.data.reactionId,e}))}function oe(e){return v(this,void 0,void 0,(function(){var t,r,i,c,u,l,p,d,h,f,m;return y(this,(function(g){switch(g.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 a.XZ.call(this)?(r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l=e.reportType,p=e.reportReason,d=e.messageId,h={username:this.user,reportType:l,reportReason:p},f="".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/user/").concat(this.user,"/moderation/report/message/").concat(d),m={url:f,type:"POST",data:JSON.stringify(h),dataType:"json",headers:{Authorization:"Bearer "+u,"Content-Type":"application/json"}},[4,s.hj.call(this,m)]):(t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)]);case 1:return g.sent(),[2]}}))}))}function se(e){var t;return v(this,void 0,void 0,(function(){var r,i,c,u,l,d,h,f,m;return y(this,(function(g){switch(g.label){case 0:if("string"!=typeof e.targetId||""===e.targetId)throw Error('"Invalid parameter targetId": '+e.targetId);if(!["singleChat","groupChat"].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 a.XZ.call(this)?(i=this.context,c=i.orgName,u=i.appName,l=i.userId,d="singleChat"===e.chatType?"userId":"groupId",h="singleChat"===e.chatType?"chat":"group",f=e.messageIds?"".concat(this.apiUrl,"/").concat(c,"/").concat(u,"/sdk/message/roaming/").concat(h,"/user/").concat(l,"?").concat(d,"=").concat(e.targetId,"&msgIdList=").concat(e.messageIds,"&resource=").concat(this.clientResource):"".concat(this.apiUrl,"/").concat(c,"/").concat(u,"/sdk/message/roaming/").concat(h,"/user/").concat(l,"/time?").concat(d,"=").concat(e.targetId,"&delTime=").concat(e.beforeTimeStamp,"&&resource=").concat(this.clientResource),m={url:f,dataType:"json",type:"DELETE",headers:{Authorization:"Bearer "+this.token,"Content-Type":"application/json"}},p.kg.debug("Call removeHistoryMessages",e),[4,s.hj.call(this,m)]):(r=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(r)]);case 1:return g.sent(),[2]}}))}))}function ie(e){var t=this;if(!a.XZ.call(this)){var r=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});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 i=this.context,c=i.orgName,u=i.appName,l=i.accessToken,h={url:"".concat(this.apiUrl,"/").concat(c,"/").concat(u,"/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 "+l,"Content-Type":"application/json"}};return p.kg.debug("Call getServerConversations",e),new Promise((function(e,r){s.hj.call(t,h,d.fI.GET_SESSION_LIST).then((function(r){return v(t,void 0,void 0,(function(){var t,a=this;return y(this,(function(n){switch(n.label){case 0:return t=ce(r),this._localCache?[4,Promise.all(t.data.conversations.map((function(e){return v(a,void 0,void 0,(function(){var t,r,a=this;return y(this,(function(n){return null===(r=null===(t=this._localCache)||void 0===t?void 0:t.getInstance())||void 0===r||r.storeMessage(e.lastMessage,f.r.SUCCESS,!0).then((function(){var t,r;null===(r=null===(t=a._localCache)||void 0===t?void 0:t.getInstance())||void 0===r||r.updateLocalConversation((0,m.MQ)({conversationId:e.conversationId,conversationType:e.conversationType}),{unReadCount:e.unReadCount})})),[2]}))}))})))]:[3,2];case 1:return n.sent(),e(t),[2];case 2:return e(t),[2]}}))}))})).catch((function(e){r(e)}))}))}function ce(e){var t=e.data,r=t.cursor,a=t.channel_infos,n=[];null==a||a.forEach((function(e){var t=null;(null==e?void 0:e.meta)&&"{}"!==JSON.stringify(e.meta)&&(e.meta.payload=JSON.parse(e.meta.payload),"delivery"!==(t=(0,h.w)(e.meta)).type&&"read"!==t.type&&"channel"!==t.type&&(t.chatType=T[t.chatType]));var r={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:t};e.marks&&(r.marks=e.marks.map((function(e){return i.Z[e]}))),n.push(r)}));var o={conversations:n,cursor:r||""};return{type:e.type,data:o}}function ue(e){if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}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 r=this.context,i=r.orgName,c=r.appName,u=r.accessToken,l={url:"".concat(this.apiUrl,"/").concat(i,"/").concat(c,"/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 "+u,"Content-Type":"application/json"}};return p.kg.debug("Call getServerConversations",e),s.hj.call(this,l,d.fI.GET_SESSION_LIST).then((function(e){return ce(e)}))}function le(e){return v(this,void 0,void 0,(function(){var t,r,i,c,u,l,h,f,m,g,v,T,S,E;return y(this,(function(y){if(!a.XZ.call(this))return t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)];if(r=e.conversationId,i=e.conversationType,c=e.isPinned,u="singleChat"===i?"chat":"groupChat","string"!=typeof r||""===r)throw Error("Invalid parameter conversationId: ".concat(r));if(!["singleChat","groupChat"].includes(i))throw Error("Invalid parameter conversationType: ".concat(i));if("boolean"!=typeof c)throw Error("Invalid parameter isPinned: ".concat(c));return l=this.context,h=l.orgName,f=l.appName,m=l.accessToken,g=l.jid,v={type:u,to:r},T=c?"":"type=".concat(u,"&to=").concat(r,"&"),S="".concat(this.apiUrl,"/").concat(h,"/").concat(f,"/sdk/user/").concat(this.user,"/user_channel/top?").concat(T,"resource=").concat(g.clientResource),E={url:S,type:c?"POST":"DELETE",dataType:"json",headers:{Authorization:"Bearer "+m,"Content-Type":"application/json"}},c&&(E.data=JSON.stringify(v)),p.kg.debug("Call pinConversation",e),[2,s.hj.call(this,E,d.fI.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 v(this,void 0,void 0,(function(){var t,r,i,c,u,l,h,f,m,g;return y(this,(function(v){switch(v.label){case 0:if(t=e.userId,r=e.remark,!a.XZ.call(this))return i=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(i)];if("string"!=typeof t||""===t)throw Error('Invalid parameter: "userId"');if("string"!=typeof r)throw Error('Invalid parameter: "remark"');return p.kg.debug("Call setContactRemark",e),c=this.context,u=c.orgName,l=c.appName,h=c.accessToken,f=c.jid,m="".concat(this.apiUrl,"/").concat(u,"/").concat(l,"/users/").concat(this.context.userId,"/contacts/users/").concat(t,"?resource=").concat(f.clientResource),g={url:m,type:"PUT",data:JSON.stringify({remark:r}),dataType:"json",headers:{Authorization:"Bearer "+h,"Content-Type":"application/json"}},[4,s.hj.call(this,g,d.fI.ROSTER_SET_CONTACT_REMARK)];case 1:return v.sent(),[2]}}))}))}function de(){if(!a.XZ.call(this)){var e=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(e)}var t=this.context,r=t.orgName,i=t.appName,c=t.accessToken,u={url:"".concat(this.apiUrl,"/").concat(r,"/").concat(i,"/users/").concat(this.user,"/contacts/users?needReturnRemark=true"),dataType:"json",type:"GET",headers:{Authorization:"Bearer "+c}};return p.kg.debug("Call getAllContacts"),s.hj.call(this,u,d.fI.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 he(e){if(!a.XZ.call(this)){var t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(t)}p.kg.debug("Call getContactsWithCursor",e);var r=e||{},i=r.pageSize,c=void 0===i?20:i,u=r.cursor,l=void 0===u?"":u;if(c&&"number"!=typeof c)throw Error("Invalid parameter pageSize: ".concat(e.pageSize));var h=this.context,f=h.orgName,m=h.appName,g=h.accessToken,v={url:"".concat(this.apiUrl,"/").concat(f,"/").concat(m,"/users/").concat(this.user,"/contacts?needReturnRemark=true&limit=").concat(c,"&cursor=").concat(l),dataType:"json",type:"GET",headers:{Authorization:"Bearer "+g}};return s.hj.call(this,v,d.fI.ROSTER_GET_ALL_CONTACTS_REMARKS_FROM_SERVER_BY_PAGE).then((function(e){var t,r,a=(null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.contacts)||[],n=(null===(r=null==e?void 0:e.data)||void 0===r?void 0:r.cursor)||"",o=a.map((function(e){return{userId:e.username,remark:e.remark}}));return{type:e.type,data:{cursor:n,contacts:o}}}))}function fe(e){return v(this,void 0,void 0,(function(){var t,r,c,u,l,h,f,m,g,v,E,k,I,_,A;return y(this,(function(y){switch(y.label){case 0:if(!a.XZ.call(this))return t=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(t)];if(p.kg.debug("Call markConversation",e),c=(r=e||{}).conversations,u=void 0===c?[]:c,l=r.mark,h=r.isMarked,!Array.isArray(u))throw Error("Invalid parameter conversations");if(f=u.map((function(e){if(!e.conversationId||!["singleChat","groupChat"].includes(e.conversationType))throw Error("Invalid parameter conversations");return{to:e.conversationId,type:S[e.conversationType]}})),"boolean"!=typeof h)throw Error("Invalid parameter isMarked: ".concat(h));if("number"!=typeof l)throw Error("Invalid parameter mark: ".concat(l));return m=this.context,g=m.orgName,v=m.appName,E=m.accessToken,k=m.userId,I=m.jid,_={mark:i.Z[l],targets:f},A={url:"".concat(this.apiUrl,"/").concat(g,"/").concat(v,"/sdk/user/").concat(k,"/user_channels/mark?resource=").concat(I.clientResource),dataType:"json",data:JSON.stringify(_),type:h?"Post":"Delete",headers:{Authorization:"Bearer "+E}},[4,s.hj.call(this,A,d.fI.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&&p.kg.debug("markConversation has ignored conversations",r.map((function(e){return{conversationId:e.to,conversationType:T[e.type]}})))}))];case 1:return y.sent(),[2]}}))}))}function me(e){return v(this,void 0,void 0,(function(){var t,r;return y(this,(function(a){return p.kg.debug("Call addConversationMark",e),t=e.conversations,r=e.mark,[2,fe.call(this,{conversations:t,mark:r,isMarked:!0})]}))}))}function ge(e){return v(this,void 0,void 0,(function(){var t,r;return y(this,(function(a){return p.kg.debug("Call removeConversationMark",e),t=e.conversations,r=e.mark,[2,fe.call(this,{conversations:t,mark:r,isMarked:!1})]}))}))}function ve(e){var t,r;if(!a.XZ.call(this)){var c=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(c)}if(p.kg.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 u=this.context,l=u.orgName,h=u.appName,f=u.accessToken,m="".concat(this.apiUrl,"/").concat(l,"/").concat(h,"/sdk/user/").concat(this.user,"/user_channels/mark/search?"),g=e.pageSize,v=e.cursor,y=((null==e?void 0:e.filter)||{}).mark,T={url:m,type:"GET",dataType:"json",data:{limit:g||10,cursor:v||"",need_mark:!0,mark:i.Z[y]},headers:{Authorization:"Bearer "+f,"Content-Type":"application/json"}};return s.hj.call(this,T,d.fI.GET_SESSION_LIST).then((function(e){return ce(e)}))}function ye(){if(!a.XZ.call(this)){var e=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"});return Promise.reject(e)}p.kg.debug("Call getSelfIdsOnOtherPlatform");var t=this.context,r=t.orgName,i=t.appName,c=t.accessToken,u=t.userId,l=t.jid,h={url:"".concat(this.apiUrl,"/").concat(r,"/").concat(i,"/users/").concat(u,"/resources"),type:"GET",dataType:"json",headers:{Authorization:"Bearer "+c,"Content-Type":"application/json"}};return s.hj.call(this,h,d.fI.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!==l.clientResource})),a=null==r?void 0:r.map((function(e){return"".concat(u,"/").concat(e.res)}));return{type:e.type,data:a}}))}function Te(){var e,t,r,i,c,u;return v(this,void 0,void 0,(function(){var l,h,f,m,g,v,T,S,E;return y(this,(function(y){switch(y.label){case 0:return a.XZ.call(this)?(p.kg.debug("Call deleteAllMessagesAndConversations"),h=this.context,f=h.orgName,m=h.appName,g=h.accessToken,v=h.userId,T=h.jid,S="".concat(this.apiUrl,"/").concat(f,"/").concat(m,"/sdk/message/roaming/user/").concat(v,"/delete/all?resource=").concat(T.clientResource),E={url:S,type:"POST",dataType:"json",headers:{Authorization:"Bearer "+g,"Content-Type":"application/json"}},[4,s.hj.call(this,E,d.fI.REST_DELETE_MESSAGES_CONVERSATIONS)]):(l=o.Z.create({type:n.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(l)]);case 1:return y.sent(),null===(t=null===(e=this._localCache)||void 0===e?void 0:e.getInstance())||void 0===t||t.clearConversationMap(),[4,null===(i=null===(r=this._localCache)||void 0===r?void 0:r.getInstance())||void 0===i?void 0:i.clearStoreData("conversationList")];case 2:return y.sent(),[4,null===(u=null===(c=this._localCache)||void 0===c?void 0:c.getInstance())||void 0===u?void 0:u.clearStoreData("message")];case 3:return y.sent(),[2]}}))}))}},3246:function(e,t,r){r.d(t,{H7:function(){return u},XZ:function(){return i},_W:function(){return c}}),r(7941),r(9554),r(1539),r(4747),r(6699),r(2023);var a=r(5531),n=r(7252);function o(){var e=this.context.appName,t=this.context.orgName;return!(!e||!t)||(this.onError&&this.onError({type:a.E.WEBIM_CONNCTION_AUTH_ERROR,message:"appName or orgName is illegal"}),!1)}function s(){var e;if(!this.context.accessToken){var t=n.Z.create({type:a.E.WEBIM_CONNCTION_TOKEN_NOT_ASSIGN_ERROR,message:"token not assign error"});return this.onError&&this.onError(t),null===(e=this.eventHandler)||void 0===e||e.dispatch("onError",t),!1}return!0}function i(){return s.call(this)&&o.call(this)}function c(e){var t=e.data,r=e.type;return{data:{status:Object.keys(t.errorKeys).length>0?"fail":"success",errorKeys:t.errorKeys,successKeys:t.successKeys},type:r}}function u(e){var t=e.data,r=void 0;return Object.keys(t.errorKeys).length>0&&Object.keys(t.errorKeys).forEach((function(e){var o=t.errorKeys[e];r=o.includes("is not part of you")?n.Z.create({type:a.E.NO_PERMISSION,message:o}):o.includes("size of metadata for this single chatroom exceeds the user defined limit")||o.includes("total size of chatroom metadata for this app exceeds the user defined limit")||o.includes("is exceeding maximum limit")?n.Z.create({type:a.E.MAX_LIMIT,message:o}):o.includes("is not Legal")?n.Z.create({type:a.E.REQUEST_PARAMETER_ERROR,message:o}):o.includes("Failed to update userMetadata. Concurrent updates not allowed")?n.Z.create({type:a.E.OPERATION_NOT_ALLOWED,message:o}):n.Z.create({type:a.E.WEBIM_CONNCTION_AJAX_ERROR,message:o})})),r}},5069:function(e,t,r){var a=r(2109),n=r(1702),o=r(3157),s=n([].reverse),i=[1,2];a({target:"Array",proto:!0,forced:String(i)===String(i.reverse())},{reverse:function(){return o(this)&&(this.length=this.length),s(this)}})}},function(e){return 7479,e(e.s=7479)}])}));
|
package/localCache/localCache.js
CHANGED
|
@@ -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([[653],{3246:function(e,t,n){n.d(t,{H7:function(){return u},XZ:function(){return i},_W:function(){return c}}),n(7941),n(9554),n(1539),n(4747),n(6699),n(2023);var r=n(5531),o=n(7252);function s(){var e=this.context.appName,t=this.context.orgName;return!(!e||!t)||(this.onError&&this.onError({type:r.E.WEBIM_CONNCTION_AUTH_ERROR,message:"appName or orgName is illegal"}),!1)}function a(){var e;if(!this.context.accessToken){var t=o.Z.create({type:r.E.WEBIM_CONNCTION_TOKEN_NOT_ASSIGN_ERROR,message:"token not assign error"});return this.onError&&this.onError(t),null===(e=this.eventHandler)||void 0===e||e.dispatch("onError",t),!1}return!0}function i(){return a.call(this)&&s.call(this)}function c(e){var t=e.data,n=e.type;return{data:{status:Object.keys(t.errorKeys).length>0?"fail":"success",errorKeys:t.errorKeys,successKeys:t.successKeys},type:n}}function u(e){var t=e.data,n=void 0;return Object.keys(t.errorKeys).length>0&&Object.keys(t.errorKeys).forEach((function(e){var s=t.errorKeys[e];n=s.includes("is not part of you")?o.Z.create({type:r.E.NO_PERMISSION,message:s}):s.includes("size of metadata for this single chatroom exceeds the user defined limit")||s.includes("total size of chatroom metadata for this app exceeds the user defined limit")||s.includes("is exceeding maximum limit")?o.Z.create({type:r.E.MAX_LIMIT,message:s}):s.includes("is not Legal")?o.Z.create({type:r.E.REQUEST_PARAMETER_ERROR,message:s}):s.includes("Failed to update userMetadata. Concurrent updates not allowed")?o.Z.create({type:r.E.OPERATION_NOT_ALLOWED,message:s}):o.Z.create({type:r.E.WEBIM_CONNCTION_AJAX_ERROR,message:s})})),n}},6007:function(e,t,n){n.r(t),n.d(t,{LocalCache:function(){return _},LocalCacheApi:function(){return r}});var r={};n.r(r),n.d(r,{clearConversationUnreadCount:function(){return K},getLocalConversation:function(){return F},getLocalConversations:function(){return P},removeLocalConversation:function(){return Z},setLocalConversationCustomField:function(){return j}}),n(1539),n(8674),n(2526),n(1817),n(2165),n(6992),n(8783),n(3948),n(1249),n(6699),n(3710),n(9601);const o=(e,t)=>t.some((t=>e instanceof t));let s,a;const i=new WeakMap,c=new WeakMap,u=new WeakMap,l=new WeakMap,d=new WeakMap;let v={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return c.get(e);if("objectStoreNames"===t)return e.objectStoreNames||u.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return h(e[t])},set(e,t,n){return e[t]=n,!0},has(e,t){return e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e}};function p(e){return"function"==typeof e?(t=e)!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(a||(a=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(t)?function(...e){return t.apply(f(this),e),h(i.get(this))}:function(...e){return h(t.apply(f(this),e))}:function(e,...n){const r=t.call(f(this),e,...n);return u.set(r,e.sort?e.sort():[e]),h(r)}:(e instanceof IDBTransaction&&function(e){if(c.has(e))return;const t=new Promise(((t,n)=>{const r=()=>{e.removeEventListener("complete",o),e.removeEventListener("error",s),e.removeEventListener("abort",s)},o=()=>{t(),r()},s=()=>{n(e.error||new DOMException("AbortError","AbortError")),r()};e.addEventListener("complete",o),e.addEventListener("error",s),e.addEventListener("abort",s)}));c.set(e,t)}(e),o(e,s||(s=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,v):e);var t}function h(e){if(e instanceof IDBRequest)return function(e){const t=new Promise(((t,n)=>{const r=()=>{e.removeEventListener("success",o),e.removeEventListener("error",s)},o=()=>{t(h(e.result)),r()},s=()=>{n(e.error),r()};e.addEventListener("success",o),e.addEventListener("error",s)}));return t.then((t=>{t instanceof IDBCursor&&i.set(t,e)})).catch((()=>{})),d.set(t,e),t}(e);if(l.has(e))return l.get(e);const t=p(e);return t!==e&&(l.set(e,t),d.set(t,e)),t}const f=e=>d.get(e);function y(e,t,{blocked:n,upgrade:r,blocking:o,terminated:s}={}){const a=indexedDB.open(e,t),i=h(a);return r&&a.addEventListener("upgradeneeded",(e=>{r(h(a.result),e.oldVersion,e.newVersion,h(a.transaction),e)})),n&&a.addEventListener("blocked",(e=>n(e.oldVersion,e.newVersion,e))),i.then((e=>{s&&e.addEventListener("close",(()=>s())),o&&e.addEventListener("versionchange",(e=>o(e.oldVersion,e.newVersion,e)))})).catch((()=>{})),i}const g=["get","getKey","getAll","getAllKeys","count"],m=["put","add","delete","clear"],b=new Map;function I(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(b.get(t))return b.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,o=m.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!o&&!g.includes(n))return;const s=async function(e,...t){const s=this.transaction(e,o?"readwrite":"readonly");let a=s.store;return r&&(a=a.index(t.shift())),(await Promise.all([a[n](...t),o&&s.done]))[0]};return b.set(t,s),s}var C;C=v,v={...C,get:(e,t,n)=>I(e,t)||C.get(e,t,n),has:(e,t)=>!!I(e,t)||C.has(e,t)};var E=n(7360),T=n(9743),w=n(7288),M=function(){return M=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},M.apply(this,arguments)},S=function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function a(e){try{c(r.next(e))}catch(e){s(e)}}function i(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,i)}c((r=r.apply(e,t||[])).next())}))},L=function(e,t){var n,r,o,s,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function i(s){return function(i){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,i])}}},k=new Date("2023/01/01"),_=function(){function e(e){var t=e.user,n=e.dbName,r=e.version,o=e.onInit;this.localCache=void 0,this.user="",this.conversationMap={},this.onInit=o,this.init({user:t,dbName:n,version:r})}return e.prototype.init=function(t){return S(this,void 0,void 0,(function(){var n,r,o,s;return L(this,(function(a){switch(a.label){case 0:n=t.dbName,r=t.version,o=t.user,this.user=o,a.label=1;case 1:return a.trys.push([1,3,,4]),[4,y(n,r,{upgrade:function(e,t,n,r){if(t<1){var o=e.createObjectStore("message",{keyPath:"id"});o.createIndex("sessionId","sessionId"),o.createIndex("time","time"),o.createIndex("serverMsgId","serverMsgId",{unique:!0}),o.createIndex("sessionTime",["sessionId","time"],{unique:!0}),e.createObjectStore("conversationList",{keyPath:"sessionId"}).createIndex("updateTime","updateTime")}}})];case 2:return s=a.sent(),this.localCache=s,e.instance||(e.instance=this,this.onInit()),[3,4];case 3:return a.sent(),E.kg.debug("open db error"),[3,4];case 4:return[2]}}))}))},e.getInstance=function(){return e.instance},e.prototype.close=function(){var t;null===(t=this.localCache)||void 0===t||t.close(),this.conversationMap={},e.instance=void 0,E.kg.debug("close db success")},e.prototype.storeConversation=function(e,t,n,r){return S(this,void 0,void 0,(function(){var o,s,a,i,c;return L(this,(function(u){switch(u.label){case 0:return u.trys.push([0,4,,5]),o=(0,T.MQ)({conversationId:e,conversationType:t}),s=M({conversationId:e,conversationType:t,sessionId:o},n),(i=this.conversationMap[o])?[3,2]:[4,this.getConversationBySessionId(o)];case 1:i=u.sent(),u.label=2;case 2:return a=i||s,this.conversationMap[o]||(this.conversationMap[o]=a),a&&(r&&(this.conversationMap[o].unReadCount=(a.unReadCount||0)+1,s.unReadCount=this.conversationMap[o].unReadCount||0),s=M(M({},a),s)),[4,this.putConversationToDB(s)];case 3:return u.sent(),[3,5];case 4:return c=u.sent(),E.kg.debug("store conversation error",c),[3,5];case 5:return[2]}}))}))},e.prototype.putConversationToDB=function(e){var t;return S(this,void 0,void 0,(function(){var n;return L(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,null===(t=this.localCache)||void 0===t?void 0:t.put("conversationList",e)];case 1:return r.sent(),[3,3];case 2:return n=r.sent(),E.kg.debug("put conversation to local error",n),[3,3];case 3:return[2]}}))}))},e.prototype.getConversationBySessionId=function(e){var t;return S(this,void 0,void 0,(function(){var n;return L(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,null===(t=this.localCache)||void 0===t?void 0:t.get("conversationList",e)];case 1:return[2,r.sent()];case 2:return n=r.sent(),E.kg.debug("get conversation by sessionId error",n),[3,3];case 3:return[2]}}))}))},e.prototype.removeConversationBySessionId=function(e){var t;return S(this,void 0,void 0,(function(){return L(this,(function(n){try{return this.conversationMap[e]&&delete this.conversationMap[e],[2,null===(t=this.localCache)||void 0===t?void 0:t.delete("conversationList",e)]}catch(e){E.kg.debug("remove conversation by sessionId error",e)}return[2]}))}))},e.prototype.getConversationList=function(){var e;return S(this,void 0,void 0,(function(){var t,n,r;return L(this,(function(o){switch(o.label){case 0:t=[],o.label=1;case 1:return o.trys.push([1,6,,7]),[4,null===(e=this.localCache)||void 0===e?void 0:e.transaction("conversationList").store.index("updateTime").openCursor(null,"prev")];case 2:n=o.sent(),o.label=3;case 3:return n?(t.push(n.value),[4,n.continue()]):[3,5];case 4:return n=o.sent(),[3,3];case 5:return[2,t];case 6:return r=o.sent(),E.kg.debug("get local conversationList error",r),[3,7];case 7:return[2]}}))}))},e.prototype.storeMessage=function(e,t,n){return S(this,void 0,void 0,(function(){var r,o,s,a,i,c,u;return L(this,(function(l){switch(l.label){case 0:return l.trys.push([0,5,,6]),r=M({},e),o={},s=!1,a=r.to,i=!1,"chatRoom"===r.chatType||r.chatThread||r.isChatThread?[2]:("groupChat"===r.chatType?s=Boolean(r.from&&r.from!==this.user):"singleChat"===r.chatType&&this.user===r.to&&(s=!0,a=r.from||r.to),"audio"!==r.type&&"video"!==r.type&&"file"!==r.type&&"combine"!==r.type&&"img"!==r.type||(delete r.onFileUploadComplete,delete r.onFileUploadError,delete r.onFileUploadProgress),"combine"!==r.type&&(delete r.success,delete r.fail),Object.assign(r,{sessionId:(0,T.MQ)({conversationId:a,conversationType:null==r?void 0:r.chatType}),status:t,serverMsgId:r.id}),[4,this.getMessageByServerMsgId(r.id)]);case 1:return(null==(c=l.sent())?void 0:c.status)===w.r.SUCCESS?[3,3]:[4,this.putMessageToDB(r)];case 2:l.sent(),l.label=3;case 3:return t>w.r.INPROGRESS&&Object.assign(o,{updateTime:r.time,lastMessageId:r.id}),s&&(i=!0,Object.assign(o,{lastMessageFromOtherId:r.id})),[4,this.storeConversation(a,r.chatType,o,!n&&i)];case 4:return l.sent(),[3,6];case 5:return u=l.sent(),E.kg.debug("store message error",u),[3,6];case 6:return[2]}}))}))},e.prototype.updateLocalMessage=function(e,t){return void 0===t&&(t={}),S(this,void 0,void 0,(function(){var n,r;return L(this,(function(o){switch(o.label){case 0:return o.trys.push([0,5,,6]),[4,this.getMessageByServerMsgId(e)];case 1:return(n=o.sent())?[4,this.putMessageToDB(M(M({},n),t))]:[3,4];case 2:return o.sent(),[4,this.updateLocalConversation((0,T.MQ)({conversationId:n.to,conversationType:n.chatType}),{lastMessageId:t.serverMsgId,updateTime:n.time})];case 3:o.sent(),o.label=4;case 4:return[3,6];case 5:return r=o.sent(),E.kg.debug("update local message error",r),[3,6];case 6:return[2]}}))}))},e.prototype.updateLocalConversation=function(e,t){return S(this,void 0,void 0,(function(){var n=this;return L(this,(function(r){try{return[2,this.getConversationBySessionId(e).then((function(r){if(r){var o=M(M({},r),t);n.putConversationToDB(o),n.conversationMap[e]=o}}))]}catch(e){E.kg.debug("update local conversation error",e)}return[2]}))}))},e.prototype.removeMsgByServerMsgId=function(e){var t,n;return S(this,void 0,void 0,(function(){var r,o;return L(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,null===(t=this.localCache)||void 0===t?void 0:t.getFromIndex("message","serverMsgId",e)];case 1:return r=s.sent(),[2,null===(n=this.localCache)||void 0===n?void 0:n.delete("message",(null==r?void 0:r.id)||"")];case 2:return o=s.sent(),E.kg.debug("remove msg by serverId error",o),[3,3];case 3:return[2]}}))}))},e.prototype.removeMsgBySessionId=function(e){var t;return S(this,void 0,void 0,(function(){var n,r;return L(this,(function(o){switch(o.label){case 0:return o.trys.push([0,6,,7]),[4,null===(t=this.localCache)||void 0===t?void 0:t.transaction("message","readwrite").store.index("sessionId").openCursor(IDBKeyRange.only(e))];case 1:n=o.sent(),o.label=2;case 2:return n?[4,n.delete()]:[3,5];case 3:return o.sent(),[4,n.continue()];case 4:return n=o.sent(),[3,2];case 5:return[3,7];case 6:return r=o.sent(),E.kg.debug("remove msg by sessionId",r),[3,7];case 7:return[2]}}))}))},e.prototype.putMessageToDB=function(e){var t;return S(this,void 0,void 0,(function(){var n;return L(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,null===(t=this.localCache)||void 0===t?void 0:t.put("message",e)];case 1:return[2,r.sent()];case 2:return n=r.sent(),E.kg.debug("put msg to local error",n),[3,3];case 3:return[2]}}))}))},e.prototype.getConversationLastMessage=function(e,t){var n,r;return S(this,void 0,void 0,(function(){var o,s,a;return L(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),o=(0,T.MQ)({conversationId:e,conversationType:t}),[4,null===(r=null===(n=this.localCache)||void 0===n?void 0:n.transaction("message").store)||void 0===r?void 0:r.index("sessionTime").openCursor(IDBKeyRange.bound([o,k.getTime()],[o,(new Date).getTime()]),"prev")];case 1:return(s=i.sent())?[2,s.value]:[2,void 0];case 2:return a=i.sent(),E.kg.debug("get conversation last msg error",a),[3,3];case 3:return[2]}}))}))},e.prototype.getMessageByServerMsgId=function(e){var t;return S(this,void 0,void 0,(function(){var n;return L(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,null===(t=this.localCache)||void 0===t?void 0:t.getFromIndex("message","serverMsgId",e)];case 1:return[2,r.sent()];case 2:return n=r.sent(),E.kg.debug("get msg by serverId error",n),[3,3];case 3:return[2]}}))}))},e}(),B=n(7252),O=n(3246),R=n(5531);function D(e){return D="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},D(e)}var A=function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function a(e){try{c(r.next(e))}catch(e){s(e)}}function i(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,i)}c((r=r.apply(e,t||[])).next())}))},x=function(e,t){var n,r,o,s,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function i(s){return function(i){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,i])}}},N=["singleChat","groupChat"];function P(){var e,t;return A(this,void 0,void 0,(function(){var n,r,o,s=this;return x(this,(function(a){switch(a.label){case 0:if(E.kg.debug("Call getLocalConversations"),!O.XZ.call(this))return n=B.Z.create({type:R.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(n)];a.label=1;case 1:return a.trys.push([1,4,,5]),[4,null===(t=null===(e=this._localCache)||void 0===e?void 0:e.getInstance())||void 0===t?void 0:t.getConversationList()];case 2:return r=a.sent()||[],[4,Promise.all(r.map((function(e){var t=e.conversationId,n=e.lastMessageId,r=e.unReadCount,o=e.conversationType,a=e.customField;return A(s,void 0,void 0,(function(){var e,s,i,c;return x(this,(function(u){switch(u.label){case 0:return s={conversationId:t,conversationType:o,unReadCount:r||0,customField:a},n?[4,null===(c=null===(i=this._localCache)||void 0===i?void 0:i.getInstance())||void 0===c?void 0:c.getMessageByServerMsgId(n)]:[3,2];case 1:return e=u.sent(),[3,3];case 2:e=void 0,u.label=3;case 3:return[2,(s.lastMessage=e,s)]}}))}))})))];case 3:return[2,{type:0,data:a.sent()}];case 4:throw o=a.sent(),B.Z.create({type:R.E.LOCAL_DB_OPERATION_FAILED,message:"getLocalConversations is failed",data:o});case 5:return[2]}}))}))}function j(e){var t,n;return A(this,void 0,void 0,(function(){var r,o,s,a,i;return x(this,(function(c){switch(c.label){case 0:if(E.kg.debug("Call setLocalConversationCustomField",e),!O.XZ.call(this))return r=B.Z.create({type:R.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(r)];if(o=e.conversationType,s=e.conversationId,a=e.customField,!N.includes(o))throw Error('"Invalid parameter conversationType": '+o);if("string"!=typeof s||""===s)throw Error('Invalid parameter: "conversationId"');if("object"!==D(a))throw Error('Invalid parameter: "customField"');c.label=1;case 1:return c.trys.push([1,3,,4]),[4,null===(n=null===(t=this._localCache)||void 0===t?void 0:t.getInstance())||void 0===n?void 0:n.updateLocalConversation((0,T.MQ)({conversationId:s,conversationType:o}),{customField:a})];case 2:return c.sent(),[3,4];case 3:throw i=c.sent(),B.Z.create({type:R.E.LOCAL_DB_OPERATION_FAILED,message:"setLocalConversationCustomField is failed",data:i});case 4:return[2]}}))}))}function F(e){var t,n,r,o;return A(this,void 0,void 0,(function(){var s,a,i,c,u,l,d,v,p;return x(this,(function(h){switch(h.label){case 0:if(E.kg.debug("Call getLocalConversation",e),!O.XZ.call(this))return s=B.Z.create({type:R.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(s)];if(a=e.conversationType,i=e.conversationId,!N.includes(a))throw Error('"Invalid parameter conversationType": '+a);if("string"!=typeof i||""===i)throw Error('Invalid parameter: "conversationId"');h.label=1;case 1:return h.trys.push([1,8,,9]),[4,null===(n=null===(t=this._localCache)||void 0===t?void 0:t.getInstance())||void 0===n?void 0:n.getConversationBySessionId((0,T.MQ)({conversationId:i,conversationType:a}))];case 2:return c=h.sent(),v={type:0},c?(p={conversationId:c.conversationId,conversationType:a,unReadCount:c.unReadCount||0,customField:c.customField},c.lastMessageId?[4,null===(o=null===(r=this._localCache)||void 0===r?void 0:r.getInstance())||void 0===o?void 0:o.getMessageByServerMsgId(c.lastMessageId)]:[3,4]):[3,6];case 3:return l=h.sent(),[3,5];case 4:l=void 0,h.label=5;case 5:return p.lastMessage=l,u=p,[3,7];case 6:u=void 0,h.label=7;case 7:return[2,(v.data=u,v)];case 8:throw d=h.sent(),B.Z.create({type:R.E.LOCAL_DB_OPERATION_FAILED,message:"getLocalConversation is failed",data:d});case 9:return[2]}}))}))}function Z(e){var t,n,r,o;return A(this,void 0,void 0,(function(){var s,a,i,c,u,l,d;return x(this,(function(v){switch(v.label){case 0:if(E.kg.debug("Call removeLocalConversation",e),!O.XZ.call(this))return s=B.Z.create({type:R.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(s)];if(a=e.conversationType,i=e.conversationId,c=e.isRemoveLocalMessage,u=void 0===c||c,!N.includes(a))throw Error('"Invalid parameter conversationType": '+a);if("string"!=typeof i||""===i)throw Error('Invalid parameter: "conversationId"');l=(0,T.MQ)({conversationId:i,conversationType:a}),v.label=1;case 1:return v.trys.push([1,5,,6]),[4,null===(n=null===(t=this._localCache)||void 0===t?void 0:t.getInstance())||void 0===n?void 0:n.removeConversationBySessionId(l)];case 2:return v.sent(),u?[4,null===(o=null===(r=this._localCache)||void 0===r?void 0:r.getInstance())||void 0===o?void 0:o.removeMsgBySessionId(l)]:[3,4];case 3:v.sent(),v.label=4;case 4:return[3,6];case 5:throw d=v.sent(),B.Z.create({type:R.E.LOCAL_DB_OPERATION_FAILED,message:"removeLocalConversation is failed",data:d});case 6:return[2]}}))}))}function K(e){var t,n;return A(this,void 0,void 0,(function(){var r,o,s,a;return x(this,(function(i){switch(i.label){case 0:if(E.kg.debug("Call clearConversationUnreadCount",e),!O.XZ.call(this))return r=B.Z.create({type:R.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(r)];if(o=e.conversationType,s=e.conversationId,!N.includes(o))throw Error('"Invalid parameter conversationType": '+o);if("string"!=typeof s||""===s)throw Error('Invalid parameter: "conversationId"');i.label=1;case 1:return i.trys.push([1,3,,4]),[4,null===(n=null===(t=this._localCache)||void 0===t?void 0:t.getInstance())||void 0===n?void 0:n.updateLocalConversation((0,T.MQ)({conversationId:s,conversationType:o}),{unReadCount:0,unreadCountClearTimestamp:(new Date).getTime()})];case 2:return i.sent(),[3,4];case 3:throw a=i.sent(),B.Z.create({type:R.E.LOCAL_DB_OPERATION_FAILED,message:"clearConversationUnreadCount is failed",data:a});case 4:return[2]}}))}))}}},function(e){return 6007,e(e.s=6007)}])}));
|
|
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([[653],{3246:function(e,t,n){n.d(t,{H7:function(){return u},XZ:function(){return i},_W:function(){return c}}),n(7941),n(9554),n(1539),n(4747),n(6699),n(2023);var r=n(5531),o=n(7252);function s(){var e=this.context.appName,t=this.context.orgName;return!(!e||!t)||(this.onError&&this.onError({type:r.E.WEBIM_CONNCTION_AUTH_ERROR,message:"appName or orgName is illegal"}),!1)}function a(){var e;if(!this.context.accessToken){var t=o.Z.create({type:r.E.WEBIM_CONNCTION_TOKEN_NOT_ASSIGN_ERROR,message:"token not assign error"});return this.onError&&this.onError(t),null===(e=this.eventHandler)||void 0===e||e.dispatch("onError",t),!1}return!0}function i(){return a.call(this)&&s.call(this)}function c(e){var t=e.data,n=e.type;return{data:{status:Object.keys(t.errorKeys).length>0?"fail":"success",errorKeys:t.errorKeys,successKeys:t.successKeys},type:n}}function u(e){var t=e.data,n=void 0;return Object.keys(t.errorKeys).length>0&&Object.keys(t.errorKeys).forEach((function(e){var s=t.errorKeys[e];n=s.includes("is not part of you")?o.Z.create({type:r.E.NO_PERMISSION,message:s}):s.includes("size of metadata for this single chatroom exceeds the user defined limit")||s.includes("total size of chatroom metadata for this app exceeds the user defined limit")||s.includes("is exceeding maximum limit")?o.Z.create({type:r.E.MAX_LIMIT,message:s}):s.includes("is not Legal")?o.Z.create({type:r.E.REQUEST_PARAMETER_ERROR,message:s}):s.includes("Failed to update userMetadata. Concurrent updates not allowed")?o.Z.create({type:r.E.OPERATION_NOT_ALLOWED,message:s}):o.Z.create({type:r.E.WEBIM_CONNCTION_AJAX_ERROR,message:s})})),n}},6007:function(e,t,n){n.r(t),n.d(t,{LocalCache:function(){return B},LocalCacheApi:function(){return r}});var r={};n.r(r),n.d(r,{clearConversationUnreadCount:function(){return K},getLocalConversation:function(){return F},getLocalConversations:function(){return P},removeLocalConversation:function(){return Z},setLocalConversationCustomField:function(){return j}}),n(1539),n(8674),n(2526),n(1817),n(2165),n(6992),n(8783),n(3948),n(1249),n(6699),n(3710),n(9601),n(2772);const o=(e,t)=>t.some((t=>e instanceof t));let s,a;const i=new WeakMap,c=new WeakMap,u=new WeakMap,l=new WeakMap,d=new WeakMap;let v={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return c.get(e);if("objectStoreNames"===t)return e.objectStoreNames||u.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return h(e[t])},set(e,t,n){return e[t]=n,!0},has(e,t){return e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e}};function p(e){return"function"==typeof e?(t=e)!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(a||(a=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(t)?function(...e){return t.apply(f(this),e),h(i.get(this))}:function(...e){return h(t.apply(f(this),e))}:function(e,...n){const r=t.call(f(this),e,...n);return u.set(r,e.sort?e.sort():[e]),h(r)}:(e instanceof IDBTransaction&&function(e){if(c.has(e))return;const t=new Promise(((t,n)=>{const r=()=>{e.removeEventListener("complete",o),e.removeEventListener("error",s),e.removeEventListener("abort",s)},o=()=>{t(),r()},s=()=>{n(e.error||new DOMException("AbortError","AbortError")),r()};e.addEventListener("complete",o),e.addEventListener("error",s),e.addEventListener("abort",s)}));c.set(e,t)}(e),o(e,s||(s=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,v):e);var t}function h(e){if(e instanceof IDBRequest)return function(e){const t=new Promise(((t,n)=>{const r=()=>{e.removeEventListener("success",o),e.removeEventListener("error",s)},o=()=>{t(h(e.result)),r()},s=()=>{n(e.error),r()};e.addEventListener("success",o),e.addEventListener("error",s)}));return t.then((t=>{t instanceof IDBCursor&&i.set(t,e)})).catch((()=>{})),d.set(t,e),t}(e);if(l.has(e))return l.get(e);const t=p(e);return t!==e&&(l.set(e,t),d.set(t,e)),t}const f=e=>d.get(e);function g(e,t,{blocked:n,upgrade:r,blocking:o,terminated:s}={}){const a=indexedDB.open(e,t),i=h(a);return r&&a.addEventListener("upgradeneeded",(e=>{r(h(a.result),e.oldVersion,e.newVersion,h(a.transaction),e)})),n&&a.addEventListener("blocked",(e=>n(e.oldVersion,e.newVersion,e))),i.then((e=>{s&&e.addEventListener("close",(()=>s())),o&&e.addEventListener("versionchange",(e=>o(e.oldVersion,e.newVersion,e)))})).catch((()=>{})),i}const y=["get","getKey","getAll","getAllKeys","count"],m=["put","add","delete","clear"],b=new Map;function I(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(b.get(t))return b.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,o=m.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!o&&!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 C;C=v,v={...C,get:(e,t,n)=>I(e,t)||C.get(e,t,n),has:(e,t)=>!!I(e,t)||C.has(e,t)};var T=n(7360),E=n(9743),w=n(7288),M=function(){return M=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},M.apply(this,arguments)},k=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())}))},S=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])}}},L=new Date("2023/01/01"),B=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 k(this,void 0,void 0,(function(){var n,r,o,s;return S(this,(function(a){switch(a.label){case 0:T.kg.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,g(n,r,{upgrade:function(e,t,n,r){if(t<1){T.kg.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){T.kg.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(),T.kg.debug("open db error"),[3,4];case 4:return[2]}}))}))},e.getInstance=function(){return e.instance},e.prototype.close=function(){var t;null===(t=this.localCache)||void 0===t||t.close(),this.clearConversationMap(),e.instance=void 0,T.kg.debug("close db success")},e.prototype.storeConversation=function(e,t,n,r){return k(this,void 0,void 0,(function(){var o,s,a,i,c;return S(this,(function(u){switch(u.label){case 0:return u.trys.push([0,4,,5]),o=(0,E.MQ)({conversationId:e,conversationType:t}),s=M({conversationId:e,conversationType:t,sessionId:o},n),(i=this.conversationMap[o])?[3,2]:[4,this.getConversationBySessionId(o)];case 1:i=u.sent(),u.label=2;case 2:return a=i||s,this.conversationMap[o]||(this.conversationMap[o]=a),a&&(r&&(this.conversationMap[o].unReadCount=(a.unReadCount||0)+1,s.unReadCount=this.conversationMap[o].unReadCount||0),s=M(M({},a),s)),[4,this.putConversationToDB(s)];case 3:return u.sent(),[3,5];case 4:return c=u.sent(),T.kg.debug("store conversation error",c),[3,5];case 5:return[2]}}))}))},e.prototype.putConversationToDB=function(e){var t;return k(this,void 0,void 0,(function(){var n;return S(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(),T.kg.debug("put conversation to local error",n),[3,3];case 3:return[2]}}))}))},e.prototype.getConversationBySessionId=function(e){var t;return k(this,void 0,void 0,(function(){var n;return S(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(),T.kg.debug("get conversation by sessionId error",n),[3,3];case 3:return[2]}}))}))},e.prototype.removeConversationBySessionId=function(e){var t;return k(this,void 0,void 0,(function(){return S(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){T.kg.debug("remove conversation by sessionId error",e)}return[2]}))}))},e.prototype.getConversationList=function(){var e;return k(this,void 0,void 0,(function(){var t,n,r;return S(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(),T.kg.debug("get local conversationList error",r),[3,7];case 7:return[2]}}))}))},e.prototype.storeMessage=function(e,t,n){return k(this,void 0,void 0,(function(){var r,o,s,a,i,c,u,l,d;return S(this,(function(v){switch(v.label){case 0:return v.trys.push([0,5,,6]),r=M({},e),o={},s=!1,a=r.to,i=!1,"chatRoom"===r.chatType||r.chatThread||r.isChatThread?[2]:("groupChat"===r.chatType?s=Boolean(r.from&&r.from!==this.user):"singleChat"===r.chatType&&(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,E.MQ)({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)===w.r.SUCCESS?[3,3]:[4,this.putMessageToDB(r)];case 2:v.sent(),v.label=3;case 3:return t>w.r.INPROGRESS&&Object.assign(o,{updateTime:r.time,lastMessageId:r.id}),s&&(i=!0,Object.assign(o,{lastMessageFromOtherId:r.id})),[4,this.storeConversation(a,r.chatType,o,!n&&i)];case 4:return v.sent(),[3,6];case 5:return d=v.sent(),T.kg.debug("store message error",d),[3,6];case 6:return[2]}}))}))},e.prototype.updateLocalMessage=function(e,t){return void 0===t&&(t={}),k(this,void 0,void 0,(function(){var n,r;return S(this,(function(o){switch(o.label){case 0:return o.trys.push([0,5,,6]),[4,this.getMessageByServerMsgId(e)];case 1:return(n=o.sent())?[4,this.putMessageToDB(M(M({},n),t))]:[3,4];case 2:return o.sent(),[4,this.updateLocalConversation((0,E.MQ)({conversationId:n.to,conversationType:n.chatType}),{lastMessageId:t.serverMsgId,updateTime:n.time})];case 3:o.sent(),o.label=4;case 4:return[3,6];case 5:return r=o.sent(),T.kg.debug("update local message error",r),[3,6];case 6:return[2]}}))}))},e.prototype.updateLocalConversation=function(e,t){return k(this,void 0,void 0,(function(){var n=this;return S(this,(function(r){try{return[2,this.getConversationBySessionId(e).then((function(r){if(r){var o=M(M({},r),t);n.putConversationToDB(o),n.conversationMap[e]=o}}))]}catch(e){T.kg.debug("update local conversation error",e)}return[2]}))}))},e.prototype.removeMsgByServerMsgId=function(e){var t,n;return k(this,void 0,void 0,(function(){var r,o;return S(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(),T.kg.debug("remove msg by serverId error",o),[3,3];case 3:return[2]}}))}))},e.prototype.removeMsgBySessionId=function(e){var t;return k(this,void 0,void 0,(function(){var n,r;return S(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(),T.kg.debug("remove msg by sessionId",r),[3,7];case 7:return[2]}}))}))},e.prototype.putMessageToDB=function(e){var t;return k(this,void 0,void 0,(function(){var n;return S(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(),T.kg.debug("put msg to local error",n),[3,3];case 3:return[2]}}))}))},e.prototype.getConversationLastMessage=function(e,t){var n,r;return k(this,void 0,void 0,(function(){var o,s,a;return S(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),o=(0,E.MQ)({conversationId:e,conversationType:t}),[4,null===(r=null===(n=this.localCache)||void 0===n?void 0:n.transaction("message").store)||void 0===r?void 0:r.index("sessionTime").openCursor(IDBKeyRange.bound([o,L.getTime()],[o,(new Date).getTime()]),"prev")];case 1:return(s=i.sent())?[2,s.value]:[2,void 0];case 2:return a=i.sent(),T.kg.debug("get conversation last msg error",a),[3,3];case 3:return[2]}}))}))},e.prototype.getMessageByServerMsgId=function(e){var t;return k(this,void 0,void 0,(function(){var n;return S(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(),T.kg.debug("get msg by serverId error",n),[3,3];case 3:return[2]}}))}))},e.prototype.clearStoreData=function(e){var t;return k(this,void 0,void 0,(function(){var n;return S(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(),T.kg.debug("clear store data error",n),[3,3];case 3:return[2]}}))}))},e.prototype.clearConversationMap=function(){this.conversationMap={}},e}(),_=n(7252),O=n(3246),D=n(5531);function R(e){return R="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},R(e)}var A=function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function a(e){try{c(r.next(e))}catch(e){s(e)}}function i(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,i)}c((r=r.apply(e,t||[])).next())}))},x=function(e,t){var n,r,o,s,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function i(s){return function(i){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,i])}}},N=["singleChat","groupChat"];function P(){var e,t;return A(this,void 0,void 0,(function(){var n,r,o,s=this;return x(this,(function(a){switch(a.label){case 0:if(T.kg.debug("Call getLocalConversations"),!O.XZ.call(this))return n=_.Z.create({type:D.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(n)];a.label=1;case 1:return a.trys.push([1,4,,5]),[4,null===(t=null===(e=this._localCache)||void 0===e?void 0:e.getInstance())||void 0===t?void 0:t.getConversationList()];case 2:return r=a.sent()||[],[4,Promise.all(r.map((function(e){var t=e.conversationId,n=e.lastMessageId,r=e.unReadCount,o=e.conversationType,a=e.customField;return A(s,void 0,void 0,(function(){var e,s,i,c;return x(this,(function(u){switch(u.label){case 0:return s={conversationId:t,conversationType:o,unReadCount:r||0,customField:a},n?[4,null===(c=null===(i=this._localCache)||void 0===i?void 0:i.getInstance())||void 0===c?void 0:c.getMessageByServerMsgId(n)]:[3,2];case 1:return e=u.sent(),[3,3];case 2:e=void 0,u.label=3;case 3:return[2,(s.lastMessage=e,s)]}}))}))})))];case 3:return[2,{type:0,data:a.sent()}];case 4:throw o=a.sent(),_.Z.create({type:D.E.LOCAL_DB_OPERATION_FAILED,message:"getLocalConversations is failed",data:o});case 5:return[2]}}))}))}function j(e){var t,n;return A(this,void 0,void 0,(function(){var r,o,s,a,i;return x(this,(function(c){switch(c.label){case 0:if(T.kg.debug("Call setLocalConversationCustomField",e),!O.XZ.call(this))return r=_.Z.create({type:D.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(r)];if(o=e.conversationType,s=e.conversationId,a=e.customField,!N.includes(o))throw Error('"Invalid parameter conversationType": '+o);if("string"!=typeof s||""===s)throw Error('Invalid parameter: "conversationId"');if("object"!==R(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,E.MQ)({conversationId:s,conversationType:o}),{customField:a})];case 2:return c.sent(),[3,4];case 3:throw i=c.sent(),_.Z.create({type:D.E.LOCAL_DB_OPERATION_FAILED,message:"setLocalConversationCustomField is failed",data:i});case 4:return[2]}}))}))}function F(e){var t,n,r,o;return A(this,void 0,void 0,(function(){var s,a,i,c,u,l,d,v,p;return x(this,(function(h){switch(h.label){case 0:if(T.kg.debug("Call getLocalConversation",e),!O.XZ.call(this))return s=_.Z.create({type:D.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(s)];if(a=e.conversationType,i=e.conversationId,!N.includes(a))throw Error('"Invalid parameter conversationType": '+a);if("string"!=typeof i||""===i)throw Error('Invalid parameter: "conversationId"');h.label=1;case 1:return h.trys.push([1,8,,9]),[4,null===(n=null===(t=this._localCache)||void 0===t?void 0:t.getInstance())||void 0===n?void 0:n.getConversationBySessionId((0,E.MQ)({conversationId:i,conversationType:a}))];case 2:return c=h.sent(),v={type:0},c?(p={conversationId:c.conversationId,conversationType:a,unReadCount:c.unReadCount||0,customField:c.customField},c.lastMessageId?[4,null===(o=null===(r=this._localCache)||void 0===r?void 0:r.getInstance())||void 0===o?void 0:o.getMessageByServerMsgId(c.lastMessageId)]:[3,4]):[3,6];case 3:return l=h.sent(),[3,5];case 4:l=void 0,h.label=5;case 5:return p.lastMessage=l,u=p,[3,7];case 6:u=void 0,h.label=7;case 7:return[2,(v.data=u,v)];case 8:throw d=h.sent(),_.Z.create({type:D.E.LOCAL_DB_OPERATION_FAILED,message:"getLocalConversation is failed",data:d});case 9:return[2]}}))}))}function Z(e){var t,n,r,o;return A(this,void 0,void 0,(function(){var s,a,i,c,u,l,d;return x(this,(function(v){switch(v.label){case 0:if(T.kg.debug("Call removeLocalConversation",e),!O.XZ.call(this))return s=_.Z.create({type:D.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(s)];if(a=e.conversationType,i=e.conversationId,c=e.isRemoveLocalMessage,u=void 0===c||c,!N.includes(a))throw Error('"Invalid parameter conversationType": '+a);if("string"!=typeof i||""===i)throw Error('Invalid parameter: "conversationId"');l=(0,E.MQ)({conversationId:i,conversationType:a}),v.label=1;case 1:return v.trys.push([1,5,,6]),[4,null===(n=null===(t=this._localCache)||void 0===t?void 0:t.getInstance())||void 0===n?void 0:n.removeConversationBySessionId(l)];case 2:return v.sent(),u?[4,null===(o=null===(r=this._localCache)||void 0===r?void 0:r.getInstance())||void 0===o?void 0:o.removeMsgBySessionId(l)]:[3,4];case 3:v.sent(),v.label=4;case 4:return[3,6];case 5:throw d=v.sent(),_.Z.create({type:D.E.LOCAL_DB_OPERATION_FAILED,message:"removeLocalConversation is failed",data:d});case 6:return[2]}}))}))}function K(e){var t,n;return A(this,void 0,void 0,(function(){var r,o,s,a;return x(this,(function(i){switch(i.label){case 0:if(T.kg.debug("Call clearConversationUnreadCount",e),!O.XZ.call(this))return r=_.Z.create({type:D.E.REST_PARAMS_STATUS,message:"appkey or token error"}),[2,Promise.reject(r)];if(o=e.conversationType,s=e.conversationId,!N.includes(o))throw Error('"Invalid parameter conversationType": '+o);if("string"!=typeof s||""===s)throw Error('Invalid parameter: "conversationId"');i.label=1;case 1:return i.trys.push([1,3,,4]),[4,null===(n=null===(t=this._localCache)||void 0===t?void 0:t.getInstance())||void 0===n?void 0:n.updateLocalConversation((0,E.MQ)({conversationId:s,conversationType:o}),{unReadCount:0,unreadCountClearTimestamp:(new Date).getTime()})];case 2:return i.sent(),[3,4];case 3:throw a=i.sent(),_.Z.create({type:D.E.LOCAL_DB_OPERATION_FAILED,message:"clearConversationUnreadCount is failed",data:a});case 4:return[2]}}))}))}}},function(e){return 6007,e(e.s=6007)}])}));
|
package/miniCore/miniCore.d.ts
CHANGED
|
@@ -52,6 +52,15 @@ export interface NewTokenResult {
|
|
|
52
52
|
expire?: number;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
|
|
56
|
+
export interface LoginResult {
|
|
57
|
+
/** The access token. */
|
|
58
|
+
/** 授权Token。 */
|
|
59
|
+
accessToken: string;
|
|
60
|
+
expireTimestamp?: number;
|
|
61
|
+
duration?: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
55
64
|
export interface DownloadCombineMessagesParams {
|
|
56
65
|
/** The file url. */
|
|
57
66
|
url: string;
|
|
@@ -140,14 +149,14 @@ declare class MiniCore {
|
|
|
140
149
|
constructor(options: MiniCoreOptions);
|
|
141
150
|
usePlugin(this: MiniCore, plugin: any, name?: string): any;
|
|
142
151
|
isOpened(): boolean;
|
|
143
|
-
open(params: OpenParams): Promise<
|
|
152
|
+
open(params: OpenParams): Promise<LoginResult>;
|
|
144
153
|
send(params: MessageBody): Promise<SendMsgResult>;
|
|
145
154
|
/** Closes the connection. */
|
|
146
155
|
close(): void;
|
|
147
156
|
registerUser(params: {
|
|
148
157
|
username: string;
|
|
149
158
|
password: string;
|
|
150
|
-
nickname
|
|
159
|
+
nickname?: string;
|
|
151
160
|
}): Promise<AsyncResult<BaseUserInfo>>;
|
|
152
161
|
/** Updates token. */
|
|
153
162
|
renewToken(token: string): Promise<NewTokenResult>;
|