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 User from '../models/user';
|
||||
|
||||
export default async (post, reply, repost, atMentions) => {
|
||||
export default async (post, reply, repost, mentions) => {
|
||||
post.mentions = [];
|
||||
|
||||
function addMention(mentionee) {
|
||||
@ -36,15 +34,7 @@ export default async (post, reply, repost, atMentions) => {
|
||||
post._repost = null;
|
||||
}
|
||||
|
||||
await Promise.all(atMentions.map(async mention => {
|
||||
// Fetch mentioned user
|
||||
// SELECT _id
|
||||
const { _id } = await User
|
||||
.findOne(parseAcct(mention), { _id: true });
|
||||
|
||||
// Add mention
|
||||
addMention(_id);
|
||||
}));
|
||||
await Promise.all(mentions.map(({ _id }) => addMention(_id)));
|
||||
|
||||
return Post.insert(post);
|
||||
};
|
||||
|
@ -25,7 +25,7 @@ export default async ({ data }, done) => {
|
||||
}) as IRemoteUser;
|
||||
|
||||
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 createPost from '../../post/create';
|
||||
import distributePost from '../../post/distribute';
|
||||
import resolvePerson from './resolve-person';
|
||||
import Resolver from './resolver';
|
||||
const createDOMPurify = require('dompurify');
|
||||
|
||||
@ -53,6 +54,15 @@ class Creator {
|
||||
.map(({ object }) => object.$id);
|
||||
|
||||
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({
|
||||
channelId: undefined,
|
||||
@ -69,7 +79,7 @@ class Creator {
|
||||
viaMobile: false,
|
||||
geo: undefined,
|
||||
uri: note.id
|
||||
}, null, null, []);
|
||||
}, null, null, await Promise.all(mentions));
|
||||
|
||||
const promises = [];
|
||||
|
||||
|
@ -4,14 +4,13 @@ import User, { validateUsername, isValidName, isValidDescription } from '../../m
|
||||
import { createHttp } from '../../queue';
|
||||
import webFinger from '../webfinger';
|
||||
import create from './create';
|
||||
import Resolver from './resolver';
|
||||
|
||||
async function isCollection(collection) {
|
||||
return ['Collection', 'OrderedCollection'].includes(collection.type);
|
||||
}
|
||||
|
||||
export default async (value, verifier?: string) => {
|
||||
const { resolver, object } = await new Resolver().resolveOne(value);
|
||||
export default async (parentResolver, value, verifier?: string) => {
|
||||
const { resolver, object } = parentResolver.resolveOne(value);
|
||||
|
||||
if (
|
||||
object === null ||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { toUnicode, toASCII } from 'punycode';
|
||||
import User from '../models/user';
|
||||
import resolvePerson from './activitypub/resolve-person';
|
||||
import Resolver from './activitypub/resolver';
|
||||
import webFinger from './webfinger';
|
||||
|
||||
export default async (username, host, option) => {
|
||||
@ -19,7 +20,7 @@ export default async (username, host, option) => {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
user = await resolvePerson(self.href, acctLower);
|
||||
user = await resolvePerson(new Resolver(), self.href, acctLower);
|
||||
}
|
||||
|
||||
return user;
|
||||
|
@ -3,12 +3,13 @@
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import deepEqual = require('deep-equal');
|
||||
import parseAcct from '../../../../acct/parse';
|
||||
import renderAcct from '../../../../acct/render';
|
||||
import config from '../../../../config';
|
||||
import html from '../../../../text/html';
|
||||
import parse from '../../../../text/parse';
|
||||
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 DriveFile from '../../../../models/drive-file';
|
||||
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')
|
||||
.map(renderAcct)
|
||||
// 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,
|
||||
visibility,
|
||||
geo
|
||||
}, reply, repost, atMentions);
|
||||
}, reply, repost, await Promise.all(atMentions));
|
||||
|
||||
const postObj = await distribute(user, post.mentions, post);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user