Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
pleroma
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
405
Issues
405
List
Boards
Labels
Service Desk
Milestones
Merge Requests
59
Merge Requests
59
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Pleroma
pleroma
Commits
2e753e8c
Commit
2e753e8c
authored
May 10, 2017
by
lain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refresh subscriptions.
parent
fca7390c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
3 deletions
+45
-3
lib/pleroma/web/federator/federator.ex
lib/pleroma/web/federator/federator.ex
+15
-2
lib/pleroma/web/websub/websub.ex
lib/pleroma/web/websub/websub.ex
+15
-0
test/web/websub/websub_test.exs
test/web/websub/websub_test.exs
+15
-1
No files found.
lib/pleroma/web/federator/federator.ex
View file @
2e753e8c
defmodule
Pleroma
.
Web
.
Federator
do
use
GenServer
alias
Pleroma
.
User
alias
Pleroma
.
Web
.
WebFinger
alias
Pleroma
.
Web
.
{
WebFinger
,
Websub
}
require
Logger
@websub
Application
.
get_env
(
:pleroma
,
:websub
)
...
...
@@ -9,14 +9,27 @@ defmodule Pleroma.Web.Federator do
@max_jobs
10
def
start_link
do
spawn
(
fn
->
Process
.
sleep
(
1000
*
60
*
1
)
# 10 minutes
enqueue
(
:refresh_subscriptions
,
nil
)
end
)
GenServer
.
start_link
(
__MODULE__
,
{
:sets
.
new
(),
:queue
.
new
()},
name:
__MODULE__
)
end
def
handle
(
:refresh_subscriptions
,
_
)
do
Logger
.
debug
(
"Federator running refresh subscriptions"
)
Websub
.
refresh_subscriptions
()
spawn
(
fn
->
Process
.
sleep
(
1000
*
60
*
60
)
# 60 minutes
enqueue
(
:refresh_subscriptions
,
nil
)
end
)
end
def
handle
(
:publish
,
activity
)
do
Logger
.
debug
(
fn
->
"Running publish for
#{
activity
.
data
[
"id"
]
}
"
end
)
with
actor
when
not
is_nil
(
actor
)
<-
User
.
get_cached_by_ap_id
(
activity
.
data
[
"actor"
])
do
Logger
.
debug
(
fn
->
"Sending
#{
activity
.
data
[
"id"
]
}
out via websub"
end
)
Pleroma
.
Web
.
Websub
.
publish
(
Pleroma
.
Web
.
OStatus
.
feed_path
(
actor
),
actor
,
activity
)
Websub
.
publish
(
Pleroma
.
Web
.
OStatus
.
feed_path
(
actor
),
actor
,
activity
)
{
:ok
,
actor
}
=
WebFinger
.
ensure_keys_present
(
actor
)
Logger
.
debug
(
fn
->
"Sending
#{
activity
.
data
[
"id"
]
}
out via salmon"
end
)
...
...
lib/pleroma/web/websub/websub.ex
View file @
2e753e8c
...
...
@@ -204,4 +204,19 @@ def request_subscription(websub, poster \\ &@httpoison.post/3, timeout \\ 10_000
{
:error
,
websub
}
end
end
def
refresh_subscriptions
(
delta
\\
60
*
60
*
24
)
do
Logger
.
debug
(
"Refreshing subscriptions"
)
cut_off
=
NaiveDateTime
.
add
(
NaiveDateTime
.
utc_now
,
delta
)
query
=
from
sub
in
WebsubClientSubscription
,
where:
sub
.
valid_until
<
^
cut_off
and
sub
.
state
==
"active"
subs
=
Repo
.
all
(
query
)
Enum
.
map
(
subs
,
fn
(
sub
)
->
request_subscription
(
sub
)
end
)
end
end
test/web/websub/websub_test.exs
View file @
2e753e8c
...
...
@@ -7,7 +7,7 @@ def verify(sub) do
defmodule
Pleroma
.
Web
.
WebsubTest
do
use
Pleroma
.
DataCase
alias
Pleroma
.
Web
.
Websub
alias
Pleroma
.
Web
.
Websub
.
WebsubServerSubscription
alias
Pleroma
.
Web
.
Websub
.
{
WebsubServerSubscription
,
WebsubClientSubscription
}
import
Pleroma
.
Factory
alias
Pleroma
.
Web
.
Router
.
Helpers
...
...
@@ -174,4 +174,18 @@ test "sign a text" do
signed
=
Websub
.
sign
(
"secret"
,
[[
"て"
],
[
'す'
]])
end
describe
"renewing subscriptions"
do
test
"it renews subscriptions that have less than a day of time left"
do
day
=
60
*
60
*
24
now
=
NaiveDateTime
.
utc_now
still_good
=
insert
(
:websub_client_subscription
,
%{
valid_until:
NaiveDateTime
.
add
(
now
,
2
*
day
),
topic:
"http://example.org/still_good"
,
state:
"active"
})
needs_refresh
=
insert
(
:websub_client_subscription
,
%{
valid_until:
NaiveDateTime
.
add
(
now
,
day
-
100
),
topic:
"http://example.org/needs_refresh"
,
state:
"active"
})
refresh
=
Websub
.
refresh_subscriptions
()
assert
still_good
==
Repo
.
get
(
WebsubClientSubscription
,
still_good
.
id
)
refute
needs_refresh
==
Repo
.
get
(
WebsubClientSubscription
,
needs_refresh
.
id
)
end
end
end
Write
Preview
Markdown
is supported
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