diff options
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/actor.ts | 19 | ||||
-rw-r--r-- | server/lib/activitypub/send/misc.ts | 9 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-accept.ts | 15 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-create.ts | 13 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-like.ts | 7 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-undo.ts | 7 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-update.ts | 10 | ||||
-rw-r--r-- | server/lib/activitypub/share.ts | 3 |
8 files changed, 47 insertions, 36 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index c3de4bdce..ff0a291e8 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts | |||
@@ -11,7 +11,7 @@ import { ActorModel } from '../../models/activitypub/actor' | |||
11 | import { ServerModel } from '../../models/server/server' | 11 | import { ServerModel } from '../../models/server/server' |
12 | import { VideoChannelModel } from '../../models/video/video-channel' | 12 | import { VideoChannelModel } from '../../models/video/video-channel' |
13 | 13 | ||
14 | // Set account keys, this could be long so process after the account creation and do not block the client | 14 | // Set account keys, this could be long so process after the account creation and do not block the client |
15 | function setAsyncActorKeys (actor: ActorModel) { | 15 | function setAsyncActorKeys (actor: ActorModel) { |
16 | return createPrivateAndPublicKeys() | 16 | return createPrivateAndPublicKeys() |
17 | .then(({ publicKey, privateKey }) => { | 17 | .then(({ publicKey, privateKey }) => { |
@@ -107,7 +107,7 @@ function saveActorAndServerAndModelIfNotExist ( | |||
107 | 107 | ||
108 | type FetchRemoteActorResult = { | 108 | type FetchRemoteActorResult = { |
109 | actor: ActorModel | 109 | actor: ActorModel |
110 | preferredUsername: string | 110 | name: string |
111 | summary: string | 111 | summary: string |
112 | attributedTo: ActivityPubAttributedTo[] | 112 | attributedTo: ActivityPubAttributedTo[] |
113 | } | 113 | } |
@@ -142,8 +142,8 @@ async function fetchRemoteActor (actorUrl: string): Promise<FetchRemoteActorResu | |||
142 | const actor = new ActorModel({ | 142 | const actor = new ActorModel({ |
143 | type: actorJSON.type, | 143 | type: actorJSON.type, |
144 | uuid: actorJSON.uuid, | 144 | uuid: actorJSON.uuid, |
145 | name: actorJSON.name, | 145 | preferredUsername: actorJSON.preferredUsername, |
146 | url: actorJSON.url, | 146 | url: actorJSON.id, |
147 | publicKey: actorJSON.publicKey.publicKeyPem, | 147 | publicKey: actorJSON.publicKey.publicKeyPem, |
148 | privateKey: null, | 148 | privateKey: null, |
149 | followersCount: followersCount, | 149 | followersCount: followersCount, |
@@ -155,19 +155,20 @@ async function fetchRemoteActor (actorUrl: string): Promise<FetchRemoteActorResu | |||
155 | followingUrl: actorJSON.following | 155 | followingUrl: actorJSON.following |
156 | }) | 156 | }) |
157 | 157 | ||
158 | const name = actorJSON.name || actorJSON.preferredUsername | ||
158 | return { | 159 | return { |
159 | actor, | 160 | actor, |
160 | preferredUsername: actorJSON.preferredUsername, | 161 | name, |
161 | summary: actorJSON.summary, | 162 | summary: actorJSON.summary, |
162 | attributedTo: actorJSON.attributedTo | 163 | attributedTo: actorJSON.attributedTo |
163 | } | 164 | } |
164 | } | 165 | } |
165 | 166 | ||
166 | function buildActorInstance (type: ActivityPubActorType, url: string, name: string, uuid?: string) { | 167 | function buildActorInstance (type: ActivityPubActorType, url: string, preferredUsername: string, uuid?: string) { |
167 | return new ActorModel({ | 168 | return new ActorModel({ |
168 | type, | 169 | type, |
169 | url, | 170 | url, |
170 | name, | 171 | preferredUsername, |
171 | uuid, | 172 | uuid, |
172 | publicKey: null, | 173 | publicKey: null, |
173 | privateKey: null, | 174 | privateKey: null, |
@@ -210,7 +211,7 @@ async function fetchActorTotalItems (url: string) { | |||
210 | 211 | ||
211 | function saveAccount (actor: ActorModel, result: FetchRemoteActorResult, t: Transaction) { | 212 | function saveAccount (actor: ActorModel, result: FetchRemoteActorResult, t: Transaction) { |
212 | const account = new AccountModel({ | 213 | const account = new AccountModel({ |
213 | name: result.preferredUsername, | 214 | name: result.name, |
214 | actorId: actor.id | 215 | actorId: actor.id |
215 | }) | 216 | }) |
216 | 217 | ||
@@ -219,7 +220,7 @@ function saveAccount (actor: ActorModel, result: FetchRemoteActorResult, t: Tran | |||
219 | 220 | ||
220 | async function saveVideoChannel (actor: ActorModel, result: FetchRemoteActorResult, ownerActor: ActorModel, t: Transaction) { | 221 | async function saveVideoChannel (actor: ActorModel, result: FetchRemoteActorResult, ownerActor: ActorModel, t: Transaction) { |
221 | const videoChannel = new VideoChannelModel({ | 222 | const videoChannel = new VideoChannelModel({ |
222 | name: result.preferredUsername, | 223 | name: result.name, |
223 | description: result.summary, | 224 | description: result.summary, |
224 | actorId: actor.id, | 225 | actorId: actor.id, |
225 | accountId: ownerActor.Account.id | 226 | accountId: ownerActor.Account.id |
diff --git a/server/lib/activitypub/send/misc.ts b/server/lib/activitypub/send/misc.ts index 14101e630..2dc8d3d59 100644 --- a/server/lib/activitypub/send/misc.ts +++ b/server/lib/activitypub/send/misc.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { Activity } from '../../../../shared/models/activitypub' | 2 | import { Activity, ActivityAudience } from '../../../../shared/models/activitypub' |
3 | import { logger } from '../../../helpers' | 3 | import { logger } from '../../../helpers' |
4 | import { ACTIVITY_PUB } from '../../../initializers' | 4 | import { ACTIVITY_PUB } from '../../../initializers' |
5 | import { ActorModel } from '../../../models/activitypub/actor' | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
@@ -116,6 +116,10 @@ async function getAudience (actorSender: ActorModel, t: Transaction, isPublic = | |||
116 | return { to, cc } | 116 | return { to, cc } |
117 | } | 117 | } |
118 | 118 | ||
119 | function audiencify (object: any, audience: ActivityAudience) { | ||
120 | return Object.assign(object, audience) | ||
121 | } | ||
122 | |||
119 | async function computeFollowerUris (toActorFollower: ActorModel[], followersException: ActorModel[], t: Transaction) { | 123 | async function computeFollowerUris (toActorFollower: ActorModel[], followersException: ActorModel[], t: Transaction) { |
120 | const toActorFollowerIds = toActorFollower.map(a => a.id) | 124 | const toActorFollowerIds = toActorFollower.map(a => a.id) |
121 | 125 | ||
@@ -133,5 +137,6 @@ export { | |||
133 | getOriginVideoAudience, | 137 | getOriginVideoAudience, |
134 | getActorsInvolvedInVideo, | 138 | getActorsInvolvedInVideo, |
135 | getObjectFollowersAudience, | 139 | getObjectFollowersAudience, |
136 | forwardActivity | 140 | forwardActivity, |
141 | audiencify | ||
137 | } | 142 | } |
diff --git a/server/lib/activitypub/send/send-accept.ts b/server/lib/activitypub/send/send-accept.ts index 7579884a7..4eaa329d9 100644 --- a/server/lib/activitypub/send/send-accept.ts +++ b/server/lib/activitypub/send/send-accept.ts | |||
@@ -1,16 +1,20 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityAccept } from '../../../../shared/models/activitypub' | 2 | import { ActivityAccept, ActivityFollow } from '../../../../shared/models/activitypub' |
3 | import { ActorModel } from '../../../models/activitypub/actor' | 3 | import { ActorModel } from '../../../models/activitypub/actor' |
4 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 4 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
5 | import { getActorFollowAcceptActivityPubUrl } from '../url' | 5 | import { getActorFollowAcceptActivityPubUrl, getActorFollowActivityPubUrl } from '../url' |
6 | import { unicastTo } from './misc' | 6 | import { unicastTo } from './misc' |
7 | import { followActivityData } from './send-follow' | ||
7 | 8 | ||
8 | async function sendAccept (actorFollow: ActorFollowModel, t: Transaction) { | 9 | async function sendAccept (actorFollow: ActorFollowModel, t: Transaction) { |
9 | const follower = actorFollow.ActorFollower | 10 | const follower = actorFollow.ActorFollower |
10 | const me = actorFollow.ActorFollowing | 11 | const me = actorFollow.ActorFollowing |
11 | 12 | ||
13 | const followUrl = getActorFollowActivityPubUrl(actorFollow) | ||
14 | const followData = followActivityData(followUrl, follower, me) | ||
15 | |||
12 | const url = getActorFollowAcceptActivityPubUrl(actorFollow) | 16 | const url = getActorFollowAcceptActivityPubUrl(actorFollow) |
13 | const data = acceptActivityData(url, me) | 17 | const data = acceptActivityData(url, me, followData) |
14 | 18 | ||
15 | return unicastTo(data, me, follower.inboxUrl, t) | 19 | return unicastTo(data, me, follower.inboxUrl, t) |
16 | } | 20 | } |
@@ -23,10 +27,11 @@ export { | |||
23 | 27 | ||
24 | // --------------------------------------------------------------------------- | 28 | // --------------------------------------------------------------------------- |
25 | 29 | ||
26 | function acceptActivityData (url: string, byActor: ActorModel): ActivityAccept { | 30 | function acceptActivityData (url: string, byActor: ActorModel, followActivityData: ActivityFollow): ActivityAccept { |
27 | return { | 31 | return { |
28 | type: 'Accept', | 32 | type: 'Accept', |
29 | id: url, | 33 | id: url, |
30 | actor: byActor.url | 34 | actor: byActor.url, |
35 | object: followActivityData | ||
31 | } | 36 | } |
32 | } | 37 | } |
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index d26c24838..249dd91dc 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts | |||
@@ -7,6 +7,7 @@ import { VideoModel } from '../../../models/video/video' | |||
7 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | 7 | import { VideoAbuseModel } from '../../../models/video/video-abuse' |
8 | import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' | 8 | import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' |
9 | import { | 9 | import { |
10 | audiencify, | ||
10 | broadcastToFollowers, | 11 | broadcastToFollowers, |
11 | getActorsInvolvedInVideo, | 12 | getActorsInvolvedInVideo, |
12 | getAudience, | 13 | getAudience, |
@@ -16,9 +17,11 @@ import { | |||
16 | } from './misc' | 17 | } from './misc' |
17 | 18 | ||
18 | async function sendCreateVideo (video: VideoModel, t: Transaction) { | 19 | async function sendCreateVideo (video: VideoModel, t: Transaction) { |
19 | const byActor = video.VideoChannel.Account.Actor | 20 | if (video.privacy === VideoPrivacy.PRIVATE) return |
20 | 21 | ||
22 | const byActor = video.VideoChannel.Account.Actor | ||
21 | const videoObject = video.toActivityPubObject() | 23 | const videoObject = video.toActivityPubObject() |
24 | |||
22 | const audience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC) | 25 | const audience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC) |
23 | const data = await createActivityData(video.url, byActor, videoObject, t, audience) | 26 | const data = await createActivityData(video.url, byActor, videoObject, t, audience) |
24 | 27 | ||
@@ -93,14 +96,12 @@ async function createActivityData ( | |||
93 | audience = await getAudience(byActor, t) | 96 | audience = await getAudience(byActor, t) |
94 | } | 97 | } |
95 | 98 | ||
96 | return { | 99 | return audiencify({ |
97 | type: 'Create', | 100 | type: 'Create', |
98 | id: url, | 101 | id: url, |
99 | actor: byActor.url, | 102 | actor: byActor.url, |
100 | to: audience.to, | 103 | object: audiencify(object, audience) |
101 | cc: audience.cc, | 104 | }, audience) |
102 | object | ||
103 | } | ||
104 | } | 105 | } |
105 | 106 | ||
106 | function createDislikeActivityData (byActor: ActorModel, video: VideoModel) { | 107 | function createDislikeActivityData (byActor: ActorModel, video: VideoModel) { |
diff --git a/server/lib/activitypub/send/send-like.ts b/server/lib/activitypub/send/send-like.ts index 7e0c73796..743646455 100644 --- a/server/lib/activitypub/send/send-like.ts +++ b/server/lib/activitypub/send/send-like.ts | |||
@@ -4,6 +4,7 @@ import { ActorModel } from '../../../models/activitypub/actor' | |||
4 | import { VideoModel } from '../../../models/video/video' | 4 | import { VideoModel } from '../../../models/video/video' |
5 | import { getVideoLikeActivityPubUrl } from '../url' | 5 | import { getVideoLikeActivityPubUrl } from '../url' |
6 | import { | 6 | import { |
7 | audiencify, | ||
7 | broadcastToFollowers, | 8 | broadcastToFollowers, |
8 | getActorsInvolvedInVideo, | 9 | getActorsInvolvedInVideo, |
9 | getAudience, | 10 | getAudience, |
@@ -44,14 +45,12 @@ async function likeActivityData ( | |||
44 | audience = await getAudience(byActor, t) | 45 | audience = await getAudience(byActor, t) |
45 | } | 46 | } |
46 | 47 | ||
47 | return { | 48 | return audiencify({ |
48 | type: 'Like', | 49 | type: 'Like', |
49 | id: url, | 50 | id: url, |
50 | actor: byActor.url, | 51 | actor: byActor.url, |
51 | to: audience.to, | ||
52 | cc: audience.cc, | ||
53 | object: video.url | 52 | object: video.url |
54 | } | 53 | }, audience) |
55 | } | 54 | } |
56 | 55 | ||
57 | // --------------------------------------------------------------------------- | 56 | // --------------------------------------------------------------------------- |
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index 92271b700..3a0597fba 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts | |||
@@ -11,6 +11,7 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | |||
11 | import { VideoModel } from '../../../models/video/video' | 11 | import { VideoModel } from '../../../models/video/video' |
12 | import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' | 12 | import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' |
13 | import { | 13 | import { |
14 | audiencify, | ||
14 | broadcastToFollowers, | 15 | broadcastToFollowers, |
15 | getActorsInvolvedInVideo, | 16 | getActorsInvolvedInVideo, |
16 | getAudience, | 17 | getAudience, |
@@ -112,12 +113,10 @@ async function undoActivityData ( | |||
112 | audience = await getAudience(byActor, t) | 113 | audience = await getAudience(byActor, t) |
113 | } | 114 | } |
114 | 115 | ||
115 | return { | 116 | return audiencify({ |
116 | type: 'Undo', | 117 | type: 'Undo', |
117 | id: url, | 118 | id: url, |
118 | actor: byActor.url, | 119 | actor: byActor.url, |
119 | to: audience.to, | ||
120 | cc: audience.cc, | ||
121 | object | 120 | object |
122 | } | 121 | }, audience) |
123 | } | 122 | } |
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts index 48bbbcac1..b623fec6c 100644 --- a/server/lib/activitypub/send/send-update.ts +++ b/server/lib/activitypub/send/send-update.ts | |||
@@ -5,7 +5,7 @@ import { ActorModel } from '../../../models/activitypub/actor' | |||
5 | import { VideoModel } from '../../../models/video/video' | 5 | import { VideoModel } from '../../../models/video/video' |
6 | import { VideoShareModel } from '../../../models/video/video-share' | 6 | import { VideoShareModel } from '../../../models/video/video-share' |
7 | import { getUpdateActivityPubUrl } from '../url' | 7 | import { getUpdateActivityPubUrl } from '../url' |
8 | import { broadcastToFollowers, getAudience } from './misc' | 8 | import { audiencify, broadcastToFollowers, getAudience } from './misc' |
9 | 9 | ||
10 | async function sendUpdateVideo (video: VideoModel, t: Transaction) { | 10 | async function sendUpdateVideo (video: VideoModel, t: Transaction) { |
11 | const byActor = video.VideoChannel.Account.Actor | 11 | const byActor = video.VideoChannel.Account.Actor |
@@ -41,12 +41,10 @@ async function updateActivityData ( | |||
41 | audience = await getAudience(byActor, t) | 41 | audience = await getAudience(byActor, t) |
42 | } | 42 | } |
43 | 43 | ||
44 | return { | 44 | return audiencify({ |
45 | type: 'Update', | 45 | type: 'Update', |
46 | id: url, | 46 | id: url, |
47 | actor: byActor.url, | 47 | actor: byActor.url, |
48 | to: audience.to, | 48 | object: audiencify(object, audience) |
49 | cc: audience.cc, | 49 | }, audience) |
50 | object | ||
51 | } | ||
52 | } | 50 | } |
diff --git a/server/lib/activitypub/share.ts b/server/lib/activitypub/share.ts index fb01368ec..386ae362a 100644 --- a/server/lib/activitypub/share.ts +++ b/server/lib/activitypub/share.ts | |||
@@ -1,10 +1,13 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { VideoPrivacy } from '../../../shared/models/videos' | ||
2 | import { getServerActor } from '../../helpers' | 3 | import { getServerActor } from '../../helpers' |
3 | import { VideoModel } from '../../models/video/video' | 4 | import { VideoModel } from '../../models/video/video' |
4 | import { VideoShareModel } from '../../models/video/video-share' | 5 | import { VideoShareModel } from '../../models/video/video-share' |
5 | import { sendVideoAnnounceToFollowers } from './send' | 6 | import { sendVideoAnnounceToFollowers } from './send' |
6 | 7 | ||
7 | async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) { | 8 | async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) { |
9 | if (video.privacy === VideoPrivacy.PRIVATE) return | ||
10 | |||
8 | const serverActor = await getServerActor() | 11 | const serverActor = await getServerActor() |
9 | 12 | ||
10 | const serverShare = VideoShareModel.create({ | 13 | const serverShare = VideoShareModel.create({ |