hashtag streaming is now working

This commit is contained in:
Nicolas Constant 2018-11-03 14:12:14 -04:00
parent d92cca787b
commit 83488ad4c5
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 47 additions and 31 deletions

View File

@ -159,7 +159,7 @@ export class StreamComponent implements OnInit {
} }
private launchWebsocket(): void { private launchWebsocket(): void {
this.websocketStreaming = this.streamingService.getStreaming(this.account, this._streamElement.type); this.websocketStreaming = this.streamingService.getStreaming(this.account, this._streamElement);
this.websocketStreaming.statusUpdateSubjet.subscribe((update: StatusUpdate) => { this.websocketStreaming.statusUpdateSubjet.subscribe((update: StatusUpdate) => {
if (update) { if (update) {
if (update.type === EventEnum.update) { if (update.type === EventEnum.update) {
@ -186,7 +186,6 @@ export class StreamComponent implements OnInit {
if (this.bufferStream.length > 60) { if (this.bufferStream.length > 60) {
this.bufferWasCleared = true; this.bufferWasCleared = true;
this.bufferStream.length = 40; this.bufferStream.length = 40;
} }
} }
} }

View File

@ -2,7 +2,7 @@ import { Injectable } from "@angular/core";
import { Status } from "./models/mastodon.interfaces"; import { Status } from "./models/mastodon.interfaces";
import { BehaviorSubject } from "rxjs"; import { BehaviorSubject } from "rxjs";
import { ApiRoutes } from "./models/api.settings"; import { ApiRoutes } from "./models/api.settings";
import { StreamTypeEnum } from "../states/streams.state"; import { StreamTypeEnum, StreamElement } from "../states/streams.state";
import { MastodonService } from "./mastodon.service"; import { MastodonService } from "./mastodon.service";
import { AccountInfo } from "../states/accounts.state"; import { AccountInfo } from "../states/accounts.state";
import { stat } from "fs"; import { stat } from "fs";
@ -12,8 +12,8 @@ export class StreamingService {
constructor( constructor(
private readonly mastodonService: MastodonService) { } private readonly mastodonService: MastodonService) { }
getStreaming(accountInfo: AccountInfo, streamType: StreamTypeEnum): StreamingWrapper { getStreaming(accountInfo: AccountInfo, stream: StreamElement): StreamingWrapper {
return new StreamingWrapper(this.mastodonService, accountInfo, streamType); return new StreamingWrapper(this.mastodonService, accountInfo, stream);
} }
@ -26,11 +26,10 @@ export class StreamingWrapper {
constructor( constructor(
private readonly mastodonService: MastodonService, private readonly mastodonService: MastodonService,
private readonly accountInfo: AccountInfo, private readonly account: AccountInfo,
private readonly streamType: StreamTypeEnum) { private readonly stream: StreamElement) {
const request = this.getRequest(streamType); const route = this.getRoute(account, stream);
const route = `wss://${accountInfo.instance}${this.apiRoutes.getStreaming}`.replace('{0}', accountInfo.token.access_token).replace('{1}', request);
this.start(route); this.start(route);
} }
@ -58,7 +57,7 @@ export class StreamingWrapper {
} }
private pullNewStatuses(domain) { private pullNewStatuses(domain) {
this.mastodonService.getTimeline(this.accountInfo, this.streamType, null, this.since_id) this.mastodonService.getTimeline(this.account, this.stream.type, null, this.since_id, 20, this.stream.tag, this.stream.list)
.then((status: Status[]) => { .then((status: Status[]) => {
// status = status.sort((n1, n2) => { return (<number>n1.id) < (<number>n2.id); }); // status = status.sort((n1, n2) => { return (<number>n1.id) < (<number>n2.id); });
status = status.sort((a, b) => a.id.localeCompare(b.id)); status = status.sort((a, b) => a.id.localeCompare(b.id));
@ -98,7 +97,17 @@ export class StreamingWrapper {
this.statusUpdateSubjet.next(newUpdate); this.statusUpdateSubjet.next(newUpdate);
} }
private getRequest(type: StreamTypeEnum): string { private getRoute(account: AccountInfo, stream: StreamElement): string {
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}`;
return route;
}
private getStreamingRouteType(type: StreamTypeEnum): string {
switch (type) { switch (type) {
case StreamTypeEnum.global: case StreamTypeEnum.global:
return 'public'; return 'public';
@ -106,6 +115,14 @@ export class StreamingWrapper {
return 'public:local'; return 'public:local';
case StreamTypeEnum.personnal: case StreamTypeEnum.personnal:
return 'user'; return 'user';
case StreamTypeEnum.directmessages:
return 'direct';
case StreamTypeEnum.tag:
return 'hashtag';
case StreamTypeEnum.list:
return 'list';
default:
throw Error('Not supported');
} }
} }
} }