aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/actor
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/actor')
-rw-r--r--server/models/actor/actor-follow.ts41
1 files changed, 41 insertions, 0 deletions
diff --git a/server/models/actor/actor-follow.ts b/server/models/actor/actor-follow.ts
index 95bb2df56..c522a7c05 100644
--- a/server/models/actor/actor-follow.ts
+++ b/server/models/actor/actor-follow.ts
@@ -20,8 +20,11 @@ import {
20} from 'sequelize-typescript' 20} from 'sequelize-typescript'
21import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc' 21import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc'
22import { afterCommitIfTransaction } from '@server/helpers/database-utils' 22import { afterCommitIfTransaction } from '@server/helpers/database-utils'
23import { CONFIG } from '@server/initializers/config'
23import { getServerActor } from '@server/models/application/application' 24import { getServerActor } from '@server/models/application/application'
24import { 25import {
26 MActor,
27 MActorFollowActors,
25 MActorFollowActorsDefault, 28 MActorFollowActorsDefault,
26 MActorFollowActorsDefaultSubscription, 29 MActorFollowActorsDefaultSubscription,
27 MActorFollowFollowingHost, 30 MActorFollowFollowingHost,
@@ -137,6 +140,44 @@ export class ActorFollowModel extends Model<Partial<AttributesOnly<ActorFollowMo
137 }) 140 })
138 } 141 }
139 142
143 /*
144 * @deprecated Use `findOrCreateCustom` instead
145 */
146 static findOrCreate (): any {
147 throw new Error('Should not be called')
148 }
149
150 // findOrCreate has issues with actor follow hooks
151 static async findOrCreateCustom (options: {
152 byActor: MActor
153 targetActor: MActor
154 activityId: string
155 state: FollowState
156 transaction: Transaction
157 }): Promise<[ MActorFollowActors, boolean ]> {
158 const { byActor, targetActor, activityId, state, transaction } = options
159
160 let created = false
161 let actorFollow: MActorFollowActors = await ActorFollowModel.loadByActorAndTarget(byActor.id, targetActor.id, transaction)
162
163 if (!actorFollow) {
164 created = true
165
166 actorFollow = await ActorFollowModel.create({
167 actorId: byActor.id,
168 targetActorId: targetActor.id,
169 url: activityId,
170
171 state
172 }, { transaction })
173
174 actorFollow.ActorFollowing = targetActor
175 actorFollow.ActorFollower = byActor
176 }
177
178 return [ actorFollow, created ]
179 }
180
140 static removeFollowsOf (actorId: number, t?: Transaction) { 181 static removeFollowsOf (actorId: number, t?: Transaction) {
141 const query = { 182 const query = {
142 where: { 183 where: {