about summary refs log tree commit diff stats
path: root/commands/account
diff options
context:
space:
mode:
Diffstat (limited to 'commands/account')
-rw-r--r--commands/account/next.go48
1 files changed, 29 insertions, 19 deletions
diff --git a/commands/account/next.go b/commands/account/next.go
index f306b48..7b1f230 100644
--- a/commands/account/next.go
+++ b/commands/account/next.go
@@ -24,8 +24,20 @@ func (_ NextPrevMsg) Complete(aerc *widgets.Aerc, args []string) []string {
 }
 
 func (_ NextPrevMsg) Execute(aerc *widgets.Aerc, args []string) error {
+	var err, n, pct = ParseNextPrevMessage(args)
+	if err != nil {
+		return err
+	}
+	acct := aerc.SelectedAccount()
+	if acct == nil {
+		return errors.New("No account selected")
+	}
+	return ExecuteNextPrevMessage(args, acct, pct, n)
+}
+
+func ParseNextPrevMessage(args []string) (error, int, bool) {
 	if len(args) > 2 {
-		return nextPrevMessageUsage(args[0])
+		return nextPrevMessageUsage(args[0]), 0, false
 	}
 	var (
 		n   int = 1
@@ -39,30 +51,28 @@ func (_ NextPrevMsg) Execute(aerc *widgets.Aerc, args []string) error {
 		}
 		n, err = strconv.Atoi(args[1])
 		if err != nil {
-			return nextPrevMessageUsage(args[0])
+			return nextPrevMessageUsage(args[0]), 0, false
 		}
 	}
-	acct := aerc.SelectedAccount()
-	if acct == nil {
-		return errors.New("No account selected")
-	}
+	return nil, n, pct
+}
+
+func ExecuteNextPrevMessage(args []string, acct *widgets.AccountView, pct bool, n int) error {
 	if pct {
 		n = int(float64(acct.Messages().Height()) * (float64(n) / 100.0))
 	}
-	for ; n > 0; n-- {
-		if args[0] == "prev-message" || args[0] == "prev" {
-			store := acct.Store()
-			if store != nil {
-				store.Prev()
-			}
-			acct.Messages().Scroll()
-		} else {
-			store := acct.Store()
-			if store != nil {
-				store.Next()
-			}
-			acct.Messages().Scroll()
+	if args[0] == "prev-message" || args[0] == "prev" {
+		store := acct.Store()
+		if store != nil {
+			store.NextPrev(-n)
+		}
+		acct.Messages().Scroll()
+	} else {
+		store := acct.Store()
+		if store != nil {
+			store.NextPrev(n)
 		}
+		acct.Messages().Scroll()
 	}
 	return nil
 }
14&id=893123ce21c5bf74880fd0ff79d587cbcc1789cf'>893123c ^
d437b89 ^


d2680fb ^
d20ad73 ^


f86e9b1 ^


6dad137 ^


45ee3c0 ^


f86e9b1 ^

6dad137 ^
d20ad73 ^
45ee3c0 ^
c4130e2 ^










45ee3c0 ^
c4130e2 ^
45ee3c0 ^

f86e9b1 ^
85f6000 ^
6dad137 ^



f86e9b1 ^

c4130e2 ^




f86e9b1 ^

d20ad73 ^
f86e9b1 ^









d2680fb ^
3bc4358 ^
3d2994b ^
d6fbc25 ^
3bc4358 ^
3d2994b ^
d2680fb ^
3bc4358 ^
d2680fb ^
f86e9b1 ^
efa99ed ^
f86e9b1 ^
5310d08 ^

d2680fb ^
3bc4358 ^
d2680fb ^
efa99ed ^
3bc4358 ^





5310d08 ^

910e69a ^
3bc4358 ^
5310d08 ^
5310d08 ^
3bc4358 ^

bd2800a ^
efa99ed ^
37bf8b0 ^

d2680fb ^
dfab6f2 ^
d2680fb ^
d2680fb ^
37bf8b0 ^





3bc4358 ^
37bf8b0 ^





d437b89 ^
d2680fb ^
3bc4358 ^

3bc4358 ^



d2680fb ^
efa99ed ^
711012e ^
dfab6f2 ^
3bc4358 ^

3bc4358 ^



d2680fb ^
893123c ^
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