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
2e58fe08
Commit
2e58fe08
authored
Apr 23, 2020
by
lain
Committed by
rinpatch
May 01, 2020
Browse files
CommonAPI: Don't make repeating announces possible
parent
6e0b0467
Changes
4
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/common_api/common_api.ex
View file @
2e58fe08
...
...
@@ -83,8 +83,9 @@ def delete(activity_id, user) do
end
end
def
repeat
(
id_or_ap_id
,
user
,
params
\\
%{})
do
with
{
_
,
%
Activity
{}
=
activity
}
<-
{
:find_activity
,
get_by_id_or_ap_id
(
id_or_ap_id
)},
def
repeat
(
id
,
user
,
params
\\
%{})
do
with
{
_
,
%
Activity
{
data:
%{
"type"
=>
"Create"
}}
=
activity
}
<-
{
:find_activity
,
Activity
.
get_by_id
(
id
)},
object
<-
Object
.
normalize
(
activity
),
announce_activity
<-
Utils
.
get_existing_announce
(
user
.
ap_id
,
object
),
public
<-
public_announce?
(
object
,
params
)
do
...
...
@@ -99,8 +100,9 @@ def repeat(id_or_ap_id, user, params \\ %{}) do
end
end
def
unrepeat
(
id_or_ap_id
,
user
)
do
with
{
_
,
%
Activity
{}
=
activity
}
<-
{
:find_activity
,
get_by_id_or_ap_id
(
id_or_ap_id
)}
do
def
unrepeat
(
id
,
user
)
do
with
{
_
,
%
Activity
{
data:
%{
"type"
=>
"Create"
}}
=
activity
}
<-
{
:find_activity
,
Activity
.
get_by_id
(
id
)}
do
object
=
Object
.
normalize
(
activity
)
ActivityPub
.
unannounce
(
user
,
object
)
else
...
...
@@ -109,8 +111,8 @@ def unrepeat(id_or_ap_id, user) do
end
end
def
favorite
(
id
_or_ap_id
,
user
)
do
with
{
_
,
%
Activity
{}
=
activity
}
<-
{
:find_activity
,
get_by_id_or_ap_id
(
id_or_ap_
id
)},
def
favorite
(
id
,
user
)
do
with
{
_
,
%
Activity
{}
=
activity
}
<-
{
:find_activity
,
Activity
.
get_by_id
(
id
)},
object
<-
Object
.
normalize
(
activity
),
like_activity
<-
Utils
.
get_existing_like
(
user
.
ap_id
,
object
)
do
if
like_activity
do
...
...
@@ -124,8 +126,9 @@ def favorite(id_or_ap_id, user) do
end
end
def
unfavorite
(
id_or_ap_id
,
user
)
do
with
{
_
,
%
Activity
{}
=
activity
}
<-
{
:find_activity
,
get_by_id_or_ap_id
(
id_or_ap_id
)}
do
def
unfavorite
(
id
,
user
)
do
with
{
_
,
%
Activity
{
data:
%{
"type"
=>
"Create"
}}
=
activity
}
<-
{
:find_activity
,
Activity
.
get_by_id
(
id
)}
do
object
=
Object
.
normalize
(
activity
)
ActivityPub
.
unlike
(
user
,
object
)
else
...
...
@@ -316,12 +319,12 @@ def update(user) do
})
end
def
pin
(
id
_or_ap_id
,
%{
ap_id:
user_ap_id
}
=
user
)
do
def
pin
(
id
,
%{
ap_id:
user_ap_id
}
=
user
)
do
with
%
Activity
{
actor:
^
user_ap_id
,
data:
%{
"type"
=>
"Create"
},
object:
%
Object
{
data:
%{
"type"
=>
object_type
}}
}
=
activity
<-
get_by_id_
or_ap_id
(
id_or_ap_
id
),
}
=
activity
<-
Activity
.
get_by_id_
with_object
(
id
),
true
<-
object_type
in
[
"Note"
,
"Article"
,
"Question"
],
true
<-
Visibility
.
is_public?
(
activity
),
{
:ok
,
_user
}
<-
User
.
add_pinnned_activity
(
user
,
activity
)
do
...
...
@@ -332,8 +335,8 @@ def pin(id_or_ap_id, %{ap_id: user_ap_id} = user) do
end
end
def
unpin
(
id
_or_ap_id
,
user
)
do
with
%
Activity
{
}
=
activity
<-
get_by_id_or_ap_id
(
id_or_ap_
id
),
def
unpin
(
id
,
user
)
do
with
%
Activity
{
data:
%{
"type"
=>
"Create"
}}
=
activity
<-
Activity
.
get_by_id
(
id
),
{
:ok
,
_user
}
<-
User
.
remove_pinnned_activity
(
user
,
activity
)
do
{
:ok
,
activity
}
else
...
...
lib/pleroma/web/common_api/utils.ex
View file @
2e58fe08
...
...
@@ -24,24 +24,6 @@ defmodule Pleroma.Web.CommonAPI.Utils do
require
Logger
require
Pleroma
.
Constants
# This is a hack for twidere.
def
get_by_id_or_ap_id
(
id
)
do
activity
=
with
true
<-
FlakeId
.
flake_id?
(
id
),
%
Activity
{}
=
activity
<-
Activity
.
get_by_id_with_object
(
id
)
do
activity
else
_
->
Activity
.
get_create_by_object_ap_id_with_object
(
id
)
end
activity
&&
if
activity
.
data
[
"type"
]
==
"Create"
do
activity
else
Activity
.
get_create_by_object_ap_id_with_object
(
activity
.
data
[
"object"
])
end
end
def
attachments_from_ids
(%{
"media_ids"
=>
ids
,
"descriptions"
=>
desc
}
=
_
)
do
attachments_from_ids_descs
(
ids
,
desc
)
end
...
...
test/web/common_api/common_api_test.exs
View file @
2e58fe08
...
...
@@ -268,6 +268,16 @@ test "repeating a status" do
{
:ok
,
%
Activity
{},
_
}
=
CommonAPI
.
repeat
(
activity
.
id
,
user
)
end
test
"can't repeat a repeat"
do
user
=
insert
(
:user
)
other_user
=
insert
(
:user
)
{
:ok
,
activity
}
=
CommonAPI
.
post
(
other_user
,
%{
"status"
=>
"cofe"
})
{
:ok
,
%
Activity
{}
=
announce
,
_
}
=
CommonAPI
.
repeat
(
activity
.
id
,
other_user
)
refute
match?
({
:ok
,
%
Activity
{},
_
},
CommonAPI
.
repeat
(
announce
.
id
,
user
))
end
test
"repeating a status privately"
do
user
=
insert
(
:user
)
other_user
=
insert
(
:user
)
...
...
@@ -294,8 +304,8 @@ test "retweeting a status twice returns the status" do
other_user
=
insert
(
:user
)
{
:ok
,
activity
}
=
CommonAPI
.
post
(
other_user
,
%{
"status"
=>
"cofe"
})
{
:ok
,
%
Activity
{}
=
a
ctivity
,
object
}
=
CommonAPI
.
repeat
(
activity
.
id
,
user
)
{
:ok
,
^
a
ctivity
,
^
object
}
=
CommonAPI
.
repeat
(
activity
.
id
,
user
)
{
:ok
,
%
Activity
{}
=
a
nnounce
,
object
}
=
CommonAPI
.
repeat
(
activity
.
id
,
user
)
{
:ok
,
^
a
nnounce
,
^
object
}
=
CommonAPI
.
repeat
(
activity
.
id
,
user
)
end
test
"favoriting a status twice returns the status"
do
...
...
@@ -369,7 +379,9 @@ test "unpin status", %{user: user, activity: activity} do
user
=
refresh_record
(
user
)
assert
{
:ok
,
^
activity
}
=
CommonAPI
.
unpin
(
activity
.
id
,
user
)
id
=
activity
.
id
assert
match?
({
:ok
,
%{
id:
^
id
}},
CommonAPI
.
unpin
(
activity
.
id
,
user
))
user
=
refresh_record
(
user
)
...
...
test/web/common_api/common_api_utils_test.exs
View file @
2e58fe08
...
...
@@ -358,26 +358,6 @@ test "for direct posts, a reply" do
end
end
describe
"get_by_id_or_ap_id/1"
do
test
"get activity by id"
do
activity
=
insert
(
:note_activity
)
%
Pleroma
.
Activity
{}
=
note
=
Utils
.
get_by_id_or_ap_id
(
activity
.
id
)
assert
note
.
id
==
activity
.
id
end
test
"get activity by ap_id"
do
activity
=
insert
(
:note_activity
)
%
Pleroma
.
Activity
{}
=
note
=
Utils
.
get_by_id_or_ap_id
(
activity
.
data
[
"object"
])
assert
note
.
id
==
activity
.
id
end
test
"get activity by object when type isn't `Create` "
do
activity
=
insert
(
:like_activity
)
%
Pleroma
.
Activity
{}
=
like
=
Utils
.
get_by_id_or_ap_id
(
activity
.
id
)
assert
like
.
data
[
"object"
]
==
activity
.
data
[
"object"
]
end
end
describe
"to_master_date/1"
do
test
"removes microseconds from date (NaiveDateTime)"
do
assert
Utils
.
to_masto_date
(
~N[2015-01-23 23:50:07.123]
)
==
"2015-01-23T23:50:07.000Z"
...
...
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