From 0feb664405f4a575a8a2b9fa7f3e57e936532b52 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 2 Mar 2020 22:02:21 -0500 Subject: [PATCH] Remove wallet and convs from options, and instead automatically enable them if the correct handlers are present --- chat.go | 35 ++++++++++++++++++----------------- types.go | 2 -- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/chat.go b/chat.go index a636f92..555e6bd 100644 --- a/chat.go +++ b/chat.go @@ -115,37 +115,38 @@ func getNewMessages(k *Keybase, subs *SubscriptionChannels, execOptions []string } // Run runs `keybase chat api-listen`, and passes incoming messages to the message handler func -func (k *Keybase) Run(handlers Handlers, options ...RunOptions) { +func (k *Keybase) Run(handlers Handlers, options *RunOptions) { var channelCapacity = 100 runOptions := make([]string, 0) - if len(options) > 0 { - if options[0].Capacity > 0 { - channelCapacity = options[0].Capacity - } - if options[0].Wallet { - runOptions = append(runOptions, "--wallet") - } - if options[0].Convs { - runOptions = append(runOptions, "--convs") + if handlers.WalletHandler != nil { + runOptions = append(runOptions, "--wallet") + } + if handlers.ConversationHandler != nil { + runOptions = append(runOptions, "--convs") + } + + if options != nil { + if options.Capacity > 0 { + channelCapacity = options.Capacity } - if options[0].Local { + if options.Local { runOptions = append(runOptions, "--local") } - if options[0].HideExploding { + if options.HideExploding { runOptions = append(runOptions, "--hide-exploding") } - if options[0].Dev { + if options.Dev { runOptions = append(runOptions, "--dev") } - if len(options[0].FilterChannels) > 0 { + if len(options.FilterChannels) > 0 { runOptions = append(runOptions, "--filter-channels") - runOptions = append(runOptions, createFiltersString(options[0].FilterChannels)) + runOptions = append(runOptions, createFiltersString(options.FilterChannels)) } - if options[0].FilterChannel.Name != "" { + if options.FilterChannel.Name != "" { runOptions = append(runOptions, "--filter-channel") - runOptions = append(runOptions, createFilterString(options[0].FilterChannel)) + runOptions = append(runOptions, createFilterString(options.FilterChannel)) } } diff --git a/types.go b/types.go index b8c4ba6..114cefc 100644 --- a/types.go +++ b/types.go @@ -16,8 +16,6 @@ type RunOptions struct { Local bool // Subscribe to local messages HideExploding bool // Ignore exploding messages Dev bool // Subscribe to dev channel messages - Wallet bool // Subscribe to wallet events - Convs bool // Subscribe to new-conversation events FilterChannel chat1.ChatChannel // Only subscribe to messages from specified channel FilterChannels []chat1.ChatChannel // Only subscribe to messages from specified channels }