implement /api/v1/favourites

This commit is contained in:
Hazelnoot 2025-03-21 23:26:12 -04:00
parent aaf49eadee
commit 3d8930f070
4 changed files with 59 additions and 27 deletions

View file

@ -691,36 +691,48 @@ export default class Misskey implements MegalodonInterface {
})
}
/**
* POST /api/users/reactions
*/
public async getReactions(userId: string, options?: { limit?: number; max_id?: string; min_id?: string }): Promise<Response<MisskeyEntity.NoteReaction[]>> {
let params = {
userId,
};
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.min_id) {
params = Object.assign(params, {
sinceId: options.min_id
})
}
}
return this.client.post<MisskeyAPI.Entity.NoteReaction[]>('/api/users/reactions', params);
}
// ======================================
// accounts/favourites
// ======================================
/**
* POST /api/i/favorites
* POST /api/users/reactions
*/
public async getFavourites(options?: { limit?: number; max_id?: string; min_id?: string }): 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, {
untilId: options.max_id
})
}
if (options.min_id) {
params = Object.assign(params, {
sinceId: options.min_id
})
}
}
return this.client.post<Array<MisskeyAPI.Entity.Favorite>>('/api/i/favorites', params).then(res => {
return Object.assign(res, {
data: res.data.map(fav => MisskeyAPI.Converter.note(fav.note, this.baseUrl))
})
})
public async getFavourites(options?: { limit?: number; max_id?: string; min_id?: string; userId?: string }): Promise<Response<Array<Entity.Status>>> {
const userId = options?.userId ?? (await this.verifyAccountCredentials()).data.id;
const response = await this.getReactions(userId, options);
return {
...response,
data: response.data.map(r => MisskeyAPI.Converter.note(r.note, this.baseUrl)),
};
}
// ======================================

View file

@ -32,6 +32,7 @@ namespace MisskeyAPI {
export type Notification = MisskeyEntity.Notification
export type Poll = MisskeyEntity.Poll
export type Reaction = MisskeyEntity.Reaction
export type NoteReaction = MisskeyEntity.NoteReaction
export type Relation = MisskeyEntity.Relation
export type User = MisskeyEntity.User
export type UserDetail = MisskeyEntity.UserDetail

View file

@ -1,4 +1,5 @@
/// <reference path="user.ts" />
/// <reference path="note.ts" />
namespace MisskeyEntity {
export type Reaction = {
@ -7,4 +8,8 @@ namespace MisskeyEntity {
user: User
type: string
}
export type NoteReaction = Reaction & {
note: Note
}
}