centralization of the nb of statuses to retrieve per call

This commit is contained in:
Nicolas Constant 2018-11-03 14:24:50 -04:00
parent d1c2b59018
commit 773d4f8453
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 15 additions and 11 deletions

View File

@ -77,8 +77,8 @@ export class StreamComponent implements OnInit {
@ViewChild('statusstream') public statustream: ElementRef;
goToTop(): boolean {
this.loadBuffer();
if (this.statuses.length > 40) {
this.statuses.length = 40;
if (this.statuses.length > 2 * this.streamingService.nbStatusPerIteration) {
this.statuses.length = 2 * this.streamingService.nbStatusPerIteration;
}
const stream = this.statustream.nativeElement as HTMLElement;
stream.scrollTo({
@ -128,7 +128,7 @@ export class StreamComponent implements OnInit {
this.isProcessingInfiniteScroll = true;
const lastStatus = this.statuses[this.statuses.length - 1];
this.mastodonService.getTimeline(this.account, this._streamElement.type, lastStatus.status.id, null, 20, this._streamElement.tag, this._streamElement.list)
this.mastodonService.getTimeline(this.account, this._streamElement.type, lastStatus.status.id, null, this.streamingService.nbStatusPerIteration, this._streamElement.tag, this._streamElement.list)
.then((status: Status[]) => {
for (const s of status) {
const wrapper = new StatusWrapper(s, this.account);
@ -149,7 +149,7 @@ export class StreamComponent implements OnInit {
}
private retrieveToots(): void {
this.mastodonService.getTimeline(this.account, this._streamElement.type, null, null, 20, this._streamElement.tag, this._streamElement.list)
this.mastodonService.getTimeline(this.account, this._streamElement.type, null, null, this.streamingService.nbStatusPerIteration, this._streamElement.tag, this._streamElement.list)
.then((results: Status[]) => {
for (const s of results) {
const wrapper = new StatusWrapper(s, this.account);
@ -179,13 +179,13 @@ export class StreamComponent implements OnInit {
}
private checkAndCleanUpStream(): void {
if (this.streamPositionnedAtTop && this.statuses.length > 60) {
this.statuses.length = 40;
if (this.streamPositionnedAtTop && this.statuses.length > 3 * this.streamingService.nbStatusPerIteration) {
this.statuses.length = 2 * this.streamingService.nbStatusPerIteration;
}
if (this.bufferStream.length > 60) {
if (this.bufferStream.length > 3 * this.streamingService.nbStatusPerIteration) {
this.bufferWasCleared = true;
this.bufferStream.length = 40;
this.bufferStream.length = 2 * this.streamingService.nbStatusPerIteration;
}
}
}

View File

@ -9,11 +9,14 @@ import { stat } from "fs";
@Injectable()
export class StreamingService {
public readonly nbStatusPerIteration :number = 30;
constructor(
private readonly mastodonService: MastodonService) { }
getStreaming(accountInfo: AccountInfo, stream: StreamElement): StreamingWrapper {
return new StreamingWrapper(this.mastodonService, accountInfo, stream);
return new StreamingWrapper(this.mastodonService, accountInfo, stream, this.nbStatusPerIteration);
}
@ -27,7 +30,8 @@ export class StreamingWrapper {
constructor(
private readonly mastodonService: MastodonService,
private readonly account: AccountInfo,
private readonly stream: StreamElement) {
private readonly stream: StreamElement,
private readonly nbStatusPerIteration: number) {
const route = this.getRoute(account, stream);
this.start(route);
@ -57,7 +61,7 @@ export class StreamingWrapper {
}
private pullNewStatuses(domain) {
this.mastodonService.getTimeline(this.account, this.stream.type, null, this.since_id, 20, this.stream.tag, this.stream.list)
this.mastodonService.getTimeline(this.account, this.stream.type, null, this.since_id, this.nbStatusPerIteration, this.stream.tag, this.stream.list)
.then((status: Status[]) => {
// status = status.sort((n1, n2) => { return (<number>n1.id) < (<number>n2.id); });
status = status.sort((a, b) => a.id.localeCompare(b.id));