rxjs#scheduled TypeScript Examples

The following examples show how to use rxjs#scheduled. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: emote.component.ts    From App with MIT License 6 votes vote down vote up
interactError = new Subject<string>().pipe(
		mergeMap(x => scheduled([
			of(!!x ? 'ERROR: ' + x : ''),
			timer(5000).pipe(
				takeUntil(this.interactError),
				mapTo('')
			)
		], asyncScheduler).pipe(mergeAll()))
	) as Subject<string>;
Example #2
Source File: emote-card.component.ts    From App with MIT License 6 votes vote down vote up
getBorderColor(): Observable<Color> {
		return scheduled([
			this.emote?.isGlobal().pipe(map(b => ({ b, type: 'global' }))),
			this.emote?.isChannel().pipe(map(b => ({ b, type: 'channel' }))),
		], asapScheduler).pipe(
			switchMap(value => value ?? EMPTY),
			filter(({ b }) => b === true),
			defaultIfEmpty({ b: false, type: 'none' }),
			take(1),
			map(o => o.type as 'global' | 'channel'),
			map(type => (type !== null ? ({
				global: this.globalBorderColor,
				channel: this.channelBorderColor
			})[type] as Color : this.borderColor))
		);
	}
Example #3
Source File: notify-button.component.ts    From App with MIT License 6 votes vote down vote up
ngOnInit(): void {
		scheduled([
			this.clientService.isAuthenticated().pipe(filter(ok => ok === true)),
			this.clientService.impersonating.pipe(mapTo(true))
		], asapScheduler).pipe(
			mergeAll(),
			switchMap(() => this.clientService.getActorUser()),
			switchMap(actor => actor.fetchNotificationCount()),
			tap(nCount => this.count.next(nCount))
		).subscribe();

		this.beginPolling();
	}
Example #4
Source File: app.service.ts    From App with MIT License 6 votes vote down vote up
updateSubscriptionData(): void {
		// EgVault - Payment API State
		scheduled([
			this.restService.egvault.Root().pipe(
				RestService.onlyResponse(),
				tap(() => this.egvaultOK.next(true)),
				catchError(() => defer(() => this.egvaultOK.next(false)))
			),
			this.restService.awaitAuth().pipe(
				filter(ok => ok === true),
				switchMap(() => this.restService.egvault.Subscriptions.Get('@me').pipe(RestService.onlyResponse())),
				tap(res => {
					if (!res.body?.subscription) {
						this.subscription.next(null);
						return undefined;
					}

					res.body.subscription.renew = res.body.renew;
					res.body.subscription.ending_at = new Date(res.body.end_at);
					this.subscription.next(res.body.subscription);
					return undefined;
				}),
				mapTo(undefined)
			)
		], asyncScheduler).pipe(mergeAll()).subscribe({
			error: err => console.error(err)
		});
	}
Example #5
Source File: client.service.ts    From App with MIT License 6 votes vote down vote up
canAccessAdminArea(): Observable<boolean> {
		return scheduled([
			this.hasPermission('MANAGE_REPORTS'),
			this.hasPermission('MANAGE_ROLES'),
			this.hasPermission('MANAGE_STACK'),
			this.hasPermission('MANAGE_USERS'),
			this.hasPermission('BAN_USERS')
		], asapScheduler).pipe(
			zipAll(),
			map(perms => perms.filter(b => b === true).length > 0)
		);
	}
Example #6
Source File: store-leaderboards.component.ts    From App with MIT License 6 votes vote down vote up
ngOnInit(): void {
		this.restService.egvault.Subscriptions.GetLeaderboards().pipe(
			RestService.onlyResponse(),
			map(res => this.gifts.next(res.body?.gift_subscriptions ?? [])),

			switchMap(() => scheduled([
				this.getPosition(1).pipe(tap(x => this.firstPlace = { user: x[0], count: x[1] })),
				this.getPosition(2).pipe(tap(x => this.secondPlace = { user: x[0], count: x[1] })),
				this.getPosition(3).pipe(tap(x => this.thirdPlace = { user: x[0], count: x[1] }))
			], asyncScheduler).pipe(mergeAll()))
		).subscribe({
			next: () => this.cdr.markForCheck()
		});
	}
Example #7
Source File: user-home.component.ts    From App with MIT License 6 votes vote down vote up
private shouldBlurEmote(emote: EmoteStructure): Observable<boolean> {
		return scheduled([
			emote.hasVisibility('HIDDEN'),
			emote.hasVisibility('PRIVATE')
		], asyncScheduler).pipe(
			concatAll(),
			toArray(),
			mergeMap(b => iif(() => b[0] === true || b[1] === true,
				this.clientService.hasPermission('EDIT_EMOTE_ALL').pipe(
					take(1),
					switchMap(bypass => iif(() => bypass,
						of(false),
						emote.getOwnerID().pipe(
							map(ownerID => ownerID !== this.clientService.id)
						)
					))
				),
				of(false)
			)),
			take(1)
		);
	}
Example #8
Source File: twitch-button.component.ts    From App with MIT License 6 votes vote down vote up
open(): void {
		scheduled([
			this.oauthService.openAuthorizeWindow<{ token: string }>().pipe(
				tap(data => this.clientService.setToken(data.token)),
				switchMap(() => this.restService.v2.GetUser('@me', { includeEditorIn: true }).pipe(
					map(res => this.clientService.pushData(res?.user ?? null))
				))
			),
			defer(() => this.oauthService.navigateTo(this.restService.v2.GetAuthURL()))
		], asyncScheduler).pipe(
			mergeAll(),
			switchMapTo(EMPTY)
		).subscribe({
			error: (err) => {
				this.dialogRef.open(ErrorDialogComponent, {
					data: {
						errorCode: err.status,
						errorMessage: err.error?.error ?? err.message,
						errorName: 'Could not sign in'
					} as ErrorDialogComponent.Data
				});
				this.logger.error('Could not sign in', err);
				this.clientService.logout();
				this.oauthService.openedWindow?.close();
			}
		});
	}
Example #9
Source File: emote-search.component.ts    From App with MIT License 5 votes vote down vote up
ngOnInit(): void {
		scheduled([
			this.form.get('query')?.valueChanges.pipe( // Look for changes to the name input form field
				mergeMap((value: string) => this.selectedSearchMode.pipe(take(1), map(mode => ({ mode, value })))),
				map(({ value, mode }) => ({ [mode.id]: value })) // Map SearchMode to value
			) ?? EMPTY,

			this.form.get('globalState')?.valueChanges.pipe( // Look for changes to the "show global"
				map((value: string) => ({ globalState: value }))
			) ?? EMPTY,

			this.form.get('channel')?.valueChanges.pipe(
				map((value: boolean) => ({ channel: value ? this.clientService.getSnapshot()?.login : '' }))
			) ?? EMPTY,
			this.form.get('zerowidth')?.valueChanges.pipe(
				map((value: boolean) => ({ filter: {
					visibility: value ? DataStructure.Emote.Visibility.ZERO_WIDTH : 0
				}}))
			) ?? EMPTY,

			this.form.get('sortBy')?.valueChanges.pipe(
				map((value: string) => ({ sortBy: value }))
			) ?? EMPTY,

			this.form.get('sortOrder')?.valueChanges.pipe(
				map((value: RestV2.GetEmotesOptions['sortOrder']) => ({ sortOrder: value }))
			) ?? EMPTY
		], asyncScheduler).pipe(
			mergeAll(),
			map(v => this.current = { ...this.current, ...v } as any),
			throttleTime(250)
		).subscribe({
			next: (v) => this.searchChange.next(v) // Emit the change
		});

		setTimeout(() => {
			if (!!this.defaultSearchOptions) {
				for (const k of Object.keys(this.form.getRawValue())) {
					const v = (this.defaultSearchOptions as any)[k as any];
					if (!v) {
						continue;
					}

					this.form.get(k)?.patchValue(v);
				}
			}
		}, 0);
	}
Example #10
Source File: chatterino-dialog.component.ts    From App with MIT License 5 votes vote down vote up
ngOnInit(): void {
		scheduled([
			this.restService.createRequest<ChatterinoDialogComponent.ChatterinoVersion>('get', '/chatterino/version/win/stable', {}, 'v2').pipe(
				RestService.onlyResponse(),
				map(res => {
					this.windowsDownloads.push(
						{ label: 'INSTALLER', url: res.body?.download ?? '' },
						{ label: 'PORTABLE / STANDALONE EXE', url: res.body?.portable_download ?? '' }
					);

					return {
						label: 'Windows', icon: 'windows', svgIcon: true,
						menu: this.installTypeMenu
					} as ChatterinoDialogComponent.PlatformIcon;
				})
			),

			this.restService.createRequest<ChatterinoDialogComponent.ChatterinoVersion>('get', '/chatterino/version/linux/stable', {}, 'v2').pipe(
				RestService.onlyResponse(),
				map(res => ({
					label: 'Linux', icon: 'linux', svgIcon: true,
					url: res.body?.download
				} as ChatterinoDialogComponent.PlatformIcon))
			),

			this.restService.createRequest<ChatterinoDialogComponent.ChatterinoVersion>('get', '/chatterino/version/macos/stable', {}, 'v2').pipe(
				RestService.onlyResponse(),
				map(res => ({
					label: 'MacOS', icon: 'apple', svgIcon: true,
					url: res.body?.download
				}))
			)
		], asapScheduler).pipe(
			concatAll()
		).subscribe({
			next: p => this.platforms.push(p)
		});

		this.platforms.push(
			{
				label: 'Nightly Build',
				icon: 'nightlight',
				url: 'https://github.com/SevenTV/chatterino7/releases/tag/nightly-build'
			}
		);
	}
Example #11
Source File: user-home.component.ts    From App with MIT License 5 votes vote down vote up
ngOnInit(): void {
		this.user.pipe(
			filter(user => !!user && AppComponent.isBrowser.getValue()),
			takeUntil(this.destroyed),
			tap(user => this.currentUser = user),
			tap(user => this.emoteSlots.next(user.getSnapshot()?.emote_slots ?? 0)),

			switchMap(user => user.getAuditEntries().pipe(
				tap(entries => this.auditEntries = entries),
				mapTo(user)
			)),
			switchMap(user => user.isLive().pipe(
				map(live => this.isLive.next(live)),
				switchMap(() => user.getBroadcast()),
				map(broadcast => this.broadcast.next(broadcast)),
				mapTo(user)
			)),
			switchMap(user => scheduled([
				user.getEmotes().pipe(map(emotes => ({ type: 'channel', emotes }))),
				user.getOwnedEmotes().pipe(map(emotes => ({ type: 'owned', emotes })))
			], asapScheduler).pipe(
				concatAll(),
				mergeMap(s => from(s.emotes).pipe(
					mergeMap(em => this.shouldBlurEmote(em).pipe(map(blur => ({ blur, emote: em })))),
					map(x => x.blur ? this.blurred.add(x.emote.getID()) : noop()),
					toArray(),
					mapTo(s)
				)),
				take(2),
			))
		).subscribe({
			next: set => {
				switch (set.type) {
					case 'channel':
						this.channelEmotes = set.emotes;
						this.channelCount.next(set.emotes.length);
						break;
					case 'owned':
						this.ownedEmotes = set.emotes;
						this.ownedCount.next(set.emotes.length);
						break;
				}
			}
		});
	}
Example #12
Source File: user.component.ts    From App with MIT License 5 votes vote down vote up
ngOnInit(): void {
		this.route.paramMap.pipe(
			takeUntil(this.destroyed),
			map(params => params.get('user') as string),
			switchMap(id => this.restService.v2.GetUser(id, {
				includeEditors: true,
				includeEditorIn: true,
				includeOwnedEmotes: true,
				includeFullEmotes: true,
				includeAuditLogs: true,
				includeStreamData: true
			}, ['banned', 'youtube_id']).pipe(
				map(res => this.dataService.add('user', res.user)[0])
			)),
			tap(user => this.user.next(user)),
			switchMap(user => scheduled([
				user.getEditors().pipe(map(editors => this.editors.next(editors))),
				user.getEditorIn().pipe(map(edited => this.edited.next(edited))),
				user.getYouTubeID().pipe(tap(ytid => this.hasYouTube.next(ytid !== null)), switchMapTo(EMPTY))
			], asyncScheduler).pipe(concatAll(), mapTo(user))),
			tap(user => {
				const appURL = this.document.location.host + this.router.serializeUrl(this.router.createUrlTree(['/users', String(user.id)]));

				this.appService.pageTitleAttr.next([ // Update page title
					{ name: 'User', value: user.getSnapshot()?.display_name ?? '' }
				]);
				const roleName = user.getSnapshot()?.role?.name;
				const roleColor = user.getSnapshot()?.role?.color;
				const emoteCount = user.getSnapshot()?.emotes.length;
				const maxEmoteCount = user.getSnapshot()?.emote_slots;
				const displayName = user.getSnapshot()?.display_name ?? '';
				this.metaService.addTags([
					// { name: 'og:title', content: this.appService.pageTitle },
					// { name: 'og:site_name', content: this.appService.pageTitle },
					{ name: 'og:description', content: `${displayName} is${!!roleName ? ` ${roleName}` : ''} on 7TV with ${emoteCount}/${maxEmoteCount} emotes enabled`},
					{ name: 'og:image', content: user.getSnapshot()?.profile_image_url ?? '' },
					{ name: 'og:image:type', content: 'image/png' },
					{ name: 'theme-color', content: (roleColor ? `#${roleColor.toString(16)}` : '#fff') }
				]);

				if (!AppComponent.isBrowser.getValue()) {
					const link = this.document.createElement('link');
					link.setAttribute('type', 'application/json+oembed');

					const query = new URLSearchParams();
					query.append('object', Buffer.from(JSON.stringify({
						title: this.appService.pageTitle,
						author_name: displayName,
						author_url: `https://${appURL}`,
						provider_name: `7TV.APP - It's like a third party thing`,
						provider_url: 'https://7tv.app'
					})).toString('base64'));
					link.setAttribute('href', `https://${environment.origin}/services/oembed?` + query.toString());
					this.document.head.appendChild(link);
				}
			})
		).subscribe({
			error: (err) => this.loggerService.error('Couldn\'t fetch user', err)
		});
	}