implement note mutings and move favorited/renoted status into note entity directly
This commit is contained in:
parent
9bebf7718f
commit
7200c3d6c8
24 changed files with 342 additions and 181 deletions
|
|
@ -8,6 +8,7 @@ import type { NotesRepository, NoteThreadMutingsRepository, NoteFavoritesReposit
|
|||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { CacheService } from '@/core/CacheService.js';
|
||||
import { QueryService } from '@/core/QueryService.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['notes'],
|
||||
|
|
@ -27,6 +28,14 @@ export const meta = {
|
|||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
isMutedNote: {
|
||||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
isRenoted: {
|
||||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -58,23 +67,37 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
private noteFavoritesRepository: NoteFavoritesRepository,
|
||||
|
||||
private readonly cacheService: CacheService,
|
||||
private readonly queryService: QueryService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const note = await this.notesRepository.findOneByOrFail({ id: ps.noteId });
|
||||
|
||||
const [favorite, threadMuting] = await Promise.all([
|
||||
const [favorite, threadMuting, noteMuting, renoted] = await Promise.all([
|
||||
// favorite
|
||||
this.noteFavoritesRepository.exists({
|
||||
where: {
|
||||
userId: me.id,
|
||||
noteId: note.id,
|
||||
},
|
||||
}),
|
||||
// treadMuting
|
||||
this.cacheService.threadMutingsCache.fetch(me.id).then(ms => ms.has(note.threadId ?? note.id)),
|
||||
// noteMuting
|
||||
this.cacheService.noteMutingsCache.fetch(me.id).then(ms => ms.has(note.id)),
|
||||
// renoted
|
||||
this.notesRepository
|
||||
.createQueryBuilder('note')
|
||||
.andWhere({ renoteId: note.id, userId: me.id })
|
||||
.andWhere(qb => this.queryService
|
||||
.andIsRenote(qb, 'note'))
|
||||
.getExists(),
|
||||
]);
|
||||
|
||||
return {
|
||||
isFavorited: favorite,
|
||||
isMutedThread: threadMuting,
|
||||
isMutedNote: noteMuting,
|
||||
isRenoted: renoted,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,9 +20,11 @@ export const meta = {
|
|||
|
||||
kind: 'write:account',
|
||||
|
||||
// Up to 10 calls, then 1/second
|
||||
limit: {
|
||||
duration: ms('1hour'),
|
||||
max: 10,
|
||||
type: 'bucket',
|
||||
size: 10,
|
||||
dripRate: 1000,
|
||||
},
|
||||
|
||||
errors: {
|
||||
|
|
@ -38,6 +40,7 @@ export const paramDef = {
|
|||
type: 'object',
|
||||
properties: {
|
||||
noteId: { type: 'string', format: 'misskey:id' },
|
||||
noteOnly: { type: 'boolean', default: false },
|
||||
},
|
||||
required: ['noteId'],
|
||||
} as const;
|
||||
|
|
@ -71,13 +74,18 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
});
|
||||
*/
|
||||
|
||||
const threadId = note.threadId ?? note.id;
|
||||
await this.noteThreadMutingsRepository.insert({
|
||||
id: this.idService.gen(),
|
||||
threadId: note.threadId ?? note.id,
|
||||
threadId: ps.noteOnly ? note.id : threadId,
|
||||
userId: me.id,
|
||||
isPostMute: ps.noteOnly,
|
||||
});
|
||||
|
||||
await this.cacheService.threadMutingsCache.refresh(me.id);
|
||||
await Promise.all([
|
||||
this.cacheService.threadMutingsCache.refresh(me.id),
|
||||
this.cacheService.noteMutingsCache.refresh(me.id),
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,10 +26,11 @@ export const meta = {
|
|||
},
|
||||
},
|
||||
|
||||
// 10 calls per hour (match create)
|
||||
// Up to 20 calls, then 2/second
|
||||
limit: {
|
||||
duration: 1000 * 60 * 60,
|
||||
max: 10,
|
||||
type: 'bucket',
|
||||
size: 20,
|
||||
dripRate: 2000,
|
||||
},
|
||||
} as const;
|
||||
|
||||
|
|
@ -37,6 +38,7 @@ export const paramDef = {
|
|||
type: 'object',
|
||||
properties: {
|
||||
noteId: { type: 'string', format: 'misskey:id' },
|
||||
noteOnly: { type: 'boolean', default: false },
|
||||
},
|
||||
required: ['noteId'],
|
||||
} as const;
|
||||
|
|
@ -56,12 +58,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
throw err;
|
||||
});
|
||||
|
||||
const threadId = note.threadId ?? note.id;
|
||||
await this.noteThreadMutingsRepository.delete({
|
||||
threadId: note.threadId ?? note.id,
|
||||
threadId: ps.noteOnly ? note.id : threadId,
|
||||
userId: me.id,
|
||||
isPostMute: ps.noteOnly,
|
||||
});
|
||||
|
||||
await this.cacheService.threadMutingsCache.refresh(me.id);
|
||||
await Promise.all([
|
||||
this.cacheService.threadMutingsCache.refresh(me.id),
|
||||
this.cacheService.noteMutingsCache.refresh(me.id),
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue