Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dima Krasner
Sharkey
Commits
d305c7e4
Commit
d305c7e4
authored
6 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
Fix
parent
8afaca36
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/remote/activitypub/models/note.ts
+25
-15
25 additions, 15 deletions
src/remote/activitypub/models/note.ts
with
25 additions
and
15 deletions
src/remote/activitypub/models/note.ts
+
25
−
15
View file @
d305c7e4
...
...
@@ -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
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment