diff --git a/cmd/twitter/main.go b/cmd/twitter/main.go index 5b23a91..b996c7a 100644 --- a/cmd/twitter/main.go +++ b/cmd/twitter/main.go @@ -83,7 +83,7 @@ func main() { if len(args) < 2 { if len(args) == 1 && (args[0] == "webserver" || args[0] == "fetch_timeline" || args[0] == "fetch_timeline_following_only" || args[0] == "fetch_inbox" || args[0] == "get_bookmarks" || - args[0] == "get_notifications") { + args[0] == "get_notifications" || args[0] == "mark_notifications_as_read") { // Doesn't need a target, so create a fake second arg args = append(args, "") } else { @@ -195,6 +195,8 @@ func main() { fetch_timeline(true) case "get_notifications": get_notifications(*how_many) + case "mark_notifications_as_read": + mark_notification_as_read() case "download_tweet_content": download_tweet_content(target) case "search": @@ -664,3 +666,10 @@ func get_notifications(how_many int) { len(trove.Notifications), len(trove.Tweets), len(trove.Users), ), nil) } + +func mark_notification_as_read() { + if err := api.MarkNotificationsAsRead(); err != nil { + panic(err) + } + happy_exit("Notifications marked as read", nil) +} diff --git a/internal/webserver/handler_notifications.go b/internal/webserver/handler_notifications.go index 32f45a2..1a2c3e0 100644 --- a/internal/webserver/handler_notifications.go +++ b/internal/webserver/handler_notifications.go @@ -3,9 +3,17 @@ package webserver import ( "net/http" "strconv" + "strings" ) func (app *Application) Notifications(w http.ResponseWriter, r *http.Request) { + app.traceLog.Printf("'Notifications' handler (path: %q)", r.URL.Path) + parts := strings.Split(strings.Trim(r.URL.Path, "/"), "/") + if parts[0] == "mark-all-as-read" { + app.NotificationsMarkAsRead(w, r) + return + } + cursor_val := 0 cursor_param := r.URL.Query().Get("cursor") if cursor_param != "" { @@ -26,3 +34,16 @@ func (app *Application) Notifications(w http.ResponseWriter, r *http.Request) { app.buffered_render_page(w, "tpl/notifications.tpl", PageGlobalData{TweetTrove: feed.TweetTrove}, feed) } } + +func (app *Application) NotificationsMarkAsRead(w http.ResponseWriter, r *http.Request) { + err := app.API.MarkNotificationsAsRead() + if err != nil { + panic(err) + } + app.toast(w, r, Toast{ + Title: "Success", + Message: `Notifications marked as "read"`, + Type: "success", + AutoCloseDelay: 2000, + }) +} diff --git a/internal/webserver/server.go b/internal/webserver/server.go index 2fb2a32..d41cb6f 100644 --- a/internal/webserver/server.go +++ b/internal/webserver/server.go @@ -134,7 +134,7 @@ func (app *Application) ServeHTTP(w http.ResponseWriter, r *http.Request) { case "bookmarks": app.Bookmarks(w, r) case "notifications": - app.Notifications(w, r) + http.StripPrefix("/notifications", http.HandlerFunc(app.Notifications)).ServeHTTP(w, r) case "messages": http.StripPrefix("/messages", http.HandlerFunc(app.Messages)).ServeHTTP(w, r) case "nav-sidebar-poll-updates": diff --git a/internal/webserver/tpl/notifications.tpl b/internal/webserver/tpl/notifications.tpl index 1ef8664..b535e9e 100644 --- a/internal/webserver/tpl/notifications.tpl +++ b/internal/webserver/tpl/notifications.tpl @@ -6,17 +6,28 @@
{{/* Extra div to take up a slot in the `row` */}}