Returns recommended introduction actions for a given user, only when the viewer is that user themselves (owner gate ?__CURRENTUSER_multi_iri = ?_user_iri). One row per applicable recommendation, each carrying a ?recommendation text. A 'local introduction' is defined exactly as the UI's isIntroWithLocalKey: SIGNED BY the local key (?__LOCALPUBKEY_multi), DECLARING it, with the local-key declaration's location absent or matching ?__SITEURL_multi (nanobench->nanodash); localCount counts those. Branches: (1) create — localCount=0 (carries local-key bundle to prefill the create action); (2) get-approval — localCount=1 and the local key is not approved in the trust repo (carries the intro nanopub); (3) derive — localCount=0 but the user has introductions elsewhere; (4) retract — localCount>1; (5) update-approved — localCount>0, the local key is not approved, but the user has another approved key in the trust repo. No rows for non-owners or logged-out viewers. local_pubkey/short/site_url are action-mapping data (hidden from display).
prefix np: <http://www.nanopub.org/nschema#> prefix npx: <http://purl.org/nanopub/x/> prefix npa: <http://purl.org/nanopub/admin/> select ?recommendation ?intro_np ?local_pubkey ?local_pubkey_short ?site_url where { values ?__CURRENTUSER_multi_iri {} filter(?_user_iri = ?__CURRENTUSER_multi_iri) { # (1) create: no local introduction yet values ?__LOCALPUBKEY_multi {} values ?__SITEURL_multi {} filter(bound(?__LOCALPUBKEY_multi)) { select (count(distinct ?lnp) as ?localCount) where { values ?__LOCALPUBKEY_multi {} values ?__SITEURL_multi {} graph npa:graph { ?lnp npa:hasValidSignatureForPublicKey ?lsign . filter not exists { ?lnpx npx:invalidates ?lnp ; npa:hasValidSignatureForPublicKey ?lsign . } ?lnp np:hasAssertion ?la . } graph ?la { ?lkd npx:declaredBy ?_user_iri ; npx:hasPublicKey ?lpubkey . optional { ?lkd npx:hasKeyLocation ?lloc . } } filter(coalesce(str(?lsign) = str(?__LOCALPUBKEY_multi), false)) filter(coalesce(str(?lpubkey) = str(?__LOCALPUBKEY_multi), false)) filter(!bound(?lloc) || coalesce(str(?lloc) = str(?__SITEURL_multi), false) || coalesce(replace(str(?lloc), "nanobench", "nanodash") = str(?__SITEURL_multi), false)) } } filter(?localCount = 0) bind(coalesce(str(?__LOCALPUBKEY_multi), "") as ?local_pubkey) bind(if(strlen(?local_pubkey) >= 45, concat(substr(?local_pubkey, 1, 1), "..", substr(?local_pubkey, 41, 5), ".."), "") as ?local_pubkey_short) bind(coalesce(str(?__SITEURL_multi), "") as ?site_url) bind("The local key from this site is not part of an introduction yet. Create one to link it to your identity." as ?recommendation) } union { # (2) get-approval: exactly one local introduction, not yet approved values ?__LOCALPUBKEY_multi {} values ?__SITEURL_multi {} filter(bound(?__LOCALPUBKEY_multi)) { select (count(distinct ?lnp) as ?localCount) (sample(?lnp) as ?localIntroNp) where { values ?__LOCALPUBKEY_multi {} values ?__SITEURL_multi {} graph npa:graph { ?lnp npa:hasValidSignatureForPublicKey ?lsign . filter not exists { ?lnpx npx:invalidates ?lnp ; npa:hasValidSignatureForPublicKey ?lsign . } ?lnp np:hasAssertion ?la . } graph ?la { ?lkd npx:declaredBy ?_user_iri ; npx:hasPublicKey ?lpubkey . optional { ?lkd npx:hasKeyLocation ?lloc . } } filter(coalesce(str(?lsign) = str(?__LOCALPUBKEY_multi), false)) filter(coalesce(str(?lpubkey) = str(?__LOCALPUBKEY_multi), false)) filter(!bound(?lloc) || coalesce(str(?lloc) = str(?__SITEURL_multi), false) || coalesce(replace(str(?lloc), "nanobench", "nanodash") = str(?__SITEURL_multi), false)) } } filter(?localCount = 1) bind(lcase(sha256(str(?__LOCALPUBKEY_multi))) as ?lpkHash) filter not exists { service <https://w3id.org/np/l/nanopub-query-1.1/repo/trust> { graph npa:graph { npa:thisRepo npa:hasCurrentTrustState ?tg . } graph ?tg { ?acct npa:agent ?_user_iri ; npa:pubkey ?lpkHash ; npa:trustStatus npa:loaded . } } } bind("Your introduction with the local key is not approved yet. Share it so a maintainer can approve it:" as ?recommendation) bind(?localIntroNp as ?intro_np) } union { # (3) derive: no local introduction, but the user has introductions elsewhere values ?__LOCALPUBKEY_multi {} values ?__SITEURL_multi {} filter(bound(?__LOCALPUBKEY_multi)) { select (count(distinct ?lnp) as ?localCount) where { values ?__LOCALPUBKEY_multi {} values ?__SITEURL_multi {} graph npa:graph { ?lnp npa:hasValidSignatureForPublicKey ?lsign . filter not exists { ?lnpx npx:invalidates ?lnp ; npa:hasValidSignatureForPublicKey ?lsign . } ?lnp np:hasAssertion ?la . } graph ?la { ?lkd npx:declaredBy ?_user_iri ; npx:hasPublicKey ?lpubkey . optional { ?lkd npx:hasKeyLocation ?lloc . } } filter(coalesce(str(?lsign) = str(?__LOCALPUBKEY_multi), false)) filter(coalesce(str(?lpubkey) = str(?__LOCALPUBKEY_multi), false)) filter(!bound(?lloc) || coalesce(str(?lloc) = str(?__SITEURL_multi), false) || coalesce(replace(str(?lloc), "nanobench", "nanodash") = str(?__SITEURL_multi), false)) } } filter(?localCount = 0) filter exists { graph npa:graph { ?unp npa:hasValidSignatureForPublicKey ?uk . filter not exists { ?unpx npx:invalidates ?unp ; npa:hasValidSignatureForPublicKey ?uk . } ?unp np:hasAssertion ?ua . } graph ?ua { ?ukd npx:declaredBy ?_user_iri ; npx:hasPublicKey ?ukey . } } bind("You have introductions elsewhere, but none with this site's local key. Use 'derive new introduction' in the table below to declare those keys alongside the local key." as ?recommendation) } union { # (4) retract: more than one local introduction values ?__LOCALPUBKEY_multi {} values ?__SITEURL_multi {} filter(bound(?__LOCALPUBKEY_multi)) { select (count(distinct ?lnp) as ?localCount) where { values ?__LOCALPUBKEY_multi {} values ?__SITEURL_multi {} graph npa:graph { ?lnp npa:hasValidSignatureForPublicKey ?lsign . filter not exists { ?lnpx npx:invalidates ?lnp ; npa:hasValidSignatureForPublicKey ?lsign . } ?lnp np:hasAssertion ?la . } graph ?la { ?lkd npx:declaredBy ?_user_iri ; npx:hasPublicKey ?lpubkey . optional { ?lkd npx:hasKeyLocation ?lloc . } } filter(coalesce(str(?lsign) = str(?__LOCALPUBKEY_multi), false)) filter(coalesce(str(?lpubkey) = str(?__LOCALPUBKEY_multi), false)) filter(!bound(?lloc) || coalesce(str(?lloc) = str(?__SITEURL_multi), false) || coalesce(replace(str(?lloc), "nanobench", "nanodash") = str(?__SITEURL_multi), false)) } } filter(?localCount > 1) bind("You have multiple introductions from this site. Use 'retract' in the table below to remove the redundant ones." as ?recommendation) } union { # (5) update-approved: local key not approved, but the user has another approved key values ?__LOCALPUBKEY_multi {} values ?__SITEURL_multi {} filter(bound(?__LOCALPUBKEY_multi)) { select (count(distinct ?lnp) as ?localCount) where { values ?__LOCALPUBKEY_multi {} values ?__SITEURL_multi {} graph npa:graph { ?lnp npa:hasValidSignatureForPublicKey ?lsign . filter not exists { ?lnpx npx:invalidates ?lnp ; npa:hasValidSignatureForPublicKey ?lsign . } ?lnp np:hasAssertion ?la . } graph ?la { ?lkd npx:declaredBy ?_user_iri ; npx:hasPublicKey ?lpubkey . optional { ?lkd npx:hasKeyLocation ?lloc . } } filter(coalesce(str(?lsign) = str(?__LOCALPUBKEY_multi), false)) filter(coalesce(str(?lpubkey) = str(?__LOCALPUBKEY_multi), false)) filter(!bound(?lloc) || coalesce(str(?lloc) = str(?__SITEURL_multi), false) || coalesce(replace(str(?lloc), "nanobench", "nanodash") = str(?__SITEURL_multi), false)) } } filter(?localCount > 0) bind(lcase(sha256(str(?__LOCALPUBKEY_multi))) as ?lpkHash) filter not exists { service <https://w3id.org/np/l/nanopub-query-1.1/repo/trust> { graph npa:graph { npa:thisRepo npa:hasCurrentTrustState ?tg . } graph ?tg { ?acct npa:agent ?_user_iri ; npa:pubkey ?lpkHash ; npa:trustStatus npa:loaded . } } } filter exists { service <https://w3id.org/np/l/nanopub-query-1.1/repo/trust> { graph npa:graph { npa:thisRepo npa:hasCurrentTrustState ?tg2 . } graph ?tg2 { ?acct2 npa:agent ?_user_iri ; npa:pubkey ?okHash ; npa:trustStatus npa:loaded . filter(?okHash != ?lpkHash) } } } bind("Your local key is not approved, but you have an approved introduction elsewhere. Add this site's local key to that approved introduction, at the site where you created it." as ?recommendation) } }