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
59770c3f
Verified
Commit
59770c3f
authored
Nov 19, 2017
by
Thog
Browse files
Fix all compilation warnings
parent
ed3403ad
Changes
26
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/PasswordResetToken.ex
View file @
59770c3f
defmodule
Pleroma
.
PasswordResetToken
do
use
Ecto
.
Schema
import
Ecto
.
{
Changeset
,
Query
}
import
Ecto
.
Changeset
alias
Pleroma
.
{
User
,
PasswordResetToken
,
Repo
}
...
...
@@ -26,7 +26,7 @@ def create_token(%User{} = user) do
end
def
used_changeset
(
struct
)
do
changeset
=
struct
struct
|>
cast
(%{},
[])
|>
put_change
(
:used
,
true
)
end
...
...
@@ -34,7 +34,7 @@ def used_changeset(struct) do
def
reset_password
(
token
,
data
)
do
with
%{
used:
false
}
=
token
<-
Repo
.
get_by
(
PasswordResetToken
,
%{
token:
token
}),
%
User
{}
=
user
<-
Repo
.
get
(
User
,
token
.
user_id
),
{
:ok
,
user
}
<-
User
.
reset_password
(
user
,
data
),
{
:ok
,
_
user
}
<-
User
.
reset_password
(
user
,
data
),
{
:ok
,
token
}
<-
Repo
.
update
(
used_changeset
(
token
))
do
{
:ok
,
token
}
else
...
...
lib/pleroma/notification.ex
View file @
59770c3f
...
...
@@ -67,7 +67,7 @@ def dismiss(%{id: user_id} = _user, id) do
end
end
def
create_notifications
(%
Activity
{
id:
id
,
data:
%{
"to"
=>
to
,
"type"
=>
type
}}
=
activity
)
when
type
in
[
"Create"
,
"Like"
,
"Announce"
,
"Follow"
]
do
def
create_notifications
(%
Activity
{
id:
_
,
data:
%{
"to"
=>
_
,
"type"
=>
type
}}
=
activity
)
when
type
in
[
"Create"
,
"Like"
,
"Announce"
,
"Follow"
]
do
users
=
User
.
get_notified_from_activity
(
activity
)
notifications
=
Enum
.
map
(
users
,
fn
(
user
)
->
create_notification
(
activity
,
user
)
end
)
...
...
lib/pleroma/object.ex
View file @
59770c3f
...
...
@@ -15,7 +15,7 @@ def create(data) do
end
def
change
(
struct
,
params
\\
%{})
do
changeset
=
struct
struct
|>
cast
(
params
,
[
:data
])
|>
validate_required
([
:data
])
|>
unique_constraint
(
:ap_id
,
name:
:objects_unique_apid_index
)
...
...
lib/pleroma/plugs/oauth_plug.ex
View file @
59770c3f
...
...
@@ -9,7 +9,7 @@ def init(options) do
end
def
call
(%{
assigns:
%{
user:
%
User
{}}}
=
conn
,
_
),
do
:
conn
def
call
(
conn
,
opts
)
do
def
call
(
conn
,
_
)
do
token
=
case
get_req_header
(
conn
,
"authorization"
)
do
[
"Bearer "
<>
header
]
->
header
_
->
get_session
(
conn
,
:oauth_token
)
...
...
lib/pleroma/user.ex
View file @
59770c3f
...
...
@@ -5,7 +5,6 @@ defmodule Pleroma.User do
alias
Pleroma
.
{
Repo
,
User
,
Object
,
Web
,
Activity
,
Notification
}
alias
Comeonin
.
Pbkdf2
alias
Pleroma
.
Web
.
{
OStatus
,
Websub
}
alias
Pleroma
.
Web
.
ActivityPub
.
ActivityPub
alias
Pleroma
.
Web
.
ActivityPub
.
Utils
schema
"users"
do
...
...
@@ -89,7 +88,7 @@ def remote_user_creation(params) do
end
def
update_changeset
(
struct
,
params
\\
%{})
do
changeset
=
struct
struct
|>
cast
(
params
,
[
:bio
,
:name
])
|>
unique_constraint
(
:nickname
)
|>
validate_format
(
:nickname
,
~r/^[a-zA-Z\d]+$/
)
...
...
@@ -159,7 +158,7 @@ def follow(%User{} = follower, %User{} = followed) do
|>
follow_changeset
(%{
following:
following
})
|>
Repo
.
update
{
:ok
,
followed
}
=
update_follower_count
(
followed
)
{
:ok
,
_
}
=
update_follower_count
(
followed
)
follower
end
...
...
@@ -214,7 +213,7 @@ def get_or_fetch_by_nickname(nickname) do
with
%
User
{}
=
user
<-
get_by_nickname
(
nickname
)
do
user
else
_e
->
with
[
nick
,
domain
]
<-
String
.
split
(
nickname
,
"@"
),
with
[
_
nick
,
_
domain
]
<-
String
.
split
(
nickname
,
"@"
),
{
:ok
,
user
}
<-
OStatus
.
make_user
(
nickname
)
do
user
else
_e
->
nil
...
...
@@ -276,7 +275,7 @@ def update_follower_count(%User{} = user) do
Repo
.
update
(
cs
)
end
def
get_notified_from_activity
(%
Activity
{
data:
%{
"to"
=>
to
}}
=
activity
)
do
def
get_notified_from_activity
(%
Activity
{
data:
%{
"to"
=>
to
}})
do
query
=
from
u
in
User
,
where:
u
.
ap_id
in
^
to
,
where:
u
.
local
==
true
...
...
@@ -284,7 +283,7 @@ def get_notified_from_activity(%Activity{data: %{"to" => to}} = activity) do
Repo
.
all
(
query
)
end
def
get_recipients_from_activity
(%
Activity
{
data:
%{
"to"
=>
to
}}
=
activity
)
do
def
get_recipients_from_activity
(%
Activity
{
data:
%{
"to"
=>
to
}})
do
query
=
from
u
in
User
,
where:
u
.
local
==
true
...
...
lib/pleroma/web/activity_pub/activity_pub.ex
View file @
59770c3f
defmodule
Pleroma
.
Web
.
ActivityPub
.
ActivityPub
do
alias
Pleroma
.
{
Activity
,
Repo
,
Object
,
Upload
,
User
,
Web
,
Notification
}
alias
Ecto
.
{
Changeset
,
UUID
}
alias
Pleroma
.
{
Activity
,
Repo
,
Object
,
Upload
,
User
,
Notification
}
import
Ecto
.
Query
import
Pleroma
.
Web
.
ActivityPub
.
Utils
require
Logger
...
...
@@ -34,7 +33,7 @@ def create(to, actor, context, object, additional \\ %{}, published \\ nil, loca
end
# TODO: This is weird, maybe we shouldn't check here if we can make the activity.
def
like
(%
User
{
ap_id:
ap_id
}
=
user
,
%
Object
{
data:
%{
"id"
=>
id
}}
=
object
,
activity_id
\\
nil
,
local
\\
true
)
do
def
like
(%
User
{
ap_id:
ap_id
}
=
user
,
%
Object
{
data:
%{
"id"
=>
_
}}
=
object
,
activity_id
\\
nil
,
local
\\
true
)
do
with
nil
<-
get_existing_like
(
ap_id
,
object
),
like_data
<-
make_like_data
(
user
,
object
,
activity_id
),
{
:ok
,
activity
}
<-
insert
(
like_data
,
local
),
...
...
@@ -56,7 +55,7 @@ def unlike(%User{} = actor, %Object{} = object) do
end
end
def
announce
(%
User
{
ap_id:
ap_id
}
=
user
,
%
Object
{
data:
%{
"id"
=>
id
}}
=
object
,
activity_id
\\
nil
,
local
\\
true
)
do
def
announce
(%
User
{
ap_id:
_
}
=
user
,
%
Object
{
data:
%{
"id"
=>
_
}}
=
object
,
activity_id
\\
nil
,
local
\\
true
)
do
with
announce_data
<-
make_announce_data
(
user
,
object
,
activity_id
),
{
:ok
,
activity
}
<-
insert
(
announce_data
,
local
),
{
:ok
,
object
}
<-
add_announce_to_object
(
activity
,
object
),
...
...
lib/pleroma/web/activity_pub/utils.ex
View file @
59770c3f
...
...
@@ -64,7 +64,7 @@ def lazy_put_object_defaults(map) do
Inserts a full object if it is contained in an activity.
"""
def
insert_full_object
(%{
"object"
=>
object_data
})
when
is_map
(
object_data
)
do
with
{
:ok
,
object
}
<-
Object
.
create
(
object_data
)
do
with
{
:ok
,
_
}
<-
Object
.
create
(
object_data
)
do
:ok
end
end
...
...
@@ -88,7 +88,7 @@ def update_object_in_activities(%{data: %{"id" => id}} = object) do
@doc
"""
Returns an existing like if a user already liked an object
"""
def
get_existing_like
(
actor
,
%{
data:
%{
"id"
=>
id
}}
=
object
)
do
def
get_existing_like
(
actor
,
%{
data:
%{
"id"
=>
id
}})
do
query
=
from
activity
in
Activity
,
where:
fragment
(
"(?)->>'actor' = ?"
,
activity
.
data
,
^
actor
),
# this is to use the index
...
...
@@ -201,7 +201,7 @@ def make_unfollow_data(follower, followed, follow_activity) do
def
make_create_data
(
params
,
additional
)
do
published
=
params
.
published
||
make_date
()
activity
=
%{
%{
"type"
=>
"Create"
,
"to"
=>
params
.
to
|>
Enum
.
uniq
,
"actor"
=>
params
.
actor
.
ap_id
,
...
...
lib/pleroma/web/common_api/utils.ex
View file @
59770c3f
...
...
@@ -57,7 +57,7 @@ def add_attachments(text, attachments) do
Enum
.
join
([
text
|
attachment_text
],
"<br>"
)
end
def
format_input
(
text
,
mentions
,
tags
)
do
def
format_input
(
text
,
mentions
,
_
tags
)
do
Phoenix
.
HTML
.
html_escape
(
text
)
|>
elem
(
1
)
|>
Formatter
.
linkify
...
...
lib/pleroma/web/federator/federator.ex
View file @
59770c3f
...
...
@@ -71,7 +71,7 @@ def handle(:publish_single_websub, %{xml: xml, topic: topic, callback: callback,
end
end
def
handle
(
type
,
payload
)
do
def
handle
(
type
,
_
)
do
Logger
.
debug
(
fn
->
"Unknown task:
#{
type
}
"
end
)
{
:error
,
"Don't know what do do with this"
}
end
...
...
@@ -101,14 +101,14 @@ def handle_cast({:enqueue, type, payload}, {running_jobs, queue}) do
{
:noreply
,
{
running_jobs
,
queue
}}
end
def
handle_cast
(
m
,
state
)
do
IO
.
inspect
(
"Unknown:
#{
inspect
(
m
)
}
,
#{
inspect
(
state
)
}
"
)
{
:noreply
,
state
}
end
def
handle_info
({
:DOWN
,
ref
,
:process
,
_pid
,
_reason
},
{
running_jobs
,
queue
})
do
running_jobs
=
:sets
.
del_element
(
ref
,
running_jobs
)
{
running_jobs
,
queue
}
=
maybe_start_job
(
running_jobs
,
queue
)
{
:noreply
,
{
running_jobs
,
queue
}}
end
def
handle_cast
(
m
,
state
)
do
IO
.
inspect
(
"Unknown:
#{
inspect
(
m
)
}
,
#{
inspect
(
state
)
}
"
)
{
:noreply
,
state
}
end
end
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
View file @
59770c3f
...
...
@@ -4,12 +4,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
alias
Pleroma
.
Web
alias
Pleroma
.
Web
.
MastodonAPI
.
{
StatusView
,
AccountView
,
MastodonView
}
alias
Pleroma
.
Web
.
ActivityPub
.
ActivityPub
alias
Pleroma
.
Web
.
TwitterAPI
.
TwitterAPI
alias
Pleroma
.
Web
.
{
CommonAPI
,
OStatus
}
alias
Pleroma
.
Web
.
OAuth
.
{
Authorization
,
Token
,
App
}
alias
Comeonin
.
Pbkdf2
import
Ecto
.
Query
import
Logger
require
Logger
def
create_app
(
conn
,
params
)
do
with
cs
<-
App
.
register_changeset
(%
App
{},
params
)
|>
IO
.
inspect
,
...
...
@@ -75,7 +74,7 @@ def update_credentials(%{assigns: %{user: user}} = conn, params) do
end
end
def
verify_credentials
(%{
assigns:
%{
user:
user
}}
=
conn
,
params
)
do
def
verify_credentials
(%{
assigns:
%{
user:
user
}}
=
conn
,
_
)
do
account
=
AccountView
.
render
(
"account.json"
,
%{
user:
user
})
json
(
conn
,
account
)
end
...
...
@@ -207,7 +206,7 @@ def get_context(%{assigns: %{user: user}} = conn, %{"id" => id}) do
end
end
def
post_status
(%{
assigns:
%{
user:
user
}}
=
conn
,
%{
"status"
=>
status
}
=
params
)
do
def
post_status
(%{
assigns:
%{
user:
user
}}
=
conn
,
%{
"status"
=>
_
}
=
params
)
do
params
=
params
|>
Map
.
put
(
"in_reply_to_status_id"
,
params
[
"in_reply_to_id"
])
...
...
@@ -293,7 +292,7 @@ def relationships(%{assigns: %{user: user}} = conn, %{"id" => id}) do
render
conn
,
AccountView
,
"relationships.json"
,
%{
user:
user
,
targets:
targets
}
end
def
upload
(%{
assigns:
%{
user:
user
}}
=
conn
,
%{
"file"
=>
file
})
do
def
upload
(%{
assigns:
%{
user:
_
}}
=
conn
,
%{
"file"
=>
file
})
do
with
{
:ok
,
object
}
<-
ActivityPub
.
upload
(
file
)
do
data
=
object
.
data
|>
Map
.
put
(
"id"
,
object
.
id
)
...
...
@@ -303,7 +302,7 @@ def upload(%{assigns: %{user: user}} = conn, %{"file" => file}) do
end
def
favourited_by
(
conn
,
%{
"id"
=>
id
})
do
with
%
Activity
{
data:
%{
"object"
=>
%{
"likes"
=>
likes
}
=
data
}}
<-
Repo
.
get
(
Activity
,
id
)
do
with
%
Activity
{
data:
%{
"object"
=>
%{
"likes"
=>
likes
}}}
<-
Repo
.
get
(
Activity
,
id
)
do
q
=
from
u
in
User
,
where:
u
.
ap_id
in
^
likes
users
=
Repo
.
all
(
q
)
...
...
@@ -356,10 +355,10 @@ def following(conn, %{"id" => id}) do
def
follow
(%{
assigns:
%{
user:
follower
}}
=
conn
,
%{
"id"
=>
id
})
do
with
%
User
{}
=
followed
<-
Repo
.
get
(
User
,
id
),
{
:ok
,
follower
}
<-
User
.
follow
(
follower
,
followed
),
{
:ok
,
activity
}
<-
ActivityPub
.
follow
(
follower
,
followed
)
do
{
:ok
,
_
activity
}
<-
ActivityPub
.
follow
(
follower
,
followed
)
do
render
conn
,
AccountView
,
"relationship.json"
,
%{
user:
follower
,
target:
followed
}
else
{
:error
,
message
}
=
err
->
{
:error
,
message
}
->
conn
|>
put_resp_content_type
(
"application/json"
)
|>
send_resp
(
403
,
Poison
.
encode!
(%{
"error"
=>
message
}))
...
...
@@ -369,10 +368,10 @@ def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
def
follow
(%{
assigns:
%{
user:
follower
}}
=
conn
,
%{
"uri"
=>
uri
})
do
with
%
User
{}
=
followed
<-
Repo
.
get_by
(
User
,
nickname:
uri
),
{
:ok
,
follower
}
<-
User
.
follow
(
follower
,
followed
),
{
:ok
,
activity
}
<-
ActivityPub
.
follow
(
follower
,
followed
)
do
{
:ok
,
_
activity
}
<-
ActivityPub
.
follow
(
follower
,
followed
)
do
render
conn
,
AccountView
,
"account.json"
,
%{
user:
followed
}
else
{
:error
,
message
}
=
err
->
{
:error
,
message
}
->
conn
|>
put_resp_content_type
(
"application/json"
)
|>
send_resp
(
403
,
Poison
.
encode!
(%{
"error"
=>
message
}))
...
...
@@ -397,7 +396,7 @@ def block(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do
{
:ok
,
blocker
}
<-
User
.
block
(
blocker
,
blocked
)
do
render
conn
,
AccountView
,
"relationship.json"
,
%{
user:
blocker
,
target:
blocked
}
else
{
:error
,
message
}
=
err
->
{
:error
,
message
}
->
conn
|>
put_resp_content_type
(
"application/json"
)
|>
send_resp
(
403
,
Poison
.
encode!
(%{
"error"
=>
message
}))
...
...
@@ -409,7 +408,7 @@ def unblock(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do
{
:ok
,
blocker
}
<-
User
.
unblock
(
blocker
,
blocked
)
do
render
conn
,
AccountView
,
"relationship.json"
,
%{
user:
blocker
,
target:
blocked
}
else
{
:error
,
message
}
=
err
->
{
:error
,
message
}
->
conn
|>
put_resp_content_type
(
"application/json"
)
|>
send_resp
(
403
,
Poison
.
encode!
(%{
"error"
=>
message
}))
...
...
@@ -459,7 +458,7 @@ def account_search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) d
json
(
conn
,
res
)
end
def
favourites
(%{
assigns:
%{
user:
user
}}
=
conn
,
params
)
do
def
favourites
(%{
assigns:
%{
user:
user
}}
=
conn
,
_
)
do
params
=
conn
|>
Map
.
put
(
"type"
,
"Create"
)
|>
Map
.
put
(
"favorited_by"
,
user
.
ap_id
)
...
...
@@ -556,7 +555,7 @@ def index(%{assigns: %{user: user}} = conn, _params) do
end
end
def
login
(
conn
,
params
)
do
def
login
(
conn
,
_
)
do
conn
|>
render
(
MastodonView
,
"login.html"
)
end
...
...
lib/pleroma/web/mastodon_api/mastodon_socket.ex
View file @
59770c3f
...
...
@@ -22,9 +22,9 @@ def connect(params, socket) do
end
end
def
id
(
socket
),
do
:
nil
def
id
(
_
),
do
:
nil
def
handle
(
:text
,
message
,
state
)
do
def
handle
(
:text
,
message
,
_
state
)
do
IO
.
inspect
message
#| :ok
#| state
...
...
@@ -34,7 +34,7 @@ def handle(:text, message, state) do
{
:text
,
message
}
end
def
handle
(
:closed
,
reason
,
%{
socket:
socket
})
do
def
handle
(
:closed
,
_
,
%{
socket:
socket
})
do
topic
=
socket
.
assigns
[
:topic
]
Pleroma
.
Web
.
Streamer
.
remove_socket
(
topic
,
socket
)
end
...
...
lib/pleroma/web/mastodon_api/views/account_view.ex
View file @
59770c3f
...
...
@@ -4,7 +4,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
alias
Pleroma
.
Web
.
MastodonAPI
.
AccountView
alias
Pleroma
.
Web
.
CommonAPI
.
Utils
defp
image_url
(%{
"url"
=>
[
%{
"href"
=>
href
}
|
t
]}),
do
:
href
defp
image_url
(%{
"url"
=>
[
%{
"href"
=>
href
}
|
_
]}),
do
:
href
defp
image_url
(
_
),
do
:
nil
def
render
(
"accounts.json"
,
%{
users:
users
}
=
opts
)
do
...
...
lib/pleroma/web/ostatus/activity_representer.ex
View file @
59770c3f
...
...
@@ -108,7 +108,7 @@ def to_simple_form(%{data: %{"type" => "Like"}} = activity, user, with_author) d
updated_at
=
activity
.
data
[
"published"
]
inserted_at
=
activity
.
data
[
"published"
]
in_reply_to
=
get_in_reply_to
(
activity
.
data
)
_
in_reply_to
=
get_in_reply_to
(
activity
.
data
)
author
=
if
with_author
,
do
:
[{
:author
,
UserRepresenter
.
to_simple_form
(
user
)}],
else
:
[]
mentions
=
activity
.
data
[
"to"
]
|>
get_mentions
...
...
@@ -136,7 +136,7 @@ def to_simple_form(%{data: %{"type" => "Announce"}} = activity, user, with_autho
updated_at
=
activity
.
data
[
"published"
]
inserted_at
=
activity
.
data
[
"published"
]
in_reply_to
=
get_in_reply_to
(
activity
.
data
)
_
in_reply_to
=
get_in_reply_to
(
activity
.
data
)
author
=
if
with_author
,
do
:
[{
:author
,
UserRepresenter
.
to_simple_form
(
user
)}],
else
:
[]
retweeted_activity
=
Activity
.
get_create_activity_by_object_ap_id
(
activity
.
data
[
"object"
])
...
...
@@ -233,6 +233,8 @@ def to_simple_form(%{data: %{"type" => "Delete"}} = activity, user, with_author)
]
++
author
end
def
to_simple_form
(
_
,
_
,
_
),
do
:
nil
def
wrap_with_entry
(
simple_form
)
do
[{
:entry
,
[
...
...
@@ -244,6 +246,4 @@ def wrap_with_entry(simple_form) do
],
simple_form
}]
end
def
to_simple_form
(
_
,
_
,
_
),
do
:
nil
end
lib/pleroma/web/ostatus/feed_representer.ex
View file @
59770c3f
...
...
@@ -2,7 +2,7 @@ defmodule Pleroma.Web.OStatus.FeedRepresenter do
alias
Pleroma
.
Web
.
OStatus
alias
Pleroma
.
Web
.
OStatus
.
{
UserRepresenter
,
ActivityRepresenter
}
def
to_simple_form
(
user
,
activities
,
users
)
do
def
to_simple_form
(
user
,
activities
,
_
users
)
do
most_recent_update
=
(
List
.
first
(
activities
)
||
user
)
.
updated_at
|>
NaiveDateTime
.
to_iso8601
...
...
lib/pleroma/web/ostatus/handlers/delete_handler.ex
View file @
59770c3f
defmodule
Pleroma
.
Web
.
OStatus
.
DeleteHandler
do
require
Logger
alias
Pleroma
.
Web
.
{
XML
,
OStatus
}
alias
Pleroma
.
{
Activity
,
Object
,
Repo
}
alias
Pleroma
.
Web
.
XML
alias
Pleroma
.
Object
alias
Pleroma
.
Web
.
ActivityPub
.
ActivityPub
def
handle_delete
(
entry
,
doc
\\
nil
)
do
def
handle_delete
(
entry
,
_
doc
\\
nil
)
do
with
id
<-
XML
.
string_from_xpath
(
"//id"
,
entry
),
object
when
not
is_nil
(
object
)
<-
Object
.
get_by_ap_id
(
id
),
{
:ok
,
delete
}
<-
ActivityPub
.
delete
(
object
,
false
)
do
...
...
lib/pleroma/web/ostatus/ostatus.ex
View file @
59770c3f
...
...
@@ -7,7 +7,6 @@ defmodule Pleroma.Web.OStatus do
alias
Pleroma
.
{
Repo
,
User
,
Web
,
Object
,
Activity
}
alias
Pleroma
.
Web
.
ActivityPub
.
ActivityPub
alias
Pleroma
.
Web
.
ActivityPub
.
Utils
alias
Pleroma
.
Web
.
{
WebFinger
,
Websub
}
alias
Pleroma
.
Web
.
OStatus
.
{
FollowHandler
,
NoteHandler
,
DeleteHandler
}
...
...
@@ -112,7 +111,7 @@ def get_or_try_fetching(entry) do
with
id
when
not
is_nil
(
id
)
<-
string_from_xpath
(
"//activity:object[1]/id"
,
entry
),
%
Activity
{}
=
activity
<-
Activity
.
get_create_activity_by_object_ap_id
(
id
)
do
{
:ok
,
activity
}
else
e
->
else
_
->
Logger
.
debug
(
"Couldn't get, will try to fetch"
)
with
href
when
not
is_nil
(
href
)
<-
string_from_xpath
(
"//activity:object[1]/link[@type=
\"
text/html
\"
]/@href"
,
entry
),
{
:ok
,
[
favorited_activity
]}
<-
fetch_activity_from_url
(
href
)
do
...
...
@@ -191,7 +190,7 @@ def maybe_update(doc, user) do
false
<-
new_data
==
old_data
do
change
=
Ecto
.
Changeset
.
change
(
user
,
new_data
)
Repo
.
update
(
change
)
else
e
->
else
_
->
{
:ok
,
user
}
end
end
...
...
lib/pleroma/web/ostatus/ostatus_controller.ex
View file @
59770c3f
...
...
@@ -46,7 +46,7 @@ defp decode_or_retry(body) do
with
[
decoded
|
_
]
<-
Pleroma
.
Web
.
Salmon
.
decode
(
body
),
doc
<-
XML
.
parse_document
(
decoded
),
uri
when
not
is_nil
(
uri
)
<-
XML
.
string_from_xpath
(
"/entry/author[1]/uri"
,
doc
),
{
:ok
,
user
}
<-
Pleroma
.
Web
.
OStatus
.
make_user
(
uri
,
true
),
{
:ok
,
_
}
<-
Pleroma
.
Web
.
OStatus
.
make_user
(
uri
,
true
),
{
:ok
,
magic_key
}
<-
Pleroma
.
Web
.
Salmon
.
fetch_magic_key
(
body
),
{
:ok
,
doc
}
<-
Pleroma
.
Web
.
Salmon
.
decode_and_validate
(
magic_key
,
body
)
do
{
:ok
,
doc
}
...
...
@@ -54,7 +54,7 @@ defp decode_or_retry(body) do
end
end
def
salmon_incoming
(
conn
,
params
)
do
def
salmon_incoming
(
conn
,
_
)
do
{
:ok
,
body
,
_conn
}
=
read_body
(
conn
)
{
:ok
,
doc
}
=
decode_or_retry
(
body
)
...
...
lib/pleroma/web/streamer.ex
View file @
59770c3f
defmodule
Pleroma
.
Web
.
Streamer
do
use
GenServer
require
Logger
import
Plug
.
Conn
alias
Pleroma
.
{
User
,
Notification
}
def
start_link
do
...
...
@@ -38,17 +37,6 @@ def handle_cast(%{action: :ping}, topics) do
{
:noreply
,
topics
}
end
def
push_to_socket
(
topics
,
topic
,
item
)
do
Enum
.
each
(
topics
[
topic
]
||
[],
fn
(
socket
)
->
json
=
%{
event:
"update"
,
payload:
Pleroma
.
Web
.
MastodonAPI
.
StatusView
.
render
(
"status.json"
,
activity:
item
,
for:
socket
.
assigns
[
:user
])
|>
Poison
.
encode!
}
|>
Poison
.
encode!
send
socket
.
transport_pid
,
{
:text
,
json
}
end
)
end
def
handle_cast
(%{
action:
:stream
,
topic:
"user"
,
item:
%
Notification
{}
=
item
},
topics
)
do
topic
=
"user:
#{
item
.
user_id
}
"
Enum
.
each
(
topics
[
topic
]
||
[],
fn
(
socket
)
->
...
...
@@ -80,11 +68,6 @@ def handle_cast(%{action: :stream, topic: topic, item: item}, topics) do
{
:noreply
,
topics
}
end
defp
internal_topic
(
"user"
,
socket
)
do
"user:
#{
socket
.
assigns
[
:user
]
.
id
}
"
end
defp
internal_topic
(
topic
,
socket
),
do
:
topic
def
handle_cast
(%{
action:
:add
,
topic:
topic
,
socket:
socket
},
sockets
)
do
topic
=
internal_topic
(
topic
,
socket
)
sockets_for_topic
=
sockets
[
topic
]
||
[]
...
...
@@ -109,4 +92,21 @@ def handle_cast(m, state) do
IO
.
inspect
(
"Unknown:
#{
inspect
(
m
)
}
,
#{
inspect
(
state
)
}
"
)
{
:noreply
,
state
}
end
def
push_to_socket
(
topics
,
topic
,
item
)
do
Enum
.
each
(
topics
[
topic
]
||
[],
fn
(
socket
)
->
json
=
%{
event:
"update"
,
payload:
Pleroma
.
Web
.
MastodonAPI
.
StatusView
.
render
(
"status.json"
,
activity:
item
,
for:
socket
.
assigns
[
:user
])
|>
Poison
.
encode!
}
|>
Poison
.
encode!
send
socket
.
transport_pid
,
{
:text
,
json
}
end
)
end
defp
internal_topic
(
"user"
,
socket
)
do
"user:
#{
socket
.
assigns
[
:user
]
.
id
}
"
end
defp
internal_topic
(
topic
,
_
),
do
:
topic
end
lib/pleroma/web/twitter_api/representers/activity_representer.ex
View file @
59770c3f
...
...
@@ -97,7 +97,7 @@ def to_map(%Activity{data: %{"type" => "Undo", "published" => created_at, "objec
}
end
def
to_map
(%
Activity
{
data:
%{
"type"
=>
"Delete"
,
"published"
=>
created_at
,
"object"
=>
deleted_object
}}
=
activity
,
%{
user:
user
}
=
opts
)
do
def
to_map
(%
Activity
{
data:
%{
"type"
=>
"Delete"
,
"published"
=>
created_at
,
"object"
=>
_
}}
=
activity
,
%{
user:
user
}
=
opts
)
do
created_at
=
created_at
|>
Utils
.
date_to_asctime
%{
...
...
lib/pleroma/web/twitter_api/twitter_api.ex
View file @
59770c3f
...
...
@@ -4,12 +4,11 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
alias
Pleroma
.
Web
.
TwitterAPI
.
Representers
.
ActivityRepresenter
alias
Pleroma
.
Web
.
TwitterAPI
.
UserView
alias
Pleroma
.
Web
.
{
OStatus
,
CommonAPI
}
alias
Pleroma
.
Formatter
import
Ecto
.
Query
@httpoison
Application
.
get_env
(
:pleroma
,
:httpoison
)
def
create_status
(%
User
{}
=
user
,
%{
"status"
=>
status
}
=
data
)
do
def
create_status
(%
User
{}
=
user
,
%{
"status"
=>
_
}
=
data
)
do
CommonAPI
.
post
(
user
,
data
)
end
...
...
@@ -216,7 +215,7 @@ def get_user(user \\ nil, params) do
end
end
defp
parse_int
(
string
,
default
\\
nil
)
defp
parse_int
(
string
,
default
)
defp
parse_int
(
string
,
default
)
when
is_binary
(
string
)
do
with
{
n
,
_
}
<-
Integer
.
parse
(
string
)
do
n
...
...
Prev
1
2
Next
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