add npub to db index and autocompletion

This commit is contained in:
Alejandro Gomez 2023-01-18 22:58:49 +01:00
parent 2f3c46629d
commit 8acdbe4f55
No known key found for this signature in database
GPG Key ID: 4DF39E566658C817
3 changed files with 13 additions and 5 deletions

View File

@ -1,4 +1,5 @@
import { HexKey, TaggedRawEvent, UserMetadata } from "../nostr";
import { hexToBech32 } from "../Util";
export interface MetadataCache extends UserMetadata {
/**
@ -22,6 +23,7 @@ export function mapEventToProfile(ev: TaggedRawEvent) {
let data: UserMetadata = JSON.parse(ev.content);
return {
pubkey: ev.pubkey,
npub: hexToBech32("npub", ev.pubkey),
created: ev.created_at,
loaded: new Date().getTime(),
...data

View File

@ -1,5 +1,6 @@
import Dexie, { Table } from 'dexie';
import { MetadataCache } from './User';
import Dexie, { Table } from "dexie";
import { MetadataCache } from "./User";
import { hexToBech32 } from "../Util";
export class SnortDB extends Dexie {
@ -7,8 +8,12 @@ export class SnortDB extends Dexie {
constructor() {
super('snortDB');
this.version(1).stores({
users: '++pubkey, name, display_name, picture, nip05' // Primary key and indexed props
this.version(2).stores({
users: '++pubkey, name, display_name, picture, nip05, npub'
}).upgrade(tx => {
return tx.table("users").toCollection().modify(user => {
user.npub = hexToBech32("npub", user.pubkey)
})
});
}
}

View File

@ -32,7 +32,8 @@ const Textarea = ({ users, onChange, ...rest }: any) => {
const allUsers = useLiveQuery(
() => db.users
.where("name").startsWithIgnoreCase(query)
.where("npub").startsWithIgnoreCase(query)
.or("name").startsWithIgnoreCase(query)
.or("display_name").startsWithIgnoreCase(query)
.or("nip05").startsWithIgnoreCase(query)
.limit(5)