Implement Mention object
This commit is contained in:
parent
a5715ecc1b
commit
168b0730b4
@ -1,8 +1,6 @@
|
|||||||
import parseAcct from '../acct/parse';
|
|
||||||
import Post from '../models/post';
|
import Post from '../models/post';
|
||||||
import User from '../models/user';
|
|
||||||
|
|
||||||
export default async (post, reply, repost, atMentions) => {
|
export default async (post, reply, repost, mentions) => {
|
||||||
post.mentions = [];
|
post.mentions = [];
|
||||||
|
|
||||||
function addMention(mentionee) {
|
function addMention(mentionee) {
|
||||||
@ -36,15 +34,7 @@ export default async (post, reply, repost, atMentions) => {
|
|||||||
post._repost = null;
|
post._repost = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(atMentions.map(async mention => {
|
await Promise.all(mentions.map(({ _id }) => addMention(_id)));
|
||||||
// Fetch mentioned user
|
|
||||||
// SELECT _id
|
|
||||||
const { _id } = await User
|
|
||||||
.findOne(parseAcct(mention), { _id: true });
|
|
||||||
|
|
||||||
// Add mention
|
|
||||||
addMention(_id);
|
|
||||||
}));
|
|
||||||
|
|
||||||
return Post.insert(post);
|
return Post.insert(post);
|
||||||
};
|
};
|
||||||
|
@ -25,7 +25,7 @@ export default async ({ data }, done) => {
|
|||||||
}) as IRemoteUser;
|
}) as IRemoteUser;
|
||||||
|
|
||||||
if (user === null) {
|
if (user === null) {
|
||||||
user = await resolvePerson(data.signature.keyId);
|
user = await resolvePerson(new Resolver(), data.signature.keyId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import { IRemoteUser } from '../../models/user';
|
|||||||
import uploadFromUrl from '../../drive/upload-from-url';
|
import uploadFromUrl from '../../drive/upload-from-url';
|
||||||
import createPost from '../../post/create';
|
import createPost from '../../post/create';
|
||||||
import distributePost from '../../post/distribute';
|
import distributePost from '../../post/distribute';
|
||||||
|
import resolvePerson from './resolve-person';
|
||||||
import Resolver from './resolver';
|
import Resolver from './resolver';
|
||||||
const createDOMPurify = require('dompurify');
|
const createDOMPurify = require('dompurify');
|
||||||
|
|
||||||
@ -53,6 +54,15 @@ class Creator {
|
|||||||
.map(({ object }) => object.$id);
|
.map(({ object }) => object.$id);
|
||||||
|
|
||||||
const { window } = new JSDOM(note.content);
|
const { window } = new JSDOM(note.content);
|
||||||
|
const mentions = [];
|
||||||
|
|
||||||
|
for (const { href, type } of note.tags) {
|
||||||
|
switch (type) {
|
||||||
|
case 'Mention':
|
||||||
|
mentions.push(resolvePerson(resolver, href));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const inserted = await createPost({
|
const inserted = await createPost({
|
||||||
channelId: undefined,
|
channelId: undefined,
|
||||||
@ -69,7 +79,7 @@ class Creator {
|
|||||||
viaMobile: false,
|
viaMobile: false,
|
||||||
geo: undefined,
|
geo: undefined,
|
||||||
uri: note.id
|
uri: note.id
|
||||||
}, null, null, []);
|
}, null, null, await Promise.all(mentions));
|
||||||
|
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
|
||||||
|
@ -4,14 +4,13 @@ import User, { validateUsername, isValidName, isValidDescription } from '../../m
|
|||||||
import { createHttp } from '../../queue';
|
import { createHttp } from '../../queue';
|
||||||
import webFinger from '../webfinger';
|
import webFinger from '../webfinger';
|
||||||
import create from './create';
|
import create from './create';
|
||||||
import Resolver from './resolver';
|
|
||||||
|
|
||||||
async function isCollection(collection) {
|
async function isCollection(collection) {
|
||||||
return ['Collection', 'OrderedCollection'].includes(collection.type);
|
return ['Collection', 'OrderedCollection'].includes(collection.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async (value, verifier?: string) => {
|
export default async (parentResolver, value, verifier?: string) => {
|
||||||
const { resolver, object } = await new Resolver().resolveOne(value);
|
const { resolver, object } = parentResolver.resolveOne(value);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
object === null ||
|
object === null ||
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { toUnicode, toASCII } from 'punycode';
|
import { toUnicode, toASCII } from 'punycode';
|
||||||
import User from '../models/user';
|
import User from '../models/user';
|
||||||
import resolvePerson from './activitypub/resolve-person';
|
import resolvePerson from './activitypub/resolve-person';
|
||||||
|
import Resolver from './activitypub/resolver';
|
||||||
import webFinger from './webfinger';
|
import webFinger from './webfinger';
|
||||||
|
|
||||||
export default async (username, host, option) => {
|
export default async (username, host, option) => {
|
||||||
@ -19,7 +20,7 @@ export default async (username, host, option) => {
|
|||||||
throw new Error();
|
throw new Error();
|
||||||
}
|
}
|
||||||
|
|
||||||
user = await resolvePerson(self.href, acctLower);
|
user = await resolvePerson(new Resolver(), self.href, acctLower);
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
|
@ -3,12 +3,13 @@
|
|||||||
*/
|
*/
|
||||||
import $ from 'cafy';
|
import $ from 'cafy';
|
||||||
import deepEqual = require('deep-equal');
|
import deepEqual = require('deep-equal');
|
||||||
|
import parseAcct from '../../../../acct/parse';
|
||||||
import renderAcct from '../../../../acct/render';
|
import renderAcct from '../../../../acct/render';
|
||||||
import config from '../../../../config';
|
import config from '../../../../config';
|
||||||
import html from '../../../../text/html';
|
import html from '../../../../text/html';
|
||||||
import parse from '../../../../text/parse';
|
import parse from '../../../../text/parse';
|
||||||
import Post, { IPost, isValidText, isValidCw } from '../../../../models/post';
|
import Post, { IPost, isValidText, isValidCw } from '../../../../models/post';
|
||||||
import { ILocalUser } from '../../../../models/user';
|
import User, { ILocalUser } from '../../../../models/user';
|
||||||
import Channel, { IChannel } from '../../../../models/channel';
|
import Channel, { IChannel } from '../../../../models/channel';
|
||||||
import DriveFile from '../../../../models/drive-file';
|
import DriveFile from '../../../../models/drive-file';
|
||||||
import create from '../../../../post/create';
|
import create from '../../../../post/create';
|
||||||
@ -267,7 +268,10 @@ module.exports = (params, user: ILocalUser, app) => new Promise(async (res, rej)
|
|||||||
.filter(t => t.type == 'mention')
|
.filter(t => t.type == 'mention')
|
||||||
.map(renderAcct)
|
.map(renderAcct)
|
||||||
// Drop dupulicates
|
// Drop dupulicates
|
||||||
.filter((v, i, s) => s.indexOf(v) == i);
|
.filter((v, i, s) => s.indexOf(v) == i)
|
||||||
|
// Fetch mentioned user
|
||||||
|
// SELECT _id
|
||||||
|
.map(mention => User.findOne(parseAcct(mention), { _id: true }));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 投稿を作成
|
// 投稿を作成
|
||||||
@ -286,7 +290,7 @@ module.exports = (params, user: ILocalUser, app) => new Promise(async (res, rej)
|
|||||||
viaMobile: viaMobile,
|
viaMobile: viaMobile,
|
||||||
visibility,
|
visibility,
|
||||||
geo
|
geo
|
||||||
}, reply, repost, atMentions);
|
}, reply, repost, await Promise.all(atMentions));
|
||||||
|
|
||||||
const postObj = await distribute(user, post.mentions, post);
|
const postObj = await distribute(user, post.mentions, post);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user