Skip to content
GitLab
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
5bf92e50
Commit
5bf92e50
authored
Nov 03, 2017
by
lain
Browse files
MastoAPI: Add blocking.
parent
33beb51d
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
View file @
5bf92e50
...
...
@@ -311,6 +311,30 @@ def unfollow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
end
end
def
block
(%{
assigns:
%{
user:
blocker
}}
=
conn
,
%{
"id"
=>
id
})
do
with
%
User
{}
=
blocked
<-
Repo
.
get
(
User
,
id
),
{
:ok
,
blocker
}
<-
User
.
block
(
blocker
,
blocked
)
do
render
conn
,
AccountView
,
"relationship.json"
,
%{
user:
blocker
,
target:
blocked
}
else
{
:error
,
message
}
=
err
->
conn
|>
put_resp_content_type
(
"application/json"
)
|>
send_resp
(
403
,
Poison
.
encode!
(%{
"error"
=>
message
}))
end
end
def
unblock
(%{
assigns:
%{
user:
blocker
}}
=
conn
,
%{
"id"
=>
id
})
do
with
%
User
{}
=
blocked
<-
Repo
.
get
(
User
,
id
),
{
:ok
,
blocker
}
<-
User
.
unblock
(
blocker
,
blocked
)
do
render
conn
,
AccountView
,
"relationship.json"
,
%{
user:
blocker
,
target:
blocked
}
else
{
:error
,
message
}
=
err
->
conn
|>
put_resp_content_type
(
"application/json"
)
|>
send_resp
(
403
,
Poison
.
encode!
(%{
"error"
=>
message
}))
end
end
def
search
(%{
assigns:
%{
user:
user
}}
=
conn
,
%{
"q"
=>
query
}
=
params
)
do
accounts
=
User
.
search
(
query
,
params
[
"resolve"
]
==
"true"
)
...
...
lib/pleroma/web/router.ex
View file @
5bf92e50
...
...
@@ -58,8 +58,8 @@ def user_fetcher(username) do
get
"/accounts/search"
,
MastodonAPIController
,
:account_search
post
"/accounts/:id/follow"
,
MastodonAPIController
,
:follow
post
"/accounts/:id/unfollow"
,
MastodonAPIController
,
:unfollow
post
"/accounts/:id/block"
,
MastodonAPIController
,
:
relationship_noop
post
"/accounts/:id/unblock"
,
MastodonAPIController
,
:
relationship_noop
post
"/accounts/:id/block"
,
MastodonAPIController
,
:
block
post
"/accounts/:id/unblock"
,
MastodonAPIController
,
:
unblock
post
"/accounts/:id/mute"
,
MastodonAPIController
,
:relationship_noop
post
"/accounts/:id/unmute"
,
MastodonAPIController
,
:relationship_noop
...
...
test/web/mastodon_api/mastodon_api_controller_test.exs
View file @
5bf92e50
...
...
@@ -291,11 +291,29 @@ test "following / unfollowing a user", %{conn: conn} do
assert
id
==
other_user
.
id
end
test
"
unimplemented block/mute endpoints"
do
test
"
blocking / unblocking a user"
,
%{
conn:
conn
}
do
user
=
insert
(
:user
)
other_user
=
insert
(
:user
)
[
"block"
,
"unblock"
,
"mute"
,
"unmute"
]
conn
=
conn
|>
assign
(
:user
,
user
)
|>
post
(
"/api/v1/accounts/
#{
other_user
.
id
}
/block"
)
assert
%{
"id"
=>
id
,
"blocking"
=>
true
}
=
json_response
(
conn
,
200
)
user
=
Repo
.
get
(
User
,
user
.
id
)
conn
=
build_conn
()
|>
assign
(
:user
,
user
)
|>
post
(
"/api/v1/accounts/
#{
other_user
.
id
}
/unblock"
)
assert
%{
"id"
=>
id
,
"blocking"
=>
false
}
=
json_response
(
conn
,
200
)
end
test
"unimplemented mute endpoints"
do
user
=
insert
(
:user
)
other_user
=
insert
(
:user
)
[
"mute"
,
"unmute"
]
|>
Enum
.
each
(
fn
(
endpoint
)
->
conn
=
build_conn
()
|>
assign
(
:user
,
user
)
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment