diff --git a/CHANGELOG.md b/CHANGELOG.md index e3e904e..a8b1434 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ Changelog ========= +## v3.0.46 + * Minor bug fixes. + ## v3.0.45 * Minor bug fixes. diff --git a/README.md b/README.md index f870c70..417d6d5 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ SendBird-SDK-JavaScript # [Documentation](https://docs.sendbird.com/javascript) -## Upgrading to v3.0.45 +## Upgrading to v3.0.46 If you want to check the record of other version, go to [Change Log](https://github.com/smilefam/SendBird-SDK-JavaScript/blob/master/CHANGELOG.md). * Minor bug fixes. diff --git a/SendBird.min.js b/SendBird.min.js index dfd82c7..4f942c1 100644 --- a/SendBird.min.js +++ b/SendBird.min.js @@ -1,8 +1,8 @@ /** * Copyright (c) 2016 SendBird DBA (Smile Family, Inc.) - * SendBird JavaScript SDK v3.0.45 + * SendBird JavaScript SDK v3.0.46 */ -!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()}(this,function(){function n(){this.oldIE=!0,this.boundary="--------FormData"+Math.random(),this._fields=[]}var t,r=!1,a="wss://ws.sendbird.com",s="https://api.sendbird.com";try{t=window.console||{log:function(){}}}catch(e){t={log:function(){}}}var i="undefined";try{i=navigator.userAgent.replace(/,/g,".")}catch(e){i="undefined"}var o,l="JS,"+i+",3.0.45,",u=function(){try{if(document&&9==document.documentMode)return!0}catch(e){return!1}return!1}(),c=function(){try{if(document&&document.documentMode<=8)return!0}catch(e){return!1}return!1}();if(u||c)"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=200&&i.status<400?d(null,JSON.parse(i.responseText),s):d({status:i.status,statusText:i.statusText,response:i.responseText},null,s)},i.onerror=function(){d({status:404,statusText:"There was a connection error"},null,s)};try{for(var l in a)i.setRequestHeader(l,a[l]?a[l]:"sendbird")}catch(e){}try{switch(r){case"get":case"GET":i.send();break;default:"undefined"!=typeof FormData&&FormData&&n instanceof FormData||void 0!==o&&o&&n instanceof o?n.oldIE?(i.setRequestHeader("Content-Type","multipart/form-data; boundary="+n.boundary),i.send(n.toString())):i.send(n):(i.setRequestHeader("Content-Type","application/json; charset=utf-8"),i.send(JSON.stringify(n)))}}catch(e){t.log("request.send() fail:"+e)}},S=!1,U=function(e,n,t){t&&"function"==typeof t&&(void 0===n&&(n=null),void 0===e&&(e=null),S?t(n,e):t(e,n))},T="",P=0,y=0,O=function(e){this.isOpenChannel=function(){return this.channelType==H.CHANNEL_TYPE_OPEN},this.isGroupChannel=function(){return this.channelType==H.CHANNEL_TYPE_GROUP},this.isUserMessage=function(){return this.messageType==O.MESSAGE_TYPE_USER},this.isAdminMessage=function(){return this.messageType==O.MESSAGE_TYPE_ADMIN},this.isFileMessage=function(){return this.messageType==O.MESSAGE_TYPE_FILE},this._update=function(e){this.messageId=e.hasOwnProperty("msg_id")?parseInt(e.msg_id):0,this.channelUrl=e.hasOwnProperty("channel_url")?String(e.channel_url):"",this.createdAt=e.hasOwnProperty("ts")?parseInt(e.ts):0,this.updatedAt=e.hasOwnProperty("updated_at")?parseInt(e.updated_at):0,this.channelType=e.hasOwnProperty("channel_type")?String(e.channel_type):H.CHANNEL_TYPE_GROUP},this.serialize=function(){var e=JSON.parse(JSON.stringify(this));return e.hasOwnProperty("_sender")&&(e.sender=e._sender,delete e._sender),f(e)},this.messageType=O.MESSAGE_TYPE_BASE,e&&this._update(e)};O.build=function(e,n){if(!e)return null;var t,r,a,s,i,o,l,u;switch(e.type){case"MESG":return t=new F(e.user),r=parseInt(e.message_id),a=String(e.message),s=String(e.data),i=parseInt(e.created_at),o=parseInt(e.updated_at),l=e.hasOwnProperty("custom_type")?String(e.custom_type):"",u=e.hasOwnProperty("translations")?e.translations:{},new M(M.build("",r,t,n,a,s,l,u,i,o));case"FILE":t=new F(e.user),r=parseInt(e.message_id),a=String(e.message),i=parseInt(e.created_at),o=parseInt(e.updated_at),l=e.hasOwnProperty("custom_type")?String(e.custom_type):"";var c=e.file,d=String(c.url),h=String(c.name),E=String(c.type),I=parseInt(c.size)||0;s=String(c.data);var p=e.hasOwnProperty("thumbnails")?e.thumbnails:[],_=!!e.hasOwnProperty("require_auth")&&e.require_auth;return new D(D.build("",r,t,n,d,h,E,I,s,l,i,p,_,o));case"BRDM":case"ADMM":return r=parseInt(e.message_id),a=String(e.message),s=String(e.data),i=parseInt(e.created_at),o=parseInt(e.updated_at),l=e.hasOwnProperty("custom_type")?String(e.custom_type):"",u=e.hasOwnProperty("translations")?e.translations:{},new L(L.build(r,n,a,s,l,u,i,o))}return null},O.MESSAGE_TYPE_BASE="base",O.MESSAGE_TYPE_ADMIN="admin",O.MESSAGE_TYPE_USER="user",O.MESSAGE_TYPE_FILE="file";var L=function(e){this.messageType=O.MESSAGE_TYPE_ADMIN,e&&(this._update(e),this.message=String(e.message),this.data=e.hasOwnProperty("data")?String(e.data):"",this.customType=e.hasOwnProperty("custom_type")?String(e.custom_type):"",this.translations=e.hasOwnProperty("translations")?e.translations:{})};I(O,L),L.build=function(e,n,t,r,a,s,i,o){var l={msg_id:e,channel_url:n.url,channel_type:n.channelType==H.CHANNEL_TYPE_OPEN?H.CHANNEL_TYPE_OPEN:H.CHANNEL_TYPE_GROUP,ts:i,updated_at:o,message:t,data:r};return a&&(l.custom_type=a),s&&(l.translations=s),l},L.buildFromSerializedData=function(e){var n=g(e);return new L(L.build(n.messageId,{url:n.channelUrl,channelType:n.channelType},n.message,n.data,n.customType,n.translations,n.createdAt,n.updatedAt))};var M=function(e){this.messageType=O.MESSAGE_TYPE_USER,e&&(this._update(e),this.message=String(e.message),this.data=e.hasOwnProperty("data")?String(e.data):"",this._sender=new F(e.user),c?this.sender=this._sender:Object.defineProperty(this,"sender",{get:function(){if(Z.getInstance().Options.UseMemberAsMessageSender&&this.isGroupChannel()){var e=w.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))}}return this._sender},set:function(e){this._sender=e}}),this.reqId=e.hasOwnProperty("req_id")?String(e.req_id):"",this.customType=e.hasOwnProperty("custom_type")?String(e.custom_type):"",this.translations=e.hasOwnProperty("translations")?e.translations:{})};I(O,M),M.build=function(e,n,t,r,a,s,i,o,l,u){var c={};c.req_id=e,c.msg_id=n,c.channel_url=r.url,c.channel_type=r.channelType==H.CHANNEL_TYPE_OPEN?H.CHANNEL_TYPE_OPEN:H.CHANNEL_TYPE_GROUP,c.ts=l,c.updated_at=u,c.message=a,s&&(c.data=s),i&&(c.custom_type=i),o&&(c.translations=o);var d={};return d.user_id=t.userId,d.nickname=t.nickname,d.profile_url=t.profileUrl,c.user=d,c},M.buildFromSerializedData=function(e){var n=g(e);return new M(M.build(n.reqId,n.messageId,n.sender,{url:n.channelUrl,channelType:n.channelType},n.message,n.data,n.customType,n.translations,n.createdAt,n.updatedAt))};var D=function(e){if(this.messageType=O.MESSAGE_TYPE_FILE,e&&(this._update(e),this._sender=new F(e.user),c?this.sender=this._sender:Object.defineProperty(this,"sender",{get:function(){if(Z.getInstance().Options.UseMemberAsMessageSender&&this.isGroupChannel()){var e=w.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))}}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="+j.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.customType=e.hasOwnProperty("custom_type")?String(e.custom_type):"",this.thumbnails=e.hasOwnProperty("thumbnails")?e.thumbnails:[],this.requireAuth))for(var n in this.thumbnails)this.thumbnails[n].url=String(this.thumbnails[n].url).split("?auth=")[0]+"?auth="+j.getInstance().ekey};I(O,D),D.build=function(e,n,t,r,a,s,i,o,l,u,c,d,h,E){var I={};I.req_id=e,I.msg_id=n,I.channel_url=r.url,I.channel_type=r.channelType==H.CHANNEL_TYPE_OPEN?H.CHANNEL_TYPE_OPEN:H.CHANNEL_TYPE_GROUP,I.ts=c,I.updated_at=E,I.url=a,I.name=s,I.type=i,I.size=o,I.custom=l;var p={};return p.user_id=t.userId,p.nickname=t.nickname,p.profile_url=t.profileUrl,I.user=p,u&&(I.custom_type=u),h&&(I.require_auth=h),d&&(I.thumbnails=d),I},D.buildFromSerializedData=function(e){var n=g(e);return new D(D.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.createdAt,n.thumbnails,n.requireAuth,n.updatedAt))};var H=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.fileUploadRequest={}},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 f(e)},this.isGroupChannel=function(){return this.channelType==H.CHANNEL_TYPE_GROUP},this.isOpenChannel=function(){return this.channelType==H.CHANNEL_TYPE_OPEN},this.getMessageChangeLogsByToken=function(e,n){if("function"==typeof e&&(n=e,e=null),"function"!=typeof n)return null;j.getInstance().getMessageChangeLogsByToken(this.isOpenChannel(),this.url,e,function(e,t){if(t)return void U(null,t,n);var r=e.updated.map(function(e){return O.build(e,this)}),a=e.deleted.map(function(e){return e.message_id}),s=e.has_more,i=e.next;U({updatedMessages:r,deletedMessageIds:a,hasMore:s,token:i},null,n)})},this.createPreviousMessageListQuery=function(){return new Q(this)},this.createMessageListQuery=function(){return new q(this)};var n=function(e,n,t,r,a,s,i,o,l){if(i===_.MessageTypeFilter.ADMIN?i="ADMM":i===_.MessageTypeFilter.USER?i="MESG":i===_.MessageTypeFilter.FILE?i="FILE":i===_.MessageTypeFilter.ALL&&(i=""),!E(n)||"boolean"!=typeof t||!E(r)||!E(a)||"boolean"!=typeof s||"string"!=typeof i||"string"!=typeof o)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),l);j.getInstance().messageList(e.isOpenChannel(),e.url,n,r,a,t,s,i,o,function(n,t){if(t)return void U(null,t,l);var r=n.messages,a=[];for(var s in r){var i=O.build(r[s],e);i&&a.push(i)}U(a,null,l)})},t=function(e,n,t,r,a,s,i,o,l){if(i===_.MessageTypeFilter.ADMIN?i="ADMM":i===_.MessageTypeFilter.USER?i="MESG":i===_.MessageTypeFilter.FILE?i="FILE":i===_.MessageTypeFilter.ALL&&(i=""),!E(n)||"boolean"!=typeof t||!E(r)||!E(a)||"boolean"!=typeof s||"string"!=typeof i||"string"!=typeof o)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),l);j.getInstance().messageListByID(e.isOpenChannel(),e.url,n,r,a,t,s,i,o,function(n,t){if(t)return void U(null,t,l);var r=n.messages,a=[];for(var s in r){var i=O.build(r[s],e);i&&a.push(i)}U(a,null,l)})};this.getNextMessagesByTimestamp=function(e,t,r,a,s,i,o){return n(this,e,t,0,r,a,s,i,o)},this.getPreviousMessagesByTimestamp=function(e,t,r,a,s,i,o){return n(this,e,t,r,0,a,s,i,o)},this.getPreviousAndNextMessagesByTimestamp=function(e,t,r,a,s,i,o){return n(this,e,!0,t,r,a,s,i,o)},this.getNextMessagesByID=function(e,n,r,a,s,i,o){return t(this,e,n,0,r,a,s,i,o)},this.getPreviousMessagesByID=function(e,n,r,a,s,i,o){return t(this,e,n,r,0,a,s,i,o)},this.getPreviousAndNextMessagesByID=function(e,n,r,a,s,i,o){return t(this,e,!0,n,r,a,s,i,o)},this._sendFileCommand=function(e,n,t,r,a,s,i,o,l,u,c){var d,h=this;d=c?c.reqId:B.generateRequestId();var E=B.bFile(d,e,n,t,r,a,s,i,o,l),I=D.build(E.requestId,0,Z.getInstance().currentUser,this,"string"==typeof n?n:"",t,r,a,s,i,null,null,!1),_=new D(I);return"string"==typeof n&&Z.getInstance().sendCommand(E,function(e,n){if(n)return void U(null,new p(n.message,n.code),u);var t=new D(e.getJsonElement()),r=Z.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)),h.isGroupChannel()&&w.getChannel(h.url,function(e,n){if(S){var r=e;e=n,n=r}if(n)return void U(null,n,u);e.lastMessage=t;for(var a in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[a].onChannelChanged(e)}}),U(t,null,u)}),_},this._getSendFileMessageParamInfo=function(e){var n={file:null,name:null,type:null,size:null,data:"",customType:"",thumbnailSizes:[],callback:null,progressHandler:null};switch("function"==typeof e.slice(-1)[0]&&(n.callback=e.pop()),"function"==typeof e.slice(-1)[0]&&(n.progressHandler=e.pop()),e.length){case 1:n.file=e[0];break;case 2:n.file=e[0],n.data=e[1];break;case 3:n.file=e[0],n.data=e[1],n.customType=e[2];break;case 4:n.file=e[0],n.data=e[1],n.customType=e[2],n.thumbnailSizes=e[3];break;case 5:n.file=e[0],n.name=e[1],n.type=e[2],n.size=e[3],n.data=e[4];break;case 6:n.file=e[0],n.name=e[1],n.type=e[2],n.size=e[3],n.data=e[4],n.customType=e[5];break;case 7:n.file=e[0],n.name=e[1],n.type=e[2],n.size=e[3],n.data=e[4],n.customType=e[5],n.thumbnailSizes=e[6]}return"string"!=typeof n.file&&null!==n.file&&(null!==n.name&&"undefined"!=typeof n.name&&n.name||(n.name=n.file.name),null!==n.type&&"undefined"!=typeof n.type&&n.type||(n.type=n.file.type),null!==n.size&&"undefined"!=typeof n.size||(n.size=n.file.size)),null!==n.name&&"undefined"!=typeof n.name||(n.name=""),null!==n.type&&"undefined"!=typeof n.type||(n.type=""),null!==n.size&&"undefined"!=typeof n.size||(n.size=0),n},this.sendFileMessage=function(){var e=this,n=this._getSendFileMessageParamInfo(Array.prototype.slice.call(arguments)),t=n.file,r=n.name,a=n.type,s=n.size,i=n.data,o=n.customType,l=n.thumbnailSizes,u=n.callback,c=n.progressHandler;if(null!==l&&void 0!==l||(l=[]),!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),u);if(null===t||void 0===t||null!==r&&void 0!==r&&"string"!=typeof r||null!==a&&void 0!==a&&"string"!=typeof a||null!==s&&void 0!==s&&(!E(s)||parseInt(s)<0)||null!==i&&void 0!==i&&"string"!=typeof i||null!==o&&void 0!==o&&"string"!=typeof o||!Array.isArray(l))return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),u);var d=e.url,h=null;return"string"==typeof t?h=e._sendFileCommand(d,t,r,a,s,i,o,[],!1,u):(h=e._sendFileCommand(d,t,r,a,s,i,o,[],!1,u),j.getInstance().uploadFile(t,a,l,d,function(n,t){if(t)return void U(null,t,u);var l="object"==typeof n?n:JSON.parse(n),c=l.url,E=l.hasOwnProperty("thumbnails")?l.thumbnails:[],I=!!l.hasOwnProperty("require_auth")&&l.require_auth;e._sendFileCommand(d,c,r,a,s,i,o,E,I,u,h)},c,this.fileUploadRequest,h.reqId)),h},this.cancelUploadingFileMessage=function(e,n){if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n);if(!E(e))return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);var t=this,r=t.fileUploadRequest[e];return r?(r.upload.onabort=function(){delete t.fileUploadRequest[e],U(!0,null,n)},r.abort(),!0):(U(!1,new p("Uploading has been completed or cancelled.",J.FILE_UPLOAD_CANCEL_FAILED),n),!1)},this.sendUserMessage=function(e,n,t,r,a){var s=this;if("function"==typeof n&&(a=n,n="",t="",r=[]),"function"==typeof t&&(a=t,t="",r=[]),"function"==typeof r&&(a=r,r=[]),r||(r=[]),"string"==typeof r&&(r=[r]),null===n&&(n=""),null===t&&(t=""),!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),a);if("string"!=typeof e||"string"!=typeof n||"string"!=typeof t||!Array.isArray(r))return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),a);var i=B.bMessage(this.url,e,n,t,[],r),o=M.build(i.requestId,0,Z.getInstance().currentUser,this,e,n,t,r,(new Date).getTime()),l=new M(o);return Z.getInstance().sendCommand(i,function(e,n){if(n)return void U(null,new p(n.message,n.code),a);var t=new M(e.getJsonElement()),r=Z.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.isGroupChannel()&&w.getChannel(s.url,function(e,n){if(S){var r=e;e=n,n=r}if(n)return void U(null,n,a);e.lastMessage=t;for(var s in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[s].onChannelChanged(e)}}),U(t,null,a)}),l},this.updateUserMessage=function(e,n,t,r,a){var s=Array.prototype.slice.call(arguments);if(5!==s.length)return"function"==typeof s.slice(-1)[0]&&(a=s.pop()),void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),a);if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),a);if(!E(e))return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),a);if("string"!=typeof n&&null!==n&&void 0!==n||"string"!=typeof t&&null!==t&&void 0!==t||"string"!=typeof r&&null!==r&&void 0!==r)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),a);var i=B.bUpdateUserMessage(this.url,e,n,t,r);Z.getInstance().sendCommand(i,function(e,n){if(n)return void U(null,new p(n.message,n.code),a);var t=new M(e.getJsonElement());U(t,null,a)})},this.updateFileMessage=function(e,n,t,r){var a=Array.prototype.slice.call(arguments);if(4!==a.length)return"function"==typeof a.slice(-1)[0]&&(r=a.pop()),void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),r);if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),r);if(!E(e))return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),r);if("string"!=typeof n&&null!==n&&void 0!==n||"string"!=typeof t&&null!==t&&void 0!==t)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),r);var s=B.bUpdateFileMessage(this.url,e,n,t);Z.getInstance().sendCommand(s,function(e,n){if(n)return void U(null,new p(n.message,n.code),r);var t=new D(e.getJsonElement());U(t,null,r)})},this.createMetaCounters=function(e,n){return Z.getInstance().hasLoggedIn()?null==e||"object"!=typeof e||Array.isArray(e)||h(e)?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):void j.getInstance().createMetaCounters(this.isOpenChannel(),this.url,e,function(e,t){if(t)return void U(null,t,n);U(e,null,n)}):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.updateMetaCounters=function(e,n,t){return Z.getInstance().hasLoggedIn()?("function"!=typeof n&&void 0!==t||(t=n,n=!1),null==e||"object"!=typeof e||Array.isArray(e)||h(e)||"boolean"!=typeof n?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),t):void j.getInstance().updateMetaCounters(this.isOpenChannel(),this.url,e,n,j.UPDATE_META_COUNTER_MODE_SET,function(e,n){if(n)return void U(null,n,t);U(e,null,t)})):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),t)},this.increaseMetaCounters=function(e,n){return Z.getInstance().hasLoggedIn()?null==e||"object"!=typeof e||Array.isArray(e)||h(e)?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):void j.getInstance().updateMetaCounters(this.isOpenChannel(),this.url,e,!1,j.UPDATE_META_COUNTER_MODE_INC,function(e,t){if(t)return void U(null,t,n);U(e,null,n)}):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.decreaseMetaCounters=function(e,n){return Z.getInstance().hasLoggedIn()?null==e||"object"!=typeof e||Array.isArray(e)||h(e)?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):void j.getInstance().updateMetaCounters(this.isOpenChannel(),this.url,e,!1,j.UPDATE_META_COUNTER_MODE_DEC,function(e,t){if(t)return void U(null,t,n);var r=e,a={};for(var s in r){var i=r[s];a[s]=i}U(a,null,n)}):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.getMetaCounters=function(e,n){return Z.getInstance().hasLoggedIn()?Array.isArray(e)?void j.getInstance().getMetaCounters(this.isOpenChannel(),this.url,e,function(e,t){if(t)return void U(null,t,n);U(e,null,n)}):void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.getAllMetaCounters=function(e){if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),e);j.getInstance().getAllMetaCounters(this.isOpenChannel(),this.url,function(n,t){if(t)return void U(null,t,e);U(n,null,e)})},this.deleteMetaCounter=function(e,n){return Z.getInstance().hasLoggedIn()?"string"!=typeof e?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):void j.getInstance().deleteMetaCounter(this.isOpenChannel(),this.url,e,function(e,t){if(t)return void U(null,t,n);U(e,null,n)}):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.deleteAllMetaCounters=function(e){if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),e);j.getInstance().deleteAllMetaCounters(this.isOpenChannel(),this.url,function(n,t){if(t)return void(e&&U(null,t,e));U(n,null,e)})},this.createMetaData=function(e,n){return Z.getInstance().hasLoggedIn()?null==e||"object"!=typeof e||Array.isArray(e)||h(e)?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):void j.getInstance().createMetaData(this.isOpenChannel(),this.url,e,function(e,t){if(t)return void U(null,t,n);U(e,null,n)}):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.updateMetaData=function(e,n,t){return Z.getInstance().hasLoggedIn()?("function"!=typeof n&&void 0!==t||(t=n,n=!1),null==e||"object"!=typeof e||Array.isArray(e)||h(e)||"boolean"!=typeof n?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),t):void j.getInstance().updateMetaData(this.isOpenChannel(),this.url,e,n,function(e,n){if(n)return void U(null,n,t);U(e,null,t)})):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),t)},this.getMetaData=function(e,n){return Z.getInstance().hasLoggedIn()?Array.isArray(e)?void j.getInstance().getMetaData(this.isOpenChannel(),this.url,e,function(e,t){if(t)return void U(null,t,n);U(e,null,n)}):void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.getAllMetaData=function(e){if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),e);j.getInstance().getAllMetaData(this.isOpenChannel(),this.url,function(n,t){if(t)return void U(null,t,e);U(n,null,e)})},this.deleteMetaData=function(e,n){return Z.getInstance().hasLoggedIn()?"string"!=typeof e?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):void j.getInstance().deleteMetaData(this.isOpenChannel(),this.url,e,function(e,t){if(t)return void U(null,t,n);U(e,null,n)}):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.deleteAllMetaData=function(e){if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),e);j.getInstance().deleteAllMetaData(this.isOpenChannel(),this.url,function(n,t){if(t)return void(e&&U(null,t,e));U(n,null,e)})},this.deleteMessage=function(e,n){var t=Array.prototype.slice.call(arguments);if(2!==t.length)return"function"==typeof t.slice(-1)[0]&&(n=t.pop()),void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n);var r=this;if("object"!=typeof e||h(e)||Array.isArray(e)||Object.keys(e).indexOf("messageId")<0||!e)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);j.getInstance().deleteMessage(r.isOpenChannel(),r.url,e.messageId,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.channelType=H.CHANNEL_TYPE_BASE,e&&this._update(e)};H.CHANNEL_TYPE_OPEN="open",H.CHANNEL_TYPE_GROUP="group",H.CHANNEL_TYPE_BASE="base";var b=function(e){this.parse=function(e){if(e.hasOwnProperty("freeze")&&(this.isFrozen=e.freeze),e.hasOwnProperty("participant_count")&&(this.participantCount=parseInt(e.participant_count)),e.hasOwnProperty("operators")&&e.operators){this.operators=[];for(var n in e.operators){var t=new F(e.operators[n]);this.operators.push(t)}}},this.refresh=function(e){b.getChannelWithoutCache(this.url,function(n,t){if(S){var r=n;n=t,t=r}if(t)return void U(null,t,e);U(n,null,e)})},this.update=function(e){this._update(e),this.parse(e)},this["delete"]=function(e){var n=this.url;j.getInstance().deleteOpenChannel(n,function(t,r){if(r)return void U(null,r,e);delete b.cachedChannels[n],U(t,null,e)})},this.enter=function(e){var n=this,t=B.bEnter(n.url);Z.getInstance().sendCommand(t,function(t,r){if(r)return void U(null,new p(r.message,r.code),e);b.enteredChannels[n.url]=n,U(null,null,e)})},this.exit=function(e){var n=this,t=B.bExit(n.url);Z.getInstance().sendCommand(t,function(t,r){if(r)return void U(null,new p(r.message,r.code),e);delete b.enteredChannels[n.url],U(null,null,e)})},this.createParticipantListQuery=function(){return new x(x.PARTICIPANT,this)},this.createMutedUserListQuery=function(){return new x(x.MUTED_USER,this)},this.createBannedUserListQuery=function(){return new x(x.BANNED_USER,this)},this.updateChannel=function(){var e=Array.prototype.slice.call(arguments),n=null,t=null,r=null,a=null,s=null,i=null;switch("function"==typeof e.slice(-1)[0]&&(i=e.pop()),e.length){case 3:n=e[0],t=e[1],r=e[2];break;case 4:n=e[0],t=e[1],r=e[2],a=e[3];break;case 5:n=e[0],t=e[1],r=e[2],a=e[3],s=e[4];break;default:return void U(null,new p("Invalid arguments.2",J.INVALID_PARAMETER),i)}this.updateChannelWithOperatorUserIds(n,t,r,a,s,i)},this.updateChannelWithOperatorUserIds=function(e,n,t,r,a,s){if("function"==typeof a&&(s=a,a=null),"string"!=typeof e&&null!==e&&void 0!==e||"string"!=typeof n&&h(n)&&null!==n&&void 0!==n||"string"!=typeof t&&null!==t&&void 0!==t||"string"!=typeof r&&!Array.isArray(r)&&null!==r&&void 0!==r||"string"!=typeof a&&null!==a&&void 0!==a)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),s);j.getInstance().updateOpenChannel(this.url,e,n,t,r,a,function(e,n){if(n)return void U(null,n,s);var t=b.upsert(e);U(t,null,s)})},this.banUser=function(e,n,t){if("function"==typeof n&&3!==arguments.length&&(t=n,n=-1),!e||parseInt(n)<0&&-1!==parseInt(n))return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),t);this.banUserWithUserId(e.userId,n,t)},this.banUserWithUserId=function(e,n,t){if("function"==typeof n&&3!==arguments.length&&(t=n,n=-1),!e||parseInt(n)<0&&-1!==parseInt(n))return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),t);j.getInstance().banUser(this.url,e,null,n,function(e,n){if(n)return void U(null,n,t);U(null,null,t)})},this.unbanUser=function(e,n){if(!e)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),n);this.unbanUserWithUserId(e.userId,n)},this.unbanUserWithUserId=function(e,n){if(!e)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),n);j.getInstance().unbanUser(this.url,e,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.muteUser=function(e,n){if(!e)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),n);this.muteUserWithUserId(e.userId,n)},this.muteUserWithUserId=function(e,n){if(!e)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),n);j.getInstance().muteUser(this.url,e,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.unmuteUser=function(e,n){if(!e)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),n);this.unmuteUserWithUserId(e.userId,n)},this.unmuteUserWithUserId=function(e,n){if(!e)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),n);j.getInstance().unmuteUser(this.url,e,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.isOperator=function(e){return!!e&&this.isOperatorWithUserId(e.userId)},this.isOperatorWithUserId=function(e){for(var n in this.operators)if(this.operators[n].userId==e)return!0;return!1},this.channelType=H.CHANNEL_TYPE_OPEN,this.participantCount=0,this.isFrozen=!1,this.operators=[],e&&(this._update(e),this.parse(e))};I(H,b),b.enteredChannels={},b.clearEnteredChannels=function(){b.enteredChannels={}},b.createOpenChannelListQuery=function(){return new W},b.buildFromSerializedData=function(e){var n=g(e);return new b({channel_url:n.url,name:n.name,cover_url:n.coverUrl,data:n.data,custom_type:n.customType,created_at:n.createdAt/1e3,freeze:n.isFrozen,participant_count:n.participantCount,operators:n.operators.map(function(e){return F.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData)})})},b.createChannel=function(){var e,n,t,r,a,s;switch(arguments.length){case 1:s=arguments[0];break;case 4:e=arguments[0],n=arguments[1],t=arguments[2],s=arguments[3];break;case 5:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],s=arguments[4];break;case 6:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],a=arguments[4],s=arguments[5]}b.createChannelWithOperatorUserIds(e,n,t,r,a,s)},b.upsert=function(e){var n=new b(e);return b.cachedChannels.hasOwnProperty(n.url)?b.cachedChannels[n.url].update(e):b.cachedChannels[n.url]=n,b.cachedChannels[n.url]},b.createChannelWithOperatorUserIds=function(e,n,t,r,a,s){if("function"==typeof a&&(s=a,a=""),"string"!=typeof e&&null!==e&&void 0!==e||"string"!=typeof n&&h(n)&&null!==n&&void 0!==n||"string"!=typeof t&&null!==t&&void 0!==t||"string"!=typeof r&&!Array.isArray(r)&&null!==r&&void 0!==r||"string"!=typeof a&&null!==a&&void 0!==a)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),s);j.getInstance().createOpenChannel(e,n,t,r,a,function(e,n){if(n)return void U(null,n,s);var t=b.upsert(e);U(t,null,s)})},b.cachedChannels={},b.clearCache=function(){b.cachedChannels={}},b.removeCachedChannel=function(e){delete b.cachedChannels[e]},b.getChannel=function(e,n){if(!e)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);b.cachedChannels.hasOwnProperty(e)?U(b.cachedChannels[e],null,n):b.getChannelWithoutCache(e,n)},b.getChannelWithoutCache=function(e,n){if(!e)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n) -;j.getInstance().getOpenChannel(e,function(t,r){if(r)return void U(null,r,n);b.upsert(t),U(b.cachedChannels[e],null,n)})};var w=function(e){var n,r,a={};this.parse=function(e){var n=this;if(n.isDistinct=!!e.is_distinct,n.unreadMessageCount=parseInt(e.unread_message_count),n.isPushEnabled=!!e.is_push_enabled,n.isHidden=!!e.hasOwnProperty("is_hidden")&&e.is_hidden,e.hasOwnProperty("read_receipt")){n.cachedReadReceiptStatus={};for(var t in e.read_receipt){var r=e.read_receipt[t];n.updateReadReceipt(t,parseInt(r))}}if(e.hasOwnProperty("members")){n.members=[],n.memberMap={};e.members.forEach(function(e){var t=new Y(e);n.members.push(t),n.memberMap[t.userId]=t}),n.memberCount=n.members.length}e.hasOwnProperty("member_count")&&(n.memberCount=parseInt(e.member_count)),e.hasOwnProperty("last_message")&&"object"==typeof e.last_message&&e.last_message?e.last_message instanceof O?n.lastMessage=e.last_message:n.lastMessage=O.build(e.last_message,n):n.lastMessage=null,e.hasOwnProperty("inviter")&&null!==e.inviter&&"object"==typeof e.inviter&&!h(e.inviter)?n.inviter=new F(e.inviter):n.inviter=null},this.refresh=function(e){w.getChannelWithoutCache(this.url,function(n,t){if(S){var r=n;n=t,t=r}if(t)return void U(null,t,e);U(n,null,e)})},this.update=function(e){this._update(e),this.parse(e)},this.updateChannel=function(){var e=this,n=Array.prototype.slice.call(arguments),t=null,r=null,a=null,s=null,i=null,o=null;switch("function"==typeof n.slice(-1)[0]&&(o=n.pop()),n.length){case 3:t=e.isDistinct,r=n[0],a=n[1],s=n[2];break;case 4:t=n[0],r=n[1],a=n[2],s=n[3];break;case 5:t=n[0],r=n[1],a=n[2],s=n[3],i=n[4];break;default:return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),o)}if("string"!=typeof r&&null!==r&&void 0!==r||"string"!=typeof a&&h(a)&&null!==a&&void 0!==a||"string"!=typeof s&&null!==s&&void 0!==s||"boolean"!=typeof t||"string"!=typeof i&&null!==i&&void 0!==i)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),o);j.getInstance().updateGroupChannel(e.url,t,r,a,s,i,function(e,n){if(n)return void U(null,n,o);var t=w.upsert(e);U(t,null,o)})},this.resetMyHistory=function(e){if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),e);j.getInstance().resetMyHistory(this.url,function(n,t){if(t)return void U(null,t,e);U(n,null,e)})},this.invite=function(e,n){if("string"==typeof e&&(e=[{userId:e}]),!Array.isArray(e)||h(e))return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);var t=[];for(var r in e){if("object"!=typeof e[r]||h(e[r])){U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);break}t.push(e[r].userId)}this.inviteWithUserIds(t,n)},this.inviteWithUserIds=function(e,n){if(!Array.isArray(e)||h(e))return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);j.getInstance().groupChannelInvite(this.url,e,function(e,t){if(t)return void U(null,t,n);var r=w.upsert(e);U(r,null,n)})},this.acceptInvitation=function(e){j.getInstance().acceptInvitation(this.url,Z.getInstance().getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);var r=w.upsert(n);U(r,null,e)})},this.declineInvitation=function(e){j.getInstance().declineInvitation(this.url,Z.getInstance().getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);U(n,null,e)})},this.hide=function(e,n){if(1===arguments.length&&"function"==typeof e&&(n=e,e=!1),null!==e&&void 0!==e||(e=!1),"boolean"!=typeof e)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),n);var t=this.url,r=this;j.getInstance().groupChannelHide(t,Z.getInstance().getCurrentUserId(),e,function(e,a){if(a)return void U(null,a,n);r.isHidden=!0;var s=w.cachedChannels[t];s&&(s.isHidden=!0),U(e,null,n)})},this.leave=function(e){var n=this.url;j.getInstance().groupChannelLeave(n,Z.getInstance().getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);U(null,null,e)})},this.markAsRead=function(){this._sendMarkAsRead(null)},this._sendMarkAsRead=function(e){var n=this,t=B.bRead(n.url);Z.getInstance().sendCommand(t,function(t,r){if(r)return void U(null,new p(r.message,r.code),e);if(n.unreadMessageCount>0){n.unreadMessageCount=0;for(var a in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[a].onChannelChanged(n)}}U(null,null,e)})},this.getReadReceipt=function(e){if(!(e instanceof O))return t.log("message is not BaseMessage instance"),-1;if(e.messageType==O.MESSAGE_TYPE_ADMIN)return 0;var n=Z.getInstance().currentUser,r=0,a=e.createdAt,s=this.members;for(var i in s){var o=s[i],l=o.userId;if(!(n.userId==l||e.sender&&e.sender.userId==l)){this.cachedReadReceiptStatus[l]=1e4&&(delete a[t],e=!0)}return e},this.updateTypingStatus=function(e,n){n?a[e.userId]=(new Date).getTime():delete a[e.userId]},this.isTyping=function(){return 0!=Object.keys(a).length},this.getTypingMembers=function(){var e=[];for(var n in a){var t=this.memberMap[n];this.memberMap[n]&&e.push(t)}return e},this.addMember=function(e){var n=this.removeMember(e);n&&n.state===Y.JOINED&&(e.state=Y.JOINED),this.memberMap[e.userId]=e,this.members.push(e),this.memberCount++,this.updateReadReceipt(e.userId,0)},this.removeMember=function(e){var n=e.userId,t=null;if(this.memberMap.hasOwnProperty(e.userId)){delete this.memberMap[e.userId];for(var r in this.members){var a=this.members[r];if(a.userId==n){t=a,this.members.splice(r,1);break}}this.memberCount--}return t},this.setPushPreference=function(e,n){var t=this;if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n);j.getInstance().setPushPreference(Z.getInstance().getCurrentUserId(),this.url,e,function(e,r){if(r)return void U(null,r,n);t.isPushEnabled=e.enable,U(e,null,n)})},this.getPushPreference=function(e){var n=this;if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),e);j.getInstance().getPushPreference(Z.getInstance().getCurrentUserId(),this.url,function(t,r){if(r)return void U(null,r,e);if(e){var a;try{a=t.enable}catch(e){a=!1}n.isPushEnabled=a,U(a,null,e)}})},this.channelType=H.CHANNEL_TYPE_GROUP,this.isDistinct=!1,this.unreadMessageCount=0,this.inviter=null,this.members=[],this.memberMap={},this.lastMessage={},this.memberCount=0,this.cachedReadReceiptStatus={},this.isPushEnabled,this.isHidden=!1,e&&(this._update(e),this.parse(e))};I(H,w),w.buildFromSerializedData=function(e){var n=g(e);return new w({channel_url:n.url,name:n.name,cover_url:n.coverUrl,data:n.data,custom_type:n.customType,created_at:n.createdAt/1e3,is_distinct:n.isDistinct,unread_message_count:n.unreadMessageCount,is_push_enabled:n.isPushEnabled,is_hidden:n.isHidden,member_count:n.memberCount,members:n.members.map(function(e){return Y.build(F.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData),e.state,e.isBlockedByMe,e.isBlockingMe)}),last_message:function(e){return null!==e&&void 0!==e&&"object"==typeof e?e.messageType===O.MESSAGE_TYPE_USER?new M(M.build(e.reqId,e.messageId,e.sender,{url:e.channelUrl,channelType:e.channelType},e.message,e.data,e.customType,e.translations,e.createdAt,e.updatedAt)):e.messageType===O.MESSAGE_TYPE_FILE?new D(D.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.createdAt,e.thumbnails,e.requireAuth,e.updatedAt)):new L(L.build(e.messageId,{url:e.channelUrl,channelType:e.channelType},e.message,e.data,e.customType,e.translations,e.createdAt,e.updatedAt)):null}(n.lastMessage),read_receipt:n.cachedReadReceiptStatus,inviter:null!==n.inviter&&"undefined"!=typeof n.inviter&&"object"==typeof n.inviter?F.build(n.inviter.userId,n.inviter.nickname,n.inviter.profileUrl,n.inviter.connectionStatus,n.inviter.lastSeenAt,n.inviter.metaData):null})},w.createMyGroupChannelListQuery=function(){return new K(Z.getInstance().currentUser)},w.memberState={ALL:0,JOINED:1,INVITED:2},w.getChannelCount=function(e,n){return"function"==typeof e&&1===arguments.length&&(n=e,e=w.memberState.ALL),e!==w.memberState.ALL&&e!==w.memberState.JOINED&&e!==w.memberState.INVITED?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):Z.getInstance().hasLoggedIn()?void j.getInstance().getGroupChannelCount(Z.getInstance().getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);var r=parseInt(e.group_channel_count);U(r,null,n)}):void(n&&U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n))},w.getTotalUnreadMessageCount=function(e){j.getInstance().getTotalUnreadMessageCount(Z.getInstance().getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);var r=parseInt(n.unread_count);U(r,null,e)})},w.getTotalUnreadChannelCount=function(e){j.getInstance().getTotalUnreadChannelCount(Z.getInstance().getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);var r=parseInt(n.unread_count);U(r,null,e)})},w.createChannel=function(){var e=null,n=null,t=null,r=null,a=null,s=null,i=null;switch(arguments.length){case 2:e=arguments[0],n=!1,s=arguments[1];break;case 3:e=arguments[0],n=arguments[1],s=arguments[2];break;case 4:e=arguments[0],n=arguments[1],i=arguments[2],s=arguments[3];break;case 6:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],a=arguments[4],s=arguments[5];break;case 7:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],a=arguments[4],i=arguments[5],s=arguments[6]}if(!Array.isArray(e)||"boolean"!=typeof n||"string"!=typeof t&&null!==t&&void 0!==t||"string"!=typeof r&&h(r)&&null!==r&&void 0!==r||"string"!=typeof a&&null!==a&&void 0!==a||"string"!=typeof i&&null!==i&&void 0!==i)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),s);var o=[];e.forEach(function(e){o.push(e.userId)}),w.createChannelWithUserIds(o,n,t,r,a,i,s)},w.createChannelWithUserIds=function(){var e=null,n=null,t=null,r=null,a=null,s=null,i=null;switch(arguments.length){case 2:e=arguments[0],n=!1,s=arguments[1];break;case 3:e=arguments[0],n=arguments[1],s=arguments[2];break;case 4:e=arguments[0],n=arguments[1],i=arguments[2],s=arguments[3];break;case 6:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],a=arguments[4],s=arguments[5];break;case 7:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],a=arguments[4],i=arguments[5],s=arguments[6]}if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),s);if(!Array.isArray(e)||"boolean"!=typeof n||"string"!=typeof t&&null!==t&&void 0!==t||"string"!=typeof r&&h(r)&&null!==r&&void 0!==r||"string"!=typeof a&&null!==a&&void 0!==a||"string"!=typeof i&&null!==i&&void 0!==i)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),s);var o=e.filter(function(e,n,t){return n==t.indexOf(e)}),l=Z.getInstance().currentUser;o.push(l.userId),j.getInstance().createGroupChannel(o,n,t,r,a,i,function(e,n){if(n)return void U(null,n,s);var t=new w(e);w.cachedChannels[t.url]=t,U(t,null,s)})},w.cachedChannels={},w.clearCache=function(){w.cachedChannels={}},w.removeCachedChannel=function(e){delete w.cachedChannels[e]},w.upsert=function(e){var n=new w(e);return w.cachedChannels.hasOwnProperty(n.url)?w.cachedChannels[n.url].update(e):w.cachedChannels[n.url]=n,w.cachedChannels[n.url]},w.getChannelWithoutCache=function(e,n){if(!e)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);j.getInstance().getGroupChannel(e,!0,!0,function(e,t){if(t)return void U(null,t,n);var r=w.upsert(e);U(r,null,n)})},w.getChannel=function(e,n){if(!e)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);w.cachedChannels.hasOwnProperty(e)?U(w.cachedChannels[e],null,n):w.getChannelWithoutCache(e,n)},w.markAsReadAllLastSentAt,w.markAsReadAll=function(e){var n=(new Date).getTime();if(n-w.markAsReadAllLastSentAt<1e3)return void U(null,new p("MarkAsRead rate limit exceeded.",J.MARK_AS_READ_RATE_LIMIT_EXCEEDED),e);w.markAsReadAllLastSentAt=n,j.getInstance().groupChannelMarkAsReadAll(Z.getInstance().getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);for(var r in w.cachedChannels)w.cachedChannels[r].unreadMessageCount=0;U(null,null,e)})};var k=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):H.CHANNEL_TYPE_GROUP),this.isGroupChannel=function(){return this.channelType==H.CHANNEL_TYPE_GROUP},this.isOpenChannel=function(){return this.channelType==H.CHANNEL_TYPE_OPEN}};k.CATEGORY_NONE=0,k.CATEGORY_CHANNEL_ENTER=10102,k.CATEGORY_CHANNEL_EXIT=10103,k.CATEGORY_USER_CHANNEL_MUTE=10201,k.CATEGORY_USER_CHANNEL_UNMUTE=10200,k.CATEGORY_USER_CHANNEL_BAN=10601,k.CATEGORY_USER_CHANNEL_UNBAN=10600,k.CATEGORY_CHANNEL_FREEZE=10701,k.CATEGORY_CHANNEL_UNFREEZE=10700,k.CATEGORY_TYPING_START=10900,k.CATEGORY_TYPING_END=10901,k.CATEGORY_CHANNEL_JOIN=1e4,k.CATEGORY_CHANNEL_LEAVE=10001,k.CATEGORY_CHANNEL_INVITE=10020,k.CATEGORY_CHANNEL_DECLINE_INVITE=10022,k.CATEGORY_CHANNEL_PROP_CHANGED=11e3,k.CATEGORY_CHANNEL_DELETED=12e3,k.CATEGORY_CHANNEL_META_DATA_CHANGED=11100,k.CATEGORY_CHANNEL_META_COUNTERS_CHANGED=11200,k.CATEGORY_CHANNEL_HIDE=13e3;var G=function(e){e&&(this.category=e.hasOwnProperty("cat")?parseInt(e.cat):0)};G.CATEGORY_USER_BLOCK=20001,G.CATEGORY_USER_UNBLOCK=2e4;var V=function(e){e&&(this.reader=new F(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):H.CHANNEL_TYPE_GROUP)},F=function(e){this.nickname="",this.profileUrl="",this.userId="",this.connectionStatus="",this.lastSeenAt=null,this.metaData={},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==F.NON_AVAILABLE?this.connectionStatus=F.NON_AVAILABLE:this.connectionStatus=e.is_online?F.ONLINE:F.OFFLINE:this.connectionStatus=F.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={}},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]})},this.createMetaData=function(e,n){var t=this;return"function"==typeof e&&1===arguments.length&&(n=e,e={}),"object"!=typeof e||h(e)||Array.isArray(e)?void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),n):Z.getInstance().hasLoggedIn()?void j.getInstance().createUserMetaData(t.userId,e,function(e,r){if(r)return void U(null,r,n);t._updateMetaData(e),U(e,null,n)}):void(n&&U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n))},this.updateMetaData=function(e,n,t){var r=this;return"function"==typeof e&&1===arguments.length&&(t=e,e={}),"function"==typeof n&&2===arguments.length&&(t=n,n=!1),"object"!=typeof e||h(e)||Array.isArray(e)||"boolean"!=typeof n?void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),t):Z.getInstance().hasLoggedIn()?void j.getInstance().updateUserMetaData(r.userId,e,n,function(e,n){if(n)return void U(null,n,t);r._updateMetaData(e),U(e,null,t)}):void(t&&U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),t))},this.deleteAllMetaData=function(e){var n=this,t=n.metaData;if(!Z.getInstance().hasLoggedIn())return void(e&&U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),e));j.getInstance().deleteAllUserMetaData(n.userId,function(r,a){if(a)return void U(null,a,e);n._updateMetaData(t,!0),U(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 U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),n);if(!Z.getInstance().hasLoggedIn())return void(n&&U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n));var r={};r[e]="",j.getInstance().deleteUserMetaData(t.userId,e,function(e,a){if(a)return void U(null,a,n);t._updateMetaData(r,!0),U(e,null,n)})},this.serialize=function(){var e=JSON.parse(JSON.stringify(this));return f(e)},e&&this._update(e)};F.NON_AVAILABLE="nonavailable",F.ONLINE="online",F.OFFLINE="offline",F.build=function(e,n,t,r,a,s){return{user_id:e,nickname:n,profile_url:t,is_online:r,last_seen_at:a,metadata:s}},F.buildFromSerializedData=function(e){var n=g(e);return new F(F.build(n.userId,n.nickname,n.profileUrl,n.connectionStatus,n.lastSeenAt,n.metaData))};var Y=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))};I(F,Y),Y.JOINED="joined",Y.INVITED="invited",Y.build=function(e,n,t,r){var a=e;return a.state=n,a.is_blocked_by_me=t,a.is_blocking_me=r,a},Y.buildFromSerializedData=function(e){var n=g(e);return new Y(Y.build(F.build(n.userId,n.nickname,n.profileUrl,n.connectionStatus,n.lastSeenAt,n.metaData),n.state,n.isBlockedByMe,n.isBlockingMe))};var B=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 a;switch(arguments.length){case 1:var s=arguments[0];if(!s||s.length<=4)return r.command="NOOP",void(r.payload="{}");if(s=s.trim(),r.command=s.substring(0,4),r.payload=s.substring(4),r.isRequestIdCommand()){var i=r.getJsonElement();i&&(r.requestId=i.hasOwnProperty("req_id")?i.req_id:"")}break;case 3:a=arguments[2];case 2:var o=arguments[0],l=arguments[1];a=a||"",r.command=o,r.requestId=a,r.requestId||r.isRequestIdCommand()&&(r.requestId=B.generateRequestId()),l.req_id=r.requestId,r.payload=JSON.stringify(l)}}};B.bMessage=function(e,n,t,r,a,s){var i={};i.channel_url=e,i.message=n,i.data=t,i.mentioned=[];for(var o in a){var l=a[o];i.mentioned.push(String(l))}return r&&(i.custom_type=r),s.length>0&&(i.target_langs=s),new B("MESG",i)},B.bRead=function(e){var n={};return n.channel_url=e,new B("READ",n)},B.bTypeStart=function(e,n){var t={};return t.channel_url=e,t.time=n,new B("TPST",t)},B.bTypeEnd=function(e,n){var t={};return t.channel_url=e,t.time=n,new B("TPEN",t)},B.bFile=function(e,n,t,r,a,s,i,o,l,u){var c={};return c.channel_url=n,c.url=t,c.name=r||"",c.type=a||"",c.size=s||0,c.custom=i,o&&(c.custom_type=o),l&&(c.thumbnails=l),u&&(c.require_auth=u),new B("FILE",c,e)},B.bPing=function(){var e={};return e.id=(new Date).getTime(),new B("PING",e)},B.bEnter=function(e){var n={};return n.channel_url=e,new B("ENTR",n)},B.bExit=function(e){var n={};return n.channel_url=e,new B("EXIT",n)},B.bUpdateUserMessage=function(e,n,t,r,a){var s={};return s.channel_url=e,s.msg_id=n,null!=t&&t!=undefined&&(s.message=t),null!=r&&r!=undefined&&(s.data=r),null!=a&&a!=undefined&&(s.custom_type=a),new B("MEDI",s)},B.bUpdateFileMessage=function(e,n,t,r){var a={};return a.channel_url=e,a.msg_id=n,null!=t&&t!=undefined&&(a.data=t),null!=r&&r!=undefined&&(a.custom_type=r),new B("FEDI",a)},B.requestIdSeed=(new Date).getTime(),B.generateRequestId=function(){return B.requestIdSeed++,String(B.requestIdSeed)};var K=function(e){this.isLoading=!1,this.hasNext=!0,this.limit=20,this.includeEmpty=!1,this.order=K.ORDER_LATEST_LAST_MESSAGE,this.userIdsFilter=[],this.userIdsFilterExactMatch=!1,this.queryType="AND",this.nicknameContainsFilter="",this.channelNameContainsFilter="",this.memberStateFilter=K.MEMBER_STATE_ALL,this.customTypeFilter="";var n=e,t="",r=this;this.next=function(e){return r.hasNext?r.isLoading?void U(null,new p("Query in progress.",J.QUERY_IN_PROGRESS),e):(null!==r.nicknameContainsFilter&&"undefined"!=typeof r.nicknameContainsFilter||(r.nicknameContainsFilter=""),null!==r.channelNameContainsFilter&&"undefined"!=typeof r.channelNameContainsFilter||(r.channelNameContainsFilter=""),r.memberStateFilter===w.memberState.JOINED?r.memberStateFilter=K.MEMBER_STATE_JOINED_ONLY:r.memberStateFilter===w.memberState.INVITED?r.memberStateFilter=K.MEMBER_STATE_INVITED_ONLY:r.memberStateFilter===w.memberState.ALL&&(r.memberStateFilter=K.MEMBER_STATE_ALL),!E(r.limit)||!Array.isArray(r.userIdsFilter)||"boolean"!=typeof r.userIdsFilterExactMatch||"string"!=typeof r.customTypeFilter||"string"!=typeof r.queryType||["AND","OR"].indexOf(r.queryType.toUpperCase())<0||"string"!=typeof r.order||[K.ORDER_CHRONOLOGICAL,K.ORDER_LATEST_LAST_MESSAGE].indexOf(r.order.toLowerCase())<0||"string"!=typeof r.memberStateFilter||[K.MEMBER_STATE_INVITED_ONLY,K.MEMBER_STATE_JOINED_ONLY,K.MEMBER_STATE_ALL].indexOf(r.memberStateFilter.toLowerCase())<0||"string"!=typeof r.nicknameContainsFilter||"string"!=typeof r.channelNameContainsFilter?void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),e):(r.isLoading=!0,void j.getInstance().loadUserGroupChannelList(n.userId,t,r.limit,r.includeEmpty,r.order,r.userIdsFilter,r.userIdsFilterExactMatch,r.nicknameContainsFilter,r.queryType,r.memberStateFilter,r.channelNameContainsFilter,r.customTypeFilter,function(n,a){if(a)return r.isLoading=!1,void U(null,a,e);var s=n;(!(t=String(s.next))||t.length<=0)&&(r.hasNext=!1);var i=s.channels,o=[];for(var l in i){var u=w.upsert(i[l]);o.push(u)}r.isLoading=!1,U(o,null,e)}))):void U([],null,e)}};K.ORDER_LATEST_LAST_MESSAGE="latest_last_message",K.ORDER_CHRONOLOGICAL="chronological",K.MEMBER_STATE_INVITED_ONLY="invited_only",K.MEMBER_STATE_JOINED_ONLY="joined_only",K.MEMBER_STATE_ALL="all";var q=function(e){this.isLoading=!1;var n=e,t=this;this.next=function(e,r,a,s){if(t.isLoading)return void U(null,new p("Query in progress.",J.QUERY_IN_PROGRESS),s);if(4!==arguments.length){if("function"!=typeof s){var i=Array.prototype.slice.call(arguments);"function"==typeof i.slice(-1)[0]&&(s=i.pop())}return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),s)}if(!E(e)||!E(r)||"boolean"!=typeof a)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),s);t.isLoading=!0,j.getInstance().messageList(n.isOpenChannel(),n.url,e,0,r,!1,a,"","",function(e,r){if(r)return t.isLoading=!1,void U(null,r,s);var a=e.messages,i=[];for(var o in a){var l=O.build(a[o],n);l&&i.push(l)}t.isLoading=!1,U(i,null,s)})},this.prev=function(e,r,a,s){if(t.isLoading)return void U(null,new p("Query in progress.",J.QUERY_IN_PROGRESS),s);if(4!==arguments.length){if("function"!=typeof s){var i=Array.prototype.slice.call(arguments);"function"==typeof i.slice(-1)[0]&&(s=i.pop())}return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),s)}if(!E(e)||!E(r)||"boolean"!=typeof a)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),s);t.isLoading=!0,j.getInstance().messageList(n.isOpenChannel(),n.url,e,r,0,!1,a,"","",function(e,r){if(r)return t.isLoading=!1,void U(null,r,s);var a=e.messages,i=[];for(var o in a){var l=O.build(a[o],n);l&&i.push(l)}t.isLoading=!1,U(i,null,s)})},this.load=function(e,r,a,s,i){if(t.isLoading)return void U(null,new p("Query in progress.",J.QUERY_IN_PROGRESS),i);if(5!==arguments.length){if("function"!=typeof i){var o=Array.prototype.slice.call(arguments);"function"==typeof o.slice(-1)[0]&&(i=o.pop())}return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),i)}if(!E(e)||!E(r)||!E(a)||"boolean"!=typeof s)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),i);t.isLoading=!0,j.getInstance().messageList(n.isOpenChannel(),n.url,e,r,a,!0,s,"","",function(e,r){if(r)return t.isLoading=!1,void U(null,r,i);var a=e.messages,s=[];for(var o in a){var l=O.build(a[o],n);l&&s.push(l)}t.isLoading=!1,U(s,null,i)})}},W=function(){var e="";this.limit=20,this.isLoading=!1,this.hasNext=!0,this.nameKeyword=null,this.urlKeyword=null,this.customType=null;var n=this;this.next=function(t){return this.hasNext?this.isLoading?void U(null,new p("Query in progress.",J.QUERY_IN_PROGRESS),t):"string"!=typeof n.nameKeyword&&null!==n.nameKeyword||"string"!=typeof n.urlKeyword&&null!==n.urlKeyword||"string"!=typeof n.customType&&null!==n.customType||!E(n.limit)?void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),t):(n.isLoading=!0,void j.getInstance().loadOpenChannelList(e,n.limit,n.nameKeyword,n.urlKeyword,n.customType,function(r,a){if(a)return n.isLoading=!1,void U(null,a,t);var s=r;try{e=String(s.next)}catch(n){e=""}e||(n.hasNext=!1);var i=s.channels,o=[];i.forEach(function(e){var n=b.upsert(e);o.push(n)}),n.isLoading=!1,U(o,null,t)})):void U([],null,t)}},Q=function(e){var n=e,t=0x8000000000000000;this.hasMore=!0,this.isLoading=!1;var r=this;this.load=function(e,a,s,i){if(3!==arguments.length&&4!==arguments.length){if("function"!=typeof i){var o=Array.prototype.slice.call(arguments);"function"==typeof o.slice(-1)[0]&&(i=o.pop())}return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),i)}if("function"==typeof s&&(i=s,s=""),s.toString().toLowerCase()===O.MESSAGE_TYPE_ADMIN||s===_.MessageTypeFilter.ADMIN?s="ADMM":s.toString().toLowerCase()===O.MESSAGE_TYPE_USER||s===_.MessageTypeFilter.USER?s="MESG":s.toString().toLowerCase()===O.MESSAGE_TYPE_FILE||s===_.MessageTypeFilter.FILE?s="FILE":null!==s&&void 0!==s&&s!==_.MessageTypeFilter.ALL||(s=""),!E(e)||"boolean"!=typeof a||"string"!=typeof s)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),i);if(r.hasMore){if(r.isLoading)return void U(null,new p("Query in progress.",J.QUERY_IN_PROGRESS),i);r.isLoading=!0,j.getInstance().messageList(n.isOpenChannel(),n.url,t,e,0,!1,a,s,"",function(a,s){if(s)return r.isLoading=!1,void U(null,s,i);var o=a.messages,l=[];for(var u in o){var c=O.build(o[u],n);c&&(l.push(c),c.createdAt<=t&&(t=c.createdAt))}(l.length<=0||l.length300?R(j.API_ROUTING_URL.replace("%s",T),{},"GET",{SendBird:l+T},function(r,i){if(i)return void e(null,new p("Server is unreachable.",J.NETWORK_ROUTING_ERROR));a=r.ws_server,s=r.api_server,n=t,"function"==typeof e&&e({API_HOST:s,WS_HOST:a})}):e({API_HOST:Z.getInstance().getCurrentApiHost(),WS_HOST:Z.getInstance().getCurrentWsHost()},null)}};var t=function(e,n,t,r,a,s,i,u,c,h){if(!Z.getInstance().hasLoggedIn())return void(i&&i(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED)));j.getInstance().checkRouting(function(n,E){if(E)i(null,new p("Request failed.",J.REQUEST_FAILED));else{var I=v();I.open("POST",n.API_HOST+e,!0),I.setRequestHeader("SendBird",l+T),I.setRequestHeader("Session-Key",j.getInstance().sessionKey);var _=o?new o:new FormData;r&&"undefined"!=typeof Blob?_.append("file",new Blob([t],{type:r}),t.name):_.append("file",t,t.name),s&&_.append("channel_url",s);for(var f in a){var g=parseInt(f)+1;_.append("thumbnail"+g,a[f].maxWidth+","+a[f].maxHeight)}I.onload=function(){c&&c[h]&&delete c[h];I.status>=200&&I.status<400?d(null,JSON.parse(I.responseText),i):d({status:I.status,statusText:I.statusText,response:I.responseText},null,i)},I.onerror=function(e){c&&c[h]&&delete c[h],i(null,new p(I.statusText,J.REQUEST_FAILED))},I.onabort=function(e){c&&c[h]&&delete c[h],i(null,new p("File upload has been cancelled.",J.REQUEST_CANCELLED))},I.upload.onprogress=function(e){e.lengthComputable&&e.loaded>=e.total&&c&&c[h]&&delete c[h],u&&u(e)},_.oldIE?(I.setRequestHeader("Content-Type","multipart/form-data; boundary="+_.boundary),I.send(_.toString())):I.send(_),c&&(c[h]=I)}})},r=function(e,n,t){if("function"==typeof n&&(t=n,n={}),!Z.getInstance().hasLoggedIn())return void(t&&t(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED)));j.getInstance().checkRouting(function(r,a){a?t(null,new p("Request failed.",J.REQUEST_FAILED)):R(r.API_HOST+e,n,"DELETE",{"Session-Key":j.getInstance().sessionKey,SendBird:l+T},t)})},i=function(e){var n="";for(var t in e)e.hasOwnProperty(t)&&(n+=encodeURIComponent(e[t])+",");return n.length>1&&(n=n.substring(0,n.length-1)),n},u=function(e,n,t){if("function"==typeof n&&(t=n,n={}),!Z.getInstance().hasLoggedIn())return void(t&&t(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED)));var r,a="";if(n){for(var s in n)""!=a&&(a+="&"),a+=s+"="+n[s];r=e+"?"+a}else r=e;j.getInstance().checkRouting(function(e,a){a?t(null,new p("Request failed.",J.REQUEST_FAILED)):R(e.API_HOST+r,n,"GET",{"Session-Key":j.getInstance().sessionKey,SendBird:l+T},t)})},c=function(e,n,t){if("function"==typeof n&&(t=n,n={}),!Z.getInstance().hasLoggedIn())return void(t&&t(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED)));j.getInstance().checkRouting(function(r,a){a?t(null,a):R(r.API_HOST+e,n,"POST",{"Session-Key":j.getInstance().sessionKey,SendBird:l+T},t)})},E=function(e,n,t){if("function"==typeof n&&(t=n,n={}),!Z.getInstance().hasLoggedIn())return void(t&&t(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED)));j.getInstance().checkRouting(function(r,a){a||R(r.API_HOST+e,n,"PUT",{"Session-Key":j.getInstance().sessionKey,SendBird:l+T},t)})};this.createUserMetaData=function(e,n,t){var r=j.API_USERS_USERID_METADATA.replace("%s",encodeURIComponent(e)),a={};a.metadata=n,c(r,a,t)},this.updateUserMetaData=function(e,n,t,r){var a=j.API_USERS_USERID_METADATA.replace("%s",encodeURIComponent(e)),s={};s.metadata=n,s.upsert=t,E(a,s,r)},this.deleteAllUserMetaData=function(e,n){var t=j.API_USERS_USERID_METADATA.replace("%s",encodeURIComponent(e));r(t,{},n)},this.deleteUserMetaData=function(e,n,t){var a=j.API_USERS_USERID_METADATA_KEY.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));r(a,{},t)},this.resetMyHistory=function(e,n){var t=j.API_GROUPCHANNELS_RESET_USER_HISTORY.replace("%s",encodeURIComponent(e));E(t,{},n)},this.groupChannelInvite=function(e,n,t){var r=j.API_GROUPCHANNELS_CHANNELURL_INVITE.replace("%s",encodeURIComponent(e)),a={},s=[];try{Array.isArray(n)?s=n:s.push(n)}catch(e){t(null,new p("Invalid parameter.",J.INVALID_PARAMETER))}a.user_ids=s,c(r,a,t)},this.acceptInvitation=function(e,n,t){var r=j.API_GROUPCHANNELS_CHANNELURL_ACCEPT_INVITATION.replace("%s",encodeURIComponent(e)),a={};a.user_id=n,E(r,a,t)},this.declineInvitation=function(e,n,t){var r=j.API_GROUPCHANNELS_CHANNELURL_DECLINE_INVITATION.replace("%s",encodeURIComponent(e)),a={};a.user_id=n,E(r,a,t)},this.groupChannelHide=function(e,n,t,r){var a=j.API_GROUPCHANNELS_CHANNELURL_HIDE.replace("%s",encodeURIComponent(e)),s={};s.user_id=n,s.hide_previous_messages=t,E(a,s,r)},this.groupChannelLeave=function(e,n,t){var r=j.API_GROUPCHANNELS_CHANNELURL_LEAVE.replace("%s",encodeURIComponent(e)),a={};a.user_id=n,E(r,a,t)},this.groupChannelMarkAsRead=function(e,n,t){var r=j.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MARKASREAD.replace("%s",encodeURIComponent(e)),a={};a.user_id=n,E(r,a,t)},this.groupChannelMarkAsReadAll=function(e,n){var t=j.API_USERS_USERID_MARKASREADALL.replace("%s",encodeURIComponent(e));E(t,{},n)},this.messageList=function(e,n,t,r,a,s,i,o,l,c){var d;d=e?String(j.API_OPENCHANNELS_CHANNELURL_MESSAGES.replace("%s",n)):String(j.API_GROUPCHANNELS_CHANNELURL_MESSAGES.replace("%s",n));var h={};h.is_sdk=String(!0),h.message_ts=String(t),h.prev_limit=String(r),h.next_limit=String(a),h.include=String(s),h.reverse=String(i),o&&(h.message_type=String(o)),l&&(h.custom_type=String(l)),u(d,h,c)},this.messageListByID=function(e,n,t,r,a,s,i,o,l,c){var d;d=e?String(j.API_OPENCHANNELS_CHANNELURL_MESSAGES.replace("%s",n)):String(j.API_GROUPCHANNELS_CHANNELURL_MESSAGES.replace("%s",n));var h={};h.is_sdk=String(!0),h.message_id=t,h.prev_limit=String(r),h.next_limit=String(a),h.include=String(s),h.reverse=String(i),o&&(h.message_type=String(o)),l&&(h.custom_type=String(l)),u(d,h,c)},this.login=function(e,n,t){var r=j.API_USERS_USERID_LOGIN.replace("%s",encodeURIComponent(e)),a={};a.app_id=T,n&&(a.access_token=n),c(r,a,function(e,n){n?t(null,n):(j.getInstance().sessionKey=e.key,j.getInstance().ekey=e.ekey,t(e,n))})},this.updateUserInfo=function(e,n,t,r){var a={};n&&(a.nickname=n),t&&(a.profile_url=t);var s=String(j.API_USERS_USERID).replace("%s",encodeURIComponent(e));E(s,a,r)},this.getGroupChannel=function(e,n,t,r){var a=j.API_GROUPCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)),s={member:String(n),read_receipt:String(t)};u(a,s,r)},this.getOpenChannel=function(e,n){var t=j.API_OPENCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e));u(t,n)},this.createGroupChannel=function(e,n,t,r,a,s,i){var l=j.API_GROUPCHANNELS,u=[];"string"==typeof e?u.push(e):e.forEach(function(e){u.push(e)});var d;r&&"string"!=typeof r?(d=o?new o:new FormData,r&&d.append("cover_file",r,r.name),d.append("user_ids",u),d.append("is_distinct",n),null!==t&&"string"==typeof t&&d.append("name",t),a&&d.append("data",a),s&&d.append("custom_type",s)):(d={},null!==r&&"string"==typeof r&&(d.cover_url=r),d.user_ids=u,d.is_distinct=n,null!==t&&"string"==typeof t&&(d.name=t),a&&(d.data=a),s&&(d.custom_type=s)),c(l,d,i)},this.createOpenChannel=function(e,n,t,r,a,s){var i,l=String(j.API_OPENCHANNELS);n&&"string"!=typeof n?(i=o?new o:new FormData,n&&i.append("cover_file",n,n.name),null!==e&&"string"==typeof e&&i.append("name",e),t&&i.append("data",t),r&&(Array.isArray(r)?i.append("operators",r):i.append("operators",[r])),a&&i.append("custom_type",a)):(i={},null!==n&&"string"==typeof n&&(i.cover_url=n),null!==e&&"string"==typeof e&&(i.name=e),t&&(i.data=t),r&&(Array.isArray(r)?i.operators=r:i.operators=[r]),a&&(i.custom_type=a)),c(l,i,s)},this.updateGroupChannel=function(e,n,t,r,a,s,i){var l,u=String(j.API_GROUPCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)));r&&"string"!=typeof r?(l=o?new o:new FormData,l.append("is_distinct",n),r&&l.append("cover_file",r,r.name),null!==t&&"string"==typeof t&&l.append("name",t),null!==a&&"string"==typeof a&&l.append("data",a),null!==s&&"string"==typeof s&&l.append("custom_type",s)):(l={},l.is_distinct=n,null!==r&&"string"==typeof r&&(l.cover_url=r),null!==t&&"string"==typeof t&&(l.name=t),null!==a&&"string"==typeof a&&(l.data=a),null!==s&&"string"==typeof s&&(l.custom_type=s)),E(u,l,i)},this.updateOpenChannel=function(e,n,t,r,a,s,i){var l,u=String(j.API_OPENCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)));t&&"string"!=typeof t?(l=o?new o:new FormData,t&&l.append("cover_file",t,t.name),null!==n&&"string"==typeof n&&l.append("name",n),null!==r&&"string"==typeof r&&l.append("data",r),null!==a&&(Array.isArray(a)?l.append("operators",a):l.append("operators",[a])),null!==s&&"string"==typeof s&&l.append("custom_type",s)):(l={},null!==t&&"string"==typeof t&&(l.cover_url=t),null!==n&&"string"==typeof n&&(l.name=n),null!==r&&"string"==typeof r&&(l.data=r),null!==a&&(Array.isArray(a)?l.operators=a:l.operators=[a]),null!==s&&"string"==typeof s&&(l.custom_type=s)),E(u,l,i)},this.deleteOpenChannel=function(e,n){var t=String(j.API_OPENCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)));r(t,{},n)},this.createMetaCounters=function(e,n,t,r){var a;a=e?j.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):j.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n));var s={};s.metacounter=t,c(a,s,r)},this.updateMetaCounters=function(e,n,t,r,a,s){var i;i=e?j.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):j.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n));var o={};switch(o.metacounter=t,o.upsert=r,a){case j.UPDATE_META_COUNTER_MODE_SET:o.mode="set";break;case j.UPDATE_META_COUNTER_MODE_INC:o.mode="increase";break;case j.UPDATE_META_COUNTER_MODE_DEC:o.mode="decrease"}E(i,o,s)},this.getAllMetaCounters=function(e,n,t){this.getMetaCounters(e,n,{},t)},this.getMetaCounters=function(e,n,t,r){var a;a=e?j.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):j.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n));var s=i(t);u(a,{keys:s},r)},this.deleteMetaCounter=function(e,n,t,a){var s="";s=e?j.API_OPENCHANNELS_CHANNELURL_METACOUNTER_KEY.replace("%s",encodeURIComponent(n)).replace("%s",t):j.API_GROUPCHANNELS_CHANNELURL_METACOUNTER_KEY.replace("%s",encodeURIComponent(n)).replace("%s",t),r(s,{},a)},this.deleteAllMetaCounters=function(e,n,t){var a="";a=e?j.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):j.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)),r(a,{},t)},this.createMetaData=function(e,n,t,r){var a="";a=e?j.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):j.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n));var s={},i={};for(var o in t){var l=t[o];i[o]=l}s.metadata=i,c(a,s,r)},this.updateMetaData=function(e,n,t,r,a){var s="";s=e?j.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):j.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n));var i={},o={};for(var l in t){var u=t[l];o[l]=u}i.metadata=o,i.upsert=r,E(s,i,a)},this.getAllMetaData=function(e,n,t){this.getMetaData(e,n,{},t)},this.getMetaData=function(e,n,t,r){var a="";a=e?j.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):j.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n));var s=i(t);u(a,{keys:s},r)},this.deleteMetaData=function(e,n,t,a){var s="";s=e?j.API_OPENCHANNELS_CHANNELURL_METADATA_KEY.replace("%s",encodeURIComponent(n)).replace("%s",t):j.API_GROUPCHANNELS_CHANNELURL_METADATA_KEY.replace("%s",encodeURIComponent(n)).replace("%s",t),r(s,{},a)},this.deleteAllMetaData=function(e,n,t){var a="";a=e?j.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):j.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)),r(a,{},t)},this.loadUserList=function(e,n,t,r,a,s){var i=j.API_USERS,o={token:encodeURIComponent(e),limit:String(n)};if(!h(t))try{var l="";for(var c in t){var d=t[c];l+=encodeURIComponent(d)+","}l.length>1&&(l=l.substring(0,l.length-1)),o.user_ids=l}catch(e){}if(r&&!h(a)){var E="";a.forEach(function(e){E+=encodeURIComponent(e)+","}),E.length>0&&(E=E.substring(0,E.length-1)),o.metadatakey=encodeURIComponent(r),o.metadatavalues_in=E}u(i,o,s)},this.loadBlockedUserList=function(e,n,t,r){var a=j.API_USERS_USERID_BLOCK.replace("%s",encodeURIComponent(e)),s={token:encodeURIComponent(n),limit:String(t)};u(a,s,r)},this.loadOpenChannelList=function(e,n,t,r,a,s){var i=j.API_OPENCHANNELS,o={token:encodeURIComponent(e),limit:String(n)};null!==t&&(o.name_contains=encodeURIComponent(t)),r&&(o.url_contains=encodeURIComponent(r)),null!==a&&(o.custom_type=encodeURIComponent(a)),u(i,o,s)},this.uploadFile=function(e,n,r,a,s,i,o,l){t(j.API_STORAGE_FILE,0,e,n,r,a,s,i,o,l)},this.uploadProfileImage=function(e,n){t(j.API_STORAGE_PROFILE,0,e,"",[],"",n)},this.loadUserGroupChannelList=function(e,n,t,r,a,s,o,l,c,d,h,E,I){var p=j.API_MYGROUPCHANNELS.replace("%s",encodeURIComponent(e)),_={token:encodeURIComponent(n),limit:String(t),show_member:!0,show_read_receipt:!0,show_empty:String(r),order:a,member_state_filter:d};if(E&&(_.custom_type=encodeURIComponent(E)),l)try{_.members_nickname_contains=encodeURIComponent(l)}catch(e){}if(h)try{_.name_contains=encodeURIComponent(h)}catch(e){}if(s.length>0)try{o?_.members_exactly_in=i(s):(_.members_include_in=i(s),_.query_type=c)}catch(e){}u(p,_,I)},this.loadOpenChannelParticipantList=function(e,n,t,r){var a=j.API_OPENCHANNELS_CHANNELURL_PARTICIPANTS.replace("%s",e),s={token:encodeURIComponent(n),limit:String(t)};u(a,s,r)},this.loadOpenChannelMutedList=function(e,n,t,r){var a=j.API_OPENCHANNELS_CHANNELURL_MUTE.replace("%s",e),s={token:encodeURIComponent(n),limit:String(t)};u(a,s,r)},this.loadOpenChannelBanList=function(e,n,t,r){var a=j.API_OPENCHANNELS_CHANNELURL_BAN.replace("%s",e),s={token:encodeURIComponent(n),limit:String(t)};u(a,s,r)},this.setPushTemplate=function(e,n,t){var r=j.API_USERS_USERID_PUSH_TEMPLATE.replace("%s",encodeURIComponent(e));E(r,{name:n},t)},this.getPushTemplate=function(e,n){var t=j.API_USERS_USERID_PUSH_TEMPLATE.replace("%s",encodeURIComponent(e));u(t,n)},this.setDoNotDisturb=function(e,n,t,r,a,s,i,o){var l=j.API_USERS_USERID_PUSHPREFERENCE.replace("%s",encodeURIComponent(e));E(l,{do_not_disturb:n,start_hour:t,start_min:r,end_hour:a,end_min:s,timezone:i},o)},this.getDoNotDisturb=function(e,n){var t=j.API_USERS_USERID_PUSHPREFERENCE.replace("%s",encodeURIComponent(e));u(t,n)},this.setPushPreference=function(e,n,t,r){var a=j.API_USERS_USERID_PUSHPREFERENCE_CHANNELURL.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n)),s={};s.enable=t,E(a,s,r)},this.getPushPreference=function(e,n,t){var r=j.API_USERS_USERID_PUSHPREFERENCE_CHANNELURL.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));u(r,t)},this.registerGCMPushToken=function(e,n,t){var r=j.API_USERS_USERID_PUSH_GCM.replace("%s",encodeURIComponent(e));c(r,{gcm_reg_token:n},t)},this.unregisterGCMPushToken=function(e,n,t){var a=j.API_USERS_USERID_PUSH_GCM_TOKEN.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));r(a,t)},this.unregisterGCMPushTokenAll=function(e,n){var t=j.API_USERS_USERID_PUSH_GCM.replace("%s",encodeURIComponent(e));r(t,n)},this.registerAPNSPushToken=function(e,n,t){var r=j.API_USERS_USERID_PUSH_APNS.replace("%s",encodeURIComponent(e));c(r,{apns_device_token:n},t)},this.unregisterAPNSPushToken=function(e,n,t){var a=j.API_USERS_USERID_PUSH_APNS_TOKEN.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));r(a,t)},this.unregisterAPNSPushTokenAll=function(e,n){var t=j.API_USERS_USERID_PUSH_APNS.replace("%s",encodeURIComponent(e));r(t,n)},this.unregisterPushTokenAll=function(e,n){var t=j.API_USERS_USERID_PUSH.replace("%s",encodeURIComponent(e));r(t,n)},this.blockUser=function(e,n,t){var r=j.API_USERS_USERID_BLOCK.replace("%s",encodeURIComponent(e));c(r,{target_id:n},t)},this.unblockUser=function(e,n,t){var a=j.API_USERS_USERID_BLOCK_TARGETID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));r(a,{},t)},this.banUser=function(e,n,t,r,a){var s=j.API_OPENCHANNELS_CHANNELURL_BAN.replace("%s",encodeURIComponent(e)),i={user_id:n};t&&(i.description=t),i.seconds=String(r),c(s,i,a)},this.unbanUser=function(e,n,t){var a=j.API_OPENCHANNELS_CHANNELURL_BAN_USERID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));r(a,{},t)},this.muteUser=function(e,n,t){var r=j.API_OPENCHANNELS_CHANNELURL_MUTE.replace("%s",encodeURIComponent(e));c(r,{user_id:n},t)},this.unmuteUser=function(e,n,t){var a=j.API_OPENCHANNELS_CHANNELURL_MUTE_USERID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));r(a,{},t)},this.deleteMessage=function(e,n,t,a){var s="";s=e?j.API_OPENCHANNELS_CHANNELURL_MESSAGES_MESSAGEID.replace("%s",encodeURIComponent(n)).replace("%s",encodeURIComponent(t)):j.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MESSAGEID.replace("%s",encodeURIComponent(n)).replace("%s",encodeURIComponent(t)),r(s,{},a)}},X=null;j.getInstance=function(){return null===X?null:X},j.API_VERSION="v3",j.API_ROUTING_URL="https://api-p.sendbird.com/routing/%s",j.API_USERS="/%v/users".replace("%v",j.API_VERSION),j.API_USERS_USERID_LOGIN="/%v/users/%s/login".replace("%v",j.API_VERSION),j.API_USERS_USERID="/%v/users/%s".replace("%v",j.API_VERSION),j.API_USERS_USERID_METADATA="/%v/users/%s/metadata".replace("%v",j.API_VERSION),j.API_USERS_USERID_METADATA_KEY="/%v/users/%s/metadata/%s".replace("%v",j.API_VERSION),j.API_USERS_USERID_UNREAD_MESSAGE_COUNT="/%v/users/%s/unread_message_count".replace("%v",j.API_VERSION),j.API_USERS_USERID_UNREAD_CHANNEL_COUNT="/%v/users/%s/unread_channel_count".replace("%v",j.API_VERSION),j.API_USERS_USERID_MARKASREADALL="/%v/users/%s/mark_as_read_all".replace("%v",j.API_VERSION),j.API_USERS_USERID_PUSH_GCM_TOKEN="/%v/users/%s/push/gcm/%s".replace("%v",j.API_VERSION),j.API_USERS_USERID_PUSH_GCM="/%v/users/%s/push/gcm".replace("%v",j.API_VERSION),j.API_USERS_USERID_PUSHPREFERENCE_CHANNELURL="/%v/users/%s/push_preference/%s".replace("%v",j.API_VERSION),j.API_USERS_USERID_PUSHPREFERENCE="/%v/users/%s/push_preference/".replace("%v",j.API_VERSION),j.API_USERS_USERID_PUSH_TEMPLATE="/%v/users/%s/push/template".replace("%v",j.API_VERSION),j.API_USERS_USERID_BLOCK="/%v/users/%s/block".replace("%v",j.API_VERSION),j.API_USERS_USERID_BLOCK_TARGETID="/%v/users/%s/block/%s".replace("%v",j.API_VERSION),j.API_USERS_USERID_PUSH_APNS_TOKEN="/%v/users/%s/push/apns/%s".replace("%v",j.API_VERSION),j.API_USERS_USERID_PUSH_APNS="/%v/users/%s/push/apns".replace("%v",j.API_VERSION),j.API_USERS_USERID_PUSH="/%v/users/%s/push".replace("%v",j.API_VERSION),j.API_USERS_USERID_GROUP_CHANNEL_INVITATION_PREFERENCE="/%v/users/%s/channel_invitation_preference".replace("%v",j.API_VERSION),j.API_USERS_USERID_GROUP_CHANNEL_COUNT="/%v/users/%s/group_channel_count".replace("%v",j.API_VERSION),j.API_OPENCHANNELS="/%v/open_channels".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL="/%v/open_channels/%s".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_MESSAGES="/%v/open_channels/%s/messages".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_MESSAGES_MESSAGEID="/%v/open_channels/%s/messages/%s".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_PARTICIPANTS="/%v/open_channels/%s/participants".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_METADATA="/%v/open_channels/%s/metadata".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_METADATA_KEY="/%v/open_channels/%s/metadata/%s".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_METACOUNTER="/%v/open_channels/%s/metacounter".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_METACOUNTER_KEY="/%v/open_channels/%s/metacounter/%s".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_BAN="/%v/open_channels/%s/ban".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_BAN_USERID="/%v/open_channels/%s/ban/%s".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_MUTE="/%v/open_channels/%s/mute".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_MUTE_USERID="/%v/open_channels/%s/mute/%s".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS="/%v/group_channels".replace("%v",j.API_VERSION),j.API_MYGROUPCHANNELS="/%v/users/%s/my_group_channels".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL="/%v/group_channels/%s".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_INVITE="/%v/group_channels/%s/invite".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_ACCEPT_INVITATION="/%v/group_channels/%s/accept".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_DECLINE_INVITATION="/%v/group_channels/%s/decline".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_HIDE="/%v/group_channels/%s/hide".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_LEAVE="/%v/group_channels/%s/leave".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_MESSAGES="/%v/group_channels/%s/messages".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MARKASREAD="/%v/group_channels/%s/messages/mark_as_read".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_MESSAGES_TOTALCOUNT="/%v/group_channels/%s/messages/total_count".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_MESSAGES_UNREADCOUNT="/%v/group_channels/%s/messages/unread_count".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MESSAGEID="/%v/group_channels/%s/messages/%s".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_MEMBERS="/%v/group_channels/%s/members".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_METADATA="/%v/group_channels/%s/metadata".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_METADATA_KEY="/%v/group_channels/%s/metadata/%s".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_METACOUNTER="/%v/group_channels/%s/metacounter".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_METACOUNTER_KEY="/%v/group_channels/%s/metacounter/%s".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_RESET_USER_HISTORY="/%v/group_channels/%s/reset_user_history".replace("%v",j.API_VERSION),j.API_STORAGE_FILE="/%v/storage/file".replace("%v",j.API_VERSION),j.API_STORAGE_PROFILE="/%v/storage/profile_image".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_MESSAGES_CHANGELOGS="/%v/open_channels/%s/messages/changelogs".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_MESSAGES_CHANGELOGS="/%v/group_channels/%s/messages/changelogs".replace("%v",j.API_VERSION),j.UPDATE_META_COUNTER_MODE_SET=0,j.UPDATE_META_COUNTER_MODE_INC=1,j.UPDATE_META_COUNTER_MODE_DEC=2;var Z=function(e){var n=Z.getInstance();if(n)return n;try{if(!e.hasOwnProperty("appId"))return t.log("Must be set appId"),{}}catch(e){return t.log("Must be set appId"),{}}this.GCMPushToken="",this.APNSPushToken="",this.PUSH_TEMPLATE_DEFAULT="default",this.PUSH_TEMPLATE_ALTERNATIVE="alternative",this.pushTokenRegistrationState={SUCCESS:"success",PENDING:"pending",ERROR:"error"},this.loginTimer,this.onLoginTimerCancel,this.globalTimer,this.reconnectTimer,this.onReconnectTimerCancel,this.currentUser=null,this.getCurrentUserId=function(){return Z.getInstance().currentUser?Z.getInstance().currentUser.userId:null},this.wsClient,this.connectionState={CONNECTING:"CONNECTING",OPEN:"OPEN",CLOSING:"CLOSING",CLOSED:"CLOSED"},this.ConnectionState=this.connectionState,this.BaseChannel=_,this.User=F,this.Member=Y,this.OpenChannel=b,this.GroupChannel=w,this.UserMessage=M,this.FileMessage=D,this.AdminMessage=L,this.channelHandlers={},this.connectionHandlers={};var i={};T=e.appId,$=this,X=j.getInstance(),X||(X=new j),this.Options={UseMemberAsMessageSender:!1},this.customApiHost=null,this.customWsHost=null,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){},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.addChannelHandler=function(e,n){Z.getInstance().channelHandlers[e]=n},this.removeChannelHandler=function(e){delete Z.getInstance().channelHandlers[e]},this.removeAllChannelHandlers=function(){Z.getInstance().channelHandlers={}},this.ConnectionHandler=function(){this.onReconnectStarted=function(){},this.onReconnectSucceeded=function(){},this.onReconnectFailed=function(){}},this.addConnectionHandler=function(e,n){Z.getInstance().connectionHandlers[e]=n},this.removeConnectionHandler=function(e){delete Z.getInstance().connectionHandlers[e]},this.removeAllConnectionHandlers=function(){Z.getInstance().connectionHandlers={}},this.createUserListQuery=function(e){return e?new x(x.FILTERED_USER,e):new x(x.ALL_USER)},this.createBlockedUserListQuery=function(){return new x(x.BLOCKED_USER)},this.getApplicationId=function(){return T},this.getDebugMode=function(){return r},this.setDebugMode=function(e){r=e},this.setAPIHost=function(e){s=e},this.setWSHost=function(e){a=e},this.clearCurrentApiHost=function(){this.customApiHost=null},this.getCurrentApiHost=function(){return this.customApiHost?this.customApiHost:s},this.clearCurrentWsHost=function(){this.customWsHost=null},this.getCurrentWsHost=function(){return this.customWsHost?this.customWsHost:a},this.setErrorFirstCallback=function(e){S=e},this.getConnectionState=function(){if(!Z.getInstance())return this.connectionState.CLOSED;try{return Z.getInstance().wsClient?Z.getInstance().wsClient.getConnectionState():Z.getInstance().connectionState.CLOSED}catch(e){return Z.getInstance().connectionState.CLOSED}},this.hasLoggedIn=function(){return Z.getInstance().currentUser&&j.getInstance().sessionKey};var o=function(e){return i.hasOwnProperty(e)?i[e]:null},l=function(e){var n=new B(e);if(n.requestId){var r=o(n.requestId);if(null==r)return;clearTimeout(r.timer);var a=r.handler;if(a)if("EROR"==n.command){var s=n.getJsonElement(),i=s.code,l=s.message;a(n,new p(l,i))}else a(n,null)}else switch(n.command){case"LOGI":if(Z.getInstance().loginTimer){clearTimeout(Z.getInstance().loginTimer),Z.getInstance().loginTimer=null,Z.getInstance().onLoginTimerCancel=null;var d=n.getJsonElement();if(d.hasOwnProperty("error")){var i=d.code,l=d.message;Z.getInstance().loginHandler(null,new p(l,i))}else d.hasOwnProperty("key")&&(j.getInstance().sessionKey=d.key),d.hasOwnProperty("ekey")&&(j.getInstance().ekey=d.ekey),d.hasOwnProperty("user_id")&&(Z.getInstance().currentUser=new F(d)),Z.getInstance().loginHandler(Z.getInstance().currentUser,null)}break;case"MESG":case"FILE":case"BRDM":case"ADMM":var h="",E=!1;if("MESG"==n.command?h=new M(n.getJsonElement()):"FILE"==n.command?h=new D(n.getJsonElement()):(h=new L(n.getJsonElement()),n.getJsonElement().hasOwnProperty("silent")&&(E=n.getJsonElement().silent)),!h)return;if(h.isGroupChannel()){var I=w.cachedChannels.hasOwnProperty(h.channelUrl);w.getChannel(h.channelUrl,function(e,n){if(S){var t=e;e=n,n=t}if(n)return void(a&&a(null,n));if(e.isHidden=!1,w.cachedChannels[e.url]=e,h._sender&&e.memberMap.hasOwnProperty(h._sender.userId)){var r=e.memberMap[h._sender.userId];r.nickname!=h._sender.nickname&&(r.nickname=h._sender.nickname),r.profileUrl!=h._sender.profileUrl&&(r.profileUrl=h._sender.profileUrl)}var s=Z.getInstance().currentUser;if(s&&h._sender&&s.userId==h._sender.userId&&(s.nickname!=h._sender.nickname&&(s.nickname=h._sender.nickname),s.profileUrl!=h._sender.profileUrl&&(s.profileUrl=h._sender.profileUrl)),!E){I&&(e.updatedLocal?(e.lastMessage=h,h.sender&&h.sender.userId==Z.getInstance().getCurrentUserId()||e.unreadMessageCount++):(!e.lastMessage||e.lastMessage.createdAt0){e.unreadMessageCount=0;for(var r in Z.getInstance().channelHandlers){var s=Z.getInstance().channelHandlers[r];s.onChannelChanged(e)}}}else if(0==e.unreadMessageCount)for(var r in Z.getInstance().channelHandlers){var s=Z.getInstance().channelHandlers[r];s.onChannelChanged(e)}}else{e.updateReadReceipt(_.reader.userId,_.timestamp);for(var r in Z.getInstance().channelHandlers){var s=Z.getInstance().channelHandlers[r];s.onReadReceiptUpdated(e)}}}) -;break;case"TPST":case"TPEN":case"MTIO":break;case"SYEV":c(n);break;case"USEV":u(n);break;case"DELM":var f=n.getJsonElement(),g=String(f.channel_type),A=String(f.channel_url),C=String(f.msg_id);switch(g){case H.CHANNEL_TYPE_OPEN:b.getChannel(A,function(e,n){if(S){var r=e;e=n,n=r}if(n)return void t.log("Discard a command.");for(var a in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[a].onMessageDeleted(e,C)}});break;case H.CHANNEL_TYPE_GROUP:w.getChannel(A,function(e,n){if(S){var r=e;e=n,n=r}if(n)return void t.log("Discard a command.");for(var a in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[a].onMessageDeleted(e,C)}})}}},u=function(e){var n=new k(e.getJsonElement());switch(n.category){case G.CATEGORY_USER_BLOCK:case G.CATEGORY_USER_UNBLOCK:var t=n.data.blocker.user_id,r=n.data.blockee.user_id;Object.keys(w.cachedChannels).forEach(function(e){var a=w.cachedChannels[e];try{Z.getInstance().getCurrentUserId()===t?a.memberMap[r].isBlockedByMe=n.category===G.CATEGORY_USER_BLOCK:Z.getInstance().getCurrentUserId()===r&&(a.memberMap[t].isBlockingMe=n.category===G.CATEGORY_USER_BLOCK)}catch(e){}})}},c=function(e){var n=new k(e.getJsonElement());switch(n.category){case k.CATEGORY_CHANNEL_JOIN:case k.CATEGORY_CHANNEL_LEAVE:w.getChannel(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);var i=new F(n.data);if(n.category==k.CATEGORY_CHANNEL_JOIN){n.data.state=Y.JOINED,r.addMember(new Y(n.data));for(var o in Z.getInstance().channelHandlers){var l=Z.getInstance().channelHandlers[o];l.onUserJoined(r,i)}}else{i.userId==Z.getInstance().getCurrentUserId()&&w.removeCachedChannel(n.channelUrl),r.removeMember(i);for(var o in Z.getInstance().channelHandlers){var l=Z.getInstance().channelHandlers[o];l.onUserLeft(r,i)}}});break;case k.CATEGORY_CHANNEL_INVITE:w.getChannel(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);var i=null;n.data&&n.data.inviter&&!h(n.data.inviter)&&(i=new F(n.data.inviter));var o=[];for(var l in n.data.invitees){n.data.invitees[l].state=Y.INVITED;var u=new Y(n.data.invitees[l]);o.push(u),r.addMember(u)}for(var l in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[l].onUserReceivedInvitation(r,i,o)}});break;case k.CATEGORY_CHANNEL_DECLINE_INVITE:w.getChannel(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);var i=null;n.data&&n.data.inviter&&!h(n.data.inviter)&&(i=new F(n.data.inviter));var o=new F(n.data.invitee);o.userId==Z.getInstance().getCurrentUserId()&&w.removeCachedChannel(n.channelUrl),r.removeMember(o);for(var l in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[l].onUserDeclinedInvitation(r,i,o)}});break;case k.CATEGORY_TYPING_START:case k.CATEGORY_TYPING_END:w.getChannel(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);var i=new F(n.data);n.category==k.CATEGORY_TYPING_START?r.updateTypingStatus(i,!0):r.updateTypingStatus(i,!1);for(var o in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[o].onTypingStatusUpdated(r)}});break;case k.CATEGORY_CHANNEL_ENTER:case k.CATEGORY_CHANNEL_EXIT:b.getChannel(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);n.data.hasOwnProperty("participant_count")&&(r.participantCount=n.data.participant_count);var i=new F(n.data);if(n.category==k.CATEGORY_CHANNEL_ENTER)for(var o in Z.getInstance().channelHandlers){var l=Z.getInstance().channelHandlers[o];l.onUserEntered(r,i)}else for(var o in Z.getInstance().channelHandlers){var l=Z.getInstance().channelHandlers[o];l.onUserExited(r,i)}});break;case k.CATEGORY_USER_CHANNEL_MUTE:case k.CATEGORY_USER_CHANNEL_UNMUTE:b.getChannel(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);var i=new F(n.data);if(n.category==k.CATEGORY_USER_CHANNEL_MUTE)for(var o in Z.getInstance().channelHandlers){var l=Z.getInstance().channelHandlers[o];l.onUserMuted(r,i)}else for(var o in Z.getInstance().channelHandlers){var l=Z.getInstance().channelHandlers[o];l.onUserUnmuted(r,i)}});break;case k.CATEGORY_USER_CHANNEL_BAN:case k.CATEGORY_USER_CHANNEL_UNBAN:b.getChannel(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);var i=new F(n.data);if(n.category==k.CATEGORY_USER_CHANNEL_BAN)for(var o in Z.getInstance().channelHandlers){var l=Z.getInstance().channelHandlers[o];l.onUserBanned(r,i)}else for(var o in Z.getInstance().channelHandlers){var l=Z.getInstance().channelHandlers[o];l.onUserUnbanned(r,i)}});break;case k.CATEGORY_CHANNEL_FREEZE:case k.CATEGORY_CHANNEL_UNFREEZE:b.getChannel(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);if(r.isFrozen=n.data.freeze,n.category==k.CATEGORY_CHANNEL_FREEZE)for(var i in Z.getInstance().channelHandlers){var o=Z.getInstance().channelHandlers[i];o.onChannelFrozen(r)}else for(var i in Z.getInstance().channelHandlers){var o=Z.getInstance().channelHandlers[i];o.onChannelUnfrozen(r)}});break;case k.CATEGORY_CHANNEL_DELETED:if(n.isGroupChannel()){w.removeCachedChannel(n.channelUrl);for(var r in Z.getInstance().channelHandlers){var a=Z.getInstance().channelHandlers[r];a.onChannelDeleted(n.channelUrl,"group")}}else{b.removeCachedChannel(n.channelUrl);for(var r in Z.getInstance().channelHandlers){var a=Z.getInstance().channelHandlers[r];a.onChannelDeleted(n.channelUrl,"open")}}break;case k.CATEGORY_CHANNEL_PROP_CHANGED:n.isOpenChannel()?b.getChannelWithoutCache(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);for(var i in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[i].onChannelChanged(r)}}):w.getChannelWithoutCache(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);for(var i in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[i].onChannelChanged(r)}});break;case k.CATEGORY_CHANNEL_META_DATA_CHANGED:case k.CATEGORY_CHANNEL_META_COUNTERS_CHANGED:var s=n.data.hasOwnProperty("created"),i=n.data.hasOwnProperty("updated"),o=n.data.hasOwnProperty("deleted");n.isOpenChannel()?b.getChannel(n.channelUrl,function(r,a){if(S){var l=r;r=a,a=l}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);for(var u in Z.getInstance().channelHandlers){var c=Z.getInstance().channelHandlers[u];n.category==k.CATEGORY_CHANNEL_META_DATA_CHANGED?(s&&c.onMetaDataCreated(r,n.data.created),i&&c.onMetaDataUpdated(r,n.data.updated),o&&c.onMetaDataDeleted(r,n.data.deleted)):(s&&c.onMetaCountersCreated(r,n.data.created),i&&c.onMetaCountersUpdated(r,n.data.updated),o&&c.onMetaCountersDeleted(r,n.data.deleted))}}):w.getChannel(n.channelUrl,function(r,a){if(S){var l=r;r=a,a=l}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);for(var u in Z.getInstance().channelHandlers){var c=Z.getInstance().channelHandlers[u];n.category==k.CATEGORY_CHANNEL_META_DATA_CHANGED?(s&&c.onMetaDataCreated(r,n.data.created),i&&c.onMetaDataUpdated(r,n.data.updated),o&&c.onMetaDataDeleted(r,n.data.deleted)):(s&&c.onMetaCountersCreated(r,n.data.created),i&&c.onMetaCountersUpdated(r,n.data.updated),o&&c.onMetaCountersDeleted(r,n.data.deleted))}});break;case k.CATEGORY_CHANNEL_HIDE:w.getChannel(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);r.isHidden=!0;for(var i in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[i].onChannelHidden(r)}})}};this.setPushTemplate=function(e,n){return!e||e!==this.PUSH_TEMPLATE_DEFAULT&&e!==this.PUSH_TEMPLATE_ALTERNATIVE?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):this.currentUser?void j.getInstance().setPushTemplate(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);var r=e.name.toString();U(r,null,n)}):void U(null,new p("Connection must be made before you set push template",J.CONNECTION_REQUIRED),n)},this.getPushTemplate=function(e){if(!this.currentUser)return void U(null,new p("Connection must be made before you get push template",J.CONNECTION_REQUIRED),e);j.getInstance().getPushTemplate(this.getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);var r=n.name.toString();U(r,null,e)})},this.setChannelInvitationPreference=function(e,n){"boolean"!=typeof e&&U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n),j.getInstance().setChannelInvitationPreference(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U({autoAccept:e.auto_accept},null,n)})},this.getChannelInvitationPreference=function(e){j.getInstance().getChannelInvitationPreference(this.getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);U({autoAccept:n.auto_accept},null,e)})},this.connect=function(){var e=Array.prototype.slice.call(arguments),n=null,a=null,s=null;switch("function"==typeof e.slice(-1)[0]&&(s=e.pop()),e.length){case 1:n=e[0];break;case 2:n=e[0],a=e[1];break;case 3:n=e[0],this.customApiHost=e[1],this.customWsHost=e[2];break;case 4:n=e[0],a=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?(f(!0,null),A(n,a,s)):U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),s)};var d=!1,E=!1,I=!0;this.setBackgroundState=function(){!d&&I&&(d=!0,this.getConnectionState()!=this.connectionState.CLOSED?(E=!0,f(!1,null)):E=!1)},this.setForegroundState=function(){d&&I&&(d=!1,E&&this.currentUser&&(P=0,g(this.getCurrentUserId(),!0)))},this.disableStateChange=function(){I=!1},this.enableStateChange=function(){I=!0},this.disconnect=function(e){f(!0,e)},this.reconnect=function(){if(!j.getInstance().sessionKey||!this.currentUser)return!1;var e=!0;return P>0&&(e=!1),f(!1,null),P=0,g(this.getCurrentUserId(),e),!0};var f=function(e,n){var t=this;Z.getInstance().loginTimer&&(clearTimeout(Z.getInstance().loginTimer),Z.getInstance().onLoginTimerCancel&&(Z.getInstance().onLoginTimerCancel(),Z.getInstance().onLoginTimerCancel=null),Z.getInstance().loginTimer=null),Z.getInstance().reconnectTimer&&(clearTimeout(Z.getInstance().reconnectTimer),Z.getInstance().onReconnectTimerCancel&&(Z.getInstance().onReconnectTimerCancel(),Z.getInstance().onReconnectTimerCancel=null),Z.getInstance().reconnectTimer=null),Z.getInstance().wsClient&&(P=0,Z.getInstance().wsClient.disconnect(!0),Z.getInstance().wsClient=null),function(){if(e){b.clearEnteredChannels(),b.clearCache(),w.clearCache(),Z.getInstance().globalTimer&&(clearTimeout(t.globalTimer),Z.getInstance().globalTimer=null);for(var r in Z.getInstance().ackStateMap)clearTimeout(Z.getInstance().ackStateMap[r].timer);Z.getInstance().ackStateMap={},Z.getInstance().currentUser=null,j.getInstance().sessionKey=null,j.getInstance().ekey=null}U(null,null,n)}()},g=function(e,n){if(Z.getInstance().reconnectTimer)r&&t.log("still reconnecting");else{if((P+=1)<=1){if(n)for(var a in Z.getInstance().connectionHandlers){var s=Z.getInstance().connectionHandlers[a];s.onReconnectStarted(a)}y=0}else y=3e3*Math.pow(2,P-2);if(!e||!j.getInstance().sessionKey||P>=6){f(!1,null),P=0;for(var a in Z.getInstance().connectionHandlers){var s=Z.getInstance().connectionHandlers[a];s.onReconnectFailed(a)}return}Z.getInstance().onReconnectTimerCancel=function(){P=0},Z.getInstance().reconnectTimer=setTimeout(function(){Z.getInstance().reconnectTimer=null,Z.getInstance().onReconnectTimerCancel=null,Z.getInstance().wsClient&&Z.getInstance().wsClient.disconnect(!0);var n=new z.WSClientHandler;Z.getInstance().wsClient=new z(n),Z.getInstance().loginHandler=function(e){P=0;for(var n in b.enteredChannels){b.enteredChannels[n].enter()}for(var n in Z.getInstance().connectionHandlers){Z.getInstance().connectionHandlers[n].onReconnectSucceeded(n)}},n.onOpen=function(){r&&t.log("reconnectWS onOpen"),Z.getInstance().loginTimer=setTimeout(function(){r&&t.log("reconnectWS loginTimer timedout"),Z.getInstance().loginTimer=null,g(e,!0)},1e4),Z.getInstance().onLoginTimerCancel=null},n.onMessage=function(e){l(e)},n.onError=function(){r&&t.log("reconnectWS onError"),g(e,!0)},n.onClose=function(){r&&t.log("reconnectWS onClose")};var a=Z.getInstance().getCurrentApiHost();j.getInstance().checkRouting(function(n,t){if(t)return void g(e,!0);a!=n.API_HOST&&R(n.API_HOST,{},"GET",{},function(){}),Z.getInstance().wsClient.connect(e,null,n.WS_HOST)})},y)}},A=function(e,n,a){var s=new z.WSClientHandler;Z.getInstance().wsClient=new z(s),s.onMessage=function(e){l(e)},Z.getInstance().loginHandler=function(e,n){if(n)Z.getInstance().disconnect(null),U(null,n,a);else{clearTimeout(Z.getInstance().globalTimer);var t=function(){if(w.cachedChannels)for(var e in w.cachedChannels){var n=w.cachedChannels[e];if(n.invalidateTypingStatus())for(var r in Z.getInstance().channelHandlers){var a=Z.getInstance().channelHandlers[r];a.onTypingStatusUpdated(n)}}Z.getInstance().globalTimer=setTimeout(function(){t()},1e3)};t(),U(e,null,a)}},s.onOpen=function(e){Z.getInstance().loginTimer=setTimeout(function(){Z.getInstance().loginTimer=null,Z.getInstance().onLoginTimerCancel=null,Z.getInstance().disconnect(null),U(null,new p("Connection timeout.",J.LOGIN_TIMEOUT),a)},1e4),Z.getInstance().onLoginTimerCancel=function(){U(null,new p("Connection Cancelled.",J.REQUEST_FAILED),a)}},s.onError=function(n){r&&t.log("WSClientHandler.onError",n),j.getInstance().sessionKey?g(e,!0):U(null,new p("Websocket connection failed.",J.WEBSOCKET_CONNECTION_FAILED),a)},s.onClose=function(e){r&&t.log("WSClientHandler.onClose")},j.getInstance().checkRouting(function(t,r){if(r)return void U(null,new p("Connection routing failed.",J.REQUEST_FAILED),a);R(t.API_HOST,{},"GET",{},function(){}),Z.getInstance().wsClient.connect(e,n,t.WS_HOST)})};this.sendCommand=function(e,n){if(!Z.getInstance().hasLoggedIn())return void(n&&n(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED)));if(null==Z.getInstance().wsClient||Z.getInstance().wsClient.getConnectionState()!=Z.getInstance().connectionState.OPEN)return void(n&&n(null,new p("Connection is not valid. Please reconnect.",J.WEBSOCKET_CONNECTION_CLOSED)));if(e.isAckRequired()){var t=e.requestId,r={handler:n,timer:setTimeout(function(){n(null,new p("Command received no ack.",J.ACK_TIMEOUT)),delete i[t]},1e4)};i[t]=r,Z.getInstance().wsClient.send(e,function(e,t){if(t)return clearTimeout(r.timer),void n(null,t)})}else Z.getInstance().wsClient.send(e,n)},this.updateCurrentUserInfoWithProfileImage=function(e,n,t){var r=this;n?j.getInstance().uploadProfileImage(n,function(n,a){if(a)return void U(null,a,t);var s="object"==typeof n?n:JSON.parse(n),i=s.url;r.updateCurrentUserInfo(e,i,t)}):r.updateCurrentUserInfo(e,null,t)},this.updateCurrentUserInfo=function(e,n,t){var r=this;j.getInstance().updateUserInfo(r.getCurrentUserId(),e,n,function(a,s){if(s)return void U(null,s,t);r.currentUser&&(e&&(r.currentUser.nickname=e),n&&(r.currentUser.profileUrl=n)),U(r.currentUser,null,t)})},this.getPendingGCMToken=function(){return this.GCMPushToken},this.getPendingAPNSToken=function(){return this.APNSPushToken},this.registerGCMPushTokenForCurrentUser=function(e,n){var t=this;return e?this.currentUser?void j.getInstance().registerGCMPushToken(this.getCurrentUserId(),e,function(e,r){if(r)return void U(t.pushTokenRegistrationState.ERROR,r,n);t.GCMPushToken="",U(t.pushTokenRegistrationState.SUCCESS,null,n)}):(t.GCMPushToken=e,void U(t.pushTokenRegistrationState.PENDING,null,n)):void U(t.pushTokenRegistrationState.ERROR,new p("Invalid token",J.INVALID_PARAMETER),n)},this.unregisterGCMPushTokenForCurrentUser=function(e,n){if(!e)return void U(null,new p("Invalid token",J.INVALID_PARAMETER),n);j.getInstance().unregisterGCMPushToken(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.unregisterGCMPushTokenAllForCurrentUser=function(e){j.getInstance().unregisterGCMPushTokenAll(this.getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);U(null,null,e)})},this.registerAPNSPushTokenForCurrentUser=function(e,n){var t=this;return e?this.currentUser?void j.getInstance().registerAPNSPushToken(this.getCurrentUserId(),e,function(e,r){if(r)return void U(t.pushTokenRegistrationState.ERROR,r,n);t.APNSPushToken="",U(t.pushTokenRegistrationState.SUCCESS,null,n)}):(t.APNSPushToken=e,void U(t.pushTokenRegistrationState.PENDING,null,n)):void U(t.pushTokenRegistrationState.ERROR,new p("Invalid token",J.INVALID_PARAMETER),n)},this.unregisterAPNSPushTokenForCurrentUser=function(e,n){if(!e)return void U(null,new p("Invalid token",J.INVALID_PARAMETER),n);j.getInstance().unregisterAPNSPushToken(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.unregisterAPNSPushTokenAllForCurrentUser=function(e){j.getInstance().unregisterAPNSPushTokenAll(this.getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);U(null,null,e)})},this.unregisterPushTokenAllForCurrentUser=function(e){j.getInstance().unregisterAPNSPushTokenAll(this.getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);U(null,null,e)})},this.setDoNotDisturb=function(e,n,t,r,a,s,i){var o=this;if(n<0||n>23||t<0||t>59||r<0||r>23||a<0||a>59)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),i);j.getInstance().setDoNotDisturb(o.getCurrentUserId(),e,n,t,r,a,s,function(e,n){if(n)return void U(null,n,i);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};U(t,null,i)})},this.getDoNotDisturb=function(e){var n=this;j.getInstance().getDoNotDisturb(n.getCurrentUserId(),function(n,t){if(t)return void U(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};U(r,null,e)})},this.blockUser=function(e,n){if("object"!=typeof e)return void U(null,new p("You have to pass user object.",J.INVALID_PARAMETER),n);this.blockUserWithUserId(e.userId,n)},this.blockUserWithUserId=function(e,n){if(this.getCurrentUserId()==e)return void U(null,new p("You can not block yourself.",J.INVALID_PARAMETER),n);j.getInstance().blockUser(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(new F(e),null,n)})},this.unblockUser=function(e,n){if("object"!=typeof e)return void U(null,new p("You have to pass user object.",J.INVALID_PARAMETER),n);this.unblockUserWithUserId(e.userId,n)},this.unblockUserWithUserId=function(e,n){if(this.getCurrentUserId()==e)return void U(null,new p("You can not unblock yourself.",J.INVALID_PARAMETER),n);j.getInstance().unblockUser(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})}},$=null;return Z.getInstance=function(){return null===$?null:$},{SendBird:Z}},C=null;return function(){var e=function(e){if(e.newInstance||!C){var n=new A;C=new n.SendBird(e)}return C};return e.getInstance=function(){return null===C?null:C},e.version="3.0.45",{SendBird:e}}().SendBird}); \ No newline at end of file +!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()}(this,function(){function n(){this.oldIE=!0,this.boundary="--------FormData"+Math.random(),this._fields=[]}var t,r=!1,a="wss://ws.sendbird.com",s="https://api.sendbird.com";try{t=window.console||{log:function(){}}}catch(e){t={log:function(){}}}var i="undefined";try{i=navigator.userAgent.replace(/,/g,".")}catch(e){i="undefined"}var o,l="JS,"+i+",3.0.46,",u=function(){try{if(document&&9==document.documentMode)return!0}catch(e){return!1}return!1}(),c=function(){try{if(document&&document.documentMode<=8)return!0}catch(e){return!1}return!1}();if(u||c)"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=200&&i.status<400?d(null,JSON.parse(i.responseText),s):d({status:i.status,statusText:i.statusText,response:i.responseText},null,s)},i.onerror=function(){d({status:404,statusText:"There was a connection error",response:JSON.stringify({message:"There was a connection error",code:J.NETWORK_ERROR})},null,s)};try{for(var l in a)i.setRequestHeader(l,a[l]?a[l]:"sendbird")}catch(e){}try{switch(r){case"get":case"GET":i.send();break;default:"undefined"!=typeof FormData&&FormData&&n instanceof FormData||void 0!==o&&o&&n instanceof o?n.oldIE?(i.setRequestHeader("Content-Type","multipart/form-data; boundary="+n.boundary),i.send(n.toString())):i.send(n):(i.setRequestHeader("Content-Type","application/json; charset=utf-8"),i.send(JSON.stringify(n)))}}catch(e){t.log("request.send() fail:"+e)}},S=!1,U=function(e,n,t){t&&"function"==typeof t&&(void 0===n&&(n=null),void 0===e&&(e=null),S?t(n,e):t(e,n))},T="",P=0,y=0,O=function(e){this.isOpenChannel=function(){return this.channelType==H.CHANNEL_TYPE_OPEN},this.isGroupChannel=function(){return this.channelType==H.CHANNEL_TYPE_GROUP},this.isUserMessage=function(){return this.messageType==O.MESSAGE_TYPE_USER},this.isAdminMessage=function(){return this.messageType==O.MESSAGE_TYPE_ADMIN},this.isFileMessage=function(){return this.messageType==O.MESSAGE_TYPE_FILE},this._update=function(e){this.messageId=e.hasOwnProperty("msg_id")?parseInt(e.msg_id):0,this.channelUrl=e.hasOwnProperty("channel_url")?String(e.channel_url):"",this.createdAt=e.hasOwnProperty("ts")?parseInt(e.ts):0,this.updatedAt=e.hasOwnProperty("updated_at")?parseInt(e.updated_at):0,this.channelType=e.hasOwnProperty("channel_type")?String(e.channel_type):H.CHANNEL_TYPE_GROUP},this.serialize=function(){var e=JSON.parse(JSON.stringify(this));return e.hasOwnProperty("_sender")&&(e.sender=e._sender,delete e._sender),f(e)},this.messageType=O.MESSAGE_TYPE_BASE,e&&this._update(e)};O.build=function(e,n){if(!e)return null;var t,r,a,s,i,o,l,u;switch(e.type){case"MESG":return t=new F(e.user),r=parseInt(e.message_id),a=String(e.message),s=String(e.data),i=parseInt(e.created_at),o=parseInt(e.updated_at),l=e.hasOwnProperty("custom_type")?String(e.custom_type):"",u=e.hasOwnProperty("translations")?e.translations:{},new M(M.build("",r,t,n,a,s,l,u,i,o));case"FILE":t=new F(e.user),r=parseInt(e.message_id),a=String(e.message),i=parseInt(e.created_at),o=parseInt(e.updated_at),l=e.hasOwnProperty("custom_type")?String(e.custom_type):"";var c=e.file,d=String(c.url),h=String(c.name),I=String(c.type),E=parseInt(c.size)||0;s=String(c.data);var p=e.hasOwnProperty("thumbnails")?e.thumbnails:[],_=!!e.hasOwnProperty("require_auth")&&e.require_auth;return new D(D.build("",r,t,n,d,h,I,E,s,l,i,p,_,o));case"BRDM":case"ADMM":return r=parseInt(e.message_id),a=String(e.message),s=String(e.data),i=parseInt(e.created_at),o=parseInt(e.updated_at),l=e.hasOwnProperty("custom_type")?String(e.custom_type):"",u=e.hasOwnProperty("translations")?e.translations:{},new L(L.build(r,n,a,s,l,u,i,o))}return null},O.MESSAGE_TYPE_BASE="base",O.MESSAGE_TYPE_ADMIN="admin",O.MESSAGE_TYPE_USER="user",O.MESSAGE_TYPE_FILE="file";var L=function(e){this.messageType=O.MESSAGE_TYPE_ADMIN,e&&(this._update(e),this.message=String(e.message),this.data=e.hasOwnProperty("data")?String(e.data):"",this.customType=e.hasOwnProperty("custom_type")?String(e.custom_type):"",this.translations=e.hasOwnProperty("translations")?e.translations:{})};E(O,L),L.build=function(e,n,t,r,a,s,i,o){var l={msg_id:e,channel_url:n.url,channel_type:n.channelType==H.CHANNEL_TYPE_OPEN?H.CHANNEL_TYPE_OPEN:H.CHANNEL_TYPE_GROUP,ts:i,updated_at:o,message:t,data:r};return a&&(l.custom_type=a),s&&(l.translations=s),l},L.buildFromSerializedData=function(e){var n=g(e);return new L(L.build(n.messageId,{url:n.channelUrl,channelType:n.channelType},n.message,n.data,n.customType,n.translations,n.createdAt,n.updatedAt))};var M=function(e){this.messageType=O.MESSAGE_TYPE_USER,e&&(this._update(e),this.message=String(e.message),this.data=e.hasOwnProperty("data")?String(e.data):"",this._sender=new F(e.user),c?this.sender=this._sender:Object.defineProperty(this,"sender",{get:function(){if(Z.getInstance().Options.UseMemberAsMessageSender&&this.isGroupChannel()){var e=w.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))}}return this._sender},set:function(e){this._sender=e}}),this.reqId=e.hasOwnProperty("req_id")?String(e.req_id):"",this.customType=e.hasOwnProperty("custom_type")?String(e.custom_type):"",this.translations=e.hasOwnProperty("translations")?e.translations:{})};E(O,M),M.build=function(e,n,t,r,a,s,i,o,l,u){var c={};c.req_id=e,c.msg_id=n,c.channel_url=r.url,c.channel_type=r.channelType==H.CHANNEL_TYPE_OPEN?H.CHANNEL_TYPE_OPEN:H.CHANNEL_TYPE_GROUP,c.ts=l,c.updated_at=u,c.message=a,s&&(c.data=s),i&&(c.custom_type=i),o&&(c.translations=o);var d={};return d.user_id=t.userId,d.nickname=t.nickname,d.profile_url=t.profileUrl,c.user=d,c},M.buildFromSerializedData=function(e){var n=g(e);return new M(M.build(n.reqId,n.messageId,n.sender,{url:n.channelUrl,channelType:n.channelType},n.message,n.data,n.customType,n.translations,n.createdAt,n.updatedAt))};var D=function(e){if(this.messageType=O.MESSAGE_TYPE_FILE,e&&(this._update(e),this._sender=new F(e.user),c?this.sender=this._sender:Object.defineProperty(this,"sender",{get:function(){if(Z.getInstance().Options.UseMemberAsMessageSender&&this.isGroupChannel()){var e=w.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))}}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="+j.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.customType=e.hasOwnProperty("custom_type")?String(e.custom_type):"",this.thumbnails=e.hasOwnProperty("thumbnails")?e.thumbnails:[],this.requireAuth))for(var n in this.thumbnails)this.thumbnails[n].url=String(this.thumbnails[n].url).split("?auth=")[0]+"?auth="+j.getInstance().ekey};E(O,D),D.build=function(e,n,t,r,a,s,i,o,l,u,c,d,h,I){var E={};E.req_id=e,E.msg_id=n,E.channel_url=r.url,E.channel_type=r.channelType==H.CHANNEL_TYPE_OPEN?H.CHANNEL_TYPE_OPEN:H.CHANNEL_TYPE_GROUP,E.ts=c,E.updated_at=I,E.url=a,E.name=s,E.type=i,E.size=o,E.custom=l;var p={};return p.user_id=t.userId,p.nickname=t.nickname,p.profile_url=t.profileUrl,E.user=p,u&&(E.custom_type=u),h&&(E.require_auth=h),d&&(E.thumbnails=d),E},D.buildFromSerializedData=function(e){var n=g(e);return new D(D.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.createdAt,n.thumbnails,n.requireAuth,n.updatedAt))};var H=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.fileUploadRequest={}},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 f(e)},this.isGroupChannel=function(){return this.channelType==H.CHANNEL_TYPE_GROUP},this.isOpenChannel=function(){return this.channelType==H.CHANNEL_TYPE_OPEN},this.getMessageChangeLogsByToken=function(e,n){if("function"==typeof e&&(n=e,e=null),"function"!=typeof n)return null;j.getInstance().getMessageChangeLogsByToken(this.isOpenChannel(),this.url,e,function(e,t){if(t)return void U(null,t,n);var r=e.updated.map(function(e){return O.build(e,this)}),a=e.deleted.map(function(e){return e.message_id}),s=e.has_more,i=e.next;U({updatedMessages:r,deletedMessageIds:a,hasMore:s,token:i},null,n)})},this.createPreviousMessageListQuery=function(){return new Q(this)},this.createMessageListQuery=function(){return new q(this)};var n=function(e,n,t,r,a,s,i,o,l){if(i===_.MessageTypeFilter.ADMIN?i="ADMM":i===_.MessageTypeFilter.USER?i="MESG":i===_.MessageTypeFilter.FILE?i="FILE":i===_.MessageTypeFilter.ALL&&(i=""),!I(n)||"boolean"!=typeof t||!I(r)||!I(a)||"boolean"!=typeof s||"string"!=typeof i||"string"!=typeof o)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),l);j.getInstance().messageList(e.isOpenChannel(),e.url,n,r,a,t,s,i,o,function(n,t){if(t)return void U(null,t,l);var r=n.messages,a=[];for(var s in r){var i=O.build(r[s],e);i&&a.push(i)}U(a,null,l)})},t=function(e,n,t,r,a,s,i,o,l){if(i===_.MessageTypeFilter.ADMIN?i="ADMM":i===_.MessageTypeFilter.USER?i="MESG":i===_.MessageTypeFilter.FILE?i="FILE":i===_.MessageTypeFilter.ALL&&(i=""),!I(n)||"boolean"!=typeof t||!I(r)||!I(a)||"boolean"!=typeof s||"string"!=typeof i||"string"!=typeof o)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),l);j.getInstance().messageListByID(e.isOpenChannel(),e.url,n,r,a,t,s,i,o,function(n,t){if(t)return void U(null,t,l);var r=n.messages,a=[];for(var s in r){var i=O.build(r[s],e);i&&a.push(i)}U(a,null,l)})};this.getNextMessagesByTimestamp=function(e,t,r,a,s,i,o){return n(this,e,t,0,r,a,s,i,o)},this.getPreviousMessagesByTimestamp=function(e,t,r,a,s,i,o){return n(this,e,t,r,0,a,s,i,o)},this.getPreviousAndNextMessagesByTimestamp=function(e,t,r,a,s,i,o){return n(this,e,!0,t,r,a,s,i,o)},this.getNextMessagesByID=function(e,n,r,a,s,i,o){return t(this,e,n,0,r,a,s,i,o)},this.getPreviousMessagesByID=function(e,n,r,a,s,i,o){return t(this,e,n,r,0,a,s,i,o)},this.getPreviousAndNextMessagesByID=function(e,n,r,a,s,i,o){return t(this,e,!0,n,r,a,s,i,o)},this._sendFileCommand=function(e,n,t,r,a,s,i,o,l,u,c){var d,h=this;d=c?c.reqId:B.generateRequestId();var I=B.bFile(d,e,n,t,r,a,s,i,o,l),E=D.build(I.requestId,0,Z.getInstance().currentUser,this,"string"==typeof n?n:"",t,r,a,s,i,null,null,!1),_=new D(E);return"string"==typeof n&&Z.getInstance().sendCommand(I,function(e,n){if(n)return void U(null,new p(n.message,n.code),u);var t=new D(e.getJsonElement()),r=Z.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)),h.isGroupChannel()&&w.getChannel(h.url,function(e,n){if(S){var r=e;e=n,n=r}if(n)return void U(null,n,u);e.lastMessage=t;for(var a in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[a].onChannelChanged(e)}}),U(t,null,u)}),_},this._getSendFileMessageParamInfo=function(e){var n={file:null,name:null,type:null,size:null,data:"",customType:"",thumbnailSizes:[],callback:null,progressHandler:null};switch("function"==typeof e.slice(-1)[0]&&(n.callback=e.pop()),"function"==typeof e.slice(-1)[0]&&(n.progressHandler=e.pop()),e.length){case 1:n.file=e[0];break;case 2:n.file=e[0],n.data=e[1];break;case 3:n.file=e[0],n.data=e[1],n.customType=e[2];break;case 4:n.file=e[0],n.data=e[1],n.customType=e[2],n.thumbnailSizes=e[3];break;case 5:n.file=e[0],n.name=e[1],n.type=e[2],n.size=e[3],n.data=e[4];break;case 6:n.file=e[0],n.name=e[1],n.type=e[2],n.size=e[3],n.data=e[4],n.customType=e[5];break;case 7:n.file=e[0],n.name=e[1],n.type=e[2],n.size=e[3],n.data=e[4],n.customType=e[5],n.thumbnailSizes=e[6]}return"string"!=typeof n.file&&null!==n.file&&(null!==n.name&&"undefined"!=typeof n.name&&n.name||(n.name=n.file.name),null!==n.type&&"undefined"!=typeof n.type&&n.type||(n.type=n.file.type),null!==n.size&&"undefined"!=typeof n.size||(n.size=n.file.size)),null!==n.name&&"undefined"!=typeof n.name||(n.name=""),null!==n.type&&"undefined"!=typeof n.type||(n.type=""),null!==n.size&&"undefined"!=typeof n.size||(n.size=0),n},this.sendFileMessage=function(){var e=this,n=this._getSendFileMessageParamInfo(Array.prototype.slice.call(arguments)),t=n.file,r=n.name,a=n.type,s=n.size,i=n.data,o=n.customType,l=n.thumbnailSizes,u=n.callback,c=n.progressHandler;if(null!==l&&void 0!==l||(l=[]),!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),u);if(null===t||void 0===t||null!==r&&void 0!==r&&"string"!=typeof r||null!==a&&void 0!==a&&"string"!=typeof a||null!==s&&void 0!==s&&(!I(s)||parseInt(s)<0)||null!==i&&void 0!==i&&"string"!=typeof i||null!==o&&void 0!==o&&"string"!=typeof o||!Array.isArray(l))return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),u);var d=e.url,h=null;return"string"==typeof t?h=e._sendFileCommand(d,t,r,a,s,i,o,[],!1,u):(h=e._sendFileCommand(d,t,r,a,s,i,o,[],!1,u),j.getInstance().uploadFile(t,a,l,d,function(n,t){if(t)return void U(null,t,u);var l="object"==typeof n?n:JSON.parse(n),c=l.url,I=l.hasOwnProperty("thumbnails")?l.thumbnails:[],E=!!l.hasOwnProperty("require_auth")&&l.require_auth;e._sendFileCommand(d,c,r,a,s,i,o,I,E,u,h)},c,this.fileUploadRequest,h.reqId)),h},this.cancelUploadingFileMessage=function(e,n){if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n);if(!I(e))return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);var t=this,r=t.fileUploadRequest[e];return r?(r.upload.onabort=function(){delete t.fileUploadRequest[e],U(!0,null,n)},r.abort(),!0):(U(!1,new p("Uploading has been completed or cancelled.",J.FILE_UPLOAD_CANCEL_FAILED),n),!1)},this.sendUserMessage=function(e,n,t,r,a){var s=this;if("function"==typeof n&&(a=n,n="",t="",r=[]),"function"==typeof t&&(a=t,t="",r=[]),"function"==typeof r&&(a=r,r=[]),r||(r=[]),"string"==typeof r&&(r=[r]),null===n&&(n=""),null===t&&(t=""),!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),a);if("string"!=typeof e||"string"!=typeof n||"string"!=typeof t||!Array.isArray(r))return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),a);var i=B.bMessage(this.url,e,n,t,[],r),o=M.build(i.requestId,0,Z.getInstance().currentUser,this,e,n,t,r,(new Date).getTime()),l=new M(o);return Z.getInstance().sendCommand(i,function(e,n){if(n)return void U(null,new p(n.message,n.code),a);var t=new M(e.getJsonElement()),r=Z.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.isGroupChannel()&&w.getChannel(s.url,function(e,n){if(S){var r=e;e=n,n=r}if(n)return void U(null,n,a);e.lastMessage=t;for(var s in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[s].onChannelChanged(e)}}),U(t,null,a)}),l},this.updateUserMessage=function(e,n,t,r,a){var s=Array.prototype.slice.call(arguments);if(5!==s.length)return"function"==typeof s.slice(-1)[0]&&(a=s.pop()),void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),a);if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),a);if(!I(e))return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),a);if("string"!=typeof n&&null!==n&&void 0!==n||"string"!=typeof t&&null!==t&&void 0!==t||"string"!=typeof r&&null!==r&&void 0!==r)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),a);var i=B.bUpdateUserMessage(this.url,e,n,t,r);Z.getInstance().sendCommand(i,function(e,n){if(n)return void U(null,new p(n.message,n.code),a);var t=new M(e.getJsonElement());U(t,null,a)})},this.updateFileMessage=function(e,n,t,r){var a=Array.prototype.slice.call(arguments);if(4!==a.length)return"function"==typeof a.slice(-1)[0]&&(r=a.pop()),void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),r);if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),r);if(!I(e))return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),r);if("string"!=typeof n&&null!==n&&void 0!==n||"string"!=typeof t&&null!==t&&void 0!==t)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),r);var s=B.bUpdateFileMessage(this.url,e,n,t);Z.getInstance().sendCommand(s,function(e,n){if(n)return void U(null,new p(n.message,n.code),r);var t=new D(e.getJsonElement());U(t,null,r)})},this.createMetaCounters=function(e,n){return Z.getInstance().hasLoggedIn()?null==e||"object"!=typeof e||Array.isArray(e)||h(e)?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):void j.getInstance().createMetaCounters(this.isOpenChannel(),this.url,e,function(e,t){if(t)return void U(null,t,n);U(e,null,n)}):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.updateMetaCounters=function(e,n,t){return Z.getInstance().hasLoggedIn()?("function"!=typeof n&&void 0!==t||(t=n,n=!1),null==e||"object"!=typeof e||Array.isArray(e)||h(e)||"boolean"!=typeof n?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),t):void j.getInstance().updateMetaCounters(this.isOpenChannel(),this.url,e,n,j.UPDATE_META_COUNTER_MODE_SET,function(e,n){if(n)return void U(null,n,t);U(e,null,t)})):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),t)},this.increaseMetaCounters=function(e,n){return Z.getInstance().hasLoggedIn()?null==e||"object"!=typeof e||Array.isArray(e)||h(e)?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):void j.getInstance().updateMetaCounters(this.isOpenChannel(),this.url,e,!1,j.UPDATE_META_COUNTER_MODE_INC,function(e,t){if(t)return void U(null,t,n);U(e,null,n)}):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.decreaseMetaCounters=function(e,n){return Z.getInstance().hasLoggedIn()?null==e||"object"!=typeof e||Array.isArray(e)||h(e)?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):void j.getInstance().updateMetaCounters(this.isOpenChannel(),this.url,e,!1,j.UPDATE_META_COUNTER_MODE_DEC,function(e,t){if(t)return void U(null,t,n);var r=e,a={};for(var s in r){var i=r[s];a[s]=i}U(a,null,n)}):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.getMetaCounters=function(e,n){return Z.getInstance().hasLoggedIn()?Array.isArray(e)?void j.getInstance().getMetaCounters(this.isOpenChannel(),this.url,e,function(e,t){if(t)return void U(null,t,n);U(e,null,n)}):void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.getAllMetaCounters=function(e){if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),e);j.getInstance().getAllMetaCounters(this.isOpenChannel(),this.url,function(n,t){if(t)return void U(null,t,e);U(n,null,e)})},this.deleteMetaCounter=function(e,n){return Z.getInstance().hasLoggedIn()?"string"!=typeof e?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):void j.getInstance().deleteMetaCounter(this.isOpenChannel(),this.url,e,function(e,t){if(t)return void U(null,t,n);U(e,null,n)}):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.deleteAllMetaCounters=function(e){if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),e);j.getInstance().deleteAllMetaCounters(this.isOpenChannel(),this.url,function(n,t){if(t)return void(e&&U(null,t,e));U(n,null,e)})},this.createMetaData=function(e,n){return Z.getInstance().hasLoggedIn()?null==e||"object"!=typeof e||Array.isArray(e)||h(e)?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):void j.getInstance().createMetaData(this.isOpenChannel(),this.url,e,function(e,t){if(t)return void U(null,t,n);U(e,null,n)}):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.updateMetaData=function(e,n,t){return Z.getInstance().hasLoggedIn()?("function"!=typeof n&&void 0!==t||(t=n,n=!1),null==e||"object"!=typeof e||Array.isArray(e)||h(e)||"boolean"!=typeof n?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),t):void j.getInstance().updateMetaData(this.isOpenChannel(),this.url,e,n,function(e,n){if(n)return void U(null,n,t);U(e,null,t)})):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),t)},this.getMetaData=function(e,n){return Z.getInstance().hasLoggedIn()?Array.isArray(e)?void j.getInstance().getMetaData(this.isOpenChannel(),this.url,e,function(e,t){if(t)return void U(null,t,n);U(e,null,n)}):void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.getAllMetaData=function(e){if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),e);j.getInstance().getAllMetaData(this.isOpenChannel(),this.url,function(n,t){if(t)return void U(null,t,e);U(n,null,e)})},this.deleteMetaData=function(e,n){return Z.getInstance().hasLoggedIn()?"string"!=typeof e?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):void j.getInstance().deleteMetaData(this.isOpenChannel(),this.url,e,function(e,t){if(t)return void U(null,t,n);U(e,null,n)}):void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.deleteAllMetaData=function(e){if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),e);j.getInstance().deleteAllMetaData(this.isOpenChannel(),this.url,function(n,t){if(t)return void(e&&U(null,t,e));U(n,null,e)})},this.deleteMessage=function(e,n){var t=Array.prototype.slice.call(arguments);if(2!==t.length)return"function"==typeof t.slice(-1)[0]&&(n=t.pop()),void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n);var r=this;if("object"!=typeof e||h(e)||Array.isArray(e)||Object.keys(e).indexOf("messageId")<0||!e)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);j.getInstance().deleteMessage(r.isOpenChannel(),r.url,e.messageId,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.channelType=H.CHANNEL_TYPE_BASE,e&&this._update(e)};H.CHANNEL_TYPE_OPEN="open",H.CHANNEL_TYPE_GROUP="group",H.CHANNEL_TYPE_BASE="base";var b=function(e){this.parse=function(e){if(e.hasOwnProperty("freeze")&&(this.isFrozen=e.freeze),e.hasOwnProperty("participant_count")&&(this.participantCount=parseInt(e.participant_count)),e.hasOwnProperty("operators")&&e.operators){this.operators=[];for(var n in e.operators){var t=new F(e.operators[n]);this.operators.push(t)}}},this.refresh=function(e){b.getChannelWithoutCache(this.url,function(n,t){if(S){var r=n;n=t,t=r}if(t)return void U(null,t,e);U(n,null,e)})},this.update=function(e){this._update(e),this.parse(e)},this["delete"]=function(e){var n=this.url;j.getInstance().deleteOpenChannel(n,function(t,r){if(r)return void U(null,r,e);delete b.cachedChannels[n],U(t,null,e)})},this.enter=function(e){var n=this,t=B.bEnter(n.url);Z.getInstance().sendCommand(t,function(t,r){if(r)return void U(null,new p(r.message,r.code),e);b.enteredChannels[n.url]=n,U(null,null,e)})},this.exit=function(e){var n=this,t=B.bExit(n.url);Z.getInstance().sendCommand(t,function(t,r){if(r)return void U(null,new p(r.message,r.code),e);delete b.enteredChannels[n.url],U(null,null,e)})},this.createParticipantListQuery=function(){return new x(x.PARTICIPANT,this)},this.createMutedUserListQuery=function(){return new x(x.MUTED_USER,this)},this.createBannedUserListQuery=function(){return new x(x.BANNED_USER,this)},this.updateChannel=function(){var e=Array.prototype.slice.call(arguments),n=null,t=null,r=null,a=null,s=null,i=null;switch("function"==typeof e.slice(-1)[0]&&(i=e.pop()),e.length){case 3:n=e[0],t=e[1],r=e[2];break;case 4:n=e[0],t=e[1],r=e[2],a=e[3];break;case 5:n=e[0],t=e[1],r=e[2],a=e[3],s=e[4];break;default:return void U(null,new p("Invalid arguments.2",J.INVALID_PARAMETER),i)}this.updateChannelWithOperatorUserIds(n,t,r,a,s,i)},this.updateChannelWithOperatorUserIds=function(e,n,t,r,a,s){if("function"==typeof a&&(s=a,a=null),"string"!=typeof e&&null!==e&&void 0!==e||"string"!=typeof n&&h(n)&&null!==n&&void 0!==n||"string"!=typeof t&&null!==t&&void 0!==t||"string"!=typeof r&&!Array.isArray(r)&&null!==r&&void 0!==r||"string"!=typeof a&&null!==a&&void 0!==a)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),s);j.getInstance().updateOpenChannel(this.url,e,n,t,r,a,function(e,n){if(n)return void U(null,n,s);var t=b.upsert(e);U(t,null,s)})},this.banUser=function(e,n,t){if("function"==typeof n&&3!==arguments.length&&(t=n,n=-1),!e||parseInt(n)<0&&-1!==parseInt(n))return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),t);this.banUserWithUserId(e.userId,n,t)},this.banUserWithUserId=function(e,n,t){if("function"==typeof n&&3!==arguments.length&&(t=n,n=-1),!e||parseInt(n)<0&&-1!==parseInt(n))return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),t);j.getInstance().banUser(this.url,e,null,n,function(e,n){if(n)return void U(null,n,t);U(null,null,t)})},this.unbanUser=function(e,n){if(!e)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),n);this.unbanUserWithUserId(e.userId,n)},this.unbanUserWithUserId=function(e,n){if(!e)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),n);j.getInstance().unbanUser(this.url,e,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.muteUser=function(e,n){if(!e)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),n);this.muteUserWithUserId(e.userId,n)},this.muteUserWithUserId=function(e,n){if(!e)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),n);j.getInstance().muteUser(this.url,e,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.unmuteUser=function(e,n){if(!e)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),n);this.unmuteUserWithUserId(e.userId,n)},this.unmuteUserWithUserId=function(e,n){if(!e)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),n);j.getInstance().unmuteUser(this.url,e,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.isOperator=function(e){return!!e&&this.isOperatorWithUserId(e.userId)},this.isOperatorWithUserId=function(e){for(var n in this.operators)if(this.operators[n].userId==e)return!0;return!1},this.channelType=H.CHANNEL_TYPE_OPEN,this.participantCount=0,this.isFrozen=!1,this.operators=[],e&&(this._update(e),this.parse(e))};E(H,b),b.enteredChannels={},b.clearEnteredChannels=function(){b.enteredChannels={}},b.createOpenChannelListQuery=function(){return new W},b.buildFromSerializedData=function(e){var n=g(e);return new b({channel_url:n.url,name:n.name,cover_url:n.coverUrl,data:n.data,custom_type:n.customType,created_at:n.createdAt/1e3,freeze:n.isFrozen,participant_count:n.participantCount,operators:n.operators.map(function(e){return F.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData)})})},b.createChannel=function(){var e,n,t,r,a,s;switch(arguments.length){case 1:s=arguments[0];break;case 4:e=arguments[0],n=arguments[1],t=arguments[2],s=arguments[3];break;case 5:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],s=arguments[4];break;case 6:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],a=arguments[4],s=arguments[5]}b.createChannelWithOperatorUserIds(e,n,t,r,a,s)},b.upsert=function(e){var n=new b(e);return b.cachedChannels.hasOwnProperty(n.url)?b.cachedChannels[n.url].update(e):b.cachedChannels[n.url]=n,b.cachedChannels[n.url]},b.createChannelWithOperatorUserIds=function(e,n,t,r,a,s){if("function"==typeof a&&(s=a,a=""),"string"!=typeof e&&null!==e&&void 0!==e||"string"!=typeof n&&h(n)&&null!==n&&void 0!==n||"string"!=typeof t&&null!==t&&void 0!==t||"string"!=typeof r&&!Array.isArray(r)&&null!==r&&void 0!==r||"string"!=typeof a&&null!==a&&void 0!==a)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),s);j.getInstance().createOpenChannel(e,n,t,r,a,function(e,n){if(n)return void U(null,n,s);var t=b.upsert(e);U(t,null,s)})},b.cachedChannels={},b.clearCache=function(){b.cachedChannels={}},b.removeCachedChannel=function(e){delete b.cachedChannels[e]},b.getChannel=function(e,n){if(!e)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);b.cachedChannels.hasOwnProperty(e)?U(b.cachedChannels[e],null,n):b.getChannelWithoutCache(e,n)},b.getChannelWithoutCache=function(e,n){ +if(!e)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);j.getInstance().getOpenChannel(e,function(t,r){if(r)return void U(null,r,n);b.upsert(t),U(b.cachedChannels[e],null,n)})};var w=function(e){var n,r,a={};this.parse=function(e){var n=this;if(n.isDistinct=!!e.is_distinct,n.unreadMessageCount=parseInt(e.unread_message_count),n.isPushEnabled=!!e.is_push_enabled,n.isHidden=!!e.hasOwnProperty("is_hidden")&&e.is_hidden,e.hasOwnProperty("read_receipt")){n.cachedReadReceiptStatus={};for(var t in e.read_receipt){var r=e.read_receipt[t];n.updateReadReceipt(t,parseInt(r))}}if(e.hasOwnProperty("members")){n.members=[],n.memberMap={};e.members.forEach(function(e){var t=new Y(e);n.members.push(t),n.memberMap[t.userId]=t}),n.memberCount=n.members.length}e.hasOwnProperty("member_count")&&(n.memberCount=parseInt(e.member_count)),e.hasOwnProperty("last_message")&&"object"==typeof e.last_message&&e.last_message?e.last_message instanceof O?n.lastMessage=e.last_message:n.lastMessage=O.build(e.last_message,n):n.lastMessage=null,e.hasOwnProperty("inviter")&&null!==e.inviter&&"object"==typeof e.inviter&&!h(e.inviter)?n.inviter=new F(e.inviter):n.inviter=null},this.refresh=function(e){w.getChannelWithoutCache(this.url,function(n,t){if(S){var r=n;n=t,t=r}if(t)return void U(null,t,e);U(n,null,e)})},this.update=function(e){this._update(e),this.parse(e)},this.updateChannel=function(){var e=this,n=Array.prototype.slice.call(arguments),t=null,r=null,a=null,s=null,i=null,o=null;switch("function"==typeof n.slice(-1)[0]&&(o=n.pop()),n.length){case 3:t=e.isDistinct,r=n[0],a=n[1],s=n[2];break;case 4:t=n[0],r=n[1],a=n[2],s=n[3];break;case 5:t=n[0],r=n[1],a=n[2],s=n[3],i=n[4];break;default:return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),o)}if("string"!=typeof r&&null!==r&&void 0!==r||"string"!=typeof a&&h(a)&&null!==a&&void 0!==a||"string"!=typeof s&&null!==s&&void 0!==s||"boolean"!=typeof t||"string"!=typeof i&&null!==i&&void 0!==i)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),o);j.getInstance().updateGroupChannel(e.url,t,r,a,s,i,function(e,n){if(n)return void U(null,n,o);var t=w.upsert(e);U(t,null,o)})},this.resetMyHistory=function(e){if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),e);j.getInstance().resetMyHistory(this.url,function(n,t){if(t)return void U(null,t,e);U(n,null,e)})},this.invite=function(e,n){if("string"==typeof e&&(e=[{userId:e}]),!Array.isArray(e)||h(e))return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);var t=[];for(var r in e){if("object"!=typeof e[r]||h(e[r])){U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);break}t.push(e[r].userId)}this.inviteWithUserIds(t,n)},this.inviteWithUserIds=function(e,n){if(!Array.isArray(e)||h(e))return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);j.getInstance().groupChannelInvite(this.url,e,function(e,t){if(t)return void U(null,t,n);var r=w.upsert(e);U(r,null,n)})},this.acceptInvitation=function(e){j.getInstance().acceptInvitation(this.url,Z.getInstance().getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);var r=w.upsert(n);U(r,null,e)})},this.declineInvitation=function(e){j.getInstance().declineInvitation(this.url,Z.getInstance().getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);U(n,null,e)})},this.hide=function(e,n){if(1===arguments.length&&"function"==typeof e&&(n=e,e=!1),null!==e&&void 0!==e||(e=!1),"boolean"!=typeof e)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),n);var t=this.url,r=this;j.getInstance().groupChannelHide(t,Z.getInstance().getCurrentUserId(),e,function(e,a){if(a)return void U(null,a,n);r.isHidden=!0;var s=w.cachedChannels[t];s&&(s.isHidden=!0),U(e,null,n)})},this.leave=function(e){var n=this.url;j.getInstance().groupChannelLeave(n,Z.getInstance().getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);U(null,null,e)})},this.markAsRead=function(){this._sendMarkAsRead(null)},this._sendMarkAsRead=function(e){var n=this,t=B.bRead(n.url);Z.getInstance().sendCommand(t,function(t,r){if(r)return void U(null,new p(r.message,r.code),e);if(n.unreadMessageCount>0){n.unreadMessageCount=0;for(var a in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[a].onChannelChanged(n)}}U(null,null,e)})},this.getReadReceipt=function(e){if(!(e instanceof O))return t.log("message is not BaseMessage instance"),-1;if(e.messageType==O.MESSAGE_TYPE_ADMIN)return 0;var n=Z.getInstance().currentUser,r=0,a=e.createdAt,s=this.members;for(var i in s){var o=s[i],l=o.userId;if(!(n.userId==l||e.sender&&e.sender.userId==l)){this.cachedReadReceiptStatus[l]=1e4&&(delete a[t],e=!0)}return e},this.updateTypingStatus=function(e,n){n?a[e.userId]=(new Date).getTime():delete a[e.userId]},this.isTyping=function(){return 0!=Object.keys(a).length},this.getTypingMembers=function(){var e=[];for(var n in a){var t=this.memberMap[n];this.memberMap[n]&&e.push(t)}return e},this.addMember=function(e){var n=this.removeMember(e);n&&n.state===Y.JOINED&&(e.state=Y.JOINED),this.memberMap[e.userId]=e,this.members.push(e),this.memberCount++,this.updateReadReceipt(e.userId,0)},this.removeMember=function(e){var n=e.userId,t=null;if(this.memberMap.hasOwnProperty(e.userId)){delete this.memberMap[e.userId];for(var r in this.members){var a=this.members[r];if(a.userId==n){t=a,this.members.splice(r,1);break}}this.memberCount--}return t},this.setPushPreference=function(e,n){var t=this;if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n);j.getInstance().setPushPreference(Z.getInstance().getCurrentUserId(),this.url,e,function(e,r){if(r)return void U(null,r,n);t.isPushEnabled=e.enable,U(e,null,n)})},this.getPushPreference=function(e){var n=this;if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),e);j.getInstance().getPushPreference(Z.getInstance().getCurrentUserId(),this.url,function(t,r){if(r)return void U(null,r,e);if(e){var a;try{a=t.enable}catch(e){a=!1}n.isPushEnabled=a,U(a,null,e)}})},this.channelType=H.CHANNEL_TYPE_GROUP,this.isDistinct=!1,this.unreadMessageCount=0,this.inviter=null,this.members=[],this.memberMap={},this.lastMessage={},this.memberCount=0,this.cachedReadReceiptStatus={},this.isPushEnabled,this.isHidden=!1,e&&(this._update(e),this.parse(e))};E(H,w),w.buildFromSerializedData=function(e){var n=g(e);return new w({channel_url:n.url,name:n.name,cover_url:n.coverUrl,data:n.data,custom_type:n.customType,created_at:n.createdAt/1e3,is_distinct:n.isDistinct,unread_message_count:n.unreadMessageCount,is_push_enabled:n.isPushEnabled,is_hidden:n.isHidden,member_count:n.memberCount,members:n.members.map(function(e){return Y.build(F.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData),e.state,e.isBlockedByMe,e.isBlockingMe)}),last_message:function(e){return null!==e&&void 0!==e&&"object"==typeof e?e.messageType===O.MESSAGE_TYPE_USER?new M(M.build(e.reqId,e.messageId,e.sender,{url:e.channelUrl,channelType:e.channelType},e.message,e.data,e.customType,e.translations,e.createdAt,e.updatedAt)):e.messageType===O.MESSAGE_TYPE_FILE?new D(D.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.createdAt,e.thumbnails,e.requireAuth,e.updatedAt)):new L(L.build(e.messageId,{url:e.channelUrl,channelType:e.channelType},e.message,e.data,e.customType,e.translations,e.createdAt,e.updatedAt)):null}(n.lastMessage),read_receipt:n.cachedReadReceiptStatus,inviter:null!==n.inviter&&"undefined"!=typeof n.inviter&&"object"==typeof n.inviter?F.build(n.inviter.userId,n.inviter.nickname,n.inviter.profileUrl,n.inviter.connectionStatus,n.inviter.lastSeenAt,n.inviter.metaData):null})},w.createMyGroupChannelListQuery=function(){return new K(Z.getInstance().currentUser)},w.memberState={ALL:0,JOINED:1,INVITED:2},w.getChannelCount=function(e,n){return"function"==typeof e&&1===arguments.length&&(n=e,e=w.memberState.ALL),e!==w.memberState.ALL&&e!==w.memberState.JOINED&&e!==w.memberState.INVITED?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):Z.getInstance().hasLoggedIn()?void j.getInstance().getGroupChannelCount(Z.getInstance().getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);var r=parseInt(e.group_channel_count);U(r,null,n)}):void(n&&U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n))},w.getTotalUnreadMessageCount=function(e){j.getInstance().getTotalUnreadMessageCount(Z.getInstance().getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);var r=parseInt(n.unread_count);U(r,null,e)})},w.getTotalUnreadChannelCount=function(e){j.getInstance().getTotalUnreadChannelCount(Z.getInstance().getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);var r=parseInt(n.unread_count);U(r,null,e)})},w.createChannel=function(){var e=null,n=null,t=null,r=null,a=null,s=null,i=null;switch(arguments.length){case 2:e=arguments[0],n=!1,s=arguments[1];break;case 3:e=arguments[0],n=arguments[1],s=arguments[2];break;case 4:e=arguments[0],n=arguments[1],i=arguments[2],s=arguments[3];break;case 6:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],a=arguments[4],s=arguments[5];break;case 7:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],a=arguments[4],i=arguments[5],s=arguments[6]}if(!Array.isArray(e)||"boolean"!=typeof n||"string"!=typeof t&&null!==t&&void 0!==t||"string"!=typeof r&&h(r)&&null!==r&&void 0!==r||"string"!=typeof a&&null!==a&&void 0!==a||"string"!=typeof i&&null!==i&&void 0!==i)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),s);var o=[];e.forEach(function(e){o.push(e.userId)}),w.createChannelWithUserIds(o,n,t,r,a,i,s)},w.createChannelWithUserIds=function(){var e=null,n=null,t=null,r=null,a=null,s=null,i=null;switch(arguments.length){case 2:e=arguments[0],n=!1,s=arguments[1];break;case 3:e=arguments[0],n=arguments[1],s=arguments[2];break;case 4:e=arguments[0],n=arguments[1],i=arguments[2],s=arguments[3];break;case 6:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],a=arguments[4],s=arguments[5];break;case 7:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],a=arguments[4],i=arguments[5],s=arguments[6]}if(!Z.getInstance().hasLoggedIn())return void U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),s);if(!Array.isArray(e)||"boolean"!=typeof n||"string"!=typeof t&&null!==t&&void 0!==t||"string"!=typeof r&&h(r)&&null!==r&&void 0!==r||"string"!=typeof a&&null!==a&&void 0!==a||"string"!=typeof i&&null!==i&&void 0!==i)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),s);var o=e.filter(function(e,n,t){return n==t.indexOf(e)}),l=Z.getInstance().currentUser;o.push(l.userId),j.getInstance().createGroupChannel(o,n,t,r,a,i,function(e,n){if(n)return void U(null,n,s);var t=new w(e);w.cachedChannels[t.url]=t,U(t,null,s)})},w.cachedChannels={},w.clearCache=function(){w.cachedChannels={}},w.removeCachedChannel=function(e){delete w.cachedChannels[e]},w.upsert=function(e){var n=new w(e);return w.cachedChannels.hasOwnProperty(n.url)?w.cachedChannels[n.url].update(e):w.cachedChannels[n.url]=n,w.cachedChannels[n.url]},w.getChannelWithoutCache=function(e,n){if(!e)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);j.getInstance().getGroupChannel(e,!0,!0,function(e,t){if(t)return void U(null,t,n);var r=w.upsert(e);U(r,null,n)})},w.getChannel=function(e,n){if(!e)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n);w.cachedChannels.hasOwnProperty(e)?U(w.cachedChannels[e],null,n):w.getChannelWithoutCache(e,n)},w.markAsReadAllLastSentAt,w.markAsReadAll=function(e){var n=(new Date).getTime();if(n-w.markAsReadAllLastSentAt<1e3)return void U(null,new p("MarkAsRead rate limit exceeded.",J.MARK_AS_READ_RATE_LIMIT_EXCEEDED),e);w.markAsReadAllLastSentAt=n,j.getInstance().groupChannelMarkAsReadAll(Z.getInstance().getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);for(var r in w.cachedChannels)w.cachedChannels[r].unreadMessageCount=0;U(null,null,e)})};var k=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):H.CHANNEL_TYPE_GROUP),this.isGroupChannel=function(){return this.channelType==H.CHANNEL_TYPE_GROUP},this.isOpenChannel=function(){return this.channelType==H.CHANNEL_TYPE_OPEN}};k.CATEGORY_NONE=0,k.CATEGORY_CHANNEL_ENTER=10102,k.CATEGORY_CHANNEL_EXIT=10103,k.CATEGORY_USER_CHANNEL_MUTE=10201,k.CATEGORY_USER_CHANNEL_UNMUTE=10200,k.CATEGORY_USER_CHANNEL_BAN=10601,k.CATEGORY_USER_CHANNEL_UNBAN=10600,k.CATEGORY_CHANNEL_FREEZE=10701,k.CATEGORY_CHANNEL_UNFREEZE=10700,k.CATEGORY_TYPING_START=10900,k.CATEGORY_TYPING_END=10901,k.CATEGORY_CHANNEL_JOIN=1e4,k.CATEGORY_CHANNEL_LEAVE=10001,k.CATEGORY_CHANNEL_INVITE=10020,k.CATEGORY_CHANNEL_DECLINE_INVITE=10022,k.CATEGORY_CHANNEL_PROP_CHANGED=11e3,k.CATEGORY_CHANNEL_DELETED=12e3,k.CATEGORY_CHANNEL_META_DATA_CHANGED=11100,k.CATEGORY_CHANNEL_META_COUNTERS_CHANGED=11200,k.CATEGORY_CHANNEL_HIDE=13e3;var G=function(e){e&&(this.category=e.hasOwnProperty("cat")?parseInt(e.cat):0)};G.CATEGORY_USER_BLOCK=20001,G.CATEGORY_USER_UNBLOCK=2e4;var V=function(e){e&&(this.reader=new F(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):H.CHANNEL_TYPE_GROUP)},F=function(e){this.nickname="",this.profileUrl="",this.userId="",this.connectionStatus="",this.lastSeenAt=null,this.metaData={},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==F.NON_AVAILABLE?this.connectionStatus=F.NON_AVAILABLE:this.connectionStatus=e.is_online?F.ONLINE:F.OFFLINE:this.connectionStatus=F.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={}},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]})},this.createMetaData=function(e,n){var t=this;return"function"==typeof e&&1===arguments.length&&(n=e,e={}),"object"!=typeof e||h(e)||Array.isArray(e)?void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),n):Z.getInstance().hasLoggedIn()?void j.getInstance().createUserMetaData(t.userId,e,function(e,r){if(r)return void U(null,r,n);t._updateMetaData(e),U(e,null,n)}):void(n&&U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n))},this.updateMetaData=function(e,n,t){var r=this;return"function"==typeof e&&1===arguments.length&&(t=e,e={}),"function"==typeof n&&2===arguments.length&&(t=n,n=!1),"object"!=typeof e||h(e)||Array.isArray(e)||"boolean"!=typeof n?void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),t):Z.getInstance().hasLoggedIn()?void j.getInstance().updateUserMetaData(r.userId,e,n,function(e,n){if(n)return void U(null,n,t);r._updateMetaData(e),U(e,null,t)}):void(t&&U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),t))},this.deleteAllMetaData=function(e){var n=this,t=n.metaData;if(!Z.getInstance().hasLoggedIn())return void(e&&U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),e));j.getInstance().deleteAllUserMetaData(n.userId,function(r,a){if(a)return void U(null,a,e);n._updateMetaData(t,!0),U(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 U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),n);if(!Z.getInstance().hasLoggedIn())return void(n&&U(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED),n));var r={};r[e]="",j.getInstance().deleteUserMetaData(t.userId,e,function(e,a){if(a)return void U(null,a,n);t._updateMetaData(r,!0),U(e,null,n)})},this.serialize=function(){var e=JSON.parse(JSON.stringify(this));return f(e)},e&&this._update(e)};F.NON_AVAILABLE="nonavailable",F.ONLINE="online",F.OFFLINE="offline",F.build=function(e,n,t,r,a,s){return{user_id:e,nickname:n,profile_url:t,is_online:r,last_seen_at:a,metadata:s}},F.buildFromSerializedData=function(e){var n=g(e);return new F(F.build(n.userId,n.nickname,n.profileUrl,n.connectionStatus,n.lastSeenAt,n.metaData))};var Y=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))};E(F,Y),Y.JOINED="joined",Y.INVITED="invited",Y.build=function(e,n,t,r){var a=e;return a.state=n,a.is_blocked_by_me=t,a.is_blocking_me=r,a},Y.buildFromSerializedData=function(e){var n=g(e);return new Y(Y.build(F.build(n.userId,n.nickname,n.profileUrl,n.connectionStatus,n.lastSeenAt,n.metaData),n.state,n.isBlockedByMe,n.isBlockingMe))};var B=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 a;switch(arguments.length){case 1:var s=arguments[0];if(!s||s.length<=4)return r.command="NOOP",void(r.payload="{}");if(s=s.trim(),r.command=s.substring(0,4),r.payload=s.substring(4),r.isRequestIdCommand()){var i=r.getJsonElement();i&&(r.requestId=i.hasOwnProperty("req_id")?i.req_id:"")}break;case 3:a=arguments[2];case 2:var o=arguments[0],l=arguments[1];a=a||"",r.command=o,r.requestId=a,r.requestId||r.isRequestIdCommand()&&(r.requestId=B.generateRequestId()),l.req_id=r.requestId,r.payload=JSON.stringify(l)}}};B.bMessage=function(e,n,t,r,a,s){var i={};i.channel_url=e,i.message=n,i.data=t,i.mentioned=[];for(var o in a){var l=a[o];i.mentioned.push(String(l))}return r&&(i.custom_type=r),s.length>0&&(i.target_langs=s),new B("MESG",i)},B.bRead=function(e){var n={};return n.channel_url=e,new B("READ",n)},B.bTypeStart=function(e,n){var t={};return t.channel_url=e,t.time=n,new B("TPST",t)},B.bTypeEnd=function(e,n){var t={};return t.channel_url=e,t.time=n,new B("TPEN",t)},B.bFile=function(e,n,t,r,a,s,i,o,l,u){var c={};return c.channel_url=n,c.url=t,c.name=r||"",c.type=a||"",c.size=s||0,c.custom=i,o&&(c.custom_type=o),l&&(c.thumbnails=l),u&&(c.require_auth=u),new B("FILE",c,e)},B.bPing=function(){var e={};return e.id=(new Date).getTime(),new B("PING",e)},B.bEnter=function(e){var n={};return n.channel_url=e,new B("ENTR",n)},B.bExit=function(e){var n={};return n.channel_url=e,new B("EXIT",n)},B.bUpdateUserMessage=function(e,n,t,r,a){var s={};return s.channel_url=e,s.msg_id=n,null!=t&&t!=undefined&&(s.message=t),null!=r&&r!=undefined&&(s.data=r),null!=a&&a!=undefined&&(s.custom_type=a),new B("MEDI",s)},B.bUpdateFileMessage=function(e,n,t,r){var a={};return a.channel_url=e,a.msg_id=n,null!=t&&t!=undefined&&(a.data=t),null!=r&&r!=undefined&&(a.custom_type=r),new B("FEDI",a)},B.requestIdSeed=(new Date).getTime(),B.generateRequestId=function(){return B.requestIdSeed++,String(B.requestIdSeed)};var K=function(e){this.isLoading=!1,this.hasNext=!0,this.limit=20,this.includeEmpty=!1,this.order=K.ORDER_LATEST_LAST_MESSAGE,this.userIdsFilter=[],this.userIdsFilterExactMatch=!1,this.queryType="AND",this.nicknameContainsFilter="",this.channelNameContainsFilter="",this.memberStateFilter=K.MEMBER_STATE_ALL,this.customTypeFilter="";var n=e,t="",r=this;this.next=function(e){return r.hasNext?r.isLoading?void U(null,new p("Query in progress.",J.QUERY_IN_PROGRESS),e):(null!==r.nicknameContainsFilter&&"undefined"!=typeof r.nicknameContainsFilter||(r.nicknameContainsFilter=""),null!==r.channelNameContainsFilter&&"undefined"!=typeof r.channelNameContainsFilter||(r.channelNameContainsFilter=""),r.memberStateFilter===w.memberState.JOINED?r.memberStateFilter=K.MEMBER_STATE_JOINED_ONLY:r.memberStateFilter===w.memberState.INVITED?r.memberStateFilter=K.MEMBER_STATE_INVITED_ONLY:r.memberStateFilter===w.memberState.ALL&&(r.memberStateFilter=K.MEMBER_STATE_ALL),!I(r.limit)||!Array.isArray(r.userIdsFilter)||"boolean"!=typeof r.userIdsFilterExactMatch||"string"!=typeof r.customTypeFilter||"string"!=typeof r.queryType||["AND","OR"].indexOf(r.queryType.toUpperCase())<0||"string"!=typeof r.order||[K.ORDER_CHRONOLOGICAL,K.ORDER_LATEST_LAST_MESSAGE].indexOf(r.order.toLowerCase())<0||"string"!=typeof r.memberStateFilter||[K.MEMBER_STATE_INVITED_ONLY,K.MEMBER_STATE_JOINED_ONLY,K.MEMBER_STATE_ALL].indexOf(r.memberStateFilter.toLowerCase())<0||"string"!=typeof r.nicknameContainsFilter||"string"!=typeof r.channelNameContainsFilter?void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),e):(r.isLoading=!0,void j.getInstance().loadUserGroupChannelList(n.userId,t,r.limit,r.includeEmpty,r.order,r.userIdsFilter,r.userIdsFilterExactMatch,r.nicknameContainsFilter,r.queryType,r.memberStateFilter,r.channelNameContainsFilter,r.customTypeFilter,function(n,a){if(a)return r.isLoading=!1,void U(null,a,e);var s=n;(!(t=String(s.next))||t.length<=0)&&(r.hasNext=!1);var i=s.channels,o=[];for(var l in i){var u=w.upsert(i[l]);o.push(u)}r.isLoading=!1,U(o,null,e)}))):void U([],null,e)}};K.ORDER_LATEST_LAST_MESSAGE="latest_last_message",K.ORDER_CHRONOLOGICAL="chronological",K.MEMBER_STATE_INVITED_ONLY="invited_only",K.MEMBER_STATE_JOINED_ONLY="joined_only",K.MEMBER_STATE_ALL="all";var q=function(e){this.isLoading=!1;var n=e,t=this;this.next=function(e,r,a,s){if(t.isLoading)return void U(null,new p("Query in progress.",J.QUERY_IN_PROGRESS),s);if(4!==arguments.length){if("function"!=typeof s){var i=Array.prototype.slice.call(arguments);"function"==typeof i.slice(-1)[0]&&(s=i.pop())}return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),s)}if(!I(e)||!I(r)||"boolean"!=typeof a)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),s);t.isLoading=!0,j.getInstance().messageList(n.isOpenChannel(),n.url,e,0,r,!1,a,"","",function(e,r){if(r)return t.isLoading=!1,void U(null,r,s);var a=e.messages,i=[];for(var o in a){var l=O.build(a[o],n);l&&i.push(l)}t.isLoading=!1,U(i,null,s)})},this.prev=function(e,r,a,s){if(t.isLoading)return void U(null,new p("Query in progress.",J.QUERY_IN_PROGRESS),s);if(4!==arguments.length){if("function"!=typeof s){var i=Array.prototype.slice.call(arguments);"function"==typeof i.slice(-1)[0]&&(s=i.pop())}return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),s)}if(!I(e)||!I(r)||"boolean"!=typeof a)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),s);t.isLoading=!0,j.getInstance().messageList(n.isOpenChannel(),n.url,e,r,0,!1,a,"","",function(e,r){if(r)return t.isLoading=!1,void U(null,r,s);var a=e.messages,i=[];for(var o in a){var l=O.build(a[o],n);l&&i.push(l)}t.isLoading=!1,U(i,null,s)})},this.load=function(e,r,a,s,i){if(t.isLoading)return void U(null,new p("Query in progress.",J.QUERY_IN_PROGRESS),i);if(5!==arguments.length){if("function"!=typeof i){var o=Array.prototype.slice.call(arguments);"function"==typeof o.slice(-1)[0]&&(i=o.pop())}return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),i)}if(!I(e)||!I(r)||!I(a)||"boolean"!=typeof s)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),i);t.isLoading=!0,j.getInstance().messageList(n.isOpenChannel(),n.url,e,r,a,!0,s,"","",function(e,r){if(r)return t.isLoading=!1,void U(null,r,i);var a=e.messages,s=[];for(var o in a){var l=O.build(a[o],n);l&&s.push(l)}t.isLoading=!1,U(s,null,i)})}},W=function(){var e="";this.limit=20,this.isLoading=!1,this.hasNext=!0,this.nameKeyword=null,this.urlKeyword=null,this.customType=null;var n=this;this.next=function(t){return this.hasNext?this.isLoading?void U(null,new p("Query in progress.",J.QUERY_IN_PROGRESS),t):"string"!=typeof n.nameKeyword&&null!==n.nameKeyword||"string"!=typeof n.urlKeyword&&null!==n.urlKeyword||"string"!=typeof n.customType&&null!==n.customType||!I(n.limit)?void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),t):(n.isLoading=!0,void j.getInstance().loadOpenChannelList(e,n.limit,n.nameKeyword,n.urlKeyword,n.customType,function(r,a){if(a)return n.isLoading=!1,void U(null,a,t);var s=r;try{e=String(s.next)}catch(n){e=""}e||(n.hasNext=!1);var i=s.channels,o=[];i.forEach(function(e){var n=b.upsert(e);o.push(n)}),n.isLoading=!1,U(o,null,t)})):void U([],null,t)}},Q=function(e){var n=e,t=0x8000000000000000;this.hasMore=!0,this.isLoading=!1;var r=this;this.load=function(e,a,s,i){if(3!==arguments.length&&4!==arguments.length){if("function"!=typeof i){var o=Array.prototype.slice.call(arguments);"function"==typeof o.slice(-1)[0]&&(i=o.pop())}return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),i)}if("function"==typeof s&&(i=s,s=""),s.toString().toLowerCase()===O.MESSAGE_TYPE_ADMIN||s===_.MessageTypeFilter.ADMIN?s="ADMM":s.toString().toLowerCase()===O.MESSAGE_TYPE_USER||s===_.MessageTypeFilter.USER?s="MESG":s.toString().toLowerCase()===O.MESSAGE_TYPE_FILE||s===_.MessageTypeFilter.FILE?s="FILE":null!==s&&void 0!==s&&s!==_.MessageTypeFilter.ALL||(s=""),!I(e)||"boolean"!=typeof a||"string"!=typeof s)return void U(null,new p("Invalid parameter.",J.INVALID_PARAMETER),i);if(r.hasMore){if(r.isLoading)return void U(null,new p("Query in progress.",J.QUERY_IN_PROGRESS),i);r.isLoading=!0,j.getInstance().messageList(n.isOpenChannel(),n.url,t,e,0,!1,a,s,"",function(a,s){if(s)return r.isLoading=!1,void U(null,s,i);var o=a.messages,l=[];for(var u in o){var c=O.build(o[u],n);c&&(l.push(c),c.createdAt<=t&&(t=c.createdAt))}(l.length<=0||l.length300?R(j.API_ROUTING_URL.replace("%s",T),{},"GET",{SendBird:l+T},function(r,i){if(i)return void e(null,new p("Server is unreachable.",J.NETWORK_ROUTING_ERROR));a=r.ws_server,s=r.api_server,n=t,"function"==typeof e&&e({API_HOST:s,WS_HOST:a})}):e({API_HOST:Z.getInstance().getCurrentApiHost(),WS_HOST:Z.getInstance().getCurrentWsHost()},null)}};var t=function(e,n,t,r,a,s,i,u,c,h){if(!Z.getInstance().hasLoggedIn())return void(i&&i(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED)));j.getInstance().checkRouting(function(n,I){if(I)i(null,new p("Request failed.",J.REQUEST_FAILED));else{var E=v();E.open("POST",n.API_HOST+e,!0),E.setRequestHeader("SendBird",l+T),E.setRequestHeader("Session-Key",j.getInstance().sessionKey);var _=o?new o:new FormData;r&&"undefined"!=typeof Blob?_.append("file",new Blob([t],{type:r}),t.name):_.append("file",t,t.name),s&&_.append("channel_url",s);for(var f in a){var g=parseInt(f)+1;_.append("thumbnail"+g,a[f].maxWidth+","+a[f].maxHeight)}E.onload=function(){c&&c[h]&&delete c[h];E.status>=200&&E.status<400?d(null,JSON.parse(E.responseText),i):d({status:E.status,statusText:E.statusText,response:E.responseText},null,i)},E.onerror=function(e){c&&c[h]&&delete c[h],i(null,new p(E.statusText,J.REQUEST_FAILED))},E.onabort=function(e){c&&c[h]&&delete c[h],i(null,new p("File upload has been cancelled.",J.REQUEST_CANCELLED))},E.upload.onprogress=function(e){e.lengthComputable&&e.loaded>=e.total&&c&&c[h]&&delete c[h],u&&u(e)},_.oldIE?(E.setRequestHeader("Content-Type","multipart/form-data; boundary="+_.boundary),E.send(_.toString())):E.send(_),c&&(c[h]=E)}})},r=function(e,n,t){if("function"==typeof n&&(t=n,n={}),!Z.getInstance().hasLoggedIn())return void(t&&t(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED)));j.getInstance().checkRouting(function(r,a){a?t(null,new p("Request failed.",J.REQUEST_FAILED)):R(r.API_HOST+e,n,"DELETE",{"Session-Key":j.getInstance().sessionKey,SendBird:l+T},t)})},i=function(e){var n="";for(var t in e)e.hasOwnProperty(t)&&(n+=encodeURIComponent(e[t])+",");return n.length>1&&(n=n.substring(0,n.length-1)),n},u=function(e,n,t){if("function"==typeof n&&(t=n,n={}),!Z.getInstance().hasLoggedIn())return void(t&&t(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED)));var r,a="";if(n){for(var s in n)""!=a&&(a+="&"),a+=s+"="+n[s];r=e+"?"+a}else r=e;j.getInstance().checkRouting(function(e,a){a?t(null,new p("Request failed.",J.REQUEST_FAILED)):R(e.API_HOST+r,n,"GET",{"Session-Key":j.getInstance().sessionKey,SendBird:l+T},t)})},c=function(e,n,t){if("function"==typeof n&&(t=n,n={}),!Z.getInstance().hasLoggedIn())return void(t&&t(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED)));j.getInstance().checkRouting(function(r,a){a?t(null,a):R(r.API_HOST+e,n,"POST",{"Session-Key":j.getInstance().sessionKey,SendBird:l+T},t)})},I=function(e,n,t){if("function"==typeof n&&(t=n,n={}),!Z.getInstance().hasLoggedIn())return void(t&&t(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED)));j.getInstance().checkRouting(function(r,a){a||R(r.API_HOST+e,n,"PUT",{"Session-Key":j.getInstance().sessionKey,SendBird:l+T},t)})};this.createUserMetaData=function(e,n,t){var r=j.API_USERS_USERID_METADATA.replace("%s",encodeURIComponent(e)),a={};a.metadata=n,c(r,a,t)},this.updateUserMetaData=function(e,n,t,r){var a=j.API_USERS_USERID_METADATA.replace("%s",encodeURIComponent(e)),s={};s.metadata=n,s.upsert=t,I(a,s,r)},this.deleteAllUserMetaData=function(e,n){var t=j.API_USERS_USERID_METADATA.replace("%s",encodeURIComponent(e));r(t,{},n)},this.deleteUserMetaData=function(e,n,t){var a=j.API_USERS_USERID_METADATA_KEY.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));r(a,{},t)},this.resetMyHistory=function(e,n){var t=j.API_GROUPCHANNELS_RESET_USER_HISTORY.replace("%s",encodeURIComponent(e));I(t,{},n)},this.groupChannelInvite=function(e,n,t){var r=j.API_GROUPCHANNELS_CHANNELURL_INVITE.replace("%s",encodeURIComponent(e)),a={},s=[];try{Array.isArray(n)?s=n:s.push(n)}catch(e){t(null,new p("Invalid parameter.",J.INVALID_PARAMETER))}a.user_ids=s,c(r,a,t)},this.acceptInvitation=function(e,n,t){var r=j.API_GROUPCHANNELS_CHANNELURL_ACCEPT_INVITATION.replace("%s",encodeURIComponent(e)),a={};a.user_id=n,I(r,a,t)},this.declineInvitation=function(e,n,t){var r=j.API_GROUPCHANNELS_CHANNELURL_DECLINE_INVITATION.replace("%s",encodeURIComponent(e)),a={};a.user_id=n,I(r,a,t)},this.groupChannelHide=function(e,n,t,r){var a=j.API_GROUPCHANNELS_CHANNELURL_HIDE.replace("%s",encodeURIComponent(e)),s={};s.user_id=n,s.hide_previous_messages=t,I(a,s,r)},this.groupChannelLeave=function(e,n,t){var r=j.API_GROUPCHANNELS_CHANNELURL_LEAVE.replace("%s",encodeURIComponent(e)),a={};a.user_id=n,I(r,a,t)},this.groupChannelMarkAsRead=function(e,n,t){var r=j.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MARKASREAD.replace("%s",encodeURIComponent(e)),a={};a.user_id=n,I(r,a,t)},this.groupChannelMarkAsReadAll=function(e,n){var t=j.API_USERS_USERID_MARKASREADALL.replace("%s",encodeURIComponent(e));I(t,{},n)},this.messageList=function(e,n,t,r,a,s,i,o,l,c){var d;d=e?String(j.API_OPENCHANNELS_CHANNELURL_MESSAGES.replace("%s",n)):String(j.API_GROUPCHANNELS_CHANNELURL_MESSAGES.replace("%s",n));var h={};h.is_sdk=String(!0),h.message_ts=String(t),h.prev_limit=String(r),h.next_limit=String(a),h.include=String(s),h.reverse=String(i),o&&(h.message_type=String(o)),l&&(h.custom_type=String(l)),u(d,h,c)},this.messageListByID=function(e,n,t,r,a,s,i,o,l,c){var d;d=e?String(j.API_OPENCHANNELS_CHANNELURL_MESSAGES.replace("%s",n)):String(j.API_GROUPCHANNELS_CHANNELURL_MESSAGES.replace("%s",n));var h={};h.is_sdk=String(!0),h.message_id=t,h.prev_limit=String(r),h.next_limit=String(a),h.include=String(s),h.reverse=String(i),o&&(h.message_type=String(o)),l&&(h.custom_type=String(l)),u(d,h,c)},this.login=function(e,n,t){var r=j.API_USERS_USERID_LOGIN.replace("%s",encodeURIComponent(e)),a={};a.app_id=T,n&&(a.access_token=n),c(r,a,function(e,n){n?t(null,n):(j.getInstance().sessionKey=e.key,j.getInstance().ekey=e.ekey,t(e,n))})},this.updateUserInfo=function(e,n,t,r){var a={};n&&(a.nickname=n),t&&(a.profile_url=t);var s=String(j.API_USERS_USERID).replace("%s",encodeURIComponent(e));I(s,a,r)},this.getGroupChannel=function(e,n,t,r){var a=j.API_GROUPCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)),s={member:String(n),read_receipt:String(t)};u(a,s,r)},this.getOpenChannel=function(e,n){var t=j.API_OPENCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e));u(t,n)},this.createGroupChannel=function(e,n,t,r,a,s,i){var l=j.API_GROUPCHANNELS,u=[];"string"==typeof e?u.push(e):e.forEach(function(e){u.push(e)});var d;r&&"string"!=typeof r?(d=o?new o:new FormData,r&&d.append("cover_file",r,r.name),d.append("user_ids",u),d.append("is_distinct",n),null!==t&&"string"==typeof t&&d.append("name",t),a&&d.append("data",a),s&&d.append("custom_type",s)):(d={},null!==r&&"string"==typeof r&&(d.cover_url=r),d.user_ids=u,d.is_distinct=n,null!==t&&"string"==typeof t&&(d.name=t),a&&(d.data=a),s&&(d.custom_type=s)),c(l,d,i)},this.createOpenChannel=function(e,n,t,r,a,s){var i,l=String(j.API_OPENCHANNELS);n&&"string"!=typeof n?(i=o?new o:new FormData,n&&i.append("cover_file",n,n.name),null!==e&&"string"==typeof e&&i.append("name",e),t&&i.append("data",t),r&&(Array.isArray(r)?i.append("operators",r):i.append("operators",[r])),a&&i.append("custom_type",a)):(i={},null!==n&&"string"==typeof n&&(i.cover_url=n),null!==e&&"string"==typeof e&&(i.name=e),t&&(i.data=t),r&&(Array.isArray(r)?i.operators=r:i.operators=[r]),a&&(i.custom_type=a)),c(l,i,s)},this.updateGroupChannel=function(e,n,t,r,a,s,i){var l,u=String(j.API_GROUPCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)));r&&"string"!=typeof r?(l=o?new o:new FormData,l.append("is_distinct",n),r&&l.append("cover_file",r,r.name),null!==t&&"string"==typeof t&&l.append("name",t),null!==a&&"string"==typeof a&&l.append("data",a),null!==s&&"string"==typeof s&&l.append("custom_type",s)):(l={},l.is_distinct=n,null!==r&&"string"==typeof r&&(l.cover_url=r),null!==t&&"string"==typeof t&&(l.name=t),null!==a&&"string"==typeof a&&(l.data=a),null!==s&&"string"==typeof s&&(l.custom_type=s)),I(u,l,i)},this.updateOpenChannel=function(e,n,t,r,a,s,i){var l,u=String(j.API_OPENCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)));t&&"string"!=typeof t?(l=o?new o:new FormData,t&&l.append("cover_file",t,t.name),null!==n&&"string"==typeof n&&l.append("name",n),null!==r&&"string"==typeof r&&l.append("data",r),null!==a&&(Array.isArray(a)?l.append("operators",a):l.append("operators",[a])),null!==s&&"string"==typeof s&&l.append("custom_type",s)):(l={},null!==t&&"string"==typeof t&&(l.cover_url=t),null!==n&&"string"==typeof n&&(l.name=n),null!==r&&"string"==typeof r&&(l.data=r),null!==a&&(Array.isArray(a)?l.operators=a:l.operators=[a]),null!==s&&"string"==typeof s&&(l.custom_type=s)),I(u,l,i)},this.deleteOpenChannel=function(e,n){var t=String(j.API_OPENCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)));r(t,{},n)},this.createMetaCounters=function(e,n,t,r){var a;a=e?j.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):j.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n));var s={};s.metacounter=t,c(a,s,r)},this.updateMetaCounters=function(e,n,t,r,a,s){var i;i=e?j.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):j.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n));var o={};switch(o.metacounter=t,o.upsert=r,a){case j.UPDATE_META_COUNTER_MODE_SET:o.mode="set";break;case j.UPDATE_META_COUNTER_MODE_INC:o.mode="increase";break;case j.UPDATE_META_COUNTER_MODE_DEC:o.mode="decrease"}I(i,o,s)},this.getAllMetaCounters=function(e,n,t){this.getMetaCounters(e,n,{},t)},this.getMetaCounters=function(e,n,t,r){var a;a=e?j.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):j.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n));var s=i(t);u(a,{keys:s},r)},this.deleteMetaCounter=function(e,n,t,a){var s="";s=e?j.API_OPENCHANNELS_CHANNELURL_METACOUNTER_KEY.replace("%s",encodeURIComponent(n)).replace("%s",t):j.API_GROUPCHANNELS_CHANNELURL_METACOUNTER_KEY.replace("%s",encodeURIComponent(n)).replace("%s",t),r(s,{},a)},this.deleteAllMetaCounters=function(e,n,t){var a="";a=e?j.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):j.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)),r(a,{},t)},this.createMetaData=function(e,n,t,r){var a="";a=e?j.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):j.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n));var s={},i={};for(var o in t){var l=t[o];i[o]=l}s.metadata=i,c(a,s,r)},this.updateMetaData=function(e,n,t,r,a){var s="";s=e?j.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):j.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n));var i={},o={};for(var l in t){var u=t[l];o[l]=u}i.metadata=o,i.upsert=r,I(s,i,a)},this.getAllMetaData=function(e,n,t){this.getMetaData(e,n,{},t)},this.getMetaData=function(e,n,t,r){var a="";a=e?j.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):j.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n));var s=i(t);u(a,{keys:s},r)},this.deleteMetaData=function(e,n,t,a){var s="";s=e?j.API_OPENCHANNELS_CHANNELURL_METADATA_KEY.replace("%s",encodeURIComponent(n)).replace("%s",t):j.API_GROUPCHANNELS_CHANNELURL_METADATA_KEY.replace("%s",encodeURIComponent(n)).replace("%s",t),r(s,{},a)},this.deleteAllMetaData=function(e,n,t){var a="";a=e?j.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):j.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)),r(a,{},t)},this.loadUserList=function(e,n,t,r,a,s){var i=j.API_USERS,o={token:encodeURIComponent(e),limit:String(n)};if(!h(t))try{var l="";for(var c in t){var d=t[c];l+=encodeURIComponent(d)+","}l.length>1&&(l=l.substring(0,l.length-1)),o.user_ids=l}catch(e){}if(r&&!h(a)){var I="";a.forEach(function(e){I+=encodeURIComponent(e)+","}),I.length>0&&(I=I.substring(0,I.length-1)),o.metadatakey=encodeURIComponent(r),o.metadatavalues_in=I}u(i,o,s)},this.loadBlockedUserList=function(e,n,t,r){var a=j.API_USERS_USERID_BLOCK.replace("%s",encodeURIComponent(e)),s={token:encodeURIComponent(n),limit:String(t)};u(a,s,r)},this.loadOpenChannelList=function(e,n,t,r,a,s){var i=j.API_OPENCHANNELS,o={token:encodeURIComponent(e),limit:String(n)};null!==t&&(o.name_contains=encodeURIComponent(t)),r&&(o.url_contains=encodeURIComponent(r)),null!==a&&(o.custom_type=encodeURIComponent(a)),u(i,o,s)},this.uploadFile=function(e,n,r,a,s,i,o,l){t(j.API_STORAGE_FILE,0,e,n,r,a,s,i,o,l)},this.uploadProfileImage=function(e,n){t(j.API_STORAGE_PROFILE,0,e,"",[],"",n)},this.loadUserGroupChannelList=function(e,n,t,r,a,s,o,l,c,d,h,I,E){var p=j.API_MYGROUPCHANNELS.replace("%s",encodeURIComponent(e)),_={token:encodeURIComponent(n),limit:String(t),show_member:!0,show_read_receipt:!0,show_empty:String(r),order:a,member_state_filter:d};if(I&&(_.custom_type=encodeURIComponent(I)),l)try{_.members_nickname_contains=encodeURIComponent(l)}catch(e){}if(h)try{_.name_contains=encodeURIComponent(h)}catch(e){}if(s.length>0)try{o?_.members_exactly_in=i(s):(_.members_include_in=i(s),_.query_type=c)}catch(e){}u(p,_,E)},this.loadOpenChannelParticipantList=function(e,n,t,r){var a=j.API_OPENCHANNELS_CHANNELURL_PARTICIPANTS.replace("%s",e),s={token:encodeURIComponent(n),limit:String(t)};u(a,s,r)},this.loadOpenChannelMutedList=function(e,n,t,r){var a=j.API_OPENCHANNELS_CHANNELURL_MUTE.replace("%s",e),s={token:encodeURIComponent(n),limit:String(t)};u(a,s,r)},this.loadOpenChannelBanList=function(e,n,t,r){var a=j.API_OPENCHANNELS_CHANNELURL_BAN.replace("%s",e),s={token:encodeURIComponent(n),limit:String(t)};u(a,s,r)},this.setPushTemplate=function(e,n,t){var r=j.API_USERS_USERID_PUSH_TEMPLATE.replace("%s",encodeURIComponent(e));I(r,{name:n},t)},this.getPushTemplate=function(e,n){var t=j.API_USERS_USERID_PUSH_TEMPLATE.replace("%s",encodeURIComponent(e));u(t,n)},this.setDoNotDisturb=function(e,n,t,r,a,s,i,o){var l=j.API_USERS_USERID_PUSHPREFERENCE.replace("%s",encodeURIComponent(e));I(l,{do_not_disturb:n,start_hour:t,start_min:r,end_hour:a,end_min:s,timezone:i},o)},this.getDoNotDisturb=function(e,n){var t=j.API_USERS_USERID_PUSHPREFERENCE.replace("%s",encodeURIComponent(e));u(t,n)},this.setPushPreference=function(e,n,t,r){var a=j.API_USERS_USERID_PUSHPREFERENCE_CHANNELURL.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n)),s={};s.enable=t,I(a,s,r)},this.getPushPreference=function(e,n,t){var r=j.API_USERS_USERID_PUSHPREFERENCE_CHANNELURL.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));u(r,t)},this.registerGCMPushToken=function(e,n,t){var r=j.API_USERS_USERID_PUSH_GCM.replace("%s",encodeURIComponent(e));c(r,{gcm_reg_token:n},t)},this.unregisterGCMPushToken=function(e,n,t){var a=j.API_USERS_USERID_PUSH_GCM_TOKEN.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));r(a,t)},this.unregisterGCMPushTokenAll=function(e,n){var t=j.API_USERS_USERID_PUSH_GCM.replace("%s",encodeURIComponent(e));r(t,n)},this.registerAPNSPushToken=function(e,n,t){var r=j.API_USERS_USERID_PUSH_APNS.replace("%s",encodeURIComponent(e));c(r,{apns_device_token:n},t)},this.unregisterAPNSPushToken=function(e,n,t){var a=j.API_USERS_USERID_PUSH_APNS_TOKEN.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));r(a,t)},this.unregisterAPNSPushTokenAll=function(e,n){var t=j.API_USERS_USERID_PUSH_APNS.replace("%s",encodeURIComponent(e));r(t,n)},this.unregisterPushTokenAll=function(e,n){var t=j.API_USERS_USERID_PUSH.replace("%s",encodeURIComponent(e));r(t,n)},this.blockUser=function(e,n,t){var r=j.API_USERS_USERID_BLOCK.replace("%s",encodeURIComponent(e));c(r,{target_id:n},t)},this.unblockUser=function(e,n,t){var a=j.API_USERS_USERID_BLOCK_TARGETID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));r(a,{},t)},this.banUser=function(e,n,t,r,a){var s=j.API_OPENCHANNELS_CHANNELURL_BAN.replace("%s",encodeURIComponent(e)),i={user_id:n};t&&(i.description=t),i.seconds=String(r),c(s,i,a)},this.unbanUser=function(e,n,t){var a=j.API_OPENCHANNELS_CHANNELURL_BAN_USERID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));r(a,{},t)},this.muteUser=function(e,n,t){var r=j.API_OPENCHANNELS_CHANNELURL_MUTE.replace("%s",encodeURIComponent(e));c(r,{user_id:n},t)},this.unmuteUser=function(e,n,t){var a=j.API_OPENCHANNELS_CHANNELURL_MUTE_USERID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));r(a,{},t)},this.deleteMessage=function(e,n,t,a){var s="";s=e?j.API_OPENCHANNELS_CHANNELURL_MESSAGES_MESSAGEID.replace("%s",encodeURIComponent(n)).replace("%s",encodeURIComponent(t)):j.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MESSAGEID.replace("%s",encodeURIComponent(n)).replace("%s",encodeURIComponent(t)),r(s,{},a)}},X=null;j.getInstance=function(){return null===X?null:X},j.API_VERSION="v3",j.API_ROUTING_URL="https://api-p.sendbird.com/routing/%s",j.API_USERS="/%v/users".replace("%v",j.API_VERSION),j.API_USERS_USERID_LOGIN="/%v/users/%s/login".replace("%v",j.API_VERSION),j.API_USERS_USERID="/%v/users/%s".replace("%v",j.API_VERSION),j.API_USERS_USERID_METADATA="/%v/users/%s/metadata".replace("%v",j.API_VERSION),j.API_USERS_USERID_METADATA_KEY="/%v/users/%s/metadata/%s".replace("%v",j.API_VERSION),j.API_USERS_USERID_UNREAD_MESSAGE_COUNT="/%v/users/%s/unread_message_count".replace("%v",j.API_VERSION),j.API_USERS_USERID_UNREAD_CHANNEL_COUNT="/%v/users/%s/unread_channel_count".replace("%v",j.API_VERSION),j.API_USERS_USERID_MARKASREADALL="/%v/users/%s/mark_as_read_all".replace("%v",j.API_VERSION),j.API_USERS_USERID_PUSH_GCM_TOKEN="/%v/users/%s/push/gcm/%s".replace("%v",j.API_VERSION),j.API_USERS_USERID_PUSH_GCM="/%v/users/%s/push/gcm".replace("%v",j.API_VERSION),j.API_USERS_USERID_PUSHPREFERENCE_CHANNELURL="/%v/users/%s/push_preference/%s".replace("%v",j.API_VERSION),j.API_USERS_USERID_PUSHPREFERENCE="/%v/users/%s/push_preference/".replace("%v",j.API_VERSION),j.API_USERS_USERID_PUSH_TEMPLATE="/%v/users/%s/push/template".replace("%v",j.API_VERSION),j.API_USERS_USERID_BLOCK="/%v/users/%s/block".replace("%v",j.API_VERSION),j.API_USERS_USERID_BLOCK_TARGETID="/%v/users/%s/block/%s".replace("%v",j.API_VERSION),j.API_USERS_USERID_PUSH_APNS_TOKEN="/%v/users/%s/push/apns/%s".replace("%v",j.API_VERSION),j.API_USERS_USERID_PUSH_APNS="/%v/users/%s/push/apns".replace("%v",j.API_VERSION),j.API_USERS_USERID_PUSH="/%v/users/%s/push".replace("%v",j.API_VERSION),j.API_USERS_USERID_GROUP_CHANNEL_INVITATION_PREFERENCE="/%v/users/%s/channel_invitation_preference".replace("%v",j.API_VERSION),j.API_USERS_USERID_GROUP_CHANNEL_COUNT="/%v/users/%s/group_channel_count".replace("%v",j.API_VERSION),j.API_OPENCHANNELS="/%v/open_channels".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL="/%v/open_channels/%s".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_MESSAGES="/%v/open_channels/%s/messages".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_MESSAGES_MESSAGEID="/%v/open_channels/%s/messages/%s".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_PARTICIPANTS="/%v/open_channels/%s/participants".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_METADATA="/%v/open_channels/%s/metadata".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_METADATA_KEY="/%v/open_channels/%s/metadata/%s".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_METACOUNTER="/%v/open_channels/%s/metacounter".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_METACOUNTER_KEY="/%v/open_channels/%s/metacounter/%s".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_BAN="/%v/open_channels/%s/ban".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_BAN_USERID="/%v/open_channels/%s/ban/%s".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_MUTE="/%v/open_channels/%s/mute".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_MUTE_USERID="/%v/open_channels/%s/mute/%s".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS="/%v/group_channels".replace("%v",j.API_VERSION),j.API_MYGROUPCHANNELS="/%v/users/%s/my_group_channels".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL="/%v/group_channels/%s".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_INVITE="/%v/group_channels/%s/invite".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_ACCEPT_INVITATION="/%v/group_channels/%s/accept".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_DECLINE_INVITATION="/%v/group_channels/%s/decline".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_HIDE="/%v/group_channels/%s/hide".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_LEAVE="/%v/group_channels/%s/leave".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_MESSAGES="/%v/group_channels/%s/messages".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MARKASREAD="/%v/group_channels/%s/messages/mark_as_read".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_MESSAGES_TOTALCOUNT="/%v/group_channels/%s/messages/total_count".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_MESSAGES_UNREADCOUNT="/%v/group_channels/%s/messages/unread_count".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MESSAGEID="/%v/group_channels/%s/messages/%s".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_MEMBERS="/%v/group_channels/%s/members".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_METADATA="/%v/group_channels/%s/metadata".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_METADATA_KEY="/%v/group_channels/%s/metadata/%s".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_METACOUNTER="/%v/group_channels/%s/metacounter".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_METACOUNTER_KEY="/%v/group_channels/%s/metacounter/%s".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_RESET_USER_HISTORY="/%v/group_channels/%s/reset_user_history".replace("%v",j.API_VERSION),j.API_STORAGE_FILE="/%v/storage/file".replace("%v",j.API_VERSION),j.API_STORAGE_PROFILE="/%v/storage/profile_image".replace("%v",j.API_VERSION),j.API_OPENCHANNELS_CHANNELURL_MESSAGES_CHANGELOGS="/%v/open_channels/%s/messages/changelogs".replace("%v",j.API_VERSION),j.API_GROUPCHANNELS_CHANNELURL_MESSAGES_CHANGELOGS="/%v/group_channels/%s/messages/changelogs".replace("%v",j.API_VERSION),j.UPDATE_META_COUNTER_MODE_SET=0,j.UPDATE_META_COUNTER_MODE_INC=1,j.UPDATE_META_COUNTER_MODE_DEC=2;var Z=function(e){var n=Z.getInstance();if(n)return n;try{if(!e.hasOwnProperty("appId"))return t.log("Must be set appId"),{}}catch(e){return t.log("Must be set appId"),{}}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.loginTimer,this.onLoginTimerCancel,this.globalTimer,this.reconnectTimer,this.onReconnectTimerCancel,this.currentUser=null,this.getCurrentUserId=function(){return Z.getInstance().currentUser?Z.getInstance().currentUser.userId:null},this.wsClient,this.connectionState={CONNECTING:"CONNECTING",OPEN:"OPEN",CLOSING:"CLOSING",CLOSED:"CLOSED"},this.ConnectionState=this.connectionState,this.BaseChannel=_,this.User=F,this.Member=Y,this.OpenChannel=b,this.GroupChannel=w,this.UserMessage=M,this.FileMessage=D,this.AdminMessage=L,this.channelHandlers={},this.connectionHandlers={};var i={};T=e.appId,$=this,X=j.getInstance(),X||(X=new j),this.Options={UseMemberAsMessageSender:!1},this.customApiHost=null,this.customWsHost=null,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){},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.addChannelHandler=function(e,n){Z.getInstance().channelHandlers[e]=n},this.removeChannelHandler=function(e){delete Z.getInstance().channelHandlers[e]},this.removeAllChannelHandlers=function(){Z.getInstance().channelHandlers={}},this.ConnectionHandler=function(){this.onReconnectStarted=function(){},this.onReconnectSucceeded=function(){},this.onReconnectFailed=function(){}},this.addConnectionHandler=function(e,n){Z.getInstance().connectionHandlers[e]=n},this.removeConnectionHandler=function(e){delete Z.getInstance().connectionHandlers[e]},this.removeAllConnectionHandlers=function(){Z.getInstance().connectionHandlers={}},this.createUserListQuery=function(e){return e?new x(x.FILTERED_USER,e):new x(x.ALL_USER)},this.createBlockedUserListQuery=function(){return new x(x.BLOCKED_USER)},this.getApplicationId=function(){return T},this.getDebugMode=function(){return r},this.setDebugMode=function(e){r=e},this.setAPIHost=function(e){s=e},this.setWSHost=function(e){a=e},this.clearCurrentApiHost=function(){this.customApiHost=null},this.getCurrentApiHost=function(){return this.customApiHost?this.customApiHost:s},this.clearCurrentWsHost=function(){this.customWsHost=null},this.getCurrentWsHost=function(){return this.customWsHost?this.customWsHost:a},this.setErrorFirstCallback=function(e){S=e},this.getConnectionState=function(){if(!Z.getInstance())return this.connectionState.CLOSED;try{return Z.getInstance().wsClient?Z.getInstance().isSessionOpened?Z.getInstance().wsClient.getConnectionState():Z.getInstance().connectionState.CONNECTING:Z.getInstance().connectionState.CLOSED}catch(e){return Z.getInstance().connectionState.CLOSED}},this.hasLoggedIn=function(){return Z.getInstance().currentUser&&j.getInstance().sessionKey};var o=function(e){return i.hasOwnProperty(e)?i[e]:null},l=function(e){var n=new B(e);if(n.requestId){var r=o(n.requestId);if(null==r)return;clearTimeout(r.timer);var a=r.handler;if(a)if("EROR"==n.command){var s=n.getJsonElement(),i=s.code,l=s.message;a(n,new p(l,i))}else a(n,null)}else switch(n.command){case"LOGI":if(Z.getInstance().loginTimer){clearTimeout(Z.getInstance().loginTimer),Z.getInstance().loginTimer=null,Z.getInstance().onLoginTimerCancel=null;var d=n.getJsonElement();if(d.hasOwnProperty("error")){Z.getInstance().isSessionOpened=!1;var i=d.code,l=d.message;Z.getInstance().loginHandler(null,new p(l,i))}else Z.getInstance().isSessionOpened=!0,d.hasOwnProperty("key")&&(j.getInstance().sessionKey=d.key),d.hasOwnProperty("ekey")&&(j.getInstance().ekey=d.ekey),d.hasOwnProperty("user_id")&&(Z.getInstance().currentUser=new F(d)),Z.getInstance().loginHandler(Z.getInstance().currentUser,null)}break;case"MESG":case"FILE":case"BRDM":case"ADMM":var h="",I=!1;if("MESG"==n.command?h=new M(n.getJsonElement()):"FILE"==n.command?h=new D(n.getJsonElement()):(h=new L(n.getJsonElement()),n.getJsonElement().hasOwnProperty("silent")&&(I=n.getJsonElement().silent)),!h)return;if(h.isGroupChannel()){var E=w.cachedChannels.hasOwnProperty(h.channelUrl);w.getChannel(h.channelUrl,function(e,n){if(S){var t=e;e=n,n=t}if(n)return void(a&&a(null,n));if(e.isHidden=!1,w.cachedChannels[e.url]=e,h._sender&&e.memberMap.hasOwnProperty(h._sender.userId)){var r=e.memberMap[h._sender.userId];r.nickname!=h._sender.nickname&&(r.nickname=h._sender.nickname),r.profileUrl!=h._sender.profileUrl&&(r.profileUrl=h._sender.profileUrl)}var s=Z.getInstance().currentUser;if(s&&h._sender&&s.userId==h._sender.userId&&(s.nickname!=h._sender.nickname&&(s.nickname=h._sender.nickname),s.profileUrl!=h._sender.profileUrl&&(s.profileUrl=h._sender.profileUrl)),!I){E&&(e.updatedLocal?(e.lastMessage=h,h.sender&&h.sender.userId==Z.getInstance().getCurrentUserId()||e.unreadMessageCount++):(!e.lastMessage||e.lastMessage.createdAt0){e.unreadMessageCount=0;for(var r in Z.getInstance().channelHandlers){var s=Z.getInstance().channelHandlers[r];s.onChannelChanged(e)}}}else if(0==e.unreadMessageCount)for(var r in Z.getInstance().channelHandlers){ +var s=Z.getInstance().channelHandlers[r];s.onChannelChanged(e)}}else{e.updateReadReceipt(_.reader.userId,_.timestamp);for(var r in Z.getInstance().channelHandlers){var s=Z.getInstance().channelHandlers[r];s.onReadReceiptUpdated(e)}}});break;case"TPST":case"TPEN":case"MTIO":break;case"SYEV":c(n);break;case"USEV":u(n);break;case"DELM":var f=n.getJsonElement(),g=String(f.channel_type),A=String(f.channel_url),C=String(f.msg_id);switch(g){case H.CHANNEL_TYPE_OPEN:b.getChannel(A,function(e,n){if(S){var r=e;e=n,n=r}if(n)return void t.log("Discard a command.");for(var a in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[a].onMessageDeleted(e,C)}});break;case H.CHANNEL_TYPE_GROUP:w.getChannel(A,function(e,n){if(S){var r=e;e=n,n=r}if(n)return void t.log("Discard a command.");for(var a in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[a].onMessageDeleted(e,C)}})}}},u=function(e){var n=new k(e.getJsonElement());switch(n.category){case G.CATEGORY_USER_BLOCK:case G.CATEGORY_USER_UNBLOCK:var t=n.data.blocker.user_id,r=n.data.blockee.user_id;Object.keys(w.cachedChannels).forEach(function(e){var a=w.cachedChannels[e];try{Z.getInstance().getCurrentUserId()===t?a.memberMap[r].isBlockedByMe=n.category===G.CATEGORY_USER_BLOCK:Z.getInstance().getCurrentUserId()===r&&(a.memberMap[t].isBlockingMe=n.category===G.CATEGORY_USER_BLOCK)}catch(e){}})}},c=function(e){var n=new k(e.getJsonElement());switch(n.category){case k.CATEGORY_CHANNEL_JOIN:case k.CATEGORY_CHANNEL_LEAVE:w.getChannel(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);var i=new F(n.data);if(n.category==k.CATEGORY_CHANNEL_JOIN){n.data.state=Y.JOINED,r.addMember(new Y(n.data));for(var o in Z.getInstance().channelHandlers){var l=Z.getInstance().channelHandlers[o];l.onUserJoined(r,i)}}else{i.userId==Z.getInstance().getCurrentUserId()&&w.removeCachedChannel(n.channelUrl),r.removeMember(i);for(var o in Z.getInstance().channelHandlers){var l=Z.getInstance().channelHandlers[o];l.onUserLeft(r,i)}}});break;case k.CATEGORY_CHANNEL_INVITE:w.getChannel(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);var i=null;n.data&&n.data.inviter&&!h(n.data.inviter)&&(i=new F(n.data.inviter));var o=[];for(var l in n.data.invitees){n.data.invitees[l].state=Y.INVITED;var u=new Y(n.data.invitees[l]);o.push(u),r.addMember(u)}for(var l in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[l].onUserReceivedInvitation(r,i,o)}});break;case k.CATEGORY_CHANNEL_DECLINE_INVITE:w.getChannel(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);var i=null;n.data&&n.data.inviter&&!h(n.data.inviter)&&(i=new F(n.data.inviter));var o=new F(n.data.invitee);o.userId==Z.getInstance().getCurrentUserId()&&w.removeCachedChannel(n.channelUrl),r.removeMember(o);for(var l in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[l].onUserDeclinedInvitation(r,i,o)}});break;case k.CATEGORY_TYPING_START:case k.CATEGORY_TYPING_END:w.getChannel(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);var i=new F(n.data);n.category==k.CATEGORY_TYPING_START?r.updateTypingStatus(i,!0):r.updateTypingStatus(i,!1);for(var o in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[o].onTypingStatusUpdated(r)}});break;case k.CATEGORY_CHANNEL_ENTER:case k.CATEGORY_CHANNEL_EXIT:b.getChannel(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);n.data.hasOwnProperty("participant_count")&&(r.participantCount=n.data.participant_count);var i=new F(n.data);if(n.category==k.CATEGORY_CHANNEL_ENTER)for(var o in Z.getInstance().channelHandlers){var l=Z.getInstance().channelHandlers[o];l.onUserEntered(r,i)}else for(var o in Z.getInstance().channelHandlers){var l=Z.getInstance().channelHandlers[o];l.onUserExited(r,i)}});break;case k.CATEGORY_USER_CHANNEL_MUTE:case k.CATEGORY_USER_CHANNEL_UNMUTE:b.getChannel(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);var i=new F(n.data);if(n.category==k.CATEGORY_USER_CHANNEL_MUTE)for(var o in Z.getInstance().channelHandlers){var l=Z.getInstance().channelHandlers[o];l.onUserMuted(r,i)}else for(var o in Z.getInstance().channelHandlers){var l=Z.getInstance().channelHandlers[o];l.onUserUnmuted(r,i)}});break;case k.CATEGORY_USER_CHANNEL_BAN:case k.CATEGORY_USER_CHANNEL_UNBAN:b.getChannel(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);var i=new F(n.data);if(n.category==k.CATEGORY_USER_CHANNEL_BAN)for(var o in Z.getInstance().channelHandlers){var l=Z.getInstance().channelHandlers[o];l.onUserBanned(r,i)}else for(var o in Z.getInstance().channelHandlers){var l=Z.getInstance().channelHandlers[o];l.onUserUnbanned(r,i)}});break;case k.CATEGORY_CHANNEL_FREEZE:case k.CATEGORY_CHANNEL_UNFREEZE:b.getChannel(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);if(r.isFrozen=n.data.freeze,n.category==k.CATEGORY_CHANNEL_FREEZE)for(var i in Z.getInstance().channelHandlers){var o=Z.getInstance().channelHandlers[i];o.onChannelFrozen(r)}else for(var i in Z.getInstance().channelHandlers){var o=Z.getInstance().channelHandlers[i];o.onChannelUnfrozen(r)}});break;case k.CATEGORY_CHANNEL_DELETED:if(n.isGroupChannel()){w.removeCachedChannel(n.channelUrl);for(var r in Z.getInstance().channelHandlers){var a=Z.getInstance().channelHandlers[r];a.onChannelDeleted(n.channelUrl,"group")}}else{b.removeCachedChannel(n.channelUrl);for(var r in Z.getInstance().channelHandlers){var a=Z.getInstance().channelHandlers[r];a.onChannelDeleted(n.channelUrl,"open")}}break;case k.CATEGORY_CHANNEL_PROP_CHANGED:n.isOpenChannel()?b.getChannelWithoutCache(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);for(var i in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[i].onChannelChanged(r)}}):w.getChannelWithoutCache(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);for(var i in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[i].onChannelChanged(r)}});break;case k.CATEGORY_CHANNEL_META_DATA_CHANGED:case k.CATEGORY_CHANNEL_META_COUNTERS_CHANGED:var s=n.data.hasOwnProperty("created"),i=n.data.hasOwnProperty("updated"),o=n.data.hasOwnProperty("deleted");n.isOpenChannel()?b.getChannel(n.channelUrl,function(r,a){if(S){var l=r;r=a,a=l}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);for(var u in Z.getInstance().channelHandlers){var c=Z.getInstance().channelHandlers[u];n.category==k.CATEGORY_CHANNEL_META_DATA_CHANGED?(s&&c.onMetaDataCreated(r,n.data.created),i&&c.onMetaDataUpdated(r,n.data.updated),o&&c.onMetaDataDeleted(r,n.data.deleted)):(s&&c.onMetaCountersCreated(r,n.data.created),i&&c.onMetaCountersUpdated(r,n.data.updated),o&&c.onMetaCountersDeleted(r,n.data.deleted))}}):w.getChannel(n.channelUrl,function(r,a){if(S){var l=r;r=a,a=l}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);for(var u in Z.getInstance().channelHandlers){var c=Z.getInstance().channelHandlers[u];n.category==k.CATEGORY_CHANNEL_META_DATA_CHANGED?(s&&c.onMetaDataCreated(r,n.data.created),i&&c.onMetaDataUpdated(r,n.data.updated),o&&c.onMetaDataDeleted(r,n.data.deleted)):(s&&c.onMetaCountersCreated(r,n.data.created),i&&c.onMetaCountersUpdated(r,n.data.updated),o&&c.onMetaCountersDeleted(r,n.data.deleted))}});break;case k.CATEGORY_CHANNEL_HIDE:w.getChannel(n.channelUrl,function(r,a){if(S){var s=r;r=a,a=s}if(a)return void t.log("Discard a command: "+e.command+":"+n.category);r.isHidden=!0;for(var i in Z.getInstance().channelHandlers){Z.getInstance().channelHandlers[i].onChannelHidden(r)}})}};this.setPushTemplate=function(e,n){return!e||e!==this.PUSH_TEMPLATE_DEFAULT&&e!==this.PUSH_TEMPLATE_ALTERNATIVE?void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n):this.currentUser?void j.getInstance().setPushTemplate(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);var r=e.name.toString();U(r,null,n)}):void U(null,new p("Connection must be made before you set push template",J.CONNECTION_REQUIRED),n)},this.getPushTemplate=function(e){if(!this.currentUser)return void U(null,new p("Connection must be made before you get push template",J.CONNECTION_REQUIRED),e);j.getInstance().getPushTemplate(this.getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);var r=n.name.toString();U(r,null,e)})},this.setChannelInvitationPreference=function(e,n){"boolean"!=typeof e&&U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),n),j.getInstance().setChannelInvitationPreference(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U({autoAccept:e.auto_accept},null,n)})},this.getChannelInvitationPreference=function(e){j.getInstance().getChannelInvitationPreference(this.getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);U({autoAccept:n.auto_accept},null,e)})},this.connect=function(){var e=Array.prototype.slice.call(arguments),n=null,a=null,s=null;switch("function"==typeof e.slice(-1)[0]&&(s=e.pop()),e.length){case 1:n=e[0];break;case 2:n=e[0],a=e[1];break;case 3:n=e[0],this.customApiHost=e[1],this.customWsHost=e[2];break;case 4:n=e[0],a=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?(f(!0,null),A(n,a,s)):U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),s)};var d=!1,I=!1,E=!0;this.setBackgroundState=function(){!d&&E&&(d=!0,this.getConnectionState()!=this.connectionState.CLOSED?(I=!0,f(!1,null)):I=!1)},this.setForegroundState=function(){d&&E&&(d=!1,I&&this.currentUser&&(P=0,g(this.getCurrentUserId(),!0)))},this.disableStateChange=function(){E=!1},this.enableStateChange=function(){E=!0},this.disconnect=function(e){f(!0,e)},this.reconnect=function(){if(!j.getInstance().sessionKey||!this.currentUser)return!1;var e=!0;return P>0&&(e=!1),f(!1,null),P=0,g(this.getCurrentUserId(),e),!0};var f=function(e,n){var t=this;Z.getInstance().loginTimer&&(clearTimeout(Z.getInstance().loginTimer),Z.getInstance().onLoginTimerCancel&&(Z.getInstance().onLoginTimerCancel(),Z.getInstance().onLoginTimerCancel=null),Z.getInstance().loginTimer=null),Z.getInstance().reconnectTimer&&(clearTimeout(Z.getInstance().reconnectTimer),Z.getInstance().onReconnectTimerCancel&&(Z.getInstance().onReconnectTimerCancel(),Z.getInstance().onReconnectTimerCancel=null),Z.getInstance().reconnectTimer=null),Z.getInstance().wsClient&&(P=0,Z.getInstance().wsClient.disconnect(!0),Z.getInstance().wsClient=null),function(){if(e){b.clearEnteredChannels(),b.clearCache(),w.clearCache(),Z.getInstance().globalTimer&&(clearTimeout(t.globalTimer),Z.getInstance().globalTimer=null);for(var r in Z.getInstance().ackStateMap)clearTimeout(Z.getInstance().ackStateMap[r].timer);Z.getInstance().ackStateMap={},Z.getInstance().currentUser=null,j.getInstance().sessionKey=null,j.getInstance().ekey=null}U(null,null,n)}()},g=function(e,n){if(Z.getInstance().reconnectTimer)r&&t.log("still reconnecting");else{if((P+=1)<=1){if(n)for(var a in Z.getInstance().connectionHandlers){var s=Z.getInstance().connectionHandlers[a];s.onReconnectStarted(a)}y=0}else y=3e3*Math.pow(2,P-2);if(!e||!j.getInstance().sessionKey||P>=6){f(!1,null),P=0;for(var a in Z.getInstance().connectionHandlers){var s=Z.getInstance().connectionHandlers[a];s.onReconnectFailed(a)}return}Z.getInstance().onReconnectTimerCancel=function(){P=0},Z.getInstance().reconnectTimer=setTimeout(function(){Z.getInstance().reconnectTimer=null,Z.getInstance().onReconnectTimerCancel=null,Z.getInstance().wsClient&&Z.getInstance().wsClient.disconnect(!0);var n=new z.WSClientHandler;Z.getInstance().wsClient=new z(n),Z.getInstance().loginHandler=function(e){P=0;for(var n in b.enteredChannels){b.enteredChannels[n].enter()}for(var n in Z.getInstance().connectionHandlers){Z.getInstance().connectionHandlers[n].onReconnectSucceeded(n)}},n.onOpen=function(){r&&t.log("reconnectWS onOpen"),Z.getInstance().loginTimer=setTimeout(function(){r&&t.log("reconnectWS loginTimer timedout"),Z.getInstance().loginTimer=null,g(e,!0)},1e4),Z.getInstance().onLoginTimerCancel=null},n.onMessage=function(e){l(e)},n.onError=function(){r&&t.log("reconnectWS onError"),g(e,!0)},n.onClose=function(){r&&t.log("reconnectWS onClose")};var a=Z.getInstance().getCurrentApiHost();j.getInstance().checkRouting(function(n,t){if(t)return void g(e,!0);a!=n.API_HOST&&R(n.API_HOST,{},"GET",{},function(){}),Z.getInstance().wsClient.connect(e,null,n.WS_HOST)})},y)}},A=function(e,n,a){var s=new z.WSClientHandler;Z.getInstance().wsClient=new z(s),s.onMessage=function(e){l(e)},Z.getInstance().loginHandler=function(e,n){if(n)Z.getInstance().disconnect(null),U(null,n,a);else{clearTimeout(Z.getInstance().globalTimer);var t=function(){if(w.cachedChannels)for(var e in w.cachedChannels){var n=w.cachedChannels[e];if(n.invalidateTypingStatus())for(var r in Z.getInstance().channelHandlers){var a=Z.getInstance().channelHandlers[r];a.onTypingStatusUpdated(n)}}Z.getInstance().globalTimer=setTimeout(function(){t()},1e3)};t(),U(e,null,a)}},s.onOpen=function(e){Z.getInstance().loginTimer=setTimeout(function(){Z.getInstance().loginTimer=null,Z.getInstance().onLoginTimerCancel=null,Z.getInstance().disconnect(null),U(null,new p("Connection timeout.",J.LOGIN_TIMEOUT),a)},1e4),Z.getInstance().onLoginTimerCancel=function(){U(null,new p("Connection Cancelled.",J.REQUEST_FAILED),a)}},s.onError=function(n){r&&t.log("WSClientHandler.onError",n),j.getInstance().sessionKey?g(e,!0):U(null,new p("Websocket connection failed.",J.WEBSOCKET_CONNECTION_FAILED),a)},s.onClose=function(e){r&&t.log("WSClientHandler.onClose")},j.getInstance().checkRouting(function(t,r){if(r)return void U(null,new p("Connection routing failed.",J.REQUEST_FAILED),a);R(t.API_HOST,{},"GET",{},function(){}),Z.getInstance().wsClient.connect(e,n,t.WS_HOST)})};this.sendCommand=function(e,n){if(!Z.getInstance().hasLoggedIn())return void(n&&n(null,new p("Connection should be made first.",J.CONNECTION_REQUIRED)));if(null==Z.getInstance().wsClient||Z.getInstance().wsClient.getConnectionState()!=Z.getInstance().connectionState.OPEN)return void(n&&n(null,new p("Connection is not valid. Please reconnect.",J.WEBSOCKET_CONNECTION_CLOSED)));if(e.isAckRequired()){var t=e.requestId,r={handler:n,timer:setTimeout(function(){n(null,new p("Command received no ack.",J.ACK_TIMEOUT)),delete i[t]},1e4)};i[t]=r,Z.getInstance().wsClient.send(e,function(e,t){if(t)return clearTimeout(r.timer),void n(null,t)})}else Z.getInstance().wsClient.send(e,n)},this.updateCurrentUserInfoWithProfileImage=function(e,n,t){var r=this;n?j.getInstance().uploadProfileImage(n,function(n,a){if(a)return void U(null,a,t);var s="object"==typeof n?n:JSON.parse(n),i=s.url;r.updateCurrentUserInfo(e,i,t)}):r.updateCurrentUserInfo(e,null,t)},this.updateCurrentUserInfo=function(e,n,t){var r=this;j.getInstance().updateUserInfo(r.getCurrentUserId(),e,n,function(a,s){if(s)return void U(null,s,t);r.currentUser&&(e&&(r.currentUser.nickname=e),n&&(r.currentUser.profileUrl=n)),U(r.currentUser,null,t)})},this.getPendingGCMToken=function(){return this.GCMPushToken},this.getPendingAPNSToken=function(){return this.APNSPushToken},this.registerGCMPushTokenForCurrentUser=function(e,n){var t=this;return e?this.currentUser?void j.getInstance().registerGCMPushToken(this.getCurrentUserId(),e,function(e,r){if(r)return void U(t.pushTokenRegistrationState.ERROR,r,n);t.GCMPushToken="",U(t.pushTokenRegistrationState.SUCCESS,null,n)}):(t.GCMPushToken=e,void U(t.pushTokenRegistrationState.PENDING,null,n)):void U(t.pushTokenRegistrationState.ERROR,new p("Invalid token",J.INVALID_PARAMETER),n)},this.unregisterGCMPushTokenForCurrentUser=function(e,n){if(!e)return void U(null,new p("Invalid token",J.INVALID_PARAMETER),n);j.getInstance().unregisterGCMPushToken(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.unregisterGCMPushTokenAllForCurrentUser=function(e){j.getInstance().unregisterGCMPushTokenAll(this.getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);U(null,null,e)})},this.registerAPNSPushTokenForCurrentUser=function(e,n){var t=this;return e?this.currentUser?void j.getInstance().registerAPNSPushToken(this.getCurrentUserId(),e,function(e,r){if(r)return void U(t.pushTokenRegistrationState.ERROR,r,n);t.APNSPushToken="",U(t.pushTokenRegistrationState.SUCCESS,null,n)}):(t.APNSPushToken=e,void U(t.pushTokenRegistrationState.PENDING,null,n)):void U(t.pushTokenRegistrationState.ERROR,new p("Invalid token",J.INVALID_PARAMETER),n)},this.unregisterAPNSPushTokenForCurrentUser=function(e,n){if(!e)return void U(null,new p("Invalid token",J.INVALID_PARAMETER),n);j.getInstance().unregisterAPNSPushToken(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.unregisterAPNSPushTokenAllForCurrentUser=function(e){j.getInstance().unregisterAPNSPushTokenAll(this.getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);U(null,null,e)})},this.unregisterPushTokenAllForCurrentUser=function(e){j.getInstance().unregisterAPNSPushTokenAll(this.getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);U(null,null,e)})},this.setDoNotDisturb=function(e,n,t,r,a,s,i){var o=this;if(n<0||n>23||t<0||t>59||r<0||r>23||a<0||a>59)return void U(null,new p("Invalid arguments.",J.INVALID_PARAMETER),i);j.getInstance().setDoNotDisturb(o.getCurrentUserId(),e,n,t,r,a,s,function(e,n){if(n)return void U(null,n,i);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};U(t,null,i)})},this.getDoNotDisturb=function(e){var n=this;j.getInstance().getDoNotDisturb(n.getCurrentUserId(),function(n,t){if(t)return void U(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};U(r,null,e)})},this.blockUser=function(e,n){if("object"!=typeof e)return void U(null,new p("You have to pass user object.",J.INVALID_PARAMETER),n);this.blockUserWithUserId(e.userId,n)},this.blockUserWithUserId=function(e,n){if(this.getCurrentUserId()==e)return void U(null,new p("You can not block yourself.",J.INVALID_PARAMETER),n);j.getInstance().blockUser(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(new F(e),null,n)})},this.unblockUser=function(e,n){if("object"!=typeof e)return void U(null,new p("You have to pass user object.",J.INVALID_PARAMETER),n);this.unblockUserWithUserId(e.userId,n)},this.unblockUserWithUserId=function(e,n){if(this.getCurrentUserId()==e)return void U(null,new p("You can not unblock yourself.",J.INVALID_PARAMETER),n);j.getInstance().unblockUser(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})}},$=null;return Z.getInstance=function(){return null===$?null:$},{SendBird:Z}},C=null;return function(){var e=function(e){if(e.newInstance||!C){var n=new A;C=new n.SendBird(e)}return C};return e.getInstance=function(){return null===C?null:C},e.version="3.0.46",{SendBird:e}}().SendBird}); \ No newline at end of file diff --git a/bower.json b/bower.json index 9b06280..8dc4c0a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "sendbird", - "version": "3.0.45", + "version": "3.0.46", "authors": [ "SendBird " ], diff --git a/package.json b/package.json index 350ed6a..a956351 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sendbird", - "version": "3.0.45", + "version": "3.0.46", "description": "SendBird JavaScript SDK", "main": "SendBird.min.js", "dependencies": {