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
e416c344
Commit
e416c344
authored
Mar 13, 2019
by
Eugenij
Browse files
Unify unfollow, accept and reject follow requests using CommonAPI
parent
92a0210f
Changes
4
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/common_api/common_api.ex
View file @
e416c344
...
...
@@ -27,6 +27,42 @@ def follow(follower, followed) do
end
end
def
unfollow
(
follower
,
unfollowed
)
do
with
{
:ok
,
follower
,
_follow_activity
}
<-
User
.
unfollow
(
follower
,
unfollowed
),
{
:ok
,
_activity
}
<-
ActivityPub
.
unfollow
(
follower
,
unfollowed
)
do
{
:ok
,
follower
}
end
end
def
accept_follow_request
(
follower
,
followed
)
do
with
{
:ok
,
follower
}
<-
User
.
maybe_follow
(
follower
,
followed
),
%
Activity
{}
=
follow_activity
<-
Utils
.
fetch_latest_follow
(
follower
,
followed
),
{
:ok
,
follow_activity
}
<-
Utils
.
update_follow_state
(
follow_activity
,
"accept"
),
{
:ok
,
_activity
}
<-
ActivityPub
.
accept
(%{
to:
[
follower
.
ap_id
],
actor:
followed
,
object:
follow_activity
.
data
[
"id"
],
type:
"Accept"
})
do
{
:ok
,
follower
}
end
end
def
reject_follow_request
(
follower
,
followed
)
do
with
%
Activity
{}
=
follow_activity
<-
Utils
.
fetch_latest_follow
(
follower
,
followed
),
{
:ok
,
follow_activity
}
<-
Utils
.
update_follow_state
(
follow_activity
,
"reject"
),
{
:ok
,
_activity
}
<-
ActivityPub
.
reject
(%{
to:
[
follower
.
ap_id
],
actor:
followed
,
object:
follow_activity
.
data
[
"id"
],
type:
"Reject"
})
do
{
:ok
,
follower
}
end
end
def
delete
(
activity_id
,
user
)
do
with
%
Activity
{
data:
%{
"object"
=>
%{
"id"
=>
object_id
}}}
<-
Repo
.
get
(
Activity
,
activity_id
),
%
Object
{}
=
object
<-
Object
.
normalize
(
object_id
),
...
...
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
View file @
e416c344
...
...
@@ -15,7 +15,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
alias
Pleroma
.
User
alias
Pleroma
.
Web
alias
Pleroma
.
Web
.
ActivityPub
.
ActivityPub
alias
Pleroma
.
Web
.
ActivityPub
.
Utils
alias
Pleroma
.
Web
.
ActivityPub
.
Visibility
alias
Pleroma
.
Web
.
CommonAPI
alias
Pleroma
.
Web
.
MastodonAPI
.
AccountView
...
...
@@ -697,16 +696,7 @@ def follow_requests(%{assigns: %{user: followed}} = conn, _params) do
def
authorize_follow_request
(%{
assigns:
%{
user:
followed
}}
=
conn
,
%{
"id"
=>
id
})
do
with
%
User
{}
=
follower
<-
Repo
.
get
(
User
,
id
),
{
:ok
,
follower
}
<-
User
.
maybe_follow
(
follower
,
followed
),
%
Activity
{}
=
follow_activity
<-
Utils
.
fetch_latest_follow
(
follower
,
followed
),
{
:ok
,
follow_activity
}
<-
Utils
.
update_follow_state
(
follow_activity
,
"accept"
),
{
:ok
,
_activity
}
<-
ActivityPub
.
accept
(%{
to:
[
follower
.
ap_id
],
actor:
followed
,
object:
follow_activity
.
data
[
"id"
],
type:
"Accept"
})
do
{
:ok
,
follower
}
<-
CommonAPI
.
accept_follow_request
(
follower
,
followed
)
do
conn
|>
put_view
(
AccountView
)
|>
render
(
"relationship.json"
,
%{
user:
followed
,
target:
follower
})
...
...
@@ -720,15 +710,7 @@ def authorize_follow_request(%{assigns: %{user: followed}} = conn, %{"id" => id}
def
reject_follow_request
(%{
assigns:
%{
user:
followed
}}
=
conn
,
%{
"id"
=>
id
})
do
with
%
User
{}
=
follower
<-
Repo
.
get
(
User
,
id
),
%
Activity
{}
=
follow_activity
<-
Utils
.
fetch_latest_follow
(
follower
,
followed
),
{
:ok
,
follow_activity
}
<-
Utils
.
update_follow_state
(
follow_activity
,
"reject"
),
{
:ok
,
_activity
}
<-
ActivityPub
.
reject
(%{
to:
[
follower
.
ap_id
],
actor:
followed
,
object:
follow_activity
.
data
[
"id"
],
type:
"Reject"
})
do
{
:ok
,
follower
}
<-
CommonAPI
.
reject_follow_request
(
follower
,
followed
)
do
conn
|>
put_view
(
AccountView
)
|>
render
(
"relationship.json"
,
%{
user:
followed
,
target:
follower
})
...
...
@@ -770,8 +752,7 @@ def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
def
unfollow
(%{
assigns:
%{
user:
follower
}}
=
conn
,
%{
"id"
=>
id
})
do
with
%
User
{}
=
followed
<-
Repo
.
get
(
User
,
id
),
{
:ok
,
_activity
}
<-
ActivityPub
.
unfollow
(
follower
,
followed
),
{
:ok
,
follower
,
_
}
<-
User
.
unfollow
(
follower
,
followed
)
do
{
:ok
,
follower
}
<-
CommonAPI
.
unfollow
(
follower
,
followed
)
do
conn
|>
put_view
(
AccountView
)
|>
render
(
"relationship.json"
,
%{
user:
follower
,
target:
followed
})
...
...
lib/pleroma/web/twitter_api/twitter_api.ex
View file @
e416c344
...
...
@@ -35,11 +35,8 @@ def follow(%User{} = follower, params) do
def
unfollow
(%
User
{}
=
follower
,
params
)
do
with
{
:ok
,
%
User
{}
=
unfollowed
}
<-
get_user
(
params
),
{
:ok
,
follower
,
_follow_activity
}
<-
User
.
unfollow
(
follower
,
unfollowed
),
{
:ok
,
_activity
}
<-
ActivityPub
.
unfollow
(
follower
,
unfollowed
)
do
{
:ok
,
follower
}
<-
CommonAPI
.
unfollow
(
follower
,
unfollowed
)
do
{
:ok
,
follower
,
unfollowed
}
else
err
->
err
end
end
...
...
lib/pleroma/web/twitter_api/twitter_api_controller.ex
View file @
e416c344
...
...
@@ -14,7 +14,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
alias
Pleroma
.
Repo
alias
Pleroma
.
User
alias
Pleroma
.
Web
.
ActivityPub
.
ActivityPub
alias
Pleroma
.
Web
.
ActivityPub
.
Utils
alias
Pleroma
.
Web
.
ActivityPub
.
Visibility
alias
Pleroma
.
Web
.
CommonAPI
alias
Pleroma
.
Web
.
OAuth
.
Token
...
...
@@ -588,16 +587,7 @@ def friend_requests(conn, params) do
def
approve_friend_request
(
conn
,
%{
"user_id"
=>
uid
}
=
_params
)
do
with
followed
<-
conn
.
assigns
[
:user
],
%
User
{}
=
follower
<-
Repo
.
get
(
User
,
uid
),
{
:ok
,
follower
}
<-
User
.
maybe_follow
(
follower
,
followed
),
%
Activity
{}
=
follow_activity
<-
Utils
.
fetch_latest_follow
(
follower
,
followed
),
{
:ok
,
follow_activity
}
<-
Utils
.
update_follow_state
(
follow_activity
,
"accept"
),
{
:ok
,
_activity
}
<-
ActivityPub
.
accept
(%{
to:
[
follower
.
ap_id
],
actor:
followed
,
object:
follow_activity
.
data
[
"id"
],
type:
"Accept"
})
do
{
:ok
,
follower
}
<-
CommonAPI
.
accept_follow_request
(
follower
,
followed
)
do
conn
|>
put_view
(
UserView
)
|>
render
(
"show.json"
,
%{
user:
follower
,
for:
followed
})
...
...
@@ -609,15 +599,7 @@ def approve_friend_request(conn, %{"user_id" => uid} = _params) do
def
deny_friend_request
(
conn
,
%{
"user_id"
=>
uid
}
=
_params
)
do
with
followed
<-
conn
.
assigns
[
:user
],
%
User
{}
=
follower
<-
Repo
.
get
(
User
,
uid
),
%
Activity
{}
=
follow_activity
<-
Utils
.
fetch_latest_follow
(
follower
,
followed
),
{
:ok
,
follow_activity
}
<-
Utils
.
update_follow_state
(
follow_activity
,
"reject"
),
{
:ok
,
_activity
}
<-
ActivityPub
.
reject
(%{
to:
[
follower
.
ap_id
],
actor:
followed
,
object:
follow_activity
.
data
[
"id"
],
type:
"Reject"
})
do
{
:ok
,
follower
}
<-
CommonAPI
.
reject_follow_request
(
follower
,
followed
)
do
conn
|>
put_view
(
UserView
)
|>
render
(
"show.json"
,
%{
user:
follower
,
for:
followed
})
...
...
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