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

@ -29,14 +29,14 @@
(it "should match if re-target is in content" (it "should match if re-target is in content"
(should (should
(match-target "#\"t\\w+t\"" {:id 1N :pubkey 2N (match-target "#\"t\\w+t\"" {:id 1N :pubkey 2N
:tags [] :tags []
:content "the target is here"}))) :content "the target is here"})))
(it "should match if re-target is in subject" (it "should match if re-target is in subject"
(should (should
(match-target "#\"t\\w+t\"" {:id 1N :pubkey 2N (match-target "#\"t\\w+t\"" {:id 1N :pubkey 2N
:tags [[:e 1N] [:subject "the target is here"]] :tags [[:e 1N] [:subject "the target is here"]]
:content "nope"}))) :content "nope"})))
(it "should match if user name is target and user is embedded with #[n]" (it "should match if user name is target and user is embedded with #[n]"
(gateway/add-profile @db 1N {:name "user-name"}) (gateway/add-profile @db 1N {:name "user-name"})
@ -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))