refactor isPureRenote to foundkey-js
This commit is contained in:
parent
9458045c8f
commit
28c11ca7af
|
@ -1,12 +0,0 @@
|
||||||
import { Note } from '@/models/entities/note.js';
|
|
||||||
|
|
||||||
export function isPureRenote(note: Note): note is Note & { renoteId: string, text: null, cw: null, fileIds: null | never[], hasPoll: false } {
|
|
||||||
return note.renoteId != null
|
|
||||||
&& note.text == null
|
|
||||||
&& note.cw == null
|
|
||||||
&& (
|
|
||||||
note.fileIds == null
|
|
||||||
|| note.fileIds.length === 0
|
|
||||||
)
|
|
||||||
&& !note.hasPoll;
|
|
||||||
}
|
|
|
@ -1,14 +1,14 @@
|
||||||
|
import * as foundkey from 'foundkey-js';
|
||||||
import config from '@/config/index.js';
|
import config from '@/config/index.js';
|
||||||
import { Notes } from '@/models/index.js';
|
import { Notes } from '@/models/index.js';
|
||||||
import { Note } from '@/models/entities/note.js';
|
import { Note } from '@/models/entities/note.js';
|
||||||
import { isPureRenote } from '@/misc/renote.js';
|
|
||||||
import { IActivity } from '@/remote/activitypub/types.js';
|
import { IActivity } from '@/remote/activitypub/types.js';
|
||||||
import renderNote from '@/remote/activitypub/renderer/note.js';
|
import renderNote from '@/remote/activitypub/renderer/note.js';
|
||||||
import renderCreate from '@/remote/activitypub/renderer/create.js';
|
import renderCreate from '@/remote/activitypub/renderer/create.js';
|
||||||
import renderAnnounce from '@/remote/activitypub/renderer/announce.js';
|
import renderAnnounce from '@/remote/activitypub/renderer/announce.js';
|
||||||
|
|
||||||
export async function renderNoteOrRenoteActivity(note: Note): Promise<IActivity> {
|
export async function renderNoteOrRenoteActivity(note: Note): Promise<IActivity> {
|
||||||
if (isPureRenote(note)) {
|
if (foundkey.entities.isPureRenote(note)) {
|
||||||
const renote = await Notes.findOneByOrFail({ id: note.renoteId });
|
const renote = await Notes.findOneByOrFail({ id: note.renoteId });
|
||||||
return renderAnnounce(renote.uri ?? `${config.url}/notes/${renote.id}`, note);
|
return renderAnnounce(renote.uri ?? `${config.url}/notes/${renote.id}`, note);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -12,7 +12,6 @@ import { countIf } from '@/prelude/array.js';
|
||||||
import * as url from '@/prelude/url.js';
|
import * as url from '@/prelude/url.js';
|
||||||
import { Users, Notes } from '@/models/index.js';
|
import { Users, Notes } from '@/models/index.js';
|
||||||
import { Note } from '@/models/entities/note.js';
|
import { Note } from '@/models/entities/note.js';
|
||||||
import { isPureRenote } from '@/misc/renote.js';
|
|
||||||
import { makePaginationQuery } from '../api/common/make-pagination-query.js';
|
import { makePaginationQuery } from '../api/common/make-pagination-query.js';
|
||||||
import { setResponseType } from '../activitypub.js';
|
import { setResponseType } from '../activitypub.js';
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { In } from 'typeorm';
|
import { In } from 'typeorm';
|
||||||
import { noteVisibilities } from 'foundkey-js';
|
import { noteVisibilities, entities } from 'foundkey-js';
|
||||||
import create from '@/services/note/create.js';
|
import create from '@/services/note/create.js';
|
||||||
import { User } from '@/models/entities/user.js';
|
import { User } from '@/models/entities/user.js';
|
||||||
import { Users, DriveFiles, Notes, Channels, Blockings } from '@/models/index.js';
|
import { Users, DriveFiles, Notes, Channels, Blockings } from '@/models/index.js';
|
||||||
|
@ -7,7 +7,6 @@ import { DriveFile } from '@/models/entities/drive-file.js';
|
||||||
import { Note } from '@/models/entities/note.js';
|
import { Note } from '@/models/entities/note.js';
|
||||||
import { Channel } from '@/models/entities/channel.js';
|
import { Channel } from '@/models/entities/channel.js';
|
||||||
import { HOUR } from '@/const.js';
|
import { HOUR } from '@/const.js';
|
||||||
import { isPureRenote } from '@/misc/renote.js';
|
|
||||||
import config from '@/config/index.js';
|
import config from '@/config/index.js';
|
||||||
import { ApiError } from '../../error.js';
|
import { ApiError } from '../../error.js';
|
||||||
import define from '../../define.js';
|
import define from '../../define.js';
|
||||||
|
@ -160,7 +159,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isPureRenote(renote)) throw new ApiError('PURE_RENOTE', 'Cannot renote a pure renote.');
|
if (entities.isPureRenote(renote)) throw new ApiError('PURE_RENOTE', 'Cannot renote a pure renote.');
|
||||||
|
|
||||||
// check that the visibility is not less restrictive
|
// check that the visibility is not less restrictive
|
||||||
if (noteVisibilities.indexOf(renote.visibility) > noteVisibilities.indexOf(ps.visibility)) {
|
if (noteVisibilities.indexOf(renote.visibility) > noteVisibilities.indexOf(ps.visibility)) {
|
||||||
|
@ -185,7 +184,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isPureRenote(reply)) throw new ApiError('PURE_RENOTE', 'Cannot reply to a pure renote.');
|
if (entities.isPureRenote(reply)) throw new ApiError('PURE_RENOTE', 'Cannot reply to a pure renote.');
|
||||||
|
|
||||||
// check that the visibility is not less restrictive
|
// check that the visibility is not less restrictive
|
||||||
if (noteVisibilities.indexOf(reply.visibility) > noteVisibilities.indexOf(ps.visibility)) {
|
if (noteVisibilities.indexOf(reply.visibility) > noteVisibilities.indexOf(ps.visibility)) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { FindOptionsWhere, In, IsNull, Not } from 'typeorm';
|
import { FindOptionsWhere, In, IsNull, Not } from 'typeorm';
|
||||||
|
import * as foundkey from 'foundkey-js';
|
||||||
import { publishNoteStream } from '@/services/stream.js';
|
import { publishNoteStream } from '@/services/stream.js';
|
||||||
import renderDelete from '@/remote/activitypub/renderer/delete.js';
|
import renderDelete from '@/remote/activitypub/renderer/delete.js';
|
||||||
import renderAnnounce from '@/remote/activitypub/renderer/announce.js';
|
import renderAnnounce from '@/remote/activitypub/renderer/announce.js';
|
||||||
|
@ -12,7 +13,6 @@ import { Notes, Users, Instances } from '@/models/index.js';
|
||||||
import { notesChart, perUserNotesChart, instanceChart } from '@/services/chart/index.js';
|
import { notesChart, perUserNotesChart, instanceChart } from '@/services/chart/index.js';
|
||||||
import { DeliverManager } from '@/remote/activitypub/deliver-manager.js';
|
import { DeliverManager } from '@/remote/activitypub/deliver-manager.js';
|
||||||
import { countSameRenotes } from '@/misc/count-same-renotes.js';
|
import { countSameRenotes } from '@/misc/count-same-renotes.js';
|
||||||
import { isPureRenote } from '@/misc/renote.js';
|
|
||||||
import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc.js';
|
import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc.js';
|
||||||
import { deliverToRelays } from '../relay.js';
|
import { deliverToRelays } from '../relay.js';
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ export default async function(user: { id: User['id']; uri: User['uri']; host: Us
|
||||||
let renote: Note | null = null;
|
let renote: Note | null = null;
|
||||||
|
|
||||||
// if deleted note is renote
|
// if deleted note is renote
|
||||||
if (isPureRenote(note)) {
|
if (foundkey.entities.isPureRenote(note)) {
|
||||||
renote = await Notes.findOneBy({ id: note.renoteId });
|
renote = await Notes.findOneBy({ id: note.renoteId });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,12 +159,7 @@ if (noteViewInterruptors.length > 0) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const isRenote = (
|
const isRenote = foundkey.entities.isPureRenote(note);
|
||||||
note.renote != null &&
|
|
||||||
note.text == null &&
|
|
||||||
note.fileIds.length === 0 &&
|
|
||||||
note.poll == null
|
|
||||||
);
|
|
||||||
|
|
||||||
const el = ref<HTMLElement>();
|
const el = ref<HTMLElement>();
|
||||||
const menuButton = ref<HTMLElement>();
|
const menuButton = ref<HTMLElement>();
|
||||||
|
|
|
@ -148,13 +148,7 @@ if (noteViewInterruptors.length > 0) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const isRenote = (
|
const isRenote = foundkey.entities.isPureRenote(note);
|
||||||
note.renote != null &&
|
|
||||||
note.text == null &&
|
|
||||||
note.cw == null &&
|
|
||||||
note.fileIds.length === 0 &&
|
|
||||||
note.poll == null
|
|
||||||
);
|
|
||||||
|
|
||||||
const el = ref<HTMLElement>();
|
const el = ref<HTMLElement>();
|
||||||
const menuButton = ref<HTMLElement>();
|
const menuButton = ref<HTMLElement>();
|
||||||
|
|
|
@ -16,14 +16,9 @@ export function getNoteMenu(props: {
|
||||||
isDeleted: Ref<boolean>;
|
isDeleted: Ref<boolean>;
|
||||||
currentClipPage?: Ref<foundkey.entities.Clip>;
|
currentClipPage?: Ref<foundkey.entities.Clip>;
|
||||||
}) {
|
}) {
|
||||||
const isRenote = (
|
const appearNote = foundkey.entities.isPureRenote(props.note)
|
||||||
props.note.renote != null &&
|
? props.note.renote as foundkey.entities.Note
|
||||||
props.note.text == null &&
|
: props.note;
|
||||||
props.note.fileIds.length === 0 &&
|
|
||||||
props.note.poll == null
|
|
||||||
);
|
|
||||||
|
|
||||||
const appearNote = isRenote ? props.note.renote as foundkey.entities.Note : props.note;
|
|
||||||
|
|
||||||
function del(): void {
|
function del(): void {
|
||||||
os.confirm({
|
os.confirm({
|
||||||
|
|
|
@ -471,3 +471,14 @@ export type UserSorting =
|
||||||
| '+updatedAt'
|
| '+updatedAt'
|
||||||
| '-updatedAt';
|
| '-updatedAt';
|
||||||
export type OriginType = 'combined' | 'local' | 'remote';
|
export type OriginType = 'combined' | 'local' | 'remote';
|
||||||
|
|
||||||
|
export function isPureRenote(note: Note): boolean {
|
||||||
|
return note.renoteId != null
|
||||||
|
&& note.text == null
|
||||||
|
&& note.cw == null
|
||||||
|
&& (
|
||||||
|
note.fileIds == null
|
||||||
|
|| note.fileIds.length === 0
|
||||||
|
)
|
||||||
|
&& note.poll == null;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue