Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F84164609
subscription_controller.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
subscription_controller.ex
View Options
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma.Web.MastodonAPI.SubscriptionController
do
@moduledoc
"The module represents functions to manage user subscriptions."
use
Pleroma.Web
,
:controller
alias
Pleroma.Web.Push
alias
Pleroma.Web.Push.Subscription
alias
Pleroma.Web.MastodonAPI.PushSubscriptionView
,
as
:
View
action_fallback
(
:errors
)
# Creates PushSubscription
# POST /api/v1/push/subscription
#
def
create
(%{
assigns
:
%{
user
:
user
,
token
:
token
}}
=
conn
,
params
)
do
with
true
<-
Push
.
enabled
(),
{
:ok
,
_
}
<-
Subscription
.
delete_if_exists
(
user
,
token
),
{
:ok
,
subscription
}
<-
Subscription
.
create
(
user
,
token
,
params
)
do
view
=
View
.
render
(
"push_subscription.json"
,
subscription
:
subscription
)
json
(
conn
,
view
)
end
end
# Gets PushSubscription
# GET /api/v1/push/subscription
#
def
get
(%{
assigns
:
%{
user
:
user
,
token
:
token
}}
=
conn
,
_params
)
do
with
true
<-
Push
.
enabled
(),
{
:ok
,
subscription
}
<-
Subscription
.
get
(
user
,
token
)
do
view
=
View
.
render
(
"push_subscription.json"
,
subscription
:
subscription
)
json
(
conn
,
view
)
end
end
# Updates PushSubscription
# PUT /api/v1/push/subscription
#
def
update
(%{
assigns
:
%{
user
:
user
,
token
:
token
}}
=
conn
,
params
)
do
with
true
<-
Push
.
enabled
(),
{
:ok
,
subscription
}
<-
Subscription
.
update
(
user
,
token
,
params
)
do
view
=
View
.
render
(
"push_subscription.json"
,
subscription
:
subscription
)
json
(
conn
,
view
)
end
end
# Deletes PushSubscription
# DELETE /api/v1/push/subscription
#
def
delete
(%{
assigns
:
%{
user
:
user
,
token
:
token
}}
=
conn
,
_params
)
do
with
true
<-
Push
.
enabled
(),
{
:ok
,
_response
}
<-
Subscription
.
delete
(
user
,
token
),
do
:
json
(
conn
,
%{})
end
# fallback action
#
def
errors
(
conn
,
{
:error
,
:not_found
})
do
conn
|>
put_status
(
404
)
|>
json
(
"Not found"
)
end
def
errors
(
conn
,
_
)
do
conn
|>
put_status
(
500
)
|>
json
(
"Something went wrong"
)
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Thu, Jun 4, 6:22 PM (1 d, 3 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1480903
Default Alt Text
subscription_controller.ex (2 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment