repos / pico

pico services mono repo
git clone https://github.com/picosh/pico.git

pico / bouncer
Antonio Mika  ·  2025-01-14

subscriber-change.diff

 1diff --git a/downstream.go b/downstream.go
 2index 78044e1..c95a0f6 100644
 3--- a/downstream.go
 4+++ b/downstream.go
 5@@ -3102,6 +3102,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@@ -3350,6 +3353,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 f6e1cf6..9114580 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@@ -333,6 +334,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@@ -347,7 +357,7 @@ 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-		Subscriber:      "https://soju.im",
59+		Subscriber:      "hello@pico.sh",
60 		TTL:             7 * 24 * 60 * 60, // seconds
61 		Urgency:         urgency,
62 		RecordSize:      2048,
63diff --git a/upstream.go b/upstream.go
64index ea309f4..e198dc7 100644
65--- a/upstream.go
66+++ b/upstream.go
67@@ -694,6 +694,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
68 		}
69 
70 		if !self && !detached && msg.Command != "TAGMSG" && (highlight || directMessage) {
71+			msg.Tags["bouncerNetwork"] = strconv.FormatInt(uc.network.ID, 10)
72 			go uc.network.broadcastWebPush(msg)
73 			if timestamp, err := time.Parse(xirc.ServerTimeLayout, string(msg.Tags["time"])); err == nil {
74 				uc.network.pushTargets.Set(bufferName, timestamp)
75@@ -1640,6 +1641,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
76 		})
77 
78 		if weAreInvited {
79+			msg.Tags["bouncerNetwork"] = strconv.FormatInt(uc.network.ID, 10)
80 			go uc.network.broadcastWebPush(msg)
81 		}
82 	case irc.RPL_INVITING: