Compare commits
2 Commits
123e069d18
...
62966473f0
| Author | SHA1 | Date | |
|---|---|---|---|
| 62966473f0 | |||
| c360432911 |
@@ -216,9 +216,7 @@ pub async fn event_file(
|
|||||||
MessageType::Video(c) => (c.source(), c.thumbnail_source()),
|
MessageType::Video(c) => (c.source(), c.thumbnail_source()),
|
||||||
_ => (None, None),
|
_ => (None, None),
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("{source:#?} {thumb_source:#?}");
|
|
||||||
|
|
||||||
let source = match (query.thumbnail, source, thumb_source) {
|
let source = match (query.thumbnail, source, thumb_source) {
|
||||||
(false, Some(s), _) => s,
|
(false, Some(s), _) => s,
|
||||||
(true, _, Some(s)) => s,
|
(true, _, Some(s)) => s,
|
||||||
|
|||||||
@@ -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: {
|
||||||
@@ -23,6 +22,7 @@ export interface RoomMessageEvent extends BaseRoomEvent {
|
|||||||
msgtype?: MessageType;
|
msgtype?: MessageType;
|
||||||
body?: string;
|
body?: string;
|
||||||
};
|
};
|
||||||
|
url?: string;
|
||||||
file?: { url: string };
|
file?: { url: string };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,24 @@
|
|||||||
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;
|
||||||
};
|
};
|
||||||
|
url?: string;
|
||||||
file?: {
|
file?: {
|
||||||
url: string;
|
url: 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 {
|
||||||
@@ -79,6 +81,7 @@ export class RoomEventsManager {
|
|||||||
rel_type: m.data["m.relates_to"].rel_type ?? "",
|
rel_type: m.data["m.relates_to"].rel_type ?? "",
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
|
url: m.data.url,
|
||||||
file: m.data.file,
|
file: m.data.file,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -140,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,
|
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