This commit is contained in:
mattyatea 2023-11-02 10:16:01 +09:00
parent 52939f5661
commit b1b6966b6b
3 changed files with 21 additions and 97 deletions

View file

@ -251,51 +251,4 @@ export class QueryService {
q.setParameters(mutingQuery.getParameters());
}
@bindThis
public generateChannelQuery(q: SelectQueryBuilder<any>, me?: { id: MiUser['id'] } | null): void {
if (me == null) {
q.andWhere('note.channelId IS NULL');
} else {
q.leftJoinAndSelect('note.channel', 'channel');
const channelFollowingQuery = this.channelFollowingsRepository.createQueryBuilder('channelFollowing')
.select('channelFollowing.followeeId')
.where('channelFollowing.followerId = :followerId', { followerId: me.id });
q.andWhere(new Brackets(qb => { qb
// チャンネルのノートではない
.where('note.channelId IS NULL')
// または自分がフォローしているチャンネルのノート
.orWhere(`note.channelId IN (${ channelFollowingQuery.getQuery() })`);
}));
q.setParameters(channelFollowingQuery.getParameters());
}
}
@bindThis
public generateRepliesQuery(q: SelectQueryBuilder<any>, withReplies: boolean, me?: Pick<MiUser, 'id'> | null): void {
if (me == null) {
q.andWhere(new Brackets(qb => { qb
.where('note.replyId IS NULL') // 返信ではない
.orWhere(new Brackets(qb => { qb // 返信だけど投稿者自身への返信
.where('note.replyId IS NOT NULL')
.andWhere('note.replyUserId = note.userId');
}));
}));
} else if (!withReplies) {
q.andWhere(new Brackets(qb => { qb
.where('note.replyId IS NULL') // 返信ではない
.orWhere('note.replyUserId = :meId', { meId: me.id }) // 返信だけど自分のノートへの返信
.orWhere(new Brackets(qb => { qb // 返信だけど自分の行った返信
.where('note.replyId IS NOT NULL')
.andWhere('note.userId = :meId', { meId: me.id });
}))
.orWhere(new Brackets(qb => { qb // 返信だけど投稿者自身への返信
.where('note.replyId IS NOT NULL')
.andWhere('note.replyUserId = note.userId');
}));
}));
}
}
}

View file

@ -19,13 +19,7 @@ import { FederatedInstanceService } from '@/core/FederatedInstanceService.js';
import { WebhookService } from '@/core/WebhookService.js';
import { NotificationService } from '@/core/NotificationService.js';
import { DI } from '@/di-symbols.js';
import type {
FollowingsRepository,
FollowRequestsRepository,
InstancesRepository,
UserProfilesRepository,
UsersRepository,
} from '@/models/_.js';
import type { FollowingsRepository, FollowRequestsRepository, InstancesRepository, UserProfilesRepository, UsersRepository } from '@/models/_.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
import { bindThis } from '@/decorators.js';
@ -59,18 +53,25 @@ export class UserFollowingService implements OnModuleInit {
constructor(
private moduleRef: ModuleRef,
@Inject(DI.config)
private config: Config,
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,
@Inject(DI.userProfilesRepository)
private userProfilesRepository: UserProfilesRepository,
@Inject(DI.followingsRepository)
private followingsRepository: FollowingsRepository,
@Inject(DI.followRequestsRepository)
private followRequestsRepository: FollowRequestsRepository,
@Inject(DI.instancesRepository)
private instancesRepository: InstancesRepository,
private cacheService: CacheService,
private utilityService: UtilityService,
private userEntityService: UserEntityService,
@ -196,18 +197,10 @@ export class UserFollowingService implements OnModuleInit {
@bindThis
private async insertFollowingDoc(
followee: {
id: MiUser['id'];
host: MiUser['host'];
uri: MiUser['host'];
inbox: MiUser['inbox'];
sharedInbox: MiUser['sharedInbox']
id: MiUser['id']; host: MiUser['host']; uri: MiUser['host']; inbox: MiUser['inbox']; sharedInbox: MiUser['sharedInbox']
},
follower: {
id: MiUser['id'];
host: MiUser['host'];
uri: MiUser['host'];
inbox: MiUser['inbox'];
sharedInbox: MiUser['sharedInbox']
id: MiUser['id']; host: MiUser['host']; uri: MiUser['host']; inbox: MiUser['inbox']; sharedInbox: MiUser['sharedInbox']
},
silent = false,
withReplies?: boolean,
@ -254,7 +247,8 @@ export class UserFollowingService implements OnModuleInit {
});
// 通知を作成
this.notificationService.createNotification(follower.id, 'followRequestAccepted', {}, followee.id);
this.notificationService.createNotification(follower.id, 'followRequestAccepted', {
}, followee.id);
}
if (alreadyFollowed) return;
@ -328,25 +322,18 @@ export class UserFollowingService implements OnModuleInit {
});
// 通知を作成
this.notificationService.createNotification(followee.id, 'follow', {}, follower.id);
this.notificationService.createNotification(followee.id, 'follow', {
}, follower.id);
}
}
@bindThis
public async unfollow(
follower: {
id: MiUser['id'];
host: MiUser['host'];
uri: MiUser['host'];
inbox: MiUser['inbox'];
sharedInbox: MiUser['sharedInbox'];
id: MiUser['id']; host: MiUser['host']; uri: MiUser['host']; inbox: MiUser['inbox']; sharedInbox: MiUser['sharedInbox'];
},
followee: {
id: MiUser['id'];
host: MiUser['host'];
uri: MiUser['host'];
inbox: MiUser['inbox'];
sharedInbox: MiUser['sharedInbox'];
id: MiUser['id']; host: MiUser['host']; uri: MiUser['host']; inbox: MiUser['inbox']; sharedInbox: MiUser['sharedInbox'];
},
silent = false,
): Promise<void> {
@ -477,18 +464,10 @@ export class UserFollowingService implements OnModuleInit {
@bindThis
public async createFollowRequest(
follower: {
id: MiUser['id'];
host: MiUser['host'];
uri: MiUser['host'];
inbox: MiUser['inbox'];
sharedInbox: MiUser['sharedInbox'];
id: MiUser['id']; host: MiUser['host']; uri: MiUser['host']; inbox: MiUser['inbox']; sharedInbox: MiUser['sharedInbox'];
},
followee: {
id: MiUser['id'];
host: MiUser['host'];
uri: MiUser['host'];
inbox: MiUser['inbox'];
sharedInbox: MiUser['sharedInbox'];
id: MiUser['id']; host: MiUser['host']; uri: MiUser['host']; inbox: MiUser['inbox']; sharedInbox: MiUser['sharedInbox'];
},
requestId?: string,
withReplies?: boolean,
@ -581,11 +560,7 @@ export class UserFollowingService implements OnModuleInit {
@bindThis
public async acceptFollowRequest(
followee: {
id: MiUser['id'];
host: MiUser['host'];
uri: MiUser['host'];
inbox: MiUser['inbox'];
sharedInbox: MiUser['sharedInbox'];
id: MiUser['id']; host: MiUser['host']; uri: MiUser['host']; inbox: MiUser['inbox']; sharedInbox: MiUser['sharedInbox'];
},
follower: MiUser,
): Promise<void> {
@ -613,11 +588,7 @@ export class UserFollowingService implements OnModuleInit {
@bindThis
public async acceptAllFollowRequests(
user: {
id: MiUser['id'];
host: MiUser['host'];
uri: MiUser['host'];
inbox: MiUser['inbox'];
sharedInbox: MiUser['sharedInbox'];
id: MiUser['id']; host: MiUser['host']; uri: MiUser['host']; inbox: MiUser['inbox']; sharedInbox: MiUser['sharedInbox'];
},
): Promise<void> {
const requests = await this.followRequestsRepository.findBy({

View file

@ -27,7 +27,7 @@ import type { UsersRepository, UserProfilesRepository, NotesRepository, DriveFil
import { bindThis } from '@/decorators.js';
import { CustomEmojiService } from '@/core/CustomEmojiService.js';
import { isNotNull } from '@/misc/is-not-null.js';
import { IdService } from '@/core/IdService.js';
import { IdService } from '@/core/IdService.js';
import { LdSignatureService } from './LdSignatureService.js';
import { ApMfmService } from './ApMfmService.js';
import type { IAccept, IActivity, IAdd, IAnnounce, IApDocument, IApEmoji, IApHashtag, IApImage, IApMention, IBlock, ICreate, IDelete, IFlag, IFollow, IKey, ILike, IMove, IObject, IPost, IQuestion, IReject, IRemove, ITombstone, IUndo, IUpdate } from './type.js';