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
700661b7
Commit
700661b7
authored
Dec 28, 2018
by
Ivan Tashkinov
Browse files
[
#483
] Blocked users list import (TwitterAPI).
parent
6e9a15b1
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/router.ex
View file @
700661b7
...
...
@@ -137,6 +137,7 @@ defmodule Pleroma.Web.Router do
scope
"/api/pleroma"
,
Pleroma
.
Web
.
TwitterAPI
do
pipe_through
(
:authenticated_api
)
post
(
"/blocks_import"
,
UtilController
,
:blocks_import
)
post
(
"/follow_import"
,
UtilController
,
:follow_import
)
post
(
"/change_password"
,
UtilController
,
:change_password
)
post
(
"/delete_account"
,
UtilController
,
:delete_account
)
...
...
lib/pleroma/web/twitter_api/controllers/util_controller.ex
View file @
700661b7
...
...
@@ -242,9 +242,12 @@ def follow_import(conn, %{"list" => %Plug.Upload{} = listfile}) do
def
follow_import
(%{
assigns:
%{
user:
user
}}
=
conn
,
%{
"list"
=>
list
})
do
Task
.
start
(
fn
->
String
.
split
(
list
)
follower
=
User
.
get_cached_by_ap_id
(
user
.
ap_id
)
list
|>
String
.
split
()
|>
Enum
.
map
(
fn
account
->
with
%
User
{}
=
follower
<-
User
.
get_cached_by_ap_id
(
user
.
ap_id
)
,
with
%
User
{}
<-
follower
,
%
User
{}
=
followed
<-
User
.
get_or_fetch
(
account
),
{
:ok
,
follower
}
<-
User
.
maybe_direct_follow
(
follower
,
followed
)
do
ActivityPub
.
follow
(
follower
,
followed
)
...
...
@@ -257,6 +260,30 @@ def follow_import(%{assigns: %{user: user}} = conn, %{"list" => list}) do
json
(
conn
,
"job started"
)
end
def
blocks_import
(
conn
,
%{
"list"
=>
%
Plug
.
Upload
{}
=
listfile
})
do
blocks_import
(
conn
,
%{
"list"
=>
File
.
read!
(
listfile
.
path
)})
end
def
blocks_import
(%{
assigns:
%{
user:
user
}}
=
conn
,
%{
"list"
=>
list
})
do
Task
.
start
(
fn
->
blocker
=
User
.
get_cached_by_ap_id
(
user
.
ap_id
)
list
|>
String
.
split
()
|>
Enum
.
map
(
fn
account
->
with
%
User
{}
<-
blocker
,
%
User
{}
=
blocked
<-
User
.
get_or_fetch
(
account
),
{
:ok
,
blocker
}
<-
User
.
block
(
blocker
,
blocked
)
do
ActivityPub
.
block
(
blocker
,
blocked
)
else
err
->
Logger
.
debug
(
"blocks_import: blocking
#{
account
}
failed with
#{
inspect
(
err
)
}
"
)
end
end
)
end
)
json
(
conn
,
"job started"
)
end
def
change_password
(%{
assigns:
%{
user:
user
}}
=
conn
,
params
)
do
case
CommonAPI
.
Utils
.
confirm_current_password
(
user
,
params
[
"password"
])
do
{
:ok
,
user
}
->
...
...
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