import {g,aS as kn,aT as to,aC as x,aU as XP,aV as oe,fO as Ue,by as Z,e0 as j1,fP as yHe,aN as $,aW as ln,aX as fe,a9 as Oe,br as lt,dl as Ie,bs as L$1,ao as D,aY as S,bL as J,bM as _o,dF as z}from'./main-BiUBeaMj.js';var I=J(_o());var d=(0, I.default)("peertube:subscriptions:UserSubscriptionService"),B=class c{authHttp=g(kn);restExtractor=g(to);videoService=g(x);restService=g(XP);static BASE_USER_SUBSCRIPTIONS_URL=oe.apiUrl+"/api/v1/users/me/subscriptions";static BASE_VIDEO_CHANNELS_URL=oe.apiUrl+"/api/v1/video-channels";static BASE_ACCOUNTS_URL=oe.apiUrl+"/api/v1/accounts";existsSubject=new Ue(1);existsObservable;myAccountSubscriptionCache={};myAccountSubscriptionCacheObservable={};myAccountSubscriptionCacheSubject=new Z;constructor(){this.existsObservable=j1(yHe({time:200,notifierObservable:this.existsSubject,bulkGet:this.doSubscriptionsExist.bind(this)}).pipe($(t=>t.response)),this.myAccountSubscriptionCacheSubject);}listFollowers(t){let{pagination:e,nameWithHost:i,search:s,channel:a}=t,r=new ln;r=this.restService.addRestGetParams(r,this.restService.componentToRestPagination(e),"-createdAt"),s&&(r=r.append("search",s));let o=a?`${c.BASE_VIDEO_CHANNELS_URL}/${a}/followers`:`${c.BASE_ACCOUNTS_URL}/${i}/followers`;return this.authHttp.get(o,{params:r}).pipe(fe(P=>this.restExtractor.handleError(P)))}getUserSubscriptionVideos(t){let{videoPagination:e,sort:i,skipCount:s}=t,a=this.restService.componentToRestPagination(e),r=new ln;return r=this.restService.addRestGetParams(r,a,i),s&&(r=r.set("skipCount",s+"")),this.authHttp.get(c.BASE_USER_SUBSCRIPTIONS_URL+"/videos",{params:r}).pipe(Oe(o=>this.videoService.extractVideos(o)),fe(o=>this.restExtractor.handleError(o)))}deleteSubscription(t){let e=c.BASE_USER_SUBSCRIPTIONS_URL+"/"+t;return this.authHttp.delete(e).pipe(lt(()=>{this.myAccountSubscriptionCache[t]=false,this.myAccountSubscriptionCacheSubject.next(this.myAccountSubscriptionCache);}),fe(i=>this.restExtractor.handleError(i)))}addSubscription(t){let e=c.BASE_USER_SUBSCRIPTIONS_URL,i={uri:t};return this.authHttp.post(e,i).pipe(lt(()=>{this.myAccountSubscriptionCache[t]=true,this.myAccountSubscriptionCacheSubject.next(this.myAccountSubscriptionCache);}),fe(s=>this.restExtractor.handleError(s)))}listSubscriptions(t){let{pagination:e,search:i}=t,s=c.BASE_USER_SUBSCRIPTIONS_URL,a=this.restService.componentToRestPagination(e),r=new ln;return r=this.restService.addRestGetParams(r,a),i&&(r=r.append("search",i)),this.authHttp.get(s,{params:r}).pipe($(o=>z.extractVideoChannels(o)),fe(o=>this.restExtractor.handleError(o)))}listenToMyAccountSubscriptionCacheSubject(){return this.myAccountSubscriptionCacheSubject.asObservable()}listenToSubscriptionCacheChange(t){if(t in this.myAccountSubscriptionCacheObservable)return this.myAccountSubscriptionCacheObservable[t];let e=this.existsObservable.pipe(Ie(i=>i[t]!==void 0),$(i=>i[t]));return this.myAccountSubscriptionCacheObservable[t]=e,e}doesSubscriptionExist(t){return d("Running subscription check for "+t),t in this.myAccountSubscriptionCache?(d("Found cache for "+t),L$1(this.myAccountSubscriptionCache[t])):(this.existsSubject.next(t),d("Fetching from network for "+t),this.existsObservable.pipe(Ie(e=>e[t]!==void 0),$(e=>e[t]),lt(e=>this.myAccountSubscriptionCache[t]=e)))}doSubscriptionsExist(t){let e=c.BASE_USER_SUBSCRIPTIONS_URL+"/exist",i=new ln;return i=this.restService.addObjectParams(i,{uris:t}),this.authHttp.get(e,{params:i}).pipe(lt(s=>{this.myAccountSubscriptionCache=D(D({},this.myAccountSubscriptionCache),s);}),fe(s=>this.restExtractor.handleError(s)))}static \u0275fac=function(e){return new(e||c)};static \u0275prov=S({token:c,factory:c.\u0275fac})};/**i18n:fad79908930cbb4c308e7550a5fe49bb3841dbb330066a6429aebaa006173605*/export{B};//# sourceMappingURL=chunk-C8m0Xc8q.js.map
