PageSourceSearch

https://www.hagerty.com/marketplace/_next/static/chunks/477aefee-0cf39b0f0d6c4336.js

js hagerty.com collected 2026-09-24 07:57:29 UTC 228,373 bytes, 1 lines download raw bytes

1!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="e20de352-a7dd-40c6-a9c2-aef1940c2af6",e._sentryDebugIdIdentifier="sentry-dbid-e20de352-a7dd-40c6-a9c2-aef1940c2af6")}catch(e){}}();"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9207],{84989:(e,t,n)=>{n.d(t,{hx:()=>tC});var r,s,i=n(81370),a=n(80502),o=n(59524),c=n(44212),u=n(85190),l=n(43081),h=n.n(l),d=n(71165),p=n(44501),f=n(54945),v=n(8972),g=n(83323),m=n(91040),y=n(41218),b=n.n(y),w=n(40002),_=n.n(w),k=n(1584),A=n(27196),x=n(22055),C=n(61371),S=n(78187),U=n(82909).Buffer,R=n(99742);function O(e){return"string"==typeof e}var I=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},P=function(){var e,t,n,r,s,i;function l(e,t,n){(0,o.A)(this,l),(0,u.A)(this,"id",void 0),(0,u.A)(this,"data",void 0),(0,u.A)(this,"client",void 0),this.client=e,this.id=t,this.data=n}return(0,c.A)(l,[{key:"create",value:(e=(0,a.A)(h().mark(function e(){var t,n,r,s,i,a,o,c,u,l,d;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return l={id:this.id,message_template:null==(t=this.data)?void 0:t.message_template,segment_ids:null==(n=this.data)?void 0:n.segment_ids,sender_id:null==(r=this.data)?void 0:r.sender_id,sender_mode:null==(s=this.data)?void 0:s.sender_mode,channel_template:null==(i=this.data)?void 0:i.channel_template,create_channels:null==(a=this.data)?void 0:a.create_channels,description:null==(o=this.data)?void 0:o.description,name:null==(c=this.data)?void 0:c.name,user_ids:null==(u=this.data)?void 0:u.user_ids},e.next=3,this.client.createCampaign(l);case 3:return d=e.sent,this.id=d.campaign.id,this.data=d.campaign,e.abrupt("return",d);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,a.A)(h().mark(function e(t){return h().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,a.A)(h().mark(function e(t){return h().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,a.A)(h().mark(function e(){return h().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,a.A)(h().mark(function e(){return h().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,a.A)(h().mark(function e(t){return h().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)})}]),l}();function L(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 M(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};
1t%2?L(Object(n),!0).forEach(function(t){(0,u.A)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):L(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function D(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 E(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 E(e,t)}}(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 E(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 T=function(e){return new Promise(function(t){return setTimeout(t,e)})};function j(e){return e&&("[object Function]"===Object.prototype.toString.call(e)||"function"==typeof e||e instanceof Function)}var F={TOKEN_EXPIRED:40,WS_CLOSED_SUCCESS:1e3};function q(e){var t,n=[],r=D(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,d.A)(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 N(e){var t=Math.min(500+2e3*e,25e3),n=Math.min(Math.max(250,(e-1)*2e3),25e3);return Math.floor(Math.random()*(t-n)+n)}function H(e){for(var t="",n=0;n<e.length;n++)t+=e[n].toString(16).padStart(2,"0");return t}function V(){var e,t=(B(e=new Uint8Array(16)),e);return t[6]=15&t[6]|64,t[8]=191&t[8]|128,H(t.subarray(0,4))+"-"+H(t.subarray(4,6))+"-"+H(t.subarray(6,8))+"-"+H(t.subarray(8,10))+"-"+H(t.subarray(10,16))}function W(e){for(var t=Math.pow(2,8*e.byteLength/e.length),n=0;n<e.length;n++)e[n]=Math.random()*t}var B=function(){var e;return"undefined"!=typeof crypto&&void 0!==(null==(e=crypto)?void 0:e.getRandomValues)?crypto.getRandomValues.bind(crypto):"undefined"!=typeof msCrypto?msCrypto.getRandomValues.bind(msCrypto):W}();function z(e){"undefined"!=typeof window&&window.addEventListener&&(window.addEventListener("offline",e),window.addEventListener("online",e))}function J(e){"undefined"!=typeof window&&window.removeEventListener&&(window.removeEventListener("offline",e),window.removeEventListener("online",e))}var K=function(e){var t=[];for(var n in e)void 0!==e[n]&&(Array.isArray(e[n])||"object"===(0,f.A)(e[n])?t.push("".concat(n,"=").concat(encodeURIComponent(JSON.stringify(e[n])))):t.push("".concat(n,"=").concat(encodeURIComponent(e[n]))));return t.join("&")};function G(e){return M(M({},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 Q=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,h=i(t);c<=u;){var d=i(n[l=Math.round((c+u)/2)]);"ascending"===o&&h<d||"descending"===o&&h>=d?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])===h;v+=f)if(r(n[v])===p)return v}return c};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],i=s||n,a=(0,g.A)(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=Q({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 X=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,g.A)(c)),c=null,o=setTimeout(n,t);return}o=null},t)}},Y=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,f.A)(e)&&t in e)return e[t]},e);return!n.has(r)&&(n.add(r),!0)})},Z=function(e){var t=e.parentSet,n=e.requestedPageSize,r=e.returnedPage,s=e.messagePaginationOptions,i=M({},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,h=!!(null!=u&&u.created_at)&&new Date(u.created_at)<a,d=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,d&&(v=!1,m=!0);else if(h)v=!1,m=!0,d&&(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.id),_=(null==u?void 0:u.id)&&u.id===(null==(b=t.messages.slice(-1)[0])?void 0:b.id);g=w,m=_;var k=Math.floor(r.length/2),A=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!==A&&(f=k<=A,v=k>=A)}return g&&void 0!==f&&(i.hasPrev=f),m&&void 0!==v&&(i.hasNext=v),i},ee=function(e){var t=e.parentSet,n=e.requestedPageSize,r=e.returnedPage,s=e.messagePaginationOptions,i=M({},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.id),h=(null==u?void 0:u.id)===(null==(g=t.messages.slice(-1)[0])?void 0:g.id),d=l,p=h,f=Math.floor(r.length/2);if((n>t.messages.length||t.messages.length>=r.length)&&n>r.length)y=m=!1,d=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 d&&void 0!==m&&(i.hasPrev=m),p&&void 0!==y&&(i.hasNext=y),i},et=function(e){var t,n,r,s,i=e.parentSet,a=e.requestedPageSize,o=e.returnedPage,c=e.messagePaginationOptions,u=M({},i.pagination),l=[o[0],o.slice(-1)[0]],h=l[0],d=l[1],p=(null==h?void 0:h.id)&&h.id===(null==(t=i.messages[0])?void 0:t.id),f=(null==d?void 0:d.id)&&d.id===(null==(n=i.messages.slice(-1)[0])?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},en=function(e){var t,n,r;return e.parentSet.messages.length<e.returnedPage.length?(null==(r=e.logger)||r.call(e,"error","Corrupted message set state: parent set size < returned page size"),e.parentSet.pagination):null!=(t=e.messagePaginationOptions)&&t.created_at_around?Z(e):null!=(n=e.messagePaginationOptions)&&n.id_around?ee(e):et(e)},er={},es=function(){var e=(0,a.A)(h().mark(function e(t){var n,r,s,i,a,o,c,u,l;return h().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?ei(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=er[u])){e.next=13;break}return e.next=11,l;case 11:e.next=20;break;case 13:return e.prev=13,er[u]=c.watch(a),e.next=17,er[u];case 17:return e.prev=17,delete er[u],e.finish(17);case 20:return e.abrupt("return",c);case 21:case"end":return e.stop()}},e,null,[[13,,17,20]])}));return function(t){return e.apply(this,arguments)}}(),ei=function(e,t){if(t){var n=(0,g.A)(t).sort().join(",");if(n)return"".concat(e,":!members-").concat(n)}},ea=function(e){if(!e)return!1;var t=e.state.membership;return!!(null!=t&&t.pinned_at)},eo=function(e){if(!e)return!1;var t=e.state.membership;return!!(null!=t&&t.archived_at)},ec=function(e){return!!e&&"boolean"==typeof e.archived},eu=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])?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[a])?t:null},el=function(e){var t=eh({sort:e});return"number"==typeof t&&1===Math.abs(t)},eh=function(e){return eu({atIndex:0,sort:e.sort,targetKey:"pinned_at"})},ed=function(e){var t,n=e.channels,r=null,s=D(n);try{for(s.s();!(t=s.n()).done;){var i=t.value;if(!ea(i))break;"number"==typeof r?r++:r=0}}catch(e){s.e(e)}finally{s.f()}return r},ep=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=el(s),u=ea(n);if(o||c&&u)return t;var l=(0,g.A)(t);a&&l.splice(i,1);var h=null;return c&&(h=ed({channels:l})),l.splice("number"==typeof h?h+1:0,0,n),l},ef={hasNext:!1,hasPrev:!1};function ev(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function eg(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};
1t%2?ev(Object(n),!0).forEach(function(t){(0,u.A)(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}var em=function(){var e;function t(e){var n,r=this;(0,o.A)(this,t),(0,u.A)(this,"_channel",void 0),(0,u.A)(this,"watcher_count",void 0),(0,u.A)(this,"typing",void 0),(0,u.A)(this,"read",void 0),(0,u.A)(this,"pinnedMessages",void 0),(0,u.A)(this,"pending_messages",void 0),(0,u.A)(this,"threads",void 0),(0,u.A)(this,"mutedUsers",void 0),(0,u.A)(this,"watchers",void 0),(0,u.A)(this,"members",void 0),(0,u.A)(this,"unreadCount",void 0),(0,u.A)(this,"membership",void 0),(0,u.A)(this,"last_message_at",void 0),(0,u.A)(this,"isUpToDate",void 0),(0,u.A)(this,"messageSets",[]),(0,u.A)(this,"formatMessage",function(e){return G(e)}),(0,u.A)(this,"setIsUpToDate",function(e){r.isUpToDate=e}),(0,u.A)(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,u.A)(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.id)===t.id&&(e[n]=eg(eg({},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,u.A)(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.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]=eg(eg({},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||null==(n=e.state)?void 0:n.last_message_at)!=null?new Date(e.state.last_message_at):null}return(0,c.A)(t,[{key:"messages",get:function(){var e;return(null==(e=this.messageSets.find(function(e){return e.isCurrent}))?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.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.pagination)||ef}},{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,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],s=!(arguments.length>3)||void 0===arguments[3]||arguments[3],i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"current",a=this.findTargetMessageSet(e,s,i),o=a.messagesToAdd,c=a.targetMessageSetIndex,u=0;u<o.length;u+=1)if(!o[u].shadowed){var l=o[u].created_at instanceof Date,h=void 0;l?h=o[u]:((h=this.formatMessage(o[u])).user&&null!=(t=this._channel)&&t.cid&&this._channel.getClient().state.updateUserReference(h.user,this._channel.cid),r&&h.id&&this.threads[h.id]&&delete this.threads[h.id],this.last_message_at||(this.last_message_at=new Date(h.created_at.getTime())),h.created_at.getTime()>this.last_message_at.getTime()&&(this.last_message_at=new Date(h.created_at.getTime())));var d=h.parent_id;if((!d||h.show_in_channel)&&-1!==c&&(this.messageSets[c].messages=this._addToMessageList(this.messageSets[c].messages,h,n,"created_at",s)),d&&!r){var p=this.threads[d]||[];this.threads[d]=this._addToMessageList(p,h,n,"created_at",s)}}return{messageSet:this.messageSets[c]}}},{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 eg(eg({},e),{},{created_at:e.created_at.toISOString(),pinned_at:null==(t=e.pinned_at)?void 0:t.toISOString(),updated_at:null==(n=e.updated_at)?void 0:n.toISOString()})},i=function(e){var i=e.reduce(function(e,t){return t.quoted_message_id===n.id&&e.push(eg(eg({},s(t)),{},{quoted_message:r?eg(eg({},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 $(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)?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,d.A)(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:ef}]}},{key:"loadMessageIntoState",value:(e=(0,a.A)(h().mark(function e(t,n){var r,s,i,a,o,c,u=arguments;return h().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])&&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:ef}),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,g.A)(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,g.A)(i),(0,g.A)(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 ey(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 eb(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 eb(e,t)}}(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 eb(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 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]:{};t%2?ew(Object(n),!0).forEach(function(t){(0,u.A)(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,t,n,r,s,i,l,d,p,v,m,y,b,w,_,k,A,x,C,S,U,R,O,I,P,L,M,D,E,T,j,F,N,H,V,W,B,z,J,K,G,Q,$,X,Y,Z,ee,et,er,es,ea;function eo(e,t,n,r){var s,i=this;if((0,o.A)(this,eo),(0,u.A)(this,"_client",void 0),(0,u.A)(this,"type",void 0),(0,u.A)(this,"id",void 0),(0,u.A)(this,"data",void 0),(0,u.A)(this,"_data",void 0),(0,u.A)(this,"cid",void 0),(0,u.A)(this,"listeners",void 0),(0,u.A)(this,"state",void 0),(0,u.A)(this,"initialized",void 0),(0,u.A)(this,"offlineMode",void 0),(0,u.A)(this,"lastKeyStroke",void 0),(0,u.A)(this,"lastTypingEvent",void 0),(0,u.A)(this,"isTyping",void 0),(0,u.A)(this,"disconnected",void 0),(0,u.A)(this,"push_preferences",void 0),(0,u.A)(this,"create",(s=(0,a.A)(h().mark(function e(t){var n;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=e_(e_({},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,u.A)(this,"_callChannelListeners",function(e){var t=[];i.listeners.all&&t.push.apply(t,(0,g.A)(i.listeners.all)),i.listeners[e.type]&&t.push.apply(t,(0,g.A)(i.listeners[e.type]));for(var n=0;n<t.length;n++){var r=t[n];"string"!=typeof r&&r(e)}}),(0,u.A)(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=e_({},r),this.cid="".concat(t,":").concat(n),this.listeners={},this.state=new em(this),this.initialized=!1,this.offlineMode=!1,this.lastTypingEvent=null,this.isTyping=!1,this.disconnected=!1}return(0,c.A)(eo,[{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,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getClient().post(this._channelURL()+"/message",e_({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,a.A)(h().mark(function e(t){return h().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,a.A)(h().mark(function e(t){var n,r,s=arguments;return h().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=e_(e_({filter_conditions:{cid:this.cid}},n),{},{sort:n.sort?q(n.sort):void 0}),"string"!=typeof t){e.next=8;break}r.query=t,e.next=13;break;case 8:if("object"!==(0,f.A)(t)){e.next=12;break}r.message_filter_conditions=t,e.next=13;break;case 12:throw Error("Invalid type ".concat((0,f.A)(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,a.A)(h().mark(function e(t){var n,r,s,i,a,o,c=arguments;return h().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)&&n.members&&Array.isArray(this.data.members)&&(o=this.data.members),e.next=6,this.getClient().get(this.getClient().baseURL+"/members",{payload:e_({type:a,id:i,members:o,sort:q(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:"partialUpdateMember",value:(s=(0,a.A)(h().mark(function e(t,n){return h().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 s.apply(this,arguments)})},{key:"sendReaction",value:(i=(0,a.A)(h().mark(function e(t,n,r){return h().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"),e_({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 i.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:(l=(0,a.A)(h().mark(function e(){var t,n,r,s=arguments;return h().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(e_({message:n,data:t},r));case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}},e,this)})),function(){return l.apply(this,arguments)})},{key:"updatePartial",value:(d=(0,a.A)(h().mark(function e(t){var n,r,s,i;return h().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,g.A)(s.channel.own_capabilities||[]).sort().join()!==(0,g.A)(Array.isArray(null==(n=this.data)?void 0:n.own_capabilities)?null==(r=this.data)?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 d.apply(this,arguments)})},{key:"enableSlowMode",value:(p=(0,a.A)(h().mark(function e(t){var n;return h().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 p.apply(this,arguments)})},{key:"disableSlowMode",value:(v=(0,a.A)(h().mark(function e(){var t;return h().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 v.apply(this,arguments)})},{key:"delete",value:(m=(0,a.A)(h().mark(function e(){var t,n=arguments;return h().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(),e_({},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:"truncate",value:(y=(0,a.A)(h().mark(function e(){var t,n=arguments;return h().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 y.apply(this,arguments)})},{key:"acceptInvite",value:(b=(0,a.A)(h().mark(function e(){var t,n=arguments;return h().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(e_({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,a.A)(h().mark(function e(){var t,n=arguments;return h().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(e_({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:(_=(0,a.A)(h().mark(function e(t,n){var r,s=arguments;return h().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(e_({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 _.apply(this,arguments)})},{key:"addModerators",value:(k=(0,a.A)(h().mark(function e(t,n){var r,s=arguments;return h().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(e_({add_moderators:t,message:n},r));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e,t){return k.apply(this,arguments)})},{key:"assignRoles",value:(A=(0,a.A)(h().mark(function e(t,n){var r,s=arguments;return h().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(e_({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 A.apply(this,arguments)})},{key:"inviteMembers",value:(x=(0,a.A)(h().mark(function e(t,n){var r,s=arguments;return h().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(e_({invites:t,message:n},r));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e,t){return x.apply(this,arguments)})},{key:"removeMembers",value:(C=(0,a.A)(h().mark(function e(t,n){var r,s=arguments;return h().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(e_({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 C.apply(this,arguments)})},{key:"demoteModerators",value:(S=(0,a.A)(h().mark(function e(t,n){var r,s=arguments;return h().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(e_({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 S.apply(this,arguments)})},{key:"_update",value:(U=(0,a.A)(h().mark(function e(t){var n;return h().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 U.apply(this,arguments)})},{key:"mute",value:(R=(0,a.A)(h().mark(function e(){var t,n=arguments;return h().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",e_({channel_cid:this.cid},t));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(){return R.apply(this,arguments)})},{key:"unmute",value:(O=(0,a.A)(h().mark(function e(){var t,n=arguments;return h().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",e_({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:"archive",value:(I=(0,a.A)(h().mark(function e(){var t,n,r,s,i=arguments;return h().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 I.apply(this,arguments)})},{key:"unarchive",value:(P=(0,a.A)(h().mark(function e(){var t,n,r,s,i=arguments;return h().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 P.apply(this,arguments)})},{key:"pin",value:(L=(0,a.A)(h().mark(function e(){var t,n,r,s,i=arguments;return h().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 L.apply(this,arguments)})},{key:"unpin",value:(M=(0,a.A)(h().mark(function e(){var t,n,r,s,i=arguments;return h().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 M.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:(D=(0,a.A)(h().mark(function e(t,n){var r,s;return h().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(e_({type:"typing.start",parent_id:t},n||{}));case 10:case"end":return e.stop()}},e,this)})),function(e,t){return D.apply(this,arguments)})},{key:"updateAIState",value:(E=(0,a.A)(h().mark(function e(t,n){var r,s=arguments;return h().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(e_(e_({},r),{},{type:"ai_indicator.update",message_id:t,ai_state:n}));case 3:case"end":return e.stop()}},e,this)})),function(e,t){return E.apply(this,arguments)})},{key:"clearAIIndicator",value:(T=(0,a.A)(h().mark(function e(){return h().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,a.A)(h().mark(function e(){return h().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,a.A)(h().mark(function e(t,n){return h().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(e_({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())&&e.typing_events)&&(null==(t=null==(n=this.getClient().user)||null==(r=n.privacy_settings)||null==(s=r.typing_indicators)?void 0:s.enabled)||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:(N=(0,a.A)(h().mark(function e(){var t,n,r=arguments;return h().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())&&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",e_({},n));case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}},e,this)})),function(){return N.apply(this,arguments)})},{key:"markUnread",value:(H=(0,a.A)(h().mark(function e(t){var n;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this._checkInitialized(),!(!(null!=(n=this.getConfig())&&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",e_({},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&&this.stopTyping().then().catch(function(e){console.warn("failed to do ".concat("stop typing event",", ran into error: "),e)}),this.state.clean()}},{key:"watch",value:(V=(0,a.A)(h().mark(function e(t){var n,r,s;return h().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=e_(e_({},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,a.A)(h().mark(function e(){var t;return h().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:(B=(0,a.A)(h().mark(function e(t,n,r){var s,i;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return s=r?q(r):void 0,e.next=3,this.getClient().get(this.getClient().baseURL+"/messages/".concat(encodeURIComponent(t),"/replies"),e_({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 B.apply(this,arguments)})},{key:"getPinnedMessages",value:(z=(0,a.A)(h().mark(function e(t){var n,r=arguments;return h().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:e_(e_({},t),{},{sort:q(n)})});case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return z.apply(this,arguments)})},{key:"getReactions",value:function(e,t){return this.getClient().get(this.getClient().baseURL+"/messages/".concat(encodeURIComponent(e),"/reactions"),e_({},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.id)===this.getClient().userID||null!=(n=e.user)&&n.id&&this.getClient().userMuteStatus(e.user.id)||Array.isArray(null==(r=this.data)?void 0:r.own_capabilities)&&!(null!=(s=this.data)&&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)&&s.some(function(e){return e.id===t})&&n++}return n}},{key:"query",value:(J=(0,a.A)(h().mark(function e(t){var n,r,s,i,a,o,c,u,l,d,p=arguments;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return a=p.length>1&&void 0!==p[1]?p[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",e_({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=ei(this.type,c.members.map(function(e){var t;return e.user_id||(null==(t=e.user)?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=e_(e_({},l.pagination),en({parentSet:l,messagePaginationOptions:null==t?void 0:t.messages,requestedPageSize:null!=(n=null==t||null==(r=t.messages)?void 0:r.limit)?n:100,returnedPage:c.messages,logger:this.getClient().logger})),this.getClient().polls.hydratePollCache(c.messages,!0),d=(0,g.A)(c.channel.own_capabilities||[]).sort().join()!==(0,g.A)(Array.isArray(null==(s=this.data)?void 0:s.own_capabilities)?null==(i=this.data)?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 J.apply(this,arguments)})},{key:"banUser",value:(K=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this._checkInitialized(),e.next=3,this.getClient().banUser(t,e_(e_({},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 K.apply(this,arguments)})},{key:"hide",value:(G=(0,a.A)(h().mark(function e(){var t,n,r=arguments;return h().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 G.apply(this,arguments)})},{key:"show",value:(Q=(0,a.A)(h().mark(function e(){var t,n=arguments;return h().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 Q.apply(this,arguments)})},{key:"unbanUser",value:($=(0,a.A)(h().mark(function e(t){return h().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 $.apply(this,arguments)})},{key:"shadowBan",value:(X=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this._checkInitialized(),e.next=3,this.getClient().shadowBan(t,e_(e_({},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 X.apply(this,arguments)})},{key:"removeShadowBan",value:(Y=(0,a.A)(h().mark(function e(t){return h().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 Y.apply(this,arguments)})},{key:"createCall",value:(Z=(0,a.A)(h().mark(function e(t){return h().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 Z.apply(this,arguments)})},{key:"vote",value:(ee=(0,a.A)(h().mark(function e(t,n,r){return h().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 ee.apply(this,arguments)})},{key:"removeVote",value:(et=(0,a.A)(h().mark(function e(t,n,r){return h().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 et.apply(this,arguments)})},{key:"createDraft",value:(er=(0,a.A)(h().mark(function e(t){return h().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 er.apply(this,arguments)})},{key:"deleteDraft",value:(es=(0,a.A)(h().mark(function e(){var t,n=arguments;return h().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 es.apply(this,arguments)})},{key:"getDraft",value:(ea=(0,a.A)(h().mark(function e(){var t,n=arguments;return h().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,l=this.state;switch(e.type){case"typing.start":null!=(h=e.user)&&h.id&&(l.typing[e.user.id]=e);break;case"typing.stop":null!=(d=e.user)&&d.id&&delete l.typing[e.user.id];break;case"message.read":null!=(p=e.user)&&p.id&&e.created_at&&(l.read[e.user.id]={last_read:new Date(e.created_at),last_read_message_id:e.last_read_message_id,user:e.user,unread_messages:0},(null==(S=e.user)?void 0:S.id)===(null==(U=this.getClient().user)?void 0:U.id)&&(l.unreadCount=0));break;case"user.watching.start":case"user.updated":null!=(f=e.user)&&f.id&&(l.watchers[e.user.id]=e.user);break;case"user.watching.stop":null!=(v=e.user)&&v.id&&delete l.watchers[e.user.id];break;case"message.deleted":e.message&&(this._extendEventWithOwnReactions(e),e.hard_delete?l.removeMessage(e.message):l.addMessageSorted(e.message,!1,!1),l.removeQuotedMessageReferences(e.message),e.message.pinned&&l.removePinnedMessage(e.message));break;case"message.new":if(e.message){var h,d,p,f,v,g,m,y,b,w,_,k,A,x,C,S,U,R,O,I,P=(null==(R=e.user)?void 0:R.id)===(null==(O=this.getClient().user)?void 0:O.id),L=e.message.parent_id&&!e.message.show_in_channel;if((this.state.isUpToDate||L)&&l.addMessageSorted(e.message,P),e.message.pinned&&l.addPinnedMessage(e.message),P||L)break;if(null!=(I=e.user)&&I.id)for(var M in l.read)M===e.user.id?l.read[e.user.id]={last_read:new Date(e.created_at),user:e.user,unread_messages:0}:l.read[M].unread_messages+=1;this._countMessageAsUnread(e.message)&&(l.unreadCount=l.unreadCount+1)}break;case"message.updated":case"message.undeleted":e.message&&(this._extendEventWithOwnReactions(e),l.addMessageSorted(e.message,!1,!1),l._updateQuotedMessageReferences({message:e.message}),e.message.pinned?l.addPinnedMessage(e.message):l.removePinnedMessage(e.message));break;case"channel.truncated":if(null!=(g=e.channel)&&g.truncated_at){var D=+new Date(e.channel.truncated_at);
1l.messageSets.forEach(function(e,t){e.messages.forEach(function(e){var n=e.created_at,r=e.id;D>+n&&l.removeMessage({id:r,messageSetIndex:t})})}),l.pinnedMessages.forEach(function(e){var t=e.id;D>+e.created_at&&l.removePinnedMessage({id:t})})}else l.clearMessages();l.unreadCount=0,e.message&&(l.addMessageSorted(e.message),e.message.pinned&&l.addPinnedMessage(e.message));break;case"member.added":case"member.updated":null!=(m=e.member)&&m.user&&(l.members=e_(e_({},l.members),{},(0,u.A)({},e.member.user.id,e.member))),"string"==typeof(null==(y=l.membership.user)?void 0:y.id)&&"string"==typeof(null==(b=e.member)||null==(w=b.user)?void 0:w.id)&&e.member.user.id===l.membership.user.id&&(l.membership=e.member);break;case"member.removed":if(null!=(_=e.user)&&_.id){var E=e_({},l.members);delete E[e.user.id],l.members=E}break;case"notification.mark_unread":if(!((null==(T=e.user)?void 0:T.id)===(null==(j=this.getClient().user)?void 0:j.id)&&e.user))break;var T,j,F,q=null!=(F=e.unread_messages)?F:0;l.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:q},l.unreadCount=q;break;case"channel.updated":e.channel&&((null==(t=e.channel)?void 0:t.frozen)!==void 0&&e.channel.frozen!==(null==(n=this.data)?void 0:n.frozen)&&this.query({state:!1,messages:{limit:0},watchers:{limit:0}}),this.data=e_(e_({},e.channel),{},{hidden:null!=(r=null==(s=e.channel)?void 0:s.hidden)?r:null==(i=this.data)?void 0:i.hidden,own_capabilities:null!=(a=null==(o=e.channel)?void 0:o.own_capabilities)?a:null==(c=this.data)?void 0:c.own_capabilities}));break;case"reaction.new":e.message&&e.reaction&&(e.message=l.addReaction(e.reaction,e.message));break;case"reaction.deleted":e.reaction&&(e.message=l.removeReaction(e.reaction,e.message));break;case"reaction.updated":e.reaction&&(e.message=l.addReaction(e.reaction,e.message,!0));break;case"channel.hidden":this.data=e_(e_({},this.data),{},{hidden:!0}),e.clear_history&&l.clearMessages();break;case"channel.visible":this.data=e_(e_({},this.data),{},{hidden:!1});break;case"user.banned":if(!(null!=(k=e.user)&&k.id))break;l.members[e.user.id]=e_(e_({},l.members[e.user.id]||{}),{},{shadow_banned:!!e.shadow,banned:!e.shadow,user:e_(e_({},(null==(A=l.members[e.user.id])?void 0:A.user)||{}),e.user)});break;case"user.unbanned":if(!(null!=(x=e.user)&&x.id))break;l.members[e.user.id]=e_(e_({},l.members[e.user.id]||{}),{},{shadow_banned:!1,banned:!1,user:e_(e_({},(null==(C=l.members[e.user.id])?void 0:C.user)||{}),e.user)})}void 0!==e.watcher_count&&(this.state.watcher_count=e.watcher_count)}},{key:"_checkInitialized",value:function(){if(!this.initialized&&!this.offlineMode&&!this.getClient()._isUsingServerAuth())throw Error("Channel ".concat(this.cid," hasn't been initialized yet. Make sure to call .watch() and wait for it to resolve"))}},{key:"_initializeState",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"latest",n=this.getClient(),r=n.state,s=n.user,i=n.userID;if(e.members){this._hydrateMembers({members:e.members});var a,o=ey(e.members);try{for(o.s();!(a=o.n()).done;){var c=a.value;c.user&&r.updateUserReference(c.user,this.cid)}}catch(e){o.e(e)}finally{o.f()}}this.state.membership=e.membership||{};var u=e.messages||[];this.state.messages||this.state.initMessages();var l=this.state.addMessagesSorted(u,!1,!0,!0,t).messageSet;if(this.state.pinnedMessages||(this.state.pinnedMessages=[]),this.state.addPinnedMessages(e.pinned_messages||[]),e.pending_messages&&(this.state.pending_messages=e.pending_messages),void 0!==e.watcher_count&&(this.state.watcher_count=e.watcher_count),e.watchers){var h,d=ey(e.watchers);try{for(d.s();!(h=d.n()).done;){var p=h.value;p&&(r.updateUserReference(p,this.cid),this.state.watchers[p.id]=p)}}catch(e){d.e(e)}finally{d.f()}}if(null!=i){var f=this.state.last_message_at||new Date;s&&(this.state.read[s.id]={user:s,last_read:f,unread_messages:0})}if(e.read){var v,g=ey(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)?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=e_(e_({},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)}}]),eo}();function eA(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 ex=function(){function e(t){var n=t.client;(0,o.A)(this,e),(0,u.A)(this,"client",void 0),(0,u.A)(this,"users",void 0),(0,u.A)(this,"userChannelReferences",void 0),this.client=n,this.users={},this.userChannelReferences={}}return(0,c.A)(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 eA(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 eA(e,t)}}(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 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,u.A)(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 e(){(0,o.A)(this,e),(0,u.A)(this,"connectionStartTimestamp",void 0),(0,u.A)(this,"wsConsecutiveFailures",void 0),(0,u.A)(this,"wsTotalFailures",void 0),(0,u.A)(this,"instanceClientId",void 0),this.connectionStartTimestamp=null,this.wsTotalFailures=0,this.wsConsecutiveFailures=0,this.instanceClientId=V()},eR=function(){var e=(0,a.A)(h().mark(function e(t,n){var r,s;return h().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,m.A.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,T((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]])}));return function(t,n){return e.apply(this,arguments)}}();function eO(e){var t,n,r,s=e.client;return{ready_state:null==(t=e.ws)?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.onLine:null,user_agent:"undefined"!=typeof navigator?null==(r=navigator)?void 0:r.userAgent:null,instance_client_id:s.insightMetrics.instanceClientId}}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}var eP=function(){var e,t,n,r;function s(e){var t=this,n=e.client;(0,o.A)(this,s),(0,u.A)(this,"client",void 0),(0,u.A)(this,"connectionID",void 0),(0,u.A)(this,"connectionOpen",void 0),(0,u.A)(this,"consecutiveFailures",void 0),(0,u.A)(this,"pingInterval",void 0),(0,u.A)(this,"healthCheckTimeoutRef",void 0),(0,u.A)(this,"isConnecting",void 0),(0,u.A)(this,"isDisconnected",void 0),(0,u.A)(this,"isHealthy",void 0),(0,u.A)(this,"isResolved",void 0),(0,u.A)(this,"lastEvent",void 0),(0,u.A)(this,"connectionCheckTimeout",void 0),(0,u.A)(this,"connectionCheckTimeoutRef",void 0),(0,u.A)(this,"rejectPromise",void 0),(0,u.A)(this,"requestID",void 0),(0,u.A)(this,"resolvePromise",void 0),(0,u.A)(this,"totalFailures",void 0),(0,u.A)(this,"ws",void 0),(0,u.A)(this,"wsID",void 0),(0,u.A)(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,u.A)(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,u.A)(this,"onopen",function(e){t.wsID===e&&t._log("onopen() - onopen callback",{wsID:e})}),(0,u.A)(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)||s.call(t,t._errorFromWSEvent(i,!1));return}null==(r=t.resolvePromise)||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,u.A)(this,"onclose",function(e,n){if(t.wsID===e)if(t._log("onclose() - onclose callback - "+n.code,{event:n,wsID:e}),n.code===F.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)||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)||r.call(t,t._errorFromWSEvent(n)),t._log("onclose() - WS connection closed. Calling reconnect ...",{event:n}),t._reconnect()}),(0,u.A)(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)||r.call(t,t._errorFromWSEvent(n)),t._log("onerror() - WS connection resulted into error",{event:n}),t._reconnect())}),(0,u.A)(this,"_setHealth",function(e){if(e!==t.isHealthy){if(t.isHealthy=e,t.isHealthy)return void t.client.dispatchEvent({type:"connection.changed",online:t.isHealthy});setTimeout(function(){t.isHealthy||t.client.dispatchEvent({type:"connection.changed",online:t.isHealthy})},5e3)}}),(0,u.A)(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,u.A)(this,"_setupConnectionPromise",function(){t.isResolved=!1,t.connectionOpen=new Promise(function(e,n){t.resolvePromise=e,t.rejectPromise=n})}),(0,u.A)(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)||e.send(JSON.stringify(n))}catch(e){}},t.pingInterval)}),(0,u.A)(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,z(this.onlineStatusChanged)}return(0,c.A)(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?eI(Object(n),!0).forEach(function(t){(0,u.A)(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}({tags:["connection"]},t))}},{key:"setClient",value:function(e){this.client=e}},{key:"connect",value:(e=(0,a.A)(h().mark(function e(){var t,n,r=arguments;return h().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===F.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,a.A)(h().mark(function e(){var t,n=this,r=arguments;return h().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,a.A)(h().mark(function e(){var r,s;return h().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,T(r);case 15:s+=r,e.next=2;break;case 18:case"end":return e.stop()}},e,null,[[3,9]])}))(),(0,a.A)(h().mark(function e(){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,T(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),J(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(F.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,a.A)(h().mark(function e(){var t,n,r,s;return h().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=V(),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(_())(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&&(eR("ws_success_after_failure",eO(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=eS(eS({},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)),eO(this)),null==eR||eR("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,a.A)(h().mark(function e(){var t,n,r=arguments;return h().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=N(this.consecutiveFailures)),e.next=9,T(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===F.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)||e.removeAllListeners(),this===null||void 0===this||null==(t=this.ws)||t.close()}catch(e){}}}]),s}();function eL(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 eM(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?eL(Object(n),!0).forEach(function(t){(0,u.A)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):eL(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 eD(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=(0,p.A)({algorithm:"HS256",noTimestamp:!0},t);return null.sign({server:!0},e,n)}var eE=function e(t){var n,r=this;(0,o.A)(this,e),(0,u.A)(this,"loadTokenPromise",void 0),(0,u.A)(this,"type",void 0),(0,u.A)(this,"secret",void 0),(0,u.A)(this,"token",void 0),(0,u.A)(this,"tokenProvider",void 0),(0,u.A)(this,"user",void 0),(0,u.A)(this,"setTokenOrProvider",(n=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r.validateToken(t,n),r.user=n,j(t)&&(r.tokenProvider=t,r.type="provider"),"string"==typeof t&&(r.token=t,r.type="static"),!t&&r.user&&r.secret&&(r.token=eM(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,u.A)(this,"reset",function(){r.token=void 0,r.tokenProvider=void 0,r.type="static",r.user=void 0,r.loadTokenPromise=null}),(0,u.A)(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&&!j(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(I(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,u.A)(this,"tokenReady",function(){return r.loadTokenPromise}),(0,u.A)(this,"loadToken",function(){var e;return r.loadTokenPromise=new Promise((e=(0,a.A)(h().mark(function e(t,n){return h().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,u.A)(this,"getToken",function(){if(r.token||r.user&&r.user.anon&&!r.token)return r.token;if(r.secret)return eD(r.secret);throw Error("Both secret and user tokens are not set. Either client.connectUser wasn't called or client.disconnect was called")}),(0,u.A)(this,"isStatic",function(){return"static"===r.type}),this.loadTokenPromise=null,t&&(this.secret=t),this.type="static",this.secret&&(this.token=eD(this.secret))},eT={"-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 ej(e){if(!e.code)return!1;var t=eT["".concat(e.code)];return!!t&&t.retryable}function eF(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 eq(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?eF(Object(n),!0).forEach(function(t){(0,u.A)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):eF(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}!function(e){e.Closed="CLOSED",e.Connected="CONNECTED",e.Connecting="CONNECTING",e.Disconnected="DISCONNECTED",e.Init="INIT"}(r||(r={}));var eN=function(){function e(t){var n,s=this,i=t.client;(0,o.A)(this,e),(0,u.A)(this,"client",void 0),(0,u.A)(this,"state",void 0),(0,u.A)(this,"consecutiveFailures",void 0),(0,u.A)(this,"connectionID",void 0),(0,u.A)(this,"cancelToken",void 0),(0,u.A)(this,"_onlineStatusChanged",function(e){if(s._log("_onlineStatusChanged() - ".concat(e.type)),"offline"===e.type){var t;s._setState(r.Closed),null==(t=s.cancelToken)||t.cancel("disconnect() is called"),s.cancelToken=void 0;return}"online"===e.type&&s.state===r.Closed&&s.connect(!0)}),(0,u.A)(this,"_req",(n=(0,a.A)(h().mark(function e(t,n,r){var i,a;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return s.cancelToken||t.close||(s.cancelToken=m.A.CancelToken.source()),e.prev=1,e.next=4,s.client.doAxiosRequest("get",s.client.baseURL.replace(":3030",":8900")+"/longpoll",void 0,{config:eq(eq({},n),{},{cancelToken:null==(i=s.cancelToken)?void 0:i.token}),params:t});case 4:return a=e.sent,s.consecutiveFailures=0,e.abrupt("return",a);case 9:if(e.prev=9,e.t0=e.catch(1),s.consecutiveFailures+=1,!(r&&ej(e.t0))){e.next=17;break}return s._log("_req() - Retryable error, retrying request"),e.next=16,T(N(s.consecutiveFailures));case 16:return e.abrupt("return",s._req(t,n,r));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,u.A)(this,"_poll",(0,a.A)(h().mark(function e(){var t,n,i;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(s.state!==r.Connected){e.next=25;break}return e.prev=1,e.next=4,s._req({},{timeout:3e4},!0);case 4:if(null!=(t=(n=e.sent).events)&&t.length)for(i=0;i<n.events.length;i++)s.client.dispatchEvent(n.events[i]);e.next=23;break;case 8:if(e.prev=8,e.t0=e.catch(1),!m.A.isCancel(e.t0)){e.next=13;break}return s._log("_poll() - axios canceled request"),e.abrupt("return");case 13:if(46!==e.t0.code){e.next=18;break}return s._log("_poll() - ConnectionID error, connecting without ID..."),s._setState(r.Disconnected),s.connect(!0),e.abrupt("return");case 18:if(!(void 0!==e.t0.code&&!ej(e.t0))){e.next=21;break}return s._setState(r.Closed),e.abrupt("return");case 21:return e.next=23,T(N(s.consecutiveFailures));case 23:e.next=0;break;case 25:case"end":return e.stop()}},e,null,[[1,8]])}))),(0,u.A)(this,"connect",(0,a.A)(h().mark(function e(){var t,n,i=arguments;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=i.length>0&&void 0!==i[0]&&i[0],s.state!==r.Connecting){e.next=4;break}return s._log("connect() - connecting already in progress",{reconnect:t},"warn"),e.abrupt("return");case 4:if(s.state!==r.Connected){e.next=7;break}return s._log("connect() - already connected and polling",{reconnect:t},"warn"),e.abrupt("return");
1case 7:return s._setState(r.Connecting),s.connectionID=void 0,e.prev=9,e.next=12,s._req({json:s.client._buildWSPayload()},{timeout:8e3},t);case 12:return n=e.sent.event,s._setState(r.Connected),s.connectionID=n.connection_id,s.client.dispatchEvent(n),s._poll(),t&&s.client.recoverState(),e.abrupt("return",n);case 22:throw e.prev=22,e.t0=e.catch(9),s._setState(r.Closed),e.t0;case 26:case"end":return e.stop()}},e,null,[[9,22]])}))),(0,u.A)(this,"isHealthy",function(){return!!s.connectionID&&s.state===r.Connected}),(0,u.A)(this,"disconnect",(0,a.A)(h().mark(function e(){var t,n,i,a=arguments;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=a.length>0&&void 0!==a[0]?a[0]:2e3,J(s._onlineStatusChanged),s._setState(r.Disconnected),null==(t=s.cancelToken)||t.cancel("disconnect() is called"),s.cancelToken=void 0,i=s.connectionID,s.connectionID=void 0,e.prev=7,e.next=10,s._req({close:!0,connection_id:i},{timeout:n},!1);case 10:s._log("disconnect() - Closed connectionID"),e.next=16;break;case 13:e.prev=13,e.t0=e.catch(7),s._log("disconnect() - Failed",{err:e.t0},"error");case 16:case"end":return e.stop()}},e,null,[[7,13]])}))),this.client=i,this.state=r.Init,this.consecutiveFailures=0,z(this._onlineStatusChanged)}return(0,c.A)(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,eq({tags:["connection_fallback","connection"]},t))}},{key:"_setState",value:function(e){this._log("_setState() - ".concat(e)),this.state===r.Connecting&&e===r.Connected&&this.client.dispatchEvent({type:"connection.changed",online:!0}),(e===r.Closed||e===r.Disconnected)&&this.client.dispatchEvent({type:"connection.changed",online:!1}),this.state=e}}]),e}(),eH=function(){var e,t,n,r,s,i,l,d;function p(e,t,n,r){(0,o.A)(this,p),(0,u.A)(this,"type",void 0),(0,u.A)(this,"id",void 0),(0,u.A)(this,"client",void 0),(0,u.A)(this,"data",void 0),this.client=e,this.type=t,this.id=n,this.data=r}return(0,c.A)(p,[{key:"create",value:(e=(0,a.A)(h().mark(function e(){var t,n,r,s,i,a;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return a={name:null==(t=this.data)?void 0:t.name,filter:null==(n=this.data)?void 0:n.filter,description:null==(r=this.data)?void 0:r.description,all_sender_channels:null==(s=this.data)?void 0:s.all_sender_channels,all_users:null==(i=this.data)?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,a.A)(h().mark(function e(){return h().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,a.A)(h().mark(function e(t){return h().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,a.A)(h().mark(function e(t){return h().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,a.A)(h().mark(function e(t){return h().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,a.A)(h().mark(function e(){return h().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:(l=(0,a.A)(h().mark(function e(t){return h().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 l.apply(this,arguments)})},{key:"queryTargets",value:(d=(0,a.A)(h().mark(function e(){var t,n,r,s=arguments;return h().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 d.apply(this,arguments)})}]),p}(),eV=function(e){(0,A.A)(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,C.A)(r);return e=t?Reflect.construct(n,arguments,(0,C.A)(this).constructor):n.apply(this,arguments),(0,x.A)(this,e)});function r(){var e;(0,o.A)(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,u.A)((0,k.A)(e),"code",void 0),(0,u.A)((0,k.A)(e),"response",void 0),(0,u.A)((0,k.A)(e),"status",void 0),e}return r}((0,S.A)(Error));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 eB(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?eW(Object(n),!0).forEach(function(t){(0,u.A)(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}!function(e){e.anonymous="anonymous",e.public="public"}(s||(s={}));var ez=function(e){return"function"==typeof e},eJ=function e(t){var n=this;(0,o.A)(this,e),this.value=t,(0,u.A)(this,"handlerSet",new Set),(0,u.A)(this,"next",function(e){var t=ez(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,u.A)(this,"partialNext",function(e){return n.next(function(t){return eB(eB({},t),e)})}),(0,u.A)(this,"getLatestValue",function(){return n.value}),(0,u.A)(this,"subscribe",function(e){return e(n.value,void 0),n.handlerSet.add(e),function(){n.handlerSet.delete(e)}}),(0,u.A)(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,u.A)(eJ,"logCount",5);var eK=["limit","sort"];function eG(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 eQ(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?eG(Object(n),!0).forEach(function(t){(0,u.A)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):eG(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var e$=[{created_at:-1}],eX={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},eY=function(e){var t={};for(var n in e)eX[n]||(t[n]=e[n]);return t},eZ=function(){function e(t){var n,r,s,i=this,c=t.client,l=t.threadData;(0,o.A)(this,e),(0,u.A)(this,"state",void 0),(0,u.A)(this,"id",void 0),(0,u.A)(this,"client",void 0),(0,u.A)(this,"unsubscribeFunctions",new Set),(0,u.A)(this,"failedRepliesMap",new Map),(0,u.A)(this,"activate",function(){i.state.partialNext({active:!0})}),(0,u.A)(this,"deactivate",function(){i.state.partialNext({active:!1})}),(0,u.A)(this,"reload",(0,a.A)(h().mark(function e(){var t;return h().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,u.A)(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,h=Array.from(i.failedRepliesMap.values());i.state.partialNext({read:n,replyCount:r,replies:h.length?s.concat(h):s,parentMessage:a,participants:o,createdAt:c,deletedAt:u,updatedAt:l,isStateStale:!1})}}),(0,u.A)(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,u.A)(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:eY(t)})}}).unsubscribe}),(0,u.A)(this,"subscribeMarkActiveThreadRead",function(){return i.state.subscribeWithSelector(function(e){return{active:e.active,unreadMessageCount:e2(i.client.userID)(e)}},function(e){var t=e.active,n=e.unreadMessageCount;t&&n&&i.throttledMarkAsRead()})}),(0,u.A)(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,u.A)(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.id)&&(null==(n=e.channel)?void 0:n.cid)===r.cid&&i.state.partialNext({isStateStale:!0})}).unsubscribe}),(0,u.A)(this,"subscribeNewReplies",function(){return i.client.on("message.new",function(e){if(i.client.userID&&(null==(h=e.message)?void 0:h.parent_id)===i.id){var t=(null==(d=e.message.user)?void 0:d.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 h,d,p,f=l;u===(null==(p=e.user)?void 0:p.id)?f=eQ(eQ({},f),{},{lastReadAt:e.created_at?new Date(e.created_at):new Date,user:e.user,unreadMessageCount:0}):r&&u===i.client.userID||(f=eQ(eQ({},f),{},{unreadMessageCount:l.unreadMessageCount+1})),a[u]=f}}i.state.partialNext({read:a})}}).unsubscribe}),(0,u.A)(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 eQ(eQ({},s),{},{read:eQ(eQ({},s.read),{},(0,u.A)({},t,{lastReadAt:new Date(n),user:r,lastReadMessageId:e.last_read_message_id,unreadMessageCount:0}))})})}}).unsubscribe}),(0,u.A)(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,u.A)(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,u.A)(this,"unregisterSubscriptions",function(){i.unsubscribeFunctions.forEach(function(e){return e()}),i.unsubscribeFunctions.clear()}),(0,u.A)(this,"deleteReplyLocally",function(e){var t,n=e.message,r=i.state.getLatestValue().replies,s=Q({needle:G(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.id)===n.id){var a=(0,g.A)(r);a.splice(s,1),i.state.partialNext({replies:a})}}),(0,u.A)(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=G(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 eQ(eQ({},e),{},{replies:$(e.replies,s,r)})})}),(0,u.A)(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=G(t);return eQ(eQ({},e),{},{deletedAt:r.deleted_at,parentMessage:r,replyCount:null!=(n=t.reply_count)?n:e.replyCount})})}),(0,u.A)(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,u.A)(this,"markAsRead",(0,a.A)(h().mark(function e(){var t,n,r=arguments;return h().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,u.A)(this,"throttledMarkAsRead",X(function(){return i.markAsRead()},1e3,{trailing:!0})),(0,u.A)(this,"queryReplies",function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.limit,n=e.sort,r=(0,v.A)(e,eK);return i.channel.getReplies(i.id,eQ({limit:void 0===t?50:t},r),void 0===n?e$:n)}),(0,u.A)(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,u.A)(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,u.A)(this,"loadPage",(n=(0,a.A)(h().mark(function e(t){var n,r,s,a,o,c,l,p,f,v,m,y,b;return h().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,d.A)(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 l=(0,u.A)({},t>0?"id_gt":"id_lt",n[o]),p=Math.abs(t),i.state.partialNext({pagination:eQ(eQ({},n),{},(0,u.A)({},a,!0))}),e.prev=7,e.next=10,i.queryReplies(eQ(eQ({},l),{},{limit:p}));case 10:b=null!=(f=null==(v=(y=(m=e.sent).messages.map(G)).at(t>0?-1:0))?void 0:v.id)?f:null,i.state.next(function(e){var t,n,r=e.replies;return y.length>0&&(n=r=(0,g.A)(e.replies))[c].apply(n,(0,g.A)(y)),eQ(eQ({},e),{},{replies:r,pagination:eQ(eQ({},e.pagination),{},(t={},(0,u.A)(t,o,m.messages.length<p?null:b),(0,u.A)(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 eQ(eQ({},e),{},{pagination:eQ(eQ({},e.pagination),{},(0,u.A)({},a,!1))})});case 20:case"end":return e.stop()}},e,null,[[7,16]])})),function(e){return n.apply(this,arguments)}));var p=c.channel(l.channel.type,l.channel.id,{name:l.channel.name});p._hydrateMembers({members:null!=(r=l.channel.members)?r:[],overrideCurrentState:!1});var f=c.userID?[{user:{id:c.userID},unread_messages:0,last_read:new Date().toISOString()}]:[];this.state=new eJ({active:!1,isLoading:!1,isStateStale:!1,channel:p,createdAt:new Date(l.created_at),deletedAt:l.deleted_at?new Date(l.deleted_at):null,pagination:e1(l),parentMessage:G(l.parent_message),participants:l.thread_participants,read:e0(l.read&&0!==l.read.length?l.read:f),replies:l.latest_replies.map(G),replyCount:null!=(s=l.reply_count)?s:0,updatedAt:l.updated_at?new Date(l.updated_at):null,title:l.title,custom:eY(l)}),this.id=l.parent_message_id,this.client=c}return(0,c.A)(e,[{key:"channel",get:function(){return this.state.getLatestValue().channel}},{key:"hasStaleState",get:function(){return this.state.getLatestValue().isStateStale}},{key:"ownUnreadCount",get:function(){return e2(this.client.userID)(this.state.getLatestValue())}}]),e}(),e0=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)?n:0,lastReadAt:new Date(t.last_read)},e},{})},e1=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.id)?t:null,isLoadingNext:!1,isLoadingPrev:!1}},e2=function(e){return function(t){var n;return e&&(null==(n=t.read[e])?void 0:n.unreadMessageCount)||0}};function e3(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 e4(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?e3(Object(n),!0).forEach(function(t){(0,u.A)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):e3(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var e5={user:"stream:user",message:"stream:chat:v1:message",userprofile:"stream:v1:u
1ser_profile"},e6=function(){var e,t,n,r,s,i,l,d,p,f,v,g,m,y,b,w;function _(e){(0,o.A)(this,_),(0,u.A)(this,"client",void 0),this.client=e}return(0,c.A)(_,[{key:"flagUser",value:(e=(0,a.A)(h().mark(function e(t,n){var r,s=arguments;return h().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(e5.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,a.A)(h().mark(function e(t,n){var r,s=arguments;return h().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(e5.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,a.A)(h().mark(function e(t,n,r,s){var i,a=arguments;return h().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",e4({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,a.A)(h().mark(function e(t){var n,r=arguments;return h().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",e4({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,a.A)(h().mark(function e(t,n){return h().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",e4({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,a.A)(h().mark(function e(t){var n,r=arguments;return h().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",e4({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:(l=(0,a.A)(h().mark(function e(){var t,n,r,s=arguments;return h().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",e4({filter:t,sort:q(n)},r));case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}},e,this)})),function(){return l.apply(this,arguments)})},{key:"upsertConfig",value:(d=(0,a.A)(h().mark(function e(t){return h().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 d.apply(this,arguments)})},{key:"getConfig",value:(p=(0,a.A)(h().mark(function e(t,n){return h().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 p.apply(this,arguments)})},{key:"deleteConfig",value:(f=(0,a.A)(h().mark(function e(t,n){return h().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 f.apply(this,arguments)})},{key:"queryConfigs",value:(v=(0,a.A)(h().mark(function e(t,n){var r,s=arguments;return h().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",e4({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 v.apply(this,arguments)})},{key:"submitAction",value:(g=(0,a.A)(h().mark(function e(t,n){var r,s=arguments;return h().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",e4({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 g.apply(this,arguments)})},{key:"check",value:(m=(0,a.A)(h().mark(function e(t,n,r,s,i,a){return h().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,a.A)(h().mark(function e(t,n){var r;return h().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(e5.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,a.A)(h().mark(function e(t,n,r,s,i){return h().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,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.addCustomFlags(e5.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 e7(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 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,u.A)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):e8(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var te={active:!1,isThreadOrderStale:!1,threads:[],unreadThreadCount:0,unseenThreadIds:[],lastConnectionDropAt:null,pagination:{isLoading:!1,isLoadingNext:!1,nextCursor:null},ready:!1},tt=function(){function e(t){var n=this,r=t.client;(0,o.A)(this,e),(0,u.A)(this,"state",void 0),(0,u.A)(this,"client",void 0),(0,u.A)(this,"unsubscribeFunctions",new Set),(0,u.A)(this,"threadsByIdGetterCache",void 0),(0,u.A)(this,"resetState",function(){n.state.next(te)}),(0,u.A)(this,"activate",function(){n.state.partialNext({active:!0})}),(0,u.A)(this,"deactivate",function(){n.state.partialNext({active:!1})}),(0,u.A)(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,u.A)(this,"subscribeUnreadThreadsCountChange",function(){var e,t=(null!=(e=n.client.user)?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)?t:e).unread_threads;"number"==typeof r&&n.state.partialNext({unreadThreadCount:r})}).unsubscribe});return function(){return r.forEach(function(e){return e()})}}),(0,u.A)(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,u.A)(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,u.A)(this,"subscribeReloadOnActivation",function(){return n.state.subscribeWithSelector(function(e){return{active:e.active}},function(e){e.active&&n.reload()})}),(0,u.A)(this,"subscribeNewReplies",function(){return n.client.on("notification.thread_message_new",function(e){var t,r=null==(t=e.message)?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,u.A)(this,"subscribeRecoverAfterConnectionDrop",function(){var e=n.client.on("connection.changed",function(e){!1===e.online&&n.state.next(function(e){return e.lastConnectionDropAt?e:e9(e9({},e),{},{lastConnectionDropAt:new Date})})}).unsubscribe,t=X(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,u.A)(this,"unregisterSubscriptions",function(){n.state.getLatestValue().threads.forEach(function(e){return e.unregisterSubscriptions()}),n.unsubscribeFunctions.forEach(function(e){return e()}),n.unsubscribeFunctions.clear()}),(0,u.A)(this,"reload",(0,a.A)(h().mark(function e(){var t,r,s,i,a,o,c,u,l,d,p,f,v,g,m,y,b=arguments;return h().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 e9(e9({},e),{},{pagination:e9(e9({},e.pagination),{},{isLoading:!0})})}),e.next=11,n.queryThreads({limit:Math.min(l,25)||25});case 11:d=e.sent,p=n.threadsById,f=[],v=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 e7(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 e7(e,t)}}(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(v.s();!(g=v.n()).done;)(y=p[(m=g.value).id])?(f.push(y),y.hasStaleState&&y.hydrateState(m)):f.push(m)}catch(e){v.e(e)}finally{v.f()}n.state.next(function(e){var t;return e9(e9({},e),{},{threads:f,unseenThreadIds:[],isThreadOrderStale:!1,pagination:e9(e9({},e.pagination),{},{isLoading:!1,nextCursor:null!=(t=d.next)?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 e9(e9({},e),{},{pagination:e9(e9({},e.pagination),{},{isLoading:!1})})});case 23:case"end":return e.stop()}},e,null,[[7,19]])}))),(0,u.A)(this,"queryThreads",function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return n.client.queryThreads(e9({limit:25,participant_limit:10,reply_limit:10,watch:!0},e))}),(0,u.A)(this,"loadNextPage",(0,a.A)(h().mark(function e(){var t,r,s,i=arguments;return h().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:e9(e9({},r),{},{isLoadingNext:!0})}),e.next=8,n.queryThreads(e9(e9({},t),{},{next:r.nextCursor}));case 8:s=e.sent,n.state.next(function(e){var t;return e9(e9({},e),{},{threads:s.threads.length?e.threads.concat(s.threads):e.threads,pagination:e9(e9({},e.pagination),{},{nextCursor:null!=(t=s.next)?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 e9(e9({},e),{},{pagination:e9(e9({},e.pagination),{},{isLoadingNext:!1})})});case 16:case"end":return e.stop()}},e,null,[[4,12]])}))),this.client=r,this.state=new eJ(te),this.threadsByIdGetterCache={threads:[],threadsById:{}}}return(0,c.A)(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}(),tn=["own_votes","id"],tr=["id"];function ts(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 ti(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};
1t%2?ts(Object(n),!0).forEach(function(t){(0,u.A)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ts(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var ta=function(e){return!!(null!=e&&e.answer_text)},to=function(){function e(t){var n,r,s,i,c,l,p,f,m,y,b,w,_=this,k=t.client,A=t.poll;(0,o.A)(this,e),(0,u.A)(this,"state",void 0),(0,u.A)(this,"id",void 0),(0,u.A)(this,"client",void 0),(0,u.A)(this,"unsubscribeFunctions",new Set),(0,u.A)(this,"getInitialStateFromPollResponse",function(e){var t,n,r=e.own_votes;e.id;var s=(0,v.A)(e,tn),i=null!=(n=null==r?void 0:r.reduce(function(e,t){return ta(t)?e.ownAnswer=t:e.ownVotes.push(t),e},{ownVotes:[]}))?n:{ownVotes:[]},a=i.ownAnswer,o=i.ownVotes;return ti(ti({},s),{},{lastActivityAt:new Date,maxVotedOptionIds:tc(s.vote_counts_by_option),ownAnswer:a,ownVotesByOptionId:(t=o)?t.reduce(function(e,t){return ta(t)||!t.option_id||(e[t.option_id]=t),e},{}):{}})}),(0,u.A)(this,"reinitializeState",function(e){_.state.partialNext(_.getInitialStateFromPollResponse(e))}),(0,u.A)(this,"handlePollUpdated",function(e){if((null==(n=e.poll)||!n.id||e.poll.id===_.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,v.A)(r,tr);_.state.partialNext(ti(ti({},s),{},{lastActivityAt:new Date(e.created_at)}))}}),(0,u.A)(this,"handlePollClosed",function(e){var t;null!=(t=e.poll)&&t.id&&e.poll.id!==_.id||"poll.closed"===e.type&&_.state.partialNext({is_closed:!0,lastActivityAt:new Date(e.created_at)})}),(0,u.A)(this,"handleVoteCasted",function(e){if((null==(t=e.poll)||!t.id||e.poll.id===_.id)&&"poll.vote_casted"===e.type){var t,n=_.data,r=e.poll_vote.user_id===_.client.userID,s=(0,g.A)(n.latest_answers),i=n.ownAnswer,a=n.ownVotesByOptionId,o=n.maxVotedOptionIds;r&&(ta(e.poll_vote)?i=e.poll_vote:e.poll_vote.option_id&&(a[e.poll_vote.option_id]=e.poll_vote)),ta(e.poll_vote)?s=[e.poll_vote].concat((0,g.A)(s)):o=tc(e.poll.vote_counts_by_option);var c=tu(e.poll);_.state.partialNext(ti(ti({},c),{},{latest_answers:s,lastActivityAt:new Date(e.created_at),ownAnswer:i,ownVotesByOptionId:a,maxVotedOptionIds:o}))}}),(0,u.A)(this,"handleVoteChanged",function(e){if((null==(t=e.poll)||!t.id||e.poll.id===_.id)&&"poll.vote_changed"===e.type){var t,n,r=_.data,s=e.poll_vote.user_id===_.client.userID,i=(0,g.A)(r.latest_answers),a=r.ownAnswer,o=r.ownVotesByOptionId,c=r.maxVotedOptionIds;s?ta(e.poll_vote)?(i=[e.poll_vote].concat((0,g.A)(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,u.A)({},e.poll_vote.option_id,e.poll_vote):(o=Object.entries(o).reduce(function(t,n){var r=(0,d.A)(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.id)===e.poll_vote.id&&(a=void 0),c=tc(e.poll.vote_counts_by_option)):ta(e.poll_vote)?i=[e.poll_vote].concat((0,g.A)(i)):c=tc(e.poll.vote_counts_by_option);var l=tu(e.poll);_.state.partialNext(ti(ti({},l),{},{latest_answers:i,lastActivityAt:new Date(e.created_at),ownAnswer:a,ownVotesByOptionId:o,maxVotedOptionIds:c}))}}),(0,u.A)(this,"handleVoteRemoved",function(e){if((null==(t=e.poll)||!t.id||e.poll.id===_.id)&&"poll.vote_removed"===e.type){var t,n=_.data,r=e.poll_vote.user_id===_.client.userID,s=(0,g.A)(n.latest_answers),i=n.ownAnswer,a=ti({},n.ownVotesByOptionId),o=n.maxVotedOptionIds;ta(e.poll_vote)?(s=s.filter(function(t){return t.id!==e.poll_vote.id}),r&&(i=void 0)):(o=tc(e.poll.vote_counts_by_option),r&&e.poll_vote.option_id&&delete a[e.poll_vote.option_id]);var c=tu(e.poll);_.state.partialNext(ti(ti({},c),{},{latest_answers:s,lastActivityAt:new Date(e.created_at),ownAnswer:i,ownVotesByOptionId:a,maxVotedOptionIds:o}))}}),(0,u.A)(this,"query",(n=(0,a.A)(h().mark(function e(t){var n;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_.client.getPoll(t);case 2:return n=e.sent.poll,_.state.partialNext(ti(ti({},n),{},{lastActivityAt:new Date})),e.abrupt("return",n);case 6:case"end":return e.stop()}},e)})),function(e){return n.apply(this,arguments)})),(0,u.A)(this,"update",(r=(0,a.A)(h().mark(function e(t){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_.client.updatePoll(ti(ti({},t),{},{id:_.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,u.A)(this,"partialUpdate",(s=(0,a.A)(h().mark(function e(t){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_.client.partialUpdatePoll(_.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,u.A)(this,"close",(0,a.A)(h().mark(function e(){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_.client.closePoll(_.id);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)}))),(0,u.A)(this,"delete",(0,a.A)(h().mark(function e(){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_.client.deletePoll(_.id);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)}))),(0,u.A)(this,"createOption",(i=(0,a.A)(h().mark(function e(t){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_.client.createPollOption(_.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,u.A)(this,"updateOption",(c=(0,a.A)(h().mark(function e(t){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_.client.updatePollOption(_.id,t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)})),function(e){return c.apply(this,arguments)})),(0,u.A)(this,"deleteOption",(l=(0,a.A)(h().mark(function e(t){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_.client.deletePollOption(_.id,t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)})),function(e){return l.apply(this,arguments)})),(0,u.A)(this,"castVote",(p=(0,a.A)(h().mark(function e(t,n){var r,s,i,a,o;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(s=(r=_.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)&&t.created_at)||new Date(e.created_at)<new Date(o.created_at))&&(o=e)}),!(null!=(a=o)&&a.id))){e.next=8;break}return e.next=8,_.removeVote(o.id,n);case 8:return e.next=10,_.client.castPollVote(n,_.id,{option_id:t});case 10:return e.abrupt("return",e.sent);case 11:case"end":return e.stop()}},e)})),function(e,t){return p.apply(this,arguments)})),(0,u.A)(this,"removeVote",(f=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_.client.removePollVote(n,_.id,t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)})),function(e,t){return f.apply(this,arguments)})),(0,u.A)(this,"addAnswer",(m=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_.client.addPollAnswer(n,_.id,t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)})),function(e,t){return m.apply(this,arguments)})),(0,u.A)(this,"removeAnswer",(y=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_.client.removePollVote(n,_.id,t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)})),function(e,t){return y.apply(this,arguments)})),(0,u.A)(this,"queryAnswers",(b=(0,a.A)(h().mark(function e(t){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_.client.queryPollAnswers(_.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 b.apply(this,arguments)})),(0,u.A)(this,"queryOptionVotes",(w=(0,a.A)(h().mark(function e(t){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_.client.queryPollVotes(_.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 w.apply(this,arguments)})),this.client=k,this.id=A.id,this.state=new eJ(this.getInitialStateFromPollResponse(A))}return(0,c.A)(e,[{key:"data",get:function(){return this.state.getLatestValue()}}]),e}();function tc(e){for(var t=0,n=[],r=0,s=Object.entries(null!=e?e:{});r<s.length;r++){var i=(0,d.A)(s[r],2),a=i[0],o=i[1];o>t?(n=[a],t=o):o===t&&n.push(a)}return n}function tu(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 tl(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 th=function(){function e(t){var n,r,s,i=this,c=t.client;(0,o.A)(this,e),(0,u.A)(this,"client",void 0),(0,u.A)(this,"pollCache",new Map),(0,u.A)(this,"unsubscribeFunctions",new Set),(0,u.A)(this,"fromState",function(e){return i.pollCache.get(e)}),(0,u.A)(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,u.A)(this,"unregisterSubscriptions",function(){i.unsubscribeFunctions.forEach(function(e){return e()}),i.unsubscribeFunctions.clear()}),(0,u.A)(this,"createPoll",(n=(0,a.A)(h().mark(function e(t){var n;return h().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 to({client:i.client,poll:n}));case 5:case"end":return e.stop()}},e)})),function(e){return n.apply(this,arguments)})),(0,u.A)(this,"getPoll",(r=(0,a.A)(h().mark(function e(t){var n,r;return h().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,u.A)(this,"queryPolls",(s=(0,a.A)(h().mark(function e(t){var n,r,s,a,o,c,u=arguments;return h().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,u.A)(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 tl(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 tl(e,t)}}(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,u.A)(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 to({client:i.client,poll:e});i.pollCache.set(r.id,r)}}}),(0,u.A)(this,"subscribePollUpdated",function(){return i.client.on("poll.updated",function(e){var t,n;null!=(t=e.poll)&&t.id&&(null==(n=i.fromState(e.poll.id))||n.handlePollUpdated(e))}).unsubscribe}),(0,u.A)(this,"subscribePollClosed",function(){return i.client.on("poll.closed",function(e){var t,n;null!=(t=e.poll)&&t.id&&(null==(n=i.fromState(e.poll.id))||n.handlePollClosed(e))}).unsubscribe}),(0,u.A)(this,"subscribeVoteCasted",function(){return i.client.on("poll.vote_casted",function(e){var t,n;null!=(t=e.poll)&&t.id&&(null==(n=i.fromState(e.poll.id))||n.handleVoteCasted(e))}).unsubscribe}),(0,u.A)(this,"subscribeVoteChanged",function(){return i.client.on("poll.vote_changed",function(e){var t,n;null!=(t=e.poll)&&t.id&&(null==(n=i.fromState(e.poll.id))||n.handleVoteChanged(e))}).unsubscribe}),(0,u.A)(this,"subscribeVoteRemoved",function(){return i.client.on("poll.vote_removed",function(e){var t,n;null!=(t=e.poll)&&t.id&&(null==(n=i.fromState(e.poll.id))||n.handleVoteRemoved(e))}).unsubscribe}),(0,u.A)(this,"subscribeMessageNew",function(){return i.client.on("message.new",function(e){var t=e.message;if(t){var n=G(t);i.hydratePollCache([n])}}).unsubscribe}),this.client=c}return(0,c.A)(e,[{key:"data",get:function(){return this.pollCache}}]),e}();function td(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 tp(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?td(Object(n),!0).forEach(function(t){(0,u.A)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):td(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var tf={"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"},tv={abortInFlightQuery:!1,allowNotLoadedChannelPromotionForEvent:{"channel.visible":!0,"message.new":!0,"notification.added_to_channel":!0,"notification.message_new":!0},lockChannelOrder:!1},tg={limit:10,offset:0},tm=function e(t){var n,r,s,i,c=this,l=t.client,p=t.eventHandlerOverrides,f=t.options;(0,o.A)(this,e),(0,u.A)(this,"state",void 0),(0,u.A)(this,"client",void 0),(0,u.A)(this,"unsubscribeFunctions",new Set),(0,u.A)(this,"eventHandlers",new Map),(0,u.A)(this,"eventHandlerOverrides",new Map),(0,u.A)(this,"options",{}),(0,u.A)(this,"stateOptions",{}),(0,u.A)(this,"setChannels",function(e){c.state.next(function(t){var n=t.channels,r=ez(e)?e(n):e;return n===r?t:tp(tp({},t),{},{channels:r})})}),(0,u.A)(this,"setEventHandlerOverrides",function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};c.eventHandlerOverrides=new Map(Object.entries(Object.entries(e).reduce(function(e,t){var n=(0,d.A)(t,2),r=n[0],s=n[1];return s&&(e[r]=s),e},{})))}),(0,u.A)(this,"setOptions",function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};c.options=tp(tp({},tv),e)}),(0,u.A)(this,"queryChannels",(n=(0,a.A)(h().mark(function e(t){var n,r,s,i,a,o,u,l,d,p,f,v,g=arguments;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n=g.length>1&&void 0!==g[1]?g[1]:[],r=g.length>2&&void 0!==g[2]?g[2]:{},s=g.length>3&&void 0!==g[3]?g[3]:{},a=(i=tp(tp({},tg),r)).offset,o=i.limit,!(c.state.getLatestValue().pagination.isLoading&&!c.options.abortInFlightQuery)){e.next=7;break}return e.abrupt("return");case 7:return e.prev=7,c.stateOptions=s,c.state.next(function(e){return tp(tp({},e),{},{pagination:tp(tp({},e.pagination),{},{isLoading:!0,isLoadingNext:!1,filters:t,sort:n,options:r})})}),e.next=12,c.client.queryChannels(t,n,r,s);case 12:d=e.sent,p=a+(null!=(u=null==d?void 0:d.length)?u:0),f=tp(tp({},r),{},{offset:p}),v=c.state.getLatestValue().pagination,c.state.partialNext({channels:d,pagination:tp(tp({},v),{},{hasNext:(null!=(l=null==d?void 0:d.length)?l:0)>=o,isLoading:!1,options:f}),initialized:!0}),e.next=24;break;case 19:throw e.prev=19,e.t0=e.catch(7),c.client.logger("error",e.t0.message),c.state.next(function(e){return tp(tp({},e),{},{pagination:tp(tp({},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,u.A)(this,"loadNext",(0,a.A)(h().mark(function e(){var t,n,r,s,i,a,o,u,l,d,p,f,v,m,y,b,w;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n=(t=c.state.getLatestValue()).pagination,r=t.initialized,s=n.filters,i=n.sort,a=n.options,o=n.isLoadingNext,u=n.hasNext,!(!r||o||!u)){e.next=4;break}return e.abrupt("return");case 4:return e.prev=4,f=(p=tp(tp({},tg),a)).offset,v=p.limit,c.state.partialNext({pagination:tp(tp({},n),{},{isLoading:!1,isLoadingNext:!0})}),e.next=9,c.client.queryChannels(s,i,a,c.stateOptions);case 9:m=e.sent,y=c.state.getLatestValue().channels,b=f+(null!=(l=null==m?void 0:m.length)?l:0),w=tp(tp({},a),{},{offset:b}),c.state.partialNext({channels:Y([].concat((0,g.A)(y||[]),(0,g.A)(m)),"cid"),pagination:tp(tp({},n),{},{hasNext:(null!=(d=null==m?void 0:m.length)?d:0)>=v,isLoading:!1,isLoadingNext:!1,options:w})}),e.next=21;break;case 16:throw e.prev=16,e.t0=e.catch(4),c.client.logger("error",e.t0.message),c.state.next(function(e){return tp(tp({},e),{},{pagination:tp(tp({},e.pagination),{},{isLoadingNext:!1})})}),e.t0;case 21:case"end":return e.stop()}},e,null,[[4,16]])}))),(0,u.A)(this,"notificationAddedToChannelHandler",(r=(0,a.A)(h().mark(function e(t){var n,r,s,i,a,o,u,l,d,p,f;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(i=(s=null!=(n=null==t?void 0:t.channel)?n:{}).id,a=s.type,o=s.members,!(!a||!(null!=(r=c.options.allowNotLoadedChannelPromotionForEvent)&&r["notification.added_to_channel"]))){e.next=3;break}return e.abrupt("return");case 3:return e.next=5,es({client:c.client,id:i,members:null==o?void 0:o.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:a});case 5:if(u=e.sent,d=(l=c.state.getLatestValue()).pagination,p=l.channels){e.next=9;break}return e.abrupt("return");case 9:f=(null!=d?d:{}).sort,c.setChannels(ep({channels:p,channelToMove:u,sort:f}));case 11:case"end":return e.stop()}},e)})),function(e){return r.apply(this,arguments)})),(0,u.A)(this,"channelDeletedHandler",function(e){var t=c.state.getLatestValue().channels;if(t){var n=(0,g.A)(t),r=n.findIndex(function(t){var n;return t.cid===(e.cid||(null==(n=e.channel)?void 0:n.cid))});r<0||(n.splice(r,1),c.setChannels(n))}}),(0,u.A)(this,"channelHiddenHandler",this.channelDeletedHandler),(0,u.A)(this,"newMessageHandler",function(e){var t,n=c.state.getLatestValue(),r=n.pagination,s=n.channels;if(s){var i=null!=r?r:{},a=i.filters,o=i.sort,u=e.channel_type,l=e.channel_id;if(u&&l){var h=c.client.channel(u,l),d=s.indexOf(h),p=d>=0,f=ea(h),v=eo(h),g=ec(a),m=el(o);g&&v&&!a.archived||g&&!v&&a.archived||m&&f||c.options.lockChannelOrder||!p&&(null==(t=c.options.allowNotLoadedChannelPromotionForEvent)||!t["message.new"])||c.setChannels(ep({channels:s,channelToMove:h,channelToMoveIndexWithinChannels:d,sort:o}))}}}),(0,u.A)(this,"notificationNewMessageHandler",(s=(0,a.A)(h().mark(function e(t){var n,r,s,i,a,o,u,l,d,p,f,v,g,m;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(i=(s=null!=(n=null==t?void 0:t.channel)?n:{}).id,a=s.type,!(!i||!a)){e.next=3;break}return e.abrupt("return");case 3:return e.next=5,es({client:c.client,id:i,type:a});case 5:if(o=e.sent,l=(u=c.state.getLatestValue()).channels,f=(p=null!=(d=u.pagination)?d:{}).filters,v=p.sort,g=ec(f),m=eo(o),!(!l||g&&m&&!f.archived||g&&!m&&f.archived||!(null!=(r=c.options.allowNotLoadedChannelPromotionForEvent)&&r["notification.message_new"]))){e.next=12;break}return e.abrupt("return");case 12:c.setChannels(ep({channels:l,channelToMove:o,sort:v}));case 13:case"end":return e.stop()}},e)})),function(e){return s.apply(this,arguments)})),(0,u.A)(this,"channelVisibleHandler",(i=(0,a.A)(h().mark(function e(t){var n,r,s,i,a,o,u,l,d,p,f,v;return h().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,es({client:c.client,id:t.channel_id,type:t.channel_type});case 5:if(i=e.sent,o=(a=c.state.getLatestValue()).channels,d=(l=null!=(u=a.pagination)?u:{}).sort,f=ec(p=l.filters),v=eo(i),!(!o||f&&v&&!p.archived||f&&!v&&p.archived||!(null!=(n=c.options.allowNotLoadedChannelPromotionForEvent)&&n["channel.visible"]))){e.next=12;break}return e.abrupt("return");case 12:c.setChannels(ep({channels:o,channelToMove:i,sort:d}));case 13:case"end":return e.stop()}},e)})),function(e){return i.apply(this,arguments)})),(0,u.A)(this,"notificationRemovedFromChannelHandler",this.channelDeletedHandler),(0,u.A)(this,"memberUpdatedHandler",function(e){var t,n=c.state.getLatestValue(),r=n.pagination,s=n.channels,i=r.filters,a=r.sort;if(null!=(t=e.member)&&t.user&&e.member.user.id===c.client.userID&&e.channel_type&&e.channel_id){var o=e.channel_type,u=e.channel_id,l=el(a),h=ec(i),d=eu({atIndex:0,sort:a,targetKey:"pinned_at"});if(s&&(l||h)&&!c.options.lockChannelOrder){var p=c.client.channel(o,u),f=s.indexOf(p),v=f>=0,m=ea(p),y=eo(p),b=(0,g.A)(s);if(v&&b.splice(f,1),h&&!y&&null!=i&&i.archived||h&&y&&!(null!=i&&i.archived))return void c.setChannels(b);var w=null;1!==d&&(-1!==d||m)||(w=ed({channels:b}));var _="number"==typeof w?w+1:0;s[_]!==p&&(b.splice(_,0,p),c.setChannels(b))}}}),(0,u.A)(this,"subscriptionOrOverride",function(e){var t=tf[e.type],n=c.eventHandlers.get(t),r=c.eventHandlerOverrides.get(t);if(r&&"function"==typeof r)return void r(c.setChannels,e);n&&"function"==typeof n&&n(e)}),(0,u.A)(this,"registerSubscriptions",function(){if(!c.unsubscribeFunctions.size)for(var e=0,t=Object.keys(tf);e<t.length;e++){var n=t[e];c.unsubscribeFunctions.add(c.client.on(n,c.subscriptionOrOverride).unsubscribe)}}),(0,u.A)(this,"unregisterSubscriptions",function(){c.unsubscribeFunctions.forEach(function(e){return e()}),c.unsubscribeFunctions.clear()}),this.client=l,this.state=new eJ({channels:[],pagination:{isLoading:!1,isLoadingNext:!1,hasNext:!1,filters:{},sort:{},options:tg},initialized:!1}),this.setEventHandlerOverrides(void 0===p?{}:p),this.setOptions(void 0===f?{}:f),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}))},ty=["created_at","updated_at","last_active","online"],tb=["params","headers"];function tw(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 t_(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 t_(e,t)}}(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 t_(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 tk(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 tA(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?tk(Object(n),!0).forEach(function(t){(0,u.A)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):tk(Object(n)).forEac
1h(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function tx(e){return"string"==typeof e||e instanceof String}var tC=function(){var e,t,n,r,s,l,y,w,_,k,A,x,C,S,I,L,M,D,E,H,W,B,z,J,G,Q,$,X,Y,Z,ee,et,er,es,ea,eo,ec,eu,el,eh,ed,ep,ef,ev,eg,em,ey,eb,ew,e_,eA,eC,eS,eO,eI,eL,eD,eT,ej,eF,eq,eW,eB,ez,eJ,eK,eG,eQ,e$,eX,eY,e0,e1,e2,e3,e4,e5,e7,e8,e9,te,tn,tr,ts,ti,ta,to,tc,tu,tl,td,tp,tf,tv,tg,t_,tk,tC,tS,tU,tR,tO,tI,tP,tL,tM,tD,tE,tT,tj,tF,tq;function tN(e,t,n){var r,s,i,c,l,d=this;(0,o.A)(this,tN),(0,u.A)(this,"_user",void 0),(0,u.A)(this,"activeChannels",void 0),(0,u.A)(this,"threads",void 0),(0,u.A)(this,"polls",void 0),(0,u.A)(this,"anonymous",void 0),(0,u.A)(this,"persistUserOnConnectionFailure",void 0),(0,u.A)(this,"axiosInstance",void 0),(0,u.A)(this,"baseURL",void 0),(0,u.A)(this,"browser",void 0),(0,u.A)(this,"cleaningIntervalRef",void 0),(0,u.A)(this,"clientID",void 0),(0,u.A)(this,"configs",void 0),(0,u.A)(this,"key",void 0),(0,u.A)(this,"listeners",void 0),(0,u.A)(this,"logger",void 0),(0,u.A)(this,"recoverStateOnReconnect",void 0),(0,u.A)(this,"moderation",void 0),(0,u.A)(this,"mutedChannels",void 0),(0,u.A)(this,"mutedUsers",void 0),(0,u.A)(this,"node",void 0),(0,u.A)(this,"options",void 0),(0,u.A)(this,"secret",void 0),(0,u.A)(this,"setUserPromise",void 0),(0,u.A)(this,"state",void 0),(0,u.A)(this,"tokenManager",void 0),(0,u.A)(this,"user",void 0),(0,u.A)(this,"userAgent",void 0),(0,u.A)(this,"userID",void 0),(0,u.A)(this,"wsBaseURL",void 0),(0,u.A)(this,"wsConnection",void 0),(0,u.A)(this,"wsFallback",void 0),(0,u.A)(this,"wsPromise",void 0),(0,u.A)(this,"consecutiveFailures",void 0),(0,u.A)(this,"insightMetrics",void 0),(0,u.A)(this,"defaultWSTimeoutWithFallback",void 0),(0,u.A)(this,"defaultWSTimeout",void 0),(0,u.A)(this,"sdkIdentifier",void 0),(0,u.A)(this,"deviceIdentifier",void 0),(0,u.A)(this,"nextRequestAbortController",null),(0,u.A)(this,"_getConnectionID",function(){var e,t;return(null==(e=d.wsConnection)?void 0:e.connectionID)||(null==(t=d.wsFallback)?void 0:t.connectionID)}),(0,u.A)(this,"_hasConnectionID",function(){return!!d._getConnectionID()}),(0,u.A)(this,"connectUser",(r=(0,a.A)(h().mark(function e(t,n){var r,s;return h().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(!(d.userID===t.id&&d.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",d.setUserPromise);case 5:if(!d.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(d._isUsingServerAuth()||d.node)&&!d.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.'),d.userID=t.id,d.anonymous=!1,r=d._setToken(t,n),d._setUser(t),s=d.openConnection(),d.setUserPromise=Promise.all([r,s]).then(function(e){return e[1]}),e.prev=14,e.next=17,d.setUserPromise;case 17:return e.abrupt("return",e.sent);case 20:throw e.prev=20,e.t0=e.catch(14),d.persistUserOnConnectionFailure?d.closeConnection():d.disconnectUser(),e.t0;case 24:case"end":return e.stop()}},e,null,[[14,20]])})),function(e,t){return r.apply(this,arguments)})),(0,u.A)(this,"setUser",this.connectUser),(0,u.A)(this,"_setToken",function(e,t){return d.tokenManager.setTokenOrProvider(t,e)}),(0,u.A)(this,"closeConnection",(s=(0,a.A)(h().mark(function e(t){var n,r;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return null!=d.cleaningIntervalRef&&(clearInterval(d.cleaningIntervalRef),d.cleaningIntervalRef=void 0),e.next=3,Promise.all([null==(n=d.wsConnection)?void 0:n.disconnect(t),null==(r=d.wsFallback)?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,u.A)(this,"createChannelManager",function(e){var t=e.eventHandlerOverrides,n=e.options;return new tm({client:d,eventHandlerOverrides:void 0===t?{}:t,options:void 0===n?{}:n})}),(0,u.A)(this,"openConnection",(0,a.A)(h().mark(function e(){var t,n,r;return h().wrap(function(e){for(;;
1)switch(e.prev=e.next){case 0:if(d.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=d.wsConnection)&&t.isConnecting&&d.wsPromise)){e.next=5;break}return d.logger("info","client:openConnection() - connection already in progress",{tags:["connection","client"]}),e.abrupt("return",d.wsPromise);case 5:if(!((null!=(n=d.wsConnection)&&n.isHealthy||null!=(r=d.wsFallback)&&r.isHealthy())&&d._hasConnectionID())){e.next=8;break}return d.logger("info","client:openConnection() - openConnection called twice, healthy connection already exists",{tags:["connection","client"]}),e.abrupt("return");case 8:return d.clientID="".concat(d.userID,"--").concat(V()),d.wsPromise=d.connect(),d._startCleaning(),e.abrupt("return",d.wsPromise);case 12:case"end":return e.stop()}},e)}))),(0,u.A)(this,"_setupConnection",this.openConnection),(0,u.A)(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,u.A)(this,"disconnectUser",(i=(0,a.A)(h().mark(function e(t){var n,r,s;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:for(d.logger("info","client:disconnect() - Disconnecting the client",{tags:["connection","client"]}),delete d.user,delete d._user,delete d.userID,d.anonymous=!1,n=d.closeConnection(t),r=0,s=Object.values(d.activeChannels);r<s.length;r++)s[r]._disconnect();return d.activeChannels={},d.state=new ex({client:d}),d.threads.resetState(),setTimeout(d.tokenManager.reset),e.abrupt("return",n);case 12:case"end":return e.stop()}},e)})),function(e){return i.apply(this,arguments)})),(0,u.A)(this,"disconnect",this.disconnectUser),(0,u.A)(this,"connectAnonymousUser",function(){(d._isUsingServerAuth()||d.node)&&!d.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.'),d.anonymous=!0,d.userID=V();var e={id:d.userID,anon:!0};return d._setToken(e,""),d._setUser(e),d._setupConnection()}),(0,u.A)(this,"setAnonymousUser",this.connectAnonymousUser),(0,u.A)(this,"doAxiosRequest",(c=(0,a.A)(h().mark(function e(t,n,r){var s,i,a,o,c=arguments;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return s=c.length>3&&void 0!==c[3]?c[3]:{},e.next=3,d.tokenManager.tokenReady();case 3:i=d._enrichAxiosOptions(s),e.prev=4,d._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,d.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,d.axiosInstance.delete(n,i);case 17:return e.next=19,d.axiosInstance.post(n,r,i);case 21:return e.next=23,d.axiosInstance.postForm(n,r,i);case 25:return e.next=27,d.axiosInstance.put(n,r,i);case 29:return e.next=31,d.axiosInstance.patch(n,r,i);case 33:return e.next=35,d.axiosInstance.options(n,i);case 37:throw Error("Invalid request type");case 38:return d._logApiResponse(t,n,a),d.consecutiveFailures=0,e.abrupt("return",d.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["x-client-request-id"],d._logApiError(t,n,e.t1),d.consecutiveFailures+=1,!e.t1.response){e.next=60;break}if(!(e.t1.response.data.code===F.TOKEN_EXPIRED&&!d.tokenManager.isStatic())){e.next=57;break}if(!(d.consecutiveFailures>1)){e.next=53;break}return e.next=53,T(N(d.consecutiveFailures));case 53:return d.tokenManager.loadToken(),e.next=56,d.doAxiosRequest(t,n,r,s);case 56:return e.abrupt("return",e.sent);case 57:return e.abrupt("return",d.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 c.apply(this,arguments)})),(0,u.A)(this,"dispatchEvent",function(e){e.received_at||(e.received_at=new Date);var t=d._handleClientEvent(e),n=e.cid,r=n?d.activeChannels[n]:void 0;r&&r._handleChannelEvent(e),d._callClientListeners(e),r&&r._callChannelListeners(e),t.forEach(function(e){return e()})}),(0,u.A)(this,"handleEvent",function(e){var t=JSON.parse(e.data);d.dispatchEvent(t)}),(0,u.A)(this,"_updateMemberWatcherReferences",function(e){var t=d.state.userChannelReferences[e.id]||{};for(var n in t){var r=d.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,u.A)(this,"_updateUserReferences",this._updateMemberWatcherReferences),(0,u.A)(this,"_updateUserMessageReferences",function(e){var t=d.state.userChannelReferences[e.id]||{};for(var n in t){var r=d.activeChannels[n];if(r){var s=r.state;null==s||s.updateUserMessages(e)}}}),(0,u.A)(this,"_deleteUserMessageReference",function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=d.state.userChannelReferences[e.id]||{};for(var r in n){var s=d.activeChannels[r];if(s){var i=s.state;null==i||i.deleteUserMessages(e,t)}}}),(0,u.A)(this,"_handleUserEvent",function(e){if(e.user){if("user.presence.changed"===e.type||"user.updated"===e.type){if(e.user.id===d.userID){var t=tA({},d.user||{}),n=tA({},d._user||{});for(var r in d.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]);d._user=tA({},n),d.user=tA(tA({},t),e.user)}d.state.updateUser(e.user),d._updateMemberWatcherReferences(e.user)}"user.updated"===e.type&&d._updateUserMessageReferences(e.user),"user.deleted"===e.type&&e.user.deleted_at&&(e.mark_messages_deleted||e.hard_delete)&&d._deleteUserMessageReference(e.user,e.hard_delete)}}),(0,u.A)(this,"_callClientListeners",function(e){var t=[];d.listeners.all&&t.push.apply(t,(0,g.A)(d.listeners.all)),d.listeners[e.type]&&t.push.apply(t,(0,g.A)(d.listeners[e.type]));for(var n=0;n<t.length;n++)(0,t[n])(e)}),(0,u.A)(this,"recoverState",(0,a.A)(h().mark(function e(){var t;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(d.logger("info","client:recoverState() - Start of recoverState with connectionID ".concat(d._getConnectionID()),{tags:["connection"]}),!((t=Object.keys(d.activeChannels)).length&&d.recoverStateOnReconnect)){e.next=10;break}return d.logger("info","client:recoverState() - Start the querying of ".concat(t.length," channels"),{tags:["connection","client"]}),e.next=6,d.queryChannels({cid:{$in:t}},{last_message_at:-1},{limit:30});case 6:d.logger("info","client:recoverState() - Querying channels finished",{tags:["connection","client"]}),d.dispatchEvent({type:"connection.recovered"}),e.next=11;break;case 10:d.dispatchEvent({type:"connection.recovered"});case 11:d.wsPromise=Promise.resolve(),d.setUserPromise=Promise.resolve();case 13:case"end":return e.stop()}},e)}))),(0,u.A)(this,"getChannelByMembers",function(e,t){var n,r=(null!=(n=t.members)?n:[]).map(function(e){var t;return"string"==typeof e?e:null!=(t=e.user_id)?t:""}),s=r.sort().join(","),i=ei(e,r);if(!i)throw Error("Please specify atleast one member when creating unique conversation");for(var a in d.activeChannels){var o=d.activeChannels[a];if(!o.disconnected&&(a===i||0===a.indexOf("".concat(e,":!members-"))&&Object.keys(o.state.members).sort().join(",")===s))return o}var c=new ek(d,e,void 0,t);return d._cacheEnabled()&&(d.activeChannels[i]=c),c}),(0,u.A)(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 d.activeChannels&&d.activeChannels[r]&&!d.activeChannels[r].disconnected){var s=d.activeChannels[r];return Object.keys(n).length>0&&(s.data=tA(tA({},s.data),n),s._data=tA(tA({},s._data),n)),s}var i=new ek(d,e,t,n);return d._cacheEnabled()&&(d.activeChannels[i.cid]=i),i}),(0,u.A)(this,"updateUsers",this.upsertUsers),(0,u.A)(this,"updateUser",this.upsertUser),(0,u.A)(this,"_unblockMessage",this.unblockMessage),(0,u.A)(this,"markAllRead",this.markChannelsRead),(0,u.A)(this,"_isUsingServerAuth",function(){return!!d.secret}),(0,u.A)(this,"_cacheEnabled",function(){return!d._isUsingServerAuth()||!d.options.disableCache}),(0,u.A)(this,"_buildWSPayload",function(e){return JSON.stringify({user_id:d.userID,user_details:d._user,device:d.options.device,client_request_id:e})}),this.key=e,this.listeners={},this.state=new ex({client:this}),this.mutedChannels=[],this.mutedUsers=[],this.moderation=new e6(this),t&&tx(t)&&(this.secret=t);var p=n||(t&&!tx(t)?t:{});this.browser=void 0!==p.browser?p.browser:"undefined"!=typeof window,this.node=!this.browser,this.options=tA({timeout:3e3,withCredentials:!1,warmUp:!1,recoverStateOnReconnect:!0,disableCache:!1,wsUrlParams:new URLSearchParams({})},p),this.node&&!this.options.httpsAgent&&(this.options.httpsAgent=new null.Agent({keepAlive:!0,keepAliveMsecs:3e3})),this.axiosInstance=m.A.create(this.options),this.setBaseURL(this.options.baseURL||"https://chat.stream-io-api.com"),void 0!==R&&"env"in R&&R.env.STREAM_LOCAL_TEST_RUN&&this.setBaseURL("http://localhost:3030"),void 0!==R&&"env"in R&&R.env.STREAM_LOCAL_TEST_HOST&&this.setBaseURL("http://"+R.env.STREAM_LOCAL_TEST_HOST),this.wsConnection=null,this.wsPromise=null,this.setUserPromise=null,this.activeChannels={},this.configs={},this.anonymous=!1,this.persistUserOnConnectionFailure=null==(l=this.options)?void 0:l.persistUserOnConnectionFailure,this.tokenManager=new eE(this.secret),this.consecutiveFailures=0,this.insightMetrics=new eU,this.defaultWSTimeoutWithFallback=6e3,this.defaultWSTimeout=15e3,this.axiosInstance.defaults.paramsSerializer
1=K,this.logger=j(p.logger)?p.logger:function(){return null},this.recoverStateOnReconnect=this.options.recoverStateOnReconnect,this.threads=new tt({client:this}),this.polls=new th({client:this})}return(0,c.A)(tN,[{key:"devToken",value:function(e){var t;return["eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9",(t=JSON.stringify({user_id:e}),(0,i.fromByteArray)(new Uint8Array(function(e,t){var n=[];if(O(e)&&t&&O(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(!O(e)&&!(t&&O(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=tA({},e)}},{key:"updateAppSettings",value:(e=(0,a.A)(h().mark(function e(t){var n;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return null!=(n=t.apn_config)&&n.p12_cert&&(t=tA(tA({},t),{},{apn_config:tA(tA({},n),{},{p12_cert:U.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,a.A)(h().mark(function e(t){return h().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,a.A)(h().mark(function e(t,n){return h().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,a.A)(h().mark(function e(t,n){var r,s,i,a;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:n=void 0===n?new Date().toISOString():this._normalizeDate(n),r=[],s=tw(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,a.A)(h().mark(function e(){return h().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:(l=(0,a.A)(h().mark(function e(t){var n,r=arguments;return h().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",tA(tA(tA(tA(tA(tA(tA({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 l.apply(this,arguments)})},{key:"testSQSSettings",value:(y=(0,a.A)(h().mark(function e(){var t,n=arguments;return h().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 y.apply(this,arguments)})},{key:"testSNSSettings",value:(w=(0,a.A)(h().mark(function e(){var t,n=arguments;return h().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 w.apply(this,arguments)})},{key:"setGuestUser",value:(_=(0,a.A)(h().mark(function e(t){var n,r,s;return h().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,v.A)(r,ty),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 _.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),eM(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=function(e,t,n){var r=new(b());return null!==e&&"object"===(0,f.A)(e)&&(e.readable||"function"==typeof e._read)||null!=e&&null!=e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)||"undefined"!=typeof window&&"File"in window&&e instanceof File||"undefined"!=typeof window&&"Blob"in window&&e instanceof Blob?t?r.append("file",e,t):r.append("file",e):r.append("file",{uri:e,name:t||e.split("/").reverse()[0],contentType:n||void 0,type:n||void 0}),r}(t,n,r||"multipart/form-data");return null!=s&&i.append("user",JSON.stringify(s)),this.doAxiosRequest("postForm",e,i,{headers:i.getHeaders?i.getHeaders():{},config:{timeout:0,maxContentLength:1/0,maxBodyLength:1/0}})}},{key:"errorFromResponse",value:function(e){var t;return t=new eV("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)&&n.channel_mutes&&(this.mutedChannels=e.me.channel_mutes),"notification.mutes_updated"===e.type&&null!=(r=e.me)&&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])||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.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:(k=(0,a.A)(h().mark(function e(){return h().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 eP({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 eN({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 k.apply(this,arguments)})},{key:"_sayHi",value:function(){var e=this,t=V();this.doAxiosRequest("get",this.baseURL+"/hi",null,{headers:{"x-client-request-id":t}}).catch(function(n){e.options.enableInsights&&eR("http_hi_failed",{api_key:e.key,err:n,client_request_id:t})})}},{key:"queryUsers",value:(A=(0,a.A)(h().mark(function e(t){var n,r,s,i,a=arguments;return h().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:tA(tA({filter_conditions:t,sort:q(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 A.apply(this,arguments)})},{key:"queryBannedUsers",value:(x=(0,a.A)(h().mark(function e(){var t,n,r,s=arguments;return h().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:tA({filter_conditions:t,sort:q(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,a.A)(h().mark(function e(){var t,n,r=arguments;return h().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:tA({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,a.A)(h().mark(function e(t){var n,r,s,i,a,o,c=arguments;return h().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=tA(tA({filter_conditions:t,sort:q(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:(I=(0,a.A)(h().mark(function e(t,n){var r,s,i,a=arguments;return h().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=tA({filter:n,sort:q(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 I.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=tw(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 h=void 0;void 0===s?h=l._initializeState(u,"latest").messageSet:s.includes(u.channel.id)||(l.state.clearMessages(),h=l._initializeState(u,"latest").messageSet),h&&(h.pagination=tA(tA({},h.pagination),en({parentSet:h,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:(L=(0,a.A)(h().mark(function e(t,n){var r,s,i=arguments;return h().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=tA(tA({filter_conditions:t},r),{},{sort:r.sort?q(r.sort):void 0}),"string"!=typeof n){e.next=8;break}s.query=n,e.next=13;break;case 8:if("object"!==(0,f.A)(n)){e.next=12;break}s.message_filter_conditions=n,e.next=13;break;case 12:throw Error("Invalid type ".concat((0,f.A)(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 L.apply(this,arguments)})},{key:"setLocalDevice",value:function(e){var t,n,r;if(null!=(t=this.wsConnection)&&t.isConnecting&&this.wsPromise||(null!=(n=this.wsConnection)&&n.isHealthy||null!=(r=this.wsFallback)&&r.isHealthy())&&this._hasConnectionID())throw Error("you can only set device before opening a websocket connection");this.options.device=e}},{key:"addDevice",value:(M=(0,a.A)(h().mark(function e(t,n,r,s){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/devices",tA(tA({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 M.apply(this,arguments)})},{key:"getDevices",value:(D=(0,a.A)(h().mark(function e(t){return h().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 D.apply(this,arguments)})},{key:"getUnreadCount",value:(E=(0,a.A)(h().mark(function e(t){return h().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 E.apply(this,arguments)})},{key:"getUnreadCountBatch",value:(H=(0,a.A)(h().mark(function e(t){return h().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 H.apply(this,arguments)})},{key:"setPushPreferences",value:(W=(0,a.A)(h().mark(function e(t){return h().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 W.apply(this,arguments)})},{key:"removeDevice",value:(B=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.delete(this.baseURL+"/devices",tA({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 B.apply(this,arguments)})},{key:"getRateLimits",value:(z=(0,a.A)(h().mark(function e(t){var n,r,s,i,a,o;return h().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 z.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,f.A)(t)?this.getChannelByMembers(e,t):!t&&"object"===(0,f.A)(r)&&null!=(n=r.members)&&n.length?this.getChannelByMembers(e,r):t?this.getChannelById(e,t,r):new ek(this,e,void 0,r)}},{key:"partialUpdateUser",value:(J=(0,a.A)(h().mark(function e(t){return h().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 J.apply(this,arguments)})},{key:"upsertUsers",value:(G=(0,a.A)(h().mark(function e(t){var n,r,s,i;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:n={},r=tw(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 G.apply(this,arguments)})},{key:"upsertUser",value:function(e){return this.upsertUsers([e])}},{key:"partialUpdateUsers",value:(Q=(0,a.A)(h().mark(function e(t){var n,r;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:n=tw(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 Q.apply(this,arguments)})},{key:"deleteUser",value:($=(0,a.A)(h().mark(function e(t,n){return h().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 $.apply(this,arguments)})},{key:"restoreUsers",value:(X=(0,a.A)(h().mark(function e(t){return h().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 X.apply(this,arguments)})},{key:"reactivateUser",value:(Y=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/".concat(encodeURIComponent(t),"/reactivate"),tA({},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:"reactivateUsers",value:(Z=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/reactivate",tA({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 Z.apply(this,arguments)})},{key:"deactivateUser",value:(ee=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/".concat(encodeURIComponent(t),"/deactivate"),tA({},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,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/deactivate",tA({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:(er=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/users/".concat(encodeURIComponent(t),"/export"),tA({},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:"banUser",value:(es=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/moderation/ban",tA({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:"unbanUser",value:(ea=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.delete(this.baseURL+"/moderation/ban",tA({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 ea.apply(this,arguments)})},{key:"shadowBan",value:(eo=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.banUser(t,tA({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 eo.apply(this,arguments)})},{key:"removeShadowBan",value:(ec=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.unbanUser(t,tA({shadow:!0},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:"blockUser",value:(eu=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/block",tA({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 eu.apply(this,arguments)})},{key:"getBlockedUsers",value:(el=(0,a.A)(h().mark(function e(t){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/users/block",tA({},t?{user_id:t}:{}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e){return el.apply(this,arguments)})},{key:"unBlockUser",value:(eh=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/users/unblock",tA({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 eh.apply(this,arguments)})},{key:"muteUser",value:(ed=(0,a.A)(h().mark(function e(t,n){var r,s=arguments;return h().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",tA(tA({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 ed.apply(this,arguments)})},{key:"unmuteUser",value:(ep=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/moderation/unmute",tA({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,a.A)(h().mark(function e(t){var n,r=arguments;return h().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",tA({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,a.A)(h().mark(function e(t){var n,r=arguments;return h().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",tA({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,a.A)(h().mark(function e(t){var n,r=arguments;return h().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",tA({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,a.A)(h().mark(function e(t){var n,r=arguments;return h().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",tA({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,a.A)(h().mark(function e(t){var n,r=arguments;return h().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)),tA({},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,a.A)(h().mark(function e(){var t,n,r=arguments;return h().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",tA({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,a.A)(h().mark(function e(){var t,n,r=arguments;return h().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",tA({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,a.A)(h().mark(function e(t,n){var r,s=arguments;return h().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)),tA({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:(eA=(0,a.A)(h().mark(function e(t){var n,r=arguments;return h().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",tA({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 eA.apply(this,arguments)})},{key:"markChannelsRead",value:(eC=(0,a.A)(h().mark(function e(){var t,n=arguments;return h().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",tA({},t));case 3:case"end":return e.stop()}},e,this)})),function(){return eC.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,p.A)({},{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:(eS=(0,a.A)(h().mark(function e(t,n){return h().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 eS.apply(this,arguments)})},{key:"translate",value:(eO=(0,a.A)(h().mark(function e(t,n,r){return h().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 eO.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 tx(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:(eI=(0,a.A)(h().mark(function e(t,n,r){var s;return h().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,p.A)({},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&&(tx(n)?s.user_id=n:s.user={id:n.id}),Array.isArray(s.mentioned_users)&&!tx(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)),tA({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 eI.apply(this,arguments)})},{key:"partialUpdateMessage",value:(eL=(0,a.A)(h().mark(function e(t,n,r,s){var i;return h().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&&tx(r)&&(i={id:r}),e.next=6,this.put(this.baseURL+"/messages/".concat(encodeURIComponent(t)),tA(tA(tA({},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 eL.apply(this,arguments)})},{key:"deleteMessage",value:(eD=(0,a.A)(h().mark(function e(t,n){var r;return h().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 eD.apply(this,arguments)})},{key:"undeleteMessage",value:(eT=(0,a.A)(h().mark(function e(t,n){return h().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 eT.apply(this,arguments)})},{key:"getMessage",value:(ej=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(this.baseURL+"/messages/".concat(encodeURIComponent(t)),tA({},n));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return ej.apply(this,arguments)})},{key:"queryThreads",value:(eF=(0,a.A)(h().mark(function e(){var t,n,r=this,s=arguments;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=tA({limit:10,participant_limit:10,reply_limit:3,watch:!0},s.length>0&&void 0!==s[0]?s[0]:{}),e.next=4,this.post("".concat(this.baseURL,"/threads"),t);case 4:return n=e.sent,e.abrupt("return",{threads:n.threads.map(function(e){return new eZ({client:r,threadData:e})}),next:n.next});case 6:case"end":return e.stop()}},e,this)})),function(){return eF.apply(this,arguments)})},{key:"getThread",value:(eq=(0,a.A)(h().mark(function e(t){var n,r,s,i=arguments;return h().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=tA({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 eZ({client:this,threadData:s.thread}));case 8:case"end":return e.stop()}},e,this)})),function(e){return eq.apply(this,arguments)})},{key:"partialUpdateThread",value:(eW=(0,a.A)(h().mark(function e(t,n){var r,s;return h().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=h().keys(tA(tA({},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 eW.apply(this,arguments)})},{key:"getUserAgent",value:function(){if(this.userAgent)return this.userAgent;var e,t="8.58.0",n="";n=this.sdkIdentifier?"stream-chat-".concat(this.sdkIdentifier.name,"-v").concat(this.sdkIdentifier.version,"-llc-v").concat(t):"stream-chat-js-v".concat(t,"-").concat(this.node?"node":"browser");var r=null!=(e=this.deviceIdentifier)?e:{};return[["os",r.os],["device_model",r.model],["client_bundle",""]].reduce(function(e,t){var n=(0,d.A)(t,2),r=n[0],s=n[1];return s&&s.length>0?e.concat("|".concat(r,"=").concat(s)):e},n)}},{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)&&e["x-client-request-id"]||(t.headers=tA(tA({},t.headers),{},{"x-client-request-id":V()}));var s=this.options.axiosRequestConfig||{},i=s.params,a=s.headers,o=(0,v.A)(s,tb);return tA(tA(tA({params:tA(tA({user_id:this.userID,connection_id:this._getConnectionID(),api_key:this.key},t.params),i||{}),headers:tA(tA(tA({},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=U.from(t,"utf8"),s=null.createHmac("sha256",r).update(e).digest("hex");try{return null.timingSafeEqual(U.from(s),U.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"),tA({},e))}},{key:"updatePermission",value:function(e,t){return this.put("".concat(this.baseURL,"/permissions/").concat(encodeURIComponent(e)),tA({},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"),tA({channel_cids:e,last_sync_at:t},n))}},{key:"sendUserCustomEvent",value:(eB=(0,a.A)(h().mark(function e(t,n){return h().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 eB.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=tA({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,f.A)(e)?new P(this,null,e):new P(this,e,t)}},{key:"segment",value:function(e,t,n){return"string"==typeof t?new eH(this,e,t,n):new eH(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:(ez=(0,a.A)(h().mark(function e(t,n,r){var s;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),s=tA({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 ez.apply(this,arguments)})},{key:"createUserSegment",value:(eJ=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.createSegment("user",t,n));case 2:case"end":return e.stop()}},e,this)})),function(e,t){return eJ.apply(this,arguments)})},{key:"createChannelSegment",value:(eK=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.createSegment("channel",t,n));case 2:case"end":return e.stop()}},e,this)})),function(e,t){return eK.apply(this,arguments)})},{key:"getSegment",value:(eG=(0,a.A)(h().mark(function e(t){return h().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 eG.apply(this,arguments)})},{key:"updateSegment",value:(eQ=(0,a.A)(h().mark(function e(t,n){return h().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 eQ.apply(this,arguments)})},{key:"addSegmentTargets",value:(e$=(0,a.A)(h().mark(function e(t,n){var r;return h().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 e$.apply(this,arguments)})},{key:"querySegmentTargets",value:(eX=(0,a.A)(h().mark(function e(t){var n,r,s,i=arguments;return h().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"),tA({filter:n||{},sort:r||[]},s)));case 5:case"end":return e.stop()}},e,this)})),function(e){return eX.apply(this,arguments)})},{key:"removeSegmentTargets",value:(eY=(0,a.A)(h().mark(function e(t,n){var r;return h().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 eY.apply(this,arguments)})},{key:"querySegments",value:(e0=(0,a.A)(h().mark(function e(t,n){var r,s=arguments;return h().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",tA({filter:t,sort:n},r)));case 3:case"end":return e.stop()}},e,this)})),function(e,t){return e0.apply(this,arguments)})},{key:"deleteSegment",value:(e1=(0,a.A)(h().mark(function e(t){return h().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 e1.apply(this,arguments)})},{key:"segmentTargetExists",value:(e2=(0,a.A)(h().mark(function e(t,n){return h().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 e2.apply(this,arguments)})},{key:"createCampaign",value:(e3=(0,a.A)(h().mark(function e(t){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.abrupt("return",this.post(this.baseURL+"/campaigns",tA({},t)));case 2:case"end":return e.stop()}},e,this)})),function(e){return e3.apply(this,arguments)})},{key:"getCampaign",value:(e4=(0,a.A)(h().mark(function e(t,n){return h().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)),tA({},null==n?void 0:n.users)));case 2:case"end":return e.stop()}},e,this)})),function(e,t){return e4.apply(this,arguments)})},{key:"startCampaign",value:(e5=(0,a.A)(h().mark(function e(t,n){return h().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:(e7=(0,a.A)(h().mark(function e(t,n,r){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.validateServerSideAuth(),e.next=3,this.post(this.baseURL+"/campaigns/query",tA({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 e7.apply(this,arguments)})},{key:"updateCampaign",value:(e8=(0,a.A)(h().mark(function e(t,n){return h().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 e8.apply(this,arguments)})}
1,{key:"deleteCampaign",value:(e9=(0,a.A)(h().mark(function e(t){return h().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 e9.apply(this,arguments)})},{key:"stopCampaign",value:(te=(0,a.A)(h().mark(function e(t){return h().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 te.apply(this,arguments)})},{key:"enrichURL",value:(tn=(0,a.A)(h().mark(function e(t){return h().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 tn.apply(this,arguments)})},{key:"getTask",value:(tr=(0,a.A)(h().mark(function e(t){return h().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 tr.apply(this,arguments)})},{key:"deleteChannels",value:(ts=(0,a.A)(h().mark(function e(t){var n,r=arguments;return h().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",tA({cids:t},n));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(e){return ts.apply(this,arguments)})},{key:"deleteUsers",value:(ti=(0,a.A)(h().mark(function e(t){var n,r=arguments;return h().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",tA({user_ids:t},n));case 9:return e.abrupt("return",e.sent);case 10:case"end":return e.stop()}},e,this)})),function(e){return ti.apply(this,arguments)})},{key:"_createImportURL",value:(ta=(0,a.A)(h().mark(function e(t){return h().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 ta.apply(this,arguments)})},{key:"_createImport",value:(to=(0,a.A)(h().mark(function e(t){var n,r=arguments;return h().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",tA({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,a.A)(h().mark(function e(t){return h().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,a.A)(h().mark(function e(t){return h().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,a.A)(h().mark(function e(t){return h().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,a.A)(h().mark(function e(t){var n,r;return h().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:(tp=(0,a.A)(h().mark(function e(){return h().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 tp.apply(this,arguments)})},{key:"createAbortControllerForNextRequest",value:function(){return this.nextRequestAbortController=new AbortController}},{key:"commitMessage",value:(tf=(0,a.A)(h().mark(function e(t){return h().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 tf.apply(this,arguments)})},{key:"createPoll",value:(tv=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/polls",tA(tA({},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:"getPoll",value:(tg=(0,a.A)(h().mark(function e(t,n){return h().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 tg.apply(this,arguments)})},{key:"updatePoll",value:(t_=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.put(this.baseURL+"/polls",tA(tA({},t),n?{user_id:n}:{}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(e,t){return t_.apply(this,arguments)})},{key:"partialUpdatePoll",value:(tk=(0,a.A)(h().mark(function e(t,n,r){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.patch(this.baseURL+"/polls/".concat(encodeURIComponent(t)),tA(tA({},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 tk.apply(this,arguments)})},{key:"deletePoll",value:(tC=(0,a.A)(h().mark(function e(t,n){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.delete(this.baseURL+"/polls/".concat(encodeURIComponent(t)),tA({},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 tC.apply(this,arguments)})},{key:"closePoll",value:(tS=(0,a.A)(h().mark(function e(t,n){return h().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 tS.apply(this,arguments)})},{key:"createPollOption",value:(tU=(0,a.A)(h().mark(function e(t,n,r){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.post(this.baseURL+"/polls/".concat(encodeURIComponent(t),"/options"),tA(tA({},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:"getPollOption",value:(tR=(0,a.A)(h().mark(function e(t,n,r){return h().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 tR.apply(this,arguments)})},{key:"updatePollOption",value:(tO=(0,a.A)(h().mark(function e(t,n,r){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.put(this.baseURL+"/polls/".concat(encodeURIComponent(t),"/options"),tA(tA({},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 tO.apply(this,arguments)})},{key:"deletePollOption",value:(tI=(0,a.A)(h().mark(function e(t,n,r){return h().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,a.A)(h().mark(function e(t,n,r,s){return h().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"),tA({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,a.A)(h().mark(function e(t,n,r,s){return h().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,a.A)(h().mark(function e(t,n,r,s){return h().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)),tA({},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,a.A)(h().mark(function e(){var t,n,r,s,i,a=arguments;return h().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),tA({filter:t,sort:q(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,a.A)(h().mark(function e(t){var n,r,s,i,a,o=arguments;return h().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),tA({filter:n,sort:q(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:(tT=(0,a.A)(h().mark(function e(t){var n,r,s,i,a,o=arguments;return h().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),tA({filter:tA(tA({},n),{},{is_answer:!0}),sort:q(r)},s));case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}},e,this)})),function(e){return tT.apply(this,arguments)})},{key:"queryMessageHistory",value:(tj=(0,a.A)(h().mark(function e(){var t,n,r,s=arguments;return h().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",tA({filter:t,sort:q(n)},r));case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}},e,this)})),function(){return tj.apply(this,arguments)})},{key:"updateFlags",value:(tF=(0,a.A)(h().mark(function e(t,n){var r,s=arguments;return h().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",tA({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 tF.apply(this,arguments)})},{key:"queryDrafts",value:(tq=(0,a.A)(h().mark(function e(){var t,n=arguments;return h().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+"/drafts/query",t);case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)})),function(){return tq.apply(this,arguments)})}],[{key:"getInstance",value:function(e,t,n){return tN._instance||("string"==typeof t?tN._instance=new tN(e,t,n):tN._instance=new tN(e,t)),tN._instance}}]),tN}();(0,u.A)(tC,"_instance",void 0);var tS="Allow",tU=["*"],tR=["*"],tO=function e(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:tU,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:tR,i=arguments.length>4&&void 0!==arguments[4]&&arguments[4],a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:tS;(0,o.A)(this,e),(0,u.A)(this,"name",void 0),(0,u.A)(this,"action",void 0),(0,u.A)(this,"owner",void 0),(0,u.A)(this,"priority",void 0),(0,u.A)(this,"resources",void 0),(0,u.A)(this,"roles",void 0),this.name=t,this.action=a,this.owner=i,this.priority=n,this.resources=r,this.roles=s};new tO("Allow all",999,tU,tR,!1,tS),new tO("Deny all",1,tU,tR,!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.