2022-05-15 06:11:59 -07:00
|
|
|
/**
|
|
|
|
* Admin report normalizer:
|
|
|
|
* Converts API admin-level report information into our internal format.
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
Map as ImmutableMap,
|
|
|
|
List as ImmutableList,
|
|
|
|
Record as ImmutableRecord,
|
|
|
|
fromJS,
|
|
|
|
} from 'immutable';
|
|
|
|
|
|
|
|
import type { ReducerAccount } from 'soapbox/reducers/accounts';
|
|
|
|
import type { Account, EmbeddedEntity, Status } from 'soapbox/types/entities';
|
|
|
|
|
|
|
|
export const AdminReportRecord = ImmutableRecord({
|
|
|
|
account: null as EmbeddedEntity<Account | ReducerAccount>,
|
|
|
|
action_taken: false,
|
|
|
|
action_taken_by_account: null as EmbeddedEntity<Account | ReducerAccount> | null,
|
|
|
|
assigned_account: null as EmbeddedEntity<Account | ReducerAccount> | null,
|
|
|
|
category: '',
|
|
|
|
comment: '',
|
|
|
|
created_at: new Date(),
|
|
|
|
id: '',
|
|
|
|
rules: ImmutableList<string>(),
|
|
|
|
statuses: ImmutableList<EmbeddedEntity<Status>>(),
|
|
|
|
target_account: null as EmbeddedEntity<Account | ReducerAccount>,
|
2022-11-12 14:30:46 -08:00
|
|
|
updated_at: new Date(),
|
2022-05-15 06:11:59 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
const normalizePleromaReport = (report: ImmutableMap<string, any>) => {
|
|
|
|
if (report.get('actor')){
|
|
|
|
return report.withMutations(report => {
|
|
|
|
report.set('target_account', report.get('account'));
|
|
|
|
report.set('account', report.get('actor'));
|
|
|
|
|
|
|
|
report.set('action_taken', report.get('state') !== 'open');
|
|
|
|
report.set('comment', report.get('content'));
|
|
|
|
report.set('updated_at', report.get('created_at'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return report;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const normalizeAdminReport = (report: Record<string, any>) => {
|
|
|
|
return AdminReportRecord(
|
|
|
|
ImmutableMap(fromJS(report)).withMutations((report: ImmutableMap<string, any>) => {
|
|
|
|
normalizePleromaReport(report);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
};
|