From 15877609e44c0d2191ad6dab92340c32f25f12b2 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Mon, 21 Oct 2024 23:06:01 +0900
Subject: [PATCH] Fix API response of pleroma read notifications
---
.../typescript/src/pleroma/notification.ts | 2 +-
.../src/pleroma/read_notifications.ts | 33 +++++++++++++++++++
megalodon/src/firefish.ts | 5 +--
megalodon/src/friendica.ts | 5 +--
megalodon/src/gotosocial.ts | 5 +--
megalodon/src/mastodon.ts | 5 +--
megalodon/src/megalodon.ts | 3 +-
megalodon/src/pleroma.ts | 22 +++----------
8 files changed, 44 insertions(+), 36 deletions(-)
create mode 100644 example/typescript/src/pleroma/read_notifications.ts
diff --git a/example/typescript/src/pleroma/notification.ts b/example/typescript/src/pleroma/notification.ts
index f539792bf..a5b8adc66 100644
--- a/example/typescript/src/pleroma/notification.ts
+++ b/example/typescript/src/pleroma/notification.ts
@@ -12,4 +12,4 @@ const access_token: string = process.env.PLEROMA_ACCESS_TOKEN
const client = generator('pleroma', BASE_URL, access_token)
-client.getNotifications({ exclude_types: [NotificationType.Favourite, NotificationType.Reblog] }).then(res => console.log(res.data))
+client.getNotifications({ exclude_types: [NotificationType.Reblog] }).then(res => console.log(res.data))
diff --git a/example/typescript/src/pleroma/read_notifications.ts b/example/typescript/src/pleroma/read_notifications.ts
new file mode 100644
index 000000000..e44b23d9d
--- /dev/null
+++ b/example/typescript/src/pleroma/read_notifications.ts
@@ -0,0 +1,33 @@
+import * as readline from 'readline'
+import generator, { Entity, Response } from 'megalodon'
+
+const rl: readline.ReadLine = readline.createInterface({
+ input: process.stdin,
+ output: process.stdout
+})
+
+const BASE_URL: string = 'https://pleroma.io'
+
+const access_token: string = process.env.PLEROMA_ACCESS_TOKEN as string
+
+const client = generator('pleroma', BASE_URL, access_token)
+
+new Promise(resolve => {
+ rl.question('Max notification ID: ', max_id => {
+ client
+ .readNotifications({ max_id: max_id })
+ .then(res => {
+ console.log(res)
+ rl.close()
+ client.getMarkers(['home', 'notifications']).then((res: Response>) => {
+ console.log(res.data)
+ })
+
+ resolve(res)
+ })
+ .catch(err => {
+ console.error(err)
+ rl.close()
+ })
+ })
+})
diff --git a/megalodon/src/firefish.ts b/megalodon/src/firefish.ts
index 2731c6f54..efb729a0e 100644
--- a/megalodon/src/firefish.ts
+++ b/megalodon/src/firefish.ts
@@ -1926,10 +1926,7 @@ export default class Firefish implements MegalodonInterface {
})
}
- public async readNotifications(_options: {
- id?: string
- max_id?: string
- }): Promise>> {
+ public async readNotifications(_options: { id?: string; max_id?: string }): Promise> {
return new Promise((_, reject) => {
const err = new NotImplementedError('mastodon does not support')
reject(err)
diff --git a/megalodon/src/friendica.ts b/megalodon/src/friendica.ts
index fb670e818..3de3b6cf0 100644
--- a/megalodon/src/friendica.ts
+++ b/megalodon/src/friendica.ts
@@ -2466,10 +2466,7 @@ export default class Friendica implements MegalodonInterface {
return this.client.post>(`/api/v1/notifications/${id}/dismiss`)
}
- public readNotifications(_options: {
- id?: string
- max_id?: string
- }): Promise>> {
+ public readNotifications(_options: { id?: string; max_id?: string }): Promise> {
return new Promise((_, reject) => {
const err = new NotImplementedError('Friendica does not support this method')
reject(err)
diff --git a/megalodon/src/gotosocial.ts b/megalodon/src/gotosocial.ts
index 69a70cd76..a472cc1a4 100644
--- a/megalodon/src/gotosocial.ts
+++ b/megalodon/src/gotosocial.ts
@@ -2431,10 +2431,7 @@ export default class Gotosocial implements MegalodonInterface {
})
}
- public readNotifications(_options: {
- id?: string
- max_id?: string
- }): Promise>> {
+ public readNotifications(_options: { id?: string; max_id?: string }): Promise> {
return new Promise((_, reject) => {
const err = new NotImplementedError('Gotosocial does not support this method')
reject(err)
diff --git a/megalodon/src/mastodon.ts b/megalodon/src/mastodon.ts
index cc33bf98c..744cdb76e 100644
--- a/megalodon/src/mastodon.ts
+++ b/megalodon/src/mastodon.ts
@@ -2803,10 +2803,7 @@ export default class Mastodon implements MegalodonInterface {
return this.client.post<{}>(`/api/v1/notifications/${id}/dismiss`)
}
- public readNotifications(_options: {
- id?: string
- max_id?: string
- }): Promise>> {
+ public readNotifications(_options: { id?: string; max_id?: string }): Promise> {
return new Promise((_, reject) => {
const err = new NotImplementedError('Mastodon does not support this method')
reject(err)
diff --git a/megalodon/src/megalodon.ts b/megalodon/src/megalodon.ts
index 281a5a655..97adf87e3 100644
--- a/megalodon/src/megalodon.ts
+++ b/megalodon/src/megalodon.ts
@@ -1183,9 +1183,8 @@ export interface MegalodonInterface {
*
* @param id A single notification ID to read
* @param max_id Read all notifications up to this ID
- * @return Array of notifications
*/
- readNotifications(options: { id?: string; max_id?: string }): Promise>>
+ readNotifications(options: { id?: string; max_id?: string }): Promise>
// ======================================
// notifications/push
// ======================================
diff --git a/megalodon/src/pleroma.ts b/megalodon/src/pleroma.ts
index cb64fe676..d14562e72 100644
--- a/megalodon/src/pleroma.ts
+++ b/megalodon/src/pleroma.ts
@@ -2781,29 +2781,17 @@ export default class Pleroma implements MegalodonInterface {
* @param max_id Read all notifications up to this ID
* @return Array of notifications
*/
- public async readNotifications(options: {
- id?: string
- max_id?: string
- }): Promise>> {
+ public async readNotifications(options: { id?: string; max_id?: string }): Promise> {
if (options.id) {
- const res = await this.client.post('/api/v1/pleroma/notifications/read', {
+ const res = await this.client.post<{}>('/api/v1/pleroma/notifications/read', {
id: options.id
})
- const notify = PleromaAPI.Converter.notification(res.data)
- if (notify instanceof UnknownNotificationTypeError) return { ...res, data: [] }
- return { ...res, data: notify }
+ return res
} else if (options.max_id) {
- const res = await this.client.post>('/api/v1/pleroma/notifications/read', {
+ const res = await this.client.post<{}>('/api/v1/pleroma/notifications/read', {
max_id: options.max_id
})
- return {
- ...res,
- data: res.data.flatMap(n => {
- const notify = PleromaAPI.Converter.notification(n)
- if (notify instanceof UnknownNotificationTypeError) return []
- return notify
- })
- }
+ return res
} else {
return new Promise((_, reject) => {
const err = new ArgumentError('id or max_id is required')