add npub to db index and autocompletion
This commit is contained in:
parent
2f3c46629d
commit
8acdbe4f55
@ -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
|
||||
|
@ -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)
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user