summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-05-07 17:45:21 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-05-07 17:45:21 +0900
commitd305c7e401fef221233b3d53f115dbb4aef665ab (patch)
tree60f61b0903fede6412c726d2a0eb78aa33fe7681 /src
parentBetter text parsing (diff)
downloadmisskey-d305c7e401fef221233b3d53f115dbb4aef665ab.tar.gz
misskey-d305c7e401fef221233b3d53f115dbb4aef665ab.tar.bz2
misskey-d305c7e401fef221233b3d53f115dbb4aef665ab.zip
Fix
Diffstat (limited to 'src')
-rw-r--r--src/remote/activitypub/models/note.ts40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts
index fe7911ae06..a1967043f0 100644
--- a/src/remote/activitypub/models/note.ts
+++ b/src/remote/activitypub/models/note.ts
@@ -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) {