diff --git a/CHANGELOG.md b/CHANGELOG.md index 532ad26..3fb6b01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ Changelog ========= -## v3.0.107(SEP 6, 2019) +## v3.0.108(SEP 9, 2019) * Improved stability. ## v3.0.106(AUG 23, 2019) diff --git a/README.md b/README.md index 0f3f42b..aca37de 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Check out [Basic Sample with SyncManager](https://github.com/sendbird/SendBird-J # [Documentation](https://docs.sendbird.com/javascript) -## v3.0.107(SEP 6, 2019) +## v3.0.108(SEP 9, 2019) If you want to check the record of other version, go to [Change Log](https://github.com/sendbird/SendBird-SDK-JavaScript/blob/master/CHANGELOG.md). * Improved stability. diff --git a/SendBird.d.ts b/SendBird.d.ts index e2dea15..a681ccd 100644 --- a/SendBird.d.ts +++ b/SendBird.d.ts @@ -1,5 +1,5 @@ /** - * Type Definitions for SendBird SDK v3.0.107 + * Type Definitions for SendBird SDK v3.0.108 * homepage: https://sendbird.com/ * git: https://github.com/sendbird/SendBird-SDK-JavaScript */ diff --git a/SendBird.min.js b/SendBird.min.js index 98db7e3..c482162 100644 --- a/SendBird.min.js +++ b/SendBird.min.js @@ -1,12 +1,12 @@ /** * Copyright (c) 2016 SendBird DBA (Smile Family, Inc.) - * SendBird JavaScript SDK v3.0.107 + * SendBird JavaScript SDK v3.0.108 */ -!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.SendBird=n():e.SendBird=n()}("undefined"!=typeof self?self:this,function(){function e(){this.oldIE=!0,this.boundary="--------FormData"+Math.random(),this._fields=[]}function n(e){var n=this,t=[];n.onChangeHandler=function(e,n,t){},Object.defineProperty(n,"push",{configurable:!1,enumerable:!1,writable:!1,value:function(e){var r=JSON.parse(JSON.stringify(t));return t.push(e),S(r,t)||n.onChangeHandler(t,r,{added:e}),t}}),Object.defineProperty(n,"pop",{configurable:!1,enumerable:!1,writable:!1,value:function(){var e=JSON.parse(JSON.stringify(t)),r=t.pop();return S(e,t)||n.onChangeHandler(t,e,{removed:r}),r}}),Object.defineProperty(n,"shift",{configurable:!1,enumerable:!1,writable:!1,value:function(){var e=JSON.parse(JSON.stringify(t)),r=t.shift();return S(e,t)||n.onChangeHandler(t,e,{removed:r}),r}}),Object.defineProperty(n,"splice",{configurable:!1,enumerable:!1,writable:!1,value:function(e,r){var i=JSON.parse(JSON.stringify(t)),a=t.splice(e,r);return S(i,t)||n.onChangeHandler(t,i,{removed:a}),a}}),Object.defineProperty(n,"length",{configurable:!1,enumerable:!1,get:function(){return t.length}}),Object.defineProperty(n,"items",{configurable:!1,enumerable:!1,get:function(){return t}}),Object.defineProperty(n,"update",{configurable:!1,enumerable:!1,value:function(e,r){var i=JSON.parse(JSON.stringify(t));return t[e]=r,S(i,t)||n.onChangeHandler(t,i,{updated:r}),t}}),Object.defineProperty(n,"searchIndexByKeyValue",{configurable:!1,enumerable:!1,value:function(e,n){for(var r=-1,i=t.length,a=0;a=t)){for(var i=e[t].seq,a=n,s=n;s<=t;s++)if(e[s].seq<=i){var o=e[a];e[a]=e[s],e[s]=o,a++}r(e,n,a-2),r(e,a,t)}};Object.defineProperty(n,"insert",{configurable:!1,enumerable:!1,value:function(e,i){var a=JSON.parse(JSON.stringify(t));return t.splice(e,0,i),r(t,0,t.length-1),S(a,t)||n.onChangeHandler(t,a,{added:i}),t}}),Object.getOwnPropertyNames(Array.prototype).forEach(function(e){e in n||Object.defineProperty(n,e,{configurable:!1,enumerable:!1,writable:!1,value:Array.prototype[e]})}),e instanceof Array&&e.length>0&&n.push.apply(n,e)}var t,r=!1,i="wss://ws.sendbird.com",a="https://api.sendbird.com",s=1e3,o=9e3;try{t=window.console||{log:function(){}}}catch(e){t={log:function(){}}}var l="undefined";try{l=navigator.userAgent.replace(/,/g,".")}catch(e){l="undefined"}var u,c="JS,"+l+",3.0.107,",d="application/json; charset=utf-8",h={interval:3,maxInterval:24,retryCount:3,multiplier:2},p=function(){try{if(document&&9===document.documentMode)return!0}catch(e){return!1}return!1}(),f=function(){try{if(document&&document.documentMode<=8)return!0}catch(e){return!1}return!1}();if(p||f)"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),"function"!=typeof Array.prototype.forEach&&(Array.prototype.forEach=function(e){for(var n=0;n=0&&("all"===e.myCountPreference||"unread_message_count_only"===e.myCountPreference?e.isSuper?e.unreadMessageCount=n>=1?1:0:e.unreadMessageCount=n:e.unreadMessageCount=0),"number"==typeof t&&t>=0&&("all"===e.myCountPreference||"unread_mention_count_only"===e.myCountPreference?e.unreadMentionCount=t:e.unreadMentionCount=0)}catch(e){}},S=function(e,n){var i=!1;try{var a=!0;if(e&&"object"==typeof e&&n&&"object"==typeof n){var s=Object.keys(e),o=Object.keys(n);if(s.indexOf("reqId")>-1&&s.indexOf("messageId")>-1&&o.indexOf("reqId")>-1&&o.indexOf("messageId")>-1){var l=e.reqId;s.splice(s.indexOf("reqId"),1);var u=e.messageId;s.splice(s.indexOf("messageId"),1);var c=n.reqId;o.splice(o.indexOf("reqId"),1);var d=n.messageId;o.splice(o.indexOf("messageId"),1),a=0!==u&&0!==d&&u===d||(0===u||0===d)&&0!==l&&0!==c&&l===c}if(s.length===o.length){i=s.map(function(t){return S(e[t],n[t])}).filter(function(e){return!e}).length<=0}else i=!1}else"number"==typeof e&&"number"==typeof n&&(isNaN(e)&&(e=0),isNaN(n)&&(n=0)),i=e instanceof Date?e.getTime()===n.getTime():e===n||"function"==typeof e&&"function"==typeof n;return i&&a}catch(e){return r&&t.log("isEqual() Exception: ",e),!1}};n.EventType={ADDED:"added",REMOVED:"removed",UPDATED:"updated"};var U=function(){var e=function(){var e=function(){try{navigator.onLine&&(Te.getInstance().reconnecting||Te.getInstance().connecting||!ge.getInstance().sessionKey||Te.getInstance().getConnectionState()===Te.getInstance().ConnectionState.OPEN||Te.getInstance().reconnect())}catch(e){r&&t.log("There is no window.addEventListener.ononline or navigator.onLine")}},n=function(){try{navigator.onLine||Te.getInstance().reconnecting||Te.getInstance().connecting||!ge.getInstance().sessionKey||(_e&&_e.stop(),Te.getInstance().reconnect())}catch(e){r&&t.log("There is no window.addEventListener.ononline or navigator.onLine")}};this.start=function(){try{window&&window.addEventListener&&"ononline"in window&&"onoffline"in window&&navigator&&"boolean"==typeof navigator.onLine&&(window.addEventListener("online",e),window.addEventListener("offline",n))}catch(e){r&&t.log("There is no window.addEventListener.ononline or navigator.onLine")}},this.stop=function(){try{window.removeEventListener("online",e,!1),window.removeEventListener("offline",n,!1)}catch(e){r&&t.log("There is no window.addEventListener.ononline or navigator.onLine")}}},p=new e,U=function(){};U.INVALID_INITIALIZATION=800100,U.CONNECTION_REQUIRED=800101,U.CONNECTION_CANCELED=800102,U.INVALID_PARAMETER=800110,U.NETWORK_ERROR=800120,U.NETWORK_ROUTING_ERROR=800121,U.MALFORMED_DATA=800130,U.MALFORMED_ERROR_DATA=800140,U.WRONG_CHANNEL_TYPE=800150,U.MARK_AS_READ_RATE_LIMIT_EXCEEDED=800160,U.QUERY_IN_PROGRESS=800170,U.ACK_TIMEOUT=800180,U.LOGIN_TIMEOUT=800190,U.WEBSOCKET_CONNECTION_CLOSED=800200,U.WEBSOCKET_CONNECTION_FAILED=800210,U.REQUEST_FAILED=800220,U.FILE_UPLOAD_CANCEL_FAILED=800230,U.REQUEST_CANCELED=800240;var T=function(){function e(e,n,i){try{n&&"function"==typeof n&&(e.upload.onprogress=function(e){i&&"function"==typeof i&&i(e),e.lengthComputable&&e.loaded>=e.total&&n()}),e.onreadystatechange=function(){if(e&&e.readyState===o.DONE){var i=e.status,a=null;if(i>=200&&i<400){var s=!0;try{a=JSON.parse(e.responseText)}catch(e){s=!1,a=null}s?_(null,a,e.callback):_(new y("Request failed.",U.REQUEST_FAILED),null,e.callback),n&&"function"==typeof n&&n(),e=null}else{var l={status:i,statusText:e.statusText,response:e.responseText};r&&t.log(l),e&&e.isAbort?e.onabort():(_(l,null,e.callback),e=null)}}},e.onabort=function(){e&&(_(new y("Request has been canceled.",U.REQUEST_CANCELED),null,e.callback),n&&"function"==typeof n&&n(),e=null)},e.onerror=function(){e&&(_(new y("There was a network error.",U.NETWORK_ERROR),null,e.callback),n&&"function"==typeof n&&n(),e=null)},e.ontimeout=function(){e&&(_(new y("Request is timeout.",U.REQUEST_FAILED),null,e.callback),n&&"function"==typeof n&&n(),e=null)}}catch(e){r&&t.log("setting request event is failed. - ",e)}}function n(e,n){try{e.setRequestHeader("SendBird",c+M),n&&e.setRequestHeader("Session-Key",n),e.setRequestHeader("Request-Sent-Timestamp",(new Date).getTime().toString())}catch(e){r&&t.log("setting default header is failed. - ",e)}}function i(e){try{var n="";for(var i in e.data)if(e.data.hasOwnProperty(i)){var a=e.data[i];if(void 0!==a&&null!==a){var s="";s="object"==typeof a?Array.isArray(a)?a.map(function(e){return encodeURIComponent(e)}).join(","):encodeURIComponent(JSON.stringify(a)):encodeURIComponent(a),n+=i+"="+s+"&"}}n&&(e.url=e.url+"?"+n.substring(0,n.length-1))}catch(e){r&&t.log("createWithEncodedGetParams is failed. - ",e)}}function a(e,n){try{switch(n){case"GET":e.send();break;default:"undefined"!=typeof FormData&&FormData&&e.data instanceof FormData||void 0!==u&&u&&e.data instanceof u?e.data.oldIE?(e.setRequestHeader("Content-Type","multipart/form-data; boundary="+e.data.boundary),e.send(e.data.toString())):e.send(e.data):(e.setRequestHeader("Content-Type",d),e.send(JSON.stringify(e.data)))}}catch(e){r&&t.log("sending a request is failed. - ",e)}}var s=function(){return"undefined"!=typeof process&&"[object process]"===Object.prototype.toString.call(process)}(),o=null;try{s?o=require("xhr2"):"undefined"!=typeof XMLHttpRequest?o=XMLHttpRequest:(r&&t.log("There is not XHR."),o=null)}catch(e){r&&t.log("There is not XHR. - ",e)}var l=function(e,n,t,r){var a=new o;return a.url=n,a.data=t,a.callback=r,"GET"!==e&&"DELETE"!==e||i(a),a.open(e,a.url,!0),a},h=function(e){_(new y("Request failed. There is not XMLHttpRequest.",U.REQUEST_FAILED),null,e)};this.get=function(t,r,i){o||h(i);var s=l("GET",t,r,i);e(s),n(s,ge.getInstance().sessionKey),a(s,"GET")},this.post=function(t,r,i){o||h(i);var s=l("POST",t,r,i);e(s),n(s,ge.getInstance().sessionKey),a(s,"POST")},this.put=function(t,r,i){o||h(i);var s=l("PUT",t,r,i);e(s),n(s,ge.getInstance().sessionKey),a(s,"PUT")},this["delete"]=function(t,r,i){o||h(i);var s=l("DELETE",t,r,i);e(s),n(s,ge.getInstance().sessionKey),a(s,"DELETE")},this.upload=function(t,r,i,s,c){o||h(c);var d=l("POST",t,null,c);Te.getInstance()._fileUploadRequest[i]=d,e(d,function(){Te.getInstance()._fileUploadRequest[i]&&delete Te.getInstance()._fileUploadRequest[i]},function(e){s&&"function"==typeof s&&s(e,i)});var p=u?new u:new FormData,f=r.file,_=r.fileType;_&&"undefined"!=typeof Blob&&(f instanceof Blob||"string"==typeof f||Array.isArray(f)||f.hasOwnProperty("isRNFetchBlobPolyfill"))?p.append("file",new Blob([f],{type:_}),f.name):p.append("file",f,f.name),r.channelUrl&&"string"==typeof r.channelUrl&&p.append("channel_url",r.channelUrl);var I=r.thumbnailSizes;if(I)for(var g=0;g0?k.SUCCEEDED:k.FAILED,e.hasOwnProperty("request_state")&&(this.requestState=e.request_state),this.requestedMentionUserIds=[],e.hasOwnProperty("requested_mention_user_ids")&&(this.requestedMentionUserIds=e.requested_mention_user_ids))};A(H,G),G.build=function(e,n,t,r,i,a,s,o,l,u,c,d,h,p,f,_,I){var g={};g.req_id=e,g.msg_id=n,g.channel_url=r.url,g.channel_type=r.channelType===Y.CHANNEL_TYPE_OPEN?Y.CHANNEL_TYPE_OPEN:Y.CHANNEL_TYPE_GROUP,g.ts=u,g.updated_at=c,g.message=i,a&&(g.data=a),s&&(g.custom_type=s),o&&(g.translations=o);var m={user_id:"",nickname:"",profile_url:"",metadata:{},is_blocked_by_me:!1};if(t){m.user_id=t.userId,m.nickname=t.nickname,m.profile_url=t.profileUrl;try{m.metadata="string"==typeof t.metaData?JSON.parse(t.metaData):t.metaData}catch(e){m.metadata={}}m.is_blocked_by_me=t.isBlockedByMe}if(g.user=m,g.is_global_block=!!l,d){g.metaarray={};for(var E=0;E0?k.SUCCEEDED:k.FAILED,_&&(g.request_state=_),f&&(g.mentioned_user_ids=f),g.requested_mention_user_ids=[],I&&(g.requested_mention_user_ids=I),g},G.buildFromSerializedData=function(e){var n=C(e),t=[];if(n.mentionedUsers.forEach(function(e){t.push(Q.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData,e.isActive,e.friendDiscoveryKey,e.friendName))}),!n.metaArrays&&n.metaArray){n.metaArrays=[];for(var r in n.metaArray)n.metaArrays.push(new Ue(r,n.metaArray[r]))}return new G(G.build(n.reqId,n.messageId,n.sender,{url:n.channelUrl,channelType:n.channelType},n.message,n.data,n.customType,n.translations,n.isGlobalBlocked,n.createdAt,n.updatedAt,n.metaArrays,n.mentionType,t,null,n.requestState,n.requestedMentionUserIds))};var V=function(e,i){var a=0,s=e,o=i,l=new n([]);l.onChangeHandler=function(e,i,a){if(r&&t.log("fileMessageQueue.onChangeHandler: ",e,i,a),a.hasOwnProperty(n.EventType.ADDED)){var s=a[n.EventType.ADDED];if(s.state=V.StateType.UPLOADING,s.error){var o=c.searchIndexByKeyValue("reqId",s.reqId);o>-1&&(s.state=V.StateType.SENT,c.update(o,s)),u(s.reqId)}else I(s,function(e){s.error&&s.state===V.StateType.SENT||(s.state=V.StateType.UPLOADED);var n=c.searchIndexByKeyValue("reqId",s.reqId);n>-1&&(s.fileInfo=e,c.update(n,s)),u(s.reqId)})}else a.hasOwnProperty(n.EventType.UPDATED)||c.length>0&&l.length<6&&h()};var u=function(e){var n=l.searchIndexByKeyValue("reqId",e);n>-1&&l.splice(n,1)},c=new n([]);c.onChangeHandler=function(e,i,a){r&&t.log("fileMessageQueue.onChangeHandler: ",e,i,a),a.hasOwnProperty(n.EventType.ADDED)?l.length<6&&h():c.length>0&&p()};var d=function(){var e=null,n=c.items.filter(function(e){return e.state===V.StateType.PENDING});return n.length>0&&(e=n[0]),e},h=function(){var e=d();e&&l.push(e)},p=function(){var e=c.items[0];e.state===V.StateType.UPLOADED?f():e.state===V.StateType.SENT&&_()},f=function(){var e=c.items[0];if(e&&e.state===V.StateType.UPLOADED){for(e.state=V.StateType.SENDING,a=0===a?(new Date).getTime()-200:a;(new Date).getTime()-a<200;);a=(new Date).getTime(),g(e,function(n,t){e.state=V.StateType.SENT,e.error=t||null,e.res=n||null;var r=c.searchIndexByKeyValue("reqId",e.reqId);r>-1&&c.update(r,e)})}},_=function(){var e=c.items[0];if(e&&e.state===V.StateType.SENT){e.state=V.StateType.DONE;var n=Te.getInstance(),t=e.res,r=e.error;if(t&&!r){var i=n.currentUser;i&&t._sender&&i.userId===t._sender.userId&&(i.nickname!==t._sender.nickname&&(i.nickname=t._sender.nickname),i.profileUrl!==t._sender.profileUrl&&(i.profileUrl=t._sender.profileUrl)),o||K.getChannel(s,function(r,i){if(O){var a=r;r=i,i=a}if(i)return L(t,i,e.fileInfo.callback),void c.shift();r.lastMessage=t;for(var s in n.channelHandlers){n.channelHandlers[s].onChannelChanged(r)}})}r&&(t=e.preMessageObj)&&(t.requestState=k.FAILED,r.code===U.INVALID_PARAMETER&&(t=null)),L(t,r,e.fileInfo.callback),c.shift()}},I=function(e,n){var t=e.fileInfo,r=e.preMessageObj;"string"!=typeof t.file&&t.file?ge.getInstance().uploadFile(t.file,t.type,t.thumbnailSizes,s,function(r,i){if(i)return e.state=V.StateType.SENT,e.error=i,e.res=null,void n(t);var a="object"==typeof r?r:JSON.parse(r);t.file=a.url,t.thumbnailSizes=a.hasOwnProperty("thumbnails")?a.thumbnails:[],t.requireAuth=!!a.hasOwnProperty("require_auth")&&a.require_auth,n(t)},t.progressHandler,r?r.reqId:null):(t.thumbnailSizes=[],t.requireAuth=!1,n(t))},g=function(e,n){if(null!==e){var t=e.fileInfo,r=e.reqId,i=Te.getInstance();if(i.getConnectionState()!==i.ConnectionState.OPEN&&i.currentUser&&!i.connecting)ge.getInstance().sendFileMessageAPI(s,o,t.file,t.name,t.size,t.type,t.data,t.customType,t.customType,t.requireAuth,t.metaArrays,t.mentionType,t.mentionedUserIds,t.pushNotificationDeliveryOption,function(e,r){var i=new q(r?a.getJsonElement():e);r&&(i.requestedMentionUserIds=t.mentionedUserIds),n(i,r)});else{var a=Z.bFile(r,s,t.file,t.name,t.type,t.size,t.data,t.customType,t.thumbnailSizes,t.requireAuth,t.metaArrays,t.mentionType,t.mentionedUserIds,t.pushNotificationDeliveryOption);i.sendCommand(a,function(e,r){var i=new q(r?a.getJsonElement():e.getJsonElement());r&&(i.requestedMentionUserIds=t.mentionedUserIds),n(i,r)})}}};this.addTask=function(e){c.push(e)},this.cancelUploadItemByReqId=function(e){u(e);var n=c.searchIndexByKeyValue("reqId",e);if(n>-1){var t=c.items[n];!t||t.state!==V.StateType.UPLOADING&&t.state!==V.StateType.PENDING||(t.state=V.StateType.SENT,t.res=null,t.error=new y("Uploading has been completed or canceled.",U.FILE_UPLOAD_CANCEL_FAILED),c.update(n,t))}}};V.StateType={PENDING:"pending",UPLOADING:"uploading",UPLOADED:"uploaded",SENDING:"sending",SENT:"sent",DONE:"done"};var q=function(e){if(this.messageType=H.MESSAGE_TYPE_FILE,e){if(this._update(e),this._sender=new J(e.user),f?this.sender=this._sender:Object.defineProperty(this,"sender",{get:function(){if(Te.getInstance().Options.useMemberAsMessageSender&&this.isGroupChannel()){var e=K.cachedChannels[this.channelUrl];if(e){var n=e.memberMap[this._sender.userId];n&&(this._sender.nickname!==n.nickname&&(this._sender.nickname=n.nickname),this._sender.profileUrl!==n.profileUrl&&(this._sender.profileUrl=n.profileUrl),S(this._sender.metaData,n.metaData)||(this._sender.metaData=n.metaData))}}return this._sender},set:function(e){this._sender=e}}),this.requireAuth=!!e.hasOwnProperty("require_auth")&&e.require_auth,this.url=this.requireAuth?String(e.url).split("?auth=")[0]+"?auth="+ge.getInstance().ekey:String(e.url).split("?auth=")[0],this.name=e.hasOwnProperty("name")?e.name:"File",this.size=parseInt(e.size)||0,this.type=String(e.type),this.data=e.hasOwnProperty("custom")?String(e.custom):"",this.reqId=e.hasOwnProperty("req_id")?String(e.req_id):"",this.thumbnails=e.hasOwnProperty("thumbnails")?e.thumbnails:[],this.requireAuth)for(var n=0;n0?k.SUCCEEDED:k.FAILED,e.hasOwnProperty("request_state")&&(this.requestState=e.request_state),this.requestedMentionUserIds=[],e.hasOwnProperty("requested_mention_user_ids")&&(this.requestedMentionUserIds=e.requested_mention_user_ids)}};A(H,q),q.build=function(e,n,t,r,i,a,s,o,l,u,c,d,h,p,f,_,I,g,m,E,A){var y={};y.req_id=e,y.msg_id=n,y.channel_url=r.url,y.channel_type=r.channelType===Y.CHANNEL_TYPE_OPEN?Y.CHANNEL_TYPE_OPEN:Y.CHANNEL_TYPE_GROUP,y.ts=d,y.updated_at=f,y.url=i,y.name=a,y.type=s,y.size=o,y.custom=l;var v={user_id:"",nickname:"",profile_url:"",metadata:{},is_global_block:!1};if(t){v.user_id=t.userId,v.nickname=t.nickname,v.profile_url=t.profileUrl;try{v.metadata=JSON.parse(t.metaData)}catch(e){v.metadata={}}v.is_blocked_by_me=t.isBlockedByMe}if(y.user=v,u&&(y.custom_type=u),p&&(y.require_auth=p),h&&(y.thumbnails=h),y.is_global_block=c,_){y.metaarray={};for(var N=0;N<_.length;N++){var C=_[N].key;y.metaarray[C]=_[N].value}y.metaarray_key_order=_.map(function(e){return e.key})}return I&&(y.mention_type=I),y.mentioned_users=[],g&&(y.mentioned_users=g),m&&(y.mentioned_user_ids=m),y.request_state=n>0?k.SUCCEEDED:k.FAILED,E&&(y.request_state=E),y.requested_mention_user_ids=[],A&&(y.requested_mention_user_ids=A),y},q.buildFromSerializedData=function(e){var n=C(e),t=[];if(n.mentionedUsers.forEach(function(e){t.push(Q.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData,e.isActive,e.friendDiscoveryKey,e.friendName))}),!n.metaArrays&&n.metaArray){n.metaArrays=[];for(var r in n.metaArray)n.metaArrays.push(new Ue(r,n.metaArray[r]))}return new q(q.build(n.reqId,n.messageId,n.sender,{url:n.channelUrl,channelType:n.channelType},n.url,n.name,n.type,n.size,n.data,n.customType,n.isGlobalBlocked,n.createdAt,n.thumbnails,n.requireAuth,n.updatedAt,n.metaArrays,n.mentionType,t,null,n.requestState,n.requestedMentionUserIds))};var Y=function(e){this._update=function(e){this.url=e.hasOwnProperty("channel_url")?String(e.channel_url):"",this.name=e.hasOwnProperty("name")?String(e.name):"",this.coverUrl=e.hasOwnProperty("cover_url")?String(e.cover_url):"",this.createdAt=e.hasOwnProperty("created_at")?1e3*e.created_at:0,this.data=e.hasOwnProperty("data")?String(e.data):"",this.customType=e.hasOwnProperty("custom_type")?e.custom_type:"",this.isFrozen=!!e.hasOwnProperty("freeze")&&e.freeze,this.isEphemeral=!!e.hasOwnProperty("is_ephemeral")&&e.is_ephemeral},this.serialize=function(){var e=JSON.parse(JSON.stringify(this));if(e.hasOwnProperty("lastMessage")&&null!==e.lastMessage&&"undefined"!=typeof e.lastMessage&&"object"==typeof e.lastMessage){var n=e.lastMessage;n.hasOwnProperty("_sender")&&(n.sender=n._sender,delete n._sender,e.lastMessage=n)}return N(e)},this.isGroupChannel=function(){return this.channelType===Y.CHANNEL_TYPE_GROUP},this.isOpenChannel=function(){return this.channelType===Y.CHANNEL_TYPE_OPEN},this.getMessageChangeLogsByTimestamp=function(e,n,t){var r=this +!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.SendBird=n():e.SendBird=n()}("undefined"!=typeof self?self:this,function(){function e(){this.oldIE=!0,this.boundary="--------FormData"+Math.random(),this._fields=[]}function n(e){var n=this,t=[];n.onChangeHandler=function(e,n,t){},Object.defineProperty(n,"push",{configurable:!1,enumerable:!1,writable:!1,value:function(e){var r=JSON.parse(JSON.stringify(t));return t.push(e),S(r,t)||n.onChangeHandler(t,r,{added:e}),t}}),Object.defineProperty(n,"pop",{configurable:!1,enumerable:!1,writable:!1,value:function(){var e=JSON.parse(JSON.stringify(t)),r=t.pop();return S(e,t)||n.onChangeHandler(t,e,{removed:r}),r}}),Object.defineProperty(n,"shift",{configurable:!1,enumerable:!1,writable:!1,value:function(){var e=JSON.parse(JSON.stringify(t)),r=t.shift();return S(e,t)||n.onChangeHandler(t,e,{removed:r}),r}}),Object.defineProperty(n,"splice",{configurable:!1,enumerable:!1,writable:!1,value:function(e,r){var i=JSON.parse(JSON.stringify(t)),a=t.splice(e,r);return S(i,t)||n.onChangeHandler(t,i,{removed:a}),a}}),Object.defineProperty(n,"length",{configurable:!1,enumerable:!1,get:function(){return t.length}}),Object.defineProperty(n,"items",{configurable:!1,enumerable:!1,get:function(){return t}}),Object.defineProperty(n,"update",{configurable:!1,enumerable:!1,value:function(e,r){var i=JSON.parse(JSON.stringify(t));return t[e]=r,S(i,t)||n.onChangeHandler(t,i,{updated:r}),t}}),Object.defineProperty(n,"searchIndexByKeyValue",{configurable:!1,enumerable:!1,value:function(e,n){for(var r=-1,i=t.length,a=0;a=t)){for(var i=e[t].seq,a=n,s=n;s<=t;s++)if(e[s].seq<=i){var o=e[a];e[a]=e[s],e[s]=o,a++}r(e,n,a-2),r(e,a,t)}};Object.defineProperty(n,"insert",{configurable:!1,enumerable:!1,value:function(e,i){var a=JSON.parse(JSON.stringify(t));return t.splice(e,0,i),r(t,0,t.length-1),S(a,t)||n.onChangeHandler(t,a,{added:i}),t}}),Object.getOwnPropertyNames(Array.prototype).forEach(function(e){e in n||Object.defineProperty(n,e,{configurable:!1,enumerable:!1,writable:!1,value:Array.prototype[e]})}),e instanceof Array&&e.length>0&&n.push.apply(n,e)}var t,r=!1,i="wss://ws.sendbird.com",a="https://api.sendbird.com",s=1e3,o=9e3;try{t=window.console||{log:function(){}}}catch(e){t={log:function(){}}}var l="undefined";try{l=navigator.userAgent.replace(/,/g,".")}catch(e){l="undefined"}var u,c="JS,"+l+",3.0.108,",d="application/json; charset=utf-8",h={interval:3,maxInterval:24,retryCount:3,multiplier:2},p=function(){try{if(document&&9===document.documentMode)return!0}catch(e){return!1}return!1}(),f=function(){try{if(document&&document.documentMode<=8)return!0}catch(e){return!1}return!1}();if(p||f)"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),"function"!=typeof Array.prototype.forEach&&(Array.prototype.forEach=function(e){for(var n=0;n=0&&("all"===e.myCountPreference||"unread_message_count_only"===e.myCountPreference?e.isSuper?e.unreadMessageCount=n>=1?1:0:e.unreadMessageCount=n:e.unreadMessageCount=0),"number"==typeof t&&t>=0&&("all"===e.myCountPreference||"unread_mention_count_only"===e.myCountPreference?e.unreadMentionCount=t:e.unreadMentionCount=0)}catch(e){}},S=function(e,n){var i=!1;try{var a=!0;if(e&&"object"==typeof e&&n&&"object"==typeof n){var s=Object.keys(e),o=Object.keys(n);if(s.indexOf("reqId")>-1&&s.indexOf("messageId")>-1&&o.indexOf("reqId")>-1&&o.indexOf("messageId")>-1){var l=e.reqId;s.splice(s.indexOf("reqId"),1);var u=e.messageId;s.splice(s.indexOf("messageId"),1);var c=n.reqId;o.splice(o.indexOf("reqId"),1);var d=n.messageId;o.splice(o.indexOf("messageId"),1),a=0!==u&&0!==d&&u===d||(0===u||0===d)&&0!==l&&0!==c&&l===c}if(s.length===o.length){i=s.map(function(t){return S(e[t],n[t])}).filter(function(e){return!e}).length<=0}else i=!1}else"number"==typeof e&&"number"==typeof n&&(isNaN(e)&&(e=0),isNaN(n)&&(n=0)),i=e instanceof Date?e.getTime()===n.getTime():e===n||"function"==typeof e&&"function"==typeof n;return i&&a}catch(e){return r&&t.log("isEqual() Exception: ",e),!1}};n.EventType={ADDED:"added",REMOVED:"removed",UPDATED:"updated"};var U=function(){var e=function(){var e=function(){try{navigator.onLine&&(Te.getInstance().reconnecting||Te.getInstance().connecting||!ge.getInstance().sessionKey||Te.getInstance().getConnectionState()===Te.getInstance().ConnectionState.OPEN||Te.getInstance().reconnect())}catch(e){r&&t.log("There is no window.addEventListener.ononline or navigator.onLine")}},n=function(){try{navigator.onLine||Te.getInstance().reconnecting||Te.getInstance().connecting||!ge.getInstance().sessionKey||(_e&&_e.stop(),Te.getInstance().reconnect())}catch(e){r&&t.log("There is no window.addEventListener.ononline or navigator.onLine")}};this.start=function(){try{window&&window.addEventListener&&"ononline"in window&&"onoffline"in window&&navigator&&"boolean"==typeof navigator.onLine&&(window.addEventListener("online",e),window.addEventListener("offline",n))}catch(e){r&&t.log("There is no window.addEventListener.ononline or navigator.onLine")}},this.stop=function(){try{window.removeEventListener("online",e,!1),window.removeEventListener("offline",n,!1)}catch(e){r&&t.log("There is no window.addEventListener.ononline or navigator.onLine")}}},p=new e,U=function(){};U.INVALID_INITIALIZATION=800100,U.CONNECTION_REQUIRED=800101,U.CONNECTION_CANCELED=800102,U.INVALID_PARAMETER=800110,U.NETWORK_ERROR=800120,U.NETWORK_ROUTING_ERROR=800121,U.MALFORMED_DATA=800130,U.MALFORMED_ERROR_DATA=800140,U.WRONG_CHANNEL_TYPE=800150,U.MARK_AS_READ_RATE_LIMIT_EXCEEDED=800160,U.QUERY_IN_PROGRESS=800170,U.ACK_TIMEOUT=800180,U.LOGIN_TIMEOUT=800190,U.WEBSOCKET_CONNECTION_CLOSED=800200,U.WEBSOCKET_CONNECTION_FAILED=800210,U.REQUEST_FAILED=800220,U.FILE_UPLOAD_CANCEL_FAILED=800230,U.REQUEST_CANCELED=800240;var T=function(){function e(e,n,i){try{n&&"function"==typeof n&&(e.upload.onprogress=function(e){i&&"function"==typeof i&&i(e),e.lengthComputable&&e.loaded>=e.total&&n()}),e.onreadystatechange=function(){if(e&&e.readyState===o.DONE){var i=e.status,a=null;if(i>=200&&i<400){var s=!0;try{a=JSON.parse(e.responseText)}catch(e){s=!1,a=null}s?_(null,a,e.callback):_(new y("Request failed.",U.REQUEST_FAILED),null,e.callback),n&&"function"==typeof n&&n(),e=null}else{var l={status:i,statusText:e.statusText,response:e.responseText};r&&t.log(l),e&&e.isAbort?e.onabort():(_(l,null,e.callback),e=null)}}},e.onabort=function(){e&&(_(new y("Request has been canceled.",U.REQUEST_CANCELED),null,e.callback),n&&"function"==typeof n&&n(),e=null)},e.onerror=function(){e&&(_(new y("There was a network error.",U.NETWORK_ERROR),null,e.callback),n&&"function"==typeof n&&n(),e=null)},e.ontimeout=function(){e&&(_(new y("Request is timeout.",U.REQUEST_FAILED),null,e.callback),n&&"function"==typeof n&&n(),e=null)}}catch(e){r&&t.log("setting request event is failed. - ",e)}}function n(e,n){try{e.setRequestHeader("SendBird",c+M),n&&e.setRequestHeader("Session-Key",n),e.setRequestHeader("Request-Sent-Timestamp",(new Date).getTime().toString())}catch(e){r&&t.log("setting default header is failed. - ",e)}}function i(e){try{var n="";for(var i in e.data)if(e.data.hasOwnProperty(i)){var a=e.data[i];if(void 0!==a&&null!==a){var s="";s="object"==typeof a?Array.isArray(a)?a.map(function(e){return encodeURIComponent(e)}).join(","):encodeURIComponent(JSON.stringify(a)):encodeURIComponent(a),n+=i+"="+s+"&"}}n&&(e.url=e.url+"?"+n.substring(0,n.length-1))}catch(e){r&&t.log("createWithEncodedGetParams is failed. - ",e)}}function a(e,n){try{switch(n){case"GET":e.send();break;default:"undefined"!=typeof FormData&&FormData&&e.data instanceof FormData||void 0!==u&&u&&e.data instanceof u?e.data.oldIE?(e.setRequestHeader("Content-Type","multipart/form-data; boundary="+e.data.boundary),e.send(e.data.toString())):e.send(e.data):(e.setRequestHeader("Content-Type",d),e.send(JSON.stringify(e.data)))}}catch(e){r&&t.log("sending a request is failed. - ",e)}}var s=function(){return"undefined"!=typeof process&&"[object process]"===Object.prototype.toString.call(process)}(),o=null;try{s?o=require("xhr2"):"undefined"!=typeof XMLHttpRequest?o=XMLHttpRequest:(r&&t.log("There is not XHR."),o=null)}catch(e){r&&t.log("There is not XHR. - ",e)}var l=function(e,n,t,r){var a=new o;return a.url=n,a.data=t,a.callback=r,"GET"!==e&&"DELETE"!==e||i(a),a.open(e,a.url,!0),a},h=function(e){_(new y("Request failed. There is not XMLHttpRequest.",U.REQUEST_FAILED),null,e)};this.get=function(t,r,i){o||h(i);var s=l("GET",t,r,i);e(s),n(s,ge.getInstance().sessionKey),a(s,"GET")},this.post=function(t,r,i){o||h(i);var s=l("POST",t,r,i);e(s),n(s,ge.getInstance().sessionKey),a(s,"POST")},this.put=function(t,r,i){o||h(i);var s=l("PUT",t,r,i);e(s),n(s,ge.getInstance().sessionKey),a(s,"PUT")},this["delete"]=function(t,r,i){o||h(i);var s=l("DELETE",t,r,i);e(s),n(s,ge.getInstance().sessionKey),a(s,"DELETE")},this.upload=function(t,r,i,s,c){o||h(c);var d=l("POST",t,null,c);Te.getInstance()._fileUploadRequest[i]=d,e(d,function(){Te.getInstance()._fileUploadRequest[i]&&delete Te.getInstance()._fileUploadRequest[i]},function(e){s&&"function"==typeof s&&s(e,i)});var p=u?new u:new FormData,f=r.file,_=r.fileType;_&&"undefined"!=typeof Blob&&(f instanceof Blob||"string"==typeof f||Array.isArray(f)||f.hasOwnProperty("isRNFetchBlobPolyfill"))?p.append("file",new Blob([f],{type:_}),f.name):p.append("file",f,f.name),r.channelUrl&&"string"==typeof r.channelUrl&&p.append("channel_url",r.channelUrl);var I=r.thumbnailSizes;if(I)for(var g=0;g0?k.SUCCEEDED:k.FAILED,e.hasOwnProperty("request_state")&&(this.requestState=e.request_state),this.requestedMentionUserIds=[],e.hasOwnProperty("requested_mention_user_ids")&&(this.requestedMentionUserIds=e.requested_mention_user_ids))};A(H,G),G.build=function(e,n,t,r,i,a,s,o,l,u,c,d,h,p,f,_,I){var g={};g.req_id=e,g.msg_id=n,g.channel_url=r.url,g.channel_type=r.channelType===Y.CHANNEL_TYPE_OPEN?Y.CHANNEL_TYPE_OPEN:Y.CHANNEL_TYPE_GROUP,g.ts=u,g.updated_at=c,g.message=i,a&&(g.data=a),s&&(g.custom_type=s),o&&(g.translations=o);var m={user_id:"",nickname:"",profile_url:"",metadata:{},is_blocked_by_me:!1};if(t){m.user_id=t.userId,m.nickname=t.nickname,m.profile_url=t.profileUrl;try{m.metadata="string"==typeof t.metaData?JSON.parse(t.metaData):t.metaData}catch(e){m.metadata={}}m.is_blocked_by_me=t.isBlockedByMe}if(g.user=m,g.is_global_block=!!l,d){g.metaarray={};for(var E=0;E0?k.SUCCEEDED:k.FAILED,_&&(g.request_state=_),f&&(g.mentioned_user_ids=f),g.requested_mention_user_ids=[],I&&(g.requested_mention_user_ids=I),g},G.buildFromSerializedData=function(e){var n=C(e),t=[];if(n.mentionedUsers.forEach(function(e){t.push(Q.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData,e.isActive,e.friendDiscoveryKey,e.friendName))}),!n.metaArrays&&n.metaArray){n.metaArrays=[];for(var r in n.metaArray)n.metaArrays.push(new Ue(r,n.metaArray[r]))}return new G(G.build(n.reqId,n.messageId,n.sender,{url:n.channelUrl,channelType:n.channelType},n.message,n.data,n.customType,n.translations,n.isGlobalBlocked,n.createdAt,n.updatedAt,n.metaArrays,n.mentionType,t,null,n.requestState,n.requestedMentionUserIds))};var V=function(e,i){var a=0,s=e,o=i,l=new n([]);l.onChangeHandler=function(e,i,a){if(r&&t.log("fileMessageQueue.onChangeHandler: ",e,i,a),a.hasOwnProperty(n.EventType.ADDED)){var s=a[n.EventType.ADDED];if(s.state=V.StateType.UPLOADING,s.error){var o=c.searchIndexByKeyValue("reqId",s.reqId);o>-1&&(s.state=V.StateType.SENT,c.update(o,s)),u(s.reqId)}else I(s,function(e){s.error&&s.state===V.StateType.SENT||(s.state=V.StateType.UPLOADED);var n=c.searchIndexByKeyValue("reqId",s.reqId);n>-1&&(s.fileInfo=e,c.update(n,s)),u(s.reqId)})}else a.hasOwnProperty(n.EventType.UPDATED)||c.length>0&&l.length<6&&h()};var u=function(e){var n=l.searchIndexByKeyValue("reqId",e);n>-1&&l.splice(n,1)},c=new n([]);c.onChangeHandler=function(e,i,a){r&&t.log("fileMessageQueue.onChangeHandler: ",e,i,a),a.hasOwnProperty(n.EventType.ADDED)?l.length<6&&h():c.length>0&&p()};var d=function(){var e=null,n=c.items.filter(function(e){return e.state===V.StateType.PENDING});return n.length>0&&(e=n[0]),e},h=function(){var e=d();e&&l.push(e)},p=function(){var e=c.items[0];e.state===V.StateType.UPLOADED?f():e.state===V.StateType.SENT&&_()},f=function(){var e=c.items[0];if(e&&e.state===V.StateType.UPLOADED){for(e.state=V.StateType.SENDING,a=0===a?(new Date).getTime()-200:a;(new Date).getTime()-a<200;);a=(new Date).getTime(),g(e,function(n,t){e.state=V.StateType.SENT,e.error=t||null,e.res=n||null;var r=c.searchIndexByKeyValue("reqId",e.reqId);r>-1&&c.update(r,e)})}},_=function(){var e=c.items[0];if(e&&e.state===V.StateType.SENT){e.state=V.StateType.DONE;var n=Te.getInstance(),t=e.res,r=e.error;if(t&&!r){var i=n.currentUser;i&&t._sender&&i.userId===t._sender.userId&&(i.nickname!==t._sender.nickname&&(i.nickname=t._sender.nickname),i.profileUrl!==t._sender.profileUrl&&(i.profileUrl=t._sender.profileUrl)),o||K.getChannel(s,function(r,i){if(O){var a=r;r=i,i=a}if(i)return L(t,i,e.fileInfo.callback),void c.shift();r.lastMessage=t;for(var s in n.channelHandlers){n.channelHandlers[s].onChannelChanged(r)}})}r&&(t=e.preMessageObj)&&(t.requestState=k.FAILED,r.code===U.INVALID_PARAMETER&&(t=null)),L(t,r,e.fileInfo.callback),c.shift()}},I=function(e,n){var t=e.fileInfo,r=e.preMessageObj;"string"!=typeof t.file&&t.file?ge.getInstance().uploadFile(t.file,t.type,t.thumbnailSizes,s,function(r,i){if(i)return e.state=V.StateType.SENT,e.error=i,e.res=null,void n(t);var a="object"==typeof r?r:JSON.parse(r);t.file=a.url,t.thumbnailSizes=a.hasOwnProperty("thumbnails")?a.thumbnails:[],t.requireAuth=!!a.hasOwnProperty("require_auth")&&a.require_auth,n(t)},t.progressHandler,r?r.reqId:null):(t.thumbnailSizes=[],t.requireAuth=!1,n(t))},g=function(e,n){if(null!==e){var t=e.fileInfo,r=e.reqId,i=Te.getInstance();if(i.getConnectionState()!==i.ConnectionState.OPEN&&i.currentUser&&!i.connecting)ge.getInstance().sendFileMessageAPI(s,o,t.file,t.name,t.size,t.type,t.data,t.customType,t.customType,t.requireAuth,t.metaArrays,t.mentionType,t.mentionedUserIds,t.pushNotificationDeliveryOption,function(e,r){var i=new q(r?a.getJsonElement():e);r&&(i.requestedMentionUserIds=t.mentionedUserIds),n(i,r)});else{var a=Z.bFile(r,s,t.file,t.name,t.type,t.size,t.data,t.customType,t.thumbnailSizes,t.requireAuth,t.metaArrays,t.mentionType,t.mentionedUserIds,t.pushNotificationDeliveryOption);i.sendCommand(a,function(e,r){var i=new q(r?a.getJsonElement():e.getJsonElement());r&&(i.requestedMentionUserIds=t.mentionedUserIds),n(i,r)})}}};this.addTask=function(e){c.push(e)},this.cancelUploadItemByReqId=function(e){u(e);var n=c.searchIndexByKeyValue("reqId",e);if(n>-1){var t=c.items[n];!t||t.state!==V.StateType.UPLOADING&&t.state!==V.StateType.PENDING||(t.state=V.StateType.SENT,t.res=null,t.error=new y("Uploading has been completed or canceled.",U.FILE_UPLOAD_CANCEL_FAILED),c.update(n,t))}}};V.StateType={PENDING:"pending",UPLOADING:"uploading",UPLOADED:"uploaded",SENDING:"sending",SENT:"sent",DONE:"done"};var q=function(e){if(this.messageType=H.MESSAGE_TYPE_FILE,e){if(this._update(e),this._sender=new J(e.user),f?this.sender=this._sender:Object.defineProperty(this,"sender",{get:function(){if(Te.getInstance().Options.useMemberAsMessageSender&&this.isGroupChannel()){var e=K.cachedChannels[this.channelUrl];if(e){var n=e.memberMap[this._sender.userId];n&&(this._sender.nickname!==n.nickname&&(this._sender.nickname=n.nickname),this._sender.profileUrl!==n.profileUrl&&(this._sender.profileUrl=n.profileUrl),S(this._sender.metaData,n.metaData)||(this._sender.metaData=n.metaData))}}return this._sender},set:function(e){this._sender=e}}),this.requireAuth=!!e.hasOwnProperty("require_auth")&&e.require_auth,this.url=this.requireAuth?String(e.url).split("?auth=")[0]+"?auth="+ge.getInstance().ekey:String(e.url).split("?auth=")[0],this.name=e.hasOwnProperty("name")?e.name:"File",this.size=parseInt(e.size)||0,this.type=String(e.type),this.data=e.hasOwnProperty("custom")?String(e.custom):"",this.reqId=e.hasOwnProperty("req_id")?String(e.req_id):"",this.thumbnails=e.hasOwnProperty("thumbnails")?e.thumbnails:[],this.requireAuth)for(var n=0;n0?k.SUCCEEDED:k.FAILED,e.hasOwnProperty("request_state")&&(this.requestState=e.request_state),this.requestedMentionUserIds=[],e.hasOwnProperty("requested_mention_user_ids")&&(this.requestedMentionUserIds=e.requested_mention_user_ids)}};A(H,q),q.build=function(e,n,t,r,i,a,s,o,l,u,c,d,h,p,f,_,I,g,m,E,A){var y={};y.req_id=e,y.msg_id=n,y.channel_url=r.url,y.channel_type=r.channelType===Y.CHANNEL_TYPE_OPEN?Y.CHANNEL_TYPE_OPEN:Y.CHANNEL_TYPE_GROUP,y.ts=d,y.updated_at=f,y.url=i,y.name=a,y.type=s,y.size=o,y.custom=l;var v={user_id:"",nickname:"",profile_url:"",metadata:{},is_global_block:!1};if(t){v.user_id=t.userId,v.nickname=t.nickname,v.profile_url=t.profileUrl;try{v.metadata=JSON.parse(t.metaData)}catch(e){v.metadata={}}v.is_blocked_by_me=t.isBlockedByMe}if(y.user=v,u&&(y.custom_type=u),p&&(y.require_auth=p),h&&(y.thumbnails=h),y.is_global_block=c,_){y.metaarray={};for(var N=0;N<_.length;N++){var C=_[N].key;y.metaarray[C]=_[N].value}y.metaarray_key_order=_.map(function(e){return e.key})}return I&&(y.mention_type=I),y.mentioned_users=[],g&&(y.mentioned_users=g),m&&(y.mentioned_user_ids=m),y.request_state=n>0?k.SUCCEEDED:k.FAILED,E&&(y.request_state=E),y.requested_mention_user_ids=[],A&&(y.requested_mention_user_ids=A),y},q.buildFromSerializedData=function(e){var n=C(e),t=[];if(n.mentionedUsers.forEach(function(e){t.push(Q.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData,e.isActive,e.friendDiscoveryKey,e.friendName))}),!n.metaArrays&&n.metaArray){n.metaArrays=[];for(var r in n.metaArray)n.metaArrays.push(new Ue(r,n.metaArray[r]))}return new q(q.build(n.reqId,n.messageId,n.sender,{url:n.channelUrl,channelType:n.channelType},n.url,n.name,n.type,n.size,n.data,n.customType,n.isGlobalBlocked,n.createdAt,n.thumbnails,n.requireAuth,n.updatedAt,n.metaArrays,n.mentionType,t,null,n.requestState,n.requestedMentionUserIds))};var Y=function(e){this._update=function(e){this.url=e.hasOwnProperty("channel_url")?String(e.channel_url):"",this.name=e.hasOwnProperty("name")?String(e.name):"",this.coverUrl=e.hasOwnProperty("cover_url")?String(e.cover_url):"",this.createdAt=e.hasOwnProperty("created_at")?1e3*e.created_at:0,this.data=e.hasOwnProperty("data")?String(e.data):"",this.customType=e.hasOwnProperty("custom_type")?e.custom_type:"",this.isFrozen=!!e.hasOwnProperty("freeze")&&e.freeze,this.isEphemeral=!!e.hasOwnProperty("is_ephemeral")&&e.is_ephemeral},this.serialize=function(){var e=JSON.parse(JSON.stringify(this));if(e.hasOwnProperty("lastMessage")&&null!==e.lastMessage&&"undefined"!=typeof e.lastMessage&&"object"==typeof e.lastMessage){var n=e.lastMessage;n.hasOwnProperty("_sender")&&(n.sender=n._sender,delete n._sender,e.lastMessage=n)}return N(e)},this.isGroupChannel=function(){return this.channelType===Y.CHANNEL_TYPE_GROUP},this.isOpenChannel=function(){return this.channelType===Y.CHANNEL_TYPE_OPEN},this.getMessageChangeLogsByTimestamp=function(e,n,t){var r=this ;if("function"==typeof n&&(t=n,n=!1),"number"!=typeof e||e<0)return void L(null,new y("Invalid parameters.",U.INVALID_PARAMETER),t);ge.getInstance().getMessageChangeLogs(r.isOpenChannel(),r.url,e,null,n,function(e,n){if(n)return void L(null,n,t);var i=e.updated.map(function(e){return H.build(e,r)}),a=e.deleted.map(function(e){return e.message_id}),s=e.has_more,o=e.next;L({updatedMessages:i,deletedMessageIds:a,hasMore:s,token:o},null,t)})},this.getMessageChangeLogsByToken=function(e,n,t){var r=this;if("function"==typeof n&&(t=n,n=!1),"function"==typeof e&&(t=e,n=!1,e=null),"string"!=typeof e&&null!==e)return void L(null,new y("Invalid parameters.",U.INVALID_PARAMETER),t);ge.getInstance().getMessageChangeLogs(r.isOpenChannel(),r.url,0,e,n,function(e,n){if(n)return void L(null,n,t);var i=e.updated.map(function(e){return H.build(e,r)}),a=e.deleted.map(function(e){return e.message_id}),s=e.has_more,o=e.next;L({updatedMessages:i,deletedMessageIds:a,hasMore:s,token:o},null,t)})},this.getMyMutedInfo=function(e){var n=this;ge.getInstance().getMyMutedInfo(n.isGroupChannel(),n.url,Te.getInstance().currentUser.userId,function(n,t){if(t)return void L(null,t,e);var r={isMuted:n.is_muted,startAt:n.start_at,endAt:n.end_at,remainingDuration:n.remaining_duration,description:n.description};L(r,null,e)})},this.createOperatorListQuery=function(){return new $(this)},this.createPreviousMessageListQuery=function(){return new ae(this)},this.createMessageListQuery=function(){return new re(this)};var n=function(e,n,t,r,i,a,s,o,l,u,c){if(s===v.MessageTypeFilter.ADMIN?s="ADMM":s===v.MessageTypeFilter.USER?s="MESG":s===v.MessageTypeFilter.FILE?s="FILE":s===v.MessageTypeFilter.ALL&&(s=""),!(m(n)&&"boolean"==typeof t&&m(r)&&m(i)&&"boolean"==typeof a&&"string"==typeof s&&"string"==typeof o&&Array.isArray(l)&&"boolean"==typeof u))return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),c);for(var d=0;d20)return a(new y("Invalid parameter.",U.INVALID_PARAMETER)),null;var s=e.length,o=[];return e.forEach(function(e,n){var l=i;n===s-1&&(l=function(e,n){i(e,n),a(null)}),o.push(t.sendFileMessage(e,r,l))}),o},this.cancelUploadingFileMessage=function(e,n){var t=this;if(!m(e))return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n);Te.getInstance()._getFileQueue(t.url).cancelUploadItemByReqId(e);var r=Te.getInstance()._fileUploadRequest[e];return r?(r.upload.onabort=function(){L(!0,null,n)},r.isAbort=!0,r.abort(),!0):(L(!1,new y("Uploading has been completed or canceled.",U.FILE_UPLOAD_CANCEL_FAILED),n),!1)},this._sendUserMessage=function(e,n,t,r,i,a,s,o,l,u){l||(l=Z.generateRequestId());var c=(new Date).getTime(),d=G.build(l,0,Te.getInstance().currentUser,this,e,n,t,s,!1,c,0,r,i,null,a),h=new G(d);if(h.requestState=k.PENDING,h.requestedMentionUserIds=a,!Te.getInstance()||!Te.getInstance().currentUser){var p=new G(d);return p.requestState=k.FAILED,p.requestedMentionUserIds=a,u&&L(p,new y("Connection should be made first.",U.CONNECTION_REQUIRED),u),h}var f=this,_=Z.bMessage(this.url,e,n,t,r,i,a,s,o,l);h.reqId=_.requestId;var I=Te.getInstance();return f.isGroupChannel()&&I.getConnectionState()!==I.ConnectionState.OPEN&&I.currentUser&&!I.connecting&&!I.reconnecting&&"string"==typeof t&&0===t.indexOf("SB_VIDEOCHAT")?ge.getInstance().sendUserMessageAPI(f.url,f.isOpenChannel(),e,n,t,s,r,i,a,o,function(e,n){var t=new G(e);n?(t.requestState=k.FAILED,t.requestedMentionUserIds=a):t.requestState=k.SUCCEEDED,L(t,n,u)}):Te.getInstance().sendCommand(_,function(e,n){var t=null;if(n)return t=new G(d),t.reqId=_.requestId,t.requestState=k.FAILED,t.requestedMentionUserIds=a,void L(t,new y(n.message,n.code),u);t=new G(e.getJsonElement());var r=Te.getInstance().currentUser;r&&t._sender&&r.userId===t._sender.userId&&(r.nickname!==t._sender.nickname&&(r.nickname=t._sender.nickname),r.profileUrl!==t._sender.profileUrl&&(r.profileUrl=t._sender.profileUrl),S(r.metaData,t._sender.metaData)||(r.metaData=t._sender.metaData)),f.isGroupChannel()&&K.getChannel(f.url,function(e,n){if(O){var r=e;e=n,n=r}if(n)return t.requestState=k.SUCCEEDED,void L(t,n,u);if(!E(t)){e.lastMessage=t;for(var i in Te.getInstance().channelHandlers){Te.getInstance().channelHandlers[i].onChannelChanged(e)}}}),t.requestState=k.SUCCEEDED,L(t,null,u)}),h},this.sendUserMessage=function(e,n,t,r,i){var a=[],s=ve.MentionType.USERS,o=[],l=Ne.PushNotificationDeliveryOption.DEFAULT;if("function"==typeof n&&(i=n,n="",t="",r=[],e instanceof Ne)){var u=e;e=u.message,n=u.data,t=u.customType,r=u.translationTargetLanguages,a=u.metaArrayKeys,s=u._mentionType,o=u._mentionedIds,l=u.pushNotificationDeliveryOption?u.pushNotificationDeliveryOption:Ne.PushNotificationDeliveryOption.DEFAULT}"function"==typeof t&&(i=t,t="",r=[]),"function"==typeof r&&(i=r,r=[]),r||(r=[]),"string"==typeof r&&(r=[r]),null===n&&(n=""),null===t&&(t="");for(var c=!0,d=0;d0)for(var s=0;s0)for(var s=0;s0});u.length>0&&a.push(new Ue(l,u).encode())}}var c=a.length>0;for(var o in a){var d=a[o];if(!d.hasOwnProperty("key")||!d.hasOwnProperty("value")||0===d.value.length){c=!1;break}}if(!i||!c)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),t);r(this.url,e,{array:a,mode:"add",upsert:!0},t)},this.removeMessageMetaArrayValues=function(e,n,t){var i=e&&(e.isUserMessage()||e.isFileMessage()||e.isAdminMessage()),a=[];if(Array.isArray(n))a=n.filter(function(e){return e instanceof Ue}).map(function(e){return e.encode()});else if("object"==typeof n&&n)for(var s=Object.keys(n),o=0;o0});u.length>0&&a.push(new Ue(l,u).encode())}}var c=a.length>0;for(var o in a){var d=a[o];if(!d.hasOwnProperty("key")||!d.hasOwnProperty("value")||0===d.value.length){c=!1;break}}if(!i||!c)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),t);r(this.url,e,{array:a,mode:"remove",upsert:!0},t)},this.channelType=Y.CHANNEL_TYPE_BASE,e&&this._update(e)};Y.CHANNEL_TYPE_OPEN="open",Y.CHANNEL_TYPE_GROUP="group",Y.CHANNEL_TYPE_BASE="base";var B=function(e){this.parse=function(e){if(e.hasOwnProperty("participant_count")&&(this.participantCount=parseInt(e.participant_count)),e.hasOwnProperty("operators")&&e.operators){this.operators=[];for(var n=0;n0||n.unreadMentionCount>0){R(n,0,0);for(var i in Te.getInstance().channelHandlers){Te.getInstance().channelHandlers[i].onChannelChanged(n)}}L(null,null,e)})},this.getReadReceipt=function(e){if(!(e instanceof H))return t.log("message is not BaseMessage instance"),0;if(e.messageType===H.MESSAGE_TYPE_ADMIN)return 0;var n=Te.getInstance().currentUser;if(!n)return 0;for(var r=0,i=e.createdAt,a=this.members,s=0;s=e.createdAt&&t.push(a)}}return t},this.getUnreadMembers=function(e,n){"boolean"!=typeof n&&(n=!1);var t=[];if(!Te.getInstance().currentUser||this.isSuper||!e||e.isAdminMessage())return t;for(var r=this.members,i=0;io)&&(n=1e3),e-r>=n){i=0,r=e;var t=Z.bTypeStart(this.url,r);Te.getInstance().sendCommand(t,null)}},this.endTyping=function(){var e=(new Date).getTime(),n=Te.getInstance().Options.typingIndicatorThrottle;if(("number"!=typeof n||no)&&(n=1e3),e-i>=n){r=0,i=e;var t=Z.bTypeEnd(this.url,i);Te.getInstance().sendCommand(t,null)}},this.invalidateTypingStatus=function(){var e=!1,t=(new Date).getTime();for(var r in n){t-n[r]>=1e4&&(delete n[r],e=!0)}return e},this.updateTypingStatus=function(e,t){t?n[e.userId]=(new Date).getTime():delete n[e.userId]},this.isTyping=function(){return 0!==Object.keys(n).length},this.getTypingMembers=function(){var e=[];for(var t in n){var r=this.memberMap[t];this.memberMap[t]&&e.push(r)}return e},this.addMember=function(e){if(!this.isSuper){var n=this.removeMember(e);n&&n.state===X.JOINED&&(e.state=X.JOINED),this.memberMap[e.userId]=e,this.members.push(e),this.memberCount++,this.updateReadReceipt(e.userId,0)}},this.removeMember=function(e){var n=null;if(!this.isSuper){var t=e.userId;if(this.memberMap.hasOwnProperty(e.userId)){delete this.memberMap[e.userId];for(var r=0;r=a&&(a=t,this.memberCount=e,this.joinedMemberCount=n)},this.setPushPreference=function(e,n){var t=this;ge.getInstance().setPushPreference(this.url,e,function(e,r){if(r)return void L(null,r,n);t.isPushEnabled=e.enable,t.isPushEnabled||(t.myPushTriggerOption=K.PushTriggerOption.OFF),L(e,null,n)})},this.getPushPreference=function(e){var n=this;ge.getInstance().getPushPreference(this.url,function(t,r){if(r)return void L(null,r,e);var i;try{i=t.enable}catch(e){i=!1}n.isPushEnabled=i,e&&L(i,null,e)})},this.setMyPushTriggerOption=function(e,n){if([K.PushTriggerOption.DEFAULT,K.PushTriggerOption.ALL,K.PushTriggerOption.MENTION_ONLY,K.PushTriggerOption.OFF].indexOf(e)<0)return void L(null,new y("Invalid parameters.",U.INVALID_PARAMETER),n);var t=this;ge.getInstance().setMyPushTriggerOption(this.url,e,function(e,r){if(r)return void L(null,r,n);t.myPushTriggerOption=e.push_trigger_option,L(t.myPushTriggerOption,null,n)})},this.getMyPushTriggerOption=function(e){var n=this;ge.getInstance().getMyPushTriggerOption(this.url,function(t,r){if(r)return void L(null,r,e);var i=K.PushTriggerOption.DEFAULT;try{i=t.push_trigger_option}catch(e){}n.myPushTriggerOption=i,L(i,null,e)})},this.setMyCountPreference=function(e,n){if([K.CountPreference.ALL,K.CountPreference.UNREAD_MESSAGE_COUNT_ONLY,K.CountPreference.UNREAD_MENTION_COUNT_ONLY,K.CountPreference.OFF].indexOf(e)<0)return void L(null,new y("Invalid parameters.",U.INVALID_PARAMETER),n);var t=this;ge.getInstance().setCountPreference(this.url,e,function(e,r){if(r)return void L(null,r,n);t.myCountPreference=e.count_preference,R(t,t.unreadMessageCount,t.unreadMentionCount),K.cachedChannels[t.url]=t,L(t.myCountPreference,null,n)})},this.createMemberListQuery=function(){var e=this.url;return new ee(e)},this.banUser=function(e,n,t,r){if(!e||!e.hasOwnProperty("userId"))return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),r);this.banUserWithUserId(e.userId,n,t,r)},this.banUserWithUserId=function(e,n,t,r){var i=this;if(!e||"string"!=typeof e||"number"!=typeof n||"string"!=typeof t)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),r);ge.getInstance().banUser(i.url,e,t,n,!0,function(n,t){if(t)return void L(null,t,r);i.removeMember({userId:e}),L(null,null,r)})},this.unbanUser=function(e,n){if(!e||!e.hasOwnProperty("userId"))return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n);this.unbanUserWithUserId(e.userId,n)},this.unbanUserWithUserId=function(e,n){if(!e||"string"!=typeof e)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n);ge.getInstance().unbanUser(this.url,e,!0,function(e,t){if(t)return void L(null,t,n);L(null,null,n)})},this.muteUser=function(e,n,t,r){if("function"==typeof n&&(r=n,n=-1,t=""),!e||!e.hasOwnProperty("userId")||"number"!=typeof n||n<0&&-1!==n||"string"!=typeof t)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),r);this.muteUserWithUserId(e.userId,n,t,r)},this.muteUserWithUserId=function(e,n,t,r){if("function"==typeof n&&(r=n,n=-1,t=""),!e||"string"!=typeof e||"number"!=typeof n||n<0&&-1!==n||"string"!=typeof t)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),r);ge.getInstance().muteUser(this.url,e,!0,n,t,function(e,n){if(n)return void L(null,n,r);L(null,null,r)})},this.unmuteUser=function(e,n){if(!e||!e.hasOwnProperty("userId"))return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n);this.unmuteUserWithUserId(e.userId,n)},this.unmuteUserWithUserId=function(e,n){if(!e||"string"!=typeof e)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n);ge.getInstance().unmuteUser(this.url,e,!0,function(e,t){if(t)return void L(null,t,n);L(null,null,n)})},this.freeze=function(e){ge.getInstance().freeze(this.url,!0,!0,function(n,t){if(t)return void L(null,t,e);K.upsert(n),L(null,null,e)})},this.unfreeze=function(e){ge.getInstance().freeze(this.url,!0,!1,function(n,t){if(t)return void L(null,t,e);K.upsert(n),L(null,null,e)})},this.createBannedUserListQuery=function(){var e=this;return new ue({channelUrl:e.url,isOpenChannel:e.isOpenChannel()})},this.channelType=Y.CHANNEL_TYPE_GROUP,this.isDistinct=!1,this.isSuper=!1,this.isPublic=!1,this.unreadMessageCount=0,this.inviter=null,this.members=[],this.memberMap={},this.lastMessage={},this.memberCount=0,this.joinedMemberCount=0,this.cachedReadReceiptStatus={},this.myPushTriggerOption=K.PushTriggerOption.DEFAULT,this.isPushEnabled,this.isHidden=!1,this.hiddenState=K.HiddenState.UNHIDDEN,this.isDiscoverable=!0,this.myLastRead=0,e&&(this._update(e),this.parse(e))};A(Y,K),K.buildFromSerializedData=function(e){var n=C(e);return new K({channel_url:n.url,name:n.name,cover_url:n.coverUrl,data:n.data,custom_type:n.customType,invited_at:n.invitedAt,created_at:n.createdAt/1e3,is_access_code_required:n.isAccessCodeRequired,is_distinct:n.isDistinct,is_super:n.isSuper,is_public:n.isPublic,is_discoverable:n.isDiscoverable,freeze:n.isFrozen,is_ephemeral:n.isEphemeral,unread_message_count:n.unreadMessageCount,unread_mention_count:n.unreadMentionCount,is_push_enabled:n.isPushEnabled,push_trigger_option:n.myPushTriggerOption,count_preference:n.myCountPreference,is_hidden:n.isHidden,hidden_state:n.hiddenState,member_count:n.memberCount,joined_member_count:n.joinedMemberCount,member_state:n.myMemberState,my_role:n.myRole,is_muted:n.myMutedState,user_last_read:n.myLastRead,members:n.members.map(function(e){return X.build(Q.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData,e.isActive,e.friendDiscoveryKey,e.friendName),e.state,e.isBlockedByMe,e.isBlockingMe)}),last_message:function(e){return null!==e&&void 0!==e&&"object"==typeof e?e.messageType===H.MESSAGE_TYPE_USER?new G(G.build(e.reqId,e.messageId,e.sender,{url:e.channelUrl,channelType:e.channelType},e.message,e.data,e.customType,e.translations,e.isGlobalBlocked,e.createdAt,e.updatedAt,e.metaArrays,e.mentionType,e.mentionedUsers)):e.messageType===H.MESSAGE_TYPE_FILE?new q(q.build(e.reqId,e.messageId,e.sender,{url:e.channelUrl,channelType:e.channelType},e.url,e.name,e.type,e.size,e.data,e.customType,e.isGlobalBlocked,e.createdAt,e.thumbnails,e.requireAuth,e.updatedAt,e.metaArrays,e.mentionType,e.mentionedUsers)):new w(w.build(e.messageId,{url:e.channelUrl,channelType:e.channelType},e.message,e.data,e.customType,e.translations,e.createdAt,e.updatedAt,e.metaArrays,e.mentionType,e.mentionedUsers)):null}(n.lastMessage),read_receipt:n.cachedReadReceiptStatus,inviter:null!==n.inviter&&"undefined"!=typeof n.inviter&&"object"==typeof n.inviter?Q.build(n.inviter.userId,n.inviter.nickname,n.inviter.profileUrl,n.inviter.connectionStatus,n.inviter.lastSeenAt,n.inviter.metaData,n.inviter.isActive,n.inviter.friendDiscoveryKey,n.inviter.friendName):null})},K.createMyGroupChannelListQuery=function(){return new ne},K.createPublicGroupChannelListQuery=function(){return new te},K.memberState={ALL:0,JOINED:1,INVITED:2,INVITED_BY_FRIEND:3,INVITED_BY_NON_FRIEND:4},K.memberStateFilter={ALL:"all",JOINED:"joined_only",INVITED:"invited_only",INVITED_BY_FRIEND:"invited_by_friend",INVITED_BY_NON_FRIEND:"invited_by_non_friend"},K.superChannelFilter={ALL:"all",SUPER:"super",NON_SUPER:"nonsuper"},K.publicChannelFilter={ALL:"all",PUBLIC:"public",PRIVATE:"private"},K.Role={OPERATOR:"operator",NONE:"none"},K.UnreadItemKey={GROUP_CHANNEL_UNREAD_MENTION_COUNT:"group_channel_unread_mention_count",NONSUPER_UNREAD_MENTION_COUNT:"non_super_group_channel_unread_mention_count",SUPER_UNREAD_MENTION_COUNT:"super_group_channel_unread_mention_count",GROUP_CHANNEL_UNREAD_MESSAGE_COUNT:"group_channel_unread_message_count",NONSUPER_UNREAD_MESSAGE_COUNT:"non_super_group_channel_unread_message_count",SUPER_UNREAD_MESSAGE_COUNT:"super_group_channel_unread_message_count",GROUP_CHANNEL_INVITATION_COUNT:"group_channel_invitation_count",NONSUPER_INVITATION_COUNT:"non_super_group_channel_invitation_count",SUPER_INVITATION_COUNT:"super_group_channel_invitation_count"},K.PushTriggerOption={DEFAULT:"default",ALL:"all",MENTION_ONLY:"mention_only",OFF:"off"},K.CountPreference={ALL:"all",UNREAD_MESSAGE_COUNT_ONLY:"unread_message_count_only",UNREAD_MENTION_COUNT_ONLY:"unread_mention_count_only",OFF:"off"},K.UnreadChannelFilter={ALL:"all",UNREAD_MESSAGE:"unread_message"},K.HiddenState={UNHIDDEN:"unhidden",HIDDEN_ALLOW_AUTO_UNHIDE:"hidden_allow_auto_unhide",HIDDEN_PREVENT_AUTO_UNHIDE:"hidden_prevent_auto_unhide"},K.HiddenChannelFilter={UNHIDDEN:"unhidden_only",HIDDEN:"hidden_only",HIDDEN_ALLOW_AUTO_UNHIDE:"hidden_allow_auto_unhide",HIDDEN_PREVENT_AUTO_UNHIDE:"hidden_prevent_auto_unhide"},K.getChannelCount=function(e,n){"function"==typeof e&&1===arguments.length&&(n=e,e=K.memberState.ALL),Te.getInstance().getGroupChannelCount(e,n)},K.getUnreadItemCount=function(e,n){Te.getInstance().getUnreadItemCount(e,n)},K.getTotalUnreadMessageCount=function(e,n){Te.getInstance().getTotalUnreadMessageCount(e,n)},K.getTotalUnreadChannelCount=function(e){Te.getInstance().getTotalUnreadChannelCount(e)},K.createDistinctChannelIfNotExist=function(e,n){var t=null,r=null,i=null,a=null,s=null,o=null,l=null,u=null,c=[],d={isPublic:null,channelUrl:null,isDiscoverable:null,isStrict:null},h=null,p=null;if(!(e instanceof ye))return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n);if(t=e._inviteUserIds,r=!0,u=e.isSuper,i=e.name,a=e.channelCover,s=e.data,l=e.customType,c=e._operatorIds,d.isPublic=e.isPublic,d.channelUrl=e.channelUrl,d.isDiscoverable=e.isDiscoverable,d.isStrict=e.isStrict,h=e.isEphemeral,p=e.accessCode,o=n,!Array.isArray(t)||"boolean"!=typeof u&&null!==u||"boolean"!=typeof h&&null!==h||"boolean"!=typeof d.isPublic&&null!==d.isPublic||"string"!=typeof d.channelUrl&&null!==d.channelUrl||"boolean"!=typeof d.isDiscoverable&&null!==d.isDiscoverable||"boolean"!=typeof d.isStrict&&null!==d.isStrict||"string"!=typeof i&&null!==i&&void 0!==i||"string"!=typeof a&&null!==a&&void 0!==a&&I(a)||"string"!=typeof s&&null!==s&&void 0!==s||"string"!=typeof l&&null!==l&&void 0!==l||"string"!=typeof p&&null!==p&&void 0!==p)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),o);d.isPublic||(p=null);var f=t.filter(function(e,n,t){return n===t.indexOf(e)});ge.getInstance().createGroupChannel(f,r,i,a,s,l,u,d,c,h,p,function(e,n){if(n)return void L(null,n,o);var t=new K(e);K.cachedChannels[t.url]=t,L({channel:t,isCreated:e.is_created},null,o)})},K.createChannel=function(){var e=null,n=[],t=null,r=null,i=null,a=null,s=null,o=null,l=null,u={isPublic:null,channelUrl:null,isDiscoverable:null,isStrict:null},c=[],d=null,h=null;switch(arguments.length){case 2:if(arguments[0]instanceof ye){var p=arguments[0];n=p._inviteUserIds,e=[],t=p.isDistinct,r=p.isSuper,i=p.name,a=p.channelCover,s=p.data,l=p.customType,c=p._operatorIds,u.isPublic=p.isPublic,u.channelUrl=p.channelUrl,u.isDiscoverable=p.isDiscoverable,u.isStrict=p.isStrict,d=p.isEphemeral,h=p.accessCode,o=arguments[1];break}e=arguments[0],t=!1,o=arguments[1];break;case 3:e=arguments[0],t=arguments[1],o=arguments[2];break;case 4:e=arguments[0],t=arguments[1],l=arguments[2],o=arguments[3];break;case 6:e=arguments[0],t=arguments[1],i=arguments[2],a=arguments[3],s=arguments[4],o=arguments[5];break;case 7:e=arguments[0],t=arguments[1],i=arguments[2],a=arguments[3],s=arguments[4],l=arguments[5],o=arguments[6]}if(!Array.isArray(e)||"boolean"!=typeof t&&null!==t||"boolean"!=typeof r&&null!==r||"boolean"!=typeof d&&null!==d||"boolean"!=typeof u.isPublic&&null!==u.isPublic||"string"!=typeof u.channelUrl&&null!==u.channelUrl||"boolean"!=typeof u.isDiscoverable&&null!==u.isDiscoverable||"boolean"!=typeof u.isStrict&&null!==u.isStrict||"string"!=typeof i&&null!==i&&void 0!==i||"string"!=typeof a&&void 0!==a&&null!==a&&I(a)||"string"!=typeof s&&null!==s&&void 0!==s||"string"!=typeof l&&null!==l&&void 0!==l||"string"!=typeof h&&null!==h&&void 0!==h)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),o);e.forEach(function(e){n.push(e.userId)}),K.createChannelWithUserIds(n,t,i,a,s,l,r,u,c,d,h,o)},K.createChannelWithUserIds=function(){var e=null,n=null,t=null,r=null,i=null,a=null,s=null,o=null,l=[],u={isPublic:null,channelUrl:null,isDiscoverable:null,isStrict:null},c=null,d=null;switch(arguments.length){case 2:e=arguments[0],n=!1,a=arguments[1];break;case 3:e=arguments[0],n=arguments[1],a=arguments[2];break;case 4:e=arguments[0],n=arguments[1],s=arguments[2],a=arguments[3];break;case 6:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],i=arguments[4],a=arguments[5];break;case 7:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],i=arguments[4],s=arguments[5],a=arguments[6];break;case 8:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],i=arguments[4],s=arguments[5],o=arguments[6],a=arguments[7];break;case 9:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],i=arguments[4],s=arguments[5],o=arguments[6],u.isPublic=arguments[7].isPublic,u.channelUrl=arguments[7].channelUrl,u.isDiscoverable=arguments[7].isDiscoverable,u.isStrict=arguments[7].isStrict,a=arguments[8];break;case 10:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],i=arguments[4],s=arguments[5],o=arguments[6],u.isPublic=arguments[7].isPublic,u.channelUrl=arguments[7].channelUrl,u.isDiscoverable=arguments[7].isDiscoverable,u.isStrict=arguments[7].isStrict,l=arguments[8],a=arguments[9];break;case 11:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],i=arguments[4],s=arguments[5],o=arguments[6],u.isPublic=arguments[7].isPublic,u.channelUrl=arguments[7].channelUrl,u.isDiscoverable=arguments[7].isDiscoverable,u.isStrict=arguments[7].isStrict,l=arguments[8],c=arguments[9],a=arguments[10];break;case 12:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],i=arguments[4],s=arguments[5],o=arguments[6],u.isPublic=arguments[7].isPublic,u.channelUrl=arguments[7].channelUrl,u.isDiscoverable=arguments[7].isDiscoverable,u.isStrict=arguments[7].isStrict,l=arguments[8],c=arguments[9],d=arguments[10],a=arguments[11]}if(!Array.isArray(e)||"boolean"!=typeof n&&null!==n||"boolean"!=typeof o&&null!==o||"boolean"!=typeof c&&null!==c||"boolean"!=typeof u.isPublic&&null!==u.isPublic||"string"!=typeof u.channelUrl&&null!==u.channelUrl||"boolean"!=typeof u.isDiscoverable&&null!==u.isDiscoverable||"boolean"!=typeof u.isStrict&&null!==u.isStrict||"string"!=typeof t&&null!==t&&void 0!==t||"string"!=typeof r&&null!==r&&void 0!==r&&I(r)||"string"!=typeof i&&null!==i&&void 0!==i||"string"!=typeof s&&null!==s&&void 0!==s||"string"!=typeof d&&null!==d&&void 0!==d)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),a);u.isPublic||(d=null);var h=e.filter(function(e,n,t){return n===t.indexOf(e)});ge.getInstance().createGroupChannel(h,n,t,r,i,s,o,u,l,c,d,function(e,n){if(n)return void L(null,n,a);var t=new K(e);K.cachedChannels[t.url]=t,L(t,null,a)})},K.cachedChannels={},K.clearCache=function(){K.cachedChannels={},Te.getInstance()._clearFileQueue()},K.removeCachedChannel=function(e){delete K.cachedChannels[e],Te.getInstance()._deleteFileQueue(e)},K.upsert=function(e){var n=new K(e);if(K.cachedChannels.hasOwnProperty(n.url)){if(n.isEphemeral){var t=K.cachedChannels[n.url];e.last_message=t.lastMessage,e.unread_message_count=t.unreadMessageCount}K.cachedChannels[n.url].update(e)}else K.cachedChannels[n.url]=n;return K.cachedChannels[n.url]},K.getChannelWithoutCache=function(e,n){if(!e)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n);ge.getInstance().getGroupChannel(e,!0,!0,function(e,t){if(t)return void L(null,t,n);var r=K.upsert(e);L(r,null,n)})},K.getChannel=function(e,n){if(!e)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n);K.cachedChannels.hasOwnProperty(e)?L(K.cachedChannels[e],null,n):K.getChannelWithoutCache(e,n)},K.markAsReadAllLastSentAt,K.markAsReadAll=function(e){Te.getInstance().markAsReadAll(e)};var j=function(e){e&&(this.category=e.hasOwnProperty("cat")?parseInt(e.cat):0,this.data=e.hasOwnProperty("data")?e.data:null,this.channelUrl=e.hasOwnProperty("channel_url")?String(e.channel_url):"",this.channelType=e.hasOwnProperty("channel_type")?String(e.channel_type):Y.CHANNEL_TYPE_GROUP),this.isGroupChannel=function(){return this.channelType===Y.CHANNEL_TYPE_GROUP},this.isOpenChannel=function(){return this.channelType===Y.CHANNEL_TYPE_OPEN}};j.CATEGORY_NONE=0,j.CATEGORY_CHANNEL_ENTER=10102,j.CATEGORY_CHANNEL_EXIT=10103,j.CATEGORY_USER_CHANNEL_MUTE=10201,j.CATEGORY_USER_CHANNEL_UNMUTE=10200,j.CATEGORY_USER_CHANNEL_BAN=10601,j.CATEGORY_USER_CHANNEL_UNBAN=10600,j.CATEGORY_CHANNEL_FREEZE=10701,j.CATEGORY_CHANNEL_UNFREEZE=10700,j.CATEGORY_TYPING_START=10900,j.CATEGORY_TYPING_END=10901,j.CATEGORY_CHANNEL_JOIN=1e4,j.CATEGORY_CHANNEL_LEAVE=10001,j.CATEGORY_CHANNEL_INVITE=10020,j.CATEGORY_CHANNEL_DECLINE_INVITE=10022,j.CATEGORY_CHANNEL_PROP_CHANGED=11e3,j.CATEGORY_CHANNEL_DELETED=12e3,j.CATEGORY_CHANNEL_META_DATA_CHANGED=11100,j.CATEGORY_CHANNEL_META_COUNTERS_CHANGED=11200,j.CATEGORY_CHANNEL_HIDE=13e3,j.CATEGORY_CHANNEL_UNHIDE=13001;var z=function(e){e&&(this.category=e.hasOwnProperty("cat")?parseInt(e.cat):0)};z.CATEGORY_USER_BLOCK=20001,z.CATEGORY_USER_UNBLOCK=2e4,z.CATEGORY_FRIEND_DISCOVERED=20900;var W=function(e){e&&(this.reader=new Q(e.user),this.timestamp=parseInt(e.ts),this.channelUrl=e.hasOwnProperty("channel_url")?String(e.channel_url):"",this.channelType=e.hasOwnProperty("channel_type")?String(e.channel_type):Y.CHANNEL_TYPE_GROUP)},Q=function(e){this.nickname="",this.profileUrl="",this.userId="",this.connectionStatus="",this.lastSeenAt=null,this.metaData={},this.isActive=!0,this.friendDiscoveryKey=null,this.friendName=null,this.getOriginalProfileUrl=function(){var e="";if(e=this.profileUrl.indexOf("://")>-1?this.profileUrl.split("/")[2]:this.profileUrl.split("/")[0],e=e.split("?")[0],(e.indexOf("sendbird.com")>-1||e.indexOf("intoz.com")>-1)&&this.profileUrl.indexOf(e+"/profile_images/")>-1){var n=this.profileUrl.replace("profile_images/","");return n===this.profileUrl?"":n}return""},this._update=function(e){e.hasOwnProperty("guest_id")&&(this.userId=String(e.guest_id)),e.hasOwnProperty("user_id")&&(this.userId=String(e.user_id)),e.hasOwnProperty("name")&&(this.nickname=String(e.name)),e.hasOwnProperty("nickname")&&(this.nickname=String(e.nickname)),e.hasOwnProperty("image")&&(this.profileUrl=String(e.image)),e.hasOwnProperty("profile_url")&&(this.profileUrl=String(e.profile_url)),e.hasOwnProperty("is_online")?e.is_online===Q.NON_AVAILABLE?this.connectionStatus=Q.NON_AVAILABLE:this.connectionStatus=e.is_online?Q.ONLINE:Q.OFFLINE:this.connectionStatus=Q.NON_AVAILABLE,e.hasOwnProperty("last_seen_at")?this.lastSeenAt=parseInt(e.last_seen_at):this.lastSeenAt=0,e.hasOwnProperty("metadata")?this.metaData=e.metadata:this.metaData={},e.hasOwnProperty("is_active")?this.isActive="undefined"==typeof e.is_active||e.is_active:this.isActive=!0,e.hasOwnProperty("friend_discovery_key")?this.friendDiscoveryKey=e.friend_discovery_key:this.friendDiscoveryKey=null,e.hasOwnProperty("friend_name")?this.friendName=e.friend_name:this.friendName=null},this._updateMetaData=function(e,n){var t=this,r=Object.keys(e);n?r.forEach(function(e){delete t.metaData[e]}):r.forEach(function(n){t.metaData[n]=e[n]});for(var i in K.cachedChannels)if(K.cachedChannels.hasOwnProperty(i)){var a=K.cachedChannels[i];if(a.memberMap.hasOwnProperty(t.userId)){var s=a.memberMap[t.userId];s.metaData=t.metaData}}},this.createMetaData=function(e,n){var t=this;if("function"==typeof e&&1===arguments.length&&(n=e,e={}),"object"!=typeof e||g(e)||Array.isArray(e))return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n);ge.getInstance().createUserMetaData(e,function(e,r){if(r)return void L(null,r,n);t._updateMetaData(e),L(e,null,n)})},this.updateMetaData=function(e,n,t){var r=this;if("function"==typeof e&&1===arguments.length&&(t=e,e={}),"function"==typeof n&&2===arguments.length&&(t=n,n=!1),"object"!=typeof e||g(e)||Array.isArray(e)||"boolean"!=typeof n)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),t);ge.getInstance().updateUserMetaData(e,n,function(e,n){if(n)return void L(null,n,t);r._updateMetaData(e),L(e,null,t)})},this.deleteAllMetaData=function(e){var n=this,t=n.metaData;ge.getInstance().deleteAllUserMetaData(function(r,i){if(i)return void L(null,i,e);n._updateMetaData(t,!0),L(r,null,e)})},this.deleteMetaData=function(e,n){var t=this;if("function"==typeof e&&1===arguments.length&&(n=e,e=null),"string"!=typeof e)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n);var r={};r[e]="",ge.getInstance().deleteUserMetaData(e,function(e,i){if(i)return void L(null,i,n);t._updateMetaData(r,!0),L(e,null,n)})},this.serialize=function(){var e=JSON.parse(JSON.stringify(this));return N(e)},e&&this._update(e)};Q.NON_AVAILABLE="nonavailable",Q.ONLINE="online",Q.OFFLINE="offline",Q.build=function(e,n,t,r,i,a,s,o,l){return{user_id:e,nickname:n,profile_url:t,is_online:r,last_seen_at:i,metadata:a,is_active:s,friend_discovery_key:o,friend_name:l}},Q.buildFromSerializedData=function(e){var n=C(e);return new Q(Q.build(n.userId,n.nickname,n.profileUrl,n.connectionStatus,n.lastSeenAt,n.metaData,n.isActive,n.friendDiscoveryKey,n.friendName))};var J=function(e){this.isBlockedByMe=!1,this.parse=function(e){e.hasOwnProperty("is_blocked_by_me")&&(this.isBlockedByMe=e.is_blocked_by_me)},e&&(this._update(e),this.parse(e))};A(Q,J),J.build=function(e,n){var t=e;return t.is_blocked_by_me=n,t},J.buildFromSerializedData=function(e){var n=C(e);return new J(J.build(Q.build(n.userId,n.nickname,n.profileUrl,n.connectionStatus,n.lastSeenAt,n.metaData,n.isActive,n.friendDiscoveryKey,n.friendName),n.isBlockedByMe))};var X=function(e){this.state="",this.isBlockedByMe=!1,this.isBlockingMe=!1,this.parse=function(e){this.state=e.state,e.hasOwnProperty("is_blocked_by_me")&&(this.isBlockedByMe=e.is_blocked_by_me),e.hasOwnProperty("is_blocking_me")&&(this.isBlockingMe=e.is_blocking_me)},e&&(this._update(e),this.parse(e))};A(Q,X),X.JOINED="joined",X.INVITED="invited",X.build=function(e,n,t,r){var i=e;return i.state=n,i.is_blocked_by_me=t,i.is_blocking_me=r,i},X.buildFromSerializedData=function(e){var n=C(e);return new X(X.build(Q.build(n.userId,n.nickname,n.profileUrl,n.connectionStatus,n.lastSeenAt,n.metaData,n.isActive,n.friendDiscoveryKey,n.friendName),n.state,n.isBlockedByMe,n.isBlockingMe))};var Z=function(e,n,t){this.isAckRequired=function(){return"MESG"===this.command||"FILE"===this.command||"ENTR"===this.command||"EXIT"===this.command||"READ"===this.command||"MEDI"===this.command||"FEDI"===this.command},this.encode=function(){return this.command+this.payload+"\n"},this.decode=function(e){e=e.trim(),this.command=e.substring(0,4),this.payload=e.substring(4)},this.getJsonElement=function(){return JSON.parse(this.payload)},this.isRequestIdCommand=function(){return this.isAckRequired()||"EROR"===this.command},this.command,this.payload,this.requestId;var r=this;if(0!==arguments.length){var i;switch(arguments.length){case 1:var a=arguments[0] -;if(!a||a.length<=4)return r.command="NOOP",void(r.payload="{}");if(a=a.trim(),r.command=a.substring(0,4),r.payload=a.substring(4),r.isRequestIdCommand()){var s=r.getJsonElement();s&&(r.requestId=s.hasOwnProperty("req_id")?s.req_id:"")}break;case 3:i=arguments[2];case 2:var o=arguments[0],l=arguments[1];i=i||"",r.command=o,r.requestId=i,r.requestId||r.isRequestIdCommand()&&(r.requestId=Z.generateRequestId()),l.req_id=r.requestId,r.payload=JSON.stringify(l)}}};Z.bMessage=function(e,n,t,r,i,a,s,o,l,u){var c={};return c.channel_url=e,c.message=n,c.data=t,i&&i.length>0&&(c.metaarray=i.map(function(e){return e.encode()})),a&&(c.mention_type=a),c.mentioned_user_ids=[],a===ve.MentionType.CHANNEL?c.mentioned_user_ids=[]:Array.isArray(s)&&s.length>0&&(c.mentioned_user_ids=s),r&&(c.custom_type=r),o.length>0&&(c.target_langs=o),l&&l!==Ne.PushNotificationDeliveryOption.DEFAULT&&(c.push_option=l),u?new Z("MESG",c,u):new Z("MESG",c)},Z.bRead=function(e){var n={};return n.channel_url=e,new Z("READ",n)},Z.bTypeStart=function(e,n){var t={};return t.channel_url=e,t.time=n,new Z("TPST",t)},Z.bTypeEnd=function(e,n){var t={};return t.channel_url=e,t.time=n,new Z("TPEN",t)},Z.bFile=function(e,n,t,r,i,a,s,o,l,u,c,d,h,p){var f={};return f.channel_url=n,f.url=t,f.name=r||"",f.type=i||"",f.size=a||0,f.custom=s,o&&(f.custom_type=o),l&&(f.thumbnails=l),u&&(f.require_auth=u),c&&c.length>0&&(f.metaarray=c.map(function(e){return e.encode()})),d&&(f.mention_type=d),f.mentioned_user_ids=[],d===ve.MentionType.CHANNEL?f.mentioned_user_ids=[]:Array.isArray(h)&&h.length>0&&(f.mentioned_user_ids=h),p&&p!==Ce.PushNotificationDeliveryOption.DEFAULT&&(f.push_option=p),new Z("FILE",f,e)},Z.bPing=function(){var e={};return e.id=(new Date).getTime(),e.active=1,new Z("PING",e)},Z.bEnter=function(e){var n={};return n.channel_url=e,new Z("ENTR",n)},Z.bExit=function(e){var n={};return n.channel_url=e,new Z("EXIT",n)},Z.bUpdateUserMessage=function(e,n,t,r,i,a,s,o){var l={};return l.channel_url=e,l.msg_id=n,null!=t&&t!==undefined&&(l.message=t),null!=r&&r!==undefined&&(l.data=r),null!=i&&i!==undefined&&(l.custom_type=i),a&&(l.mention_type=a),a===ve.MentionType.CHANNEL?l.mentioned_user_ids=[]:Array.isArray(s)&&s.length>0&&(l.mentioned_user_ids=s),o&&(l.metaarray=o),new Z("MEDI",l)},Z.bUpdateFileMessage=function(e,n,t,r,i,a,s){var o={};return o.channel_url=e,o.msg_id=n,null!=t&&t!==undefined&&(o.data=t),null!=r&&r!==undefined&&(o.custom_type=r),i&&(o.mention_type=i),i===ve.MentionType.CHANNEL?o.mentioned_user_ids=[]:Array.isArray(a)&&a.length>0&&(o.mentioned_user_ids=a),s&&(o.metaarray=s),new Z("FEDI",o)},Z.requestIdSeed=(new Date).getTime(),Z.generateRequestId=function(){return Z.requestIdSeed++,String(Z.requestIdSeed)};var $=function(e){this.isLoading=!1,this.hasNext=!0,this.limit=20;var n="",t=this;this.next=function(r){return t.hasNext?t.isLoading?void L(null,new y("Query in progress.",U.QUERY_IN_PROGRESS),r):"number"!=typeof t.limit||t.limit<1?void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),r):(t.isLoading=!0,void ge.getInstance().loadOperatorList(e.url,e.isOpenChannel(),n,t.limit,function(e,i){if(i)return t.isLoading=!1,void L(null,i,r);var a=e;(!(n=String(a.next))||n.length<=0)&&(t.hasNext=!1);var s=a.operators.map(function(e){return new Q(e)});t.isLoading=!1,L(s,null,r)})):void L([],null,r)}},ee=function(e){this.isLoading=!1,this.hasNext=!0,this.limit=20,this.mutedMemberFilter=ee.MUTED_MEMBER_FILTER.ALL,this.operatorFilter=ee.OPERATOR_FILTER.ALL,this.memberStateFilter=K.memberStateFilter.ALL,this.nicknameStartsWithFilter=null;var n=ee.Order.MEMBER_NICKNAME_ALPHABETICAL,t="",r=this;this.next=function(i){return r.hasNext?r.isLoading?void L(null,new y("Query in progress.",U.QUERY_IN_PROGRESS),i):"number"!=typeof r.limit||r.limit<1||"string"!=typeof r.mutedMemberFilter||[ee.MUTED_MEMBER_FILTER.ALL,ee.MUTED_MEMBER_FILTER.MUTED,ee.MUTED_MEMBER_FILTER.UNMUTED].indexOf(r.mutedMemberFilter.toLowerCase())<0||"string"!=typeof r.operatorFilter||[ee.OPERATOR_FILTER.ALL,ee.OPERATOR_FILTER.OPERATOR,ee.OPERATOR_FILTER.NONOPERATOR].indexOf(r.operatorFilter.toLowerCase())<0||"string"!=typeof r.memberStateFilter||[K.memberStateFilter.ALL,K.memberStateFilter.JOINED,K.memberStateFilter.INVITED,K.memberStateFilter.INVITED_BY_FRIEND,K.memberStateFilter.INVITED_BY_NON_FRIEND].indexOf(r.memberStateFilter.toLowerCase())<0||null!==r.nicknameStartsWithFilter&&"string"!=typeof r.nicknameStartsWithFilter?void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),i):(r.isLoading=!0,void ge.getInstance().loadGroupChannelMemberList(e,t,r.limit,r.mutedMemberFilter,r.operatorFilter,r.memberStateFilter,r.nicknameStartsWithFilter,n,function(e,n){if(n)return r.isLoading=!1,void L(null,n,i);var a=e;(!(t=String(a.next))||t.length<=0)&&(r.hasNext=!1);var s=a.members.map(function(e){return new X(e)});r.isLoading=!1,L(s,null,i)})):void L([],null,i)}};ee.MUTED_MEMBER_FILTER={ALL:"all",MUTED:"muted",UNMUTED:"unmuted"},ee.OPERATOR_FILTER={ALL:"all",OPERATOR:"operator",NONOPERATOR:"nonoperator"},ee.Order={MEMBER_NICKNAME_ALPHABETICAL:"member_nickname_alphabetical"};var ne=function(){this.isLoading=!1,this.hasNext=!0,this.limit=20,this.includeEmpty=!1,this.order=ne.ORDER_LATEST_LAST_MESSAGE,this.userIdsFilter=[],this.userIdsFilterExactMatch=!1,this.queryType=ne.QueryType.AND;var e={userIds:[],includeMode:!0,queryType:ne.QueryType.AND};this._userIdsExactFilter=[],this._userIdsIncludeFilter=[],this._userIdsIncludeFilterQueryType=ne.QueryType.AND,f?(this.userIdsExactFilter=this._userIdsExactFilter,this.userIdsIncludeFilter=this._userIdsIncludeFilter,this.userIdsIncludeFilterQueryType=this._userIdsIncludeFilterQueryType):(Object.defineProperty(this,"userIdsExactFilter",{get:function(){return this._userIdsExactFilter},set:function(n){Array.isArray(n)&&(this._userIdsExactFilter=n,this._userIdsIncludeFilter=[],e.userIds=this._userIdsExactFilter,e.includeMode=!1)}}),Object.defineProperty(this,"userIdsIncludeFilter",{get:function(){return this._userIdsIncludeFilter},set:function(n){Array.isArray(n)&&(this._userIdsIncludeFilter=n,this._userIdsExactFilter=[],e.userIds=this._userIdsIncludeFilter,e.includeMode=!0)}}),Object.defineProperty(this,"userIdsIncludeFilterQueryType",{get:function(){return this._userIdsIncludeFilterQueryType},set:function(n){[ne.QueryType.AND,ne.QueryType.OR].indexOf(n.toUpperCase())<0||(this._userIdsIncludeFilterQueryType=n.toUpperCase(),e.queryType=this._userIdsIncludeFilterQueryType)}})),this.nicknameContainsFilter="",this.channelNameContainsFilter="",this.memberStateFilter=K.memberStateFilter.ALL,this.customTypeFilter="",this.customTypesFilter=[],this.channelUrlsFilter=[],this.superChannelFilter=K.superChannelFilter.ALL,this.publicChannelFilter=K.publicChannelFilter.ALL,this.customTypeStartsWithFilter=null,this.unreadChannelFilter=K.UnreadChannelFilter.ALL,this.metadataOrderKeyFilter=null,this.hiddenChannelFilter=K.HiddenChannelFilter.UNHIDDEN,this._searchFilter={},this.setSearchFilter=function(e,n){Array.isArray(e)&&0!==e.length&&"string"==typeof n&&n&&(this._searchFilter.search_query=n,this._searchFilter.search_fields=e.join(",").toLowerCase())},this._token="";var n=this;this.serialize=function(){var e=JSON.parse(JSON.stringify(n));return e.isLoading=!1,N(e)},this.next=function(t){if(!n.hasNext)return void L([],null,t);if(n.isLoading)return void L(null,new y("Query in progress.",U.QUERY_IN_PROGRESS),t);if(null!==n.nicknameContainsFilter&&"undefined"!=typeof n.nicknameContainsFilter||(n.nicknameContainsFilter=""),null!==n.channelNameContainsFilter&&"undefined"!=typeof n.channelNameContainsFilter||(n.channelNameContainsFilter=""),null!==n.customTypeStartsWithFilter&&"string"!=typeof n.customTypeStartsWithFilter)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),t);if(!Array.isArray(n._userIdsExactFilter)||!Array.isArray(n._userIdsIncludeFilter)||"string"!=typeof n._userIdsIncludeFilterQueryType||[ne.QueryType.AND,ne.QueryType.OR].indexOf(n._userIdsIncludeFilterQueryType.toUpperCase())<0)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),t);if("number"==typeof n.memberStateFilter){if(typeof n.memberStateFilter<0||typeof n.memberStateFilter>4)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),t);var r=["all","joined_only","invited_only","invited_by_friend","invited_by_non_friend"];n.memberStateFilter=r[n.memberStateFilter]}if(!m(n.limit)||!Array.isArray(n.userIdsFilter)||"boolean"!=typeof n.includeEmpty||"boolean"!=typeof n.userIdsFilterExactMatch||"string"!=typeof n.customTypeFilter||!Array.isArray(n.customTypesFilter)||"string"!=typeof n.queryType||["AND","OR"].indexOf(n.queryType.toUpperCase())<0||"string"!=typeof n.order||[ne.ORDER_CHRONOLOGICAL,ne.ORDER_LATEST_LAST_MESSAGE,ne.CHANNEL_NAME_ALPHABETICAL,ne.METADATA_VALUE_ALPHABETICAL].indexOf(n.order.toLowerCase())<0||"string"!=typeof n.memberStateFilter||[K.memberStateFilter.ALL,K.memberStateFilter.JOINED,K.memberStateFilter.INVITED,K.memberStateFilter.INVITED_BY_FRIEND,K.memberStateFilter.INVITED_BY_NON_FRIEND].indexOf(n.memberStateFilter.toLowerCase())<0||"string"!=typeof n.nicknameContainsFilter||"string"!=typeof n.channelNameContainsFilter||!Array.isArray(n.channelUrlsFilter)||"string"!=typeof n.superChannelFilter||[K.superChannelFilter.ALL,K.superChannelFilter.SUPER,K.superChannelFilter.NON_SUPER].indexOf(n.superChannelFilter.toLowerCase())<0||"string"!=typeof n.publicChannelFilter||[K.publicChannelFilter.ALL,K.publicChannelFilter.PUBLIC,K.publicChannelFilter.PRIVATE].indexOf(n.publicChannelFilter.toLowerCase())<0||"string"!=typeof n.unreadChannelFilter||[K.UnreadChannelFilter.ALL,K.UnreadChannelFilter.UNREAD_MESSAGE].indexOf(n.unreadChannelFilter)<0||null!==n.metadataOrderKeyFilter&&"string"!=typeof n.metadataOrderKeyFilter||"string"!=typeof n.hiddenChannelFilter||[K.HiddenChannelFilter.UNHIDDEN,K.HiddenChannelFilter.HIDDEN,K.HiddenChannelFilter.HIDDEN_ALLOW_AUTO_UNHIDE,K.HiddenChannelFilter.HIDDEN_PREVENT_AUTO_UNHIDE].indexOf(n.hiddenChannelFilter)<0)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),t);Array.isArray(n.userIdsFilter)&&n.userIdsFilter.length>0&&(e={userIds:n.userIdsFilter,includeMode:!n.userIdsFilterExactMatch,queryType:n.queryType}),n.isLoading=!0,ge.getInstance().loadUserGroupChannelList(n._token,n.limit,n.includeEmpty,n.order,e,n.nicknameContainsFilter,n.channelNameContainsFilter,n.channelUrlsFilter,n.customTypeFilter,n.customTypesFilter,n.customTypeStartsWithFilter,n.memberStateFilter,n.superChannelFilter,n.publicChannelFilter,n.unreadChannelFilter,n.metadataOrderKeyFilter,n.hiddenChannelFilter,n._searchFilter,function(e,r){if(r)return n.isLoading=!1,void L(null,r,t);var i=e;n._token=String(i.next),(!n._token||n._token.length<=0)&&(n.hasNext=!1);for(var a=i.channels,s=[],o=0;o0&&(o.metaarray=e.metaArrayKeys),e.mentionType&&(o.mention_type=e._mentionType),e._mentionType===ve.MentionType.CHANNEL?o.mentioned_user_ids=[]:Array.isArray(e._mentionedIds)&&e._mentionedIds.length>0&&(o.mentioned_user_ids=e._mentionedIds),e.translationTargetLanguages&&e.translationTargetLanguages.length>0&&(o.translation_target_langs=e.translationTargetLanguages),e.pushNotificationDeliveryOption&&e.pushNotificationDeliveryOption!==ve.PushNotificationDeliveryOption.DEFAULT&&(o.push_option=e.pushNotificationDeliveryOption),i(s,o,t)},!0)},this.getMyGroupChannelChangeLogs=function(e,n,t,i,a){Te.getInstance().ConnectionManager.ready(function(s,o){if(o)return void a(null,o);var l=ge.API_USERS_USERID_MY_GROUP_CHANNEL_CHANGELOGS.replace("%s",encodeURIComponent(s.userId)),u={};n&&(u.token=n),e&&(u.change_ts=e),t&&t.length>0&&(u.custom_types=t),"boolean"==typeof i&&(u.show_empty=i),u.show_read_receipt=!0,u.show_member=!0,r(l,u,a)},!0)},this.getMessageChangeLogs=function(e,n,t,i,a,s){Te.getInstance().ConnectionManager.ready(function(o,l){if(l)return void s(null,l);var u="";u=e?ge.API_OPENCHANNELS_CHANNELURL_MESSAGES_CHANGELOGS.replace("%s",encodeURIComponent(n)):ge.API_GROUPCHANNELS_CHANNELURL_MESSAGES_CHANGELOGS.replace("%s",encodeURIComponent(n));var c={};i&&(c.token=i),t&&(c.change_ts=t),"boolean"==typeof a&&(c.with_sorted_meta_array=a),r(u,c,s)},!0)},this.getPushTokens=function(e,n,t,i){Te.getInstance().ConnectionManager.ready(function(a,s){if(s)return void i(null,s);var o=ge.API_USERS_USERID_PUSH_DEVICE_TOKENS.replace("%s",encodeURIComponent(a.userId)).replace("%s",encodeURIComponent(t)),l={};n&&(l.token=n),e&&(l.created_ts=e),r(o,l,i)},!0)},this.setChannelInvitationPreference=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,r){if(r)return void n(null,r);var i=ge.API_USERS_USERID_GROUP_CHANNEL_INVITATION_PREFERENCE.replace("%s",encodeURIComponent(t.userId));a(i,{auto_accept:e},n)},!0)},this.getChannelInvitationPreference=function(e){Te.getInstance().ConnectionManager.ready(function(n,t){if(t)return void e(null,t);var i=ge.API_USERS_USERID_GROUP_CHANNEL_INVITATION_PREFERENCE.replace("%s",encodeURIComponent(n.userId));r(i,e)},!0)},this.getGroupChannelCount=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,i){if(i)return void n(null,i);var a=ge.API_USERS_USERID_GROUP_CHANNEL_COUNT.replace("%s",encodeURIComponent(t.userId)),s="";s=e===K.memberState.JOINED?"joined":e===K.memberState.INVITED?"invited":e===K.memberState.INVITED_BY_FRIEND?"invited_by_friend":e===K.memberState.INVITED_BY_NON_FRIEND?"invited_by_non_friend":"all",r(a,{state:s},n)},!0)},this.getUnreadItemCount=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,i){if(i)return void n(null,i);var a=ge.API_USERS_USERID_UNREAD_ITEM_COUNT.replace("%s",encodeURIComponent(t.userId));r(a,{item_keys:e},n)},!0)},this.getTotalUnreadMessageCount=function(e,n,t){Te.getInstance().ConnectionManager.ready(function(i,a){if(a)return void t(null,a);var s=ge.API_USERS_USERID_UNREAD_MESSAGE_COUNT.replace("%s",encodeURIComponent(i.userId)),o={super_mode:n};null!==e&&e.length>0&&(o.custom_types=e),r(s,o,t)},!0)},this.getTotalUnreadChannelCount=function(e){Te.getInstance().ConnectionManager.ready(function(n,t){if(t)return void e(null,t);var i=ge.API_USERS_USERID_UNREAD_CHANNEL_COUNT.replace("%s",encodeURIComponent(n.userId));r(i,e)},!0)},this.getMyMutedInfo=function(e,n,t,i){Te.getInstance().ConnectionManager.ready(function(a,s){if(s)return void i(null,s);var o=e?ge.API_GROUPCHANNELS_CHANNELURL_MUTE_USERID.replace("%s",encodeURIComponent(n)).replace("%s",encodeURIComponent(t)):ge.API_OPENCHANNELS_CHANNELURL_MUTE_USERID.replace("%s",encodeURIComponent(n)).replace("%s",encodeURIComponent(t));r(o,i)},!0)},this.checkRouting=function(e){Te.getInstance()&&Te.getInstance().customApiHost&&Te.getInstance().customWsHost?"function"==typeof e&&e({API_HOST:Te.getInstance().customApiHost,WS_HOST:Te.getInstance().customWsHost}):e({API_HOST:ge.API_ROUTING_URL.replace("%s",M),WS_HOST:"wss://ws-%s.sendbird.com".replace("%s",M)},null)};var n=function(e,n,t,r,i,a,s,o,l){ge.getInstance().checkRouting(function(n,u){if(u)return void s(null,new y("Request failed.",U.REQUEST_FAILED));var c={file:t,fileType:r,channelUrl:a,thumbnailSizes:i};P.upload(n.API_HOST+e,c,l,o,s)})},t=function(e,n,t){"function"==typeof n&&(t=n,n={}),ge.getInstance().checkRouting(function(r,i){i?t(null,new y("Request failed.",U.REQUEST_FAILED)):P["delete"](r.API_HOST+e,n,t)})},r=function(e,n,t){"function"==typeof n&&(t=n,n={}),ge.getInstance().checkRouting(function(r,i){i?t(null,new y("Request failed.",U.REQUEST_FAILED)):P.get(r.API_HOST+e,n,t)})},i=function(e,n,t){"function"==typeof n&&(t=n,n={}),ge.getInstance().checkRouting(function(r,i){i?t(null,i):P.post(r.API_HOST+e,n,t)})},a=function(e,n,t){"function"==typeof n&&(t=n,n={}),ge.getInstance().checkRouting(function(r,i){i?t(null,i):P.put(r.API_HOST+e,n,t)})};this.addFriends=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,r){if(r)return void n(null,r);var a=ge.API_FRIENDS.replace("%s",encodeURIComponent(t.userId));i(a,{user_ids:e},n)},!0)},this.deleteFriends=function(e,n){Te.getInstance().ConnectionManager.ready(function(r,i){if(i)return void n(null,i);var a=ge.API_FRIENDS.replace("%s",encodeURIComponent(r.userId));t(a,{user_ids:e},n)},!0)},this.deleteFriendDiscoveries=function(e,n){Te.getInstance().ConnectionManager.ready(function(r,i){if(i)return void n(null,i);var a=ge.API_FRIENDS_DISCOVERIES.replace("%s",encodeURIComponent(r.userId));t(a,{friend_discovery_keys:e},n)},!0)},this.uploadFriendDiscoveries=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,r){if(r)return void n(null,r);var i=ge.API_FRIENDS_DISCOVERIES.replace("%s",encodeURIComponent(t.userId)),s={friend_discoveries:[]};e.forEach(function(e){s.friend_discoveries.push({ +;if(!a||a.length<=4)return r.command="NOOP",void(r.payload="{}");if(a=a.trim(),r.command=a.substring(0,4),r.payload=a.substring(4),r.isRequestIdCommand()){var s=r.getJsonElement();s&&(r.requestId=s.hasOwnProperty("req_id")?s.req_id:"")}break;case 3:i=arguments[2];case 2:var o=arguments[0],l=arguments[1];i=i||"",r.command=o,r.requestId=i,r.requestId||r.isRequestIdCommand()&&(r.requestId=Z.generateRequestId()),l.req_id=r.requestId,r.payload=JSON.stringify(l)}}};Z.bMessage=function(e,n,t,r,i,a,s,o,l,u){var c={};return c.channel_url=e,c.message=n,c.data=t,i&&i.length>0&&(c.metaarray=i.map(function(e){return e.encode()})),a&&(c.mention_type=a),c.mentioned_user_ids=[],a===ve.MentionType.CHANNEL?c.mentioned_user_ids=[]:Array.isArray(s)&&s.length>0&&(c.mentioned_user_ids=s),r&&(c.custom_type=r),o.length>0&&(c.target_langs=o),l&&l!==Ne.PushNotificationDeliveryOption.DEFAULT&&(c.push_option=l),u?new Z("MESG",c,u):new Z("MESG",c)},Z.bRead=function(e){var n={};return n.channel_url=e,new Z("READ",n)},Z.bTypeStart=function(e,n){var t={};return t.channel_url=e,t.time=n,new Z("TPST",t)},Z.bTypeEnd=function(e,n){var t={};return t.channel_url=e,t.time=n,new Z("TPEN",t)},Z.bFile=function(e,n,t,r,i,a,s,o,l,u,c,d,h,p){var f={};return f.channel_url=n,f.url=t,f.name=r||"",f.type=i||"",f.size=a||0,f.custom=s,o&&(f.custom_type=o),l&&(f.thumbnails=l),u&&(f.require_auth=u),c&&c.length>0&&(f.metaarray=c.map(function(e){return e.encode()})),d&&(f.mention_type=d),f.mentioned_user_ids=[],d===ve.MentionType.CHANNEL?f.mentioned_user_ids=[]:Array.isArray(h)&&h.length>0&&(f.mentioned_user_ids=h),p&&p!==Ce.PushNotificationDeliveryOption.DEFAULT&&(f.push_option=p),new Z("FILE",f,e)},Z.bPing=function(){var e={};return e.id=(new Date).getTime(),e.active=1,new Z("PING",e)},Z.bEnter=function(e){var n={};return n.channel_url=e,new Z("ENTR",n)},Z.bExit=function(e){var n={};return n.channel_url=e,new Z("EXIT",n)},Z.bUpdateUserMessage=function(e,n,t,r,i,a,s,o){var l={};return l.channel_url=e,l.msg_id=n,null!=t&&t!==undefined&&(l.message=t),null!=r&&r!==undefined&&(l.data=r),null!=i&&i!==undefined&&(l.custom_type=i),a&&(l.mention_type=a),a===ve.MentionType.CHANNEL?l.mentioned_user_ids=[]:Array.isArray(s)&&s.length>0&&(l.mentioned_user_ids=s),o&&(l.metaarray=o),new Z("MEDI",l)},Z.bUpdateFileMessage=function(e,n,t,r,i,a,s){var o={};return o.channel_url=e,o.msg_id=n,null!=t&&t!==undefined&&(o.data=t),null!=r&&r!==undefined&&(o.custom_type=r),i&&(o.mention_type=i),i===ve.MentionType.CHANNEL?o.mentioned_user_ids=[]:Array.isArray(a)&&a.length>0&&(o.mentioned_user_ids=a),s&&(o.metaarray=s),new Z("FEDI",o)},Z.requestIdSeed=(new Date).getTime(),Z.generateRequestId=function(){return Z.requestIdSeed++,String(Z.requestIdSeed)};var $=function(e){this.isLoading=!1,this.hasNext=!0,this.limit=20;var n="",t=this;this.next=function(r){return t.hasNext?t.isLoading?void L(null,new y("Query in progress.",U.QUERY_IN_PROGRESS),r):"number"!=typeof t.limit||t.limit<1?void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),r):(t.isLoading=!0,void ge.getInstance().loadOperatorList(e.url,e.isOpenChannel(),n,t.limit,function(e,i){if(i)return t.isLoading=!1,void L(null,i,r);var a=e;(!(n=String(a.next))||n.length<=0)&&(t.hasNext=!1);var s=a.operators.map(function(e){return new Q(e)});t.isLoading=!1,L(s,null,r)})):void L([],null,r)}},ee=function(e){this.isLoading=!1,this.hasNext=!0,this.limit=20,this.mutedMemberFilter=ee.MUTED_MEMBER_FILTER.ALL,this.operatorFilter=ee.OPERATOR_FILTER.ALL,this.memberStateFilter=K.memberStateFilter.ALL,this.nicknameStartsWithFilter=null;var n=ee.Order.MEMBER_NICKNAME_ALPHABETICAL,t="",r=this;this.next=function(i){return r.hasNext?r.isLoading?void L(null,new y("Query in progress.",U.QUERY_IN_PROGRESS),i):"number"!=typeof r.limit||r.limit<1||"string"!=typeof r.mutedMemberFilter||[ee.MUTED_MEMBER_FILTER.ALL,ee.MUTED_MEMBER_FILTER.MUTED,ee.MUTED_MEMBER_FILTER.UNMUTED].indexOf(r.mutedMemberFilter.toLowerCase())<0||"string"!=typeof r.operatorFilter||[ee.OPERATOR_FILTER.ALL,ee.OPERATOR_FILTER.OPERATOR,ee.OPERATOR_FILTER.NONOPERATOR].indexOf(r.operatorFilter.toLowerCase())<0||"string"!=typeof r.memberStateFilter||[K.memberStateFilter.ALL,K.memberStateFilter.JOINED,K.memberStateFilter.INVITED,K.memberStateFilter.INVITED_BY_FRIEND,K.memberStateFilter.INVITED_BY_NON_FRIEND].indexOf(r.memberStateFilter.toLowerCase())<0||null!==r.nicknameStartsWithFilter&&"string"!=typeof r.nicknameStartsWithFilter?void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),i):(r.isLoading=!0,void ge.getInstance().loadGroupChannelMemberList(e,t,r.limit,r.mutedMemberFilter,r.operatorFilter,r.memberStateFilter,r.nicknameStartsWithFilter,n,function(e,n){if(n)return r.isLoading=!1,void L(null,n,i);var a=e;(!(t=String(a.next))||t.length<=0)&&(r.hasNext=!1);var s=a.members.map(function(e){return new X(e)});r.isLoading=!1,L(s,null,i)})):void L([],null,i)}};ee.MUTED_MEMBER_FILTER={ALL:"all",MUTED:"muted",UNMUTED:"unmuted"},ee.OPERATOR_FILTER={ALL:"all",OPERATOR:"operator",NONOPERATOR:"nonoperator"},ee.Order={MEMBER_NICKNAME_ALPHABETICAL:"member_nickname_alphabetical"};var ne=function(){this.isLoading=!1,this.hasNext=!0,this.limit=20,this.includeEmpty=!1,this.order=ne.ORDER_LATEST_LAST_MESSAGE,this.userIdsFilter=[],this.userIdsFilterExactMatch=!1,this.queryType=ne.QueryType.AND;var e={userIds:[],includeMode:!0,queryType:ne.QueryType.AND};this._userIdsExactFilter=[],this._userIdsIncludeFilter=[],this._userIdsIncludeFilterQueryType=ne.QueryType.AND,f?(this.userIdsExactFilter=this._userIdsExactFilter,this.userIdsIncludeFilter=this._userIdsIncludeFilter,this.userIdsIncludeFilterQueryType=this._userIdsIncludeFilterQueryType):(Object.defineProperty(this,"userIdsExactFilter",{get:function(){return this._userIdsExactFilter},set:function(n){Array.isArray(n)&&(this._userIdsExactFilter=n,this._userIdsIncludeFilter=[],e.userIds=this._userIdsExactFilter,e.includeMode=!1)}}),Object.defineProperty(this,"userIdsIncludeFilter",{get:function(){return this._userIdsIncludeFilter},set:function(n){Array.isArray(n)&&(this._userIdsIncludeFilter=n,this._userIdsExactFilter=[],e.userIds=this._userIdsIncludeFilter,e.includeMode=!0)}}),Object.defineProperty(this,"userIdsIncludeFilterQueryType",{get:function(){return this._userIdsIncludeFilterQueryType},set:function(n){[ne.QueryType.AND,ne.QueryType.OR].indexOf(n.toUpperCase())<0||(this._userIdsIncludeFilterQueryType=n.toUpperCase(),e.queryType=this._userIdsIncludeFilterQueryType)}})),this.nicknameContainsFilter="",this.channelNameContainsFilter="",this.memberStateFilter=K.memberStateFilter.ALL,this.customTypeFilter="",this.customTypesFilter=[],this.channelUrlsFilter=[],this.superChannelFilter=K.superChannelFilter.ALL,this.publicChannelFilter=K.publicChannelFilter.ALL,this.customTypeStartsWithFilter=null,this.unreadChannelFilter=K.UnreadChannelFilter.ALL,this.metadataOrderKeyFilter=null,this.hiddenChannelFilter=K.HiddenChannelFilter.UNHIDDEN,this._searchFilter={},this.setSearchFilter=function(e,n){Array.isArray(e)&&0!==e.length&&"string"==typeof n&&n&&(this._searchFilter.search_query=n,this._searchFilter.search_fields=e.join(",").toLowerCase())},this._token="";var n=this;this.serialize=function(){var e=JSON.parse(JSON.stringify(n));return e.isLoading=!1,N(e)},this.next=function(t){if(!n.hasNext)return void L([],null,t);if(n.isLoading)return void L(null,new y("Query in progress.",U.QUERY_IN_PROGRESS),t);if(null!==n.nicknameContainsFilter&&"undefined"!=typeof n.nicknameContainsFilter||(n.nicknameContainsFilter=""),null!==n.channelNameContainsFilter&&"undefined"!=typeof n.channelNameContainsFilter||(n.channelNameContainsFilter=""),null!==n.customTypeStartsWithFilter&&"string"!=typeof n.customTypeStartsWithFilter)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),t);if(!Array.isArray(n._userIdsExactFilter)||!Array.isArray(n._userIdsIncludeFilter)||"string"!=typeof n._userIdsIncludeFilterQueryType||[ne.QueryType.AND,ne.QueryType.OR].indexOf(n._userIdsIncludeFilterQueryType.toUpperCase())<0)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),t);if("number"==typeof n.memberStateFilter){if(typeof n.memberStateFilter<0||typeof n.memberStateFilter>4)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),t);var r=["all","joined_only","invited_only","invited_by_friend","invited_by_non_friend"];n.memberStateFilter=r[n.memberStateFilter]}if(!m(n.limit)||!Array.isArray(n.userIdsFilter)||"boolean"!=typeof n.includeEmpty||"boolean"!=typeof n.userIdsFilterExactMatch||"string"!=typeof n.customTypeFilter||!Array.isArray(n.customTypesFilter)||"string"!=typeof n.queryType||["AND","OR"].indexOf(n.queryType.toUpperCase())<0||"string"!=typeof n.order||[ne.ORDER_CHRONOLOGICAL,ne.ORDER_LATEST_LAST_MESSAGE,ne.CHANNEL_NAME_ALPHABETICAL,ne.METADATA_VALUE_ALPHABETICAL].indexOf(n.order.toLowerCase())<0||"string"!=typeof n.memberStateFilter||[K.memberStateFilter.ALL,K.memberStateFilter.JOINED,K.memberStateFilter.INVITED,K.memberStateFilter.INVITED_BY_FRIEND,K.memberStateFilter.INVITED_BY_NON_FRIEND].indexOf(n.memberStateFilter.toLowerCase())<0||"string"!=typeof n.nicknameContainsFilter||"string"!=typeof n.channelNameContainsFilter||!Array.isArray(n.channelUrlsFilter)||"string"!=typeof n.superChannelFilter||[K.superChannelFilter.ALL,K.superChannelFilter.SUPER,K.superChannelFilter.NON_SUPER].indexOf(n.superChannelFilter.toLowerCase())<0||"string"!=typeof n.publicChannelFilter||[K.publicChannelFilter.ALL,K.publicChannelFilter.PUBLIC,K.publicChannelFilter.PRIVATE].indexOf(n.publicChannelFilter.toLowerCase())<0||"string"!=typeof n.unreadChannelFilter||[K.UnreadChannelFilter.ALL,K.UnreadChannelFilter.UNREAD_MESSAGE].indexOf(n.unreadChannelFilter)<0||null!==n.metadataOrderKeyFilter&&"string"!=typeof n.metadataOrderKeyFilter||"string"!=typeof n.hiddenChannelFilter||[K.HiddenChannelFilter.UNHIDDEN,K.HiddenChannelFilter.HIDDEN,K.HiddenChannelFilter.HIDDEN_ALLOW_AUTO_UNHIDE,K.HiddenChannelFilter.HIDDEN_PREVENT_AUTO_UNHIDE].indexOf(n.hiddenChannelFilter)<0)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),t);Array.isArray(n.userIdsFilter)&&n.userIdsFilter.length>0&&(e={userIds:n.userIdsFilter,includeMode:!n.userIdsFilterExactMatch,queryType:n.queryType}),n.isLoading=!0,ge.getInstance().loadUserGroupChannelList(n._token,n.limit,n.includeEmpty,n.order,e,n.nicknameContainsFilter,n.channelNameContainsFilter,n.channelUrlsFilter,n.customTypeFilter,n.customTypesFilter,n.customTypeStartsWithFilter,n.memberStateFilter,n.superChannelFilter,n.publicChannelFilter,n.unreadChannelFilter,n.metadataOrderKeyFilter,n.hiddenChannelFilter,n._searchFilter,function(e,r){if(r)return n.isLoading=!1,void L(null,r,t);var i=e;n._token=String(i.next),(!n._token||n._token.length<=0)&&(n.hasNext=!1);for(var a=i.channels,s=[],o=0;o0&&(o.metaarray=e.metaArrayKeys),e.mentionType&&(o.mention_type=e._mentionType),e._mentionType===ve.MentionType.CHANNEL?o.mentioned_user_ids=[]:Array.isArray(e._mentionedIds)&&e._mentionedIds.length>0&&(o.mentioned_user_ids=e._mentionedIds),e.translationTargetLanguages&&e.translationTargetLanguages.length>0&&(o.translation_target_langs=e.translationTargetLanguages),e.pushNotificationDeliveryOption&&e.pushNotificationDeliveryOption!==ve.PushNotificationDeliveryOption.DEFAULT&&(o.push_option=e.pushNotificationDeliveryOption),i(s,o,t)},!0)},this.getMyGroupChannelChangeLogs=function(e,n,t,i,a){Te.getInstance().ConnectionManager.ready(function(s,o){if(o)return void a(null,o);var l=ge.API_USERS_USERID_MY_GROUP_CHANNEL_CHANGELOGS.replace("%s",encodeURIComponent(s.userId)),u={};n&&(u.token=n),e&&(u.change_ts=e),t&&t.length>0&&(u.custom_types=t),"boolean"==typeof i&&(u.show_empty=i),u.show_read_receipt=!0,u.show_member=!0,r(l,u,a)},!0)},this.getMessageChangeLogs=function(e,n,t,i,a,s){Te.getInstance().ConnectionManager.ready(function(o,l){if(l)return void s(null,l);var u="";u=e?ge.API_OPENCHANNELS_CHANNELURL_MESSAGES_CHANGELOGS.replace("%s",encodeURIComponent(n)):ge.API_GROUPCHANNELS_CHANNELURL_MESSAGES_CHANGELOGS.replace("%s",encodeURIComponent(n));var c={};i&&(c.token=i),t&&(c.change_ts=t),"boolean"==typeof a&&(c.with_sorted_meta_array=a),r(u,c,s)},!0)},this.getPushTokens=function(e,n,t,i){Te.getInstance().ConnectionManager.ready(function(a,s){if(s)return void i(null,s);var o=ge.API_USERS_USERID_PUSH_DEVICE_TOKENS.replace("%s",encodeURIComponent(a.userId)).replace("%s",encodeURIComponent(t)),l={};n&&(l.token=n),e&&(l.created_ts=e),r(o,l,i)},!0)},this.setChannelInvitationPreference=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,r){if(r)return void n(null,r);var i=ge.API_USERS_USERID_GROUP_CHANNEL_INVITATION_PREFERENCE.replace("%s",encodeURIComponent(t.userId));a(i,{auto_accept:e},n)},!0)},this.getChannelInvitationPreference=function(e){Te.getInstance().ConnectionManager.ready(function(n,t){if(t)return void e(null,t);var i=ge.API_USERS_USERID_GROUP_CHANNEL_INVITATION_PREFERENCE.replace("%s",encodeURIComponent(n.userId));r(i,e)},!0)},this.getGroupChannelCount=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,i){if(i)return void n(null,i);var a=ge.API_USERS_USERID_GROUP_CHANNEL_COUNT.replace("%s",encodeURIComponent(t.userId)),s="";s=e===K.memberState.JOINED?"joined":e===K.memberState.INVITED?"invited":e===K.memberState.INVITED_BY_FRIEND?"invited_by_friend":e===K.memberState.INVITED_BY_NON_FRIEND?"invited_by_non_friend":"all",r(a,{state:s},n)},!0)},this.getUnreadItemCount=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,i){if(i)return void n(null,i);var a=ge.API_USERS_USERID_UNREAD_ITEM_COUNT.replace("%s",encodeURIComponent(t.userId));r(a,{item_keys:e},n)},!0)},this.getTotalUnreadMessageCount=function(e,n,t){Te.getInstance().ConnectionManager.ready(function(i,a){if(a)return void t(null,a);var s=ge.API_USERS_USERID_UNREAD_MESSAGE_COUNT.replace("%s",encodeURIComponent(i.userId)),o={super_mode:n};null!==e&&e.length>0&&(o.custom_types=e),r(s,o,t)},!0)},this.getTotalUnreadChannelCount=function(e){Te.getInstance().ConnectionManager.ready(function(n,t){if(t)return void e(null,t);var i=ge.API_USERS_USERID_UNREAD_CHANNEL_COUNT.replace("%s",encodeURIComponent(n.userId));r(i,e)},!0)},this.getMyMutedInfo=function(e,n,t,i){Te.getInstance().ConnectionManager.ready(function(a,s){if(s)return void i(null,s);var o=e?ge.API_GROUPCHANNELS_CHANNELURL_MUTE_USERID.replace("%s",encodeURIComponent(n)).replace("%s",encodeURIComponent(t)):ge.API_OPENCHANNELS_CHANNELURL_MUTE_USERID.replace("%s",encodeURIComponent(n)).replace("%s",encodeURIComponent(t));r(o,i)},!0)},this.checkRouting=function(e){Te.getInstance()&&Te.getInstance().customApiHost&&Te.getInstance().customWsHost?"function"==typeof e&&e({API_HOST:Te.getInstance().customApiHost,WS_HOST:Te.getInstance().customWsHost}):e({API_HOST:ge.API_ROUTING_URL.replace("%s",M),WS_HOST:"wss://ws-%s.sendbird.com".replace("%s",M)},null)};var n=function(e,n,t,r,i,a,s,o,l){ge.getInstance().checkRouting(function(n,u){if(u)return void s(null,new y("Request failed.",U.REQUEST_FAILED));var c={file:t,fileType:r,channelUrl:a,thumbnailSizes:i};P.upload(n.API_HOST+e,c,l,o,s)})},t=function(e,n,t){"function"==typeof n&&(t=n,n={}),ge.getInstance().checkRouting(function(r,i){i?t(null,new y("Request failed.",U.REQUEST_FAILED)):P["delete"](r.API_HOST+e,n,t)})},r=function(e,n,t){"function"==typeof n&&(t=n,n={}),ge.getInstance().checkRouting(function(r,i){i?t(null,new y("Request failed.",U.REQUEST_FAILED)):P.get(r.API_HOST+e,n,t)})},i=function(e,n,t){"function"==typeof n&&(t=n,n={}),ge.getInstance().checkRouting(function(r,i){i?t(null,i):P.post(r.API_HOST+e,n,t)})},a=function(e,n,t){"function"==typeof n&&(t=n,n={}),ge.getInstance().checkRouting(function(r,i){i?t(null,i):P.put(r.API_HOST+e,n,t)})};this.addFriends=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,r){if(r)return void n(null,r);var a=ge.API_FRIENDS.replace("%s",encodeURIComponent(t.userId));i(a,{user_ids:e},n)},!0)},this.deleteFriends=function(e,n){Te.getInstance().ConnectionManager.ready(function(r,i){if(i)return void n(null,i);var a=ge.API_FRIENDS.replace("%s",encodeURIComponent(r.userId));t(a,{user_ids:e},n)},!0)},this.deleteFriendDiscoveries=function(e,n){Te.getInstance().ConnectionManager.ready(function(r,i){if(i)return void n(null,i);var a=ge.API_FRIENDS_DISCOVERIES.replace("%s",encodeURIComponent(r.userId));t(a,{friend_discovery_keys:e},n)},!0)},this.uploadFriendDiscoveries=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,r){if(r)return void n(null,r);var i=ge.API_FRIENDS_DISCOVERIES.replace("%s",encodeURIComponent(t.userId)),s={friend_discoveries:[]};e.forEach(function(e){s.friend_discoveries.push({ friend_discovery_key:e.friendDiscoveryKey,friend_name:"string"==typeof e.friendName||e.friendName?e.friendName:null})}),a(i,s,n)},!0)},this.getFriendChangeLogsByToken=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,i){if(i)return void n(null,i);var a=ge.API_FRIENDS_CHANGE_LOGS.replace("%s",encodeURIComponent(t.userId)),s={};e&&(s.token=e),r(a,s,n)},!0)},this.friendListQuery=function(e,n,t){Te.getInstance().ConnectionManager.ready(function(i,a){if(a)return void t(null,a);var s=ge.API_FRIENDS.replace("%s",encodeURIComponent(i.userId));r(s,{limit:n,token:e},t)},!0)},this.createUserMetaData=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,r){if(r)return void n(null,r);var a=ge.API_USERS_USERID_METADATA.replace("%s",encodeURIComponent(t.userId)),s={};s.metadata=e,i(a,s,n)},!0)},this.updateUserMetaData=function(e,n,t){Te.getInstance().ConnectionManager.ready(function(r,i){if(i)return void t(null,i);var s=ge.API_USERS_USERID_METADATA.replace("%s",encodeURIComponent(r.userId)),o={};o.metadata=e,o.upsert=n,a(s,o,t)},!0)},this.deleteAllUserMetaData=function(e){Te.getInstance().ConnectionManager.ready(function(n,r){if(r)return void e(null,r);var i=ge.API_USERS_USERID_METADATA.replace("%s",encodeURIComponent(n.userId));t(i,{},e)},!0)},this.deleteUserMetaData=function(e,n){Te.getInstance().ConnectionManager.ready(function(r,i){if(i)return void n(null,i);var a=ge.API_USERS_USERID_METADATA_KEY.replace("%s",encodeURIComponent(r.userId)).replace("%s",encodeURIComponent(e));t(a,{},n)},!0)},this.resetMyHistory=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,r){if(r)return void n(null,r);var i=ge.API_GROUPCHANNELS_RESET_USER_HISTORY.replace("%s",encodeURIComponent(e));a(i,{},n)},!0)},this.groupChannelInvite=function(e,n,t){Te.getInstance().ConnectionManager.ready(function(r,a){if(a)return void t(null,a);var s=ge.API_GROUPCHANNELS_CHANNELURL_INVITE.replace("%s",encodeURIComponent(e)),o={},l=[];try{Array.isArray(n)?l=n:l.push(n)}catch(e){t(null,new y("Invalid parameter.",U.INVALID_PARAMETER))}o.user_ids=l,i(s,o,t)},!0)},this.acceptInvitation=function(e,n,t){Te.getInstance().ConnectionManager.ready(function(r,i){if(i)return void t(null,i);var s=ge.API_GROUPCHANNELS_CHANNELURL_ACCEPT_INVITATION.replace("%s",encodeURIComponent(e)),o={};o.user_id=r.userId,n&&(o.access_code=n),a(s,o,t)},!0)},this.declineInvitation=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,r){if(r)return void n(null,r);var i=ge.API_GROUPCHANNELS_CHANNELURL_DECLINE_INVITATION.replace("%s",encodeURIComponent(e)),s={};s.user_id=t.userId,a(i,s,n)},!0)},this.groupChannelHide=function(e,n,t,r){Te.getInstance().ConnectionManager.ready(function(i,s){if(s)return void r(null,s);var o=ge.API_GROUPCHANNELS_CHANNELURL_HIDE.replace("%s",encodeURIComponent(e)),l={user_id:i.userId,hide_previous_messages:n,allow_auto_unhide:t};a(o,l,r)},!0)},this.groupChannelUnhide=function(e,n){Te.getInstance().ConnectionManager.ready(function(r,i){if(i)return void n(null,i);var a=ge.API_GROUPCHANNELS_CHANNELURL_HIDE.replace("%s",encodeURIComponent(e));t(a,{},n)},!0)},this.publicGroupChannelJoin=function(e,n,t){Te.getInstance().ConnectionManager.ready(function(r,i){if(i)return void t(null,i);var s=ge.API_GROUPCHANNELS_CHANNELURL_JOIN.replace("%s",encodeURIComponent(e)),o={};o.user_id=r.userId,n&&(o.access_code=n),a(s,o,t)},!0)},this.groupChannelLeave=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,r){if(r)return void n(null,r);var i=ge.API_GROUPCHANNELS_CHANNELURL_LEAVE.replace("%s",encodeURIComponent(e)),s={};s.user_id=t.userId,a(i,s,n)},!0)},this.groupChannelMarkAsRead=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,r){if(r)return void n(null,r);var i=ge.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MARKASREAD.replace("%s",encodeURIComponent(e)),s={};s.user_id=t.userId,a(i,s,n)},!0)},this.groupChannelMarkAsReadAll=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,r){if(r)return void n(null,r);var i=ge.API_USERS_USERID_MARKASREADALL.replace("%s",encodeURIComponent(t.userId)),s={};e&&(s.channel_urls=e),a(i,s,n)},!0)},this.messageList=function(e,n,t,i,a,s,o,l,u,c,d,h){Te.getInstance().ConnectionManager.ready(function(p,f){if(f)return void h(null,f);var _;_=e?String(ge.API_OPENCHANNELS_CHANNELURL_MESSAGES.replace("%s",n)):String(ge.API_GROUPCHANNELS_CHANNELURL_MESSAGES.replace("%s",n));var I={};I.is_sdk=String(!0),I.message_ts=String(t),I.prev_limit=String(i),I.next_limit=String(a),I.include=String(s),I.reverse=String(o),l&&(I.message_type=String(l)),u&&(I.custom_type=String(u)),c.length>0&&(I.sender_ids=c),"boolean"==typeof d&&(I.with_sorted_meta_array=d),r(_,I,h)},!0)},this.messageListByID=function(e,n,t,i,a,s,o,l,u,c,d,h){Te.getInstance().ConnectionManager.ready(function(p,f){if(f)return void h(null,f);var _;_=e?String(ge.API_OPENCHANNELS_CHANNELURL_MESSAGES.replace("%s",n)):String(ge.API_GROUPCHANNELS_CHANNELURL_MESSAGES.replace("%s",n));var I={};I.is_sdk=String(!0),I.message_id=t,I.prev_limit=String(i),I.next_limit=String(a),I.include=String(s),I.reverse=String(o),l&&(I.message_type=String(l)),u&&(I.custom_type=String(u)),c.length>0&&(I.sender_ids=c),"boolean"==typeof d&&(I.with_sorted_meta_array=d),r(_,I,h)},!0)},this.updateUserInfo=function(e,n,t){Te.getInstance().ConnectionManager.ready(function(r,i){if(i)return void t(null,i);var s={};e&&(s.nickname=e),n&&(s.profile_url=n);var o=String(ge.API_USERS_USERID).replace("%s",encodeURIComponent(r.userId));a(o,s,t)},!0)},this.updateCurrentUserInfoWithFile=function(e,n,t){var r=this;Te.getInstance().ConnectionManager.ready(function(i,s){if(s)return void t(null,s);if("string"==typeof n)r.updateUserInfo(i.userId,e,n,t);else{var o=u?new u:new FormData;o.append("nickname",e),o.append("profile_file",n,n.name);var l=String(ge.API_USERS_USERID).replace("%s",encodeURIComponent(i.userId));a(l,o,t)}},!0)},this.getGroupChannel=function(e,n,t,i){Te.getInstance().ConnectionManager.ready(function(a,s){if(s)return void i(null,s);var o=ge.API_GROUPCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)),l={member:String(n),read_receipt:String(t)};r(o,l,i)},!0)},this.getOpenChannel=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,i){if(i)return void n(null,i);var a=ge.API_OPENCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e));r(a,n)},!0)},this.createGroupChannel=function(e,n,t,r,a,s,o,l,c,d,h,p){Te.getInstance().ConnectionManager.ready(function(f,_){if(_)return void p(null,_);var I=ge.API_GROUPCHANNELS,g=[];"string"==typeof e?g.push(e):e.forEach(function(e){g.push(e)}),g.push(f.userId);var m,E=g.filter(function(e,n){return g.indexOf(e)===n}),A=l.isPublic,y=l.channelUrl,v=l.isDiscoverable,N=l.isStrict;r&&"string"!=typeof r?(m=u?new u:new FormData,r&&m.append("cover_file",r,r.name),m.append("user_ids",E),null!==y&&m.append("channel_url",y),null!==n&&m.append("is_distinct",n),null!==o&&m.append("is_super",o),null!==A&&m.append("is_public",A),null!==v&&m.append("is_discoverable",v),null!==N&&m.append("strict",N),null!==d&&m.append("is_ephemeral",d),h&&m.append("access_code",h),null!==t&&"string"==typeof t&&m.append("name",t),a&&m.append("data",a),s&&m.append("custom_type",s),Array.isArray(c)&&c.length>0&&m.append("operator_ids",c)):(m={},null!==r&&"string"==typeof r&&(m.cover_url=r),m.user_ids=E,null!==y&&(m.channel_url=y),null!==n&&(m.is_distinct=n),null!==o&&(m.is_super=o),null!==A&&(m.is_public=A),null!==v&&(m.is_discoverable=v),null!==N&&(m.strict=N),null!==d&&(m.is_ephemeral=d),h&&(m.access_code=h),null!==t&&"string"==typeof t&&(m.name=t),a&&(m.data=a),s&&(m.custom_type=s),Array.isArray(c)&&c.length>0&&(m.operator_ids=c)),i(I,m,p)},!0)},this.createOpenChannel=function(e,n,t,r,a,s){Te.getInstance().ConnectionManager.ready(function(o,l){if(l)return void s(null,l);var c,d=String(ge.API_OPENCHANNELS);n&&"string"!=typeof n?(c=u?new u:new FormData,n&&c.append("cover_file",n,n.name),null!==e&&"string"==typeof e&&c.append("name",e),t&&c.append("data",t),r&&(Array.isArray(r)?c.append("operators",r):c.append("operators",[r])),a&&c.append("custom_type",a)):(c={},null!==n&&"string"==typeof n&&(c.cover_url=n),null!==e&&"string"==typeof e&&(c.name=e),t&&(c.data=t),r&&(Array.isArray(r)?c.operators=r:c.operators=[r]),a&&(c.custom_type=a)),i(d,c,s)},!0)},this.updateGroupChannel=function(e,n,t,r,i,s,o,l,c,d){Te.getInstance().ConnectionManager.ready(function(h,p){if(p)return void d(null,p);var f,_=String(ge.API_GROUPCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)));r&&"string"!=typeof r?(f=u?new u:new FormData,null!==n&&f.append("is_distinct",n),null!==o&&f.append("is_public",o),null!==l&&f.append("access_code",l),null!==c&&f.append("is_discoverable",c),r&&f.append("cover_file",r,r.name),null!==t&&"string"==typeof t&&f.append("name",t),null!==i&&"string"==typeof i&&f.append("data",i),null!==s&&"string"==typeof s&&f.append("custom_type",s)):(f={},null!==n&&(f.is_distinct=n),null!==o&&(f.is_public=o),null!==c&&(f.is_discoverable=c),null!==l&&(f.access_code=l),null!==r&&"string"==typeof r&&(f.cover_url=r),null!==t&&"string"==typeof t&&(f.name=t),null!==i&&"string"==typeof i&&(f.data=i),null!==s&&"string"==typeof s&&(f.custom_type=s)),a(_,f,d)},!0)},this.deleteGroupChannel=function(e,n){Te.getInstance().ConnectionManager.ready(function(r,i){if(i)return void n(null,i);var a=String(ge.API_GROUPCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)));t(a,{},n)},!0)},this.updateOpenChannel=function(e,n,t,r,i,s,o){Te.getInstance().ConnectionManager.ready(function(l,c){if(c)return void o(null,c);var d,h=String(ge.API_OPENCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)));t&&"string"!=typeof t?(d=u?new u:new FormData,t&&d.append("cover_file",t,t.name),null!==n&&"string"==typeof n&&d.append("name",n),null!==r&&"string"==typeof r&&d.append("data",r),null!==i&&(Array.isArray(i)?d.append("operators",i):d.append("operators",[i])),null!==s&&"string"==typeof s&&d.append("custom_type",s)):(d={},null!==t&&"string"==typeof t&&(d.cover_url=t),null!==n&&"string"==typeof n&&(d.name=n),null!==r&&"string"==typeof r&&(d.data=r),null!==i&&(Array.isArray(i)?d.operators=i:d.operators=[i]),null!==s&&"string"==typeof s&&(d.custom_type=s)),a(h,d,o)},!0)},this.deleteOpenChannel=function(e,n){Te.getInstance().ConnectionManager.ready(function(r,i){if(i)return void n(null,i);var a=String(ge.API_OPENCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)));t(a,{},n)},!0)},this.createMetaCounters=function(e,n,t,r){Te.getInstance().ConnectionManager.ready(function(a,s){if(s)return void r(null,s);var o;o=e?ge.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):ge.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n));var l={};l.metacounter=t,i(o,l,r)},!0)},this.updateMetaCounters=function(e,n,t,r,i,s){Te.getInstance().ConnectionManager.ready(function(o,l){if(l)return void s(null,l);var u;u=e?ge.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):ge.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n));var c={};switch(c.metacounter=t,c.upsert=r,i){case ge.UPDATE_META_COUNTER_MODE_SET:c.mode="set";break;case ge.UPDATE_META_COUNTER_MODE_INC:c.mode="increase";break;case ge.UPDATE_META_COUNTER_MODE_DEC:c.mode="decrease"}a(u,c,s)},!0)},this.getAllMetaCounters=function(e,n,t){this.getMetaCounters(e,n,[],t)},this.getMetaCounters=function(e,n,t,i){Te.getInstance().ConnectionManager.ready(function(a,s){if(s)return void i(null,s);var o;o=e?ge.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):ge.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)),r(o,{keys:t},i)},!0)},this.deleteMetaCounter=function(e,n,r,i){Te.getInstance().ConnectionManager.ready(function(a,s){if(s)return void i(null,s);var o="";o=e?ge.API_OPENCHANNELS_CHANNELURL_METACOUNTER_KEY.replace("%s",encodeURIComponent(n)).replace("%s",r):ge.API_GROUPCHANNELS_CHANNELURL_METACOUNTER_KEY.replace("%s",encodeURIComponent(n)).replace("%s",r),t(o,{},i)},!0)},this.deleteAllMetaCounters=function(e,n,r){Te.getInstance().ConnectionManager.ready(function(i,a){if(a)return void r(null,a);var s="";s=e?ge.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):ge.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)),t(s,{},r)},!0)},this.createMetaData=function(e,n,t,r){Te.getInstance().ConnectionManager.ready(function(a,s){if(s)return void r(null,s);var o="";o=e?ge.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):ge.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n));var l={},u={};for(var c in t){var d=t[c];u[c]=d}l.metadata=u,i(o,l,r)},!0)},this.updateMetaData=function(e,n,t,r,i){Te.getInstance().ConnectionManager.ready(function(s,o){if(o)return void i(null,o);var l="";l=e?ge.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):ge.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n));var u={},c={};for(var d in t){var h=t[d];c[d]=h}u.metadata=c,u.upsert=r,a(l,u,i)},!0)},this.getAllMetaData=function(e,n,t){this.getMetaData(e,n,[],t)},this.getMetaData=function(e,n,t,i){Te.getInstance().ConnectionManager.ready(function(a,s){if(s)return void i(null,s);var o="";o=e?ge.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):ge.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)),r(o,{keys:t},i)},!0)},this.deleteMetaData=function(e,n,r,i){Te.getInstance().ConnectionManager.ready(function(a,s){if(s)return void i(null,s);var o="";o=e?ge.API_OPENCHANNELS_CHANNELURL_METADATA_KEY.replace("%s",encodeURIComponent(n)).replace("%s",r):ge.API_GROUPCHANNELS_CHANNELURL_METADATA_KEY.replace("%s",encodeURIComponent(n)).replace("%s",r),t(o,{},i)},!0)},this.deleteAllMetaData=function(e,n,r){Te.getInstance().ConnectionManager.ready(function(i,a){if(a)return void r(null,a);var s="";s=e?ge.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):ge.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)),t(s,{},r)},!0)},this.loadUserList=function(e,n,t,i,a,s){Te.getInstance().ConnectionManager.ready(function(o,l){if(l)return void s(null,l);var u=ge.API_USERS,c={token:e,limit:String(n)};g(t)||(c.user_ids=t),i&&!g(a)&&(c.metadatakey=i,c.metadatavalues_in=a),r(u,c,s)},!0)},this.loadBlockedUserList=function(e,n,t,i){Te.getInstance().ConnectionManager.ready(function(a,s){if(s)return void i(null,s);var o=ge.API_USERS_USERID_BLOCK.replace("%s",encodeURIComponent(a.userId)),l={token:e,limit:String(n)};g(t)||(l.user_ids=t),r(o,l,i)},!0)},this.loadOpenChannelList=function(e,n,t,i,a,s){Te.getInstance().ConnectionManager.ready(function(o,l){if(l)return void s(null,l);var u=ge.API_OPENCHANNELS,c={token:e,limit:String(n)};null!==t&&(c.name_contains=t),i&&(c.url_contains=i),null!==a&&(c.custom_type=a),r(u,c,s)},!0)},this.sendUserMessageAPI=function(e,n,t,r,a,s,o,l,u,c,d){Te.getInstance().ConnectionManager.ready(function(h,p){if(p)return void d(null,p);var f=n?ge.API_OPENCHANNELS_CHANNELURL_MESSAGES.replace("%s",encodeURIComponent(e)):ge.API_GROUPCHANNELS_CHANNELURL_MESSAGES.replace("%s",encodeURIComponent(e)),_={message_type:"MESG",user_id:h.userId,message:t,mention_type:l,mentioned_user_ids:[]};null!==r&&void 0!==r&&(_.data=r),null!==a&&void 0!==a&&(_.custom_type=a),s&&(_.translation_target_langs=s),o&&o.length>0&&(_.sorted_metaarray=o.map(function(e){return e.encode()})),l===ve.MentionType.CHANNEL?_.mentioned_user_ids=[]:Array.isArray(u)&&u.length>0&&(_.mentioned_user_ids=u),c&&c!==Ce.PushNotificationDeliveryOption.DEFAULT&&(_.push_option=c),i(f,_,d)},!0)},this.translateUserMessageAPI=function(e,n,t,r,a){Te.getInstance().ConnectionManager.ready(function(s,o){if(o)return void a(null,o);var l=n?ge.API_OPENCHANNELS_CHANNELURL_MESSAGES_MESSAGEID_TRANSLATION.replace("%channelUrl",encodeURIComponent(e)):ge.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MESSAGEID_TRANSLATION.replace("%channelUrl",encodeURIComponent(e));l=l.replace("%messageId",t),i(l,{target_langs:r},a)},!0)},this.sendFileMessageAPI=function(e,n,t,r,a,s,o,l,u,c,d,h,p,f,_){Te.getInstance().ConnectionManager.ready(function(I,g){if(g)return void _(null,g);var m=n?ge.API_OPENCHANNELS_CHANNELURL_MESSAGES.replace("%s",encodeURIComponent(e)):ge.API_GROUPCHANNELS_CHANNELURL_MESSAGES.replace("%s",encodeURIComponent(e)),E={message_type:"FILE",user_id:I.userId,url:t,mention_type:h,mentioned_user_ids:[]};null!==r&&void 0!==r&&(E.file_name=r),null!==a&&void 0!==a&&(E.file_size=a),null!==s&&void 0!==s&&(E.file_type=s),null!==o&&void 0!==o&&(E.custom_field=o),null!==l&&void 0!==l&&(E.custom_type=l),u&&(E.thumbnails=u),c&&(E.require_auth=c),d&&d.length>0&&(E.sorted_metaarray=d.map(function(e){return e.encode()})),h===ve.MentionType.CHANNEL?E.mentioned_user_ids=[]:Array.isArray(p)&&p.length>0&&(E.mentioned_user_ids=p),f&&f!==Ce.PushNotificationDeliveryOption.DEFAULT&&(E.push_option=f),i(m,E,_)},!0)},this.uploadFile=function(e,t,r,i,a,s,o){Te.getInstance().ConnectionManager.ready(function(l,u){if(u)return void a(null,u);n(ge.API_STORAGE_FILE,0,e,t,r,i,a,s,o)},!0)},this.loadOperatorList=function(e,n,t,i,a){Te.getInstance().ConnectionManager.ready(function(s,o){if(o)return void a(null,o);var l=n?ge.API_OPENCHANNELS_OPERATORS.replace("%url",encodeURIComponent(e)):ge.API_GROUPCHANNELS_OPERATORS.replace("%url",encodeURIComponent(e));r(l,{token:t,limit:i},a)},!0)},this.loadGroupChannelMemberList=function(e,n,t,i,a,s,o,l,u){Te.getInstance().ConnectionManager.ready(function(c,d){if(d)return void u(null,d);var h=ge.API_GROUPCHANNELS_MEMBERS.replace("%url",encodeURIComponent(e)),p={token:n,limit:t,muted_member_filter:i.toLowerCase(),operator_filter:a.toLowerCase(),member_state_filter:s,order:l.toLowerCase()};o&&(p.nickname_startswith=o),r(h,p,u)},!0)},this.loadPublicGroupChannelList=function(e,n,t,i,a,s,o,l,u,c,d,h){Te.getInstance().ConnectionManager.ready(function(p,f){if(f)return void h(null,f);var _=ge.API_GROUPCHANNELS,I={public_mode:K.publicChannelFilter.PUBLIC,token:e,limit:String(n),show_member:!0,show_read_receipt:!0,show_empty:String(t),order:i};if(a)try{I.name_contains=a}catch(e){}if(s.length>0)try{I.channel_urls=s}catch(e){}o.length>0&&(I.custom_types=o),l&&(I.custom_type_startswith=l),d&&(I.metadata_order_key=d),I.super_mode=u,I.public_membership_mode=c,r(_,I,h)},!0)},this.loadUserGroupChannelList=function(e,n,t,i,a,s,o,l,u,c,d,h,p,f,_,I,g,m,E){Te.getInstance().ConnectionManager.ready(function(A,y){if(y)return void E(null,y);var v=ge.API_MYGROUPCHANNELS.replace("%s",encodeURIComponent(A.userId)),N=a.userIds,C=!a.includeMode,R=a.queryType,S={token:e,limit:String(n),show_member:!0,show_read_receipt:!0,show_empty:String(t),order:i,member_state_filter:h};if(c&&c.length>0?S.custom_types=c:u&&(S.custom_type=u),s)try{S.members_nickname_contains=s}catch(e){}if(o)try{S.name_contains=o}catch(e){}if(m.hasOwnProperty("search_query")&&m.hasOwnProperty("search_fields"))try{S.search_query=m.search_query,S.search_fields=m.search_fields}catch(e){}if(N&&N.length>0)try{C?S.members_exactly_in=N:(S.members_include_in=N,S.query_type=R.toUpperCase())}catch(e){}if(l&&l.length>0)try{S.channel_urls=l}catch(e){}S.super_mode=p,S.public_mode=f,S.unread_filter=_,I&&(S.metadata_order_key=I),d&&(S.custom_type_startswith=d),S.hidden_mode=g,r(v,S,E)},!0)},this.loadOpenChannelParticipantList=function(e,n,t,i){Te.getInstance().ConnectionManager.ready(function(a,s){if(s)return void i(null,s);var o=ge.API_OPENCHANNELS_CHANNELURL_PARTICIPANTS.replace("%s",encodeURIComponent(e)),l={token:n,limit:String(t)};r(o,l,i)},!0)},this.loadMutedUserList=function(e,n,t,i){Te.getInstance().ConnectionManager.ready(function(a,s){if(s)return void i(null,s);var o=e.isOpenChannel?ge.API_OPENCHANNELS_CHANNELURL_MUTE.replace("%s",encodeURIComponent(e.channelUrl)):ge.API_GROUPCHANNELS_CHANNELURL_MUTE.replace("%s",encodeURIComponent(e.channelUrl)),l={token:n,limit:String(t)};r(o,l,i)},!0)},this.loadBannedUserList=function(e,n,t,i){Te.getInstance().ConnectionManager.ready(function(a,s){if(s)return void i(null,s);var o=e.isOpenChannel?ge.API_OPENCHANNELS_CHANNELURL_BAN.replace("%s",encodeURIComponent(e.channelUrl)):ge.API_GROUPCHANNELS_CHANNELURL_BAN.replace("%s",encodeURIComponent(e.channelUrl)),l={token:n,limit:String(t)};r(o,l,i)},!0)},this.setPushTemplate=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,r){if(r)return void n(null,r);var i=ge.API_USERS_USERID_PUSH_TEMPLATE.replace("%s",encodeURIComponent(t.userId));a(i,{name:e},n)},!0)},this.getPushTemplate=function(e){Te.getInstance().ConnectionManager.ready(function(n,t){if(t)return void e(null,t);var i=ge.API_USERS_USERID_PUSH_TEMPLATE.replace("%s",encodeURIComponent(n.userId));r(i,e)},!0)},this.setDoNotDisturb=function(e,n,t,r,i,s,o){Te.getInstance().ConnectionManager.ready(function(l,u){if(u)return void o(null,u);var c=ge.API_USERS_USERID_PUSHPREFERENCE.replace("%s",encodeURIComponent(l.userId));a(c,{do_not_disturb:e,start_hour:n,start_min:t,end_hour:r,end_min:i,timezone:s},o)},!0)},this.getDoNotDisturb=function(e){Te.getInstance().ConnectionManager.ready(function(n,t){if(t)return void e(null,t);var i=ge.API_USERS_USERID_PUSHPREFERENCE.replace("%s",encodeURIComponent(n.userId));r(i,e)},!0)},this.setSnoozePeriod=function(e,n,t,r){Te.getInstance().ConnectionManager.ready(function(i,s){if(s)return void r(null,s);var o=ge.API_USERS_USERID_PUSHPREFERENCE.replace("%s",encodeURIComponent(i.userId));a(o,{snooze_enabled:e,snooze_start_ts:n,snooze_end_ts:t},r)},!0)},this.getSnoozePeriod=function(e){Te.getInstance().ConnectionManager.ready(function(n,t){if(t)return void e(null,t);var i=ge.API_USERS_USERID_PUSHPREFERENCE.replace("%s",encodeURIComponent(n.userId));r(i,e)},!0)},this.setPushTriggerOption=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,r){if(r)return void n(null,r);var i=ge.API_USERS_USERID_PUSHPREFERENCE.replace("%s",encodeURIComponent(t.userId));a(i,{push_trigger_option:e},n)},!0)},this.getPushTriggerOption=function(e){Te.getInstance().ConnectionManager.ready(function(n,t){if(t)return void e(null,t);var i=ge.API_USERS_USERID_PUSHPREFERENCE.replace("%s",encodeURIComponent(n.userId));r(i,e)},!0)},this.setPushPreference=function(e,n,t){Te.getInstance().ConnectionManager.ready(function(r,i){if(i)return void t(null,i);var s=ge.API_USERS_USERID_PUSHPREFERENCE_CHANNELURL.replace("%s",encodeURIComponent(r.userId)).replace("%s",encodeURIComponent(e)),o={};o.enable=n,a(s,o,t)},!0)},this.getPushPreference=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,i){if(i)return void n(null,i);var a=ge.API_USERS_USERID_PUSHPREFERENCE_CHANNELURL.replace("%s",encodeURIComponent(t.userId)).replace("%s",encodeURIComponent(e));r(a,n)},!0)},this.setMyPushTriggerOption=function(e,n,t){Te.getInstance().ConnectionManager.ready(function(r,i){if(i)return void t(null,i);var s=ge.API_USERS_USERID_PUSHPREFERENCE_CHANNELURL.replace("%s",encodeURIComponent(r.userId)).replace("%s",encodeURIComponent(e)),o={};o.push_trigger_option=n,a(s,o,t)},!0)},this.getMyPushTriggerOption=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,i){if(i)return void n(null,i);var a=ge.API_USERS_USERID_PUSHPREFERENCE_CHANNELURL.replace("%s",encodeURIComponent(t.userId)).replace("%s",encodeURIComponent(e));r(a,n)},!0)},this.setCountPreference=function(e,n,t){Te.getInstance().ConnectionManager.ready(function(r,i){if(i)return void t(null,i);var s=ge.API_USERS_COUNT_PREFERENCE.replace("%s",encodeURIComponent(r.userId)).replace("%s",encodeURIComponent(e)),o={};o.count_preference=n,a(s,o,t)},!0)},this.registerGCMPushToken=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,r){if(r)return void n(null,r);var a=ge.API_USERS_USERID_PUSH_GCM.replace("%s",encodeURIComponent(t.userId));i(a,{gcm_reg_token:e},n)},!0)},this.unregisterGCMPushToken=function(e,n){Te.getInstance().ConnectionManager.ready(function(r,i){if(i)return void n(null,i);var a=ge.API_USERS_USERID_PUSH_GCM_TOKEN.replace("%s",encodeURIComponent(r.userId)).replace("%s",encodeURIComponent(e));t(a,n)},!0)},this.unregisterGCMPushTokenAll=function(e){Te.getInstance().ConnectionManager.ready(function(n,r){if(r)return void e(null,r);var i=ge.API_USERS_USERID_PUSH_GCM.replace("%s",encodeURIComponent(n.userId));t(i,e)},!0)},this.registerAPNSPushToken=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,r){if(r)return void n(null,r);var a=ge.API_USERS_USERID_PUSH_APNS.replace("%s",encodeURIComponent(t.userId));i(a,{apns_device_token:e},n)},!0)},this.unregisterAPNSPushToken=function(e,n){Te.getInstance().ConnectionManager.ready(function(r,i){if(i)return void n(null,i);var a=ge.API_USERS_USERID_PUSH_APNS_TOKEN.replace("%s",encodeURIComponent(r.userId)).replace("%s",encodeURIComponent(e));t(a,n)},!0)},this.unregisterAPNSPushTokenAll=function(e){Te.getInstance().ConnectionManager.ready(function(n,r){if(r)return void e(null,r);var i=ge.API_USERS_USERID_PUSH_APNS.replace("%s",encodeURIComponent(n.userId));t(i,e)},!0)},this.unregisterPushTokenAll=function(e){Te.getInstance().ConnectionManager.ready(function(n,r){if(r)return void e(null,r);var i=ge.API_USERS_USERID_PUSH.replace("%s",encodeURIComponent(n.userId));t(i,e)},!0)},this.blockUser=function(e,n){Te.getInstance().ConnectionManager.ready(function(t,r){if(r)return void n(null,r);var a=ge.API_USERS_USERID_BLOCK.replace("%s",encodeURIComponent(t.userId));i(a,{target_id:e},n)},!0)},this.unblockUser=function(e,n){Te.getInstance().ConnectionManager.ready(function(r,i){if(i)return void n(null,i);var a=ge.API_USERS_USERID_BLOCK_TARGETID.replace("%s",encodeURIComponent(r.userId)).replace("%s",encodeURIComponent(e));t(a,{},n)},!0)},this.banUser=function(e,n,t,r,a,s){Te.getInstance().ConnectionManager.ready(function(o,l){if(l)return void s(null,l);var u=a?ge.API_GROUPCHANNELS_CHANNELURL_BAN.replace("%s",encodeURIComponent(e)):ge.API_OPENCHANNELS_CHANNELURL_BAN.replace("%s",encodeURIComponent(e)),c={user_id:n};t&&(c.description=t),c.seconds=String(r),i(u,c,s)},!0)},this.unbanUser=function(e,n,r,i){Te.getInstance().ConnectionManager.ready(function(a,s){if(s)return void i(null,s);var o=r?ge.API_GROUPCHANNELS_CHANNELURL_BAN_USERID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n)):ge.API_OPENCHANNELS_CHANNELURL_BAN_USERID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));t(o,{},i)},!0)},this.muteUser=function(e,n,t,r,a,s){Te.getInstance().ConnectionManager.ready(function(o,l){if(l)return void s(null,l);var u=t?ge.API_GROUPCHANNELS_CHANNELURL_MUTE.replace("%s",encodeURIComponent(e)):ge.API_OPENCHANNELS_CHANNELURL_MUTE.replace("%s",encodeURIComponent(e)),c={user_id:n};r&&(r>0||-1!==r)&&(c.seconds=r),a&&(c.description=a),i(u,c,s)},!0)},this.unmuteUser=function(e,n,r,i){Te.getInstance().ConnectionManager.ready(function(a,s){if(s)return void i(null,s);var o=r?ge.API_GROUPCHANNELS_CHANNELURL_MUTE_USERID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n)):ge.API_OPENCHANNELS_CHANNELURL_MUTE_USERID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));t(o,{},i)},!0)},this.deleteMessage=function(e,n,r,i){Te.getInstance().ConnectionManager.ready(function(a,s){if(s)return void i(null,s);var o="";o=e?ge.API_OPENCHANNELS_CHANNELURL_MESSAGES_MESSAGEID.replace("%s",encodeURIComponent(n)).replace("%s",encodeURIComponent(r)):ge.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MESSAGEID.replace("%s",encodeURIComponent(n)).replace("%s",encodeURIComponent(r)),t(o,{},i)},!0)},this.freeze=function(e,n,t,r){Te.getInstance().ConnectionManager.ready(function(i,s){if(s)return void r(null,s);var o=n?ge.API_GROUPCHANNELS_CHANNELURL_FREEZE.replace("%s",encodeURIComponent(e)):ge.API_OPENCHANNELS_CHANNELURL_FREEZE.replace("%s",encodeURIComponent(e));a(o,{freeze:t},r)},!0)}},me=null;ge.getInstance=function(){return null===me?null:me},ge.API_VERSION="v3",ge.API_ROUTING_URL="https://api-%s.sendbird.com",ge.API_USERS="/%v/users".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_LOGIN="/%v/users/%s/login".replace("%v",ge.API_VERSION),ge.API_USERS_USERID="/%v/users/%s".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_UNREAD_ITEM_COUNT="/%v/users/%s/unread_item_count".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_METADATA="/%v/users/%s/metadata".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_METADATA_KEY="/%v/users/%s/metadata/%s".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_UNREAD_MESSAGE_COUNT="/%v/users/%s/unread_message_count".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_UNREAD_CHANNEL_COUNT="/%v/users/%s/unread_channel_count".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_MY_GROUP_CHANNEL_CHANGELOGS="/%v/users/%s/my_group_channels/changelogs".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_MARKASREADALL="/%v/users/%s/mark_as_read_all".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_PUSH_GCM_TOKEN="/%v/users/%s/push/gcm/%s".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_PUSH_GCM="/%v/users/%s/push/gcm".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_PUSH_DEVICE_TOKENS="/%v/users/%s/push/%s/device_tokens".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_PUSHPREFERENCE_CHANNELURL="/%v/users/%s/push_preference/%s".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_PUSHPREFERENCE="/%v/users/%s/push_preference/".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_PUSH_TEMPLATE="/%v/users/%s/push/template".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_BLOCK="/%v/users/%s/block".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_BLOCK_TARGETID="/%v/users/%s/block/%s".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_PUSH_APNS_TOKEN="/%v/users/%s/push/apns/%s".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_PUSH_APNS="/%v/users/%s/push/apns".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_PUSH="/%v/users/%s/push".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_GROUP_CHANNEL_INVITATION_PREFERENCE="/%v/users/%s/channel_invitation_preference".replace("%v",ge.API_VERSION),ge.API_USERS_USERID_GROUP_CHANNEL_COUNT="/%v/users/%s/group_channel_count".replace("%v",ge.API_VERSION),ge.API_USERS_COUNT_PREFERENCE="/%v/users/%s/count_preference/%s".replace("%v",ge.API_VERSION),ge.API_OPENCHANNELS="/%v/open_channels".replace("%v",ge.API_VERSION),ge.API_OPENCHANNELS_CHANNELURL="/%v/open_channels/%s".replace("%v",ge.API_VERSION),ge.API_OPENCHANNELS_CHANNELURL_MESSAGES="/%v/open_channels/%s/messages".replace("%v",ge.API_VERSION),ge.API_OPENCHANNELS_CHANNELURL_MESSAGES_MESSAGEID_TRANSLATION="/%v/open_channels/%channelUrl/messages/%messageId/translation".replace("%v",ge.API_VERSION),ge.API_OPENCHANNELS_CHANNELURL_MESSAGES_MESSAGEID="/%v/open_channels/%s/messages/%s".replace("%v",ge.API_VERSION),ge.API_OPENCHANNELS_CHANNELURL_SCHEDULED_MESSAGES="/%v/open_channels/%s/scheduled_messages".replace("%v",ge.API_VERSION),ge.API_OPENCHANNELS_CHANNELURL_PARTICIPANTS="/%v/open_channels/%s/participants".replace("%v",ge.API_VERSION),ge.API_OPENCHANNELS_CHANNELURL_METADATA="/%v/open_channels/%s/metadata".replace("%v",ge.API_VERSION),ge.API_OPENCHANNELS_CHANNELURL_METADATA_KEY="/%v/open_channels/%s/metadata/%s".replace("%v",ge.API_VERSION),ge.API_OPENCHANNELS_CHANNELURL_METACOUNTER="/%v/open_channels/%s/metacounter".replace("%v",ge.API_VERSION),ge.API_OPENCHANNELS_CHANNELURL_METACOUNTER_KEY="/%v/open_channels/%s/metacounter/%s".replace("%v",ge.API_VERSION),ge.API_OPENCHANNELS_CHANNELURL_BAN="/%v/open_channels/%s/ban".replace("%v",ge.API_VERSION),ge.API_OPENCHANNELS_CHANNELURL_BAN_USERID="/%v/open_channels/%s/ban/%s".replace("%v",ge.API_VERSION),ge.API_OPENCHANNELS_CHANNELURL_MUTE="/%v/open_channels/%s/mute".replace("%v",ge.API_VERSION),ge.API_OPENCHANNELS_CHANNELURL_MUTE_USERID="/%v/open_channels/%s/mute/%s".replace("%v",ge.API_VERSION),ge.API_OPENCHANNELS_CHANNELURL_FREEZE="/%v/open_channels/%s/freeze".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS="/%v/group_channels".replace("%v",ge.API_VERSION),ge.API_MYGROUPCHANNELS="/%v/users/%s/my_group_channels".replace("%v",ge.API_VERSION), -ge.API_GROUPCHANNELS_CHANNELURL="/%v/group_channels/%s".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_INVITE="/%v/group_channels/%s/invite".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_ACCEPT_INVITATION="/%v/group_channels/%s/accept".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_DECLINE_INVITATION="/%v/group_channels/%s/decline".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_HIDE="/%v/group_channels/%s/hide".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_LEAVE="/%v/group_channels/%s/leave".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_JOIN="/%v/group_channels/%s/join".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_MESSAGES="/%v/group_channels/%s/messages".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MARKASREAD="/%v/group_channels/%s/messages/mark_as_read".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_MESSAGES_TOTALCOUNT="/%v/group_channels/%s/messages/total_count".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_MESSAGES_UNREADCOUNT="/%v/group_channels/%s/messages/unread_count".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MESSAGEID_TRANSLATION="/%v/group_channels/%channelUrl/messages/%messageId/translation".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MESSAGEID="/%v/group_channels/%s/messages/%s".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_SCHEDULED_MESSAGES="/%v/group_channels/%s/scheduled_messages".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_MEMBERS="/%v/group_channels/%s/members".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_METADATA="/%v/group_channels/%s/metadata".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_METADATA_KEY="/%v/group_channels/%s/metadata/%s".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_METACOUNTER="/%v/group_channels/%s/metacounter".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_METACOUNTER_KEY="/%v/group_channels/%s/metacounter/%s".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_RESET_USER_HISTORY="/%v/group_channels/%s/reset_user_history".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_MEMBERS="/%v/group_channels/%url/members".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_BAN="/%v/group_channels/%s/ban".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_BAN_USERID="/%v/group_channels/%s/ban/%s".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_MUTE="/%v/group_channels/%s/mute".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_MUTE_USERID="/%v/group_channels/%s/mute/%s".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_FREEZE="/%v/group_channels/%s/freeze".replace("%v",ge.API_VERSION),ge.API_STORAGE_FILE="/%v/storage/file".replace("%v",ge.API_VERSION),ge.API_STORAGE_PROFILE="/%v/storage/profile_image".replace("%v",ge.API_VERSION),ge.API_OPENCHANNELS_CHANNELURL_MESSAGES_CHANGELOGS="/%v/open_channels/%s/messages/changelogs".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_CHANNELURL_MESSAGES_CHANGELOGS="/%v/group_channels/%s/messages/changelogs".replace("%v",ge.API_VERSION),ge.API_FRIENDS="/%v/users/%s/friends".replace("%v",ge.API_VERSION),ge.API_FRIENDS_CHANGE_LOGS="/%v/users/%s/friends/changelogs".replace("%v",ge.API_VERSION),ge.API_FRIENDS_DISCOVERIES="/%v/users/%s/friend_discoveries".replace("%v",ge.API_VERSION),ge.API_GROUPCHANNELS_OPERATORS="/%v/group_channels/%url/operators".replace("%v",ge.API_VERSION),ge.API_OPENCHANNELS_OPERATORS="/%v/open_channels/%url/operators".replace("%v",ge.API_VERSION),ge.UPDATE_META_COUNTER_MODE_SET=0,ge.UPDATE_META_COUNTER_MODE_INC=1,ge.UPDATE_META_COUNTER_MODE_DEC=2;var Ee=function(){var e="";this.isLoading=!1,this.hasMore=!0,this.limit=20;var n=this;this.next=function(t){return m(n.limit)?n.hasMore?n.isLoading?void L(null,new y("Query in progress.",U.QUERY_IN_PROGRESS),t):(n.isLoading=!0,void ge.getInstance().friendListQuery(e,n.limit,function(r,i){if(i)return n.isLoading=!1,void L(null,i,t);var a=r.users,s=a.map(function(e){return new Q(e)});n.hasMore=r.has_more,n.isLoading=!1,e=r.next,L(s,null,t)})):void L([],null,t):void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),t)}},Ae=function(e,n,t,r){f?this[t]=e[n]:Object.defineProperty(e,t,{get:function(){return"_coverUrl"===n||"_coverImage"===n?e._channelCover:e[n]},set:function(t){if("file"===r){if("string"==typeof t||"object"!=typeof t)return}else if(r&&typeof t!==r)return;e[n]=t,"_coverUrl"!==n&&"_coverImage"!==n||(e._channelCover=t)}})},ye=function(){this._isDistinct=null,Ae(this,"_isDistinct","isDistinct","boolean"),this._isSuper=null,Ae(this,"_isSuper","isSuper","boolean"),this._isPublic=null,Ae(this,"_isPublic","isPublic","boolean"),this._channelUrl=null,Ae(this,"_channelUrl","channelUrl","string"),this._isDiscoverable=null,Ae(this,"_isDiscoverable","isDiscoverable","boolean"),this._isStrict=null,Ae(this,"_isStrict","isStrict","boolean"),this._name=null,Ae(this,"_name","name","string"),this._data=null,Ae(this,"_data","data","string"),this._customType=null,Ae(this,"_customType","customType","string"),this._channelCover=null,Ae(this,"_channelCover","channelCover",null),this._coverUrl=null,Ae(this,"_coverUrl","coverUrl","string"),this._coverImage=null,Ae(this,"_coverImage","coverImage","file"),this._accessCode=null,Ae(this,"_accessCode","accessCode","string"),this._operatorIds=[],this._operators=null,f?this.operators=this._operators:Object.defineProperty(this,"operators",{get:function(){return this._operators},set:function(e){if(Array.isArray(e)){for(var n=[],t=0;t0&&(this._inviteUserIds=this._inviteUserIds.concat(t))}},this.addUser=function(e){e.hasOwnProperty("userId")&&this._inviteUserIds.push(e.userId)},this.addUserIds=function(e){if(Array.isArray(e)){for(var n=e.length,t=[],r=0;r0&&(this._inviteUserIds=this._inviteUserIds.concat(t))}},this.addUserId=function(e){"string"==typeof e&&this._inviteUserIds.push(e)}},ve=function(){};ve.MentionType={USERS:"users",CHANNEL:"channel"},ve.PushNotificationDeliveryOption={DEFAULT:"default",SUPPRESS:"suppress"};var Ne=function(){this._message=null,Ae(this,"_message","message","string"),this._translationTargetLanguages=null,f?this.translationTargetLanguages=this._translationTargetLanguages:Object.defineProperty(this,"translationTargetLanguages",{get:function(){return this._translationTargetLanguages},set:function(e){if(Array.isArray(e)){for(var n=0;n=1&&this._month<=12&&"number"==typeof this._day&&this._day>=1&&this._day<=31&&"number"==typeof this._hour&&this._hour>=0&&this._hour<=24&&"number"==typeof this._min&&this._min>=0&&this._min<=60&&"string"==typeof this._timezone&&this._timezone.length>0?this._year.toString()+"-"+("0"+this._month.toString()).substr(-2)+"-"+("0"+this._day.toString()).substr(-2)+" "+("0"+this._hour.toString()).substr(-2)+":"+("0"+this._min.toString()).substr(-2):null},set:function(e){e&&"string"==typeof e&&(this._scheduledDateTimeString=e)}}),this.setSchedule=function(e,n,t,r,i,a){"number"==typeof e&&4===e.toString().length&&"number"==typeof n&&n>=1&&n<=12&&"number"==typeof t&&t>=1&&t<=31&&"number"==typeof r&&r>=0&&r<=24&&"number"==typeof i&&i>=0&&i<=60&&"string"==typeof a&&a.length>0&&(this.scheduledDateTimeString=e.toString()+"-"+("0"+n.toString()).substr(-2)+"-"+("0"+t.toString()).substr(-2)+" "+("0"+r.toString()).substr(-2)+":"+("0"+i.toString()).substr(-2),this.timezone=a)},this._getScheduleString=function(){return this.scheduledDateTimeString?this.scheduledDateTimeString+" "+this.timezone:"number"==typeof this.year&&4===this.year.toString().length&&"number"==typeof this.month&&this.month>=1&&this.month<=12&&"number"==typeof this.day&&this.day>=1&&this.day<=31&&"number"==typeof this.hour&&this.hour>=0&&this.hour<=24&&"number"==typeof this.min&&this.min>=0&&this.min<=60&&"string"==typeof this.timezone&&this.timezone.length>0?this.year.toString()+"-"+("0"+this.month.toString()).substr(-2)+"-"+("0"+this.day.toString()).substr(-2)+" "+("0"+this.hour.toString()).substr(-2)+":"+("0"+this.min.toString()).substr(-2)+" "+this.timezone:null},this._update=function(e){e.hasOwnProperty("message")&&(this.message=e.message),e.hasOwnProperty("year")&&(this.year=e.year),e.hasOwnProperty("month")&&(this.month=e.month),e.hasOwnProperty("day")&&(this.day=e.day),e.hasOwnProperty("hour")&&(this.hour=e.hour),e.hasOwnProperty("min")&&(this.min=e.min),e.hasOwnProperty("timezone")&&(this.timezone=e.timezone)},e&&this._update(e)},Se=function(){this.networkHandlers={},this.authenticateTimer=1e4,this.authInfoRequester=null;var e=0,n=[],t=new y("Connection should be made first.",U.CONNECTION_REQUIRED),r=new y("Invalid parameter.",U.INVALID_PARAMETER);this.addReadyHandler=function(e){e&&"function"==typeof e&&n.push(e)},this.ready=function(e,n){var t=ge.getInstance().sessionKey,r=Te.getInstance();return n&&t?void(e&&(e(r.currentUser,null),r.getConnectionState()===r.ConnectionState.CLOSED&&r.reconnect())):(this.addReadyHandler(e),r.isReconnectingOnError?void this.errorAllReadyHandler():void(r.getConnectionState()===r.ConnectionState.OPEN?this.processAllReadyHandler(null):r.getConnectionState()===r.ConnectionState.CONNECTING||this.errorAllReadyHandler()))},this.processAllReadyHandler=function(e){if(n.length>0){var t=n;n=[],t.forEach(function(n){n&&"function"==typeof n&&n(Te.getInstance().currentUser,e)}),t=[]}},this.errorAllReadyHandler=function(){this.processAllReadyHandler(t)},this.NetworkHandler=function(){this.onReconnected=function(){}},this.addNetworkHandler=function(e,n){this.networkHandlers[e]=n},this.removeNetworkHandler=function(e){delete this.networkHandlers[e]},this.removeAllNetworkHandler=function(){this.networkHandlers={}},this.authenticate=function(n){var i=this,a=Te.getInstance();if(a.getConnectionState()===a.ConnectionState.OPEN||a.reconnecting)a.connecting=!1,L(a.currentUser,null,n);else if(i.authInfoRequester&&"function"==typeof i.authInfoRequester){a.connecting=!0,e++;var s=setTimeout(function(){s=null,e--,0===e&&0===a.connectionCallback.length&&(a.connecting=!1),i.errorAllReadyHandler(),L(null,t,n)},i.authenticateTimer);i.authInfoRequester(function(t){if(s){clearTimeout(s),s=null,e--;var i=function(e,t){a.connecting=!1,t?L(null,new y(t.message,t.code),n):L(e,null,n)};t&&t.hasOwnProperty("userId")?t.apiHost&&t.wsHost?a.connect(t.userId,t.accessToken,t.apiHost,t.wsHost,i):a.connect(t.userId,t.accessToken,i):L(null,r,n)}})}else L(null,r,n)}},Ue=function(e,n){this.key=e,this.value=n};Ue.prototype.encode=function(){return{key:this.key,value:this.value}};var Te=function(e){var n=Te.getInstance();if(n)return n;try{if(!e.hasOwnProperty("appId"))return t.log("Must be set appId"),null}catch(e){return t.log("Must be set appId"),null}this.connecting=!1,this.reconnecting=!1,this.isReconnectingOnError=!1,this.ConnectionManager=new Se,this.GCMPushToken="",this.APNSPushToken="",this.PUSH_TEMPLATE_DEFAULT="default",this.PUSH_TEMPLATE_ALTERNATIVE="alternative",this.isSessionOpened=!1,this.pushTokenRegistrationState={SUCCESS:"success",PENDING:"pending",ERROR:"error"},this.PushTriggerOption={ALL:"all",MENTION_ONLY:"mention_only",OFF:"off"},this.loginTimer,this.onLoginTimerCancel,this.globalTimer,this.reconnectTimer,this.onReconnectTimerCancel,this.currentUser=null,this.getCurrentUserId=function(){return Te.getInstance().currentUser?Te.getInstance().currentUser.userId:null},this.wsClient,this.ConnectionState={CONNECTING:"CONNECTING",OPEN:"OPEN",CLOSING:"CLOSING",CLOSED:"CLOSED"},this.connectionState=this.ConnectionState,this._connectedAt=0,this.getLastConnectedAt=function(){var e=this;return e.getConnectionState()===e.ConnectionState.OPEN&&e.currentUser?e._connectedAt:0},this.BaseChannel=v,this.User=Q,this.Member=X,this.OpenChannel=B,this.GroupChannel=K,this.UserMessage=G,this.MessageRequestState=k,this.FileMessage=q,this.AdminMessage=w,this.GroupChannelListQuery=ne,this.MessageMetaArray=Ue,this.userEventHandlers={},this.channelHandlers={},this.connectionHandlers={},this.connectionCallback=[];var l=function(e,n){var t=Te.getInstance().connectionCallback;Te.getInstance().connectionCallback=[],t.forEach(function(t){L(e,n,t)}),t=[]};this.GroupChannelParams=ye,this.BaseMessageParams=ve,this.FileMessageParams=Ce,this.UserMessageParams=Ne,this.ScheduledUserMessageParams=Re,this.GroupChannelTotalUnreadMessageCountParams=x,this._ackStateMap={},M=e.appId,Pe=this,me=ge.getInstance(),me||(me=new ge),this.Options={_useMemberAsMessageSender:!0,get UseMemberAsMessageSender(){return this._useMemberAsMessageSender},set UseMemberAsMessageSender(e){"boolean"==typeof e&&(this._useMemberAsMessageSender=e)},get useMemberAsMessageSender(){return this._useMemberAsMessageSender},set useMemberAsMessageSender(e){"boolean"==typeof e&&(this._useMemberAsMessageSender=e)},_typingIndicatorThrottle:1e3,get typingIndicatorThrottle(){return this._typingIndicatorThrottle},set typingIndicatorThrottle(e){"number"==typeof e&&e>=s&&e<=o&&(this._typingIndicatorThrottle=e)}},this.customApiHost=null,this.customWsHost=null,this.UserEventHandler=function(){this.onFriendsDiscovered=function(e){}},this.addUserEventHandler=function(e,n){Te.getInstance().userEventHandlers[e]=n},this.removeUserEventHandler=function(e){delete Te.getInstance().userEventHandlers[e]},this.removeAllUserEventHandler=function(){Te.getInstance().userEventHandlers={}},this.ChannelHandler=function(){this.onMessageReceived=function(e,n){},this.onMessageUpdated=function(e,n){},this.onMessageDeleted=function(e,n){},this.onReadReceiptUpdated=function(e){},this.onTypingStatusUpdated=function(e){},this.onUserJoined=function(e,n){},this.onUserLeft=function(e,n){},this.onUserEntered=function(e,n){},this.onUserExited=function(e,n){},this.onUserMuted=function(e,n){},this.onUserUnmuted=function(e,n){},this.onUserBanned=function(e,n){},this.onUserUnbanned=function(e,n){},this.onChannelFrozen=function(e){},this.onChannelUnfrozen=function(e){},this.onChannelChanged=function(e){},this.onChannelDeleted=function(e,n){},this.onUserReceivedInvitation=function(e,n,t){},this.onUserDeclinedInvitation=function(e,n,t){},this.onMetaDataCreated=function(e,n){},this.onMetaDataUpdated=function(e,n){},this.onMetaDataDeleted=function(e,n){},this.onMetaCountersCreated=function(e,n){},this.onMetaCountersUpdated=function(e,n){},this.onMetaCountersDeleted=function(e,n){},this.onChannelHidden=function(e){},this.onMentionReceived=function(e,n){}},this.addChannelHandler=function(e,n){Te.getInstance().channelHandlers[e]=n},this.removeChannelHandler=function(e){delete Te.getInstance().channelHandlers[e]},this.removeAllChannelHandlers=function(){Te.getInstance().channelHandlers={}},this.ConnectionHandler=function(){this.onReconnectStarted=function(){},this.onReconnectSucceeded=function(){},this.onReconnectFailed=function(){}},this.addConnectionHandler=function(e,n){Te.getInstance().connectionHandlers[e]=n},this.removeConnectionHandler=function(e){delete Te.getInstance().connectionHandlers[e]},this.removeAllConnectionHandlers=function(){Te.getInstance().connectionHandlers={}},this.createUserListQuery=function(e){var n=new de;return e&&(n.userIds=e),n},this.createApplicationUserListQuery=function(){return new se},this.createBlockedUserListQuery=function(){return new oe},this.getApplicationId=function(){return M},this.getDebugMode=function(){return r},this.setDebugMode=function(e){r=e},this.setAPIHost=function(e){a=e},this.setWSHost=function(e){i=e},this.clearCurrentApiHost=function(){this.customApiHost=null},this.getCurrentApiHost=function(){return this.customApiHost?this.customApiHost:a},this.clearCurrentWsHost=function(){this.customWsHost=null},this.getCurrentWsHost=function(){return this.customWsHost?this.customWsHost:i},this.setErrorFirstCallback=function(e){O=e},this.getErrorFirstCallback=function(){return O},this.getConnectionState=function(){try{if(Te.getInstance()){var e=Te.getInstance();return e.connecting||e.reconnecting?e.ConnectionState.CONNECTING:e.wsClient?e.connecting||e.reconnecting?e.ConnectionState.CONNECTING:e.isSessionOpened?e.wsClient.getConnectionState():e.ConnectionState.CLOSED:e.ConnectionState.CLOSED}return Te.getInstance().ConnectionState.CLOSED}catch(e){return Te.getInstance().ConnectionState.CLOSED}},this.hasLoggedIn=function(){return Te.getInstance().currentUser&&ge.getInstance().sessionKey};var u={};this._createFileQueue=function(e,n){return u.hasOwnProperty(e)||(u[e]=new V(e,n)),u[e]},this._getFileQueue=function(e){return u.hasOwnProperty(e)?u[e]:null},this._clearFileQueue=function(){u={}},this._deleteFileQueue=function(e){u.hasOwnProperty(e)&&delete u[e]},this._fileUploadRequest={},this.setPushTriggerOption=function(e,n){if([this.PushTriggerOption.ALL,this.PushTriggerOption.MENTION_ONLY,this.PushTriggerOption.OFF].indexOf(e)<0)return void L(null,new y("Invalid parameters.",U.INVALID_PARAMETER),n);ge.getInstance().setPushTriggerOption(e,function(e,t){if(t)return void L(null,t,n);L(e.push_trigger_option,null,n)})},this.getPushTriggerOption=function(e){ge.getInstance().getPushTriggerOption(function(n,t){if(t)return void L(null,t,e);e&&L(n.push_trigger_option,null,e)})};var c=function(e){var n=Te.getInstance();return n._ackStateMap.hasOwnProperty(e)?n._ackStateMap[e]:null},d=function(e){var n=(Te.getInstance(),new Z(e));"LOGI"===n.command&&(m={all:0,custom_types:{},ts:0}),A(n.getJsonElement());var r=n.requestId;if(r){var i=c(r);if(null==i)return;clearTimeout(i.timer);var a=i.handler;if(a)if("EROR"===n.command){var s=n.getJsonElement(),o=new y(s.message,s.code);a(null,o)}else a(n,null);try{delete Te.getInstance()._ackStateMap[n.requestId]}catch(e){}}else switch(_e&&"LOGI"!==n.command&&_e.start(),n.command){case"LOGI":if(Te.getInstance().loginTimer){clearTimeout(Te.getInstance().loginTimer),Te.getInstance().loginTimer=null,Te.getInstance().onLoginTimerCancel=null;var l=n.getJsonElement();if(l.hasOwnProperty("error")){Te.getInstance().isSessionOpened=!1;var u=l.code,d=l.message;Te.getInstance().loginHandler(null,new y(d,u))}else Te.getInstance().isSessionOpened=!0,l.hasOwnProperty("key")&&(ge.getInstance().sessionKey=l.key),l.hasOwnProperty("ekey")&&(ge.getInstance().ekey=l.ekey),l.hasOwnProperty("user_id")&&(Te.getInstance().currentUser=new Q(l)),l.hasOwnProperty("ping_interval")&&"number"==typeof l.ping_interval&&l.ping_interval>0&&(he=1e3*l.ping_interval),l.hasOwnProperty("pong_timeout")&&"number"==typeof l.pong_timeout&&l.pong_timeout>0&&(pe=1e3*l.pong_timeout),l.hasOwnProperty("reconnect")&&"object"==typeof l.reconnect&&(h={interval:l.reconnect.interval||3,maxInterval:l.reconnect.max_interval||24,retryCount:l.reconnect.retry_cnt||3,multiplier:l.reconnect.mul||2}),l.hasOwnProperty("login_ts")&&"number"==typeof l.login_ts&&(Te.getInstance()._connectedAt=l.login_ts),_e&&_e.start(),Te.getInstance().loginHandler(Te.getInstance().currentUser,null);Te.getInstance().connecting=!1,Te.getInstance().reconnecting=!1}break;case"MESG":case"FILE":case"BRDM":case"ADMM":var p="",I=!1;if("MESG"===n.command?p=new G(n.getJsonElement()):"FILE"===n.command?p=new q(n.getJsonElement()):(p=new w(n.getJsonElement()),n.getJsonElement().hasOwnProperty("silent")&&(I=n.getJsonElement().silent)),!p)return;if(p.isGroupChannel()){var g=K.cachedChannels.hasOwnProperty(p.channelUrl);K.getChannel(p.channelUrl,function(e,n){if(O){var t=e;e=n,n=t}if(n)return void(a&&a(null,n));if(e.isHidden=!1,e.hiddenState=K.HiddenState.UNHIDDEN,K.cachedChannels[e.url]=e,p._sender&&e.memberMap.hasOwnProperty(p._sender.userId)){var r=e.memberMap[p._sender.userId];r.nickname!==p._sender.nickname&&(r.nickname=p._sender.nickname),r.profileUrl!==p._sender.profileUrl&&(r.profileUrl=p._sender.profileUrl),S(r.metaData,p._sender.metaData)||(r.metaData=p._sender.metaData),r.isBlockedByMe!==p._sender.isBlockedByMe&&(r.isBlockedByMe=p._sender.isBlockedByMe)}var i=Te.getInstance().currentUser;i&&p._sender&&i.userId===p._sender.userId&&(i.nickname!==p._sender.nickname&&(i.nickname=p._sender.nickname),i.profileUrl!==p._sender.profileUrl&&(i.profileUrl=p._sender.profileUrl),S(i.metaData,p._sender.metaData)||(i.metaData=p._sender.metaData));var s=!1;if(p.mentionType===ve.MentionType.CHANNEL)p.sender&&p.sender.userId===Te.getInstance().getCurrentUserId()||(s=!0);else if(p.mentionType===ve.MentionType.USERS)for(var o=0;o=p.createAt,o=Te.getInstance().currentUser;o&&p._sender&&o.userId===p._sender.userId&&(o.nickname!==p._sender.nickname&&(o.nickname=p._sender.nickname),o.profileUrl!==p._sender.profileUrl&&(o.profileUrl=p._sender.profileUrl),S(o.metaData,p._sender.metaData)||(o.metaData=p._sender.metaData));var l=!1,u=n.getJsonElement();if((!p.sender||p.sender.userId!==Te.getInstance().getCurrentUserId())&&!s&&u&&u.hasOwnProperty("old_values")){var c=u.old_values.mention_type||p.mentionType,d=u.old_values.mentioned_user_ids||p.mentionedUsers.map(function(e){return e.userId});if(c===ve.MentionType.USERS&&p.mentionType===ve.MentionType.USERS){for(var h=!1,f=!1,_=0;_0||e.unreadMentionCount>0)&&(R(e,0,0),0===e.unreadMessageCount||0===e.unreadMentionCount))for(var r in Te.getInstance().channelHandlers){var i=Te.getInstance().channelHandlers[r];i.onChannelChanged(e)}}else if(0===e.unreadMessageCount||0===e.unreadMentionCount)for(var r in Te.getInstance().channelHandlers){var i=Te.getInstance().channelHandlers[r];i.onChannelChanged(e)}}else for(var r in Te.getInstance().channelHandlers){var i=Te.getInstance().channelHandlers[r];i.onReadReceiptUpdated(e)}});break;case"TPST":case"TPEN":case"MTIO":break;case"SYEV":_(n);break;case"USEV":f(n);break;case"DELM":var N=n.getJsonElement(),C=String(N.channel_type),U=String(N.channel_url),T=String(N.msg_id);switch(C){case Y.CHANNEL_TYPE_OPEN:B.getChannel(U,function(e,n){if(O){var r=e;e=n,n=r}if(n)return void t.log("Discard a command.");for(var i in Te.getInstance().channelHandlers){Te.getInstance().channelHandlers[i].onMessageDeleted(e,T)}});break;case Y.CHANNEL_TYPE_GROUP:K.getChannel(U,function(e,n){if(O){var r=e;e=n,n=r}if(n)return void t.log("Discard a command.");for(var i in Te.getInstance().channelHandlers){Te.getInstance().channelHandlers[i].onMessageDeleted(e,T)}})}}},f=function(e){var n=new j(e.getJsonElement());switch(n.category){case z.CATEGORY_USER_BLOCK:case z.CATEGORY_USER_UNBLOCK:var t=n.data.blocker.user_id,r=n.data.blockee.user_id;Object.keys(K.cachedChannels).forEach(function(e){var i=K.cachedChannels[e];try{Te.getInstance().getCurrentUserId()===t?i.memberMap[r].isBlockedByMe=n.category===z.CATEGORY_USER_BLOCK:Te.getInstance().getCurrentUserId()===r&&(i.memberMap[t].isBlockingMe=n.category===z.CATEGORY_USER_BLOCK)}catch(e){}});break;case z.CATEGORY_FRIEND_DISCOVERED:var i=n.data.friend_discoveries,a=i.map(function(e){return new Q(e)});for(var s in Te.getInstance().userEventHandlers){Te.getInstance().userEventHandlers[s].onFriendsDiscovered(a)}}},_=function(e){var n=e.getJsonElement(),r=new j(n);switch(r.category){case j.CATEGORY_CHANNEL_JOIN:case j.CATEGORY_CHANNEL_LEAVE:K.getChannel(r.channelUrl,function(i,a){if(O){var s=i;i=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+r.category);var o=r.data.hasOwnProperty("member_count")?r.data.member_count:null,l=r.data.hasOwnProperty("joined_member_count")?r.data.joined_member_count:null;if(r.category===j.CATEGORY_CHANNEL_JOIN){(r.data.hasOwnProperty("users")?r.data.users:function(e){return e.state=X.JOINED,[e]}(r.data)).forEach(function(e){!function(e,t,r){i.isSuper?i.setLatestMemberCount(t,r,n.ts):(e.state=X.JOINED,i.addMember(new X(e)),i.updateJoinedMemberCount());var a=new Q(e);a.userId===Te.getInstance().getCurrentUserId()&&(i.myMemberState="joined",K.cachedChannels[i.url]=i);for(var s in Te.getInstance().channelHandlers){Te.getInstance().channelHandlers[s].onUserJoined(i,a)}}(e,o,l)})}else{var u=new Q(r.data);u.userId===Te.getInstance().getCurrentUserId()?(i.isPublic||K.removeCachedChannel(r.channelUrl),i.myMemberState="none",i.invitedAt=0,R(i,0,0)):K.cachedChannels[i.url]=i,i.isSuper?i.setLatestMemberCount(o,l,n.ts):(i.removeMember(u),i.updateJoinedMemberCount());for(var c in Te.getInstance().channelHandlers){Te.getInstance().channelHandlers[c].onUserLeft(i,u)}}});break;case j.CATEGORY_CHANNEL_INVITE:K.getChannel(r.channelUrl,function(i,a){if(O){var s=i;i=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+r.category);var o=null;r.data&&r.data.inviter&&!g(r.data.inviter)&&(o=new Q(r.data.inviter));for(var l=[],u=0;um.ts){if(m.all=e.unread_cnt.all>=0?e.unread_cnt.all:0,e.unread_cnt.custom_types)for(var t in e.unread_cnt.custom_types)m.custom_types[t]=e.unread_cnt.custom_types[t];m.ts=n}}};this.getSubscribedTotalUnreadMessageCount=function(){return m.all>=0?m.all:0},this.getSubscribedCustomTypeTotalUnreadMessageCount=function(){if(Object.keys(m.custom_types).length>0){var e=0;for(var n in m.custom_types)e+=m.custom_types[n];return e}return 0},this.getSubscribedCustomTypeUnreadMessageCount=function(e){return e&&"string"==typeof e&&m.custom_types.hasOwnProperty(e)?m.custom_types[e]:0},this.getMyPushTokensByToken=function(e,n,t){if("string"!=typeof e||["gcm","apns","apns_voip"].indexOf(n)<0)return void L(null,new y("Invalid parameters.",U.INVALID_PARAMETER),t);ge.getInstance().getPushTokens(null,e,n,function(e,n){if(n)return void L(null,n,t);var r=e.device_tokens,i=e.type,a=e.has_more,s=e.token;L({deviceTokens:r,type:i?i.toLowerCase():"unknown",hasMore:a,token:s},null,t)})},this.setPushTemplate=function(e,n){if(!e||e!==this.PUSH_TEMPLATE_DEFAULT&&e!==this.PUSH_TEMPLATE_ALTERNATIVE)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n);ge.getInstance().setPushTemplate(e,function(e,t){if(t)return void L(null,t,n);var r=e.name.toString();L(r,null,n)})},this.getPushTemplate=function(e){ge.getInstance().getPushTemplate(function(n,t){if(t)return void L(null,t,e);var r=n.name.toString();L(r,null,e)})},this.setChannelInvitationPreference=function(e,n){"boolean"!=typeof e&&L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n),ge.getInstance().setChannelInvitationPreference(e,function(e,t){if(t)return void L(null,t,n);L({autoAccept:e.auto_accept},null,n)})},this.getChannelInvitationPreference=function(e){ge.getInstance().getChannelInvitationPreference(function(n,t){if(t)return void L(null,t,e);L({autoAccept:n.auto_accept},null,e)})},this.getMyGroupChannelChangeLogsByTimestamp=function(e,n,t,r){if("function"==typeof n?(r=n,n=null,t=null):"function"==typeof t&&(r=t,t=null),"number"!=typeof e||e<0||null!==n&&!Array.isArray(n)||null!==t&&"boolean"!=typeof t)return void L(null,new y("Invalid parameters.",U.INVALID_PARAMETER),r);ge.getInstance().getMyGroupChannelChangeLogs(e,null,n,t,function(e,n){if(n)return void L(null,n,r);var t=e.updated.map(function(e){return new K(e)}),i=e.deleted,a=e.has_more,s=e.next;L({updatedChannels:t,deletedChannelUrls:i,hasMore:a,token:s},null,r)})},this.getMyGroupChannelChangeLogsByToken=function(e,n,t,r){if("function"==typeof n?(r=n,n=null,t=null):"function"==typeof t&&(r=t,t=null),"string"!=typeof e&&null!==e||null!==n&&!Array.isArray(n)||null!==t&&"boolean"!=typeof t)return void L(null,new y("Invalid parameters.",U.INVALID_PARAMETER),r);ge.getInstance().getMyGroupChannelChangeLogs(0,e,n,t,function(e,n){if(n)return void L(null,n,r);var t=e.updated.map(function(e){return new K(e)}),i=e.deleted,a=e.has_more,s=e.next;L({updatedChannels:t,deletedChannelUrls:i,hasMore:a,token:s},null,r)})},this.connect=function(){p&&p.start();var e=Array.prototype.slice.call(arguments),n=null,i=null,a=null;switch("function"==typeof e.slice(-1)[0]&&(a=e.pop()),e.length){case 1:n=e[0];break;case 2:n=e[0],i=e[1];break;case 3:n=e[0],this.customApiHost=e[1],this.customWsHost=e[2];break;case 4:n=e[0],i=e[1],this.customApiHost=e[2],this.customWsHost=e[3];break;default:r&&t.log("sb.connect args length error: ",arguments)}n&&0!==n.length?(Te.getInstance().connecting=!0,Te.getInstance().reconnecting=!1,Te.getInstance().isReconnectingOnError=!1,Te.getInstance().reconnectTimer&&(clearTimeout(Te.getInstance().reconnectTimer),Te.getInstance().reconnectTimer=null,Te.getInstance().onReconnectTimerCancel=null),Te.getInstance().getConnectionState()===this.ConnectionState.OPEN&&Te.getInstance().getCurrentUserId()===n?(Te.getInstance().connecting=!1,L(Te.getInstance().currentUser,null,a)):(Te.getInstance().connectionCallback.push(a),1===Te.getInstance().connectionCallback.length&&(H(!0,null,null),J(n,i)))):L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),a)};var N=!1,C=!1,T=!0;this.setBackgroundState=function(){if(!N&&T)if(N=!0,this.getConnectionState()!==this.ConnectionState.CLOSED){C=!0;var e=new y("Websocket connection failed.",U.WEBSOCKET_CONNECTION_FAILED);H(!1,null,e)}else C=!1},this.setForegroundState=function(){N&&T&&(N=!1,C&&this.currentUser&&(D=0,F(this.getCurrentUserId(),!0)))},this.disableStateChange=function(){T=!1},this.enableStateChange=function(){T=!0},this.disconnect=function(e){p&&p.stop();var n=new y("Connection has been canceled.",U.CONNECTION_CANCELED);H(!0,e,n)},this.reconnect=function(){if(!ge.getInstance().sessionKey||!this.currentUser)return!1;var e=!0;D>0&&(e=!1);var n=new y("Connection has been canceled.",U.CONNECTION_CANCELED);return H(!1,null,n),D=0,F(this.getCurrentUserId(),e),!0};var H=function(e,n,t){var r=Te.getInstance();r.loginTimer&&(clearTimeout(r.loginTimer),r.onLoginTimerCancel&&(r.onLoginTimerCancel(),r.onLoginTimerCancel=null),r.loginTimer=null),r.reconnectTimer&&(clearTimeout(r.reconnectTimer),r.onReconnectTimerCancel&&(r.onReconnectTimerCancel(),r.onReconnectTimerCancel=null),r.reconnectTimer=null),r.wsClient&&(D=0,r.wsClient.disconnect(!0),r.wsClient=null),function(){if(e){B.clearEnteredChannels(),B.clearCache(),K.clearCache(),r.globalTimer&&(clearInterval(r.globalTimer),r.globalTimer=null);for(var i in r._ackStateMap)clearTimeout(r._ackStateMap[i].timer);r._ackStateMap={},r.currentUser=null,ge.getInstance().sessionKey=null,ge.getInstance().ekey=null}t&&(l(null,t),r.connecting=!1,r.reconnecting=!1,r.isReconnectingOnError=!1),L(null,null,n)}()},F=function(e,n){if(Te.getInstance().reconnecting=!0,Te.getInstance().reconnectTimer)r&&t.log("still reconnecting");else{if((D+=1)<=1){if(n)for(var i in Te.getInstance().connectionHandlers){var a=Te.getInstance().connectionHandlers[i];a.onReconnectStarted()}b=0}else b=Math.min(1e3*h.interval*Math.pow(h.multiplier,D-2),h.maxInterval>0?1e3*h.maxInterval:Number.MAX_SAFE_INTEGER);if(!e||!ge.getInstance().sessionKey||D>h.retryCount&&h.retryCount>0){var s=new y("Websocket connection failed.",U.WEBSOCKET_CONNECTION_FAILED);H(!1,null,s),D=0;for(var i in Te.getInstance().connectionHandlers){var a=Te.getInstance().connectionHandlers[i];a.onReconnectFailed()}return Te.getInstance().connecting=!1,Te.getInstance().reconnecting=!1,Te.getInstance().isReconnectingOnError=!1,void Te.getInstance().ConnectionManager.errorAllReadyHandler()}Te.getInstance().onReconnectTimerCancel=function(){D=0},Te.getInstance().reconnectTimer=setTimeout(function(){Te.getInstance().reconnectTimer=null,Te.getInstance().onReconnectTimerCancel=null,Te.getInstance().wsClient&&Te.getInstance().wsClient.disconnect(!0);var n=new Ie.WSClientHandler;Te.getInstance().wsClient=new Ie(n),Te.getInstance().loginHandler=function(e){D=0,Te.getInstance().connecting=!1,Te.getInstance().reconnecting=!1,Te.getInstance().isReconnectingOnError=!1;for(var n in Te.getInstance().connectionHandlers){Te.getInstance().connectionHandlers[n].onReconnectSucceeded()}if(Te.getInstance().ConnectionManager.processAllReadyHandler(null),Te.getInstance().isReconnectingOnError)for(var n in Te.getInstance().ConnectionManager.networkHandlers)Te.getInstance().ConnectionManager.networkHandlers[n].onReconnected();var t=[];for(var n in B.enteredChannels)t.push(n);for(var r=0;r23||t<0||t>59||r<0||r>23||i<0||i>59)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),s);ge.getInstance().setDoNotDisturb(e,n,t,r,i,a,function(e,n){if(n)return void L(null,n,s);var t={doNotDisturbOn:e.do_not_disturb,startHour:e.start_hour,startMin:e.start_min,endHour:e.end_hour,endMin:e.end_min,timezone:e.timezone};L(t,null,s)})},this.getDoNotDisturb=function(e){ge.getInstance().getDoNotDisturb(function(n,t){if(t)return void L(null,t,e);var r={doNotDisturbOn:n.do_not_disturb,startHour:n.start_hour,startMin:n.start_min,endHour:n.end_hour,endMin:n.end_min,timezone:n.timezone};L(r,null,e)})},this.setSnoozePeriod=function(e,n,t,r){if("boolean"!=typeof e||"number"!=typeof n||"number"!=typeof t||n<0||t<0||n>=t)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),r);ge.getInstance().setSnoozePeriod(e,n,t,function(e,n){if(n)return void L(null,n,r);var t={isSnoozeOn:e.snooze_enabled,startTs:e.snooze_start_ts,endTs:e.snooze_end_ts};L(t,null,r)})},this.getSnoozePeriod=function(e){ -ge.getInstance().getSnoozePeriod(function(n,t){if(t)return void L(null,t,e);var r={isSnoozeOn:n.snooze_enabled,startTs:n.snooze_start_ts,endTs:n.snooze_end_ts};L(r,null,e)})},this.blockUser=function(e,n){if("object"!=typeof e)return void L(null,new y("You have to pass user object.",U.INVALID_PARAMETER),n);this.blockUserWithUserId(e.userId,n)},this.blockUserWithUserId=function(e,n){if(this.getCurrentUserId()===e)return void L(null,new y("You cannot block yourself.",U.INVALID_PARAMETER),n);ge.getInstance().blockUser(e,function(e,t){if(t)return void L(null,t,n);L(new Q(e),null,n)})},this.unblockUser=function(e,n){if("object"!=typeof e)return void L(null,new y("You have to pass user object.",U.INVALID_PARAMETER),n);this.unblockUserWithUserId(e.userId,n)},this.unblockUserWithUserId=function(e,n){if(this.getCurrentUserId()===e)return void L(null,new y("You cannot unblock yourself.",U.INVALID_PARAMETER),n);ge.getInstance().unblockUser(e,function(e,t){if(t)return void L(null,t,n);L(null,null,n)})},this.addFriends=function(e,n){if(!Array.isArray(e))return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n);ge.getInstance().addFriends(e,function(e,t){if(t)return void L(null,t,n);var r=e.users.map(function(e){return new Q(e)});L(r,null,n)})},this.deleteFriends=function(e,n){if(!Array.isArray(e))return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n);ge.getInstance().deleteFriends(e,function(e,t){if(t)return void L(null,t,n);L(e,null,n)})},this.deleteFriend=function(e,n){if("string"!=typeof e)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n);this.deleteFriends([e],n)},this.uploadFriendDiscoveries=function(e,n){for(var t=!0,r=0;r0&&(this._inviteUserIds=this._inviteUserIds.concat(t))}},this.addUser=function(e){e.hasOwnProperty("userId")&&this._inviteUserIds.push(e.userId)},this.addUserIds=function(e){if(Array.isArray(e)){for(var n=e.length,t=[],r=0;r0&&(this._inviteUserIds=this._inviteUserIds.concat(t))}},this.addUserId=function(e){"string"==typeof e&&this._inviteUserIds.push(e)}},ve=function(){};ve.MentionType={USERS:"users",CHANNEL:"channel"},ve.PushNotificationDeliveryOption={DEFAULT:"default",SUPPRESS:"suppress"};var Ne=function(){this._message=null,Ae(this,"_message","message","string"),this._translationTargetLanguages=null,f?this.translationTargetLanguages=this._translationTargetLanguages:Object.defineProperty(this,"translationTargetLanguages",{get:function(){return this._translationTargetLanguages},set:function(e){if(Array.isArray(e)){for(var n=0;n=1&&this._month<=12&&"number"==typeof this._day&&this._day>=1&&this._day<=31&&"number"==typeof this._hour&&this._hour>=0&&this._hour<=24&&"number"==typeof this._min&&this._min>=0&&this._min<=60&&"string"==typeof this._timezone&&this._timezone.length>0?this._year.toString()+"-"+("0"+this._month.toString()).substr(-2)+"-"+("0"+this._day.toString()).substr(-2)+" "+("0"+this._hour.toString()).substr(-2)+":"+("0"+this._min.toString()).substr(-2):null},set:function(e){e&&"string"==typeof e&&(this._scheduledDateTimeString=e)}}),this.setSchedule=function(e,n,t,r,i,a){"number"==typeof e&&4===e.toString().length&&"number"==typeof n&&n>=1&&n<=12&&"number"==typeof t&&t>=1&&t<=31&&"number"==typeof r&&r>=0&&r<=24&&"number"==typeof i&&i>=0&&i<=60&&"string"==typeof a&&a.length>0&&(this.scheduledDateTimeString=e.toString()+"-"+("0"+n.toString()).substr(-2)+"-"+("0"+t.toString()).substr(-2)+" "+("0"+r.toString()).substr(-2)+":"+("0"+i.toString()).substr(-2),this.timezone=a)},this._getScheduleString=function(){return this.scheduledDateTimeString?this.scheduledDateTimeString+" "+this.timezone:"number"==typeof this.year&&4===this.year.toString().length&&"number"==typeof this.month&&this.month>=1&&this.month<=12&&"number"==typeof this.day&&this.day>=1&&this.day<=31&&"number"==typeof this.hour&&this.hour>=0&&this.hour<=24&&"number"==typeof this.min&&this.min>=0&&this.min<=60&&"string"==typeof this.timezone&&this.timezone.length>0?this.year.toString()+"-"+("0"+this.month.toString()).substr(-2)+"-"+("0"+this.day.toString()).substr(-2)+" "+("0"+this.hour.toString()).substr(-2)+":"+("0"+this.min.toString()).substr(-2)+" "+this.timezone:null},this._update=function(e){e.hasOwnProperty("message")&&(this.message=e.message),e.hasOwnProperty("year")&&(this.year=e.year),e.hasOwnProperty("month")&&(this.month=e.month),e.hasOwnProperty("day")&&(this.day=e.day),e.hasOwnProperty("hour")&&(this.hour=e.hour),e.hasOwnProperty("min")&&(this.min=e.min),e.hasOwnProperty("timezone")&&(this.timezone=e.timezone)},e&&this._update(e)},Se=function(){this.networkHandlers={},this.authenticateTimer=1e4,this.authInfoRequester=null;var e=0,n=[],t=new y("Connection should be made first.",U.CONNECTION_REQUIRED),r=new y("Invalid parameter.",U.INVALID_PARAMETER);this.addReadyHandler=function(e){e&&"function"==typeof e&&n.push(e)},this.ready=function(e,n){var t=ge.getInstance().sessionKey,r=Te.getInstance();return n&&t?void(e&&(e(r.currentUser,null),r.getConnectionState()!==r.ConnectionState.CLOSED||r.isBackgroundState()||r.reconnect())):(this.addReadyHandler(e),r.isReconnectingOnError?void this.errorAllReadyHandler():void(r.getConnectionState()===r.ConnectionState.OPEN?this.processAllReadyHandler(null):r.getConnectionState()===r.ConnectionState.CONNECTING||this.errorAllReadyHandler()))},this.processAllReadyHandler=function(e){if(n.length>0){var t=n;n=[],t.forEach(function(n){n&&"function"==typeof n&&n(Te.getInstance().currentUser,e)}),t=[]}},this.errorAllReadyHandler=function(){this.processAllReadyHandler(t)},this.NetworkHandler=function(){this.onReconnected=function(){}},this.addNetworkHandler=function(e,n){this.networkHandlers[e]=n},this.removeNetworkHandler=function(e){delete this.networkHandlers[e]},this.removeAllNetworkHandler=function(){this.networkHandlers={}},this.authenticate=function(n){var i=this,a=Te.getInstance();if(a.getConnectionState()===a.ConnectionState.OPEN||a.reconnecting)a.connecting=!1,L(a.currentUser,null,n);else if(i.authInfoRequester&&"function"==typeof i.authInfoRequester){a.connecting=!0,e++;var s=setTimeout(function(){s=null,e--,0===e&&0===a.connectionCallback.length&&(a.connecting=!1),i.errorAllReadyHandler(),L(null,t,n)},i.authenticateTimer);i.authInfoRequester(function(t){if(s){clearTimeout(s),s=null,e--;var i=function(e,t){a.connecting=!1,t?L(null,new y(t.message,t.code),n):L(e,null,n)};t&&t.hasOwnProperty("userId")?t.apiHost&&t.wsHost?a.connect(t.userId,t.accessToken,t.apiHost,t.wsHost,i):a.connect(t.userId,t.accessToken,i):L(null,r,n)}})}else L(null,r,n)}},Ue=function(e,n){this.key=e,this.value=n};Ue.prototype.encode=function(){return{key:this.key,value:this.value}};var Te=function(e){var n=Te.getInstance();if(n)return n;try{if(!e.hasOwnProperty("appId"))return t.log("Must be set appId"),null}catch(e){return t.log("Must be set appId"),null}this.connecting=!1,this.reconnecting=!1,this.isReconnectingOnError=!1,this.ConnectionManager=new Se,this.GCMPushToken="",this.APNSPushToken="",this.PUSH_TEMPLATE_DEFAULT="default",this.PUSH_TEMPLATE_ALTERNATIVE="alternative",this.isSessionOpened=!1,this.pushTokenRegistrationState={SUCCESS:"success",PENDING:"pending",ERROR:"error"},this.PushTriggerOption={ALL:"all",MENTION_ONLY:"mention_only",OFF:"off"},this.loginTimer,this.onLoginTimerCancel,this.globalTimer,this.reconnectTimer,this.onReconnectTimerCancel,this.currentUser=null,this.getCurrentUserId=function(){return Te.getInstance().currentUser?Te.getInstance().currentUser.userId:null},this.wsClient,this.ConnectionState={CONNECTING:"CONNECTING",OPEN:"OPEN",CLOSING:"CLOSING",CLOSED:"CLOSED"},this.connectionState=this.ConnectionState,this._connectedAt=0,this.getLastConnectedAt=function(){var e=this;return e.getConnectionState()===e.ConnectionState.OPEN&&e.currentUser?e._connectedAt:0},this.BaseChannel=v,this.User=Q,this.Member=X,this.OpenChannel=B,this.GroupChannel=K,this.UserMessage=G,this.MessageRequestState=k,this.FileMessage=q,this.AdminMessage=w,this.GroupChannelListQuery=ne,this.MessageMetaArray=Ue,this.userEventHandlers={},this.channelHandlers={},this.connectionHandlers={},this.connectionCallback=[];var l=function(e,n){var t=Te.getInstance().connectionCallback;Te.getInstance().connectionCallback=[],t.forEach(function(t){L(e,n,t)}),t=[]};this.GroupChannelParams=ye,this.BaseMessageParams=ve,this.FileMessageParams=Ce,this.UserMessageParams=Ne,this.ScheduledUserMessageParams=Re,this.GroupChannelTotalUnreadMessageCountParams=x,this._ackStateMap={},M=e.appId,Pe=this,me=ge.getInstance(),me||(me=new ge),this.Options={_useMemberAsMessageSender:!0,get UseMemberAsMessageSender(){return this._useMemberAsMessageSender},set UseMemberAsMessageSender(e){"boolean"==typeof e&&(this._useMemberAsMessageSender=e)},get useMemberAsMessageSender(){return this._useMemberAsMessageSender},set useMemberAsMessageSender(e){"boolean"==typeof e&&(this._useMemberAsMessageSender=e)},_typingIndicatorThrottle:1e3,get typingIndicatorThrottle(){return this._typingIndicatorThrottle},set typingIndicatorThrottle(e){"number"==typeof e&&e>=s&&e<=o&&(this._typingIndicatorThrottle=e)}},this.customApiHost=null,this.customWsHost=null,this.UserEventHandler=function(){this.onFriendsDiscovered=function(e){}},this.addUserEventHandler=function(e,n){Te.getInstance().userEventHandlers[e]=n},this.removeUserEventHandler=function(e){delete Te.getInstance().userEventHandlers[e]},this.removeAllUserEventHandler=function(){Te.getInstance().userEventHandlers={}},this.ChannelHandler=function(){this.onMessageReceived=function(e,n){},this.onMessageUpdated=function(e,n){},this.onMessageDeleted=function(e,n){},this.onReadReceiptUpdated=function(e){},this.onTypingStatusUpdated=function(e){},this.onUserJoined=function(e,n){},this.onUserLeft=function(e,n){},this.onUserEntered=function(e,n){},this.onUserExited=function(e,n){},this.onUserMuted=function(e,n){},this.onUserUnmuted=function(e,n){},this.onUserBanned=function(e,n){},this.onUserUnbanned=function(e,n){},this.onChannelFrozen=function(e){},this.onChannelUnfrozen=function(e){},this.onChannelChanged=function(e){},this.onChannelDeleted=function(e,n){},this.onUserReceivedInvitation=function(e,n,t){},this.onUserDeclinedInvitation=function(e,n,t){},this.onMetaDataCreated=function(e,n){},this.onMetaDataUpdated=function(e,n){},this.onMetaDataDeleted=function(e,n){},this.onMetaCountersCreated=function(e,n){},this.onMetaCountersUpdated=function(e,n){},this.onMetaCountersDeleted=function(e,n){},this.onChannelHidden=function(e){},this.onMentionReceived=function(e,n){}},this.addChannelHandler=function(e,n){Te.getInstance().channelHandlers[e]=n},this.removeChannelHandler=function(e){delete Te.getInstance().channelHandlers[e]},this.removeAllChannelHandlers=function(){Te.getInstance().channelHandlers={}},this.ConnectionHandler=function(){this.onReconnectStarted=function(){},this.onReconnectSucceeded=function(){},this.onReconnectFailed=function(){}},this.addConnectionHandler=function(e,n){Te.getInstance().connectionHandlers[e]=n},this.removeConnectionHandler=function(e){delete Te.getInstance().connectionHandlers[e]},this.removeAllConnectionHandlers=function(){Te.getInstance().connectionHandlers={}},this.createUserListQuery=function(e){var n=new de;return e&&(n.userIds=e),n},this.createApplicationUserListQuery=function(){return new se},this.createBlockedUserListQuery=function(){return new oe},this.getApplicationId=function(){return M},this.getDebugMode=function(){return r},this.setDebugMode=function(e){r=e},this.setAPIHost=function(e){a=e},this.setWSHost=function(e){i=e},this.clearCurrentApiHost=function(){this.customApiHost=null},this.getCurrentApiHost=function(){return this.customApiHost?this.customApiHost:a},this.clearCurrentWsHost=function(){this.customWsHost=null},this.getCurrentWsHost=function(){return this.customWsHost?this.customWsHost:i},this.setErrorFirstCallback=function(e){O=e},this.getErrorFirstCallback=function(){return O},this.getConnectionState=function(){try{if(Te.getInstance()){var e=Te.getInstance();return e.connecting||e.reconnecting?e.ConnectionState.CONNECTING:e.wsClient?e.connecting||e.reconnecting?e.ConnectionState.CONNECTING:e.isSessionOpened?e.wsClient.getConnectionState():e.ConnectionState.CLOSED:e.ConnectionState.CLOSED}return Te.getInstance().ConnectionState.CLOSED}catch(e){return Te.getInstance().ConnectionState.CLOSED}},this.hasLoggedIn=function(){return Te.getInstance().currentUser&&ge.getInstance().sessionKey};var u={};this._createFileQueue=function(e,n){return u.hasOwnProperty(e)||(u[e]=new V(e,n)),u[e]},this._getFileQueue=function(e){return u.hasOwnProperty(e)?u[e]:null},this._clearFileQueue=function(){u={}},this._deleteFileQueue=function(e){u.hasOwnProperty(e)&&delete u[e]},this._fileUploadRequest={},this.setPushTriggerOption=function(e,n){if([this.PushTriggerOption.ALL,this.PushTriggerOption.MENTION_ONLY,this.PushTriggerOption.OFF].indexOf(e)<0)return void L(null,new y("Invalid parameters.",U.INVALID_PARAMETER),n);ge.getInstance().setPushTriggerOption(e,function(e,t){if(t)return void L(null,t,n);L(e.push_trigger_option,null,n)})},this.getPushTriggerOption=function(e){ge.getInstance().getPushTriggerOption(function(n,t){if(t)return void L(null,t,e);e&&L(n.push_trigger_option,null,e)})};var c=function(e){var n=Te.getInstance();return n._ackStateMap.hasOwnProperty(e)?n._ackStateMap[e]:null},d=function(e){var n=(Te.getInstance(),new Z(e));"LOGI"===n.command&&(m={all:0,custom_types:{},ts:0}),A(n.getJsonElement());var r=n.requestId;if(r){var i=c(r);if(null==i)return;clearTimeout(i.timer);var a=i.handler;if(a)if("EROR"===n.command){var s=n.getJsonElement(),o=new y(s.message,s.code);a(null,o)}else a(n,null);try{delete Te.getInstance()._ackStateMap[n.requestId]}catch(e){}}else switch(_e&&"LOGI"!==n.command&&_e.start(),n.command){case"LOGI":if(Te.getInstance().loginTimer){clearTimeout(Te.getInstance().loginTimer),Te.getInstance().loginTimer=null,Te.getInstance().onLoginTimerCancel=null;var l=n.getJsonElement();if(l.hasOwnProperty("error")){Te.getInstance().isSessionOpened=!1;var u=l.code,d=l.message;Te.getInstance().loginHandler(null,new y(d,u))}else Te.getInstance().isSessionOpened=!0,l.hasOwnProperty("key")&&(ge.getInstance().sessionKey=l.key),l.hasOwnProperty("ekey")&&(ge.getInstance().ekey=l.ekey),l.hasOwnProperty("user_id")&&(Te.getInstance().currentUser=new Q(l)),l.hasOwnProperty("ping_interval")&&"number"==typeof l.ping_interval&&l.ping_interval>0&&(he=1e3*l.ping_interval),l.hasOwnProperty("pong_timeout")&&"number"==typeof l.pong_timeout&&l.pong_timeout>0&&(pe=1e3*l.pong_timeout),l.hasOwnProperty("reconnect")&&"object"==typeof l.reconnect&&(h={interval:l.reconnect.interval||3,maxInterval:l.reconnect.max_interval||24,retryCount:l.reconnect.retry_cnt||3,multiplier:l.reconnect.mul||2}),l.hasOwnProperty("login_ts")&&"number"==typeof l.login_ts&&(Te.getInstance()._connectedAt=l.login_ts),_e&&_e.start(),Te.getInstance().loginHandler(Te.getInstance().currentUser,null);Te.getInstance().connecting=!1,Te.getInstance().reconnecting=!1}break;case"MESG":case"FILE":case"BRDM":case"ADMM":var p="",I=!1;if("MESG"===n.command?p=new G(n.getJsonElement()):"FILE"===n.command?p=new q(n.getJsonElement()):(p=new w(n.getJsonElement()),n.getJsonElement().hasOwnProperty("silent")&&(I=n.getJsonElement().silent)),!p)return;if(p.isGroupChannel()){var g=K.cachedChannels.hasOwnProperty(p.channelUrl);K.getChannel(p.channelUrl,function(e,n){if(O){var t=e;e=n,n=t}if(n)return void(a&&a(null,n));if(e.isHidden=!1,e.hiddenState=K.HiddenState.UNHIDDEN,K.cachedChannels[e.url]=e,p._sender&&e.memberMap.hasOwnProperty(p._sender.userId)){var r=e.memberMap[p._sender.userId];r.nickname!==p._sender.nickname&&(r.nickname=p._sender.nickname),r.profileUrl!==p._sender.profileUrl&&(r.profileUrl=p._sender.profileUrl),S(r.metaData,p._sender.metaData)||(r.metaData=p._sender.metaData),r.isBlockedByMe!==p._sender.isBlockedByMe&&(r.isBlockedByMe=p._sender.isBlockedByMe)}var i=Te.getInstance().currentUser;i&&p._sender&&i.userId===p._sender.userId&&(i.nickname!==p._sender.nickname&&(i.nickname=p._sender.nickname),i.profileUrl!==p._sender.profileUrl&&(i.profileUrl=p._sender.profileUrl),S(i.metaData,p._sender.metaData)||(i.metaData=p._sender.metaData));var s=!1;if(p.mentionType===ve.MentionType.CHANNEL)p.sender&&p.sender.userId===Te.getInstance().getCurrentUserId()||(s=!0);else if(p.mentionType===ve.MentionType.USERS)for(var o=0;o=p.createAt,o=Te.getInstance().currentUser;o&&p._sender&&o.userId===p._sender.userId&&(o.nickname!==p._sender.nickname&&(o.nickname=p._sender.nickname),o.profileUrl!==p._sender.profileUrl&&(o.profileUrl=p._sender.profileUrl),S(o.metaData,p._sender.metaData)||(o.metaData=p._sender.metaData));var l=!1,u=n.getJsonElement();if((!p.sender||p.sender.userId!==Te.getInstance().getCurrentUserId())&&!s&&u&&u.hasOwnProperty("old_values")){var c=u.old_values.mention_type||p.mentionType,d=u.old_values.mentioned_user_ids||p.mentionedUsers.map(function(e){return e.userId});if(c===ve.MentionType.USERS&&p.mentionType===ve.MentionType.USERS){for(var h=!1,f=!1,_=0;_0||e.unreadMentionCount>0)&&(R(e,0,0),0===e.unreadMessageCount||0===e.unreadMentionCount))for(var r in Te.getInstance().channelHandlers){var i=Te.getInstance().channelHandlers[r];i.onChannelChanged(e)}}else if(0===e.unreadMessageCount||0===e.unreadMentionCount)for(var r in Te.getInstance().channelHandlers){var i=Te.getInstance().channelHandlers[r];i.onChannelChanged(e)}}else for(var r in Te.getInstance().channelHandlers){var i=Te.getInstance().channelHandlers[r];i.onReadReceiptUpdated(e)}});break;case"TPST":case"TPEN":case"MTIO":break;case"SYEV":_(n);break;case"USEV":f(n);break;case"DELM":var N=n.getJsonElement(),C=String(N.channel_type),U=String(N.channel_url),T=String(N.msg_id);switch(C){case Y.CHANNEL_TYPE_OPEN:B.getChannel(U,function(e,n){if(O){var r=e;e=n,n=r}if(n)return void t.log("Discard a command.");for(var i in Te.getInstance().channelHandlers){Te.getInstance().channelHandlers[i].onMessageDeleted(e,T)}});break;case Y.CHANNEL_TYPE_GROUP:K.getChannel(U,function(e,n){if(O){var r=e;e=n,n=r}if(n)return void t.log("Discard a command.");for(var i in Te.getInstance().channelHandlers){Te.getInstance().channelHandlers[i].onMessageDeleted(e,T)}})}}},f=function(e){var n=new j(e.getJsonElement());switch(n.category){case z.CATEGORY_USER_BLOCK:case z.CATEGORY_USER_UNBLOCK:var t=n.data.blocker.user_id,r=n.data.blockee.user_id;Object.keys(K.cachedChannels).forEach(function(e){var i=K.cachedChannels[e];try{Te.getInstance().getCurrentUserId()===t?i.memberMap[r].isBlockedByMe=n.category===z.CATEGORY_USER_BLOCK:Te.getInstance().getCurrentUserId()===r&&(i.memberMap[t].isBlockingMe=n.category===z.CATEGORY_USER_BLOCK)}catch(e){}});break;case z.CATEGORY_FRIEND_DISCOVERED:var i=n.data.friend_discoveries,a=i.map(function(e){return new Q(e)});for(var s in Te.getInstance().userEventHandlers){Te.getInstance().userEventHandlers[s].onFriendsDiscovered(a)}}},_=function(e){var n=e.getJsonElement(),r=new j(n);switch(r.category){case j.CATEGORY_CHANNEL_JOIN:case j.CATEGORY_CHANNEL_LEAVE:K.getChannel(r.channelUrl,function(i,a){if(O){var s=i;i=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+r.category);var o=r.data.hasOwnProperty("member_count")?r.data.member_count:null,l=r.data.hasOwnProperty("joined_member_count")?r.data.joined_member_count:null;if(r.category===j.CATEGORY_CHANNEL_JOIN){(r.data.hasOwnProperty("users")?r.data.users:function(e){return e.state=X.JOINED,[e]}(r.data)).forEach(function(e){!function(e,t,r){i.isSuper?i.setLatestMemberCount(t,r,n.ts):(e.state=X.JOINED,i.addMember(new X(e)),i.updateJoinedMemberCount());var a=new Q(e);a.userId===Te.getInstance().getCurrentUserId()&&(i.myMemberState="joined",K.cachedChannels[i.url]=i);for(var s in Te.getInstance().channelHandlers){Te.getInstance().channelHandlers[s].onUserJoined(i,a)}}(e,o,l)})}else{var u=new Q(r.data);u.userId===Te.getInstance().getCurrentUserId()?(i.isPublic||K.removeCachedChannel(r.channelUrl),i.myMemberState="none",i.invitedAt=0,R(i,0,0)):K.cachedChannels[i.url]=i,i.isSuper?i.setLatestMemberCount(o,l,n.ts):(i.removeMember(u),i.updateJoinedMemberCount());for(var c in Te.getInstance().channelHandlers){Te.getInstance().channelHandlers[c].onUserLeft(i,u)}}});break;case j.CATEGORY_CHANNEL_INVITE:K.getChannel(r.channelUrl,function(i,a){if(O){var s=i;i=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+r.category);var o=null;r.data&&r.data.inviter&&!g(r.data.inviter)&&(o=new Q(r.data.inviter));for(var l=[],u=0;um.ts){if(m.all=e.unread_cnt.all>=0?e.unread_cnt.all:0,e.unread_cnt.custom_types)for(var t in e.unread_cnt.custom_types)m.custom_types[t]=e.unread_cnt.custom_types[t];m.ts=n}}};this.getSubscribedTotalUnreadMessageCount=function(){return m.all>=0?m.all:0},this.getSubscribedCustomTypeTotalUnreadMessageCount=function(){if(Object.keys(m.custom_types).length>0){var e=0;for(var n in m.custom_types)e+=m.custom_types[n];return e}return 0},this.getSubscribedCustomTypeUnreadMessageCount=function(e){return e&&"string"==typeof e&&m.custom_types.hasOwnProperty(e)?m.custom_types[e]:0},this.getMyPushTokensByToken=function(e,n,t){if("string"!=typeof e||["gcm","apns","apns_voip"].indexOf(n)<0)return void L(null,new y("Invalid parameters.",U.INVALID_PARAMETER),t);ge.getInstance().getPushTokens(null,e,n,function(e,n){if(n)return void L(null,n,t);var r=e.device_tokens,i=e.type,a=e.has_more,s=e.token;L({deviceTokens:r,type:i?i.toLowerCase():"unknown",hasMore:a,token:s},null,t)})},this.setPushTemplate=function(e,n){if(!e||e!==this.PUSH_TEMPLATE_DEFAULT&&e!==this.PUSH_TEMPLATE_ALTERNATIVE)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n);ge.getInstance().setPushTemplate(e,function(e,t){if(t)return void L(null,t,n);var r=e.name.toString();L(r,null,n)})},this.getPushTemplate=function(e){ge.getInstance().getPushTemplate(function(n,t){if(t)return void L(null,t,e);var r=n.name.toString();L(r,null,e)})},this.setChannelInvitationPreference=function(e,n){"boolean"!=typeof e&&L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n),ge.getInstance().setChannelInvitationPreference(e,function(e,t){if(t)return void L(null,t,n);L({autoAccept:e.auto_accept},null,n)})},this.getChannelInvitationPreference=function(e){ge.getInstance().getChannelInvitationPreference(function(n,t){if(t)return void L(null,t,e);L({autoAccept:n.auto_accept},null,e)})},this.getMyGroupChannelChangeLogsByTimestamp=function(e,n,t,r){if("function"==typeof n?(r=n,n=null,t=null):"function"==typeof t&&(r=t,t=null),"number"!=typeof e||e<0||null!==n&&!Array.isArray(n)||null!==t&&"boolean"!=typeof t)return void L(null,new y("Invalid parameters.",U.INVALID_PARAMETER),r);ge.getInstance().getMyGroupChannelChangeLogs(e,null,n,t,function(e,n){if(n)return void L(null,n,r);var t=e.updated.map(function(e){return new K(e)}),i=e.deleted,a=e.has_more,s=e.next;L({updatedChannels:t,deletedChannelUrls:i,hasMore:a,token:s},null,r)})},this.getMyGroupChannelChangeLogsByToken=function(e,n,t,r){if("function"==typeof n?(r=n,n=null,t=null):"function"==typeof t&&(r=t,t=null),"string"!=typeof e&&null!==e||null!==n&&!Array.isArray(n)||null!==t&&"boolean"!=typeof t)return void L(null,new y("Invalid parameters.",U.INVALID_PARAMETER),r);ge.getInstance().getMyGroupChannelChangeLogs(0,e,n,t,function(e,n){if(n)return void L(null,n,r);var t=e.updated.map(function(e){return new K(e)}),i=e.deleted,a=e.has_more,s=e.next;L({updatedChannels:t,deletedChannelUrls:i,hasMore:a,token:s},null,r)})},this.connect=function(){p&&p.start();var e=Array.prototype.slice.call(arguments),n=null,i=null,a=null;switch("function"==typeof e.slice(-1)[0]&&(a=e.pop()),e.length){case 1:n=e[0];break;case 2:n=e[0],i=e[1];break;case 3:n=e[0],this.customApiHost=e[1],this.customWsHost=e[2];break;case 4:n=e[0],i=e[1],this.customApiHost=e[2],this.customWsHost=e[3];break;default:r&&t.log("sb.connect args length error: ",arguments)}n&&0!==n.length?(Te.getInstance().connecting=!0,Te.getInstance().reconnecting=!1,Te.getInstance().isReconnectingOnError=!1,Te.getInstance().reconnectTimer&&(clearTimeout(Te.getInstance().reconnectTimer),Te.getInstance().reconnectTimer=null,Te.getInstance().onReconnectTimerCancel=null),Te.getInstance().getConnectionState()===this.ConnectionState.OPEN&&Te.getInstance().getCurrentUserId()===n?(Te.getInstance().connecting=!1,L(Te.getInstance().currentUser,null,a)):(Te.getInstance().connectionCallback.push(a),1===Te.getInstance().connectionCallback.length&&(H(!0,null,null),J(n,i)))):L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),a)};var N=!1,C=!1,T=!0;this.isBackgroundState=function(){return N},this.setBackgroundState=function(){if(!N&&T)if(N=!0,this.getConnectionState()!==this.ConnectionState.CLOSED){C=!0;var e=new y("Websocket connection failed.",U.WEBSOCKET_CONNECTION_FAILED);H(!1,null,e)}else C=!1},this.setForegroundState=function(){N&&T&&(N=!1,C&&this.currentUser&&(D=0,F(this.getCurrentUserId(),!0)))},this.disableStateChange=function(){T=!1},this.enableStateChange=function(){T=!0},this.disconnect=function(e){p&&p.stop();var n=new y("Connection has been canceled.",U.CONNECTION_CANCELED);H(!0,e,n)},this.reconnect=function(){if(!ge.getInstance().sessionKey||!this.currentUser)return!1;var e=!0;D>0&&(e=!1);var n=new y("Connection has been canceled.",U.CONNECTION_CANCELED);return H(!1,null,n),D=0,F(this.getCurrentUserId(),e),!0};var H=function(e,n,t){var r=Te.getInstance();r.loginTimer&&(clearTimeout(r.loginTimer),r.onLoginTimerCancel&&(r.onLoginTimerCancel(),r.onLoginTimerCancel=null),r.loginTimer=null),r.reconnectTimer&&(clearTimeout(r.reconnectTimer),r.onReconnectTimerCancel&&(r.onReconnectTimerCancel(),r.onReconnectTimerCancel=null),r.reconnectTimer=null),r.wsClient&&(D=0,r.wsClient.disconnect(!0),r.wsClient=null),function(){if(e){B.clearEnteredChannels(),B.clearCache(),K.clearCache(),r.globalTimer&&(clearInterval(r.globalTimer),r.globalTimer=null);for(var i in r._ackStateMap)clearTimeout(r._ackStateMap[i].timer);r._ackStateMap={},r.currentUser=null,ge.getInstance().sessionKey=null,ge.getInstance().ekey=null}t&&(l(null,t),r.connecting=!1,r.reconnecting=!1,r.isReconnectingOnError=!1),L(null,null,n)}()},F=function(e,n){if(Te.getInstance().reconnecting=!0,Te.getInstance().reconnectTimer)r&&t.log("still reconnecting");else{if((D+=1)<=1){if(n)for(var i in Te.getInstance().connectionHandlers){var a=Te.getInstance().connectionHandlers[i];a.onReconnectStarted()}b=0}else b=Math.min(1e3*h.interval*Math.pow(h.multiplier,D-2),h.maxInterval>0?1e3*h.maxInterval:Number.MAX_SAFE_INTEGER);if(!e||!ge.getInstance().sessionKey||D>h.retryCount&&h.retryCount>0){var s=new y("Websocket connection failed.",U.WEBSOCKET_CONNECTION_FAILED);H(!1,null,s),D=0;for(var i in Te.getInstance().connectionHandlers){var a=Te.getInstance().connectionHandlers[i];a.onReconnectFailed()}return Te.getInstance().connecting=!1,Te.getInstance().reconnecting=!1,Te.getInstance().isReconnectingOnError=!1,void Te.getInstance().ConnectionManager.errorAllReadyHandler()}Te.getInstance().onReconnectTimerCancel=function(){D=0},Te.getInstance().reconnectTimer=setTimeout(function(){Te.getInstance().reconnectTimer=null,Te.getInstance().onReconnectTimerCancel=null,Te.getInstance().wsClient&&Te.getInstance().wsClient.disconnect(!0);var n=new Ie.WSClientHandler;Te.getInstance().wsClient=new Ie(n),Te.getInstance().loginHandler=function(e){D=0,Te.getInstance().connecting=!1,Te.getInstance().reconnecting=!1,Te.getInstance().isReconnectingOnError=!1;for(var n in Te.getInstance().connectionHandlers){Te.getInstance().connectionHandlers[n].onReconnectSucceeded()}if(Te.getInstance().ConnectionManager.processAllReadyHandler(null),Te.getInstance().isReconnectingOnError)for(var n in Te.getInstance().ConnectionManager.networkHandlers)Te.getInstance().ConnectionManager.networkHandlers[n].onReconnected();var t=[];for(var n in B.enteredChannels)t.push(n);for(var r=0;r23||t<0||t>59||r<0||r>23||i<0||i>59)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),s);ge.getInstance().setDoNotDisturb(e,n,t,r,i,a,function(e,n){if(n)return void L(null,n,s);var t={doNotDisturbOn:e.do_not_disturb,startHour:e.start_hour,startMin:e.start_min,endHour:e.end_hour,endMin:e.end_min,timezone:e.timezone};L(t,null,s)})},this.getDoNotDisturb=function(e){ge.getInstance().getDoNotDisturb(function(n,t){if(t)return void L(null,t,e);var r={doNotDisturbOn:n.do_not_disturb,startHour:n.start_hour,startMin:n.start_min,endHour:n.end_hour,endMin:n.end_min,timezone:n.timezone};L(r,null,e)})},this.setSnoozePeriod=function(e,n,t,r){if("boolean"!=typeof e||"number"!=typeof n||"number"!=typeof t||n<0||t<0||n>=t)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),r);ge.getInstance().setSnoozePeriod(e,n,t,function(e,n){if(n)return void L(null,n,r);var t={isSnoozeOn:e.snooze_enabled,startTs:e.snooze_start_ts,endTs:e.snooze_end_ts};L(t,null,r)})}, +this.getSnoozePeriod=function(e){ge.getInstance().getSnoozePeriod(function(n,t){if(t)return void L(null,t,e);var r={isSnoozeOn:n.snooze_enabled,startTs:n.snooze_start_ts,endTs:n.snooze_end_ts};L(r,null,e)})},this.blockUser=function(e,n){if("object"!=typeof e)return void L(null,new y("You have to pass user object.",U.INVALID_PARAMETER),n);this.blockUserWithUserId(e.userId,n)},this.blockUserWithUserId=function(e,n){if(this.getCurrentUserId()===e)return void L(null,new y("You cannot block yourself.",U.INVALID_PARAMETER),n);ge.getInstance().blockUser(e,function(e,t){if(t)return void L(null,t,n);L(new Q(e),null,n)})},this.unblockUser=function(e,n){if("object"!=typeof e)return void L(null,new y("You have to pass user object.",U.INVALID_PARAMETER),n);this.unblockUserWithUserId(e.userId,n)},this.unblockUserWithUserId=function(e,n){if(this.getCurrentUserId()===e)return void L(null,new y("You cannot unblock yourself.",U.INVALID_PARAMETER),n);ge.getInstance().unblockUser(e,function(e,t){if(t)return void L(null,t,n);L(null,null,n)})},this.addFriends=function(e,n){if(!Array.isArray(e))return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n);ge.getInstance().addFriends(e,function(e,t){if(t)return void L(null,t,n);var r=e.users.map(function(e){return new Q(e)});L(r,null,n)})},this.deleteFriends=function(e,n){if(!Array.isArray(e))return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n);ge.getInstance().deleteFriends(e,function(e,t){if(t)return void L(null,t,n);L(e,null,n)})},this.deleteFriend=function(e,n){if("string"!=typeof e)return void L(null,new y("Invalid parameter.",U.INVALID_PARAMETER),n);this.deleteFriends([e],n)},this.uploadFriendDiscoveries=function(e,n){for(var t=!0,r=0;r"], "homepage": "https://github.com/sendbird/SendBird-SDK-JavaScript", "description": "SendBird JavaScript SDK", diff --git a/package.json b/package.json index 54799af..896de80 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sendbird", - "version": "3.0.107", + "version": "3.0.108", "description": "SendBird JavaScript SDK", "main": "SendBird.min.js", "dependencies": {