@@ -20,8 +20,10 @@ export class AbuseReportService {
20
20
constructor (
21
21
@Inject ( DI . abuseUserReportsRepository )
22
22
private abuseUserReportsRepository : AbuseUserReportsRepository ,
23
+
23
24
@Inject ( DI . usersRepository )
24
25
private usersRepository : UsersRepository ,
26
+
25
27
private idService : IdService ,
26
28
private abuseReportNotificationService : AbuseReportNotificationService ,
27
29
private queueService : QueueService ,
@@ -77,16 +79,16 @@ export class AbuseReportService {
77
79
* - SystemWebhook
78
80
*
79
81
* @param params 通報内容. もし複数件の通報に対応した時のために、あらかじめ複数件を処理できる前提で考える
80
- * @param operator 通報を処理したユーザ
82
+ * @param moderator 通報を処理したユーザ
81
83
* @see AbuseReportNotificationService.notify
82
84
*/
83
85
@bindThis
84
86
public async resolve (
85
87
params : {
86
88
reportId : string ;
87
- forward : boolean ;
89
+ resolvedAs : MiAbuseUserReport [ 'resolvedAs' ] ;
88
90
} [ ] ,
89
- operator : MiUser ,
91
+ moderator : MiUser ,
90
92
) {
91
93
const paramsMap = new Map ( params . map ( it => [ it . reportId , it ] ) ) ;
92
94
const reports = await this . abuseUserReportsRepository . findBy ( {
@@ -99,30 +101,74 @@ export class AbuseReportService {
99
101
100
102
await this . abuseUserReportsRepository . update ( report . id , {
101
103
resolved : true ,
102
- assigneeId : operator . id ,
103
- forwarded : ps . forward && report . targetUserHost !== null ,
104
+ assigneeId : moderator . id ,
105
+ resolvedAs : ps . resolvedAs ,
104
106
} ) ;
105
107
106
- if ( ps . forward && report . targetUserHost != null ) {
107
- const actor = await this . instanceActorService . getInstanceActor ( ) ;
108
- const targetUser = await this . usersRepository . findOneByOrFail ( { id : report . targetUserId } ) ;
109
-
110
- // eslint-disable-next-line
111
- const flag = this . apRendererService . renderFlag ( actor , targetUser . uri ! , report . comment ) ;
112
- const contextAssignedFlag = this . apRendererService . addContext ( flag ) ;
113
- this . queueService . deliver ( actor , contextAssignedFlag , targetUser . inbox , false ) ;
114
- }
115
-
116
108
this . moderationLogService
117
- . log ( operator , 'resolveAbuseReport' , {
109
+ . log ( moderator , 'resolveAbuseReport' , {
118
110
reportId : report . id ,
119
111
report : report ,
120
- forwarded : ps . forward && report . targetUserHost !== null ,
112
+ resolvedAs : ps . resolvedAs ,
121
113
} )
122
114
. then ( ) ;
123
115
}
124
116
125
117
return this . abuseUserReportsRepository . findBy ( { id : In ( reports . map ( it => it . id ) ) } )
126
118
. then ( reports => this . abuseReportNotificationService . notifySystemWebhook ( reports , 'abuseReportResolved' ) ) ;
127
119
}
120
+
121
+ @bindThis
122
+ public async forward (
123
+ reportId : MiAbuseUserReport [ 'id' ] ,
124
+ moderator : MiUser ,
125
+ ) {
126
+ const report = await this . abuseUserReportsRepository . findOneByOrFail ( { id : reportId } ) ;
127
+
128
+ if ( report . targetUserHost == null ) {
129
+ throw new Error ( 'The target user host is null.' ) ;
130
+ }
131
+
132
+ await this . abuseUserReportsRepository . update ( report . id , {
133
+ forwarded : true ,
134
+ } ) ;
135
+
136
+ const actor = await this . instanceActorService . getInstanceActor ( ) ;
137
+ const targetUser = await this . usersRepository . findOneByOrFail ( { id : report . targetUserId } ) ;
138
+
139
+ const flag = this . apRendererService . renderFlag ( actor , targetUser . uri ! , report . comment ) ;
140
+ const contextAssignedFlag = this . apRendererService . addContext ( flag ) ;
141
+ this . queueService . deliver ( actor , contextAssignedFlag , targetUser . inbox , false ) ;
142
+
143
+ this . moderationLogService
144
+ . log ( moderator , 'forwardAbuseReport' , {
145
+ reportId : report . id ,
146
+ report : report ,
147
+ } )
148
+ . then ( ) ;
149
+ }
150
+
151
+ @bindThis
152
+ public async update (
153
+ reportId : MiAbuseUserReport [ 'id' ] ,
154
+ params : {
155
+ moderationNote ?: MiAbuseUserReport [ 'moderationNote' ] ;
156
+ } ,
157
+ moderator : MiUser ,
158
+ ) {
159
+ const report = await this . abuseUserReportsRepository . findOneByOrFail ( { id : reportId } ) ;
160
+
161
+ await this . abuseUserReportsRepository . update ( report . id , {
162
+ moderationNote : params . moderationNote ,
163
+ } ) ;
164
+
165
+ if ( params . moderationNote != null && report . moderationNote !== params . moderationNote ) {
166
+ this . moderationLogService . log ( moderator , 'updateAbuseReportNote' , {
167
+ reportId : report . id ,
168
+ report : report ,
169
+ before : report . moderationNote ,
170
+ after : params . moderationNote ,
171
+ } ) ;
172
+ }
173
+ }
128
174
}
0 commit comments