From ac907dc7c158056e9b6a5cb58acd27df5c7c2670 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 6 Apr 2022 08:50:43 +0200 Subject: Improve viewer counter More precise, avoid weird decrease, reuse an id to federate viewers --- server/lib/activitypub/process/process-view.ts | 2 +- server/lib/activitypub/send/send-view.ts | 5 +++-- server/lib/activitypub/url.ts | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) (limited to 'server/lib/activitypub') 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 ? new Date(activity.expires) : undefined - await VideoViewsManager.Instance.processRemoteView({ video, viewerExpires }) + await VideoViewsManager.Instance.processRemoteView({ video, viewerId: activity.id, viewerExpires }) if (video.isOwned()) { // 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: { byActor: MActorLight type: ViewType video: MVideoImmutable + viewerIdentifier: string transaction?: Transaction }) { - const { byActor, type, video, transaction } = options + const { byActor, type, video, viewerIdentifier, transaction } = options logger.info('Creating job to send %s of %s.', type, video.url) const activityBuilder = (audience: ActivityAudience) => { - const url = getLocalVideoViewActivityPubUrl(byActor, video) + const url = getLocalVideoViewActivityPubUrl(byActor, video, viewerIdentifier) return buildViewActivity({ url, byActor, video, audience, type }) } 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) { return WEBSERVER.URL + '/admin/abuses/' + abuse.id } -function getLocalVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId) { - return byActor.url + '/views/videos/' + video.id + '/' + new Date().toISOString() +function getLocalVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId, viewerIdentifier: string) { + return byActor.url + '/views/videos/' + video.id + '/' + viewerIdentifier } function getLocalVideoViewerActivityPubUrl (stats: MLocalVideoViewer) { -- cgit v1.2.3