diff --git a/src/app/components/stream/user-profile/user-profile.component.ts b/src/app/components/stream/user-profile/user-profile.component.ts index 64fb26a5..70d07d8a 100644 --- a/src/app/components/stream/user-profile/user-profile.component.ts +++ b/src/app/components/stream/user-profile/user-profile.component.ts @@ -28,7 +28,7 @@ export class UserProfileComponent implements OnInit { //set currentAccount(account: Account) { set currentAccount(accountName: string) { this.statuses.length = 0; - this.isLoading = true; + this.isLoading = true; this.loadAccount(accountName) .then((account: Account) => { @@ -36,9 +36,10 @@ export class UserProfileComponent implements OnInit { return this.getStatuses(this.account); }) .catch(err => { - this.error = 'Error when retieving account'; + this.error = 'Error when retrieving account'; this.isLoading = false; this.statusLoading = false; + console.warn(this.error); }); // this.account = account; @@ -70,21 +71,17 @@ export class UserProfileComponent implements OnInit { if (selectedAccounts.length === 0) { this.error = 'no user selected'; - return; + console.error(this.error); + return Promise.resolve(null); } this.isLoading = true; return this.mastodonService.search(selectedAccounts[0], accountName, true) .then((result: Results) => { + console.warn(result); this.isLoading = false; return result.accounts[0]; }); - // .catch((err) => { - // this.error = 'Error when retieving account'; - // }) - // .then(()=>{ - // this.isLoading = false; - // }); } private getStatuses(account: Account): Promise { diff --git a/src/app/services/streaming.service.ts b/src/app/services/streaming.service.ts index 697a0b30..ebcfbf25 100644 --- a/src/app/services/streaming.service.ts +++ b/src/app/services/streaming.service.ts @@ -39,11 +39,12 @@ export class StreamingWrapper { this.eventSource.onmessage = x => this.statusParsing(JSON.parse(x.data)); this.eventSource.onerror = x => this.webSocketGotError(x); this.eventSource.onopen = x => console.log(x); - this.eventSource.onclose = x => this.webSocketClosed(route, x); + this.eventSource.onclose = x => this.webSocketClosed(route, x); } private errorClosing: boolean; private webSocketGotError(x: Event) { + console.log(x); this.errorClosing = true; } @@ -52,7 +53,36 @@ export class StreamingWrapper { console.log(x); if (this.errorClosing) { - this.mastodonService.getTimeline(this.accountInfo, this.streamType, null, this.since_id) + + this.pullNewStatuses(domain); + + // this.mastodonService.getTimeline(this.accountInfo, this.streamType, null, this.since_id) + // .then((status: Status[]) => { + // // status = status.sort((n1, n2) => { return (n1.id) < (n2.id); }); + // status = status.sort((a, b) => a.id.localeCompare(b.id)); + // for (const s of status) { + // const update = new StatusUpdate(); + // update.status = s; + // update.type = EventEnum.update; + // this.since_id = update.status.id; + // this.statusUpdateSubjet.next(update); + // } + // }) + // .catch(err => { + // console.error(err); + // }) + // .then(() => { + // setTimeout(() => { this.start(domain) }, 20 * 1000); + // }); + + this.errorClosing = false; + } else { + setTimeout(() => { this.start(domain) }, 5000); + } + } + + private pullNewStatuses(domain){ + this.mastodonService.getTimeline(this.accountInfo, this.streamType, null, this.since_id) .then((status: Status[]) => { // status = status.sort((n1, n2) => { return (n1.id) < (n2.id); }); status = status.sort((a, b) => a.id.localeCompare(b.id)); @@ -68,13 +98,9 @@ export class StreamingWrapper { console.error(err); }) .then(() => { - setTimeout(() => { this.start(domain) }, 20 * 1000); + // setTimeout(() => { this.start(domain) }, 20 * 1000); + setTimeout(() => { this.pullNewStatuses(domain) }, 15 * 1000); }); - - this.errorClosing = false; - } else { - setTimeout(() => { this.start(domain) }, 5000); - } } private statusParsing(event: WebSocketEvent) {