diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-18 11:17:35 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-03-18 11:21:50 +0100 |
commit | 57e4e1c1a95c3a81a967f54ecc2a510d8b0e129c (patch) | |
tree | fcf12670d643ec4a3b5eccdfa834227c0417d988 /server/lib/activitypub/process/process-undo.ts | |
parent | 2e3f7a5a6fbae276d3ba1cb1b08289917ec7604b (diff) | |
download | PeerTube-57e4e1c1a95c3a81a967f54ecc2a510d8b0e129c.tar.gz PeerTube-57e4e1c1a95c3a81a967f54ecc2a510d8b0e129c.tar.zst PeerTube-57e4e1c1a95c3a81a967f54ecc2a510d8b0e129c.zip |
Don't store remote rates of remote videos
In the future we'll stop to expose all available rates to improve users
privacy
Diffstat (limited to 'server/lib/activitypub/process/process-undo.ts')
-rw-r--r-- | server/lib/activitypub/process/process-undo.ts | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts index d4b2a795f..257eb6c2b 100644 --- a/server/lib/activitypub/process/process-undo.ts +++ b/server/lib/activitypub/process/process-undo.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import { VideoModel } from '@server/models/video/video' | ||
1 | import { ActivityAnnounce, ActivityFollow, ActivityLike, ActivityUndo, CacheFileObject } from '../../../../shared/models/activitypub' | 2 | import { ActivityAnnounce, ActivityFollow, ActivityLike, ActivityUndo, CacheFileObject } from '../../../../shared/models/activitypub' |
2 | import { DislikeObject } from '../../../../shared/models/activitypub/objects' | 3 | import { DislikeObject } from '../../../../shared/models/activitypub/objects' |
3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
@@ -10,8 +11,8 @@ import { VideoRedundancyModel } from '../../../models/redundancy/video-redundanc | |||
10 | import { VideoShareModel } from '../../../models/video/video-share' | 11 | import { VideoShareModel } from '../../../models/video/video-share' |
11 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' | 12 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' |
12 | import { MActorSignature } from '../../../types/models' | 13 | import { MActorSignature } from '../../../types/models' |
13 | import { forwardVideoRelatedActivity } from '../send/utils' | 14 | import { forwardVideoRelatedActivity } from '../send/shared/send-utils' |
14 | import { getOrCreateAPVideo } from '../videos' | 15 | import { federateVideoIfNeeded, getOrCreateAPVideo } from '../videos' |
15 | 16 | ||
16 | async function processUndoActivity (options: APProcessorOptions<ActivityUndo>) { | 17 | async function processUndoActivity (options: APProcessorOptions<ActivityUndo>) { |
17 | const { activity, byActor } = options | 18 | const { activity, byActor } = options |
@@ -55,23 +56,22 @@ export { | |||
55 | async function processUndoLike (byActor: MActorSignature, activity: ActivityUndo) { | 56 | async function processUndoLike (byActor: MActorSignature, activity: ActivityUndo) { |
56 | const likeActivity = activity.object as ActivityLike | 57 | const likeActivity = activity.object as ActivityLike |
57 | 58 | ||
58 | const { video } = await getOrCreateAPVideo({ videoObject: likeActivity.object }) | 59 | const { video: onlyVideo } = await getOrCreateAPVideo({ videoObject: likeActivity.object }) |
60 | // We don't care about likes of remote videos | ||
61 | if (!onlyVideo.isOwned()) return | ||
59 | 62 | ||
60 | return sequelizeTypescript.transaction(async t => { | 63 | return sequelizeTypescript.transaction(async t => { |
61 | if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) | 64 | if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) |
62 | 65 | ||
66 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(onlyVideo.id, t) | ||
63 | const rate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byActor.Account.id, video.id, likeActivity.id, t) | 67 | const rate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byActor.Account.id, video.id, likeActivity.id, t) |
64 | if (!rate || rate.type !== 'like') throw new Error(`Unknown like by account ${byActor.Account.id} for video ${video.id}.`) | 68 | if (!rate || rate.type !== 'like') throw new Error(`Unknown like by account ${byActor.Account.id} for video ${video.id}.`) |
65 | 69 | ||
66 | await rate.destroy({ transaction: t }) | 70 | await rate.destroy({ transaction: t }) |
67 | await video.decrement('likes', { transaction: t }) | 71 | await video.decrement('likes', { transaction: t }) |
68 | 72 | ||
69 | if (video.isOwned()) { | 73 | video.likes-- |
70 | // Don't resend the activity to the sender | 74 | await federateVideoIfNeeded(video, false, t) |
71 | const exceptions = [ byActor ] | ||
72 | |||
73 | await forwardVideoRelatedActivity(activity, t, exceptions, video) | ||
74 | } | ||
75 | }) | 75 | }) |
76 | } | 76 | } |
77 | 77 | ||
@@ -80,26 +80,27 @@ async function processUndoDislike (byActor: MActorSignature, activity: ActivityU | |||
80 | ? activity.object | 80 | ? activity.object |
81 | : activity.object.object as DislikeObject | 81 | : activity.object.object as DislikeObject |
82 | 82 | ||
83 | const { video } = await getOrCreateAPVideo({ videoObject: dislike.object }) | 83 | const { video: onlyVideo } = await getOrCreateAPVideo({ videoObject: dislike.object }) |
84 | // We don't care about likes of remote videos | ||
85 | if (!onlyVideo.isOwned()) return | ||
84 | 86 | ||
85 | return sequelizeTypescript.transaction(async t => { | 87 | return sequelizeTypescript.transaction(async t => { |
86 | if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) | 88 | if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) |
87 | 89 | ||
90 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(onlyVideo.id, t) | ||
88 | const rate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byActor.Account.id, video.id, dislike.id, t) | 91 | const rate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byActor.Account.id, video.id, dislike.id, t) |
89 | if (!rate || rate.type !== 'dislike') throw new Error(`Unknown dislike by account ${byActor.Account.id} for video ${video.id}.`) | 92 | if (!rate || rate.type !== 'dislike') throw new Error(`Unknown dislike by account ${byActor.Account.id} for video ${video.id}.`) |
90 | 93 | ||
91 | await rate.destroy({ transaction: t }) | 94 | await rate.destroy({ transaction: t }) |
92 | await video.decrement('dislikes', { transaction: t }) | 95 | await video.decrement('dislikes', { transaction: t }) |
96 | video.dislikes-- | ||
93 | 97 | ||
94 | if (video.isOwned()) { | 98 | await federateVideoIfNeeded(video, false, t) |
95 | // Don't resend the activity to the sender | ||
96 | const exceptions = [ byActor ] | ||
97 | |||
98 | await forwardVideoRelatedActivity(activity, t, exceptions, video) | ||
99 | } | ||
100 | }) | 99 | }) |
101 | } | 100 | } |
102 | 101 | ||
102 | // --------------------------------------------------------------------------- | ||
103 | |||
103 | async function processUndoCacheFile (byActor: MActorSignature, activity: ActivityUndo) { | 104 | async function processUndoCacheFile (byActor: MActorSignature, activity: ActivityUndo) { |
104 | const cacheFileObject = activity.object.object as CacheFileObject | 105 | const cacheFileObject = activity.object.object as CacheFileObject |
105 | 106 | ||
@@ -125,19 +126,6 @@ async function processUndoCacheFile (byActor: MActorSignature, activity: Activit | |||
125 | }) | 126 | }) |
126 | } | 127 | } |
127 | 128 | ||
128 | function processUndoFollow (follower: MActorSignature, followActivity: ActivityFollow) { | ||
129 | return sequelizeTypescript.transaction(async t => { | ||
130 | const following = await ActorModel.loadByUrlAndPopulateAccountAndChannel(followActivity.object, t) | ||
131 | const actorFollow = await ActorFollowModel.loadByActorAndTarget(follower.id, following.id, t) | ||
132 | |||
133 | if (!actorFollow) throw new Error(`'Unknown actor follow ${follower.id} -> ${following.id}.`) | ||
134 | |||
135 | await actorFollow.destroy({ transaction: t }) | ||
136 | |||
137 | return undefined | ||
138 | }) | ||
139 | } | ||
140 | |||
141 | function processUndoAnnounce (byActor: MActorSignature, announceActivity: ActivityAnnounce) { | 129 | function processUndoAnnounce (byActor: MActorSignature, announceActivity: ActivityAnnounce) { |
142 | return sequelizeTypescript.transaction(async t => { | 130 | return sequelizeTypescript.transaction(async t => { |
143 | const share = await VideoShareModel.loadByUrl(announceActivity.id, t) | 131 | const share = await VideoShareModel.loadByUrl(announceActivity.id, t) |
@@ -155,3 +143,18 @@ function processUndoAnnounce (byActor: MActorSignature, announceActivity: Activi | |||
155 | } | 143 | } |
156 | }) | 144 | }) |
157 | } | 145 | } |
146 | |||
147 | // --------------------------------------------------------------------------- | ||
148 | |||
149 | function processUndoFollow (follower: MActorSignature, followActivity: ActivityFollow) { | ||
150 | return sequelizeTypescript.transaction(async t => { | ||
151 | const following = await ActorModel.loadByUrlAndPopulateAccountAndChannel(followActivity.object, t) | ||
152 | const actorFollow = await ActorFollowModel.loadByActorAndTarget(follower.id, following.id, t) | ||
153 | |||
154 | if (!actorFollow) throw new Error(`'Unknown actor follow ${follower.id} -> ${following.id}.`) | ||
155 | |||
156 | await actorFollow.destroy({ transaction: t }) | ||
157 | |||
158 | return undefined | ||
159 | }) | ||
160 | } | ||