From 8604dcd4059e6fbb6708b26e9b522ed986a38db8 Mon Sep 17 00:00:00 2001 From: BlowaterNostr <127284497+BlowaterNostr@users.noreply.github.com> Date: Tue, 26 Mar 2024 14:03:03 +0800 Subject: [PATCH] faster content filtering and record urls on new events (#439) --- app/UI/app_update.tsx | 13 +++++++++---- app/UI/dexie-db.ts | 2 +- app/UI/public-message-container.tsx | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/UI/app_update.tsx b/app/UI/app_update.tsx index 2dad22b..e56faf3 100644 --- a/app/UI/app_update.tsx +++ b/app/UI/app_update.tsx @@ -438,9 +438,14 @@ const handle_update_event = async (chan: PutChannel, args: { } continue; } else if (event.type == "FilterContent") { - const pubkey = PublicKey.FromBech32(event.content.trim()); - if (pubkey instanceof PublicKey) { - sync_user_detail_data({ pool, pubkey, database: app.database }); + const trimmed = event.content.trim(); + if (trimmed.length == 63) { + const pubkey = PublicKey.FromBech32(trimmed); + if (pubkey instanceof PublicKey) { + sync_user_detail_data({ pool, pubkey, database: app.database }); + } + } else { + continue; } } else { console.log(event, "is not handled"); @@ -665,7 +670,7 @@ async function sync_user_detail_data( if (msg.res.type == "EOSE") { break; } else if (msg.res.type == "EVENT") { - await args.database.addEvent(msg.res.event); + await args.database.addEvent(msg.res.event, msg.url); } } await args.pool.closeSub(args.pubkey.bech32()); diff --git a/app/UI/dexie-db.ts b/app/UI/dexie-db.ts index 6753743..f91b2a7 100644 --- a/app/UI/dexie-db.ts +++ b/app/UI/dexie-db.ts @@ -17,7 +17,7 @@ export class DexieDatabase extends Dexie implements EventsAdapter, RelayRecorder constructor() { super("Events"); - this.version(20).stores({ + this.version(22).stores({ events: "&id, created_at, kind, tags, pubkey", // indices relayRecords: "[url+event_id]", // RelayRecord eventMarks: "&event_id, reason", // RemoveRecords diff --git a/app/UI/public-message-container.tsx b/app/UI/public-message-container.tsx index 4bff192..c50008e 100644 --- a/app/UI/public-message-container.tsx +++ b/app/UI/public-message-container.tsx @@ -131,9 +131,6 @@ function filter_messages(msgs: ChatMessage[], filter: FilterContent) { const noteID = NoteID.FromBech32(filter_string); const is_note = noteID instanceof NoteID; msgs = msgs.filter((msg) => { - if (msg.content.toLocaleLowerCase().indexOf(filter_string) != -1) { - return true; - } if (is_pubkey) { if (msg.author.hex == pubkey.hex) { return true; @@ -144,6 +141,9 @@ function filter_messages(msgs: ChatMessage[], filter: FilterContent) { return true; } } + if (msg.content.toLocaleLowerCase().indexOf(filter_string) != -1) { + return true; + } return false; }); return msgs;