Merge tag '2023.10.2' into merge-upstream
This commit is contained in:
commit
78835eac52
282 changed files with 4676 additions and 4314 deletions
|
@ -21,7 +21,7 @@ import { IdService } from '@/core/IdService.js';
|
|||
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
||||
import { ModerationLogService } from '@/core/ModerationLogService.js';
|
||||
import type { Packed } from '@/misc/json-schema.js';
|
||||
import { RedisTimelineService } from '@/core/RedisTimelineService.js';
|
||||
import { FunoutTimelineService } from '@/core/FunoutTimelineService.js';
|
||||
import type { OnApplicationShutdown } from '@nestjs/common';
|
||||
|
||||
export type RolePolicies = {
|
||||
|
@ -107,7 +107,7 @@ export class RoleService implements OnApplicationShutdown {
|
|||
private globalEventService: GlobalEventService,
|
||||
private idService: IdService,
|
||||
private moderationLogService: ModerationLogService,
|
||||
private redisTimelineService: RedisTimelineService,
|
||||
private funoutTimelineService: FunoutTimelineService,
|
||||
) {
|
||||
//this.onMessage = this.onMessage.bind(this);
|
||||
|
||||
|
@ -129,7 +129,6 @@ export class RoleService implements OnApplicationShutdown {
|
|||
if (cached) {
|
||||
cached.push({
|
||||
...body,
|
||||
createdAt: new Date(body.createdAt),
|
||||
updatedAt: new Date(body.updatedAt),
|
||||
lastUsedAt: new Date(body.lastUsedAt),
|
||||
});
|
||||
|
@ -143,7 +142,6 @@ export class RoleService implements OnApplicationShutdown {
|
|||
if (i > -1) {
|
||||
cached[i] = {
|
||||
...body,
|
||||
createdAt: new Date(body.createdAt),
|
||||
updatedAt: new Date(body.updatedAt),
|
||||
lastUsedAt: new Date(body.lastUsedAt),
|
||||
};
|
||||
|
@ -163,7 +161,6 @@ export class RoleService implements OnApplicationShutdown {
|
|||
if (cached) {
|
||||
cached.push({
|
||||
...body,
|
||||
createdAt: new Date(body.createdAt),
|
||||
expiresAt: body.expiresAt ? new Date(body.expiresAt) : null,
|
||||
});
|
||||
}
|
||||
|
@ -202,10 +199,10 @@ export class RoleService implements OnApplicationShutdown {
|
|||
return this.userEntityService.isRemoteUser(user);
|
||||
}
|
||||
case 'createdLessThan': {
|
||||
return user.createdAt.getTime() > (Date.now() - (value.sec * 1000));
|
||||
return this.idService.parse(user.id).date.getTime() > (Date.now() - (value.sec * 1000));
|
||||
}
|
||||
case 'createdMoreThan': {
|
||||
return user.createdAt.getTime() < (Date.now() - (value.sec * 1000));
|
||||
return this.idService.parse(user.id).date.getTime() < (Date.now() - (value.sec * 1000));
|
||||
}
|
||||
case 'followersLessThanOrEq': {
|
||||
return user.followersCount <= value.value;
|
||||
|
@ -389,7 +386,7 @@ export class RoleService implements OnApplicationShutdown {
|
|||
|
||||
@bindThis
|
||||
public async assign(userId: MiUser['id'], roleId: MiRole['id'], expiresAt: Date | null = null, moderator?: MiUser): Promise<void> {
|
||||
const now = new Date();
|
||||
const now = Date.now();
|
||||
|
||||
const role = await this.rolesRepository.findOneByOrFail({ id: roleId });
|
||||
|
||||
|
@ -398,7 +395,7 @@ export class RoleService implements OnApplicationShutdown {
|
|||
userId: userId,
|
||||
});
|
||||
|
||||
if (existing?.expiresAt && (existing.expiresAt.getTime() < now.getTime())) {
|
||||
if (existing?.expiresAt && (existing.expiresAt.getTime() < now)) {
|
||||
await this.roleAssignmentsRepository.delete({
|
||||
roleId: roleId,
|
||||
userId: userId,
|
||||
|
@ -408,8 +405,7 @@ export class RoleService implements OnApplicationShutdown {
|
|||
|
||||
if (!existing) {
|
||||
const created = await this.roleAssignmentsRepository.insert({
|
||||
id: this.idService.genId(),
|
||||
createdAt: now,
|
||||
id: this.idService.gen(now),
|
||||
expiresAt: expiresAt,
|
||||
roleId: roleId,
|
||||
userId: userId,
|
||||
|
@ -488,7 +484,7 @@ export class RoleService implements OnApplicationShutdown {
|
|||
const redisPipeline = this.redisClient.pipeline();
|
||||
|
||||
for (const role of roles) {
|
||||
this.redisTimelineService.push(`roleTimeline:${role.id}`, note.id, 1000, redisPipeline);
|
||||
this.funoutTimelineService.push(`roleTimeline:${role.id}`, note.id, 1000, redisPipeline);
|
||||
this.globalEventService.publishRoleTimelineStream(role.id, 'note', note);
|
||||
}
|
||||
|
||||
|
@ -499,8 +495,7 @@ export class RoleService implements OnApplicationShutdown {
|
|||
public async create(values: Partial<MiRole>, moderator?: MiUser): Promise<MiRole> {
|
||||
const date = new Date();
|
||||
const created = await this.rolesRepository.insert({
|
||||
id: this.idService.genId(),
|
||||
createdAt: date,
|
||||
id: this.idService.gen(date.getTime()),
|
||||
updatedAt: date,
|
||||
lastUsedAt: date,
|
||||
name: values.name,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue