repos / pico

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

commit
2ea92f9
parent
81fd732
author
Antonio Mika
date
2023-11-16 21:56:51 +0000 UTC
Update soju patch to include selective message notifications
1 files changed,  +41, -7
M bouncer/subscriber-change.diff
+41, -7
 1@@ -1,5 +1,5 @@
 2 diff --git a/downstream.go b/downstream.go
 3-index f383212..b59dc29 100644
 4+index f383212..35082d4 100644
 5 --- a/downstream.go
 6 +++ b/downstream.go
 7 @@ -2947,6 +2947,9 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
 8@@ -12,11 +12,46 @@ index f383212..b59dc29 100644
 9  				Command: "MARKREAD",
10  				Params:  []string{target, timestampStr},
11  			})
12+@@ -3198,6 +3201,10 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
13+ 				}}
14+ 			}
15+ 
16++			if filterCommands, filterCommandExists := rawKeys["filterCommands"]; filterCommandExists {
17++				endpoint = fmt.Sprintf("%s;%s", endpoint, filterCommands)
18++			}
19++
20+ 			newSub := database.WebPushSubscription{
21+ 				Endpoint: endpoint,
22+ 			}
23 diff --git a/server.go b/server.go
24-index 552104e..498d827 100644
25+index 552104e..251635c 100644
26 --- a/server.go
27 +++ b/server.go
28-@@ -339,7 +339,7 @@ func (s *Server) sendWebPush(ctx context.Context, sub *webpush.Subscription, vap
29+@@ -10,6 +10,7 @@ import (
30+ 	"net"
31+ 	"net/http"
32+ 	"runtime/debug"
33++	"strings"
34+ 	"sync"
35+ 	"sync/atomic"
36+ 	"time"
37+@@ -325,6 +326,15 @@ func (s *Server) sendWebPush(ctx context.Context, sub *webpush.Subscription, vap
38+ 	ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
39+ 	defer cancel()
40+ 
41++	if strings.Contains(";", sub.Endpoint) {
42++		parts := strings.Split(sub.Endpoint, ";")
43++		sub.Endpoint = parts[0]
44++
45++		if !strings.Contains(parts[1], msg.Command) {
46++			return nil
47++		}
48++	}
49++
50+ 	var urgency webpush.Urgency
51+ 	switch msg.Command {
52+ 	case "PRIVMSG", "NOTICE", "INVITE":
53+@@ -339,7 +349,7 @@ func (s *Server) sendWebPush(ctx context.Context, sub *webpush.Subscription, vap
54  		},
55  		VAPIDPublicKey:  s.webPush.VAPIDKeys.Public,
56  		VAPIDPrivateKey: s.webPush.VAPIDKeys.Private,
57@@ -26,19 +61,18 @@ index 552104e..498d827 100644
58  		Urgency:         urgency,
59  		RecordSize:      2048,
60 diff --git a/upstream.go b/upstream.go
61-index ca56a82..a7c5dbb 100644
62+index ca56a82..8ff0a55 100644
63 --- a/upstream.go
64 +++ b/upstream.go
65-@@ -682,6 +682,8 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
66+@@ -682,6 +682,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
67  		}
68  
69  		if highlight || directMessage {
70 +			msg.Tags["bouncerNetwork"] = strconv.FormatInt(uc.network.ID, 10)
71-+
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-@@ -1611,6 +1613,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
76+@@ -1611,6 +1612,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
77  		})
78  
79  		if weAreInvited {