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
f1d27a5f
Commit
f1d27a5f
authored
Nov 09, 2017
by
lain
Browse files
Add actor column to activities.
parent
41b8a76e
Pipeline
#126
passed with stage
in 1 minute and 54 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/activity.ex
View file @
f1d27a5f
...
...
@@ -6,6 +6,7 @@ defmodule Pleroma.Activity do
schema
"activities"
do
field
:data
,
:map
field
:local
,
:boolean
,
default:
true
field
:actor
,
:string
has_many
:notifications
,
Notification
timestamps
()
...
...
lib/pleroma/web/activity_pub/activity_pub.ex
View file @
f1d27a5f
...
...
@@ -9,7 +9,7 @@ def insert(map, local \\ true) when is_map(map) do
with
nil
<-
Activity
.
get_by_ap_id
(
map
[
"id"
]),
map
<-
lazy_put_activity_defaults
(
map
),
:ok
<-
insert_full_object
(
map
)
do
{
:ok
,
activity
}
=
Repo
.
insert
(%
Activity
{
data:
map
,
local:
local
})
{
:ok
,
activity
}
=
Repo
.
insert
(%
Activity
{
data:
map
,
local:
local
,
actor:
map
[
"actor"
]
})
Notification
.
create_notifications
(
activity
)
{
:ok
,
activity
}
else
...
...
@@ -137,7 +137,7 @@ defp restrict_max(query, _), do: query
defp
restrict_actor
(
query
,
%{
"actor_id"
=>
actor_id
})
do
from
activity
in
query
,
where:
fragment
(
"?->>'actor' = ?"
,
activity
.
data
,
^
actor_id
)
where:
activity
.
actor
==
^
actor_id
end
defp
restrict_actor
(
query
,
_
),
do
:
query
...
...
@@ -168,14 +168,14 @@ defp restrict_recent(query, _) do
defp
restrict_blocked
(
query
,
%{
"blocking_user"
=>
%
User
{
info:
info
}})
do
blocks
=
info
[
"blocks"
]
||
[]
from
activity
in
query
,
where:
fragment
(
"not (?
->>'actor'
= ANY(?))"
,
activity
.
data
,
^
blocks
)
where:
fragment
(
"not (? = ANY(?))"
,
activity
.
actor
,
^
blocks
)
end
defp
restrict_blocked
(
query
,
_
),
do
:
query
def
fetch_activities
(
recipients
,
opts
\\
%{})
do
base_query
=
from
activity
in
Activity
,
limit:
20
,
order_by:
[
desc:
:
id
]
order_by:
[
fragment
(
"? desc nulls last"
,
activity
.
id
)
]
base_query
|>
restrict_recipients
(
recipients
)
...
...
priv/repo/migrations/20171109091239_add_actor_to_activity.exs
0 → 100644
View file @
f1d27a5f
defmodule
Pleroma
.
Repo
.
Migrations
.
AddActorToActivity
do
use
Ecto
.
Migration
@disable_ddl_transaction
true
def
up
do
alter
table
(
:activities
)
do
add
:actor
,
:string
end
execute
"""
update activities set actor = data->>'actor';
"""
create
index
(
:activities
,
[
:actor
,
"id DESC NULLS LAST"
],
concurrently:
true
)
end
def
down
do
drop
index
(
:activities
,
[
:actor
,
"id DESC NULLS LAST"
])
alter
table
(
:activities
)
do
remove
:actor
end
end
end
test/support/factory.ex
View file @
f1d27a5f
...
...
@@ -51,7 +51,8 @@ def note_activity_factory do
}
%
Pleroma
.
Activity
{
data:
data
data:
data
,
actor:
data
[
"actor"
]
}
end
...
...
test/web/activity_pub/activity_pub_test.exs
View file @
f1d27a5f
...
...
@@ -52,6 +52,7 @@ test "adds an id to a given object if it lacks one and inserts it to the object
test
"removes doubled 'to' recipients"
do
{
:ok
,
activity
}
=
ActivityPub
.
create
([
"user1"
,
"user1"
,
"user2"
],
%
User
{
ap_id:
"1"
},
""
,
%{})
assert
activity
.
data
[
"to"
]
==
[
"user1"
,
"user2"
]
assert
activity
.
actor
==
"1"
end
end
...
...
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