browsing hashtag working

This commit is contained in:
Nicolas Constant 2018-11-23 23:04:02 -05:00
parent eb1249a641
commit 143d445fcb
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
3 changed files with 26 additions and 8 deletions

View File

@ -10,6 +10,6 @@
</div> -->
<app-user-profile *ngIf="accountName" [currentAccount]="accountName" (browseAccount)="accountSelected($event)" (browseHashtag)="hashtagSelected($event)"></app-user-profile>
<app-hashtag *ngIf="hashtagElement" [hashtagElement]="hashtagElement"></app-hashtag>
<app-hashtag *ngIf="hashtagElement" [hashtagElement]="hashtagElement" (browseAccount)="accountSelected($event)" (browseHashtag)="hashtagSelected($event)"></app-hashtag>
<app-thread *ngIf="browseThread"></app-thread>
</div>

View File

@ -16,6 +16,7 @@ import { StatusWrapper } from '../stream.component';
styleUrls: ['./stream-statuses.component.scss']
})
export class StreamStatusesComponent implements OnInit, OnDestroy {
private _streamElement: StreamElement;
private account: AccountInfo;
private websocketStreaming: StreamingWrapper;
@ -30,6 +31,9 @@ export class StreamStatusesComponent implements OnInit, OnDestroy {
@Input()
set streamElement(streamElement: StreamElement) {
console.warn('new stream');
this.resetStream();
this._streamElement = streamElement;
const splitedUserName = streamElement.accountId.split('@');
@ -64,6 +68,12 @@ export class StreamStatusesComponent implements OnInit, OnDestroy {
if( this.goToTopSubscription) this.goToTopSubscription.unsubscribe();
}
private resetStream() {
this.statuses.length = 0;
this.bufferStream.length = 0;
if(this.websocketStreaming) this.websocketStreaming.dispose();
}
private launchWebsocket(): void {
this.websocketStreaming = this.streamingService.getStreaming(this.account, this._streamElement);
this.websocketStreaming.statusUpdateSubjet.subscribe((update: StatusUpdate) => {

View File

@ -10,7 +10,7 @@ import { stat } from "fs";
@Injectable()
export class StreamingService {
public readonly nbStatusPerIteration :number = 20;
public readonly nbStatusPerIteration: number = 20;
constructor(
private readonly mastodonService: MastodonService) { }
@ -26,6 +26,9 @@ export class StreamingWrapper {
statusUpdateSubjet = new BehaviorSubject<StatusUpdate>(null);
eventSource: WebSocket;
private apiRoutes = new ApiRoutes();
private errorClosing: boolean;
private since_id: string;
private disposed: boolean;
constructor(
private readonly mastodonService: MastodonService,
@ -37,6 +40,11 @@ export class StreamingWrapper {
this.start(route);
}
dispose(): any {
this.disposed = true;
this.eventSource.close();
}
private start(route: string) {
this.eventSource = new WebSocket(route);
this.eventSource.onmessage = x => this.statusParsing(<WebSocketEvent>JSON.parse(x.data));
@ -45,17 +53,15 @@ export class StreamingWrapper {
this.eventSource.onclose = x => this.webSocketClosed(route, x);
}
private errorClosing: boolean;
private webSocketGotError(x: Event) {
this.errorClosing = true;
}
private since_id: string;
private webSocketClosed(domain, x: Event) {
if (this.errorClosing) {
this.pullNewStatuses(domain);
this.errorClosing = false;
} else {
} else if (!this.disposed) {
setTimeout(() => { this.start(domain) }, 5000);
}
}
@ -78,7 +84,9 @@ export class StreamingWrapper {
})
.then(() => {
// setTimeout(() => { this.start(domain) }, 20 * 1000);
setTimeout(() => { this.pullNewStatuses(domain) }, 15 * 1000);
if (!this.disposed) {
setTimeout(() => { this.pullNewStatuses(domain) }, 15 * 1000);
}
});
}
@ -105,8 +113,8 @@ export class StreamingWrapper {
const streamingRouteType = this.getStreamingRouteType(stream.type);
let route = `wss://${account.instance}${this.apiRoutes.getStreaming}`.replace('{0}', account.token.access_token).replace('{1}', streamingRouteType);
if(stream.tag) route = `${route}&tag=${stream.tag}`;
if(stream.list) route = `${route}&tag=${stream.list}`;
if (stream.tag) route = `${route}&tag=${stream.tag}`;
if (stream.list) route = `${route}&tag=${stream.list}`;
return route;
}