Add topics database table

This commit is contained in:
Jonathan Staab 2023-04-12 16:41:37 -05:00
parent f019b64695
commit 8573140134
2 changed files with 16 additions and 2 deletions

View File

@ -209,6 +209,7 @@ export const contacts = new Table("contacts", "pubkey")
export const rooms = new Table("rooms", "id")
export const relays = new Table("relays", "url")
export const routes = new Table("routes", "id", {max: 3000, sort: sortByLastSeen})
export const topics = new Table("topics", "name")
export const getPersonWithFallback = pubkey => people.get(pubkey) || {pubkey}
export const getRelayWithFallback = url => relays.get(url) || {url}

View File

@ -1,4 +1,4 @@
import {uniq, pick, identity} from "ramda"
import {uniq, nth, objOf, pick, identity} from "ramda"
import {nip05} from "nostr-tools"
import {noop, ensurePlural, chunk} from "hurdak/lib/hurdak"
import {
@ -13,7 +13,7 @@ import {
hash,
} from "src/util/misc"
import {Tags, roomAttrs, isRelay, isShareableRelay, normalizeRelayUrl} from "src/util/nostr"
import {people, userEvents, relays, rooms, routes} from "src/agent/db"
import {topics, people, userEvents, relays, rooms, routes} from "src/agent/db"
import {uniqByUrl} from "src/agent/relays"
import user from "src/agent/user"
@ -341,4 +341,17 @@ addHandler(10002, e => {
})
})
// Topics
const processTopics = e => {
const matches = Array.from(e.content.matchAll(/#(\w{2,100})/g))
if (matches.length > 0) {
topics.patch(matches.map(nth(1)).map(objOf("name")))
}
}
addHandler(1, processTopics)
addHandler(42, processTopics)
export default {processEvents}