diff options
author | Chocobozzz <me@florianbigard.com> | 2022-04-06 08:50:43 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2022-04-15 09:49:35 +0200 |
commit | ac907dc7c158056e9b6a5cb58acd27df5c7c2670 (patch) | |
tree | f9d8bff22e0543a305c64e1a1808c0df6d512f1e /server/lib/activitypub | |
parent | dfbcefc20dc64f0814b1f2e8e782a4ea1bd24db2 (diff) | |
download | PeerTube-ac907dc7c158056e9b6a5cb58acd27df5c7c2670.tar.gz PeerTube-ac907dc7c158056e9b6a5cb58acd27df5c7c2670.tar.zst PeerTube-ac907dc7c158056e9b6a5cb58acd27df5c7c2670.zip |
Improve viewer counter
More precise, avoid weird decrease, reuse an id to federate viewers
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/process/process-view.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-view.ts | 5 | ||||
-rw-r--r-- | server/lib/activitypub/url.ts | 4 |
3 files changed, 6 insertions, 5 deletions
diff --git a/server/lib/activitypub/process/process-view.ts b/server/lib/activitypub/process/process-view.ts index bad079843..e49506d82 100644 --- a/server/lib/activitypub/process/process-view.ts +++ b/server/lib/activitypub/process/process-view.ts | |||
@@ -32,7 +32,7 @@ async function processCreateView (activity: ActivityView, byActor: MActorSignatu | |||
32 | ? new Date(activity.expires) | 32 | ? new Date(activity.expires) |
33 | : undefined | 33 | : undefined |
34 | 34 | ||
35 | await VideoViewsManager.Instance.processRemoteView({ video, viewerExpires }) | 35 | await VideoViewsManager.Instance.processRemoteView({ video, viewerId: activity.id, viewerExpires }) |
36 | 36 | ||
37 | if (video.isOwned()) { | 37 | if (video.isOwned()) { |
38 | // Forward the view but don't resend the activity to the sender | 38 | // Forward the view but don't resend the activity to the sender |
diff --git a/server/lib/activitypub/send/send-view.ts b/server/lib/activitypub/send/send-view.ts index 1088bf258..25a20ec6d 100644 --- a/server/lib/activitypub/send/send-view.ts +++ b/server/lib/activitypub/send/send-view.ts | |||
@@ -13,14 +13,15 @@ async function sendView (options: { | |||
13 | byActor: MActorLight | 13 | byActor: MActorLight |
14 | type: ViewType | 14 | type: ViewType |
15 | video: MVideoImmutable | 15 | video: MVideoImmutable |
16 | viewerIdentifier: string | ||
16 | transaction?: Transaction | 17 | transaction?: Transaction |
17 | }) { | 18 | }) { |
18 | const { byActor, type, video, transaction } = options | 19 | const { byActor, type, video, viewerIdentifier, transaction } = options |
19 | 20 | ||
20 | logger.info('Creating job to send %s of %s.', type, video.url) | 21 | logger.info('Creating job to send %s of %s.', type, video.url) |
21 | 22 | ||
22 | const activityBuilder = (audience: ActivityAudience) => { | 23 | const activityBuilder = (audience: ActivityAudience) => { |
23 | const url = getLocalVideoViewActivityPubUrl(byActor, video) | 24 | const url = getLocalVideoViewActivityPubUrl(byActor, video, viewerIdentifier) |
24 | 25 | ||
25 | return buildViewActivity({ url, byActor, video, audience, type }) | 26 | return buildViewActivity({ url, byActor, video, audience, type }) |
26 | } | 27 | } |
diff --git a/server/lib/activitypub/url.ts b/server/lib/activitypub/url.ts index 8443fef4c..2f68f7a17 100644 --- a/server/lib/activitypub/url.ts +++ b/server/lib/activitypub/url.ts | |||
@@ -56,8 +56,8 @@ function getLocalAbuseActivityPubUrl (abuse: MAbuseId) { | |||
56 | return WEBSERVER.URL + '/admin/abuses/' + abuse.id | 56 | return WEBSERVER.URL + '/admin/abuses/' + abuse.id |
57 | } | 57 | } |
58 | 58 | ||
59 | function getLocalVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId) { | 59 | function getLocalVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId, viewerIdentifier: string) { |
60 | return byActor.url + '/views/videos/' + video.id + '/' + new Date().toISOString() | 60 | return byActor.url + '/views/videos/' + video.id + '/' + viewerIdentifier |
61 | } | 61 | } |
62 | 62 | ||
63 | function getLocalVideoViewerActivityPubUrl (stats: MLocalVideoViewer) { | 63 | function getLocalVideoViewerActivityPubUrl (stats: MLocalVideoViewer) { |