Fix exclude_types for notifications
This commit is contained in:
parent
07e7185a61
commit
f525163c5e
15
example/typescript/src/pleroma/notification.ts
Normal file
15
example/typescript/src/pleroma/notification.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import generator, { NotificationType } from 'megalodon'
|
||||
|
||||
declare var process: {
|
||||
env: {
|
||||
PLEROMA_ACCESS_TOKEN: string
|
||||
}
|
||||
}
|
||||
|
||||
const BASE_URL: string = 'https://pleroma.io'
|
||||
|
||||
const access_token: string = process.env.PLEROMA_ACCESS_TOKEN
|
||||
|
||||
const client = generator('mastodon', BASE_URL, access_token)
|
||||
|
||||
client.getNotifications({ exclude_types: [NotificationType.Favourite, NotificationType.Reblog] }).then(res => console.log(res.data))
|
|
@ -2,7 +2,7 @@ import Response from './response'
|
|||
import OAuth from './oauth'
|
||||
import { isCancel, RequestCanceledError } from './cancel'
|
||||
import { ProxyConfig } from './proxy_config'
|
||||
import generator, { detector, MegalodonInterface, WebSocketInterface, StreamListenerInterface } from './megalodon'
|
||||
import generator, { detector, MegalodonInterface, WebSocketInterface, StreamListenerInterface, NotificationType } from './megalodon'
|
||||
import Mastodon from './mastodon'
|
||||
import Pleroma from './pleroma'
|
||||
import Misskey from './misskey'
|
||||
|
@ -18,6 +18,7 @@ export {
|
|||
MegalodonInterface,
|
||||
WebSocketInterface,
|
||||
StreamListenerInterface,
|
||||
NotificationType,
|
||||
Mastodon,
|
||||
Pleroma,
|
||||
Misskey,
|
||||
|
|
|
@ -4,7 +4,7 @@ import { ProxyConfig } from './proxy_config'
|
|||
import OAuth from './oauth'
|
||||
import Response from './response'
|
||||
import WebSocket from './mastodon/web_socket'
|
||||
import { MegalodonInterface, StreamListenerInterface, NoImplementedError } from './megalodon'
|
||||
import { MegalodonInterface, StreamListenerInterface, NoImplementedError, NotificationType } from './megalodon'
|
||||
import Entity from './entity'
|
||||
import { NO_REDIRECT, DEFAULT_SCOPE, DEFAULT_UA } from './default'
|
||||
|
||||
|
@ -281,8 +281,34 @@ export default class Mastodon implements MegalodonInterface {
|
|||
})
|
||||
}
|
||||
|
||||
public async getAccountStatuses(id: string): Promise<Response<Array<Entity.Status>>> {
|
||||
return this.client.get<Array<MastodonAPI.Entity.Status>>(`/api/v1/accounts/${id}/statuses`).then(res => {
|
||||
public async getAccountStatuses(
|
||||
id: string,
|
||||
options?: { limit?: number; max_id?: string; since_id?: string; pinned: boolean }
|
||||
): Promise<Response<Array<Entity.Status>>> {
|
||||
let params = {}
|
||||
if (options) {
|
||||
if (options.limit) {
|
||||
params = Object.assign(params, {
|
||||
limit: options.limit
|
||||
})
|
||||
}
|
||||
if (options.max_id) {
|
||||
params = Object.assign(params, {
|
||||
max_id: options.max_id
|
||||
})
|
||||
}
|
||||
if (options.since_id) {
|
||||
params = Object.assign(params, {
|
||||
since_id: options.since_id
|
||||
})
|
||||
}
|
||||
if (options.pinned) {
|
||||
params = Object.assign(params, {
|
||||
pinned: options.pinned
|
||||
})
|
||||
}
|
||||
}
|
||||
return this.client.get<Array<MastodonAPI.Entity.Status>>(`/api/v1/accounts/${id}/statuses`, params).then(res => {
|
||||
return Object.assign(res, {
|
||||
data: res.data.map(s => MastodonAPI.Converter.status(s))
|
||||
})
|
||||
|
@ -399,16 +425,18 @@ export default class Mastodon implements MegalodonInterface {
|
|||
})
|
||||
}
|
||||
|
||||
public async followAccount(id: string, reblog: boolean = true): Promise<Response<Entity.Relationship>> {
|
||||
return this.client
|
||||
.post<MastodonAPI.Entity.Relationship>(`/api/v1/accounts/${id}/follow`, {
|
||||
public async followAccount(id: string, reblog?: boolean): Promise<Response<Entity.Relationship>> {
|
||||
let params = {}
|
||||
if (reblog !== undefined) {
|
||||
params = Object.assign(params, {
|
||||
reblog: reblog
|
||||
})
|
||||
.then(res => {
|
||||
return Object.assign(res, {
|
||||
data: MastodonAPI.Converter.relationship(res.data)
|
||||
})
|
||||
}
|
||||
return this.client.post<MastodonAPI.Entity.Relationship>(`/api/v1/accounts/${id}/follow`, params).then(res => {
|
||||
return Object.assign(res, {
|
||||
data: MastodonAPI.Converter.relationship(res.data)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public async unfollowAccount(id: string): Promise<Response<Entity.Relationship>> {
|
||||
|
@ -1068,8 +1096,29 @@ export default class Mastodon implements MegalodonInterface {
|
|||
})
|
||||
}
|
||||
|
||||
public async getStatusContext(id: string): Promise<Response<Entity.Context>> {
|
||||
return this.client.get<MastodonAPI.Entity.Context>(`/api/v1/statuses/${id}/context`).then(res => {
|
||||
public async getStatusContext(
|
||||
id: string,
|
||||
options?: { limit?: number; max_id?: string; since_id?: string }
|
||||
): Promise<Response<Entity.Context>> {
|
||||
let params = {}
|
||||
if (options) {
|
||||
if (options.limit) {
|
||||
params = Object.assign(params, {
|
||||
limit: options.limit
|
||||
})
|
||||
}
|
||||
if (options.max_id) {
|
||||
params = Object.assign(params, {
|
||||
max_id: options.max_id
|
||||
})
|
||||
}
|
||||
if (options.since_id) {
|
||||
params = Object.assign(params, {
|
||||
since_id: options.since_id
|
||||
})
|
||||
}
|
||||
}
|
||||
return this.client.get<MastodonAPI.Entity.Context>(`/api/v1/statuses/${id}/context`, params).then(res => {
|
||||
return Object.assign(res, {
|
||||
data: MastodonAPI.Converter.context(res.data)
|
||||
})
|
||||
|
@ -1715,7 +1764,7 @@ export default class Mastodon implements MegalodonInterface {
|
|||
max_id?: string
|
||||
since_id?: string
|
||||
min_id?: string
|
||||
exclude_type?: Array<'follow' | 'favourite' | 'reblog' | 'mention' | 'poll'>
|
||||
exclude_types?: Array<NotificationType>
|
||||
account_id?: string
|
||||
}): Promise<Response<Array<Entity.Notification>>> {
|
||||
let params = {}
|
||||
|
@ -1740,9 +1789,9 @@ export default class Mastodon implements MegalodonInterface {
|
|||
min_id: options.min_id
|
||||
})
|
||||
}
|
||||
if (options.exclude_type) {
|
||||
if (options.exclude_types) {
|
||||
params = Object.assign(params, {
|
||||
exclude_type: options.exclude_type
|
||||
exclude_types: options.exclude_types
|
||||
})
|
||||
}
|
||||
if (options.account_id) {
|
||||
|
|
|
@ -166,7 +166,10 @@ export interface MegalodonInterface {
|
|||
* @param id The account ID.
|
||||
* @return Account's statuses.
|
||||
*/
|
||||
getAccountStatuses(id: string): Promise<Response<Array<Entity.Status>>>
|
||||
getAccountStatuses(
|
||||
id: string,
|
||||
options?: { limit?: number; max_id?: string; since_id?: string; pinned: boolean }
|
||||
): Promise<Response<Array<Entity.Status>>>
|
||||
/**
|
||||
* GET /api/v1/pleroma/accounts/:id/favourites
|
||||
*
|
||||
|
@ -253,7 +256,7 @@ export interface MegalodonInterface {
|
|||
* @param reblog Receive this account's reblogs in home timeline.
|
||||
* @return Relationship
|
||||
*/
|
||||
followAccount(id: string, reblog: boolean): Promise<Response<Entity.Relationship>>
|
||||
followAccount(id: string, reblog?: boolean): Promise<Response<Entity.Relationship>>
|
||||
/**
|
||||
* POST /api/v1/accounts/:id/unfollow
|
||||
*
|
||||
|
@ -614,7 +617,7 @@ export interface MegalodonInterface {
|
|||
* @param id The target status id.
|
||||
* @return Context
|
||||
*/
|
||||
getStatusContext(id: string): Promise<Response<Entity.Context>>
|
||||
getStatusContext(id: string, options?: { limit?: number; max_id?: string; since_id?: string }): Promise<Response<Entity.Context>>
|
||||
/**
|
||||
* GET /api/v1/statuses/:id/reblogged_by
|
||||
*
|
||||
|
@ -1010,7 +1013,7 @@ export interface MegalodonInterface {
|
|||
* @param options.max_id Return results older than ID.
|
||||
* @param options.since_id Return results newer than ID.
|
||||
* @param options.min_id Return results immediately newer than ID.
|
||||
* @param options.exclude_type Array of types to exclude.
|
||||
* @param options.exclude_types Array of types to exclude.
|
||||
* @param options.account_id Return only notifications received from this account.
|
||||
* @return Array of notifications.
|
||||
*/
|
||||
|
@ -1019,7 +1022,7 @@ export interface MegalodonInterface {
|
|||
max_id?: string
|
||||
since_id?: string
|
||||
min_id?: string
|
||||
exclude_type?: Array<'follow' | 'favourite' | 'reblog' | 'mention' | 'poll'>
|
||||
exclude_types?: Array<NotificationType>
|
||||
account_id?: string
|
||||
}): Promise<Response<Array<Entity.Notification>>>
|
||||
/**
|
||||
|
@ -1289,4 +1292,12 @@ const generator = (
|
|||
}
|
||||
}
|
||||
|
||||
export enum NotificationType {
|
||||
Follow = 'follow',
|
||||
Favourite = 'favourite',
|
||||
Reblog = 'reblog',
|
||||
Mention = 'mention',
|
||||
Poll = 'poll'
|
||||
}
|
||||
|
||||
export default generator
|
||||
|
|
106
src/misskey.ts
106
src/misskey.ts
|
@ -9,7 +9,8 @@ import {
|
|||
WebSocketInterface,
|
||||
NoImplementedError,
|
||||
ArgumentError,
|
||||
UnexpectedError
|
||||
UnexpectedError,
|
||||
NotificationType
|
||||
} from './megalodon'
|
||||
|
||||
export default class Misskey implements MegalodonInterface {
|
||||
|
@ -283,17 +284,49 @@ export default class Misskey implements MegalodonInterface {
|
|||
/**
|
||||
* POST /api/users/notes
|
||||
*/
|
||||
public async getAccountStatuses(id: string): Promise<Response<Array<Entity.Status>>> {
|
||||
return this.client
|
||||
.post<Array<MisskeyAPI.Entity.Note>>('/api/users/notes', {
|
||||
userId: id
|
||||
})
|
||||
.then(res => {
|
||||
const statuses: Array<Entity.Status> = res.data.map(note => MisskeyAPI.Converter.note(note))
|
||||
return Object.assign(res, {
|
||||
data: statuses
|
||||
public async getAccountStatuses(
|
||||
id: string,
|
||||
options?: { limit?: number; max_id?: string; since_id?: string; pinned: boolean }
|
||||
): Promise<Response<Array<Entity.Status>>> {
|
||||
if (options && options.pinned) {
|
||||
return this.client
|
||||
.post<MisskeyAPI.Entity.UserDetail>('/api/usres/show', {
|
||||
userId: id
|
||||
})
|
||||
.then(res => {
|
||||
if (res.data.pinnedNotes) {
|
||||
return { ...res, data: res.data.pinnedNotes.map(n => MisskeyAPI.Converter.note(n)) }
|
||||
}
|
||||
return { ...res, data: [] }
|
||||
})
|
||||
}
|
||||
|
||||
let params = {
|
||||
userId: id
|
||||
}
|
||||
if (options) {
|
||||
if (options.limit) {
|
||||
params = Object.assign(params, {
|
||||
limit: options.limit
|
||||
})
|
||||
}
|
||||
if (options.max_id) {
|
||||
params = Object.assign(params, {
|
||||
untilId: options.max_id
|
||||
})
|
||||
}
|
||||
if (options.since_id) {
|
||||
params = Object.assign(params, {
|
||||
sinceId: options.since_id
|
||||
})
|
||||
}
|
||||
}
|
||||
return this.client.post<Array<MisskeyAPI.Entity.Note>>('/api/users/notes', params).then(res => {
|
||||
const statuses: Array<Entity.Status> = res.data.map(note => MisskeyAPI.Converter.note(note))
|
||||
return Object.assign(res, {
|
||||
data: statuses
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public async getAccountFavourites(
|
||||
|
@ -397,7 +430,7 @@ export default class Misskey implements MegalodonInterface {
|
|||
/**
|
||||
* POST /api/following/create
|
||||
*/
|
||||
public async followAccount(id: string, _reblog: boolean): Promise<Response<Entity.Relationship>> {
|
||||
public async followAccount(id: string, _reblog?: boolean): Promise<Response<Entity.Relationship>> {
|
||||
await this.client.post<{}>('api/following/create', {
|
||||
userId: id
|
||||
})
|
||||
|
@ -1002,21 +1035,40 @@ export default class Misskey implements MegalodonInterface {
|
|||
/**
|
||||
* POST /api/notes/children
|
||||
*/
|
||||
public async getStatusContext(id: string): Promise<Response<Entity.Context>> {
|
||||
return this.client
|
||||
.post<Array<MisskeyAPI.Entity.Note>>('/api/notes/children', {
|
||||
noteId: id
|
||||
})
|
||||
.then(res => {
|
||||
const context: Entity.Context = {
|
||||
ancestors: [],
|
||||
descendants: res.data.map(n => MisskeyAPI.Converter.note(n))
|
||||
}
|
||||
return {
|
||||
...res,
|
||||
data: context
|
||||
}
|
||||
})
|
||||
public async getStatusContext(
|
||||
id: string,
|
||||
options?: { limit?: number; max_id?: string; since_id?: string }
|
||||
): Promise<Response<Entity.Context>> {
|
||||
let params = {
|
||||
noteId: id
|
||||
}
|
||||
if (options) {
|
||||
if (options.limit) {
|
||||
params = Object.assign(params, {
|
||||
limit: options.limit
|
||||
})
|
||||
}
|
||||
if (options.max_id) {
|
||||
params = Object.assign(params, {
|
||||
untilId: options.max_id
|
||||
})
|
||||
}
|
||||
if (options.since_id) {
|
||||
params = Object.assign(params, {
|
||||
sinceId: options.since_id
|
||||
})
|
||||
}
|
||||
}
|
||||
return this.client.post<Array<MisskeyAPI.Entity.Note>>('/api/notes/children', params).then(res => {
|
||||
const context: Entity.Context = {
|
||||
ancestors: [],
|
||||
descendants: res.data.map(n => MisskeyAPI.Converter.note(n))
|
||||
}
|
||||
return {
|
||||
...res,
|
||||
data: context
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1640,7 +1692,7 @@ export default class Misskey implements MegalodonInterface {
|
|||
max_id?: string
|
||||
since_id?: string
|
||||
min_id?: string
|
||||
exclude_type?: Array<'follow' | 'favourite' | 'reblog' | 'mention' | 'poll'>
|
||||
exclude_type?: Array<NotificationType>
|
||||
account_id?: string
|
||||
}): Promise<Response<Array<Entity.Notification>>> {
|
||||
let params = {}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/// <reference path="emoji.ts" />
|
||||
/// <reference path="note.ts" />
|
||||
|
||||
namespace MisskeyEntity {
|
||||
export type UserDetail = {
|
||||
|
@ -25,5 +26,7 @@ namespace MisskeyEntity {
|
|||
notesCount: number
|
||||
avatarId: string
|
||||
bannerId: string
|
||||
pinnedNoteIds?: Array<string>
|
||||
pinnedNotes?: Array<Note>
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue