1
0
Fork 0

Add notification on auto follow index

This commit is contained in:
Chocobozzz 2019-09-04 11:39:25 +02:00 committed by Chocobozzz
parent 6f1b4fa417
commit 10a105f0c8
3 changed files with 46 additions and 9 deletions

View File

@ -439,13 +439,13 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
const followerId = (await getServerActor()).id const followerId = (await getServerActor()).id
const query = { const query = {
attributes: [], attributes: [ 'id' ],
where: { where: {
actorId: followerId actorId: followerId
}, },
include: [ include: [
{ {
attributes: [ ], attributes: [ 'id' ],
model: ActorModel.unscoped(), model: ActorModel.unscoped(),
required: true, required: true,
as: 'ActorFollowing', as: 'ActorFollowing',
@ -469,7 +469,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
} }
const res = await ActorFollowModel.findAll(query) 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) return difference(hosts, followedHosts)
} }

View File

@ -14,10 +14,13 @@ import {
getVideoCommentThreads, getVideoCommentThreads,
getVideoThreadComments, getVideoThreadComments,
immutableAssign, immutableAssign,
MockInstancesIndex,
registerUser, registerUser,
removeVideoFromBlacklist, removeVideoFromBlacklist,
reportVideoAbuse, unfollow, reportVideoAbuse,
updateCustomConfig, updateCustomSubConfig, unfollow,
updateCustomConfig,
updateCustomSubConfig,
updateMyUser, updateMyUser,
updateVideo, updateVideo,
updateVideoChannel, updateVideoChannel,
@ -29,6 +32,7 @@ import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/l
import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import { getUserNotificationSocket } from '../../../../shared/extra-utils/socket/socket-io' import { getUserNotificationSocket } from '../../../../shared/extra-utils/socket/socket-io'
import { import {
checkAutoInstanceFollowing,
checkCommentMention, checkCommentMention,
CheckerBaseParams, CheckerBaseParams,
checkMyVideoImportIsFinished, checkMyVideoImportIsFinished,
@ -45,8 +49,7 @@ import {
getUserNotifications, getUserNotifications,
markAsReadAllNotifications, markAsReadAllNotifications,
markAsReadNotifications, markAsReadNotifications,
updateMyNotificationSettings, updateMyNotificationSettings
checkAutoInstanceFollowing
} from '../../../../shared/extra-utils/users/user-notifications' } from '../../../../shared/extra-utils/users/user-notifications'
import { import {
User, 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 let baseParams: CheckerBaseParams
before(async () => { before(async () => {
@ -885,6 +899,9 @@ describe('Test users notifications', function () {
socketNotifications: adminNotifications, socketNotifications: adminNotifications,
token: servers[0].accessToken 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 () { 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 config.followings.instance.autoFollowBack.enabled = false
await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) 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])
}) })
}) })

View File

@ -19,4 +19,4 @@ export type DeepPartial<T> = {
: T[P] extends ReadonlyArray<infer U> : T[P] extends ReadonlyArray<infer U>
? ReadonlyArray<DeepPartial<U>> ? ReadonlyArray<DeepPartial<U>>
: DeepPartial<T[P]> : DeepPartial<T[P]>
}; }