Merge branch 'develop' into sw-notification-action

This commit is contained in:
tamaina
2021-05-21 19:56:52 +09:00
81 changed files with 2712 additions and 625 deletions

View File

@@ -35,7 +35,7 @@ export default async function(user: User, note: Note, quiet = false) {
});
//#region ローカルの投稿なら削除アクティビティを配送
if (Users.isLocalUser(user)) {
if (Users.isLocalUser(user) && !note.localOnly) {
let renote: Note | undefined;
// if deletd note is renote

View File

@@ -13,12 +13,13 @@ import { createNotification } from '../../create-notification';
import deleteReaction from './delete';
import { isDuplicateKeyValueError } from '@/misc/is-duplicate-key-value-error';
import { NoteReaction } from '../../../models/entities/note-reaction';
import { IdentifiableError } from '@/misc/identifiable-error';
export default async (user: { id: User['id']; host: User['host']; }, note: Note, reaction?: string) => {
// TODO: cache
reaction = await toDbReaction(reaction, user.host);
let record: NoteReaction = {
const record: NoteReaction = {
id: genId(),
createdAt: new Date(),
noteId: note.id,
@@ -31,17 +32,18 @@ export default async (user: { id: User['id']; host: User['host']; }, note: Note,
await NoteReactions.insert(record);
} catch (e) {
if (isDuplicateKeyValueError(e)) {
record = await NoteReactions.findOneOrFail({
const exists = await NoteReactions.findOneOrFail({
noteId: note.id,
userId: user.id,
});
if (record.reaction !== reaction) {
if (exists.reaction !== reaction) {
// 別のリアクションがすでにされていたら置き換える
await deleteReaction(user, note);
await NoteReactions.insert(record);
} else {
// 同じリアクションがすでにされていたら何もしない
return;
// 同じリアクションがすでにされていたらエラー
throw new IdentifiableError('51c42bb4-931a-456b-bff7-e5a8a70dd298');
}
} else {
throw e;