forked from misskey-dev/misskey
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
13 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,14 @@ | ||
import * as mongo from 'mongodb'; | ||
import Note from '../../../models/note'; | ||
import { IRemoteUser } from '../../../models/user'; | ||
import { ILike } from '../type'; | ||
import { ILike, getApId } from '../type'; | ||
import create from '../../../services/note/reaction/create'; | ||
import { isSelfHost, extractApHost } from '../../../misc/convert-host'; | ||
import { apLogger } from '../logger'; | ||
import { fetchNote } from '../models/note'; | ||
|
||
export default async (actor: IRemoteUser, activity: ILike) => { | ||
const id = typeof activity.object == 'string' ? activity.object : activity.object.id; | ||
const targetUri = getApId(activity.object); | ||
|
||
if (!isSelfHost(extractApHost(id))) { | ||
apLogger.warn(`skip ${activity.type} to foreign host (${id})`); | ||
return; | ||
} | ||
|
||
// Transform: | ||
// https://misskey.ex/notes/xxxx to | ||
// xxxx | ||
const noteId = new mongo.ObjectID(id.split('/').pop()); | ||
|
||
const note = await Note.findOne({ _id: noteId }); | ||
if (note === null) { | ||
throw new Error(); | ||
} | ||
const note = await fetchNote(targetUri); | ||
if (!note) return `skip: target note not found ${targetUri}`; | ||
|
||
await create(actor, note, activity._misskey_reaction || activity.content || activity.name); | ||
return `ok`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,17 @@ | ||
import * as mongo from 'mongodb'; | ||
import { IRemoteUser } from '../../../../models/user'; | ||
import { ILike } from '../../type'; | ||
import Note from '../../../../models/note'; | ||
import { ILike, getApId } from '../../type'; | ||
import deleteReaction from '../../../../services/note/reaction/delete'; | ||
import { isSelfHost, extractApHost } from '../../../../misc/convert-host'; | ||
import { apLogger } from '../../logger'; | ||
import { fetchNote } from '../../models/note'; | ||
|
||
/** | ||
* Process Undo.Like activity | ||
*/ | ||
export default async (actor: IRemoteUser, activity: ILike): Promise<void> => { | ||
const id = typeof activity.object == 'string' ? activity.object : activity.object.id; | ||
export default async (actor: IRemoteUser, activity: ILike) => { | ||
const targetUri = getApId(activity.object); | ||
|
||
if (!isSelfHost(extractApHost(id))) { | ||
apLogger.warn(`skip Undo ${activity.type} to foreign host (${id})`); | ||
return; | ||
} | ||
const noteId = new mongo.ObjectID(id.split('/').pop()); | ||
|
||
const note = await Note.findOne({ _id: noteId }); | ||
if (note === null) { | ||
throw 'note not found'; | ||
} | ||
const note = await fetchNote(targetUri); | ||
if (!note) return `skip: target note not found ${targetUri}`; | ||
|
||
await deleteReaction(actor, note); | ||
return `ok`; | ||
}; |