Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
81d6ca17
Commit
81d6ca17
authored
Nov 08, 2018
by
kaniini
Browse files
user: implement AS2 mention extraction + unify Announce handling
parent
6b4064fa
Pipeline
#4339
passed with stages
in 6 minutes and 44 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
lib/pleroma/user.ex
View file @
81d6ca17
...
@@ -482,28 +482,37 @@ def get_notified_from_activity_query(to, true) do
...
@@ -482,28 +482,37 @@ def get_notified_from_activity_query(to, true) do
def
get_notified_from_activity
(
activity
,
local_only
\\
true
)
def
get_notified_from_activity
(
activity
,
local_only
\\
true
)
def
get_notified_from_activity
(
def
get_notified_from_activity
(%
Activity
{
data:
%{
"to"
=>
to
}
=
data
},
local_only
)
do
%
Activity
{
data:
%{
"type"
=>
"Announce"
,
"to"
=>
to
}
=
data
},
local_only
)
do
object
=
Object
.
normalize
(
data
[
"object"
])
object
=
Object
.
normalize
(
data
[
"object"
])
actor
=
User
.
get_cached_by_ap_id
(
data
[
"actor"
])
# ensure that the actor who published the announced object appears only once
# somehow, get an AS2 object, preferring the normalized object if we have one
to
=
object_data
=
if
actor
.
nickname
!=
nil
do
if
object
do
to
++
[
object
.
data
[
"actor"
]]
object
.
data
else
if
is_map
(
data
[
"object"
])
do
data
[
"object"
]
else
else
to
%{}
end
end
end
|>
Enum
.
uniq
()
query
=
get_notified_from_activity_query
(
to
,
local_only
)
Repo
.
all
(
query
)
# finally extract AS2 mentions from this object
tagged_mentions
=
if
object_data
[
"tag"
]
do
object_data
[
"tag"
]
|>
Enum
.
filter
(
fn
x
->
is_map
(
x
)
end
)
|>
Enum
.
filter
(
fn
x
->
x
[
"type"
]
==
"Mention"
end
)
|>
Enum
.
map
(
fn
x
->
x
[
"href"
]
end
)
else
[]
end
end
def
get_notified_from_activity
(%
Activity
{
data:
%{
"to"
=>
to
}},
local_only
)
do
# ensure all mentioned users are unique
to
=
(
to
++
tagged_mentions
)
|>
Enum
.
uniq
()
query
=
get_notified_from_activity_query
(
to
,
local_only
)
query
=
get_notified_from_activity_query
(
to
,
local_only
)
Repo
.
all
(
query
)
Repo
.
all
(
query
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment