webpush improvements

This commit is contained in:
Egor 2026-02-16 21:52:53 -08:00
parent 66968834fb
commit 6027c1cac5
4 changed files with 46 additions and 10 deletions

View file

@ -167,7 +167,9 @@ details[open] > .card-header::before {
border: 0.0625rem solid var(--border-color);
font-size: 0.875rem;
font-weight: 400;
white-space: nowrap;
white-space: normal;
word-break: break-all;
max-width: 20rem;
transition: opacity 0.2s;
pointer-events: none;
z-index: 10;
@ -284,6 +286,10 @@ details[open] > .card-header::before {
pointer-events: none;
}
.badge-subscribed {
cursor: default;
}
.channel-signal.badge-active {
background: var(--accent);
color: var(--text-on-color);
@ -294,11 +300,21 @@ details[open] > .card-header::before {
background: transparent;
}
.channel-signal.badge-subscribed {
background: var(--accent);
color: var(--text-on-color);
}
.channel-webpush.badge-active {
background: var(--success);
color: var(--text-on-color);
}
.channel-webpush.badge-subscribed {
background: var(--success);
color: var(--text-on-color);
}
.channel-telegram.badge-active {
background: var(--accent);
color: var(--text-on-color);
@ -309,6 +325,11 @@ details[open] > .card-header::before {
background: transparent;
}
.channel-telegram.badge-subscribed {
background: var(--accent);
color: var(--text-on-color);
}
.app-actions {
display: flex;
gap: 0.5rem;

View file

@ -4,6 +4,7 @@ import (
"encoding/json"
"net/http"
"prism/service/notification"
"prism/service/util"
"github.com/go-chi/chi/v5"
@ -33,5 +34,24 @@ func (s *Server) handleGetApps(w http.ResponseWriter, r *http.Request) {
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(apps)
json.NewEncoder(w).Encode(sanitizeApps(apps))
}
func sanitizeApps(apps []notification.App) []notification.App {
sanitized := make([]notification.App, len(apps))
for i, app := range apps {
sanitized[i] = notification.App{
AppName: app.AppName,
Subscriptions: make([]notification.Subscription, len(app.Subscriptions)),
}
for j, sub := range app.Subscriptions {
sanitized[i].Subscriptions[j] = sub
if sub.WebPush != nil {
sanitized[i].Subscriptions[j].WebPush = &notification.WebPushSubscription{
Endpoint: sub.WebPush.Endpoint,
}
}
}
}
return sanitized
}

View file

@ -3,7 +3,6 @@ package server
import (
"bytes"
"net/http"
"net/url"
"prism/service/integration/signal"
"prism/service/notification"
@ -128,14 +127,10 @@ func (s *Server) buildAppListData(apps []notification.App) []AppListItem {
webPushSubs := []SubscriptionItem{}
for _, sub := range app.Subscriptions {
if sub.Channel == notification.ChannelWebPush && sub.WebPush != nil {
item := SubscriptionItem{
webPushSubs = append(webPushSubs, SubscriptionItem{
ID: sub.ID,
Tooltip: sub.WebPush.Endpoint,
}
if u, err := url.Parse(sub.WebPush.Endpoint); err == nil {
item.Hostname = u.Hostname()
}
webPushSubs = append(webPushSubs, item)
})
}
}

View file

@ -31,7 +31,7 @@
{{else}}
{{range .Subscriptions}}
<span class="channel-badge channel-{{$channel.Channel}} badge-subscribed">
{{$channel.Label}}{{if .Hostname}} ({{.Hostname}}){{end}}
{{$channel.Label}}
{{if .Tooltip}}<span class="tooltip">{{.Tooltip}}</span>{{end}}
<button type="button" class="btn-delete-sub"
hx-delete="/apps/{{$app.AppName}}/subscriptions/{{.ID}}"