matrix-search

A small nodejs script which indexes a whole matrix account into meilisearch and has a pdf rendering UI
git clone git://archive.git.mtrnord.blog/MTRNord/matrix-search.git
Log | Files | Refs | README | LICENSE

commit 485e0483421c88509f61bf79582668a95a84fc89
parent cd5df6a05aabb2f33b2027a8ee4243ae97227004
Author: MTRNord <mtrnord1@gmail.com>
Date:   Tue, 15 Oct 2024 02:03:45 +0200

Try to fix various sync issues

Diffstat:
Msrc/bot.ts | 4++--
Msrc/renderer.tsx | 2+-
Msrc/tiny-sdk.ts | 7++++++-
3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/bot.ts b/src/bot.ts @@ -94,9 +94,9 @@ function convertEventToDocument(event: any, roomId: string, room_name?: string) async function handleMessages(indexer: Indexer, client: MatrixClient, roomId: string, event: any, historical = false) { if (event["content"]["msgtype"] === "m.text") { - const user = await client.whoami(); + const user = client.userId?.toString(); // If command and sender is bot user then handle as a command and not index - if (event["content"]["body"].startsWith("!") && event["sender"] === user.user_id && !historical) { + if (event["content"]["body"].startsWith("!") && event["sender"] === user && !historical) { // Get the command directly after the ! (e.g. !search -> search) const command = event["content"]["body"].split(" ")[0].substring(1); const args: string[] = event["content"]["body"].split(" ").slice(1); diff --git a/src/renderer.tsx b/src/renderer.tsx @@ -60,7 +60,7 @@ export const MessageDocument = ({ query, room_id, sender, queryResults }: PropsW <View> {queryResults.hits.map((result, index) => ( <View - wrap={result.content.body.length > 500} + wrap={result.content.body?.length > 500} key={index} style={{ flexDirection: 'column', diff --git a/src/tiny-sdk.ts b/src/tiny-sdk.ts @@ -29,7 +29,7 @@ export type WhoAmIResponse = { } export class MatrixClient { - private userId?: UserId; + public userId?: UserId; private deviceId?: DeviceId; public olmMachine?: OlmMachine; private syncRunning: boolean = true; @@ -219,6 +219,11 @@ export class MatrixClient { } async decryptEvent(event: Record<string, any>, roomId: string): Promise<Record<string, any>> { + if (event["type"] === "m.room.member") { + if (event.content.membership !== 'join' && event.content.membership !== 'invite') return event; + await this.addTrackedUsers([event["state_key"] as string]) + return event; + } if (event.type === "m.room.encrypted") { const members = await this.getRoomMembers(roomId, ['join', 'invite']); await this.addTrackedUsers(members.map(e => e["state_key"] as string))