Debian Codegraph @

commands/account/connection.go

raw
1 package account
2
3 import (
4 "context"
5 "errors"
6
7 "git.sr.ht/~rjarry/aerc/app"
8 "git.sr.ht/~rjarry/aerc/commands"
9 "git.sr.ht/~rjarry/aerc/lib/state"
10 "git.sr.ht/~rjarry/aerc/worker/types"
11 )
12
13 type Connection struct{}
14
15 func init() {
16 commands.Register(Connection{})
17 }
18
19 func (Connection) Description() string {
20 return "Disconnect or reconnect the current account."
21 }
22
23 func (Connection) Context() commands.CommandContext {
24 return commands.MESSAGE_LIST
25 }
26
27 func (Connection) Aliases() []string {
28 return []string{"connect", "disconnect"}
29 }
30
31 func (c Connection) Execute(args []string) error {
32 acct := app.SelectedAccount()
33 if acct == nil {
34 return errors.New("No account selected")
35 }
36 cb := func(msg types.WorkerMessage) {
37 acct.SetStatus(state.ConnectionActivity(""))
38 }
39 if args[0] == "connect" {
40 acct.Worker().PostAction(context.TODO(), &types.Connect{}, cb)
41 acct.SetStatus(state.ConnectionActivity("Connecting..."))
42 } else {
43 acct.Worker().PostAction(context.TODO(), &types.Disconnect{}, cb)
44 acct.SetStatus(state.ConnectionActivity("Disconnecting..."))
45 }
46 return nil
47 }