cmd/stream.go
changeset 166 79c0f8db66ff
parent 144 15ecc49bbb25
child 174 0b30e670aa82
--- a/cmd/stream.go	Sat Jul 15 12:07:37 2017 +0200
+++ b/cmd/stream.go	Sat Jul 15 21:58:24 2017 +0200
@@ -19,6 +19,7 @@
 var streamOpts struct {
 	command           string
 	notificationsOnly bool
+	notificationTypes string
 }
 
 // Maximum number of websockets (1 hashtag <=> 1 ws)
@@ -38,6 +39,8 @@
   madonctl stream public    # Public timeline stream
   madonctl stream :mastodon # Hashtag
   madonctl stream #madonctl
+  madonctl stream --notifications-only
+  madonctl stream --notifications-only --notification-types mentions,follows
 
 Several (up to 4) hashtags can be given.
 Note: madonctl will use 1 websocket per hashtag stream.
@@ -53,6 +56,7 @@
 
 	streamCmd.Flags().StringVar(&streamOpts.command, "command", "", "Execute external command")
 	streamCmd.Flags().BoolVar(&streamOpts.notificationsOnly, "notifications-only", false, "Display only notifications (user stream)")
+	streamCmd.Flags().StringVar(&streamOpts.notificationTypes, "notification-types", "", "Filter notifications (mentions, favourites, reblogs, follows)")
 }
 
 func streamRunE(cmd *cobra.Command, args []string) error {
@@ -99,6 +103,15 @@
 		return err
 	}
 
+	var filterMap *map[string]bool
+	if streamOpts.notificationTypes != "" {
+		var err error
+		filterMap, err = buildFilterMap(streamOpts.notificationTypes)
+		if err != nil {
+			return err
+		}
+	}
+
 	evChan := make(chan madon.StreamEvent, 10)
 	stop := make(chan bool)
 	done := make(chan bool)
@@ -188,6 +201,9 @@
 				continue
 			case "notification":
 				n := ev.Data.(madon.Notification)
+				if filterMap != nil && !(*filterMap)[n.Type] {
+					continue
+				}
 				if p.printObj(&n); err != nil {
 					break LISTEN
 				}