author | Mikael Berthe <mikael@lilotux.net> |
Sun, 13 Jan 2019 12:28:07 +0100 | |
changeset 243 | 1bec7d3d6a85 |
parent 239 | 605a00e9d1ab |
child 265 | 05c40b36d3b2 |
child 267 | 5b91a65ba95a |
permissions | -rw-r--r-- |
185 | 1 |
// Copyright © 2017-2018 Mikael Berthe <mikael@lilotux.net> |
0 | 2 |
// |
3 |
// Licensed under the MIT license. |
|
4 |
// Please see the LICENSE file is this directory. |
|
5 |
||
6 |
package cmd |
|
7 |
||
8 |
import ( |
|
47
82d8b6074309
Set exit code to non-zero when API calls fail
Mikael Berthe <mikael@lilotux.net>
parents:
45
diff
changeset
|
9 |
"os" |
165
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
10 |
"strings" |
47
82d8b6074309
Set exit code to non-zero when API calls fail
Mikael Berthe <mikael@lilotux.net>
parents:
45
diff
changeset
|
11 |
|
45
b58a7ea1aeb2
Use github.com/pkg/errors
Mikael Berthe <mikael@lilotux.net>
parents:
44
diff
changeset
|
12 |
"github.com/pkg/errors" |
0 | 13 |
"github.com/spf13/cobra" |
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
14 |
|
239
605a00e9d1ab
Switch to Go modules (and bump Go version requirement)
Mikael Berthe <mikael@lilotux.net>
parents:
197
diff
changeset
|
15 |
"github.com/McKael/madon/v2" |
0 | 16 |
) |
17 |
||
18 |
var notificationsOpts struct { |
|
19
4c81f4393773
Add notification --dismiss to clear a single notification
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
19 |
list, clear, dismiss bool |
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
20 |
notifID int64 |
165
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
21 |
types string |
197
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
22 |
excludeTypes string |
0 | 23 |
} |
24 |
||
25 |
// notificationsCmd represents the notifications subcommand |
|
26 |
var notificationsCmd = &cobra.Command{ |
|
27 |
Use: "notifications", // XXX |
|
28 |
Aliases: []string{"notification", "notif"}, |
|
29 |
Short: "Manage notifications", |
|
30 |
Example: ` madonctl accounts notifications --list |
|
31 |
madonctl accounts notifications --list --clear |
|
19
4c81f4393773
Add notification --dismiss to clear a single notification
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
32 |
madonctl accounts notifications --dismiss --notification-id N |
165
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
33 |
madonctl accounts notifications --notification-id N |
197
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
34 |
madonctl accounts notifications --list --exclude-types mention,reblog |
165
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
35 |
madonctl accounts notifications --list --notification-types mentions |
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
36 |
madonctl accounts notifications --list --notification-types favourites |
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
37 |
madonctl accounts notifications --list --notification-types follows,reblogs`, |
197
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
38 |
Long: `Manage notifications |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
39 |
|
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
40 |
This commands let you list, display and dismiss notifications. |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
41 |
|
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
42 |
Please note that --notifications-types filters the notifications locally, |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
43 |
while --exclude-types is supported by the API and should be more efficient.`, |
0 | 44 |
RunE: notificationRunE, |
45 |
} |
|
46 |
||
47 |
func init() { |
|
48 |
accountsCmd.AddCommand(notificationsCmd) |
|
49 |
||
50 |
notificationsCmd.Flags().BoolVar(¬ificationsOpts.list, "list", false, "List all current notifications") |
|
51 |
notificationsCmd.Flags().BoolVar(¬ificationsOpts.clear, "clear", false, "Clear all current notifications") |
|
19
4c81f4393773
Add notification --dismiss to clear a single notification
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
52 |
notificationsCmd.Flags().BoolVar(¬ificationsOpts.dismiss, "dismiss", false, "Delete a notification") |
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
53 |
notificationsCmd.Flags().Int64Var(¬ificationsOpts.notifID, "notification-id", 0, "Get a notification") |
197
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
54 |
notificationsCmd.Flags().StringVar(¬ificationsOpts.types, "notification-types", "", "Filter notifications (mention, favourite, reblog, follow)") |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
55 |
notificationsCmd.Flags().StringVar(¬ificationsOpts.excludeTypes, "exclude-types", "", "Exclude notifications types (mention, favourite, reblog, follow)") |
0 | 56 |
} |
57 |
||
58 |
func notificationRunE(cmd *cobra.Command, args []string) error { |
|
59 |
opt := notificationsOpts |
|
60 |
||
61 |
if !opt.list && !opt.clear && opt.notifID < 1 { |
|
62 |
return errors.New("missing parameters") |
|
63 |
} |
|
64 |
||
65 |
if err := madonInit(true); err != nil { |
|
66 |
return err |
|
67 |
} |
|
68 |
||
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
69 |
var limOpts *madon.LimitParams |
30
14561d44211b
Add option --all to fetch all available results
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
70 |
if accountsOpts.all || accountsOpts.limit > 0 || accountsOpts.sinceID > 0 || accountsOpts.maxID > 0 { |
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
19
diff
changeset
|
71 |
limOpts = new(madon.LimitParams) |
30
14561d44211b
Add option --all to fetch all available results
Mikael Berthe <mikael@lilotux.net>
parents:
22
diff
changeset
|
72 |
limOpts.All = accountsOpts.all |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
73 |
} |
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
74 |
|
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
75 |
if accountsOpts.limit > 0 { |
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
19
diff
changeset
|
76 |
limOpts.Limit = int(accountsOpts.limit) |
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
19
diff
changeset
|
77 |
} |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
78 |
if accountsOpts.maxID > 0 { |
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
79 |
limOpts.MaxID = int64(accountsOpts.maxID) |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
80 |
} |
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
81 |
if accountsOpts.sinceID > 0 { |
44
6da40ca4534c
Sync with Madon; switch IDs to int64 integers
Mikael Berthe <mikael@lilotux.net>
parents:
30
diff
changeset
|
82 |
limOpts.SinceID = int64(accountsOpts.sinceID) |
22
5778b09bc6fe
Add --since-id and --max-id
Mikael Berthe <mikael@lilotux.net>
parents:
20
diff
changeset
|
83 |
} |
20
b0ccc09f07a2
Sync with Madon library update; use limit API parameter
Mikael Berthe <mikael@lilotux.net>
parents:
19
diff
changeset
|
84 |
|
166
79c0f8db66ff
Add --notification-types to the stream command as well
Mikael Berthe <mikael@lilotux.net>
parents:
165
diff
changeset
|
85 |
var filterMap *map[string]bool |
165
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
86 |
if opt.types != "" { |
166
79c0f8db66ff
Add --notification-types to the stream command as well
Mikael Berthe <mikael@lilotux.net>
parents:
165
diff
changeset
|
87 |
var err error |
79c0f8db66ff
Add --notification-types to the stream command as well
Mikael Berthe <mikael@lilotux.net>
parents:
165
diff
changeset
|
88 |
filterMap, err = buildFilterMap(opt.types) |
79c0f8db66ff
Add --notification-types to the stream command as well
Mikael Berthe <mikael@lilotux.net>
parents:
165
diff
changeset
|
89 |
if err != nil { |
197
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
90 |
return errors.Wrap(err, "bad notification filter") |
165
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
91 |
} |
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
92 |
} |
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
93 |
|
197
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
94 |
var xTypes []string |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
95 |
if xt, err := splitNotificationTypes(opt.excludeTypes); err == nil { |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
96 |
xTypes = xt |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
97 |
} else { |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
98 |
return errors.Wrap(err, "invalid exclude-types argument") |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
99 |
} |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
100 |
|
0 | 101 |
var obj interface{} |
102 |
var err error |
|
103 |
||
104 |
if opt.list { |
|
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
105 |
var notifications []madon.Notification |
197
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
106 |
notifications, err = gClient.GetNotifications(xTypes, limOpts) |
165
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
107 |
|
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
108 |
// Filter notifications |
166
79c0f8db66ff
Add --notification-types to the stream command as well
Mikael Berthe <mikael@lilotux.net>
parents:
165
diff
changeset
|
109 |
if filterMap != nil && len(*filterMap) > 0 { |
165
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
110 |
if verbose { |
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
111 |
errPrint("Filtering notifications") |
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
112 |
} |
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
113 |
var newNotifications []madon.Notification |
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
114 |
for _, notif := range notifications { |
166
79c0f8db66ff
Add --notification-types to the stream command as well
Mikael Berthe <mikael@lilotux.net>
parents:
165
diff
changeset
|
115 |
if (*filterMap)[notif.Type] { |
165
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
116 |
newNotifications = append(newNotifications, notif) |
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
117 |
} |
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
118 |
} |
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
119 |
notifications = newNotifications |
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
120 |
} |
e76422bfe6ee
Add --notification-types flag to filter notifications
Mikael Berthe <mikael@lilotux.net>
parents:
110
diff
changeset
|
121 |
|
167
1341bacd01c9
Add option --keep to keep the N last items
Mikael Berthe <mikael@lilotux.net>
parents:
166
diff
changeset
|
122 |
if accountsOpts.keep > 0 && len(notifications) > int(accountsOpts.keep) { |
1341bacd01c9
Add option --keep to keep the N last items
Mikael Berthe <mikael@lilotux.net>
parents:
166
diff
changeset
|
123 |
notifications = notifications[:accountsOpts.keep] |
13
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
124 |
} |
f862af8faf17
Add option --limit (-l) to limit the number of displayed results
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
125 |
obj = notifications |
0 | 126 |
} else if opt.notifID > 0 { |
19
4c81f4393773
Add notification --dismiss to clear a single notification
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
127 |
if opt.dismiss { |
4c81f4393773
Add notification --dismiss to clear a single notification
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
128 |
err = gClient.DismissNotification(opt.notifID) |
4c81f4393773
Add notification --dismiss to clear a single notification
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
129 |
} else { |
4c81f4393773
Add notification --dismiss to clear a single notification
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
130 |
obj, err = gClient.GetNotification(opt.notifID) |
4c81f4393773
Add notification --dismiss to clear a single notification
Mikael Berthe <mikael@lilotux.net>
parents:
13
diff
changeset
|
131 |
} |
0 | 132 |
} |
133 |
||
134 |
if err == nil && opt.clear { |
|
135 |
err = gClient.ClearNotifications() |
|
136 |
} |
|
137 |
||
138 |
if err != nil { |
|
139 |
errPrint("Error: %s", err.Error()) |
|
47
82d8b6074309
Set exit code to non-zero when API calls fail
Mikael Berthe <mikael@lilotux.net>
parents:
45
diff
changeset
|
140 |
os.Exit(1) |
0 | 141 |
} |
142 |
if obj == nil { |
|
143 |
return nil |
|
144 |
} |
|
145 |
||
146 |
p, err := getPrinter() |
|
147 |
if err != nil { |
|
81
b1671f83e91b
Do not display usage when GetPrinter fails
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
148 |
errPrint("Error: %s", err.Error()) |
b1671f83e91b
Do not display usage when GetPrinter fails
Mikael Berthe <mikael@lilotux.net>
parents:
47
diff
changeset
|
149 |
os.Exit(1) |
0 | 150 |
} |
110 | 151 |
return p.printObj(obj) |
0 | 152 |
} |
166
79c0f8db66ff
Add --notification-types to the stream command as well
Mikael Berthe <mikael@lilotux.net>
parents:
165
diff
changeset
|
153 |
|
197
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
154 |
func splitNotificationTypes(types string) ([]string, error) { |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
155 |
var typeList []string |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
156 |
if types == "" { |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
157 |
return typeList, nil |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
158 |
} |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
159 |
for _, f := range strings.Split(types, ",") { |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
160 |
switch f { |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
161 |
case "mention", "mentions": |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
162 |
f = "mention" |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
163 |
case "favourite", "favourites", "favorite", "favorites", "fave", "faves": |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
164 |
f = "favourite" |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
165 |
case "reblog", "reblogs", "retoot", "retoots": |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
166 |
f = "reblog" |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
167 |
case "follow", "follows": |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
168 |
f = "follow" |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
169 |
default: |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
170 |
return nil, errors.Errorf("unknown notification type: '%s'", f) |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
171 |
} |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
172 |
typeList = append(typeList, f) |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
173 |
} |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
174 |
return typeList, nil |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
175 |
} |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
176 |
|
166
79c0f8db66ff
Add --notification-types to the stream command as well
Mikael Berthe <mikael@lilotux.net>
parents:
165
diff
changeset
|
177 |
func buildFilterMap(types string) (*map[string]bool, error) { |
79c0f8db66ff
Add --notification-types to the stream command as well
Mikael Berthe <mikael@lilotux.net>
parents:
165
diff
changeset
|
178 |
filterMap := make(map[string]bool) |
197
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
179 |
if types == "" { |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
180 |
return &filterMap, nil |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
181 |
} |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
182 |
for _, f := range strings.Split(types, ",") { |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
183 |
switch f { |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
184 |
case "mention", "mentions": |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
185 |
filterMap["mention"] = true |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
186 |
case "favourite", "favourites", "favorite", "favorites", "fave", "faves": |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
187 |
filterMap["favourite"] = true |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
188 |
case "reblog", "reblogs", "retoot", "retoots": |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
189 |
filterMap["reblog"] = true |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
190 |
case "follow", "follows": |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
191 |
filterMap["follow"] = true |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
192 |
default: |
0b0fd2f02296
Add '--exclude-types' to accounts notifications --list
Mikael Berthe <mikael@lilotux.net>
parents:
185
diff
changeset
|
193 |
return nil, errors.Errorf("unknown notification type: '%s'", f) |
166
79c0f8db66ff
Add --notification-types to the stream command as well
Mikael Berthe <mikael@lilotux.net>
parents:
165
diff
changeset
|
194 |
} |
79c0f8db66ff
Add --notification-types to the stream command as well
Mikael Berthe <mikael@lilotux.net>
parents:
165
diff
changeset
|
195 |
} |
79c0f8db66ff
Add --notification-types to the stream command as well
Mikael Berthe <mikael@lilotux.net>
parents:
165
diff
changeset
|
196 |
return &filterMap, nil |
79c0f8db66ff
Add --notification-types to the stream command as well
Mikael Berthe <mikael@lilotux.net>
parents:
165
diff
changeset
|
197 |
} |