@@ -2,8 +2,8 @@ import { JSDOM } from 'jsdom';
|
||||
import * as debug from 'debug';
|
||||
|
||||
import Resolver from '../../resolver';
|
||||
import Post, { IPost } from '../../../../models/post';
|
||||
import createPost from '../../../../services/post/create';
|
||||
import Note, { INote } from '../../../../models/note';
|
||||
import post from '../../../../services/note/create';
|
||||
import { IRemoteUser } from '../../../../models/user';
|
||||
import resolvePerson from '../../resolve-person';
|
||||
import createImage from './image';
|
||||
@@ -14,14 +14,14 @@ const log = debug('misskey:activitypub');
|
||||
/**
|
||||
* 投稿作成アクティビティを捌きます
|
||||
*/
|
||||
export default async function createNote(resolver: Resolver, actor: IRemoteUser, note, silent = false): Promise<IPost> {
|
||||
export default async function createNote(resolver: Resolver, actor: IRemoteUser, note, silent = false): Promise<INote> {
|
||||
if (typeof note.id !== 'string') {
|
||||
log(`invalid note: ${JSON.stringify(note, null, 2)}`);
|
||||
throw new Error('invalid note');
|
||||
}
|
||||
|
||||
// 既に同じURIを持つものが登録されていないかチェックし、登録されていたらそれを返す
|
||||
const exist = await Post.findOne({ uri: note.id });
|
||||
const exist = await Note.findOne({ uri: note.id });
|
||||
if (exist) {
|
||||
return exist;
|
||||
}
|
||||
@@ -54,12 +54,12 @@ export default async function createNote(resolver: Resolver, actor: IRemoteUser,
|
||||
if ('inReplyTo' in note && note.inReplyTo != null) {
|
||||
// リプライ先の投稿がMisskeyに登録されているか調べる
|
||||
const uri: string = note.inReplyTo.id || note.inReplyTo;
|
||||
const inReplyToPost = uri.startsWith(config.url + '/')
|
||||
? await Post.findOne({ _id: uri.split('/').pop() })
|
||||
: await Post.findOne({ uri });
|
||||
const inReplyToNote = uri.startsWith(config.url + '/')
|
||||
? await Note.findOne({ _id: uri.split('/').pop() })
|
||||
: await Note.findOne({ uri });
|
||||
|
||||
if (inReplyToPost) {
|
||||
reply = inReplyToPost;
|
||||
if (inReplyToNote) {
|
||||
reply = inReplyToNote;
|
||||
} else {
|
||||
// 無かったらフェッチ
|
||||
const inReplyTo = await resolver.resolve(note.inReplyTo) as any;
|
||||
@@ -75,11 +75,11 @@ export default async function createNote(resolver: Resolver, actor: IRemoteUser,
|
||||
|
||||
const { window } = new JSDOM(note.content);
|
||||
|
||||
return await createPost(actor, {
|
||||
return await post(actor, {
|
||||
createdAt: new Date(note.published),
|
||||
media,
|
||||
reply,
|
||||
repost: undefined,
|
||||
renote: undefined,
|
||||
text: window.document.body.textContent,
|
||||
viaMobile: false,
|
||||
geo: undefined,
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import Resolver from '../../resolver';
|
||||
import deleteNote from './note';
|
||||
import Post from '../../../../models/post';
|
||||
import Note from '../../../../models/note';
|
||||
import { IRemoteUser } from '../../../../models/user';
|
||||
|
||||
/**
|
||||
@@ -23,8 +23,8 @@ export default async (actor: IRemoteUser, activity): Promise<void> => {
|
||||
break;
|
||||
|
||||
case 'Tombstone':
|
||||
const post = await Post.findOne({ uri });
|
||||
if (post != null) {
|
||||
const note = await Note.findOne({ uri });
|
||||
if (note != null) {
|
||||
deleteNote(actor, uri);
|
||||
}
|
||||
break;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import * as debug from 'debug';
|
||||
|
||||
import Post from '../../../../models/post';
|
||||
import Note from '../../../../models/note';
|
||||
import { IRemoteUser } from '../../../../models/user';
|
||||
|
||||
const log = debug('misskey:activitypub');
|
||||
@@ -8,17 +8,17 @@ const log = debug('misskey:activitypub');
|
||||
export default async function(actor: IRemoteUser, uri: string): Promise<void> {
|
||||
log(`Deleting the Note: ${uri}`);
|
||||
|
||||
const post = await Post.findOne({ uri });
|
||||
const note = await Note.findOne({ uri });
|
||||
|
||||
if (post == null) {
|
||||
throw new Error('post not found');
|
||||
if (note == null) {
|
||||
throw new Error('note not found');
|
||||
}
|
||||
|
||||
if (!post.userId.equals(actor._id)) {
|
||||
if (!note.userId.equals(actor._id)) {
|
||||
throw new Error('投稿を削除しようとしているユーザーは投稿の作成者ではありません');
|
||||
}
|
||||
|
||||
Post.update({ _id: post._id }, {
|
||||
Note.update({ _id: note._id }, {
|
||||
$set: {
|
||||
deletedAt: new Date(),
|
||||
text: null,
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import Post from '../../../models/post';
|
||||
import Note from '../../../models/note';
|
||||
import { IRemoteUser } from '../../../models/user';
|
||||
import { ILike } from '../type';
|
||||
import create from '../../../services/post/reaction/create';
|
||||
import create from '../../../services/note/reaction/create';
|
||||
|
||||
export default async (actor: IRemoteUser, activity: ILike) => {
|
||||
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
|
||||
@@ -9,12 +9,12 @@ export default async (actor: IRemoteUser, activity: ILike) => {
|
||||
// Transform:
|
||||
// https://misskey.ex/@syuilo/xxxx to
|
||||
// xxxx
|
||||
const postId = id.split('/').pop();
|
||||
const noteId = id.split('/').pop();
|
||||
|
||||
const post = await Post.findOne({ _id: postId });
|
||||
if (post === null) {
|
||||
const note = await Note.findOne({ _id: noteId });
|
||||
if (note === null) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
await create(actor, post, 'pudding');
|
||||
await create(actor, note, 'pudding');
|
||||
};
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import config from '../../../config';
|
||||
|
||||
export default (user, post) => {
|
||||
export default (user, note) => {
|
||||
return {
|
||||
type: 'Like',
|
||||
actor: `${config.url}/@${user.username}`,
|
||||
object: post.uri ? post.uri : `${config.url}/posts/${post._id}`
|
||||
object: note.uri ? note.uri : `${config.url}/notes/${note._id}`
|
||||
};
|
||||
};
|
||||
|
@@ -2,28 +2,28 @@ import renderDocument from './document';
|
||||
import renderHashtag from './hashtag';
|
||||
import config from '../../../config';
|
||||
import DriveFile from '../../../models/drive-file';
|
||||
import Post, { IPost } from '../../../models/post';
|
||||
import Note, { INote } from '../../../models/note';
|
||||
import User, { IUser } from '../../../models/user';
|
||||
|
||||
export default async (user: IUser, post: IPost) => {
|
||||
const promisedFiles = post.mediaIds
|
||||
? DriveFile.find({ _id: { $in: post.mediaIds } })
|
||||
export default async (user: IUser, note: INote) => {
|
||||
const promisedFiles = note.mediaIds
|
||||
? DriveFile.find({ _id: { $in: note.mediaIds } })
|
||||
: Promise.resolve([]);
|
||||
|
||||
let inReplyTo;
|
||||
|
||||
if (post.replyId) {
|
||||
const inReplyToPost = await Post.findOne({
|
||||
_id: post.replyId,
|
||||
if (note.replyId) {
|
||||
const inReplyToNote = await Note.findOne({
|
||||
_id: note.replyId,
|
||||
});
|
||||
|
||||
if (inReplyToPost !== null) {
|
||||
if (inReplyToNote !== null) {
|
||||
const inReplyToUser = await User.findOne({
|
||||
_id: inReplyToPost.userId,
|
||||
_id: inReplyToNote.userId,
|
||||
});
|
||||
|
||||
if (inReplyToUser !== null) {
|
||||
inReplyTo = inReplyToPost.uri || `${config.url}/posts/${inReplyToPost._id}`;
|
||||
inReplyTo = inReplyToNote.uri || `${config.url}/notes/${inReplyToNote._id}`;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -33,15 +33,15 @@ export default async (user: IUser, post: IPost) => {
|
||||
const attributedTo = `${config.url}/@${user.username}`;
|
||||
|
||||
return {
|
||||
id: `${config.url}/posts/${post._id}`,
|
||||
id: `${config.url}/notes/${note._id}`,
|
||||
type: 'Note',
|
||||
attributedTo,
|
||||
content: post.textHtml,
|
||||
published: post.createdAt.toISOString(),
|
||||
content: note.textHtml,
|
||||
published: note.createdAt.toISOString(),
|
||||
to: 'https://www.w3.org/ns/activitystreams#Public',
|
||||
cc: `${attributedTo}/followers`,
|
||||
inReplyTo,
|
||||
attachment: (await promisedFiles).map(renderDocument),
|
||||
tag: (post.tags || []).map(renderHashtag)
|
||||
tag: (note.tags || []).map(renderHashtag)
|
||||
};
|
||||
};
|
||||
|
@@ -31,7 +31,7 @@ export default async (value, verifier?: string) => {
|
||||
throw new Error('invalid person');
|
||||
}
|
||||
|
||||
const [followersCount = 0, followingCount = 0, postsCount = 0, finger] = await Promise.all([
|
||||
const [followersCount = 0, followingCount = 0, notesCount = 0, finger] = await Promise.all([
|
||||
resolver.resolve(object.followers).then(
|
||||
resolved => isCollectionOrOrderedCollection(resolved) ? resolved.totalItems : undefined,
|
||||
() => undefined
|
||||
@@ -59,7 +59,7 @@ export default async (value, verifier?: string) => {
|
||||
description: summaryDOM.textContent,
|
||||
followersCount,
|
||||
followingCount,
|
||||
postsCount,
|
||||
notesCount,
|
||||
name: object.name,
|
||||
driveCapacity: 1024 * 1024 * 8, // 8MiB
|
||||
username: object.preferredUsername,
|
||||
|
Reference in New Issue
Block a user