Repository: neet/masto.js
Pull request #196 (2020-01-29 04:19:20)

Merge pull request #196 from neet/mastodon-3.1.0-rc1


Patch:
diff --git a/cspell.json b/cspell.json
index 11b8bd64..4ffab944 100644
--- a/cspell.json
+++ b/cspell.json
@@ -27,6 +27,7 @@
     "unfollow",
     "unreblog",
     "unreviewed",
-    "unsilence"
+    "unsilence",
+    "unbookmark"
   ]
 }
diff --git a/src/clients/masto-admin/params.ts b/src/clients/masto-admin/params.ts
index 29fb2900..477d1055 100644
--- a/src/clients/masto-admin/params.ts
+++ b/src/clients/masto-admin/params.ts
@@ -18,6 +18,7 @@ export interface AdminFetchReportsParams {
   resolved?: boolean | null;
   account_id?: string | null;
   target_account_id?: string | null;
+  by_target_domain?: string | null;
 }
 
 export type AccountActionType = 'none' | 'disable' | 'silence' | 'suspend';
diff --git a/src/clients/masto/masto.ts b/src/clients/masto/masto.ts
index bd7d638f..4e274719 100644
--- a/src/clients/masto/masto.ts
+++ b/src/clients/masto/masto.ts
@@ -1,3 +1,5 @@
+import { Announcement } from '../../entities/announcement';
+import { Reaction } from '../../entities/reaction';
 import {
   Account,
   AccountCredentials,
@@ -1142,6 +1144,35 @@ export class Masto extends Gateway {
     return this.post<Status>(`/api/v1/statuses/${id}/unpin`);
   }
 
+  /**
+   * Fetch bookmarked statuses
+   * @return Statuses
+   */
+  @available({ since: '3.0.1' })
+  fetchBookmarks() {
+    return this.get<Status[]>(`/api/v1/bookmarks`);
+  }
+
+  /**
+   * Bookmark the status
+   * @param id ID of the status
+   * @return Status
+   */
+  @available({ since: '3.1.0' })
+  bookmarkStatus(id: string) {
+    return this.post<Status>(`/api/v1/statuses/${id}/bookmark`);
+  }
+
+  /**
+   * Unbookmark the status
+   * @param id ID of the status
+   * @return Status
+   */
+  @available({ since: '3.1.0' })
+  unbookmarkStatus(id: string) {
+    return this.post<Status>(`/api/v1/statuses/${id}/unbookmark`);
+  }
+
   /**
    * Retrieving the home timeline
    * @param params Query parameter
@@ -1329,4 +1360,47 @@ export class Masto extends Gateway {
   fetchDirectory(params: FetchDirectoryParams) {
     return this.get<Account[]>('/api/v1/directory', params);
   }
+
+  /**
+   * Fetch announcements
+   * @return Announcements
+   */
+  @available({ since: '3.0.1' })
+  fetchAnnouncements() {
+    return this.get<Announcement[]>('/api/v1/announcements');
+  }
+
+  /**
+   * Dismiss announcement
+   * @param id ID of the announcement
+   * @return Nothing
+   */
+  @available({ since: '3.0.1' })
+  dismissAnnouncement(id: string) {
+    return this.post<void>(`/api/v1/announcements/${id}/dismiss`);
+  }
+
+  /**
+   * Add a reaction to an announcement
+   * @param id ID of the announcement
+   * @param name Emoji string
+   * @return Announcement
+   */
+  @available({ since: '3.0.1' })
+  addReactionToAnnouncement(id: string, name: string) {
+    return this.put<Reaction>(`/api/v1/announcements/${id}/reactions/${name}`);
+  }
+
+  /**
+   * Remove a reaction from an announcement
+   * @param id ID of the announcement
+   * @param name Emoji string
+   * @return Announcement
+   */
+  @available({ since: '3.0.1' })
+  removeReactionFromAnnouncement(id: string, name: string) {
+    return this.delete<Reaction>(
+      `/api/v1/announcements/${id}/reactions/${name}`,
+    );
+  }
 }
diff --git a/src/entities/account.ts b/src/entities/account.ts
index 87bc443b..29f22484 100644
--- a/src/entities/account.ts
+++ b/src/entities/account.ts
@@ -16,6 +16,8 @@ export interface Account {
   bot?: boolean | null;
   /** The time the account was created */
   created_at: string;
+  /** Time of the last status posted */
+  last_status_at: string;
   /** The number of followers for the account */
   followers_count: number;
   /** The number of accounts the given account is following */
@@ -40,6 +42,8 @@ export interface Account {
   moved?: boolean | null;
   /** Array of profile metadata field, each element has 'name' and 'value' */
   fields?: AccountField[] | null;
+  /** no-index flag */
+  discoverable?: false;
 }
 
 export interface AccountField {
diff --git a/src/entities/announcement.ts b/src/entities/announcement.ts
new file mode 100644
index 00000000..6443ab48
--- /dev/null
+++ b/src/entities/announcement.ts
@@ -0,0 +1,16 @@
+import { Mention } from './mention';
+import { Tag } from './tag';
+import { Emoji } from './emoji';
+import { Reaction } from './reaction';
+
+export interface Announcement {
+  id: string;
+  content: string;
+  starts_at: string;
+  ends_at: string;
+  all_day: boolean;
+  mentions: Mention[];
+  tags: Tag[];
+  emojis: Emoji[];
+  reactions: Reaction[];
+}
diff --git a/src/entities/filter.ts b/src/entities/filter.ts
index d0764d28..0a857bc5 100644
--- a/src/entities/filter.ts
+++ b/src/entities/filter.ts
@@ -1,5 +1,10 @@
 /** Type of filter context */
-export type FilterContext = 'home' | 'notifications' | 'public' | 'thread';
+export type FilterContext =
+  | 'home'
+  | 'notifications'
+  | 'public'
+  | 'thread'
+  | 'account';
 
 export interface Filter {
   /** ID of the filter */
diff --git a/src/entities/notification.ts b/src/entities/notification.ts
index 0d166fdc..a8e490ea 100644
--- a/src/entities/notification.ts
+++ b/src/entities/notification.ts
@@ -6,7 +6,8 @@ export type NotificationType =
   | 'reblog'
   | 'favourite'
   | 'follow'
-  | 'poll';
+  | 'poll'
+  | 'follow_request';
 
 export interface Notification {
   /** The notification ID */
diff --git a/src/entities/reaction.ts b/src/entities/reaction.ts
new file mode 100644
index 00000000..296d28bb
--- /dev/null
+++ b/src/entities/reaction.ts
@@ -0,0 +1,7 @@
+export interface Reaction {
+  name: string;
+  count: number;
+  me: boolean;
+  url: string;
+  static_url: string;
+}
diff --git a/src/entities/status.ts b/src/entities/status.ts
index ff780b61..a9c0f66b 100644
--- a/src/entities/status.ts
+++ b/src/entities/status.ts
@@ -61,4 +61,6 @@ export interface Status {
   language?: string | null;
   /** Whether this is the pinned status for the account that posted it */
   pinned?: boolean | null;
+  /** Whether the status was bookmarked */
+  bookmarked?: boolean | null;
 }


Test patch:
diff --git a/src/clients/masto/__tests__/__snapshots__/masto.spec.ts.snap b/src/clients/masto/__tests__/__snapshots__/masto.spec.ts.snap
index 61739d06..4b1b388c 100644
--- a/src/clients/masto/__tests__/__snapshots__/masto.spec.ts.snap
+++ b/src/clients/masto/__tests__/__snapshots__/masto.spec.ts.snap
@@ -56,6 +56,22 @@ exports[`Masto addPushSubscription 1`] = `
 }
 `;
 
+exports[`Masto addReactionToAnnouncement 1`] = `
+[MockFunction] {
+  "calls": Array [
+    Array [
+      "/api/v1/announcements/123/reactions/😁",
+    ],
+  ],
+  "results": Array [
+    Object {
+      "type": "return",
+      "value": undefined,
+    },
+  ],
+}
+`;
+
 exports[`Masto authorizeFollowRequest 1`] = `
 [MockFunction] {
   "calls": Array [
@@ -107,6 +123,22 @@ exports[`Masto blockDomain 1`] = `
 }
 `;
 
+exports[`Masto bookmarkStatus 1`] = `
+[MockFunction] {
+  "calls": Array [
+    Array [
+      "/api/v1/statuses/123/bookmark",
+    ],
+  ],
+  "results": Array [
+    Object {
+      "type": "return",
+      "value": undefined,
+    },
+  ],
+}
+`;
+
 exports[`Masto clearNotifications 1`] = `
 [MockFunction] {
   "calls": Array [
@@ -338,6 +370,22 @@ exports[`Masto createStatus with media ids 1`] = `
 }
 `;
 
+exports[`Masto dismissAnnouncement 1`] = `
+[MockFunction] {
+  "calls": Array [
+    Array [
+      "/api/v1/announcements/123/dismiss",
+    ],
+  ],
+  "results": Array [
+    Object {
+      "type": "return",
+      "value": undefined,
+    },
+  ],
+}
+`;
+
 exports[`Masto dismissNotification 1`] = `
 [MockFunction] {
   "calls": Array [
@@ -550,6 +598,22 @@ exports[`Masto fetchAccountStatuses 1`] = `
 }
 `;
 
+exports[`Masto fetchAnnouncements 1`] = `
+[MockFunction] {
+  "calls": Array [
+    Array [
+      "/api/v1/announcements",
+    ],
+  ],
+  "results": Array [
+    Object {
+      "type": "return",
+      "value": undefined,
+    },
+  ],
+}
+`;
+
 exports[`Masto fetchBlocks 1`] = `
 [MockFunction] {
   "calls": Array [
@@ -572,6 +636,22 @@ exports[`Masto fetchBlocks 1`] = `
 }
 `;
 
+exports[`Masto fetchBookmarks 1`] = `
+[MockFunction] {
+  "calls": Array [
+    Array [
+      "/api/v1/bookmarks",
+    ],
+  ],
+  "results": Array [
+    Object {
+      "type": "return",
+      "value": undefined,
+    },
+  ],
+}
+`;
+
 exports[`Masto fetchCommunityTimeline 1`] = `
 [MockFunction] {
   "calls": Array [
@@ -1513,6 +1593,22 @@ exports[`Masto removePushSubscription 1`] = `
 }
 `;
 
+exports[`Masto removeReactionFromAnnouncement 1`] = `
+[MockFunction] {
+  "calls": Array [
+    Array [
+      "/api/v1/announcements/123/reactions/😁",
+    ],
+  ],
+  "results": Array [
+    Object {
+      "type": "return",
+      "value": undefined,
+    },
+  ],
+}
+`;
+
 exports[`Masto removeScheduledStatus 1`] = `
 [MockFunction] {
   "calls": Array [
@@ -1843,6 +1939,22 @@ exports[`Masto unblockDomain 1`] = `
 }
 `;
 
+exports[`Masto unbookmarkStatus 1`] = `
+[MockFunction] {
+  "calls": Array [
+    Array [
+      "/api/v1/statuses/123/unbookmark",
+    ],
+  ],
+  "results": Array [
+    Object {
+      "type": "return",
+      "value": undefined,
+    },
+  ],
+}
+`;
+
 exports[`Masto unfavouriteStatus 1`] = `
 [MockFunction] {
   "calls": Array [
diff --git a/src/clients/masto/__tests__/masto.spec.ts b/src/clients/masto/__tests__/masto.spec.ts
index dd69872d..9f84b6b8 100644
--- a/src/clients/masto/__tests__/masto.spec.ts
+++ b/src/clients/masto/__tests__/masto.spec.ts
@@ -942,4 +942,46 @@ describe('Masto', () => {
     expect(mockGet).toBeCalledTimes(1);
     expect(mockGet).toMatchSnapshot();
   });
+
+  test('bookmarkStatus', async () => {
+    await masto.bookmarkStatus('123');
+    expect(mockPost).toBeCalledTimes(1);
+    expect(mockPost).toMatchSnapshot();
+  });
+
+  test('unbookmarkStatus', async () => {
+    await masto.unbookmarkStatus('123');
+    expect(mockPost).toBeCalledTimes(1);
+    expect(mockPost).toMatchSnapshot();
+  });
+
+  test('fetchBookmarks', async () => {
+    await masto.fetchBookmarks();
+    expect(mockGet).toBeCalledTimes(1);
+    expect(mockGet).toMatchSnapshot();
+  });
+
+  test('fetchAnnouncements', async () => {
+    await masto.fetchAnnouncements();
+    expect(mockGet).toBeCalledTimes(1);
+    expect(mockGet).toMatchSnapshot();
+  });
+
+  test('dismissAnnouncement', async () => {
+    await masto.dismissAnnouncement('123');
+    expect(mockPost).toBeCalledTimes(1);
+    expect(mockPost).toMatchSnapshot();
+  });
+
+  test('addReactionToAnnouncement', async () => {
+    await masto.addReactionToAnnouncement('123', '😁');
+    expect(mockPut).toBeCalledTimes(1);
+    expect(mockPut).toMatchSnapshot();
+  });
+
+  test('removeReactionFromAnnouncement', async () => {
+    await masto.removeReactionFromAnnouncement('123', '😁');
+    expect(mockDelete).toBeCalledTimes(1);
+    expect(mockDelete).toMatchSnapshot();
+  });
 });