- return Promise.all([
- ActorModel.rebuildFollowsCount(instance.actorId, 'following', options.transaction),
- ActorModel.rebuildFollowsCount(instance.targetActorId, 'followers', options.transaction)
- ])
+ return afterCommitIfTransaction(options.transaction, () => {
+ return Promise.all([
+ ActorModel.rebuildFollowsCount(instance.actorId, 'following'),
+ ActorModel.rebuildFollowsCount(instance.targetActorId, 'followers')
+ ])
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
+ static getSQLAttributes (tableName: string, aliasPrefix = '') {
+ return buildSQLAttributes({
+ model: this,
+ tableName,
+ aliasPrefix
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
+ /*
+ * @deprecated Use `findOrCreateCustom` instead
+ */
+ static findOrCreate (): any {
+ throw new Error('Must not be called')
+ }
+
+ // findOrCreate has issues with actor follow hooks
+ static async findOrCreateCustom (options: {
+ byActor: MActor
+ targetActor: MActor
+ activityId: string
+ state: FollowState
+ transaction: Transaction
+ }): Promise<[ MActorFollowActors, boolean ]> {
+ const { byActor, targetActor, activityId, state, transaction } = options
+
+ let created = false
+ let actorFollow: MActorFollowActors = await ActorFollowModel.loadByActorAndTarget(byActor.id, targetActor.id, transaction)
+
+ if (!actorFollow) {
+ created = true
+
+ actorFollow = await ActorFollowModel.create({
+ actorId: byActor.id,
+ targetActorId: targetActor.id,
+ url: activityId,
+
+ state
+ }, { transaction })
+
+ actorFollow.ActorFollowing = targetActor
+ actorFollow.ActorFollower = byActor
+ }
+
+ return [ actorFollow, created ]