refactor(reports): rename variables and remove type assertion
This commit is contained in:
parent
394599734f
commit
24068d12d0
|
@ -44,7 +44,7 @@ import {
|
||||||
} from '@/controllers/api/pleroma.ts';
|
} from '@/controllers/api/pleroma.ts';
|
||||||
import { preferencesController } from '@/controllers/api/preferences.ts';
|
import { preferencesController } from '@/controllers/api/preferences.ts';
|
||||||
import { relayController } from '@/controllers/nostr/relay.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 { searchController } from '@/controllers/api/search.ts';
|
||||||
import {
|
import {
|
||||||
bookmarkController,
|
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.put('/api/v1/admin/ditto/relays', requireRole('admin'), adminSetRelaysController);
|
||||||
|
|
||||||
app.post('/api/v1/reports', requirePubkey, reportsController);
|
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.
|
// Not (yet) implemented.
|
||||||
app.get('/api/v1/custom_emojis', emptyArrayController);
|
app.get('/api/v1/custom_emojis', emptyArrayController);
|
||||||
|
|
|
@ -57,7 +57,7 @@ const reportsController: AppController = async (c) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
/** https://docs.joinmastodon.org/methods/admin/reports/#get */
|
/** https://docs.joinmastodon.org/methods/admin/reports/#get */
|
||||||
const viewAllReportsController: AppController = async (c) => {
|
const adminReportsController: AppController = async (c) => {
|
||||||
const store = c.get('store');
|
const store = c.get('store');
|
||||||
const reports = await store.query([{ kinds: [1984], '#P': [Conf.pubkey] }])
|
const reports = await store.query([{ kinds: [1984], '#P': [Conf.pubkey] }])
|
||||||
.then((events) => hydrateEvents({ storage: store, events: events, signal: c.req.raw.signal }))
|
.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);
|
return c.json(reports);
|
||||||
};
|
};
|
||||||
|
|
||||||
export { reportsController, viewAllReportsController };
|
export { adminReportsController, reportsController };
|
||||||
|
|
|
@ -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 */
|
/** Expects a `reportEvent` of kind 1984 and a `profile` of kind 0 of the person being reported */
|
||||||
async function renderReport(reportEvent: DittoEvent, profile: DittoEvent) {
|
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
|
// 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 {
|
return {
|
||||||
id: reportEvent.id,
|
id: reportEvent.id,
|
||||||
|
@ -21,9 +21,9 @@ async function renderReport(reportEvent: DittoEvent, profile: DittoEvent) {
|
||||||
comment: reportEvent.content,
|
comment: reportEvent.content,
|
||||||
forwarded: false,
|
forwarded: false,
|
||||||
created_at: nostrDate(reportEvent.created_at).toISOString(),
|
created_at: nostrDate(reportEvent.created_at).toISOString(),
|
||||||
status_ids,
|
status_ids: statusIds,
|
||||||
rules_ids: null,
|
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;
|
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
|
// 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 = [];
|
const statuses = [];
|
||||||
if (reportEvent.reported_notes) {
|
if (reportEvent.reported_notes) {
|
||||||
|
|
Loading…
Reference in New Issue