-
Notifications
You must be signed in to change notification settings - Fork 16
/
feedChannel.js
1 lines (1 loc) · 35.8 KB
/
feedChannel.js
1
import{e,u as t,c as n,w as r,s as a,g as i,p as o,q as s,_ as c,b as u,ag as l,t as h,b9 as d,B as f,A as p,d as v,f as _,h as g,bh as y,aA as m,a as C,bq as b,aR as w,Q as E,V as M,av as T,W as N,br as k,z as x,a2 as I,C as S,O as A,a9 as U,G as D,ao as F,bl as R,ax as O,aj as P,ba as H,bb as L,aB as j,aP as G,a$ as V}from"./lib/__bundle-2f7467b8.js";import{i as B,aO as z,ak as q,aP as Q,ac as W,aQ as K,aR as J,T as Y,z as X,aS as Z,aT as $}from"./lib/__bundle-d4f5ef6d.js";export{ak as NotificationMessage,aR as NotificationMessageStatus}from"./lib/__bundle-d4f5ef6d.js";import{y as ee,z as te,A as ne,B as re,o as ae,E as ie,F as oe,I as se,b as ce}from"./lib/__bundle-1a70f031.js";import{g as ue,N as le}from"./lib/__bundle-27dc6a30.js";import{D as he}from"./lib/__bundle-04894092.js";import{B as de,C as fe,a as pe}from"./lib/__bundle-5d883d52.js";import"./lib/__bundle-acd77193.js";var ve=function(){function n(e){this.id=e.id,this.name=e.name,this.isDefault=e.is_default}return n.payloadify=function(n){return e(t({id:n.id,name:n.name,is_default:n.isDefault}))},Object.defineProperty(n.prototype,"customType",{get:function(){return this.isDefault?"*":String(this.id)},enumerable:!1,configurable:!0}),n}(),_e=function(t){function l(e,n){var r=n.sdkState,a=n.cacheContext,i=n.channelManager,o=t.call(this,e)||this;return o._channels=new Map,o._sdkState=r,o._cacheContext=a,o._channelManager=i,o}return n(l,t),Object.defineProperty(l.prototype,"collection",{get:function(){var e=this._cacheContext.nestdb;return r(!!e).throw(a.databaseError),e.collection(B)},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"localCacheEnabled",{get:function(){return this._cacheContext.localCacheEnabled&&!!this.collection},enumerable:!1,configurable:!0}),l.prototype._serialize=function(e,t){return void 0===t&&(t=0),i(i({},e.serialize()),{lastMessageUpdatedAt:e.lastMessage?e.lastMessage.createdAt:0,syncIndex:t})},l.prototype._deserialize=function(e){return this._channelManager.buildFeedChannelFromSerializedData(e)},Object.defineProperty(l.prototype,"channels",{get:function(){return o([],s(this._channels.values()),!1)},enumerable:!1,configurable:!0}),l.prototype.isCachedInMemory=function(e){return this._channels.has(e)},l.prototype.get=function(e){return c(this,void 0,void 0,(function(){var t;return u(this,(function(n){switch(n.label){case 0:return this._channels.has(e)?[3,3]:this.localCacheEnabled?[4,this.collection.getByKey(e)]:[3,2];case 1:if(t=n.sent())return this._channels.set(e,this._deserialize(t)),[2,this._channels.get(e)];n.label=2;case 2:return[2,void 0];case 3:return[2,this._channels.get(e)]}}))}))},l.prototype.fetch=function(e){var t=e.token,n=e.limit,r=void 0===n?z:n,a=e.backward,i=void 0!==a&&a,o=e.order,s=void 0===o?"latest_last_message":o,l=e.borderlineChannelUrl;return c(this,void 0,void 0,(function(){var e,n,a,o,c=this;return u(this,(function(u){switch(u.label){case 0:return this.localCacheEnabled?(e=ue(s),n={where:function(e){if(t&&"latest_last_message"===s)if(!i&&e.lastMessageUpdatedAt>t||i&&e.lastMessageUpdatedAt<t)return!1;return!l||l!==e.url},index:e,backward:i},[4,this.collection.query(n)]):[3,3];case 1:return[4,u.sent().fetch({limit:r})];case 2:return a=u.sent(),(o=a.map((function(e){return c._deserialize(e)}))).forEach((function(e){c._channels.has(e.url)||c._channels.set(e.url,e)})),[2,o];case 3:return[2,[]]}}))}))},l.prototype.upsert=function(t){return c(this,void 0,void 0,(function(){var n,r,a,i=this;return u(this,(function(o){switch(o.label){case 0:if(n=[],t.forEach((function(t){if(i._channels.has(t.url)){var r=i._channels.get(t.url),a=e(t);Object.assign(r,a,{_iid:i._iid}),n.push(r)}else i._channels.set(t.url,t),n.push(t)})),!this.localCacheEnabled)return[3,2];for(r=[],a=0;a<n.length;a++)r.push(this._serialize(n[a],a));return[4,this.collection.upsertMany(r)];case 1:o.sent(),o.label=2;case 2:return[2,n]}}))}))},l.prototype.remove=function(e){return c(this,void 0,void 0,(function(){var t,n,r,a,i,o;return u(this,(function(s){switch(s.label){case 0:s.trys.push([0,5,6,7]),t=h(e),n=t.next(),s.label=1;case 1:return n.done?[3,4]:(r=n.value,this._channels.delete(r),this.localCacheEnabled?[4,this.collection.remove(r)]:[3,3]);case 2:s.sent(),s.label=3;case 3:return n=t.next(),[3,1];case 4:return[3,7];case 5:return a=s.sent(),i={error:a},[3,7];case 6:try{n&&!n.done&&(o=t.return)&&o.call(t)}finally{if(i)throw i.error}return[7];case 7:return[2]}}))}))},l.prototype.clear=function(){return c(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return this.clearMemoryCache(),this.localCacheEnabled?[4,this.collection.clear()]:[3,2];case 1:e.sent(),e.label=2;case 2:return[2]}}))}))},l.prototype.clearMemoryCache=function(){this._channels.clear()},l}(l),ge=function(e){function t(t){var n=t.channels,r=t.context,a=t.isWebSocketEventComing,i=void 0!==a&&a,o=e.call(this)||this;return o.channels=n,o.context=r,o.isWebSocketEventComing=i,o}return n(t,e),t}(d),ye=function(e){function t(t){var n=t.channelUrls,r=t.context,a=t.isWebSocketEventComing,i=void 0!==a&&a,o=e.call(this)||this;return o.channelUrls=n,o.context=r,o.isWebSocketEventComing=i,o}return n(t,e),t}(d),me=function(){function e(e){var t=e.feedChannelCache,n=e.notificationMessageCache,r=e.dispatcher,a=this;this._observers=new Map,r.on((function(e){return c(a,void 0,void 0,(function(){var r,a,i,o,s,l,d=this;return u(this,(function(p){switch(p.label){case 0:return e instanceof ge?(r=e.channels,s=e.context,l=e.isWebSocketEventComing,a=r.filter((function(e){return e instanceof Ge})),[4,t.upsert(a)]):[3,3];case 1:return i=p.sent(),[4,Promise.all(a.map((function(e){return n.markAsReadByTimestamp(e.url,e.myLastRead)})))];case 2:return p.sent(),l||this._broadcastUpdateEvent(i,s),[3,8];case 3:return e instanceof ye?(o=e.channelUrls,s=e.context,l=e.isWebSocketEventComing,[4,t.remove(o)]):[3,6];case 4:return p.sent(),[4,f((function(){return c(d,void 0,void 0,(function(){var e,t,r,a,i,s;return u(this,(function(c){switch(c.label){case 0:c.trys.push([0,5,6,7]),e=h(o),t=e.next(),c.label=1;case 1:return t.done?[3,4]:(r=t.value,[4,n.removeMessagesOfChannel(r)]);case 2:c.sent(),c.label=3;case 3:return t=e.next(),[3,1];case 4:return[3,7];case 5:return a=c.sent(),i={error:a},[3,7];case 6:try{t&&!t.done&&(s=e.return)&&s.call(e)}finally{if(i)throw i.error}return[7];case 7:return[2]}}))}))}))];case 5:return p.sent(),l||this._broadcastRemoveEvent(o,s),[3,8];case 6:return e instanceof he?[4,t.fetch({token:Number.MAX_SAFE_INTEGER,limit:Number.MAX_SAFE_INTEGER})]:[3,8];case 7:p.sent(),p.label=8;case 8:return[2]}}))}))}))}return e.prototype._broadcastUpdateEvent=function(e,t){var n,r;try{for(var a=h(this._observers.values()),i=a.next();!i.done;i=a.next()){var o=i.value;o.onUpdate&&o.onUpdate(e,t)}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}},e.prototype._broadcastRemoveEvent=function(e,t){var n,r;try{for(var a=h(this._observers.values()),i=a.next();!i.done;i=a.next()){var o=i.value;o.onRemove&&o.onRemove(e,t)}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}},e.prototype.subscribe=function(e,t){this._observers.set(e,t)},e.prototype.unsubscribe=function(e){this._observers.delete(e)},e.prototype.unsubscribeAll=function(){this._observers.clear()},e}(),Ce=!1,be=function(t){function r(n){var r=t.call(this)||this,a=n.userId,i=n.token,o=n.limit,s=n.includeEmpty;return r.method=p.GET,r.path="".concat(v,"/").concat(encodeURIComponent(a),"/my_group_channels"),r.params=e({token:i,limit:o,show_empty:null!=s?s:Ce,show_read_receipt:!0,show_delivery_receipt:!0,show_member:!0,is_feed_channel:!0,order:"latest_last_message"}),r}return n(r,t),r}(_),we=function(e){function t(t,n){var r=e.call(this,t,n)||this;r.channels=[];var a=n.next,i=n.channels,o=n.ts;return r.token=a,r.ts=null!=o?o:0,r.channels=(null!=i?i:[]).map((function(e){return e.ts=o,new Ge(t,e)})),r}return n(t,e),t}(g),Ee=function(e){function t(t){var n=t.channelUrl,r=t.isInternalCall,a=e.call(this)||this;return a.method=p.GET,a.path="".concat(r?y:m,"/").concat(encodeURIComponent(n)),a.params={show_member:!0,show_read_receipt:!0,show_delivery_receipt:!0,is_feed_channel:!0},a}return n(t,e),t}(_),Me=function(e){function t(t,n){var r=e.call(this,t,n)||this;return r.channel=new Ge(t,n),r}return n(t,e),t}(g),Te={includeEmpty:!0},Ne=function(e){return C("boolean",e.includeEmpty)},ke=function(r){function a(n){var a=n.userId,o=n.ts,s=n.token,c=n.params,u=r.call(this)||this,l=i(i({},Te),c).includeEmpty;return u.method=p.GET,u.path="".concat(v,"/").concat(encodeURIComponent(a),"/my_group_channels/changelogs"),u.params=e(t({show_delivery_receipt:!0,show_member:!0,show_read_receipt:!0,is_feed_channel:!0,show_empty:l,change_ts:o||null,token:s})),u}return n(a,r),a}(_),xe=function(e){function t(t,n){var r=e.call(this,t,n)||this;return r.updatedChannels=n.updated.map((function(e){return new Ge(t,e)})),r.deletedChannelUrls=n.deleted,r.hasMore=n.has_more,r.token=n.next,r}return n(t,e),t}(g),Ie=function(e){function t(){var t=e.call(this)||this;return t.method=p.GET,t.path="".concat(b,"/settings"),t}return n(t,e),t}(_),Se=function(e){function t(t,n){var r=e.call(this,t,n)||this;return r.jsonString=JSON.stringify(n),r}return n(t,e),t}(g),Ae=function(t){function r(n){var r=this,a=n.reverse,i=void 0!==a&&a,o=n.keys,s=n.limit,c=void 0===s?20:s,u=n.token;return(r=t.call(this)||this).method=p.GET,r.path="".concat(b,"/templates"),r.params=e({token:u,keys:o,limit:c,reverse:i,order:"updated_at",show_ui_template:!0,show_color_variables:!0}),r}return n(r,t),r}(_),Ue=function(e){function t(t,n){var r=e.call(this,t,n)||this,a=n.next,i=n.has_more,o=void 0!==i&&i,s=w(n,["next","has_more"]);return r.nextToken=a,r.hasMore=o,r.notificationTemplateList={jsonString:JSON.stringify(s)},r}return n(t,e),t}(g),De={reverse:!1,keys:void 0,limit:20},Fe=function(t){function r(n){var r=this,a=n.key;return(r=t.call(this)||this).method=p.GET,r.path="".concat(b,"/templates/").concat(a),r.params=e({key:a}),r}return n(r,t),r}(_),Re=function(e){function t(t,n){var r=e.call(this,t,n)||this;return r.jsonString=JSON.stringify(n),r}return n(t,e),t}(g),Oe=function(e){function t(t,n,r){var a,i,o,s=this;(s=e.call(this,t,"ADMM",r)||this).message=new q(t,r);var c=M.of(t).sdkState;return s.isMentioned=T(s.message.mentionType,null!==(o=null!==(a=s.message.mentionedUserIds)&&void 0!==a?a:null===(i=s.message.mentionedUsers)||void 0===i?void 0:i.map((function(e){return e.userId})))&&void 0!==o?o:[],c.userId),s}return n(t,e),t}(N),Pe=function(e){function t(t){var n=t.userId,r=e.call(this)||this;return r.method=p.GET,r.path="".concat(k,"/").concat(encodeURIComponent(n),"/unread_message_count"),r}return n(t,e),t}(_);!function(e){function t(t,n){var r=e.call(this,t,n)||this;return r.unreadFeedCount=n.unread_feed_count,r}n(t,e)}(g);var He={},Le=function(e){function l(t,n){var r=e.call(this,t,i(i({},n),{channelType:S.FEED}))||this;return r._feedChannelHandlers=new Map,r._feedChannelCache=new _e(r._iid,{sdkState:r._sdkState,cacheContext:r._cacheContext,channelManager:r}),r._feedChannelBroadcast=new me({feedChannelCache:r._feedChannelCache,dispatcher:r._dispatcher,notificationMessageCache:Q.of(t)}),r._dispatcher.on((function(e){e instanceof N&&r._handleEvent(e).catch((function(e){if(A(e))throw e}))})),He[t]||(He[t]=r),r}return n(l,e),Object.defineProperty(l.prototype,"_notificationMessageCache",{get:function(){return Q.of(this._iid)},enumerable:!1,configurable:!0}),l.of=function(e){return He[e]||(He[e]=new l(e,M.of(e))),He[e]},l.clear=function(e){He[e]&&delete He[e]},Object.defineProperty(l.prototype,"handlers",{get:function(){return o([],s(this._feedChannelHandlers.values()),!1)},enumerable:!1,configurable:!0}),l.prototype.buildFeedChannelFromSerializedData=function(e){var t=x(e);return new Ge(this._iid,Ge.payloadify(t))},l.prototype.addHandler=function(e,t){this._feedChannelHandlers.set(e,t)},l.prototype.removeHandler=function(e){this._feedChannelHandlers.delete(e)},l.prototype.clearHandler=function(){this._feedChannelHandlers.clear()},l.prototype.getMyFeedChannels=function(e,t,n){return c(this,void 0,void 0,(function(){var r,a,o,s,c;return u(this,(function(u){switch(u.label){case 0:return r=new be(i(i({},t),{userId:this._sdkState.userId,token:e,limit:n})),[4,this._requestQueue.send(r)];case 1:return a=u.sent(),o=a.as(we),s=o.channels,c=o.token,[2,{channels:s,token:c}]}}))}))},l.prototype.getChannel=function(e,t){return void 0===t&&(t=!1),c(this,void 0,void 0,(function(){var n;return u(this,(function(i){switch(i.label){case 0:r(C("string",e)).throw(a.invalidParameters),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,this.getChannelFromCache(e)];case 2:return(n=i.sent())?[2,n]:[3,4];case 3:return i.sent(),[3,4];case 4:return[4,this.getChannelWithoutCache(e,t)];case 5:return[2,i.sent()]}}))}))},l.prototype.getChannelFromCache=function(e){var t;return c(this,void 0,void 0,(function(){return u(this,(function(n){switch(n.label){case 0:return r(C("string",e)).throw(a.invalidParameters),[4,this._feedChannelCache.get(e)];case 1:return[2,null!==(t=n.sent())&&void 0!==t?t:null]}}))}))},l.prototype.getChannelWithoutCache=function(e,t){return void 0===t&&(t=!1),c(this,void 0,void 0,(function(){var n,i,o,c;return u(this,(function(u){switch(u.label){case 0:return r(C("string",e)).throw(a.invalidParameters),n=new Ee({channelUrl:e,isInternalCall:t}),[4,this._requestQueue.send(n)];case 1:return i=u.sent(),o=i.as(Me).channel,[4,this.upsertChannelsToCache([o])];case 2:return c=s.apply(void 0,[u.sent(),1]),[2,c[0]]}}))}))},l.prototype.getMyFeedChannelChangeLogs=function(e,n,o){return void 0===o&&(o=I.REQUEST_CHANNEL_CHANGELOGS),c(this,void 0,void 0,(function(){var s,c,l,h,d,f,p,v;return u(this,(function(u){switch(u.label){case 0:return s=i(i({},Te),n),r((C("string",e)||C("number",e))&&Ne(s)).throw(a.invalidParameters),c=new ke(t({userId:this._sdkState.userId,ts:"number"==typeof e?e:null,token:"string"==typeof e?e:null,params:s})),[4,this._requestQueue.send(c)];case 1:return l=u.sent(),h=l.as(xe),d=h.updatedChannels,f=h.deletedChannelUrls,p=h.hasMore,v=h.token,d.length>0&&this._dispatcher.dispatch(new ge({channels:d,context:{source:o}})),f.length>0&&this._dispatcher.dispatch(new ye({channelUrls:f,context:{source:o}})),[2,{updatedChannels:d,deletedChannelUrls:f,hasMore:p,token:v}]}}))}))},l.prototype.getTotalUnreadMessageCount=function(e){return c(this,void 0,void 0,(function(){var t,n,o,s,c,l,h;return u(this,(function(u){switch(u.label){case 0:return t=i(i({},te),e),r(ne(t)).throw(a.invalidParameters),n=M.of(this._iid),o=n.sdkState,s=n.requestQueue,c=new re({userId:o.userId,filter:t,includeFeedChannel:!0}),[4,s.send(c)];case 1:return l=u.sent(),h=l.as(ee).unreadFeedCount,[2,void 0===h?0:h]}}))}))},l.prototype.getTotalUnreadNotificationCount=function(){return c(this,void 0,void 0,(function(){var e,t,n,r,a,i;return u(this,(function(o){switch(o.label){case 0:return e=M.of(this._iid),t=e.sdkState,n=e.requestQueue,r=new Pe({userId:t.userId}),[4,n.send(r)];case 1:return a=o.sent(),i=a.as(ee).unreadFeedCount,[2,void 0===i?0:i]}}))}))},l.prototype.getGlobalNotificationChannelSetting=function(){return c(this,void 0,void 0,(function(){var e,t;return u(this,(function(n){switch(n.label){case 0:return e=new Ie,[4,this._requestQueue.send(e)];case 1:return t=n.sent(),[2,{jsonString:t.as(Se).jsonString}]}}))}))},l.prototype.getNotificationTemplateListByToken=function(e,t){return void 0===t&&(t={}),c(this,void 0,void 0,(function(){var n,o,s,c,l,h,d;return u(this,(function(u){switch(u.label){case 0:return n=i(i({},De),t),r(C("string",e)&&function(e){return C("boolean",e.reverse,!0)&&E("string",e.keys,!0)&&C("number",e.limit,!0)}(n)).throw(a.invalidParameters),o=new Ae({token:e,keys:n.keys,reverse:n.reverse,limit:n.limit}),[4,this._requestQueue.send(o)];case 1:return s=u.sent(),c=s.as(Ue),l=c.hasMore,h=c.nextToken,d=c.notificationTemplateList,[2,{hasMore:l,token:h,notificationTemplateList:d}]}}))}))},l.prototype.getNotificationTemplate=function(e){return c(this,void 0,void 0,(function(){var t,n;return u(this,(function(i){switch(i.label){case 0:return r(C("string",e)).throw(a.invalidParameters),t=new Fe({key:e}),[4,this._requestQueue.send(t)];case 1:return n=i.sent(),[2,{jsonString:n.as(Re).jsonString}]}}))}))},l.prototype.upsertChannelsToCache=function(e){return c(this,void 0,void 0,(function(){return u(this,(function(t){switch(t.label){case 0:return[4,this._feedChannelCache.upsert(e)];case 1:return[2,t.sent()]}}))}))},l.prototype.removeChannelsFromCache=function(e){return c(this,void 0,void 0,(function(){return u(this,(function(t){switch(t.label){case 0:return[4,this._feedChannelCache.remove(e)];case 1:return t.sent(),[2]}}))}))},l.prototype.getNotificationMessageFromCache=function(e){return c(this,void 0,void 0,(function(){return u(this,(function(t){switch(t.label){case 0:return[4,this._notificationMessageCache.get(e)];case 1:return[2,t.sent()]}}))}))},l.prototype.refreshChannel=function(e,t,n){return void 0===t&&(t=!0),void 0===n&&(n=I.REFRESH_CHANNEL),c(this,void 0,void 0,(function(){var r,a,i,o,s;return u(this,(function(c){switch(c.label){case 0:return c.trys.push([0,5,,6]),r=new Ee({channelUrl:e,isInternalCall:t}),[4,this._requestQueue.send(r)];case 1:return a=c.sent(),(i=a.as(Me).channel).myMemberState!==ae.NONE?[3,2]:(this._dispatcher.dispatch(new ye({channelUrls:[i.url],context:{source:n}})),[3,4]);case 2:return[4,this.upsertChannelsToCache([i])];case 3:o=c.sent(),this._dispatcher.dispatch(new ge({channels:o,context:{source:n}})),c.label=4;case 4:return[3,6];case 5:return(s=c.sent()).code!==U.NON_AUTHORIZED&&s.code!==U.NOT_FOUND_IN_DATABASE||this._dispatcher.dispatch(new ye({channelUrls:[e],context:{source:n}})),[3,6];case 6:return[2]}}))}))},l.prototype.refreshNotificationCollections=function(){this._dispatcher.dispatch(new le)},l.prototype.subscribeChannelEvent=function(e,t){this._feedChannelBroadcast.subscribe(e,t)},l.prototype.unsubscribeChannelEvent=function(e){this._feedChannelBroadcast.unsubscribe(e)},l.prototype._handleEvent=function(e){return c(this,void 0,void 0,(function(){var t,n,r,a,i,o,s,l,d,f,p=this;return u(this,(function(v){switch(v.label){case 0:switch(e.code){case"ADMM":case"BRDM":return[3,1];case"READ":return[3,4];case"SYEV":return[3,7]}return[3,13];case 1:return(s="ADMM"===e.code||"BRDM"===e.code?e.as(Oe):null)&&s.message.channelType===this._channelType?(t=s.message,n=s.isMentioned,[4,this.getChannel(t.channelUrl,!0)]):[3,3];case 2:(r=v.sent())._runIfHandleableWithGroupChannel((function(e){var a;t instanceof q&&n&&(null===(a=t.mentionedUsers)||void 0===a||a.forEach((function(t){var n,r;try{for(var a=h(e.members),i=a.next();!i.done;i=a.next()){var o=i.value;if(t.userId===o.userId){t.nickname=o.nickname,t.plainProfileUrl=o.plainProfileUrl,t.metaData=o.metaData;break}}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}}))),p._dispatcher.dispatch(new ge({channels:[r],context:{source:I.EVENT_MESSAGE_RECEIVED}})),p._dispatcher.dispatch(new F({messages:[t],source:I.EVENT_MESSAGE_RECEIVED})),D((function(){return c(p,void 0,void 0,(function(){var e,a,i,o,s;return u(this,(function(c){try{for(e=h(this._feedChannelHandlers.values()),a=e.next();!a.done;a=e.next())(i=a.value).onMessageReceived&&i.onMessageReceived(r,t),n&&i.onMentionReceived&&i.onMentionReceived(r,t)}catch(e){o={error:e}}finally{try{a&&!a.done&&(s=e.return)&&s.call(e)}finally{if(o)throw o.error}}return[2]}))}))}))})),v.label=3;case 3:return[3,13];case 4:return(s="READ"===e.code?e.as(W):null)&&s.readStatus.channelType===this._channelType?(a=s.readStatus,i=this._feedChannelCache.isCachedInMemory(a.channelUrl),[4,this.getChannel(a.channelUrl,!0)]):[3,6];case 5:(o=v.sent())._runIfHandleableWithGroupChannel((function(e){i&&e._updateUnreadMemberState(a.reader.userId,a.readAt),a.reader.userId===p._sdkState.userId&&(i?(e.unreadMessageCount>0||e.unreadMentionCount>0)&&(e._updateUnreadCount(0,0),p._dispatcher.dispatch(new ge({channels:[o],context:{source:I.EVENT_CHANNEL_READ}})),D((function(){return c(p,void 0,void 0,(function(){var e,t,n,r,a;return u(this,(function(i){try{for(e=h(this._feedChannelHandlers.values()),t=e.next();!t.done;t=e.next())(n=t.value).onChannelChanged&&n.onChannelChanged(o)}catch(e){r={error:e}}finally{try{t&&!t.done&&(a=e.return)&&a.call(e)}finally{if(r)throw r.error}}return[2]}))}))}))):0!==e.unreadMessageCount&&0!==e.unreadMentionCount||(p._dispatcher.dispatch(new ge({channels:[o],context:{source:I.EVENT_CHANNEL_READ}})),D((function(){return c(p,void 0,void 0,(function(){var e,t,n,r,a;return u(this,(function(i){try{for(e=h(this._feedChannelHandlers.values()),t=e.next();!t.done;t=e.next())(n=t.value).onChannelChanged&&n.onChannelChanged(o)}catch(e){r={error:e}}finally{try{t&&!t.done&&(a=e.return)&&a.call(e)}finally{if(r)throw r.error}}return[2]}))}))}))))})),v.label=6;case 6:return[3,13];case 7:if(!(s="SYEV"===e.code?e.as(fe):null)||s.event.channelType!==this._channelType)return[3,12];switch(l=s.event,l.category){case pe.CHANNEL_DELETED:return[3,8];case pe.CHANNEL_PROP_CHANGED:return[3,10]}return[3,12];case 8:return[4,this.getChannel(l.channelUrl,!0)];case 9:return d=v.sent(),this._dispatcher.dispatch(new ye({channelUrls:[l.channelUrl],context:{source:I.EVENT_CHANNEL_DELETED}})),D((function(){return c(p,void 0,void 0,(function(){return u(this,(function(e){return this._feedChannelHandlers.forEach((function(e){e.onChannelDeleted&&e.onChannelDeleted(d.url,d.channelType)})),[2]}))}))})),[3,12];case 10:return[4,this.getChannelWithoutCache(l.channelUrl,!0)];case 11:return f=v.sent(),this._dispatcher.dispatch(new ge({channels:[f],context:{source:I.EVENT_CHANNEL_UPDATED}})),D((function(){return c(p,void 0,void 0,(function(){return u(this,(function(e){return this._feedChannelHandlers.forEach((function(e){e.onChannelChanged&&e.onChannelChanged(f)})),[2]}))}))})),[3,12];case 12:return[3,13];case 13:return[2]}}))}))},l.prototype.getMessageFromCache=function(e){var t;return c(this,void 0,void 0,(function(){return u(this,(function(n){switch(n.label){case 0:return[4,this._notificationMessageCache.get(e)];case 1:return[2,null!==(t=n.sent())&&void 0!==t?t:null]}}))}))},l.prototype.getExactlyMatchingMessagesForTokenFromCache=function(e,t,n){return c(this,void 0,void 0,(function(){return u(this,(function(r){switch(r.label){case 0:return[4,this._notificationMessageCache.fetch({channelUrl:e,token:t,filter:n,exactMatch:!0})];case 1:return[2,r.sent()]}}))}))},l.prototype.getMessagesFromCache=function(e,t,n,r,a,i){return void 0===a&&(a=K),void 0===i&&(i=!0),c(this,void 0,void 0,(function(){return u(this,(function(o){switch(o.label){case 0:return[4,this._notificationMessageCache.fetch({channelUrl:e,token:t,limit:a,filter:r,backward:"next"===n,inclusive:i})];case 1:return[2,o.sent()]}}))}))},l}(de),je=function(e){function t(t,n){var r=e.call(this,t,i(i({},n),{channelManager:Le.of(t)}))||this,a=M.of(r._iid),o=a.connectionManager,s=a.dispatcher;return r._notificationCollectionEventContext=s.on((function(e){e instanceof le&&O(10).then((function(){o.isConnected||o.isConnecting||r.refresh()}))})),r}return n(t,e),t.prototype.keyOf=function(e){return e.notificationId},Object.defineProperty(t.prototype,"changelogIncludeParams",{get:function(){return{includeReactions:!1,includeThreadInfo:!0,includeMetaArray:!0,includeParentMessageInfo:!0}},enumerable:!1,configurable:!0}),t.prototype.dispose=function(){e.prototype.dispose.call(this),this._notificationCollectionEventContext.close()},t.prototype.setMessageCollectionHandler=function(e){this._setBaseMessageCollectionHandler(e)},t.prototype._postprocessChannelUpdateEvent=function(e,t){var n,r,a=this._messages.filter((function(t){return t.messageStatus===J.SENT&&t.createdAt<=e.myLastRead}));if(a.length>0){try{for(var i=h(a),o=i.next();!o.done;o=i.next()){o.value.messageStatus=J.READ}}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}this._updateMessagesToView(a,t)}},t.prototype._postprocessMessageUpdateEvent=function(e,t){var n,r;if(t===I.EVENT_CHANNEL_READ){var a=[],i=this._messages.map((function(e){return e.notificationId}));try{for(var o=h(e),s=o.next();!s.done;s=o.next()){var c=s.value.notificationId,u=i.indexOf(c);u>=0&&(this._messages[u].messageStatus=J.READ,a.push(this._messages[u]))}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}a.length>0&&this._updateMessagesToView(a,t)}},t.prototype._addMessagesToView=function(e,t){var n,r,a=this,i=this._filterUnderOffsetMessage(e),o=[],s=[];try{for(var l=h(i),d=l.next();!d.done;d=l.next()){var f,p=d.value;if(t===I.SYNC_MESSAGE_FILL){if((f=ie(this._messages,p))<0){var v=oe(this._messages,p);this._messages.splice(v,0,p),o.push(p)}}else if((f=ie(this._messages,p))<0){v=oe(this._messages,p);this._messages.splice(v,0,p),o.push(p)}else this._messages[f]=p,s.push(p)}}catch(e){n={error:e}}finally{try{d&&!d.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}R(t)&&D((function(){return c(a,void 0,void 0,(function(){var e,n,r,a,i;return u(this,(function(c){return e={source:t},o.length>0&&(null===(r=null===(n=this._handler)||void 0===n?void 0:n.onMessagesAdded)||void 0===r||r.call(n,e,this.channel,o)),s.length>0&&(null===(i=null===(a=this._handler)||void 0===a?void 0:a.onMessagesUpdated)||void 0===i||i.call(a,e,this.channel,s)),[2]}))}))}))},t.prototype._updateMessagesToView=function(e,t){var n,r,a=this,i=[];try{for(var o=h(e),s=o.next();!s.done;s=o.next()){var l=s.value,d=ie(this._messages,l);d>=0&&(i.push(l),this._messages[d]=l)}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return R(t)&&D((function(){return c(a,void 0,void 0,(function(){var e,n,r;return u(this,(function(a){return e={source:t},i.length>0&&(null===(r=null===(n=this._handler)||void 0===n?void 0:n.onMessagesUpdated)||void 0===r||r.call(n,e,this.channel,i)),[2]}))}))})),i},t.prototype.refresh=function(){return c(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,this._activate()];case 1:return e.sent(),[2]}}))}))},t}(se),Ge=function(e){function t(t,n){var r,a,o=this;return(o=e.call(this,t,n)||this).channelType=S.FEED,o._groupChannel=new ce(t,n),o.isCategoryFilterEnabled=null!==(r=n.is_category_filter_enabled)&&void 0!==r&&r,o.isTemplateLabelEnabled=null===(a=n.is_template_label_enabled)||void 0===a||a,o.notificationCategories=n.categories?n.categories.map((function(e){return new ve(e)})):[],o.lastMessage=n.last_message?Y(o._iid,i({channel_type:o.channelType},n.last_message)):null,o}return n(t,e),t.payloadify=function(e){var t;return i(i({},ce.payloadify(null!==(t=e._groupChannel)&&void 0!==t?t:e)),{is_category_filter_enabled:e.isCategoryFilterEnabled,is_template_label_enabled:e.isTemplateLabelEnabled,categories:e.notificationCategories.map((function(e){return ve.payloadify(e)})),last_message:e.lastMessage?q.payloadify(e.lastMessage):null})},Object.defineProperty(t.prototype,"groupChannel",{get:function(){return this._groupChannel},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"url",{get:function(){return this._groupChannel.url},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"name",{get:function(){return this._groupChannel.name},set:function(e){this._groupChannel.name=e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"createdAt",{get:function(){return this._groupChannel.createdAt},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"members",{get:function(){return this._groupChannel.members},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"memberCount",{get:function(){return this._groupChannel.memberCount},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"myMemberState",{get:function(){return this._groupChannel.myMemberState},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"myLastRead",{get:function(){return this._groupChannel.myLastRead},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"unreadMessageCount",{get:function(){return this._groupChannel.unreadMessageCount},enumerable:!1,configurable:!0}),t.prototype.serialize=function(){var e,t;return i(i({},this._groupChannel.serialize()),{notificationCategories:this.notificationCategories.map((function(e){return P(e)})),lastMessage:null!==(t=null===(e=this.lastMessage)||void 0===e?void 0:e.serialize())&&void 0!==t?t:null})},t.prototype.refresh=function(){return c(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,this._groupChannel._refresh(!0)];case 1:return e.sent(),[2,this]}}))}))},t.prototype.markAsRead=function(e){return c(this,void 0,void 0,(function(){var t,n,r,a,i,o,s,c,l,h,d=this;return u(this,(function(u){switch(u.label){case 0:return t=M.of(this._iid),n=t.sdkState,r=t.dispatcher,a=t.requestQueue,!(i=null==e?void 0:e.filter((function(e){return!e||e.messageStatus===J.SENT})).map((function(e){return e.notificationId})))||i.length>0?(o=new $({userId:n.userId,channelUrl:this.url,channelType:S.FEED,notificationIds:i}),[4,a.send(o)]):[3,2];case 1:s=u.sent(),c=s.as(Z),l=c.unreadMessageCount,h=c.readAt,e?("number"==typeof l&&(this._groupChannel._updateUnreadCount(l,this._groupChannel.unreadMentionCount),Le.of(this._iid).handlers.map((function(e){e.onChannelChanged&&e.onChannelChanged(d)}))),e.forEach((function(e){e.messageStatus=J.READ})),r.dispatch(new F({messages:e,source:I.EVENT_CHANNEL_READ}))):(this._groupChannel._updateUnreadMemberState(n.userId,h),this._groupChannel.unreadMessageCount!==l&&(this._groupChannel._updateUnreadCount(l,0),Le.of(this._iid).handlers.map((function(e){e.onChannelChanged&&e.onChannelChanged(d)})))),r.dispatch(new ge({channels:[this],context:{source:I.EVENT_CHANNEL_READ}})),u.label=2;case 2:return[2]}}))}))},t.prototype.markAsClicked=function(e){return c(this,void 0,void 0,(function(){return u(this,(function(t){switch(t.label){case 0:return[4,this.logClicked(e)];case 1:return t.sent(),[2]}}))}))},t.prototype.logClicked=function(e){return c(this,void 0,void 0,(function(){var t,n,r,a,i,o;return u(this,(function(s){if(t=M.of(this._iid).statManager,e.length<=30)try{for(n=h(e),r=n.next();!r.done;r=n.next())(a=r.value)&&a.notificationId&&a.notificationData&&t.put(new H({type:L.NOTIFICATION,ts:Date.now(),data:{action:"clicked",template_key:a.notificationData.templateKey,channel_url:this.url,message_id:a.notificationId,tags:a.notificationData.tags,source:"notification",message_ts:a.createdAt,notification_event_deadline:a.notificationEventDeadline}}))}catch(e){i={error:e}}finally{try{r&&!r.done&&(o=n.return)&&o.call(n)}finally{if(i)throw i.error}}return[2]}))}))},t.prototype.logImpression=function(e){return c(this,void 0,void 0,(function(){return u(this,(function(t){return[2,this.logViewed(e)]}))}))},t.prototype.logViewed=function(e){return c(this,void 0,void 0,(function(){var t,n,r,a,i,o;return u(this,(function(s){if(t=M.of(this._iid).statManager,e.length<=30){try{for(n=h(e),r=n.next();!r.done;r=n.next())(a=r.value)&&a.notificationId&&a.notificationData&&t.put(new H({type:L.NOTIFICATION,ts:Date.now(),data:{action:"viewed",template_key:a.notificationData.templateKey,channel_url:this.url,message_id:a.notificationId,tags:a.notificationData.tags,source:"notification",message_ts:a.createdAt,notification_event_deadline:a.notificationEventDeadline}}))}catch(e){i={error:e}}finally{try{r&&!r.done&&(o=n.return)&&o.call(n)}finally{if(i)throw i.error}}return[2,!0]}return[2,!1]}))}))},t.prototype.logCustom=function(e,t){return c(this,void 0,void 0,(function(){var n,r,a,i,o,s;return u(this,(function(c){if(n=M.of(this._iid).statManager,0<e.length&&e.length<=15&&t.length<=30){try{for(r=h(t),a=r.next();!a.done;a=r.next())(i=a.value)&&i.notificationId&&i.notificationData&&n.put(new H({type:L.NOTIFICATION,ts:Date.now(),data:{action:"custom",topic:e,template_key:i.notificationData.templateKey,channel_url:this.url,message_id:i.notificationId,tags:i.notificationData.tags,source:"notification",message_ts:i.createdAt,notification_event_deadline:i.notificationEventDeadline}}))}catch(e){o={error:e}}finally{try{a&&!a.done&&(s=r.return)&&s.call(r)}finally{if(o)throw o.error}}return[2,!0]}return[2,!1]}))}))},t.prototype.createNotificationCollection=function(e){return void 0===e&&(e={}),new je(this._iid,i({channel:this},e))},t}(X),Ve=function(e){function t(t){void 0===t&&(t={});var n=e.call(this)||this;return Object.keys(t).forEach((function(e){Object.prototype.hasOwnProperty.call(n,e)&&(n[e]=t[e])})),n}return n(t,e),t}((function(){this.onChannelChanged=j,this.onChannelDeleted=j,this.onMessageReceived=j,this.onMentionReceived=j})),Be=function(e){function r(t,n){var r,a=this;return(a=e.call(this,t,n)||this).includeEmpty=Ce,a.includeEmpty=null!==(r=n.includeEmpty)&&void 0!==r?r:Ce,a}return n(r,e),r.prototype._validate=function(){return e.prototype._validate.call(this)&&C("boolean",this.includeEmpty)},r.prototype.next=function(){return c(this,void 0,void 0,(function(){var e,n,r,o,s;return u(this,(function(c){switch(c.label){case 0:return this._validate()?this._isLoading?[3,3]:this._hasNext?(this._isLoading=!0,e=Le.of(this._iid),n=t(i({},this)),[4,e.getMyFeedChannels(this._token,n,this.limit)]):[3,2]:[3,5];case 1:return r=c.sent(),o=r.channels,s=r.token,this._token=s,this._hasNext=!!s,this._isLoading=!1,[2,o];case 2:return[2,[]];case 3:throw a.queryInProgress;case 4:return[3,6];case 5:throw a.invalidParameters;case 6:return[2]}}))}))},r}(G),ze=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.name="feedChannel",t}return n(t,e),t.prototype.init=function(t,n){e.prototype.init.call(this,t,n),this._manager=new Le(t,n)},t.prototype.buildFeedChannelFromSerializedData=function(e){return this._manager.buildFeedChannelFromSerializedData(e)},t.prototype.createMyFeedChannelListQuery=function(e){return void 0===e&&(e={}),new Be(this._iid,e)},t.prototype.addFeedChannelHandler=function(e,t){r(C("string",e)&&t instanceof Ve).throw(a.invalidParameters),this._manager.addHandler(e,t)},t.prototype.removeFeedChannelHandler=function(e){r(C("string",e)).throw(a.invalidParameters),this._manager.removeHandler(e)},t.prototype.removeAllFeedChannelHandlers=function(){this._manager.clearHandler()},t.prototype.getChannel=function(e){return c(this,void 0,void 0,(function(){return u(this,(function(t){return r(C("string",e)).throw(a.invalidParameters),[2,this._manager.getChannel(e)]}))}))},t.prototype.getMyFeedChannelChangeLogsByTimestamp=function(e,t){return void 0===t&&(t={}),c(this,void 0,void 0,(function(){var n;return u(this,(function(o){switch(o.label){case 0:return n=i(i({},Te),t),r(C("number",e)&&Ne(n)).throw(a.invalidParameters),[4,this._manager.getMyFeedChannelChangeLogs(e,n)];case 1:return[2,o.sent()]}}))}))},t.prototype.getMyFeedChannelChangeLogsByToken=function(e,t){return void 0===t&&(t={}),c(this,void 0,void 0,(function(){var n;return u(this,(function(o){switch(o.label){case 0:return n=i(i({},Te),t),r(C("string",e)&&Ne(n)).throw(a.invalidParameters),[4,this._manager.getMyFeedChannelChangeLogs(e,n)];case 1:return[2,o.sent()]}}))}))},t.prototype.getTotalUnreadMessageCount=function(e){return c(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,this.getTotalUnreadNotificationCount()];case 1:return[2,e.sent()]}}))}))},t.prototype.getTotalUnreadNotificationCount=function(){return c(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,this._manager.getTotalUnreadNotificationCount()];case 1:return[2,e.sent()]}}))}))},t.prototype.getGlobalNotificationChannelSetting=function(){return c(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,this._manager.getGlobalNotificationChannelSetting()];case 1:return[2,e.sent()]}}))}))},t.prototype.getNotificationTemplateListByToken=function(e,t){return void 0===t&&(t={}),c(this,void 0,void 0,(function(){return u(this,(function(n){switch(n.label){case 0:return[4,this._manager.getNotificationTemplateListByToken(e,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.getNotificationTemplate=function(e){return c(this,void 0,void 0,(function(){return u(this,(function(t){switch(t.label){case 0:return[4,this._manager.getNotificationTemplate(e)];case 1:return[2,t.sent()]}}))}))},t.prototype.refreshNotificationCollections=function(){this._manager.refreshNotificationCollections()},t}(V);export{Ge as FeedChannel,Ve as FeedChannelHandler,Be as FeedChannelListQuery,ze as FeedChannelModule,ve as NotificationCategory,je as NotificationCollection};