mute users when blocking them - fixes #558

we already unfollow them, and make them unfollow us, so muting them is
a very sensible thing to want

since the mute is handled separately, users can un-mute the people
they block (same as they can re-follow them)
This commit is contained in:
dakkar 2024-07-13 10:39:24 +01:00
parent 7dfe9087b2
commit 9a9570ab62
2 changed files with 36 additions and 4 deletions

View file

@ -6,9 +6,10 @@
import ms from 'ms';
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import type { UsersRepository, BlockingsRepository } from '@/models/_.js';
import type { UsersRepository, BlockingsRepository, MutingsRepository } from '@/models/_.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { UserBlockingService } from '@/core/UserBlockingService.js';
import { UserMutingService } from '@/core/UserMutingService.js';
import { DI } from '@/di-symbols.js';
import { GetterService } from '@/server/api/GetterService.js';
import { ApiError } from '../../error.js';
@ -69,9 +70,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
@Inject(DI.blockingsRepository)
private blockingsRepository: BlockingsRepository,
@Inject(DI.mutingsRepository)
private mutingsRepository: MutingsRepository,
private userEntityService: UserEntityService,
private getterService: GetterService,
private userBlockingService: UserBlockingService,
private userMutingService: UserMutingService,
) {
super(meta, paramDef, async (ps, me) => {
const blocker = await this.usersRepository.findOneByOrFail({ id: me.id });
@ -99,7 +104,19 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.alreadyBlocking);
}
await this.userBlockingService.block(blocker, blockee);
await Promise.all([
this.userBlockingService.block(blocker, blockee),
this.mutingsRepository.exists({
where: {
muterId: blocker.id,
muteeId: blockee.id,
},
}).then(exists => {
if (!exists) {
this.userMutingService.mute(blocker, blockee, null);
}
}),
]);
return await this.userEntityService.pack(blockee.id, blocker, {
schema: 'UserDetailedNotMe',

View file

@ -6,9 +6,10 @@
import ms from 'ms';
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import type { UsersRepository, BlockingsRepository } from '@/models/_.js';
import type { UsersRepository, BlockingsRepository, MutingsRepository } from '@/models/_.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { UserBlockingService } from '@/core/UserBlockingService.js';
import { UserMutingService } from '@/core/UserMutingService.js';
import { DI } from '@/di-symbols.js';
import { GetterService } from '@/server/api/GetterService.js';
import { ApiError } from '../../error.js';
@ -69,9 +70,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
@Inject(DI.blockingsRepository)
private blockingsRepository: BlockingsRepository,
@Inject(DI.mutingsRepository)
private mutingsRepository: MutingsRepository,
private userEntityService: UserEntityService,
private getterService: GetterService,
private userBlockingService: UserBlockingService,
private userMutingService: UserMutingService,
) {
super(meta, paramDef, async (ps, me) => {
const blocker = await this.usersRepository.findOneByOrFail({ id: me.id });
@ -100,7 +105,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
// Delete blocking
await this.userBlockingService.unblock(blocker, blockee);
await Promise.all([
this.userBlockingService.unblock(blocker, blockee),
this.mutingsRepository.findOneBy({
muterId: blocker.id,
muteeId: blockee.id,
}).then(exists => {
if (exists) {
this.userMutingService.unmute([exists]);
}
}),
]);
return await this.userEntityService.pack(blockee.id, blocker, {
schema: 'UserDetailedNotMe',