@@ -160,6 +160,55 @@ var notificationReadAllCmd = &cobra.Command{
160160 },
161161}
162162
163+ // Notification tray flags
164+ var notificationTrayIncludeRead bool
165+
166+ var notificationTrayCmd = & cobra.Command {
167+ Use : "tray" ,
168+ Short : "Show notification tray" ,
169+ Long : "Shows your notification tray (up to 100 unread notifications). Use --include-read to also include read notifications." ,
170+ Run : func (cmd * cobra.Command , args []string ) {
171+ if err := requireAuthAndAccount (); err != nil {
172+ exitWithError (err )
173+ }
174+
175+ client := getClient ()
176+ path := "/notifications/tray.json"
177+ if notificationTrayIncludeRead {
178+ path += "?include_read=true"
179+ }
180+
181+ resp , err := client .Get (path )
182+ if err != nil {
183+ exitWithError (err )
184+ }
185+
186+ // Build summary
187+ count := 0
188+ unreadCount := 0
189+ if arr , ok := resp .Data .([]interface {}); ok {
190+ count = len (arr )
191+ for _ , item := range arr {
192+ if notif , ok := item .(map [string ]interface {}); ok {
193+ if read , ok := notif ["read" ].(bool ); ok && ! read {
194+ unreadCount ++
195+ }
196+ }
197+ }
198+ }
199+ summary := fmt .Sprintf ("%d notifications (%d unread)" , count , unreadCount )
200+
201+ // Build breadcrumbs
202+ breadcrumbs := []response.Breadcrumb {
203+ breadcrumb ("read" , "fizzy notification read <id>" , "Mark as read" ),
204+ breadcrumb ("read-all" , "fizzy notification read-all" , "Mark all as read" ),
205+ breadcrumb ("list" , "fizzy notification list" , "List all notifications" ),
206+ }
207+
208+ printSuccessWithBreadcrumbs (resp .Data , summary , breadcrumbs )
209+ },
210+ }
211+
163212func init () {
164213 rootCmd .AddCommand (notificationCmd )
165214
@@ -168,6 +217,10 @@ func init() {
168217 notificationListCmd .Flags ().BoolVar (& notificationListAll , "all" , false , "Fetch all pages" )
169218 notificationCmd .AddCommand (notificationListCmd )
170219
220+ // Tray
221+ notificationTrayCmd .Flags ().BoolVar (& notificationTrayIncludeRead , "include-read" , false , "Include read notifications" )
222+ notificationCmd .AddCommand (notificationTrayCmd )
223+
171224 // Read/Unread
172225 notificationCmd .AddCommand (notificationReadCmd )
173226 notificationCmd .AddCommand (notificationUnreadCmd )
0 commit comments