PageSourceSearch

https://happykids.id/_next/static/chunks/3baf5dbb-d6e70104d5dac784.js

js happykids.id collected 2026-10-02 01:57:09 UTC 231,484 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8171],{41662:function(e,t,n){n.d(t,{c8:function(){return tI},t1:function(){return N}});var r,s,i,a,o,c,u,l=n(59196),d=n(54580),h=n(76405),p=n(25049),f=n(11993),v=n(35750),g=n.n(v),m=n(1119),y=n(41154),b=n(10902),w=n(26365),_=n(83145),k=n(18697),x=n(4679),Z=n.n(x),C=n(63819),S=n.n(C),U=n(63496),R=n(41690),O=n(37977),I=n(24995),P=n(51358),L=n(96434).Buffer,M=n(40257);function D(e){return"string"==typeof e}var E=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<a;n++)for(o=(o<<6)+s[e.charAt(n)],c+=6;c>=8;)((r=o>>>(c-=8)&255)||n<a-2)&&(u+=i(r));return u},A=function(){var e,t,n,r,s,i;function a(e,t,n){(0,h.Z)(this,a),(0,f.Z)(this,"id",void 0),(0,f.Z)(this,"data",void 0),(0,f.Z)(this,"client",void 0),this.client=e,this.id=t,this.data=n}return(0,p.Z)(a,[{key:"create",value:(e=(0,d.Z)(g().mark(function e(){var t,n,r,s,i,a,o,c,u,l,d,h,p,f;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return p={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,sender_mode:null===(s=this.data)||void 0===s?void 0:s.sender_mode,channel_template:null===(i=this.data)||void 0===i?void 0:i.channel_template,create_channels:null===(a=this.data)||void 0===a?void 0:a.create_channels,show_channels:null===(o=this.data)||void 0===o?void 0:o.show_channels,description:null===(c=this.data)||void 0===c?void 0:c.description,name:null===(u=this.data)||void 0===u?void 0:u.name,skip_push:null===(l=this.data)||void 0===l?void 0:l.skip_push,skip_webhook:null===(d=this.data)||void 0===d?void 0:d.skip_webhook,user_ids:null===(h=this.data)||void 0===h?void 0:h.user_ids},e.next=3,this.client.createCampaign(p);case 3:return f=e.sent,this.id=f.campaign.id,this.data=f.campaign,e.abrupt("return",f);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,d.Z)(g().mark(function e(t){return g().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,d.Z)(g().mark(function e(t){return g().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,d.Z)(g().mark(function e(){return g().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,d.Z)(g().mark(function e(){return g().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,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.verifyCampaignId(),e.abrupt("return",this.client.getCampaign(this.id,t));case 2:case"end":return e.stop()}},e,this)})),function(e){return i.apply(this,arguments)})}]),a}();function T(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 j(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};
1t%2?T(Object(n),!0).forEach(function(t){(0,f.Z)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):T(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function F(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 q(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 q(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){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}}}}function q(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function N(e,t){e.then().catch(function(e){console.warn("failed to do ".concat(t,", ran into error: "),e)})}var H=function(e){return new Promise(function(t){return setTimeout(t,e)})};function V(e){return e&&("[object Function]"===Object.prototype.toString.call(e)||"function"==typeof e||e instanceof Function)}var W={TOKEN_EXPIRED:40,WS_CLOSED_SUCCESS:1e3};function B(e){var t,n=[],r=F(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;a<i.length;a++){var o=(0,w.Z)(i[a],2),c=o[0],u=o[1];n.push({field:c,direction:u})}}}catch(e){r.e(e)}finally{r.f()}return n}function z(e){var t=Math.min(Math.max(250,(e-1)*2e3),25e3);return Math.floor(Math.random()*(Math.min(500+2e3*e,25e3)-t)+t)}function J(e){for(var t="",n=0;n<e.length;n++)t+=e[n].toString(16).padStart(2,"0");return t}function K(){var e,t=(G(e=new Uint8Array(16)),e);return t[6]=15&t[6]|64,t[8]=191&t[8]|128,J(t.subarray(0,4))+"-"+J(t.subarray(4,6))+"-"+J(t.subarray(6,8))+"-"+J(t.subarray(8,10))+"-"+J(t.subarray(10,16))}var G="undefined"!=typeof crypto&&void 0!==(null===(r=crypto)||void 0===r?void 0:r.getRandomValues)?crypto.getRandomValues.bind(crypto):"undefined"!=typeof msCrypto?msCrypto.getRandomValues.bind(msCrypto):function(e){for(var t=Math.pow(2,8*e.byteLength/e.length),n=0;n<e.length;n++)e[n]=Math.random()*t};function Q(e){"undefined"!=typeof window&&window.addEventListener&&(window.addEventListener("offline",e),window.addEventListener("online",e))}function $(e){"undefined"!=typeof window&&window.removeEventListener&&(window.removeEventListener("offline",e),window.removeEventListener("online",e))}var X=function(e){var t=[];for(var n in e)void 0!==e[n]&&(Array.isArray(e[n])||"object"===(0,y.Z)(e[n])?t.push("".concat(n,"=").concat(encodeURIComponent(JSON.stringify(e[n])))):t.push("".concat(n,"=").concat(encodeURIComponent(e[n]))));return t.join("&")};function Y(e){return j(j({},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,deleted_at:e.deleted_at?new Date(e.deleted_at):null,status:e.status||"received",reaction_groups:function(e,t,n){if(e)return e;if(t&&n){for(var r={},s=0,i=Object.keys(t);s<i.length;s++){var a=i[s];r[a]={count:t[a],sum_scores:n[a]}}return r}return null}(e.reaction_groups,e.reaction_counts,e.reaction_scores)})}var ee=function(e){var t=e.needle,n=e.sortedArray,r=e.selectKey,s=e.selectValueToCompare,i=void 0===s?function(e){return e}:s,a=e.sortDirection,o=void 0===a?"ascending":a;if(!n.length)return 0;for(var c=0,u=n.length-1,l=0,d=i(t);c<=u;){var h=i(n[l=Math.round((c+u)/2)]);"ascending"===o&&d<h||"descending"===o&&d>=h?u=l-1:c=l+1}if(r){for(var p=r(t),f="ascending"===o?-1:1,v=c+f;0<=v&&v<n.length&&i(n[v])===d;v+=f)if(r(n[v])===p)return v}return c};function et(e,t){var n=arguments.length>2&&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=(0,_.Z)(e);if(n&&(a=a.filter(function(e){return!(e.id&&t.id===e.id)}
1)),0===a.length&&i)return a.concat(t);if(0===a.length)return a;var o=t[r].getTime(),c=a.at(-1)[r].getTime()<o;if(c&&i)return a.concat(t);if(c)return a;var u=ee({needle:t,sortedArray:a,sortDirection:"ascending",selectValueToCompare:function(e){return e[r].getTime()},selectKey:function(e){return e.id}});return!n&&t.id&&a[u]&&t.id===a[u].id?a[u]=t:i&&a.splice(u,0,t),a}var en=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:200,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.leading,s=void 0===r||r,i=n.trailing,a=void 0!==i&&i,o=null,c=null;return function(){for(var n=arguments.length,r=Array(n),i=0;i<n;i++)r[i]=arguments[i];if(o){a&&(c=r);return}s&&e.apply(void 0,r),o=setTimeout(function n(){if(c){e.apply(void 0,(0,_.Z)(c)),c=null,o=setTimeout(n,t);return}o=null},t)}},er=function(e,t){if(!Array.isArray(e))return[];var n=new Set;return e.filter(function(e){var r="function"==typeof t?t(e):t.split(".").reduce(function(e,t){if(e&&"object"===(0,y.Z)(e)&&t in e)return e[t]},e);return!n.has(r)&&(n.add(r),!0)})},es=function(e){var t=e.parentSet,n=e.requestedPageSize,r=e.returnedPage,s=e.messagePaginationOptions,i=j({},t.pagination);if(!(null!=s&&s.created_at_around))return i;var a=new Date(s.created_at_around),o=[r[0],r.slice(-1)[0]],c=o[0],u=o[1],l=!!(null!=c&&c.created_at)&&new Date(c.created_at)>a,d=!!(null!=u&&u.created_at)&&new Date(u.created_at)<a,h=n>t.messages.length&&n>r.length,p=(n>t.messages.length||t.messages.length>=r.length)&&n>r.length;if(l)f=!1,g=!0,h&&(v=!1,m=!0);else if(d)v=!1,m=!0,h&&(f=!1,g=!0);else if(p)v=f=!1,g=m=!0;else{var f,v,g,m,y,b,w=(null==c?void 0:c.id)&&c.id===(null===(y=t.messages[0])||void 0===y?void 0:y.id),_=(null==u?void 0:u.id)&&u.id===(null===(b=t.messages.slice(-1)[0])||void 0===b?void 0:b.id);g=w,m=_;var k=Math.floor(r.length/2),x=function(e,t){for(var n=0,r=e.length-1;n<=r;){var s=Math.floor((n+r)/2),i=e[s].created_at;if(!i){n+=1;continue}var a=new Date(i);if(a.getTime()===t.getTime())return s;a.getTime()<t.getTime()?n=s+1:r=s-1}return n}(r,a);-1!==x&&(f=k<=x,v=k>=x)}return g&&void 0!==f&&(i.hasPrev=f),m&&void 0!==v&&(i.hasNext=v),i},ei=function(e){var t=e.parentSet,n=e.requestedPageSize,r=e.returnedPage,s=e.messagePaginationOptions,i=j({},t.pagination),a=(s||{}).id_around;if(!a)return i;var o=[r[0],r.slice(-1)[0]],c=o[0],u=o[1],l=(null==c?void 0:c.id)===(null===(v=t.messages[0])||void 0===v?void 0:v.id),d=(null==u?void 0:u.id)===(null===(g=t.messages.slice(-1)[0])||void 0===g?void 0:g.id),h=l,p=d,f=Math.floor(r.length/2);if((n>t.messages.length||t.messages.length>=r.length)&&n>r.length)y=m=!1,h=p=!0;else if(!r[f])return i;else if(r[f].id===a)m=y=!0;else{var v,g,m,y,b,w=[r.slice(0,f),r.slice(f)];m=y=!0;for(var _=0;_<w.length;_++)(b=w[_].find(function(e){return e.id===a}))&&0===_&&(m=!1),b&&1===_&&(y=!1)}return h&&void 0!==m&&(i.hasPrev=m),p&&void 0!==y&&(i.hasNext=y),i},ea=function(e){var t,n,r,s,i=e.parentSet,a=e.requestedPageSize,o=e.returnedPage,c=e.messagePaginationOptions,u=j({},i.pagination),l=[o[0],o.slice(-1)[0]],d=l[0],h=l[1],p=(null==d?void 0:d.id)&&d.id===(null===(t=i.messages[0])||void 0===t?void 0:t.id),f=(null==h?void 0:h.id)&&h.id===(null===(n=i.messages.slice(-1)[0])||void 0===n?void 0:n.id),v=c&&(c.created_at_after_or_equal||c.created_at_after||c.id_gt||c.id_gte),g=void 0===c||c.created_at_before_or_equal||c.created_at_before||c.id_lt||c.id_lte||c.offset,m=!v&&!g&&!(null!=c&&c.id_around)&&!(null!=c&&c.created_at_around),y=o.length>=a;(void 0!==g||m)&&(r=y),void 0!==v&&(s=y);var b=0===o.length;return(p||b)&&void 0!==r&&(u.hasPrev=r),(f||b)&&void 0!==s&&(u.hasNext=s),u},eo=function(e){var t,n,r;return e.parentSet.messages.length<e.returnedPage.length?(null===(r=e.logger)||void 0===r||r.call(e,"error","Corrupted message set state: parent set size < returned page size"),e.parentSet.pagination):null!==(t=e.messagePaginationOptions)&&void 0!==t&&t.created_at_around?es(e):null!==(n=e.messagePaginationOptions)&&void 0!==n&&n.id_around?ei(e):ea(e)},ec={},eu=(s=(0,d.Z)(g().mark(function e(t){var n,r,s,i,a,o,c,u,l;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.channel,r=t.client,s=t.id,i=t.members,a=t.options,o=t.type,!(!n&&!o)){e.next=3;break}throw Error("Channel or channel type have to be provided to query a channel.");case 3:if(u=(c=n||r.channel(o,s,{members:i})).id?c.cid:i&&i.length?el(c.type,i):void 0){e.next=7;break}throw Error("Channel ID or channel members array have to be provided to query a channel.");case 7:if(!(l=ec[u])){e.next=13;break}return e.next=11,l;case 11:e.next=20;break;case 13:return e.prev=13,ec[u]=c.watch(a),e.next=17,ec[u];case 17:return e.prev=17,delete ec[u],e.finish(17);case 20:return e.abrupt("return",c);case 21:case"end":return e.stop()}},e,null,[[13,,17,20]])})),function(e){return s.apply(this,arguments)}),el=function(e,t){if(t){var n=(0,_.Z)(t).sort().join(",");if(n)return"".concat(e,":!members-").concat(n)}},ed=function(e){if(!e)return!1;var t=e.state.membership;return!!(null!=t&&t.pinned_at)},eh=function(e){if(!e)return!1;var t=e.state.membership;return!!(null!=t&&t.archived_at)},ep=function(e){return!!e&&"boolean"==typeof e.archived},ef=function(e){var t,n,r,s=e.atIndex,i=e.sort,a=e.targetKey;if(!i)return null;var o=null;if(Array.isArray(i))o=null!==(r=i[s])&&void 0!==r?r:null;else{var c=0;for(var u in i){if(c!==s){c++;continue}if(u!==a)return null;o=i;break}}return null!==(t=null===(n=o)||void 0===n?void 0:n[a])&&void 0!==t?t:null},ev=function(e){var t=eg({sort:e});return"number"==typeof t&&1===Math.abs(t)},eg=function(e){return ef({atIndex:0,sort:e.sort,targetKey:"pinned_at"})},em=function(e){var t,n=e.channels,r=null,s=F(n);try{for(s.s();!(t=s.n()).done;){var i=t.value;if(!ed(i))break;"number"==typeof r?r++:r=0}}catch(e){s.e(e)}finally{s.f()}return r},ey=function(e){var t=e.channels,n=e.channelToMove,r=e.channelToMoveIndexWithinChannels,s=e.sort,i=null!=r?r:t.findIndex(function(e){return e.cid===n.cid}),a=i>=0,o=0===i,c=ev(s),u=ed(n);if(o||c&&u)return t;var l=(0,_.Z)(t);a&&l.splice(i,1);var d=null;return c&&(d=em({channels:l})),l.splice("number"==typeof d?d+1:0,0,n),l},eb={hasNext:!1,hasPrev:!1};function ew(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;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};
1t%2?ew(Object(n),!0).forEach(function(t){(0,f.Z)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ew(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var ek=function(){var e;function t(e){var n,r=this;(0,h.Z)(this,t),(0,f.Z)(this,"_channel",void 0),(0,f.Z)(this,"watcher_count",void 0),(0,f.Z)(this,"typing",void 0),(0,f.Z)(this,"read",void 0),(0,f.Z)(this,"pinnedMessages",void 0),(0,f.Z)(this,"pending_messages",void 0),(0,f.Z)(this,"threads",void 0),(0,f.Z)(this,"mutedUsers",void 0),(0,f.Z)(this,"watchers",void 0),(0,f.Z)(this,"members",void 0),(0,f.Z)(this,"unreadCount",void 0),(0,f.Z)(this,"membership",void 0),(0,f.Z)(this,"last_message_at",void 0),(0,f.Z)(this,"isUpToDate",void 0),(0,f.Z)(this,"messageSets",[]),(0,f.Z)(this,"formatMessage",function(e){return Y(e)}),(0,f.Z)(this,"setIsUpToDate",function(e){r.isUpToDate=e}),(0,f.Z)(this,"removeMessageFromArray",function(e,t){var n=e.filter(function(e){return!(e.id&&t.id&&e.id===t.id)});return{removed:n.length<e.length,result:n}}),(0,f.Z)(this,"updateUserMessages",function(e){var t=function(e,t){for(var n=0;n<e.length;n++){var r,s=e[n];(null===(r=s.user)||void 0===r?void 0:r.id)===t.id&&(e[n]=e_(e_({},s),{},{user:t}))}};for(var n in r.messageSets.forEach(function(n){return t(n.messages,e)}),r.threads)t(r.threads[n],e);t(r.pinnedMessages,e)}),(0,f.Z)(this,"deleteUserMessages",function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=0;r<e.length;r++){var s,i=e[r];(null===(s=i.user)||void 0===s?void 0:s.id)===t.id&&(n?e[r]={cid:i.cid,created_at:i.created_at,deleted_at:t.deleted_at,id:i.id,latest_reactions:[],mentioned_users:[],own_reactions:[],parent_id:i.parent_id,reply_count:i.reply_count,status:i.status,thread_participants:i.thread_participants,type:"deleted",updated_at:i.updated_at,user:i.user}:e[r]=e_(e_({},i),{},{type:"deleted",deleted_at:t.deleted_at?new Date(t.deleted_at):null}))}};for(var s in r.messageSets.forEach(function(r){return n(r.messages,e,t)}),r.threads)n(r.threads[s],e,t);n(r.pinnedMessages,e,t)}),this._channel=e,this.watcher_count=0,this.typing={},this.read={},this.initMessages(),this.pinnedMessages=[],this.pending_messages=[],this.threads={},this.mutedUsers=[],this.watchers={},this.members={},this.membership={},this.unreadCount=0,this.isUpToDate=!0,this.last_message_at=(null==e?void 0:null===(n=e.state)||void 0===n?void 0:n.last_message_at)!=null?new Date(e.state.last_message_at):null}return(0,p.Z)(t,[{key:"messages",get:function(){var e;return(null===(e=this.messageSets.find(function(e){return e.isCurrent}))||void 0===e?void 0:e.messages)||[]},set:function(e){var t=this.messageSets.findIndex(function(e){return e.isCurrent});this.messageSets[t].messages=e}},{key:"latestMessages",get:function(){var e;return(null===(e=this.messageSets.find(function(e){return e.isLatest}))||void 0===e?void 0:e.messages)||[]},set:function(e){var t=this.messageSets.findIndex(function(e){return e.isLatest});this.messageSets[t].messages=e}},{key:"messagePagination",get:function(){var e;return(null===(e=this.messageSets.find(function(e){return e.isCurrent}))||void 0===e?void 0:e.pagination)||eb}},{key:"addMessageSorted",value:function(e){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]:"latest";return this.addMessagesSorted([e],t,!1,n,r)}},{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;c<a.length;c+=1)if(!a[c].shadowed){var u,l=a[c].created_at instanceof Date,d=void 0;l?d=a[c]:((d=this.formatMessage(a[c])).user&&null!==(u=this._channel)&&void 0!==u&&u.cid&&this._channel.getClient().state.updateUserReference(d.user,this._channel.cid),n&&d.id&&this.threads[d.id]&&delete this.threads[d.id],this.last_message_at||(this.last_message_at=new Date(d.created_at.getTime())),d.created_at.getTime()>this.last_message_at.getTime()&&(this.last_message_at=new Date(d.created_at.getTime())));var h=d.parent_id;if((!h||d.show_in_channel)&&-1!==o&&(this.messageSets[o].messages=this._addToMessageList(this.messageSets[o].messages,d,t,"created_at",r)),h&&!n){var p=this.threads[h]||[];this.threads[h]=this._addToMessageList(p,d,t,"created_at",r)}}return{messageSet:this.messageSets[o]}}},{key:"addPinnedMessages",value:function(e){for(var t=0;t<e.length;t+=1)this.addPinnedMessage(e[t])}},{key:"addPinnedMessage",value:function(e){this.pinnedMessages=this._addToMessageList(this.pinnedMessages,this.formatMessage(e),!1,"pinned_at")}},{key:"removePinnedMessage",value:function(e){var t=this.removeMessageFromArray(this.pinnedMessages,e).result;this.pinnedMessages=t}},{key:"addReaction",value:function(e,t,n){var r=this;if(t)return this._updateMessage(t,function(s){return t.own_reactions=r._addOwnReactionToMessage(s.own_reactions,e,n),r.formatMessage(t)}),t}},{key:"_addOwnReactionToMessage",value:function(e,t,n){return e=(e=n?[]:this._removeOwnReactionFromMessage(e,t))||[],this._channel.getClient().userID===t.user_id&&e.push(t),e}},{key:"_removeOwnReactionFromMessage",value:function(e,t){return e?e.filter(function(e){return e.user_id!==t.user_id||e.type!==t.type}):e}},{key:"removeReaction",value:function(e,t){var n=this;if(t)return this._updateMessage(t,function(r){return t.own_reactions=n._removeOwnReactionFromMessage(r.own_reactions,e),n.formatMessage(t)}),t}},{key:"_updateQuotedMessageReferences",value:function(e){var t=this,n=e.message,r=e.remove,s=function(e){var t,n;return e_(e_({},e),{},{created_at:e.created_at.toISOString(),pinned_at:null===(t=e.pinned_at)||void 0===t?void 0:t.toISOString(),updated_at:null===(n=e.updated_at)||void 0===n?void 0:n.toISOString()})},i=function(e){var i=e.reduce(function(e,t){return t.quoted_message_id===n.id&&e.push(e_(e_({},s(t)),{},{quoted_message:r?e_(e_({},n),{},{attachments:[]}):n})),e},[]);t.addMessagesSorted(i,!0)};n.parent_id?n.parent_id&&this.threads[n.parent_id]&&i(this.threads[n.parent_id]):this.messageSets.forEac
1h(function(e){return i(e.messages)})}},{key:"removeQuotedMessageReferences",value:function(e){this._updateQuotedMessageReferences({message:e,remove:!0})}},{key:"_updateMessage",value:function(e,t){var n=e.parent_id,r=e.show_in_channel,s=e.pinned;if(n&&this.threads[n]){var i=this.threads[n],a=i.findIndex(function(t){return t.id===e.id});-1!==a&&(i[a]=t(i[a]),this.threads[n]=i)}if(!r&&!n||r){var o=this.findMessageSetIndex(e);if(-1!==o){var c=this.messageSets[o].messages.findIndex(function(t){return t.id===e.id});-1!==c&&(this.messageSets[o].messages[c]=t(this.messageSets[o].messages[c]))}}if(s){var u=this.pinnedMessages.findIndex(function(t){return t.id===e.id});-1!==u&&(this.pinnedMessages[u]=t(this.pinnedMessages[u]))}}},{key:"_addToMessageList",value:function(e,t){var n=arguments.length>2&&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 et(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);t<n.length;t++){var r=(0,w.Z)(n[t],2),s=r[0],i=r[1],a="string"==typeof i.received_at?new Date(i.received_at):i.received_at||new Date;e.getTime()-a.getTime()>7e3&&(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,pagination:eb}]}},{key:"loadMessageIntoState",value:(e=(0,d.Z)(g().mark(function e(t,n){var r,s,i,a,o,c,u=arguments;return g().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,pagination:eb}),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,_.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,u.pagination.hasPrev=e.messages[0].created_at<u.messages[0].created_at?e.pagination.hasPrev:u.pagination.hasPrev,u.pagination.hasNext=u.messages.slice(-1)[0].created_at<e.messages.slice(-1)[0].created_at?e.pagination.hasNext:u.pagination.hasNext,i=[].concat((0,_.Z)(i),(0,_.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 ex(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];
1if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return eZ(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 eZ(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 eZ(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}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 eS(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?eC(Object(n),!0).forEach(function(t){(0,f.Z)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):eC(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var eU=function(){var e,t,n,r,s,i,a,o,c,u,l,v,m,b,w,k,x,Z,C,S,U,R,O,I,P,L,M,D,E,A,T,j,F,q,H,V,W,z,J,K,G,Q,$,X,Y,ee,et,en,er,es,ei,ea;function ec(e,t,n,r){var s,i=this;if((0,h.Z)(this,ec),(0,f.Z)(this,"_client",void 0),(0,f.Z)(this,"type",void 0),(0,f.Z)(this,"id",void 0),(0,f.Z)(this,"data",void 0),(0,f.Z)(this,"_data",void 0),(0,f.Z)(this,"cid",void 0),(0,f.Z)(this,"listeners",void 0),(0,f.Z)(this,"state",void 0),(0,f.Z)(this,"initialized",void 0),(0,f.Z)(this,"offlineMode",void 0),(0,f.Z)(this,"lastKeyStroke",void 0),(0,f.Z)(this,"lastTypingEvent",void 0),(0,f.Z)(this,"isTyping",void 0),(0,f.Z)(this,"disconnected",void 0),(0,f.Z)(this,"push_preferences",void 0),(0,f.Z)(this,"create",(s=(0,d.Z)(g().mark(function e(t){var n;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=eS(eS({},t),{},{watch:!1,state:!1,presence:!1}),e.next=3,i.query(n,"latest");case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e)})),function(e){return s.apply(this,arguments)})),(0,f.Z)(this,"_callChannelListeners",function(e){var t=[];i.listeners.all&&t.push.apply(t,(0,_.Z)(i.listeners.all)),i.listeners[e.type]&&t.push.apply(t,(0,_.Z)(i.listeners[e.type]));for(var n=0;n<t.length;n++){var r=t[n];"string"!=typeof r&&r(e)}}),(0,f.Z)(this,"_channelURL",function(){if(!i.id)throw Error("channel id is not defined");return"".concat(i.getClient().baseURL,"/channels/").concat(encodeURIComponent(i.type),"/").concat(encodeURIComponent(i.id))}),!/^[\w_-]+$/.test(t))throw Error("Invalid chat type ".concat(t,', letters, numbers and "_-" are allowed'));if("string"==typeof n&&!/^[\w!_-]+$/.test(n))throw Error("Invalid chat id ".concat(n,', letters, numbers and "!-_" are allowed'));this._client=e,this.type=t,this.id=n,this.data=r,this._data=eS({},r),this.cid="".concat(t,":").concat(n),this.listeners={},this.state=new ek(this),this.initialized=!1,this.offlineMode=!1,this.lastTypingEvent=null,this.isTyping=!1,this.disconnected=!1}return(0,p.Z)(ec,[{key:"getClient",value:function(){if(!0===this.disconnected)throw Error("You can't use a channel after client.disconnect() was called");return this._client}},{key:"getConfig",value:function(){return this.getClient().configs[this.cid]}},{key:"sendMessage",value:(e=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getClient().post(this._channelURL()+"/message",eS({message:t},n));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(t,n){return e.apply(this,arguments)})},{key:"sendFile",value:function(e,t,n,r){return this.getClient().sendFile("".concat(this._channelURL(),"/file"),e,t,n,r)}},{key:"sendImage",value:function(e,t,n,r){return this.getClient().sendFile("".concat(this._channelURL(),"/image"),e,t,n,r)}},{key:"deleteFile",value:function(e){return this.getClient().delete("".concat(this._channelURL(),"/file"),{url:e})}},{key:"deleteImage",value:function(e){return this.getClient().delete("".concat(this._channelURL(),"/image"),{url:e})}},{key:"sendEvent",value:(t=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this._checkInitialized(),e.next=3,this.getClient().post(this._channelURL()+"/event",{event: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:"search",value:(n=(0,d.Z)(g().mark(function e(t){var n,r,s=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!((n=s.length>1&&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?B(n.sort):void 0}),"string"!=typeof t){e.next=8;break}r.query=t,e.next=13;break;case 8:if("object"!==(0,y.Z)(t)){e.next=12;break}r.message_filter_conditions=t,e.next=13;break;case 12:throw Error("Invalid type ".concat((0,y.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,d.Z)(g().mark(function e(t){var n,r,s,i,a,o,c=arguments;return g().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:B(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:"updateMemberPartial",value:(s=(0,d.Z)(g().mark(function e(t,n){var r;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=new URL("".concat(this._channelURL(),"/member")),null!=n&&n.userId&&r.searchParams.append("user_id",n.userId),e.next=4,this.getClient().patch(r.toString(),t);case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}},e,this)})),function(e,t){return s.apply(this,arguments)})},{key:"partialUpdateMember",value:(i=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}throw Error("Please specify the user id");case 2:return e.next=4,this.getClient().patch(this._channelURL()+"/member/".concat(encodeURIComponent(t)),n);case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}},e,this)})),function(e,t){return i.apply(this,arguments)})},{key:"sendReaction",value:(a=(0,d.Z)(g().mark(function e(t,n,r){return g().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(encodeURIComponent(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 a.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(encodeURIComponent(e),"/reaction/").concat(encodeURIComponent(t));return n?this.getClient().delete(r,{user_id:n}):this.getClient().delete(r,{})}},{key:"update",value:(o=(0,d.Z)(g().mark(function e(){var t,n,r,s=arguments;return g().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 o.apply(this,arguments)})},{key:"updatePartial",value:(c=(0,d.Z)(g().mark(function e(t){var n,r,s,i;return g().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,_.Z)(s.channel.own_capabilities||[]).sort().join()!==(0,_.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 c.apply(this,arguments)})},{key:"enableSlowMode",value:(u=(0,d.Z)(g().mark(function e(t){var n;return g().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 u.apply(this,arguments)})},{key:"disableSlowMode",value:(l=(0,d.Z)(g().mark(function e(){var t;return g().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 l.apply(this,arguments)})},{key:"delete",value:(v=(0,d.Z)(g().mark(function e(){var t,n=arguments;return g().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 v.apply(this,arguments)})},{key:"truncate",value:(m=(0,d.Z)(g().mark(function e(){var t,n=arguments;return g().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 m.apply(this,arguments)})},{key:"acceptInvite",value:(b=(0,d.Z)(g().mark(function e(){var t,n=arguments;return g().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 b.apply(this,arguments)})},{key:"rejectInvite",value:(w=(0,d.Z)(g().mark(function e(){var t,n=arguments;return g().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 w.apply(this,arguments)})},{key:"addMembers",value:(k=(0,d.Z)(g().mark(function e(t,n){var r,s=arguments;return g().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 k.apply(this,arguments)})},{key:"addModerators",value:(x=(0,d.Z)(g().mark(function e(t,n){var r,s=arguments;return g().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 x.apply(this,arguments)})},{key:"assignRoles",value:(Z=(0,d.Z)(g().mark(function e(t,n){var r,s=arguments;return g().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 Z.apply(this,arguments)})},{key:"inviteMembers",value:(C=(0,d.Z)(g().mark(function e(t,n){var r,s=arguments;return g().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 C.apply(this,arguments)})},{key:"removeMembers",value:(S=(0,d.Z)(g().mark(function e(t,n){var r,s=arguments;return g().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 S.apply(this,arguments)})},{key:"demoteModerators",value:(U=(0,d.Z)(g().mark(function e(t,n){var r,s=arguments;return g().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 U.apply(this,arguments)})},{key:"_update",value:(R=(0,d.Z)(g().mark(function e(t){var n;return g().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 R.apply(this,arguments)})},{key:"mute",value:(O=(0,d.Z)(g().mark(function e(){var t,n=arguments;return g().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 O.apply(this,arguments)})},{key:"unmute",value:(I=(0,d.Z)(g().mark(function e(){var t,n=arguments;return g().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 I.apply(this,arguments)})},{key:"archive",value:(P=(0,d.Z)(g().mark(function e(){var t,n,r,s,i=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=i.length>0&&void 0!==i[0]?i[0]:{}
1,n=this.getClient(),r=t.user_id||n.userID){e.next=5;break}throw Error("A user_id is required for archiving a channel");case 5:return e.next=7,this.partialUpdateMember(r,{set:{archived:!0}});case 7:return s=e.sent,e.abrupt("return",s.channel_member);case 9:case"end":return e.stop()}},e,this)})),function(){return P.apply(this,arguments)})},{key:"unarchive",value:(L=(0,d.Z)(g().mark(function e(){var t,n,r,s,i=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=i.length>0&&void 0!==i[0]?i[0]:{},n=this.getClient(),r=t.user_id||n.userID){e.next=5;break}throw Error("A user_id is required for unarchiving a channel");case 5:return e.next=7,this.partialUpdateMember(r,{set:{archived:!1}});case 7:return s=e.sent,e.abrupt("return",s.channel_member);case 9:case"end":return e.stop()}},e,this)})),function(){return L.apply(this,arguments)})},{key:"pin",value:(M=(0,d.Z)(g().mark(function e(){var t,n,r,s,i=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=i.length>0&&void 0!==i[0]?i[0]:{},n=this.getClient(),r=t.user_id||n.userID){e.next=5;break}throw Error("A user_id is required for pinning a channel");case 5:return e.next=7,this.partialUpdateMember(r,{set:{pinned:!0}});case 7:return s=e.sent,e.abrupt("return",s.channel_member);case 9:case"end":return e.stop()}},e,this)})),function(){return M.apply(this,arguments)})},{key:"unpin",value:(D=(0,d.Z)(g().mark(function e(){var t,n,r,s,i=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=i.length>0&&void 0!==i[0]?i[0]:{},n=this.getClient(),r=t.user_id||n.userID){e.next=5;break}throw Error("A user_id is required for unpinning a channel");case 5:return e.next=7,this.partialUpdateMember(r,{set:{pinned:!1}});case 7:return s=e.sent,e.abrupt("return",s.channel_member);case 9:case"end":return e.stop()}},e,this)})),function(){return D.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(encodeURIComponent(e),"/action"),{message_id:e,form_data:t,id:this.id,type:this.t
1ype})}},{key:"keystroke",value:(E=(0,d.Z)(g().mark(function e(t,n){var r,s;return g().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 E.apply(this,arguments)})},{key:"updateAIState",value:(A=(0,d.Z)(g().mark(function e(t,n){var r,s=arguments;return g().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.sendEvent(eS(eS({},r),{},{type:"ai_indicator.update",message_id:t,ai_state:n}));case 3:case"end":return e.stop()}},e,this)})),function(e,t){return A.apply(this,arguments)})},{key:"clearAIIndicator",value:(T=(0,d.Z)(g().mark(function e(){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sendEvent({type:"ai_indicator.clear"});case 2:case"end":return e.stop()}},e,this)})),function(){return T.apply(this,arguments)})},{key:"stopAIResponse",value:(j=(0,d.Z)(g().mark(function e(){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sendEvent({type:"ai_indicator.stop"});case 2:case"end":return e.stop()}},e,this)})),function(){return j.apply(this,arguments)})},{key:"stopTyping",value:(F=(0,d.Z)(g().mark(function e(t,n){return g().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 F.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:(q=(0,d.Z)(g().mark(function e(){var t,n,r=arguments;return g().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 q.apply(this,arguments)})},{key:"markUnread",value:(H=(0,d.Z)(g().mark(function e(t){var n;return g().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 H.apply(this,arguments)})},{key:"clean",value:function(){this.lastKeyStroke&&new Date().getTime()-this.lastKeyStroke.getTime()>1e3&&this.isTyping&&N(this.stopTyping(),"stop typing event"),this.state.clean()}},{key:"watch",value:(V=(0,d.Z)(g().mark(function e(t){var n,r,s;return g().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"],
1channel:this}),e.abrupt("return",s);case 12:case"end":return e.stop()}},e,this)})),function(e){return V.apply(this,arguments)})},{key:"stopWatching",value:(W=(0,d.Z)(g().mark(function e(){var t;return g().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 W.apply(this,arguments)})},{key:"getReplies",value:(z=(0,d.Z)(g().mark(function e(t,n,r){var s,i;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return s=r?B(r):void 0,e.next=3,this.getClient().get(this.getClient().baseURL+"/messages/".concat(encodeURIComponent(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 z.apply(this,arguments)})},{key:"getPinnedMessages",value:(J=(0,d.Z)(g().mark(function e(t){var n,r=arguments;return g().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._channelURL()+"/pinned_messages",{payload:eS(eS({},t),{},{sort:B(n)})});case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return J.apply(this,arguments)})},{key:"getReactions",value:function(e,t){return this.getClient().get(this.getClient().baseURL+"/messages/".concat(encodeURIComponent(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)||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;n<this.state.latestMessages.length;n+=1){var r=this.state.latestMessages[n];r.created_at>e&&this._countMessageAsUnread(r)&&t++}return t}},{key:"countUnreadMentions",value:function(){for(var e=this.lastRead(),t=this.getClient().userID,n=0,r=0;r<this.state.latestMessages.length;r+=1){var s,i=this.state.latestMessages[r];this._countMessageAsUnread(i)&&(!e||i.created_at>e)&&null!==(s=i.mentioned_users)&&void 0!==s&&s.some(function(e){return e.id===t})&&n++}return n}},{key:"query",value:(K=(0,d.Z)(g().mark(function e(t){var n,r,s,i,a,o,c,u,l,d,h=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return a=h.length>1&&void 0!==h[1]?h[1]:"current",e.next=3,this.getClient().wsPromise;case 3:return o="".concat(this.getClient().baseURL,"/channels/").concat(encodeURIComponent(this.type)),this.id&&(o+="/".concat(encodeURIComponent(this.id))),e.next=7,this.getClient().post(o+"/query",eS({data:this._data,state:!0},t));case 7:return c=e.sent,this.id||(this.id=c.channel.id,this.cid=c.channel.cid,(u=el(this.type,c.members.map(function(e){var t;return e.user_id||(null===(t=e.user)||void 0===t?void 0:t.id)||""})))&&u in this.getClient().activeChannels&&delete this.getClient().activeChannels[u],!(this.cid in this.getClient().activeChannels)&&this.getClient()._cacheEnabled()&&(this.getClient().activeChannels[this.cid]=this)),this.getClient()._addChannelConfig(c.channel),(l=this._initializeState(c,a).messageSet).pagination=eS(eS({},l.pagination),eo({parentSet:l,messagePaginationOptions:null==t?void 0:t.messages,requestedPageSize:null!==(n=null==t?void 0:null===(r=t.messages)||void 0===r?void 0:r.limit)&&void 0!==n?n:100,returnedPage:c.messages,logger:this.getClient().logger})),this.getClient().polls.hydratePollCache(c.messages,!0),d=(0,_.Z)(c.channel.own_capabilities||[]).sort().join()!==(0,_.Z)(Array.isArray(null===(s=this.data)||void 0===s?void 0:s.own_capabilities)?null===(i=this.data)||void 0===i?void 0:i.own_capabilities:[]).sort().join(),this.data=c.channel,this.offlineMode=!1,d&&this.getClient().dispatchEvent({type:"capabilities.changed",cid:this.cid,own_capabilities:c.channel.own_capabilities}),this.getClient().dispatchEvent({type:"channels.queried",queriedChannels:{channels:[c],isLatestMessageSet:l.isLatest}}),e.abrupt("return",c);case 19:case"end":return e.stop()}},e,this)})),function(e){return K.apply(this,arguments)})},{key:"banUser",value:(G=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this._checkInitialized(),e.next=3,this.getClient().banUser(t,eS(eS({},n),{}
1,{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 G.apply(this,arguments)})},{key:"hide",value:(Q=(0,d.Z)(g().mark(function e(){var t,n,r=arguments;return g().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:($=(0,d.Z)(g().mark(function e(){var t,n=arguments;return g().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 $.apply(this,arguments)})},{key:"unbanUser",value:(X=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this._checkInitialized(),e.next=3,this.getClient().unbanUser(t,{type:this.t
1ype,id:this.id});case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return X.apply(this,arguments)})},{key:"shadowBan",value:(Y=(0,d.Z)(g().mark(function e(t,n){return g().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 Y.apply(this,arguments)})},{key:"removeShadowBan",value:(ee=(0,d.Z)(g().mark(function e(t){return g().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 ee.apply(this,arguments)})},{key:"createCall",value:(et=(0,d.Z)(g().mark(function e(t){return g().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 et.apply(this,arguments)})},{key:"vote",value:(en=(0,d.Z)(g().mark(function e(t,n,r){return g().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 en.apply(this,arguments)})},{key:"removeVote",value:(er=(0,d.Z)(g().mark(function e(t,n,r){return g().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 er.apply(this,arguments)})},{key:"createDraft",value:(es=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getClient().post(this._channelURL()+"/draft",{message:t});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return es.apply(this,arguments)})},{key:"deleteDraft",value:(ei=(0,d.Z)(g().mark(function e(){var t,n=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=(n.length>0&&void 0!==n[0]?n[0]:{}).parent_id,e.next=3,this.getClient().delete(this._channelURL()+"/draft",{parent_id:t});case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(){return ei.apply(this,arguments)})},{key:"getDraft",value:(ea=(0,d.Z)(g().mark(function e(){var t,n=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=(n.length>0&&void 0!==n[0]?n[0]:{}).parent_id,e.next=3,this.getClient().get(this._channelURL()+"/draft",{parent_id:t});case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(){return ea.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!==(l=e.user)&&void 0!==l&&l.id&&(u.typing[e.user.id]=e);break;case"typing.stop":null!==(d=e.user)&&void 0!==d&&d.id&&delete u.typing[e.user.id];break;case"message.read":null!==(h=e.user)&&void 0!==h&&h.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===(k=e.user)||void 0===k?void 0:k.id)===(null===(x=this.getClient().user)||void 0===x?void 0:x.id)&&(u.unreadCount=0));break;case"user.watching.start":case"user.updated":null!==(p=e.user)&&void 0!==p&&p.id&&(u.watchers[e.user.id]=e.user);break;case"user.watching.stop":null!==(v=e.user)&&void 0!==v&&v.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,d,h,p,v,g,m,y,b,w,_,k,x,Z,C,S,U=(null===(Z=e.user)||void 0===Z?void 0:Z.id)===(null===(C=this.getClient().user)||void 0===C?void 0:C.id),R=e.message.parent_id&&!e.message.show_in_channel;if((this.state.isUpToDate||R)&&u.addMessageSorted(e.message,U),e.message.pinned&&u.addPinnedMessage(e.message),U||R)break;if(null!==(S=e.user)&&void 0!==S&&S.id)for(var O in u.read)O===e.user.id?u.read[e.user.id]={last_read:new Date(e.created_at),user:e.user,unread_messages:0}:u.read[O].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!==(g=e.channel)&&void 0!==g&&g.truncated_at){var I=+new Date(e.channel.truncated_at);
1u.messageSets.forEach(function(e,t){e.messages.forEach(function(e){var n=e.created_at,r=e.id;I>+n&&u.removeMessage({id:r,messageSetIndex:t})})}),u.pinnedMessages.forEach(function(e){var t=e.id;I>+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":var P,L=eS({},e.member);null===L.pinned_at&&delete L.pinned_at,null===L.archived_at&&delete L.archived_at,null!=L&&L.user&&(u.members=eS(eS({},u.members),{},(0,f.Z)({},L.user.id,L)));var M=this.getClient().userID;"string"==typeof M&&"string"==typeof(null==L?void 0:null===(P=L.user)||void 0===P?void 0:P.id)&&L.user.id===M&&(u.membership=L);break;case"member.removed":if(null!==(m=e.user)&&void 0!==m&&m.id){var D=eS({},u.members);delete D[e.user.id],u.members=D}break;case"notification.mark_unread":if(!((null===(E=e.user)||void 0===E?void 0:E.id)===(null===(A=this.getClient().user)||void 0===A?void 0:A.id)&&e.user))break;var E,A,T,j=null!==(T=e.unread_messages)&&void 0!==T?T: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"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!==(y=e.user)&&void 0!==y&&y.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===(b=u.members[e.user.id])||void 0===b?void 0:b.user)||{}),e.user)});break;case"user.unbanned":if(!(null!==(w=e.user)&&void 0!==w&&w.id))break;u.members[e.user.id]=eS(eS({},u.members[e.user.id]||{}),{},{shadow_banned:!1,banned:!1,user:eS(eS({},(null===(_=u.members[e.user.id])||void 0===_?void 0:_.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){this._hydrateMembers({members:e.members});var a,o=ex(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 d,h=ex(e.watchers);try{for(h.s();!(d=h.n()).done;){var p=d.value;p&&(r.updateUserReference(p,this.cid),this.state.watchers[p.id]=p)}}catch(e){h.e(e)}finally{h.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=ex(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{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:"_hydrateMembers",value:function(e){var t=e.members,n=e.overrideCurrentState,r=void 0===n||n,s=t.reduce(function(e,t){return t.user&&(e[t.user.id]=t),e},{});r?this.state.members=s:!r&&t.length&&(this.state.members=eS(eS({},this.state.members),s))}},{key:"_disconnect",value:function(){this._client.logger("info","channel:disconnect() - Disconnecting the channel ".concat(this.cid),{tags:["connection","channel"],
1channel:this}),this.disconnected=!0,this.state.setIsUpToDate(!1)}}]),ec}();function eR(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var eO=function(){function e(t){var n=t.client;(0,h.Z)(this,e),(0,f.Z)(this,"client",void 0),(0,f.Z)(this,"users",void 0),(0,f.Z)(this,"userChannelReferences",void 0),this.client=n,this.users={},this.userChannelReferences={}}return(0,p.Z)(e,[{key:"updateUsers",value:function(e){var t,n=function(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 eR(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 eR(e,void 0)}}(e))){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}}}}(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.client._cacheEnabled()&&(this.users[e.id]=e)}},{key:"updateUserReference",value:function(e,t){null!=e&&this.client._cacheEnabled()&&(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 eI(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 eP(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?eI(Object(n),!0).forEach(function(t){(0,f.Z)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):eI(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var eL=function e(){(0,h.Z)(this,e),(0,f.Z)(this,"connectionStartTimestamp",void 0),(0,f.Z)(this,"wsConsecutiveFailures",void 0),(0,f.Z)(this,"wsTotalFailures",void 0),(0,f.Z)(this,"instanceClientId",void 0),this.connectionStartTimestamp=null,this.wsTotalFailures=0,this.wsConsecutiveFailures=0,this.instanceClientId=K()},eM=(i=(0,d.Z)(g().mark(function e(t,n){var r,s;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:r=3,s=0;case 2:if(!(s<r)){e.next=17;break}return e.prev=3,e.next=6,k.Z.post("https://chat-insights.getstream.io/insights/".concat(t),n);case 6:e.next=13;break;case 8:return e.prev=8,e.t0=e.catch(3),e.next=12,H((s+1)*3e3);case 12:return e.abrupt("continue",14);case 13:return e.abrupt("break",17);case 14:s++,e.next=2;break;case 17:case"end":return e.stop()}},e,null,[[3,8]])})),function(e,t){return i.apply(this,arguments)});function eD(e){var t,n,r,s=e.client;return{ready_state:null===(t=e.ws)||void 0===t?void 0:t.readyState,url:e._buildUrl(),api_key:s.key,start_ts:s.insightMetrics.connectionStartTimestamp,end_ts:new Date().getTime(),auth_type:s.getAuthType(),token:s.tokenManager.token,user_id:s.userID,user_details:s._user,device:s.options.device,client_id:e.connectionID,ws_details:e.ws,ws_consecutive_failures:s.insightMetrics.wsConsecutiveFailures,ws_total_failures:s.insightMetrics.wsTotalFailures,request_id:e.requestID,online:"undefined"!=typeof navigator?null===(n=navigator)||void 0===n?void 0:n.onLine:null,user_agent:"undefined"!=typeof navigator?null===(r=navigator)||void 0===r?void 0:r.userAgent:null,instance_client_id:s.insightMetrics.instanceClientId}}function eE(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}var eA=function(){var e,t,n,r;function s(e){var t=this,n=e.client;(0,h.Z)(this,s),(0,f.Z)(this,"client",void 0),(0,f.Z)(this,"connectionID",void 0),(0,f.Z)(this,"connectionOpen",void 0),(0,f.Z)(this,"consecutiveFailures",void 0),(0,f.Z)(this,"pingInterval",void 0),(0,f.Z)(this,"healthCheckTimeoutRef",void 0),(0,f.Z)(this,"isConnecting",void 0),(0,f.Z)(this,"isDisconnected",void 0),(0,f.Z)(this,"isHealthy",void 0),(0,f.Z)(this,"isResolved",void 0),(0,f.Z)(this,"lastEvent",void 0),(0,f.Z)(this,"connectionCheckTimeout",void 0),(0,f.Z)(this,"connectionCheckTimeoutRef",void 0),(0,f.Z)(this,"rejectPromise",void 0),(0,f.Z)(this,"requestID",void 0),(0,f.Z)(this,"resolvePromise",void 0),(0,f.Z)(this,"totalFailures",void 0),(0,f.Z)(this,"ws",void 0),(0,f.Z)(this,"wsID",void 0),(0,f.Z)(this,"_buildUrl",function(){var e=t.client._buildWSPayload(t.requestID),n=t.client.tokenManager.getToken(),r=new 
1URLSearchParams(t.client.options.wsUrlParams);return r.set("json",e),r.set("api_key",t.client.key),r.set("authorization","".concat(n)),r.set("stream-auth-type",t.client.getAuthType()),r.set("X-Stream-Client",t.client.getUserAgent()),"".concat(t.client.wsBaseURL,"/connect?").concat(r.toString())}),(0,f.Z)(this,"onlineStatusChanged",function(e){"offline"===e.type?(t._log("onlineStatusChanged() - Status changing to offline"),t._setHealth(!1)):"online"!==e.type||(t._log("onlineStatusChanged() - Status changing to online. isHealthy: ".concat(t.isHealthy)),t.isHealthy||t._reconnect({interval:10}))}),(0,f.Z)(this,"onopen",function(e){t.wsID===e&&t._log("onopen() - onopen callback",{wsID:e})}),(0,f.Z)(this,"onmessage",function(e,n){if(t.wsID===e){t._log("onmessage() - onmessage callback",{event:n,wsID:e});var r,s,i="string"==typeof n.data?JSON.parse(n.data):null;if(!t.isResolved&&i){if(t.isResolved=!0,i.error){null===(s=t.rejectPromise)||void 0===s||s.call(t,t._errorFromWSEvent(i,!1));return}null===(r=t.resolvePromise)||void 0===r||r.call(t,i),t._setHealth(!0)}t.lastEvent=new Date,i&&"health.check"===i.type&&t.scheduleNextPing(),t.client.handleEvent(n),t.scheduleConnectionCheck()}}),(0,f.Z)(this,"onclose",function(e,n){if(t.wsID===e){if(t._log("onclose() - onclose callback - "+n.code,{event:n,wsID:e}),n.code===W.WS_CLOSED_SUCCESS){var r,s,i=Error("WS connection reject with error ".concat(n.reason));i.reason=n.reason,i.code=n.code,i.wasClean=n.wasClean,i.target=n.target,null===(s=t.rejectPromise)||void 0===s||s.call(t,i),t._log("onclose() - WS connection reject with error ".concat(n.reason),{event:n})}else t.consecutiveFailures+=1,t.totalFailures+=1,t._setHealth(!1),t.isConnecting=!1,null===(r=t.rejectPromise)||void 0===r||r.call(t,t._errorFromWSEvent(n)),t._log("onclose() - WS connection closed. Calling reconnect ...",{event:n}),t._reconnect()}}),(0,f.Z)(this,"onerror",function(e,n){var r;t.wsID===e&&(t.consecutiveFailures+=1,t.totalFailures+=1,t._setHealth(!1),t.isConnecting=!1,null===(r=t.rejectPromise)||void 0===r||r.call(t,t._errorFromWSEvent(n)),t._log("onerror() - WS connection resulted into error",{event:n}),t._reconnect())}),(0,f.Z)(this,"_setHealth",function(e){if(e!==t.isHealthy){if(t.isHealthy=e,t.isHealthy){t.client.dispatchEvent({type:"connection.changed",online:t.isHealthy});return}setTimeout(function(){t.isHealthy||t.client.dispatchEvent({type:"connection.changed",online:t.isHealthy})},5e3)}}),(0,f.Z)(this,"_errorFromWSEvent",function(e){var n,r,s,i=!(arguments.length>1)||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,f.Z)(this,"_setupConnectionPromise",function(){t.isResolved=!1,t.connectionOpen=new Promise(function(e,n){t.resolvePromise=e,t.rejectPromise=n})}),(0,f.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,f.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,Q(this.onlineStatusChanged)}return(0,p.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;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};
1t%2?eE(Object(n),!0).forEach(function(t){(0,f.Z)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):eE(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}({tags:["connection"]},t))}},{key:"setClient",value:function(e){this.client=e}},{key:"connect",value:(e=(0,d.Z)(g().mark(function e(){var t,n,r=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=r.length>0&&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,d.Z)(g().mark(function e(){var t,n=this,r=arguments;return g().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,d.Z)(g().mark(function e(){var r,s;return g().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,H(r);case 15:s+=r,e.next=2;break;case 18:case"end":return e.stop()}},e,null,[[3,9]])}))(),(0,d.Z)(g().mark(function e(){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,H(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),$(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,d.Z)(g().mark(function e(){var t,n,r,s;return g().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=K(),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(S())(n),this.ws.onopen=this.onopen.bind(this,this.wsID),this.ws.onclose
1=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&&(eM("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=eP(eP({},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==eM||eM("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,d.Z)(g().mark(function e(){var t,n,r=arguments;return g().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=z(this.consecutiveFailures)),e.next=9,H(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 eT(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 ej(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;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?eT(Object(n),!0).forEach(function(t){(0,f.Z)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):eT(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}}({user_id:t},n),Error("Unable to find jwt crypto, if you are getting this error is probably because you are trying to generate tokens on browser or React Native (or other environment where crypto functions are not available). Please Note: token should only be generated server-side.")}function eF(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=(0,m.Z)({algorithm:"HS256",noTimestamp:!0},t);return null.sign({server:!0},e,n)}var eq=function e(t){var n,r=this;(0,h.Z)(this,e),(0,f.Z)(this,"loadTokenPromise",void 0),(0,f.Z)(this,"type",void 0),(0,f.Z)(this,"secret",void 0),(0,f.Z)(this,"token",void 0),(0,f.Z)(this,"tokenProvider",void 0),(0,f.Z)(this,"user",void 0),(0,f.Z)(this,"setTokenOrProvider",(n=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r.validateToken(t,n),r.user=n,V(t)&&(r.tokenProvider=t,r.type="provider"),"string"==typeof t&&(r.token=t,r.type="static"),!t&&r.user&&r.secret&&(r.token=ej(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,f.Z)(this,"reset",function(){r.token=void 0,r.tokenProvider=void 0,r.type="static",r.user=void 0,r.loadTokenPromise=null}),(0,f.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&&!V(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(E(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,f.Z)(this,"tokenReady",function(){return r.loadTokenPromise}),(0,f.Z)(this,"loadToken",function(){var e;return r.loadTokenPromise=new Promise((e=(0,d.Z)(g().mark(function e(t,n){return g().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,f.Z)(this,"getToken",function(){if(r.token||r.user&&r.user.anon&&!r.token)return r.token;if(r.secret)return eF(r.secret);throw Error("Both secret and user tokens are not set. Either client.connectUser wasn't called or client.disconnect was called")}),(0,f.Z)(this,"isStatic",function(){return"static"===r.type}),this.loadTokenPromise=null,t&&(this.secret=t),this.type="static",this.secret&&(this.token=eF(this.secret))},eN={"-1":{name:"InternalSystemError",retryable:!0}
1,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 eH(e){if(!e.code)return!1;var t=eN["".concat(e.code)];return!!t&&t.retryable}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 eW(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?eV(Object(n),!0).forEach(function(t){(0,f.Z)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):eV(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}(a=c||(c={})).Closed="CLOSED",a.Connected="CONNECTED",a.Connecting="CONNECTING",a.Disconnected="DISCONNECTED",a.Init="INIT";var eB=function(){function e(t){var n,r=this,s=t.client;(0,h.Z)(this,e),(0,f.Z)(this,"client",void 0),(0,f.Z)(this,"state",void 0),(0,f.Z)(this,"consecutiveFailures",void 0),(0,f.Z)(this,"connectionID",void 0),(0,f.Z)(this,"cancelToken",void 0),(0,f.Z)(this,"_onlineStatusChanged",function(e){if(r._log("_onlineStatusChanged() - ".concat(e.type)),"offline"===e.type){var t;r._setState(c.Closed),null===(t=r.cancelToken)||void 0===t||t.cancel("disconnect() is called"),r.cancelToken=void 0;return}"online"===e.type&&r.state===c.Closed&&r.connect(!0)}),(0,f.Z)(this,"_req",(n=(0,d.Z)(g().mark(function e(t,n,s){var i,a;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r.cancelToken||t.close||(r.cancelToken=k.Z.CancelToken.source()),e.prev=1,e.next=4,r.client.doAxiosRequest("get",r.client.baseURL.replace(":3030",":8900")+"/longpoll",void 0,{config:eW(eW({},n),{},{cancelToken:null===(i=r.cancelToken)||void 0===i?void 0:i.token}),params:t});case 4:return a=e.sent,r.consecutiveFailures=0,e.abrupt("return",a);case 9:if(e.prev=9,e.t0=e.catch(1),r.consecutiveFailures+=1,!(s&&eH(e.t0))){e.next=17;break}return r._log("_req() - Retryable error, retrying request"),e.next=16,H(z(r.consecutiveFailures));case 16:return e.abrupt("return",r._req(t,n,s));case 17:throw e.t0;case 18:case"end":return e.stop()}},e,null,[[1,9]])})),function(e,t,r){return n.apply(this,arguments)})),(0,f.Z)(this,"_poll",(0,d.Z)(g().mark(function e(){var t,n,s;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r.state!==c.Connected){e.next=25;break}return e.prev=1,e.next=4,r._req({},{timeout:3e4},!0);case 4:if(null!==(t=(n=e.sent).events)&&void 0!==t&&t.length)for(s=0;s<n.events.length;s++)r.client.dispatchEvent(n.events[s]);e.next=23;break;case 8:if(e.prev=8,e.t0=e.catch(1),!k.Z.isCancel(e.t0)){e.next=13;break}return r._log("_poll() - axios canceled request"),e.abrupt("return");case 13:if(46!==e.t0.code){e.next=18;break}return r._log("_poll() - ConnectionID error, connecting without ID..."),r._setState(c.Disconnected),r.connect(!0),e.abrupt("return");case 18:if(!(void 0!==e.t0.code&&!eH(e.t0))){e.next=21;break}return r._setState(c.Closed),e.abrupt("return");case 21:return e.next=23,H(z(r.consecutiveFailures));case 23:e.next=0;break;case 25:case"end":return e.stop()}},e,null,[[1,8]])}))),(0,f.Z)(this,"connect",(0,d.Z)(g().mark(function e(){var t,n,s=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=s.length>0&&void 0!==s[0]&&s[0],r.state!==c.Connecting){e.next=4;break}return r._log("connect() - connecting already in progress",{reconnect:t},"warn"),e.abrupt("return");case 4:if(r.state!==c.Connected){e.next=7;break}return r._log("connect() - already connected and polling",{reconnect:t},"warn"),e.abrupt("return");case 7:return r._setState(c.Connecting),r.connectionID=void 0,e.prev=9,e.next=12,r._req({
1json:r.client._buildWSPayload()},{timeout:8e3},t);case 12:return n=e.sent.event,r._setState(c.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(c.Closed),e.t0;case 26:case"end":return e.stop()}},e,null,[[9,22]])}))),(0,f.Z)(this,"isHealthy",function(){return!!r.connectionID&&r.state===c.Connected}),(0,f.Z)(this,"disconnect",(0,d.Z)(g().mark(function e(){var t,n,s,i=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=i.length>0&&void 0!==i[0]?i[0]:2e3,$(r._onlineStatusChanged),r._setState(c.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=c.Init,this.consecutiveFailures=0,Q(this._onlineStatusChanged)}return(0,p.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,eW({tags:["connection_fallback","connection"]},t))}},{key:"_setState",value:function(e){this._log("_setState() - ".concat(e)),this.state===c.Connecting&&e===c.Connected&&this.client.dispatchEvent({type:"connection.changed",online:!0}),(e===c.Closed||e===c.Disconnected)&&this.client.dispatchEvent({type:"connection.changed",online:!1}),this.state=e}}]),e}(),ez=function(){var e,t,n,r,s,i,a,o;function c(e,t,n,r){(0,h.Z)(this,c),(0,f.Z)(this,"type",void 0),(0,f.Z)(this,"id",void 0),(0,f.Z)(this,"client",void 0),(0,f.Z)(this,"data",void 0),this.client=e,this.type=t,this.id=n,this.data=r}return(0,p.Z)(c,[{key:"create",value:(e=(0,d.Z)(g().mark(function e(){var t,n,r,s,i,a;return g().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,d.Z)(g().mark(function e(){return g().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,d.Z)(g().mark(function e(t){return g().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,d.Z)(g().mark(function e(t){return g().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,d.Z)(g().mark(function e(t){return g().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,d.Z)(g().mark(function e(){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.verifySegmentId(),e.abrupt("return",this.client.deleteSegment(this.id
1));case 2:case"end":return e.stop()}},e,this)})),function(){return i.apply(this,arguments)})},{key:"targetExists",value:(a=(0,d.Z)(g().mark(function e(t){return g().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,d.Z)(g().mark(function e(){var t,n,r,s=arguments;return g().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}(),eJ=function(e){(0,R.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,I.Z)(r);return e=t?Reflect.construct(n,arguments,(0,I.Z)(this).constructor):n.apply(this,arguments),(0,O.Z)(this,e)});function r(){var e;(0,h.Z)(this,r);for(var t=arguments.length,s=Array(t),i=0;i<t;i++)s[i]=arguments[i];return e=n.call.apply(n,[this].concat(s)),(0,f.Z)((0,U.Z)(e),"code",void 0),(0,f.Z)((0,U.Z)(e),"response",void 0),(0,f.Z)((0,U.Z)(e),"status",void 0),e}return r}((0,P.Z)(Error));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 eG(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?eK(Object(n),!0).forEach(function(t){(0,f.Z)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):eK(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}(o=u||(u={})).anonymous="anonymous",o.public="public";var eQ=function(e){return"function"==typeof e},e$=function e(t){var n=this;(0,h.Z)(this,e),this.value=t,(0,f.Z)(this,"handlerSet",new Set),(0,f.Z)(this,"next",function(e){var t=eQ(e)?e(n.value):e;if(t!==n.value){var r=n.value;n.value=t,n.handlerSet.forEach(function(e){return e(n.value,r)})}}),(0,f.Z)(this,"partialNext",function(e){return n.next(function(t){return eG(eG({},t),e)})}),(0,f.Z)(this,"getLatestValue",function(){return n.value}),(0,f.Z)(this,"subscribe",function(e){return e(n.value,void 0),n.handlerSet.add(e),function(){n.handlerSet.delete(e)}}),(0,f.Z)(this,"subscribeWithSelector",function(t,r){var s;return n.subscribe(function(n){var i=t(n),a=!s;for(var o in Array.isArray(i)&&e.logCount>0&&(console.warn("[StreamChat]: The API of our StateStore has changed. Instead of returning an array in the selector, please return a named object of properties."),e.logCount--),s)if(s[o]!==i[o]){a=!0;break}if(a){var c=s;s=i,r(i,c)}})})};(0,f.Z)(e$,"logCount",5);var eX=["limit","sort"];function eY(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 e0(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?eY(Object(n),!0).forEach(function(t){(0,f.Z)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):eY(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var e1=[{created_at:-1}],e2={channel:!0,channel_cid:!0,created_at:!0,created_by_user_id:!0,parent_message_id:!0,title:!0,updated_at:!0,latest_replies:!0,active_participant_count:!0,deleted_at:!0,last_message_at:!0,participant_count:!0,reply_count:!0,read:!0,thread_participants:!0,created_by:!0,parent_message:!0},e3=function(e){var t={};for(var n in e)e2[n]||(t[n]=e[n]);return t},e4=function(){function e(t){var n,r,s,i=this,a=t.client,o=t.threadData;(0,h.Z)(this,e),(0,f.Z)(this,"state",void 0),(0,f.Z)(this,"id",void 0),(0,f.Z)(this,"client",void 0),(0,f.Z)(this,"unsubscribeFunctions",new Set),(0,f.Z)(this,"failedRepliesMap",new Map),(0,f.Z)(this,"activate",function(){i.state.partialNext({active:!0})}),(0,f.Z)(this,"deactivate",function(){i.state.partialNext({active:!1})}),(0,f.Z)(this,"reload",(0,d.Z)(g().mark(function e(){var t;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!i.state.getLatestValue().isLoading){e.next=2;break}return e.abrupt("return");case 2:return i.state.partialNext({isLoading:!0}),e.prev=3,e.next=6,i.client.getThread(i.id,{watch:!0});case 6:t=e.sent,i.hydrateState(t);case 8:return e.prev=8,i.state.partialNext({isLoading:!1}),e.finish(8);case 11:case"end":return e.stop()}},e,null,[[3,,8,11]])}))),(0,f.Z)(this,"hydrateState",function(e){if(e!==i){if(e.id!==i.id)throw Error("Cannot hydrate thread state with using thread's state");var t=e.state.getLatestValue(),n=t.read,r=t.replyCount,s=t.replies,a=t.parentMessage,o=t.participants,c=t.createdAt,u=t.deletedAt,l=t.updatedAt,d=Array.from(i.failedRepliesMap.values());i.state.partialNext({read:n,replyCount:r,replies:d.length?s.concat(d):s,parentMessage:a,participants:o,createdAt:c,deletedAt:u,updatedAt:l,isStateStale:!1})}}),(0,f.Z)(this,"registerSubscriptions",function(){i.unsubscribeFunctions.size||(i.unsubscribeFunctions.add(i.subscribeThreadUpdated()),i.unsubscribeFunctions.add(i.subscribeMarkActiveThreadRead()),i.unsubscribeFunctions.add(i.subscribeReloadActiveStaleThread()),i.unsubscribeFunctions.add(i.subscribeMarkThreadStale()),i.unsubscribeFunctions.add(i.subscribeNewReplies()),i.unsubscribeFunctions.add(i.subscribeRepliesRead()),i.unsubscribeFunctions.add(i.subscribeMessageDeleted()),i.unsubscribeFunctions.add(i.subscribeMessageUpdated()))}),(0,f.Z)(this,"subscribeThreadUpdated",function(){return i.client.on("thread.updated",function(e){if(e.thread&&e.thread.parent_message_id===i.id){var t=e.thread;i.state.partialNext({title:t.title,updatedAt:new Date(t.updated_at),deletedAt:t.deleted_at?new Date(t.deleted_at):null,custom:e3(t)})}}).unsubscribe}),(0,f.Z)(this,"subscribeMarkActiveThreadRead",function(){return i.state.subscribeWithSelector(function(e){return{active:e.active,unreadMessageCount:e7(i.client.userID)(e)}},function(e){var t=e.active,n=e.unreadMessageCount;t&&n&&i.throttledMarkAsRead()})}),(0,f.Z)(this,"subscribeReloadActiveStaleThread",function(){return i.state.subscribeWithSelector(function(e){return{active:e.active,isStateStale:e.isStateStale}},function(e){var t=e.active,n=e.isStateStale;t&&n&&i.reload()})}),(0,f.Z)(this,"subscribeMarkThreadStale",function(){return i.client.on("user.watching.stop",function(e){var t,n,r=i.state.getLatestValue().channel;i.client.userID&&i.client.userID===(null===(t=e.user)||void 0===t?void 0:t.id)&&(null===(n=e.channel)||void 0===n?void 0:n.cid)===r.cid&&i.state.partialNext({isStateStale:!0})}).unsubscribe}),(0,f.Z)(this,"subscribeNewReplies",function(){return i.client.on("message.new",function(e){if(i.client.userID&&(null===(d=e.message)||void 0===d?void 0:d.parent_id)===i.id){var t=(null===(h=e.message.user)||void 0===h?void 0:h.id)===i.client.userID,n=i.state.getLatestValue(),r=n.active,s=n.read;i.upsertReplyLocally({message:e.message,timestampChanged:t}),r&&i.throttledMarkAsRead();for(var a={},o=0,c=Object.keys(s);o<c.length;o++){var u=c[o],l=s[u];if(l){var d,h,p,f=l;u===(null===(p=e.user)||void 0===p?void 0:p.id)?f=e0(e0({},f),{},{lastReadAt:e.created_at?new Date(e.created_at):new Date,user:e.user,unreadMessageCount:0}):r&&u===i.client.userID||(f=e0(e0({},f),{},{unreadMessageCount:l.unreadMessageCount+1})),a[u]=f}}i.state.partialNext({read:a})}}).unsubscribe}),(0,f.Z)(this,"subscribeRepliesRead",function(){return i.client.on("message.read",function(e){if(e.user&&e.created_at&&e.thread&&e.thread.parent_message_id===i.id){var t=e.user.id,n=e.created_at,r=e.user;i.state.next(function(s){return e0(e0({},s),{},{read:e0(e0({},s.read),{},(0,f.Z)({},t,{lastReadAt:new Date(n),user:r,lastReadMessageId:e.last_read_message_id,unreadMessageCount:0}))})})}}).unsubscribe}),(0,f.Z)(this,"subscribeMessageDeleted",function(){return i.client.on("message.deleted",function(e){e.message&&(e.message.parent_id===i.id&&(e.hard_delete?i.deleteReplyLocally({message:e.message}):i.upsertReplyLocally({message:e.message})),e.message.id===i.id&&i.updateParentMessageLocally({message:e.message}))}).unsubscribe}),(0,f.Z)(this,"subscribeMessageUpdated",function(){var e=["message.updated","reaction.new","reaction.deleted","reaction.updated"].map(function(e){return i.client.on(e,function(e){e.message&&i.updateParentMessageOrReplyLocally(e.message)}).unsubscribe});return function(){return e.forEach(function(e){return e()})}}),(0,f.Z)(this,"unregisterSubscriptions",function(){i.unsubscribeFunctions.forEach(function(e){return e()}),i.unsubscribeFunctions.clear()}),(0,f.Z)(this,"deleteReplyLocally",function(e){var t,n=e.message,r=i.state.getLatestValue().replies,s=ee({needle:Y(n),sortedArray:r,sortDirection:"ascending",selectValueToCompare:function(e){return e.created_at.getTime()},selectKey:function(e){return e.id}});if((null===(t=r[s])||void 0===t?void 0:t.id)===n.id){var a=(0,_.Z)(r);a.splice(s,1),i.state.partialNext({replies:a})}}),(0,f.Z)(this,"upsertReplyLocally",function(e){var t=e.message,n=e.timestampChanged,r=void 0!==n&&n;if(t.parent_id!==i.id)throw Error("Reply does not belong to this thread");var s=Y(t);"failed"===t.status?i.failedRepliesMap.set(s.id,s):i.failedRepliesMap.has(t.id)&&i.failedRepliesMap.delete(t.id),i.state.next(function(e){return e0(e0({},e),{},{replies:et(e.replies,s,r)})})}),(0,f.Z)(this,"updateParentMessageLocally",function(e){var t=e.message;if(t.id!==i.id)throw Error("Message does not belong to this thread");i.state.next(function(e){var n,r=Y(t);return e0(e0({},e),{},{deletedAt:r.deleted_at,parentMessage:r,replyCount:null!==(n=t.reply_count)&&void 0!==n?n:e.replyCount})})}),(0,f.Z)(this,"updateParentMessageOrReplyLocally",function(e){e.parent_id===i.id&&i.upsertReplyLocally({message:e}),e.parent_id||e.id!==i.id||i.updateParentMessageLocally({message:e})}),(0,f.Z)(this,"markAsRead",(0,d.Z)(g().mark(function e(){var t,n,r=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n=void 0!==(t=(r.length>0&&void 0!==r[0]?r[0]:{}
1).force)&&t,!(0===i.ownUnreadCount&&!n)){e.next=3;break}return e.abrupt("return",null);case 3:return e.next=5,i.channel.markRead({thread_id:i.id});case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}},e)}))),(0,f.Z)(this,"throttledMarkAsRead",en(function(){return i.markAsRead()},1e3,{trailing:!0})),(0,f.Z)(this,"queryReplies",function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.limit,n=e.sort,r=void 0===n?e1:n,s=(0,b.Z)(e,eX);return i.channel.getReplies(i.id,e0({limit:void 0===t?50:t},s),r)}),(0,f.Z)(this,"loadNextPage",function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.limit;return i.loadPage(void 0===t?50:t)}),(0,f.Z)(this,"loadPrevPage",function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.limit;return i.loadPage(-(void 0===t?50:t))}),(0,f.Z)(this,"loadPage",(n=(0,d.Z)(g().mark(function e(t){var n,r,s,a,o,c,u,l,d,h,p,v,m;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n=i.state.getLatestValue().pagination,r=t>0?["isLoadingNext","nextCursor","push"]:["isLoadingPrev","prevCursor","unshift"],a=(s=(0,w.Z)(r,3))[0],o=s[1],c=s[2],!(n[a]||null===n[o])){e.next=4;break}return e.abrupt("return");case 4:return u=(0,f.Z)({},t>0?"id_gt":"id_lt",n[o]),l=Math.abs(t),i.state.partialNext({pagination:e0(e0({},n),{},(0,f.Z)({},a,!0))}),e.prev=7,e.next=10,i.queryReplies(e0(e0({},u),{},{limit:l}));case 10:m=null!==(d=null===(h=(v=(p=e.sent).messages.map(Y)).at(t>0?-1:0))||void 0===h?void 0:h.id)&&void 0!==d?d:null,i.state.next(function(e){var t,n,r=e.replies;return v.length>0&&(n=r=(0,_.Z)(e.replies))[c].apply(n,(0,_.Z)(v)),e0(e0({},e),{},{replies:r,pagination:e0(e0({},e.pagination),{},(t={},(0,f.Z)(t,o,p.messages.length<l?null:m),(0,f.Z)(t,a,!1),t))})}),e.next=20;break;case 16:e.prev=16,e.t0=e.catch(7),i.client.logger("error",e.t0.message),i.state.next(function(e){return e0(e0({},e),{},{pagination:e0(e0({},e.pagination),{},(0,f.Z)({},a,!1))})});case 20:case"end":return e.stop()}},e,null,[[7,16]])})),function(e){return n.apply(this,arguments)}));var c=a.channel(o.channel.type,o.channel.id,{name:o.channel.name});c._hydrateMembers({members:null!==(r=o.channel.members)&&void 0!==r?r:[],overrideCurrentState:!1});var u=a.userID?[{user:{id:a.userID},unread_messages:0,last_read:new Date().toISOString()}]:[];this.state=new e$({active:!1,isLoading:!1,isStateStale:!1,channel:c,createdAt:new Date(o.created_at),deletedAt:o.deleted_at?new Date(o.deleted_at):null,pagination:e6(o),parentMessage:Y(o.parent_message),participants:o.thread_participants,read:e5(o.read&&0!==o.read.length?o.read:u),replies:o.latest_replies.map(Y),replyCount:null!==(s=o.reply_count)&&void 0!==s?s:0,updatedAt:o.updated_at?new Date(o.updated_at):null,title:o.title,custom:e3(o)}),this.id=o.parent_message_id,this.client=a}return(0,p.Z)(e,[{key:"channel",get:function(){return this.state.getLatestValue().channel}},{key:"hasStaleState",get:function(){return this.state.getLatestValue().isStateStale}},{key:"ownUnreadCount",get:function(){return e7(this.client.userID)(this.state.getLatestValue())}}]),e}(),e5=function(e){return e.reduce(function(e,t){var n;return e[t.user.id]={user:t.user,lastReadMessageId:t.last_read_message_id,unreadMessageCount:null!==(n=t.unread_messages)&&void 0!==n?n:0,lastReadAt:new Date(t.last_read)},e},{})},e6=function(e){var t,n;return{nextCursor:null,prevCursor:e.latest_replies.length===e.reply_count?null:null!==(t=null===(n=e.latest_replies.at(0))||void 0===n?void 0:n.id)&&void 0!==t?t:null,isLoadingNext:!1,isLoadingPrev:!1}},e7=function(e){return function(t){var n;return e&&(null===(n=t.read[e])||void 0===n?void 0:n.unreadMessageCount)||0}};function e8(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 e9(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?e8(Object(n),!0).forEach(function(t){(0,f.Z)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):e8(Object(n)).forEac
1h(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var te={user:"stream:user",message:"stream:chat:v1:message",userprofile:"stream:v1:user_profile"},tt=function(){var e,t,n,r,s,i,a,o,c,u,l,v,m,y,b,w;function _(e){(0,h.Z)(this,_),(0,f.Z)(this,"client",void 0),this.client=e}return(0,p.Z)(_,[{key:"flagUser",value:(e=(0,d.Z)(g().mark(function e(t,n){var r,s=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=s.length>2&&void 0!==s[2]?s[2]:{},e.abrupt("return",this.flag(te.user,t,"",n,r));case 2:case"end":return e.stop()}},e,this)})),function(t,n){return e.apply(this,arguments)})},{key:"flagMessage",value:(t=(0,d.Z)(g().mark(function e(t,n){var r,s=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=s.length>2&&void 0!==s[2]?s[2]:{},e.abrupt("return",this.flag(te.message,t,"",n,r));case 2:case"end":return e.stop()}},e,this)})),function(e,n){return t.apply(this,arguments)})},{key:"flag",value:(n=(0,d.Z)(g().mark(function e(t,n,r,s){var i,a=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return i=a.length>4&&void 0!==a[4]?a[4]:{},e.next=3,this.client.post(this.client.baseURL+"/api/v2/moderation/flag",e9({entity_type:t,entity_id:n,entity_creator_id:r,reason:s},i));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e,t,r,s){return n.apply(this,arguments)})},{key:"muteUser",value:(r=(0,d.Z)(g().mark(function e(t){var n,r=arguments;return g().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.client.post(this.client.baseURL+"/api/v2/moderation/mute",e9({target_ids:[t]},n));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return r.apply(this,arguments)})},{key:"unmuteUser",value:(s=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.client.post(this.client.baseURL+"/api/v2/moderation/unmute",e9({target_ids:[t]},n));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return s.apply(this,arguments)})},{key:"getUserModerationReport",value:(i=(0,d.Z)(g().mark(function e(t){var n,r=arguments;return g().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.client.get(this.client.baseURL+"/api/v2/moderation/user_report",e9({user_id:t},n));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:"queryReviewQueue",value:(a=(0,d.Z)(g().mark(function e(){var t,n,r,s=arguments;return g().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.client.post(this.client.baseURL+"/api/v2/moderation/review_queue",e9({filter:t,sort:B(n)},r));case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}},e,this)})),function(){return a.apply(this,arguments)})},{key:"upsertConfig",value:(o=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.client.post(this.client.baseURL+"/api/v2/moderation/config",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:"getConfig",value:(c=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.client.get(this.client.baseURL+"/api/v2/moderation/config/"+t,n);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return c.apply(this,arguments)})},{key:"deleteConfig",value:(u=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.client.delete(this.client.baseURL+"/api/v2/moderation/config/"+t,n);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return u.apply(this,arguments)})},{key:"queryConfigs",value:(l=(0,d.Z)(g().mark(function e(t,n){var r,s=arguments;return g().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.client.post(this.client.baseURL+"/api/v2/moderation/configs",e9({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){return l.apply(this,arguments)})},{key:"submitAction",value:(v=(0,d.Z)(g().mark(function e(t,n){var r,s=arguments;return g().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.client.post(this.client.baseURL+"/api/v2/moderation/submit_action",e9({action_type:t,item_id:n},r));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e,t){return v.apply(this,arguments)})},{key:"check",value:(m=(0,d.Z)(g().mark(function e(t,n,r,s,i,a){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.client.post(this.client.baseURL+"/api/v2/moderation/check",{entity_type:t,entity_id:n,entity_creator_id:r,moderation_payload:s,config_key:i,options:a});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t,n,r,s,i){return m.apply(this,arguments)})},{key:"checkUserProfile",value:(y=(0,d.Z)(g().mark(function e(t,n){var r;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!(!n.username&&!n.image)){e.next=2;break}throw Error("Either username or image must be provided");case 2:return r={},n.username&&(r.texts=[n.username]),n.image&&(r.images=[n.image]),e.next=7,this.check(te.userprofile,t,t,r,"user_profile:default",{force_sync:!0,test_mode:!0});case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}},e,this)})),function(e,t){return y.apply(this,arguments)})},{key:"addCustomFlags",value:(b=(0,d.Z)(g().mark(function e(t,n,r,s,i){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.client.post(this.client.baseURL+"/api/v2/moderation/custom_check",{entity_type:t,entity_id:n,entity_creator_id:r,moderation_payload:s,flags:i});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}
1)),function(e,t,n,r,s){return b.apply(this,arguments)})},{key:"addCustomMessageFlags",value:(w=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.addCustomFlags(te.message,t,"",{},n);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return w.apply(this,arguments)})}]),_}();function tn(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function tr(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 ts(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?tr(Object(n),!0).forEach(function(t){(0,f.Z)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):tr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var ti={active:!1,isThreadOrderStale:!1,threads:[],unreadThreadCount:0,unseenThreadIds:[],lastConnectionDropAt:null,pagination:{isLoading:!1,isLoadingNext:!1,nextCursor:null},ready:!1},ta=function(){function e(t){var n=this,r=t.client;(0,h.Z)(this,e),(0,f.Z)(this,"state",void 0),(0,f.Z)(this,"client",void 0),(0,f.Z)(this,"unsubscribeFunctions",new Set),(0,f.Z)(this,"threadsByIdGetterCache",void 0),(0,f.Z)(this,"resetState",function(){n.state.next(ti)}),(0,f.Z)(this,"activate",function(){n.state.partialNext({active:!0})}),(0,f.Z)(this,"deactivate",function(){n.state.partialNext({active:!1})}),(0,f.Z)(this,"registerSubscriptions",function(){n.unsubscribeFunctions.size||(n.unsubscribeFunctions.add(n.subscribeUnreadThreadsCountChange()),n.unsubscribeFunctions.add(n.subscribeManageThreadSubscriptions()),n.unsubscribeFunctions.add(n.subscribeReloadOnActivation()),n.unsubscribeFunctions.add(n.subscribeNewReplies()),n.unsubscribeFunctions.add(n.subscribeRecoverAfterConnectionDrop()),n.unsubscribeFunctions.add(n.subscribeChannelDeleted()))}),(0,f.Z)(this,"subscribeUnreadThreadsCountChange",function(){var e,t=(null!==(e=n.client.user)&&void 0!==e?e:{}).unread_threads;n.state.partialNext({unreadThreadCount:void 0===t?0:t});var r=["health.check","notification.mark_read","notification.thread_message_new","notification.channel_deleted"].map(function(e){return n.client.on(e,function(e){var t,r=(null!==(t=e.me)&&void 0!==t?t:e).unread_threads;"number"==typeof r&&n.state.partialNext({unreadThreadCount:r})}).unsubscribe});return function(){return r.forEach(function(e){return e()})}}),(0,f.Z)(this,"subscribeChannelDeleted",function(){return n.client.on("notification.channel_deleted",function(e){var t=e.cid,r=n.state.getLatestValue().threads.filter(function(e){return e.channel.cid!==t});n.state.partialNext({threads:r})}).unsubscribe}),(0,f.Z)(this,"subscribeManageThreadSubscriptions",function(){return n.state.subscribeWithSelector(function(e){return{threads:e.threads}},function(e,t){var r=e.threads,s=(null!=t?t:{}).threads,i=(void 0===s?[]:s).filter(function(e){return e!==n.threadsById[e.id]});r.forEach(function(e){return e.registerSubscriptions()}
1),i.forEach(function(e){return e.unregisterSubscriptions()})})}),(0,f.Z)(this,"subscribeReloadOnActivation",function(){return n.state.subscribeWithSelector(function(e){return{active:e.active}},function(e){e.active&&n.reload()})}),(0,f.Z)(this,"subscribeNewReplies",function(){return n.client.on("notification.thread_message_new",function(e){var t,r=null===(t=e.message)||void 0===t?void 0:t.parent_id;if(r){var s=n.state.getLatestValue(),i=s.unseenThreadIds;s.ready&&(n.threadsById[r]?n.state.partialNext({isThreadOrderStale:!0}):i.includes(r)||n.state.partialNext({unseenThreadIds:i.concat(r)}))}}).unsubscribe}),(0,f.Z)(this,"subscribeRecoverAfterConnectionDrop",function(){var e=n.client.on("connection.changed",function(e){!1===e.online&&n.state.next(function(e){return e.lastConnectionDropAt?e:ts(ts({},e),{},{lastConnectionDropAt:new Date})})}).unsubscribe,t=en(function(){n.state.getLatestValue().lastConnectionDropAt&&n.reload({force:!0})},1e3,{trailing:!0}),r=n.client.on("connection.recovered",t).unsubscribe;return function(){e(),r()}}),(0,f.Z)(this,"unregisterSubscriptions",function(){n.state.getLatestValue().threads.forEach(function(e){return e.unregisterSubscriptions()}),n.unsubscribeFunctions.forEach(function(e){return e()}),n.unsubscribeFunctions.clear()}),(0,f.Z)(this,"reload",(0,d.Z)(g().mark(function e(){var t,r,s,i,a,o,c,u,l,d,h,p,f,v,m,y,b=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r=void 0!==(t=(b.length>0&&void 0!==b[0]?b[0]:{}).force)&&t,i=(s=n.state.getLatestValue()).threads,a=s.unseenThreadIds,o=s.isThreadOrderStale,c=s.pagination,u=s.ready,!c.isLoading){e.next=4;break}return e.abrupt("return");case 4:if(!(!r&&u&&!a.length&&!o)){e.next=6;break}return e.abrupt("return");case 6:return l=i.length+a.length,e.prev=7,n.state.next(function(e){return ts(ts({},e),{},{pagination:ts(ts({},e.pagination),{},{isLoading:!0})})}),e.next=11,n.queryThreads({limit:Math.min(l,25)||25});case 11:d=e.sent,h=n.threadsById,p=[],f=function(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 tn(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 tn(e,void 0)}}(e))){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}}}}(d.threads);try{for(f.s();!(v=f.n()).done;)(y=h[(m=v.value).id])?(p.push(y),y.hasStaleState&&y.hydrateState(m)):p.push(m)}catch(e){f.e(e)}finally{f.f()}n.state.next(function(e){var t;return ts(ts({},e),{},{threads:p,unseenThreadIds:[],isThreadOrderStale:!1,pagination:ts(ts({},e.pagination),{},{isLoading:!1,nextCursor:null!==(t=d.next)&&void 0!==t?t:null}),ready:!0})}),e.next=23;break;case 19:e.prev=19,e.t0=e.catch(7),n.client.logger("error",e.t0.message),n.state.next(function(e){return ts(ts({},e),{},{pagination:ts(ts({},e.pagination),{},{isLoading:!1})})});case 23:case"end":return e.stop()}},e,null,[[7,19]])}))),(0,f.Z)(this,"queryThreads",function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return n.client.queryThreads(ts({limit:25,participant_limit:10,reply_limit:10,watch:!0},e))}),(0,f.Z)(this,"loadNextPage",(0,d.Z)(g().mark(function e(){var t,r,s,i=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=i.length>0&&void 0!==i[0]?i[0]:{},!((r=n.state.getLatestValue().pagination).isLoadingNext||!r.nextCursor)){e.next=4;break}return e.abrupt("return");case 4:return e.prev=4,n.state.partialNext({pagination:ts(ts({},r),{},{isLoadingNext:!0})}),e.next=8,n.queryThreads(ts(ts({},t),{},{next:r.nextCursor}));case 8:s=e.sent,n.state.next(function(e){var t;return ts(ts({},e),{},{threads:s.threads.length?e.threads.concat(s.threads):e.threads,pagination:ts(ts({},e.pagination),{},{nextCursor:null!==(t=s.next)&&void 0!==t?t:null,isLoadingNext:!1})})}),e.next=16;break;case 12:e.prev=12,e.t0=e.catch(4),n.client.logger("error",e.t0.message),n.state.next(function(e){return ts(ts({},e),{},{pagination:ts(ts({},e.pagination),{},{isLoadingNext:!1})})});case 16:case"end":return e.stop()}},e,null,[[4,12]])}))),this.client=r,this.state=new e$(ti),this.threadsByIdGetterCache={threads:[],threadsById:{}}}return(0,p.Z)(e,[{key:"threadsById",get:function(){var e=this.state.getLatestValue().threads;if(e===this.threadsByIdGetterCache.threads)return this.threadsByIdGetterCache.threadsById;var t=e.reduce(function(e,t){return e[t.id]=t,e},{});return this.threadsByIdGetterCache.threads=e,this.threadsByIdGetterCache.threadsById=t,t}}]),e}(),to=["own_votes","id"],tc=["id"];function tu(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 tl(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};
1t%2?tu(Object(n),!0).forEach(function(t){(0,f.Z)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):tu(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var td=function(e){return!!(null!=e&&e.answer_text)},th=function(){function e(t){var n,r,s,i,a,o,c,u,l,p,v,m,y=this,k=t.client,x=t.poll;(0,h.Z)(this,e),(0,f.Z)(this,"state",void 0),(0,f.Z)(this,"id",void 0),(0,f.Z)(this,"client",void 0),(0,f.Z)(this,"unsubscribeFunctions",new Set),(0,f.Z)(this,"getInitialStateFromPollResponse",function(e){var t,n=e.own_votes;e.id;var r=(0,b.Z)(e,to),s=null!==(t=null==n?void 0:n.reduce(function(e,t){return td(t)?e.ownAnswer=t:e.ownVotes.push(t),e},{ownVotes:[]}))&&void 0!==t?t:{ownVotes:[]},i=s.ownAnswer,a=s.ownVotes;return tl(tl({},r),{},{lastActivityAt:new Date,maxVotedOptionIds:tp(r.vote_counts_by_option),ownAnswer:i,ownVotesByOptionId:a?a.reduce(function(e,t){return td(t)||!t.option_id||(e[t.option_id]=t),e},{}):{}})}),(0,f.Z)(this,"reinitializeState",function(e){y.state.partialNext(y.getInitialStateFromPollResponse(e))}),(0,f.Z)(this,"handlePollUpdated",function(e){if((null===(n=e.poll)||void 0===n||!n.id||e.poll.id===y.id)&&"poll.updated"===e.type){var t,n,r={allow_answers:(t=e.poll).allow_answers,allow_user_suggested_options:t.allow_user_suggested_options,description:t.description,enforce_unique_vote:t.enforce_unique_vote,id:t.id,is_closed:t.is_closed,max_votes_allowed:t.max_votes_allowed,name:t.name,options:t.options,voting_visibility:t.voting_visibility},s=(0,b.Z)(r,tc);y.state.partialNext(tl(tl({},s),{},{lastActivityAt:new Date(e.created_at)}))}}),(0,f.Z)(this,"handlePollClosed",function(e){var t;null!==(t=e.poll)&&void 0!==t&&t.id&&e.poll.id!==y.id||"poll.closed"!==e.type||y.state.partialNext({is_closed:!0,lastActivityAt:new Date(e.created_at)})}),(0,f.Z)(this,"handleVoteCasted",function(e){if((null===(t=e.poll)||void 0===t||!t.id||e.poll.id===y.id)&&"poll.vote_casted"===e.type){var t,n=y.data,r=e.poll_vote.user_id===y.client.userID,s=(0,_.Z)(n.latest_answers),i=n.ownAnswer,a=n.ownVotesByOptionId,o=n.maxVotedOptionIds;r&&(td(e.poll_vote)?i=e.poll_vote:e.poll_vote.option_id&&(a[e.poll_vote.option_id]=e.poll_vote)),td(e.poll_vote)?s=[e.poll_vote].concat((0,_.Z)(s)):o=tp(e.poll.vote_counts_by_option);var c=tf(e.poll);y.state.partialNext(tl(tl({},c),{},{latest_answers:s,lastActivityAt:new Date(e.created_at),ownAnswer:i,ownVotesByOptionId:a,maxVotedOptionIds:o}))}}),(0,f.Z)(this,"handleVoteChanged",function(e){if((null===(t=e.poll)||void 0===t||!t.id||e.poll.id===y.id)&&"poll.vote_changed"===e.type){var t,n,r=y.data,s=e.poll_vote.user_id===y.client.userID,i=(0,_.Z)(r.latest_answers),a=r.ownAnswer,o=r.ownVotesByOptionId,c=r.maxVotedOptionIds;s?td(e.poll_vote)?(i=[e.poll_vote].concat((0,_.Z)(i.filter(function(t){return t.id!==e.poll_vote.id}))),a=e.poll_vote):e.poll_vote.option_id&&(e.poll.enforce_unique_votes?o=(0,f.Z)({},e.poll_vote.option_id,e.poll_vote):(o=Object.entries(o).reduce(function(t,n){var r=(0,w.Z)(n,2),s=r[0],i=r[1];return s!==e.poll_vote.option_id&&i.id===e.poll_vote.id||(t[s]=i),t},{}))[e.poll_vote.option_id]=e.poll_vote,(null===(n=a)||void 0===n?void 0:n.id)===e.poll_vote.id&&(a=void 0),c=tp(e.poll.vote_counts_by_option)):td(e.poll_vote)?i=[e.poll_vote].concat((0,_.Z)(i)):c=tp(e.poll.vote_counts_by_option);var u=tf(e.poll);y.state.partialNext(tl(tl({},u),{},{latest_answers:i,lastActivityAt:new Date(e.created_at),ownAnswer:a,ownVotesByOptionId:o,maxVotedOptionIds:c}))}}),(0,f.Z)(this,"handleVoteRemoved",function(e){if((null===(t=e.poll)||void 0===t||!t.id||e.poll.id===y.id)&&"poll.vote_removed"===e.type){var t,n=y.data,r=e.poll_vote.user_id===y.client.userID,s=(0,_.Z)(n.latest_answers),i=n.ownAnswer,a=tl({},n.ownVotesByOptionId),o=n.maxVotedOptionIds;td(e.poll_vote)?(s=s.filter(function(t){return t.id!==e.poll_vote.id}),r&&(i=void 0)):(o=tp(e.poll.vote_counts_by_option),r&&e.poll_vote.option_id&&delete a[e.poll_vote.option_id]);var c=tf(e.poll);y.state.partialNext(tl(tl({},c),{},{latest_answers:s,lastActivityAt:new Date(e.created_at),ownAnswer:i,ownVotesByOptionId:a,maxVotedOptionIds:o}))}}),(0,f.Z)(this,"query",(n=(0,d.Z)(g().mark(function e(t){var n;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.client.getPoll(t);case 2:return n=e.sent.poll,y.state.partialNext(tl(tl({},n),{},{lastActivityAt:new Date})),e.abrupt("return",n);case 6:case"end":return e.stop()}},e)})),function(e){return n.apply(this,arguments)})),(0,f.Z)(this,"update",(r=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.client.updatePoll(tl(tl({},t),{},{id:y.id}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)})),function(e){return r.apply(this,arguments)})),(0,f.Z)(this,"partialUpdate",(s=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.client.partialUpdatePoll(y.id,t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)})),function(e){return s.apply(this,arguments)})),(0,f.Z)(this,"close",(0,d.Z)(g().mark(function e(){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.client.closePoll(y.id);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)}))),(0,f.Z)(this,"delete",(0,d.Z)(g().mark(function e(){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.client.deletePoll(y.id);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)}))),(0,f.Z)(this,"createOption",(i=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.client.createPollOption(y.id,t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)})),function(e){return i.apply(this,arguments)})),(0,f.Z)(this,"updateOption",(a=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.client.updatePollOption(y.id,t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)})),function(e){return a.apply(this,arguments)})),(0,f.Z)(this,"deleteOption",(o=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.client.deletePollOption(y.id,t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)})),function(e){return o.apply(this,arguments)})),(0,f.Z)(this,"castVote",(c=(0,d.Z)(g().mark(function e(t,n){var r,s,i,a,o;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(s=(r=y.data).max_votes_allowed,i=r.ownVotesByOptionId,!(s&&s===Object.keys(i).length)||(o=Object.values(i)[0],Object.values(i).slice(1).forEac
1h(function(e){var t;(!(null!==(t=o)&&void 0!==t&&t.created_at)||new Date(e.created_at)<new Date(o.created_at))&&(o=e)}),!(null!==(a=o)&&void 0!==a&&a.id))){e.next=8;break}return e.next=8,y.removeVote(o.id,n);case 8:return e.next=10,y.client.castPollVote(n,y.id,{option_id:t});case 10:return e.abrupt("return",e.sent);case 11:case"end":return e.stop()}},e)})),function(e,t){return c.apply(this,arguments)})),(0,f.Z)(this,"removeVote",(u=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.client.removePollVote(n,y.id,t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)})),function(e,t){return u.apply(this,arguments)})),(0,f.Z)(this,"addAnswer",(l=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.client.addPollAnswer(n,y.id,t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)})),function(e,t){return l.apply(this,arguments)})),(0,f.Z)(this,"removeAnswer",(p=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.client.removePollVote(n,y.id,t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)})),function(e,t){return p.apply(this,arguments)})),(0,f.Z)(this,"queryAnswers",(v=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.client.queryPollAnswers(y.id,t.filter,t.sort,t.options);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)})),function(e){return v.apply(this,arguments)})),(0,f.Z)(this,"queryOptionVotes",(m=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,y.client.queryPollVotes(y.id,t.filter,t.sort,t.options);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)})),function(e){return m.apply(this,arguments)})),this.client=k,this.id=x.id,this.state=new e$(this.getInitialStateFromPollResponse(x))}return(0,p.Z)(e,[{key:"data",get:function(){return this.state.getLatestValue()}}]),e}();function tp(e){for(var t=0,n=[],r=0,s=Object.entries(null!=e?e:{});r<s.length;r++){var i=(0,w.Z)(s[r],2),a=i[0],o=i[1];o>t?(n=[a],t=o):o===t&&n.push(a)}return n}function tf(e){return{answers_count:e.answers_count,latest_votes_by_option:e.latest_votes_by_option,vote_count:e.vote_count,vote_counts_by_option:e.vote_counts_by_option}}function tv(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var tg=function(){function e(t){var n,r,s,i=this,a=t.client;(0,h.Z)(this,e),(0,f.Z)(this,"client",void 0),(0,f.Z)(this,"pollCache",new Map),(0,f.Z)(this,"unsubscribeFunctions",new Set),(0,f.Z)(this,"fromState",function(e){return i.pollCache.get(e)}),(0,f.Z)(this,"registerSubscriptions",function(){i.unsubscribeFunctions.size||(i.unsubscribeFunctions.add(i.subscribeMessageNew()),i.unsubscribeFunctions.add(i.subscribePollUpdated()),i.unsubscribeFunctions.add(i.subscribePollClosed()),i.unsubscribeFunctions.add(i.subscribeVoteCasted()),i.unsubscribeFunctions.add(i.subscribeVoteChanged()),i.unsubscribeFunctions.add(i.subscribeVoteRemoved()))}),(0,f.Z)(this,"unregisterSubscriptions",function(){i.unsubscribeFunctions.forEach(function(e){return e()}),i.unsubscribeFunctions.clear()}),(0,f.Z)(this,"createPoll",(n=(0,d.Z)(g().mark(function e(t){var n;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,i.client.createPoll(t);case 2:return n=e.sent.poll,e.abrupt("return",new th({client:i.client,poll:n}));case 5:case"end":return e.stop()}},e)})),function(e){return n.apply(this,arguments)})),(0,f.Z)(this,"getPoll",(r=(0,d.Z)(g().mark(function e(t){var n,r;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!(n=i.fromState(t))){e.next=4;break}return i.client.getPoll(t).then(function(e){var t=e.poll;return i.setOrOverwriteInCache(t,!0)}),e.abrupt("return",n);case 4:return e.next=6,i.client.getPoll(t);case 6:return r=e.sent.poll,i.setOrOverwriteInCache(r),e.abrupt("return",i.fromState(t));case 10:case"end":return e.stop()}},e)})),function(e){return r.apply(this,arguments)})),(0,f.Z)(this,"queryPolls",(s=(0,d.Z)(g().mark(function e(t){var n,r,s,a,o,c,u=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=u.length>1&&void 0!==u[1]?u[1]:[],r=u.length>2&&void 0!==u[2]?u[2]:{},e.next=4,i.client.queryPolls(t,n,r);case 4:return a=(s=e.sent).polls,o=s.next,c=a.map(function(e){return i.setOrOverwriteInCache(e,!0),i.fromState(e.id)}),e.abrupt("return",{polls:c,next:o});case 9:case"end":return e.stop()}},e)})),function(e){return s.apply(this,arguments)})),(0,f.Z)(this,"hydratePollCache",function(e,t){var n,r=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];
1if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return tv(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 tv(e,void 0)}}(e))){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}}}}(e);try{for(r.s();!(n=r.n()).done;){var s=n.value;if(s.poll){var a=s.poll;i.setOrOverwriteInCache(a,t)}}}catch(e){r.e(e)}finally{r.f()}}),(0,f.Z)(this,"setOrOverwriteInCache",function(e,t){if(i.client._cacheEnabled()){var n=i.fromState(e.id);if(n)t&&n.reinitializeState(e);else{var r=new th({client:i.client,poll:e});i.pollCache.set(r.id,r)}}}),(0,f.Z)(this,"subscribePollUpdated",function(){return i.client.on("poll.updated",function(e){var t,n;null!==(t=e.poll)&&void 0!==t&&t.id&&(null===(n=i.fromState(e.poll.id))||void 0===n||n.handlePollUpdated(e))}).unsubscribe}),(0,f.Z)(this,"subscribePollClosed",function(){return i.client.on("poll.closed",function(e){var t,n;null!==(t=e.poll)&&void 0!==t&&t.id&&(null===(n=i.fromState(e.poll.id))||void 0===n||n.handlePollClosed(e))}).unsubscribe}),(0,f.Z)(this,"subscribeVoteCasted",function(){return i.client.on("poll.vote_casted",function(e){var t,n;null!==(t=e.poll)&&void 0!==t&&t.id&&(null===(n=i.fromState(e.poll.id))||void 0===n||n.handleVoteCasted(e))}).unsubscribe}),(0,f.Z)(this,"subscribeVoteChanged",function(){return i.client.on("poll.vote_changed",function(e){var t,n;null!==(t=e.poll)&&void 0!==t&&t.id&&(null===(n=i.fromState(e.poll.id))||void 0===n||n.handleVoteChanged(e))}).unsubscribe}),(0,f.Z)(this,"subscribeVoteRemoved",function(){return i.client.on("poll.vote_removed",function(e){var t,n;null!==(t=e.poll)&&void 0!==t&&t.id&&(null===(n=i.fromState(e.poll.id))||void 0===n||n.handleVoteRemoved(e))}).unsubscribe}),(0,f.Z)(this,"subscribeMessageNew",function(){return i.client.on("message.new",function(e){var t=e.message;if(t){var n=Y(t);i.hydratePollCache([n])}}).unsubscribe}),this.client=a}return(0,p.Z)(e,[{key:"data",get:function(){return this.pollCache}}]),e}();function tm(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 ty(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?tm(Object(n),!0).forEach(function(t){(0,f.Z)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):tm(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var tb={"channel.deleted":"channelDeletedHandler","channel.hidden":"channelHiddenHandler","channel.truncated":"channelTruncatedHandler","channel.updated":"channelUpdatedHandler","channel.visible":"channelVisibleHandler","message.new":"newMessageHandler","member.updated":"memberUpdatedHandler","notification.added_to_channel":"notificationAddedToChannelHandler","notification.message_new":"notificationNewMessageHandler","notification.removed_from_channel":"notificationRemovedFromChannelHandler"},tw={abortInFlightQuery:!1,allowNotLoadedChannelPromotionForEvent:{"channel.visible":!0,"message.new":!0,"notification.added_to_channel":!0,"notification.message_new":!0},lockChannelOrder:!1},t_={limit:10,offset:0},tk=function e(t){var n,r,s,i,a=this,o=t.client,c=t.eventHandlerOverrides,u=t.options;(0,h.Z)(this,e),(0,f.Z)(this,"state",void 0),(0,f.Z)(this,"client",void 0),(0,f.Z)(this,"unsubscribeFunctions",new Set),(0,f.Z)(this,"eventHandlers",new Map),(0,f.Z)(this,"eventHandlerOverrides",new Map),(0,f.Z)(this,"options",{}),(0,f.Z)(this,"stateOptions",{}),(0,f.Z)(this,"setChannels",function(e){a.state.next(function(t){var n=t.channels,r=eQ(e)?e(n):e;return n===r?t:ty(ty({},t),{},{channels:r})})}),(0,f.Z)(this,"setEventHandlerOverrides",function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=Object.entries(e).reduce(function(e,t){var n=(0,w.Z)(t,2),r=n[0],s=n[1];return s&&(e[r]=s),e},{});a.eventHandlerOverrides=new Map(Object.entries(t))}),(0,f.Z)(this,"setOptions",function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};a.options=ty(ty({},tw),e)}),(0,f.Z)(this,"queryChannels",(n=(0,d.Z)(g().mark(function e(t){var n,r,s,i,o,c,u,l,d,h,p,f,v=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n=v.length>1&&void 0!==v[1]?v[1]:[],r=v.length>2&&void 0!==v[2]?v[2]:{},s=v.length>3&&void 0!==v[3]?v[3]:{},o=(i=ty(ty({},t_),r)).offset,c=i.limit,!(a.state.getLatestValue().pagination.isLoading&&!a.options.abortInFlightQuery)){e.next=7;break}return e.abrupt("return");case 7:return e.prev=7,a.stateOptions=s,a.state.next(function(e){return ty(ty({},e),{},{pagination:ty(ty({},e.pagination),{},{isLoading:!0,isLoadingNext:!1,filters:t,sort:n,options:r})})}),e.next=12,a.client.queryChannels(t,n,r,s);case 12:d=e.sent,h=o+(null!==(u=null==d?void 0:d.length)&&void 0!==u?u:0),p=ty(ty({},r),{},{offset:h}),f=a.state.getLatestValue().pagination,a.state.partialNext({channels:d,pagination:ty(ty({},f),{},{hasNext:(null!==(l=null==d?void 0:d.length)&&void 0!==l?l:0)>=c,isLoading:!1,options:p}),initialized:!0}),e.next=24;break;case 19:throw e.prev=19,e.t0=e.catch(7),a.client.logger("error",e.t0.message),a.state.next(function(e){return ty(ty({},e),{},{pagination:ty(ty({},e.pagination),{},{isLoading:!1})})}),e.t0;case 24:case"end":return e.stop()}},e,null,[[7,19]])})),function(e){return n.apply(this,arguments)})),(0,f.Z)(this,"loadNext",(0,d.Z)(g().mark(function e(){var t,n,r,s,i,o,c,u,l,d,h,p,f,v,m,y,b;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n=(t=a.state.getLatestValue()).pagination,r=t.initialized,s=n.filters,i=n.sort,o=n.options,c=n.isLoadingNext,u=n.hasNext,!(!r||c||!u)){e.next=4;break}return e.abrupt("return");case 4:return e.prev=4,p=(h=ty(ty({},t_),o)).offset,f=h.limit,a.state.partialNext({pagination:ty(ty({},n),{},{isLoading:!1,isLoadingNext:!0})}),e.next=9,a.client.queryChannels(s,i,o,a.stateOptions);case 9:v=e.sent,m=a.state.getLatestValue().channels,y=p+(null!==(l=null==v?void 0:v.length)&&void 0!==l?l:0),b=ty(ty({},o),{},{offset:y}),a.state.partialNext({channels:er([].concat((0,_.Z)(m||[]),(0,_.Z)(v)),"cid"),pagination:ty(ty({},n),{},{hasNext:(null!==(d=null==v?void 0:v.length)&&void 0!==d?d:0)>=f,isLoading:!1,isLoadingNext:!1,options:b})}),e.next=21;break;case 16:throw e.prev=16,e.t0=e.catch(4),a.client.logger("error",e.t0.message),a.state.next(function(e){return ty(ty({},e),{},{pagination:ty(ty({},e.pagination),{},{isLoadingNext:!1})})}),e.t0;case 21:case"end":return e.stop()}},e,null,[[4,16]])}))),(0,f.Z)(this,"notificationAddedToChannelHandler",(r=(0,d.Z)(g().mark(function e(t){var n,r,s,i,o,c,u,l,d,h,p;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(i=(s=null!==(n=null==t?void 0:t.channel)&&void 0!==n?n:{}).id,o=s.type,c=s.members,!(!o||!(null!==(r=a.options.allowNotLoadedChannelPromotionForEvent)&&void 0!==r&&r["notification.added_to_channel"]))){e.next=3;break}return e.abrupt("return");case 3:return e.next=5,eu({client:a.client,id:i,members:null==c?void 0:c.reduce(function(e,t){var n=t.user,r=t.user_id||(null==n?void 0:n.id);return r&&e.push(r),e},[]),type:o});case 5:if(u=e.sent,d=(l=a.state.getLatestValue()).pagination,h=l.channels){e.next=9;break}return e.abrupt("return");case 9:p=(null!=d?d:{}).sort,a.setChannels(ey({channels:h,channelToMove:u,sort:p}));case 11:case"end":return e.stop()}},e)})),function(e){return r.apply(this,arguments)})),(0,f.Z)(this,"channelDeletedHandler",function(e){var t=a.state.getLatestValue().channels;if(t){var n=(0,_.Z)(t),r=n.findIndex(function(t){var n;return t.cid===(e.cid||(null===(n=e.channel)||void 0===n?void 0:n.cid))});r<0||(n.splice(r,1),a.setChannels(n))}}),(0,f.Z)(this,"channelHiddenHandler",this.channelDeletedHandler),(0,f.Z)(this,"newMessageHandler",function(e){var t,n=a.state.getLatestValue(),r=n.pagination,s=n.channels;if(s){var i=null!=r?r:{},o=i.filters,c=i.sort,u=e.channel_type,l=e.channel_id;if(u&&l){var d=a.client.channel(u,l),h=s.indexOf(d),p=h>=0,f=ed(d),v=eh(d),g=ep(o),m=ev(c);g&&v&&!o.archived||g&&!v&&o.archived||m&&f||a.options.lockChannelOrder||!p&&(null===(t=a.options.allowNotLoadedChannelPromotionForEvent)||void 0===t||!t["message.new"])||a.setChannels(ey({channels:s,channelToMove:d,channelToMoveIndexWithinChannels:h,sort:c}))}}}),(0,f.Z)(this,"notificationNewMessageHandler",(s=(0,d.Z)(g().mark(function e(t){var n,r,s,i,o,c,u,l,d,h,p,f,v,m;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(i=(s=null!==(n=null==t?void 0:t.channel)&&void 0!==n?n:{}).id,o=s.type,!(!i||!o)){e.next=3;break}return e.abrupt("return");case 3:return e.next=5,eu({client:a.client,id:i,type:o});case 5:if(c=e.sent,l=(u=a.state.getLatestValue()).channels,p=(h=null!=(d=u.pagination)?d:{}).filters,f=h.sort,v=ep(p),m=eh(c),!(!l||v&&m&&!p.archived||v&&!m&&p.archived||!(null!==(r=a.options.allowNotLoadedChannelPromotionForEvent)&&void 0!==r&&r["notification.message_new"]))){e.next=12;break}return e.abrupt("return");case 12:a.setChannels(ey({channels:l,channelToMove:c,sort:f}));case 13:case"end":return e.stop()}},e)})),function(e){return s.apply(this,arguments)})),(0,f.Z)(this,"channelVisibleHandler",(i=(0,d.Z)(g().mark(function e(t){var n,r,s,i,o,c,u,l,d,h,p,f;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.channel_type,s=t.channel_id,!(!r||!s)){e.
1next=3;break}return e.abrupt("return");case 3:return e.next=5,eu({client:a.client,id:t.channel_id,type:t.channel_type});case 5:if(i=e.sent,c=(o=a.state.getLatestValue()).channels,d=(l=null!=(u=o.pagination)?u:{}).sort,p=ep(h=l.filters),f=eh(i),!(!c||p&&f&&!h.archived||p&&!f&&h.archived||!(null!==(n=a.options.allowNotLoadedChannelPromotionForEvent)&&void 0!==n&&n["channel.visible"]))){e.next=12;break}return e.abrupt("return");case 12:a.setChannels(ey({channels:c,channelToMove:i,sort:d}));case 13:case"end":return e.stop()}},e)})),function(e){return i.apply(this,arguments)})),(0,f.Z)(this,"notificationRemovedFromChannelHandler",this.channelDeletedHandler),(0,f.Z)(this,"memberUpdatedHandler",function(e){var t,n=a.state.getLatestValue(),r=n.pagination,s=n.channels,i=r.filters,o=r.sort;if(null!==(t=e.member)&&void 0!==t&&t.user&&e.member.user.id===a.client.userID&&e.channel_type&&e.channel_id){var c=e.channel_type,u=e.channel_id,l=ev(o),d=ep(i),h=ef({atIndex:0,sort:o,targetKey:"pinned_at"});if(s&&(l||d)&&!a.options.lockChannelOrder){var p=a.client.channel(c,u),f=s.indexOf(p),v=f>=0,g=ed(p),m=eh(p),y=(0,_.Z)(s);if(v&&y.splice(f,1),d&&!m&&null!=i&&i.archived||d&&m&&!(null!=i&&i.archived)){a.setChannels(y);return}var b=null;1!==h&&(-1!==h||g)||(b=em({channels:y}));var w="number"==typeof b?b+1:0;s[w]!==p&&(y.splice(w,0,p),a.setChannels(y))}}}),(0,f.Z)(this,"subscriptionOrOverride",function(e){var t=tb[e.type],n=a.eventHandlers.get(t),r=a.eventHandlerOverrides.get(t);if(r&&"function"==typeof r){r(a.setChannels,e);return}n&&"function"==typeof n&&n(e)}),(0,f.Z)(this,"registerSubscriptions",function(){if(!a.unsubscribeFunctions.size)for(var e=0,t=Object.keys(tb);e<t.length;e++){var n=t[e];a.unsubscribeFunctions.add(a.client.on(n,a.subscriptionOrOverride).unsubscribe)}}),(0,f.Z)(this,"unregisterSubscriptions",function(){a.unsubscribeFunctions.forEach(function(e){return e()}),a.unsubscribeFunctions.clear()}),this.client=o,this.state=new e$({channels:[],pagination:{isLoading:!1,isLoadingNext:!1,hasNext:!1,filters:{},sort:{},options:t_},initialized:!1}),this.setEventHandlerOverrides(void 0===c?{}:c),this.setOptions(void 0===u?{}:u),this.eventHandlers=new Map(Object.entries({channelDeletedHandler:this.channelDeletedHandler,channelHiddenHandler:this.channelHiddenHandler,channelVisibleHandler:this.channelVisibleHandler,memberUpdatedHandler:this.memberUpdatedHandler,newMessageHandler:this.newMessageHandler,notificationAddedToChannelHandler:this.notificationAddedToChannelHandler,notificationNewMessageHandler:this.notificationNewMessageHandler,notificationRemovedFromChannelHandler:this.notificationRemovedFromChannelHandler}))},tx=["created_at","updated_at","last_active","online"],tZ=["params","headers"];function tC(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 tS(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 tS(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 tS(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function tU(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 tR(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};
1t%2?tU(Object(n),!0).forEach(function(t){(0,f.Z)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):tU(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function tO(e){return"string"==typeof e||e instanceof String}var tI=function(){var e,t,n,r,s,i,a,o,c,u,v,x,C,S,U,R,O,I,P,E,T,j,F,q,N,J,G,Q,$,Y,ee,et,en,er,es,ei,ea,ec,eu,ed,eh,ep,ef,ev,eg,em,ey,eb,ew,e_,ek,ex,eZ,eC,eS,eR,eI,eP,eD,eE,eT,eF,eN,eH,eV,eW,eK,eG,eQ,e$,eX,eY,e0,e1,e2,e3,e5,e6,e7,e8,e9,te,tn,tr,ts,ti,to,tc,tu,tl,td,th,tp,tf,tv,tm,ty,tb,tw,t_,tS,tU,tI,tP,tL,tM,tD,tE,tA,tT,tj,tF;function tq(e,t,n){var r,s,i,a,o,c=this;(0,h.Z)(this,tq),(0,f.Z)(this,"_user",void 0),(0,f.Z)(this,"activeChannels",void 0),(0,f.Z)(this,"threads",void 0),(0,f.Z)(this,"polls",void 0),(0,f.Z)(this,"anonymous",void 0),(0,f.Z)(this,"persistUserOnConnectionFailure",void 0),(0,f.Z)(this,"axiosInstance",void 0),(0,f.Z)(this,"baseURL",void 0),(0,f.Z)(this,"browser",void 0),(0,f.Z)(this,"cleaningIntervalRef",void 0),(0,f.Z)(this,"clientID",void 0),(0,f.Z)(this,"configs",void 0),(0,f.Z)(this,"key",void 0),(0,f.Z)(this,"listeners",void 0),(0,f.Z)(this,"logger",void 0),(0,f.Z)(this,"recoverStateOnReconnect",void 0),(0,f.Z)(this,"moderation",void 0),(0,f.Z)(this,"mutedChannels",void 0),(0,f.Z)(this,"mutedUsers",void 0),(0,f.Z)(this,"node",void 0),(0,f.Z)(this,"options",void 0),(0,f.Z)(this,"secret",void 0),(0,f.Z)(this,"setUserPromise",void 0),(0,f.Z)(this,"state",void 0),(0,f.Z)(this,"tokenManager",void 0),(0,f.Z)(this,"user",void 0),(0,f.Z)(this,"userAgent",void 0),(0,f.Z)(this,"userID",void 0),(0,f.Z)(this,"wsBaseURL",void 0),(0,f.Z)(this,"wsConnection",void 0),(0,f.Z)(this,"wsFallback",void 0),(0,f.Z)(this,"wsPromise",void 0),(0,f.Z)(this,"consecutiveFailures",void 0),(0,f.Z)(this,"insightMetrics",void 0),(0,f.Z)(this,"defaultWSTimeoutWithFallback",void 0),(0,f.Z)(this,"defaultWSTimeout",void 0),(0,f.Z)(this,"sdkIdentifier",void 0),(0,f.Z)(this,"deviceIdentifier",void 0),(0,f.Z)(this,"appIdentifier",void 0),(0,f.Z)(this,"cachedUserAgent",void 0),(0,f.Z)(this,"nextRequestAbortController",null),(0,f.Z)(this,"_getConnectionID",function(){var e,t;return(null===(e=c.wsConnection)||void 0===e?void 0:e.connectionID)||(null===(t=c.wsFallback)||void 0===t?void 0:t.connectionID)}),(0,f.Z)(this,"_hasConnectionID",function(){return!!c._getConnectionID()}),(0,f.Z)(this,"connectUser",(r=(0,d.Z)(g().mark(function e(t,n){var r,s;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t.id){e.next=2;break}throw Error('The "id" field on the user is missing');case 2:if(!(c.userID===t.id&&c.setUserPromise)){e.next=5;break}return console.warn("Consecutive calls to connectUser is detected, ideally you should only call this function once in your app."),e.abrupt("return",c.setUserPromise);case 5:if(!c.userID){e.next=7;break}throw Error("Use client.disconnect() before trying to connect as a different user. connectUser was called twice.");case 7:return(c._isUsingServerAuth()||c.node)&&!c.options.allowServerSideConnect&&console.warn('Please do not use connectUser server side. connectUser impacts MAU and concurrent connection usage and thus your bill. If you have a valid use-case, add "allowServerSideConnect: true" to the client options to disable this warning.'),c.userID=t.id,c.anonymous=!1,r=c._setToken(t,n),c._setUser(t),s=c.openConnection(),c.setUserPromise=Promise.all([r,s]).then(function(e){return e[1]}),e.prev=14,e.next=17,c.setUserPromise;case 17:return e.abrupt("return",e.sent);case 20:throw e.prev=20,e.t0=e.catch(14),c.persistUserOnConnectionFailure?c.closeConnection():c.disconnectUser(),e.t0;case 24:case"end":return e.stop()}},e,null,[[14,20]])})),function(e,t){return r.apply(this,arguments)})),(0,f.Z)(this,"setUser",this.connectUser),(0,f.Z)(this,"_setToken",function(e,t){return c.tokenManager.setTokenOrProvider(t,e)}),(0,f.Z)(this,"closeConnection",(s=(0,d.Z)(g().mark(function e(t){var n,r;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return null!=c.cleaningIntervalRef&&(clearInterval(c.cleaningIntervalRef),c.cleaningIntervalRef=void 0),e.next=3,Promise.all([null===(n=c.wsConnection)||void 0===n?void 0:n.disconnect(t),null===(r=c.wsFallback)||void 0===r?void 0:r.disconnect(t)]);case 3:return e.abrupt("return",Promise.resolve());case 4:case"end":return e.stop()}},e)})),function(e){return s.apply(this,arguments)})),(0,f.Z)(this,"createChannelManager",function(e){var t=e.eventHandlerOverrides,n=e.options;return new tk({client:c,eventHandlerOverrides:void 0===t?{}:t,options:void 0===n?{}:n})}),(0,f.Z)(this,"openConnection",(0,d.Z)(g().mark(function e(){var t,n,r;return g().wrap(function(e){for(;;
1)switch(e.prev=e.next){case 0:if(c.userID){e.next=2;break}throw Error("User is not set on client, use client.connectUser or client.connectAnonymousUser instead");case 2:if(!(null!==(t=c.wsConnection)&&void 0!==t&&t.isConnecting&&c.wsPromise)){e.next=5;break}return c.logger("info","client:openConnection() - connection already in progress",{tags:["connection","client"]}),e.abrupt("return",c.wsPromise);case 5:if(!((null!==(n=c.wsConnection)&&void 0!==n&&n.isHealthy||null!==(r=c.wsFallback)&&void 0!==r&&r.isHealthy())&&c._hasConnectionID())){e.next=8;break}return c.logger("info","client:openConnection() - openConnection called twice, healthy connection already exists",{tags:["connection","client"]}),e.abrupt("return");case 8:return c.clientID="".concat(c.userID,"--").concat(K()),c.wsPromise=c.connect(),c._startCleaning(),e.abrupt("return",c.wsPromise);case 12:case"end":return e.stop()}},e)}))),(0,f.Z)(this,"_setupConnection",this.openConnection),(0,f.Z)(this,"_normalizeDate",function(e){if(e instanceof Date&&(e=e.toISOString()),""===e)throw Error("Don't pass blank string for since, use null instead if resetting the token revoke");return e}),(0,f.Z)(this,"disconnectUser",(i=(0,d.Z)(g().mark(function e(t){var n,r,s;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:for(c.logger("info","client:disconnect() - Disconnecting the client",{tags:["connection","client"]}),delete c.user,delete c._user,delete c.userID,c.anonymous=!1,n=c.closeConnection(t),r=0,s=Object.values(c.activeChannels);r<s.length;r++)s[r]._disconnect();return c.activeChannels={},c.state=new eO({client:c}),c.threads.resetState(),setTimeout(c.tokenManager.reset),e.abrupt("return",n);case 12:case"end":return e.stop()}},e)})),function(e){return i.apply(this,arguments)})),(0,f.Z)(this,"disconnect",this.disconnectUser),(0,f.Z)(this,"connectAnonymousUser",function(){(c._isUsingServerAuth()||c.node)&&!c.options.allowServerSideConnect&&console.warn('Please do not use connectUser server side. connectUser impacts MAU and concurrent connection usage and thus your bill. If you have a valid use-case, add "allowServerSideConnect: true" to the client options to disable this warning.'),c.anonymous=!0,c.userID=K();var e={id:c.userID,anon:!0};return c._setToken(e,""),c._setUser(e),c._setupConnection()}),(0,f.Z)(this,"setAnonymousUser",this.connectAnonymousUser),(0,f.Z)(this,"doAxiosRequest",(a=(0,d.Z)(g().mark(function e(t,n,r){var s,i,a,o,u=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return s=u.length>3&&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,H(z(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,f.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;
1r&&r._handleChannelEvent(e),c._callClientListeners(e),r&&r._callChannelListeners(e),t.forEach(function(e){return e()})}),(0,f.Z)(this,"handleEvent",function(e){var t=JSON.parse(e.data);c.dispatchEvent(t)}),(0,f.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,f.Z)(this,"_updateUserReferences",this._updateMemberWatcherReferences),(0,f.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,f.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];if(s){var i=s.state;null==i||i.deleteUserMessages(e,t)}}}),(0,f.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=tR({},c.user||{}),n=tR({},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,push_preferences:!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=tR({},n),c.user=tR(tR({},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,f.Z)(this,"_callClientListeners",function(e){var t=[];c.listeners.all&&t.push.apply(t,(0,_.Z)(c.listeners.all)),c.listeners[e.type]&&t.push.apply(t,(0,_.Z)(c.listeners[e.type]));for(var n=0;n<t.length;n++)(0,t[n])(e)}),(0,f.Z)(this,"recoverState",(0,d.Z)(g().mark(function e(){var t;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(c.logger("info","client:recoverState() - Start of recoverState with connectionID ".concat(c._getConnectionID()),{tags:["connection"]}),!((t=Object.keys(c.activeChannels)).length&&c.recoverStateOnReconnect)){e.next=10;break}return c.logger("info","client:recoverState() - Start the querying of ".concat(t.length," channels"),{tags:["connection","client"]}),e.next=6,c.queryChannels({cid:{$in:t}},{last_message_at:-1},{limit:30});case 6:c.logger("info","client:recoverState() - Querying channels finished",{tags:["connection","client"]}),c.dispatchEvent({type:"connection.recovered"}),e.next=11;break;case 10:c.dispatchEvent({type:"connection.recovered"});case 11:c.wsPromise=Promise.resolve(),c.setUserPromise=Promise.resolve();case 13:case"end":return e.stop()}},e)}))),(0,f.Z)(this,"getChannelByMembers",function(e,t){var n,r=(null!==(n=t.members)&&void 0!==n?n:[]).map(function(e){var t;return"string"==typeof e?e:null!==(t=e.user_id)&&void 0!==t?t:""}),s=r.sort().join(","),i=el(e,r);if(!i)throw Error("Please specify atleast one member when creating unique conversation");for(var a in c.activeChannels){var o=c.activeChannels[a];if(!o.disconnected&&(a===i||0===a.indexOf("".concat(e,":!members-"))&&Object.keys(o.state.members).sort().join(",")===s))return o}var u=new eU(c,e,void 0,t);return c._cacheEnabled()&&(c.activeChannels[i]=u),u}),(0,f.Z)(this,"getChannelById",function(e,t,n){if("string"==typeof t&&~t.indexOf(":"))throw Error("Invalid channel id ".concat(t,", can't contain the : character"));var r="".concat(e,":").concat(t);if(r in c.activeChannels&&c.activeChannels[r]&&!c.activeChannels[r].disconnected){var s=c.activeChannels[r];return Object.keys(n).length>0&&(s.data=tR(tR({},s.data),n),s._data=tR(tR({},s._data),n)),s}var i=new eU(c,e,t,n);return c._cacheEnabled()&&(c.activeChannels[i.cid]=i),i}),(0,f.Z)(this,"updateUsers",this.upsertUsers),(0,f.Z)(this,"updateUser",this.upsertUser),(0,f.Z)(this,"_unblockMessage",this.unblockMessage),(0,f.Z)(this,"markAllRead",this.markChannelsRead),(0,f.Z)(this,"getUserAgent",function(){if(c.userAgent)return c.userAgent;if(!c.cachedUserAgent){var e,t,n,r="8.61.0",s=null!==(e=c.sdkIdentifier)&&void 0!==e?e:{},i=s.name,a=s.version,o=null!==(t=c.appIdentifier)&&void 0!==t?t:{},u=o.name,l=o.version,d=null!==(n=c.deviceIdentifier)&&void 0!==n?n:{},h=d.os,p=d.model,f=i?"stream-chat-".concat(i,"-v").concat(a,"-llc-v").concat(r):"stream-chat-js-v".concat(r,"-").concat(c.node?"node":"browser");c.cachedUserAgent=[f].concat((0,_.Z)(Object.entries({app:u,app_version:l,os:h,device_model:p,client_bundle:""}).filter(function(e){var t=(0,w.Z)(e,2)[1];return t&&t.length>0}).map(function(e){var t=(0,w.Z)(e,2),n=t[0],r=t[1];return"".concat(n,"=").concat(r)}))).join("|")}return c.cachedUserAgent}),(0,f.Z)(this,"_isUsingServerAuth",function(){return!!c.secret}),(0,f.Z)(this,"_cacheEnabled",function(){return!c._isUsingServerAuth()||!c.options.disableCache}),(0,f.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({client:this}),this.mutedChannels=[],this.mutedUsers=[],this.moderation=new tt(this),t&&tO(t)&&(this.secret=t);var u=n||(t&&!tO(t)?t:{});this.browser=void 0!==u.browser?u.browser:"undefined"!=typeof window,this.node=!this.browser,this.options=tR({timeout:3e3,withCredentials:!1,warmUp:!1,recoverStateOnReconnect:!0,disableCache:!1,wsUrlParams:new URLSearchParams({})},u),this.node&&!this.options.httpsAgent&&(this.options.httpsAgent=new null.Agent({keepAlive:!0,keepAliveMsecs:3e3})),this.axiosInstance=k.Z.create(this.options),this.setBaseURL(this.options.baseURL||"https://chat.stream-io-api.com"),void 0!==M&&"env"in M&&M.env.STREAM_LOCAL_TEST_RUN&&this.setBaseURL("http://localhost:3030"),void 0!==M&&"env"in M&&M.env.STREAM_LOCAL_TEST_HOST&&this.setBaseURL("http://"+M.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 eq(this.secret),this.consecutiveFailures=0,this.insightMetrics=new eL,this.defaultWSTimeoutWithFallback=6e3,this.defaultWSTimeout=15e3,this.axiosInstance.defaults.paramsSerializer
1=X,this.logger=V(u.logger)?u.logger:function(){return null},this.recoverStateOnReconnect=this.options.recoverStateOnReconnect,this.threads=new ta({client:this}),this.polls=new tg({client:this})}return(0,p.Z)(tq,[{key:"devToken",value:function(e){var t;return["eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9",(t=JSON.stringify({user_id:e}),(0,l.JQ)(new Uint8Array(function(e,t){var n=[];if(D(e)&&t&&D(e)){for(var r=0,s=e.length;r<s;r++)if(e.charAt(r)){var i=t(e.charAt(r),r,e);n[r]=i}}else if(!D(e)&&!(t&&D(e))){for(var a=0,o=e.length;a<o;a++)if(a in e){var c=t(e[a],a,e);n[a]=c}}return n}(t,function(e){return e.charCodeAt(0)})))),"devtoken"].join(".")}},{key:"getAuthType",value:function(){return this.anonymous?"anonymous":"jwt"}},{key:"setBaseURL",value:function(e){this.baseURL=e,this.wsBaseURL=this.baseURL.replace("http","ws").replace(":3030",":8800")}},{key:"_setUser",value:function(e){this.user=e,this.userID=e.id,this._user=tR({},e)}},{key:"updateAppSettings",value:(e=(0,d.Z)(g().mark(function e(t){var n;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return null!=(n=t.apn_config)&&n.p12_cert&&(t=tR(tR({},t),{},{apn_config:tR(tR({},n),{},{p12_cert:L.from(n.p12_cert).toString("base64")})})),e.next=4,this.patch(this.baseURL+"/app",t);case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}},e,this)})),function(t){return e.apply(this,arguments)})},{key:"revokeTokens",value:(t=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.updateAppSettings({revoke_tokens_issued_before:this._normalizeDate(t)});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return t.apply(this,arguments)})},{key:"revokeUserToken",value:(n=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.revokeUsersToken([t],n);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return n.apply(this,arguments)})},{key:"revokeUsersToken",value:(r=(0,d.Z)(g().mark(function e(t,n){var r,s,i,a;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:n=void 0===n?new Date().toISOString():this._normalizeDate(n),r=[],s=tC(t);try{for(s.s();!(i=s.n()).done;)a=i.value,r.push({id:a,set:{revoke_tokens_issued_before:n}})}catch(e){s.e(e)}finally{s.f()}return e.next=6,this.partialUpdateUsers(r);case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}},e,this)})),function(e,t){return r.apply(this,arguments)})},{key:"getAppSettings",value:(s=(0,d.Z)(g().mark(function e(){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/app");case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(){return s.apply(this,arguments)})},{key:"testPushSettings",value:(i=(0,d.Z)(g().mark(function e(t){var n,r=arguments;return g().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+"/check_push",tR(tR(tR(tR(tR(tR(tR({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,d.Z)(g().mark(function e(){var t,n=arguments;return g().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,d.Z)(g().mark(function e(){var t,n=arguments;return g().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,d.Z)(g().mark(function e(t){var n,r,s;return g().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,b.Z)(r,tx),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),ej(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})}}
1,{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(Z()),null!==i&&"object"===(0,y.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 eJ("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;n<this.mutedChannels.length;n++){var r,s=this.mutedChannels[n];if((null===(r=s.channel)||void 0===r?void 0:r.cid)===e){t={muted:!s.expires||new Date(s.expires).getTime()>new 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:(u=(0,d.Z)(g().mark(function e(){return g().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 eA({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 eB({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 u.apply(this,arguments)})},{key:"_sayHi",value:function(){var e=this,t=K();this.doAxiosRequest("get",this.baseURL+"/hi",null,{headers:{"x-client-request-id":t}}).catch(function(n){e.options.enableInsights&&eM("http_hi_failed",{api_key:e.key,err:n,client_request_id:t})})}},{key:"queryUsers",value:(v=(0,d.Z)(g().mark(function e(t){var n,r,s,i,a=arguments;return g().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:tR(tR({filter_conditions:t,sort:B(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 v.apply(this,arguments)})},{key:"queryBannedUsers",value:(x=(0,d.Z)(g().mark(function e(){var t,n,r,s=arguments;return g().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:tR({filter_conditions:t,sort:B(n)},r)});case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}},e,this)})),function(){return x.apply(this,arguments)})},{key:"queryMessageFlags",value:(C=(0,d.Z)(g().mark(function e(){var t,n,r=arguments;return g().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:tR({filter_conditions:t},n)});case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}},e,this)})),function(){return C.apply(this,arguments)})},{key:"queryChannels",value:(S=(0,d.Z)(g().mark(function e(t){var n,r,s,i,a,o,c=arguments;return g().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=tR(tR({filter_conditions:t,sort:B(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,r));case 13:case"end":return e.stop()}},e,this)})),function(e){return S.apply(this,arguments)})},{key:"queryReactions",value:(U=(0,d.Z)(g().mark(function e(t,n){var r,s,i,a=arguments;return g().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=tR({filter:n,sort:B(r)},s),e.next=7,this.post(this.baseURL+"/messages/"+encodeURIComponent(t)+"/reactions",i);case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}},e,this)})),function(e,t){return U.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=arguments.length>2?arguments[2]:void 0,s=n.skipInitialization,i=n.offlineMode,a=void 0!==i&&i,o=[],c=tC(t);try{for(c.s();!(e=c.n()).done;){var u=e.value;this._addChannelConfig(u.channel);
1var l=this.channel(u.channel.type,u.channel.id);l.data=u.channel,l.offlineMode=a,l.initialized=!a,l.push_preferences=u.push_preferences;var d=void 0;void 0===s?d=l._initializeState(u,"latest").messageSet:s.includes(u.channel.id)||(l.state.clearMessages(),d=l._initializeState(u,"latest").messageSet),d&&(d.pagination=tR(tR({},d.pagination),eo({parentSet:d,requestedPageSize:(null==r?void 0:r.message_limit)||25,returnedPage:u.messages,logger:this.logger})),this.polls.hydratePollCache(u.messages,!0)),o.push(l)}}catch(e){c.e(e)}finally{c.f()}return o}},{key:"search",value:(R=(0,d.Z)(g().mark(function e(t,n){var r,s,i=arguments;return g().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=tR(tR({filter_conditions:t},r),{},{sort:r.sort?B(r.sort):void 0}),"string"!=typeof n){e.next=8;break}s.query=n,e.next=13;break;case 8:if("object"!==(0,y.Z)(n)){e.next=12;break}s.message_filter_conditions=n,e.next=13;break;case 12:throw Error("Invalid type ".concat((0,y.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 R.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:(O=(0,d.Z)(g().mark(function e(t,n,r,s){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/devices",tR(tR({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 O.apply(this,arguments)})},{key:"getDevices",value:(I=(0,d.Z)(g().mark(function e(t){return g().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 I.apply(this,arguments)})},{key:"getUnreadCount",value:(P=(0,d.Z)(g().mark(function e(t){return g().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 P.apply(this,arguments)})},{key:"getUnreadCountBatch",value:(E=(0,d.Z)(g().mark(function e(t){return g().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 E.apply(this,arguments)})},{key:"setPushPreferences",value:(T=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/push_preferences",{preferences:t});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return T.apply(this,arguments)})},{key:"removeDevice",value:(j=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.delete(this.baseURL+"/devices",tR({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 j.apply(this,arguments)})},{key:"getRateLimits",value:(F=(0,d.Z)(g().mark(function e(t){var n,r,s,i,a,o;return g().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 F.apply(this,arguments)})},{key:"_addChannelConfig",value:function(e){var t=e.cid,n=e.config;this._cacheEnabled()&&(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");
1if(~e.indexOf(":"))throw Error("Invalid channel group ".concat(e,", can't contain the : character"));return t&&"object"===(0,y.Z)(t)?this.getChannelByMembers(e,t):!t&&"object"===(0,y.Z)(r)&&null!==(n=r.members)&&void 0!==n&&n.length?this.getChannelByMembers(e,r):t?this.getChannelById(e,t,r):new eU(this,e,void 0,r)}},{key:"partialUpdateUser",value:(q=(0,d.Z)(g().mark(function e(t){return g().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 q.apply(this,arguments)})},{key:"upsertUsers",value:(N=(0,d.Z)(g().mark(function e(t){var n,r,s,i;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:n={},r=tC(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 N.apply(this,arguments)})},{key:"upsertUser",value:function(e){return this.upsertUsers([e])}},{key:"partialUpdateUsers",value:(J=(0,d.Z)(g().mark(function e(t){var n,r;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:n=tC(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 J.apply(this,arguments)})},{key:"deleteUser",value:(G=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.delete(this.baseURL+"/users/".concat(encodeURIComponent(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:"restoreUsers",value:(Q=(0,d.Z)(g().mark(function e(t){return g().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 Q.apply(this,arguments)})},{key:"reactivateUser",value:($=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/".concat(encodeURIComponent(t),"/reactivate"),tR({},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:"reactivateUsers",value:(Y=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/reactivate",tR({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 Y.apply(this,arguments)})},{key:"deactivateUser",value:(ee=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/".concat(encodeURIComponent(t),"/deactivate"),tR({},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:"deactivateUsers",value:(et=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/deactivate",tR({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 et.apply(this,arguments)})},{key:"exportUser",value:(en=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/users/".concat(encodeURIComponent(t),"/export"),tR({},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:"banUser",value:(er=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/moderation/ban",tR({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 er.apply(this,arguments)})},{key:"unbanUser",value:(es=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.delete(this.baseURL+"/moderation/ban",tR({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 es.apply(this,arguments)})},{key:"shadowBan",value:(ei=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.banUser(t,tR({shadow:!0}
1,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:"removeShadowBan",value:(ea=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.unbanUser(t,tR({shadow:!0},n));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return ea.apply(this,arguments)})},{key:"blockUser",value:(ec=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/block",tR({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:"getBlockedUsers",value:(eu=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/users/block",tR({},t?{user_id:t}:{}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return eu.apply(this,arguments)})},{key:"unBlockUser",value:(ed=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/unblock",tR({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 ed.apply(this,arguments)})},{key:"muteUser",value:(eh=(0,d.Z)(g().mark(function e(t,n){var r,s=arguments;return g().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",tR(tR({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 eh.apply(this,arguments)})},{key:"unmuteUser",value:(ep=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/moderation/unmute",tR({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 ep.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;t<this.mutedUsers.length;t+=1)if(this.mutedUsers[t].target.id===e)return!0;return!1}},{key:"flagMessage",value:(ef=(0,d.Z)(g().mark(function e(t){var n,r=arguments;return g().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",tR({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 ef.apply(this,arguments)})},{key:"flagUser",value:(ev=(0,d.Z)(g().mark(function e(t){var n,r=arguments;return g().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",tR({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:(eg=(0,d.Z)(g().mark(function e(t){var n,r=arguments;return g().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",tR({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 eg.apply(this,arguments)})},{key:"unflagUser",value:(em=(0,d.Z)(g().mark(function e(t){var n,r=arguments;return g().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",tR({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 em.apply(this,arguments)})},{key:"getCallToken",value:(ey=(0,d.Z)(g().mark(function e(t){var n,r=arguments;return g().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(encodeURIComponent(t)),tR({},n));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return ey.apply(this,arguments)})},{key:"_queryFlags",value:(eb=(0,d.Z)(g().mark(function e(){var t,n,r=arguments;return g().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",tR({filter_conditions:t},n));case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}},e,this)})),function(){return eb.apply(this,arguments)})},{key:"_queryFlagReports",value:(ew=(0,d.Z)(g().mark(function e(){var t,n,r=arguments;return g().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",tR({filter_conditions:t},n));case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}},e,this)})),function(){return ew.apply(this,arguments)})},{key:"_reviewFlagReport",value:(e_=(0,d.Z)(g().mark(function e(t,n){var r,s=arguments;return g().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(encodeURIComponent(t)),tR({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 e_.apply(this,arguments)})},{key:"unblockMessage",value:(ek=(0,d.Z)(g().mark(function e(t){var n,r=arguments;return g().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",tR({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 ek.apply(this,arguments)})},{key:"markChannelsRead",value:(ex=(0,d.Z)(g().mark(function e(){var t,n=arguments;return g().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",tR({},t));case 3:case"end":return e.stop()}},e,this)})),function(){return ex.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(encodeURIComponent(e)))}},{key:"updateCommand",value:function(e,t){return this.put(this.baseURL+"/commands/".concat(encodeURIComponent(e)),t)}},{key:"deleteCommand",value:function(e){return this.delete(this.baseURL+"/commands/".concat(encodeURIComponent(e)))}},{key:"listCommands",value:function(){return this.get(this.baseURL+"/commands")}},{key:"createChannelType",value:function(e){var t=(0,m.Z)({},{commands:["all"]},e);return this.post(this.baseURL+"/channeltypes",t)}},{key:"getChannelType",value:function(e){return this.get(this.baseURL+"/channeltypes/".concat(encodeURIComponent(e)))}},{key:"updateChannelType",value:function(e,t){return this.put(this.baseURL+"/channeltypes/".concat(encodeURIComponent(e)),t)}},{key:"deleteChannelType",value:function(e){return this.delete(this.baseURL+"/channeltypes/".concat(encodeURIComponent(e)))}},{key:"listChannelTypes",value:function(){return this.get(this.baseURL+"/channeltypes")}},{key:"translateMessage",value:(eZ=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/messages/".concat(encodeURIComponent(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 eZ.apply(this,arguments)})},{key:"translate",value:(eC=(0,d.Z)(g().mark(function e(t,n,r){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/translate",{text:t,source_language:r,de
1stination_language:n});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t,n){return eC.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 tO(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:(eS=(0,d.Z)(g().mark(function e(t,n,r){var s;return g().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,m.Z)({},t),delete s.id,["command","created_at","html","latest_reactions","own_reactions","quoted_message","reaction_counts","reply_count","type","updated_at","user","pinned_at","__html"].forEach(function(e){null!=s[e]&&delete s[e]}),null!=n&&(tO(n)?s.user_id=n:s.user={id:n.id}),Array.isArray(s.mentioned_users)&&!tO(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(encodeURIComponent(t.id)),tR({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 eS.apply(this,arguments)})},{key:"partialUpdateMessage",value:(eR=(0,d.Z)(g().mark(function e(t,n,r,s){var i;return g().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&&tO(r)&&(i={id:r}),e.next=6,this.put(this.baseURL+"/messages/".concat(encodeURIComponent(t)),tR(tR(tR({},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 eR.apply(this,arguments)})},{key:"deleteMessage",value:(eI=(0,d.Z)(g().mark(function e(t,n){var r;return g().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(encodeURIComponent(t)),r);case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}},e,this)})),function(e,t){return eI.apply(this,arguments)})},{key:"undeleteMessage",value:(eP=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/messages/".concat(encodeURIComponent(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 eP.apply(this,arguments)})},{key:"getMessage",value:(eD=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/messages/".concat(encodeURIComponent(t)),tR({},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:"queryThreads",value:(eE=(0,d.Z)(g().mark(function e(){var t,n,r,s=this,i=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=tR({limit:10,participant_limit:10,reply_limit:3,watch:!0},i.length>0&&void 0!==i[0]?i[0]:{}),n=tR({},t),t.filter&&Object.keys(t.filter).length>0&&(n.filter=t.filter),t.sort&&(Array.isArray(t.sort)?t.sort.length>0:Object.keys(t.sort).length>0)&&(n.sort=B(t.sort)),e.next=7,this.post("".concat(this.baseURL,"/threads"),n);case 7:return r=e.sent,e.abrupt("return",{threads:r.threads.map(function(e){return new e4({client:s,threadData:e})}),next:r.next});case 9:case"end":return e.stop()}},e,this)})),function(){return eE.apply(this,arguments)})},{key:"getThread",value:(eT=(0,d.Z)(g().mark(function e(t){var n,r,s,i=arguments;return g().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 messageId when calling getThread");case 3:return r=tR({participant_limit:100,reply_limit:3,watch:!0},n),e.next=6,this.get("".concat(this.baseURL,"/threads/").concat(encodeURIComponent(t)),r);case 6:return s=e.sent,e.abrupt("return",new e4({client:this,threadData:s.thread}));case 8:case"end":return e.stop()}},e,this)})),function(e){return eT.apply(this,arguments)})},{key:"partialUpdateThread",value:(eF=(0,d.Z)(g().mark(function e(t,n){var r,s;return g().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","custom"],e.t0=g().keys(tR(tR({},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 ").
1concat(s," from your set object."));case 8:e.next=4;break;case 10:return e.next=12,this.patch("".concat(this.baseURL,"/threads/").concat(encodeURIComponent(t)),n);case 12:return e.abrupt("return",e.sent);case 13:case"end":return e.stop()}},e,this)})),function(e,t){return eF.apply(this,arguments)})},{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=tR(tR({},t.headers),{},{"x-client-request-id":K()}));var s=this.options.axiosRequestConfig||{},i=s.params,a=s.headers,o=(0,b.Z)(s,tZ);return tR(tR(tR({params:tR(tR({user_id:this.userID,connection_id:this._getConnectionID(),api_key:this.key},t.params),i||{}),headers:tR(tR(tR({},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);t<n.length;t++)n[t].clean()},500))}},{key:"verifyWebhook",value:function(e,t){return!!this.secret&&function(e,t,n){var r=L.from(t,"utf8"),s=null.createHmac("sha256",r).update(e).digest("hex");try{return null.timingSafeEqual(L.from(s),L.from(n))}catch(e){return!1}}(e,this.secret,t)}},{key:"getPermission",value:function(e){return this.get("".concat(this.baseURL,"/permissions/").concat(encodeURIComponent(e)))}},{key:"createPermission",value:function(e){return this.post("".concat(this.baseURL,"/permissions"),tR({},e))}},{key:"updatePermission",value:function(e,t){return this.put("".concat(this.baseURL,"/permissions/").concat(encodeURIComponent(e)),tR({},t))}},{key:"deletePermission",value:function(e){return this.delete("".concat(this.baseURL,"/permissions/").concat(encodeURIComponent(e)))}},{key:"listPermissions",value:function(){return this.get("".concat(this.baseURL,"/permissions"))}},{key:"createRole",value:function(e){return this.post("".concat(this.baseURL,"/roles"),{name:e})}},{key:"listRoles",value:function(){return this.get("".concat(this.baseURL,"/roles"))}},{key:"deleteRole",value:function(e){return this.delete("".concat(this.baseURL,"/roles/").concat(encodeURIComponent(e)))}},{key:"sync",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return this.post("".concat(this.baseURL,"/sync"),tR({channel_cids:e,last_sync_at:t},n))}},{key:"sendUserCustomEvent",value:(eN=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post("".concat(this.baseURL,"/users/").concat(encodeURIComponent(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 eN.apply(this,arguments)})},{key:"createBlockList",value:function(e){return this.post("".concat(this.baseURL,"/blocklists"),e)}},{key:"listBlockLists",value:function(e){return this.get("".concat(this.baseURL,"/blocklists"),e)}},{key:"getBlockList",value:function(e,t){return this.get("".concat(this.baseURL,"/blocklists/").concat(encodeURIComponent(e)),t)}},{key:"updateBlockList",value:function(e,t){return this.put("".concat(this.baseURL,"/blocklists/").concat(encodeURIComponent(e)),t)}},{key:"deleteBlockList",value:function(e,t){return this.delete("".concat(this.baseURL,"/blocklists/").concat(encodeURIComponent(e)),t)}},{key:"exportChannels",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=tR({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(encodeURIComponent(e)))}},{key:"campaign",value:function(e,t){return e&&"object"===(0,y.Z)(e)?new A(this,null,e):new A(this,e,t)}},{key:"segment",value:function(e,t,n){return"string"==typeof t?new ez(this,e,t,n):new ez(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:(eH=(0,d.Z)(g().mark(function e(t,n,r){var s;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),s=tR({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 eH.apply(this,arguments)})},{key:"createUserSegment",value:(eV=(0,d.Z)(g().mark(function e(t,n){return g().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 eV.apply(this,arguments)})},{key:"createChannelSegment",value:(eW=(0,d.Z)(g().mark(function e(t,n){return g().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 eW.apply(this,arguments)})},{key:"getSegment",value:(eK=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.get(this.baseURL+"/segments/".concat(encodeURIComponent(t))));case 2:case"end":return e.stop()}},e,this)})),function(e){return eK.apply(this,arguments)})},{key:"updateSegment",value:(eG=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.put(this.baseURL+"/segments/".concat(encodeURIComponent(t)),n));case 2:case"end":return e.stop()}},e,this)})),function(e,t){return eG.apply(this,arguments)})},{key:"addSegmentTargets",value:(eQ=(0,d.Z)(g().mark(function e(t,n){var r;return g().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(encodeURIComponent(t),"/addtargets"),r));case 3:case"end":return e.stop()}},e,this)})),function(e,t){return eQ.apply(this,arguments)})},{key:"querySegmentTargets",value:(e$=(0,d.Z)(g().mark(function e(t){var n,r,s,i=arguments;return g().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(encodeURIComponent(t),"/targets/query"),tR({filter:n||{},sort:r||[]},s)));case 5:case"end":return e.stop()}},e,this)})),function(e){return e$.apply(this,arguments)})},{key:"removeSegmentTargets",value:(eX=(0,d.Z)(g().mark(function e(t,n){var r;return g().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(encodeURIComponent(t),"/deletetargets"),r));case 3:case"end":return e.stop()}},e,this)})),function(e,t){return eX.apply(this,arguments)})},{key:"querySegments",value:(eY=(0,d.Z)(g().mark(function e(t,n){var r,s=arguments;return g().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",tR({filter:t,sort:n},r)));case 3:case"end":return e.stop()}},e,this)})),function(e,t){return eY.apply(this,arguments)})},{key:"deleteSegment",value:(e0=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.delete(this.baseURL+"/segments/".concat(encodeURIComponent(t))));case 2:case"end":return e.stop()}},e,this)})),function(e){return e0.apply(this,arguments)})},{key:"segmentTargetExists",value:(e1=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.get(this.baseURL+"/segments/".concat(encodeURIComponent(t),"/target/").concat(encodeURIComponent(n))));case 2:case"end":return e.stop()}},e,this)})),function(e,t){return e1.apply(this,arguments)})},{key:"createCampaign",value:(e2=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.post(this.baseURL+"/campaigns",tR({},t)));case 2:case"end":return e.stop()}},e,this)})),function(e){return e2.apply(this,arguments)})},{key:"getCampaign",value:(e3=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.get(this.baseURL+"/campaigns/".concat(encodeURIComponent(t)),tR({},null==n?void 0:n.users)));case 2:case"end":return e.stop()}},e,this)})),function(e,t){return e3.apply(this,arguments)})},{key:"startCampaign",value:(e5=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.post(this.baseURL+"/campaigns/".concat(encodeURIComponent(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,d.Z)(g().mark(function e(t,n,r){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.next=3,this.post(this.baseURL+"/campaigns/query",tR({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:(e7=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.put(this.baseURL+"/campaigns/".concat(encodeURIComponent(t)),n));case 2:case"end":return e.stop()}},e,this)})),function(e,t){return e7.apply(this,arguments)})}
1,{key:"deleteCampaign",value:(e8=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.delete(this.baseURL+"/campaigns/".concat(encodeURIComponent(t))));case 2:case"end":return e.stop()}},e,this)})),function(e){return e8.apply(this,arguments)})},{key:"stopCampaign",value:(e9=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.post(this.baseURL+"/campaigns/".concat(encodeURIComponent(t),"/stop")));case 2:case"end":return e.stop()}},e,this)})),function(e){return e9.apply(this,arguments)})},{key:"enrichURL",value:(te=(0,d.Z)(g().mark(function e(t){return g().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:(tn=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.get("".concat(this.baseURL,"/tasks/").concat(encodeURIComponent(t))));case 1:case"end":return e.stop()}},e,this)})),function(e){return tn.apply(this,arguments)})},{key:"deleteChannels",value:(tr=(0,d.Z)(g().mark(function e(t){var n,r=arguments;return g().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",tR({cids:t},n));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return tr.apply(this,arguments)})},{key:"deleteUsers",value:(ts=(0,d.Z)(g().mark(function e(t){var n,r=arguments;return g().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",tR({user_ids:t},n));case 9:return e.abrupt("return",e.sent);case 10:case"end":return e.stop()}},e,this)})),function(e){return ts.apply(this,arguments)})},{key:"_createImportURL",value:(ti=(0,d.Z)(g().mark(function e(t){return g().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 ti.apply(this,arguments)})},{key:"_createImport",value:(to=(0,d.Z)(g().mark(function e(t){var n,r=arguments;return g().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",tR({path:t},n));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return to.apply(this,arguments)})},{key:"_getImport",value:(tc=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/imports/".concat(encodeURIComponent(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:"_listImports",value:(tu=(0,d.Z)(g().mark(function e(t){return g().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 tu.apply(this,arguments)})},{key:"upsertPushProvider",value:(tl=(0,d.Z)(g().mark(function e(t){return g().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 tl.apply(this,arguments)})}
1,{key:"deletePushProvider",value:(td=(0,d.Z)(g().mark(function e(t){var n,r;return g().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(encodeURIComponent(n),"/").concat(encodeURIComponent(r)));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return td.apply(this,arguments)})},{key:"listPushProviders",value:(th=(0,d.Z)(g().mark(function e(){return g().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 th.apply(this,arguments)})},{key:"createAbortControllerForNextRequest",value:function(){return this.nextRequestAbortController=new AbortController}},{key:"commitMessage",value:(tp=(0,d.Z)(g().mark(function e(t){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/messages/".concat(encodeURIComponent(t),"/commit"));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return tp.apply(this,arguments)})},{key:"createPoll",value:(tf=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/polls",tR(tR({},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 tf.apply(this,arguments)})},{key:"getPoll",value:(tv=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/polls/".concat(encodeURIComponent(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 tv.apply(this,arguments)})},{key:"updatePoll",value:(tm=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.put(this.baseURL+"/polls",tR(tR({},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 tm.apply(this,arguments)})},{key:"partialUpdatePoll",value:(ty=(0,d.Z)(g().mark(function e(t,n,r){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.patch(this.baseURL+"/polls/".concat(encodeURIComponent(t)),tR(tR({},n),r?{user_id:r}:{}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t,n){return ty.apply(this,arguments)})},{key:"deletePoll",value:(tb=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.delete(this.baseURL+"/polls/".concat(encodeURIComponent(t)),tR({},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 tb.apply(this,arguments)})},{key:"closePoll",value:(tw=(0,d.Z)(g().mark(function e(t,n){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.partialUpdatePoll(t,{set:{is_closed:!0}},n));case 1:case"end":return e.stop()}},e,this)})),function(e,t){return tw.apply(this,arguments)})},{key:"createPollOption",value:(t_=(0,d.Z)(g().mark(function e(t,n,r){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/polls/".concat(encodeURIComponent(t),"/options"),tR(tR({},n),r?{user_id:r}:{}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t,n){return t_.apply(this,arguments)})},{key:"getPollOption",value:(tS=(0,d.Z)(g().mark(function e(t,n,r){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/polls/".concat(encodeURIComponent(t),"/options/").concat(encodeURIComponent(n)),r?{user_id:r}:{});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t,n){return tS.apply(this,arguments)})},{key:"updatePollOption",value:(tU=(0,d.Z)(g().mark(function e(t,n,r){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.put(this.baseURL+"/polls/".concat(encodeURIComponent(t),"/options"),tR(tR({},n),r?{user_id:r}:{}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t,n){return tU.apply(this,arguments)})},{key:"deletePollOption",value:(tI=(0,d.Z)(g().mark(function e(t,n,r){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.delete(this.baseURL+"/polls/".concat(encodeURIComponent(t),"/options/").concat(encodeURIComponent(n)),r?{user_id:r}:{});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t,n){return tI.apply(this,arguments)})},{key:"castPollVote",value:(tP=(0,d.Z)(g().mark(function e(t,n,r,s){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/messages/".concat(encodeURIComponent(t),"/polls/").concat(encodeURIComponent(n),"/vote"),tR({vote:r},s?{user_id:s}:{}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t,n,r){return tP.apply(this,arguments)})},{key:"addPollAnswer",value:(tL=(0,d.Z)(g().mark(function e(t,n,r,s){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.castPollVote(t,n,{answer_text:r},s));case 1:case"end":return e.stop()}},e,this)})),function(e,t,n,r){return tL.apply(this,arguments)})},{key:"removePollVote",value:(tM=(0,d.Z)(g().mark(function e(t,n,r,s){return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.delete(this.baseURL+"/messages/".concat(encodeURIComponent(t),"/polls/").concat(encodeURIComponent(n),"/vote/").concat(encodeURIComponent(r)),tR({},s?{user_id:s}:{}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t,n,r){return tM.apply(this,arguments)})},{key:"queryPolls",value:(tD=(0,d.Z)(g().mark(function e(){var t,n,r,s,i,a=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=a.length>0&&void 0!==a[0]?a[0]:{},n=a.length>1&&void 0!==a[1]?a[1]:[],r=a.length>2&&void 0!==a[2]?a[2]:{},i=(s=a.length>3?a[3]:void 0)?"?user_id=".concat(s):"",e.next=7,this.post(this.baseURL+"/polls/query".concat(i),tR({filter:t,sort:B(n)},r));case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}},e,this)})),function(){return tD.apply(this,arguments)})},{key:"queryPollVotes",value:(tE=(0,d.Z)(g().mark(function e(t){var n,r,s,i,a,o=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=o.length>1&&void 0!==o[1]?o[1]:{},r=o.length>2&&void 0!==o[2]?o[2]:[],s=o.length>3&&void 0!==o[3]?o[3]:{},a=(i=o.length>4?o[4]:void 0)?"?user_id=".concat(i):"",e.next=7,this.post(this.baseURL+"/polls/".concat(encodeURIComponent(t),"/votes").concat(a),tR({filter:n,sort:B(r)},s));case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}},e,this)})),function(e){return tE.apply(this,arguments)})},{key:"queryPollAnswers",value:(tA=(0,d.Z)(g().mark(function e(t){var n,r,s,i,a,o=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=o.length>1&&void 0!==o[1]?o[1]:{},r=o.length>2&&void 0!==o[2]?o[2]:[],s=o.length>3&&void 0!==o[3]?o[3]:{},a=(i=o.length>4?o[4]:void 0)?"?user_id=".concat(i):"",e.next=7,this.post(this.baseURL+"/polls/".concat(encodeURIComponent(t),"/votes").concat(a),tR({filter:tR(tR({},n),{},{is_answer:!0}),sort:B(r)},s));case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}},e,this)})),function(e){return tA.apply(this,arguments)})},{key:"queryMessageHistory",value:(tT=(0,d.Z)(g().mark(function e(){var t,n,r,s=arguments;return g().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",tR({filter:t,sort:B(n)},r));case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}},e,this)})),function(){return tT.apply(this,arguments)})},{key:"updateFlags",value:(tj=(0,d.Z)(g().mark(function e(t,n){var r,s=arguments;return g().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",tR({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 tj.apply(this,arguments)})},{key:"queryDrafts",value:(tF=(0,d.Z)(g().mark(function e(){var t,n,r=arguments;return g().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=tR(tR({},t=r.length>0&&void 0!==r[0]?r[0]:{}),{},{sort:t.sort?B(t.sort):void 0}),e.next=4,this.post(this.baseURL+"/drafts/query",n);case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}},e,this)})),function(){return tF.apply(this,arguments)})}],[{key:"getInstance",value:function(e,t,n){return tq._instance||("string"==typeof t?tq._instance=new tq(e,t,n):tq._instance=new tq(e,t)),tq._instance}}]),tq}();(0,f.Z)(tI,"_instance",void 0);var tP="Allow",tL=["*"],tM=["*"],tD=function e(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:tL,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:tM,i=arguments.length>4&&void 0!==arguments[4]&&arguments[4],a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:tP;(0,h.Z)(this,e),(0,f.Z)(this,"name",void 0),(0,f.Z)(this,"action",void 0),(0,f.Z)(this,"owner",void 0),(0,f.Z)(this,"priority",void 0),(0,f.Z)(this,"resources",void 0),(0,f.Z)(this,"roles",void 0),this.name=t,this.action=a,this.owner=i,this.priority=n,this.resources=r,this.roles=s};new tD("Allow all",999,tL,tM,!1,tP),new tD("Deny all",1,tL,tM,!1,"Deny")}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.