diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/models/activitypub/actor-follow.ts | 6 | ||||
-rw-r--r-- | server/tests/api/notifications/user-notifications.ts | 47 | ||||
-rw-r--r-- | server/typings/utils.ts | 2 |
3 files changed, 46 insertions, 9 deletions
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts index 0833b9a93..8498692f0 100644 --- a/server/models/activitypub/actor-follow.ts +++ b/server/models/activitypub/actor-follow.ts | |||
@@ -439,13 +439,13 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
439 | const followerId = (await getServerActor()).id | 439 | const followerId = (await getServerActor()).id |
440 | 440 | ||
441 | const query = { | 441 | const query = { |
442 | attributes: [], | 442 | attributes: [ 'id' ], |
443 | where: { | 443 | where: { |
444 | actorId: followerId | 444 | actorId: followerId |
445 | }, | 445 | }, |
446 | include: [ | 446 | include: [ |
447 | { | 447 | { |
448 | attributes: [ ], | 448 | attributes: [ 'id' ], |
449 | model: ActorModel.unscoped(), | 449 | model: ActorModel.unscoped(), |
450 | required: true, | 450 | required: true, |
451 | as: 'ActorFollowing', | 451 | as: 'ActorFollowing', |
@@ -469,7 +469,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
469 | } | 469 | } |
470 | 470 | ||
471 | const res = await ActorFollowModel.findAll(query) | 471 | const res = await ActorFollowModel.findAll(query) |
472 | const followedHosts = res.map(res => res.ActorFollowing.Server.host) | 472 | const followedHosts = res.map(row => row.ActorFollowing.Server.host) |
473 | 473 | ||
474 | return difference(hosts, followedHosts) | 474 | return difference(hosts, followedHosts) |
475 | } | 475 | } |
diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index 62b797b47..15a34f5aa 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts | |||
@@ -14,10 +14,13 @@ import { | |||
14 | getVideoCommentThreads, | 14 | getVideoCommentThreads, |
15 | getVideoThreadComments, | 15 | getVideoThreadComments, |
16 | immutableAssign, | 16 | immutableAssign, |
17 | MockInstancesIndex, | ||
17 | registerUser, | 18 | registerUser, |
18 | removeVideoFromBlacklist, | 19 | removeVideoFromBlacklist, |
19 | reportVideoAbuse, unfollow, | 20 | reportVideoAbuse, |
20 | updateCustomConfig, updateCustomSubConfig, | 21 | unfollow, |
22 | updateCustomConfig, | ||
23 | updateCustomSubConfig, | ||
21 | updateMyUser, | 24 | updateMyUser, |
22 | updateVideo, | 25 | updateVideo, |
23 | updateVideoChannel, | 26 | updateVideoChannel, |
@@ -29,6 +32,7 @@ import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/l | |||
29 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 32 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
30 | import { getUserNotificationSocket } from '../../../../shared/extra-utils/socket/socket-io' | 33 | import { getUserNotificationSocket } from '../../../../shared/extra-utils/socket/socket-io' |
31 | import { | 34 | import { |
35 | checkAutoInstanceFollowing, | ||
32 | checkCommentMention, | 36 | checkCommentMention, |
33 | CheckerBaseParams, | 37 | CheckerBaseParams, |
34 | checkMyVideoImportIsFinished, | 38 | checkMyVideoImportIsFinished, |
@@ -45,8 +49,7 @@ import { | |||
45 | getUserNotifications, | 49 | getUserNotifications, |
46 | markAsReadAllNotifications, | 50 | markAsReadAllNotifications, |
47 | markAsReadNotifications, | 51 | markAsReadNotifications, |
48 | updateMyNotificationSettings, | 52 | updateMyNotificationSettings |
49 | checkAutoInstanceFollowing | ||
50 | } from '../../../../shared/extra-utils/users/user-notifications' | 53 | } from '../../../../shared/extra-utils/users/user-notifications' |
51 | import { | 54 | import { |
52 | User, | 55 | User, |
@@ -875,7 +878,18 @@ describe('Test users notifications', function () { | |||
875 | }) | 878 | }) |
876 | }) | 879 | }) |
877 | 880 | ||
878 | describe('New instance follower', function () { | 881 | describe('New instance follows', function () { |
882 | const instanceIndexServer = new MockInstancesIndex() | ||
883 | const config = { | ||
884 | followings: { | ||
885 | instance: { | ||
886 | autoFollowIndex: { | ||
887 | indexUrl: 'http://localhost:42100', | ||
888 | enabled: true | ||
889 | } | ||
890 | } | ||
891 | } | ||
892 | } | ||
879 | let baseParams: CheckerBaseParams | 893 | let baseParams: CheckerBaseParams |
880 | 894 | ||
881 | before(async () => { | 895 | before(async () => { |
@@ -885,6 +899,9 @@ describe('Test users notifications', function () { | |||
885 | socketNotifications: adminNotifications, | 899 | socketNotifications: adminNotifications, |
886 | token: servers[0].accessToken | 900 | token: servers[0].accessToken |
887 | } | 901 | } |
902 | |||
903 | await instanceIndexServer.initialize() | ||
904 | instanceIndexServer.addInstance(servers[1].host) | ||
888 | }) | 905 | }) |
889 | 906 | ||
890 | it('Should send a notification only to admin when there is a new instance follower', async function () { | 907 | 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 () { | |||
928 | 945 | ||
929 | config.followings.instance.autoFollowBack.enabled = false | 946 | config.followings.instance.autoFollowBack.enabled = false |
930 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | 947 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) |
948 | await unfollow(servers[0].url, servers[0].accessToken, servers[2]) | ||
949 | await unfollow(servers[2].url, servers[2].accessToken, servers[0]) | ||
950 | }) | ||
951 | |||
952 | it('Should send a notification on auto instances index follow', async function () { | ||
953 | this.timeout(30000) | ||
954 | await unfollow(servers[0].url, servers[0].accessToken, servers[1]) | ||
955 | |||
956 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | ||
957 | |||
958 | await wait(5000) | ||
959 | await waitJobs(servers) | ||
960 | |||
961 | const followerHost = servers[0].host | ||
962 | const followingHost = servers[1].host | ||
963 | await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') | ||
964 | |||
965 | config.followings.instance.autoFollowIndex.enabled = false | ||
966 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | ||
967 | await unfollow(servers[0].url, servers[0].accessToken, servers[1]) | ||
931 | }) | 968 | }) |
932 | }) | 969 | }) |
933 | 970 | ||
diff --git a/server/typings/utils.ts b/server/typings/utils.ts index 1abb4f73e..24d43b258 100644 --- a/server/typings/utils.ts +++ b/server/typings/utils.ts | |||
@@ -19,4 +19,4 @@ export type DeepPartial<T> = { | |||
19 | : T[P] extends ReadonlyArray<infer U> | 19 | : T[P] extends ReadonlyArray<infer U> |
20 | ? ReadonlyArray<DeepPartial<U>> | 20 | ? ReadonlyArray<DeepPartial<U>> |
21 | : DeepPartial<T[P]> | 21 | : DeepPartial<T[P]> |
22 | }; | 22 | } |