summaryrefslogtreecommitdiff
path: root/packages/backend/src/core
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-03-30 01:58:17 -0400
committerHazelnoot <acomputerdog@gmail.com>2025-03-30 01:58:17 -0400
commit4ae26e6e185e52ac186ac10ccd4eda7718bf6e26 (patch)
tree8d556072f3876f0bfbab9d24e7cd209ca6bd091a /packages/backend/src/core
parentrestore following feed deck UI (diff)
parentNew Crowdin updates (#15721) (diff)
downloadsharkey-4ae26e6e185e52ac186ac10ccd4eda7718bf6e26.tar.gz
sharkey-4ae26e6e185e52ac186ac10ccd4eda7718bf6e26.tar.bz2
sharkey-4ae26e6e185e52ac186ac10ccd4eda7718bf6e26.zip
Merge branch 'misskey-develop' into merge/2025-03-24
Diffstat (limited to 'packages/backend/src/core')
-rw-r--r--packages/backend/src/core/QueryService.ts4
-rw-r--r--packages/backend/src/core/SearchService.ts4
-rw-r--r--packages/backend/src/core/UserSearchService.ts100
-rw-r--r--packages/backend/src/core/WebhookTestService.ts1
-rw-r--r--packages/backend/src/core/entities/UserEntityService.ts1
5 files changed, 104 insertions, 6 deletions
diff --git a/packages/backend/src/core/QueryService.ts b/packages/backend/src/core/QueryService.ts
index c4feeaf971..412ab33b3f 100644
--- a/packages/backend/src/core/QueryService.ts
+++ b/packages/backend/src/core/QueryService.ts
@@ -69,7 +69,7 @@ export class QueryService {
// ここでいうBlockedは被Blockedの意
@bindThis
- public generateBlockedUserQuery(q: SelectQueryBuilder<any>, me: { id: MiUser['id'] }): void {
+ public generateBlockedUserQueryForNotes(q: SelectQueryBuilder<any>, me: { id: MiUser['id'] }): void {
const blockingQuery = this.blockingsRepository.createQueryBuilder('blocking')
.select('blocking.blockerId')
.where('blocking.blockeeId = :blockeeId', { blockeeId: me.id });
@@ -127,7 +127,7 @@ export class QueryService {
}
@bindThis
- public generateMutedUserQuery(q: SelectQueryBuilder<any>, me: { id: MiUser['id'] }, exclude?: { id: MiUser['id'] }): void {
+ public generateMutedUserQueryForNotes(q: SelectQueryBuilder<any>, me: { id: MiUser['id'] }, exclude?: { id: MiUser['id'] }): void {
const mutingQuery = this.mutingsRepository.createQueryBuilder('muting')
.select('muting.muteeId')
.where('muting.muterId = :muterId', { muterId: me.id });
diff --git a/packages/backend/src/core/SearchService.ts b/packages/backend/src/core/SearchService.ts
index 4782a6c7b0..e17677bcb5 100644
--- a/packages/backend/src/core/SearchService.ts
+++ b/packages/backend/src/core/SearchService.ts
@@ -300,8 +300,8 @@ export class SearchService {
}
this.queryService.generateVisibilityQuery(query, me);
- if (me) this.queryService.generateMutedUserQuery(query, me);
- if (me) this.queryService.generateBlockedUserQuery(query, me);
+ if (me) this.queryService.generateMutedUserQueryForNotes(query, me);
+ if (me) this.queryService.generateBlockedUserQueryForNotes(query, me);
return await query.limit(pagination.limit).getMany();
}
diff --git a/packages/backend/src/core/UserSearchService.ts b/packages/backend/src/core/UserSearchService.ts
index 0d03cf6ee0..4be7bd9bdb 100644
--- a/packages/backend/src/core/UserSearchService.ts
+++ b/packages/backend/src/core/UserSearchService.ts
@@ -6,7 +6,7 @@
import { Inject, Injectable } from '@nestjs/common';
import { Brackets, SelectQueryBuilder } from 'typeorm';
import { DI } from '@/di-symbols.js';
-import { type FollowingsRepository, MiUser, type UsersRepository } from '@/models/_.js';
+import { type FollowingsRepository, MiUser, type MutingsRepository, type UserProfilesRepository, type UsersRepository } from '@/models/_.js';
import { bindThis } from '@/decorators.js';
import { sqlLikeEscape } from '@/misc/sql-like-escape.js';
import type { Config } from '@/config.js';
@@ -22,10 +22,19 @@ export class UserSearchService {
constructor(
@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.mutingsRepository)
+ private mutingsRepository: MutingsRepository,
+
private userEntityService: UserEntityService,
) {
}
@@ -58,7 +67,7 @@ export class UserSearchService {
* @see {@link UserSearchService#buildSearchUserNoLoginQueries}
*/
@bindThis
- public async search(
+ public async searchByUsernameAndHost(
params: {
username?: string | null,
host?: string | null,
@@ -202,4 +211,91 @@ export class UserSearchService {
return userQuery;
}
+
+ @bindThis
+ public async search(query: string, meId: MiUser['id'] | null, options: Partial<{
+ limit: number;
+ offset: number;
+ origin: 'local' | 'remote' | 'combined';
+ }> = {}) {
+ const activeThreshold = new Date(Date.now() - (1000 * 60 * 60 * 24 * 30)); // 30日
+
+ const isUsername = query.startsWith('@') && !query.includes(' ') && query.indexOf('@', 1) === -1;
+
+ let users: MiUser[] = [];
+
+ const mutingQuery = meId == null ? null : this.mutingsRepository.createQueryBuilder('muting')
+ .select('muting.muteeId')
+ .where('muting.muterId = :muterId', { muterId: meId });
+
+ const nameQuery = this.usersRepository.createQueryBuilder('user')
+ .where(new Brackets(qb => {
+ qb.where('user.name ILIKE :query', { query: '%' + sqlLikeEscape(query) + '%' });
+
+ if (isUsername) {
+ qb.orWhere('user.usernameLower LIKE :username', { username: sqlLikeEscape(query.replace('@', '').toLowerCase()) + '%' });
+ } else if (this.userEntityService.validateLocalUsername(query)) { // Also search username if it qualifies as username
+ qb.orWhere('user.usernameLower LIKE :username', { username: '%' + sqlLikeEscape(query.toLowerCase()) + '%' });
+ }
+ }))
+ .andWhere(new Brackets(qb => {
+ qb
+ .where('user.updatedAt IS NULL')
+ .orWhere('user.updatedAt > :activeThreshold', { activeThreshold: activeThreshold });
+ }))
+ .andWhere('user.isSuspended = FALSE');
+
+ if (mutingQuery) {
+ nameQuery.andWhere(`user.id NOT IN (${mutingQuery.getQuery()})`);
+ nameQuery.setParameters(mutingQuery.getParameters());
+ }
+
+ if (options.origin === 'local') {
+ nameQuery.andWhere('user.host IS NULL');
+ } else if (options.origin === 'remote') {
+ nameQuery.andWhere('user.host IS NOT NULL');
+ }
+
+ users = await nameQuery
+ .orderBy('user.updatedAt', 'DESC', 'NULLS LAST')
+ .limit(options.limit)
+ .offset(options.offset)
+ .getMany();
+
+ if (users.length < (options.limit ?? 30)) {
+ const profQuery = this.userProfilesRepository.createQueryBuilder('prof')
+ .select('prof.userId')
+ .where('prof.description ILIKE :query', { query: '%' + sqlLikeEscape(query) + '%' });
+
+ if (mutingQuery) {
+ profQuery.andWhere(`prof.userId NOT IN (${mutingQuery.getQuery()})`);
+ profQuery.setParameters(mutingQuery.getParameters());
+ }
+
+ if (options.origin === 'local') {
+ profQuery.andWhere('prof.userHost IS NULL');
+ } else if (options.origin === 'remote') {
+ profQuery.andWhere('prof.userHost IS NOT NULL');
+ }
+
+ const userQuery = this.usersRepository.createQueryBuilder('user')
+ .where(`user.id IN (${ profQuery.getQuery() })`)
+ .andWhere(new Brackets(qb => {
+ qb
+ .where('user.updatedAt IS NULL')
+ .orWhere('user.updatedAt > :activeThreshold', { activeThreshold: activeThreshold });
+ }))
+ .andWhere('user.isSuspended = FALSE')
+ .setParameters(profQuery.getParameters());
+
+ users = users.concat(await userQuery
+ .orderBy('user.updatedAt', 'DESC', 'NULLS LAST')
+ .limit(options.limit)
+ .offset(options.offset)
+ .getMany(),
+ );
+ }
+
+ return users;
+ }
}
diff --git a/packages/backend/src/core/WebhookTestService.ts b/packages/backend/src/core/WebhookTestService.ts
index 8d2e181aa5..3e89595155 100644
--- a/packages/backend/src/core/WebhookTestService.ts
+++ b/packages/backend/src/core/WebhookTestService.ts
@@ -482,6 +482,7 @@ export class WebhookTestService {
followersVisibility: 'public',
followingVisibility: 'public',
chatScope: 'mutual',
+ canChat: true,
twoFactorEnabled: false,
usePasswordLessLogin: false,
securityKeys: false,
diff --git a/packages/backend/src/core/entities/UserEntityService.ts b/packages/backend/src/core/entities/UserEntityService.ts
index cfcf10a0f4..2dc2c50e4a 100644
--- a/packages/backend/src/core/entities/UserEntityService.ts
+++ b/packages/backend/src/core/entities/UserEntityService.ts
@@ -664,6 +664,7 @@ export class UserEntityService implements OnModuleInit {
followersVisibility: profile!.followersVisibility,
followingVisibility: profile!.followingVisibility,
chatScope: user.chatScope,
+ canChat: this.roleService.getUserPolicies(user.id).then(r => r.canChat),
roles: this.roleService.getUserRoles(user.id).then(roles => roles.filter(role => role.isPublic).sort((a, b) => b.displayOrder - a.displayOrder).map(role => ({
id: role.id,
name: role.name,