mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-11-22 05:55:12 +00:00
fix: align note edit errors with note create errors
This commit is contained in:
parent
15d2319011
commit
d1b787192a
2 changed files with 42 additions and 27 deletions
|
@ -51,6 +51,7 @@ import { CacheService } from '@/core/CacheService.js';
|
||||||
import { isReply } from '@/misc/is-reply.js';
|
import { isReply } from '@/misc/is-reply.js';
|
||||||
import { trackPromise } from '@/misc/promise-tracker.js';
|
import { trackPromise } from '@/misc/promise-tracker.js';
|
||||||
import { isUserRelated } from '@/misc/is-user-related.js';
|
import { isUserRelated } from '@/misc/is-user-related.js';
|
||||||
|
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
||||||
|
|
||||||
type NotificationType = 'reply' | 'renote' | 'quote' | 'mention' | 'edited';
|
type NotificationType = 'reply' | 'renote' | 'quote' | 'mention' | 'edited';
|
||||||
|
|
||||||
|
@ -244,8 +245,7 @@ export class NoteEditService implements OnApplicationShutdown {
|
||||||
// we never want to change the replyId, so fetch the original "parent"
|
// we never want to change the replyId, so fetch the original "parent"
|
||||||
if (oldnote.replyId) {
|
if (oldnote.replyId) {
|
||||||
data.reply = await this.notesRepository.findOneBy({ id: oldnote.replyId });
|
data.reply = await this.notesRepository.findOneBy({ id: oldnote.replyId });
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
data.reply = undefined;
|
data.reply = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ export class NoteEditService implements OnApplicationShutdown {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.utilityService.isKeyWordIncluded(data.cw ?? data.text ?? '', meta.prohibitedWords)) {
|
if (this.utilityService.isKeyWordIncluded(data.cw ?? data.text ?? '', meta.prohibitedWords)) {
|
||||||
throw new NoteEditService.ContainsProhibitedWordsError();
|
throw new IdentifiableError('689ee33f-f97c-479a-ac49-1b9f8140af99', 'Note contains prohibited words');
|
||||||
}
|
}
|
||||||
|
|
||||||
const inSilencedInstance = this.utilityService.isSilencedHost((meta).silencedHosts, user.host);
|
const inSilencedInstance = this.utilityService.isSilencedHost((meta).silencedHosts, user.host);
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||||
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
||||||
import { NoteEditService } from '@/core/NoteEditService.js';
|
import { NoteEditService } from '@/core/NoteEditService.js';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
|
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
||||||
import { ApiError } from '../../error.js';
|
import { ApiError } from '../../error.js';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
|
@ -141,6 +142,12 @@ export const meta = {
|
||||||
code: 'MAX_LENGTH',
|
code: 'MAX_LENGTH',
|
||||||
id: '3ac74a84-8fd5-4bb0-870f-01804f82ce16',
|
id: '3ac74a84-8fd5-4bb0-870f-01804f82ce16',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
containsProhibitedWords: {
|
||||||
|
message: 'Cannot post because it contains prohibited words.',
|
||||||
|
code: 'CONTAINS_PROHIBITED_WORDS',
|
||||||
|
id: 'aa6e01d3-a85c-669d-758a-76aab43af334',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
@ -379,32 +386,40 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
throw new ApiError(meta.errors.noSuchChannel);
|
throw new ApiError(meta.errors.noSuchChannel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
// 投稿を作成
|
||||||
|
const note = await this.noteEditService.edit(me, ps.editId!, {
|
||||||
|
files: files,
|
||||||
|
poll: ps.poll ? {
|
||||||
|
choices: ps.poll.choices,
|
||||||
|
multiple: ps.poll.multiple ?? false,
|
||||||
|
expiresAt: ps.poll.expiresAt ? new Date(ps.poll.expiresAt) : null,
|
||||||
|
} : undefined,
|
||||||
|
text: ps.text ?? undefined,
|
||||||
|
reply,
|
||||||
|
renote,
|
||||||
|
cw: ps.cw,
|
||||||
|
localOnly: ps.localOnly,
|
||||||
|
reactionAcceptance: ps.reactionAcceptance,
|
||||||
|
visibility: ps.visibility,
|
||||||
|
visibleUsers,
|
||||||
|
channel,
|
||||||
|
apMentions: ps.noExtractMentions ? [] : undefined,
|
||||||
|
apHashtags: ps.noExtractHashtags ? [] : undefined,
|
||||||
|
apEmojis: ps.noExtractEmojis ? [] : undefined,
|
||||||
|
});
|
||||||
|
|
||||||
// 投稿を作成
|
return {
|
||||||
const note = await this.noteEditService.edit(me, ps.editId!, {
|
createdNote: await this.noteEntityService.pack(note, me),
|
||||||
files: files,
|
};
|
||||||
poll: ps.poll ? {
|
} catch (e) {
|
||||||
choices: ps.poll.choices,
|
// TODO: 他のErrorもここでキャッチしてエラーメッセージを当てるようにしたい
|
||||||
multiple: ps.poll.multiple ?? false,
|
if (e instanceof IdentifiableError) {
|
||||||
expiresAt: ps.poll.expiresAt ? new Date(ps.poll.expiresAt) : null,
|
if (e.id === '689ee33f-f97c-479a-ac49-1b9f8140af99') throw new ApiError(meta.errors.containsProhibitedWords);
|
||||||
} : undefined,
|
}
|
||||||
text: ps.text ?? undefined,
|
|
||||||
reply,
|
|
||||||
renote,
|
|
||||||
cw: ps.cw,
|
|
||||||
localOnly: ps.localOnly,
|
|
||||||
reactionAcceptance: ps.reactionAcceptance,
|
|
||||||
visibility: ps.visibility,
|
|
||||||
visibleUsers,
|
|
||||||
channel,
|
|
||||||
apMentions: ps.noExtractMentions ? [] : undefined,
|
|
||||||
apHashtags: ps.noExtractHashtags ? [] : undefined,
|
|
||||||
apEmojis: ps.noExtractEmojis ? [] : undefined,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
throw e;
|
||||||
createdNote: await this.noteEntityService.pack(note, me),
|
}
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue