Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
samunohito committed Oct 10, 2024
1 parent 346074c commit 02ca448
Showing 1 changed file with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ export class CheckModeratorsActivityProcessorService {
if (isModeratorsInactive) {
this.logger.warn(`The moderator has been inactive for ${MODERATOR_INACTIVITY_LIMIT_DAYS} days. We will move to invitation only.`);
await this.changeToInvitationOnly();

// TODO: モデレータに通知メール+Misskey通知
// TODO: SystemWebhook通知
} else {
if (inactivityLimitCountdown <= 2) {
this.logger.warn(`A moderator has been inactive for a period of time. If you are inactive for an additional ${inactivityLimitCountdown} days, it will switch to invitation only.`);

// TODO: 警告メール
}
}
}
Expand All @@ -67,7 +72,7 @@ export class CheckModeratorsActivityProcessorService {
*
* #### パターン①
* - モデレータA: lastActiveDate = 2022-01-20 00:00:00 ※アウト
* - モデレータB: lastActiveDate = 2022-01-23 12:00:00 ※セーフ(ギリギリ残り0日
* - モデレータB: lastActiveDate = 2022-01-23 12:00:00 ※セーフ(判定基準と同値なのでギリギリ残り0日
* - モデレータC: lastActiveDate = 2022-01-23 11:59:59 ※アウト(残り-1日)
* - モデレータD: lastActiveDate = null
*
Expand All @@ -77,7 +82,7 @@ export class CheckModeratorsActivityProcessorService {
* - モデレータA: lastActiveDate = 2022-01-20 00:00:00 ※アウト
* - モデレータB: lastActiveDate = 2022-01-22 12:00:00 ※アウト(残り-1日)
* - モデレータC: lastActiveDate = 2022-01-23 11:59:59 ※アウト(残り-1日)
* - モデレータC: lastActiveDate = null
* - モデレータD: lastActiveDate = null
*
* この場合、モデレータA, B, Cのアクティビティは判定基準日よりも古いため、モデレーターが不在と判断される。
*/
Expand All @@ -88,25 +93,28 @@ export class CheckModeratorsActivityProcessorService {
inactivePeriod.setDate(today.getDate() - MODERATOR_INACTIVITY_LIMIT_DAYS);

// TODO: モデレーター以外にも特別な権限を持つユーザーがいる場合は考慮する
const moderators = await this.roleService.getModerators({
includeAdmins: true,
includeRoot: true,
excludeExpire: true,
});
const inactiveModeratorCount = moderators
.map(it => it.lastActiveDate)
.filter(it => it != null)
.filter(it => it.getTime() < inactivePeriod.getTime())
.length;
const moderators = await this.fetchModerators();
const inactiveModerators = moderators
.filter(it => it.lastActiveDate != null && it.lastActiveDate.getTime() < inactivePeriod.getTime());

return {
isModeratorsInactive: inactiveModeratorCount !== moderators.length,
isModeratorsInactive: inactiveModerators.length !== moderators.length,
inactiveModerators,
inactivityLimitCountdown: MODERATOR_INACTIVITY_LIMIT_DAYS - Math.floor((today.getTime() - inactivePeriod.getTime()) / ONE_DAY_MILLI_SEC),
};
}

@bindThis
public async changeToInvitationOnly() {
private async changeToInvitationOnly() {
await this.metaService.update({ disableRegistration: true });
}

@bindThis
private async fetchModerators() {
return this.roleService.getModerators({
includeAdmins: true,
includeRoot: true,
excludeExpire: true,
});
}
}

0 comments on commit 02ca448

Please sign in to comment.