Improve messages appearance
This commit is contained in:
@@ -1,16 +1,34 @@
|
|||||||
|
import { Dialog, Typography } from "@mui/material";
|
||||||
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 type { Message, RoomEventsManager } from "../../utils/RoomEventsManager";
|
import type { Message, RoomEventsManager } from "../../utils/RoomEventsManager";
|
||||||
import { AccountIcon } from "./AccountIcon";
|
import { AccountIcon } from "./AccountIcon";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
export function RoomMessagesList(p: {
|
export function RoomMessagesList(p: {
|
||||||
room: Room;
|
room: Room;
|
||||||
users: UsersMap;
|
users: UsersMap;
|
||||||
mgr: RoomEventsManager;
|
mgr: RoomEventsManager;
|
||||||
}): React.ReactElement {
|
}): React.ReactElement {
|
||||||
|
const messagesEndRef = React.createRef<HTMLDivElement>();
|
||||||
|
|
||||||
|
// Automatically scroll to bottom when number of messages change
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (messagesEndRef)
|
||||||
|
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
||||||
|
}, [p.mgr.messages.length]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ flex: 1, width: "100%" }}>
|
<div
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
width: "100%",
|
||||||
|
paddingRight: "50px",
|
||||||
|
overflow: "scroll",
|
||||||
|
paddingLeft: "20px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
{p.mgr.messages.map((m, idx) => (
|
{p.mgr.messages.map((m, idx) => (
|
||||||
<RoomMessage
|
<RoomMessage
|
||||||
key={m.event_id}
|
key={m.event_id}
|
||||||
@@ -28,6 +46,8 @@ export function RoomMessagesList(p: {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
<div ref={messagesEndRef} style={{ height: "10px" }} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -39,42 +59,75 @@ function RoomMessage(p: {
|
|||||||
previousFromSamePerson: boolean;
|
previousFromSamePerson: boolean;
|
||||||
firstMessageOfDay: boolean;
|
firstMessageOfDay: boolean;
|
||||||
}): React.ReactElement {
|
}): React.ReactElement {
|
||||||
|
const [showImageFullScreen, setShowImageFullScreen] = React.useState(false);
|
||||||
|
|
||||||
|
const closeImageFullScreen = () => setShowImageFullScreen(false);
|
||||||
|
|
||||||
const user = p.users.get(p.message.account);
|
const user = p.users.get(p.message.account);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{p.firstMessageOfDay && (
|
{p.firstMessageOfDay && (
|
||||||
<div style={{ textAlign: "center" }}>
|
<Typography
|
||||||
|
variant="caption"
|
||||||
|
component={"div"}
|
||||||
|
style={{ textAlign: "center", marginTop: "50px" }}
|
||||||
|
>
|
||||||
{p.message.time_sent_dayjs.format("DD/MM/YYYY")}
|
{p.message.time_sent_dayjs.format("DD/MM/YYYY")}
|
||||||
</div>
|
</Typography>
|
||||||
)}
|
)}
|
||||||
{!p.previousFromSamePerson && user && (
|
{(!p.previousFromSamePerson || p.firstMessageOfDay) && user && (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
|
marginTop: "20px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<AccountIcon user={user} />
|
<AccountIcon user={user} />
|
||||||
|
|
||||||
{user.display_name}
|
{user.display_name}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div>
|
<div
|
||||||
{p.message.time_sent_dayjs.format("HH:mm")}{" "}
|
style={{
|
||||||
|
wordBreak: "break-all",
|
||||||
|
wordWrap: "break-word",
|
||||||
|
maxWidth: "100%",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography variant="caption">
|
||||||
|
{p.message.time_sent_dayjs.format("HH:mm")}
|
||||||
|
</Typography>{" "}
|
||||||
|
|
||||||
{p.message.image ? (
|
{p.message.image ? (
|
||||||
<img
|
<img
|
||||||
|
onClick={() => setShowImageFullScreen(true)}
|
||||||
src={MatrixApiEvent.GetEventFileURL(
|
src={MatrixApiEvent.GetEventFileURL(
|
||||||
p.room,
|
p.room,
|
||||||
p.message.event_id,
|
p.message.event_id,
|
||||||
true
|
true
|
||||||
)}
|
)}
|
||||||
|
style={{
|
||||||
|
maxWidth: "200px",
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
p.message.content
|
p.message.content
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Dialog open={showImageFullScreen} onClose={closeImageFullScreen}>
|
||||||
|
<img
|
||||||
|
src={MatrixApiEvent.GetEventFileURL(
|
||||||
|
p.room,
|
||||||
|
p.message.event_id,
|
||||||
|
false
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</Dialog>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user