Fix NoteReaction (#4547)
This commit is contained in:
parent
1d7933349b
commit
1c79e30436
4 changed files with 9 additions and 10 deletions
|
@ -2,7 +2,6 @@ import * as mongo from 'mongodb';
|
||||||
import * as deepcopy from 'deepcopy';
|
import * as deepcopy from 'deepcopy';
|
||||||
import db from '../db/mongodb';
|
import db from '../db/mongodb';
|
||||||
import isObjectId from '../misc/is-objectid';
|
import isObjectId from '../misc/is-objectid';
|
||||||
import Reaction from './note-reaction';
|
|
||||||
import { pack as packUser } from './user';
|
import { pack as packUser } from './user';
|
||||||
|
|
||||||
const NoteReaction = db.get<INoteReaction>('noteReactions');
|
const NoteReaction = db.get<INoteReaction>('noteReactions');
|
||||||
|
@ -30,11 +29,11 @@ export const pack = (
|
||||||
|
|
||||||
// Populate the reaction if 'reaction' is ID
|
// Populate the reaction if 'reaction' is ID
|
||||||
if (isObjectId(reaction)) {
|
if (isObjectId(reaction)) {
|
||||||
_reaction = await Reaction.findOne({
|
_reaction = await NoteReaction.findOne({
|
||||||
_id: reaction
|
_id: reaction
|
||||||
});
|
});
|
||||||
} else if (typeof reaction === 'string') {
|
} else if (typeof reaction === 'string') {
|
||||||
_reaction = await Reaction.findOne({
|
_reaction = await NoteReaction.findOne({
|
||||||
_id: new mongo.ObjectID(reaction)
|
_id: new mongo.ObjectID(reaction)
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { length } from 'stringz';
|
||||||
import { IUser, pack as packUser } from './user';
|
import { IUser, pack as packUser } from './user';
|
||||||
import { pack as packApp } from './app';
|
import { pack as packApp } from './app';
|
||||||
import PollVote from './poll-vote';
|
import PollVote from './poll-vote';
|
||||||
import Reaction from './note-reaction';
|
import NoteReaction from './note-reaction';
|
||||||
import { packMany as packFileMany, IDriveFile } from './drive-file';
|
import { packMany as packFileMany, IDriveFile } from './drive-file';
|
||||||
import Following from './following';
|
import Following from './following';
|
||||||
import Emoji from './emoji';
|
import Emoji from './emoji';
|
||||||
|
@ -357,7 +357,7 @@ export const pack = async (
|
||||||
if (meId) {
|
if (meId) {
|
||||||
// Fetch my reaction
|
// Fetch my reaction
|
||||||
_note.myReaction = (async () => {
|
_note.myReaction = (async () => {
|
||||||
const reaction = await Reaction
|
const reaction = await NoteReaction
|
||||||
.findOne({
|
.findOne({
|
||||||
userId: meId,
|
userId: meId,
|
||||||
noteId: id,
|
noteId: id,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import $ from 'cafy';
|
import $ from 'cafy';
|
||||||
import ID, { transform } from '../../../../misc/cafy-id';
|
import ID, { transform } from '../../../../misc/cafy-id';
|
||||||
import Reaction, { pack } from '../../../../models/note-reaction';
|
import NoteReaction, { pack } from '../../../../models/note-reaction';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import { getNote } from '../../common/getters';
|
import { getNote } from '../../common/getters';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
|
@ -87,7 +87,7 @@ export default define(meta, async (ps, user) => {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const reactions = await Reaction.find(query, {
|
const reactions = await NoteReaction.find(query, {
|
||||||
limit: ps.limit,
|
limit: ps.limit,
|
||||||
skip: ps.offset,
|
skip: ps.offset,
|
||||||
sort: sort
|
sort: sort
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { IUser, isLocalUser, isRemoteUser } from '../../../models/user';
|
import { IUser, isLocalUser, isRemoteUser } from '../../../models/user';
|
||||||
import Note, { INote } from '../../../models/note';
|
import Note, { INote } from '../../../models/note';
|
||||||
import Reaction from '../../../models/note-reaction';
|
import NoteReaction from '../../../models/note-reaction';
|
||||||
import { publishNoteStream } from '../../stream';
|
import { publishNoteStream } from '../../stream';
|
||||||
import renderLike from '../../../remote/activitypub/renderer/like';
|
import renderLike from '../../../remote/activitypub/renderer/like';
|
||||||
import renderUndo from '../../../remote/activitypub/renderer/undo';
|
import renderUndo from '../../../remote/activitypub/renderer/undo';
|
||||||
|
@ -10,7 +10,7 @@ import { IdentifiableError } from '../../../misc/identifiable-error';
|
||||||
|
|
||||||
export default async (user: IUser, note: INote) => {
|
export default async (user: IUser, note: INote) => {
|
||||||
// if already unreacted
|
// if already unreacted
|
||||||
const exist = await Reaction.findOne({
|
const exist = await NoteReaction.findOne({
|
||||||
noteId: note._id,
|
noteId: note._id,
|
||||||
userId: user._id,
|
userId: user._id,
|
||||||
deletedAt: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
|
@ -21,7 +21,7 @@ export default async (user: IUser, note: INote) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete reaction
|
// Delete reaction
|
||||||
await Reaction.remove({
|
await NoteReaction.remove({
|
||||||
_id: exist._id
|
_id: exist._id
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue