Skip to content

Commit

Permalink
Merge remote-branch 'misskey/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
noridev committed Jul 14, 2023
1 parent 86d8b61 commit 8383d9c
Show file tree
Hide file tree
Showing 43 changed files with 157 additions and 153 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- フォルダーやファイルに対しても開発者モード使用時、IDをコピーできるように
- 引用対象を「もっと見る」で展開した場合、「閉じる」で畳めるように
- プロフィールURLをコピーできるボタンを追加 #11190
- `CURRENT_URL`で現在表示中のURLを取得できるように(AiScript)
- ユーザーのContextMenuに「アンテナに追加」ボタンを追加
- フォローやお気に入り登録をしていないチャンネルを開く時は概要ページを開くように
- 画面ビューワをタップした場合、マウスクリックと同様に画像ビューワを閉じるように
Expand Down
134 changes: 67 additions & 67 deletions packages/backend/src/core/activitypub/ApDeliverManagerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,73 +29,6 @@ const isFollowers = (recipe: IRecipe): recipe is IFollowersRecipe =>
const isDirect = (recipe: IRecipe): recipe is IDirectRecipe =>
recipe.type === 'Direct';

@Injectable()
export class ApDeliverManagerService {
constructor(
@Inject(DI.config)
private config: Config,

@Inject(DI.usersRepository)
private usersRepository: UsersRepository,

@Inject(DI.followingsRepository)
private followingsRepository: FollowingsRepository,

private userEntityService: UserEntityService,
private queueService: QueueService,
) {
}

/**
* Deliver activity to followers
* @param actor
* @param activity Activity
*/
@bindThis
public async deliverToFollowers(actor: { id: LocalUser['id']; host: null; }, activity: IActivity): Promise<void> {
const manager = new DeliverManager(
this.userEntityService,
this.followingsRepository,
this.queueService,
actor,
activity,
);
manager.addFollowersRecipe();
await manager.execute();
}

/**
* Deliver activity to user
* @param actor
* @param activity Activity
* @param to Target user
*/
@bindThis
public async deliverToUser(actor: { id: LocalUser['id']; host: null; }, activity: IActivity, to: RemoteUser): Promise<void> {
const manager = new DeliverManager(
this.userEntityService,
this.followingsRepository,
this.queueService,
actor,
activity,
);
manager.addDirectRecipe(to);
await manager.execute();
}

@bindThis
public createDeliverManager(actor: { id: User['id']; host: null; }, activity: IActivity | null): DeliverManager {
return new DeliverManager(
this.userEntityService,
this.followingsRepository,
this.queueService,

actor,
activity,
);
}
}

class DeliverManager {
private actor: ThinUser;
private activity: IActivity | null;
Expand Down Expand Up @@ -210,3 +143,70 @@ class DeliverManager {
this.queueService.deliverMany(this.actor, this.activity, inboxes);
}
}

@Injectable()
export class ApDeliverManagerService {
constructor(
@Inject(DI.config)
private config: Config,

@Inject(DI.usersRepository)
private usersRepository: UsersRepository,

@Inject(DI.followingsRepository)
private followingsRepository: FollowingsRepository,

private userEntityService: UserEntityService,
private queueService: QueueService,
) {
}

/**
* Deliver activity to followers
* @param actor
* @param activity Activity
*/
@bindThis
public async deliverToFollowers(actor: { id: LocalUser['id']; host: null; }, activity: IActivity): Promise<void> {
const manager = new DeliverManager(
this.userEntityService,
this.followingsRepository,
this.queueService,
actor,
activity,
);
manager.addFollowersRecipe();
await manager.execute();
}

/**
* Deliver activity to user
* @param actor
* @param activity Activity
* @param to Target user
*/
@bindThis
public async deliverToUser(actor: { id: LocalUser['id']; host: null; }, activity: IActivity, to: RemoteUser): Promise<void> {
const manager = new DeliverManager(
this.userEntityService,
this.followingsRepository,
this.queueService,
actor,
activity,
);
manager.addDirectRecipe(to);
await manager.execute();
}

@bindThis
public createDeliverManager(actor: { id: User['id']; host: null; }, activity: IActivity | null): DeliverManager {
return new DeliverManager(
this.userEntityService,
this.followingsRepository,
this.queueService,

actor,
activity,
);
}
}
4 changes: 2 additions & 2 deletions packages/backend/src/core/chart/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export default abstract class Chart<T extends Schema> {
private convertRawRecord(x: RawRecord<T>): KVs<T> {
const kvs = {} as Record<string, number>;
for (const k of Object.keys(x).filter((k) => k.startsWith(COLUMN_PREFIX)) as (keyof Columns<T>)[]) {
kvs[(k as string).substr(COLUMN_PREFIX.length).split(COLUMN_DELIMITER).join('.')] = x[k] as unknown as number;
kvs[(k as string).substring(COLUMN_PREFIX.length).split(COLUMN_DELIMITER).join('.')] = x[k] as unknown as number;
}
return kvs as KVs<T>;
}
Expand Down Expand Up @@ -627,7 +627,7 @@ export default abstract class Chart<T extends Schema> {
}

// 要求された範囲の最も古い箇所に位置するログが存在しなかったら
} else if (!isTimeSame(new Date(logs[logs.length - 1].date * 1000), gt)) {
} else if (!isTimeSame(new Date(logs.at(-1)!.date * 1000), gt)) {
// 要求された範囲の最も古い箇所時点での最も新しいログを持ってきて末尾に追加する
// (隙間埋めできないため)
const outdatedLog = await repository.findOne({
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/misc/acct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type Acct = {
};

export function parse(acct: string): Acct {
if (acct.startsWith('@')) acct = acct.substr(1);
if (acct.startsWith('@')) acct = acct.substring(1);
const split = acct.split('@', 2);
return { username: split[0], host: split[1] ?? null };
}
Expand Down
5 changes: 3 additions & 2 deletions packages/backend/src/misc/prelude/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ export function maximum(xs: number[]): number {
export function groupBy<T>(f: EndoRelation<T>, xs: T[]): T[][] {
const groups = [] as T[][];
for (const x of xs) {
if (groups.length !== 0 && f(groups[groups.length - 1][0], x)) {
groups[groups.length - 1].push(x);
const lastGroup = groups.at(-1);
if (lastGroup !== undefined && f(lastGroup[0], x)) {
lastGroup.push(x);
} else {
groups.push([x]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Inject, Injectable } from '@nestjs/common';
import { IsNull, MoreThan, Not } from 'typeorm';
import { DI } from '@/di-symbols.js';
import type { DriveFilesRepository } from '@/models/index.js';
import type { DriveFile, DriveFilesRepository } from '@/models/index.js';
import type { Config } from '@/config.js';
import type Logger from '@/logger.js';
import { DriveService } from '@/core/DriveService.js';
Expand Down Expand Up @@ -31,7 +31,7 @@ export class CleanRemoteFilesProcessorService {
this.logger.info('Deleting cached remote files...');

let deletedCount = 0;
let cursor: any = null;
let cursor: DriveFile['id'] | null = null;

while (true) {
const files = await this.driveFilesRepository.find({
Expand All @@ -51,7 +51,7 @@ export class CleanRemoteFilesProcessorService {
break;
}

cursor = files[files.length - 1].id;
cursor = files.at(-1)?.id ?? null;

await Promise.all(files.map(file => this.driveService.deleteFileSync(file, true)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class DeleteAccountProcessorService {
break;
}

cursor = notes[notes.length - 1].id;
cursor = notes.at(-1)?.id ?? null;

await this.notesRepository.delete(notes.map(note => note.id));

Expand Down Expand Up @@ -101,7 +101,7 @@ export class DeleteAccountProcessorService {
break;
}

cursor = files[files.length - 1].id;
cursor = files.at(-1)?.id ?? null;

for (const file of files) {
await this.driveService.deleteFileSync(file);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Inject, Injectable } from '@nestjs/common';
import { MoreThan } from 'typeorm';
import { DI } from '@/di-symbols.js';
import type { UsersRepository, DriveFilesRepository } from '@/models/index.js';
import type { UsersRepository, DriveFilesRepository, DriveFile } from '@/models/index.js';
import type { Config } from '@/config.js';
import type Logger from '@/logger.js';
import { DriveService } from '@/core/DriveService.js';
Expand Down Expand Up @@ -40,7 +40,7 @@ export class DeleteDriveFilesProcessorService {
}

let deletedCount = 0;
let cursor: any = null;
let cursor: DriveFile['id'] | null = null;

while (true) {
const files = await this.driveFilesRepository.find({
Expand All @@ -59,7 +59,7 @@ export class DeleteDriveFilesProcessorService {
break;
}

cursor = files[files.length - 1].id;
cursor = files.at(-1)?.id ?? null;

for (const file of files) {
await this.driveService.deleteFileSync(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Inject, Injectable } from '@nestjs/common';
import { MoreThan } from 'typeorm';
import { format as dateFormat } from 'date-fns';
import { DI } from '@/di-symbols.js';
import type { UsersRepository, BlockingsRepository } from '@/models/index.js';
import type { UsersRepository, BlockingsRepository, Blocking } from '@/models/index.js';
import type { Config } from '@/config.js';
import type Logger from '@/logger.js';
import { DriveService } from '@/core/DriveService.js';
Expand Down Expand Up @@ -53,7 +53,7 @@ export class ExportBlockingProcessorService {
const stream = fs.createWriteStream(path, { flags: 'a' });

let exportedCount = 0;
let cursor: any = null;
let cursor: Blocking['id'] | null = null;

while (true) {
const blockings = await this.blockingsRepository.find({
Expand All @@ -72,7 +72,7 @@ export class ExportBlockingProcessorService {
break;
}

cursor = blockings[blockings.length - 1].id;
cursor = blockings.at(-1)?.id ?? null;

for (const block of blockings) {
const u = await this.usersRepository.findOneBy({ id: block.blockeeId });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class ExportFavoritesProcessorService {
break;
}

cursor = favorites[favorites.length - 1].id;
cursor = favorites.at(-1)?.id ?? null;

for (const favorite of favorites) {
let poll: Poll | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class ExportFollowingProcessorService {
break;
}

cursor = followings[followings.length - 1].id;
cursor = followings.at(-1)?.id ?? null;

for (const following of followings) {
const u = await this.usersRepository.findOneBy({ id: following.followeeId });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Inject, Injectable } from '@nestjs/common';
import { IsNull, MoreThan } from 'typeorm';
import { format as dateFormat } from 'date-fns';
import { DI } from '@/di-symbols.js';
import type { MutingsRepository, UsersRepository, BlockingsRepository } from '@/models/index.js';
import type { MutingsRepository, UsersRepository, BlockingsRepository, Muting } from '@/models/index.js';
import type { Config } from '@/config.js';
import type Logger from '@/logger.js';
import { DriveService } from '@/core/DriveService.js';
Expand Down Expand Up @@ -56,7 +56,7 @@ export class ExportMutingProcessorService {
const stream = fs.createWriteStream(path, { flags: 'a' });

let exportedCount = 0;
let cursor: any = null;
let cursor: Muting['id'] | null = null;

while (true) {
const mutes = await this.mutingsRepository.find({
Expand All @@ -76,7 +76,7 @@ export class ExportMutingProcessorService {
break;
}

cursor = mutes[mutes.length - 1].id;
cursor = mutes.at(-1)?.id ?? null;

for (const mute of mutes) {
const u = await this.usersRepository.findOneBy({ id: mute.muteeId });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class ExportNotesProcessorService {
break;
}

cursor = notes[notes.length - 1].id;
cursor = notes.at(-1)?.id ?? null;

for (const note of notes) {
let poll: Poll | undefined;
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/server/ActivityPubServerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class ActivityPubServerService {
undefined,
inStock ? `${partOf}?${url.query({
page: 'true',
cursor: followings[followings.length - 1].id,
cursor: followings.at(-1)!.id,
})}` : undefined,
);

Expand Down Expand Up @@ -273,7 +273,7 @@ export class ActivityPubServerService {
undefined,
inStock ? `${partOf}?${url.query({
page: 'true',
cursor: followings[followings.length - 1].id,
cursor: followings.at(-1)!.id,
})}` : undefined,
);

Expand Down Expand Up @@ -398,7 +398,7 @@ export class ActivityPubServerService {
})}` : undefined,
notes.length ? `${partOf}?${url.query({
page: 'true',
until_id: notes[notes.length - 1].id,
until_id: notes.at(-1)!.id,
})}` : undefined,
);

Expand Down
Loading

0 comments on commit 8383d9c

Please sign in to comment.