mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2025-04-13 09:44:40 +00:00
implement /api/v1/favourites
This commit is contained in:
parent
aaf49eadee
commit
3d8930f070
4 changed files with 59 additions and 27 deletions
|
@ -19,6 +19,7 @@ import { ApiStatusMastodon } from '@/server/api/mastodon/endpoints/status.js';
|
|||
import { ApiNotificationsMastodon } from '@/server/api/mastodon/endpoints/notifications.js';
|
||||
import { ApiTimelineMastodon } from '@/server/api/mastodon/endpoints/timeline.js';
|
||||
import { ApiSearchMastodon } from '@/server/api/mastodon/endpoints/search.js';
|
||||
import { ApiError } from '@/server/api/error.js';
|
||||
import { parseTimelineArgs, TimelineArgs, toBoolean } from './argsUtils.js';
|
||||
import { convertAnnouncement, convertAttachment, MastoConverters, convertRelationship } from './converters.js';
|
||||
import type { Entity } from 'megalodon';
|
||||
|
@ -231,8 +232,21 @@ export class MastodonApiServerService {
|
|||
fastify.get<{ Querystring: TimelineArgs }>('/v1/favourites', async (_request, reply) => {
|
||||
const { client, me } = await this.clientService.getAuthClient(_request);
|
||||
|
||||
const data = await client.getFavourites(parseTimelineArgs(_request.query));
|
||||
const response = Promise.all(data.data.map((status) => this.mastoConverters.convertStatus(status, me)));
|
||||
if (!me) {
|
||||
throw new ApiError({
|
||||
message: 'Credential required.',
|
||||
code: 'CREDENTIAL_REQUIRED',
|
||||
id: '1384574d-a912-4b81-8601-c7b1c4085df1',
|
||||
httpStatusCode: 401,
|
||||
});
|
||||
}
|
||||
|
||||
const args = {
|
||||
...parseTimelineArgs(_request.query),
|
||||
userId: me.id,
|
||||
};
|
||||
const data = await client.getFavourites(args);
|
||||
const response = await Promise.all(data.data.map((status) => this.mastoConverters.convertStatus(status, me)));
|
||||
|
||||
reply.send(response);
|
||||
});
|
||||
|
|
|
@ -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)),
|
||||
};
|
||||
}
|
||||
|
||||
// ======================================
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue