From: Chocobozzz <me@florianbigard.com>
Date: Fri, 2 Aug 2019 07:46:48 +0000 (+0200)
Subject: Fix broken follow notification
X-Git-Tag: v1.4.0-rc.1~33
X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=44b88f180bc9ec692885e7db08757a43b3e2df79;p=oweals%2Fpeertube.git

Fix broken follow notification
---

diff --git a/client/src/app/shared/users/user-notification.model.ts b/client/src/app/shared/users/user-notification.model.ts
index 72fc3e7b4..06eace71c 100644
--- a/client/src/app/shared/users/user-notification.model.ts
+++ b/client/src/app/shared/users/user-notification.model.ts
@@ -148,6 +148,7 @@ export class UserNotification implements UserNotificationServer {
           break
       }
     } catch (err) {
+      this.type = null
       console.error(err)
     }
   }
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index 28014946f..4dc412301 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -30,6 +30,7 @@ import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants'
 import { FindOptions, IncludeOptions, Op, Transaction, WhereOptions } from 'sequelize'
 import { AccountBlocklistModel } from './account-blocklist'
 import { ServerBlocklistModel } from '../server/server-blocklist'
+import { ActorFollowModel } from '../activitypub/actor-follow'
 
 export enum ScopeNames {
   SUMMARY = 'SUMMARY'
@@ -220,6 +221,7 @@ export class AccountModel extends Model<AccountModel> {
       instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel
     }
 
+    await ActorFollowModel.removeFollowsOf(instance.Actor.id, options.transaction)
     if (instance.isOwned()) {
       return sendDeleteActor(instance.Actor, options.transaction)
     }
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts
index b0461b981..3039b90c7 100644
--- a/server/models/activitypub/actor-follow.ts
+++ b/server/models/activitypub/actor-follow.ts
@@ -113,6 +113,24 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
     ])
   }
 
+  static removeFollowsOf (actorId: number, t?: Transaction) {
+    const query = {
+      where: {
+        [Op.or]: [
+          {
+            actorId
+          },
+          {
+            targetActorId: actorId
+          }
+        ]
+      },
+      transaction: t
+    }
+
+    return ActorFollowModel.destroy(query)
+  }
+
   // Remove actor follows with a score of 0 (too many requests where they were unreachable)
   static async removeBadActorFollows () {
     const actorFollows = await ActorFollowModel.listBadActorFollows()