diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-24 13:41:10 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:53 +0100 |
commit | 63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd (patch) | |
tree | 3ee4b351025d4b19f6e880754df44fa7605b683d /server/lib/activitypub/send/send-create.ts | |
parent | d4f1e94c89336255537b0b82913591f00e716201 (diff) | |
download | PeerTube-63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd.tar.gz PeerTube-63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd.tar.zst PeerTube-63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd.zip |
Correctly forward like/dislikes and undo
Diffstat (limited to 'server/lib/activitypub/send/send-create.ts')
-rw-r--r-- | server/lib/activitypub/send/send-create.ts | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index 6afe67ee6..113d89233 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts | |||
@@ -1,12 +1,12 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityCreate } from '../../../../shared/models/activitypub/activity' | 2 | import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub/activity' |
3 | import { getServerAccount } from '../../../helpers/utils' | 3 | import { getServerAccount } from '../../../helpers/utils' |
4 | import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models' | 4 | import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models' |
5 | import { VideoAbuseInstance } from '../../../models/video/video-abuse-interface' | 5 | import { VideoAbuseInstance } from '../../../models/video/video-abuse-interface' |
6 | import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' | 6 | import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' |
7 | import { | 7 | import { |
8 | broadcastToFollowers, | 8 | broadcastToFollowers, |
9 | getAccountsToForwardVideoAction, | 9 | getAccountsInvolvedInVideo, |
10 | getAudience, | 10 | getAudience, |
11 | getOriginVideoAudience, | 11 | getOriginVideoAudience, |
12 | getVideoFollowersAudience, | 12 | getVideoFollowersAudience, |
@@ -35,7 +35,8 @@ async function sendCreateViewToOrigin (byAccount: AccountInstance, video: VideoI | |||
35 | const url = getVideoViewActivityPubUrl(byAccount, video) | 35 | const url = getVideoViewActivityPubUrl(byAccount, video) |
36 | const viewActivity = createViewActivityData(byAccount, video) | 36 | const viewActivity = createViewActivityData(byAccount, video) |
37 | 37 | ||
38 | const audience = getOriginVideoAudience(video) | 38 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video) |
39 | const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) | ||
39 | const data = await createActivityData(url, byAccount, viewActivity, audience) | 40 | const data = await createActivityData(url, byAccount, viewActivity, audience) |
40 | 41 | ||
41 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | 42 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) |
@@ -45,12 +46,12 @@ async function sendCreateViewToVideoFollowers (byAccount: AccountInstance, video | |||
45 | const url = getVideoViewActivityPubUrl(byAccount, video) | 46 | const url = getVideoViewActivityPubUrl(byAccount, video) |
46 | const viewActivity = createViewActivityData(byAccount, video) | 47 | const viewActivity = createViewActivityData(byAccount, video) |
47 | 48 | ||
48 | const audience = getVideoFollowersAudience(video) | 49 | const accountsToForwardView = await getAccountsInvolvedInVideo(video) |
50 | const audience = getVideoFollowersAudience(accountsToForwardView) | ||
49 | const data = await createActivityData(url, byAccount, viewActivity, audience) | 51 | const data = await createActivityData(url, byAccount, viewActivity, audience) |
50 | 52 | ||
53 | // Use the server account to send the view, because it could be an unregistered account | ||
51 | const serverAccount = await getServerAccount() | 54 | const serverAccount = await getServerAccount() |
52 | const accountsToForwardView = await getAccountsToForwardVideoAction(byAccount, video) | ||
53 | |||
54 | const followersException = [ byAccount ] | 55 | const followersException = [ byAccount ] |
55 | return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException) | 56 | return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException) |
56 | } | 57 | } |
@@ -59,7 +60,8 @@ async function sendCreateDislikeToOrigin (byAccount: AccountInstance, video: Vid | |||
59 | const url = getVideoDislikeActivityPubUrl(byAccount, video) | 60 | const url = getVideoDislikeActivityPubUrl(byAccount, video) |
60 | const dislikeActivity = createDislikeActivityData(byAccount, video) | 61 | const dislikeActivity = createDislikeActivityData(byAccount, video) |
61 | 62 | ||
62 | const audience = getOriginVideoAudience(video) | 63 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video) |
64 | const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) | ||
63 | const data = await createActivityData(url, byAccount, dislikeActivity, audience) | 65 | const data = await createActivityData(url, byAccount, dislikeActivity, audience) |
64 | 66 | ||
65 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | 67 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) |
@@ -69,17 +71,15 @@ async function sendCreateDislikeToVideoFollowers (byAccount: AccountInstance, vi | |||
69 | const url = getVideoDislikeActivityPubUrl(byAccount, video) | 71 | const url = getVideoDislikeActivityPubUrl(byAccount, video) |
70 | const dislikeActivity = createDislikeActivityData(byAccount, video) | 72 | const dislikeActivity = createDislikeActivityData(byAccount, video) |
71 | 73 | ||
72 | const audience = getVideoFollowersAudience(video) | 74 | const accountsToForwardView = await getAccountsInvolvedInVideo(video) |
75 | const audience = getVideoFollowersAudience(accountsToForwardView) | ||
73 | const data = await createActivityData(url, byAccount, dislikeActivity, audience) | 76 | const data = await createActivityData(url, byAccount, dislikeActivity, audience) |
74 | 77 | ||
75 | const accountsToForwardView = await getAccountsToForwardVideoAction(byAccount, video) | ||
76 | const serverAccount = await getServerAccount() | ||
77 | |||
78 | const followersException = [ byAccount ] | 78 | const followersException = [ byAccount ] |
79 | return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException) | 79 | return broadcastToFollowers(data, byAccount, accountsToForwardView, t, followersException) |
80 | } | 80 | } |
81 | 81 | ||
82 | async function createActivityData (url: string, byAccount: AccountInstance, object: any, audience?: { to: string[], cc: string[] }) { | 82 | async function createActivityData (url: string, byAccount: AccountInstance, object: any, audience?: ActivityAudience) { |
83 | if (!audience) { | 83 | if (!audience) { |
84 | audience = await getAudience(byAccount) | 84 | audience = await getAudience(byAccount) |
85 | } | 85 | } |