diff options
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/actor.ts | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index a39b4e137..7494aadbb 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts | |||
@@ -212,7 +212,13 @@ function saveActorAndServerAndModelIfNotExist ( | |||
212 | 212 | ||
213 | // Force the actor creation, sometimes Sequelize skips the save() when it thinks the instance already exists | 213 | // Force the actor creation, sometimes Sequelize skips the save() when it thinks the instance already exists |
214 | // (which could be false in a retried query) | 214 | // (which could be false in a retried query) |
215 | const actorCreated = await ActorModel.create(actor.toJSON(), { transaction: t }) | 215 | const [ actorCreated ] = await ActorModel.findOrCreate({ |
216 | defaults: actor.toJSON(), | ||
217 | where: { | ||
218 | url: actor.url | ||
219 | }, | ||
220 | transaction: t | ||
221 | }) | ||
216 | 222 | ||
217 | if (actorCreated.type === 'Person' || actorCreated.type === 'Application') { | 223 | if (actorCreated.type === 'Person' || actorCreated.type === 'Application') { |
218 | const account = await saveAccount(actorCreated, result, t) | 224 | const account = await saveAccount(actorCreated, result, t) |
@@ -284,24 +290,36 @@ async function fetchRemoteActor (actorUrl: string): Promise<FetchRemoteActorResu | |||
284 | } | 290 | } |
285 | } | 291 | } |
286 | 292 | ||
287 | function saveAccount (actor: ActorModel, result: FetchRemoteActorResult, t: Transaction) { | 293 | async function saveAccount (actor: ActorModel, result: FetchRemoteActorResult, t: Transaction) { |
288 | const account = new AccountModel({ | 294 | const [ accountCreated ] = await AccountModel.findOrCreate({ |
289 | name: result.name, | 295 | defaults: { |
290 | actorId: actor.id | 296 | name: result.name, |
297 | actorId: actor.id | ||
298 | }, | ||
299 | where: { | ||
300 | actorId: actor.id | ||
301 | }, | ||
302 | transaction: t | ||
291 | }) | 303 | }) |
292 | 304 | ||
293 | return account.save({ transaction: t }) | 305 | return accountCreated |
294 | } | 306 | } |
295 | 307 | ||
296 | async function saveVideoChannel (actor: ActorModel, result: FetchRemoteActorResult, ownerActor: ActorModel, t: Transaction) { | 308 | async function saveVideoChannel (actor: ActorModel, result: FetchRemoteActorResult, ownerActor: ActorModel, t: Transaction) { |
297 | const videoChannel = new VideoChannelModel({ | 309 | const [ videoChannelCreated ] = await VideoChannelModel.findOrCreate({ |
298 | name: result.name, | 310 | defaults: { |
299 | description: result.summary, | 311 | name: result.name, |
300 | actorId: actor.id, | 312 | description: result.summary, |
301 | accountId: ownerActor.Account.id | 313 | actorId: actor.id, |
314 | accountId: ownerActor.Account.id | ||
315 | }, | ||
316 | where: { | ||
317 | actorId: actor.id | ||
318 | }, | ||
319 | transaction: t | ||
302 | }) | 320 | }) |
303 | 321 | ||
304 | return videoChannel.save({ transaction: t }) | 322 | return videoChannelCreated |
305 | } | 323 | } |
306 | 324 | ||
307 | async function refreshActorIfNeeded (actor: ActorModel) { | 325 | async function refreshActorIfNeeded (actor: ActorModel) { |