cmd/notifications.go
changeset 166 79c0f8db66ff
parent 165 e76422bfe6ee
child 167 1341bacd01c9
--- a/cmd/notifications.go	Sat Jul 15 12:07:37 2017 +0200
+++ b/cmd/notifications.go	Sat Jul 15 21:58:24 2017 +0200
@@ -74,21 +74,12 @@
 		limOpts.SinceID = int64(accountsOpts.sinceID)
 	}
 
-	filterMap := make(map[string]bool)
+	var filterMap *map[string]bool
 	if opt.types != "" {
-		for _, f := range strings.Split(opt.types, ",") {
-			switch f {
-			case "mention", "mentions":
-				filterMap["mention"] = true
-			case "favourite", "favourites", "favorite", "favorites", "fave", "faves":
-				filterMap["favourite"] = true
-			case "reblog", "reblogs", "retoot", "retoots":
-				filterMap["reblog"] = true
-			case "follow", "follows":
-				filterMap["follow"] = true
-			default:
-				return errors.Errorf("unknown notification type: '%s'", f)
-			}
+		var err error
+		filterMap, err = buildFilterMap(opt.types)
+		if err != nil {
+			return nil
 		}
 	}
 
@@ -100,13 +91,13 @@
 		notifications, err = gClient.GetNotifications(limOpts)
 
 		// Filter notifications
-		if len(filterMap) > 0 {
+		if filterMap != nil && len(*filterMap) > 0 {
 			if verbose {
 				errPrint("Filtering notifications")
 			}
 			var newNotifications []madon.Notification
 			for _, notif := range notifications {
-				if filterMap[notif.Type] {
+				if (*filterMap)[notif.Type] {
 					newNotifications = append(newNotifications, notif)
 				}
 			}
@@ -144,3 +135,24 @@
 	}
 	return p.printObj(obj)
 }
+
+func buildFilterMap(types string) (*map[string]bool, error) {
+	filterMap := make(map[string]bool)
+	if types != "" {
+		for _, f := range strings.Split(types, ",") {
+			switch f {
+			case "mention", "mentions":
+				filterMap["mention"] = true
+			case "favourite", "favourites", "favorite", "favorites", "fave", "faves":
+				filterMap["favourite"] = true
+			case "reblog", "reblogs", "retoot", "retoots":
+				filterMap["reblog"] = true
+			case "follow", "follows":
+				filterMap["follow"] = true
+			default:
+				return nil, errors.Errorf("unknown notification type: '%s'", f)
+			}
+		}
+	}
+	return &filterMap, nil
+}