about summary refs log tree commit diff stats
path: root/WWW/Library/Implementation/HTList.c
Commit message (Collapse)AuthorAgeFilesLines
* snapshot of project "lynx", label v2-8-9dev_11cThomas E. Dickey2016-11-241-7/+1
|
* snapshot of project "lynx", label v2-8-8dev-15bThomas E. Dickey2013-05-011-13/+13
|
* snapshot of project "lynx", label v2-8-8dev_11Thomas E. Dickey2012-02-201-0/+408
|
* snapshot of project "lynx", label v2-8-8dev_10bThomas E. Dickey2012-02-201-408/+0
|
* snapshot of project "lynx", label v2-8-8dev_8mThomas E. Dickey2011-06-111-0/+408
|
* snapshot of project "lynx", label v2_8_8dev_9aThomas E. Dickey2011-06-111-408/+0
|
* snapshot of project "lynx", label v2-8-8dev_3cThomas E. Dickey2010-05-031-0/+408
|
* snapshot of project "lynx", label v2_8_8dev_6cThomas E. Dickey2010-04-291-402/+0
|
* snapshot of project "lynx", label v2-8-7dev_9nThomas E. Dickey2008-09-211-3/+6
|
* snapshot of project "lynx", label v2-8-6dev_3Thomas E. Dickey2004-05-071-125/+92
|
* snapshot of project "lynx", label v2-8-6dev_2Thomas E. Dickey2004-04-271-45/+45
|
* snapshot of project "lynx", label v2-8-5dev_15Thomas E. Dickey2003-04-281-2/+6
|
* snapshot of project "lynx", label v2-8-5dev_14Thomas E. Dickey2003-02-051-3/+15
|
* snapshot of project "lynx", label v2-8-5dev_13Thomas E. Dickey2003-01-221-0/+70
|
* snapshot of project "lynx", label v2-8-5dev_11Thomas E. Dickey2002-12-021-3/+3
|
* snapshot of project "lynx", label v2-8-4dev_20Thomas E. Dickey2001-04-021-17/+17
|
* snapshot of project "lynx", label v2-8-3dev_10Thomas E. Dickey1999-09-291-8/+8
|
* snapshot of project "lynx", label v2-8-2dev_14Thomas E. Dickey1999-01-181-1/+45
|
* snapshot of project "lynx", label v2-8-2dev_2Thomas E. Dickey1998-11-101-17/+5
|
* snapshot of project "lynx", label v2-8-1dev_4Thomas E. Dickey1998-11-061-5/+17
|
* snapshot of project "lynx", label v2-8-1dev_20Thomas E. Dickey1998-08-061-3/+0
|
* snapshot of project "lynx", label v2-8-1dev_17Thomas E. Dickey1998-06-251-2/+0
|
* snapshot of project "lynx", label v2-8-1dev_7Thomas E. Dickey1998-04-231-12/+5
|
* snapshot of project "lynx", label v2-8-1dev_5Thomas E. Dickey1998-03-291-3/+3
|
* snapshot of project "lynx", label v2-7-1ac_0-105Thomas E. Dickey1998-01-021-1/+1
|
* snapshot of project "lynx", label v2_6fm_970129Thomas E. Dickey1997-01-291-0/+52
|
* snapshot of project "lynx", label v2_6Thomas E. Dickey1996-09-021-0/+262
title='author Reto Brunner <reto@labrat.space> 2019-12-22 12:05:28 +0100 committer Drew DeVault <sir@cmpwn.com> 2019-12-22 16:21:38 -0500 read: adapt to ProvidesMessages' href='/akspecs/aerc/commit/commands/msg/read.go?id=ce42429cbf2e2565e019f5e2cc0c538534b78196'>ce42429 ^
0535f63 ^













a1763bf ^
0535f63 ^









a1763bf ^
0535f63 ^

ce42429 ^
0535f63 ^
ce42429 ^
a1763bf ^
6271d45 ^
0535f63 ^













8446d48 ^
6271d45 ^
0535f63 ^


ce42429 ^

0535f63 ^



ce42429 ^




caad1b2 ^
ce42429 ^




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195


           
             
              
              
 

                                    
                                      
                                         



                                               
                     
 
             
                           

 

                                                           

 
                                                                     
                  

 







































                                                                            


                          



                                     

























                                                                                                        
                 
         










                                                  
 

                               


                          
 


                                                              
 













                                                                      
                         









                                                                    
                 

                                          
                        
                                           
                 
         
 













                                                                                    
                                                                                                     
                 


                  

 



                                                                        




                                          
                                                               




                                        
package msg

import (
	"fmt"
	"sync"
	"time"

	"git.sr.ht/~sircmpwn/getopt"

	"git.sr.ht/~sircmpwn/aerc/lib"
	"git.sr.ht/~sircmpwn/aerc/models"
	"git.sr.ht/~sircmpwn/aerc/widgets"
	"git.sr.ht/~sircmpwn/aerc/worker/types"
)

type FlagMsg struct{}

func init() {
	register(FlagMsg{})
}

func (FlagMsg) Aliases() []string {
	return []string{"flag", "unflag", "read", "unread"}
}

func (FlagMsg) Complete(aerc *widgets.Aerc, args []string) []string {
	return nil
}

// If this was called as 'flag' or 'unflag', without the toggle (-t)
// option, then it will flag the corresponding messages with the given
// flag.  If the toggle option was given, it will individually toggle
// the given flag for the corresponding messages.
//
// If this was called as 'read' or 'unread', it has the same effect as
// 'flag' or 'unflag', respectively, but the 'Seen' flag is affected.
func (FlagMsg) Execute(aerc *widgets.Aerc, args []string) error {

	// The flag to change
	var flag models.Flag
	// User-readable name of the flag to change
	var flagName string
	// Whether to toggle the flag (true) or to enable/disable it (false)
	var toggle bool
	// Whether to enable (true) or disable (false) the flag
	enable := (args[0] == "read" || args[0] == "flag")
	// User-readable name for the action being performed
	var actionName string
	// Getopt option string, varies by command name
	var getoptString string
	// Help message to provide on parsing failure
	var helpMessage string
	// Used during parsing to prevent choosing a flag muliple times
	// A default flag will be used if this is false
	flagChosen := false

	if args[0] == "read" || args[0] == "unread" {
		flag = models.SeenFlag
		flagName = "read"
		getoptString = "t"
		helpMessage = "Usage: " + args[0] + " [-t]"
	} else { // 'flag' / 'unflag'
		flag = models.FlaggedFlag
		flagName = "flagged"
		getoptString = "tax:"
		helpMessage = "Usage: " + args[0] + " [-t] [-a | -x <flag>]"
	}

	opts, optind, err := getopt.Getopts(args, getoptString)
	if err != nil {
		return err
	}
	for _, opt := range opts {
		switch opt.Option {
		case 't':
			toggle = true
		case 'a':
			if flagChosen {
				return fmt.Errorf("Cannot choose a flag multiple times! " + helpMessage)
			}
			flag = models.AnsweredFlag
			flagName = "answered"
			flagChosen = true
		case 'x':
			if flagChosen {
				return fmt.Errorf("Cannot choose a flag multiple times! " + helpMessage)
			}
			// TODO: Support all flags?
			switch opt.Value {
			case "Seen":
				flag = models.SeenFlag
				flagName = "seen"
			case "Answered":
				flag = models.AnsweredFlag
				flagName = "answered"
			case "Flagged":
				flag = models.FlaggedFlag
				flagName = "flagged"
			default:
				return fmt.Errorf("Unknown / Prohibited flag \"%v\"", opt.Value)
			}
			flagChosen = true
		}
	}
	if toggle {
		actionName = "Toggling"
	} else if enable {
		actionName = "Setting"
	} else {
		actionName = "Unsetting"
	}
	if optind != len(args) {
		// Any non-option arguments: Error
		return fmt.Errorf(helpMessage)
	}

	h := newHelper(aerc)
	store, err := h.store()
	if err != nil {
		return err
	}

	// UIDs of messages to enable or disable the flag for.
	var toEnable []uint32
	var toDisable []uint32

	if toggle {
		// If toggling, split messages into those that need to
		// be enabled / disabled.
		msgs, err := h.messages()
		if err != nil {
			return err
		}
		for _, m := range msgs {
			var enabled bool
			for _, mFlag := range m.Flags {
				if mFlag == flag {
					enabled = true
					break
				}
			}
			if enabled {
				toDisable = append(toDisable, m.Uid)
			} else {
				toEnable = append(toEnable, m.Uid)
			}
		}
	} else {
		msgUids, err := h.markedOrSelectedUids()
		if err != nil {
			return err
		}
		if enable {
			toEnable = msgUids
		} else {
			toDisable = msgUids
		}
	}

	var wg sync.WaitGroup
	success := true

	if len(toEnable) != 0 {
		submitFlagChange(aerc, store, toEnable, flag, true, &wg, &success)
	}
	if len(toDisable) != 0 {
		submitFlagChange(aerc, store, toDisable, flag, false, &wg, &success)
	}

	// We need to do flagging in the background, else we block the main thread
	go func() {
		wg.Wait()
		if success {
			aerc.PushStatus(actionName+" flag '"+flagName+"' successful", 10*time.Second)
		}
	}()

	return nil
}

func submitFlagChange(aerc *widgets.Aerc, store *lib.MessageStore,
	uids []uint32, flag models.Flag, newState bool,
	wg *sync.WaitGroup, success *bool) {
	store.Flag(uids, flag, newState, func(msg types.WorkerMessage) {
		wg.Add(1)
		switch msg := msg.(type) {
		case *types.Done:
			wg.Done()
		case *types.Error:
			aerc.PushError(" " + msg.Error.Error())
			*success = false
			wg.Done()
		}
	})
}