Add notification on auto follow index
authorChocobozzz <me@florianbigard.com>
Wed, 4 Sep 2019 09:39:25 +0000 (11:39 +0200)
committerChocobozzz <chocobozzz@cpy.re>
Wed, 4 Sep 2019 14:24:58 +0000 (16:24 +0200)
server/models/activitypub/actor-follow.ts
server/tests/api/notifications/user-notifications.ts
server/typings/utils.ts

index 0833b9a9382512829c609bac234e221fdd002bae..8498692f0fcba3b049ebf03782673b36445fd489 100644 (file)
@@ -439,13 +439,13 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
     const followerId = (await getServerActor()).id
 
     const query = {
-      attributes: [],
+      attributes: [ 'id' ],
       where: {
         actorId: followerId
       },
       include: [
         {
-          attributes: [ ],
+          attributes: [ 'id' ],
           model: ActorModel.unscoped(),
           required: true,
           as: 'ActorFollowing',
@@ -469,7 +469,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
     }
 
     const res = await ActorFollowModel.findAll(query)
-    const followedHosts = res.map(res => res.ActorFollowing.Server.host)
+    const followedHosts = res.map(row => row.ActorFollowing.Server.host)
 
     return difference(hosts, followedHosts)
   }
index 62b797b47e83f02c0551904d65e96392d89601b3..15a34f5aab9c86dc2c6a0addd84519dea6274d03 100644 (file)
@@ -14,10 +14,13 @@ import {
   getVideoCommentThreads,
   getVideoThreadComments,
   immutableAssign,
+  MockInstancesIndex,
   registerUser,
   removeVideoFromBlacklist,
-  reportVideoAbuse, unfollow,
-  updateCustomConfig, updateCustomSubConfig,
+  reportVideoAbuse,
+  unfollow,
+  updateCustomConfig,
+  updateCustomSubConfig,
   updateMyUser,
   updateVideo,
   updateVideoChannel,
@@ -29,6 +32,7 @@ import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/l
 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
 import { getUserNotificationSocket } from '../../../../shared/extra-utils/socket/socket-io'
 import {
+  checkAutoInstanceFollowing,
   checkCommentMention,
   CheckerBaseParams,
   checkMyVideoImportIsFinished,
@@ -45,8 +49,7 @@ import {
   getUserNotifications,
   markAsReadAllNotifications,
   markAsReadNotifications,
-  updateMyNotificationSettings,
-  checkAutoInstanceFollowing
+  updateMyNotificationSettings
 } from '../../../../shared/extra-utils/users/user-notifications'
 import {
   User,
@@ -875,7 +878,18 @@ describe('Test users notifications', function () {
     })
   })
 
-  describe('New instance follower', function () {
+  describe('New instance follows', function () {
+    const instanceIndexServer = new MockInstancesIndex()
+    const config = {
+      followings: {
+        instance: {
+          autoFollowIndex: {
+            indexUrl: 'http://localhost:42100',
+            enabled: true
+          }
+        }
+      }
+    }
     let baseParams: CheckerBaseParams
 
     before(async () => {
@@ -885,6 +899,9 @@ describe('Test users notifications', function () {
         socketNotifications: adminNotifications,
         token: servers[0].accessToken
       }
+
+      await instanceIndexServer.initialize()
+      instanceIndexServer.addInstance(servers[1].host)
     })
 
     it('Should send a notification only to admin when there is a new instance follower', async function () {
@@ -928,6 +945,26 @@ describe('Test users notifications', function () {
 
       config.followings.instance.autoFollowBack.enabled = false
       await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
+      await unfollow(servers[0].url, servers[0].accessToken, servers[2])
+      await unfollow(servers[2].url, servers[2].accessToken, servers[0])
+    })
+
+    it('Should send a notification on auto instances index follow', async function () {
+      this.timeout(30000)
+      await unfollow(servers[0].url, servers[0].accessToken, servers[1])
+
+      await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
+
+      await wait(5000)
+      await waitJobs(servers)
+
+      const followerHost = servers[0].host
+      const followingHost = servers[1].host
+      await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence')
+
+      config.followings.instance.autoFollowIndex.enabled = false
+      await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config)
+      await unfollow(servers[0].url, servers[0].accessToken, servers[1])
     })
   })
 
index 1abb4f73e3a4747ee6930b648f21b005a5d8d9da..24d43b2587007611a1836bc3a881e562e243f5c3 100644 (file)
@@ -19,4 +19,4 @@ export type DeepPartial<T> = {
     : T[P] extends ReadonlyArray<infer U>
       ? ReadonlyArray<DeepPartial<U>>
       : DeepPartial<T[P]>
-};
+}