refactor(reports): rename variables and remove type assertion

This commit is contained in:
P. Reis 2024-05-06 11:47:05 -03:00
parent 394599734f
commit 24068d12d0
3 changed files with 10 additions and 10 deletions

View File

@ -44,7 +44,7 @@ import {
} from '@/controllers/api/pleroma.ts';
import { preferencesController } from '@/controllers/api/preferences.ts';
import { relayController } from '@/controllers/nostr/relay.ts';
import { reportsController, viewAllReportsController } from '@/controllers/api/reports.ts';
import { adminReportsController, reportsController } from '@/controllers/api/reports.ts';
import { searchController } from '@/controllers/api/search.ts';
import {
bookmarkController,
@ -208,7 +208,7 @@ app.get('/api/v1/admin/ditto/relays', requireRole('admin'), adminRelaysControlle
app.put('/api/v1/admin/ditto/relays', requireRole('admin'), adminSetRelaysController);
app.post('/api/v1/reports', requirePubkey, reportsController);
app.get('/api/v1/admin/reports', requirePubkey, requireRole('admin'), viewAllReportsController);
app.get('/api/v1/admin/reports', requirePubkey, requireRole('admin'), adminReportsController);
// Not (yet) implemented.
app.get('/api/v1/custom_emojis', emptyArrayController);

View File

@ -57,7 +57,7 @@ const reportsController: AppController = async (c) => {
};
/** https://docs.joinmastodon.org/methods/admin/reports/#get */
const viewAllReportsController: AppController = async (c) => {
const adminReportsController: AppController = async (c) => {
const store = c.get('store');
const reports = await store.query([{ kinds: [1984], '#P': [Conf.pubkey] }])
.then((events) => hydrateEvents({ storage: store, events: events, signal: c.req.raw.signal }))
@ -66,4 +66,4 @@ const viewAllReportsController: AppController = async (c) => {
return c.json(reports);
};
export { reportsController, viewAllReportsController };
export { adminReportsController, reportsController };

View File

@ -7,11 +7,11 @@ import { renderStatus } from '@/views/mastodon/statuses.ts';
/** Expects a `reportEvent` of kind 1984 and a `profile` of kind 0 of the person being reported */
async function renderReport(reportEvent: DittoEvent, profile: DittoEvent) {
// The category is present in both the 'e' and 'p' tag, however, it is possible to report a user without reporting a note, so it's better to get the category from the 'p' tag
const category = reportEvent.tags.find(([name]) => name === 'p')?.[2] as string;
const category = reportEvent.tags.find(([name]) => name === 'p')?.[2];
const status_ids = reportEvent.tags.filter(([name]) => name === 'e').map((tag) => tag[1]) ?? [];
const statusIds = reportEvent.tags.filter(([name]) => name === 'e').map((tag) => tag[1]) ?? [];
const reported_profile_pubkey = reportEvent.tags.find(([name]) => name === 'p')?.[1] as string;
const reportedPubkey = reportEvent.tags.find(([name]) => name === 'p')?.[1]!;
return {
id: reportEvent.id,
@ -21,9 +21,9 @@ async function renderReport(reportEvent: DittoEvent, profile: DittoEvent) {
comment: reportEvent.content,
forwarded: false,
created_at: nostrDate(reportEvent.created_at).toISOString(),
status_ids,
status_ids: statusIds,
rules_ids: null,
target_account: profile ? await renderAccount(profile) : await accountFromPubkey(reported_profile_pubkey),
target_account: profile ? await renderAccount(profile) : await accountFromPubkey(reportedPubkey),
};
}
@ -38,7 +38,7 @@ async function renderAdminReport(reportEvent: DittoEvent, opts: RenderAdminRepor
const { viewerPubkey } = opts;
// The category is present in both the 'e' and 'p' tag, however, it is possible to report a user without reporting a note, so it's better to get the category from the 'p' tag
const category = reportEvent.tags.find(([name]) => name === 'p')?.[2] as string;
const category = reportEvent.tags.find(([name]) => name === 'p')?.[2];
const statuses = [];
if (reportEvent.reported_notes) {