From 57b98e9e4f536c04ba0ae84ebe1d2ca39560c461 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Thu, 12 Mar 2020 19:54:52 -0400 Subject: [PATCH] added bookmarks in service and models --- src/app/services/mastodon-wrapper.service.ts | 14 ++++++++++++++ src/app/services/mastodon.service.ts | 12 ++++++++++++ src/app/services/models/api.settings.ts | 2 ++ src/app/services/models/mastodon.interfaces.ts | 1 + 4 files changed, 29 insertions(+) diff --git a/src/app/services/mastodon-wrapper.service.ts b/src/app/services/mastodon-wrapper.service.ts index f5262783..0d592055 100644 --- a/src/app/services/mastodon-wrapper.service.ts +++ b/src/app/services/mastodon-wrapper.service.ts @@ -183,6 +183,20 @@ export class MastodonWrapperService { }); } + bookmark(account: AccountInfo, status: Status): Promise { + return this.refreshAccountIfNeeded(account) + .then((refreshedAccount: AccountInfo) => { + return this.mastodonService.bookmark(refreshedAccount, status); + }); + } + + unbookmark(account: AccountInfo, status: Status): Promise { + return this.refreshAccountIfNeeded(account) + .then((refreshedAccount: AccountInfo) => { + return this.mastodonService.unbookmark(refreshedAccount, status); + }); + } + getRelationships(account: AccountInfo, accountsToRetrieve: Account[]): Promise { return this.refreshAccountIfNeeded(account) .then((refreshedAccount: AccountInfo) => { diff --git a/src/app/services/mastodon.service.ts b/src/app/services/mastodon.service.ts index 076e928c..bbddeeb1 100644 --- a/src/app/services/mastodon.service.ts +++ b/src/app/services/mastodon.service.ts @@ -218,6 +218,18 @@ export class MastodonService { return this.httpClient.post(route, null, { headers: headers }).toPromise() } + bookmark(account: AccountInfo, status: Status): Promise { + const route = `https://${account.instance}${this.apiRoutes.bookmarkingStatus}`.replace('{0}', status.id); + const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` }); + return this.httpClient.post(route, null, { headers: headers }).toPromise() + } + + unbookmark(account: AccountInfo, status: Status): Promise { + const route = `https://${account.instance}${this.apiRoutes.unbookmarkingStatus}`.replace('{0}', status.id); + const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` }); + return this.httpClient.post(route, null, { headers: headers }).toPromise() + } + getRelationships(account: AccountInfo, accountsToRetrieve: Account[]): Promise { let params = `?${this.formatArray(accountsToRetrieve.map(x => x.id.toString()), 'id')}`; diff --git a/src/app/services/models/api.settings.ts b/src/app/services/models/api.settings.ts index 0b82ffc7..1b001c8f 100644 --- a/src/app/services/models/api.settings.ts +++ b/src/app/services/models/api.settings.ts @@ -70,4 +70,6 @@ export class ApiRoutes { getScheduledStatuses = '/api/v1/scheduled_statuses'; putScheduleStatus = '/api/v1/scheduled_statuses/{0}'; deleteScheduleStatus = '/api/v1/scheduled_statuses/{0}'; + bookmarkingStatus = '/api/v1/statuses/{0}/bookmark'; + unbookmarkingStatus = '/api/v1/statuses/{0}/unbookmark'; } diff --git a/src/app/services/models/mastodon.interfaces.ts b/src/app/services/models/mastodon.interfaces.ts index b5c8f476..844585e6 100644 --- a/src/app/services/models/mastodon.interfaces.ts +++ b/src/app/services/models/mastodon.interfaces.ts @@ -187,6 +187,7 @@ export interface Status { language: string; pinned: boolean; muted: boolean; + bookmarked: boolean; card: Card; poll: Poll;