Add support for more file formats
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { APIClient } from "./ApiClient";
|
import { APIClient } from "./ApiClient";
|
||||||
|
import type { MessageType } from "./matrix/MatrixApiEvent";
|
||||||
|
|
||||||
interface BaseRoomEvent {
|
interface BaseRoomEvent {
|
||||||
time: number;
|
time: number;
|
||||||
@@ -8,8 +9,6 @@ interface BaseRoomEvent {
|
|||||||
origin_server_ts: number;
|
origin_server_ts: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
type MessageType = "m.text" | "m.image" | string;
|
|
||||||
|
|
||||||
export interface RoomMessageEvent extends BaseRoomEvent {
|
export interface RoomMessageEvent extends BaseRoomEvent {
|
||||||
type: "RoomMessageEvent";
|
type: "RoomMessageEvent";
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@@ -1,11 +1,19 @@
|
|||||||
import { APIClient } from "../ApiClient";
|
import { APIClient } from "../ApiClient";
|
||||||
import type { Room } from "./MatrixApiRoom";
|
import type { Room } from "./MatrixApiRoom";
|
||||||
|
|
||||||
|
export type MessageType =
|
||||||
|
| "m.text"
|
||||||
|
| "m.image"
|
||||||
|
| "m.audio"
|
||||||
|
| "m.file"
|
||||||
|
| "m.video"
|
||||||
|
| "_OTHER_";
|
||||||
|
|
||||||
export interface MatrixRoomMessage {
|
export interface MatrixRoomMessage {
|
||||||
type: "m.room.message";
|
type: "m.room.message";
|
||||||
content: {
|
content: {
|
||||||
body: string;
|
body: string;
|
||||||
msgtype: "m.text" | "m.image" | string;
|
msgtype: MessageType;
|
||||||
"m.relates_to"?: {
|
"m.relates_to"?: {
|
||||||
event_id: string;
|
event_id: string;
|
||||||
rel_type: "m.replace" | string;
|
rel_type: "m.replace" | string;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import type {
|
|||||||
MatrixEvent,
|
MatrixEvent,
|
||||||
MatrixEventData,
|
MatrixEventData,
|
||||||
MatrixEventsList,
|
MatrixEventsList,
|
||||||
|
MessageType,
|
||||||
} from "../api/matrix/MatrixApiEvent";
|
} from "../api/matrix/MatrixApiEvent";
|
||||||
import type { Room } from "../api/matrix/MatrixApiRoom";
|
import type { Room } from "../api/matrix/MatrixApiRoom";
|
||||||
import type { WsMessage } from "../api/WsApi";
|
import type { WsMessage } from "../api/WsApi";
|
||||||
@@ -21,7 +22,8 @@ export interface Message {
|
|||||||
modified: boolean;
|
modified: boolean;
|
||||||
reactions: Map<string, MessageReaction[]>;
|
reactions: Map<string, MessageReaction[]>;
|
||||||
content: string;
|
content: string;
|
||||||
image?: string;
|
type: MessageType;
|
||||||
|
file?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class RoomEventsManager {
|
export class RoomEventsManager {
|
||||||
@@ -141,7 +143,8 @@ export class RoomEventsManager {
|
|||||||
reactions: new Map(),
|
reactions: new Map(),
|
||||||
time_sent: evt.time,
|
time_sent: evt.time,
|
||||||
time_sent_dayjs: dayjs.unix(evt.time / 1000),
|
time_sent_dayjs: dayjs.unix(evt.time / 1000),
|
||||||
image: data.content.file?.url ?? data.content.url,
|
type: data.content.msgtype,
|
||||||
|
file: data.content.file?.url ?? data.content.url,
|
||||||
content: data.content.body,
|
content: data.content.body,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import AddReactionIcon from "@mui/icons-material/AddReaction";
|
import AddReactionIcon from "@mui/icons-material/AddReaction";
|
||||||
import DeleteIcon from "@mui/icons-material/Delete";
|
import DeleteIcon from "@mui/icons-material/Delete";
|
||||||
import EditIcon from "@mui/icons-material/Edit";
|
import EditIcon from "@mui/icons-material/Edit";
|
||||||
|
import DownloadIcon from "@mui/icons-material/Download";
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Button,
|
Button,
|
||||||
@@ -220,7 +221,8 @@ function RoomMessage(p: {
|
|||||||
|
|
||||||
{/** Message itself */}
|
{/** Message itself */}
|
||||||
<div style={{ marginLeft: "15px", whiteSpace: "pre-wrap" }}>
|
<div style={{ marginLeft: "15px", whiteSpace: "pre-wrap" }}>
|
||||||
{p.message.image ? (
|
{/* Image */}
|
||||||
|
{p.message.type === "m.image" && (
|
||||||
<img
|
<img
|
||||||
onClick={() => setShowImageFullScreen(true)}
|
onClick={() => setShowImageFullScreen(true)}
|
||||||
src={MatrixApiEvent.GetEventFileURL(
|
src={MatrixApiEvent.GetEventFileURL(
|
||||||
@@ -232,9 +234,53 @@ function RoomMessage(p: {
|
|||||||
maxWidth: "200px",
|
maxWidth: "200px",
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
) : (
|
|
||||||
p.message.content
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Audio */}
|
||||||
|
{p.message.type === "m.audio" && (
|
||||||
|
<audio controls>
|
||||||
|
<source
|
||||||
|
src={MatrixApiEvent.GetEventFileURL(
|
||||||
|
p.room,
|
||||||
|
p.message.event_id,
|
||||||
|
false
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</audio>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Video */}
|
||||||
|
{p.message.type === "m.video" && (
|
||||||
|
<video controls style={{ maxHeight: "300px", maxWidth: "300px" }}>
|
||||||
|
<source
|
||||||
|
src={MatrixApiEvent.GetEventFileURL(
|
||||||
|
p.room,
|
||||||
|
p.message.event_id,
|
||||||
|
false
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</video>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* File */}
|
||||||
|
{p.message.type === "m.file" && (
|
||||||
|
<a
|
||||||
|
href={MatrixApiEvent.GetEventFileURL(
|
||||||
|
p.room,
|
||||||
|
p.message.event_id,
|
||||||
|
false
|
||||||
|
)}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener"
|
||||||
|
>
|
||||||
|
<Button variant="outlined" startIcon={<DownloadIcon />}>
|
||||||
|
{p.message.content}
|
||||||
|
</Button>
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Text message */}
|
||||||
|
{p.message.type === "m.text" && p.message.content}
|
||||||
</div>
|
</div>
|
||||||
<ButtonGroup
|
<ButtonGroup
|
||||||
className="buttons"
|
className="buttons"
|
||||||
@@ -257,7 +303,7 @@ function RoomMessage(p: {
|
|||||||
</Button>
|
</Button>
|
||||||
{/* Edit text message */}
|
{/* Edit text message */}
|
||||||
{p.message.account === user.info.matrix_user_id &&
|
{p.message.account === user.info.matrix_user_id &&
|
||||||
!p.message.image && (
|
!p.message.file && (
|
||||||
<Button onClick={handleEditMessage}>
|
<Button onClick={handleEditMessage}>
|
||||||
<EditIcon />
|
<EditIcon />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user