~emersion/soju-dev

Add detach option to channel update v1 APPLIED

gildarts: 2
 Add detach option to channel update
 Add detach option to channel update

 2 files changed, 23 insertions(+), 2 deletions(-)
Pushed with a minor edit (see below) and a man page update. Thanks!

On Friday, June 24th, 2022 at 20:41, gildarts <gildarts@orbital.rocks> wrote:
Next
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/soju-dev/patches/33206/mbox | git am -3
Learn more about email & git

[PATCH] Add detach option to channel update Export this patch

Add `--detached` to `channel update` command
---
 service.go | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/service.go b/service.go
index feba0fa..e425f6c 100644
--- a/service.go
+++ b/service.go
@@ -288,7 +288,7 @@ func init() {
					handle: handleServiceChannelStatus,
				},
				"update": {
					usage:  "<name> [-relay-detached <default|none|highlight|message>] [-reattach-on <default|none|highlight|message>] [-detach-after <duration>] [-detach-on <default|none|highlight|message>]",
					usage:  "<name> [--detached <true|false>] [-relay-detached <default|none|highlight|message>] [-reattach-on <default|none|highlight|message>] [-detach-after <duration>] [-detach-on <default|none|highlight|message>]",
					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,15 @@ func handleServiceChannelUpdate(ctx context.Context, dc *downstreamConn, params
		return err
	}

	detached := *fs.Detached
	if detached != ch.Detached {
		if detached {
			uc.network.detach(ch)
		} else if !detached {
			uc.network.attach(ctx, ch)
		}
	}

	uc.updateChannelAutoDetach(upstreamName)

	if err := dc.srv.db.StoreChannel(ctx, uc.network.ID, ch); err != nil {
-- 
2.36.1.windows.1
Nice and simple! Two small comments below.

On Wednesday, June 22nd, 2022 at 22:44, gildarts <gildarts@orbital.rocks> wrote:

[PATCH v2] Add detach option to channel update Export this patch

Add `-detached` to `channel update` command
---
Fixed double `-` in help text
Add guard for nil flag values

 service.go | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/service.go b/service.go
index feba0fa..57ca104 100644
--- a/service.go
+++ b/service.go
@@ -288,7 +288,7 @@ func init() {
					handle: handleServiceChannelStatus,
				},
				"update": {
					usage:  "<name> [-relay-detached <default|none|highlight|message>] [-reattach-on <default|none|highlight|message>] [-detach-after <duration>] [-detach-on <default|none|highlight|message>]",
					usage:  "<name> [-detached <true|false>] [-relay-detached <default|none|highlight|message>] [-reattach-on <default|none|highlight|message>] [-detach-after <duration>] [-detach-on <default|none|highlight|message>]",
					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 if !*fs.Detached {
			uc.network.attach(ctx, ch)
		}
	}

	uc.updateChannelAutoDetach(upstreamName)

	if err := dc.srv.db.StoreChannel(ctx, uc.network.ID, ch); err != nil {
-- 
2.36.1.windows.1
Pushed with a minor edit (see below) and a man page update. Thanks!

On Friday, June 24th, 2022 at 20:41, gildarts <gildarts@orbital.rocks> wrote: