diff --git a/CHANGELOG.md b/CHANGELOG.md index af03908..24e2c59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +## v3.0.57 + * Added `pushNotificationDeliveryOption` in `UserMessageParams` and `FileMessageParams` to determine whether it’d deliver the push notification for a user/file message. + * Added `channelCustomTypes` in `getTotalUnreadMessageCount()` to get an unread message count of `GroupChannel` with specific custom types. + ## v3.0.56 * Changed an ephemeral `GroupChannel` to maintain fields of `lastMessage` and `unreadMessageCount` after connected. * Update `SendBird.d.ts` file. diff --git a/README.md b/README.md index a77b2a9..9fc44d0 100644 --- a/README.md +++ b/README.md @@ -39,11 +39,10 @@ If you have trouble importing `SendBird`, please check your `tsconfig.json` file # [Documentation](https://docs.sendbird.com/javascript) -## Upgrading to v3.0.56 +## Upgrading to v3.0.57 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). - * Changed an ephemeral `GroupChannel` to maintain fields of `lastMessage` and `unreadMessageCount` after connected. - * Update `SendBird.d.ts` file. - + * Added `pushNotificationDeliveryOption` in `UserMessageParams` and `FileMessageParams` to determine whether it’d deliver the push notification for a user/file message. + * Added `channelCustomTypes` in `getTotalUnreadMessageCount()` to get an unread message count of `GroupChannel` with specific custom types. ## [Change Log](https://github.com/smilefam/SendBird-SDK-JavaScript/blob/master/CHANGELOG.md) diff --git a/SendBird.d.ts b/SendBird.d.ts index 6ea482d..974b9dd 100644 --- a/SendBird.d.ts +++ b/SendBird.d.ts @@ -1,5 +1,5 @@ /** - * Type Definitions for SendBird SDK v3.0.56 + * Type Definitions for SendBird SDK v3.0.57 * homepage: https://sendbird.com/ * git: https://github.com/smilefam/SendBird-SDK-JavaScript */ @@ -238,6 +238,7 @@ declare namespace SendBird { targetLanguages: Array; mentionedUserIds: Array; mentionedUsers: Array; + pushNotificationDeliveryOption: 'default' | 'suppress'; } interface UserMessage extends BaseMessageInstance { sender: User; @@ -259,6 +260,7 @@ declare namespace SendBird { thumbnailSizes: Array; mentionedUserIds: Array; mentionedUsers: Array; + pushNotificationDeliveryOption: 'default' | 'suppress'; } interface FileMessage extends BaseMessageInstance { sender: User; @@ -872,6 +874,7 @@ declare namespace SendBird { createPublicGroupChannelListQuery(): PublicGroupChannelListQuery; getTotalUnreadMessageCount(callback: groupChannelCountCallback): void; + getTotalUnreadMessageCount(channelCustomTypes: Array, callback: groupChannelCountCallback): void; getTotalUnreadChannelCount(callback: groupChannelCountCallback): void; createChannel(groupChannelParams: GroupChannelParams, callback: groupChannelCallback): void; diff --git a/SendBird.min.js b/SendBird.min.js index b740ccb..d312c04 100644 --- a/SendBird.min.js +++ b/SendBird.min.js @@ -1,9 +1,9 @@ /** * Copyright (c) 2016 SendBird DBA (Smile Family, Inc.) - * SendBird JavaScript SDK v3.0.56 + * SendBird JavaScript SDK v3.0.57 */ -!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define(["SendBird"],n):"object"==typeof exports?exports.SendBird=n():e.SendBird=n()}("undefined"!=typeof self?self:this,function(){function e(){this.oldIE=!0,this.boundary="--------FormData"+Math.random(),this._fields=[]}var n,t=!1,r="wss://ws.sendbird.com",a="https://api.sendbird.com";try{n=window.console||{log:function(){}}}catch(e){n={log:function(){}}}var i="undefined";try{i=navigator.userAgent.replace(/,/g,".")}catch(e){i="undefined"}var s,o="JS,"+i+",3.0.56,",l=function(){try{if(document&&9===document.documentMode)return!0}catch(e){return!1}return!1}(),u=function(){try{if(document&&document.documentMode<=8)return!0}catch(e){return!1}return!1}();if(l||u)"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&&l.status<400?c(null,JSON.parse(l.responseText),o):c({status:l.status,statusText:l.statusText,response:l.responseText},null,o)},l.onerror=function(){c({status:404,statusText:"There was a connection error",response:JSON.stringify({message:"There was a connection error",code:J.NETWORK_ERROR})},null,o)};try{for(var u in i)l.setRequestHeader(u,i[u]?i[u]:"sendbird")}catch(e){}try{switch(a){case"get":case"GET":l.send();break;default:"undefined"!=typeof FormData&&FormData&&r instanceof FormData||void 0!==s&&s&&r instanceof s?r.oldIE?(l.setRequestHeader("Content-Type","multipart/form-data; boundary="+r.boundary),l.send(r.toString())):l.send(r):(l.setRequestHeader("Content-Type","application/json; charset=utf-8"),l.send(JSON.stringify(r)))}}catch(e){t&&n.log("request.send() fail: ",e)}},R=!1,U=function(e,n,t){t&&"function"==typeof t&&(void 0===n&&(n=null),void 0===e&&(e=null),R?t(n,e):t(e,n))},S="",y=0,T=0,P=function(e){this.isOpenChannel=function(){return this.channelType===M.CHANNEL_TYPE_OPEN},this.isGroupChannel=function(){return this.channelType===M.CHANNEL_TYPE_GROUP},this.isUserMessage=function(){return this.messageType===P.MESSAGE_TYPE_USER},this.isAdminMessage=function(){return this.messageType===P.MESSAGE_TYPE_ADMIN},this.isFileMessage=function(){return this.messageType===P.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):M.CHANNEL_TYPE_GROUP;var n=this;if(n.mentionedUsers=[],e.hasOwnProperty("mentioned_users")){e.mentioned_users.forEach(function(e){var t=new G(e);n.mentionedUsers.push(t)})}},this.serialize=function(){var e=JSON.parse(JSON.stringify(this));return e.hasOwnProperty("_sender")&&(e.sender=e._sender,delete e._sender),p(e)},this.messageType=P.MESSAGE_TYPE_BASE,e&&this._update(e)};P.build=function(e,n){if(!e)return null;var t,r,a,i,s,o,l,u,c;switch(e.type){case"MESG":return t=new G(e.user),r=parseInt(e.message_id),a=String(e.message),i=String(e.data),s=parseInt(e.created_at),o=parseInt(e.updated_at),l=e.hasOwnProperty("custom_type")?String(e.custom_type):"",u=e.hasOwnProperty("translations")?e.translations:{},c=e.mentioned_users,new O(O.build("",r,t,n,a,i,l,u,s,o,c));case"FILE":t=new G(e.user),r=parseInt(e.message_id),a=String(e.message),s=parseInt(e.created_at),o=parseInt(e.updated_at),l=e.hasOwnProperty("custom_type")?String(e.custom_type):"",c=e.mentioned_users;var d=e.file,h=String(d.url),I=String(d.name),_=String(d.type),E=parseInt(d.size)||0;i=String(d.data);var p=e.hasOwnProperty("thumbnails")?e.thumbnails:[],f=!!e.hasOwnProperty("require_auth")&&e.require_auth;return new D(D.build("",r,t,n,h,I,_,E,i,l,s,p,f,o,c));case"BRDM":case"ADMM":return r=parseInt(e.message_id),a=String(e.message),i=String(e.data),s=parseInt(e.created_at),o=parseInt(e.updated_at),l=e.hasOwnProperty("custom_type")?String(e.custom_type):"",u=e.hasOwnProperty("translations")?e.translations:{},c=e.mentioned_users,new L(L.build(r,n,a,i,l,u,s,o,c))}return null},P.MESSAGE_TYPE_BASE="base",P.MESSAGE_TYPE_ADMIN="admin",P.MESSAGE_TYPE_USER="user",P.MESSAGE_TYPE_FILE="file";var L=function(e){this.messageType=P.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(P,L),L.build=function(e,n,t,r,a,i,s,o,l){var u={msg_id:e,channel_url:n.url,channel_type:n.channelType===M.CHANNEL_TYPE_OPEN?M.CHANNEL_TYPE_OPEN:M.CHANNEL_TYPE_GROUP,ts:s,updated_at:o,message:t,data:r};return a&&(u.custom_type=a),i&&(u.translations=i),u.mentioned_users=[],l&&(u.mentioned_users=l),u},L.buildFromSerializedData=function(e){var n=f(e),t=[];return n.mentionedUsers.forEach(function(e){t.push(G.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData,e.isActive,e.friendDiscoveryKey,e.friendName))}),new L(L.build(n.messageId,{url:n.channelUrl,channelType:n.channelType},n.message,n.data,n.customType,n.translations,n.createdAt,n.updatedAt,t))};var O=function(e){this.messageType=P.MESSAGE_TYPE_USER,e&&(this._update(e),this.message=String(e.message),this.data=e.hasOwnProperty("data")?String(e.data):"",this._sender=new G(e.user),u?this.sender=this._sender:Object.defineProperty(this,"sender",{get:function(){if(ae.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),this._sender.metaData!==n.metaData&&(this._sender.metaData=n.metaData))}}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(P,O),O.build=function(e,n,t,r,a,i,s,o,l,u,c,d){var h={};h.req_id=e,h.msg_id=n,h.channel_url=r.url,h.channel_type=r.channelType===M.CHANNEL_TYPE_OPEN?M.CHANNEL_TYPE_OPEN:M.CHANNEL_TYPE_GROUP,h.ts=l,h.updated_at=u,h.message=a,i&&(h.data=i),s&&(h.custom_type=s),o&&(h.translations=o);var I={};I.user_id=t.userId,I.nickname=t.nickname,I.profile_url=t.profileUrl;try{I.metadata="string"==typeof t.metaData?JSON.parse(t.metaData):t.metaData}catch(e){I.metadata={}}return h.user=I,h.mentioned_users=[],c&&(h.mentioned_users=c),d&&(h.mentioned_user_ids=d),h},O.buildFromSerializedData=function(e){var n=f(e),t=[];return n.mentionedUsers.forEach(function(e){t.push(G.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData,e.isActive,e.friendDiscoveryKey,e.friendName))}),new O(O.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,t))};var D=function(e){if(this.messageType=P.MESSAGE_TYPE_FILE,e&&(this._update(e),this._sender=new G(e.user),u?this.sender=this._sender:Object.defineProperty(this,"sender",{get:function(){if(ae.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),this._sender.metaData!==n.metaData&&(this._sender.metaData=n.metaData))}}return this._sender},set:function(e){this._sender=e}}),this.requireAuth=!!e.hasOwnProperty("require_auth")&&e.require_auth,this.url=this.requireAuth?String(e.url).split("?auth=")[0]+"?auth="+Z.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="+Z.getInstance().ekey};I(P,D),D.build=function(e,n,t,r,a,i,s,o,l,u,c,d,h,I,_,E){var p={};p.req_id=e,p.msg_id=n,p.channel_url=r.url,p.channel_type=r.channelType===M.CHANNEL_TYPE_OPEN?M.CHANNEL_TYPE_OPEN:M.CHANNEL_TYPE_GROUP,p.ts=c,p.updated_at=I,p.url=a,p.name=i,p.type=s,p.size=o,p.custom=l;var f={};f.user_id=t.userId,f.nickname=t.nickname,f.profile_url=t.profileUrl;try{f.metadata=JSON.parse(t.metaData)}catch(e){f.metadata={}}return p.user=f,u&&(p.custom_type=u),h&&(p.require_auth=h),d&&(p.thumbnails=d),p.mentioned_users=[],_&&(p.mentioned_users=_),E&&(p.mentioned_user_ids=E),p},D.buildFromSerializedData=function(e){var n=f(e),t=[];return n.mentionedUsers.forEach(function(e){t.push(G.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData,e.isActive,e.friendDiscoveryKey,e.friendName))}),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,t))};var M=function(e){this._update=function(e){this.url=e.hasOwnProperty("channel_url")?String(e.channel_url):"",this.name=e.hasOwnProperty("name")?String(e.name):"",this.coverUrl=e.hasOwnProperty("cover_url")?String(e.cover_url):"",this.createdAt=e.hasOwnProperty("created_at")?1e3*e.created_at:0,this.data=e.hasOwnProperty("data")?String(e.data):"",this.customType=e.hasOwnProperty("custom_type")?e.custom_type:"",this.isFrozen=!!e.hasOwnProperty("freeze")&&e.freeze,this.isEphemeral=!!e.hasOwnProperty("is_ephemeral")&&e.is_ephemeral,this.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 p(e)},this.isGroupChannel=function(){return this.channelType===M.CHANNEL_TYPE_GROUP},this.isOpenChannel=function(){return this.channelType===M.CHANNEL_TYPE_OPEN},this.getMessageChangeLogsByToken=function(e,n){if("function"==typeof e&&(n=e,e=null),"function"!=typeof n)return null;Z.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 P.build(e,this)}),a=e.deleted.map(function(e){return e.message_id}),i=e.has_more,s=e.next;U({updatedMessages:r,deletedMessageIds:a,hasMore:i,token:s},null,n)})},this.createPreviousMessageListQuery=function(){return new q(this)},this.createMessageListQuery=function(){return new W(this)};var n=function(e,n,t,r,a,i,s,o,l){if(s===E.MessageTypeFilter.ADMIN?s="ADMM":s===E.MessageTypeFilter.USER?s="MESG":s===E.MessageTypeFilter.FILE?s="FILE":s===E.MessageTypeFilter.ALL&&(s=""),!h(n)||"boolean"!=typeof t||!h(r)||!h(a)||"boolean"!=typeof i||"string"!=typeof s||"string"!=typeof o)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),l);Z.getInstance().messageList(e.isOpenChannel(),e.url,n,r,a,t,i,s,o,function(n,t){if(t)return void U(null,t,l);var r=n.messages,a=[];for(var i in r){var s=P.build(r[i],e);s&&a.push(s)}U(a,null,l)})},t=function(e,n,t,r,a,i,s,o,l){if(s===E.MessageTypeFilter.ADMIN?s="ADMM":s===E.MessageTypeFilter.USER?s="MESG":s===E.MessageTypeFilter.FILE?s="FILE":s===E.MessageTypeFilter.ALL&&(s=""),!h(n)||"boolean"!=typeof t||!h(r)||!h(a)||"boolean"!=typeof i||"string"!=typeof s||"string"!=typeof o)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),l);Z.getInstance().messageListByID(e.isOpenChannel(),e.url,n,r,a,t,i,s,o,function(n,t){if(t)return void U(null,t,l);var r=n.messages,a=[];for(var i in r){var s=P.build(r[i],e);s&&a.push(s)}U(a,null,l)})};this.getNextMessagesByTimestamp=function(e,t,r,a,i,s,o){return n(this,e,t,0,r,a,i,s,o)},this.getPreviousMessagesByTimestamp=function(e,t,r,a,i,s,o){return n(this,e,t,r,0,a,i,s,o)},this.getPreviousAndNextMessagesByTimestamp=function(e,t,r,a,i,s,o){return n(this,e,!0,t,r,a,i,s,o)},this.getNextMessagesByID=function(e,n,r,a,i,s,o){return t(this,e,n,0,r,a,i,s,o)},this.getPreviousMessagesByID=function(e,n,r,a,i,s,o){return t(this,e,n,r,0,a,i,s,o)},this.getPreviousAndNextMessagesByID=function(e,n,r,a,i,s,o){return t(this,e,!0,n,r,a,i,s,o)},this._sendFileCommand=function(e,n,t,r,a,i,s,o,l,u,c,d){var h,I=this;h=d?d.reqId:Y.generateRequestId();var E=Y.bFile(h,e,n,t,r,a,i,s,o,l,u),p=D.build(E.requestId,0,ae.getInstance().currentUser,this,"string"==typeof n?n:"",t,r,a,i,s,null,null,!1,null,null,u),f=new D(p);return"string"==typeof n&&ae.getInstance().sendCommand(E,function(e,n){if(n)return void U(null,new _(n.message,n.code),c);var t=new D(e.getJsonElement()),r=ae.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)),I.isGroupChannel()&&w.getChannel(I.url,function(e,n){if(R){var r=e;e=n,n=r}if(n)return void U(null,n,c);e.lastMessage=t;for(var a in ae.getInstance().channelHandlers){ae.getInstance().channelHandlers[a].onChannelChanged(e)}}),U(t,null,c)}),f},this._getSendFileMessageParamInfo=function(e){var n={file:null,name:null,type:null,size:null,data:"",customType:"",thumbnailSizes:[],callback:null,progressHandler:null,mentionedUserIds:[]};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:if(e[0]instanceof re){var t=e[0];n.file=t.file?t.file:t.fileUrl,n.name=t.fileName,n.type=t.mimeType,n.size=t.fileSize,n.data=t.data,n.customType=t.customType,n.thumbnailSizes=t.thumbnailSizes,n.mentionedUserIds=t._mentionedIds}else 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,i=n.size,s=n.data,o=n.customType,l=n.thumbnailSizes,u=n.callback,c=n.progressHandler,d=n.mentionedUserIds;if(null!==l&&void 0!==l||(l=[]),!ae.getInstance().hasLoggedIn())return void U(null,new _("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!==i&&void 0!==i&&(!h(i)||parseInt(i)<0)||null!==s&&void 0!==s&&"string"!=typeof s||null!==o&&void 0!==o&&"string"!=typeof o||!Array.isArray(l))return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),u);var I=e.url,E=null;return"string"==typeof t?E=e._sendFileCommand(I,t,r,a,i,s,o,[],!1,d,u):(E=e._sendFileCommand(I,t,r,a,i,s,o,[],!1,d,u),Z.getInstance().uploadFile(t,a,l,I,function(n,t){if(t)return void U(null,t,u);var l="object"==typeof n?n:JSON.parse(n),c=l.url,h=l.hasOwnProperty("thumbnails")?l.thumbnails:[],_=!!l.hasOwnProperty("require_auth")&&l.require_auth;e._sendFileCommand(I,c,r,a,i,s,o,h,_,d,u,E)},c,this.fileUploadRequest,E.reqId)),E},this.cancelUploadingFileMessage=function(e,n){if(!ae.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),n);if(!h(e))return void U(null,new _("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 _("Uploading has been completed or cancelled.",J.FILE_UPLOAD_CANCEL_FAILED),n),!1)},this.sendUserMessage=function(e,n,t,r,a){var i=this,s=[];if("function"==typeof n&&(a=n,n="",t="",r=[],e instanceof te)){var o=e;e=o.message,n=o.data,t=o.customType,r=o.targetLanguages,s=o._mentionedIds}if("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=""),!ae.getInstance().hasLoggedIn())return void U(null,new _("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 _("Invalid arguments.",J.INVALID_PARAMETER),a);var l=Y.bMessage(this.url,e,n,t,s,r),u=O.build(l.requestId,0,ae.getInstance().currentUser,this,e,n,t,r,(new Date).getTime(),null,null,s),c=new O(u);return ae.getInstance().sendCommand(l,function(e,n){if(n)return void U(null,new _(n.message,n.code),a);var t=new O(e.getJsonElement()),r=ae.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)),i.isGroupChannel()&&w.getChannel(i.url,function(e,n){if(R){var r=e;e=n,n=r}if(n)return void U(null,n,a);e.lastMessage=t;for(var i in ae.getInstance().channelHandlers){ae.getInstance().channelHandlers[i].onChannelChanged(e)}}),U(t,null,a)}),c},this.updateUserMessage=function(e,n,t,r,a){var i=Array.prototype.slice.call(arguments);if(5!==i.length)return"function"==typeof i.slice(-1)[0]&&(a=i.pop()),void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),a);if(!ae.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),a);if(!h(e))return void U(null,new _("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 _("Invalid arguments.",J.INVALID_PARAMETER),a);var s=Y.bUpdateUserMessage(this.url,e,n,t,r);ae.getInstance().sendCommand(s,function(e,n){if(n)return void U(null,new _(n.message,n.code),a);var t=new O(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 _("Invalid arguments.",J.INVALID_PARAMETER),r);if(!ae.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),r);if(!h(e))return void U(null,new _("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 _("Invalid arguments.",J.INVALID_PARAMETER),r);var i=Y.bUpdateFileMessage(this.url,e,n,t);ae.getInstance().sendCommand(i,function(e,n){if(n)return void U(null,new _(n.message,n.code),r);var t=new D(e.getJsonElement());U(t,null,r)})},this.createMetaCounters=function(e,n){return ae.getInstance().hasLoggedIn()?null==e||"object"!=typeof e||Array.isArray(e)||d(e)?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n):void Z.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 _("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.updateMetaCounters=function(e,n,t){return ae.getInstance().hasLoggedIn()?("function"!=typeof n&&void 0!==t||(t=n,n=!1),null==e||"object"!=typeof e||Array.isArray(e)||d(e)||"boolean"!=typeof n?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),t):void Z.getInstance().updateMetaCounters(this.isOpenChannel(),this.url,e,n,Z.UPDATE_META_COUNTER_MODE_SET,function(e,n){if(n)return void U(null,n,t);U(e,null,t)})):void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),t)},this.increaseMetaCounters=function(e,n){return ae.getInstance().hasLoggedIn()?null==e||"object"!=typeof e||Array.isArray(e)||d(e)?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n):void Z.getInstance().updateMetaCounters(this.isOpenChannel(),this.url,e,!1,Z.UPDATE_META_COUNTER_MODE_INC,function(e,t){if(t)return void U(null,t,n);U(e,null,n)}):void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.decreaseMetaCounters=function(e,n){return ae.getInstance().hasLoggedIn()?null==e||"object"!=typeof e||Array.isArray(e)||d(e)?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n):void Z.getInstance().updateMetaCounters(this.isOpenChannel(),this.url,e,!1,Z.UPDATE_META_COUNTER_MODE_DEC,function(e,t){if(t)return void U(null,t,n);var r=e,a={};for(var i in r){var s=r[i];a[i]=s}U(a,null,n)}):void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.getMetaCounters=function(e,n){return ae.getInstance().hasLoggedIn()?Array.isArray(e)?void Z.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 _("Invalid arguments.",J.INVALID_PARAMETER),n):void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.getAllMetaCounters=function(e){if(!ae.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),e);Z.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 ae.getInstance().hasLoggedIn()?"string"!=typeof e?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n):void Z.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 _("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.deleteAllMetaCounters=function(e){if(!ae.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),e);Z.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 ae.getInstance().hasLoggedIn()?null==e||"object"!=typeof e||Array.isArray(e)||d(e)?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n):void Z.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 _("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.updateMetaData=function(e,n,t){return ae.getInstance().hasLoggedIn()?("function"!=typeof n&&void 0!==t||(t=n,n=!1),null==e||"object"!=typeof e||Array.isArray(e)||d(e)||"boolean"!=typeof n?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),t):void Z.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 _("Connection should be made first.",J.CONNECTION_REQUIRED),t)},this.getMetaData=function(e,n){return ae.getInstance().hasLoggedIn()?Array.isArray(e)?void Z.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 _("Invalid arguments.",J.INVALID_PARAMETER),n):void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.getAllMetaData=function(e){if(!ae.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),e);Z.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 ae.getInstance().hasLoggedIn()?"string"!=typeof e?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n):void Z.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 _("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.deleteAllMetaData=function(e){if(!ae.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),e);Z.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 _("Invalid arguments.",J.INVALID_PARAMETER),n);if(!ae.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),n);var r=this;if("object"!=typeof e||d(e)||Array.isArray(e)||Object.keys(e).indexOf("messageId")<0||!e)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);Z.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=M.CHANNEL_TYPE_BASE,e&&this._update(e)};M.CHANNEL_TYPE_OPEN="open",M.CHANNEL_TYPE_GROUP="group",M.CHANNEL_TYPE_BASE="base";var b=function(e){this.parse=function(e){if(e.hasOwnProperty("participant_count")&&(this.participantCount=parseInt(e.participant_count)),e.hasOwnProperty("operators")&&e.operators){this.operators=[];for(var n in e.operators){var t=new G(e.operators[n]);this.operators.push(t)}}},this.refresh=function(e){b.getChannelWithoutCache(this.url,function(n,t){if(R){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;Z.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=Y.bEnter(n.url);ae.getInstance().sendCommand(t,function(t,r){if(r)return void U(null,new _(r.message,r.code),e);b.enteredChannels[n.url]=n,U(null,null,e)})},this.exit=function(e){var n=this,t=Y.bExit(n.url);ae.getInstance().sendCommand(t,function(t,r){if(r)return void U(null,new _(r.message,r.code),e);delete b.enteredChannels[n.url],U(null,null,e)})},this.createParticipantListQuery=function(){return new z(z.PARTICIPANT,this)},this.createMutedUserListQuery=function(){return new z(z.MUTED_USER,this)},this.createBannedUserListQuery=function(){return new z(z.BANNED_USER,this)},this.updateChannel=function(){var e=Array.prototype.slice.call(arguments),n=null,t=null,r=null,a=null,i=null,s=null;switch("function"==typeof e.slice(-1)[0]&&(s=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],i=e[4];break;default:return void U(null,new _("Invalid arguments.2",J.INVALID_PARAMETER),s)}this.updateChannelWithOperatorUserIds(n,t,r,a,i,s)},this.updateChannelWithOperatorUserIds=function(e,n,t,r,a,i){if("function"==typeof a&&(i=a,a=null),"string"!=typeof e&&null!==e&&void 0!==e||"string"!=typeof n&&d(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 _("Invalid arguments.",J.INVALID_PARAMETER),i);Z.getInstance().updateOpenChannel(this.url,e,n,t,r,a,function(e,n){if(n)return void U(null,n,i);var t=b.upsert(e);U(t,null,i)})},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 _("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 _("Invalid parameter.",J.INVALID_PARAMETER),t);Z.getInstance().banUser(this.url,e,null,n,!1,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 _("Invalid parameter.",J.INVALID_PARAMETER),n);this.unbanUserWithUserId(e.userId,n)},this.unbanUserWithUserId=function(e,n){if(!e)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);Z.getInstance().unbanUser(this.url,e,!1,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 _("Invalid parameter.",J.INVALID_PARAMETER),n);this.muteUserWithUserId(e.userId,n)},this.muteUserWithUserId=function(e,n){if(!e)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);Z.getInstance().muteUser(this.url,e,!1,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 _("Invalid parameter.",J.INVALID_PARAMETER),n);this.unmuteUserWithUserId(e.userId,n)},this.unmuteUserWithUserId=function(e,n){if(!e)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);Z.getInstance().unmuteUser(this.url,e,!1,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=M.CHANNEL_TYPE_OPEN,this.participantCount=0,this.operators=[],e&&(this._update(e),this.parse(e))};I(M,b),b.enteredChannels={},b.clearEnteredChannels=function(){b.enteredChannels={}}, -b.createOpenChannelListQuery=function(){return new K},b.buildFromSerializedData=function(e){var n=f(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,is_ephemeral:n.isEphemeral,participant_count:n.participantCount,operators:n.operators.map(function(e){return G.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData,e.isActive,e.friendDiscoveryKey,e.friendName)})})},b.createChannel=function(){var e,n,t,r,a,i;switch(arguments.length){case 1:i=arguments[0];break;case 4:e=arguments[0],n=arguments[1],t=arguments[2],i=arguments[3];break;case 5:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],i=arguments[4];break;case 6:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],a=arguments[4],i=arguments[5]}b.createChannelWithOperatorUserIds(e,n,t,r,a,i)},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,i){if("function"==typeof a&&(i=a,a=""),"string"!=typeof e&&null!==e&&void 0!==e||"string"!=typeof n&&d(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 _("Invalid arguments.",J.INVALID_PARAMETER),i);Z.getInstance().createOpenChannel(e,n,t,r,a,function(e,n){if(n)return void U(null,n,i);var t=b.upsert(e);U(t,null,i)})},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 _("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 _("Invalid arguments.",J.INVALID_PARAMETER),n);Z.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 t,r,a={};this.parse=function(e){var n=this;if(n.isDistinct=!!e.is_distinct&&e.is_distinct,n.unreadMessageCount=parseInt(e.unread_message_count),n.isPushEnabled=!!e.is_push_enabled&&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 V(e);n.members.push(t),n.memberMap[t.userId]=t})}e.hasOwnProperty("member_state")?n.myMemberState=e.member_state:n.myMemberState="none",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 P?n.lastMessage=e.last_message:n.lastMessage=P.build(e.last_message,n):n.lastMessage=null,e.hasOwnProperty("inviter")&&null!==e.inviter&&"object"==typeof e.inviter&&!d(e.inviter)?n.inviter=new G(e.inviter):n.inviter=null,e.hasOwnProperty("is_super")&&null!==e.is_super&&"boolean"==typeof e.is_super?n.isSuper=e.is_super:n.isSuper=!1,e.hasOwnProperty("is_public")&&null!==e.is_public&&"boolean"==typeof e.is_public?n.isPublic=e.is_public:n.isPublic=!1},this.refresh=function(e){w.getChannelWithoutCache(this.url,function(n,t){if(R){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,i=null,s=null,o=null,l=null;switch("function"==typeof n.slice(-1)[0]&&(o=n.pop()),n.length){case 1:if(!(n[0]instanceof ne))return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),o);var u=n[0];t=u.isDistinct,r=u.name,a=u.channelCover,i=u.data,s=u.customType,l=u.isPublic;break;case 3:t=e.isDistinct,r=n[0],a=n[1],i=n[2];break;case 4:t=n[0],r=n[1],a=n[2],i=n[3];break;case 5:t=n[0],r=n[1],a=n[2],i=n[3],s=n[4];break;default:return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),o)}if("string"!=typeof r&&null!==r&&void 0!==r||"string"!=typeof a&&d(a)&&null!==a&&void 0!==a||"string"!=typeof i&&null!==i&&void 0!==i||"boolean"!=typeof t&&null!==t||"boolean"!=typeof l&&null!==l||"string"!=typeof s&&null!==s&&void 0!==s)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),o);Z.getInstance().updateGroupChannel(e.url,t,r,a,i,s,l,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(!ae.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),e);Z.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)||d(e))return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);var t=[];for(var r in e){if("object"!=typeof e[r]||d(e[r])){U(null,new _("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)||d(e))return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);Z.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){Z.getInstance().acceptInvitation(this.url,ae.getInstance().getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);var r=w.upsert(n);r.myMemberState="joined",w.cachedChannels[r.url]=r,U(r,null,e)})},this.declineInvitation=function(e){var n=this;Z.getInstance().declineInvitation(this.url,ae.getInstance().getCurrentUserId(),function(t,r){if(r)return void U(null,r,e);n.myMemberState="none",w.cachedChannels[n.url]=n,n.isPublic||w.removeCachedChannel(n.url),U(t,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 _("Invalid parameter.",J.INVALID_PARAMETER),n);var t=this.url,r=this;Z.getInstance().groupChannelHide(t,ae.getInstance().getCurrentUserId(),e,function(a,i){if(i)return void U(null,i,n);r.isHidden=!0;var s=w.cachedChannels[t];s&&(s.isHidden=!0,e&&(s.unreadMessageCount=0),w.cachedChannels[t]=s),U(a,null,n)})},this.join=function(e){var n=this.url;Z.getInstance().publicGroupChannelJoin(n,ae.getInstance().getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);var r=w.upsert(n);r.myMemberState="joined",w.cachedChannels[r.url]=r,U(r,null,e)})},this.leave=function(e){var n=this.url;Z.getInstance().groupChannelLeave(n,ae.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=Y.bRead(n.url);ae.getInstance().sendCommand(t,function(t,r){if(r)return void U(null,new _(r.message,r.code),e);if(n.unreadMessageCount>0){n.unreadMessageCount=0;for(var a in ae.getInstance().channelHandlers){ae.getInstance().channelHandlers[a].onChannelChanged(n)}}U(null,null,e)})},this.getReadReceipt=function(e){if(!(e instanceof P))return n.log("message is not BaseMessage instance"),-1;if(e.messageType===P.MESSAGE_TYPE_ADMIN)return 0;var t=ae.getInstance().currentUser,r=0,a=e.createdAt,i=this.members;for(var s in i){var o=i[s],l=o.userId;if(!(t.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===V.JOINED&&(e.state=V.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 null===t&&this.isSuper&&this.memberCount--,t},this.setPushPreference=function(e,n){var t=this;if(!ae.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),n);Z.getInstance().setPushPreference(ae.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(!ae.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),e);Z.getInstance().getPushPreference(ae.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.createMemberListQuery=function(){var e=this.url;return new B(e)},this.banUser=function(e,n,t,r){if(!e||!e.hasOwnProperty("userId")||"string"!=typeof t)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),r);this.banUserWithUserId(e.userId,n,t,r)},this.banUserWithUserId=function(e,n,t,r){if(!e||"string"!=typeof e||"string"!=typeof t)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),r);Z.getInstance().banUser(this.url,e,t,n,!0,function(e,n){if(n)return void U(null,n,r);U(null,null,r)})},this.unbanUser=function(e,n){if(!e||!e.hasOwnProperty("userId"))return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);this.unbanUserWithUserId(e.userId,n)},this.unbanUserWithUserId=function(e,n){if(!e||"string"!=typeof e)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);Z.getInstance().unbanUser(this.url,e,!0,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.muteUser=function(e,n){if(!e||!e.hasOwnProperty("userId"))return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);this.muteUserWithUserId(e.userId,n)},this.muteUserWithUserId=function(e,n){if(!e||"string"!=typeof e)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);Z.getInstance().muteUser(this.url,e,!0,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.unmuteUser=function(e,n){if(!e||!e.hasOwnProperty("userId"))return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);this.unmuteUserWithUserId(e.userId,n)},this.unmuteUserWithUserId=function(e,n){if(!e||"string"!=typeof e)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);Z.getInstance().unmuteUser(this.url,e,!0,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.freeze=function(e){Z.getInstance().freeze(this.url,!0,!0,function(n,t){if(t)return void U(null,t,e);w.upsert(n),U(null,null,e)})},this.unfreeze=function(e){Z.getInstance().freeze(this.url,!0,!1,function(n,t){if(t)return void U(null,t,e);w.upsert(n),U(null,null,e)})},this.createBannedUserListQuery=function(){return new z(z.BANNED_USER,this)},this.channelType=M.CHANNEL_TYPE_GROUP,this.isDistinct=!1,this.isSuper=!1,this.isPublic=!1,this.unreadMessageCount=0,this.inviter=null,this.members=[],this.memberMap={},this.lastMessage={},this.memberCount=0,this.cachedReadReceiptStatus={},this.isPushEnabled,this.isHidden=!1,e&&(this._update(e),this.parse(e))};I(M,w),w.buildFromSerializedData=function(e){var n=f(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,is_super:n.isSuper,is_public:n.isPublic,freeze:n.isFrozen,is_ephemeral:n.isEphemeral,unread_message_count:n.unreadMessageCount,is_push_enabled:n.isPushEnabled,is_hidden:n.isHidden,member_count:n.memberCount,member_state:n.myMemberState,members:n.members.map(function(e){return V.build(G.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData,e.isActive,e.friendDiscoveryKey,e.friendName),e.state,e.isBlockedByMe,e.isBlockingMe)}),last_message:function(e){return null!==e&&void 0!==e&&"object"==typeof e?e.messageType===P.MESSAGE_TYPE_USER?new O(O.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===P.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?G.build(n.inviter.userId,n.inviter.nickname,n.inviter.profileUrl,n.inviter.connectionStatus,n.inviter.lastSeenAt,n.inviter.metaData,n.inviter.isActive,n.inviter.friendDiscoveryKey,n.inviter.friendName):null})},w.createMyGroupChannelListQuery=function(){return new Q(ae.getInstance().currentUser)},w.createPublicGroupChannelListQuery=function(){return new x},w.memberState={ALL:0,JOINED:1,INVITED:2,INVITED_BY_FRIEND:3,INVITED_BY_NON_FRIEND:4},w.memberStateFilter={ALL:"all",JOINED:"joined_only",INVITED:"invited_only",INVITED_BY_FRIEND:"invited_by_friend",INVITED_BY_NON_FRIEND:"invited_by_non_friend"},w.superChannelFilter={ALL:"all",SUPER:"super",NON_SUPER:"nonsuper"},w.publicChannelFilter={ALL:"all",PUBLIC:"public",PRIVATE:"private"},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&&e!==w.memberState.INVITED_BY_FRIEND&&e!==w.memberState.INVITED_BY_NON_FRIEND?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n):ae.getInstance().hasLoggedIn()?void Z.getInstance().getGroupChannelCount(ae.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 _("Connection should be made first.",J.CONNECTION_REQUIRED),n))},w.getTotalUnreadMessageCount=function(e){Z.getInstance().getTotalUnreadMessageCount(ae.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){Z.getInstance().getTotalUnreadChannelCount(ae.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=[],t=null,r=null,a=null,i=null,s=null,o=null,l=null,u={isPublic:null,channelUrl:null},c=[],h=null;switch(arguments.length){case 2:if(arguments[0]instanceof ne){var I=arguments[0];n=I._inviteUserIds,e=[],t=I.isDistinct,r=I.isSuper,a=I.name,i=I.channelCover,s=I.data,l=I.customType,c=I._operatorIds,u.isPublic=I.isPublic,u.channelUrl=I.channelUrl,h=I.isEphemeral,o=arguments[1];break}e=arguments[0],t=!1,o=arguments[1];break;case 3:e=arguments[0],t=arguments[1],o=arguments[2];break;case 4:e=arguments[0],t=arguments[1],l=arguments[2],o=arguments[3];break;case 6:e=arguments[0],t=arguments[1],a=arguments[2],i=arguments[3],s=arguments[4],o=arguments[5];break;case 7:e=arguments[0],t=arguments[1],a=arguments[2],i=arguments[3],s=arguments[4],l=arguments[5],o=arguments[6]}if(!Array.isArray(e)||"boolean"!=typeof t&&null!==t||"boolean"!=typeof r&&null!==r||"boolean"!=typeof h&&null!==h||"boolean"!=typeof u.isPublic&&null!==u.isPublic||"string"!=typeof u.channelUrl&&null!==u.channelUrl||"string"!=typeof a&&null!==a&&void 0!==a||"string"!=typeof i&&d(i)&&null!==i&&void 0!==i||"string"!=typeof s&&null!==s&&void 0!==s||"string"!=typeof l&&null!==l&&void 0!==l)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),o);e.forEach(function(e){n.push(e.userId)}),w.createChannelWithUserIds(n,t,a,i,s,l,r,u,c,h,o)},w.createChannelWithUserIds=function(){var e=null,n=null,t=null,r=null,a=null,i=null,s=null,o=null,l=[],u={isPublic:null,channelUrl:null},c=null;switch(arguments.length){case 2:e=arguments[0],n=!1,i=arguments[1];break;case 3:e=arguments[0],n=arguments[1],i=arguments[2];break;case 4:e=arguments[0],n=arguments[1],s=arguments[2],i=arguments[3];break;case 6:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],a=arguments[4],i=arguments[5];break;case 7:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],a=arguments[4],s=arguments[5],i=arguments[6];break;case 8:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],a=arguments[4],s=arguments[5],o=arguments[6],i=arguments[7];break;case 9:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],a=arguments[4],s=arguments[5],o=arguments[6],u.isPublic=arguments[7].isPublic,u.channelUrl=arguments[7].channelUrl,i=arguments[8];break;case 10:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],a=arguments[4],s=arguments[5],o=arguments[6],u.isPublic=arguments[7].isPublic,u.channelUrl=arguments[7].channelUrl,l=arguments[8],i=arguments[9];break;case 11:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],a=arguments[4],s=arguments[5],o=arguments[6],u.isPublic=arguments[7].isPublic,u.channelUrl=arguments[7].channelUrl,l=arguments[8],c=arguments[9],i=arguments[10]}if(!ae.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),i);if(!Array.isArray(e)||"boolean"!=typeof n&&null!==n||"boolean"!=typeof o&&null!==o||"boolean"!=typeof c&&null!==c||"boolean"!=typeof u.isPublic&&null!==u.isPublic||"string"!=typeof u.channelUrl&&null!==u.channelUrl||"string"!=typeof t&&null!==t&&void 0!==t||"string"!=typeof r&&d(r)&&null!==r&&void 0!==r||"string"!=typeof a&&null!==a&&void 0!==a||"string"!=typeof s&&null!==s&&void 0!==s)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),i);var h=e.filter(function(e,n,t){return n===t.indexOf(e)}),I=ae.getInstance().currentUser;h.push(I.userId),Z.getInstance().createGroupChannel(h,n,t,r,a,s,o,u,l,c,function(e,n){if(n)return void U(null,n,i);var t=new w(e);w.cachedChannels[t.url]=t,U(t,null,i)})},w.cachedChannels={},w.clearCache=function(){w.cachedChannels={}},w.removeCachedChannel=function(e){delete w.cachedChannels[e]},w.upsert=function(e){var n=new w(e);if(w.cachedChannels.hasOwnProperty(n.url)){if(n.isEphemeral){var t=w.cachedChannels[n.url];e.last_message=t.lastMessage,e.unread_message_count=t.unreadMessageCount}w.cachedChannels[n.url].update(e)}else w.cachedChannels[n.url]=n;return w.cachedChannels[n.url]},w.getChannelWithoutCache=function(e,n){if(!e)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);Z.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 _("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){ae.getInstance().markAsReadAll(e)};var H=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):M.CHANNEL_TYPE_GROUP),this.isGroupChannel=function(){return this.channelType===M.CHANNEL_TYPE_GROUP},this.isOpenChannel=function(){return this.channelType===M.CHANNEL_TYPE_OPEN}};H.CATEGORY_NONE=0,H.CATEGORY_CHANNEL_ENTER=10102,H.CATEGORY_CHANNEL_EXIT=10103,H.CATEGORY_USER_CHANNEL_MUTE=10201,H.CATEGORY_USER_CHANNEL_UNMUTE=10200,H.CATEGORY_USER_CHANNEL_BAN=10601,H.CATEGORY_USER_CHANNEL_UNBAN=10600,H.CATEGORY_CHANNEL_FREEZE=10701,H.CATEGORY_CHANNEL_UNFREEZE=10700,H.CATEGORY_TYPING_START=10900,H.CATEGORY_TYPING_END=10901,H.CATEGORY_CHANNEL_JOIN=1e4,H.CATEGORY_CHANNEL_LEAVE=10001,H.CATEGORY_CHANNEL_INVITE=10020,H.CATEGORY_CHANNEL_DECLINE_INVITE=10022,H.CATEGORY_CHANNEL_PROP_CHANGED=11e3,H.CATEGORY_CHANNEL_DELETED=12e3,H.CATEGORY_CHANNEL_META_DATA_CHANGED=11100,H.CATEGORY_CHANNEL_META_COUNTERS_CHANGED=11200,H.CATEGORY_CHANNEL_HIDE=13e3;var k=function(e){e&&(this.category=e.hasOwnProperty("cat")?parseInt(e.cat):0)};k.CATEGORY_USER_BLOCK=20001,k.CATEGORY_USER_UNBLOCK=2e4,k.CATEGORY_FRIEND_DISCOVERED=20900;var F=function(e){e&&(this.reader=new G(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):M.CHANNEL_TYPE_GROUP)},G=function(e){this.nickname="",this.profileUrl="",this.userId="",this.connectionStatus="",this.lastSeenAt=null,this.metaData={},this.isActive=!0,this.friendDiscoveryKey=null,this.friendName=null,this.getOriginalProfileUrl=function(){var e="";if(e=this.profileUrl.indexOf("://")>-1?this.profileUrl.split("/")[2]:this.profileUrl.split("/")[0],e=e.split("?")[0],(e.indexOf("sendbird.com")>-1||e.indexOf("intoz.com")>-1)&&this.profileUrl.indexOf(e+"/profile_images/")>-1){var n=this.profileUrl.replace("profile_images/","");return n===this.profileUrl?"":n}return""},this._update=function(e){e.hasOwnProperty("guest_id")&&(this.userId=String(e.guest_id)),e.hasOwnProperty("user_id")&&(this.userId=String(e.user_id)),e.hasOwnProperty("name")&&(this.nickname=String(e.name)),e.hasOwnProperty("nickname")&&(this.nickname=String(e.nickname)),e.hasOwnProperty("image")&&(this.profileUrl=String(e.image)),e.hasOwnProperty("profile_url")&&(this.profileUrl=String(e.profile_url)),e.hasOwnProperty("is_online")?e.is_online===G.NON_AVAILABLE?this.connectionStatus=G.NON_AVAILABLE:this.connectionStatus=e.is_online?G.ONLINE:G.OFFLINE:this.connectionStatus=G.NON_AVAILABLE,e.hasOwnProperty("last_seen_at")?this.lastSeenAt=parseInt(e.last_seen_at):this.lastSeenAt=0,e.hasOwnProperty("metadata")?this.metaData=e.metadata:this.metaData={},e.hasOwnProperty("is_active")?this.isActive="undefined"==typeof e.is_active||e.is_active:this.isActive=!0,e.hasOwnProperty("friend_discovery_key")?this.friendDiscoveryKey=e.friend_discovery_key:this.friendDiscoveryKey=null,e.hasOwnProperty("friend_name")?this.friendName=e.friend_name:this.friendName=null},this._updateMetaData=function(e,n){var t=this,r=Object.keys(e);n?r.forEach(function(e){delete t.metaData[e]}):r.forEach(function(n){t.metaData[n]=e[n]})},this.createMetaData=function(e,n){var t=this;return"function"==typeof e&&1===arguments.length&&(n=e,e={}),"object"!=typeof e||d(e)||Array.isArray(e)?void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n):ae.getInstance().hasLoggedIn()?void Z.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 _("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||d(e)||Array.isArray(e)||"boolean"!=typeof n?void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),t):ae.getInstance().hasLoggedIn()?void Z.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 _("Connection should be made first.",J.CONNECTION_REQUIRED),t))},this.deleteAllMetaData=function(e){var n=this,t=n.metaData;if(!ae.getInstance().hasLoggedIn())return void(e&&U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),e));Z.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 _("Invalid parameter.",J.INVALID_PARAMETER),n);if(!ae.getInstance().hasLoggedIn())return void(n&&U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),n));var r={};r[e]="",Z.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 p(e)},e&&this._update(e)};G.NON_AVAILABLE="nonavailable",G.ONLINE="online",G.OFFLINE="offline",G.build=function(e,n,t,r,a,i,s,o,l){return{user_id:e,nickname:n,profile_url:t,is_online:r,last_seen_at:a,metadata:i,is_active:s,friend_discovery_key:o,friend_name:l}},G.buildFromSerializedData=function(e){var n=f(e);return new G(G.build(n.userId,n.nickname,n.profileUrl,n.connectionStatus,n.lastSeenAt,n.metaData,n.isActive,n.friendDiscoveryKey,n.friendName))};var V=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(G,V),V.JOINED="joined",V.INVITED="invited",V.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},V.buildFromSerializedData=function(e){var n=f(e);return new V(V.build(G.build(n.userId,n.nickname,n.profileUrl,n.connectionStatus,n.lastSeenAt,n.metaData,n.isActive,n.friendDiscoveryKey,n.friendName),n.state,n.isBlockedByMe,n.isBlockingMe))};var Y=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 i=arguments[0];if(!i||i.length<=4)return r.command="NOOP",void(r.payload="{}");if(i=i.trim(),r.command=i.substring(0,4),r.payload=i.substring(4),r.isRequestIdCommand()){var s=r.getJsonElement();s&&(r.requestId=s.hasOwnProperty("req_id")?s.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=Y.generateRequestId()),l.req_id=r.requestId,r.payload=JSON.stringify(l)}}};Y.bMessage=function(e,n,t,r,a,i){var s={};return s.channel_url=e,s.message=n,s.data=t,s.mentioned_user_ids=[],Array.isArray(a)&&a.length>0&&(s.mentioned_user_ids=a),r&&(s.custom_type=r),i.length>0&&(s.target_langs=i),new Y("MESG",s)},Y.bRead=function(e){var n={};return n.channel_url=e,new Y("READ",n)},Y.bTypeStart=function(e,n){var t={};return t.channel_url=e,t.time=n,new Y("TPST",t)},Y.bTypeEnd=function(e,n){var t={};return t.channel_url=e,t.time=n,new Y("TPEN",t)},Y.bFile=function(e,n,t,r,a,i,s,o,l,u,c){var d={};d.channel_url=n,d.url=t,d.name=r||"",d.type=a||"",d.size=i||0,d.custom=s,o&&(d.custom_type=o),l&&(d.thumbnails=l),u&&(d.require_auth=u),d.mentioned_user_ids=[];for(var h in c){var I=c[h];d.mentioned_user_ids.push(String(I))}return new Y("FILE",d,e)},Y.bPing=function(){var e={};return e.id=(new Date).getTime(),new Y("PING",e)},Y.bEnter=function(e){var n={};return n.channel_url=e,new Y("ENTR",n)},Y.bExit=function(e){var n={};return n.channel_url=e,new Y("EXIT",n)},Y.bUpdateUserMessage=function(e,n,t,r,a){var i={};return i.channel_url=e,i.msg_id=n,null!=t&&t!==undefined&&(i.message=t),null!=r&&r!==undefined&&(i.data=r),null!=a&&a!==undefined&&(i.custom_type=a),new Y("MEDI",i)},Y.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 Y("FEDI",a)},Y.requestIdSeed=(new Date).getTime(),Y.generateRequestId=function(){return Y.requestIdSeed++,String(Y.requestIdSeed)};var B=function(e){this.isLoading=!1,this.hasNext=!0,this.limit=20,this.mutedMemberFilter=B.MUTED_MEMBER_FILTER.ALL,this.operatorFilter=B.OPERATOR_FILTER.ALL;var n="",t=this;this.next=function(r){return t.hasNext?t.isLoading?void U(null,new _("Query in progress.",J.QUERY_IN_PROGRESS),r):"string"!=typeof t.mutedMemberFilter||[B.MUTED_MEMBER_FILTER.ALL,B.MUTED_MEMBER_FILTER.MUTED,B.MUTED_MEMBER_FILTER.UNMUTED].indexOf(t.mutedMemberFilter.toLowerCase())<0||"string"!=typeof t.operatorFilter||[B.OPERATOR_FILTER.ALL,B.OPERATOR_FILTER.OPERATOR,B.OPERATOR_FILTER.NONOPERATOR].indexOf(t.operatorFilter.toLowerCase())<0?void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),r):(t.isLoading=!0,void Z.getInstance().loadGroupChannelMemberList(e,n,t.limit,t.mutedMemberFilter,t.operatorFilter,function(e,a){if(a)return t.isLoading=!1,void U(null,a,r);var i=e;(!(n=String(i.next))||n.length<=0)&&(t.hasNext=!1);var s=i.members.map(function(e){return new V(e)});t.isLoading=!1,U(s,null,r)})):void U([],null,r)}};B.MUTED_MEMBER_FILTER={ALL:"all",MUTED:"muted",UNMUTED:"unmuted"},B.OPERATOR_FILTER={ALL:"all",OPERATOR:"operator",NONOPERATOR:"nonoperator"};var Q=function(e){this.isLoading=!1,this.hasNext=!0,this.limit=20,this.includeEmpty=!1,this.order=Q.ORDER_LATEST_LAST_MESSAGE,this.userIdsFilter=[],this.userIdsFilterExactMatch=!1,this.queryType="AND";var n={userIds:[],includeMode:!0,queryType:x.USER_IDS_INCLUDE_QUERY_TYPE.AND};this._userIdsExactFilter=[],this._userIdsIncludeFilter=[],this._userIdsIncludeFilterQueryType=x.USER_IDS_INCLUDE_QUERY_TYPE.AND,u?(this.userIdsExactFilter=this._userIdsExactFilter,this.userIdsIncludeFilter=this._userIdsIncludeFilter,this.userIdsIncludeFilterQueryType=this._userIdsIncludeFilterQueryType):(Object.defineProperty(this,"userIdsExactFilter",{get:function(){return this._userIdsExactFilter},set:function(e){if(!Array.isArray(e))throw new _("Invalid parameter.",J.INVALID_PARAMETER);this._userIdsExactFilter=e,this._userIdsIncludeFilter=[],n={userIds:this._userIdsExactFilter,includeMode:!1}}}),Object.defineProperty(this,"userIdsIncludeFilter",{get:function(){return this._userIdsIncludeFilter},set:function(e){if(!Array.isArray(e))throw new _("Invalid parameter.",J.INVALID_PARAMETER);this._userIdsIncludeFilter=e,this._userIdsExactFilter=[],n={userIds:this._userIdsIncludeFilter,includeMode:!0}}}),Object.defineProperty(this,"userIdsIncludeFilterQueryType",{get:function(){return this._userIdsIncludeFilterQueryType},set:function(e){this._userIdsIncludeFilterQueryType=e,n={queryType:this._userIdsIncludeFilterQueryType}}})),this.nicknameContainsFilter="",this.channelNameContainsFilter="",this.memberStateFilter=w.memberStateFilter.ALL,this.customTypeFilter="",this.customTypesFilter=[],this.channelUrlsFilter=[],this.superChannelFilter=w.superChannelFilter.ALL,this.publicChannelFilter=w.publicChannelFilter.ALL,this.customTypeStartsWithFilter=null;var t=e,r="",a=this;this.next=function(e){if(!a.hasNext)return void U([],null,e) -;if(a.isLoading)return void U(null,new _("Query in progress.",J.QUERY_IN_PROGRESS),e);if(null!==a.nicknameContainsFilter&&"undefined"!=typeof a.nicknameContainsFilter||(a.nicknameContainsFilter=""),null!==a.channelNameContainsFilter&&"undefined"!=typeof a.channelNameContainsFilter||(a.channelNameContainsFilter=""),null!==a.customTypeStartsWithFilter&&"string"!=typeof a.customTypeStartsWithFilter)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),e);if(!Array.isArray(a._userIdsExactFilter)||!Array.isArray(a._userIdsIncludeFilter)||"string"!=typeof a._userIdsIncludeFilterQueryType||[x.USER_IDS_INCLUDE_QUERY_TYPE.AND,x.USER_IDS_INCLUDE_QUERY_TYPE.OR].indexOf(a._userIdsIncludeFilterQueryType.toUpperCase())<0)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),e);if("number"==typeof a.memberStateFilter){if(typeof a.memberStateFilter<0||typeof a.memberStateFilter>4)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),e);var i=["all","joined_only","invited_only","invited_by_friend","invited_by_non_friend"];a.memberStateFilter=i[a.memberStateFilter]}if(!h(a.limit)||!Array.isArray(a.userIdsFilter)||"boolean"!=typeof a.userIdsFilterExactMatch||"string"!=typeof a.customTypeFilter||!Array.isArray(a.customTypesFilter)||"string"!=typeof a.queryType||["AND","OR"].indexOf(a.queryType.toUpperCase())<0||"string"!=typeof a.order||[Q.ORDER_CHRONOLOGICAL,Q.ORDER_LATEST_LAST_MESSAGE,Q.CHANNEL_NAME_ALPHABETICAL].indexOf(a.order.toLowerCase())<0||"string"!=typeof a.memberStateFilter||[w.memberStateFilter.ALL,w.memberStateFilter.JOINED,w.memberStateFilter.INVITED,w.memberStateFilter.INVITED_BY_FRIEND,w.memberStateFilter.INVITED_BY_NON_FRIEND].indexOf(a.memberStateFilter.toLowerCase())<0||"string"!=typeof a.nicknameContainsFilter||"string"!=typeof a.channelNameContainsFilter||!Array.isArray(a.channelUrlsFilter)||"string"!=typeof a.superChannelFilter||[w.superChannelFilter.ALL,w.superChannelFilter.SUPER,w.superChannelFilter.NON_SUPER].indexOf(a.superChannelFilter.toLowerCase())<0||"string"!=typeof a.publicChannelFilter||[w.publicChannelFilter.ALL,w.publicChannelFilter.PUBLIC,w.publicChannelFilter.PRIVATE].indexOf(a.publicChannelFilter.toLowerCase())<0)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),e);Array.isArray(a.userIdsFilter)&&a.userIdsFilter.length>0&&(n={userIds:a.userIdsFilter,includeMode:!a.userIdsFilterExactMatch,queryType:a.queryType}),a.isLoading=!0,Z.getInstance().loadUserGroupChannelList(t.userId,r,a.limit,a.includeEmpty,a.order,n,a.nicknameContainsFilter,a.channelNameContainsFilter,a.channelUrlsFilter,a.customTypeFilter,a.customTypesFilter,a.customTypeStartsWithFilter,a.memberStateFilter,a.superChannelFilter,a.publicChannelFilter,function(n,t){if(t)return a.isLoading=!1,void U(null,t,e);var i=n;(!(r=String(i.next))||r.length<=0)&&(a.hasNext=!1);var s=i.channels,o=[];for(var l in s){var u=w.upsert(s[l]);o.push(u)}a.isLoading=!1,U(o,null,e)})}};Q.ORDER_LATEST_LAST_MESSAGE="latest_last_message",Q.ORDER_CHRONOLOGICAL="chronological",Q.CHANNEL_NAME_ALPHABETICAL="channel_name_alphabetical",Q.MEMBER_STATE_INVITED_ONLY="invited_only",Q.MEMBER_STATE_JOINED_ONLY="joined_only",Q.MEMBER_STATE_ALL="all";var x=function(){var e="";this.isLoading=!1,this.hasNext=!0,this.limit=20,this.includeEmpty=!0,this.order=x.ORDER_CHRONOLOGICAL,this.channelNameContainsFilter=null,this.channelUrlsFilter=[],this.customTypesFilter=[],this.customTypeStartsWithFilter=null,this.superChannelFilter=w.superChannelFilter.ALL,this.membershipFilter=x.MEMBERSHIP_TYPE.JOINED;var n=this;this.next=function(t){return ae.getInstance().hasLoggedIn()?n.hasNext?n.isLoading?void U(null,new _("Query in progress.",J.QUERY_IN_PROGRESS),t):!h(n.limit)||"boolean"!=typeof n.includeEmpty||!Array.isArray(n.customTypesFilter)||!Array.isArray(n.channelUrlsFilter)||null!==n.channelNameContainsFilter&&"string"!=typeof n.channelNameContainsFilter||null!==n.customTypeStartsWithFilter&&"string"!=typeof n.customTypeStartsWithFilter||"string"!=typeof n.order||[x.ORDER_CHRONOLOGICAL,x.ORDER_LATEST_LAST_MESSAGE,x.CHANNEL_NAME_ALPHABETICAL].indexOf(n.order.toLowerCase())<0?void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),t):"string"!=typeof n.superChannelFilter||[w.superChannelFilter.ALL,w.superChannelFilter.SUPER,w.superChannelFilter.NON_SUPER].indexOf(n.superChannelFilter.toLowerCase())<0||"string"!=typeof n.membershipFilter||[x.MEMBERSHIP_TYPE.ALL,x.MEMBERSHIP_TYPE.JOINED].indexOf(n.membershipFilter.toLowerCase())<0?void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),t):(n.isLoading=!0,void Z.getInstance().loadPublicGroupChannelList(e,n.limit,n.includeEmpty,n.order,n.channelNameContainsFilter,n.channelUrlsFilter,n.customTypesFilter,n.customTypeStartsWithFilter,n.superChannelFilter,n.membershipFilter,function(r,a){if(a)return n.isLoading=!1,void U(null,a,t);var i=r;(!(e=String(i.next))||e.length<=0)&&(n.hasNext=!1);var s=i.channels,o=[];for(var l in s){var u=w.upsert(s[l]);o.push(u)}n.isLoading=!1,U(o,null,t)})):void U([],null,t):void(t&&U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),t))}};x.ORDER_CHRONOLOGICAL="chronological",x.CHANNEL_NAME_ALPHABETICAL="channel_name_alphabetical",x.USER_IDS_INCLUDE_QUERY_TYPE={AND:"AND",OR:"OR"},x.MEMBERSHIP_TYPE={ALL:"all",JOINED:"joined"};var W=function(e){this.isLoading=!1;var n=e,t=this;this.next=function(e,r,a,i){if(t.isLoading)return void U(null,new _("Query in progress.",J.QUERY_IN_PROGRESS),i);if(4!==arguments.length){if("function"!=typeof i){var s=Array.prototype.slice.call(arguments);"function"==typeof s.slice(-1)[0]&&(i=s.pop())}return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),i)}if(!h(e)||!h(r)||"boolean"!=typeof a)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),i);t.isLoading=!0,Z.getInstance().messageList(n.isOpenChannel(),n.url,e,0,r,!1,a,"","",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=P.build(a[o],n);l&&s.push(l)}t.isLoading=!1,U(s,null,i)})},this.prev=function(e,r,a,i){if(t.isLoading)return void U(null,new _("Query in progress.",J.QUERY_IN_PROGRESS),i);if(4!==arguments.length){if("function"!=typeof i){var s=Array.prototype.slice.call(arguments);"function"==typeof s.slice(-1)[0]&&(i=s.pop())}return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),i)}if(!h(e)||!h(r)||"boolean"!=typeof a)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),i);t.isLoading=!0,Z.getInstance().messageList(n.isOpenChannel(),n.url,e,r,0,!1,a,"","",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=P.build(a[o],n);l&&s.push(l)}t.isLoading=!1,U(s,null,i)})},this.load=function(e,r,a,i,s){if(t.isLoading)return void U(null,new _("Query in progress.",J.QUERY_IN_PROGRESS),s);if(5!==arguments.length){if("function"!=typeof s){var o=Array.prototype.slice.call(arguments);"function"==typeof o.slice(-1)[0]&&(s=o.pop())}return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),s)}if(!h(e)||!h(r)||!h(a)||"boolean"!=typeof i)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),s);t.isLoading=!0,Z.getInstance().messageList(n.isOpenChannel(),n.url,e,r,a,!0,i,"","",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=P.build(a[o],n);l&&i.push(l)}t.isLoading=!1,U(i,null,s)})}},K=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 _("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||!h(n.limit)?void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),t):(n.isLoading=!0,void Z.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 i=r;try{e=String(i.next)}catch(n){e=""}e||(n.hasNext=!1);var s=i.channels,o=[];s.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,i,s){if(3!==arguments.length&&4!==arguments.length){if("function"!=typeof s){var o=Array.prototype.slice.call(arguments);"function"==typeof o.slice(-1)[0]&&(s=o.pop())}return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),s)}if("function"==typeof i&&(s=i,i=""),i.toString().toLowerCase()===P.MESSAGE_TYPE_ADMIN||i===E.MessageTypeFilter.ADMIN?i="ADMM":i.toString().toLowerCase()===P.MESSAGE_TYPE_USER||i===E.MessageTypeFilter.USER?i="MESG":i.toString().toLowerCase()===P.MESSAGE_TYPE_FILE||i===E.MessageTypeFilter.FILE?i="FILE":null!==i&&void 0!==i&&i!==E.MessageTypeFilter.ALL||(i=""),!h(e)||"boolean"!=typeof a||"string"!=typeof i)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),s);if(r.hasMore){if(r.isLoading)return void U(null,new _("Query in progress.",J.QUERY_IN_PROGRESS),s);r.isLoading=!0,Z.getInstance().messageList(n.isOpenChannel(),n.url,t,e,0,!1,a,i,"",function(a,i){if(i)return r.isLoading=!1,void U(null,i,s);var o=a.messages,l=[];for(var u in o){var c=P.build(o[u],n);c&&(l.push(c),c.createdAt<=t&&(t=c.createdAt))}(l.length<=0||l.length300?C(Z.API_ROUTING_URL.replace("%s",S),{},"GET",{SendBird:o+S},function(i,s){if(s)return void e(null,new _("Server is unreachable.",J.NETWORK_ROUTING_ERROR));r=i.ws_server,a=i.api_server,n=t,"function"==typeof e&&e({API_HOST:a,WS_HOST:r})}):e({API_HOST:ae.getInstance().getCurrentApiHost(),WS_HOST:ae.getInstance().getCurrentWsHost()},null)}};var t=function(e,n,t,r,a,i,l,u,d,h){if(!ae.getInstance().hasLoggedIn())return void(l&&l(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED)));Z.getInstance().checkRouting(function(n,I){if(I)l(null,new _("Request failed.",J.REQUEST_FAILED));else{var E=N();E.open("POST",n.API_HOST+e,!0),E.setRequestHeader("SendBird",o+S),E.setRequestHeader("Session-Key",Z.getInstance().sessionKey);var p=s?new s:new FormData;r&&"undefined"!=typeof Blob?p.append("file",new Blob([t],{type:r}),t.name):p.append("file",t,t.name),i&&p.append("channel_url",i);for(var f in a){var A=parseInt(f)+1;p.append("thumbnail"+A,a[f].maxWidth+","+a[f].maxHeight)}E.onload=function(){d&&d[h]&&delete d[h];E.status>=200&&E.status<400?c(null,JSON.parse(E.responseText),l):c({status:E.status,statusText:E.statusText,response:E.responseText},null,l)},E.onerror=function(e){d&&d[h]&&delete d[h],l(null,new _(E.statusText,J.REQUEST_FAILED))},E.onabort=function(e){d&&d[h]&&delete d[h],l(null,new _("File upload has been cancelled.",J.REQUEST_CANCELLED))},E.upload.onprogress=function(e){e.lengthComputable&&e.loaded>=e.total&&d&&d[h]&&delete d[h],u&&u(e)},p.oldIE?(E.setRequestHeader("Content-Type","multipart/form-data; boundary="+p.boundary),E.send(p.toString())):E.send(p),d&&(d[h]=E)}})},i=function(e,n,t){if("function"==typeof n&&(t=n,n={}),!ae.getInstance().hasLoggedIn())return void(t&&t(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED)));Z.getInstance().checkRouting(function(r,a){a?t(null,new _("Request failed.",J.REQUEST_FAILED)):C(r.API_HOST+e,n,"DELETE",{"Session-Key":Z.getInstance().sessionKey,SendBird:o+S},t)})},l=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={}),!ae.getInstance().hasLoggedIn())return void(t&&t(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED)));var r,a="";if(n){for(var i in n)""!==a&&(a+="&"),a+=i+"="+n[i];r=e+"?"+a}else r=e;Z.getInstance().checkRouting(function(e,a){a?t(null,new _("Request failed.",J.REQUEST_FAILED)):C(e.API_HOST+r,n,"GET",{"Session-Key":Z.getInstance().sessionKey,SendBird:o+S},t)})},h=function(e,n,t){if("function"==typeof n&&(t=n,n={}),!ae.getInstance().hasLoggedIn())return void(t&&t(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED)));Z.getInstance().checkRouting(function(r,a){a?t(null,a):C(r.API_HOST+e,n,"POST",{"Session-Key":Z.getInstance().sessionKey,SendBird:o+S},t)})},I=function(e,n,t){if("function"==typeof n&&(t=n,n={}),!ae.getInstance().hasLoggedIn())return void(t&&t(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED)));Z.getInstance().checkRouting(function(r,a){a||C(r.API_HOST+e,n,"PUT",{"Session-Key":Z.getInstance().sessionKey,SendBird:o+S},t)})};this.addFriends=function(e,n,t){var r=Z.API_FRIENDS.replace("%s",encodeURIComponent(e));h(r,{user_ids:n},t)},this.deleteFriends=function(e,n,t){var r=Z.API_FRIENDS.replace("%s",encodeURIComponent(e));n.length>0&&(r+="?user_ids=",n.forEach(function(e){r+=encodeURIComponent(e)+","}),r=r.substring(0,r.length-1)),i(r,{},t)},this.deleteFriendDiscoveries=function(e,n,t){var r=Z.API_FRIENDS_DISCOVERIES.replace("%s",encodeURIComponent(e));n.length>0&&(r+="?friend_discovery_keys=",n.forEach(function(e){r+=encodeURIComponent(e)+","}),r=r.substring(0,r.length-1)),i(r,{},t)},this.uploadFriendDiscoveries=function(e,n,t){var r=Z.API_FRIENDS_DISCOVERIES.replace("%s",encodeURIComponent(e)),a={friend_discoveries:[]};n.forEach(function(e){a.friend_discoveries.push({friend_discovery_key:e.friendDiscoveryKey,friend_name:"string"==typeof e.friendName||e.friendName?e.friendName:null})}),I(r,a,t)},this.getFriendChangeLogsByToken=function(e,n,t){var r=Z.API_FRIENDS_CHANGE_LOGS.replace("%s",encodeURIComponent(e)),a={};n&&(a.token=n),u(r,a,t)},this.friendListQuery=function(e,n,t,r){var a=Z.API_FRIENDS.replace("%s",encodeURIComponent(e)),i={limit:t,token:encodeURIComponent(n)};u(a,i,r)},this.createUserMetaData=function(e,n,t){var r=Z.API_USERS_USERID_METADATA.replace("%s",encodeURIComponent(e)),a={};a.metadata=n,h(r,a,t)},this.updateUserMetaData=function(e,n,t,r){var a=Z.API_USERS_USERID_METADATA.replace("%s",encodeURIComponent(e)),i={};i.metadata=n,i.upsert=t,I(a,i,r)},this.deleteAllUserMetaData=function(e,n){var t=Z.API_USERS_USERID_METADATA.replace("%s",encodeURIComponent(e));i(t,{},n)},this.deleteUserMetaData=function(e,n,t){var r=Z.API_USERS_USERID_METADATA_KEY.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));i(r,{},t)},this.resetMyHistory=function(e,n){var t=Z.API_GROUPCHANNELS_RESET_USER_HISTORY.replace("%s",encodeURIComponent(e));I(t,{},n)},this.groupChannelInvite=function(e,n,t){var r=Z.API_GROUPCHANNELS_CHANNELURL_INVITE.replace("%s",encodeURIComponent(e)),a={},i=[];try{Array.isArray(n)?i=n:i.push(n)}catch(e){t(null,new _("Invalid parameter.",J.INVALID_PARAMETER))}a.user_ids=i,h(r,a,t)},this.acceptInvitation=function(e,n,t){var r=Z.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=Z.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=Z.API_GROUPCHANNELS_CHANNELURL_HIDE.replace("%s",encodeURIComponent(e)),i={};i.user_id=n,i.hide_previous_messages=t,I(a,i,r)},this.publicGroupChannelJoin=function(e,n,t){var r=Z.API_GROUPCHANNELS_CHANNELURL_JOIN.replace("%s",encodeURIComponent(e)),a={};a.user_id=n,I(r,a,t)},this.groupChannelLeave=function(e,n,t){var r=Z.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=Z.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MARKASREAD.replace("%s",encodeURIComponent(e)),a={};a.user_id=n,I(r,a,t)},this.groupChannelMarkAsReadAll=function(e,n,t){var r=Z.API_USERS_USERID_MARKASREADALL.replace("%s",encodeURIComponent(e)),a={};n&&(a.channel_urls=n),I(r,a,t)},this.messageList=function(e,n,t,r,a,i,s,o,l,c){var d;d=e?String(Z.API_OPENCHANNELS_CHANNELURL_MESSAGES.replace("%s",n)):String(Z.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(i),h.reverse=String(s),o&&(h.message_type=String(o)),l&&(h.custom_type=String(l)),u(d,h,c)},this.messageListByID=function(e,n,t,r,a,i,s,o,l,c){var d;d=e?String(Z.API_OPENCHANNELS_CHANNELURL_MESSAGES.replace("%s",n)):String(Z.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(i),h.reverse=String(s),o&&(h.message_type=String(o)),l&&(h.custom_type=String(l)),u(d,h,c)},this.login=function(e,n,t){var r=Z.API_USERS_USERID_LOGIN.replace("%s",encodeURIComponent(e)),a={};a.app_id=S,n&&(a.access_token=n),h(r,a,function(e,n){n?t(null,n):(Z.getInstance().sessionKey=e.key,Z.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 i=String(Z.API_USERS_USERID).replace("%s",encodeURIComponent(e));I(i,a,r)},this.updateCurrentUserInfoWithFile=function(e,n,t,r){if("string"==typeof t)this.updateUserInfo(e,n,t,r);else{var a=s?new s:new FormData;a.append("nickname",n),a.append("profile_file",t,t.name);var i=String(Z.API_USERS_USERID).replace("%s",encodeURIComponent(e));I(i,a,r)}},this.getGroupChannel=function(e,n,t,r){var a=Z.API_GROUPCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)),i={member:String(n),read_receipt:String(t)};u(a,i,r)},this.getOpenChannel=function(e,n){var t=Z.API_OPENCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e));u(t,n)},this.createGroupChannel=function(e,n,t,r,a,i,o,l,u,c,d){var I=Z.API_GROUPCHANNELS,_=[];"string"==typeof e?_.push(e):e.forEach(function(e){_.push(e)});var E,p=_.filter(function(e,n){return _.indexOf(e)===n}),f=l.isPublic,A=l.channelUrl;r&&"string"!=typeof r?(E=s?new s:new FormData,r&&E.append("cover_file",r,r.name),E.append("user_ids",p),null!==A&&E.append("channel_url",A),null!==n&&E.append("is_distinct",n),null!==o&&E.append("is_super",o),null!==f&&E.append("is_public",f),null!==c&&E.append("is_ephemeral",c),null!==t&&"string"==typeof t&&E.append("name",t),a&&E.append("data",a),i&&E.append("custom_type",i),Array.isArray(u)&&u.length>0&&E.append("operator_ids",u)):(E={},null!==r&&"string"==typeof r&&(E.cover_url=r),E.user_ids=p,null!==A&&(E.channel_url=A),null!==n&&(E.is_distinct=n),null!==o&&(E.is_super=o),null!==f&&(E.is_public=f),null!==c&&(E.is_ephemeral=c),null!==t&&"string"==typeof t&&(E.name=t),a&&(E.data=a),i&&(E.custom_type=i),Array.isArray(u)&&u.length>0&&(E.operator_ids=u)),h(I,E,d)},this.createOpenChannel=function(e,n,t,r,a,i){var o,l=String(Z.API_OPENCHANNELS);n&&"string"!=typeof n?(o=s?new s:new FormData,n&&o.append("cover_file",n,n.name),null!==e&&"string"==typeof e&&o.append("name",e),t&&o.append("data",t),r&&(Array.isArray(r)?o.append("operators",r):o.append("operators",[r])),a&&o.append("custom_type",a)):(o={},null!==n&&"string"==typeof n&&(o.cover_url=n),null!==e&&"string"==typeof e&&(o.name=e),t&&(o.data=t),r&&(Array.isArray(r)?o.operators=r:o.operators=[r]),a&&(o.custom_type=a)),h(l,o,i)},this.updateGroupChannel=function(e,n,t,r,a,i,o,l){var u,c=String(Z.API_GROUPCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)));r&&"string"!=typeof r?(u=s?new s:new FormData,null!==n&&u.append("is_distinct",n),null!==o&&u.append("is_public",o),r&&u.append("cover_file",r,r.name),null!==t&&"string"==typeof t&&u.append("name",t),null!==a&&"string"==typeof a&&u.append("data",a),null!==i&&"string"==typeof i&&u.append("custom_type",i)):(u={},null!==n&&(u.is_distinct=n),null!==o&&(u.is_public=o),null!==r&&"string"==typeof r&&(u.cover_url=r),null!==t&&"string"==typeof t&&(u.name=t),null!==a&&"string"==typeof a&&(u.data=a),null!==i&&"string"==typeof i&&(u.custom_type=i)),I(c,u,l)},this.updateOpenChannel=function(e,n,t,r,a,i,o){var l,u=String(Z.API_OPENCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)));t&&"string"!=typeof t?(l=s?new s: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!==i&&"string"==typeof i&&l.append("custom_type",i)):(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!==i&&"string"==typeof i&&(l.custom_type=i)),I(u,l,o)},this.deleteOpenChannel=function(e,n){var t=String(Z.API_OPENCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)));i(t,{},n)},this.createMetaCounters=function(e,n,t,r){var a;a=e?Z.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):Z.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n));var i={};i.metacounter=t,h(a,i,r)},this.updateMetaCounters=function(e,n,t,r,a,i){var s;s=e?Z.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):Z.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n));var o={};switch(o.metacounter=t,o.upsert=r,a){case Z.UPDATE_META_COUNTER_MODE_SET:o.mode="set";break;case Z.UPDATE_META_COUNTER_MODE_INC:o.mode="increase";break;case Z.UPDATE_META_COUNTER_MODE_DEC:o.mode="decrease"}I(s,o,i)},this.getAllMetaCounters=function(e,n,t){this.getMetaCounters(e,n,{},t)},this.getMetaCounters=function(e,n,t,r){var a;a=e?Z.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):Z.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n));var i=l(t);u(a,{keys:i},r)},this.deleteMetaCounter=function(e,n,t,r){var a="";a=e?Z.API_OPENCHANNELS_CHANNELURL_METACOUNTER_KEY.replace("%s",encodeURIComponent(n)).replace("%s",t):Z.API_GROUPCHANNELS_CHANNELURL_METACOUNTER_KEY.replace("%s",encodeURIComponent(n)).replace("%s",t),i(a,{},r)},this.deleteAllMetaCounters=function(e,n,t){var r="";r=e?Z.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):Z.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)),i(r,{},t)},this.createMetaData=function(e,n,t,r){var a="";a=e?Z.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):Z.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n));var i={},s={};for(var o in t){var l=t[o];s[o]=l}i.metadata=s,h(a,i,r)},this.updateMetaData=function(e,n,t,r,a){var i="";i=e?Z.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):Z.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n));var s={},o={};for(var l in t){var u=t[l];o[l]=u}s.metadata=o,s.upsert=r,I(i,s,a)},this.getAllMetaData=function(e,n,t){this.getMetaData(e,n,{},t)},this.getMetaData=function(e,n,t,r){var a="";a=e?Z.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):Z.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n));var i=l(t);u(a,{keys:i},r)},this.deleteMetaData=function(e,n,t,r){var a="";a=e?Z.API_OPENCHANNELS_CHANNELURL_METADATA_KEY.replace("%s",encodeURIComponent(n)).replace("%s",t):Z.API_GROUPCHANNELS_CHANNELURL_METADATA_KEY.replace("%s",encodeURIComponent(n)).replace("%s",t),i(a,{},r)},this.deleteAllMetaData=function(e,n,t){var r="";r=e?Z.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):Z.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)),i(r,{},t)},this.loadUserList=function(e,n,t,r,a,i){var s=Z.API_USERS,o={token:encodeURIComponent(e),limit:String(n)};if(!d(t))try{var l="";for(var c in t){var h=t[c];l+=encodeURIComponent(h)+","}l.length>1&&(l=l.substring(0,l.length-1)),o.user_ids=l}catch(e){}if(r&&!d(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(s,o,i)},this.loadBlockedUserList=function(e,n,t,r){var a=Z.API_USERS_USERID_BLOCK.replace("%s",encodeURIComponent(e)),i={token:encodeURIComponent(n),limit:String(t)};u(a,i,r)},this.loadOpenChannelList=function(e,n,t,r,a,i){var s=Z.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(s,o,i)},this.uploadFile=function(e,n,r,a,i,s,o,l){t(Z.API_STORAGE_FILE,0,e,n,r,a,i,s,o,l)},this.uploadProfileImage=function(e,n){t(Z.API_STORAGE_PROFILE,0,e,"",[],"",n)},this.loadGroupChannelMemberList=function(e,n,t,r,a,i){var s=Z.API_GROUPCHANNELS_MEMBERS.replace("%url",encodeURIComponent(e)),o={token:encodeURIComponent(n),limit:t,muted_member_filter:r.toLowerCase(),operator_filter:a.toLowerCase()};u(s,o,i)},this.loadPublicGroupChannelList=function(e,n,t,r,a,i,s,o,l,c,d){var h=Z.API_GROUPCHANNELS,I={public_mode:w.publicChannelFilter.PUBLIC,token:encodeURIComponent(e),limit:String(n),show_member:!0,show_read_receipt:!0,show_empty:String(t),order:r};if(a)try{I.name_contains=encodeURIComponent(a)}catch(e){}if(i.length>0)try{I.channel_urls=i.map(function(e){return encodeURIComponent(e)}).join(",")}catch(e){}if(s.length>0){var _="";s.forEach(function(e){_+=encodeURIComponent(e)+","}),_=_.substring(0,_.length-1),I.custom_types=_}o&&(I.custom_type_startswith=o),I.super_mode=l,I.public_membership_mode=c,u(h,I,d)},this.loadUserGroupChannelList=function(e,n,t,r,a,i,s,o,c,d,h,I,_,E,p,f){var A=Z.API_MYGROUPCHANNELS.replace("%s",encodeURIComponent(e)),g=i.userIds,m=!i.includeMode,v=i.queryType,N={token:encodeURIComponent(n),limit:String(t),show_member:!0,show_read_receipt:!0,show_empty:String(r),order:a,member_state_filter:_};if(h.length>0){var C="";h.forEach(function(e){C+=encodeURIComponent(e)+","}), -C=C.substring(0,C.length-1),N.custom_types=C}else d&&(N.custom_type=encodeURIComponent(d));if(s)try{N.members_nickname_contains=encodeURIComponent(s)}catch(e){}if(o)try{N.name_contains=encodeURIComponent(o)}catch(e){}if(g.length>0)try{m?N.members_exactly_in=l(g):(N.members_include_in=l(g),N.query_type=v)}catch(e){}if(c.length>0)try{N.channel_urls=c.map(function(e){return encodeURIComponent(e)}).join(",")}catch(e){}N.super_mode=E,N.public_mode=p,I&&(N.custom_type_startswith=I),u(A,N,f)},this.loadOpenChannelParticipantList=function(e,n,t,r){var a=Z.API_OPENCHANNELS_CHANNELURL_PARTICIPANTS.replace("%s",e),i={token:encodeURIComponent(n),limit:String(t)};u(a,i,r)},this.loadMutedUserList=function(e,n,t,r){var a=e.isOpenChannel()?Z.API_OPENCHANNELS_CHANNELURL_MUTE.replace("%s",e.url):Z.API_GROUPCHANNELS_CHANNELURL_MUTE.replace("%s",e.url),i={token:encodeURIComponent(n),limit:String(t)};u(a,i,r)},this.loadBannedUserList=function(e,n,t,r){var a=e.isOpenChannel()?Z.API_OPENCHANNELS_CHANNELURL_BAN.replace("%s",e.url):Z.API_GROUPCHANNELS_CHANNELURL_BAN.replace("%s",e.url),i={token:encodeURIComponent(n),limit:String(t)};u(a,i,r)},this.setPushTemplate=function(e,n,t){var r=Z.API_USERS_USERID_PUSH_TEMPLATE.replace("%s",encodeURIComponent(e));I(r,{name:n},t)},this.getPushTemplate=function(e,n){var t=Z.API_USERS_USERID_PUSH_TEMPLATE.replace("%s",encodeURIComponent(e));u(t,n)},this.setDoNotDisturb=function(e,n,t,r,a,i,s,o){var l=Z.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:i,timezone:s},o)},this.getDoNotDisturb=function(e,n){var t=Z.API_USERS_USERID_PUSHPREFERENCE.replace("%s",encodeURIComponent(e));u(t,n)},this.setPushPreference=function(e,n,t,r){var a=Z.API_USERS_USERID_PUSHPREFERENCE_CHANNELURL.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n)),i={};i.enable=t,I(a,i,r)},this.getPushPreference=function(e,n,t){var r=Z.API_USERS_USERID_PUSHPREFERENCE_CHANNELURL.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));u(r,t)},this.registerGCMPushToken=function(e,n,t){var r=Z.API_USERS_USERID_PUSH_GCM.replace("%s",encodeURIComponent(e));h(r,{gcm_reg_token:n},t)},this.unregisterGCMPushToken=function(e,n,t){var r=Z.API_USERS_USERID_PUSH_GCM_TOKEN.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));i(r,t)},this.unregisterGCMPushTokenAll=function(e,n){var t=Z.API_USERS_USERID_PUSH_GCM.replace("%s",encodeURIComponent(e));i(t,n)},this.registerAPNSPushToken=function(e,n,t){var r=Z.API_USERS_USERID_PUSH_APNS.replace("%s",encodeURIComponent(e));h(r,{apns_device_token:n},t)},this.unregisterAPNSPushToken=function(e,n,t){var r=Z.API_USERS_USERID_PUSH_APNS_TOKEN.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));i(r,t)},this.unregisterAPNSPushTokenAll=function(e,n){var t=Z.API_USERS_USERID_PUSH_APNS.replace("%s",encodeURIComponent(e));i(t,n)},this.unregisterPushTokenAll=function(e,n){var t=Z.API_USERS_USERID_PUSH.replace("%s",encodeURIComponent(e));i(t,n)},this.blockUser=function(e,n,t){var r=Z.API_USERS_USERID_BLOCK.replace("%s",encodeURIComponent(e));h(r,{target_id:n},t)},this.unblockUser=function(e,n,t){var r=Z.API_USERS_USERID_BLOCK_TARGETID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));i(r,{},t)},this.banUser=function(e,n,t,r,a,i){var s=a?Z.API_GROUPCHANNELS_CHANNELURL_BAN.replace("%s",encodeURIComponent(e)):Z.API_OPENCHANNELS_CHANNELURL_BAN.replace("%s",encodeURIComponent(e)),o={user_id:n};t&&(o.description=t),o.seconds=String(r),h(s,o,i)},this.unbanUser=function(e,n,t,r){var a=t?Z.API_GROUPCHANNELS_CHANNELURL_BAN_USERID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n)):Z.API_OPENCHANNELS_CHANNELURL_BAN_USERID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));i(a,{},r)},this.muteUser=function(e,n,t,r){var a=t?Z.API_GROUPCHANNELS_CHANNELURL_MUTE.replace("%s",encodeURIComponent(e)):Z.API_OPENCHANNELS_CHANNELURL_MUTE.replace("%s",encodeURIComponent(e));h(a,{user_id:n},r)},this.unmuteUser=function(e,n,t,r){var a=t?Z.API_GROUPCHANNELS_CHANNELURL_MUTE_USERID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n)):Z.API_OPENCHANNELS_CHANNELURL_MUTE_USERID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));i(a,{},r)},this.deleteMessage=function(e,n,t,r){var a="";a=e?Z.API_OPENCHANNELS_CHANNELURL_MESSAGES_MESSAGEID.replace("%s",encodeURIComponent(n)).replace("%s",encodeURIComponent(t)):Z.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MESSAGEID.replace("%s",encodeURIComponent(n)).replace("%s",encodeURIComponent(t)),i(a,{},r)},this.freeze=function(e,n,t,r){var a=n?Z.API_GROUPCHANNELS_CHANNELURL_FREEZE.replace("%s",encodeURIComponent(e)):Z.API_OPENCHANNELS_CHANNELURL_FREEZE.replace("%s",encodeURIComponent(e));I(a,{freeze:t},r)}},X=null;Z.getInstance=function(){return null===X?null:X},Z.API_VERSION="v3",Z.API_ROUTING_URL="https://api-p.sendbird.com/routing/%s",Z.API_USERS="/%v/users".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_LOGIN="/%v/users/%s/login".replace("%v",Z.API_VERSION),Z.API_USERS_USERID="/%v/users/%s".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_METADATA="/%v/users/%s/metadata".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_METADATA_KEY="/%v/users/%s/metadata/%s".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_UNREAD_MESSAGE_COUNT="/%v/users/%s/unread_message_count".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_UNREAD_CHANNEL_COUNT="/%v/users/%s/unread_channel_count".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_MARKASREADALL="/%v/users/%s/mark_as_read_all".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_PUSH_GCM_TOKEN="/%v/users/%s/push/gcm/%s".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_PUSH_GCM="/%v/users/%s/push/gcm".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_PUSHPREFERENCE_CHANNELURL="/%v/users/%s/push_preference/%s".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_PUSHPREFERENCE="/%v/users/%s/push_preference/".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_PUSH_TEMPLATE="/%v/users/%s/push/template".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_BLOCK="/%v/users/%s/block".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_BLOCK_TARGETID="/%v/users/%s/block/%s".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_PUSH_APNS_TOKEN="/%v/users/%s/push/apns/%s".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_PUSH_APNS="/%v/users/%s/push/apns".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_PUSH="/%v/users/%s/push".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_GROUP_CHANNEL_INVITATION_PREFERENCE="/%v/users/%s/channel_invitation_preference".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_GROUP_CHANNEL_COUNT="/%v/users/%s/group_channel_count".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS="/%v/open_channels".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL="/%v/open_channels/%s".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_MESSAGES="/%v/open_channels/%s/messages".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_MESSAGES_MESSAGEID="/%v/open_channels/%s/messages/%s".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_PARTICIPANTS="/%v/open_channels/%s/participants".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_METADATA="/%v/open_channels/%s/metadata".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_METADATA_KEY="/%v/open_channels/%s/metadata/%s".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_METACOUNTER="/%v/open_channels/%s/metacounter".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_METACOUNTER_KEY="/%v/open_channels/%s/metacounter/%s".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_BAN="/%v/open_channels/%s/ban".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_BAN_USERID="/%v/open_channels/%s/ban/%s".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_MUTE="/%v/open_channels/%s/mute".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_MUTE_USERID="/%v/open_channels/%s/mute/%s".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_FREEZE="/%v/open_channels/%s/freeze".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS="/%v/group_channels".replace("%v",Z.API_VERSION),Z.API_MYGROUPCHANNELS="/%v/users/%s/my_group_channels".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL="/%v/group_channels/%s".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_INVITE="/%v/group_channels/%s/invite".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_ACCEPT_INVITATION="/%v/group_channels/%s/accept".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_DECLINE_INVITATION="/%v/group_channels/%s/decline".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_HIDE="/%v/group_channels/%s/hide".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_LEAVE="/%v/group_channels/%s/leave".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_JOIN="/%v/group_channels/%s/join".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_MESSAGES="/%v/group_channels/%s/messages".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MARKASREAD="/%v/group_channels/%s/messages/mark_as_read".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_MESSAGES_TOTALCOUNT="/%v/group_channels/%s/messages/total_count".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_MESSAGES_UNREADCOUNT="/%v/group_channels/%s/messages/unread_count".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MESSAGEID="/%v/group_channels/%s/messages/%s".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_MEMBERS="/%v/group_channels/%s/members".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_METADATA="/%v/group_channels/%s/metadata".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_METADATA_KEY="/%v/group_channels/%s/metadata/%s".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_METACOUNTER="/%v/group_channels/%s/metacounter".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_METACOUNTER_KEY="/%v/group_channels/%s/metacounter/%s".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_RESET_USER_HISTORY="/%v/group_channels/%s/reset_user_history".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_MEMBERS="/%v/group_channels/%url/members".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_BAN="/%v/group_channels/%s/ban".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_BAN_USERID="/%v/group_channels/%s/ban/%s".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_MUTE="/%v/group_channels/%s/mute".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_MUTE_USERID="/%v/group_channels/%s/mute/%s".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_FREEZE="/%v/group_channels/%s/freeze".replace("%v",Z.API_VERSION),Z.API_STORAGE_FILE="/%v/storage/file".replace("%v",Z.API_VERSION),Z.API_STORAGE_PROFILE="/%v/storage/profile_image".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_MESSAGES_CHANGELOGS="/%v/open_channels/%s/messages/changelogs".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_MESSAGES_CHANGELOGS="/%v/group_channels/%s/messages/changelogs".replace("%v",Z.API_VERSION),Z.API_FRIENDS="/%v/users/%s/friends".replace("%v",Z.API_VERSION),Z.API_FRIENDS_CHANGE_LOGS="/%v/users/%s/friends/changelogs".replace("%v",Z.API_VERSION),Z.API_FRIENDS_DISCOVERIES="/%v/users/%s/friend_discoveries".replace("%v",Z.API_VERSION),Z.UPDATE_META_COUNTER_MODE_SET=0,Z.UPDATE_META_COUNTER_MODE_INC=1,Z.UPDATE_META_COUNTER_MODE_DEC=2;var $=function(){var e="";this.isLoading=!1,this.hasMore=!0,this.limit=20;var n=this;this.next=function(t){if(!h(n.limit))return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),t);if(n.hasMore){if(n.isLoading)return void U(null,new _("Query in progress.",J.QUERY_IN_PROGRESS),t);n.isLoading=!0,Z.getInstance().friendListQuery(ae.getInstance().getCurrentUserId(),e,n.limit,function(r,a){if(a)return n.isLoading=!1,void U(null,a,t);var i=r.users,s=i.map(function(e){return new G(e)});n.hasMore=r.has_more,n.isLoading=!1,e=r.next,U(s,null,t)})}}},ee=function(e,n,t,r){u?this[t]=e[n]:Object.defineProperty(e,t,{get:function(){return"_coverUrl"===n||"_coverImage"===n?e._channelCover:e[n]},set:function(t){if("file"===r){if("string"==typeof t||"object"!=typeof t)throw new _("Invalid parameter.",J.INVALID_PARAMETER)}else if(r&&typeof t!==r)throw new _("Invalid parameter.",J.INVALID_PARAMETER);e[n]=t,"_coverUrl"!==n&&"_coverImage"!==n||(e._channelCover=t)}})},ne=function(){this._isDistinct=null,ee(this,"_isDistinct","isDistinct","boolean"),this._isSuper=null,ee(this,"_isSuper","isSuper","boolean"),this._isPublic=null,ee(this,"_isPublic","isPublic","boolean"),this._channelUrl=null,ee(this,"_channelUrl","channelUrl","string"),this._name=null,ee(this,"_name","name","string"),this._data=null,ee(this,"_data","data","string"),this._customType=null,ee(this,"_customType","customType","string"),this._channelCover=null,ee(this,"_channelCover","channelCover",null),this._coverUrl=null,ee(this,"_coverUrl","coverUrl","string"),this._coverImage=null,ee(this,"_coverImage","coverImage","file"),this._operatorIds=[],this._operators=null,u?this.operators=this._operators:Object.defineProperty(this,"operators",{get:function(){return this._operators},set:function(e){if(!Array.isArray(e))throw new _("Invalid parameter.",J.INVALID_PARAMETER);for(var n=[],t=0;t0){e.unreadMessageCount=0;for(var r in ae.getInstance().channelHandlers){var i=ae.getInstance().channelHandlers[r];i.onChannelChanged(e)}}}else if(0===e.unreadMessageCount)for(var r in ae.getInstance().channelHandlers){var i=ae.getInstance().channelHandlers[r];i.onChannelChanged(e)}}else{e.updateReadReceipt(p.reader.userId,p.timestamp);for(var r in ae.getInstance().channelHandlers){var i=ae.getInstance().channelHandlers[r];i.onReadReceiptUpdated(e)}}});break;case"TPST":case"TPEN":case"MTIO":break;case"SYEV":c(t);break;case"USEV":u(t);break;case"DELM":var f=t.getJsonElement(),A=String(f.channel_type),g=String(f.channel_url),m=String(f.msg_id);switch(A){case M.CHANNEL_TYPE_OPEN:b.getChannel(g,function(e,t){if(R){var r=e;e=t,t=r}if(t)return void n.log("Discard a command.");for(var a in ae.getInstance().channelHandlers){ae.getInstance().channelHandlers[a].onMessageDeleted(e,m)}});break;case M.CHANNEL_TYPE_GROUP:w.getChannel(g,function(e,t){if(R){var r=e;e=t,t=r}if(t)return void n.log("Discard a command.");for(var a in ae.getInstance().channelHandlers){ae.getInstance().channelHandlers[a].onMessageDeleted(e,m)}})}}},u=function(e){var n=new H(e.getJsonElement());switch(n.category){case k.CATEGORY_USER_BLOCK:case k.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{ae.getInstance().getCurrentUserId()===t?a.memberMap[r].isBlockedByMe=n.category===k.CATEGORY_USER_BLOCK:ae.getInstance().getCurrentUserId()===r&&(a.memberMap[t].isBlockingMe=n.category===k.CATEGORY_USER_BLOCK)}catch(e){}});break;case k.CATEGORY_FRIEND_DISCOVERED:var a=n.data.friend_discoveries,i=a.map(function(e){return new G(e)});for(var s in ae.getInstance().userEventHandlers){ae.getInstance().userEventHandlers[s].onFriendsDiscovered(i)}}},c=function(e){var t=new H(e.getJsonElement());switch(t.category){case H.CATEGORY_CHANNEL_JOIN:case H.CATEGORY_CHANNEL_LEAVE:w.getChannel(t.channelUrl,function(r,a){if(R){var i=r;r=a,a=i}if(a)return void n.log("Discard a command: "+e.command+":"+t.category);var s=new G(t.data);if(t.category===H.CATEGORY_CHANNEL_JOIN){t.data.state=V.JOINED,r.addMember(new V(t.data)),s.userId===ae.getInstance().getCurrentUserId()&&(r.myMemberState="joined",w.cachedChannels[r.url]=r);for(var o in ae.getInstance().channelHandlers){var l=ae.getInstance().channelHandlers[o];l.onUserJoined(r,s)}}else{s.userId===ae.getInstance().getCurrentUserId()&&(r.isPublic||w.removeCachedChannel(t.channelUrl));r.removeMember(s);r.myMemberState="none",w.cachedChannels[r.url]=r;for(var o in ae.getInstance().channelHandlers){var l=ae.getInstance().channelHandlers[o];l.onUserLeft(r,s)}}});break;case H.CATEGORY_CHANNEL_INVITE:w.getChannel(t.channelUrl,function(r,a){if(R){var i=r;r=a,a=i}if(a)return void n.log("Discard a command: "+e.command+":"+t.category);var s=null;t.data&&t.data.inviter&&!d(t.data.inviter)&&(s=new G(t.data.inviter));var o=[];for(var l in t.data.invitees){t.data.invitees[l].state=V.INVITED;var u=new V(t.data.invitees[l]);o.push(u),r.addMember(u),u.userId===ae.getInstance().getCurrentUserId()&&(r.isHidden=!1,"joined"!==r.myMemberState&&(r.myMemberState="invited"),w.cachedChannels[r.url]=r)}for(var l in ae.getInstance().channelHandlers){ae.getInstance().channelHandlers[l].onUserReceivedInvitation(r,s,o)}});break;case H.CATEGORY_CHANNEL_DECLINE_INVITE:w.getChannel(t.channelUrl,function(r,a){if(R){var i=r;r=a,a=i}if(a)return void n.log("Discard a command: "+e.command+":"+t.category);var s=null;t.data&&t.data.inviter&&!d(t.data.inviter)&&(s=new G(t.data.inviter));var o=new G(t.data.invitee);o.userId===ae.getInstance().getCurrentUserId()&&(r.isPublic||w.removeCachedChannel(t.channelUrl)),r.removeMember(o),r.myMemberState="none",w.cachedChannels[r.url]=r;for(var l in ae.getInstance().channelHandlers){ae.getInstance().channelHandlers[l].onUserDeclinedInvitation(r,s,o)}});break;case H.CATEGORY_TYPING_START:case H.CATEGORY_TYPING_END:w.getChannel(t.channelUrl,function(r,a){if(R){var i=r;r=a,a=i}if(a)return void n.log("Discard a command: "+e.command+":"+t.category);var s=new G(t.data);t.category===H.CATEGORY_TYPING_START?r.updateTypingStatus(s,!0):r.updateTypingStatus(s,!1);for(var o in ae.getInstance().channelHandlers){ae.getInstance().channelHandlers[o].onTypingStatusUpdated(r)}});break;case H.CATEGORY_CHANNEL_ENTER:case H.CATEGORY_CHANNEL_EXIT:b.getChannel(t.channelUrl,function(r,a){if(R){var i=r;r=a,a=i}if(a)return void n.log("Discard a command: "+e.command+":"+t.category);t.data.hasOwnProperty("participant_count")&&(r.participantCount=t.data.participant_count);var s=new G(t.data);if(t.category===H.CATEGORY_CHANNEL_ENTER)for(var o in ae.getInstance().channelHandlers){var l=ae.getInstance().channelHandlers[o];l.onUserEntered(r,s) -}else for(var o in ae.getInstance().channelHandlers){var l=ae.getInstance().channelHandlers[o];l.onUserExited(r,s)}});break;case H.CATEGORY_USER_CHANNEL_MUTE:case H.CATEGORY_USER_CHANNEL_UNMUTE:t.isOpenChannel()?b.getChannel(t.channelUrl,function(r,a){if(R){var i=r;r=a,a=i}if(a)return void n.log("Discard a command: "+e.command+":"+t.category);var s=new G(t.data);if(t.category===H.CATEGORY_USER_CHANNEL_MUTE)for(var o in ae.getInstance().channelHandlers){var l=ae.getInstance().channelHandlers[o];l.onUserMuted(r,s)}else for(var o in ae.getInstance().channelHandlers){var l=ae.getInstance().channelHandlers[o];l.onUserUnmuted(r,s)}}):w.getChannel(t.channelUrl,function(r,a){if(R){var i=r;r=a,a=i}if(a)return void n.log("Discard a command: "+e.command+":"+t.category);var s=new G(t.data);if(t.category===H.CATEGORY_USER_CHANNEL_MUTE)for(var o in ae.getInstance().channelHandlers){var l=ae.getInstance().channelHandlers[o];l.onUserMuted(r,s)}else for(var o in ae.getInstance().channelHandlers){var l=ae.getInstance().channelHandlers[o];l.onUserUnmuted(r,s)}});break;case H.CATEGORY_USER_CHANNEL_BAN:case H.CATEGORY_USER_CHANNEL_UNBAN:t.isOpenChannel()?b.getChannel(t.channelUrl,function(r,a){if(R){var i=r;r=a,a=i}if(a)return void n.log("Discard a command: "+e.command+":"+t.category);var s=new G(t.data);if(t.category===H.CATEGORY_USER_CHANNEL_BAN)for(var o in ae.getInstance().channelHandlers){var l=ae.getInstance().channelHandlers[o];l.onUserBanned(r,s)}else for(var o in ae.getInstance().channelHandlers){var l=ae.getInstance().channelHandlers[o];l.onUserUnbanned(r,s)}}):w.getChannel(t.channelUrl,function(r,a){if(R){var i=r;r=a,a=i}if(a)return void n.log("Discard a command: "+e.command+":"+t.category);var s=new G(t.data);if(t.category===H.CATEGORY_USER_CHANNEL_BAN)for(var o in ae.getInstance().channelHandlers){var l=ae.getInstance().channelHandlers[o];l.onUserBanned(r,s)}else for(var o in ae.getInstance().channelHandlers){var l=ae.getInstance().channelHandlers[o];l.onUserUnbanned(r,s)}});break;case H.CATEGORY_CHANNEL_FREEZE:case H.CATEGORY_CHANNEL_UNFREEZE:t.isOpenChannel()?b.getChannel(t.channelUrl,function(r,a){if(R){var i=r;r=a,a=i}if(a)return void n.log("Discard a command: "+e.command+":"+t.category);if(r.isFrozen=t.data.freeze,b.cachedChannels[r.url]=r,t.category===H.CATEGORY_CHANNEL_FREEZE)for(var s in ae.getInstance().channelHandlers){var o=ae.getInstance().channelHandlers[s];o.onChannelFrozen(r)}else for(var s in ae.getInstance().channelHandlers){var o=ae.getInstance().channelHandlers[s];o.onChannelUnfrozen(r)}}):w.getChannel(t.channelUrl,function(r,a){if(R){var i=r;r=a,a=i}if(a)return void n.log("Discard a command: "+e.command+":"+t.category);if(r.isFrozen=t.data.freeze,w.cachedChannels[r.url]=r,t.category===H.CATEGORY_CHANNEL_FREEZE)for(var s in ae.getInstance().channelHandlers){var o=ae.getInstance().channelHandlers[s];o.onChannelFrozen(r)}else for(var s in ae.getInstance().channelHandlers){var o=ae.getInstance().channelHandlers[s];o.onChannelUnfrozen(r)}});break;case H.CATEGORY_CHANNEL_DELETED:if(t.isGroupChannel()){w.removeCachedChannel(t.channelUrl);for(var r in ae.getInstance().channelHandlers){var a=ae.getInstance().channelHandlers[r];a.onChannelDeleted(t.channelUrl,"group")}}else{b.removeCachedChannel(t.channelUrl);for(var r in ae.getInstance().channelHandlers){var a=ae.getInstance().channelHandlers[r];a.onChannelDeleted(t.channelUrl,"open")}}break;case H.CATEGORY_CHANNEL_PROP_CHANGED:t.isOpenChannel()?b.getChannelWithoutCache(t.channelUrl,function(r,a){if(R){var i=r;r=a,a=i}if(a)return void n.log("Discard a command: "+e.command+":"+t.category);for(var s in ae.getInstance().channelHandlers){ae.getInstance().channelHandlers[s].onChannelChanged(r)}}):w.getChannelWithoutCache(t.channelUrl,function(r,a){if(R){var i=r;r=a,a=i}if(a)return void n.log("Discard a command: "+e.command+":"+t.category);for(var s in ae.getInstance().channelHandlers){ae.getInstance().channelHandlers[s].onChannelChanged(r)}});break;case H.CATEGORY_CHANNEL_META_DATA_CHANGED:case H.CATEGORY_CHANNEL_META_COUNTERS_CHANGED:var i=t.data.hasOwnProperty("created"),s=t.data.hasOwnProperty("updated"),o=t.data.hasOwnProperty("deleted");t.isOpenChannel()?b.getChannel(t.channelUrl,function(r,a){if(R){var l=r;r=a,a=l}if(a)return void n.log("Discard a command: "+e.command+":"+t.category);for(var u in ae.getInstance().channelHandlers){var c=ae.getInstance().channelHandlers[u];t.category===H.CATEGORY_CHANNEL_META_DATA_CHANGED?(i&&c.onMetaDataCreated(r,t.data.created),s&&c.onMetaDataUpdated(r,t.data.updated),o&&c.onMetaDataDeleted(r,t.data.deleted)):(i&&c.onMetaCountersCreated(r,t.data.created),s&&c.onMetaCountersUpdated(r,t.data.updated),o&&c.onMetaCountersDeleted(r,t.data.deleted))}}):w.getChannel(t.channelUrl,function(r,a){if(R){var l=r;r=a,a=l}if(a)return void n.log("Discard a command: "+e.command+":"+t.category);for(var u in ae.getInstance().channelHandlers){var c=ae.getInstance().channelHandlers[u];t.category===H.CATEGORY_CHANNEL_META_DATA_CHANGED?(i&&c.onMetaDataCreated(r,t.data.created),s&&c.onMetaDataUpdated(r,t.data.updated),o&&c.onMetaDataDeleted(r,t.data.deleted)):(i&&c.onMetaCountersCreated(r,t.data.created),s&&c.onMetaCountersUpdated(r,t.data.updated),o&&c.onMetaCountersDeleted(r,t.data.deleted))}});break;case H.CATEGORY_CHANNEL_HIDE:w.getChannel(t.channelUrl,function(r,a){if(R){var i=r;r=a,a=i}if(a)return void n.log("Discard a command: "+e.command+":"+t.category);if(r.isHidden=!0,t.data&&t.data.hasOwnProperty("hide_previous_messages")&&t.data.hide_previous_messages&&w.cachedChannels){var s=w.cachedChannels[r.url];s.unreadMessageCount=0,w.cachedChannels[r.url]=s}for(var o in ae.getInstance().channelHandlers){ae.getInstance().channelHandlers[o].onChannelHidden(r)}})}};this.setPushTemplate=function(e,n){return!e||e!==this.PUSH_TEMPLATE_DEFAULT&&e!==this.PUSH_TEMPLATE_ALTERNATIVE?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n):this.currentUser?void Z.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 _("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 _("Connection must be made before you get push template",J.CONNECTION_REQUIRED),e);Z.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 _("Invalid arguments.",J.INVALID_PARAMETER),n),Z.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){Z.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),r=null,a=null,i=null;switch("function"==typeof e.slice(-1)[0]&&(i=e.pop()),e.length){case 1:r=e[0];break;case 2:r=e[0],a=e[1];break;case 3:r=e[0],this.customApiHost=e[1],this.customWsHost=e[2];break;case 4:r=e[0],a=e[1],this.customApiHost=e[2],this.customWsHost=e[3];break;default:t&&n.log("sb.connect args length error: ",arguments)}r&&0!==r.length?(ae.getInstance().reconnectTimer&&(clearTimeout(ae.getInstance().reconnectTimer),ae.getInstance().reconnectTimer=null,ae.getInstance().onReconnectTimerCancel=null),ae.getInstance().getConnectionState()===this.connectionState.OPEN&&ae.getInstance().getCurrentUserId()===r?U(ae.getInstance().currentUser,null,i):(ae.getInstance().connectionCallback.push(i),1===ae.getInstance().connectionCallback.length&&(f(!0,null),g(r,a)))):U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),i)};var h=!1,I=!1,p=!0;this.setBackgroundState=function(){!h&&p&&(h=!0,this.getConnectionState()!==this.connectionState.CLOSED?(I=!0,f(!1,null)):I=!1)},this.setForegroundState=function(){h&&p&&(h=!1,I&&this.currentUser&&(y=0,A(this.getCurrentUserId(),!0)))},this.disableStateChange=function(){p=!1},this.enableStateChange=function(){p=!0},this.disconnect=function(e){f(!0,e)},this.reconnect=function(){if(!Z.getInstance().sessionKey||!this.currentUser)return!1;var e=!0;return y>0&&(e=!1),f(!1,null),y=0,A(this.getCurrentUserId(),e),!0};var f=function(e,n){var t=this;ae.getInstance().loginTimer&&(clearTimeout(ae.getInstance().loginTimer),ae.getInstance().onLoginTimerCancel&&(ae.getInstance().onLoginTimerCancel(),ae.getInstance().onLoginTimerCancel=null),ae.getInstance().loginTimer=null),ae.getInstance().reconnectTimer&&(clearTimeout(ae.getInstance().reconnectTimer),ae.getInstance().onReconnectTimerCancel&&(ae.getInstance().onReconnectTimerCancel(),ae.getInstance().onReconnectTimerCancel=null),ae.getInstance().reconnectTimer=null),ae.getInstance().wsClient&&(y=0,ae.getInstance().wsClient.disconnect(!0),ae.getInstance().wsClient=null),function(){if(e){b.clearEnteredChannels(),b.clearCache(),w.clearCache(),ae.getInstance().globalTimer&&(clearTimeout(t.globalTimer),ae.getInstance().globalTimer=null);for(var r in ae.getInstance().ackStateMap)clearTimeout(ae.getInstance().ackStateMap[r].timer);ae.getInstance().ackStateMap={},ae.getInstance().currentUser=null,Z.getInstance().sessionKey=null,Z.getInstance().ekey=null}U(null,null,n)}()},A=function(e,r){if(ae.getInstance().reconnectTimer)t&&n.log("still reconnecting");else{if((y+=1)<=1){if(r)for(var a in ae.getInstance().connectionHandlers){var i=ae.getInstance().connectionHandlers[a];i.onReconnectStarted(a)}T=0}else T=3e3*Math.pow(2,y-2);if(!e||!Z.getInstance().sessionKey||y>=6){f(!1,null),y=0;for(var a in ae.getInstance().connectionHandlers){var i=ae.getInstance().connectionHandlers[a];i.onReconnectFailed(a)}return}ae.getInstance().onReconnectTimerCancel=function(){y=0},ae.getInstance().reconnectTimer=setTimeout(function(){ae.getInstance().reconnectTimer=null,ae.getInstance().onReconnectTimerCancel=null,ae.getInstance().wsClient&&ae.getInstance().wsClient.disconnect(!0);var r=new j.WSClientHandler;ae.getInstance().wsClient=new j(r),ae.getInstance().loginHandler=function(e){y=0;for(var n in b.enteredChannels){b.enteredChannels[n].enter()}for(var n in ae.getInstance().connectionHandlers){ae.getInstance().connectionHandlers[n].onReconnectSucceeded(n)}},r.onOpen=function(){t&&n.log("reconnectWS onOpen"),ae.getInstance().loginTimer=setTimeout(function(){t&&n.log("reconnectWS loginTimer timedout"),ae.getInstance().loginTimer=null,A(e,!0)},1e4),ae.getInstance().onLoginTimerCancel=null},r.onMessage=function(e){l(e)},r.onError=function(){t&&n.log("reconnectWS onError"),A(e,!0)},r.onClose=function(){t&&n.log("reconnectWS onClose")};var a=ae.getInstance().getCurrentApiHost();Z.getInstance().checkRouting(function(n,t){if(t)return void A(e,!0);a!==n.API_HOST&&C(n.API_HOST,{},"GET",{},function(){}),ae.getInstance().wsClient.connect(e,null,n.WS_HOST)})},T)}},g=function(e,r){var a=new j.WSClientHandler;ae.getInstance().wsClient=new j(a),a.onMessage=function(e){l(e)},ae.getInstance().loginHandler=function(e,n){if(n)ae.getInstance().disconnect(null),ae.getInstance().connectionCallback.forEach(function(e){U(null,n,e)}),ae.getInstance().connectionCallback=[];else{clearTimeout(ae.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 ae.getInstance().channelHandlers){var a=ae.getInstance().channelHandlers[r];a.onTypingStatusUpdated(n)}}ae.getInstance().globalTimer=setTimeout(function(){t()},1e3)};t();var r=ae.getInstance().connectionCallback;ae.getInstance().connectionCallback=[],r.forEach(function(n){U(e,null,n)}),r=[]}},a.onOpen=function(e){ae.getInstance().loginTimer=setTimeout(function(){ae.getInstance().loginTimer=null,ae.getInstance().onLoginTimerCancel=null,ae.getInstance().disconnect(null),ae.getInstance().connectionCallback.forEach(function(e){U(null,new _("Connection timeout.",J.LOGIN_TIMEOUT),e)}),ae.getInstance().connectionCallback=[]},1e4),ae.getInstance().onLoginTimerCancel=function(){ae.getInstance().connectionCallback.forEach(function(e){U(null,new _("Connection Cancelled.",J.REQUEST_FAILED),e)}),ae.getInstance().connectionCallback=[]}},a.onError=function(r){t&&n.log("WSClientHandler.onError",r),Z.getInstance().sessionKey?A(e,!0):(ae.getInstance().connectionCallback.forEach(function(e){U(null,new _("Websocket connection failed.",J.WEBSOCKET_CONNECTION_FAILED),e)}),ae.getInstance().connectionCallback=[])},a.onClose=function(e){t&&n.log("WSClientHandler.onClose")},Z.getInstance().checkRouting(function(n,t){if(t)return ae.getInstance().connectionCallback.forEach(function(e){U(null,new _("Connection routing failed.",J.REQUEST_FAILED),e)}),void(ae.getInstance().connectionCallback=[]);C(n.API_HOST,{},"GET",{},function(){}),ae.getInstance().wsClient.connect(e,r,n.WS_HOST)})};this.sendCommand=function(e,n){if(!ae.getInstance().hasLoggedIn())return void(n&&n(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED)));if(null==ae.getInstance().wsClient||ae.getInstance().wsClient.getConnectionState()!==ae.getInstance().connectionState.OPEN)return void(n&&n(null,new _("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 _("Command received no ack.",J.ACK_TIMEOUT)),delete s[t]},1e4)};s[t]=r,ae.getInstance().wsClient.send(e,function(e,t){if(t)return clearTimeout(r.timer),void n(null,t)})}else ae.getInstance().wsClient.send(e,n)},this.markAsReadAll=function(e){var n=(new Date).getTime();if(n-w.markAsReadAllLastSentAt<1e3)return void U(null,new _("MarkAsRead rate limit exceeded.",J.MARK_AS_READ_RATE_LIMIT_EXCEEDED),e);w.markAsReadAllLastSentAt=n,Z.getInstance().groupChannelMarkAsReadAll(ae.getInstance().getCurrentUserId(),null,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)})},this.markAsReadWithChannelUrls=function(e,n){if(!Array.isArray(e))return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);var t=(new Date).getTime();if(t-w.markAsReadAllLastSentAt<1e3)return void U(null,new _("MarkAsRead rate limit exceeded.",J.MARK_AS_READ_RATE_LIMIT_EXCEEDED),n);w.markAsReadAllLastSentAt=t,Z.getInstance().groupChannelMarkAsReadAll(ae.getInstance().getCurrentUserId(),e,function(t,r){if(r)return void U(null,r,n);e.forEach(function(e){var n=w.cachedChannels[e];n&&(n.unreadMessageCount=0,w.cachedChannels[e]=n)}),U(null,null,n)})},this.updateCurrentUserInfoWithProfileImage=function(e,n,t){var r=this;n?Z.getInstance().updateCurrentUserInfoWithFile(r.getCurrentUserId(),e,n,function(a,i){if(i)return void U(null,i,t);r.currentUser&&(e&&(r.currentUser.nickname=e),n&&(r.currentUser.profileUrl=a.profile_url)),U(r.currentUser,null,t)}):r.updateCurrentUserInfo(e,null,t)},this.updateCurrentUserInfo=function(e,n,t){var r=this;Z.getInstance().updateUserInfo(r.getCurrentUserId(),e,n,function(a,i){if(i)return void U(null,i,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 Z.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 _("Invalid token",J.INVALID_PARAMETER),n)},this.unregisterGCMPushTokenForCurrentUser=function(e,n){if(!e)return void U(null,new _("Invalid token",J.INVALID_PARAMETER),n);Z.getInstance().unregisterGCMPushToken(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.unregisterGCMPushTokenAllForCurrentUser=function(e){Z.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 Z.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 _("Invalid token",J.INVALID_PARAMETER),n)},this.unregisterAPNSPushTokenForCurrentUser=function(e,n){if(!e)return void U(null,new _("Invalid token",J.INVALID_PARAMETER),n);Z.getInstance().unregisterAPNSPushToken(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.unregisterAPNSPushTokenAllForCurrentUser=function(e){Z.getInstance().unregisterAPNSPushTokenAll(this.getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);U(null,null,e)})},this.unregisterPushTokenAllForCurrentUser=function(e){Z.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,i,s){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 _("Invalid arguments.",J.INVALID_PARAMETER),s);Z.getInstance().setDoNotDisturb(o.getCurrentUserId(),e,n,t,r,a,i,function(e,n){if(n)return void U(null,n,s);var t={doNotDisturbOn:e.do_not_disturb,startHour:e.start_hour,startMin:e.start_min,endHour:e.end_hour,endMin:e.end_min,timezone:e.timezone};U(t,null,s)})},this.getDoNotDisturb=function(e){var n=this;Z.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 _("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 _("You can not block yourself.",J.INVALID_PARAMETER),n);Z.getInstance().blockUser(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(new G(e),null,n)})},this.unblockUser=function(e,n){if("object"!=typeof e)return void U(null,new _("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 _("You can not unblock yourself.",J.INVALID_PARAMETER),n);Z.getInstance().unblockUser(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.addFriends=function(e,n){if(!Array.isArray(e))return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);var t=this;Z.getInstance().addFriends(t.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);var r=e.users.map(function(e){return new G(e)});U(r,null,n)})},this.deleteFriends=function(e,n){if(!Array.isArray(e))return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);var t=this;Z.getInstance().deleteFriends(t.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(e,null,n)})},this.deleteFriend=function(e,n){if("string"!=typeof e)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);this.deleteFriends([e],n)},this.uploadFriendDiscoveries=function(e,n){var t=!0;for(var r in e)if(!e[r].hasOwnProperty("friendDiscoveryKey")){t=!1,U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);break}if(t){var a=this;Z.getInstance().uploadFriendDiscoveries(a.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(e,null,n)})}},this.deleteFriendDiscoveries=function(e,n){if(!Array.isArray(e))return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);var t=this;Z.getInstance().deleteFriendDiscoveries(t.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(e,null,n)})},this.deleteFriendDiscovery=function(e,n){if("string"!=typeof e)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);this.deleteFriendDiscoveries([e],n)},this.getFriendChangeLogsByToken=function(e,n){if("function"==typeof e&&(n=e,e=null),"function"!=typeof n)return null;var t=this;Z.getInstance().getFriendChangeLogsByToken(t.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);var r=e.updated.map(function(e){return new G(G.build(e.user_id,e.nickname,e.profile_url,e.is_online,e.last_seen_at,e.metadata,e.is_active,e.friend_discovery_key,e.friend_name))}),a=e.deleted,i=e.has_more,s=e.next;U({updatedUsers:r,deletedUserIds:a,hasMore:i,token:s},null,n)})},this.createFriendListQuery=function(){return new $}},ie=null;return ae.getInstance=function(){return null===ie?null:ie},{SendBird:ae}},g=null;return function(){var e=function(e){if(e.newInstance||!g){var n=new A;g=new n.SendBird(e)}return g};return e.getInstance=function(){return null===g?null:g},e.version="3.0.56",{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(["SendBird"],n):"object"==typeof exports?exports.SendBird=n():e.SendBird=n()}("undefined"!=typeof self?self:this,function(){function e(){this.oldIE=!0,this.boundary="--------FormData"+Math.random(),this._fields=[]}var n,t=!1,r="wss://ws.sendbird.com",i="https://api.sendbird.com";try{n=window.console||{log:function(){}}}catch(e){n={log:function(){}}}var a="undefined";try{a=navigator.userAgent.replace(/,/g,".")}catch(e){a="undefined"}var s,o="JS,"+a+",3.0.57,",l=function(){try{if(document&&9===document.documentMode)return!0}catch(e){return!1}return!1}(),u=function(){try{if(document&&document.documentMode<=8)return!0}catch(e){return!1}return!1}();if(l||u)"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&&l.status<400?c(null,JSON.parse(l.responseText),o):c({status:l.status,statusText:l.statusText,response:l.responseText},null,o)},l.onerror=function(){c({status:404,statusText:"There was a connection error",response:JSON.stringify({message:"There was a connection error",code:J.NETWORK_ERROR})},null,o)};try{for(var u in a)l.setRequestHeader(u,a[u]?a[u]:"sendbird")}catch(e){}try{switch(i){case"get":case"GET":l.send();break;default:"undefined"!=typeof FormData&&FormData&&r instanceof FormData||void 0!==s&&s&&r instanceof s?r.oldIE?(l.setRequestHeader("Content-Type","multipart/form-data; boundary="+r.boundary),l.send(r.toString())):l.send(r):(l.setRequestHeader("Content-Type","application/json; charset=utf-8"),l.send(JSON.stringify(r)))}}catch(e){t&&n.log("request.send() fail: ",e)}},R=!1,U=function(e,n,t){t&&"function"==typeof t&&(void 0===n&&(n=null),void 0===e&&(e=null),R?t(n,e):t(e,n))},S="",y=0,T=0,P=function(e){this.isOpenChannel=function(){return this.channelType===M.CHANNEL_TYPE_OPEN},this.isGroupChannel=function(){return this.channelType===M.CHANNEL_TYPE_GROUP},this.isUserMessage=function(){return this.messageType===P.MESSAGE_TYPE_USER},this.isAdminMessage=function(){return this.messageType===P.MESSAGE_TYPE_ADMIN},this.isFileMessage=function(){return this.messageType===P.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):M.CHANNEL_TYPE_GROUP;var n=this;if(n.mentionedUsers=[],e.hasOwnProperty("mentioned_users")){e.mentioned_users.forEach(function(e){var t=new G(e);n.mentionedUsers.push(t)})}},this.serialize=function(){var e=JSON.parse(JSON.stringify(this));return e.hasOwnProperty("_sender")&&(e.sender=e._sender,delete e._sender),E(e)},this.messageType=P.MESSAGE_TYPE_BASE,e&&this._update(e)};P.build=function(e,n){if(!e)return null;var t,r,i,a,s,o,l,u,c;switch(e.type){case"MESG":return t=new G(e.user),r=parseInt(e.message_id),i=String(e.message),a=String(e.data),s=parseInt(e.created_at),o=parseInt(e.updated_at),l=e.hasOwnProperty("custom_type")?String(e.custom_type):"",u=e.hasOwnProperty("translations")?e.translations:{},c=e.mentioned_users,new O(O.build("",r,t,n,i,a,l,u,s,o,c));case"FILE":t=new G(e.user),r=parseInt(e.message_id),i=String(e.message),s=parseInt(e.created_at),o=parseInt(e.updated_at),l=e.hasOwnProperty("custom_type")?String(e.custom_type):"",c=e.mentioned_users;var d=e.file,h=String(d.url),I=String(d.name),_=String(d.type),p=parseInt(d.size)||0;a=String(d.data);var E=e.hasOwnProperty("thumbnails")?e.thumbnails:[],f=!!e.hasOwnProperty("require_auth")&&e.require_auth;return new D(D.build("",r,t,n,h,I,_,p,a,l,s,E,f,o,c));case"BRDM":case"ADMM":return r=parseInt(e.message_id),i=String(e.message),a=String(e.data),s=parseInt(e.created_at),o=parseInt(e.updated_at),l=e.hasOwnProperty("custom_type")?String(e.custom_type):"",u=e.hasOwnProperty("translations")?e.translations:{},c=e.mentioned_users,new L(L.build(r,n,i,a,l,u,s,o,c))}return null},P.MESSAGE_TYPE_BASE="base",P.MESSAGE_TYPE_ADMIN="admin",P.MESSAGE_TYPE_USER="user",P.MESSAGE_TYPE_FILE="file";var L=function(e){this.messageType=P.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(P,L),L.build=function(e,n,t,r,i,a,s,o,l){var u={msg_id:e,channel_url:n.url,channel_type:n.channelType===M.CHANNEL_TYPE_OPEN?M.CHANNEL_TYPE_OPEN:M.CHANNEL_TYPE_GROUP,ts:s,updated_at:o,message:t,data:r};return i&&(u.custom_type=i),a&&(u.translations=a),u.mentioned_users=[],l&&(u.mentioned_users=l),u},L.buildFromSerializedData=function(e){var n=f(e),t=[];return n.mentionedUsers.forEach(function(e){t.push(G.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData,e.isActive,e.friendDiscoveryKey,e.friendName))}),new L(L.build(n.messageId,{url:n.channelUrl,channelType:n.channelType},n.message,n.data,n.customType,n.translations,n.createdAt,n.updatedAt,t))};var O=function(e){this.messageType=P.MESSAGE_TYPE_USER,e&&(this._update(e),this.message=String(e.message),this.data=e.hasOwnProperty("data")?String(e.data):"",this._sender=new G(e.user),u?this.sender=this._sender:Object.defineProperty(this,"sender",{get:function(){if(ie.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),this._sender.metaData!==n.metaData&&(this._sender.metaData=n.metaData))}}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(P,O),O.build=function(e,n,t,r,i,a,s,o,l,u,c,d){var h={};h.req_id=e,h.msg_id=n,h.channel_url=r.url,h.channel_type=r.channelType===M.CHANNEL_TYPE_OPEN?M.CHANNEL_TYPE_OPEN:M.CHANNEL_TYPE_GROUP,h.ts=l,h.updated_at=u,h.message=i,a&&(h.data=a),s&&(h.custom_type=s),o&&(h.translations=o);var I={};I.user_id=t.userId,I.nickname=t.nickname,I.profile_url=t.profileUrl;try{I.metadata="string"==typeof t.metaData?JSON.parse(t.metaData):t.metaData}catch(e){I.metadata={}}return h.user=I,h.mentioned_users=[],c&&(h.mentioned_users=c),d&&(h.mentioned_user_ids=d),h},O.buildFromSerializedData=function(e){var n=f(e),t=[];return n.mentionedUsers.forEach(function(e){t.push(G.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData,e.isActive,e.friendDiscoveryKey,e.friendName))}),new O(O.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,t))};var D=function(e){if(this.messageType=P.MESSAGE_TYPE_FILE,e&&(this._update(e),this._sender=new G(e.user),u?this.sender=this._sender:Object.defineProperty(this,"sender",{get:function(){if(ie.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),this._sender.metaData!==n.metaData&&(this._sender.metaData=n.metaData))}}return this._sender},set:function(e){this._sender=e}}),this.requireAuth=!!e.hasOwnProperty("require_auth")&&e.require_auth,this.url=this.requireAuth?String(e.url).split("?auth=")[0]+"?auth="+Z.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="+Z.getInstance().ekey};I(P,D),D.build=function(e,n,t,r,i,a,s,o,l,u,c,d,h,I,_,p){var E={};E.req_id=e,E.msg_id=n,E.channel_url=r.url,E.channel_type=r.channelType===M.CHANNEL_TYPE_OPEN?M.CHANNEL_TYPE_OPEN:M.CHANNEL_TYPE_GROUP,E.ts=c,E.updated_at=I,E.url=i,E.name=a,E.type=s,E.size=o,E.custom=l;var f={};f.user_id=t.userId,f.nickname=t.nickname,f.profile_url=t.profileUrl;try{f.metadata=JSON.parse(t.metaData)}catch(e){f.metadata={}}return E.user=f,u&&(E.custom_type=u),h&&(E.require_auth=h),d&&(E.thumbnails=d),E.mentioned_users=[],_&&(E.mentioned_users=_),p&&(E.mentioned_user_ids=p),E},D.buildFromSerializedData=function(e){var n=f(e),t=[];return n.mentionedUsers.forEach(function(e){t.push(G.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData,e.isActive,e.friendDiscoveryKey,e.friendName))}),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,t))};var M=function(e){this._update=function(e){this.url=e.hasOwnProperty("channel_url")?String(e.channel_url):"",this.name=e.hasOwnProperty("name")?String(e.name):"",this.coverUrl=e.hasOwnProperty("cover_url")?String(e.cover_url):"",this.createdAt=e.hasOwnProperty("created_at")?1e3*e.created_at:0,this.data=e.hasOwnProperty("data")?String(e.data):"",this.customType=e.hasOwnProperty("custom_type")?e.custom_type:"",this.isFrozen=!!e.hasOwnProperty("freeze")&&e.freeze,this.isEphemeral=!!e.hasOwnProperty("is_ephemeral")&&e.is_ephemeral,this.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 E(e)},this.isGroupChannel=function(){return this.channelType===M.CHANNEL_TYPE_GROUP},this.isOpenChannel=function(){return this.channelType===M.CHANNEL_TYPE_OPEN},this.getMessageChangeLogsByToken=function(e,n){if("function"==typeof e&&(n=e,e=null),"function"!=typeof n)return null;Z.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 P.build(e,this)}),i=e.deleted.map(function(e){return e.message_id}),a=e.has_more,s=e.next;U({updatedMessages:r,deletedMessageIds:i,hasMore:a,token:s},null,n)})},this.createPreviousMessageListQuery=function(){return new q(this)},this.createMessageListQuery=function(){return new W(this)};var n=function(e,n,t,r,i,a,s,o,l){if(s===p.MessageTypeFilter.ADMIN?s="ADMM":s===p.MessageTypeFilter.USER?s="MESG":s===p.MessageTypeFilter.FILE?s="FILE":s===p.MessageTypeFilter.ALL&&(s=""),!h(n)||"boolean"!=typeof t||!h(r)||!h(i)||"boolean"!=typeof a||"string"!=typeof s||"string"!=typeof o)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),l);Z.getInstance().messageList(e.isOpenChannel(),e.url,n,r,i,t,a,s,o,function(n,t){if(t)return void U(null,t,l);var r=n.messages,i=[];for(var a in r){var s=P.build(r[a],e);s&&i.push(s)}U(i,null,l)})},t=function(e,n,t,r,i,a,s,o,l){if(s===p.MessageTypeFilter.ADMIN?s="ADMM":s===p.MessageTypeFilter.USER?s="MESG":s===p.MessageTypeFilter.FILE?s="FILE":s===p.MessageTypeFilter.ALL&&(s=""),!h(n)||"boolean"!=typeof t||!h(r)||!h(i)||"boolean"!=typeof a||"string"!=typeof s||"string"!=typeof o)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),l);Z.getInstance().messageListByID(e.isOpenChannel(),e.url,n,r,i,t,a,s,o,function(n,t){if(t)return void U(null,t,l);var r=n.messages,i=[];for(var a in r){var s=P.build(r[a],e);s&&i.push(s)}U(i,null,l)})};this.getNextMessagesByTimestamp=function(e,t,r,i,a,s,o){return n(this,e,t,0,r,i,a,s,o)},this.getPreviousMessagesByTimestamp=function(e,t,r,i,a,s,o){return n(this,e,t,r,0,i,a,s,o)},this.getPreviousAndNextMessagesByTimestamp=function(e,t,r,i,a,s,o){return n(this,e,!0,t,r,i,a,s,o)},this.getNextMessagesByID=function(e,n,r,i,a,s,o){return t(this,e,n,0,r,i,a,s,o)},this.getPreviousMessagesByID=function(e,n,r,i,a,s,o){return t(this,e,n,r,0,i,a,s,o)},this.getPreviousAndNextMessagesByID=function(e,n,r,i,a,s,o){return t(this,e,!0,n,r,i,a,s,o)},this._sendFileCommand=function(e,n,t,r,i,a,s,o,l,u,c,d,h){var I,p=this;I=h?h.reqId:Y.generateRequestId();var E=Y.bFile(I,e,n,t,r,i,a,s,o,l,u,c),f=D.build(E.requestId,0,ie.getInstance().currentUser,this,"string"==typeof n?n:"",t,r,i,a,s,null,null,!1,null,null,u),A=new D(f);return"string"==typeof n&&ie.getInstance().sendCommand(E,function(e,n){if(n)return void U(null,new _(n.message,n.code),d);var t=new D(e.getJsonElement()),r=ie.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)),p.isGroupChannel()&&w.getChannel(p.url,function(e,n){if(R){var r=e;e=n,n=r}if(n)return void U(null,n,d);e.lastMessage=t;for(var i in ie.getInstance().channelHandlers){ie.getInstance().channelHandlers[i].onChannelChanged(e)}}),U(t,null,d)}),A},this._getSendFileMessageParamInfo=function(e){var n={file:null,name:null,type:null,size:null,data:"",customType:"",thumbnailSizes:[],callback:null,progressHandler:null,mentionedUserIds:[],pushNotificationDeliveryOption:re.PushNotificationDeliveryOption.DEFAULT};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:if(e[0]instanceof re){var t=e[0];n.file=t.file?t.file:t.fileUrl,n.name=t.fileName,n.type=t.mimeType,n.size=t.fileSize,n.data=t.data,n.customType=t.customType,n.thumbnailSizes=t.thumbnailSizes,n.mentionedUserIds=t._mentionedIds,n.pushNotificationDeliveryOption=t.pushNotificationDeliveryOption}else 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,i=n.type,a=n.size,s=n.data,o=n.customType,l=n.thumbnailSizes,u=n.callback,c=n.progressHandler,d=n.mentionedUserIds,I=n.pushNotificationDeliveryOption;if(null!==l&&void 0!==l||(l=[]),!ie.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),u);if(null===t||void 0===t||null!==r&&void 0!==r&&"string"!=typeof r||null!==i&&void 0!==i&&"string"!=typeof i||null!==a&&void 0!==a&&(!h(a)||parseInt(a)<0)||null!==s&&void 0!==s&&"string"!=typeof s||null!==o&&void 0!==o&&"string"!=typeof o||!Array.isArray(l)||[re.PushNotificationDeliveryOption.DEFAULT,re.PushNotificationDeliveryOption.SUPPRESS].indexOf(I)<-1)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),u);var p=e.url,E=null;return"string"==typeof t?E=e._sendFileCommand(p,t,r,i,a,s,o,[],!1,d,I,u):(E=e._sendFileCommand(p,t,r,i,a,s,o,[],!1,d,I,u),Z.getInstance().uploadFile(t,i,l,p,function(n,t){if(t)return void U(null,t,u);var l="object"==typeof n?n:JSON.parse(n),c=l.url,h=l.hasOwnProperty("thumbnails")?l.thumbnails:[],_=!!l.hasOwnProperty("require_auth")&&l.require_auth;e._sendFileCommand(p,c,r,i,a,s,o,h,_,d,I,u,E)},c,this.fileUploadRequest,E.reqId)),E},this.cancelUploadingFileMessage=function(e,n){if(!ie.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),n);if(!h(e))return void U(null,new _("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 _("Uploading has been completed or cancelled.",J.FILE_UPLOAD_CANCEL_FAILED),n),!1)},this.sendUserMessage=function(e,n,t,r,i){var a=this,s=[],o=te.PushNotificationDeliveryOption.DEFAULT;if("function"==typeof n&&(i=n,n="",t="",r=[],e instanceof te)){var l=e;e=l.message,n=l.data,t=l.customType,r=l.targetLanguages,s=l._mentionedIds,o=l.pushNotificationDeliveryOption}if("function"==typeof t&&(i=t,t="",r=[]),"function"==typeof r&&(i=r,r=[]),r||(r=[]),"string"==typeof r&&(r=[r]),null===n&&(n=""),null===t&&(t=""),!ie.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),i);if("string"!=typeof e||"string"!=typeof n||"string"!=typeof t||!Array.isArray(r)||[te.PushNotificationDeliveryOption.DEFAULT,te.PushNotificationDeliveryOption.SUPPRESS].indexOf(o)<-1)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),i);var u=Y.bMessage(this.url,e,n,t,s,r,o),c=O.build(u.requestId,0,ie.getInstance().currentUser,this,e,n,t,r,(new Date).getTime(),null,null,s),d=new O(c);return ie.getInstance().sendCommand(u,function(e,n){if(n)return void U(null,new _(n.message,n.code),i);var t=new O(e.getJsonElement()),r=ie.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)),a.isGroupChannel()&&w.getChannel(a.url,function(e,n){if(R){var r=e;e=n,n=r}if(n)return void U(null,n,i);e.lastMessage=t;for(var a in ie.getInstance().channelHandlers){ie.getInstance().channelHandlers[a].onChannelChanged(e)}}),U(t,null,i)}),d},this.updateUserMessage=function(e,n,t,r,i){var a=Array.prototype.slice.call(arguments);if(5!==a.length)return"function"==typeof a.slice(-1)[0]&&(i=a.pop()),void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),i);if(!ie.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),i);if(!h(e))return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),i);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 _("Invalid arguments.",J.INVALID_PARAMETER),i);var s=Y.bUpdateUserMessage(this.url,e,n,t,r);ie.getInstance().sendCommand(s,function(e,n){if(n)return void U(null,new _(n.message,n.code),i);var t=new O(e.getJsonElement());U(t,null,i)})},this.updateFileMessage=function(e,n,t,r){var i=Array.prototype.slice.call(arguments);if(4!==i.length)return"function"==typeof i.slice(-1)[0]&&(r=i.pop()),void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),r);if(!ie.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),r);if(!h(e))return void U(null,new _("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 _("Invalid arguments.",J.INVALID_PARAMETER),r);var a=Y.bUpdateFileMessage(this.url,e,n,t);ie.getInstance().sendCommand(a,function(e,n){if(n)return void U(null,new _(n.message,n.code),r);var t=new D(e.getJsonElement());U(t,null,r)})},this.createMetaCounters=function(e,n){return ie.getInstance().hasLoggedIn()?null==e||"object"!=typeof e||Array.isArray(e)||d(e)?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n):void Z.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 _("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.updateMetaCounters=function(e,n,t){return ie.getInstance().hasLoggedIn()?("function"!=typeof n&&void 0!==t||(t=n,n=!1),null==e||"object"!=typeof e||Array.isArray(e)||d(e)||"boolean"!=typeof n?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),t):void Z.getInstance().updateMetaCounters(this.isOpenChannel(),this.url,e,n,Z.UPDATE_META_COUNTER_MODE_SET,function(e,n){if(n)return void U(null,n,t);U(e,null,t)})):void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),t)},this.increaseMetaCounters=function(e,n){return ie.getInstance().hasLoggedIn()?null==e||"object"!=typeof e||Array.isArray(e)||d(e)?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n):void Z.getInstance().updateMetaCounters(this.isOpenChannel(),this.url,e,!1,Z.UPDATE_META_COUNTER_MODE_INC,function(e,t){if(t)return void U(null,t,n);U(e,null,n)}):void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.decreaseMetaCounters=function(e,n){return ie.getInstance().hasLoggedIn()?null==e||"object"!=typeof e||Array.isArray(e)||d(e)?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n):void Z.getInstance().updateMetaCounters(this.isOpenChannel(),this.url,e,!1,Z.UPDATE_META_COUNTER_MODE_DEC,function(e,t){if(t)return void U(null,t,n);var r=e,i={};for(var a in r){var s=r[a];i[a]=s}U(i,null,n)}):void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.getMetaCounters=function(e,n){return ie.getInstance().hasLoggedIn()?Array.isArray(e)?void Z.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 _("Invalid arguments.",J.INVALID_PARAMETER),n):void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.getAllMetaCounters=function(e){if(!ie.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),e);Z.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 ie.getInstance().hasLoggedIn()?"string"!=typeof e?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n):void Z.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 _("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.deleteAllMetaCounters=function(e){if(!ie.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),e);Z.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 ie.getInstance().hasLoggedIn()?null==e||"object"!=typeof e||Array.isArray(e)||d(e)?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n):void Z.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 _("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.updateMetaData=function(e,n,t){return ie.getInstance().hasLoggedIn()?("function"!=typeof n&&void 0!==t||(t=n,n=!1),null==e||"object"!=typeof e||Array.isArray(e)||d(e)||"boolean"!=typeof n?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),t):void Z.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 _("Connection should be made first.",J.CONNECTION_REQUIRED),t)},this.getMetaData=function(e,n){return ie.getInstance().hasLoggedIn()?Array.isArray(e)?void Z.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 _("Invalid arguments.",J.INVALID_PARAMETER),n):void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.getAllMetaData=function(e){if(!ie.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),e);Z.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 ie.getInstance().hasLoggedIn()?"string"!=typeof e?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n):void Z.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 _("Connection should be made first.",J.CONNECTION_REQUIRED),n)},this.deleteAllMetaData=function(e){if(!ie.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),e);Z.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 _("Invalid arguments.",J.INVALID_PARAMETER),n);if(!ie.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),n);var r=this;if("object"!=typeof e||d(e)||Array.isArray(e)||Object.keys(e).indexOf("messageId")<0||!e)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);Z.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=M.CHANNEL_TYPE_BASE,e&&this._update(e)};M.CHANNEL_TYPE_OPEN="open",M.CHANNEL_TYPE_GROUP="group",M.CHANNEL_TYPE_BASE="base";var b=function(e){this.parse=function(e){if(e.hasOwnProperty("participant_count")&&(this.participantCount=parseInt(e.participant_count)),e.hasOwnProperty("operators")&&e.operators){this.operators=[];for(var n in e.operators){var t=new G(e.operators[n]);this.operators.push(t)}}},this.refresh=function(e){b.getChannelWithoutCache(this.url,function(n,t){if(R){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;Z.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=Y.bEnter(n.url);ie.getInstance().sendCommand(t,function(t,r){if(r)return void U(null,new _(r.message,r.code),e);b.enteredChannels[n.url]=n,U(null,null,e)})},this.exit=function(e){var n=this,t=Y.bExit(n.url);ie.getInstance().sendCommand(t,function(t,r){if(r)return void U(null,new _(r.message,r.code),e);delete b.enteredChannels[n.url],U(null,null,e)})},this.createParticipantListQuery=function(){return new z(z.PARTICIPANT,this)},this.createMutedUserListQuery=function(){return new z(z.MUTED_USER,this)},this.createBannedUserListQuery=function(){return new z(z.BANNED_USER,this)},this.updateChannel=function(){var e=Array.prototype.slice.call(arguments),n=null,t=null,r=null,i=null,a=null,s=null;switch("function"==typeof e.slice(-1)[0]&&(s=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],i=e[3];break;case 5:n=e[0],t=e[1],r=e[2],i=e[3],a=e[4];break;default:return void U(null,new _("Invalid arguments.2",J.INVALID_PARAMETER),s)}this.updateChannelWithOperatorUserIds(n,t,r,i,a,s)},this.updateChannelWithOperatorUserIds=function(e,n,t,r,i,a){if("function"==typeof i&&(a=i,i=null),"string"!=typeof e&&null!==e&&void 0!==e||"string"!=typeof n&&d(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 i&&null!==i&&void 0!==i)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),a);Z.getInstance().updateOpenChannel(this.url,e,n,t,r,i,function(e,n){if(n)return void U(null,n,a);var t=b.upsert(e);U(t,null,a)})},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 _("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 _("Invalid parameter.",J.INVALID_PARAMETER),t);Z.getInstance().banUser(this.url,e,null,n,!1,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 _("Invalid parameter.",J.INVALID_PARAMETER),n);this.unbanUserWithUserId(e.userId,n)},this.unbanUserWithUserId=function(e,n){if(!e)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);Z.getInstance().unbanUser(this.url,e,!1,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 _("Invalid parameter.",J.INVALID_PARAMETER),n);this.muteUserWithUserId(e.userId,n)},this.muteUserWithUserId=function(e,n){if(!e)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);Z.getInstance().muteUser(this.url,e,!1,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 _("Invalid parameter.",J.INVALID_PARAMETER),n);this.unmuteUserWithUserId(e.userId,n)},this.unmuteUserWithUserId=function(e,n){if(!e)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);Z.getInstance().unmuteUser(this.url,e,!1,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=M.CHANNEL_TYPE_OPEN,this.participantCount=0,this.operators=[],e&&(this._update(e),this.parse(e))};I(M,b),b.enteredChannels={},b.clearEnteredChannels=function(){b.enteredChannels={}},b.createOpenChannelListQuery=function(){return new K},b.buildFromSerializedData=function(e){var n=f(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,is_ephemeral:n.isEphemeral,participant_count:n.participantCount,operators:n.operators.map(function(e){return G.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData,e.isActive,e.friendDiscoveryKey,e.friendName)})})},b.createChannel=function(){var e,n,t,r,i,a;switch(arguments.length){case 1:a=arguments[0];break;case 4:e=arguments[0],n=arguments[1],t=arguments[2],a=arguments[3];break;case 5:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],a=arguments[4];break;case 6:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],i=arguments[4],a=arguments[5]}b.createChannelWithOperatorUserIds(e,n,t,r,i,a)},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,i,a){if("function"==typeof i&&(a=i,i=""),"string"!=typeof e&&null!==e&&void 0!==e||"string"!=typeof n&&d(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 i&&null!==i&&void 0!==i)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),a);Z.getInstance().createOpenChannel(e,n,t,r,i,function(e,n){if(n)return void U(null,n,a);var t=b.upsert(e);U(t,null,a)})},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 _("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 _("Invalid arguments.",J.INVALID_PARAMETER),n);Z.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 t,r,i={};this.parse=function(e){var n=this;if(n.isDistinct=!!e.is_distinct&&e.is_distinct,n.unreadMessageCount=parseInt(e.unread_message_count),n.isPushEnabled=!!e.is_push_enabled&&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 V(e);n.members.push(t),n.memberMap[t.userId]=t})}e.hasOwnProperty("member_state")?n.myMemberState=e.member_state:n.myMemberState="none",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 P?n.lastMessage=e.last_message:n.lastMessage=P.build(e.last_message,n):n.lastMessage=null,e.hasOwnProperty("inviter")&&null!==e.inviter&&"object"==typeof e.inviter&&!d(e.inviter)?n.inviter=new G(e.inviter):n.inviter=null,e.hasOwnProperty("is_super")&&null!==e.is_super&&"boolean"==typeof e.is_super?n.isSuper=e.is_super:n.isSuper=!1,e.hasOwnProperty("is_public")&&null!==e.is_public&&"boolean"==typeof e.is_public?n.isPublic=e.is_public:n.isPublic=!1},this.refresh=function(e){w.getChannelWithoutCache(this.url,function(n,t){if(R){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,i=null,a=null,s=null,o=null,l=null;switch("function"==typeof n.slice(-1)[0]&&(o=n.pop()),n.length){case 1:if(!(n[0]instanceof ne))return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),o);var u=n[0];t=u.isDistinct,r=u.name,i=u.channelCover,a=u.data,s=u.customType,l=u.isPublic;break;case 3:t=e.isDistinct,r=n[0],i=n[1],a=n[2];break;case 4:t=n[0],r=n[1],i=n[2],a=n[3];break;case 5:t=n[0],r=n[1],i=n[2],a=n[3],s=n[4];break;default:return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),o)}if("string"!=typeof r&&null!==r&&void 0!==r||"string"!=typeof i&&d(i)&&null!==i&&void 0!==i||"string"!=typeof a&&null!==a&&void 0!==a||"boolean"!=typeof t&&null!==t||"boolean"!=typeof l&&null!==l||"string"!=typeof s&&null!==s&&void 0!==s)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),o);Z.getInstance().updateGroupChannel(e.url,t,r,i,a,s,l,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(!ie.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),e);Z.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)||d(e))return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);var t=[];for(var r in e){if("object"!=typeof e[r]||d(e[r])){U(null,new _("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)||d(e))return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);Z.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){Z.getInstance().acceptInvitation(this.url,ie.getInstance().getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);var r=w.upsert(n);r.myMemberState="joined",w.cachedChannels[r.url]=r,U(r,null,e)})},this.declineInvitation=function(e){var n=this;Z.getInstance().declineInvitation(this.url,ie.getInstance().getCurrentUserId(),function(t,r){if(r)return void U(null,r,e);n.myMemberState="none",w.cachedChannels[n.url]=n,n.isPublic||w.removeCachedChannel(n.url),U(t,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 _("Invalid parameter.",J.INVALID_PARAMETER),n);var t=this.url,r=this;Z.getInstance().groupChannelHide(t,ie.getInstance().getCurrentUserId(),e,function(i,a){if(a)return void U(null,a,n);r.isHidden=!0;var s=w.cachedChannels[t];s&&(s.isHidden=!0,e&&(s.unreadMessageCount=0),w.cachedChannels[t]=s),U(i,null,n)})},this.join=function(e){var n=this.url;Z.getInstance().publicGroupChannelJoin(n,ie.getInstance().getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);var r=w.upsert(n);r.myMemberState="joined",w.cachedChannels[r.url]=r,U(r,null,e)})},this.leave=function(e){var n=this.url;Z.getInstance().groupChannelLeave(n,ie.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=Y.bRead(n.url);ie.getInstance().sendCommand(t,function(t,r){if(r)return void U(null,new _(r.message,r.code),e);if(n.unreadMessageCount>0){n.unreadMessageCount=0;for(var i in ie.getInstance().channelHandlers){ie.getInstance().channelHandlers[i].onChannelChanged(n)}}U(null,null,e)})},this.getReadReceipt=function(e){if(!(e instanceof P))return n.log("message is not BaseMessage instance"),-1;if(e.messageType===P.MESSAGE_TYPE_ADMIN)return 0;var t=ie.getInstance().currentUser,r=0,i=e.createdAt,a=this.members;for(var s in a){var o=a[s],l=o.userId;if(!(t.userId===l||e.sender&&e.sender.userId===l)){this.cachedReadReceiptStatus[l]=1e4&&(delete i[t],e=!0)}return e},this.updateTypingStatus=function(e,n){n?i[e.userId]=(new Date).getTime():delete i[e.userId]},this.isTyping=function(){return 0!==Object.keys(i).length},this.getTypingMembers=function(){var e=[];for(var n in i){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===V.JOINED&&(e.state=V.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 i=this.members[r];if(i.userId===n){t=i,this.members.splice(r,1);break}}this.memberCount--}return null===t&&this.isSuper&&this.memberCount--,t},this.setPushPreference=function(e,n){var t=this;if(!ie.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),n);Z.getInstance().setPushPreference(ie.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(!ie.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),e);Z.getInstance().getPushPreference(ie.getInstance().getCurrentUserId(),this.url,function(t,r){if(r)return void U(null,r,e);if(e){var i;try{i=t.enable}catch(e){i=!1}n.isPushEnabled=i,U(i,null,e)}})},this.createMemberListQuery=function(){var e=this.url;return new B(e)},this.banUser=function(e,n,t,r){if(!e||!e.hasOwnProperty("userId")||"string"!=typeof t)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),r);this.banUserWithUserId(e.userId,n,t,r)},this.banUserWithUserId=function(e,n,t,r){if(!e||"string"!=typeof e||"string"!=typeof t)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),r);Z.getInstance().banUser(this.url,e,t,n,!0,function(e,n){if(n)return void U(null,n,r);U(null,null,r)})},this.unbanUser=function(e,n){if(!e||!e.hasOwnProperty("userId"))return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);this.unbanUserWithUserId(e.userId,n)},this.unbanUserWithUserId=function(e,n){if(!e||"string"!=typeof e)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);Z.getInstance().unbanUser(this.url,e,!0,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.muteUser=function(e,n){if(!e||!e.hasOwnProperty("userId"))return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);this.muteUserWithUserId(e.userId,n)},this.muteUserWithUserId=function(e,n){if(!e||"string"!=typeof e)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);Z.getInstance().muteUser(this.url,e,!0,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.unmuteUser=function(e,n){if(!e||!e.hasOwnProperty("userId"))return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);this.unmuteUserWithUserId(e.userId,n)},this.unmuteUserWithUserId=function(e,n){if(!e||"string"!=typeof e)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);Z.getInstance().unmuteUser(this.url,e,!0,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.freeze=function(e){Z.getInstance().freeze(this.url,!0,!0,function(n,t){if(t)return void U(null,t,e);w.upsert(n),U(null,null,e)})},this.unfreeze=function(e){Z.getInstance().freeze(this.url,!0,!1,function(n,t){if(t)return void U(null,t,e);w.upsert(n),U(null,null,e)})},this.createBannedUserListQuery=function(){return new z(z.BANNED_USER,this)},this.channelType=M.CHANNEL_TYPE_GROUP,this.isDistinct=!1,this.isSuper=!1,this.isPublic=!1,this.unreadMessageCount=0,this.inviter=null,this.members=[],this.memberMap={},this.lastMessage={},this.memberCount=0,this.cachedReadReceiptStatus={},this.isPushEnabled,this.isHidden=!1,e&&(this._update(e),this.parse(e))};I(M,w),w.buildFromSerializedData=function(e){var n=f(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,is_super:n.isSuper,is_public:n.isPublic,freeze:n.isFrozen,is_ephemeral:n.isEphemeral,unread_message_count:n.unreadMessageCount,is_push_enabled:n.isPushEnabled,is_hidden:n.isHidden,member_count:n.memberCount,member_state:n.myMemberState,members:n.members.map(function(e){return V.build(G.build(e.userId,e.nickname,e.profileUrl,e.connectionStatus,e.lastSeenAt,e.metaData,e.isActive,e.friendDiscoveryKey,e.friendName),e.state,e.isBlockedByMe,e.isBlockingMe)}),last_message:function(e){return null!==e&&void 0!==e&&"object"==typeof e?e.messageType===P.MESSAGE_TYPE_USER?new O(O.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===P.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?G.build(n.inviter.userId,n.inviter.nickname,n.inviter.profileUrl,n.inviter.connectionStatus,n.inviter.lastSeenAt,n.inviter.metaData,n.inviter.isActive,n.inviter.friendDiscoveryKey,n.inviter.friendName):null})},w.createMyGroupChannelListQuery=function(){return new x(ie.getInstance().currentUser)},w.createPublicGroupChannelListQuery=function(){return new Q},w.memberState={ALL:0,JOINED:1,INVITED:2,INVITED_BY_FRIEND:3,INVITED_BY_NON_FRIEND:4},w.memberStateFilter={ALL:"all",JOINED:"joined_only",INVITED:"invited_only",INVITED_BY_FRIEND:"invited_by_friend",INVITED_BY_NON_FRIEND:"invited_by_non_friend"},w.superChannelFilter={ALL:"all",SUPER:"super",NON_SUPER:"nonsuper"},w.publicChannelFilter={ALL:"all",PUBLIC:"public",PRIVATE:"private"},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&&e!==w.memberState.INVITED_BY_FRIEND&&e!==w.memberState.INVITED_BY_NON_FRIEND?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n):ie.getInstance().hasLoggedIn()?void Z.getInstance().getGroupChannelCount(ie.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 _("Connection should be made first.",J.CONNECTION_REQUIRED),n))},w.getTotalUnreadMessageCount=function(e,n){if("function"==typeof e&&(n=e,e=null),null!==e&&void 0!==e&&!Array.isArray(e))return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);Z.getInstance().getTotalUnreadMessageCount(ie.getInstance().getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);var r=parseInt(e.unread_count);U(r,null,n)})},w.getTotalUnreadChannelCount=function(e){Z.getInstance().getTotalUnreadChannelCount(ie.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=[],t=null,r=null,i=null,a=null,s=null,o=null,l=null,u={isPublic:null,channelUrl:null},c=[],h=null;switch(arguments.length){case 2:if(arguments[0]instanceof ne){var I=arguments[0];n=I._inviteUserIds,e=[],t=I.isDistinct,r=I.isSuper,i=I.name,a=I.channelCover,s=I.data,l=I.customType,c=I._operatorIds,u.isPublic=I.isPublic,u.channelUrl=I.channelUrl,h=I.isEphemeral,o=arguments[1];break}e=arguments[0],t=!1,o=arguments[1];break;case 3:e=arguments[0],t=arguments[1],o=arguments[2];break;case 4:e=arguments[0],t=arguments[1],l=arguments[2],o=arguments[3];break;case 6:e=arguments[0],t=arguments[1],i=arguments[2],a=arguments[3],s=arguments[4],o=arguments[5];break;case 7:e=arguments[0],t=arguments[1],i=arguments[2],a=arguments[3],s=arguments[4],l=arguments[5],o=arguments[6]}if(!Array.isArray(e)||"boolean"!=typeof t&&null!==t||"boolean"!=typeof r&&null!==r||"boolean"!=typeof h&&null!==h||"boolean"!=typeof u.isPublic&&null!==u.isPublic||"string"!=typeof u.channelUrl&&null!==u.channelUrl||"string"!=typeof i&&null!==i&&void 0!==i||"string"!=typeof a&&d(a)&&null!==a&&void 0!==a||"string"!=typeof s&&null!==s&&void 0!==s||"string"!=typeof l&&null!==l&&void 0!==l)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),o);e.forEach(function(e){n.push(e.userId)}),w.createChannelWithUserIds(n,t,i,a,s,l,r,u,c,h,o)},w.createChannelWithUserIds=function(){var e=null,n=null,t=null,r=null,i=null,a=null,s=null,o=null,l=[],u={isPublic:null,channelUrl:null},c=null;switch(arguments.length){case 2:e=arguments[0],n=!1,a=arguments[1];break;case 3:e=arguments[0],n=arguments[1],a=arguments[2];break;case 4:e=arguments[0],n=arguments[1],s=arguments[2],a=arguments[3];break;case 6:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],i=arguments[4],a=arguments[5];break;case 7:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],i=arguments[4],s=arguments[5],a=arguments[6];break;case 8:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],i=arguments[4],s=arguments[5],o=arguments[6],a=arguments[7];break;case 9:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],i=arguments[4],s=arguments[5],o=arguments[6],u.isPublic=arguments[7].isPublic,u.channelUrl=arguments[7].channelUrl,a=arguments[8];break;case 10:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],i=arguments[4],s=arguments[5],o=arguments[6],u.isPublic=arguments[7].isPublic,u.channelUrl=arguments[7].channelUrl,l=arguments[8],a=arguments[9];break;case 11:e=arguments[0],n=arguments[1],t=arguments[2],r=arguments[3],i=arguments[4],s=arguments[5],o=arguments[6],u.isPublic=arguments[7].isPublic,u.channelUrl=arguments[7].channelUrl,l=arguments[8],c=arguments[9],a=arguments[10]}if(!ie.getInstance().hasLoggedIn())return void U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),a);if(!Array.isArray(e)||"boolean"!=typeof n&&null!==n||"boolean"!=typeof o&&null!==o||"boolean"!=typeof c&&null!==c||"boolean"!=typeof u.isPublic&&null!==u.isPublic||"string"!=typeof u.channelUrl&&null!==u.channelUrl||"string"!=typeof t&&null!==t&&void 0!==t||"string"!=typeof r&&d(r)&&null!==r&&void 0!==r||"string"!=typeof i&&null!==i&&void 0!==i||"string"!=typeof s&&null!==s&&void 0!==s)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),a);var h=e.filter(function(e,n,t){return n===t.indexOf(e)}),I=ie.getInstance().currentUser;h.push(I.userId),Z.getInstance().createGroupChannel(h,n,t,r,i,s,o,u,l,c,function(e,n){if(n)return void U(null,n,a);var t=new w(e);w.cachedChannels[t.url]=t,U(t,null,a)})},w.cachedChannels={},w.clearCache=function(){w.cachedChannels={}},w.removeCachedChannel=function(e){delete w.cachedChannels[e]},w.upsert=function(e){var n=new w(e);if(w.cachedChannels.hasOwnProperty(n.url)){if(n.isEphemeral){var t=w.cachedChannels[n.url];e.last_message=t.lastMessage,e.unread_message_count=t.unreadMessageCount}w.cachedChannels[n.url].update(e)}else w.cachedChannels[n.url]=n;return w.cachedChannels[n.url]},w.getChannelWithoutCache=function(e,n){if(!e)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);Z.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 _("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){ie.getInstance().markAsReadAll(e)};var H=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):M.CHANNEL_TYPE_GROUP),this.isGroupChannel=function(){return this.channelType===M.CHANNEL_TYPE_GROUP},this.isOpenChannel=function(){return this.channelType===M.CHANNEL_TYPE_OPEN}};H.CATEGORY_NONE=0,H.CATEGORY_CHANNEL_ENTER=10102,H.CATEGORY_CHANNEL_EXIT=10103,H.CATEGORY_USER_CHANNEL_MUTE=10201,H.CATEGORY_USER_CHANNEL_UNMUTE=10200,H.CATEGORY_USER_CHANNEL_BAN=10601,H.CATEGORY_USER_CHANNEL_UNBAN=10600,H.CATEGORY_CHANNEL_FREEZE=10701,H.CATEGORY_CHANNEL_UNFREEZE=10700,H.CATEGORY_TYPING_START=10900,H.CATEGORY_TYPING_END=10901,H.CATEGORY_CHANNEL_JOIN=1e4,H.CATEGORY_CHANNEL_LEAVE=10001,H.CATEGORY_CHANNEL_INVITE=10020,H.CATEGORY_CHANNEL_DECLINE_INVITE=10022,H.CATEGORY_CHANNEL_PROP_CHANGED=11e3,H.CATEGORY_CHANNEL_DELETED=12e3,H.CATEGORY_CHANNEL_META_DATA_CHANGED=11100,H.CATEGORY_CHANNEL_META_COUNTERS_CHANGED=11200,H.CATEGORY_CHANNEL_HIDE=13e3;var k=function(e){e&&(this.category=e.hasOwnProperty("cat")?parseInt(e.cat):0)};k.CATEGORY_USER_BLOCK=20001,k.CATEGORY_USER_UNBLOCK=2e4,k.CATEGORY_FRIEND_DISCOVERED=20900;var F=function(e){e&&(this.reader=new G(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):M.CHANNEL_TYPE_GROUP)},G=function(e){this.nickname="",this.profileUrl="",this.userId="",this.connectionStatus="",this.lastSeenAt=null,this.metaData={},this.isActive=!0,this.friendDiscoveryKey=null,this.friendName=null,this.getOriginalProfileUrl=function(){var e="";if(e=this.profileUrl.indexOf("://")>-1?this.profileUrl.split("/")[2]:this.profileUrl.split("/")[0],e=e.split("?")[0],(e.indexOf("sendbird.com")>-1||e.indexOf("intoz.com")>-1)&&this.profileUrl.indexOf(e+"/profile_images/")>-1){var n=this.profileUrl.replace("profile_images/","");return n===this.profileUrl?"":n}return""},this._update=function(e){e.hasOwnProperty("guest_id")&&(this.userId=String(e.guest_id)),e.hasOwnProperty("user_id")&&(this.userId=String(e.user_id)),e.hasOwnProperty("name")&&(this.nickname=String(e.name)),e.hasOwnProperty("nickname")&&(this.nickname=String(e.nickname)),e.hasOwnProperty("image")&&(this.profileUrl=String(e.image)),e.hasOwnProperty("profile_url")&&(this.profileUrl=String(e.profile_url)),e.hasOwnProperty("is_online")?e.is_online===G.NON_AVAILABLE?this.connectionStatus=G.NON_AVAILABLE:this.connectionStatus=e.is_online?G.ONLINE:G.OFFLINE:this.connectionStatus=G.NON_AVAILABLE,e.hasOwnProperty("last_seen_at")?this.lastSeenAt=parseInt(e.last_seen_at):this.lastSeenAt=0,e.hasOwnProperty("metadata")?this.metaData=e.metadata:this.metaData={},e.hasOwnProperty("is_active")?this.isActive="undefined"==typeof e.is_active||e.is_active:this.isActive=!0,e.hasOwnProperty("friend_discovery_key")?this.friendDiscoveryKey=e.friend_discovery_key:this.friendDiscoveryKey=null,e.hasOwnProperty("friend_name")?this.friendName=e.friend_name:this.friendName=null},this._updateMetaData=function(e,n){var t=this,r=Object.keys(e);n?r.forEach(function(e){delete t.metaData[e]}):r.forEach(function(n){t.metaData[n]=e[n]})},this.createMetaData=function(e,n){var t=this;return"function"==typeof e&&1===arguments.length&&(n=e,e={}),"object"!=typeof e||d(e)||Array.isArray(e)?void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n):ie.getInstance().hasLoggedIn()?void Z.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 _("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||d(e)||Array.isArray(e)||"boolean"!=typeof n?void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),t):ie.getInstance().hasLoggedIn()?void Z.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 _("Connection should be made first.",J.CONNECTION_REQUIRED),t))},this.deleteAllMetaData=function(e){var n=this,t=n.metaData;if(!ie.getInstance().hasLoggedIn())return void(e&&U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),e));Z.getInstance().deleteAllUserMetaData(n.userId,function(r,i){if(i)return void U(null,i,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 _("Invalid parameter.",J.INVALID_PARAMETER),n);if(!ie.getInstance().hasLoggedIn())return void(n&&U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),n));var r={};r[e]="",Z.getInstance().deleteUserMetaData(t.userId,e,function(e,i){if(i)return void U(null,i,n);t._updateMetaData(r,!0),U(e,null,n)})},this.serialize=function(){var e=JSON.parse(JSON.stringify(this));return E(e)},e&&this._update(e)};G.NON_AVAILABLE="nonavailable",G.ONLINE="online",G.OFFLINE="offline",G.build=function(e,n,t,r,i,a,s,o,l){return{user_id:e,nickname:n,profile_url:t,is_online:r,last_seen_at:i,metadata:a,is_active:s,friend_discovery_key:o,friend_name:l}},G.buildFromSerializedData=function(e){var n=f(e);return new G(G.build(n.userId,n.nickname,n.profileUrl,n.connectionStatus,n.lastSeenAt,n.metaData,n.isActive,n.friendDiscoveryKey,n.friendName))};var V=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(G,V),V.JOINED="joined",V.INVITED="invited",V.build=function(e,n,t,r){var i=e;return i.state=n,i.is_blocked_by_me=t,i.is_blocking_me=r,i},V.buildFromSerializedData=function(e){var n=f(e);return new V(V.build(G.build(n.userId,n.nickname,n.profileUrl,n.connectionStatus,n.lastSeenAt,n.metaData,n.isActive,n.friendDiscoveryKey,n.friendName),n.state,n.isBlockedByMe,n.isBlockingMe))};var Y=function(e,n,t){this.isAckRequired=function(){return"MESG"===this.command||"FILE"===this.command||"ENTR"===this.command||"EXIT"===this.command||"READ"===this.command||"MEDI"===this.command||"FEDI"===this.command},this.encode=function(){return this.command+this.payload+"\n"},this.decode=function(e){e=e.trim(),this.command=e.substring(0,4),this.payload=e.substring(4)},this.getJsonElement=function(){return JSON.parse(this.payload)},this.isRequestIdCommand=function(){return this.isAckRequired()||"EROR"===this.command},this.command,this.payload,this.requestId;var r=this;if(0!==arguments.length){var i;switch(arguments.length){case 1:var a=arguments[0];if(!a||a.length<=4)return r.command="NOOP",void(r.payload="{}");if(a=a.trim(),r.command=a.substring(0,4),r.payload=a.substring(4),r.isRequestIdCommand()){var s=r.getJsonElement();s&&(r.requestId=s.hasOwnProperty("req_id")?s.req_id:"")}break;case 3:i=arguments[2];case 2:var o=arguments[0],l=arguments[1];i=i||"",r.command=o,r.requestId=i,r.requestId||r.isRequestIdCommand()&&(r.requestId=Y.generateRequestId()),l.req_id=r.requestId,r.payload=JSON.stringify(l)}}};Y.bMessage=function(e,n,t,r,i,a,s){var o={};return o.channel_url=e,o.message=n,o.data=t,o.mentioned_user_ids=[],Array.isArray(i)&&i.length>0&&(o.mentioned_user_ids=i),r&&(o.custom_type=r),a.length>0&&(o.target_langs=a),s&&s!==te.PushNotificationDeliveryOption.DEFAULT&&(o.push_option=s),new Y("MESG",o)},Y.bRead=function(e){var n={};return n.channel_url=e,new Y("READ",n)},Y.bTypeStart=function(e,n){var t={};return t.channel_url=e,t.time=n,new Y("TPST",t)},Y.bTypeEnd=function(e,n){var t={};return t.channel_url=e,t.time=n,new Y("TPEN",t)},Y.bFile=function(e,n,t,r,i,a,s,o,l,u,c,d){var h={};h.channel_url=n,h.url=t,h.name=r||"",h.type=i||"",h.size=a||0,h.custom=s,o&&(h.custom_type=o),l&&(h.thumbnails=l),u&&(h.require_auth=u),h.mentioned_user_ids=[];for(var I in c){var _=c[I];h.mentioned_user_ids.push(String(_))}return d&&d!==re.PushNotificationDeliveryOption.DEFAULT&&(h.push_option=d),new Y("FILE",h,e)},Y.bPing=function(){var e={};return e.id=(new Date).getTime(),new Y("PING",e)},Y.bEnter=function(e){var n={};return n.channel_url=e,new Y("ENTR",n)},Y.bExit=function(e){var n={};return n.channel_url=e,new Y("EXIT",n)},Y.bUpdateUserMessage=function(e,n,t,r,i){var a={};return a.channel_url=e,a.msg_id=n,null!=t&&t!==undefined&&(a.message=t),null!=r&&r!==undefined&&(a.data=r),null!=i&&i!==undefined&&(a.custom_type=i),new Y("MEDI",a)},Y.bUpdateFileMessage=function(e,n,t,r){var i={};return i.channel_url=e,i.msg_id=n,null!=t&&t!==undefined&&(i.data=t),null!=r&&r!==undefined&&(i.custom_type=r),new Y("FEDI",i)},Y.requestIdSeed=(new Date).getTime(),Y.generateRequestId=function(){return Y.requestIdSeed++,String(Y.requestIdSeed)};var B=function(e){this.isLoading=!1,this.hasNext=!0,this.limit=20,this.mutedMemberFilter=B.MUTED_MEMBER_FILTER.ALL,this.operatorFilter=B.OPERATOR_FILTER.ALL;var n="",t=this;this.next=function(r){return t.hasNext?t.isLoading?void U(null,new _("Query in progress.",J.QUERY_IN_PROGRESS),r):"string"!=typeof t.mutedMemberFilter||[B.MUTED_MEMBER_FILTER.ALL,B.MUTED_MEMBER_FILTER.MUTED,B.MUTED_MEMBER_FILTER.UNMUTED].indexOf(t.mutedMemberFilter.toLowerCase())<0||"string"!=typeof t.operatorFilter||[B.OPERATOR_FILTER.ALL,B.OPERATOR_FILTER.OPERATOR,B.OPERATOR_FILTER.NONOPERATOR].indexOf(t.operatorFilter.toLowerCase())<0?void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),r):(t.isLoading=!0,void Z.getInstance().loadGroupChannelMemberList(e,n,t.limit,t.mutedMemberFilter,t.operatorFilter,function(e,i){if(i)return t.isLoading=!1,void U(null,i,r);var a=e;(!(n=String(a.next))||n.length<=0)&&(t.hasNext=!1);var s=a.members.map(function(e){return new V(e)});t.isLoading=!1,U(s,null,r)})):void U([],null,r)}};B.MUTED_MEMBER_FILTER={ALL:"all",MUTED:"muted",UNMUTED:"unmuted"},B.OPERATOR_FILTER={ALL:"all",OPERATOR:"operator",NONOPERATOR:"nonoperator"};var x=function(e){this.isLoading=!1,this.hasNext=!0,this.limit=20,this.includeEmpty=!1,this.order=x.ORDER_LATEST_LAST_MESSAGE,this.userIdsFilter=[],this.userIdsFilterExactMatch=!1,this.queryType="AND";var n={userIds:[],includeMode:!0,queryType:Q.USER_IDS_INCLUDE_QUERY_TYPE.AND};this._userIdsExactFilter=[],this._userIdsIncludeFilter=[],this._userIdsIncludeFilterQueryType=Q.USER_IDS_INCLUDE_QUERY_TYPE.AND,u?(this.userIdsExactFilter=this._userIdsExactFilter,this.userIdsIncludeFilter=this._userIdsIncludeFilter,this.userIdsIncludeFilterQueryType=this._userIdsIncludeFilterQueryType):(Object.defineProperty(this,"userIdsExactFilter",{get:function(){return this._userIdsExactFilter},set:function(e){if(!Array.isArray(e))throw new _("Invalid parameter.",J.INVALID_PARAMETER);this._userIdsExactFilter=e,this._userIdsIncludeFilter=[],n={userIds:this._userIdsExactFilter,includeMode:!1}}}),Object.defineProperty(this,"userIdsIncludeFilter",{get:function(){return this._userIdsIncludeFilter},set:function(e){if(!Array.isArray(e))throw new _("Invalid parameter.",J.INVALID_PARAMETER);this._userIdsIncludeFilter=e, +this._userIdsExactFilter=[],n={userIds:this._userIdsIncludeFilter,includeMode:!0}}}),Object.defineProperty(this,"userIdsIncludeFilterQueryType",{get:function(){return this._userIdsIncludeFilterQueryType},set:function(e){this._userIdsIncludeFilterQueryType=e,n={queryType:this._userIdsIncludeFilterQueryType}}})),this.nicknameContainsFilter="",this.channelNameContainsFilter="",this.memberStateFilter=w.memberStateFilter.ALL,this.customTypeFilter="",this.customTypesFilter=[],this.channelUrlsFilter=[],this.superChannelFilter=w.superChannelFilter.ALL,this.publicChannelFilter=w.publicChannelFilter.ALL,this.customTypeStartsWithFilter=null;var t=e,r="",i=this;this.next=function(e){if(!i.hasNext)return void U([],null,e);if(i.isLoading)return void U(null,new _("Query in progress.",J.QUERY_IN_PROGRESS),e);if(null!==i.nicknameContainsFilter&&"undefined"!=typeof i.nicknameContainsFilter||(i.nicknameContainsFilter=""),null!==i.channelNameContainsFilter&&"undefined"!=typeof i.channelNameContainsFilter||(i.channelNameContainsFilter=""),null!==i.customTypeStartsWithFilter&&"string"!=typeof i.customTypeStartsWithFilter)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),e);if(!Array.isArray(i._userIdsExactFilter)||!Array.isArray(i._userIdsIncludeFilter)||"string"!=typeof i._userIdsIncludeFilterQueryType||[Q.USER_IDS_INCLUDE_QUERY_TYPE.AND,Q.USER_IDS_INCLUDE_QUERY_TYPE.OR].indexOf(i._userIdsIncludeFilterQueryType.toUpperCase())<0)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),e);if("number"==typeof i.memberStateFilter){if(typeof i.memberStateFilter<0||typeof i.memberStateFilter>4)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),e);var a=["all","joined_only","invited_only","invited_by_friend","invited_by_non_friend"];i.memberStateFilter=a[i.memberStateFilter]}if(!h(i.limit)||!Array.isArray(i.userIdsFilter)||"boolean"!=typeof i.userIdsFilterExactMatch||"string"!=typeof i.customTypeFilter||!Array.isArray(i.customTypesFilter)||"string"!=typeof i.queryType||["AND","OR"].indexOf(i.queryType.toUpperCase())<0||"string"!=typeof i.order||[x.ORDER_CHRONOLOGICAL,x.ORDER_LATEST_LAST_MESSAGE,x.CHANNEL_NAME_ALPHABETICAL].indexOf(i.order.toLowerCase())<0||"string"!=typeof i.memberStateFilter||[w.memberStateFilter.ALL,w.memberStateFilter.JOINED,w.memberStateFilter.INVITED,w.memberStateFilter.INVITED_BY_FRIEND,w.memberStateFilter.INVITED_BY_NON_FRIEND].indexOf(i.memberStateFilter.toLowerCase())<0||"string"!=typeof i.nicknameContainsFilter||"string"!=typeof i.channelNameContainsFilter||!Array.isArray(i.channelUrlsFilter)||"string"!=typeof i.superChannelFilter||[w.superChannelFilter.ALL,w.superChannelFilter.SUPER,w.superChannelFilter.NON_SUPER].indexOf(i.superChannelFilter.toLowerCase())<0||"string"!=typeof i.publicChannelFilter||[w.publicChannelFilter.ALL,w.publicChannelFilter.PUBLIC,w.publicChannelFilter.PRIVATE].indexOf(i.publicChannelFilter.toLowerCase())<0)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),e);Array.isArray(i.userIdsFilter)&&i.userIdsFilter.length>0&&(n={userIds:i.userIdsFilter,includeMode:!i.userIdsFilterExactMatch,queryType:i.queryType}),i.isLoading=!0,Z.getInstance().loadUserGroupChannelList(t.userId,r,i.limit,i.includeEmpty,i.order,n,i.nicknameContainsFilter,i.channelNameContainsFilter,i.channelUrlsFilter,i.customTypeFilter,i.customTypesFilter,i.customTypeStartsWithFilter,i.memberStateFilter,i.superChannelFilter,i.publicChannelFilter,function(n,t){if(t)return i.isLoading=!1,void U(null,t,e);var a=n;(!(r=String(a.next))||r.length<=0)&&(i.hasNext=!1);var s=a.channels,o=[];for(var l in s){var u=w.upsert(s[l]);o.push(u)}i.isLoading=!1,U(o,null,e)})}};x.ORDER_LATEST_LAST_MESSAGE="latest_last_message",x.ORDER_CHRONOLOGICAL="chronological",x.CHANNEL_NAME_ALPHABETICAL="channel_name_alphabetical",x.MEMBER_STATE_INVITED_ONLY="invited_only",x.MEMBER_STATE_JOINED_ONLY="joined_only",x.MEMBER_STATE_ALL="all";var Q=function(){var e="";this.isLoading=!1,this.hasNext=!0,this.limit=20,this.includeEmpty=!0,this.order=Q.ORDER_CHRONOLOGICAL,this.channelNameContainsFilter=null,this.channelUrlsFilter=[],this.customTypesFilter=[],this.customTypeStartsWithFilter=null,this.superChannelFilter=w.superChannelFilter.ALL,this.membershipFilter=Q.MEMBERSHIP_TYPE.JOINED;var n=this;this.next=function(t){return ie.getInstance().hasLoggedIn()?n.hasNext?n.isLoading?void U(null,new _("Query in progress.",J.QUERY_IN_PROGRESS),t):!h(n.limit)||"boolean"!=typeof n.includeEmpty||!Array.isArray(n.customTypesFilter)||!Array.isArray(n.channelUrlsFilter)||null!==n.channelNameContainsFilter&&"string"!=typeof n.channelNameContainsFilter||null!==n.customTypeStartsWithFilter&&"string"!=typeof n.customTypeStartsWithFilter||"string"!=typeof n.order||[Q.ORDER_CHRONOLOGICAL,Q.ORDER_LATEST_LAST_MESSAGE,Q.CHANNEL_NAME_ALPHABETICAL].indexOf(n.order.toLowerCase())<0?void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),t):"string"!=typeof n.superChannelFilter||[w.superChannelFilter.ALL,w.superChannelFilter.SUPER,w.superChannelFilter.NON_SUPER].indexOf(n.superChannelFilter.toLowerCase())<0||"string"!=typeof n.membershipFilter||[Q.MEMBERSHIP_TYPE.ALL,Q.MEMBERSHIP_TYPE.JOINED].indexOf(n.membershipFilter.toLowerCase())<0?void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),t):(n.isLoading=!0,void Z.getInstance().loadPublicGroupChannelList(e,n.limit,n.includeEmpty,n.order,n.channelNameContainsFilter,n.channelUrlsFilter,n.customTypesFilter,n.customTypeStartsWithFilter,n.superChannelFilter,n.membershipFilter,function(r,i){if(i)return n.isLoading=!1,void U(null,i,t);var a=r;(!(e=String(a.next))||e.length<=0)&&(n.hasNext=!1);var s=a.channels,o=[];for(var l in s){var u=w.upsert(s[l]);o.push(u)}n.isLoading=!1,U(o,null,t)})):void U([],null,t):void(t&&U(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED),t))}};Q.ORDER_CHRONOLOGICAL="chronological",Q.CHANNEL_NAME_ALPHABETICAL="channel_name_alphabetical",Q.USER_IDS_INCLUDE_QUERY_TYPE={AND:"AND",OR:"OR"},Q.MEMBERSHIP_TYPE={ALL:"all",JOINED:"joined"};var W=function(e){this.isLoading=!1;var n=e,t=this;this.next=function(e,r,i,a){if(t.isLoading)return void U(null,new _("Query in progress.",J.QUERY_IN_PROGRESS),a);if(4!==arguments.length){if("function"!=typeof a){var s=Array.prototype.slice.call(arguments);"function"==typeof s.slice(-1)[0]&&(a=s.pop())}return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),a)}if(!h(e)||!h(r)||"boolean"!=typeof i)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),a);t.isLoading=!0,Z.getInstance().messageList(n.isOpenChannel(),n.url,e,0,r,!1,i,"","",function(e,r){if(r)return t.isLoading=!1,void U(null,r,a);var i=e.messages,s=[];for(var o in i){var l=P.build(i[o],n);l&&s.push(l)}t.isLoading=!1,U(s,null,a)})},this.prev=function(e,r,i,a){if(t.isLoading)return void U(null,new _("Query in progress.",J.QUERY_IN_PROGRESS),a);if(4!==arguments.length){if("function"!=typeof a){var s=Array.prototype.slice.call(arguments);"function"==typeof s.slice(-1)[0]&&(a=s.pop())}return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),a)}if(!h(e)||!h(r)||"boolean"!=typeof i)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),a);t.isLoading=!0,Z.getInstance().messageList(n.isOpenChannel(),n.url,e,r,0,!1,i,"","",function(e,r){if(r)return t.isLoading=!1,void U(null,r,a);var i=e.messages,s=[];for(var o in i){var l=P.build(i[o],n);l&&s.push(l)}t.isLoading=!1,U(s,null,a)})},this.load=function(e,r,i,a,s){if(t.isLoading)return void U(null,new _("Query in progress.",J.QUERY_IN_PROGRESS),s);if(5!==arguments.length){if("function"!=typeof s){var o=Array.prototype.slice.call(arguments);"function"==typeof o.slice(-1)[0]&&(s=o.pop())}return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),s)}if(!h(e)||!h(r)||!h(i)||"boolean"!=typeof a)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),s);t.isLoading=!0,Z.getInstance().messageList(n.isOpenChannel(),n.url,e,r,i,!0,a,"","",function(e,r){if(r)return t.isLoading=!1,void U(null,r,s);var i=e.messages,a=[];for(var o in i){var l=P.build(i[o],n);l&&a.push(l)}t.isLoading=!1,U(a,null,s)})}},K=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 _("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||!h(n.limit)?void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),t):(n.isLoading=!0,void Z.getInstance().loadOpenChannelList(e,n.limit,n.nameKeyword,n.urlKeyword,n.customType,function(r,i){if(i)return n.isLoading=!1,void U(null,i,t);var a=r;try{e=String(a.next)}catch(n){e=""}e||(n.hasNext=!1);var s=a.channels,o=[];s.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,i,a,s){if(3!==arguments.length&&4!==arguments.length){if("function"!=typeof s){var o=Array.prototype.slice.call(arguments);"function"==typeof o.slice(-1)[0]&&(s=o.pop())}return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),s)}if("function"==typeof a&&(s=a,a=""),a.toString().toLowerCase()===P.MESSAGE_TYPE_ADMIN||a===p.MessageTypeFilter.ADMIN?a="ADMM":a.toString().toLowerCase()===P.MESSAGE_TYPE_USER||a===p.MessageTypeFilter.USER?a="MESG":a.toString().toLowerCase()===P.MESSAGE_TYPE_FILE||a===p.MessageTypeFilter.FILE?a="FILE":null!==a&&void 0!==a&&a!==p.MessageTypeFilter.ALL||(a=""),!h(e)||"boolean"!=typeof i||"string"!=typeof a)return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),s);if(r.hasMore){if(r.isLoading)return void U(null,new _("Query in progress.",J.QUERY_IN_PROGRESS),s);r.isLoading=!0,Z.getInstance().messageList(n.isOpenChannel(),n.url,t,e,0,!1,i,a,"",function(i,a){if(a)return r.isLoading=!1,void U(null,a,s);var o=i.messages,l=[];for(var u in o){var c=P.build(o[u],n);c&&(l.push(c),c.createdAt<=t&&(t=c.createdAt))}(l.length<=0||l.length0&&(i=l(n)),u(r,null===i?{}:{custom_types:i},t)},this.getTotalUnreadChannelCount=function(e,n){var t=Z.API_USERS_USERID_UNREAD_CHANNEL_COUNT.replace("%s",encodeURIComponent(e));u(t,n)},this.checkRouting=function(e){if(ie.getInstance()&&ie.getInstance().customApiHost&&ie.getInstance().customWsHost)"function"==typeof e&&e({API_HOST:ie.getInstance().customApiHost,WS_HOST:ie.getInstance().customWsHost});else{var t=(new Date).getTime()/1e3;0===n||n-t>300?C(Z.API_ROUTING_URL.replace("%s",S),{},"GET",{SendBird:o+S},function(a,s){if(s)return void e(null,new _("Server is unreachable.",J.NETWORK_ROUTING_ERROR));r=a.ws_server,i=a.api_server,n=t,"function"==typeof e&&e({API_HOST:i,WS_HOST:r})}):e({API_HOST:ie.getInstance().getCurrentApiHost(),WS_HOST:ie.getInstance().getCurrentWsHost()},null)}};var t=function(e,n,t,r,i,a,l,u,d,h){if(!ie.getInstance().hasLoggedIn())return void(l&&l(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED)));Z.getInstance().checkRouting(function(n,I){if(I)l(null,new _("Request failed.",J.REQUEST_FAILED));else{var p=N();p.open("POST",n.API_HOST+e,!0),p.setRequestHeader("SendBird",o+S),p.setRequestHeader("Session-Key",Z.getInstance().sessionKey);var E=s?new s:new FormData;r&&"undefined"!=typeof Blob?E.append("file",new Blob([t],{type:r}),t.name):E.append("file",t,t.name),a&&E.append("channel_url",a);for(var f in i){var A=parseInt(f)+1;E.append("thumbnail"+A,i[f].maxWidth+","+i[f].maxHeight)}p.onload=function(){d&&d[h]&&delete d[h];p.status>=200&&p.status<400?c(null,JSON.parse(p.responseText),l):c({status:p.status,statusText:p.statusText,response:p.responseText},null,l)},p.onerror=function(e){d&&d[h]&&delete d[h],l(null,new _(p.statusText,J.REQUEST_FAILED))},p.onabort=function(e){d&&d[h]&&delete d[h],l(null,new _("File upload has been cancelled.",J.REQUEST_CANCELLED))},p.upload.onprogress=function(e){e.lengthComputable&&e.loaded>=e.total&&d&&d[h]&&delete d[h],u&&u(e)},E.oldIE?(p.setRequestHeader("Content-Type","multipart/form-data; boundary="+E.boundary),p.send(E.toString())):p.send(E),d&&(d[h]=p)}})},a=function(e,n,t){if("function"==typeof n&&(t=n,n={}),!ie.getInstance().hasLoggedIn())return void(t&&t(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED)));Z.getInstance().checkRouting(function(r,i){i?t(null,new _("Request failed.",J.REQUEST_FAILED)):C(r.API_HOST+e,n,"DELETE",{"Session-Key":Z.getInstance().sessionKey,SendBird:o+S},t)})},l=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={}),!ie.getInstance().hasLoggedIn())return void(t&&t(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED)));var r,i="";if(n){for(var a in n)""!==i&&(i+="&"),i+=a+"="+n[a];r=e+"?"+i}else r=e;Z.getInstance().checkRouting(function(e,i){i?t(null,new _("Request failed.",J.REQUEST_FAILED)):C(e.API_HOST+r,n,"GET",{"Session-Key":Z.getInstance().sessionKey,SendBird:o+S},t)})},h=function(e,n,t){if("function"==typeof n&&(t=n,n={}),!ie.getInstance().hasLoggedIn())return void(t&&t(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED)));Z.getInstance().checkRouting(function(r,i){i?t(null,i):C(r.API_HOST+e,n,"POST",{"Session-Key":Z.getInstance().sessionKey,SendBird:o+S},t)})},I=function(e,n,t){if("function"==typeof n&&(t=n,n={}),!ie.getInstance().hasLoggedIn())return void(t&&t(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED)));Z.getInstance().checkRouting(function(r,i){i||C(r.API_HOST+e,n,"PUT",{"Session-Key":Z.getInstance().sessionKey,SendBird:o+S},t)})};this.addFriends=function(e,n,t){var r=Z.API_FRIENDS.replace("%s",encodeURIComponent(e));h(r,{user_ids:n},t)},this.deleteFriends=function(e,n,t){var r=Z.API_FRIENDS.replace("%s",encodeURIComponent(e));n.length>0&&(r+="?user_ids=",n.forEach(function(e){r+=encodeURIComponent(e)+","}),r=r.substring(0,r.length-1)),a(r,{},t)},this.deleteFriendDiscoveries=function(e,n,t){var r=Z.API_FRIENDS_DISCOVERIES.replace("%s",encodeURIComponent(e));n.length>0&&(r+="?friend_discovery_keys=",n.forEach(function(e){r+=encodeURIComponent(e)+","}),r=r.substring(0,r.length-1)),a(r,{},t)},this.uploadFriendDiscoveries=function(e,n,t){var r=Z.API_FRIENDS_DISCOVERIES.replace("%s",encodeURIComponent(e)),i={friend_discoveries:[]};n.forEach(function(e){i.friend_discoveries.push({friend_discovery_key:e.friendDiscoveryKey,friend_name:"string"==typeof e.friendName||e.friendName?e.friendName:null})}),I(r,i,t)},this.getFriendChangeLogsByToken=function(e,n,t){var r=Z.API_FRIENDS_CHANGE_LOGS.replace("%s",encodeURIComponent(e)),i={};n&&(i.token=n),u(r,i,t)},this.friendListQuery=function(e,n,t,r){var i=Z.API_FRIENDS.replace("%s",encodeURIComponent(e)),a={limit:t,token:encodeURIComponent(n)};u(i,a,r)},this.createUserMetaData=function(e,n,t){var r=Z.API_USERS_USERID_METADATA.replace("%s",encodeURIComponent(e)),i={};i.metadata=n,h(r,i,t)},this.updateUserMetaData=function(e,n,t,r){var i=Z.API_USERS_USERID_METADATA.replace("%s",encodeURIComponent(e)),a={};a.metadata=n,a.upsert=t,I(i,a,r)},this.deleteAllUserMetaData=function(e,n){var t=Z.API_USERS_USERID_METADATA.replace("%s",encodeURIComponent(e));a(t,{},n)},this.deleteUserMetaData=function(e,n,t){var r=Z.API_USERS_USERID_METADATA_KEY.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));a(r,{},t)},this.resetMyHistory=function(e,n){var t=Z.API_GROUPCHANNELS_RESET_USER_HISTORY.replace("%s",encodeURIComponent(e));I(t,{},n)},this.groupChannelInvite=function(e,n,t){var r=Z.API_GROUPCHANNELS_CHANNELURL_INVITE.replace("%s",encodeURIComponent(e)),i={},a=[];try{Array.isArray(n)?a=n:a.push(n)}catch(e){t(null,new _("Invalid parameter.",J.INVALID_PARAMETER))}i.user_ids=a,h(r,i,t)},this.acceptInvitation=function(e,n,t){var r=Z.API_GROUPCHANNELS_CHANNELURL_ACCEPT_INVITATION.replace("%s",encodeURIComponent(e)),i={};i.user_id=n,I(r,i,t)},this.declineInvitation=function(e,n,t){var r=Z.API_GROUPCHANNELS_CHANNELURL_DECLINE_INVITATION.replace("%s",encodeURIComponent(e)),i={};i.user_id=n,I(r,i,t)},this.groupChannelHide=function(e,n,t,r){var i=Z.API_GROUPCHANNELS_CHANNELURL_HIDE.replace("%s",encodeURIComponent(e)),a={};a.user_id=n,a.hide_previous_messages=t,I(i,a,r)},this.publicGroupChannelJoin=function(e,n,t){var r=Z.API_GROUPCHANNELS_CHANNELURL_JOIN.replace("%s",encodeURIComponent(e)),i={};i.user_id=n,I(r,i,t)},this.groupChannelLeave=function(e,n,t){var r=Z.API_GROUPCHANNELS_CHANNELURL_LEAVE.replace("%s",encodeURIComponent(e)),i={};i.user_id=n,I(r,i,t)},this.groupChannelMarkAsRead=function(e,n,t){var r=Z.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MARKASREAD.replace("%s",encodeURIComponent(e)),i={};i.user_id=n,I(r,i,t)},this.groupChannelMarkAsReadAll=function(e,n,t){var r=Z.API_USERS_USERID_MARKASREADALL.replace("%s",encodeURIComponent(e)),i={};n&&(i.channel_urls=n),I(r,i,t)},this.messageList=function(e,n,t,r,i,a,s,o,l,c){var d;d=e?String(Z.API_OPENCHANNELS_CHANNELURL_MESSAGES.replace("%s",n)):String(Z.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(i),h.include=String(a),h.reverse=String(s),o&&(h.message_type=String(o)),l&&(h.custom_type=String(l)),u(d,h,c)},this.messageListByID=function(e,n,t,r,i,a,s,o,l,c){var d;d=e?String(Z.API_OPENCHANNELS_CHANNELURL_MESSAGES.replace("%s",n)):String(Z.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(i),h.include=String(a),h.reverse=String(s),o&&(h.message_type=String(o)),l&&(h.custom_type=String(l)),u(d,h,c)},this.login=function(e,n,t){var r=Z.API_USERS_USERID_LOGIN.replace("%s",encodeURIComponent(e)),i={};i.app_id=S,n&&(i.access_token=n),h(r,i,function(e,n){n?t(null,n):(Z.getInstance().sessionKey=e.key,Z.getInstance().ekey=e.ekey,t(e,n))})},this.updateUserInfo=function(e,n,t,r){var i={};n&&(i.nickname=n),t&&(i.profile_url=t);var a=String(Z.API_USERS_USERID).replace("%s",encodeURIComponent(e));I(a,i,r)},this.updateCurrentUserInfoWithFile=function(e,n,t,r){if("string"==typeof t)this.updateUserInfo(e,n,t,r);else{var i=s?new s:new FormData;i.append("nickname",n),i.append("profile_file",t,t.name);var a=String(Z.API_USERS_USERID).replace("%s",encodeURIComponent(e));I(a,i,r)}},this.getGroupChannel=function(e,n,t,r){var i=Z.API_GROUPCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)),a={member:String(n),read_receipt:String(t)};u(i,a,r)},this.getOpenChannel=function(e,n){var t=Z.API_OPENCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e));u(t,n)},this.createGroupChannel=function(e,n,t,r,i,a,o,l,u,c,d){var I=Z.API_GROUPCHANNELS,_=[];"string"==typeof e?_.push(e):e.forEach(function(e){_.push(e)});var p,E=_.filter(function(e,n){return _.indexOf(e)===n}),f=l.isPublic,A=l.channelUrl;r&&"string"!=typeof r?(p=s?new s:new FormData,r&&p.append("cover_file",r,r.name),p.append("user_ids",E),null!==A&&p.append("channel_url",A),null!==n&&p.append("is_distinct",n),null!==o&&p.append("is_super",o),null!==f&&p.append("is_public",f),null!==c&&p.append("is_ephemeral",c),null!==t&&"string"==typeof t&&p.append("name",t),i&&p.append("data",i),a&&p.append("custom_type",a),Array.isArray(u)&&u.length>0&&p.append("operator_ids",u)):(p={},null!==r&&"string"==typeof r&&(p.cover_url=r),p.user_ids=E,null!==A&&(p.channel_url=A),null!==n&&(p.is_distinct=n),null!==o&&(p.is_super=o),null!==f&&(p.is_public=f),null!==c&&(p.is_ephemeral=c),null!==t&&"string"==typeof t&&(p.name=t),i&&(p.data=i),a&&(p.custom_type=a),Array.isArray(u)&&u.length>0&&(p.operator_ids=u)),h(I,p,d)},this.createOpenChannel=function(e,n,t,r,i,a){var o,l=String(Z.API_OPENCHANNELS);n&&"string"!=typeof n?(o=s?new s:new FormData,n&&o.append("cover_file",n,n.name),null!==e&&"string"==typeof e&&o.append("name",e),t&&o.append("data",t),r&&(Array.isArray(r)?o.append("operators",r):o.append("operators",[r])),i&&o.append("custom_type",i)):(o={},null!==n&&"string"==typeof n&&(o.cover_url=n),null!==e&&"string"==typeof e&&(o.name=e),t&&(o.data=t),r&&(Array.isArray(r)?o.operators=r:o.operators=[r]),i&&(o.custom_type=i)),h(l,o,a)},this.updateGroupChannel=function(e,n,t,r,i,a,o,l){var u,c=String(Z.API_GROUPCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)));r&&"string"!=typeof r?(u=s?new s:new FormData,null!==n&&u.append("is_distinct",n),null!==o&&u.append("is_public",o),r&&u.append("cover_file",r,r.name),null!==t&&"string"==typeof t&&u.append("name",t),null!==i&&"string"==typeof i&&u.append("data",i),null!==a&&"string"==typeof a&&u.append("custom_type",a)):(u={},null!==n&&(u.is_distinct=n),null!==o&&(u.is_public=o),null!==r&&"string"==typeof r&&(u.cover_url=r),null!==t&&"string"==typeof t&&(u.name=t),null!==i&&"string"==typeof i&&(u.data=i),null!==a&&"string"==typeof a&&(u.custom_type=a)),I(c,u,l)},this.updateOpenChannel=function(e,n,t,r,i,a,o){var l,u=String(Z.API_OPENCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)));t&&"string"!=typeof t?(l=s?new s: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!==i&&(Array.isArray(i)?l.append("operators",i):l.append("operators",[i])),null!==a&&"string"==typeof a&&l.append("custom_type",a)):(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!==i&&(Array.isArray(i)?l.operators=i:l.operators=[i]),null!==a&&"string"==typeof a&&(l.custom_type=a)),I(u,l,o)},this.deleteOpenChannel=function(e,n){var t=String(Z.API_OPENCHANNELS_CHANNELURL.replace("%s",encodeURIComponent(e)));a(t,{},n)},this.createMetaCounters=function(e,n,t,r){var i;i=e?Z.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):Z.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n));var a={};a.metacounter=t,h(i,a,r)},this.updateMetaCounters=function(e,n,t,r,i,a){var s;s=e?Z.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):Z.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n));var o={};switch(o.metacounter=t,o.upsert=r,i){case Z.UPDATE_META_COUNTER_MODE_SET:o.mode="set";break;case Z.UPDATE_META_COUNTER_MODE_INC:o.mode="increase";break;case Z.UPDATE_META_COUNTER_MODE_DEC:o.mode="decrease"}I(s,o,a)},this.getAllMetaCounters=function(e,n,t){this.getMetaCounters(e,n,{},t)},this.getMetaCounters=function(e,n,t,r){var i;i=e?Z.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):Z.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n));var a=l(t);u(i,{keys:a},r)},this.deleteMetaCounter=function(e,n,t,r){var i="";i=e?Z.API_OPENCHANNELS_CHANNELURL_METACOUNTER_KEY.replace("%s",encodeURIComponent(n)).replace("%s",t):Z.API_GROUPCHANNELS_CHANNELURL_METACOUNTER_KEY.replace("%s",encodeURIComponent(n)).replace("%s",t),a(i,{},r)},this.deleteAllMetaCounters=function(e,n,t){var r="";r=e?Z.API_OPENCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)):Z.API_GROUPCHANNELS_CHANNELURL_METACOUNTER.replace("%s",encodeURIComponent(n)),a(r,{},t)},this.createMetaData=function(e,n,t,r){var i="";i=e?Z.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):Z.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n));var a={},s={};for(var o in t){var l=t[o];s[o]=l}a.metadata=s,h(i,a,r)},this.updateMetaData=function(e,n,t,r,i){var a="";a=e?Z.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):Z.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n));var s={},o={};for(var l in t){var u=t[l];o[l]=u}s.metadata=o,s.upsert=r,I(a,s,i)},this.getAllMetaData=function(e,n,t){this.getMetaData(e,n,{},t)},this.getMetaData=function(e,n,t,r){var i="";i=e?Z.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):Z.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n));var a=l(t);u(i,{keys:a},r)},this.deleteMetaData=function(e,n,t,r){var i="";i=e?Z.API_OPENCHANNELS_CHANNELURL_METADATA_KEY.replace("%s",encodeURIComponent(n)).replace("%s",t):Z.API_GROUPCHANNELS_CHANNELURL_METADATA_KEY.replace("%s",encodeURIComponent(n)).replace("%s",t),a(i,{},r)},this.deleteAllMetaData=function(e,n,t){var r="";r=e?Z.API_OPENCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)):Z.API_GROUPCHANNELS_CHANNELURL_METADATA.replace("%s",encodeURIComponent(n)),a(r,{},t)},this.loadUserList=function(e,n,t,r,i,a){var s=Z.API_USERS,o={token:encodeURIComponent(e),limit:String(n)};if(!d(t))try{var l="";for(var c in t){var h=t[c];l+=encodeURIComponent(h)+","}l.length>1&&(l=l.substring(0,l.length-1)),o.user_ids=l}catch(e){}if(r&&!d(i)){var I="";i.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(s,o,a)},this.loadBlockedUserList=function(e,n,t,r){var i=Z.API_USERS_USERID_BLOCK.replace("%s",encodeURIComponent(e)),a={token:encodeURIComponent(n),limit:String(t)};u(i,a,r)},this.loadOpenChannelList=function(e,n,t,r,i,a){var s=Z.API_OPENCHANNELS,o={token:encodeURIComponent(e),limit:String(n)};null!==t&&(o.name_contains=encodeURIComponent(t)),r&&(o.url_contains=encodeURIComponent(r)),null!==i&&(o.custom_type=encodeURIComponent(i)),u(s,o,a)},this.uploadFile=function(e,n,r,i,a,s,o,l){t(Z.API_STORAGE_FILE,0,e,n,r,i,a,s,o,l)},this.uploadProfileImage=function(e,n){t(Z.API_STORAGE_PROFILE,0,e,"",[],"",n)},this.loadGroupChannelMemberList=function(e,n,t,r,i,a){var s=Z.API_GROUPCHANNELS_MEMBERS.replace("%url",encodeURIComponent(e)),o={token:encodeURIComponent(n),limit:t,muted_member_filter:r.toLowerCase(),operator_filter:i.toLowerCase()};u(s,o,a)},this.loadPublicGroupChannelList=function(e,n,t,r,i,a,s,o,l,c,d){var h=Z.API_GROUPCHANNELS,I={public_mode:w.publicChannelFilter.PUBLIC,token:encodeURIComponent(e),limit:String(n),show_member:!0,show_read_receipt:!0, +show_empty:String(t),order:r};if(i)try{I.name_contains=encodeURIComponent(i)}catch(e){}if(a.length>0)try{I.channel_urls=a.map(function(e){return encodeURIComponent(e)}).join(",")}catch(e){}if(s.length>0){var _="";s.forEach(function(e){_+=encodeURIComponent(e)+","}),_=_.substring(0,_.length-1),I.custom_types=_}o&&(I.custom_type_startswith=o),I.super_mode=l,I.public_membership_mode=c,u(h,I,d)},this.loadUserGroupChannelList=function(e,n,t,r,i,a,s,o,c,d,h,I,_,p,E,f){var A=Z.API_MYGROUPCHANNELS.replace("%s",encodeURIComponent(e)),g=a.userIds,m=!a.includeMode,v=a.queryType,N={token:encodeURIComponent(n),limit:String(t),show_member:!0,show_read_receipt:!0,show_empty:String(r),order:i,member_state_filter:_};if(h.length>0){var C="";h.forEach(function(e){C+=encodeURIComponent(e)+","}),C=C.substring(0,C.length-1),N.custom_types=C}else d&&(N.custom_type=encodeURIComponent(d));if(s)try{N.members_nickname_contains=encodeURIComponent(s)}catch(e){}if(o)try{N.name_contains=encodeURIComponent(o)}catch(e){}if(g.length>0)try{m?N.members_exactly_in=l(g):(N.members_include_in=l(g),N.query_type=v)}catch(e){}if(c.length>0)try{N.channel_urls=c.map(function(e){return encodeURIComponent(e)}).join(",")}catch(e){}N.super_mode=p,N.public_mode=E,I&&(N.custom_type_startswith=I),u(A,N,f)},this.loadOpenChannelParticipantList=function(e,n,t,r){var i=Z.API_OPENCHANNELS_CHANNELURL_PARTICIPANTS.replace("%s",e),a={token:encodeURIComponent(n),limit:String(t)};u(i,a,r)},this.loadMutedUserList=function(e,n,t,r){var i=e.isOpenChannel()?Z.API_OPENCHANNELS_CHANNELURL_MUTE.replace("%s",e.url):Z.API_GROUPCHANNELS_CHANNELURL_MUTE.replace("%s",e.url),a={token:encodeURIComponent(n),limit:String(t)};u(i,a,r)},this.loadBannedUserList=function(e,n,t,r){var i=e.isOpenChannel()?Z.API_OPENCHANNELS_CHANNELURL_BAN.replace("%s",e.url):Z.API_GROUPCHANNELS_CHANNELURL_BAN.replace("%s",e.url),a={token:encodeURIComponent(n),limit:String(t)};u(i,a,r)},this.setPushTemplate=function(e,n,t){var r=Z.API_USERS_USERID_PUSH_TEMPLATE.replace("%s",encodeURIComponent(e));I(r,{name:n},t)},this.getPushTemplate=function(e,n){var t=Z.API_USERS_USERID_PUSH_TEMPLATE.replace("%s",encodeURIComponent(e));u(t,n)},this.setDoNotDisturb=function(e,n,t,r,i,a,s,o){var l=Z.API_USERS_USERID_PUSHPREFERENCE.replace("%s",encodeURIComponent(e));I(l,{do_not_disturb:n,start_hour:t,start_min:r,end_hour:i,end_min:a,timezone:s},o)},this.getDoNotDisturb=function(e,n){var t=Z.API_USERS_USERID_PUSHPREFERENCE.replace("%s",encodeURIComponent(e));u(t,n)},this.setPushPreference=function(e,n,t,r){var i=Z.API_USERS_USERID_PUSHPREFERENCE_CHANNELURL.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n)),a={};a.enable=t,I(i,a,r)},this.getPushPreference=function(e,n,t){var r=Z.API_USERS_USERID_PUSHPREFERENCE_CHANNELURL.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));u(r,t)},this.registerGCMPushToken=function(e,n,t){var r=Z.API_USERS_USERID_PUSH_GCM.replace("%s",encodeURIComponent(e));h(r,{gcm_reg_token:n},t)},this.unregisterGCMPushToken=function(e,n,t){var r=Z.API_USERS_USERID_PUSH_GCM_TOKEN.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));a(r,t)},this.unregisterGCMPushTokenAll=function(e,n){var t=Z.API_USERS_USERID_PUSH_GCM.replace("%s",encodeURIComponent(e));a(t,n)},this.registerAPNSPushToken=function(e,n,t){var r=Z.API_USERS_USERID_PUSH_APNS.replace("%s",encodeURIComponent(e));h(r,{apns_device_token:n},t)},this.unregisterAPNSPushToken=function(e,n,t){var r=Z.API_USERS_USERID_PUSH_APNS_TOKEN.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));a(r,t)},this.unregisterAPNSPushTokenAll=function(e,n){var t=Z.API_USERS_USERID_PUSH_APNS.replace("%s",encodeURIComponent(e));a(t,n)},this.unregisterPushTokenAll=function(e,n){var t=Z.API_USERS_USERID_PUSH.replace("%s",encodeURIComponent(e));a(t,n)},this.blockUser=function(e,n,t){var r=Z.API_USERS_USERID_BLOCK.replace("%s",encodeURIComponent(e));h(r,{target_id:n},t)},this.unblockUser=function(e,n,t){var r=Z.API_USERS_USERID_BLOCK_TARGETID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));a(r,{},t)},this.banUser=function(e,n,t,r,i,a){var s=i?Z.API_GROUPCHANNELS_CHANNELURL_BAN.replace("%s",encodeURIComponent(e)):Z.API_OPENCHANNELS_CHANNELURL_BAN.replace("%s",encodeURIComponent(e)),o={user_id:n};t&&(o.description=t),o.seconds=String(r),h(s,o,a)},this.unbanUser=function(e,n,t,r){var i=t?Z.API_GROUPCHANNELS_CHANNELURL_BAN_USERID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n)):Z.API_OPENCHANNELS_CHANNELURL_BAN_USERID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));a(i,{},r)},this.muteUser=function(e,n,t,r){var i=t?Z.API_GROUPCHANNELS_CHANNELURL_MUTE.replace("%s",encodeURIComponent(e)):Z.API_OPENCHANNELS_CHANNELURL_MUTE.replace("%s",encodeURIComponent(e));h(i,{user_id:n},r)},this.unmuteUser=function(e,n,t,r){var i=t?Z.API_GROUPCHANNELS_CHANNELURL_MUTE_USERID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n)):Z.API_OPENCHANNELS_CHANNELURL_MUTE_USERID.replace("%s",encodeURIComponent(e)).replace("%s",encodeURIComponent(n));a(i,{},r)},this.deleteMessage=function(e,n,t,r){var i="";i=e?Z.API_OPENCHANNELS_CHANNELURL_MESSAGES_MESSAGEID.replace("%s",encodeURIComponent(n)).replace("%s",encodeURIComponent(t)):Z.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MESSAGEID.replace("%s",encodeURIComponent(n)).replace("%s",encodeURIComponent(t)),a(i,{},r)},this.freeze=function(e,n,t,r){var i=n?Z.API_GROUPCHANNELS_CHANNELURL_FREEZE.replace("%s",encodeURIComponent(e)):Z.API_OPENCHANNELS_CHANNELURL_FREEZE.replace("%s",encodeURIComponent(e));I(i,{freeze:t},r)}},X=null;Z.getInstance=function(){return null===X?null:X},Z.API_VERSION="v3",Z.API_ROUTING_URL="https://api-p.sendbird.com/routing/%s",Z.API_USERS="/%v/users".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_LOGIN="/%v/users/%s/login".replace("%v",Z.API_VERSION),Z.API_USERS_USERID="/%v/users/%s".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_METADATA="/%v/users/%s/metadata".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_METADATA_KEY="/%v/users/%s/metadata/%s".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_UNREAD_MESSAGE_COUNT="/%v/users/%s/unread_message_count".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_UNREAD_CHANNEL_COUNT="/%v/users/%s/unread_channel_count".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_MARKASREADALL="/%v/users/%s/mark_as_read_all".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_PUSH_GCM_TOKEN="/%v/users/%s/push/gcm/%s".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_PUSH_GCM="/%v/users/%s/push/gcm".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_PUSHPREFERENCE_CHANNELURL="/%v/users/%s/push_preference/%s".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_PUSHPREFERENCE="/%v/users/%s/push_preference/".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_PUSH_TEMPLATE="/%v/users/%s/push/template".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_BLOCK="/%v/users/%s/block".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_BLOCK_TARGETID="/%v/users/%s/block/%s".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_PUSH_APNS_TOKEN="/%v/users/%s/push/apns/%s".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_PUSH_APNS="/%v/users/%s/push/apns".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_PUSH="/%v/users/%s/push".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_GROUP_CHANNEL_INVITATION_PREFERENCE="/%v/users/%s/channel_invitation_preference".replace("%v",Z.API_VERSION),Z.API_USERS_USERID_GROUP_CHANNEL_COUNT="/%v/users/%s/group_channel_count".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS="/%v/open_channels".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL="/%v/open_channels/%s".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_MESSAGES="/%v/open_channels/%s/messages".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_MESSAGES_MESSAGEID="/%v/open_channels/%s/messages/%s".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_PARTICIPANTS="/%v/open_channels/%s/participants".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_METADATA="/%v/open_channels/%s/metadata".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_METADATA_KEY="/%v/open_channels/%s/metadata/%s".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_METACOUNTER="/%v/open_channels/%s/metacounter".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_METACOUNTER_KEY="/%v/open_channels/%s/metacounter/%s".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_BAN="/%v/open_channels/%s/ban".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_BAN_USERID="/%v/open_channels/%s/ban/%s".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_MUTE="/%v/open_channels/%s/mute".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_MUTE_USERID="/%v/open_channels/%s/mute/%s".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_FREEZE="/%v/open_channels/%s/freeze".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS="/%v/group_channels".replace("%v",Z.API_VERSION),Z.API_MYGROUPCHANNELS="/%v/users/%s/my_group_channels".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL="/%v/group_channels/%s".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_INVITE="/%v/group_channels/%s/invite".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_ACCEPT_INVITATION="/%v/group_channels/%s/accept".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_DECLINE_INVITATION="/%v/group_channels/%s/decline".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_HIDE="/%v/group_channels/%s/hide".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_LEAVE="/%v/group_channels/%s/leave".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_JOIN="/%v/group_channels/%s/join".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_MESSAGES="/%v/group_channels/%s/messages".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MARKASREAD="/%v/group_channels/%s/messages/mark_as_read".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_MESSAGES_TOTALCOUNT="/%v/group_channels/%s/messages/total_count".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_MESSAGES_UNREADCOUNT="/%v/group_channels/%s/messages/unread_count".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_MESSAGES_MESSAGEID="/%v/group_channels/%s/messages/%s".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_MEMBERS="/%v/group_channels/%s/members".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_METADATA="/%v/group_channels/%s/metadata".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_METADATA_KEY="/%v/group_channels/%s/metadata/%s".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_METACOUNTER="/%v/group_channels/%s/metacounter".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_METACOUNTER_KEY="/%v/group_channels/%s/metacounter/%s".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_RESET_USER_HISTORY="/%v/group_channels/%s/reset_user_history".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_MEMBERS="/%v/group_channels/%url/members".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_BAN="/%v/group_channels/%s/ban".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_BAN_USERID="/%v/group_channels/%s/ban/%s".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_MUTE="/%v/group_channels/%s/mute".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_MUTE_USERID="/%v/group_channels/%s/mute/%s".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_FREEZE="/%v/group_channels/%s/freeze".replace("%v",Z.API_VERSION),Z.API_STORAGE_FILE="/%v/storage/file".replace("%v",Z.API_VERSION),Z.API_STORAGE_PROFILE="/%v/storage/profile_image".replace("%v",Z.API_VERSION),Z.API_OPENCHANNELS_CHANNELURL_MESSAGES_CHANGELOGS="/%v/open_channels/%s/messages/changelogs".replace("%v",Z.API_VERSION),Z.API_GROUPCHANNELS_CHANNELURL_MESSAGES_CHANGELOGS="/%v/group_channels/%s/messages/changelogs".replace("%v",Z.API_VERSION),Z.API_FRIENDS="/%v/users/%s/friends".replace("%v",Z.API_VERSION),Z.API_FRIENDS_CHANGE_LOGS="/%v/users/%s/friends/changelogs".replace("%v",Z.API_VERSION),Z.API_FRIENDS_DISCOVERIES="/%v/users/%s/friend_discoveries".replace("%v",Z.API_VERSION),Z.UPDATE_META_COUNTER_MODE_SET=0,Z.UPDATE_META_COUNTER_MODE_INC=1,Z.UPDATE_META_COUNTER_MODE_DEC=2;var $=function(){var e="";this.isLoading=!1,this.hasMore=!0,this.limit=20;var n=this;this.next=function(t){if(!h(n.limit))return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),t);if(n.hasMore){if(n.isLoading)return void U(null,new _("Query in progress.",J.QUERY_IN_PROGRESS),t);n.isLoading=!0,Z.getInstance().friendListQuery(ie.getInstance().getCurrentUserId(),e,n.limit,function(r,i){if(i)return n.isLoading=!1,void U(null,i,t);var a=r.users,s=a.map(function(e){return new G(e)});n.hasMore=r.has_more,n.isLoading=!1,e=r.next,U(s,null,t)})}}},ee=function(e,n,t,r){u?this[t]=e[n]:Object.defineProperty(e,t,{get:function(){return"_coverUrl"===n||"_coverImage"===n?e._channelCover:e[n]},set:function(t){if("file"===r){if("string"==typeof t||"object"!=typeof t)throw new _("Invalid parameter.",J.INVALID_PARAMETER)}else if(r&&typeof t!==r)throw new _("Invalid parameter.",J.INVALID_PARAMETER);e[n]=t,"_coverUrl"!==n&&"_coverImage"!==n||(e._channelCover=t)}})},ne=function(){this._isDistinct=null,ee(this,"_isDistinct","isDistinct","boolean"),this._isSuper=null,ee(this,"_isSuper","isSuper","boolean"),this._isPublic=null,ee(this,"_isPublic","isPublic","boolean"),this._channelUrl=null,ee(this,"_channelUrl","channelUrl","string"),this._name=null,ee(this,"_name","name","string"),this._data=null,ee(this,"_data","data","string"),this._customType=null,ee(this,"_customType","customType","string"),this._channelCover=null,ee(this,"_channelCover","channelCover",null),this._coverUrl=null,ee(this,"_coverUrl","coverUrl","string"),this._coverImage=null,ee(this,"_coverImage","coverImage","file"),this._operatorIds=[],this._operators=null,u?this.operators=this._operators:Object.defineProperty(this,"operators",{get:function(){return this._operators},set:function(e){if(!Array.isArray(e))throw new _("Invalid parameter.",J.INVALID_PARAMETER);for(var n=[],t=0;t0){e.unreadMessageCount=0;for(var r in ie.getInstance().channelHandlers){var a=ie.getInstance().channelHandlers[r];a.onChannelChanged(e)}}}else if(0===e.unreadMessageCount)for(var r in ie.getInstance().channelHandlers){var a=ie.getInstance().channelHandlers[r];a.onChannelChanged(e)}}else{e.updateReadReceipt(E.reader.userId,E.timestamp);for(var r in ie.getInstance().channelHandlers){var a=ie.getInstance().channelHandlers[r];a.onReadReceiptUpdated(e)}}});break;case"TPST":case"TPEN":case"MTIO":break;case"SYEV":c(t);break;case"USEV":u(t);break;case"DELM":var f=t.getJsonElement(),A=String(f.channel_type),g=String(f.channel_url),m=String(f.msg_id);switch(A){case M.CHANNEL_TYPE_OPEN:b.getChannel(g,function(e,t){if(R){var r=e;e=t,t=r}if(t)return void n.log("Discard a command.");for(var i in ie.getInstance().channelHandlers){ie.getInstance().channelHandlers[i].onMessageDeleted(e,m)}});break;case M.CHANNEL_TYPE_GROUP:w.getChannel(g,function(e,t){if(R){var r=e;e=t,t=r}if(t)return void n.log("Discard a command.");for(var i in ie.getInstance().channelHandlers){ie.getInstance().channelHandlers[i].onMessageDeleted(e,m)}})}}},u=function(e){var n=new H(e.getJsonElement());switch(n.category){case k.CATEGORY_USER_BLOCK:case k.CATEGORY_USER_UNBLOCK:var t=n.data.blocker.user_id,r=n.data.blockee.user_id;Object.keys(w.cachedChannels).forEach(function(e){var i=w.cachedChannels[e];try{ie.getInstance().getCurrentUserId()===t?i.memberMap[r].isBlockedByMe=n.category===k.CATEGORY_USER_BLOCK:ie.getInstance().getCurrentUserId()===r&&(i.memberMap[t].isBlockingMe=n.category===k.CATEGORY_USER_BLOCK)}catch(e){}});break;case k.CATEGORY_FRIEND_DISCOVERED:var i=n.data.friend_discoveries,a=i.map(function(e){return new G(e)});for(var s in ie.getInstance().userEventHandlers){ie.getInstance().userEventHandlers[s].onFriendsDiscovered(a)}}},c=function(e){var t=new H(e.getJsonElement());switch(t.category){case H.CATEGORY_CHANNEL_JOIN:case H.CATEGORY_CHANNEL_LEAVE:w.getChannel(t.channelUrl,function(r,i){if(R){var a=r;r=i,i=a}if(i)return void n.log("Discard a command: "+e.command+":"+t.category);var s=new G(t.data);if(t.category===H.CATEGORY_CHANNEL_JOIN){t.data.state=V.JOINED,r.addMember(new V(t.data)),s.userId===ie.getInstance().getCurrentUserId()&&(r.myMemberState="joined",w.cachedChannels[r.url]=r);for(var o in ie.getInstance().channelHandlers){var l=ie.getInstance().channelHandlers[o];l.onUserJoined(r,s)}}else{s.userId===ie.getInstance().getCurrentUserId()&&(r.isPublic||w.removeCachedChannel(t.channelUrl));r.removeMember(s);r.myMemberState="none",w.cachedChannels[r.url]=r;for(var o in ie.getInstance().channelHandlers){var l=ie.getInstance().channelHandlers[o];l.onUserLeft(r,s)}}});break;case H.CATEGORY_CHANNEL_INVITE:w.getChannel(t.channelUrl,function(r,i){if(R){var a=r;r=i,i=a}if(i)return void n.log("Discard a command: "+e.command+":"+t.category);var s=null;t.data&&t.data.inviter&&!d(t.data.inviter)&&(s=new G(t.data.inviter));var o=[];for(var l in t.data.invitees){t.data.invitees[l].state=V.INVITED;var u=new V(t.data.invitees[l]);o.push(u),r.addMember(u),u.userId===ie.getInstance().getCurrentUserId()&&(r.isHidden=!1,"joined"!==r.myMemberState&&(r.myMemberState="invited"),w.cachedChannels[r.url]=r)}for(var l in ie.getInstance().channelHandlers){ie.getInstance().channelHandlers[l].onUserReceivedInvitation(r,s,o)}});break;case H.CATEGORY_CHANNEL_DECLINE_INVITE:w.getChannel(t.channelUrl,function(r,i){if(R){var a=r;r=i,i=a}if(i)return void n.log("Discard a command: "+e.command+":"+t.category);var s=null;t.data&&t.data.inviter&&!d(t.data.inviter)&&(s=new G(t.data.inviter)) +;var o=new G(t.data.invitee);o.userId===ie.getInstance().getCurrentUserId()&&(r.isPublic||w.removeCachedChannel(t.channelUrl)),r.removeMember(o),r.myMemberState="none",w.cachedChannels[r.url]=r;for(var l in ie.getInstance().channelHandlers){ie.getInstance().channelHandlers[l].onUserDeclinedInvitation(r,s,o)}});break;case H.CATEGORY_TYPING_START:case H.CATEGORY_TYPING_END:w.getChannel(t.channelUrl,function(r,i){if(R){var a=r;r=i,i=a}if(i)return void n.log("Discard a command: "+e.command+":"+t.category);var s=new G(t.data);t.category===H.CATEGORY_TYPING_START?r.updateTypingStatus(s,!0):r.updateTypingStatus(s,!1);for(var o in ie.getInstance().channelHandlers){ie.getInstance().channelHandlers[o].onTypingStatusUpdated(r)}});break;case H.CATEGORY_CHANNEL_ENTER:case H.CATEGORY_CHANNEL_EXIT:b.getChannel(t.channelUrl,function(r,i){if(R){var a=r;r=i,i=a}if(i)return void n.log("Discard a command: "+e.command+":"+t.category);t.data.hasOwnProperty("participant_count")&&(r.participantCount=t.data.participant_count);var s=new G(t.data);if(t.category===H.CATEGORY_CHANNEL_ENTER)for(var o in ie.getInstance().channelHandlers){var l=ie.getInstance().channelHandlers[o];l.onUserEntered(r,s)}else for(var o in ie.getInstance().channelHandlers){var l=ie.getInstance().channelHandlers[o];l.onUserExited(r,s)}});break;case H.CATEGORY_USER_CHANNEL_MUTE:case H.CATEGORY_USER_CHANNEL_UNMUTE:t.isOpenChannel()?b.getChannel(t.channelUrl,function(r,i){if(R){var a=r;r=i,i=a}if(i)return void n.log("Discard a command: "+e.command+":"+t.category);var s=new G(t.data);if(t.category===H.CATEGORY_USER_CHANNEL_MUTE)for(var o in ie.getInstance().channelHandlers){var l=ie.getInstance().channelHandlers[o];l.onUserMuted(r,s)}else for(var o in ie.getInstance().channelHandlers){var l=ie.getInstance().channelHandlers[o];l.onUserUnmuted(r,s)}}):w.getChannel(t.channelUrl,function(r,i){if(R){var a=r;r=i,i=a}if(i)return void n.log("Discard a command: "+e.command+":"+t.category);var s=new G(t.data);if(t.category===H.CATEGORY_USER_CHANNEL_MUTE)for(var o in ie.getInstance().channelHandlers){var l=ie.getInstance().channelHandlers[o];l.onUserMuted(r,s)}else for(var o in ie.getInstance().channelHandlers){var l=ie.getInstance().channelHandlers[o];l.onUserUnmuted(r,s)}});break;case H.CATEGORY_USER_CHANNEL_BAN:case H.CATEGORY_USER_CHANNEL_UNBAN:t.isOpenChannel()?b.getChannel(t.channelUrl,function(r,i){if(R){var a=r;r=i,i=a}if(i)return void n.log("Discard a command: "+e.command+":"+t.category);var s=new G(t.data);if(t.category===H.CATEGORY_USER_CHANNEL_BAN)for(var o in ie.getInstance().channelHandlers){var l=ie.getInstance().channelHandlers[o];l.onUserBanned(r,s)}else for(var o in ie.getInstance().channelHandlers){var l=ie.getInstance().channelHandlers[o];l.onUserUnbanned(r,s)}}):w.getChannel(t.channelUrl,function(r,i){if(R){var a=r;r=i,i=a}if(i)return void n.log("Discard a command: "+e.command+":"+t.category);var s=new G(t.data);if(t.category===H.CATEGORY_USER_CHANNEL_BAN)for(var o in ie.getInstance().channelHandlers){var l=ie.getInstance().channelHandlers[o];l.onUserBanned(r,s)}else for(var o in ie.getInstance().channelHandlers){var l=ie.getInstance().channelHandlers[o];l.onUserUnbanned(r,s)}});break;case H.CATEGORY_CHANNEL_FREEZE:case H.CATEGORY_CHANNEL_UNFREEZE:t.isOpenChannel()?b.getChannel(t.channelUrl,function(r,i){if(R){var a=r;r=i,i=a}if(i)return void n.log("Discard a command: "+e.command+":"+t.category);if(r.isFrozen=t.data.freeze,b.cachedChannels[r.url]=r,t.category===H.CATEGORY_CHANNEL_FREEZE)for(var s in ie.getInstance().channelHandlers){var o=ie.getInstance().channelHandlers[s];o.onChannelFrozen(r)}else for(var s in ie.getInstance().channelHandlers){var o=ie.getInstance().channelHandlers[s];o.onChannelUnfrozen(r)}}):w.getChannel(t.channelUrl,function(r,i){if(R){var a=r;r=i,i=a}if(i)return void n.log("Discard a command: "+e.command+":"+t.category);if(r.isFrozen=t.data.freeze,w.cachedChannels[r.url]=r,t.category===H.CATEGORY_CHANNEL_FREEZE)for(var s in ie.getInstance().channelHandlers){var o=ie.getInstance().channelHandlers[s];o.onChannelFrozen(r)}else for(var s in ie.getInstance().channelHandlers){var o=ie.getInstance().channelHandlers[s];o.onChannelUnfrozen(r)}});break;case H.CATEGORY_CHANNEL_DELETED:if(t.isGroupChannel()){w.removeCachedChannel(t.channelUrl);for(var r in ie.getInstance().channelHandlers){var i=ie.getInstance().channelHandlers[r];i.onChannelDeleted(t.channelUrl,"group")}}else{b.removeCachedChannel(t.channelUrl);for(var r in ie.getInstance().channelHandlers){var i=ie.getInstance().channelHandlers[r];i.onChannelDeleted(t.channelUrl,"open")}}break;case H.CATEGORY_CHANNEL_PROP_CHANGED:t.isOpenChannel()?b.getChannelWithoutCache(t.channelUrl,function(r,i){if(R){var a=r;r=i,i=a}if(i)return void n.log("Discard a command: "+e.command+":"+t.category);for(var s in ie.getInstance().channelHandlers){ie.getInstance().channelHandlers[s].onChannelChanged(r)}}):w.getChannelWithoutCache(t.channelUrl,function(r,i){if(R){var a=r;r=i,i=a}if(i)return void n.log("Discard a command: "+e.command+":"+t.category);for(var s in ie.getInstance().channelHandlers){ie.getInstance().channelHandlers[s].onChannelChanged(r)}});break;case H.CATEGORY_CHANNEL_META_DATA_CHANGED:case H.CATEGORY_CHANNEL_META_COUNTERS_CHANGED:var a=t.data.hasOwnProperty("created"),s=t.data.hasOwnProperty("updated"),o=t.data.hasOwnProperty("deleted");t.isOpenChannel()?b.getChannel(t.channelUrl,function(r,i){if(R){var l=r;r=i,i=l}if(i)return void n.log("Discard a command: "+e.command+":"+t.category);for(var u in ie.getInstance().channelHandlers){var c=ie.getInstance().channelHandlers[u];t.category===H.CATEGORY_CHANNEL_META_DATA_CHANGED?(a&&c.onMetaDataCreated(r,t.data.created),s&&c.onMetaDataUpdated(r,t.data.updated),o&&c.onMetaDataDeleted(r,t.data.deleted)):(a&&c.onMetaCountersCreated(r,t.data.created),s&&c.onMetaCountersUpdated(r,t.data.updated),o&&c.onMetaCountersDeleted(r,t.data.deleted))}}):w.getChannel(t.channelUrl,function(r,i){if(R){var l=r;r=i,i=l}if(i)return void n.log("Discard a command: "+e.command+":"+t.category);for(var u in ie.getInstance().channelHandlers){var c=ie.getInstance().channelHandlers[u];t.category===H.CATEGORY_CHANNEL_META_DATA_CHANGED?(a&&c.onMetaDataCreated(r,t.data.created),s&&c.onMetaDataUpdated(r,t.data.updated),o&&c.onMetaDataDeleted(r,t.data.deleted)):(a&&c.onMetaCountersCreated(r,t.data.created),s&&c.onMetaCountersUpdated(r,t.data.updated),o&&c.onMetaCountersDeleted(r,t.data.deleted))}});break;case H.CATEGORY_CHANNEL_HIDE:w.getChannel(t.channelUrl,function(r,i){if(R){var a=r;r=i,i=a}if(i)return void n.log("Discard a command: "+e.command+":"+t.category);if(r.isHidden=!0,t.data&&t.data.hasOwnProperty("hide_previous_messages")&&t.data.hide_previous_messages&&w.cachedChannels){var s=w.cachedChannels[r.url];s.unreadMessageCount=0,w.cachedChannels[r.url]=s}for(var o in ie.getInstance().channelHandlers){ie.getInstance().channelHandlers[o].onChannelHidden(r)}})}};this.setPushTemplate=function(e,n){return!e||e!==this.PUSH_TEMPLATE_DEFAULT&&e!==this.PUSH_TEMPLATE_ALTERNATIVE?void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n):this.currentUser?void Z.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 _("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 _("Connection must be made before you get push template",J.CONNECTION_REQUIRED),e);Z.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 _("Invalid arguments.",J.INVALID_PARAMETER),n),Z.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){Z.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),r=null,i=null,a=null;switch("function"==typeof e.slice(-1)[0]&&(a=e.pop()),e.length){case 1:r=e[0];break;case 2:r=e[0],i=e[1];break;case 3:r=e[0],this.customApiHost=e[1],this.customWsHost=e[2];break;case 4:r=e[0],i=e[1],this.customApiHost=e[2],this.customWsHost=e[3];break;default:t&&n.log("sb.connect args length error: ",arguments)}r&&0!==r.length?(ie.getInstance().reconnectTimer&&(clearTimeout(ie.getInstance().reconnectTimer),ie.getInstance().reconnectTimer=null,ie.getInstance().onReconnectTimerCancel=null),ie.getInstance().getConnectionState()===this.connectionState.OPEN&&ie.getInstance().getCurrentUserId()===r?U(ie.getInstance().currentUser,null,a):(ie.getInstance().connectionCallback.push(a),1===ie.getInstance().connectionCallback.length&&(f(!0,null),g(r,i)))):U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),a)};var h=!1,I=!1,E=!0;this.setBackgroundState=function(){!h&&E&&(h=!0,this.getConnectionState()!==this.connectionState.CLOSED?(I=!0,f(!1,null)):I=!1)},this.setForegroundState=function(){h&&E&&(h=!1,I&&this.currentUser&&(y=0,A(this.getCurrentUserId(),!0)))},this.disableStateChange=function(){E=!1},this.enableStateChange=function(){E=!0},this.disconnect=function(e){f(!0,e)},this.reconnect=function(){if(!Z.getInstance().sessionKey||!this.currentUser)return!1;var e=!0;return y>0&&(e=!1),f(!1,null),y=0,A(this.getCurrentUserId(),e),!0};var f=function(e,n){var t=this;ie.getInstance().loginTimer&&(clearTimeout(ie.getInstance().loginTimer),ie.getInstance().onLoginTimerCancel&&(ie.getInstance().onLoginTimerCancel(),ie.getInstance().onLoginTimerCancel=null),ie.getInstance().loginTimer=null),ie.getInstance().reconnectTimer&&(clearTimeout(ie.getInstance().reconnectTimer),ie.getInstance().onReconnectTimerCancel&&(ie.getInstance().onReconnectTimerCancel(),ie.getInstance().onReconnectTimerCancel=null),ie.getInstance().reconnectTimer=null),ie.getInstance().wsClient&&(y=0,ie.getInstance().wsClient.disconnect(!0),ie.getInstance().wsClient=null),function(){if(e){b.clearEnteredChannels(),b.clearCache(),w.clearCache(),ie.getInstance().globalTimer&&(clearTimeout(t.globalTimer),ie.getInstance().globalTimer=null);for(var r in ie.getInstance().ackStateMap)clearTimeout(ie.getInstance().ackStateMap[r].timer);ie.getInstance().ackStateMap={},ie.getInstance().currentUser=null,Z.getInstance().sessionKey=null,Z.getInstance().ekey=null}U(null,null,n)}()},A=function(e,r){if(ie.getInstance().reconnectTimer)t&&n.log("still reconnecting");else{if((y+=1)<=1){if(r)for(var i in ie.getInstance().connectionHandlers){var a=ie.getInstance().connectionHandlers[i];a.onReconnectStarted(i)}T=0}else T=3e3*Math.pow(2,y-2);if(!e||!Z.getInstance().sessionKey||y>=6){f(!1,null),y=0;for(var i in ie.getInstance().connectionHandlers){var a=ie.getInstance().connectionHandlers[i];a.onReconnectFailed(i)}return}ie.getInstance().onReconnectTimerCancel=function(){y=0},ie.getInstance().reconnectTimer=setTimeout(function(){ie.getInstance().reconnectTimer=null,ie.getInstance().onReconnectTimerCancel=null,ie.getInstance().wsClient&&ie.getInstance().wsClient.disconnect(!0);var r=new j.WSClientHandler;ie.getInstance().wsClient=new j(r),ie.getInstance().loginHandler=function(e){y=0;for(var n in b.enteredChannels){b.enteredChannels[n].enter()}for(var n in ie.getInstance().connectionHandlers){ie.getInstance().connectionHandlers[n].onReconnectSucceeded(n)}},r.onOpen=function(){t&&n.log("reconnectWS onOpen"),ie.getInstance().loginTimer=setTimeout(function(){t&&n.log("reconnectWS loginTimer timedout"),ie.getInstance().loginTimer=null,A(e,!0)},1e4),ie.getInstance().onLoginTimerCancel=null},r.onMessage=function(e){l(e)},r.onError=function(){t&&n.log("reconnectWS onError"),A(e,!0)},r.onClose=function(){t&&n.log("reconnectWS onClose")};var i=ie.getInstance().getCurrentApiHost();Z.getInstance().checkRouting(function(n,t){if(t)return void A(e,!0);i!==n.API_HOST&&C(n.API_HOST,{},"GET",{},function(){}),ie.getInstance().wsClient.connect(e,null,n.WS_HOST)})},T)}},g=function(e,r){var i=new j.WSClientHandler;ie.getInstance().wsClient=new j(i),i.onMessage=function(e){l(e)},ie.getInstance().loginHandler=function(e,n){if(n)ie.getInstance().disconnect(null),ie.getInstance().connectionCallback.forEach(function(e){U(null,n,e)}),ie.getInstance().connectionCallback=[];else{clearTimeout(ie.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 ie.getInstance().channelHandlers){var i=ie.getInstance().channelHandlers[r];i.onTypingStatusUpdated(n)}}ie.getInstance().globalTimer=setTimeout(function(){t()},1e3)};t();var r=ie.getInstance().connectionCallback;ie.getInstance().connectionCallback=[],r.forEach(function(n){U(e,null,n)}),r=[]}},i.onOpen=function(e){ie.getInstance().loginTimer=setTimeout(function(){ie.getInstance().loginTimer=null,ie.getInstance().onLoginTimerCancel=null,ie.getInstance().disconnect(null),ie.getInstance().connectionCallback.forEach(function(e){U(null,new _("Connection timeout.",J.LOGIN_TIMEOUT),e)}),ie.getInstance().connectionCallback=[]},1e4),ie.getInstance().onLoginTimerCancel=function(){ie.getInstance().connectionCallback.forEach(function(e){U(null,new _("Connection Cancelled.",J.REQUEST_FAILED),e)}),ie.getInstance().connectionCallback=[]}},i.onError=function(r){t&&n.log("WSClientHandler.onError",r),Z.getInstance().sessionKey?A(e,!0):(ie.getInstance().connectionCallback.forEach(function(e){U(null,new _("Websocket connection failed.",J.WEBSOCKET_CONNECTION_FAILED),e)}),ie.getInstance().connectionCallback=[])},i.onClose=function(e){t&&n.log("WSClientHandler.onClose")},Z.getInstance().checkRouting(function(n,t){if(t)return ie.getInstance().connectionCallback.forEach(function(e){U(null,new _("Connection routing failed.",J.REQUEST_FAILED),e)}),void(ie.getInstance().connectionCallback=[]);C(n.API_HOST,{},"GET",{},function(){}),ie.getInstance().wsClient.connect(e,r,n.WS_HOST)})};this.sendCommand=function(e,n){if(!ie.getInstance().hasLoggedIn())return void(n&&n(null,new _("Connection should be made first.",J.CONNECTION_REQUIRED)));if(null==ie.getInstance().wsClient||ie.getInstance().wsClient.getConnectionState()!==ie.getInstance().connectionState.OPEN)return void(n&&n(null,new _("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 _("Command received no ack.",J.ACK_TIMEOUT)),delete s[t]},1e4)};s[t]=r,ie.getInstance().wsClient.send(e,function(e,t){if(t)return clearTimeout(r.timer),void n(null,t)})}else ie.getInstance().wsClient.send(e,n)},this.markAsReadAll=function(e){var n=(new Date).getTime();if(n-w.markAsReadAllLastSentAt<1e3)return void U(null,new _("MarkAsRead rate limit exceeded.",J.MARK_AS_READ_RATE_LIMIT_EXCEEDED),e);w.markAsReadAllLastSentAt=n,Z.getInstance().groupChannelMarkAsReadAll(ie.getInstance().getCurrentUserId(),null,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)})},this.markAsReadWithChannelUrls=function(e,n){if(!Array.isArray(e))return void U(null,new _("Invalid parameter.",J.INVALID_PARAMETER),n);var t=(new Date).getTime();if(t-w.markAsReadAllLastSentAt<1e3)return void U(null,new _("MarkAsRead rate limit exceeded.",J.MARK_AS_READ_RATE_LIMIT_EXCEEDED),n);w.markAsReadAllLastSentAt=t,Z.getInstance().groupChannelMarkAsReadAll(ie.getInstance().getCurrentUserId(),e,function(t,r){if(r)return void U(null,r,n);e.forEach(function(e){var n=w.cachedChannels[e];n&&(n.unreadMessageCount=0,w.cachedChannels[e]=n)}),U(null,null,n)})},this.updateCurrentUserInfoWithProfileImage=function(e,n,t){var r=this;n?Z.getInstance().updateCurrentUserInfoWithFile(r.getCurrentUserId(),e,n,function(i,a){if(a)return void U(null,a,t);r.currentUser&&(e&&(r.currentUser.nickname=e),n&&(r.currentUser.profileUrl=i.profile_url)),U(r.currentUser,null,t)}):r.updateCurrentUserInfo(e,null,t)},this.updateCurrentUserInfo=function(e,n,t){var r=this;Z.getInstance().updateUserInfo(r.getCurrentUserId(),e,n,function(i,a){if(a)return void U(null,a,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 Z.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 _("Invalid token",J.INVALID_PARAMETER),n)},this.unregisterGCMPushTokenForCurrentUser=function(e,n){if(!e)return void U(null,new _("Invalid token",J.INVALID_PARAMETER),n);Z.getInstance().unregisterGCMPushToken(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.unregisterGCMPushTokenAllForCurrentUser=function(e){Z.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 Z.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 _("Invalid token",J.INVALID_PARAMETER),n)},this.unregisterAPNSPushTokenForCurrentUser=function(e,n){if(!e)return void U(null,new _("Invalid token",J.INVALID_PARAMETER),n);Z.getInstance().unregisterAPNSPushToken(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.unregisterAPNSPushTokenAllForCurrentUser=function(e){Z.getInstance().unregisterAPNSPushTokenAll(this.getCurrentUserId(),function(n,t){if(t)return void U(null,t,e);U(null,null,e)})},this.unregisterPushTokenAllForCurrentUser=function(e){Z.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,i,a,s){var o=this;if(n<0||n>23||t<0||t>59||r<0||r>23||i<0||i>59)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),s);Z.getInstance().setDoNotDisturb(o.getCurrentUserId(),e,n,t,r,i,a,function(e,n){if(n)return void U(null,n,s);var t={doNotDisturbOn:e.do_not_disturb,startHour:e.start_hour,startMin:e.start_min,endHour:e.end_hour,endMin:e.end_min,timezone:e.timezone};U(t,null,s)})},this.getDoNotDisturb=function(e){var n=this;Z.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 _("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 _("You can not block yourself.",J.INVALID_PARAMETER),n);Z.getInstance().blockUser(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(new G(e),null,n)})},this.unblockUser=function(e,n){if("object"!=typeof e)return void U(null,new _("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 _("You can not unblock yourself.",J.INVALID_PARAMETER),n);Z.getInstance().unblockUser(this.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(null,null,n)})},this.addFriends=function(e,n){if(!Array.isArray(e))return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);var t=this;Z.getInstance().addFriends(t.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);var r=e.users.map(function(e){return new G(e)});U(r,null,n)})},this.deleteFriends=function(e,n){if(!Array.isArray(e))return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);var t=this;Z.getInstance().deleteFriends(t.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(e,null,n)})},this.deleteFriend=function(e,n){if("string"!=typeof e)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);this.deleteFriends([e],n)},this.uploadFriendDiscoveries=function(e,n){var t=!0;for(var r in e)if(!e[r].hasOwnProperty("friendDiscoveryKey")){t=!1,U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);break}if(t){var i=this;Z.getInstance().uploadFriendDiscoveries(i.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(e,null,n)})}},this.deleteFriendDiscoveries=function(e,n){if(!Array.isArray(e))return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);var t=this;Z.getInstance().deleteFriendDiscoveries(t.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);U(e,null,n)})},this.deleteFriendDiscovery=function(e,n){if("string"!=typeof e)return void U(null,new _("Invalid arguments.",J.INVALID_PARAMETER),n);this.deleteFriendDiscoveries([e],n)},this.getFriendChangeLogsByToken=function(e,n){if("function"==typeof e&&(n=e,e=null),"function"!=typeof n)return null;var t=this;Z.getInstance().getFriendChangeLogsByToken(t.getCurrentUserId(),e,function(e,t){if(t)return void U(null,t,n);var r=e.updated.map(function(e){return new G(G.build(e.user_id,e.nickname,e.profile_url,e.is_online,e.last_seen_at,e.metadata,e.is_active,e.friend_discovery_key,e.friend_name))}),i=e.deleted,a=e.has_more,s=e.next;U({updatedUsers:r,deletedUserIds:i,hasMore:a,token:s},null,n)})},this.createFriendListQuery=function(){return new $}},ae=null;return ie.getInstance=function(){return null===ae?null:ae},{SendBird:ie}},g=null;return function(){var e=function(e){if(e.newInstance||!g){var n=new A;g=new n.SendBird(e)}else if(g&&e.appId!==g.getApplicationId()&&g.getConnectionState()===g.connectionState.CLOSED){var n=new A;g=new n.SendBird(e)}return g};return e.getInstance=function(){return null===g?null:g},e.version="3.0.57",{SendBird:e}}().SendBird}); \ No newline at end of file diff --git a/bower.json b/bower.json index a9619e0..d8a4304 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "sendbird", - "version": "3.0.56", + "version": "3.0.57", "authors": ["SendBird "], "homepage": "https://github.com/smilefam/SendBird-SDK-JavaScript", "description": "SendBird JavaScript SDK", diff --git a/package.json b/package.json index 2426b5a..f93b77e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sendbird", - "version": "3.0.56", + "version": "3.0.57", "description": "SendBird JavaScript SDK", "main": "SendBird.min.js", "dependencies": {