forked from mirror/misskey
Correct Like id generation (#5852)
This commit is contained in:
parent
1c7c72181e
commit
988ac80087
@ -1,10 +1,12 @@
|
||||
import config from '../../../config';
|
||||
import { ILocalUser } from '../../../models/entities/user';
|
||||
import { NoteReaction } from '../../../models/entities/note-reaction';
|
||||
import { Note } from '../../../models/entities/note';
|
||||
|
||||
export default (user: ILocalUser, note: Note, reaction: string) => ({
|
||||
export const renderLike = (noteReaction: NoteReaction, note: Note) => ({
|
||||
type: 'Like',
|
||||
actor: `${config.url}/users/${user.id}`,
|
||||
object: note.uri ? note.uri : `${config.url}/notes/${note.id}`,
|
||||
_misskey_reaction: reaction
|
||||
id: `${config.url}/likes/${noteReaction.id}`,
|
||||
actor: `${config.url}/users/${noteReaction.userId}`,
|
||||
object: note.uri ? note.uri : `${config.url}/notes/${noteReaction.noteId}`,
|
||||
content: noteReaction.reaction,
|
||||
_misskey_reaction: noteReaction.reaction
|
||||
});
|
||||
|
@ -13,10 +13,11 @@ import Following from './activitypub/following';
|
||||
import Featured from './activitypub/featured';
|
||||
import { inbox as processInbox } from '../queue';
|
||||
import { isSelfHost } from '../misc/convert-host';
|
||||
import { Notes, Users, Emojis, UserKeypairs } from '../models';
|
||||
import { Notes, Users, Emojis, UserKeypairs, NoteReactions } from '../models';
|
||||
import { ILocalUser, User } from '../models/entities/user';
|
||||
import { In } from 'typeorm';
|
||||
import { ensure } from '../prelude/ensure';
|
||||
import { renderLike } from '../remote/activitypub/renderer/like';
|
||||
|
||||
// Init router
|
||||
const router = new Router();
|
||||
@ -202,4 +203,25 @@ router.get('/emojis/:emoji', async ctx => {
|
||||
setResponseType(ctx);
|
||||
});
|
||||
|
||||
// like
|
||||
router.get('/likes/:like', async ctx => {
|
||||
const reaction = await NoteReactions.findOne(ctx.params.like);
|
||||
|
||||
if (reaction == null) {
|
||||
ctx.status = 404;
|
||||
return;
|
||||
}
|
||||
|
||||
const note = await Notes.findOne(reaction.noteId);
|
||||
|
||||
if (note == null) {
|
||||
ctx.status = 404;
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.body = renderActivity(await renderLike(reaction, note));
|
||||
ctx.set('Cache-Control', 'public, max-age=180');
|
||||
setResponseType(ctx);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { publishNoteStream } from '../../stream';
|
||||
import watch from '../watch';
|
||||
import renderLike from '../../../remote/activitypub/renderer/like';
|
||||
import { renderLike } from '../../../remote/activitypub/renderer/like';
|
||||
import DeliverManager from '../../../remote/activitypub/deliver-manager';
|
||||
import { renderActivity } from '../../../remote/activitypub/renderer';
|
||||
import { IdentifiableError } from '../../../misc/identifiable-error';
|
||||
@ -38,7 +38,7 @@ export default async (user: User, note: Note, reaction?: string) => {
|
||||
}
|
||||
|
||||
// Create reaction
|
||||
await NoteReactions.save({
|
||||
const inserted = await NoteReactions.save({
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
noteId: note.id,
|
||||
@ -94,7 +94,7 @@ export default async (user: User, note: Note, reaction?: string) => {
|
||||
|
||||
//#region 配信
|
||||
if (Users.isLocalUser(user) && !note.localOnly) {
|
||||
const content = renderActivity(renderLike(user, note, reaction));
|
||||
const content = renderActivity(renderLike(inserted, note));
|
||||
const dm = new DeliverManager(user, content);
|
||||
if (note.userHost !== null) {
|
||||
const reactee = await Users.findOne(note.userId)
|
||||
|
@ -1,5 +1,5 @@
|
||||
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 { renderActivity } from '../../../remote/activitypub/renderer';
|
||||
import DeliverManager from '../../../remote/activitypub/deliver-manager';
|
||||
@ -40,7 +40,7 @@ export default async (user: User, note: Note) => {
|
||||
|
||||
//#region 配信
|
||||
if (Users.isLocalUser(user) && !note.localOnly) {
|
||||
const content = renderActivity(renderUndo(renderLike(user, note, exist.reaction), user));
|
||||
const content = renderActivity(renderUndo(renderLike(exist, note), user));
|
||||
const dm = new DeliverManager(user, content);
|
||||
if (note.userHost !== null) {
|
||||
const reactee = await Users.findOne(note.userId)
|
||||
|
Loading…
Reference in New Issue
Block a user