Skip to content

Commit cd7f727

Browse files
authored
enhance: 新しいコンディショナルロール条件の実装 (misskey-dev#13732)
* enhance: 新しいコンディショナルロールの実装 * fix: CHANGELOG.md
1 parent ea9aa6f commit cd7f727

File tree

12 files changed

+617
-67
lines changed

12 files changed

+617
-67
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
- Enhance: アンテナでBotによるノートを除外できるように
99
(Cherry-picked from https://github.com/MisskeyIO/misskey/pull/545)
1010
- Enhance: クリップのノート数を表示するように
11+
- Enhance: コンディショナルロールの条件として以下を新たに追加 (#13667)
12+
- 猫ユーザーか
13+
- botユーザーか
14+
- サスペンド済みユーザーか
15+
- 鍵アカウントユーザーか
16+
- 「アカウントを見つけやすくする」が有効なユーザーか
1117
- Fix: Play作成時に設定した公開範囲が機能していない問題を修正
1218

1319
### Client

locales/index.d.ts

+20
Original file line numberDiff line numberDiff line change
@@ -6592,6 +6592,26 @@ export interface Locale extends ILocale {
65926592
* リモートユーザー
65936593
*/
65946594
"isRemote": string;
6595+
/**
6596+
* 猫ユーザー
6597+
*/
6598+
"isCat": string;
6599+
/**
6600+
* botユーザー
6601+
*/
6602+
"isBot": string;
6603+
/**
6604+
* サスペンド済みユーザー
6605+
*/
6606+
"isSuspended": string;
6607+
/**
6608+
* 鍵アカウントユーザー
6609+
*/
6610+
"isLocked": string;
6611+
/**
6612+
* 「アカウントを見つけやすくする」が有効なユーザー
6613+
*/
6614+
"isExplorable": string;
65956615
/**
65966616
* アカウント作成から~以内
65976617
*/

locales/ja-JP.yml

+5
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,11 @@ _role:
17031703
roleAssignedTo: "マニュアルロールにアサイン済み"
17041704
isLocal: "ローカルユーザー"
17051705
isRemote: "リモートユーザー"
1706+
isCat: "猫ユーザー"
1707+
isBot: "botユーザー"
1708+
isSuspended: "サスペンド済みユーザー"
1709+
isLocked: "鍵アカウントユーザー"
1710+
isExplorable: "「アカウントを見つけやすくする」が有効なユーザー"
17061711
createdLessThan: "アカウント作成から~以内"
17071712
createdMoreThan: "アカウント作成から~経過"
17081713
followersLessThanOrEq: "フォロワー数が~以下"

packages/backend/src/core/RoleService.ts

+34
Original file line numberDiff line numberDiff line change
@@ -205,45 +205,79 @@ export class RoleService implements OnApplicationShutdown, OnModuleInit {
205205
private evalCond(user: MiUser, roles: MiRole[], value: RoleCondFormulaValue): boolean {
206206
try {
207207
switch (value.type) {
208+
// ~かつ~
208209
case 'and': {
209210
return value.values.every(v => this.evalCond(user, roles, v));
210211
}
212+
// ~または~
211213
case 'or': {
212214
return value.values.some(v => this.evalCond(user, roles, v));
213215
}
216+
// ~ではない
214217
case 'not': {
215218
return !this.evalCond(user, roles, value.value);
216219
}
220+
// マニュアルロールがアサインされている
217221
case 'roleAssignedTo': {
218222
return roles.some(r => r.id === value.roleId);
219223
}
224+
// ローカルユーザのみ
220225
case 'isLocal': {
221226
return this.userEntityService.isLocalUser(user);
222227
}
228+
// リモートユーザのみ
223229
case 'isRemote': {
224230
return this.userEntityService.isRemoteUser(user);
225231
}
232+
// サスペンド済みユーザである
233+
case 'isSuspended': {
234+
return user.isSuspended;
235+
}
236+
// 鍵アカウントユーザである
237+
case 'isLocked': {
238+
return user.isLocked;
239+
}
240+
// botユーザである
241+
case 'isBot': {
242+
return user.isBot;
243+
}
244+
// 猫である
245+
case 'isCat': {
246+
return user.isCat;
247+
}
248+
// 「ユーザを見つけやすくする」が有効なアカウント
249+
case 'isExplorable': {
250+
return user.isExplorable;
251+
}
252+
// ユーザが作成されてから指定期間経過した
226253
case 'createdLessThan': {
227254
return this.idService.parse(user.id).date.getTime() > (Date.now() - (value.sec * 1000));
228255
}
256+
// ユーザが作成されてから指定期間経っていない
229257
case 'createdMoreThan': {
230258
return this.idService.parse(user.id).date.getTime() < (Date.now() - (value.sec * 1000));
231259
}
260+
// フォロワー数が指定値以下
232261
case 'followersLessThanOrEq': {
233262
return user.followersCount <= value.value;
234263
}
264+
// フォロワー数が指定値以上
235265
case 'followersMoreThanOrEq': {
236266
return user.followersCount >= value.value;
237267
}
268+
// フォロー数が指定値以下
238269
case 'followingLessThanOrEq': {
239270
return user.followingCount <= value.value;
240271
}
272+
// フォロー数が指定値以上
241273
case 'followingMoreThanOrEq': {
242274
return user.followingCount >= value.value;
243275
}
276+
// ノート数が指定値以下
244277
case 'notesLessThanOrEq': {
245278
return user.notesCount <= value.value;
246279
}
280+
// ノート数が指定値以上
247281
case 'notesMoreThanOrEq': {
248282
return user.notesCount >= value.value;
249283
}

packages/backend/src/misc/json-schema.ts

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
packedRoleCondFormulaValueCreatedSchema,
4949
packedRoleCondFormulaFollowersOrFollowingOrNotesSchema,
5050
packedRoleCondFormulaValueSchema,
51+
packedRoleCondFormulaValueUserSettingBooleanSchema,
5152
} from '@/models/json-schema/role.js';
5253
import { packedAdSchema } from '@/models/json-schema/ad.js';
5354
import { packedReversiGameLiteSchema, packedReversiGameDetailedSchema } from '@/models/json-schema/reversi-game.js';
@@ -97,6 +98,7 @@ export const refs = {
9798
RoleCondFormulaLogics: packedRoleCondFormulaLogicsSchema,
9899
RoleCondFormulaValueNot: packedRoleCondFormulaValueNot,
99100
RoleCondFormulaValueIsLocalOrRemote: packedRoleCondFormulaValueIsLocalOrRemoteSchema,
101+
RoleCondFormulaValueUserSettingBooleanSchema: packedRoleCondFormulaValueUserSettingBooleanSchema,
100102
RoleCondFormulaValueAssignedRole: packedRoleCondFormulaValueAssignedRoleSchema,
101103
RoleCondFormulaValueCreated: packedRoleCondFormulaValueCreatedSchema,
102104
RoleCondFormulaFollowersOrFollowingOrNotes: packedRoleCondFormulaFollowersOrFollowingOrNotesSchema,

packages/backend/src/models/Role.ts

+85
Original file line numberDiff line numberDiff line change
@@ -6,69 +6,149 @@
66
import { Entity, Column, PrimaryColumn } from 'typeorm';
77
import { id } from './util/id.js';
88

9+
/**
10+
* ~かつ~
11+
* 複数の条件を同時に満たす場合のみ成立とする
12+
*/
913
type CondFormulaValueAnd = {
1014
type: 'and';
1115
values: RoleCondFormulaValue[];
1216
};
1317

18+
/**
19+
* ~または~
20+
* 複数の条件のうち、いずれかを満たす場合のみ成立とする
21+
*/
1422
type CondFormulaValueOr = {
1523
type: 'or';
1624
values: RoleCondFormulaValue[];
1725
};
1826

27+
/**
28+
* ~ではない
29+
* 条件を満たさない場合のみ成立とする
30+
*/
1931
type CondFormulaValueNot = {
2032
type: 'not';
2133
value: RoleCondFormulaValue;
2234
};
2335

36+
/**
37+
* ローカルユーザーのみ成立とする
38+
*/
2439
type CondFormulaValueIsLocal = {
2540
type: 'isLocal';
2641
};
2742

43+
/**
44+
* リモートユーザーのみ成立とする
45+
*/
2846
type CondFormulaValueIsRemote = {
2947
type: 'isRemote';
3048
};
3149

50+
/**
51+
* 既に指定のマニュアルロールにアサインされている場合のみ成立とする
52+
*/
3253
type CondFormulaValueRoleAssignedTo = {
3354
type: 'roleAssignedTo';
3455
roleId: string;
3556
};
3657

58+
/**
59+
* サスペンド済みアカウントの場合のみ成立とする
60+
*/
61+
type CondFormulaValueIsSuspended = {
62+
type: 'isSuspended';
63+
};
64+
65+
/**
66+
* 鍵アカウントの場合のみ成立とする
67+
*/
68+
type CondFormulaValueIsLocked = {
69+
type: 'isLocked';
70+
};
71+
72+
/**
73+
* botアカウントの場合のみ成立とする
74+
*/
75+
type CondFormulaValueIsBot = {
76+
type: 'isBot';
77+
};
78+
79+
/**
80+
* 猫アカウントの場合のみ成立とする
81+
*/
82+
type CondFormulaValueIsCat = {
83+
type: 'isCat';
84+
};
85+
86+
/**
87+
* 「ユーザを見つけやすくする」が有効なアカウントの場合のみ成立とする
88+
*/
89+
type CondFormulaValueIsExplorable = {
90+
type: 'isExplorable';
91+
};
92+
93+
/**
94+
* ユーザが作成されてから指定期間経過した場合のみ成立とする
95+
*/
3796
type CondFormulaValueCreatedLessThan = {
3897
type: 'createdLessThan';
3998
sec: number;
4099
};
41100

101+
/**
102+
* ユーザが作成されてから指定期間経っていない場合のみ成立とする
103+
*/
42104
type CondFormulaValueCreatedMoreThan = {
43105
type: 'createdMoreThan';
44106
sec: number;
45107
};
46108

109+
/**
110+
* フォロワー数が指定値以下の場合のみ成立とする
111+
*/
47112
type CondFormulaValueFollowersLessThanOrEq = {
48113
type: 'followersLessThanOrEq';
49114
value: number;
50115
};
51116

117+
/**
118+
* フォロワー数が指定値以上の場合のみ成立とする
119+
*/
52120
type CondFormulaValueFollowersMoreThanOrEq = {
53121
type: 'followersMoreThanOrEq';
54122
value: number;
55123
};
56124

125+
/**
126+
* フォロー数が指定値以下の場合のみ成立とする
127+
*/
57128
type CondFormulaValueFollowingLessThanOrEq = {
58129
type: 'followingLessThanOrEq';
59130
value: number;
60131
};
61132

133+
/**
134+
* フォロー数が指定値以上の場合のみ成立とする
135+
*/
62136
type CondFormulaValueFollowingMoreThanOrEq = {
63137
type: 'followingMoreThanOrEq';
64138
value: number;
65139
};
66140

141+
/**
142+
* 投稿数が指定値以下の場合のみ成立とする
143+
*/
67144
type CondFormulaValueNotesLessThanOrEq = {
68145
type: 'notesLessThanOrEq';
69146
value: number;
70147
};
71148

149+
/**
150+
* 投稿数が指定値以上の場合のみ成立とする
151+
*/
72152
type CondFormulaValueNotesMoreThanOrEq = {
73153
type: 'notesMoreThanOrEq';
74154
value: number;
@@ -80,6 +160,11 @@ export type RoleCondFormulaValue = { id: string } & (
80160
CondFormulaValueNot |
81161
CondFormulaValueIsLocal |
82162
CondFormulaValueIsRemote |
163+
CondFormulaValueIsSuspended |
164+
CondFormulaValueIsLocked |
165+
CondFormulaValueIsBot |
166+
CondFormulaValueIsCat |
167+
CondFormulaValueIsExplorable |
83168
CondFormulaValueRoleAssignedTo |
84169
CondFormulaValueCreatedLessThan |
85170
CondFormulaValueCreatedMoreThan |

packages/backend/src/models/json-schema/role.ts

+17
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ export const packedRoleCondFormulaValueIsLocalOrRemoteSchema = {
5757
},
5858
} as const;
5959

60+
export const packedRoleCondFormulaValueUserSettingBooleanSchema = {
61+
type: 'object',
62+
properties: {
63+
id: {
64+
type: 'string', optional: false,
65+
},
66+
type: {
67+
type: 'string',
68+
nullable: false, optional: false,
69+
enum: ['isSuspended', 'isLocked', 'isBot', 'isCat', 'isExplorable'],
70+
},
71+
},
72+
} as const;
73+
6074
export const packedRoleCondFormulaValueAssignedRoleSchema = {
6175
type: 'object',
6276
properties: {
@@ -135,6 +149,9 @@ export const packedRoleCondFormulaValueSchema = {
135149
{
136150
ref: 'RoleCondFormulaValueIsLocalOrRemote',
137151
},
152+
{
153+
ref: 'RoleCondFormulaValueUserSettingBooleanSchema',
154+
},
138155
{
139156
ref: 'RoleCondFormulaValueAssignedRole',
140157
},

0 commit comments

Comments
 (0)