Handle typing events
This commit is contained in:
@@ -69,7 +69,8 @@ export type WsMessage =
|
|||||||
| RoomMessageEvent
|
| RoomMessageEvent
|
||||||
| RoomReactionEvent
|
| RoomReactionEvent
|
||||||
| RoomRedactionEvent
|
| RoomRedactionEvent
|
||||||
| RoomReceiptEvent;
|
| RoomReceiptEvent
|
||||||
|
| RoomTypingEvent;
|
||||||
|
|
||||||
export class WsApi {
|
export class WsApi {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,11 +31,13 @@ export class RoomEventsManager {
|
|||||||
private events: MatrixEvent[];
|
private events: MatrixEvent[];
|
||||||
messages: Message[];
|
messages: Message[];
|
||||||
endToken?: string;
|
endToken?: string;
|
||||||
|
typingUsers: string[];
|
||||||
|
|
||||||
constructor(room: Room, initialMessages: MatrixEventsList) {
|
constructor(room: Room, initialMessages: MatrixEventsList) {
|
||||||
this.room = room;
|
this.room = room;
|
||||||
this.events = [];
|
this.events = [];
|
||||||
this.messages = [];
|
this.messages = [];
|
||||||
|
this.typingUsers = [];
|
||||||
|
|
||||||
this.processNewEvents(initialMessages);
|
this.processNewEvents(initialMessages);
|
||||||
}
|
}
|
||||||
@@ -88,6 +90,9 @@ export class RoomEventsManager {
|
|||||||
file: m.data.file,
|
file: m.data.file,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
} else if (m.type === "TypingEvent") {
|
||||||
|
this.typingUsers = m.user_ids;
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// Ignore event
|
// Ignore event
|
||||||
console.info("Event not supported => ignored");
|
console.info("Event not supported => ignored");
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
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 { useSnackbar } from "../../hooks/contexts_provider/SnackbarProvider";
|
||||||
import { RoomEventsManager } from "../../utils/RoomEventsManager";
|
import { RoomEventsManager } from "../../utils/RoomEventsManager";
|
||||||
import { RoomMessagesList } from "./RoomMessagesList";
|
import { RoomMessagesList } from "./RoomMessagesList";
|
||||||
import { SendMessageForm } from "./SendMessageForm";
|
import { SendMessageForm } from "./SendMessageForm";
|
||||||
import { MatrixApiEvent } from "../../api/matrix/MatrixApiEvent";
|
import { TypingNotice } from "./TypingNotice";
|
||||||
import { useSnackbar } from "../../hooks/contexts_provider/SnackbarProvider";
|
|
||||||
|
|
||||||
export function RoomWidget(p: {
|
export function RoomWidget(p: {
|
||||||
room: Room;
|
room: Room;
|
||||||
@@ -36,6 +37,7 @@ export function RoomWidget(p: {
|
|||||||
onClick={handleRoomClick}
|
onClick={handleRoomClick}
|
||||||
>
|
>
|
||||||
<RoomMessagesList {...p} />
|
<RoomMessagesList {...p} />
|
||||||
|
<TypingNotice {...p} />
|
||||||
<SendMessageForm {...p} />
|
<SendMessageForm {...p} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
35
matrixgw_frontend/src/widgets/messages/TypingNotice.tsx
Normal file
35
matrixgw_frontend/src/widgets/messages/TypingNotice.tsx
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { Typography } from "@mui/material";
|
||||||
|
import React from "react";
|
||||||
|
import type { UsersMap } from "../../api/matrix/MatrixApiProfile";
|
||||||
|
import type { RoomEventsManager } from "../../utils/RoomEventsManager";
|
||||||
|
import { useUserInfo } from "../dashboard/BaseAuthenticatedPage";
|
||||||
|
|
||||||
|
export function TypingNotice(p: {
|
||||||
|
users: UsersMap;
|
||||||
|
manager: RoomEventsManager;
|
||||||
|
}): React.ReactElement {
|
||||||
|
const user = useUserInfo();
|
||||||
|
|
||||||
|
const users = React.useMemo(
|
||||||
|
() =>
|
||||||
|
[...p.users.values()].filter(
|
||||||
|
(u) =>
|
||||||
|
p.manager.typingUsers.includes(u.user_id) &&
|
||||||
|
u.user_id !== user.info.matrix_user_id
|
||||||
|
),
|
||||||
|
[p.manager.typingUsers]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (users.length === 0) return <></>;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Typography
|
||||||
|
variant="caption"
|
||||||
|
component="div"
|
||||||
|
style={{ paddingLeft: "20px" }}
|
||||||
|
>
|
||||||
|
{users.map((u) => u.display_name ?? u.display_name).join(", ")}{" "}
|
||||||
|
{users.length > 1 ? "are" : "is"} typing...
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user