Search is working. More could be added I suppose. Added treating petnames as ids.

This commit is contained in:
Robert C. Martin 2023-02-21 14:16:13 -06:00
parent aee5ca8af3
commit 280ed9b187
2 changed files with 15 additions and 5 deletions

View File

@ -77,5 +77,13 @@
{:id 153N :pubkey 2N :content "" {:id 153N :pubkey 2N :content ""
:tags [[:e (util/hexify 1N)] :tags [[:e (util/hexify 1N)]
[:p (util/hexify 88N)]]}))) [:p (util/hexify 88N)]]})))
(it "should match if petname matches any p tag"
(set-mem :pubkey 99N)
(gateway/add-contacts @db 99N [{:pubkey 1N :petname "pet"}])
(should (match-target "pet"
{:id 153N :pubkey 2N :content ""
:tags [[:e (util/hexify 1N)]
[:p (util/hexify 88N)]]})))
) )
) )

View File

@ -29,13 +29,15 @@
(defn match-string-target [target event] (defn match-string-target [target event]
(let [content (formatters/replace-references event) (let [content (formatters/replace-references event)
author-name (:name (gateway/get-profile (get-db) (:pubkey event))) author-name (:name (gateway/get-profile (get-db) (:pubkey event)))
author-id (contact-list/get-pubkey-from-petname target)
petname (contact-list/get-petname (:pubkey event)) petname (contact-list/get-petname (:pubkey event))
subject (get-subject event) subject (get-subject event)
re-target (re-pattern target)] re-target (re-pattern target)]
(or (re-find re-target content) (or (re-find re-target content)
(and subject (re-find re-target subject)) (and subject (re-find re-target subject))
(and author-name (re-find re-target author-name)) (and author-name (re-find re-target author-name))
(and petname (re-find re-target petname))))) (and petname (re-find re-target petname))
(and author-id (match-id author-id event)))))
(defn match-npub [target event] (defn match-npub [target event]
(match-id (bech32/address->number target) event)) (match-id (bech32/address->number target) event))