Compare commits
2 Commits
9f83a6fb66
...
3d27279a16
| Author | SHA1 | Date | |
|---|---|---|---|
| 3d27279a16 | |||
| 94ce9c3c95 |
@@ -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}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export default function DashboardSidebar({
|
|||||||
const hasDrawerTransitions = isOverSmViewport && isOverMdViewport;
|
const hasDrawerTransitions = isOverSmViewport && isOverMdViewport;
|
||||||
|
|
||||||
const getDrawerContent = React.useCallback(
|
const getDrawerContent = React.useCallback(
|
||||||
(viewport: "phone" | "tablet" | "desktop") => (
|
(viewport: "phone" | "desktop") => (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<Box
|
<Box
|
||||||
component="nav"
|
component="nav"
|
||||||
@@ -194,20 +194,7 @@ export default function DashboardSidebar({
|
|||||||
<Drawer
|
<Drawer
|
||||||
variant="permanent"
|
variant="permanent"
|
||||||
sx={{
|
sx={{
|
||||||
display: {
|
display: { xs: "none", sm: "block", md: "block" },
|
||||||
xs: "none",
|
|
||||||
sm: "block",
|
|
||||||
md: "none",
|
|
||||||
},
|
|
||||||
...getDrawerSharedSx(false),
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{getDrawerContent("tablet")}
|
|
||||||
</Drawer>
|
|
||||||
<Drawer
|
|
||||||
variant="permanent"
|
|
||||||
sx={{
|
|
||||||
display: { xs: "none", md: "block" },
|
|
||||||
...getDrawerSharedSx(false, true),
|
...getDrawerSharedSx(false, true),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,10 +1,22 @@
|
|||||||
import { 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";
|
|
||||||
|
|
||||||
export function RoomMessagesList(p: {
|
export function RoomMessagesList(p: {
|
||||||
room: Room;
|
room: Room;
|
||||||
@@ -59,14 +71,30 @@ 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 (
|
||||||
<>
|
<>
|
||||||
|
{/* Print date if required */}
|
||||||
{p.firstMessageOfDay && (
|
{p.firstMessageOfDay && (
|
||||||
<Typography
|
<Typography
|
||||||
variant="caption"
|
variant="caption"
|
||||||
@@ -76,7 +104,9 @@ function RoomMessage(p: {
|
|||||||
{p.message.time_sent_dayjs.format("DD/MM/YYYY")}
|
{p.message.time_sent_dayjs.format("DD/MM/YYYY")}
|
||||||
</Typography>
|
</Typography>
|
||||||
)}
|
)}
|
||||||
{(!p.previousFromSamePerson || p.firstMessageOfDay) && user && (
|
|
||||||
|
{/* Give person name if required */}
|
||||||
|
{(!p.previousFromSamePerson || p.firstMessageOfDay) && sender && (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
@@ -85,17 +115,30 @@ function RoomMessage(p: {
|
|||||||
marginTop: "20px",
|
marginTop: "20px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<AccountIcon user={user} />
|
<AccountIcon user={sender} />
|
||||||
|
|
||||||
{user.display_name}
|
{sender.display_name}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div
|
{/* Message content */}
|
||||||
|
<Box
|
||||||
style={{
|
style={{
|
||||||
wordBreak: "break-all",
|
wordBreak: "break-all",
|
||||||
wordWrap: "break-word",
|
wordWrap: "break-word",
|
||||||
maxWidth: "100%",
|
maxWidth: "100%",
|
||||||
|
transition: "all 0.01s ease-in",
|
||||||
|
position: "relative",
|
||||||
|
}}
|
||||||
|
component="div"
|
||||||
|
sx={{
|
||||||
|
[theme.getColorSchemeSelector("dark") + "&:hover"]: {
|
||||||
|
backgroundColor: "#ffffff2b",
|
||||||
|
},
|
||||||
|
[theme.getColorSchemeSelector("light") + "&:hover"]: {
|
||||||
|
backgroundColor: "#00000039",
|
||||||
|
},
|
||||||
|
"&:hover *": { visibility: "visible" },
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Typography variant="caption">
|
<Typography variant="caption">
|
||||||
@@ -117,7 +160,29 @@ function RoomMessage(p: {
|
|||||||
) : (
|
) : (
|
||||||
p.message.content
|
p.message.content
|
||||||
)}
|
)}
|
||||||
</div>
|
<ButtonGroup
|
||||||
|
className="buttons"
|
||||||
|
size="small"
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
visibility: "hidden",
|
||||||
|
display: "block",
|
||||||
|
top: "-34px",
|
||||||
|
right: "0px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{p.message.account === user.info.matrix_user_id && (
|
||||||
|
<Button>
|
||||||
|
<EditIcon />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{p.message.account === user.info.matrix_user_id && (
|
||||||
|
<Button onClick={handleDeleteMessage}>
|
||||||
|
<DeleteIcon color="error" />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</ButtonGroup>
|
||||||
|
</Box>
|
||||||
|
|
||||||
<Dialog open={showImageFullScreen} onClose={closeImageFullScreen}>
|
<Dialog open={showImageFullScreen} onClose={closeImageFullScreen}>
|
||||||
<img
|
<img
|
||||||
|
|||||||
Reference in New Issue
Block a user