added stream update on settings changes

This commit is contained in:
Nicolas Constant 2019-06-23 23:11:16 -04:00
parent b5f063b158
commit dcb929eac3
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
1 changed files with 24 additions and 15 deletions

View File

@ -49,6 +49,8 @@ export class StreamStatusesComponent implements OnInit, OnDestroy {
@Input() userLocked = true; @Input() userLocked = true;
private goToTopSubscription: Subscription; private goToTopSubscription: Subscription;
private streamsSubscription: Subscription;
private streams$: Observable<StreamElement[]>;
constructor( constructor(
private readonly store: Store, private readonly store: Store,
@ -56,16 +58,23 @@ export class StreamStatusesComponent implements OnInit, OnDestroy {
private readonly notificationService: NotificationService, private readonly notificationService: NotificationService,
private readonly streamingService: StreamingService, private readonly streamingService: StreamingService,
private readonly mastodonService: MastodonService) { private readonly mastodonService: MastodonService) {
this.streams$ = this.store.select(state => state.streamsstatemodel.streams);
} }
ngOnInit() { ngOnInit() {
this.goToTopSubscription = this.goToTop.subscribe(() => { this.goToTopSubscription = this.goToTop.subscribe(() => {
this.applyGoToTop(); this.applyGoToTop();
}); });
this.streamsSubscription = this.streams$.subscribe((streams: StreamElement[]) => {
this.streamElement = streams.find(x => x.id === this.streamElement.id);
});
} }
ngOnDestroy() { ngOnDestroy() {
if (this.goToTopSubscription) this.goToTopSubscription.unsubscribe(); if (this.goToTopSubscription) this.goToTopSubscription.unsubscribe();
if (this.streamsSubscription) this.streamsSubscription.unsubscribe();
} }
refresh(): any { refresh(): any {
@ -101,7 +110,7 @@ export class StreamStatusesComponent implements OnInit, OnDestroy {
if (update.type === EventEnum.update) { if (update.type === EventEnum.update) {
if (!this.statuses.find(x => x.status.id == update.status.id)) { if (!this.statuses.find(x => x.status.id == update.status.id)) {
if (this.streamPositionnedAtTop) { if (this.streamPositionnedAtTop) {
if(this.isFiltered(update.status)){ if (this.isFiltered(update.status)) {
return; return;
} }
@ -177,7 +186,7 @@ export class StreamStatusesComponent implements OnInit, OnDestroy {
} }
for (const status of this.bufferStream) { for (const status of this.bufferStream) {
if(this.isFiltered(status)){ if (this.isFiltered(status)) {
continue; continue;
} }
@ -189,7 +198,7 @@ export class StreamStatusesComponent implements OnInit, OnDestroy {
} }
private scrolledToBottom() { private scrolledToBottom() {
if(this.isLoading) return; if (this.isLoading) return;
this.isLoading = true; this.isLoading = true;
this.isProcessingInfiniteScroll = true; this.isProcessingInfiniteScroll = true;
@ -198,7 +207,7 @@ export class StreamStatusesComponent implements OnInit, OnDestroy {
this.mastodonService.getTimeline(this.account, this._streamElement.type, lastStatus.status.id, null, this.streamingService.nbStatusPerIteration, this._streamElement.tag, this._streamElement.listId) this.mastodonService.getTimeline(this.account, this._streamElement.type, lastStatus.status.id, null, this.streamingService.nbStatusPerIteration, this._streamElement.tag, this._streamElement.listId)
.then((status: Status[]) => { .then((status: Status[]) => {
for (const s of status) { for (const s of status) {
if(this.isFiltered(s)){ if (this.isFiltered(s)) {
continue; continue;
} }
@ -226,7 +235,7 @@ export class StreamStatusesComponent implements OnInit, OnDestroy {
.then((results: Status[]) => { .then((results: Status[]) => {
this.isLoading = false; this.isLoading = false;
for (const s of results) { for (const s of results) {
if(this.isFiltered(s)){ if (this.isFiltered(s)) {
continue; continue;
} }
@ -250,19 +259,19 @@ export class StreamStatusesComponent implements OnInit, OnDestroy {
} }
} }
private isFiltered(status: Status): boolean{ private isFiltered(status: Status): boolean {
if(this.streamElement.hideBoosts){ if (this.streamElement.hideBoosts) {
if(status.reblog){ if (status.reblog) {
return true; return true;
} }
} }
if(this.streamElement.hideBots){ if (this.streamElement.hideBots) {
if(status.account.bot){ if (status.account.bot) {
return true; return true;
} }
} }
if(this.streamElement.hideReplies){ if (this.streamElement.hideReplies) {
if(status.in_reply_to_account_id && status.account.id !== status.in_reply_to_account_id){ if (status.in_reply_to_account_id && status.account.id !== status.in_reply_to_account_id) {
return true; return true;
} }
} }