Add read notifications method for pleroma API
This commit is contained in:
parent
d782a86cb1
commit
f65652f2a1
|
@ -1881,6 +1881,16 @@ export default class Mastodon implements MegalodonInterface {
|
|||
return this.client.post<{}>(`/api/v1/notifications/${id}/dismiss`)
|
||||
}
|
||||
|
||||
public readNotifications(_options: {
|
||||
id?: string
|
||||
max_id?: string
|
||||
}): Promise<Response<Entity.Notification | Array<Entity.Notification>>> {
|
||||
return new Promise((_, reject) => {
|
||||
const err = new NoImplementedError('mastodon does not support')
|
||||
reject(err)
|
||||
})
|
||||
}
|
||||
|
||||
// ======================================
|
||||
// notifications/push
|
||||
// ======================================
|
||||
|
|
|
@ -1072,6 +1072,14 @@ export interface MegalodonInterface {
|
|||
* @param id Target notification ID.
|
||||
*/
|
||||
dismissNotification(id: string): Promise<Response<{}>>
|
||||
/**
|
||||
* POST /api/v1/pleroma/notifcations/read
|
||||
*
|
||||
* @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<Response<Entity.Notification | Array<Entity.Notification>>>
|
||||
// ======================================
|
||||
// notifications/push
|
||||
// ======================================
|
||||
|
|
|
@ -1793,6 +1793,16 @@ export default class Misskey implements MegalodonInterface {
|
|||
})
|
||||
}
|
||||
|
||||
public async readNotifications(_options: {
|
||||
id?: string
|
||||
max_id?: string
|
||||
}): Promise<Response<Entity.Notification | Array<Entity.Notification>>> {
|
||||
return new Promise((_, reject) => {
|
||||
const err = new NoImplementedError('mastodon does not support')
|
||||
reject(err)
|
||||
})
|
||||
}
|
||||
|
||||
// ======================================
|
||||
// notifications/push
|
||||
// ======================================
|
||||
|
|
|
@ -3,7 +3,7 @@ import FormData from 'form-data'
|
|||
|
||||
import PleromaAPI from './pleroma/api_client'
|
||||
import WebSocket from './pleroma/web_socket'
|
||||
import { MegalodonInterface, StreamListenerInterface, NoImplementedError } from './megalodon'
|
||||
import { MegalodonInterface, StreamListenerInterface, NoImplementedError, ArgumentError } from './megalodon'
|
||||
import Response from './response'
|
||||
import Entity from './entity'
|
||||
import { NO_REDIRECT, DEFAULT_SCOPE, DEFAULT_UA } from './default'
|
||||
|
@ -1888,6 +1888,38 @@ export default class Pleroma implements MegalodonInterface {
|
|||
return this.client.post<{}>(`/api/v1/notifications/${id}/dismiss`)
|
||||
}
|
||||
|
||||
public async readNotifications(options: {
|
||||
id?: string
|
||||
max_id?: string
|
||||
}): Promise<Response<Entity.Notification | Array<Entity.Notification>>> {
|
||||
if (options.id) {
|
||||
return this.client
|
||||
.post<PleromaAPI.Entity.Notification>('/api/v1/pleroma/notifications/read', {
|
||||
id: options.id
|
||||
})
|
||||
.then(res => {
|
||||
return Object.assign(res, {
|
||||
data: PleromaAPI.Converter.notification(res.data)
|
||||
})
|
||||
})
|
||||
} else if (options.max_id) {
|
||||
return this.client
|
||||
.post<Array<PleromaAPI.Entity.Notification>>('/api/v1/pleroma/notifications/read', {
|
||||
max_id: options.max_id
|
||||
})
|
||||
.then(res => {
|
||||
return Object.assign(res, {
|
||||
data: res.data.map(n => PleromaAPI.Converter.notification(n))
|
||||
})
|
||||
})
|
||||
} else {
|
||||
return new Promise((_, reject) => {
|
||||
const err = new ArgumentError('id or max_id is required')
|
||||
reject(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ======================================
|
||||
// notifications/push
|
||||
// ======================================
|
||||
|
|
Loading…
Reference in a new issue