Skip to content
Snippets Groups Projects
Commit d305c7e4 authored by syuilo's avatar syuilo
Browse files

Fix

parent 8afaca36
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,7 @@ import { IRemoteUser } from '../../../models/user';
const log = debug('misskey:activitypub');
function parse(tag, html: string): string {
function parse(html: string): string {
const dom = parse5.parseFragment(html) as parse5.AST.Default.Document;
let text = '';
......@@ -22,6 +22,16 @@ function parse(tag, html: string): string {
return text.trim();
function getText(node) {
if (node.nodeName == '#text') return node.value;
if (node.childNodes) {
return node.childNodes.map(n => getText(n)).join('');
}
return '';
}
function analyze(node) {
switch (node.nodeName) {
case '#text':
......@@ -39,23 +49,23 @@ function parse(tag, html: string): string {
// for Mastodon
if (cls.includes('mention')) {
//#region ホスト名部分が省略されているので復元する
// Activityのtag情報に次のような形で省略前の情報が添付されているのでそこから持ってくる
// {
// "type": "Mention",
// "href": "https://misskey.xyz/users/57d01a501fdf2d07be417afe",
// "name": "@syuilo@misskey.xyz"
// }
const mention = getText(node);
const href = node.attrs.find(x => x.name == 'href').value;
const acct = tag.find(t => t.type == 'Mention' && t.href == href).name;
const part = mention.split('@');
text += acct;
if (part.length == 2) {
//#region ホスト名部分が省略されているので復元する
break;
const href = new URL(node.attrs.find(x => x.name == 'href').value);
const acct = mention + '@' + href.hostname;
text += acct;
break;
//#endregion
//#endregion
} else if (part.length == 3) {
text += mention;
break;
}
}
if (node.childNodes) {
......@@ -154,7 +164,7 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
const reply = note.inReplyTo ? await resolveNote(note.inReplyTo, resolver) : null;
// テキストのパース
const text = parse(note.tag, note.content);
const text = parse(note.content);
// ユーザーの情報が古かったらついでに更新しておく
if (actor.updatedAt == null || Date.now() - actor.updatedAt.getTime() > 1000 * 60 * 60 * 24) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment