rework client lists backend code.

This commit is contained in:
fiatjaf
2024-01-08 09:10:32 -03:00
parent a7325ea795
commit a9155a78b0
8 changed files with 94 additions and 81 deletions

View File

@@ -1,93 +1,106 @@
package main
import (
"strings"
"github.com/a-h/templ"
"github.com/nbd-wtf/go-nostr"
)
type ClientReference struct {
ID string
Name string
URL string
Base string
Platform string
}
func (c ClientReference) URL(code string) templ.SafeURL {
return templ.SafeURL(strings.Replace(c.Base, "{code}", code, -1))
}
var (
native = ClientReference{ID: "native", Name: "Your default app", Base: "nostr:{code}", Platform: "native"}
nosta = ClientReference{ID: "nosta", Name: "Nosta", Base: "https://nosta.me/{code}", Platform: "web"}
snort = ClientReference{ID: "snort", Name: "Snort", Base: "https://snort.social/p/{code}", Platform: "web"}
satellite = ClientReference{ID: "satellite", Name: "Satellite", Base: "https://satellite.earth/@{code}", Platform: "web"}
primalWeb = ClientReference{ID: "primal", Name: "Primal", Base: "https://primal.net/p/{code}", Platform: "web"}
nostrudel = ClientReference{ID: "nostrudel", Name: "Nostrudel", Base: "https://nostrudel.ninja/#/u/{code}", Platform: "web"}
nostter = ClientReference{ID: "nostter", Name: "Nostter", Base: "https://nostter.app/{code}", Platform: "web"}
iris = ClientReference{ID: "iris", Name: "Iris", Base: "https://iris.to/{code}", Platform: "web"}
coracle = ClientReference{ID: "coracle", Name: "Coracle", Base: "https://coracle.social/{code}", Platform: "web"}
zapStream = ClientReference{ID: "zap.stream", Name: "zap.stream", Base: "https://zap.stream/{code}", Platform: "web"}
nostrrr = ClientReference{ID: "nostrrr", Name: "Nostrrr", Base: "https://nostrrr.com/relay/{code}", Platform: "web"}
yakihonne = ClientReference{ID: "yakihonne", Name: "YakiHonne", Base: "https://yakihonne.com/article/{code}", Platform: "web"}
habla = ClientReference{ID: "habla", Name: "Habla", Base: "https://habla.news/a/{code}", Platform: "web"}
highlighter = ClientReference{ID: "highlighter", Name: "Highlighter", Base: "https://highlighter.com/a/{code}", Platform: "web"}
blogstack = ClientReference{ID: "blogstack", Name: "Blogstack", Base: "https://blogstack.io/{code}", Platform: "web"}
yanaAndroid = ClientReference{ID: "yana", Name: "Yana", Base: "intent:{code}#Intent;scheme=nostr;package=yana.nostr;end`;", Platform: "android"}
springAndroid = ClientReference{ID: "spring", Name: "Spring", Base: "intent:{code}#Intent;scheme=nostr;package=com.nostr.universe;end`;", Platform: "android"}
amethyst = ClientReference{ID: "amethyst", Name: "Amethyst", Base: "intent:{code}#Intent;scheme=nostr;package=com.vitorpamplona.amethyst;end`;", Platform: "android"}
freeFromAndroid = ClientReference{ID: "freefrom", Name: "FreeFrom", Base: "intent:{code}#Intent;scheme=nostr;package=com.freefrom;end`;", Platform: "android"}
currentAndroid = ClientReference{ID: "current", Name: "Current", Base: "intent:{code}#Intent;scheme=nostr;package=io.getcurrent.current;end`;", Platform: "android"}
plebstrAndroid = ClientReference{ID: "plebstr", Name: "Plebstr", Base: "intent:{code}#Intent;scheme=nostr;package=com.plebstr.client;end`;", Platform: "android"}
nos = ClientReference{ID: "nos", Name: "Nos", Base: "nos:{code}", Platform: "ios"}
damus = ClientReference{ID: "damus", Name: "Damus", Base: "damus:{code}", Platform: "ios"}
nostur = ClientReference{ID: "nostur", Name: "Nostur", Base: "nostur:{code}", Platform: "ios"}
primalIOS = ClientReference{ID: "primal", Name: "Primal", Base: "primal:{code}", Platform: "ios"}
freeFromIOS = ClientReference{ID: "freefrom", Name: "FreeFrom", Base: "freefrom:{code}", Platform: "ios"}
plebstrIOS = ClientReference{ID: "plebstr", Name: "Plebstr", Base: "plebstr:{code}", Platform: "ios"}
)
func generateClientList(code string, event *nostr.Event) []ClientReference {
clients := []ClientReference{
{ID: "native", Name: "Your default app", URL: "nostr:" + code, Platform: "native"},
switch event.Kind {
case 1, 6:
return []ClientReference{
native,
coracle, snort, nostter, nostrudel, primalWeb, satellite, iris,
nos, damus, nostur, primalIOS, freeFromIOS, plebstrIOS,
yanaAndroid, springAndroid, amethyst, currentAndroid, plebstrAndroid, freeFromAndroid,
}
case 0:
return []ClientReference{
native,
nosta, coracle, snort, nostter, nostrudel, primalWeb, satellite, iris,
nos, damus, nostur, primalIOS, freeFromIOS, plebstrIOS,
yanaAndroid, springAndroid, amethyst, currentAndroid, plebstrAndroid, freeFromAndroid,
}
case 30023, 30024:
return []ClientReference{
native,
yakihonne, habla, highlighter, blogstack,
damus, nos, nostur,
amethyst, springAndroid,
}
case 1063:
return []ClientReference{
native,
snort, coracle,
amethyst,
}
case 30311:
return []ClientReference{
native,
zapStream, nostrudel,
amethyst,
}
default:
return []ClientReference{
native,
coracle, snort, nostter, nostrudel, primalWeb, satellite, iris,
nos, damus, nostur, primalIOS, freeFromIOS, plebstrIOS,
yanaAndroid, springAndroid, amethyst, currentAndroid, plebstrAndroid, freeFromAndroid,
}
}
webClients_1_6 := []ClientReference{
{ID: "snort", Name: "Snort", URL: "https://Snort.social/e/" + code, Platform: "web"},
{ID: "nostrudel", Name: "Nostrudel", URL: "https://nostrudel.ninja/#/n/" + code, Platform: "web"},
{ID: "satellite", Name: "Satellite", URL: "https://satellite.earth/thread/" + event.ID, Platform: "web"},
{ID: "coracle", Name: "Coracle", URL: "https://coracle.social/" + code, Platform: "web"},
{ID: "primal", Name: "Primal", URL: "https://primal.net/thread/" + event.ID, Platform: "web"},
{ID: "nostter", Name: "Nostter", URL: "https://nostter.app/" + code, Platform: "web"},
{ID: "highlighter", Name: "Highlighter", URL: "https://highlighter.com/a/" + code, Platform: "web"},
{ID: "iris", Name: "Iris", URL: "https://iris.to/" + code, Platform: "web"},
}
webClients_0 := []ClientReference{
{ID: "nosta", Name: "Nosta", URL: "https://nosta.me/" + code, Platform: "web"},
{ID: "snort", Name: "Snort", URL: "https://snort.social/p/" + code, Platform: "web"},
{ID: "satellite", Name: "Satellite", URL: "https://satellite.earth/@" + code, Platform: "web"},
{ID: "coracle", Name: "Coracle", URL: "https://coracle.social/" + code, Platform: "web"},
{ID: "primal", Name: "Primal", URL: "https://primal.net/profile/" + event.PubKey, Platform: "web"},
{ID: "nostrudel", Name: "Nostrudel", URL: "https://nostrudel.ninja/#/u/" + code, Platform: "web"},
{ID: "nostter", Name: "Nostter", URL: "https://nostter.app/" + code, Platform: "web"},
{ID: "iris", Name: "Iris", URL: "https://iris.to/" + code, Platform: "web"},
}
webClients_30024 := []ClientReference{
{ID: "yakihonne", Name: "YakiHonne", URL: "https://yakihonne.com/article/" + code, Platform: "web"},
{ID: "habla", Name: "Habla", URL: "https://habla.news/a/" + code, Platform: "web"},
{ID: "highlighter", Name: "Highlighter", URL: "https://highlighter.com/a/" + code, Platform: "web"},
{ID: "blogstack", Name: "Blogstack", URL: "https://blogstack.io/" + code, Platform: "web"},
}
webClients_1063 := []ClientReference{
{ID: "native", Name: "your native client", URL: "nostr:" + code, Platform: "web"},
{ID: "snort", Name: "Snort", URL: "https://snort.social/p/" + code, Platform: "web"},
{ID: "coracle", Name: "Coracle", URL: "https://coracle.social/" + code, Platform: "web"},
}
androidClients := []ClientReference{
{ID: "yana", Name: "Yana", URL: "intent:" + code + "#Intent;scheme=nostr;package=yana.nostr;end`;", Platform: "android"},
{ID: "spring", Name: "Spring", URL: "intent:" + code + "#Intent;scheme=nostr;package=com.nostr.universe;end`;", Platform: "android"},
{ID: "amethyst", Name: "Amethyst", URL: "intent:" + code + "#Intent;scheme=nostr;package=com.vitorpamplona.amethyst;end`;", Platform: "android"},
{ID: "freefrom", Name: "FreeFrom", URL: "intent:" + code + "#Intent;scheme=nostr;package=com.freefrom;end`;", Platform: "android"},
{ID: "current", Name: "Current", URL: "intent:" + code + "#Intent;scheme=nostr;package=io.getcurrent.current;end`;", Platform: "android"},
{ID: "plebstr", Name: "Plebstr", URL: "intent:" + code + "#Intent;scheme=nostr;package=com.plebstr.client;end`;", Platform: "android"},
// {ID: "", Name: "", URL: "intent:" + code + "#Intent;scheme=nostr;package=;end`;", Platform: "app"},
}
iosClients := []ClientReference{
{ID: "nos", Name: "Nos", URL: "nos:" + code, Platform: "ios"},
{ID: "damus", Name: "Damus", URL: "damus:" + code, Platform: "ios"},
{ID: "nostur", Name: "Nostur", URL: "nostur:" + code, Platform: "ios"},
{ID: "primal", Name: "Primal", URL: "primal:" + code, Platform: "ios"},
{ID: "freefrom", Name: "FreeFrom", URL: "freefrom:" + code, Platform: "ios"},
{ID: "plebstr", Name: "Plbestr", URL: "plebstr:" + code, Platform: "ios"},
}
clients = append(clients, androidClients...)
clients = append(clients, iosClients...)
if event.Kind == 1 || event.Kind == 6 {
clients = append(clients, webClients_1_6...)
} else if event.Kind == 0 {
clients = append(clients, webClients_0...)
} else if event.Kind == 30023 || event.Kind == 30024 {
clients = append(clients, webClients_30024...)
} else if event.Kind == 1063 {
clients = append(clients, webClients_1063...)
}
return clients
}
func generateRelayBrowserClientList(host string) []ClientReference {
return []ClientReference{
{ID: "coracle", Name: "Coracle", URL: "https://coracle.social/relays/" + host, Platform: "web"},
coracle,
nostrrr,
}
}

View File

@@ -1,6 +1,6 @@
package main
templ clientsTemplate(clients []ClientReference) {
templ clientsTemplate(clients []ClientReference, code string) {
<aside class="fixed bottom-0 left-0 top-auto mt-4 w-full basis-3/12 self-start transition-all duration-500 print:hidden sm:sticky sm:bottom-auto sm:left-auto sm:top-8 sm:w-auto">
<div class="absolute right-0 top-0 z-10 mb-4 h-10 w-10 text-center text-sm sm:relative sm:h-auto sm:w-auto">
<span class="hidden sm:block">Open in</span>
@@ -70,7 +70,7 @@ templ clientsTemplate(clients []ClientReference) {
>
<a
class="client block basis-full px-3 py-3 text-left text-[17px] font-normal leading-4 text-white no-underline sm:inline sm:py-1.5 sm:text-center sm:font-light"
href={ templ.SafeURL(client.URL) }
href={ client.URL(code) }
>
<span class="ml-1.5 pr-2 inline basis-1/5 text-neutral-400 sm:hidden">Open in</span>
{ client.Name }

View File

@@ -64,7 +64,7 @@ templ fileMetadataTemplate(params FileMetadataPageParams) {
@detailsTemplate(params.DetailsParams)
<div class="-ml-4 mb-6 h-1.5 w-1/3 bg-zinc-100 dark:bg-zinc-700 sm:-ml-2.5"></div>
</div>
@clientsTemplate(params.Clients)
@clientsTemplate(params.Clients, params.Nevent)
</div>
</div>
@footerTemplate()

View File

@@ -67,7 +67,7 @@ templ liveEventTemplate(params LiveEventPageParams) {
@detailsTemplate(params.DetailsParams)
<div class="-ml-4 mb-6 h-1.5 w-1/3 bg-zinc-100 dark:bg-zinc-700 sm:-ml-2.5"></div>
</div>
@clientsTemplate(params.Clients)
@clientsTemplate(params.Clients, params.Nevent)
</div>
</div>
@footerTemplate()

View File

@@ -43,7 +43,7 @@ templ liveEventMessageTemplate(params LiveEventMessagePageParams) {
@detailsTemplate(params.DetailsParams)
<div class="-ml-4 mb-6 h-1.5 w-1/3 bg-zinc-100 dark:bg-zinc-700 sm:-ml-2.5"></div>
</div>
@clientsTemplate(params.Clients)
@clientsTemplate(params.Clients, params.Nevent)
</div>
</div>
@footerTemplate()

View File

@@ -43,7 +43,7 @@ templ noteTemplate(params NotePageParams) {
@detailsTemplate(params.DetailsParams)
<div class="-ml-4 mb-6 h-1.5 w-1/3 bg-zinc-100 dark:bg-zinc-700 sm:-ml-2.5"></div>
</div>
@clientsTemplate(params.Clients)
@clientsTemplate(params.Clients, params.Nevent)
</div>
</div>
@footerTemplate()

View File

@@ -147,7 +147,7 @@ templ profileTemplate(params ProfilePageParams) {
</div>
<div class="-ml-4 mb-6 h-1.5 w-1/3 bg-zinc-100 sm:-ml-2.5 dark:bg-zinc-700"></div>
</div>
@clientsTemplate(params.Clients)
@clientsTemplate(params.Clients, params.Metadata.Npub())
</div>
</div>
@footerTemplate()

View File

@@ -136,7 +136,7 @@ templ relayTemplate(params RelayPageParams) {
</div>
</aside>
</div>
@clientsTemplate(params.Clients)
@clientsTemplate(params.Clients, params.Hostname)
</div>
</div>
@footerTemplate()