fix follower pagination

This commit is contained in:
Nicolas Constant 2020-06-15 00:44:00 -04:00
parent 34dcc3050a
commit 9a8f24462c
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 16 additions and 12 deletions

View File

@ -18,7 +18,7 @@ export class UserFollowsComponent implements OnInit, OnDestroy {
private _type: 'follows' | 'followers';
private _currentAccount: string;
private sinceId: string;
private maxId: string;
isLoading: boolean = true;
accounts: Account[] = [];
@ -97,7 +97,7 @@ export class UserFollowsComponent implements OnInit, OnDestroy {
})
.then((result: FollowingResult) => {
console.warn(result);
this.sinceId = result.sinceId;
this.maxId = result.maxId;
this.accounts = result.follows;
})
.catch(err => {
@ -119,9 +119,9 @@ export class UserFollowsComponent implements OnInit, OnDestroy {
this.toolsService.findAccount(currentAccount, this._currentAccount)
.then((acc: Account) => {
if (this._type === 'followers') {
return this.mastodonService.getFollowers(currentAccount, acc.id, this.sinceId, null);
return this.mastodonService.getFollowers(currentAccount, acc.id, this.maxId, null);
} else if (this._type === 'follows') {
return this.mastodonService.getFollowing(currentAccount, acc.id, this.sinceId, null);
return this.mastodonService.getFollowing(currentAccount, acc.id, this.maxId, null);
} else {
throw Error('not implemented');
}
@ -135,11 +135,15 @@ export class UserFollowsComponent implements OnInit, OnDestroy {
this.maxReached = true;
return;
}
this.sinceId = result.sinceId;
for (let a of accounts) {
this.accounts.push(a);
}
this.maxId = result.maxId;
if(!this.maxId) {
this.maxReached = true;
}
})
.catch((err: HttpErrorResponse) => {
this.scrolledErrorOccured = true;

View File

@ -482,9 +482,9 @@ export class MastodonService {
const link = res.headers.get('Link');
let lastId = null;
if (link) {
const sinceId = link.split('since_id=')[1];
const maxId = link.split('max_id=')[1];
if (maxId) {
lastId = sinceId.split('>;')[0];
lastId = maxId.split('>;')[0];
}
}
return new FollowingResult(lastId, res.body)
@ -503,9 +503,9 @@ export class MastodonService {
const link = res.headers.get('Link');
let lastId = null;
if (link) {
const sinceId = link.split('since_id=')[1];
if (sinceId) {
lastId = sinceId.split('>;')[0];
const maxId = link.split('max_id=')[1];
if (maxId) {
lastId = maxId.split('>;')[0];
}
}
return new FollowingResult(lastId, res.body)
@ -553,6 +553,6 @@ export class BookmarkResult {
export class FollowingResult {
constructor(
public sinceId: string,
public maxId: string,
public follows: Account[]) { }
}