mirror of
https://github.com/NicolasConstant/sengi
synced 2025-01-28 09:19:21 +01:00
centralization of the nb of statuses to retrieve per call
This commit is contained in:
parent
d1c2b59018
commit
773d4f8453
@ -77,8 +77,8 @@ export class StreamComponent implements OnInit {
|
|||||||
@ViewChild('statusstream') public statustream: ElementRef;
|
@ViewChild('statusstream') public statustream: ElementRef;
|
||||||
goToTop(): boolean {
|
goToTop(): boolean {
|
||||||
this.loadBuffer();
|
this.loadBuffer();
|
||||||
if (this.statuses.length > 40) {
|
if (this.statuses.length > 2 * this.streamingService.nbStatusPerIteration) {
|
||||||
this.statuses.length = 40;
|
this.statuses.length = 2 * this.streamingService.nbStatusPerIteration;
|
||||||
}
|
}
|
||||||
const stream = this.statustream.nativeElement as HTMLElement;
|
const stream = this.statustream.nativeElement as HTMLElement;
|
||||||
stream.scrollTo({
|
stream.scrollTo({
|
||||||
@ -128,7 +128,7 @@ export class StreamComponent implements OnInit {
|
|||||||
this.isProcessingInfiniteScroll = true;
|
this.isProcessingInfiniteScroll = true;
|
||||||
|
|
||||||
const lastStatus = this.statuses[this.statuses.length - 1];
|
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[]) => {
|
.then((status: Status[]) => {
|
||||||
for (const s of status) {
|
for (const s of status) {
|
||||||
const wrapper = new StatusWrapper(s, this.account);
|
const wrapper = new StatusWrapper(s, this.account);
|
||||||
@ -149,7 +149,7 @@ export class StreamComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private retrieveToots(): void {
|
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[]) => {
|
.then((results: Status[]) => {
|
||||||
for (const s of results) {
|
for (const s of results) {
|
||||||
const wrapper = new StatusWrapper(s, this.account);
|
const wrapper = new StatusWrapper(s, this.account);
|
||||||
@ -179,13 +179,13 @@ export class StreamComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private checkAndCleanUpStream(): void {
|
private checkAndCleanUpStream(): void {
|
||||||
if (this.streamPositionnedAtTop && this.statuses.length > 60) {
|
if (this.streamPositionnedAtTop && this.statuses.length > 3 * this.streamingService.nbStatusPerIteration) {
|
||||||
this.statuses.length = 40;
|
this.statuses.length = 2 * this.streamingService.nbStatusPerIteration;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.bufferStream.length > 60) {
|
if (this.bufferStream.length > 3 * this.streamingService.nbStatusPerIteration) {
|
||||||
this.bufferWasCleared = true;
|
this.bufferWasCleared = true;
|
||||||
this.bufferStream.length = 40;
|
this.bufferStream.length = 2 * this.streamingService.nbStatusPerIteration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,11 +9,14 @@ import { stat } from "fs";
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class StreamingService {
|
export class StreamingService {
|
||||||
|
|
||||||
|
public readonly nbStatusPerIteration :number = 30;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly mastodonService: MastodonService) { }
|
private readonly mastodonService: MastodonService) { }
|
||||||
|
|
||||||
getStreaming(accountInfo: AccountInfo, stream: StreamElement): StreamingWrapper {
|
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(
|
constructor(
|
||||||
private readonly mastodonService: MastodonService,
|
private readonly mastodonService: MastodonService,
|
||||||
private readonly account: AccountInfo,
|
private readonly account: AccountInfo,
|
||||||
private readonly stream: StreamElement) {
|
private readonly stream: StreamElement,
|
||||||
|
private readonly nbStatusPerIteration: number) {
|
||||||
|
|
||||||
const route = this.getRoute(account, stream);
|
const route = this.getRoute(account, stream);
|
||||||
this.start(route);
|
this.start(route);
|
||||||
@ -57,7 +61,7 @@ export class StreamingWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private pullNewStatuses(domain) {
|
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[]) => {
|
.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));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user