repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

pico / bouncer
Eric Bower · 16 Aug 24

subscriber-change.diff

 1diff --git a/downstream.go b/downstream.go
 2index 8527e94..82e2158 100644
 3--- a/downstream.go
 4+++ b/downstream.go
 5@@ -2926,6 +2926,9 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
 6 				network.pushTargets.Del(target)
 7 			}
 8 			go network.broadcastWebPush(&irc.Message{
 9+				Tags: irc.Tags{
10+					"bouncerNetwork": strconv.FormatInt(dc.network.ID, 10),
11+				},
12 				Command: "MARKREAD",
13 				Params:  []string{target, timestampStr},
14 			})
15@@ -3173,6 +3176,10 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
16 				}}
17 			}
18 
19+			if filterCommands, filterCommandExists := rawKeys["filterCommands"]; filterCommandExists {
20+				endpoint = fmt.Sprintf("%s;%s", endpoint, filterCommands)
21+			}
22+
23 			newSub := database.WebPushSubscription{
24 				Endpoint: endpoint,
25 			}
26diff --git a/server.go b/server.go
27index 1f56205..4375fad 100644
28--- a/server.go
29+++ b/server.go
30@@ -10,6 +10,7 @@ import (
31 	"net"
32 	"net/http"
33 	"runtime/debug"
34+	"strings"
35 	"sync"
36 	"sync/atomic"
37 	"time"
38@@ -328,6 +329,15 @@ func (s *Server) sendWebPush(ctx context.Context, sub *webpush.Subscription, vap
39 	ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
40 	defer cancel()
41 
42+	if strings.Contains(sub.Endpoint, ";") {
43+		parts := strings.Split(sub.Endpoint, ";")
44+		sub.Endpoint = parts[0]
45+
46+		if !strings.Contains(parts[1], msg.Command) {
47+			return nil
48+		}
49+	}
50+
51 	var urgency webpush.Urgency
52 	switch msg.Command {
53 	case "PRIVMSG", "NOTICE", "INVITE":
54@@ -342,12 +352,10 @@ func (s *Server) sendWebPush(ctx context.Context, sub *webpush.Subscription, vap
55 		},
56 		VAPIDPublicKey:  s.webPush.VAPIDKeys.Public,
57 		VAPIDPrivateKey: s.webPush.VAPIDKeys.Private,
58-		// TODO: switch back to an HTTP URL once this is merged:
59-		// https://github.com/SherClockHolmes/webpush-go/pull/57
60-		Subscriber: "webpush@soju.im",
61-		TTL:        7 * 24 * 60 * 60, // seconds
62-		Urgency:    urgency,
63-		RecordSize: 2048,
64+		Subscriber:      "hello@pico.sh",
65+		TTL:             7 * 24 * 60 * 60, // seconds
66+		Urgency:         urgency,
67+		RecordSize:      2048,
68 	}
69 
70 	if vapidPubKey != options.VAPIDPublicKey {
71diff --git a/upstream.go b/upstream.go
72index 6de6445..d734fa0 100644
73--- a/upstream.go
74+++ b/upstream.go
75@@ -695,6 +695,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
76 		}
77 
78 		if sendPushNotification && (highlight || directMessage) {
79+			msg.Tags["bouncerNetwork"] = strconv.FormatInt(uc.network.ID, 10)
80 			go uc.network.broadcastWebPush(msg)
81 			if timestamp, err := time.Parse(xirc.ServerTimeLayout, string(msg.Tags["time"])); err == nil {
82 				uc.network.pushTargets.Set(bufferName, timestamp)
83@@ -1639,6 +1640,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
84 		})
85 
86 		if weAreInvited {
87+			msg.Tags["bouncerNetwork"] = strconv.FormatInt(uc.network.ID, 10)
88 			go uc.network.broadcastWebPush(msg)
89 		}
90 	case irc.RPL_INVITING: