Can delete events from WebUI
This commit is contained in:
@@ -91,4 +91,14 @@ export class MatrixApiEvent {
|
|||||||
jsonData: { content },
|
jsonData: { content },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete an event
|
||||||
|
*/
|
||||||
|
static async DeleteEvent(room: Room, event_id: string): Promise<void> {
|
||||||
|
await APIClient.exec({
|
||||||
|
method: "DELETE",
|
||||||
|
uri: `/matrix/room/${room.id}/event/${event_id}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,22 @@
|
|||||||
import { Box, Button, ButtonGroup, Dialog, Typography } from "@mui/material";
|
import DeleteIcon from "@mui/icons-material/Delete";
|
||||||
|
import EditIcon from "@mui/icons-material/Edit";
|
||||||
|
import {
|
||||||
|
Box,
|
||||||
|
Button,
|
||||||
|
ButtonGroup,
|
||||||
|
Dialog,
|
||||||
|
Typography,
|
||||||
|
useTheme,
|
||||||
|
} from "@mui/material";
|
||||||
|
import React from "react";
|
||||||
import { MatrixApiEvent } from "../../api/matrix/MatrixApiEvent";
|
import { MatrixApiEvent } from "../../api/matrix/MatrixApiEvent";
|
||||||
import type { UsersMap } from "../../api/matrix/MatrixApiProfile";
|
import type { UsersMap } from "../../api/matrix/MatrixApiProfile";
|
||||||
import type { Room } from "../../api/matrix/MatrixApiRoom";
|
import type { Room } from "../../api/matrix/MatrixApiRoom";
|
||||||
|
import { useAlert } from "../../hooks/contexts_provider/AlertDialogProvider";
|
||||||
|
import { useConfirm } from "../../hooks/contexts_provider/ConfirmDialogProvider";
|
||||||
import type { Message, RoomEventsManager } from "../../utils/RoomEventsManager";
|
import type { Message, RoomEventsManager } from "../../utils/RoomEventsManager";
|
||||||
|
import { useUserInfo } from "../dashboard/BaseAuthenticatedPage";
|
||||||
import { AccountIcon } from "./AccountIcon";
|
import { AccountIcon } from "./AccountIcon";
|
||||||
import React from "react";
|
|
||||||
import EditIcon from "@mui/icons-material/Edit";
|
|
||||||
import DeleteIcon from "@mui/icons-material/Delete";
|
|
||||||
|
|
||||||
export function RoomMessagesList(p: {
|
export function RoomMessagesList(p: {
|
||||||
room: Room;
|
room: Room;
|
||||||
@@ -61,11 +71,26 @@ function RoomMessage(p: {
|
|||||||
previousFromSamePerson: boolean;
|
previousFromSamePerson: boolean;
|
||||||
firstMessageOfDay: boolean;
|
firstMessageOfDay: boolean;
|
||||||
}): React.ReactElement {
|
}): React.ReactElement {
|
||||||
|
const theme = useTheme();
|
||||||
|
const user = useUserInfo();
|
||||||
|
const alert = useAlert();
|
||||||
|
const confirm = useConfirm();
|
||||||
|
|
||||||
const [showImageFullScreen, setShowImageFullScreen] = React.useState(false);
|
const [showImageFullScreen, setShowImageFullScreen] = React.useState(false);
|
||||||
|
|
||||||
const closeImageFullScreen = () => setShowImageFullScreen(false);
|
const closeImageFullScreen = () => setShowImageFullScreen(false);
|
||||||
|
|
||||||
const user = p.users.get(p.message.account);
|
const sender = p.users.get(p.message.account);
|
||||||
|
|
||||||
|
const handleDeleteMessage = async () => {
|
||||||
|
if (!(await confirm(`Do you really want to delete this message?`))) return;
|
||||||
|
try {
|
||||||
|
await MatrixApiEvent.DeleteEvent(p.room, p.message.event_id);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Failed to delete message!`, e),
|
||||||
|
alert(`Failed to delete message!${e}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -81,7 +106,7 @@ function RoomMessage(p: {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Give person name if required */}
|
{/* Give person name if required */}
|
||||||
{(!p.previousFromSamePerson || p.firstMessageOfDay) && user && (
|
{(!p.previousFromSamePerson || p.firstMessageOfDay) && sender && (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
@@ -90,9 +115,9 @@ function RoomMessage(p: {
|
|||||||
marginTop: "20px",
|
marginTop: "20px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<AccountIcon user={user} />
|
<AccountIcon user={sender} />
|
||||||
|
|
||||||
{user.display_name}
|
{sender.display_name}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -107,9 +132,12 @@ function RoomMessage(p: {
|
|||||||
}}
|
}}
|
||||||
component="div"
|
component="div"
|
||||||
sx={{
|
sx={{
|
||||||
"&:hover": {
|
[theme.getColorSchemeSelector("dark") + "&:hover"]: {
|
||||||
backgroundColor: "#ffffff2b",
|
backgroundColor: "#ffffff2b",
|
||||||
},
|
},
|
||||||
|
[theme.getColorSchemeSelector("light") + "&:hover"]: {
|
||||||
|
backgroundColor: "#00000039",
|
||||||
|
},
|
||||||
"&:hover *": { visibility: "visible" },
|
"&:hover *": { visibility: "visible" },
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -142,14 +170,17 @@ function RoomMessage(p: {
|
|||||||
top: "-34px",
|
top: "-34px",
|
||||||
right: "0px",
|
right: "0px",
|
||||||
}}
|
}}
|
||||||
sx={{ "parent:hover": { visibility: "visible" } }}
|
|
||||||
>
|
>
|
||||||
|
{p.message.account === user.info.matrix_user_id && (
|
||||||
<Button>
|
<Button>
|
||||||
<EditIcon />
|
<EditIcon />
|
||||||
</Button>
|
</Button>
|
||||||
<Button>
|
)}
|
||||||
<DeleteIcon />
|
{p.message.account === user.info.matrix_user_id && (
|
||||||
|
<Button onClick={handleDeleteMessage}>
|
||||||
|
<DeleteIcon color="error" />
|
||||||
</Button>
|
</Button>
|
||||||
|
)}
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user