Add support for replied messages
This commit is contained in:
parent
6264567ec9
commit
791883f580
5 changed files with 46 additions and 8 deletions
|
|
@ -57,7 +57,7 @@ const checkMessageCallback = (
|
|||
const registerModules = (client: MatrixClient) => {
|
||||
const startupTime = Date.now();
|
||||
|
||||
client.on(RoomEvent.Timeline, (event: MatrixEvent) => {
|
||||
client.on(RoomEvent.Timeline, async (event: MatrixEvent) => {
|
||||
const ts = event.getTs();
|
||||
if (ts < startupTime) {
|
||||
return;
|
||||
|
|
@ -83,6 +83,23 @@ const registerModules = (client: MatrixClient) => {
|
|||
return;
|
||||
}
|
||||
|
||||
const relatesTo = event.getContent()["m.relates_to"];
|
||||
const replyToId = relatesTo?.["m.in_reply_to"]?.event_id;
|
||||
let repliedMessage: string | undefined;
|
||||
|
||||
if (replyToId) {
|
||||
const repliedEvent = await client.fetchRoomEvent(roomId, replyToId);
|
||||
const repliedContent = repliedEvent.content;
|
||||
|
||||
if (repliedContent) {
|
||||
if (repliedContent.body) {
|
||||
repliedMessage = repliedContent.body.toString();
|
||||
} else if (repliedContent.formatted_body) {
|
||||
repliedMessage = repliedContent.formatted_body.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Message from ${sender} in ${roomId}: ${body}`);
|
||||
|
||||
onAnyMessage(client, body.toString(), roomId, sender);
|
||||
|
|
@ -97,7 +114,12 @@ const registerModules = (client: MatrixClient) => {
|
|||
sender,
|
||||
)
|
||||
) {
|
||||
callback.callbackFunc(body.toString(), roomId, sender);
|
||||
callback.callbackFunc(
|
||||
body.toString(),
|
||||
roomId,
|
||||
sender,
|
||||
repliedMessage,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue