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
b93498eb
Commit
b93498eb
authored
Jul 29, 2019
by
kaniini
Browse files
constants: add as_public constant and use it everywhere
parent
9d78b3b2
Pipeline
#15373
passed with stages
in 8 minutes and 31 seconds
Changes
26
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/mix/tasks/pleroma/database.ex
View file @
b93498eb
...
...
@@ -8,6 +8,7 @@ defmodule Mix.Tasks.Pleroma.Database do
alias
Pleroma
.
Repo
alias
Pleroma
.
User
require
Logger
require
Pleroma
.
Constants
import
Mix
.
Pleroma
use
Mix
.
Task
...
...
@@ -99,10 +100,15 @@ def run(["prune_objects" | args]) do
NaiveDateTime
.
utc_now
()
|>
NaiveDateTime
.
add
(
-
(
deadline
*
86_400
))
public
=
"https://www.w3.org/ns/activitystreams#Public"
from
(
o
in
Object
,
where:
fragment
(
"?->'to'
\\
? ? OR ?->'cc'
\\
? ?"
,
o
.
data
,
^
public
,
o
.
data
,
^
public
),
where:
fragment
(
"?->'to'
\\
? ? OR ?->'cc'
\\
? ?"
,
o
.
data
,
^
Pleroma
.
Constants
.
as_public
(),
o
.
data
,
^
Pleroma
.
Constants
.
as_public
()
),
where:
o
.
inserted_at
<
^
time_deadline
,
where:
fragment
(
"split_part(?->>'actor', '/', 3) != ?"
,
o
.
data
,
^
Pleroma
.
Web
.
Endpoint
.
host
())
...
...
lib/pleroma/activity/search.ex
View file @
b93498eb
...
...
@@ -9,6 +9,8 @@ defmodule Pleroma.Activity.Search do
alias
Pleroma
.
User
alias
Pleroma
.
Web
.
ActivityPub
.
Visibility
require
Pleroma
.
Constants
import
Ecto
.
Query
def
search
(
user
,
search_query
,
options
\\
[])
do
...
...
@@ -39,7 +41,7 @@ def maybe_restrict_author(query, _), do: query
defp
restrict_public
(
q
)
do
from
([
a
,
o
]
in
q
,
where:
fragment
(
"?->>'type' = 'Create'"
,
a
.
data
),
where:
"https://www.w3.org/ns/activitystreams#P
ublic
"
in
a
.
recipients
where:
^
Pleroma
.
Constants
.
as_p
ublic
()
in
a
.
recipients
)
end
...
...
lib/pleroma/constants.ex
0 → 100644
View file @
b93498eb
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma
.
Constants
do
use
Const
const
(
as_public
,
do
:
"https://www.w3.org/ns/activitystreams#Public"
)
end
lib/pleroma/web/activity_pub/activity_pub.ex
View file @
b93498eb
...
...
@@ -23,6 +23,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
import
Pleroma
.
Web
.
ActivityPub
.
Visibility
require
Logger
require
Pleroma
.
Constants
# For Announce activities, we filter the recipients based on following status for any actors
# that match actual users. See issue #164 for more information about why this is necessary.
...
...
@@ -207,8 +208,6 @@ def stream_out_participations(%Object{data: %{"context" => context}}, user) do
def
stream_out_participations
(
_
,
_
),
do
:
:noop
def
stream_out
(
activity
)
do
public
=
"https://www.w3.org/ns/activitystreams#Public"
if
activity
.
data
[
"type"
]
in
[
"Create"
,
"Announce"
,
"Delete"
]
do
object
=
Object
.
normalize
(
activity
)
# Do not stream out poll replies
...
...
@@ -216,7 +215,7 @@ def stream_out(activity) do
Pleroma
.
Web
.
Streamer
.
stream
(
"user"
,
activity
)
Pleroma
.
Web
.
Streamer
.
stream
(
"list"
,
activity
)
if
Enum
.
member?
(
activity
.
data
[
"to"
],
public
)
do
if
get_visibility
(
activity
)
==
"
public
"
do
Pleroma
.
Web
.
Streamer
.
stream
(
"public"
,
activity
)
if
activity
.
local
do
...
...
@@ -238,13 +237,8 @@ def stream_out(activity) do
end
end
else
# TODO: Write test, replace with visibility test
if
!Enum
.
member?
(
activity
.
data
[
"cc"
]
||
[],
public
)
&&
!Enum
.
member?
(
activity
.
data
[
"to"
],
User
.
get_cached_by_ap_id
(
activity
.
data
[
"actor"
])
.
follower_address
),
do
:
Pleroma
.
Web
.
Streamer
.
stream
(
"direct"
,
activity
)
if
get_visibility
(
activity
)
==
"direct"
,
do
:
Pleroma
.
Web
.
Streamer
.
stream
(
"direct"
,
activity
)
end
end
end
...
...
@@ -514,7 +508,7 @@ def flag(
end
defp
fetch_activities_for_context_query
(
context
,
opts
)
do
public
=
[
"https://www.w3.org/ns/activitystreams#P
ublic
"
]
public
=
[
Pleroma
.
Constants
.
as_p
ublic
()
]
recipients
=
if
opts
[
"user"
],
do
:
[
opts
[
"user"
]
.
ap_id
|
opts
[
"user"
]
.
following
]
++
public
,
else
:
public
...
...
@@ -555,7 +549,7 @@ def fetch_latest_activity_id_for_context(context, opts \\ %{}) do
end
def
fetch_public_activities
(
opts
\\
%{})
do
q
=
fetch_activities_query
([
"https://www.w3.org/ns/activitystreams#P
ublic
"
],
opts
)
q
=
fetch_activities_query
([
Pleroma
.
Constants
.
as_p
ublic
()
],
opts
)
q
|>
restrict_unlisted
()
...
...
@@ -646,10 +640,9 @@ defp user_activities_recipients(%{"godmode" => true}) do
defp
user_activities_recipients
(%{
"reading_user"
=>
reading_user
})
do
if
reading_user
do
[
"https://www.w3.org/ns/activitystreams#Public"
]
++
[
reading_user
.
ap_id
|
reading_user
.
following
]
[
Pleroma
.
Constants
.
as_public
()]
++
[
reading_user
.
ap_id
|
reading_user
.
following
]
else
[
"https://www.w3.org/ns/activitystreams#P
ublic
"
]
[
Pleroma
.
Constants
.
as_p
ublic
()
]
end
end
...
...
@@ -834,7 +827,7 @@ defp restrict_unlisted(query) do
fragment
(
"not (coalesce(?->'cc', '{}'::jsonb)
\\
?| ?)"
,
activity
.
data
,
^
[
"https://www.w3.org/ns/activitystreams#P
ublic
"
]
^
[
Pleroma
.
Constants
.
as_p
ublic
()
]
)
)
end
...
...
@@ -971,7 +964,7 @@ def fetch_activities_bounded_query(query, recipients, recipients_with_public) do
where:
fragment
(
"? && ?"
,
activity
.
recipients
,
^
recipients
)
or
(
fragment
(
"? && ?"
,
activity
.
recipients
,
^
recipients_with_public
)
and
"https://www.w3.org/ns/activitystreams#P
ublic
"
in
activity
.
recipients
)
^
Pleroma
.
Constants
.
as_p
ublic
()
in
activity
.
recipients
)
)
end
...
...
lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex
View file @
b93498eb
...
...
@@ -4,6 +4,9 @@
defmodule
Pleroma
.
Web
.
ActivityPub
.
MRF
.
HellthreadPolicy
do
alias
Pleroma
.
User
require
Pleroma
.
Constants
@moduledoc
"Block messages with too much mentions (configurable)"
@behaviour
Pleroma
.
Web
.
ActivityPub
.
MRF
...
...
@@ -19,12 +22,12 @@ defp delist_message(message, threshold) when threshold > 0 do
when
follower_collection?
and
recipients
>
threshold
->
message
|>
Map
.
put
(
"to"
,
[
follower_collection
])
|>
Map
.
put
(
"cc"
,
[
"https://www.w3.org/ns/activitystreams#P
ublic
"
])
|>
Map
.
put
(
"cc"
,
[
Pleroma
.
Constants
.
as_p
ublic
()
])
{
:public
,
recipients
}
when
recipients
>
threshold
->
message
|>
Map
.
put
(
"to"
,
[])
|>
Map
.
put
(
"cc"
,
[
"https://www.w3.org/ns/activitystreams#P
ublic
"
])
|>
Map
.
put
(
"cc"
,
[
Pleroma
.
Constants
.
as_p
ublic
()
])
_
->
message
...
...
@@ -51,10 +54,10 @@ defp get_recipient_count(message) do
recipients
=
(
message
[
"to"
]
||
[])
++
(
message
[
"cc"
]
||
[])
follower_collection
=
User
.
get_cached_by_ap_id
(
message
[
"actor"
])
.
follower_address
if
Enum
.
member?
(
recipients
,
"https://www.w3.org/ns/activitystreams#P
ublic
"
)
do
if
Enum
.
member?
(
recipients
,
Pleroma
.
Constants
.
as_p
ublic
()
)
do
recipients
=
recipients
|>
List
.
delete
(
"https://www.w3.org/ns/activitystreams#P
ublic
"
)
|>
List
.
delete
(
Pleroma
.
Constants
.
as_p
ublic
()
)
|>
List
.
delete
(
follower_collection
)
{
:public
,
length
(
recipients
)}
...
...
lib/pleroma/web/activity_pub/mrf/keyword_policy.ex
View file @
b93498eb
...
...
@@ -3,6 +3,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma
.
Web
.
ActivityPub
.
MRF
.
KeywordPolicy
do
require
Pleroma
.
Constants
@moduledoc
"Reject or Word-Replace messages with a keyword or regex"
@behaviour
Pleroma
.
Web
.
ActivityPub
.
MRF
...
...
@@ -31,12 +33,12 @@ defp check_reject(%{"object" => %{"content" => content, "summary" => summary}} =
defp
check_ftl_removal
(
%{
"to"
=>
to
,
"object"
=>
%{
"content"
=>
content
,
"summary"
=>
summary
}}
=
message
)
do
if
"https://www.w3.org/ns/activitystreams#P
ublic
"
in
to
and
if
Pleroma
.
Constants
.
as_p
ublic
()
in
to
and
Enum
.
any?
(
Pleroma
.
Config
.
get
([
:mrf_keyword
,
:federated_timeline_removal
]),
fn
pattern
->
string_matches?
(
content
,
pattern
)
or
string_matches?
(
summary
,
pattern
)
end
)
do
to
=
List
.
delete
(
to
,
"https://www.w3.org/ns/activitystreams#P
ublic
"
)
cc
=
[
"https://www.w3.org/ns/activitystreams#P
ublic
"
|
message
[
"cc"
]
||
[]]
to
=
List
.
delete
(
to
,
Pleroma
.
Constants
.
as_p
ublic
()
)
cc
=
[
Pleroma
.
Constants
.
as_p
ublic
()
|
message
[
"cc"
]
||
[]]
message
=
message
...
...
lib/pleroma/web/activity_pub/mrf/reject_non_public.ex
View file @
b93498eb
...
...
@@ -10,7 +10,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublic do
@behaviour
Pleroma
.
Web
.
ActivityPub
.
MRF
@public
"https://www.w3.org/ns/activitystreams#Public"
require
Pleroma
.
Constants
@impl
true
def
filter
(%{
"type"
=>
"Create"
}
=
object
)
do
...
...
@@ -19,8 +19,8 @@ def filter(%{"type" => "Create"} = object) do
# Determine visibility
visibility
=
cond
do
@
public
in
object
[
"to"
]
->
"public"
@
public
in
object
[
"cc"
]
->
"unlisted"
Pleroma
.
Constants
.
as_
public
()
in
object
[
"to"
]
->
"public"
Pleroma
.
Constants
.
as_
public
()
in
object
[
"cc"
]
->
"unlisted"
user
.
follower_address
in
object
[
"to"
]
->
"followers"
true
->
"direct"
end
...
...
lib/pleroma/web/activity_pub/mrf/simple_policy.ex
View file @
b93498eb
...
...
@@ -8,6 +8,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
@moduledoc
"Filter activities depending on their origin instance"
@behaviour
MRF
require
Pleroma
.
Constants
defp
check_accept
(%{
host:
actor_host
}
=
_actor_info
,
object
)
do
accepts
=
Pleroma
.
Config
.
get
([
:mrf_simple
,
:accept
])
...
...
@@ -89,14 +91,10 @@ defp check_ftl_removal(%{host: actor_host} = _actor_info, object) do
object
=
with
true
<-
MRF
.
subdomain_match?
(
timeline_removal
,
actor_host
),
user
<-
User
.
get_cached_by_ap_id
(
object
[
"actor"
]),
true
<-
"https://www.w3.org/ns/activitystreams#Public"
in
object
[
"to"
]
do
to
=
List
.
delete
(
object
[
"to"
],
"https://www.w3.org/ns/activitystreams#Public"
)
++
[
user
.
follower_address
]
cc
=
List
.
delete
(
object
[
"cc"
],
user
.
follower_address
)
++
[
"https://www.w3.org/ns/activitystreams#Public"
]
true
<-
Pleroma
.
Constants
.
as_public
()
in
object
[
"to"
]
do
to
=
List
.
delete
(
object
[
"to"
],
Pleroma
.
Constants
.
as_public
())
++
[
user
.
follower_address
]
cc
=
List
.
delete
(
object
[
"cc"
],
user
.
follower_address
)
++
[
Pleroma
.
Constants
.
as_public
()]
object
|>
Map
.
put
(
"to"
,
to
)
...
...
lib/pleroma/web/activity_pub/mrf/tag_policy.ex
View file @
b93498eb
...
...
@@ -19,7 +19,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
- `mrf_tag:disable-any-subscription`: Reject any follow requests
"""
@public
"https://www.w3.org/ns/activitystreams#Public"
require
Pleroma
.
Constants
defp
get_tags
(%
User
{
tags:
tags
})
when
is_list
(
tags
),
do
:
tags
defp
get_tags
(
_
),
do
:
[]
...
...
@@ -70,9 +70,9 @@ defp process_tag(
)
do
user
=
User
.
get_cached_by_ap_id
(
actor
)
if
Enum
.
member?
(
to
,
@
public
)
do
to
=
List
.
delete
(
to
,
@
public
)
++
[
user
.
follower_address
]
cc
=
List
.
delete
(
cc
,
user
.
follower_address
)
++
[
@
public
]
if
Enum
.
member?
(
to
,
Pleroma
.
Constants
.
as_
public
()
)
do
to
=
List
.
delete
(
to
,
Pleroma
.
Constants
.
as_
public
()
)
++
[
user
.
follower_address
]
cc
=
List
.
delete
(
cc
,
user
.
follower_address
)
++
[
Pleroma
.
Constants
.
as_
public
()
]
object
=
object
...
...
@@ -103,9 +103,10 @@ defp process_tag(
)
do
user
=
User
.
get_cached_by_ap_id
(
actor
)
if
Enum
.
member?
(
to
,
@public
)
or
Enum
.
member?
(
cc
,
@public
)
do
to
=
List
.
delete
(
to
,
@public
)
++
[
user
.
follower_address
]
cc
=
List
.
delete
(
cc
,
@public
)
if
Enum
.
member?
(
to
,
Pleroma
.
Constants
.
as_public
())
or
Enum
.
member?
(
cc
,
Pleroma
.
Constants
.
as_public
())
do
to
=
List
.
delete
(
to
,
Pleroma
.
Constants
.
as_public
())
++
[
user
.
follower_address
]
cc
=
List
.
delete
(
cc
,
Pleroma
.
Constants
.
as_public
())
object
=
object
...
...
lib/pleroma/web/activity_pub/publisher.ex
View file @
b93498eb
...
...
@@ -11,6 +11,8 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
alias
Pleroma
.
Web
.
ActivityPub
.
Relay
alias
Pleroma
.
Web
.
ActivityPub
.
Transmogrifier
require
Pleroma
.
Constants
import
Pleroma
.
Web
.
ActivityPub
.
Visibility
@behaviour
Pleroma
.
Web
.
Federator
.
Publisher
...
...
@@ -117,8 +119,6 @@ defp get_cc_ap_ids(ap_id, recipients) do
|>
Enum
.
map
(
&
&1
.
ap_id
)
end
@as_public
"https://www.w3.org/ns/activitystreams#Public"
defp
maybe_use_sharedinbox
(%
User
{
info:
%{
source_data:
data
}}),
do
:
(
is_map
(
data
[
"endpoints"
])
&&
Map
.
get
(
data
[
"endpoints"
],
"sharedInbox"
))
||
data
[
"inbox"
]
...
...
@@ -145,7 +145,7 @@ def determine_inbox(
type
==
"Delete"
->
maybe_use_sharedinbox
(
user
)
@
as_public
in
to
||
@
as_public
in
cc
->
Pleroma
.
Constants
.
as_public
()
in
to
||
Pleroma
.
Constants
.
as_public
()
in
cc
->
maybe_use_sharedinbox
(
user
)
length
(
to
)
+
length
(
cc
)
>
1
->
...
...
lib/pleroma/web/activity_pub/transmogrifier.ex
View file @
b93498eb
...
...
@@ -19,6 +19,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
import
Ecto
.
Query
require
Logger
require
Pleroma
.
Constants
@doc
"""
Modifies an incoming AP object (mastodon format) to our internal format.
...
...
@@ -102,8 +103,7 @@ def fix_explicit_addressing(object) do
follower_collection
=
User
.
get_cached_by_ap_id
(
Containment
.
get_actor
(
object
))
.
follower_address
explicit_mentions
=
explicit_mentions
++
[
"https://www.w3.org/ns/activitystreams#Public"
,
follower_collection
]
explicit_mentions
=
explicit_mentions
++
[
Pleroma
.
Constants
.
as_public
(),
follower_collection
]
fix_explicit_addressing
(
object
,
explicit_mentions
,
follower_collection
)
end
...
...
@@ -115,11 +115,11 @@ def fix_implicit_addressing(%{"to" => to, "cc" => cc} = object, followers_collec
if
followers_collection
not
in
recipients
do
cond
do
"https://www.w3.org/ns/activitystreams#P
ublic
"
in
cc
->
Pleroma
.
Constants
.
as_p
ublic
()
in
cc
->
to
=
to
++
[
followers_collection
]
Map
.
put
(
object
,
"to"
,
to
)
"https://www.w3.org/ns/activitystreams#P
ublic
"
in
to
->
Pleroma
.
Constants
.
as_p
ublic
()
in
to
->
cc
=
cc
++
[
followers_collection
]
Map
.
put
(
object
,
"cc"
,
cc
)
...
...
@@ -480,8 +480,7 @@ def handle_incoming(
{
:ok
,
%
User
{}
=
follower
}
<-
User
.
get_or_fetch_by_ap_id
(
follower
),
{
:ok
,
activity
}
<-
ActivityPub
.
follow
(
follower
,
followed
,
id
,
false
)
do
with
deny_follow_blocked
<-
Pleroma
.
Config
.
get
([
:user
,
:deny_follow_blocked
]),
{
_
,
false
}
<-
{
:user_blocked
,
User
.
blocks?
(
followed
,
follower
)
&&
deny_follow_blocked
},
{
_
,
false
}
<-
{
:user_blocked
,
User
.
blocks?
(
followed
,
follower
)
&&
deny_follow_blocked
},
{
_
,
false
}
<-
{
:user_locked
,
User
.
locked?
(
followed
)},
{
_
,
{
:ok
,
follower
}}
<-
{
:follow
,
User
.
follow
(
follower
,
followed
)},
{
_
,
{
:ok
,
_
}}
<-
...
...
lib/pleroma/web/activity_pub/utils.ex
View file @
b93498eb
...
...
@@ -18,6 +18,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
import
Ecto
.
Query
require
Logger
require
Pleroma
.
Constants
@supported_object_types
[
"Article"
,
"Note"
,
"Video"
,
"Page"
,
"Question"
,
"Answer"
]
@supported_report_states
~w(open closed resolved)
...
...
@@ -418,7 +419,7 @@ def make_follow_data(
"type"
=>
"Follow"
,
"actor"
=>
follower_id
,
"to"
=>
[
followed_id
],
"cc"
=>
[
"https://www.w3.org/ns/activitystreams#P
ublic
"
],
"cc"
=>
[
Pleroma
.
Constants
.
as_p
ublic
()
],
"object"
=>
followed_id
,
"state"
=>
"pending"
}
...
...
@@ -510,7 +511,7 @@ def make_announce_data(
"actor"
=>
ap_id
,
"object"
=>
id
,
"to"
=>
[
user
.
follower_address
,
object
.
data
[
"actor"
]],
"cc"
=>
[
"https://www.w3.org/ns/activitystreams#P
ublic
"
],
"cc"
=>
[
Pleroma
.
Constants
.
as_p
ublic
()
],
"context"
=>
object
.
data
[
"context"
]
}
...
...
@@ -530,7 +531,7 @@ def make_unannounce_data(
"actor"
=>
ap_id
,
"object"
=>
activity
.
data
,
"to"
=>
[
user
.
follower_address
,
activity
.
data
[
"actor"
]],
"cc"
=>
[
"https://www.w3.org/ns/activitystreams#P
ublic
"
],
"cc"
=>
[
Pleroma
.
Constants
.
as_p
ublic
()
],
"context"
=>
context
}
...
...
@@ -547,7 +548,7 @@ def make_unlike_data(
"actor"
=>
ap_id
,
"object"
=>
activity
.
data
,
"to"
=>
[
user
.
follower_address
,
activity
.
data
[
"actor"
]],
"cc"
=>
[
"https://www.w3.org/ns/activitystreams#P
ublic
"
],
"cc"
=>
[
Pleroma
.
Constants
.
as_p
ublic
()
],
"context"
=>
context
}
...
...
@@ -556,7 +557,7 @@ def make_unlike_data(
def
add_announce_to_object
(
%
Activity
{
data:
%{
"actor"
=>
actor
,
"cc"
=>
[
"https://www.w3.org/ns/activitystreams#P
ublic
"
]}
data:
%{
"actor"
=>
actor
,
"cc"
=>
[
Pleroma
.
Constants
.
as_p
ublic
()
]}
},
object
)
do
...
...
@@ -765,7 +766,7 @@ defp get_updated_targets(
)
do
cc
=
Map
.
get
(
data
,
"cc"
,
[])
follower_address
=
User
.
get_cached_by_ap_id
(
data
[
"actor"
])
.
follower_address
public
=
"https://www.w3.org/ns/activitystreams#P
ublic
"
public
=
Pleroma
.
Constants
.
as_p
ublic
()
case
visibility
do
"public"
->
...
...
lib/pleroma/web/activity_pub/visibility.ex
View file @
b93498eb
...
...
@@ -8,14 +8,14 @@ defmodule Pleroma.Web.ActivityPub.Visibility do
alias
Pleroma
.
Repo
alias
Pleroma
.
User
@public
"https://www.w3.org/ns/activitystreams#Public"
require
Pleroma
.
Constants
@spec
is_public?
(
Object
.
t
()
|
Activity
.
t
()
|
map
())
::
boolean
()
def
is_public?
(%
Object
{
data:
%{
"type"
=>
"Tombstone"
}}),
do
:
false
def
is_public?
(%
Object
{
data:
data
}),
do
:
is_public?
(
data
)
def
is_public?
(%
Activity
{
data:
data
}),
do
:
is_public?
(
data
)
def
is_public?
(%{
"directMessage"
=>
true
}),
do
:
false
def
is_public?
(
data
),
do
:
@
public
in
(
data
[
"to"
]
++
(
data
[
"cc"
]
||
[]))
def
is_public?
(
data
),
do
:
Pleroma
.
Constants
.
as_
public
()
in
(
data
[
"to"
]
++
(
data
[
"cc"
]
||
[]))
def
is_private?
(
activity
)
do
with
false
<-
is_public?
(
activity
),
...
...
@@ -73,10 +73,10 @@ def get_visibility(object) do
cc
=
object
.
data
[
"cc"
]
||
[]
cond
do
@
public
in
to
->
Pleroma
.
Constants
.
as_
public
()
in
to
->
"public"
@
public
in
cc
->
Pleroma
.
Constants
.
as_
public
()
in
cc
->
"unlisted"
# this should use the sql for the object's activity
...
...
lib/pleroma/web/auth/authenticator.ex
View file @
b93498eb
...
...
@@ -21,8 +21,7 @@ def get_user(plug), do: implementation().get_user(plug)
def
create_from_registration
(
plug
,
registration
),
do
:
implementation
()
.
create_from_registration
(
plug
,
registration
)
@callback
get_registration
(
Plug
.
Conn
.
t
())
::
{
:ok
,
Registration
.
t
()}
|
{
:error
,
any
()}
@callback
get_registration
(
Plug
.
Conn
.
t
())
::
{
:ok
,
Registration
.
t
()}
|
{
:error
,
any
()}
def
get_registration
(
plug
),
do
:
implementation
()
.
get_registration
(
plug
)
@callback
handle_error
(
Plug
.
Conn
.
t
(),
any
())
::
any
()
...
...
lib/pleroma/web/common_api/common_api.ex
View file @
b93498eb
...
...
@@ -300,8 +300,7 @@ def pin(id_or_ap_id, %{ap_id: user_ap_id} = user) do
}
}
=
activity
<-
get_by_id_or_ap_id
(
id_or_ap_id
),
true
<-
Visibility
.
is_public?
(
activity
),
%{
valid?:
true
}
=
info_changeset
<-
User
.
Info
.
add_pinnned_activity
(
user
.
info
,
activity
),
%{
valid?:
true
}
=
info_changeset
<-
User
.
Info
.
add_pinnned_activity
(
user
.
info
,
activity
),
changeset
<-
Ecto
.
Changeset
.
change
(
user
)
|>
Ecto
.
Changeset
.
put_embed
(
:info
,
info_changeset
),
{
:ok
,
_user
}
<-
User
.
update_and_set_cache
(
changeset
)
do
...
...
lib/pleroma/web/common_api/utils.ex
View file @
b93498eb
...
...
@@ -19,6 +19,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
alias
Pleroma
.
Web
.
MediaProxy
require
Logger
require
Pleroma
.
Constants
# This is a hack for twidere.
def
get_by_id_or_ap_id
(
id
)
do
...
...
@@ -66,7 +67,7 @@ def attachments_from_ids_descs(ids, descs_str) do
@spec
get_to_and_cc
(
User
.
t
(),
list
(
String
.
t
()),
Activity
.
t
()
|
nil
,
String
.
t
())
::
{
list
(
String
.
t
()),
list
(
String
.
t
())}
def
get_to_and_cc
(
user
,
mentioned_users
,
inReplyTo
,
"public"
)
do
to
=
[
"https://www.w3.org/ns/activitystreams#P
ublic
"
|
mentioned_users
]
to
=
[
Pleroma
.
Constants
.
as_p
ublic
()
|
mentioned_users
]
cc
=
[
user
.
follower_address
]
if
inReplyTo
do
...
...
@@ -78,7 +79,7 @@ def get_to_and_cc(user, mentioned_users, inReplyTo, "public") do
def
get_to_and_cc
(
user
,
mentioned_users
,
inReplyTo
,
"unlisted"
)
do
to
=
[
user
.
follower_address
|
mentioned_users
]
cc
=
[
"https://www.w3.org/ns/activitystreams#P
ublic
"
]
cc
=
[
Pleroma
.
Constants
.
as_p
ublic
()
]
if
inReplyTo
do
{
Enum
.
uniq
([
inReplyTo
.
data
[
"actor"
]
|
to
]),
cc
}
...
...
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
View file @
b93498eb
...
...
@@ -49,6 +49,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
import
Ecto
.
Query
require
Logger
require
Pleroma
.
Constants
@rate_limited_relations_actions
~w(follow unfollow)a
...
...
@@ -1224,10 +1225,9 @@ def user_favourites(%{assigns: %{user: for_user}} = conn, %{"id" => id} = params
recipients
=
if
for_user
do
[
"https://www.w3.org/ns/activitystreams#Public"
]
++
[
for_user
.
ap_id
|
for_user
.
following
]
[
Pleroma
.
Constants
.
as_public
()]
++
[
for_user
.
ap_id
|
for_user
.
following
]
else
[
"https://www.w3.org/ns/activitystreams#P
ublic
"
]
[
Pleroma
.
Constants
.
as_p
ublic
()
]
end
activities
=
...
...
lib/pleroma/web/oauth/oauth_controller.ex
View file @
b93498eb
...
...
@@ -365,8 +365,7 @@ def registration_details(%Plug.Conn{} = conn, %{"authorization" => auth_attrs})
def
register
(%
Plug
.
Conn
{}
=
conn
,
%{
"authorization"
=>
_
,
"op"
=>
"connect"
}
=
params
)
do
with
registration_id
when
not
is_nil
(
registration_id
)
<-
get_session_registration_id
(
conn
),
%
Registration
{}
=
registration
<-
Repo
.
get
(
Registration
,
registration_id
),
{
_
,
{
:ok
,
auth
}}
<-
{
:create_authorization
,
do_create_authorization
(
conn
,
params
)},
{
_
,
{
:ok
,
auth
}}
<-
{
:create_authorization
,
do_create_authorization
(
conn
,
params
)},
%
User
{}
=
user
<-
Repo
.
preload
(
auth
,
:user
)
.
user
,
{
:ok
,
_updated_registration
}
<-
Registration
.
bind_to_user
(
registration
,
user
)
do
conn
...
...
lib/pleroma/web/oauth/token.ex
View file @
b93498eb
...
...
@@ -44,8 +44,7 @@ def get_by_refresh_token(%App{id: app_id} = _app, token) do
|>
Repo
.
find_resource
()
end
@spec
exchange_token
(
App
.
t
(),
Authorization
.
t
())
::
{
:ok
,
Token
.
t
()}
|
{
:error
,
Changeset
.
t
()}
@spec
exchange_token
(
App
.
t
(),
Authorization
.
t
())
::
{
:ok
,
Token
.
t
()}
|
{
:error
,
Changeset
.
t
()}
def
exchange_token
(
app
,
auth
)
do
with
{
:ok
,
auth
}
<-
Authorization
.
use_token
(
auth
),
true
<-
auth
.
app_id
==
app
.
id
do
...
...
lib/pleroma/web/ostatus/activity_representer.ex
View file @
b93498eb
...
...
@@ -9,6 +9,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
alias
Pleroma
.
Web
.
OStatus
.
UserRepresenter
require
Logger
require
Pleroma
.
Constants
defp
get_href
(
id
)
do
with
%
Object
{
data:
%{
"external_url"
=>
external_url
}}
<-
Object
.
get_cached_by_ap_id
(
id
)
do
...
...
@@ -34,7 +35,7 @@ defp get_mentions(to) do
Enum
.
map
(
to
,
fn
id
->
cond
do
# Special handling for the AP/Ostatus public collections
"https://www.w3.org/ns/activitystreams#P
ublic
"
==
id
->
Pleroma
.
Constants
.
as_p
ublic
()
==
id
->
{
:link
,
[
rel:
"mentioned"
,
...
...
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