mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-25 03:35:12 +00:00
parent
eb5781465b
commit
54630edb0f
9 changed files with 59 additions and 4 deletions
|
@ -22,6 +22,7 @@
|
|||
- ロールの並び順を設定可能に
|
||||
- カスタム絵文字にライセンス情報を付与できるように
|
||||
- 指定した文字列を含む投稿の公開範囲をホームにできるように
|
||||
- 使われてないアンテナは自動停止されるように
|
||||
|
||||
### Client
|
||||
- 設定から自分のロールを確認できるように
|
||||
|
|
17
packages/backend/migration/1679309757174-antenna-active.js
Normal file
17
packages/backend/migration/1679309757174-antenna-active.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
export class antennaActive1679309757174 {
|
||||
name = 'antennaActive1679309757174'
|
||||
|
||||
async up(queryRunner) {
|
||||
await queryRunner.query(`ALTER TABLE "antenna" ADD "lastUsedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT 'now'`);
|
||||
await queryRunner.query(`ALTER TABLE "antenna" ADD "isActive" boolean NOT NULL DEFAULT true`);
|
||||
await queryRunner.query(`CREATE INDEX "IDX_084c2abb8948ef59a37dce6ac1" ON "antenna" ("lastUsedAt") `);
|
||||
await queryRunner.query(`CREATE INDEX "IDX_36ef5192a1ce55ed0e40aa4db5" ON "antenna" ("isActive") `);
|
||||
}
|
||||
|
||||
async down(queryRunner) {
|
||||
await queryRunner.query(`DROP INDEX "public"."IDX_36ef5192a1ce55ed0e40aa4db5"`);
|
||||
await queryRunner.query(`DROP INDEX "public"."IDX_084c2abb8948ef59a37dce6ac1"`);
|
||||
await queryRunner.query(`ALTER TABLE "antenna" DROP COLUMN "isActive"`);
|
||||
await queryRunner.query(`ALTER TABLE "antenna" DROP COLUMN "lastUsedAt"`);
|
||||
}
|
||||
}
|
|
@ -71,12 +71,14 @@ export class AntennaService implements OnApplicationShutdown {
|
|||
this.antennas.push({
|
||||
...body,
|
||||
createdAt: new Date(body.createdAt),
|
||||
lastUsedAt: new Date(body.lastUsedAt),
|
||||
});
|
||||
break;
|
||||
case 'antennaUpdated':
|
||||
this.antennas[this.antennas.findIndex(a => a.id === body.id)] = {
|
||||
...body,
|
||||
createdAt: new Date(body.createdAt),
|
||||
lastUsedAt: new Date(body.lastUsedAt),
|
||||
};
|
||||
break;
|
||||
case 'antennaDeleted':
|
||||
|
@ -217,7 +219,9 @@ export class AntennaService implements OnApplicationShutdown {
|
|||
@bindThis
|
||||
public async getAntennas() {
|
||||
if (!this.antennasFetched) {
|
||||
this.antennas = await this.antennasRepository.find();
|
||||
this.antennas = await this.antennasRepository.findBy({
|
||||
isActive: true,
|
||||
});
|
||||
this.antennasFetched = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ export class AntennaEntityService {
|
|||
notify: antenna.notify,
|
||||
withReplies: antenna.withReplies,
|
||||
withFile: antenna.withFile,
|
||||
isActive: antenna.isActive,
|
||||
hasUnreadNote,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -13,6 +13,10 @@ export class Antenna {
|
|||
})
|
||||
public createdAt: Date;
|
||||
|
||||
@Index()
|
||||
@Column('timestamp with time zone')
|
||||
public lastUsedAt: Date;
|
||||
|
||||
@Index()
|
||||
@Column({
|
||||
...id(),
|
||||
|
@ -83,4 +87,10 @@ export class Antenna {
|
|||
|
||||
@Column('boolean')
|
||||
public notify: boolean;
|
||||
|
||||
@Index()
|
||||
@Column('boolean', {
|
||||
default: true,
|
||||
})
|
||||
public isActive: boolean;
|
||||
}
|
||||
|
|
|
@ -75,6 +75,10 @@ export const packedAntennaSchema = {
|
|||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
isActive: {
|
||||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
hasUnreadNote: {
|
||||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { In, LessThan } from 'typeorm';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import type { AntennaNotesRepository, MutedNotesRepository, NotificationsRepository, RoleAssignmentsRepository, UserIpsRepository } from '@/models/index.js';
|
||||
import type { AntennaNotesRepository, AntennasRepository, MutedNotesRepository, NotificationsRepository, RoleAssignmentsRepository, UserIpsRepository } from '@/models/index.js';
|
||||
import type { Config } from '@/config.js';
|
||||
import type Logger from '@/logger.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
@ -26,6 +26,9 @@ export class CleanProcessorService {
|
|||
@Inject(DI.mutedNotesRepository)
|
||||
private mutedNotesRepository: MutedNotesRepository,
|
||||
|
||||
@Inject(DI.antennasRepository)
|
||||
private antennasRepository: AntennasRepository,
|
||||
|
||||
@Inject(DI.antennaNotesRepository)
|
||||
private antennaNotesRepository: AntennaNotesRepository,
|
||||
|
||||
|
@ -55,8 +58,16 @@ export class CleanProcessorService {
|
|||
reason: 'word',
|
||||
});
|
||||
|
||||
this.antennaNotesRepository.delete({
|
||||
this.mutedNotesRepository.delete({
|
||||
id: LessThan(this.idService.genId(new Date(Date.now() - (1000 * 60 * 60 * 24 * 90)))),
|
||||
reason: 'word',
|
||||
});
|
||||
|
||||
// 7日以上使われてないアンテナを停止
|
||||
this.antennasRepository.update({
|
||||
lastUsedAt: LessThan(new Date(Date.now() - (1000 * 60 * 60 * 24 * 7))),
|
||||
}, {
|
||||
isActive: false,
|
||||
});
|
||||
|
||||
const expiredRoleAssignments = await this.roleAssignmentsRepository.createQueryBuilder('assign')
|
||||
|
|
|
@ -103,9 +103,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
}
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
|
||||
const antenna = await this.antennasRepository.insert({
|
||||
id: this.idService.genId(),
|
||||
createdAt: new Date(),
|
||||
createdAt: now,
|
||||
lastUsedAt: now,
|
||||
userId: me.id,
|
||||
name: ps.name,
|
||||
src: ps.src,
|
||||
|
|
|
@ -101,6 +101,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
this.noteReadService.read(me.id, notes);
|
||||
}
|
||||
|
||||
this.antennasRepository.update(antenna.id, {
|
||||
lastUsedAt: new Date(),
|
||||
});
|
||||
|
||||
return await this.noteEntityService.packMany(notes, me);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue