"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[171],{55644:function(e,t,n){n.d(t,{c8:function(){return eF},t1:function(){return j}});var r,s,i,a,o,c,u=n(48738),l=n(22988),h=n(8620),d=n(135),p=n(57111),f=n(23668),v=n(82546),g=n(84179),m=n(12475),y=n(54566),b=n.n(y),w=n(38472),k=n(39428),_=n(42558),x=n.n(_),Z=n(99588),C=n.n(Z),S=n(41088),U=n(71227),R=n(52799),O=n(35743),I=n(74130),M=n(86300).Buffer,E=n(20357);function L(e){return"string"==typeof e}var P=function(e){var t,n,r,s={},i=String.fromCharCode,a=e.length,o=0,c=0,u="";for(t=0;t<64;t++)s["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(t)]=t;for(n=0;n=8;)((r=o>>>(c-=8)&255)||ne.length)&&(t=e.length);for(var n=0,r=Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){function t(t){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}(function(e){throw e}),f:s}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){function t(t){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}(function(e){o=!0,i=e}),f:function(){try{a||null==n.return||n.return()}finally{if(o)throw i}}}}(Array.isArray(e)?e:[e]);try{for(r.s();!(t=r.n()).done;){var s=t.value,i=Object.entries(s);i.length>1&&console.warn("client._buildSort() - multiple fields in a single sort object detected. Object's field order is not guaranteed");for(var a=0;a2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"created_at",s=!(arguments.length>4)||void 0===arguments[4]||arguments[4],i=s||n,a=e;n&&(a=a.filter(function(e){return!(e.id&&t.id===e.id)}));var o=a.length;if(0===o&&i)return a.concat(t);if(0===o)return(0,p.Z)(a);var c=t[r].getTime(),u=a[o-1][r].getTime()-1&&o.splice(c,1)}a.own_votes=o;var u=Y(Y({},i),{},{poll:a});r.addMessageSorted(u,!1,!1)}}),(0,m.Z)(this,"updatePoll",function(e,t){var n,s=r.findMessage(t);if(s){var i=Y(Y({},e),{},{own_votes:(0,p.Z)((null===(n=s.poll)||void 0===n?void 0:n.own_votes)||[])}),a=Y(Y({},s),{},{poll:i});r.addMessageSorted(a,!1,!1)}}),(0,m.Z)(this,"updateUserMessages",function(e){var t=function(e,t){for(var n=0;n1&&void 0!==arguments[1]&&arguments[1],n=function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=0;r1&&void 0!==arguments[1]&&arguments[1],n=!(arguments.length>2)||void 0===arguments[2]||arguments[2],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"latest";return this.addMessagesSorted([e],t,!1,n,r)}},{key:"formatMessage",value:function(e){return Y(Y({},e),{},{__html:e.html,pinned_at:e.pinned_at?new Date(e.pinned_at):null,created_at:e.created_at?new Date(e.created_at):new Date,updated_at:e.updated_at?new Date(e.updated_at):new Date,status:e.status||"received"})}},{key:"addMessagesSorted",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=!(arguments.length>3)||void 0===arguments[3]||arguments[3],s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"current",i=this.findTargetMessageSet(e,r,s),a=i.messagesToAdd,o=i.targetMessageSetIndex,c=0;cthis.last_message_at.getTime()&&(this.last_message_at=new Date(h.created_at.getTime())));var d=h.parent_id;if((!d||h.show_in_channel)&&-1!==o&&(this.messageSets[o].messages=this._addToMessageList(this.messageSets[o].messages,h,t,"created_at",r)),d&&!n){var p=this.threads[d]||[];this.threads[d]=this._addToMessageList(p,h,t,"created_at",r)}}return{messageSet:this.messageSets[o]}}},{key:"addPinnedMessages",value:function(e){for(var t=0;t2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"created_at",s=!(arguments.length>4)||void 0===arguments[4]||arguments[4];return $(e,t,n,r,s)}},{key:"removeMessage",value:function(e){var t=!1;if(e.parent_id&&this.threads[e.parent_id]){var n=this.removeMessageFromArray(this.threads[e.parent_id],e),r=n.removed,s=n.result;this.threads[e.parent_id]=s,t=r}else{var i,a=null!==(i=e.messageSetIndex)&&void 0!==i?i:this.findMessageSetIndex(e);if(-1!==a){var o=this.removeMessageFromArray(this.messageSets[a].messages,e),c=o.removed,u=o.result;this.messageSets[a].messages=u,t=c}}return t}},{key:"filterErrorMessages",value:function(){var e=this.latestMessages.filter(function(e){return"error"!==e.type});this.latestMessages=e}},{key:"clean",value:function(){for(var e=new Date,t=0,n=Object.entries(this.typing);t7e3&&(delete this.typing[s],this._channel.getClient().dispatchEvent({cid:this._channel.cid,type:"typing.stop",user:{id:s}}))}}},{key:"clearMessages",value:function(){this.initMessages(),this.pinnedMessages=[]}},{key:"initMessages",value:function(){this.messageSets=[{messages:[],isLatest:!0,isCurrent:!0}]}},{key:"loadMessageIntoState",value:(e=(0,f.Z)(b().mark(function e(t,n){var r,s,i,a,o,c,u=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(s=u.length>2&&void 0!==u[2]?u[2]:25,a=!1,o=!1,c=n||t,"latest"!==t){e.next=10;break}if(this.messages!==this.latestMessages){e.next=7;break}return e.abrupt("return");case 7:i=this.messageSets.findIndex(function(e){return e.isLatest}),e.next=11;break;case 10:i=this.findMessageSetIndex({id:c});case 11:if(-1!==i&&(this.switchToMessageSet(i),a=!0),o=!n||!!(null!==(r=this.threads[n])&&void 0!==r&&r.find(function(e){return e.id===t})),!(a&&o)){e.next=15;break}return e.abrupt("return");case 15:if(a){e.next=18;break}return e.next=18,this._channel.query({messages:{id_around:c,limit:s}},"new");case 18:if(!(!o&&n)){e.next=21;break}return e.next=21,this._channel.getReplies(n,{id_around:t,limit:s});case 21:-1!==(i=this.findMessageSetIndex({id:c}))&&this.switchToMessageSet(i);case 23:case"end":return e.stop()}},e,this)})),function(t,n){return e.apply(this,arguments)})},{key:"findMessage",value:function(e,t){if(t){var n=this.threads[t];if(!n)return;return n.find(function(t){return t.id===e})}var r=this.findMessageSetIndex({id:e});if(-1!==r)return this.messageSets[r].messages.find(function(t){return t.id===e})}},{key:"switchToMessageSet",value:function(e){var t=this.messageSets.find(function(e){return e.isCurrent});t&&(t.isCurrent=!1,this.messageSets[e].isCurrent=!0)}},{key:"areMessageSetsOverlap",value:function(e,t){return e.some(function(e){return t.find(function(t){return e.id===t.id})})}},{key:"findMessageSetIndex",value:function(e){return this.messageSets.findIndex(function(t){return!!t.messages.find(function(t){return t.id===e.id})})}},{key:"findTargetMessageSet",value:function(e){var t,n=this,r=!(arguments.length>1)||void 0===arguments[1]||arguments[1],s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"current",i=e;if(r){var a=this.messageSets.map(function(e,t){return t}).filter(function(t){return n.areMessageSetsOverlap(n.messageSets[t].messages,e)});switch(s){case"new":a.length>0?t=a[0]:e.some(function(e){return!e.parent_id})&&(this.messageSets.push({messages:[],isCurrent:!1,isLatest:!1}),t=this.messageSets.length-1);break;case"current":t=this.messageSets.findIndex(function(e){return e.isCurrent});break;case"latest":t=this.messageSets.findIndex(function(e){return e.isLatest});break;default:t=-1}var o=a.splice(0,1)[0],c=(0,p.Z)(a);if(void 0!==o&&o!==t&&c.push(t),c.length>0){var u=this.messageSets[o],l=this.messageSets.filter(function(e,t){return -1!==c.indexOf(t)});l.forEach(function(e){u.isLatest=u.isLatest||e.isLatest,u.isCurrent=u.isCurrent||e.isCurrent,i=[].concat((0,p.Z)(i),(0,p.Z)(e.messages))}),l.forEach(function(e){return n.messageSets.splice(n.messageSets.indexOf(e),1)}),t=this.messageSets.findIndex(function(t){return n.areMessageSetsOverlap(t.messages,e)})}}else t=this.findMessageSetIndex(e[0]);return{targetMessageSetIndex:t,messagesToAdd:i}}}]),t}();function et(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return en(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return en(e,void 0)}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,s=function(){};return{s:s,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:s}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){o=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(o)throw i}}}}function en(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n1&&void 0!==s[1]?s[1]:{}).offset&&n.next)){e.next=3;break}throw Error("Cannot specify offset with next");case 3:if(r=es(es({filter_conditions:{cid:this.cid}},n),{},{sort:n.sort?N(n.sort):void 0}),"string"!=typeof t){e.next=8;break}r.query=t,e.next=13;break;case 8:if("object"!==(0,h.Z)(t)){e.next=12;break}r.message_filter_conditions=t,e.next=13;break;case 12:throw Error("Invalid type ".concat((0,h.Z)(t)," for query parameter"));case 13:return e.next=15,this.getClient().wsPromise;case 15:return e.next=17,this.getClient().get(this.getClient().baseURL+"/search",{payload:r});case 17:return e.abrupt("return",e.sent);case 18:case"end":return e.stop()}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"queryMembers",value:(r=(0,f.Z)(b().mark(function e(t){var n,r,s,i,a,o,c=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=c.length>1&&void 0!==c[1]?c[1]:[],s=c.length>2&&void 0!==c[2]?c[2]:{},a=this.type,this.id?i=this.id:null!==(n=this.data)&&void 0!==n&&n.members&&Array.isArray(this.data.members)&&(o=this.data.members),e.next=6,this.getClient().get(this.getClient().baseURL+"/members",{payload:es({type:a,id:i,members:o,sort:N(r),filter_conditions:t},s)});case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}},e,this)})),function(e){return r.apply(this,arguments)})},{key:"sendReaction",value:(s=(0,f.Z)(b().mark(function e(t,n,r){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}throw Error("Message id is missing");case 2:if(!(!n||0===Object.keys(n).length)){e.next=4;break}throw Error("Reaction object is missing");case 4:return e.next=6,this.getClient().post(this.getClient().baseURL+"/messages/".concat(t,"/reaction"),es({reaction:n},r));case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}},e,this)})),function(e,t,n){return s.apply(this,arguments)})},{key:"deleteReaction",value:function(e,t,n){if(this._checkInitialized(),!t||!e)throw Error("Deleting a reaction requires specifying both the message and reaction type");var r=this.getClient().baseURL+"/messages/".concat(e,"/reaction/").concat(t);return n?this.getClient().delete(r,{user_id:n}):this.getClient().delete(r,{})}},{key:"update",value:(i=(0,f.Z)(b().mark(function e(){var t,n,r,s=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=s.length>0&&void 0!==s[0]?s[0]:{},n=s.length>1?s[1]:void 0,r=s.length>2?s[2]:void 0,["config","cid","created_by","id","member_count","type","created_at","updated_at","last_message_at","own_capabilities"].forEach(function(e){delete t[e]}),e.next=7,this._update(es({message:n,data:t},r));case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}},e,this)})),function(){return i.apply(this,arguments)})},{key:"updatePartial",value:(a=(0,f.Z)(b().mark(function e(t){var n,r,s,i;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getClient().patch(this._channelURL(),t);case 2:return s=e.sent,i=(0,p.Z)(s.channel.own_capabilities||[]).sort().join()!==(0,p.Z)(Array.isArray(null===(n=this.data)||void 0===n?void 0:n.own_capabilities)?null===(r=this.data)||void 0===r?void 0:r.own_capabilities:[]).sort().join(),this.data=s.channel,i&&this.getClient().dispatchEvent({type:"capabilities.changed",cid:this.cid,own_capabilities:s.channel.own_capabilities}),e.abrupt("return",s);case 7:case"end":return e.stop()}},e,this)})),function(e){return a.apply(this,arguments)})},{key:"enableSlowMode",value:(o=(0,f.Z)(b().mark(function e(t){var n;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getClient().post(this._channelURL(),{cooldown:t});case 2:return n=e.sent,this.data=n.channel,e.abrupt("return",n);case 5:case"end":return e.stop()}},e,this)})),function(e){return o.apply(this,arguments)})},{key:"disableSlowMode",value:(c=(0,f.Z)(b().mark(function e(){var t;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getClient().post(this._channelURL(),{cooldown:0});case 2:return t=e.sent,this.data=t.channel,e.abrupt("return",t);case 5:case"end":return e.stop()}},e,this)})),function(){return c.apply(this,arguments)})},{key:"delete",value:(u=(0,f.Z)(b().mark(function e(){var t,n=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>0&&void 0!==n[0]?n[0]:{},e.next=3,this.getClient().delete(this._channelURL(),es({},t));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(){return u.apply(this,arguments)})},{key:"truncate",value:(l=(0,f.Z)(b().mark(function e(){var t,n=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>0&&void 0!==n[0]?n[0]:{},e.next=3,this.getClient().post(this._channelURL()+"/truncate",t);case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(){return l.apply(this,arguments)})},{key:"acceptInvite",value:(d=(0,f.Z)(b().mark(function e(){var t,n=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>0&&void 0!==n[0]?n[0]:{},e.next=3,this._update(es({accept_invite:!0},t));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(){return d.apply(this,arguments)})},{key:"rejectInvite",value:(y=(0,f.Z)(b().mark(function e(){var t,n=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>0&&void 0!==n[0]?n[0]:{},e.next=3,this._update(es({reject_invite:!0},t));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(){return y.apply(this,arguments)})},{key:"addMembers",value:(w=(0,f.Z)(b().mark(function e(t,n){var r,s=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=s.length>2&&void 0!==s[2]?s[2]:{},e.next=3,this._update(es({add_members:t,message:n},r));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e,t){return w.apply(this,arguments)})},{key:"addModerators",value:(k=(0,f.Z)(b().mark(function e(t,n){var r,s=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=s.length>2&&void 0!==s[2]?s[2]:{},e.next=3,this._update(es({add_moderators:t,message:n},r));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e,t){return k.apply(this,arguments)})},{key:"assignRoles",value:(_=(0,f.Z)(b().mark(function e(t,n){var r,s=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=s.length>2&&void 0!==s[2]?s[2]:{},e.next=3,this._update(es({assign_roles:t,message:n},r));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e,t){return _.apply(this,arguments)})},{key:"inviteMembers",value:(x=(0,f.Z)(b().mark(function e(t,n){var r,s=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=s.length>2&&void 0!==s[2]?s[2]:{},e.next=3,this._update(es({invites:t,message:n},r));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e,t){return x.apply(this,arguments)})},{key:"removeMembers",value:(Z=(0,f.Z)(b().mark(function e(t,n){var r,s=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=s.length>2&&void 0!==s[2]?s[2]:{},e.next=3,this._update(es({remove_members:t,message:n},r));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e,t){return Z.apply(this,arguments)})},{key:"demoteModerators",value:(C=(0,f.Z)(b().mark(function e(t,n){var r,s=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=s.length>2&&void 0!==s[2]?s[2]:{},e.next=3,this._update(es({demote_moderators:t,message:n},r));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e,t){return C.apply(this,arguments)})},{key:"_update",value:(S=(0,f.Z)(b().mark(function e(t){var n;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getClient().post(this._channelURL(),t);case 2:return n=e.sent,this.data=n.channel,e.abrupt("return",n);case 5:case"end":return e.stop()}},e,this)})),function(e){return S.apply(this,arguments)})},{key:"mute",value:(U=(0,f.Z)(b().mark(function e(){var t,n=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>0&&void 0!==n[0]?n[0]:{},e.next=3,this.getClient().post(this.getClient().baseURL+"/moderation/mute/channel",es({channel_cid:this.cid},t));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(){return U.apply(this,arguments)})},{key:"unmute",value:(R=(0,f.Z)(b().mark(function e(){var t,n=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>0&&void 0!==n[0]?n[0]:{},e.next=3,this.getClient().post(this.getClient().baseURL+"/moderation/unmute/channel",es({channel_cid:this.cid},t));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(){return R.apply(this,arguments)})},{key:"muteStatus",value:function(){return this._checkInitialized(),this.getClient()._muteStatus(this.cid)}},{key:"sendAction",value:function(e,t){if(this._checkInitialized(),!e)throw Error("Message id is missing");return this.getClient().post(this.getClient().baseURL+"/messages/".concat(e,"/action"),{message_id:e,form_data:t,id:this.id,type:this.type})}},{key:"keystroke",value:(O=(0,f.Z)(b().mark(function e(t,n){var r,s;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this._isTypingIndicatorsEnabled()){e.next=2;break}return e.abrupt("return");case 2:if(r=new Date,s=this.lastTypingEvent&&r.getTime()-this.lastTypingEvent.getTime(),this.lastKeyStroke=r,this.isTyping=!0,!(null===s||s>2e3)){e.next=10;break}return this.lastTypingEvent=new Date,e.next=10,this.sendEvent(es({type:"typing.start",parent_id:t},n||{}));case 10:case"end":return e.stop()}},e,this)})),function(e,t){return O.apply(this,arguments)})},{key:"stopTyping",value:(I=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this._isTypingIndicatorsEnabled()){e.next=2;break}return e.abrupt("return");case 2:return this.lastTypingEvent=null,this.isTyping=!1,e.next=6,this.sendEvent(es({type:"typing.stop",parent_id:t},n||{}));case 6:case"end":return e.stop()}},e,this)})),function(e,t){return I.apply(this,arguments)})},{key:"_isTypingIndicatorsEnabled",value:function(){var e,t,n,r,s;return null!==(e=this.getConfig())&&void 0!==e&&!!e.typing_events&&(null===(t=null===(n=this.getClient().user)||void 0===n?void 0:null===(r=n.privacy_settings)||void 0===r?void 0:null===(s=r.typing_indicators)||void 0===s?void 0:s.enabled)||void 0===t||t)}},{key:"lastMessage",value:function(){var e=this.state.latestMessages.length-5;e<0&&(e=0);var t=this.state.latestMessages.length+1,n=this.state.latestMessages.slice(e,t);return n.sort(function(e,t){return t.created_at.getTime()-e.created_at.getTime()}),n[0]}},{key:"markRead",value:(M=(0,f.Z)(b().mark(function e(){var t,n,r=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n=r.length>0&&void 0!==r[0]?r[0]:{},this._checkInitialized(),!(!(null!==(t=this.getConfig())&&void 0!==t&&t.read_events)&&!this.getClient()._isUsingServerAuth())){e.next=4;break}return e.abrupt("return",Promise.resolve(null));case 4:return e.next=6,this.getClient().post(this._channelURL()+"/read",es({},n));case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}},e,this)})),function(){return M.apply(this,arguments)})},{key:"markUnread",value:(E=(0,f.Z)(b().mark(function e(t){var n;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this._checkInitialized(),!(!(null!==(n=this.getConfig())&&void 0!==n&&n.read_events)&&!this.getClient()._isUsingServerAuth())){e.next=3;break}return e.abrupt("return",Promise.resolve(null));case 3:return e.next=5,this.getClient().post(this._channelURL()+"/unread",es({},t));case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}},e,this)})),function(e){return E.apply(this,arguments)})},{key:"clean",value:function(){this.lastKeyStroke&&new Date().getTime()-this.lastKeyStroke.getTime()>1e3&&this.isTyping&&j(this.stopTyping(),"stop typing event"),this.state.clean()}},{key:"watch",value:(L=(0,f.Z)(b().mark(function e(t){var n,r,s;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n={state:!0,watch:!0,presence:!1},e.next=3,this.getClient().wsPromise;case 3:return this.getClient()._hasConnectionID()||(n.watch=!1),r=es(es({},n),t),e.next=7,this.query(r,"latest");case 7:return s=e.sent,this.initialized=!0,this.data=s.channel,this._client.logger("info","channel:watch() - started watching channel ".concat(this.cid),{tags:["channel"],channel:this}),e.abrupt("return",s);case 12:case"end":return e.stop()}},e,this)})),function(e){return L.apply(this,arguments)})},{key:"stopWatching",value:(P=(0,f.Z)(b().mark(function e(){var t;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getClient().post(this._channelURL()+"/stop-watching",{});case 2:return t=e.sent,this._client.logger("info","channel:watch() - stopped watching channel ".concat(this.cid),{tags:["channel"],channel:this}),e.abrupt("return",t);case 5:case"end":return e.stop()}},e,this)})),function(){return P.apply(this,arguments)})},{key:"getReplies",value:(T=(0,f.Z)(b().mark(function e(t,n,r){var s,i;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return s=r?N(r):void 0,e.next=3,this.getClient().get(this.getClient().baseURL+"/messages/".concat(t,"/replies"),es({sort:s},n));case 3:return(i=e.sent).messages&&this.state.addMessagesSorted(i.messages),e.abrupt("return",i);case 6:case"end":return e.stop()}},e,this)})),function(e,t,n){return T.apply(this,arguments)})},{key:"getPinnedMessages",value:(D=(0,f.Z)(b().mark(function e(t){var n,r=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.length>1&&void 0!==r[1]?r[1]:[],e.next=3,this.getClient().get(this.getClient().baseURL+"/channels/".concat(this.type,"/").concat(this.id,"/pinned_messages"),{payload:es(es({},t),{},{sort:N(n)})});case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return D.apply(this,arguments)})},{key:"getReactions",value:function(e,t){return this.getClient().get(this.getClient().baseURL+"/messages/".concat(e,"/reactions"),es({},t))}},{key:"getMessagesById",value:function(e){return this.getClient().get(this._channelURL()+"/messages",{ids:e.join(",")})}},{key:"lastRead",value:function(){var e=this.getClient().userID;if(e)return this.state.read[e]?this.state.read[e].last_read:null}},{key:"_countMessageAsUnread",value:function(e){var t,n,r,s;return!(e.shadowed||e.silent||e.parent_id&&!e.show_in_channel||(null===(t=e.user)||void 0===t?void 0:t.id)===this.getClient().userID||null!==(n=e.user)&&void 0!==n&&n.id&&this.getClient().userMuteStatus(e.user.id)||"system"===e.type||Array.isArray(null===(r=this.data)||void 0===r?void 0:r.own_capabilities)&&!(null!==(s=this.data)&&void 0!==s&&s.own_capabilities.includes("read-events")))&&!this.muteStatus().muted}},{key:"countUnread",value:function(e){if(!e)return this.state.unreadCount;for(var t=0,n=0;ne&&this._countMessageAsUnread(r)&&t++}return t}},{key:"countUnreadMentions",value:function(){for(var e=this.lastRead(),t=this.getClient().userID,n=0,r=0;re)&&null!==(s=i.mentioned_users)&&void 0!==s&&s.some(function(e){return e.id===t})&&n++}return n}},{key:"query",value:(A=(0,f.Z)(b().mark(function e(t){var n,r,s,i,a,o,c,u,l,h=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return s=h.length>1&&void 0!==h[1]?h[1]:"current",e.next=3,this.getClient().wsPromise;case 3:return i="".concat(this.getClient().baseURL,"/channels/").concat(this.type),this.id&&(i+="/".concat(this.id)),e.next=7,this.getClient().post(i+"/query",es({data:this._data,state:!0},t));case 7:return a=e.sent,this.id||(this.id=a.channel.id,this.cid=a.channel.cid,o=a.members.map(function(e){var t;return e.user_id||(null===(t=e.user)||void 0===t?void 0:t.id)}).sort().join(","),(c="".concat(this.type,":!members-").concat(o))in this.getClient().activeChannels&&delete this.getClient().activeChannels[c],this.cid in this.getClient().activeChannels||(this.getClient().activeChannels[this.cid]=this)),this.getClient()._addChannelConfig(a.channel),u=this._initializeState(a,s).messageSet,l=(0,p.Z)(a.channel.own_capabilities||[]).sort().join()!==(0,p.Z)(Array.isArray(null===(n=this.data)||void 0===n?void 0:n.own_capabilities)?null===(r=this.data)||void 0===r?void 0:r.own_capabilities:[]).sort().join(),this.data=a.channel,this.offlineMode=!1,l&&this.getClient().dispatchEvent({type:"capabilities.changed",cid:this.cid,own_capabilities:a.channel.own_capabilities}),this.getClient().dispatchEvent({type:"channels.queried",queriedChannels:{channels:[a],isLatestMessageSet:u.isLatest}}),e.abrupt("return",a);case 17:case"end":return e.stop()}},e,this)})),function(e){return A.apply(this,arguments)})},{key:"banUser",value:(F=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this._checkInitialized(),e.next=3,this.getClient().banUser(t,es(es({},n),{},{type:this.type,id:this.id}));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e,t){return F.apply(this,arguments)})},{key:"hide",value:(q=(0,f.Z)(b().mark(function e(){var t,n,r=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=r.length>0&&void 0!==r[0]?r[0]:null,n=r.length>1&&void 0!==r[1]&&r[1],this._checkInitialized(),e.next=5,this.getClient().post("".concat(this._channelURL(),"/hide"),{user_id:t,clear_history:n});case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}},e,this)})),function(){return q.apply(this,arguments)})},{key:"show",value:(W=(0,f.Z)(b().mark(function e(){var t,n=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>0&&void 0!==n[0]?n[0]:null,this._checkInitialized(),e.next=4,this.getClient().post("".concat(this._channelURL(),"/show"),{user_id:t});case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}},e,this)})),function(){return W.apply(this,arguments)})},{key:"unbanUser",value:(B=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this._checkInitialized(),e.next=3,this.getClient().unbanUser(t,{type:this.type,id:this.id});case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return B.apply(this,arguments)})},{key:"shadowBan",value:(z=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this._checkInitialized(),e.next=3,this.getClient().shadowBan(t,es(es({},n),{},{type:this.type,id:this.id}));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e,t){return z.apply(this,arguments)})},{key:"removeShadowBan",value:(H=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this._checkInitialized(),e.next=3,this.getClient().removeShadowBan(t,{type:this.type,id:this.id});case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return H.apply(this,arguments)})},{key:"createCall",value:(V=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getClient().post(this._channelURL()+"/call",t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return V.apply(this,arguments)})},{key:"vote",value:(J=(0,f.Z)(b().mark(function e(t,n,r){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getClient().castPollVote(t,n,r);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t,n){return J.apply(this,arguments)})},{key:"removeVote",value:(K=(0,f.Z)(b().mark(function e(t,n,r){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getClient().removePollVote(t,n,r);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t,n){return K.apply(this,arguments)})},{key:"on",value:function(e,t){var n=this,r=t?e:"all",s=t||e;return r in this.listeners||(this.listeners[r]=[]),this._client.logger("info","Attaching listener for ".concat(r," event on channel ").concat(this.cid),{tags:["event","channel"],channel:this}),this.listeners[r].push(s),{unsubscribe:function(){n._client.logger("info","Removing listener for ".concat(r," event from channel ").concat(n.cid),{tags:["event","channel"],channel:n}),n.listeners[r]=n.listeners[r].filter(function(e){return e!==s})}}}},{key:"off",value:function(e,t){var n=t?e:"all",r=t||e;n in this.listeners||(this.listeners[n]=[]),this._client.logger("info","Removing listener for ".concat(n," event from channel ").concat(this.cid),{tags:["event","channel"],channel:this}),this.listeners[n]=this.listeners[n].filter(function(e){return e!==r})}},{key:"_handleChannelEvent",value:function(e){this._client.logger("info","channel:_handleChannelEvent - Received event of type { ".concat(e.type," } on ").concat(this.cid),{tags:["event","channel"],channel:this});var t,n,r,s,i,a,o,c,u=this.state;switch(e.type){case"typing.start":null!==(f=e.user)&&void 0!==f&&f.id&&(u.typing[e.user.id]=e);break;case"typing.stop":null!==(v=e.user)&&void 0!==v&&v.id&&delete u.typing[e.user.id];break;case"message.read":null!==(g=e.user)&&void 0!==g&&g.id&&e.created_at&&(u.read[e.user.id]={last_read:new Date(e.created_at),last_read_message_id:e.last_read_message_id,user:e.user,unread_messages:0},(null===(S=e.user)||void 0===S?void 0:S.id)===(null===(U=this.getClient().user)||void 0===U?void 0:U.id)&&(u.unreadCount=0));break;case"user.watching.start":case"user.updated":null!==(m=e.user)&&void 0!==m&&m.id&&(u.watchers[e.user.id]=e.user);break;case"user.watching.stop":null!==(y=e.user)&&void 0!==y&&y.id&&delete u.watchers[e.user.id];break;case"message.deleted":e.message&&(this._extendEventWithOwnReactions(e),e.hard_delete?u.removeMessage(e.message):u.addMessageSorted(e.message,!1,!1),u.removeQuotedMessageReferences(e.message),e.message.pinned&&u.removePinnedMessage(e.message));break;case"message.new":if(e.message){var l,h,d,p,f,v,g,m,y,b,w,k,_,x,Z,C,S,U,R,O,I,M=(null===(R=e.user)||void 0===R?void 0:R.id)===(null===(O=this.getClient().user)||void 0===O?void 0:O.id),E=e.message.parent_id&&!e.message.show_in_channel;if((this.state.isUpToDate||E)&&u.addMessageSorted(e.message,M),e.message.pinned&&u.addPinnedMessage(e.message),M||E)break;if(null!==(I=e.user)&&void 0!==I&&I.id)for(var L in u.read)L===e.user.id?u.read[e.user.id]={last_read:new Date(e.created_at),user:e.user,unread_messages:0}:u.read[L].unread_messages+=1;this._countMessageAsUnread(e.message)&&(u.unreadCount=u.unreadCount+1)}break;case"message.updated":case"message.undeleted":e.message&&(this._extendEventWithOwnReactions(e),u.addMessageSorted(e.message,!1,!1),u._updateQuotedMessageReferences({message:e.message}),e.message.pinned?u.addPinnedMessage(e.message):u.removePinnedMessage(e.message));break;case"channel.truncated":if(null!==(b=e.channel)&&void 0!==b&&b.truncated_at){var P=+new Date(e.channel.truncated_at);u.messageSets.forEach(function(e,t){e.messages.forEach(function(e){var n=e.created_at,r=e.id;P>+n&&u.removeMessage({id:r,messageSetIndex:t})})}),u.pinnedMessages.forEach(function(e){var t=e.id;P>+e.created_at&&u.removePinnedMessage({id:t})})}else u.clearMessages();u.unreadCount=0,e.message&&(u.addMessageSorted(e.message),e.message.pinned&&u.addPinnedMessage(e.message));break;case"member.added":case"member.updated":null!==(w=e.member)&&void 0!==w&&w.user_id&&(u.members[e.member.user_id]=e.member);break;case"member.removed":null!==(k=e.user)&&void 0!==k&&k.id&&delete u.members[e.user.id];break;case"notification.mark_unread":if(!((null===(T=e.user)||void 0===T?void 0:T.id)===(null===(D=this.getClient().user)||void 0===D?void 0:D.id)&&e.user))break;var T,D,A,j=null!==(A=e.unread_messages)&&void 0!==A?A:0;u.read[e.user.id]={first_unread_message_id:e.first_unread_message_id,last_read:new Date(e.last_read_at),last_read_message_id:e.last_read_message_id,user:e.user,unread_messages:j},u.unreadCount=j;break;case"channel.updated":e.channel&&((null===(t=e.channel)||void 0===t?void 0:t.frozen)!==void 0&&e.channel.frozen!==(null===(n=this.data)||void 0===n?void 0:n.frozen)&&this.query({state:!1,messages:{limit:0},watchers:{limit:0}}),this.data=es(es({},e.channel),{},{hidden:null!==(r=null===(s=e.channel)||void 0===s?void 0:s.hidden)&&void 0!==r?r:null===(i=this.data)||void 0===i?void 0:i.hidden,own_capabilities:null!==(a=null===(o=e.channel)||void 0===o?void 0:o.own_capabilities)&&void 0!==a?a:null===(c=this.data)||void 0===c?void 0:c.own_capabilities}));break;case"poll.updated":e.poll&&u.updatePoll(e.poll,(null===(l=e.message)||void 0===l?void 0:l.id)||"");break;case"poll.vote_casted":e.poll_vote&&e.poll&&u.addPollVote(e.poll_vote,e.poll,(null===(h=e.message)||void 0===h?void 0:h.id)||"");break;case"poll.vote_changed":e.poll_vote&&e.poll&&u.updatePollVote(e.poll_vote,e.poll,(null===(d=e.message)||void 0===d?void 0:d.id)||"");break;case"poll.vote_removed":e.poll_vote&&e.poll&&u.removePollVote(e.poll_vote,e.poll,(null===(p=e.message)||void 0===p?void 0:p.id)||"");break;case"poll.closed":e.message&&u.addMessageSorted(e.message,!1,!1);break;case"reaction.new":e.message&&e.reaction&&(e.message=u.addReaction(e.reaction,e.message));break;case"reaction.deleted":e.reaction&&(e.message=u.removeReaction(e.reaction,e.message));break;case"reaction.updated":e.reaction&&(e.message=u.addReaction(e.reaction,e.message,!0));break;case"channel.hidden":this.data=es(es({},this.data),{},{hidden:!0}),e.clear_history&&u.clearMessages();break;case"channel.visible":this.data=es(es({},this.data),{},{hidden:!1});break;case"user.banned":if(!(null!==(_=e.user)&&void 0!==_&&_.id))break;u.members[e.user.id]=es(es({},u.members[e.user.id]||{}),{},{shadow_banned:!!e.shadow,banned:!e.shadow,user:es(es({},(null===(x=u.members[e.user.id])||void 0===x?void 0:x.user)||{}),e.user)});break;case"user.unbanned":if(!(null!==(Z=e.user)&&void 0!==Z&&Z.id))break;u.members[e.user.id]=es(es({},u.members[e.user.id]||{}),{},{shadow_banned:!1,banned:!1,user:es(es({},(null===(C=u.members[e.user.id])||void 0===C?void 0:C.user)||{}),e.user)})}void 0!==e.watcher_count&&(this.state.watcher_count=e.watcher_count)}},{key:"_checkInitialized",value:function(){if(!this.initialized&&!this.offlineMode&&!this.getClient()._isUsingServerAuth())throw Error("Channel ".concat(this.cid," hasn't been initialized yet. Make sure to call .watch() and wait for it to resolve"))}},{key:"_initializeState",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"latest",n=this.getClient(),r=n.state,s=n.user,i=n.userID;if(e.members){var a,o=et(e.members);try{for(o.s();!(a=o.n()).done;){var c=a.value;c.user&&r.updateUserReference(c.user,this.cid)}}catch(e){o.e(e)}finally{o.f()}}this.state.membership=e.membership||{};var u=e.messages||[];this.state.messages||this.state.initMessages();var l=this.state.addMessagesSorted(u,!1,!0,!0,t).messageSet;if(this.state.pinnedMessages||(this.state.pinnedMessages=[]),this.state.addPinnedMessages(e.pinned_messages||[]),e.pending_messages&&(this.state.pending_messages=e.pending_messages),void 0!==e.watcher_count&&(this.state.watcher_count=e.watcher_count),e.watchers){var h,d=et(e.watchers);try{for(d.s();!(h=d.n()).done;){var p=h.value;p&&(r.updateUserReference(p,this.cid),this.state.watchers[p.id]=p)}}catch(e){d.e(e)}finally{d.f()}}if(null!=i){var f=this.state.last_message_at||new Date;s&&(this.state.read[s.id]={user:s,last_read:f,unread_messages:0})}if(e.read){var v,g=et(e.read);try{for(g.s();!(v=g.n()).done;){var m,y=v.value;this.state.read[y.user.id]={last_read:new Date(y.last_read),last_read_message_id:y.last_read_message_id,unread_messages:null!==(m=y.unread_messages)&&void 0!==m?m:0,user:y.user},y.user.id===(null==s?void 0:s.id)&&(this.state.unreadCount=this.state.read[y.user.id].unread_messages)}}catch(e){g.e(e)}finally{g.f()}}return e.members&&(this.state.members=e.members.reduce(function(e,t){return t.user&&(e[t.user.id]=t),e},{})),{messageSet:l}}},{key:"_extendEventWithOwnReactions",value:function(e){if(e.message){var t=this.state.findMessage(e.message.id,e.message.parent_id);t&&(e.message.own_reactions=t.own_reactions)}}},{key:"_disconnect",value:function(){this._client.logger("info","channel:disconnect() - Disconnecting the channel ".concat(this.cid),{tags:["connection","channel"],channel:this}),this.disconnected=!0,this.state.setIsUpToDate(!1)}}]),Q}();function ea(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:s}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){o=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(o)throw i}}}}(e);try{for(n.s();!(t=n.n()).done;){var r=t.value;this.updateUser(r)}}catch(e){n.e(e)}finally{n.f()}}},{key:"updateUser",value:function(e){null!=e&&(this.users[e.id]=e)}},{key:"updateUserReference",value:function(e,t){null!=e&&(this.updateUser(e),this.userChannelReferences[e.id]||(this.userChannelReferences[e.id]={}),this.userChannelReferences[e.id][t]=!0)}},{key:"deleteAllChannelReference",value:function(e){for(var t in this.userChannelReferences)delete this.userChannelReferences[t][e]}}]),e}();function ec(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function eu(e){for(var t=1;t1)||void 0===arguments[1]||arguments[1];void 0!==e.code&&(n=e.code,r="unknown",s=e.reason),void 0!==e.error&&(n=e.error.code,r=e.error.StatusCode,s=e.error.message),t._log("_errorFromWSEvent() - WS failed with code ".concat(n),{event:e},"warn");var a=Error("WS failed with code ".concat(n," and reason - ").concat(s));return a.code=n,a.StatusCode=r,a.isWSFailure=i,a}),(0,m.Z)(this,"_setupConnectionPromise",function(){t.isResolved=!1,t.connectionOpen=new Promise(function(e,n){t.resolvePromise=e,t.rejectPromise=n})}),(0,m.Z)(this,"scheduleNextPing",function(){t.healthCheckTimeoutRef&&clearTimeout(t.healthCheckTimeoutRef),t.healthCheckTimeoutRef=setTimeout(function(){var e,n=[{type:"health.check",client_id:t.client.clientID}];try{null===(e=t.ws)||void 0===e||e.send(JSON.stringify(n))}catch(e){}},t.pingInterval)}),(0,m.Z)(this,"scheduleConnectionCheck",function(){t.connectionCheckTimeoutRef&&clearTimeout(t.connectionCheckTimeoutRef),t.connectionCheckTimeoutRef=setTimeout(function(){var e=new Date;t.lastEvent&&e.getTime()-t.lastEvent.getTime()>t.connectionCheckTimeout&&(t._log("scheduleConnectionCheck - going to reconnect"),t._setHealth(!1),t._reconnect())},t.connectionCheckTimeout)}),this.client=n,this.consecutiveFailures=0,this.totalFailures=0,this.isConnecting=!1,this.isDisconnected=!1,this.isResolved=!1,this.isHealthy=!1,this.wsID=1,this.lastEvent=null,this.pingInterval=25e3,this.connectionCheckTimeout=this.pingInterval+1e4,J(this.onlineStatusChanged)}return(0,g.Z)(s,[{key:"_log",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"info";this.client.logger(n,"connection:"+e,function(e){for(var t=1;t0&&void 0!==r[0]?r[0]:15e3,!this.isConnecting){e.next=3;break}throw Error("You've called connect twice, can only attempt 1 connection at the time");case 3:return this.isDisconnected=!1,e.prev=4,e.next=7,this._connect();case 7:n=e.sent,this.consecutiveFailures=0,this._log("connect() - Established ws connection with healthcheck: ".concat(n)),e.next=23;break;case 12:if(e.prev=12,e.t0=e.catch(4),this.isHealthy=!1,this.consecutiveFailures+=1,!(e.t0.code===W.TOKEN_EXPIRED&&!this.client.tokenManager.isStatic())){e.next=21;break}this._log("connect() - WS failure due to expired token, so going to try to reload token and reconnect"),this._reconnect({refreshToken:!0}),e.next=23;break;case 21:if(e.t0.isWSFailure){e.next=23;break}throw Error(JSON.stringify({code:e.t0.code,StatusCode:e.t0.StatusCode,message:e.t0.message,isWSFailure:e.t0.isWSFailure}));case 23:return e.next=25,this._waitForHealthy(t);case 25:return e.abrupt("return",e.sent);case 26:case"end":return e.stop()}},e,this,[[4,12]])})),function(){return e.apply(this,arguments)})},{key:"_waitForHealthy",value:(t=(0,f.Z)(b().mark(function e(){var t,n=this,r=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=r.length>0&&void 0!==r[0]?r[0]:15e3,e.abrupt("return",Promise.race([(0,f.Z)(b().mark(function e(){var r,s;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:r=50,s=0;case 2:if(!(s<=t)){e.next=18;break}return e.prev=3,e.next=6,n.connectionOpen;case 6:return e.abrupt("return",e.sent);case 9:if(e.prev=9,e.t0=e.catch(3),s!==t){e.next=13;break}throw Error(JSON.stringify({code:e.t0.code,StatusCode:e.t0.StatusCode,message:e.t0.message,isWSFailure:e.t0.isWSFailure}));case 13:return e.next=15,F(r);case 15:s+=r,e.next=2;break;case 18:case"end":return e.stop()}},e,null,[[3,9]])}))(),(0,f.Z)(b().mark(function e(){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,F(t);case 2:throw n.isConnecting=!1,Error(JSON.stringify({code:"",StatusCode:"",message:"initial WS connection could not be established",isWSFailure:!0}));case 4:case"end":return e.stop()}},e)}))()]));case 2:case"end":return e.stop()}},e)})),function(){return t.apply(this,arguments)})},{key:"disconnect",value:function(e){var t,n=this;this._log("disconnect() - Closing the websocket connection for wsID ".concat(this.wsID)),this.wsID+=1,this.isConnecting=!1,this.isDisconnected=!0,this.healthCheckTimeoutRef&&clearInterval(this.healthCheckTimeoutRef),this.connectionCheckTimeoutRef&&clearInterval(this.connectionCheckTimeoutRef),K(this.onlineStatusChanged),this.isHealthy=!1,this.ws&&this.ws.removeAllListeners&&this.ws.removeAllListeners();var r=this.ws;return r&&r.close&&r.readyState===r.OPEN?(t=new Promise(function(t){var s=function(e){n._log("disconnect() - resolving isClosedPromise ".concat(e?"with":"without"," close frame"),{event:e}),t()};r.onclose=s,setTimeout(s,null!=e?e:1e3)}),this._log("disconnect() - Manually closed connection by calling client.disconnect()"),r.close(W.WS_CLOSED_SUCCESS,"Manually closed connection by calling client.disconnect()")):(this._log("disconnect() - ws connection doesn't exist or it is already closed."),t=Promise.resolve()),delete this.ws,t}},{key:"_connect",value:(n=(0,f.Z)(b().mark(function e(){var t,n,r,s;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!(this.isConnecting||this.isDisconnected&&this.client.options.enableWSFallback)){e.next=2;break}return e.abrupt("return");case 2:return this.isConnecting=!0,this.requestID=H(),this.client.insightMetrics.connectionStartTimestamp=new Date().getTime(),t=!1,e.prev=6,this._log("_connect() - waiting for token"),e.next=10,this.client.tokenManager.tokenReady();case 10:t=!0,e.next=15;break;case 13:e.prev=13,e.t0=e.catch(6);case 15:if(e.prev=15,t){e.next=20;break}return this._log("_connect() - tokenProvider failed before, so going to retry"),e.next=20,this.client.tokenManager.loadToken();case 20:return this._setupConnectionPromise(),n=this._buildUrl(),this._log("_connect() - Connecting to ".concat(n),{wsURL:n,requestID:this.requestID}),this.ws=new(C())(n),this.ws.onopen=this.onopen.bind(this,this.wsID),this.ws.onclose=this.onclose.bind(this,this.wsID),this.ws.onerror=this.onerror.bind(this,this.wsID),this.ws.onmessage=this.onmessage.bind(this,this.wsID),e.next=30,this.connectionOpen;case 30:if(r=e.sent,this.isConnecting=!1,!r){e.next=36;break}return this.connectionID=r.connection_id,this.client.insightMetrics.wsConsecutiveFailures>0&&this.client.options.enableInsights&&(eh("ws_success_after_failure",ed(this)),this.client.insightMetrics.wsConsecutiveFailures=0),e.abrupt("return",r);case 36:e.next=44;break;case 38:throw e.prev=38,e.t1=e.catch(15),this.isConnecting=!1,this._log("_connect() - Error - ",e.t1),this.client.options.enableInsights&&(this.client.insightMetrics.wsConsecutiveFailures++,this.client.insightMetrics.wsTotalFailures++,s=eu(eu({},function(e){var t={};if(!e)return t;try{Object.getOwnPropertyNames(e).forEach(function(n){t[n]=Object.getOwnPropertyDescriptor(e,n)})}catch(e){return{error:"failed to serialize the error"}}return t}(e.t1)),ed(this)),null==eh||eh("ws_fatal",s)),e.t1;case 44:case"end":return e.stop()}},e,this,[[6,13],[15,38]])})),function(){return n.apply(this,arguments)})},{key:"_reconnect",value:(r=(0,f.Z)(b().mark(function e(){var t,n,r=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=r.length>0&&void 0!==r[0]?r[0]:{},this._log("_reconnect() - Initiating the reconnect"),!(this.isConnecting||this.isHealthy)){e.next=5;break}return this._log("_reconnect() - Abort (1) since already connecting or healthy"),e.abrupt("return");case 5:return(n=t.interval)||(n=B(this.consecutiveFailures)),e.next=9,F(n);case 9:if(!(this.isConnecting||this.isHealthy)){e.next=12;break}return this._log("_reconnect() - Abort (2) since already connecting or healthy"),e.abrupt("return");case 12:if(!(this.isDisconnected&&this.client.options.enableWSFallback)){e.next=15;break}return this._log("_reconnect() - Abort (3) since disconnect() is called"),e.abrupt("return");case 15:if(this._log("_reconnect() - Destroying current WS connection"),this._destroyCurrentWSConnection(),!t.refreshToken){e.next=20;break}return e.next=20,this.client.tokenManager.loadToken();case 20:return e.prev=20,e.next=23,this._connect();case 23:return this._log("_reconnect() - Waiting for recoverCallBack"),e.next=26,this.client.recoverState();case 26:this._log("_reconnect() - Finished recoverCallBack"),this.consecutiveFailures=0,e.next=38;break;case 30:if(e.prev=30,e.t0=e.catch(20),this.isHealthy=!1,this.consecutiveFailures+=1,!(e.t0.code===W.TOKEN_EXPIRED&&!this.client.tokenManager.isStatic())){e.next=37;break}return this._log("_reconnect() - WS failure due to expired token, so going to try to reload token and reconnect"),e.abrupt("return",this._reconnect({refreshToken:!0}));case 37:e.t0.isWSFailure&&(this._log("_reconnect() - WS failure, so going to try to reconnect"),this._reconnect());case 38:this._log("_reconnect() - == END ==");case 39:case"end":return e.stop()}},e,this,[[20,30]])})),function(){return r.apply(this,arguments)})},{key:"_destroyCurrentWSConnection",value:function(){this.wsID+=1;try{var e,t;this===null||void 0===this||null===(e=this.ws)||void 0===e||e.removeAllListeners(),this===null||void 0===this||null===(t=this.ws)||void 0===t||t.close()}catch(e){}}}]),s}();function ev(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function eg(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(arguments.length>3&&void 0!==arguments[3]&&arguments[3],"string"!=typeof t)throw TypeError("userId should be a string");throw!function(e){for(var t=1;t1&&void 0!==arguments[1]?arguments[1]:{},n=(0,l.Z)({algorithm:"HS256",noTimestamp:!0},t);return null.sign({server:!0},e,n)}var ey=function e(t){var n,r=this;(0,v.Z)(this,e),(0,m.Z)(this,"loadTokenPromise",void 0),(0,m.Z)(this,"type",void 0),(0,m.Z)(this,"secret",void 0),(0,m.Z)(this,"token",void 0),(0,m.Z)(this,"tokenProvider",void 0),(0,m.Z)(this,"user",void 0),(0,m.Z)(this,"setTokenOrProvider",(n=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r.validateToken(t,n),r.user=n,q(t)&&(r.tokenProvider=t,r.type="provider"),"string"==typeof t&&(r.token=t,r.type="static"),!t&&r.user&&r.secret&&(r.token=eg(r.secret,n.id,{},{}),r.type="static"),e.next=7,r.loadToken();case 7:case"end":return e.stop()}},e)})),function(e,t){return n.apply(this,arguments)})),(0,m.Z)(this,"reset",function(){r.token=void 0,r.user=void 0,r.loadTokenPromise=null}),(0,m.Z)(this,"validateToken",function(e,t){if(!t||!t.anon||e){if(!r.secret&&!e)throw Error("User token can not be empty");if(e&&"string"!=typeof e&&!q(e))throw Error("user token should either be a string or a function");if("string"==typeof e){if(t.anon&&""===e)return;var n,s=3!==(n=e.split(".")).length?"":JSON.parse(P(n[1])).user_id;if(null!=e&&(null==s||""===s||s!==t.id))throw Error("userToken does not have a user_id or is not matching with user.id")}}}),(0,m.Z)(this,"tokenReady",function(){return r.loadTokenPromise}),(0,m.Z)(this,"loadToken",function(){var e;return r.loadTokenPromise=new Promise((e=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if("static"!==r.type){e.next=2;break}return e.abrupt("return",t(r.token));case 2:if(!(r.tokenProvider&&"string"!=typeof r.tokenProvider)){e.next=13;break}return e.prev=3,e.next=6,r.tokenProvider();case 6:r.token=e.sent,e.next=12;break;case 9:return e.prev=9,e.t0=e.catch(3),e.abrupt("return",n(Error("Call to tokenProvider failed with message: ".concat(e.t0))));case 12:t(r.token);case 13:case"end":return e.stop()}},e,null,[[3,9]])})),function(t,n){return e.apply(this,arguments)})),r.loadTokenPromise}),(0,m.Z)(this,"getToken",function(){if(r.token||r.user&&r.user.anon&&!r.token)return r.token;if(r.secret)return em(r.secret);throw Error("Both secret and user tokens are not set. Either client.connectUser wasn't called or client.disconnect was called")}),(0,m.Z)(this,"isStatic",function(){return"static"===r.type}),this.loadTokenPromise=null,t&&(this.secret=t),this.type="static",this.secret&&(this.token=em(this.secret))},eb={"-1":{name:"InternalSystemError",retryable:!0},2:{name:"AccessKeyError",retryable:!1},3:{name:"AuthenticationFailedError",retryable:!0},4:{name:"InputError",retryable:!1},6:{name:"DuplicateUsernameError",retryable:!1},9:{name:"RateLimitError",retryable:!0},16:{name:"DoesNotExistError",retryable:!1},17:{name:"NotAllowedError",retryable:!1},18:{name:"EventNotSupportedError",retryable:!1},19:{name:"ChannelFeatureNotSupportedError",retryable:!1},20:{name:"MessageTooLongError",retryable:!1},21:{name:"MultipleNestingLevelError",retryable:!1},22:{name:"PayloadTooBigError",retryable:!1},23:{name:"RequestTimeoutError",retryable:!0},24:{name:"MaxHeaderSizeExceededError",retryable:!1},40:{name:"AuthErrorTokenExpired",retryable:!1},41:{name:"AuthErrorTokenNotValidYet",retryable:!1},42:{name:"AuthErrorTokenUsedBeforeIssuedAt",retryable:!1},43:{name:"AuthErrorTokenSignatureInvalid",retryable:!1},44:{name:"CustomCommandEndpointMissingError",retryable:!1},45:{name:"CustomCommandEndpointCallError",retryable:!0},46:{name:"ConnectionIDNotFoundError",retryable:!1},60:{name:"CoolDownError",retryable:!0},69:{name:"ErrWrongRegion",retryable:!1},70:{name:"ErrQueryChannelPermissions",retryable:!1},71:{name:"ErrTooManyConnections",retryable:!0},99:{name:"AppSuspendedError",retryable:!1}};function ew(e){if(!e.code)return!1;var t=eb["".concat(e.code)];return!!t&&t.retryable}function ek(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function e_(e){for(var t=1;t0&&void 0!==s[0]&&s[0],r.state!==o.Connecting){e.next=4;break}return r._log("connect() - connecting already in progress",{reconnect:t},"warn"),e.abrupt("return");case 4:if(r.state!==o.Connected){e.next=7;break}return r._log("connect() - already connected and polling",{reconnect:t},"warn"),e.abrupt("return");case 7:return r._setState(o.Connecting),r.connectionID=void 0,e.prev=9,e.next=12,r._req({json:r.client._buildWSPayload()},{timeout:8e3},t);case 12:return n=e.sent.event,r._setState(o.Connected),r.connectionID=n.connection_id,r.client.dispatchEvent(n),r._poll(),t&&r.client.recoverState(),e.abrupt("return",n);case 22:throw e.prev=22,e.t0=e.catch(9),r._setState(o.Closed),e.t0;case 26:case"end":return e.stop()}},e,null,[[9,22]])}))),(0,m.Z)(this,"isHealthy",function(){return!!r.connectionID&&r.state===o.Connected}),(0,m.Z)(this,"disconnect",(0,f.Z)(b().mark(function e(){var t,n,s,i=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=i.length>0&&void 0!==i[0]?i[0]:2e3,K(r._onlineStatusChanged),r._setState(o.Disconnected),null===(t=r.cancelToken)||void 0===t||t.cancel("disconnect() is called"),r.cancelToken=void 0,s=r.connectionID,r.connectionID=void 0,e.prev=7,e.next=10,r._req({close:!0,connection_id:s},{timeout:n},!1);case 10:r._log("disconnect() - Closed connectionID"),e.next=16;break;case 13:e.prev=13,e.t0=e.catch(7),r._log("disconnect() - Failed",{err:e.t0},"error");case 16:case"end":return e.stop()}},e,null,[[7,13]])}))),this.client=s,this.state=o.Init,this.consecutiveFailures=0,J(this._onlineStatusChanged)}return(0,g.Z)(e,[{key:"_log",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"info";this.client.logger(n,"WSConnectionFallback:"+e,e_({tags:["connection_fallback","connection"]},t))}},{key:"_setState",value:function(e){this._log("_setState() - ".concat(e)),this.state===o.Connecting&&e===o.Connected&&this.client.dispatchEvent({type:"connection.changed",online:!0}),(e===o.Closed||e===o.Disconnected)&&this.client.dispatchEvent({type:"connection.changed",online:!1}),this.state=e}}]),e}(),eZ=function(){var e,t,n,r,s,i;function a(e,t,n){(0,v.Z)(this,a),(0,m.Z)(this,"id",void 0),(0,m.Z)(this,"data",void 0),(0,m.Z)(this,"client",void 0),this.client=e,this.id=t,this.data=n}return(0,g.Z)(a,[{key:"create",value:(e=(0,f.Z)(b().mark(function e(){var t,n,r,s,i,a,o,c,u,l;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return u={id:this.id,message_template:null===(t=this.data)||void 0===t?void 0:t.message_template,segment_ids:null===(n=this.data)||void 0===n?void 0:n.segment_ids,sender_id:null===(r=this.data)||void 0===r?void 0:r.sender_id,channel_template:null===(s=this.data)||void 0===s?void 0:s.channel_template,create_channels:null===(i=this.data)||void 0===i?void 0:i.create_channels,description:null===(a=this.data)||void 0===a?void 0:a.description,name:null===(o=this.data)||void 0===o?void 0:o.name,user_ids:null===(c=this.data)||void 0===c?void 0:c.user_ids},e.next=3,this.client.createCampaign(u);case 3:return l=e.sent,this.id=l.campaign.id,this.data=l.campaign,e.abrupt("return",l);case 7:case"end":return e.stop()}},e,this)})),function(){return e.apply(this,arguments)})},{key:"verifyCampaignId",value:function(){if(!this.id)throw Error("Campaign id is missing. Either create the campaign using campaign.create() or set the id during instantiation - const campaign = client.campaign(id)")}},{key:"start",value:(t=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.verifyCampaignId(),e.next=3,this.client.startCampaign(this.id,t);case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return t.apply(this,arguments)})},{key:"update",value:(n=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.verifyCampaignId(),e.abrupt("return",this.client.updateCampaign(this.id,t));case 2:case"end":return e.stop()}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"delete",value:(r=(0,f.Z)(b().mark(function e(){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.verifyCampaignId(),e.next=3,this.client.deleteCampaign(this.id);case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(){return r.apply(this,arguments)})},{key:"stop",value:(s=(0,f.Z)(b().mark(function e(){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.verifyCampaignId(),e.abrupt("return",this.client.stopCampaign(this.id));case 2:case"end":return e.stop()}},e,this)})),function(){return s.apply(this,arguments)})},{key:"get",value:(i=(0,f.Z)(b().mark(function e(){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.verifyCampaignId(),e.abrupt("return",this.client.getCampaign(this.id));case 2:case"end":return e.stop()}},e,this)})),function(){return i.apply(this,arguments)})}]),a}(),eC=function(){var e,t,n,r,s,i,a,o;function c(e,t,n,r){(0,v.Z)(this,c),(0,m.Z)(this,"type",void 0),(0,m.Z)(this,"id",void 0),(0,m.Z)(this,"client",void 0),(0,m.Z)(this,"data",void 0),this.client=e,this.type=t,this.id=n,this.data=r}return(0,g.Z)(c,[{key:"create",value:(e=(0,f.Z)(b().mark(function e(){var t,n,r,s,i,a;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return a={name:null===(t=this.data)||void 0===t?void 0:t.name,filter:null===(n=this.data)||void 0===n?void 0:n.filter,description:null===(r=this.data)||void 0===r?void 0:r.description,all_sender_channels:null===(s=this.data)||void 0===s?void 0:s.all_sender_channels,all_users:null===(i=this.data)||void 0===i?void 0:i.all_users},e.abrupt("return",this.client.createSegment(this.type,this.id,a));case 2:case"end":return e.stop()}},e,this)})),function(){return e.apply(this,arguments)})},{key:"verifySegmentId",value:function(){if(!this.id)throw Error("Segment id is missing. Either create the segment using segment.create() or set the id during instantiation - const segment = client.segment(id)")}},{key:"get",value:(t=(0,f.Z)(b().mark(function e(){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.verifySegmentId(),e.abrupt("return",this.client.getSegment(this.id));case 2:case"end":return e.stop()}},e,this)})),function(){return t.apply(this,arguments)})},{key:"update",value:(n=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.verifySegmentId(),e.abrupt("return",this.client.updateSegment(this.id,t));case 2:case"end":return e.stop()}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"addTargets",value:(r=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.verifySegmentId(),e.abrupt("return",this.client.addSegmentTargets(this.id,t));case 2:case"end":return e.stop()}},e,this)})),function(e){return r.apply(this,arguments)})},{key:"removeTargets",value:(s=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.verifySegmentId(),e.abrupt("return",this.client.removeSegmentTargets(this.id,t));case 2:case"end":return e.stop()}},e,this)})),function(e){return s.apply(this,arguments)})},{key:"delete",value:(i=(0,f.Z)(b().mark(function e(){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.verifySegmentId(),e.abrupt("return",this.client.deleteSegment(this.id));case 2:case"end":return e.stop()}},e,this)})),function(){return i.apply(this,arguments)})},{key:"targetExists",value:(a=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.verifySegmentId(),e.abrupt("return",this.client.segmentTargetExists(this.id,t));case 2:case"end":return e.stop()}},e,this)})),function(e){return a.apply(this,arguments)})},{key:"queryTargets",value:(o=(0,f.Z)(b().mark(function e(){var t,n,r,s=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=s.length>0&&void 0!==s[0]?s[0]:{},n=s.length>1&&void 0!==s[1]?s[1]:[],r=s.length>2&&void 0!==s[2]?s[2]:{},this.verifySegmentId(),e.abrupt("return",this.client.querySegmentTargets(this.id,t,n,r));case 5:case"end":return e.stop()}},e,this)})),function(){return o.apply(this,arguments)})}]),c}(),eS=function(e){(0,U.Z)(r,e);var t,n=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}(),function(){var e,n=(0,O.Z)(r);return e=t?Reflect.construct(n,arguments,(0,O.Z)(this).constructor):n.apply(this,arguments),(0,R.Z)(this,e)});function r(){var e;(0,v.Z)(this,r);for(var t=arguments.length,s=Array(t),i=0;ie.length)&&(t=e.length);for(var n=0,r=Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:s}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){o=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(o)throw i}}}}(u);try{for(p.s();!(h=p.n()).done;){var f=h.value;this.read[f.user.id]=eO(eO({},f),{},{last_read:new Date(f.last_read)})}}catch(e){p.e(e)}finally{p.f()}}this.data=l}return(0,g.Z)(e,[{key:"getClient",value:function(){return this._client}},{key:"addReply",value:function(e){if(e.parent_id!==this.message.id)throw Error("Message does not belong to this thread");this.latestReplies=$(this.latestReplies,X(e),!0)}},{key:"updateReply",value:function(e){this.latestReplies=this.latestReplies.map(function(t){return t.id===e.id?X(e):t})}},{key:"updateMessageOrReplyIfExists",value:function(e){if((e.parent_id||e.id===this.message.id)&&(!e.parent_id||e.parent_id===this.message.id)){if(e.parent_id&&e.parent_id===this.message.id){this.updateReply(e);return}e.parent_id||e.id!==this.message.id||(this.message=X(e))}}},{key:"addReaction",value:function(e,t,n){var r=this;t&&(this.latestReplies=this.latestReplies.map(function(s){return s.id===t.id?X(r._channel.state.addReaction(e,t,n)):s}))}},{key:"removeReaction",value:function(e,t){var n=this;t&&(this.latestReplies=this.latestReplies.map(function(r){return r.id===t.id?X(n._channel.state.removeReaction(e,t)):r}))}}]),e}(),eE=["created_at","updated_at","last_active","online"],eL=["params","headers"];function eP(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return eT(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return eT(e,void 0)}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,s=function(){};return{s:s,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:s}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){o=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(o)throw i}}}}function eT(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n3&&void 0!==u[3]?u[3]:{},e.next=3,c.tokenManager.tokenReady();case 3:i=c._enrichAxiosOptions(s),e.prev=4,c._logApiRequest(t,n,r,i),e.t0=t,e.next="get"===e.t0?9:"delete"===e.t0?13:"post"===e.t0?17:"postForm"===e.t0?21:"put"===e.t0?25:"patch"===e.t0?29:"options"===e.t0?33:37;break;case 9:return e.next=11,c.axiosInstance.get(n,i);case 11:case 15:case 19:case 23:case 27:case 31:case 35:return a=e.sent,e.abrupt("break",38);case 13:return e.next=15,c.axiosInstance.delete(n,i);case 17:return e.next=19,c.axiosInstance.post(n,r,i);case 21:return e.next=23,c.axiosInstance.postForm(n,r,i);case 25:return e.next=27,c.axiosInstance.put(n,r,i);case 29:return e.next=31,c.axiosInstance.patch(n,r,i);case 33:return e.next=35,c.axiosInstance.options(n,i);case 37:throw Error("Invalid request type");case 38:return c._logApiResponse(t,n,a),c.consecutiveFailures=0,e.abrupt("return",c.handleResponse(a));case 43:if(e.prev=43,e.t1=e.catch(4),e.t1.client_request_id=null===(o=i.headers)||void 0===o?void 0:o["x-client-request-id"],c._logApiError(t,n,e.t1),c.consecutiveFailures+=1,!e.t1.response){e.next=60;break}if(!(e.t1.response.data.code===W.TOKEN_EXPIRED&&!c.tokenManager.isStatic())){e.next=57;break}if(!(c.consecutiveFailures>1)){e.next=53;break}return e.next=53,F(B(c.consecutiveFailures));case 53:return c.tokenManager.loadToken(),e.next=56,c.doAxiosRequest(t,n,r,s);case 56:return e.abrupt("return",e.sent);case 57:return e.abrupt("return",c.handleResponse(e.t1.response));case 60:throw e.t1;case 61:case"end":return e.stop()}},e,null,[[4,43]])})),function(e,t,n){return a.apply(this,arguments)})),(0,m.Z)(this,"dispatchEvent",function(e){e.received_at||(e.received_at=new Date);var t=c._handleClientEvent(e),n=e.cid,r=n?c.activeChannels[n]:void 0;r&&r._handleChannelEvent(e),c._callClientListeners(e),r&&r._callChannelListeners(e),t.forEach(function(e){return e()})}),(0,m.Z)(this,"handleEvent",function(e){var t=JSON.parse(e.data);c.dispatchEvent(t)}),(0,m.Z)(this,"_updateMemberWatcherReferences",function(e){var t=c.state.userChannelReferences[e.id]||{};for(var n in t){var r=c.activeChannels[n];null!=r&&r.state&&(r.state.members[e.id]&&(r.state.members[e.id].user=e),r.state.watchers[e.id]&&(r.state.watchers[e.id]=e),r.state.read[e.id]&&(r.state.read[e.id].user=e))}}),(0,m.Z)(this,"_updateUserReferences",this._updateMemberWatcherReferences),(0,m.Z)(this,"_updateUserMessageReferences",function(e){var t=c.state.userChannelReferences[e.id]||{};for(var n in t){var r=c.activeChannels[n];if(r){var s=r.state;null==s||s.updateUserMessages(e)}}}),(0,m.Z)(this,"_deleteUserMessageReference",function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=c.state.userChannelReferences[e.id]||{};for(var r in n){var s=c.activeChannels[r].state;null==s||s.deleteUserMessages(e,t)}}),(0,m.Z)(this,"_handleUserEvent",function(e){if(e.user){if("user.presence.changed"===e.type||"user.updated"===e.type){if(e.user.id===c.userID){var t=eA({},c.user||{}),n=eA({},c._user||{});for(var r in c.user)r in e.user||({channel_mutes:!0,devices:!0,mutes:!0,total_unread_count:!0,unread_channels:!0,unread_count:!0,unread_threads:!0,invisible:!0,privacy_settings:!0,roles:!0})[r]||(delete t[r],delete n[r]);for(var s in e.user)n&&s in n&&(n[s]=e.user[s]);c._user=eA({},n),c.user=eA(eA({},t),e.user)}c.state.updateUser(e.user),c._updateMemberWatcherReferences(e.user)}"user.updated"===e.type&&c._updateUserMessageReferences(e.user),"user.deleted"===e.type&&e.user.deleted_at&&(e.mark_messages_deleted||e.hard_delete)&&c._deleteUserMessageReference(e.user,e.hard_delete)}}),(0,m.Z)(this,"_callClientListeners",function(e){var t=[];c.listeners.all&&t.push.apply(t,(0,p.Z)(c.listeners.all)),c.listeners[e.type]&&t.push.apply(t,(0,p.Z)(c.listeners[e.type]));for(var n=0;n0&&(s.data=n,s._data=n),s}var i=new ei(c,e,t,n);return c.activeChannels[i.cid]=i,i}),(0,m.Z)(this,"updateUsers",this.upsertUsers),(0,m.Z)(this,"updateUser",this.upsertUser),(0,m.Z)(this,"_unblockMessage",this.unblockMessage),(0,m.Z)(this,"markAllRead",this.markChannelsRead),(0,m.Z)(this,"_isUsingServerAuth",function(){return!!c.secret}),(0,m.Z)(this,"_buildWSPayload",function(e){return JSON.stringify({user_id:c.userID,user_details:c._user,device:c.options.device,client_request_id:e})}),this.key=e,this.listeners={},this.state=new eo,this.mutedChannels=[],this.mutedUsers=[],t&&ej(t)&&(this.secret=t);var u=n||(t&&!ej(t)?t:{});this.browser=void 0!==u.browser?u.browser:"undefined"!=typeof window,this.node=!this.browser,this.options=eA({timeout:3e3,withCredentials:!1,warmUp:!1,recoverStateOnReconnect:!0},u),this.node&&!this.options.httpsAgent&&(this.options.httpsAgent=new null.Agent({keepAlive:!0,keepAliveMsecs:3e3})),this.axiosInstance=w.default.create(this.options),this.setBaseURL(this.options.baseURL||"https://chat.stream-io-api.com"),void 0!==E&&E.env.STREAM_LOCAL_TEST_RUN&&this.setBaseURL("http://localhost:3030"),void 0!==E&&E.env.STREAM_LOCAL_TEST_HOST&&this.setBaseURL("http://"+E.env.STREAM_LOCAL_TEST_HOST),this.wsConnection=null,this.wsPromise=null,this.setUserPromise=null,this.activeChannels={},this.configs={},this.anonymous=!1,this.persistUserOnConnectionFailure=null===(o=this.options)||void 0===o?void 0:o.persistUserOnConnectionFailure,this.tokenManager=new ey(this.secret),this.consecutiveFailures=0,this.insightMetrics=new el,this.defaultWSTimeoutWithFallback=6e3,this.defaultWSTimeout=15e3,this.axiosInstance.defaults.paramsSerializer=Q,this.logger=q(u.logger)?u.logger:function(){return null},this.recoverStateOnReconnect=this.options.recoverStateOnReconnect}return(0,g.Z)(tO,[{key:"devToken",value:function(e){var t;return["eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9",(t=JSON.stringify({user_id:e}),(0,u.JQ)(new Uint8Array(function(e,t){var n=[];if(L(e)&&t&&L(e)){for(var r=0,s=e.length;r1&&void 0!==r[1]?r[1]:{},e.next=3,this.post(this.baseURL+"/check_push",eA(eA(eA(eA(eA(eA(eA({user_id:t},n.messageID?{message_id:n.messageID}:{}),n.apnTemplate?{apn_template:n.apnTemplate}:{}),n.firebaseTemplate?{firebase_template:n.firebaseTemplate}:{}),n.firebaseDataTemplate?{firebase_data_template:n.firebaseDataTemplate}:{}),n.skipDevices?{skip_devices:!0}:{}),n.pushProviderName?{push_provider_name:n.pushProviderName}:{}),n.pushProviderType?{push_provider_type:n.pushProviderType}:{}));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"testSQSSettings",value:(a=(0,f.Z)(b().mark(function e(){var t,n=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>0&&void 0!==n[0]?n[0]:{},e.next=3,this.post(this.baseURL+"/check_sqs",t);case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(){return a.apply(this,arguments)})},{key:"testSNSSettings",value:(o=(0,f.Z)(b().mark(function e(){var t,n=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>0&&void 0!==n[0]?n[0]:{},e.next=3,this.post(this.baseURL+"/check_sns",t);case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(){return o.apply(this,arguments)})},{key:"setGuestUser",value:(c=(0,f.Z)(b().mark(function e(t){var n,r,s;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.anonymous=!0,e.prev=1,e.next=4,this.post(this.baseURL+"/guest",{user:t});case 4:n=e.sent,e.next=11;break;case 7:throw e.prev=7,e.t0=e.catch(1),this.anonymous=!1,e.t0;case 11:return this.anonymous=!1,(r=n.user).created_at,r.updated_at,r.last_active,r.online,s=(0,d.Z)(r,eE),e.next=15,this.connectUser(s,n.access_token);case 15:return e.abrupt("return",e.sent);case 16:case"end":return e.stop()}},e,this,[[1,7]])})),function(e){return c.apply(this,arguments)})},{key:"createToken",value:function(e,t,n){if(null==this.secret)throw Error("tokens can only be created server-side using the API Secret");var r={};return t&&(r.exp=t),n&&(r.iat=n),eg(this.secret,e,r,{})}},{key:"on",value:function(e,t){var n=this,r=t?e:"all",s=t||e;return r in this.listeners||(this.listeners[r]=[]),this.logger("info","Attaching listener for ".concat(r," event"),{tags:["event","client"]}),this.listeners[r].push(s),{unsubscribe:function(){n.logger("info","Removing listener for ".concat(r," event"),{tags:["event","client"]}),n.listeners[r]=n.listeners[r].filter(function(e){return e!==s})}}}},{key:"off",value:function(e,t){var n=t?e:"all",r=t||e;n in this.listeners||(this.listeners[n]=[]),this.logger("info","Removing listener for ".concat(n," event"),{tags:["event","client"]}),this.listeners[n]=this.listeners[n].filter(function(e){return e!==r})}},{key:"_logApiRequest",value:function(e,t,n,r){this.logger("info","client: ".concat(e," - Request - ").concat(t),{tags:["api","api_request","client"],url:t,payload:n,config:r})}},{key:"_logApiResponse",value:function(e,t,n){this.logger("info","client:".concat(e," - Response - url: ").concat(t," > status ").concat(n.status),{tags:["api","api_response","client"],url:t,response:n})}},{key:"_logApiError",value:function(e,t,n){this.logger("error","client:".concat(e," - Error - url: ").concat(t),{tags:["api","api_response","client"],url:t,error:n})}},{key:"get",value:function(e,t){return this.doAxiosRequest("get",e,null,{params:t})}},{key:"put",value:function(e,t){return this.doAxiosRequest("put",e,t)}},{key:"post",value:function(e,t){return this.doAxiosRequest("post",e,t)}},{key:"patch",value:function(e,t){return this.doAxiosRequest("patch",e,t)}},{key:"delete",value:function(e,t){return this.doAxiosRequest("delete",e,null,{params:t})}},{key:"sendFile",value:function(e,t,n,r,s){var i,a,o,c,u=(i=t,a=n,o=r||"multipart/form-data",c=new(x()),null!==i&&"object"===(0,h.Z)(i)&&(i.readable||"function"==typeof i._read)||null!=i&&null!=i.constructor&&"function"==typeof i.constructor.isBuffer&&i.constructor.isBuffer(i)||"undefined"!=typeof window&&"File"in window&&i instanceof File||"undefined"!=typeof window&&"Blob"in window&&i instanceof Blob?a?c.append("file",i,a):c.append("file",i):c.append("file",{uri:i,name:a||i.split("/").reverse()[0],contentType:o||void 0,type:o||void 0}),c);return null!=s&&u.append("user",JSON.stringify(s)),this.doAxiosRequest("postForm",e,u,{headers:u.getHeaders?u.getHeaders():{},config:{timeout:0,maxContentLength:1/0,maxBodyLength:1/0}})}},{key:"errorFromResponse",value:function(e){var t;return t=new eS("StreamChat error HTTP code: ".concat(e.status)),e.data&&e.data.code&&((t=Error("StreamChat error code ".concat(e.data.code,": ").concat(e.data.message))).code=e.data.code),t.response=e,t.status=e.status,t}},{key:"handleResponse",value:function(e){var t=e.data;if(!e.status||e.status<200||300<=e.status)throw this.errorFromResponse(e);return t}},{key:"_handleClientEvent",value:function(e){var t,n,r,s=this,i=[];return this.logger("info","client:_handleClientEvent - Received event of type { ".concat(e.type," }"),{tags:["event","client"],event:e}),("user.presence.changed"===e.type||"user.updated"===e.type||"user.deleted"===e.type)&&this._handleUserEvent(e),"health.check"===e.type&&e.me&&(this.user=e.me,this.state.updateUser(e.me),this.mutedChannels=e.me.channel_mutes,this.mutedUsers=e.me.mutes),e.channel&&"notification.message_new"===e.type&&this._addChannelConfig(e.channel),"notification.channel_mutes_updated"===e.type&&null!==(n=e.me)&&void 0!==n&&n.channel_mutes&&(this.mutedChannels=e.me.channel_mutes),"notification.mutes_updated"===e.type&&null!==(r=e.me)&&void 0!==r&&r.mutes&&(this.mutedUsers=e.me.mutes),"notification.mark_read"===e.type&&0===e.unread_channels&&Object.keys(this.activeChannels).forEach(function(e){return s.activeChannels[e].state.unreadCount=0}),("channel.deleted"===e.type||"notification.channel_deleted"===e.type)&&e.cid&&(this.state.deleteAllChannelReference(e.cid),null===(t=this.activeChannels[e.cid])||void 0===t||t._disconnect(),i.push(function(){e.cid&&delete s.activeChannels[e.cid]})),i}},{key:"_muteStatus",value:function(e){for(var t,n=0;nnew Date().getTime(),createdAt:s.created_at?new Date(s.created_at):new Date,expiresAt:s.expires?new Date(s.expires):null};break}}return t||{muted:!1,createdAt:null,expiresAt:null}}},{key:"connect",value:(y=(0,f.Z)(b().mark(function e(){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!(!this.userID||!this._user)){e.next=2;break}throw Error("Call connectUser or connectAnonymousUser before starting the connection");case 2:if(this.wsBaseURL){e.next=4;break}throw Error("Websocket base url not set");case 4:if(this.clientID){e.next=6;break}throw Error("clientID is not set");case 6:if(!this.wsConnection&&(this.options.warmUp||this.options.enableInsights)&&this._sayHi(),this.options.wsConnection&&this.node?(this.options.wsConnection.setClient(this),this.wsConnection=this.options.wsConnection):this.wsConnection=new ef({client:this}),e.prev=8,!this.wsFallback){e.next=13;break}return e.next=12,this.wsFallback.connect();case 12:case 15:case 28:return e.abrupt("return",e.sent);case 13:return e.next=15,this.wsConnection.connect(this.options.enableWSFallback?this.defaultWSTimeoutWithFallback:this.defaultWSTimeout);case 18:if(e.prev=18,e.t0=e.catch(8),!(this.options.enableWSFallback&&function(e){if("boolean"==typeof e.isWSFailure)return e.isWSFailure;try{return JSON.parse(e.message).isWSFailure}catch(e){return!1}}(e.t0)&&function(){var e="undefined"!=typeof navigator?navigator:"undefined"!=typeof window&&window.navigator?window.navigator:void 0;return e?"boolean"!=typeof e.onLine||e.onLine:(console.warn("isOnline failed to access window.navigator and assume browser is online"),!0)}())){e.next=29;break}return this.logger("info","client:connect() - WS failed, fallback to longpoll",{tags:["connection","client"]}),this.dispatchEvent({type:"transport.changed",mode:"longpoll"}),this.wsConnection._destroyCurrentWSConnection(),this.wsConnection.disconnect().then(),this.wsFallback=new ex({client:this}),e.next=28,this.wsFallback.connect();case 29:throw e.t0;case 30:case"end":return e.stop()}},e,this,[[8,18]])})),function(){return y.apply(this,arguments)})},{key:"_sayHi",value:function(){var e=this,t=H();this.doAxiosRequest("get",this.baseURL+"/hi",null,{headers:{"x-client-request-id":t}}).catch(function(n){e.options.enableInsights&&eh("http_hi_failed",{api_key:e.key,err:n,client_request_id:t})})}},{key:"queryUsers",value:(k=(0,f.Z)(b().mark(function e(t){var n,r,s,i,a=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=a.length>1&&void 0!==a[1]?a[1]:[],r=a.length>2&&void 0!==a[2]?a[2]:{},s={presence:!1},e.next=5,this.wsPromise;case 5:return this._hasConnectionID()||(s.presence=!1),e.next=8,this.get(this.baseURL+"/users",{payload:eA(eA({filter_conditions:t,sort:N(n)},s),r)});case 8:return i=e.sent,this.state.updateUsers(i.users),e.abrupt("return",i);case 11:case"end":return e.stop()}},e,this)})),function(e){return k.apply(this,arguments)})},{key:"queryBannedUsers",value:(_=(0,f.Z)(b().mark(function e(){var t,n,r,s=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=s.length>0&&void 0!==s[0]?s[0]:{},n=s.length>1&&void 0!==s[1]?s[1]:[],r=s.length>2&&void 0!==s[2]?s[2]:{},e.next=5,this.get(this.baseURL+"/query_banned_users",{payload:eA({filter_conditions:t,sort:N(n)},r)});case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}},e,this)})),function(){return _.apply(this,arguments)})},{key:"queryMessageFlags",value:(Z=(0,f.Z)(b().mark(function e(){var t,n,r=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=r.length>0&&void 0!==r[0]?r[0]:{},n=r.length>1&&void 0!==r[1]?r[1]:{},e.next=4,this.get(this.baseURL+"/moderation/flags/message",{payload:eA({filter_conditions:t},n)});case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}},e,this)})),function(){return Z.apply(this,arguments)})},{key:"queryChannels",value:(C=(0,f.Z)(b().mark(function e(t){var n,r,s,i,a,o,c=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=c.length>1&&void 0!==c[1]?c[1]:[],r=c.length>2&&void 0!==c[2]?c[2]:{},s=c.length>3&&void 0!==c[3]?c[3]:{},i={state:!0,watch:!0,presence:!1},e.next=6,this.wsPromise;case 6:return this._hasConnectionID()||(i.watch=!1),a=eA(eA({filter_conditions:t,sort:N(n)},i),r),e.next=10,this.post(this.baseURL+"/channels",a);case 10:return o=e.sent,this.dispatchEvent({type:"channels.queried",queriedChannels:{channels:o.channels,isLatestMessageSet:!0}}),e.abrupt("return",this.hydrateActiveChannels(o.channels,s));case 13:case"end":return e.stop()}},e,this)})),function(e){return C.apply(this,arguments)})},{key:"queryReactions",value:(S=(0,f.Z)(b().mark(function e(t,n){var r,s,i,a=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=a.length>2&&void 0!==a[2]?a[2]:[],s=a.length>3&&void 0!==a[3]?a[3]:{},e.next=4,this.wsPromise;case 4:return i=eA({filter:n,sort:N(r)},s),e.next=7,this.post(this.baseURL+"/messages/"+t+"/reactions",i);case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}},e,this)})),function(e,t){return S.apply(this,arguments)})},{key:"hydrateActiveChannels",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.skipInitialization,s=n.offlineMode,i=void 0!==s&&s,a=eP(t);try{for(a.s();!(e=a.n()).done;){var o=e.value;this._addChannelConfig(o.channel)}}catch(e){a.e(e)}finally{a.f()}var c,u=[],l=eP(t);try{for(l.s();!(c=l.n()).done;){var h=c.value,d=this.channel(h.channel.type,h.channel.id);d.data=h.channel,d.offlineMode=i,d.initialized=!i,void 0===r?d._initializeState(h,"latest"):r.includes(h.channel.id)||(d.state.clearMessages(),d._initializeState(h,"latest")),u.push(d)}}catch(e){l.e(e)}finally{l.f()}return u}},{key:"search",value:(U=(0,f.Z)(b().mark(function e(t,n){var r,s,i=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!((r=i.length>2&&void 0!==i[2]?i[2]:{}).offset&&r.next)){e.next=3;break}throw Error("Cannot specify offset with next");case 3:if(s=eA(eA({filter_conditions:t},r),{},{sort:r.sort?N(r.sort):void 0}),"string"!=typeof n){e.next=8;break}s.query=n,e.next=13;break;case 8:if("object"!==(0,h.Z)(n)){e.next=12;break}s.message_filter_conditions=n,e.next=13;break;case 12:throw Error("Invalid type ".concat((0,h.Z)(n)," for query parameter"));case 13:return e.next=15,this.wsPromise;case 15:return e.next=17,this.get(this.baseURL+"/search",{payload:s});case 17:return e.abrupt("return",e.sent);case 18:case"end":return e.stop()}},e,this)})),function(e,t){return U.apply(this,arguments)})},{key:"setLocalDevice",value:function(e){var t,n,r;if(null!==(t=this.wsConnection)&&void 0!==t&&t.isConnecting&&this.wsPromise||(null!==(n=this.wsConnection)&&void 0!==n&&n.isHealthy||null!==(r=this.wsFallback)&&void 0!==r&&r.isHealthy())&&this._hasConnectionID())throw Error("you can only set device before opening a websocket connection");this.options.device=e}},{key:"addDevice",value:(R=(0,f.Z)(b().mark(function e(t,n,r,s){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/devices",eA(eA({id:t,push_provider:n},null!=r?{user_id:r}:{}),null!=s?{push_provider_name:s}:{}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t,n,r){return R.apply(this,arguments)})},{key:"getDevices",value:(O=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/devices",t?{user_id:t}:{});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return O.apply(this,arguments)})},{key:"getUnreadCount",value:(I=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/unread",t?{user_id:t}:{});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return I.apply(this,arguments)})},{key:"getUnreadCountBatch",value:(P=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/unread_batch",{user_ids:t});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return P.apply(this,arguments)})},{key:"removeDevice",value:(T=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.delete(this.baseURL+"/devices",eA({id:t},n?{user_id:n}:{}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return T.apply(this,arguments)})},{key:"getRateLimits",value:(D=(0,f.Z)(b().mark(function e(t){var n,r,s,i,a,o;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=(n=t||{}).serverSide,s=n.web,i=n.android,a=n.ios,o=n.endpoints,e.abrupt("return",this.get(this.baseURL+"/rate_limits",{server_side:r,web:s,android:i,ios:a,endpoints:o?o.join(","):void 0}));case 2:case"end":return e.stop()}},e,this)})),function(e){return D.apply(this,arguments)})},{key:"_addChannelConfig",value:function(e){var t=e.cid,n=e.config;this.configs[t]=n}},{key:"channel",value:function(e,t){var n,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!this.userID&&!this._isUsingServerAuth())throw Error("Call connectUser or connectAnonymousUser before creating a channel");if(~e.indexOf(":"))throw Error("Invalid channel group ".concat(e,", can't contain the : character"));return t&&"object"===(0,h.Z)(t)?this.getChannelByMembers(e,t):!t&&"object"===(0,h.Z)(r)&&null!==(n=r.members)&&void 0!==n&&n.length?this.getChannelByMembers(e,r):t?this.getChannelById(e,t,r):new ei(this,e,void 0,r)}},{key:"partialUpdateUser",value:(A=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.partialUpdateUsers([t]);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return A.apply(this,arguments)})},{key:"upsertUsers",value:(j=(0,f.Z)(b().mark(function e(t){var n,r,s,i;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:n={},r=eP(t),e.prev=2,r.s();case 4:if((s=r.n()).done){e.next=11;break}if((i=s.value).id){e.next=8;break}throw Error("User ID is required when updating a user");case 8:n[i.id]=i;case 9:e.next=4;break;case 11:e.next=16;break;case 13:e.prev=13,e.t0=e.catch(2),r.e(e.t0);case 16:return e.prev=16,r.f(),e.finish(16);case 19:return e.next=21,this.post(this.baseURL+"/users",{users:n});case 21:return e.abrupt("return",e.sent);case 22:case"end":return e.stop()}},e,this,[[2,13,16,19]])})),function(e){return j.apply(this,arguments)})},{key:"upsertUser",value:function(e){return this.upsertUsers([e])}},{key:"partialUpdateUsers",value:(z=(0,f.Z)(b().mark(function e(t){var n,r;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:n=eP(t),e.prev=1,n.s();case 3:if((r=n.n()).done){e.next=9;break}if(r.value.id){e.next=7;break}throw Error("User ID is required when updating a user");case 7:e.next=3;break;case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(1),n.e(e.t0);case 14:return e.prev=14,n.f(),e.finish(14);case 17:return e.next=19,this.patch(this.baseURL+"/users",{users:t});case 19:return e.abrupt("return",e.sent);case 20:case"end":return e.stop()}},e,this,[[1,11,14,17]])})),function(e){return z.apply(this,arguments)})},{key:"deleteUser",value:(V=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.delete(this.baseURL+"/users/".concat(t),n);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return V.apply(this,arguments)})},{key:"restoreUsers",value:(J=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/restore",{user_ids:t});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return J.apply(this,arguments)})},{key:"reactivateUser",value:(K=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/".concat(t,"/reactivate"),eA({},n));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return K.apply(this,arguments)})},{key:"reactivateUsers",value:(X=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/reactivate",eA({user_ids:t},n));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return X.apply(this,arguments)})},{key:"deactivateUser",value:($=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/".concat(t,"/deactivate"),eA({},n));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return $.apply(this,arguments)})},{key:"deactivateUsers",value:(G=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/deactivate",eA({user_ids:t},n));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return G.apply(this,arguments)})},{key:"exportUser",value:(Y=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/users/".concat(t,"/export"),eA({},n));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return Y.apply(this,arguments)})},{key:"banUser",value:(ee=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/moderation/ban",eA({target_user_id:t},n));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return ee.apply(this,arguments)})},{key:"unbanUser",value:(et=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.delete(this.baseURL+"/moderation/ban",eA({target_user_id:t},n));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return et.apply(this,arguments)})},{key:"shadowBan",value:(en=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.banUser(t,eA({shadow:!0},n));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return en.apply(this,arguments)})},{key:"removeShadowBan",value:(er=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.unbanUser(t,eA({shadow:!0},n));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return er.apply(this,arguments)})},{key:"blockUser",value:(es=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/block",eA({blocked_user_id:t},n?{user_id:n}:{}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return es.apply(this,arguments)})},{key:"getBlockedUsers",value:(ea=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/users/block",eA({},t?{user_id:t}:{}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return ea.apply(this,arguments)})},{key:"unBlockUser",value:(ec=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/unblock",eA({blocked_user_id:t},n?{user_id:n}:{}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return ec.apply(this,arguments)})},{key:"muteUser",value:(eu=(0,f.Z)(b().mark(function e(t,n){var r,s=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=s.length>2&&void 0!==s[2]?s[2]:{},e.next=3,this.post(this.baseURL+"/moderation/mute",eA(eA({target_id:t},n?{user_id:n}:{}),r));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e,t){return eu.apply(this,arguments)})},{key:"unmuteUser",value:(ed=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/moderation/unmute",eA({target_id:t},n?{user_id:n}:{}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return ed.apply(this,arguments)})},{key:"userMuteStatus",value:function(e){if(!this.user||!this.wsPromise)throw Error("Make sure to await connectUser() first.");for(var t=0;t1&&void 0!==r[1]?r[1]:{},e.next=3,this.post(this.baseURL+"/moderation/flag",eA({target_message_id:t},n));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return ep.apply(this,arguments)})},{key:"flagUser",value:(ev=(0,f.Z)(b().mark(function e(t){var n,r=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.length>1&&void 0!==r[1]?r[1]:{},e.next=3,this.post(this.baseURL+"/moderation/flag",eA({target_user_id:t},n));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return ev.apply(this,arguments)})},{key:"unflagMessage",value:(em=(0,f.Z)(b().mark(function e(t){var n,r=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.length>1&&void 0!==r[1]?r[1]:{},e.next=3,this.post(this.baseURL+"/moderation/unflag",eA({target_message_id:t},n));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return em.apply(this,arguments)})},{key:"unflagUser",value:(eb=(0,f.Z)(b().mark(function e(t){var n,r=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.length>1&&void 0!==r[1]?r[1]:{},e.next=3,this.post(this.baseURL+"/moderation/unflag",eA({target_user_id:t},n));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return eb.apply(this,arguments)})},{key:"getCallToken",value:(ew=(0,f.Z)(b().mark(function e(t){var n,r=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.length>1&&void 0!==r[1]?r[1]:{},e.next=3,this.post(this.baseURL+"/calls/".concat(t),eA({},n));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return ew.apply(this,arguments)})},{key:"_queryFlags",value:(ek=(0,f.Z)(b().mark(function e(){var t,n,r=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=r.length>0&&void 0!==r[0]?r[0]:{},n=r.length>1&&void 0!==r[1]?r[1]:{},e.next=4,this.post(this.baseURL+"/moderation/flags",eA({filter_conditions:t},n));case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}},e,this)})),function(){return ek.apply(this,arguments)})},{key:"_queryFlagReports",value:(e_=(0,f.Z)(b().mark(function e(){var t,n,r=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=r.length>0&&void 0!==r[0]?r[0]:{},n=r.length>1&&void 0!==r[1]?r[1]:{},e.next=4,this.post(this.baseURL+"/moderation/reports",eA({filter_conditions:t},n));case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}},e,this)})),function(){return e_.apply(this,arguments)})},{key:"_reviewFlagReport",value:(eU=(0,f.Z)(b().mark(function e(t,n){var r,s=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=s.length>2&&void 0!==s[2]?s[2]:{},e.next=3,this.patch(this.baseURL+"/moderation/reports/".concat(t),eA({review_result:n},r));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e,t){return eU.apply(this,arguments)})},{key:"unblockMessage",value:(eR=(0,f.Z)(b().mark(function e(t){var n,r=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.length>1&&void 0!==r[1]?r[1]:{},e.next=3,this.post(this.baseURL+"/moderation/unblock_message",eA({target_message_id:t},n));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return eR.apply(this,arguments)})},{key:"markChannelsRead",value:(eO=(0,f.Z)(b().mark(function e(){var t,n=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>0&&void 0!==n[0]?n[0]:{},e.next=3,this.post(this.baseURL+"/channels/read",eA({},t));case 3:case"end":return e.stop()}},e,this)})),function(){return eO.apply(this,arguments)})},{key:"createCommand",value:function(e){return this.post(this.baseURL+"/commands",e)}},{key:"getCommand",value:function(e){return this.get(this.baseURL+"/commands/".concat(e))}},{key:"updateCommand",value:function(e,t){return this.put(this.baseURL+"/commands/".concat(e),t)}},{key:"deleteCommand",value:function(e){return this.delete(this.baseURL+"/commands/".concat(e))}},{key:"listCommands",value:function(){return this.get(this.baseURL+"/commands")}},{key:"createChannelType",value:function(e){var t=(0,l.Z)({},{commands:["all"]},e);return this.post(this.baseURL+"/channeltypes",t)}},{key:"getChannelType",value:function(e){return this.get(this.baseURL+"/channeltypes/".concat(e))}},{key:"updateChannelType",value:function(e,t){return this.put(this.baseURL+"/channeltypes/".concat(e),t)}},{key:"deleteChannelType",value:function(e){return this.delete(this.baseURL+"/channeltypes/".concat(e))}},{key:"listChannelTypes",value:function(){return this.get(this.baseURL+"/channeltypes")}},{key:"translateMessage",value:(eI=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/messages/".concat(t,"/translate"),{language:n});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return eI.apply(this,arguments)})},{key:"_normalizeExpiration",value:function(e){var t=null;if("number"==typeof e){var n=new Date;n.setSeconds(n.getSeconds()+e),t=n.toISOString()}else ej(e)?t=e:e instanceof Date&&(t=e.toISOString());return t}},{key:"_validateAndGetMessageId",value:function(e,t){var n;if("string"==typeof e)n=e;else{if(!e.id)throw Error(t);n=e.id}return n}},{key:"pinMessage",value:function(e,t,n,r){var s=this._validateAndGetMessageId(e,"Please specify the message id when calling unpinMessage");return this.partialUpdateMessage(s,{set:{pinned:!0,pin_expires:this._normalizeExpiration(t),pinned_at:this._normalizeExpiration(r)}},n)}},{key:"unpinMessage",value:function(e,t){var n=this._validateAndGetMessageId(e,"Please specify the message id when calling unpinMessage");return this.partialUpdateMessage(n,{set:{pinned:!1}},t)}},{key:"updateMessage",value:(eT=(0,f.Z)(b().mark(function e(t,n,r){var s;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t.id){e.next=2;break}throw Error("Please specify the message id when calling updateMessage");case 2:return s=(0,l.Z)({},t),delete s.id,["command","created_at","html","latest_reactions","own_reactions","quoted_message","reaction_counts","reply_count","type","updated_at","user","__html"].forEach(function(e){null!=s[e]&&delete s[e]}),null!=n&&(ej(n)?s.user_id=n:s.user={id:n.id}),Array.isArray(s.mentioned_users)&&!ej(s.mentioned_users[0])&&(s.mentioned_users=s.mentioned_users.map(function(e){return e.id})),e.next=10,this.post(this.baseURL+"/messages/".concat(t.id),eA({message:s},r));case 10:return e.abrupt("return",e.sent);case 11:case"end":return e.stop()}},e,this)})),function(e,t,n){return eT.apply(this,arguments)})},{key:"partialUpdateMessage",value:(eD=(0,f.Z)(b().mark(function e(t,n,r,s){var i;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}throw Error("Please specify the message id when calling partialUpdateMessage");case 2:return i=r,null!=r&&ej(r)&&(i={id:r}),e.next=6,this.put(this.baseURL+"/messages/".concat(t),eA(eA(eA({},n),s),{},{user:i}));case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}},e,this)})),function(e,t,n,r){return eD.apply(this,arguments)})},{key:"deleteMessage",value:(eF=(0,f.Z)(b().mark(function e(t,n){var r;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r={},n&&(r={hard:!0}),e.next=4,this.delete(this.baseURL+"/messages/".concat(t),r);case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}},e,this)})),function(e,t){return eF.apply(this,arguments)})},{key:"undeleteMessage",value:(eq=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/messages/".concat(t,"/undelete"),{undeleted_by:n});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return eq.apply(this,arguments)})},{key:"getMessage",value:(eW=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/messages/".concat(encodeURIComponent(t)),eA({},n));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return eW.apply(this,arguments)})},{key:"queryThreads",value:(eN=(0,f.Z)(b().mark(function e(t){var n,r,s=this;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=eA({limit:10,participant_limit:10,reply_limit:3,watch:!0},t),e.next=3,this.post(this.baseURL+"/threads",n);case 3:return r=e.sent,e.abrupt("return",{threads:r.threads.map(function(e){return new eM(s,e)}),next:r.next});case 5:case"end":return e.stop()}},e,this)})),function(e){return eN.apply(this,arguments)})},{key:"getThread",value:(eB=(0,f.Z)(b().mark(function e(t){var n,r,s,i=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n=i.length>1&&void 0!==i[1]?i[1]:{},t){e.next=3;break}throw Error("Please specify the message id when calling partialUpdateThread");case 3:return r=eA({participant_limit:100,reply_limit:3,watch:!0},n),e.next=6,this.get(this.baseURL+"/threads/".concat(t),r);case 6:return s=e.sent,e.abrupt("return",new eM(this,s.thread));case 8:case"end":return e.stop()}},e,this)})),function(e){return eB.apply(this,arguments)})},{key:"partialUpdateThread",value:(ez=(0,f.Z)(b().mark(function e(t,n){var r,s;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}throw Error("Please specify the message id when calling partialUpdateThread");case 2:r=["created_at","id","last_message_at","type","updated_at","user","reply_count","participants","channel"],e.t0=b().keys(eA(eA({},n.set),n.unset));case 4:if((e.t1=e.t0()).done){e.next=10;break}if(s=e.t1.value,!r.includes(s)){e.next=8;break}throw Error("You cannot set ".concat(s," field on Thread object. ").concat(s," is reserved for server-side use. Please omit ").concat(s," from your set object."));case 8:e.next=4;break;case 10:return e.next=12,this.patch(this.baseURL+"/threads/".concat(t),n);case 12:return e.abrupt("return",e.sent);case 13:case"end":return e.stop()}},e,this)})),function(e,t){return ez.apply(this,arguments)})},{key:"getUserAgent",value:function(){return this.userAgent||"stream-chat-javascript-client-".concat(this.node?"node":"browser","-","8.37.0")}},{key:"setUserAgent",value:function(e){this.userAgent=e}},{key:"_enrichAxiosOptions",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{params:{},headers:{},config:{}},n=this._getToken(),r=null;null!==this.nextRequestAbortController&&(r=this.nextRequestAbortController.signal,this.nextRequestAbortController=null),null!==(e=t.headers)&&void 0!==e&&e["x-client-request-id"]||(t.headers=eA(eA({},t.headers),{},{"x-client-request-id":H()}));var s=this.options.axiosRequestConfig||{},i=s.params,a=s.headers,o=(0,d.Z)(s,eL);return eA(eA(eA({params:eA(eA({user_id:this.userID,connection_id:this._getConnectionID(),api_key:this.key},t.params),i||{}),headers:eA(eA(eA({},n?{Authorization:n}:void 0),{},{"stream-auth-type":this.getAuthType(),"X-Stream-Client":this.getUserAgent()},t.headers),a||{})},r?{signal:r}:{}),t.config),o||{})}},{key:"_getToken",value:function(){return!this.tokenManager||this.anonymous?null:this.tokenManager.getToken()}},{key:"_startCleaning",value:function(){var e=this;null==this.cleaningIntervalRef&&(this.cleaningIntervalRef=setInterval(function(){for(var t=0,n=Object.values(e.activeChannels);t2&&void 0!==arguments[2]?arguments[2]:{};return this.post("".concat(this.baseURL,"/sync"),eA({channel_cids:e,last_sync_at:t},n))}},{key:"sendUserCustomEvent",value:(eH=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post("".concat(this.baseURL,"/users/").concat(t,"/event"),{event:n});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return eH.apply(this,arguments)})},{key:"createBlockList",value:function(e){return this.post("".concat(this.baseURL,"/blocklists"),e)}},{key:"listBlockLists",value:function(){return this.get("".concat(this.baseURL,"/blocklists"))}},{key:"getBlockList",value:function(e){return this.get("".concat(this.baseURL,"/blocklists/").concat(e))}},{key:"updateBlockList",value:function(e,t){return this.put("".concat(this.baseURL,"/blocklists/").concat(e),t)}},{key:"deleteBlockList",value:function(e){return this.delete("".concat(this.baseURL,"/blocklists/").concat(e))}},{key:"exportChannels",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=eA({channels:e},t);return this.post("".concat(this.baseURL,"/export_channels"),n)}},{key:"exportUsers",value:function(e){return this.post("".concat(this.baseURL,"/export/users"),e)}},{key:"exportChannel",value:function(e,t){return this.exportChannels([e],t)}},{key:"getExportChannelStatus",value:function(e){return this.get("".concat(this.baseURL,"/export_channels/").concat(e))}},{key:"campaign",value:function(e,t){return e&&"object"===(0,h.Z)(e)?new eZ(this,null,e):new eZ(this,e,t)}},{key:"segment",value:function(e,t,n){return"string"==typeof t?new eC(this,e,t,n):new eC(this,e,null,t)}},{key:"validateServerSideAuth",value:function(){if(!this.secret)throw Error("Campaigns is a server-side only feature. Please initialize the client with a secret to use this feature.")}},{key:"createSegment",value:(eV=(0,f.Z)(b().mark(function e(t,n,r){var s;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),s=eA({id:n,type:t},r),e.abrupt("return",this.post(this.baseURL+"/segments",s));case 3:case"end":return e.stop()}},e,this)})),function(e,t,n){return eV.apply(this,arguments)})},{key:"createUserSegment",value:(eJ=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.createSegment("user",t,n));case 2:case"end":return e.stop()}},e,this)})),function(e,t){return eJ.apply(this,arguments)})},{key:"createChannelSegment",value:(eK=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.createSegment("channel",t,n));case 2:case"end":return e.stop()}},e,this)})),function(e,t){return eK.apply(this,arguments)})},{key:"getSegment",value:(eQ=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.get(this.baseURL+"/segments/".concat(t)));case 2:case"end":return e.stop()}},e,this)})),function(e){return eQ.apply(this,arguments)})},{key:"updateSegment",value:(eX=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.put(this.baseURL+"/segments/".concat(t),n));case 2:case"end":return e.stop()}},e,this)})),function(e,t){return eX.apply(this,arguments)})},{key:"addSegmentTargets",value:(e$=(0,f.Z)(b().mark(function e(t,n){var r;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),r={target_ids:n},e.abrupt("return",this.post(this.baseURL+"/segments/".concat(t,"/addtargets"),r));case 3:case"end":return e.stop()}},e,this)})),function(e,t){return e$.apply(this,arguments)})},{key:"querySegmentTargets",value:(eG=(0,f.Z)(b().mark(function e(t){var n,r,s,i=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=i.length>1&&void 0!==i[1]?i[1]:{},r=i.length>2&&void 0!==i[2]?i[2]:[],s=i.length>3&&void 0!==i[3]?i[3]:{},this.validateServerSideAuth(),e.abrupt("return",this.post(this.baseURL+"/segments/".concat(t,"/targets/query"),eA({filter:n||{},sort:r||[]},s)));case 5:case"end":return e.stop()}},e,this)})),function(e){return eG.apply(this,arguments)})},{key:"removeSegmentTargets",value:(eY=(0,f.Z)(b().mark(function e(t,n){var r;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),r={target_ids:n},e.abrupt("return",this.post(this.baseURL+"/segments/".concat(t,"/deletetargets"),r));case 3:case"end":return e.stop()}},e,this)})),function(e,t){return eY.apply(this,arguments)})},{key:"querySegments",value:(e0=(0,f.Z)(b().mark(function e(t,n){var r,s=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=s.length>2&&void 0!==s[2]?s[2]:{},this.validateServerSideAuth(),e.abrupt("return",this.post(this.baseURL+"/segments/query",eA({filter:t,sort:n},r)));case 3:case"end":return e.stop()}},e,this)})),function(e,t){return e0.apply(this,arguments)})},{key:"deleteSegment",value:(e1=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.delete(this.baseURL+"/segments/".concat(t)));case 2:case"end":return e.stop()}},e,this)})),function(e){return e1.apply(this,arguments)})},{key:"segmentTargetExists",value:(e2=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.get(this.baseURL+"/segments/".concat(t,"/target/").concat(n)));case 2:case"end":return e.stop()}},e,this)})),function(e,t){return e2.apply(this,arguments)})},{key:"createCampaign",value:(e3=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.post(this.baseURL+"/campaigns",eA({},t)));case 2:case"end":return e.stop()}},e,this)})),function(e){return e3.apply(this,arguments)})},{key:"getCampaign",value:(e4=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.get(this.baseURL+"/campaigns/".concat(t)));case 2:case"end":return e.stop()}},e,this)})),function(e){return e4.apply(this,arguments)})},{key:"startCampaign",value:(e5=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.post(this.baseURL+"/campaigns/".concat(t,"/start"),{scheduled_for:null==n?void 0:n.scheduledFor,stop_at:null==n?void 0:n.stopAt}));case 2:case"end":return e.stop()}},e,this)})),function(e,t){return e5.apply(this,arguments)})},{key:"queryCampaigns",value:(e6=(0,f.Z)(b().mark(function e(t,n,r){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.next=3,this.post(this.baseURL+"/campaigns/query",eA({filter:t,sort:n},r||{}));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e,t,n){return e6.apply(this,arguments)})},{key:"updateCampaign",value:(e8=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.put(this.baseURL+"/campaigns/".concat(t),n));case 2:case"end":return e.stop()}},e,this)})),function(e,t){return e8.apply(this,arguments)})},{key:"deleteCampaign",value:(e7=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.delete(this.baseURL+"/campaigns/".concat(t)));case 2:case"end":return e.stop()}},e,this)})),function(e){return e7.apply(this,arguments)})},{key:"stopCampaign",value:(e9=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.post(this.baseURL+"/campaigns/".concat(t,"/stop")));case 2:case"end":return e.stop()}},e,this)})),function(e){return e9.apply(this,arguments)})},{key:"enrichURL",value:(te=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.get(this.baseURL+"/og",{url:t}));case 1:case"end":return e.stop()}},e,this)})),function(e){return te.apply(this,arguments)})},{key:"getTask",value:(tt=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.get("".concat(this.baseURL,"/tasks/").concat(t)));case 1:case"end":return e.stop()}},e,this)})),function(e){return tt.apply(this,arguments)})},{key:"deleteChannels",value:(tn=(0,f.Z)(b().mark(function e(t){var n,r=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.length>1&&void 0!==r[1]?r[1]:{},e.next=3,this.post(this.baseURL+"/channels/delete",eA({cids:t},n));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return tn.apply(this,arguments)})},{key:"deleteUsers",value:(tr=(0,f.Z)(b().mark(function e(t){var n,r=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!(void 0!==(n=r.length>1&&void 0!==r[1]?r[1]:{}).user&&!["soft","hard","pruning"].includes(n.user))){e.next=3;break}throw Error("Invalid delete user options. user must be one of [soft hard pruning]");case 3:if(!(void 0!==n.conversations&&!["soft","hard"].includes(n.conversations))){e.next=5;break}throw Error("Invalid delete user options. conversations must be one of [soft hard]");case 5:if(!(void 0!==n.messages&&!["soft","hard","pruning"].includes(n.messages))){e.next=7;break}throw Error("Invalid delete user options. messages must be one of [soft hard pruning]");case 7:return e.next=9,this.post(this.baseURL+"/users/delete",eA({user_ids:t},n));case 9:return e.abrupt("return",e.sent);case 10:case"end":return e.stop()}},e,this)})),function(e){return tr.apply(this,arguments)})},{key:"_createImportURL",value:(ts=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/import_urls",{filename:t});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return ts.apply(this,arguments)})},{key:"_createImport",value:(ti=(0,f.Z)(b().mark(function e(t){var n,r=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.length>1&&void 0!==r[1]?r[1]:{mode:"upsert"},e.next=3,this.post(this.baseURL+"/imports",eA({path:t},n));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return ti.apply(this,arguments)})},{key:"_getImport",value:(ta=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/imports/".concat(t));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return ta.apply(this,arguments)})},{key:"_listImports",value:(to=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/imports",t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return to.apply(this,arguments)})},{key:"upsertPushProvider",value:(tc=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/push_providers",{push_provider:t});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return tc.apply(this,arguments)})},{key:"deletePushProvider",value:(tu=(0,f.Z)(b().mark(function e(t){var n,r;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.type,r=t.name,e.next=3,this.delete(this.baseURL+"/push_providers/".concat(n,"/").concat(r));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return tu.apply(this,arguments)})},{key:"listPushProviders",value:(tl=(0,f.Z)(b().mark(function e(){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/push_providers");case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(){return tl.apply(this,arguments)})},{key:"createAbortControllerForNextRequest",value:function(){return this.nextRequestAbortController=new AbortController}},{key:"commitMessage",value:(th=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/messages/".concat(t,"/commit"));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return th.apply(this,arguments)})},{key:"createPoll",value:(td=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/polls",t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return td.apply(this,arguments)})},{key:"getPoll",value:(tp=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/polls/".concat(t),eA({},n?{user_id:n}:{}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return tp.apply(this,arguments)})},{key:"updatePoll",value:(tf=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.put(this.baseURL+"/polls",t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return tf.apply(this,arguments)})},{key:"partialUpdatePoll",value:(tv=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.patch(this.baseURL+"/polls/".concat(t),n);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return tv.apply(this,arguments)})},{key:"deletePoll",value:(tg=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.delete(this.baseURL+"/polls/".concat(t),eA({},n?{user_id:n}:{}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return tg.apply(this,arguments)})},{key:"closePoll",value:(tm=(0,f.Z)(b().mark(function e(t){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.partialUpdatePoll(t,{set:{is_closed:!0}}));case 1:case"end":return e.stop()}},e,this)})),function(e){return tm.apply(this,arguments)})},{key:"createPollOption",value:(ty=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/polls/".concat(t,"/options"),n);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return ty.apply(this,arguments)})},{key:"getPollOption",value:(tb=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/polls/".concat(t,"/options/").concat(n));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return tb.apply(this,arguments)})},{key:"updatePollOption",value:(tw=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.put(this.baseURL+"/polls/".concat(t,"/options"),n);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return tw.apply(this,arguments)})},{key:"deletePollOption",value:(tk=(0,f.Z)(b().mark(function e(t,n){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.delete(this.baseURL+"/polls/".concat(t,"/options/").concat(n));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return tk.apply(this,arguments)})},{key:"castPollVote",value:(t_=(0,f.Z)(b().mark(function e(t,n,r){var s,i=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return s=i.length>3&&void 0!==i[3]?i[3]:{},e.next=3,this.post(this.baseURL+"/messages/".concat(t,"/polls/").concat(n,"/vote"),eA({vote:r},s));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e,t,n){return t_.apply(this,arguments)})},{key:"addPollAnswer",value:(tx=(0,f.Z)(b().mark(function e(t,n,r){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.castPollVote(t,n,{answer_text:r}));case 1:case"end":return e.stop()}},e,this)})),function(e,t,n){return tx.apply(this,arguments)})},{key:"removePollVote",value:(tZ=(0,f.Z)(b().mark(function e(t,n,r){return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.delete(this.baseURL+"/messages/".concat(t,"/polls/").concat(n,"/vote/").concat(r));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t,n){return tZ.apply(this,arguments)})},{key:"queryPolls",value:(tC=(0,f.Z)(b().mark(function e(){var t,n,r,s=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=s.length>0&&void 0!==s[0]?s[0]:{},n=s.length>1&&void 0!==s[1]?s[1]:[],r=s.length>2&&void 0!==s[2]?s[2]:{},e.next=5,this.post(this.baseURL+"/polls/query",eA({filter:t,sort:N(n)},r));case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}},e,this)})),function(){return tC.apply(this,arguments)})},{key:"queryPollVotes",value:(tS=(0,f.Z)(b().mark(function e(t){var n,r,s,i=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=i.length>1&&void 0!==i[1]?i[1]:{},r=i.length>2&&void 0!==i[2]?i[2]:[],s=i.length>3&&void 0!==i[3]?i[3]:{},e.next=5,this.post(this.baseURL+"/polls/".concat(t,"/votes"),eA({filter:n,sort:N(r)},s));case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}},e,this)})),function(e){return tS.apply(this,arguments)})},{key:"queryMessageHistory",value:(tU=(0,f.Z)(b().mark(function e(){var t,n,r,s=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=s.length>0&&void 0!==s[0]?s[0]:{},n=s.length>1&&void 0!==s[1]?s[1]:[],r=s.length>2&&void 0!==s[2]?s[2]:{},e.next=5,this.post(this.baseURL+"/messages/history",eA({filter:t,sort:N(n)},r));case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}},e,this)})),function(){return tU.apply(this,arguments)})},{key:"updateFlags",value:(tR=(0,f.Z)(b().mark(function e(t,n){var r,s=arguments;return b().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=s.length>2&&void 0!==s[2]?s[2]:{},e.next=3,this.post(this.baseURL+"/automod/v1/moderation/update_flags",eA({message_ids:t,reviewed_by:n},r));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e,t){return tR.apply(this,arguments)})}],[{key:"getInstance",value:function(e,t,n){return tO._instance||("string"==typeof t?tO._instance=new tO(e,t,n):tO._instance=new tO(e,t)),tO._instance}}]),tO}();(0,m.Z)(eF,"_instance",void 0);var eq="Allow",eW=["*"],eN=["*"],eB=function e(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:eW,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:eN,i=arguments.length>4&&void 0!==arguments[4]&&arguments[4],a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:eq;(0,v.Z)(this,e),(0,m.Z)(this,"name",void 0),(0,m.Z)(this,"action",void 0),(0,m.Z)(this,"owner",void 0),(0,m.Z)(this,"priority",void 0),(0,m.Z)(this,"resources",void 0),(0,m.Z)(this,"roles",void 0),this.name=t,this.action=a,this.owner=i,this.priority=n,this.resources=r,this.roles=s};new eB("Allow all",999,eW,eN,!1,eq),new eB("Deny all",1,eW,eN,!1,"Deny")}}]);