From 4bc9aaf6592e770a5aa4a8ac900df5bbd03bfb95 Mon Sep 17 00:00:00 2001 From: gildarts Date: Fri, 24 Jun 2022 14:41:13 -0400 Subject: [PATCH] Add detach option to channel update Add `-detached` to `channel update` command Co-authored-by: Simon Ser Closes: https://todo.sr.ht/~emersion/soju/140 --- doc/soju.1.scd | 7 +++++++ service.go | 12 +++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/soju.1.scd b/doc/soju.1.scd index 0c09255..4b7a7de 100644 --- a/doc/soju.1.scd +++ b/doc/soju.1.scd @@ -283,6 +283,13 @@ abbreviated form, for instance *network* can be abbreviated as *net* or just Options are: + *-detached* true|false + Attach or detach this channel. + + A detached channel is joined but is hidden by the bouncer. This is + useful to e.g. collect logs and highlights in low-interest or + high-traffic channels. + *-relay-detached* Set when to relay messages from detached channels to the user with a BouncerServ NOTICE. diff --git a/service.go b/service.go index feba0fa..689555f 100644 --- a/service.go +++ b/service.go @@ -288,7 +288,7 @@ func init() { handle: handleServiceChannelStatus, }, "update": { - usage: " [-relay-detached ] [-reattach-on ] [-detach-after ] [-detach-on ]", + usage: " [-detached ] [-relay-detached ] [-reattach-on ] [-detach-after ] [-detach-on ]", desc: "update a channel", handle: handleServiceChannelUpdate, }, @@ -1048,11 +1048,13 @@ func parseFilter(filter string) (database.MessageFilter, error) { type channelFlagSet struct { *flag.FlagSet + Detached *bool RelayDetached, ReattachOn, DetachAfter, DetachOn *string } func newChannelFlagSet() *channelFlagSet { fs := &channelFlagSet{FlagSet: newFlagSet()} + fs.Var(boolPtrFlag{&fs.Detached}, "detached", "") fs.Var(stringPtrFlag{&fs.RelayDetached}, "relay-detached", "") fs.Var(stringPtrFlag{&fs.ReattachOn}, "reattach-on", "") fs.Var(stringPtrFlag{&fs.DetachAfter}, "detach-after", "") @@ -1117,6 +1119,14 @@ func handleServiceChannelUpdate(ctx context.Context, dc *downstreamConn, params return err } + if fs.Detached != nil && *fs.Detached != ch.Detached { + if *fs.Detached { + uc.network.detach(ch) + } else { + uc.network.attach(ctx, ch) + } + } + uc.updateChannelAutoDetach(upstreamName) if err := dc.srv.db.StoreChannel(ctx, uc.network.ID, ch); err != nil {