refs #125 Implement notification methods for misskey
This commit is contained in:
parent
aae498b7e9
commit
b9d3afc029
|
@ -6,7 +6,7 @@ namespace Entity {
|
|||
account: Account
|
||||
created_at: string
|
||||
id: string
|
||||
status: Status | null
|
||||
type: 'mention' | 'reblog' | 'favourite' | 'follow'
|
||||
status?: Status
|
||||
type: 'mention' | 'reblog' | 'favourite' | 'follow' | 'poll'
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace MastodonEntity {
|
|||
account: Account
|
||||
created_at: string
|
||||
id: string
|
||||
status: Status | null
|
||||
type: 'mention' | 'reblog' | 'favourite' | 'follow'
|
||||
status?: Status
|
||||
type: 'mention' | 'reblog' | 'favourite' | 'follow' | 'poll'
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1559,4 +1559,65 @@ export default class Misskey {
|
|||
reject(err)
|
||||
})
|
||||
}
|
||||
|
||||
// ======================================
|
||||
// notifications
|
||||
// ======================================
|
||||
/**
|
||||
* POST /api/i/notifications
|
||||
*/
|
||||
public async getNotifications(
|
||||
limit?: number | null,
|
||||
max_id?: string | null,
|
||||
since_id?: string | null,
|
||||
_min_id?: string | null,
|
||||
exclude_type?: Array<'follow' | 'favourite' | 'reblog' | 'mention' | 'poll'> | null,
|
||||
_account_id?: string | null
|
||||
): Promise<Response<Array<Entity.Notification>>> {
|
||||
let params = {}
|
||||
if (limit) {
|
||||
params = Object.assign(params, {
|
||||
limit: limit
|
||||
})
|
||||
}
|
||||
if (max_id) {
|
||||
params = Object.assign(params, {
|
||||
untilId: max_id
|
||||
})
|
||||
}
|
||||
if (since_id) {
|
||||
params = Object.assign(params, {
|
||||
since_id: since_id
|
||||
})
|
||||
}
|
||||
if (exclude_type) {
|
||||
params = Object.assign(params, {
|
||||
excludeType: exclude_type.map(e => MisskeyAPI.Converter.encodeNotificationType(e))
|
||||
})
|
||||
}
|
||||
return this.client
|
||||
.post<Array<MisskeyAPI.Entity.Notification>>('/api/i/notifications', params)
|
||||
.then(res => ({ ...res, data: res.data.map(n => MisskeyAPI.Converter.notification(n)) }))
|
||||
}
|
||||
|
||||
public async getNotification(_id: string): Promise<Response<Entity.Notification>> {
|
||||
return new Promise((_, reject) => {
|
||||
const err = new NoImplementedError('misskey does not support')
|
||||
reject(err)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/notifications/mark-all-as-read
|
||||
*/
|
||||
public async dismissNotifications(): Promise<Response<{}>> {
|
||||
return this.client.post<{}>('/api/notifications/mark-all-as-read')
|
||||
}
|
||||
|
||||
public async dismissNotification(_id: string): Promise<Response<{}>> {
|
||||
return new Promise((_, reject) => {
|
||||
const err = new NoImplementedError('misskey does not support')
|
||||
reject(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace MisskeyAPI {
|
|||
export type List = MisskeyEntity.List
|
||||
export type Mute = MisskeyEntity.Mute
|
||||
export type Note = MisskeyEntity.Note
|
||||
export type Notification = MisskeyEntity.Notification
|
||||
export type Poll = MisskeyEntity.Poll
|
||||
export type Relation = MisskeyEntity.Relation
|
||||
export type User = MisskeyEntity.User
|
||||
|
@ -228,6 +229,68 @@ namespace MisskeyAPI {
|
|||
id: l.id,
|
||||
title: l.name
|
||||
})
|
||||
|
||||
export const encodeNotificationType = (
|
||||
e: 'follow' | 'favourite' | 'reblog' | 'mention' | 'poll'
|
||||
): 'follow' | 'mention' | 'reply' | 'renote' | 'quote' | 'reaction' | 'pollVote' => {
|
||||
switch (e) {
|
||||
case 'follow':
|
||||
return e
|
||||
case 'mention':
|
||||
return 'reply'
|
||||
case 'favourite':
|
||||
return 'reaction'
|
||||
case 'reblog':
|
||||
return 'renote'
|
||||
case 'poll':
|
||||
return 'pollVote'
|
||||
}
|
||||
}
|
||||
|
||||
export const decodeNotificationType = (
|
||||
e:
|
||||
| 'follow'
|
||||
| 'mention'
|
||||
| 'reply'
|
||||
| 'renote'
|
||||
| 'quote'
|
||||
| 'reaction'
|
||||
| 'pollVote'
|
||||
| 'receiveFollowRequest'
|
||||
| 'followRequestAccepted'
|
||||
| 'groupInvited'
|
||||
): 'follow' | 'favourite' | 'reblog' | 'mention' | 'poll' => {
|
||||
switch (e) {
|
||||
case 'follow':
|
||||
return e
|
||||
case 'mention':
|
||||
case 'reply':
|
||||
return 'mention'
|
||||
case 'renote':
|
||||
return 'reblog'
|
||||
case 'reaction':
|
||||
return 'favourite'
|
||||
case 'pollVote':
|
||||
return 'poll'
|
||||
default:
|
||||
return 'follow'
|
||||
}
|
||||
}
|
||||
|
||||
export const notification = (n: Entity.Notification): MegalodonEntity.Notification => {
|
||||
let notification = {
|
||||
id: n.id,
|
||||
account: user(n.user),
|
||||
created_at: n.createdAt,
|
||||
type: decodeNotificationType(n.type)
|
||||
}
|
||||
if (n.note) {
|
||||
notification = Object.assign(notification, {
|
||||
status: note(n.note)
|
||||
})
|
||||
}
|
||||
return notification
|
||||
}
|
||||
}
|
||||
|
||||
export const DEFAULT_SCOPE = [
|
||||
|
|
25
src/misskey/entities/notification.ts
Normal file
25
src/misskey/entities/notification.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
/// <reference path="user.ts" />
|
||||
/// <reference path="note.ts" />
|
||||
|
||||
namespace MisskeyEntity {
|
||||
export type Notification = {
|
||||
id: string
|
||||
createdAt: string
|
||||
// https://github.com/syuilo/misskey/blob/056942391aee135eb6c77aaa63f6ed5741d701a6/src/models/entities/notification.ts#L50-L62
|
||||
type:
|
||||
| 'follow'
|
||||
| 'mention'
|
||||
| 'reply'
|
||||
| 'renote'
|
||||
| 'quote'
|
||||
| 'reaction'
|
||||
| 'pollVote'
|
||||
| 'receiveFollowRequest'
|
||||
| 'followRequestAccepted'
|
||||
| 'groupInvited'
|
||||
userId: string
|
||||
user: User
|
||||
note?: Note
|
||||
reaction?: string
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
/// <reference path="entities/list.ts" />
|
||||
/// <reference path="entities/mute.ts" />
|
||||
/// <reference path="entities/note.ts" />
|
||||
/// <reference path="entities/notification.ts" />
|
||||
/// <reference path="entities/poll.ts" />
|
||||
/// <reference path="entities/relation.ts" />
|
||||
/// <reference path="entities/user.ts" />
|
||||
|
|
Loading…
Reference in a new issue