Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F162776
queries.ex
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
queries.ex
View Options
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma.Activity.Queries
do
@moduledoc
"""
Contains queries for Activity.
"""
import
Ecto.Query
,
only
:
[
from
:
2
,
where
:
3
]
@type
query
::
Ecto.Queryable
.
t
()
|
Pleroma.Activity
.
t
()
alias
Pleroma.Activity
alias
Pleroma.User
@spec
by_id
(
query
(),
String
.
t
())
::
query
()
def
by_id
(
query
\\
Activity
,
id
)
do
from
(
a
in
query
,
where
:
a
.
id
==
^
id
)
end
@spec
by_ap_id
(
query
,
String
.
t
())
::
query
def
by_ap_id
(
query
\\
Activity
,
ap_id
)
do
from
(
activity
in
query
,
where
:
fragment
(
"(?)->>'id' = ?"
,
activity
.
data
,
^
to_string
(
ap_id
))
)
end
@spec
by_actor
(
query
,
String
.
t
())
::
query
def
by_actor
(
query
\\
Activity
,
actor
)
do
from
(
a
in
query
,
where
:
a
.
actor
==
^
actor
)
end
@spec
by_author
(
query
,
User
.
t
())
::
query
def
by_author
(
query
\\
Activity
,
%
User
{
ap_id
:
ap_id
})
do
from
(
a
in
query
,
where
:
a
.
actor
==
^
ap_id
)
end
def
find_by_object_ap_id
(
activities
,
object_ap_id
)
do
Enum
.
find
(
activities
,
&
(
object_ap_id
in
[
is_map
(
&1
.
data
[
"object"
])
&&
&1
.
data
[
"object"
][
"id"
],
&1
.
data
[
"object"
]])
)
end
@spec
by_object_id
(
query
,
String
.
t
()
|
[
String
.
t
()])
::
query
def
by_object_id
(
query
\\
Activity
,
object_id
)
def
by_object_id
(
query
,
object_ids
)
when
is_list
(
object_ids
)
do
from
(
activity
in
query
,
where
:
fragment
(
"associated_object_id((?)) = ANY(?)"
,
activity
.
data
,
^
object_ids
)
)
end
def
by_object_id
(
query
,
object_id
)
when
is_binary
(
object_id
)
do
from
(
activity
in
query
,
where
:
fragment
(
"associated_object_id((?)) = ?"
,
activity
.
data
,
^
object_id
)
)
end
@spec
by_object_in_reply_to_id
(
query
,
String
.
t
(),
keyword
())
::
query
def
by_object_in_reply_to_id
(
query
,
in_reply_to_id
,
opts
\\
[])
do
query
=
if
opts
[
:skip_preloading
]
do
Activity
.
with_joined_object
(
query
)
else
Activity
.
with_preloaded_object
(
query
)
end
where
(
query
,
[
activity
,
object
:
o
],
fragment
(
"(?)->>'inReplyTo' = ?"
,
o
.
data
,
^
to_string
(
in_reply_to_id
))
)
end
@spec
by_type
(
query
,
String
.
t
())
::
query
def
by_type
(
query
\\
Activity
,
activity_type
)
do
from
(
activity
in
query
,
where
:
fragment
(
"(?)->>'type' = ?"
,
activity
.
data
,
^
activity_type
)
)
end
@spec
exclude_type
(
query
,
String
.
t
())
::
query
def
exclude_type
(
query
\\
Activity
,
activity_type
)
do
from
(
activity
in
query
,
where
:
fragment
(
"(?)->>'type' != ?"
,
activity
.
data
,
^
activity_type
)
)
end
def
exclude_authors
(
query
\\
Activity
,
actors
)
do
from
(
activity
in
query
,
where
:
activity
.
actor
not
in
^
actors
)
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Fri, Feb 21, 6:07 PM (13 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
66853
Default Alt Text
queries.ex (2 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment