Improve types for sendEvent
(#12335)
This commit is contained in:
parent
4941327c78
commit
ef2bd7ae04
26 changed files with 209 additions and 99 deletions
|
@ -32,6 +32,12 @@ import Field from "../elements/Field";
|
|||
import Spinner from "../elements/Spinner";
|
||||
import LabelledCheckbox from "../elements/LabelledCheckbox";
|
||||
|
||||
declare module "matrix-js-sdk/src/types" {
|
||||
interface TimelineEvents {
|
||||
[ABUSE_EVENT_TYPE]: AbuseEventContent;
|
||||
}
|
||||
}
|
||||
|
||||
interface IProps {
|
||||
mxEvent: MatrixEvent;
|
||||
onFinished(report?: boolean): void;
|
||||
|
@ -56,7 +62,16 @@ const MODERATED_BY_STATE_EVENT_TYPE = [
|
|||
*/
|
||||
];
|
||||
|
||||
const ABUSE_EVENT_TYPE = "org.matrix.msc3215.abuse.report";
|
||||
export const ABUSE_EVENT_TYPE = "org.matrix.msc3215.abuse.report";
|
||||
|
||||
interface AbuseEventContent {
|
||||
event_id: string;
|
||||
room_id: string;
|
||||
moderated_by_id: string;
|
||||
nature?: ExtendedNature;
|
||||
reporter: string;
|
||||
comment: string;
|
||||
}
|
||||
|
||||
// Standard abuse natures.
|
||||
enum Nature {
|
||||
|
@ -250,13 +265,13 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
|
|||
}
|
||||
|
||||
await client.sendEvent(dmRoomId, ABUSE_EVENT_TYPE, {
|
||||
event_id: ev.getId(),
|
||||
room_id: ev.getRoomId(),
|
||||
event_id: ev.getId()!,
|
||||
room_id: ev.getRoomId()!,
|
||||
moderated_by_id: this.moderation.moderationRoomId,
|
||||
nature,
|
||||
reporter: client.getUserId(),
|
||||
reporter: client.getUserId()!,
|
||||
comment: this.state.reason.trim(),
|
||||
});
|
||||
} satisfies AbuseEventContent);
|
||||
} else {
|
||||
// Report to homeserver admin through the dedicated Matrix API.
|
||||
await client.reportEvent(ev.getRoomId()!, ev.getId()!, -100, this.state.reason.trim());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue