forked from FoundKeyGang/FoundKey
refactor: reusable function for pure renote detection
There was some code to detect if a note is a quote renote. However this code was unused and it seems the kind of reversed detection of checking if something is a pure renote is more useful.
This commit is contained in:
parent
ce45f9f1b0
commit
ec4fe55acf
5 changed files with 14 additions and 11 deletions
|
@ -1,5 +0,0 @@
|
|||
import { Note } from '@/models/entities/note.js';
|
||||
|
||||
export default function(note: Note): boolean {
|
||||
return note.renoteId != null && (note.text != null || note.hasPoll || (note.fileIds != null && note.fileIds.length > 0));
|
||||
}
|
5
packages/backend/src/misc/renote.ts
Normal file
5
packages/backend/src/misc/renote.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { Note } from '@/models/entities/note.js';
|
||||
|
||||
export function isPureRenote(note: Note): boolean {
|
||||
return note.renoteId != null && note.text == null && (renote.fileIds == null || renote.fileIds.length === 0) && !note.hasPoll;
|
||||
}
|
|
@ -13,6 +13,7 @@ import { Users, Notes } from '@/models/index.js';
|
|||
import { Note } from '@/models/entities/note.js';
|
||||
import { makePaginationQuery } from '../api/common/make-pagination-query.js';
|
||||
import { setResponseType } from '../activitypub.js';
|
||||
import { isPureRenote } from '@/misc/renote.js';
|
||||
|
||||
export default async (ctx: Router.RouterContext) => {
|
||||
const userId = ctx.params.user;
|
||||
|
@ -99,10 +100,10 @@ export default async (ctx: Router.RouterContext) => {
|
|||
* @param note Note
|
||||
*/
|
||||
export async function packActivity(note: Note): Promise<any> {
|
||||
if (note.renoteId && note.text == null && !note.hasPoll && (note.fileIds == null || note.fileIds.length === 0)) {
|
||||
if (isPureRenote(note)) {
|
||||
const renote = await Notes.findOneByOrFail({ id: note.renoteId });
|
||||
return renderAnnounce(renote.uri ? renote.uri : `${config.url}/notes/${renote.id}`, note);
|
||||
}
|
||||
|
||||
} else {
|
||||
return renderCreate(await renderNote(note, false), note);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import { noteVisibilities } from '../../../../types.js';
|
|||
import { ApiError } from '../../error.js';
|
||||
import define from '../../define.js';
|
||||
import { getNote } from '../../common/getters.js';
|
||||
import { isPureRenote } from '@/misc/renote.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['notes'],
|
||||
|
@ -201,7 +202,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
throw e;
|
||||
});
|
||||
|
||||
if (renote.renoteId && !renote.text && !renote.fileIds && !renote.hasPoll) {
|
||||
if (isPureRenote(renote)) {
|
||||
throw new ApiError(meta.errors.cannotReRenote);
|
||||
}
|
||||
|
||||
|
@ -230,7 +231,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
throw e;
|
||||
});
|
||||
|
||||
if (reply.renoteId && !reply.text && !reply.fileIds && !reply.hasPoll) {
|
||||
if (isPureRenote(reply)) {
|
||||
throw new ApiError(meta.errors.cannotReplyToPureRenote);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import { deliverToFollowers, deliverToUser } from '@/remote/activitypub/deliver-
|
|||
import { countSameRenotes } from '@/misc/count-same-renotes.js';
|
||||
import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc.js';
|
||||
import { deliverToRelays } from '../relay.js';
|
||||
import { isPureRenote } from '@/misc/renote.js';
|
||||
|
||||
/**
|
||||
* 投稿を削除します。
|
||||
|
@ -43,7 +44,7 @@ export default async function(user: { id: User['id']; uri: User['uri']; host: Us
|
|||
let renote: Note | null = null;
|
||||
|
||||
// if deletd note is renote
|
||||
if (note.renoteId && note.text == null && !note.hasPoll && (note.fileIds == null || note.fileIds.length === 0)) {
|
||||
if (isPureRenote(note)) {
|
||||
renote = await Notes.findOneBy({
|
||||
id: note.renoteId,
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue