Skip to content

Commit

Permalink
source: fix Mastodon pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Sep 7, 2022
1 parent 88a7311 commit c7ab868
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/sites/Mastodon/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,26 @@ export const source: ISource = {
auth: [],
maxLimit: 40,
search: {
url: (query: ISearchQuery, opts: IUrlOptions): string | IError => {
url: (query: ISearchQuery, opts: IUrlOptions, previous: IPreviousSearch | undefined): string | IError => {
const search = Grabber.parseSearchQuery(query.search, meta);
const pagePart = Grabber.pageUrl(query.page, previous, 1, "", "&min_id={max}", "&max_id={min}");

// Search
if (search.query) {
if (!opts.loggedIn) {
return { error: "You must be logged in to use search" };
}
const userId = search.user_id ? "&account_id=" + search.user_id : "";
return "/api/v2/search?type=statuses&q=" + encodeURIComponent(search.query) + userId + "&limit=" + opts.limit;
return "/api/v2/search?type=statuses&q=" + encodeURIComponent(search.query) + userId + "&limit=" + opts.limit + pagePart;
}

// User ID
if (search.user_id) {
return "/api/v1/accounts/" + search.user_id + "/statuses?only_media=true&limit=" + opts.limit;
return "/api/v1/accounts/" + search.user_id + "/statuses?only_media=true&limit=" + opts.limit + pagePart;
}

// Public timeline
return "/api/v1/timelines/public?only_media=true&limit=" + opts.limit;
return "/api/v1/timelines/public?only_media=true&limit=" + opts.limit + pagePart;
},
parse: (src: string): IParsedSearch => {
const data: any[] = JSON.parse(src);
Expand Down

0 comments on commit c7ab868

Please sign in to comment.