add npub to db index and autocompletion
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
import { HexKey, TaggedRawEvent, UserMetadata } from "../nostr";
|
import { HexKey, TaggedRawEvent, UserMetadata } from "../nostr";
|
||||||
|
import { hexToBech32 } from "../Util";
|
||||||
|
|
||||||
export interface MetadataCache extends UserMetadata {
|
export interface MetadataCache extends UserMetadata {
|
||||||
/**
|
/**
|
||||||
@ -22,6 +23,7 @@ export function mapEventToProfile(ev: TaggedRawEvent) {
|
|||||||
let data: UserMetadata = JSON.parse(ev.content);
|
let data: UserMetadata = JSON.parse(ev.content);
|
||||||
return {
|
return {
|
||||||
pubkey: ev.pubkey,
|
pubkey: ev.pubkey,
|
||||||
|
npub: hexToBech32("npub", ev.pubkey),
|
||||||
created: ev.created_at,
|
created: ev.created_at,
|
||||||
loaded: new Date().getTime(),
|
loaded: new Date().getTime(),
|
||||||
...data
|
...data
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import Dexie, { Table } from 'dexie';
|
import Dexie, { Table } from "dexie";
|
||||||
import { MetadataCache } from './User';
|
import { MetadataCache } from "./User";
|
||||||
|
import { hexToBech32 } from "../Util";
|
||||||
|
|
||||||
|
|
||||||
export class SnortDB extends Dexie {
|
export class SnortDB extends Dexie {
|
||||||
@ -7,8 +8,12 @@ export class SnortDB extends Dexie {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super('snortDB');
|
super('snortDB');
|
||||||
this.version(1).stores({
|
this.version(2).stores({
|
||||||
users: '++pubkey, name, display_name, picture, nip05' // Primary key and indexed props
|
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(
|
const allUsers = useLiveQuery(
|
||||||
() => db.users
|
() => db.users
|
||||||
.where("name").startsWithIgnoreCase(query)
|
.where("npub").startsWithIgnoreCase(query)
|
||||||
|
.or("name").startsWithIgnoreCase(query)
|
||||||
.or("display_name").startsWithIgnoreCase(query)
|
.or("display_name").startsWithIgnoreCase(query)
|
||||||
.or("nip05").startsWithIgnoreCase(query)
|
.or("nip05").startsWithIgnoreCase(query)
|
||||||
.limit(5)
|
.limit(5)
|
||||||
|
Reference in New Issue
Block a user