Skip to content

Commit

Permalink
Merge branch 'io' into update-host
Browse files Browse the repository at this point in the history
  • Loading branch information
riku6460 committed Sep 16, 2024
2 parents 138c303 + 6c732d1 commit 5f2c250
Show file tree
Hide file tree
Showing 50 changed files with 805 additions and 91 deletions.
2 changes: 2 additions & 0 deletions locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ followingVisibility: "Visibility of follows"
followersVisibility: "Visibility of followers"
continueThread: "View thread continuation"
deleteAccountConfirm: "This will irreversibly delete your account. Proceed?"
deleteAccountConfirmAndWarn: "This will irreversibly delete your account.\nPlease note that re-logging in after a deletion request will interrupt the deletion of your account.\nProceed?"
incorrectPassword: "Incorrect password."
voteConfirm: "Confirm your vote for \"{choice}\"?"
hide: "Hide"
Expand Down Expand Up @@ -1813,6 +1814,7 @@ _accountDelete:
requestAccountDelete: "Request account deletion"
started: "Deletion has been started."
inProgress: "Deletion is currently in progress"
dontLogin: "We recommend that you do not log in to your account, as this will interrupt the deletion process."
_ad:
back: "Back"
reduceFrequencyOfThisAd: "Show this ad less"
Expand Down
31 changes: 31 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,22 @@ export interface Locale extends ILocale {
* モデログ
*/
"moderationLogs": string;
/**
* アカウント移行使用ログ
*/
"userAccountMoveLogs": string;
/**
* {from} が {to} にアカウントを移行しました
*/
"userAccountMoveLogsTitle": ParameterizedString<"from" | "to">;
/**
* 移行先のアカウントのID
*/
"movedToId": string;
/**
* 移行元のアカウントのID
*/
"moveFromId": string;
/**
* {n}人が投稿
*/
Expand Down Expand Up @@ -3660,6 +3676,13 @@ export interface Locale extends ILocale {
* アカウントが削除されます。よろしいですか?
*/
"deleteAccountConfirm": string;
/**
* アカウントが削除されます。
* 削除リクエスト後に再ログインすると
* アカウントの削除が中断されてしまいますのでご注意ください。
* よろしいですか?
*/
"deleteAccountConfirmAndWarn": string;
/**
* パスワードが間違っています。
*/
Expand Down Expand Up @@ -4368,6 +4391,10 @@ export interface Locale extends ILocale {
* このユーザーは新しいアカウントに移行しました:
*/
"accountMoved": string;
/**
* このユーザーは次のアカウントから移行されました:
*/
"accountMovedFrom": string;
/**
* このアカウントは移行されています
*/
Expand Down Expand Up @@ -7081,6 +7108,10 @@ export interface Locale extends ILocale {
* 削除が進行中
*/
"inProgress": string;
/**
* 削除が中断されてしまいますので、アカウントにログインしないことをおすすめします。
*/
"dontLogin": string;
};
"_ad": {
/**
Expand Down
7 changes: 7 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,10 @@ moderation: "モデレーション"
moderationNote: "モデレーションノート"
addModerationNote: "モデレーションノートを追加する"
moderationLogs: "モデログ"
userAccountMoveLogs: "アカウント移行使用ログ"
userAccountMoveLogsTitle: "{from} が {to} にアカウントを移行しました"
movedToId: "移行先のアカウントのID"
moveFromId: "移行元のアカウントのID"
nUsersMentioned: "{n}人が投稿"
securityKeyAndPasskey: "セキュリティキー・パスキー"
securityKey: "セキュリティキー"
Expand Down Expand Up @@ -911,6 +915,7 @@ followingVisibility: "フォローの公開範囲"
followersVisibility: "フォロワーの公開範囲"
continueThread: "さらにスレッドを見る"
deleteAccountConfirm: "アカウントが削除されます。よろしいですか?"
deleteAccountConfirmAndWarn: "アカウントが削除されます。\n削除リクエスト後に再ログインすると\nアカウントの削除が中断されてしまいますのでご注意ください。\nよろしいですか?"
incorrectPassword: "パスワードが間違っています。"
voteConfirm: "「{choice}」に投票しますか?"
hide: "隠す"
Expand Down Expand Up @@ -1088,6 +1093,7 @@ audioFiles: "音声"
dataSaver: "データセーバー"
accountMigration: "アカウントの移行"
accountMoved: "このユーザーは新しいアカウントに移行しました:"
accountMovedFrom: "このユーザーは次のアカウントから移行されました:"
accountMovedShort: "このアカウントは移行されています"
operationForbidden: "この操作はできません"
forceShowAds: "常に広告を表示する"
Expand Down Expand Up @@ -1833,6 +1839,7 @@ _accountDelete:
requestAccountDelete: "アカウント削除をリクエスト"
started: "削除処理が開始されました。"
inProgress: "削除が進行中"
dontLogin: "削除が中断されてしまいますので、アカウントにログインしないことをおすすめします。"

_ad:
back: "戻る"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "misskey",
"version": "2024.5.0-host.2d",
"version": "2024.5.0-host.2e",
"codename": "nasubi",
"repository": {
"type": "git",
Expand Down
19 changes: 19 additions & 0 deletions packages/backend/migration/1724749627479-useraccountmovelogs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export class Useraccountmovelogs1724749627479 {
name = 'Useraccountmovelogs1724749627479'

async up(queryRunner) {
await queryRunner.query(`CREATE TABLE "user_account_move_log" ("id" character varying(32) NOT NULL, "movedToId" character varying(32) NOT NULL, "movedFromId" character varying(32) NOT NULL, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), CONSTRAINT "PK_8ffd4ae965a5e3a0fbf4b084212" PRIMARY KEY ("id")); COMMENT ON COLUMN "user_account_move_log"."createdAt" IS 'The created date of the UserIp.'`);
await queryRunner.query(`CREATE INDEX "IDX_d5ee7d4d1b5e7a69d8855ab069" ON "user_account_move_log" ("movedToId") `);
await queryRunner.query(`CREATE INDEX "IDX_82930731d6390e7bb429a1938f" ON "user_account_move_log" ("movedFromId") `);
await queryRunner.query(`ALTER TABLE "user_account_move_log" ADD CONSTRAINT "FK_d5ee7d4d1b5e7a69d8855ab0696" FOREIGN KEY ("movedToId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "user_account_move_log" ADD CONSTRAINT "FK_82930731d6390e7bb429a1938f8" FOREIGN KEY ("movedFromId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "user_account_move_log" DROP CONSTRAINT "FK_82930731d6390e7bb429a1938f8"`);
await queryRunner.query(`ALTER TABLE "user_account_move_log" DROP CONSTRAINT "FK_d5ee7d4d1b5e7a69d8855ab0696"`);
await queryRunner.query(`DROP INDEX "public"."IDX_82930731d6390e7bb429a1938f"`);
await queryRunner.query(`DROP INDEX "public"."IDX_d5ee7d4d1b5e7a69d8855ab069"`);
await queryRunner.query(`DROP TABLE "user_account_move_log"`);
}
}
39 changes: 38 additions & 1 deletion packages/backend/src/core/AccountMoveService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { bindThis } from '@/decorators.js';
import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js';
import type { MiLocalUser, MiRemoteUser, MiUser } from '@/models/User.js';
import type { BlockingsRepository, FollowingsRepository, InstancesRepository, MutingsRepository, UserListMembershipsRepository, UsersRepository } from '@/models/_.js';
import type { BlockingsRepository, FollowingsRepository, InstancesRepository, MutingsRepository, UserListMembershipsRepository, UserAccountMoveLogRepository, UserProfilesRepository, UsersRepository } from '@/models/_.js';
import type { RelationshipJobData, ThinUser } from '@/queue/types.js';

import { IdService } from '@/core/IdService.js';
Expand Down Expand Up @@ -48,6 +48,15 @@ export class AccountMoveService {
@Inject(DI.instancesRepository)
private instancesRepository: InstancesRepository,

@Inject(DI.userProfilesRepository)
private userProfilesRepository: UserProfilesRepository,

@Inject(DI.userAccountMoveLogRepository)
private userAccountMoveLogRepository: UserAccountMoveLogRepository,

@Inject(DI.config)
private config: Config,

private userEntityService: UserEntityService,
private idService: IdService,
private apPersonService: ApPersonService,
Expand Down Expand Up @@ -119,6 +128,8 @@ export class AccountMoveService {
this.copyBlocking(src, dst),
this.copyMutings(src, dst),
this.updateLists(src, dst),
this.mergeModerationNote(src, dst),
this.insertAccountMoveLog(src, dst),
]);
} catch {
/* skip if any error happens */
Expand Down Expand Up @@ -256,6 +267,32 @@ export class AccountMoveService {
}
}

@bindThis
private async mergeModerationNote(src: ThinUser, dst: MiUser): Promise<void> {
const srcprofile = await this.userProfilesRepository.findOneBy({ userId: src.id });
const dstprofile = await this.userProfilesRepository.findOneBy({ userId: dst.id });

if (!srcprofile || !dstprofile) return;

await this.userProfilesRepository.update({ userId: dst.id }, {
moderationNote: srcprofile.moderationNote + '\n' + dstprofile.moderationNote,
});

await this.userProfilesRepository.update({ userId: src.id }, {
moderationNote: srcprofile.moderationNote + '\n' + dstprofile.moderationNote,
});
}

@bindThis
private async insertAccountMoveLog(src: ThinUser, dst: MiUser): Promise<void> {
await this.userAccountMoveLogRepository.insert({
id: this.idService.gen(),
movedToId: dst.id,
movedFromId: src.id,
createdAt: new Date(),
});
}

@bindThis
private async adjustFollowingCounts(localFollowerIds: string[], oldAccount: MiUser): Promise<void> {
if (localFollowerIds.length === 0) return;
Expand Down
13 changes: 8 additions & 5 deletions packages/backend/src/core/AntennaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,14 @@ export class AntennaService implements OnApplicationShutdown {
if (antenna.src === 'home') {
// TODO
} else if (antenna.src === 'list') {
const listUsers = (await this.userListMembershipsRepository.findBy({
userListId: antenna.userListId!,
})).map(x => x.userId);

if (!listUsers.includes(note.userId)) return false;
if (antenna.userListId == null) return false;
const exists = await this.userListMembershipsRepository.exists({
where: {
userListId: antenna.userListId,
userId: note.userId,
},
});
if (!exists) return false;
} else if (antenna.src === 'users') {
const accts = antenna.users.map(x => {
const { username, host } = Acct.parse(x);
Expand Down
6 changes: 6 additions & 0 deletions packages/backend/src/core/CoreModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import { HashtagEntityService } from './entities/HashtagEntityService.js';
import { InstanceEntityService } from './entities/InstanceEntityService.js';
import { InviteCodeEntityService } from './entities/InviteCodeEntityService.js';
import { ModerationLogEntityService } from './entities/ModerationLogEntityService.js';
import { UserAccountMoveLogEntityService } from './entities/UserAccountMoveLogEntityService.js';
import { MutingEntityService } from './entities/MutingEntityService.js';
import { RenoteMutingEntityService } from './entities/RenoteMutingEntityService.js';
import { NoteEntityService } from './entities/NoteEntityService.js';
Expand Down Expand Up @@ -242,6 +243,7 @@ const $HashtagEntityService: Provider = { provide: 'HashtagEntityService', useEx
const $InstanceEntityService: Provider = { provide: 'InstanceEntityService', useExisting: InstanceEntityService };
const $InviteCodeEntityService: Provider = { provide: 'InviteCodeEntityService', useExisting: InviteCodeEntityService };
const $ModerationLogEntityService: Provider = { provide: 'ModerationLogEntityService', useExisting: ModerationLogEntityService };
const $UserAccountMoveLogEntityService: Provider = { provide: 'UserAccountMoveLogEntityService', useExisting: UserAccountMoveLogEntityService };
const $MutingEntityService: Provider = { provide: 'MutingEntityService', useExisting: MutingEntityService };
const $RenoteMutingEntityService: Provider = { provide: 'RenoteMutingEntityService', useExisting: RenoteMutingEntityService };
const $NoteEntityService: Provider = { provide: 'NoteEntityService', useExisting: NoteEntityService };
Expand Down Expand Up @@ -382,6 +384,7 @@ const $ApQuestionService: Provider = { provide: 'ApQuestionService', useExisting
InstanceEntityService,
InviteCodeEntityService,
ModerationLogEntityService,
UserAccountMoveLogEntityService,
MutingEntityService,
RenoteMutingEntityService,
NoteEntityService,
Expand Down Expand Up @@ -518,6 +521,7 @@ const $ApQuestionService: Provider = { provide: 'ApQuestionService', useExisting
$InstanceEntityService,
$InviteCodeEntityService,
$ModerationLogEntityService,
$UserAccountMoveLogEntityService,
$MutingEntityService,
$RenoteMutingEntityService,
$NoteEntityService,
Expand Down Expand Up @@ -654,6 +658,7 @@ const $ApQuestionService: Provider = { provide: 'ApQuestionService', useExisting
InstanceEntityService,
InviteCodeEntityService,
ModerationLogEntityService,
UserAccountMoveLogEntityService,
MutingEntityService,
RenoteMutingEntityService,
NoteEntityService,
Expand Down Expand Up @@ -789,6 +794,7 @@ const $ApQuestionService: Provider = { provide: 'ApQuestionService', useExisting
$InstanceEntityService,
$InviteCodeEntityService,
$ModerationLogEntityService,
$UserAccountMoveLogEntityService,
$MutingEntityService,
$RenoteMutingEntityService,
$NoteEntityService,
Expand Down
22 changes: 18 additions & 4 deletions packages/backend/src/core/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { isReply } from '@/misc/is-reply.js';
import { trackPromise } from '@/misc/promise-tracker.js';
import { isNotNull } from '@/misc/is-not-null.js';
import { IdentifiableError } from '@/misc/identifiable-error.js';
import { CollapsedQueue } from '@/misc/collapsed-queue.js';

type NotificationType = 'reply' | 'renote' | 'quote' | 'mention';

Expand Down Expand Up @@ -150,6 +151,7 @@ type Option = {
export class NoteCreateService implements OnApplicationShutdown {
private logger: Logger;
#shutdownController = new AbortController();
private updateNotesCountQueue: CollapsedQueue<MiNote['id'], number>;

constructor(
@Inject(DI.config)
Expand Down Expand Up @@ -217,6 +219,7 @@ export class NoteCreateService implements OnApplicationShutdown {
private loggerService: LoggerService,
) {
this.logger = this.loggerService.getLogger('note:create');
this.updateNotesCountQueue = new CollapsedQueue(60 * 1000 * 5, this.collapseNotesCount, this.performUpdateNotesCount);
}

@bindThis
Expand Down Expand Up @@ -548,7 +551,7 @@ export class NoteCreateService implements OnApplicationShutdown {
// Register host
if (this.userEntityService.isRemoteUser(user)) {
this.federatedInstanceService.fetch(user.host).then(async i => {
this.instancesRepository.increment({ id: i.id }, 'notesCount', 1);
this.updateNotesCountQueue.enqueue(i.id, 1);
if ((await this.metaService.fetch()).enableChartsForFederatedInstances) {
this.instanceChart.updateNote(i.host, note, true);
}
Expand Down Expand Up @@ -1093,12 +1096,23 @@ export class NoteCreateService implements OnApplicationShutdown {
}

@bindThis
public dispose(): void {
private collapseNotesCount(oldValue: number, newValue: number) {
return oldValue + newValue;
}

@bindThis
private async performUpdateNotesCount(id: MiNote['id'], incrBy: number) {
await this.instancesRepository.increment({ id: id }, 'notesCount', incrBy);
}

@bindThis
public async dispose(): Promise<void> {
this.#shutdownController.abort();
await this.updateNotesCountQueue.performAllNow();
}

@bindThis
public onApplicationShutdown(signal?: string | undefined): void {
this.dispose();
public async onApplicationShutdown(signal?: string | undefined): Promise<void> {
await this.dispose();
}
}
16 changes: 12 additions & 4 deletions packages/backend/src/core/SearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export class SearchService {
if (note.text == null && note.cw == null) return;
if (!['home', 'public'].includes(note.visibility)) return;

const createdAt = this.idService.parse(note.id).date;
if (this.meilisearch) {
switch (this.meilisearchIndexScope) {
case 'global':
Expand All @@ -190,7 +191,7 @@ export class SearchService {

await this.meilisearchNoteIndex?.addDocuments([{
id: note.id,
createdAt: this.idService.parse(note.id).date.getTime(),
createdAt: createdAt.getTime(),
userId: note.userId,
userHost: note.userHost,
channelId: note.channelId,
Expand All @@ -202,7 +203,7 @@ export class SearchService {
});
} else if (this.elasticsearch) {
const body = {
createdAt: this.idService.parse(note.id).date.getTime(),
createdAt: createdAt.getTime(),
userId: note.userId,
userHost: note.userHost,
channelId: note.channelId,
Expand All @@ -211,11 +212,11 @@ export class SearchService {
tags: note.tags,
};
await this.elasticsearch.index({
index: this.elasticsearchNoteIndex + `-${new Date().toISOString().slice(0, 7).replace(/-/g, '')}` as string,
index: `${this.elasticsearchNoteIndex}-${createdAt.toISOString().slice(0, 7).replace(/-/g, '')}`,
id: note.id,
body: body,
}).catch((error) => {
console.error(error);
this.logger.error(error);
});
}
}
Expand All @@ -226,6 +227,13 @@ export class SearchService {

if (this.meilisearch) {
this.meilisearchNoteIndex!.deleteDocument(note.id);
} else if (this.elasticsearch) {
await this.elasticsearch.delete({
index: `${this.elasticsearchNoteIndex}-${this.idService.parse(note.id).date.toISOString().slice(0, 7).replace(/-/g, '')}`,
id: note.id,
}).catch((error) => {
this.logger.error(error);
});
}
}

Expand Down
Loading

0 comments on commit 5f2c250

Please sign in to comment.