diff --git a/router/template_variables.go b/router/template_variables.go index bc6d20e2..a33585a4 100644 --- a/router/template_variables.go +++ b/router/template_variables.go @@ -98,6 +98,7 @@ type UserProfileVariables struct { } type UserProfileNotifVariables struct { + Infos map[string][]string Search SearchForm Navigation Navigation User *model.User diff --git a/router/user_handler.go b/router/user_handler.go index cf6cb0e7..e4670aa2 100644 --- a/router/user_handler.go +++ b/router/user_handler.go @@ -7,10 +7,12 @@ import ( "github.com/NyaaPantsu/nyaa/model" "github.com/NyaaPantsu/nyaa/service/captcha" + "github.com/NyaaPantsu/nyaa/service/notifier" "github.com/NyaaPantsu/nyaa/service/user" "github.com/NyaaPantsu/nyaa/service/user/form" "github.com/NyaaPantsu/nyaa/service/user/permission" "github.com/NyaaPantsu/nyaa/util/languages" + msg "github.com/NyaaPantsu/nyaa/util/messages" "github.com/NyaaPantsu/nyaa/util/modelHelper" "github.com/gorilla/mux" ) @@ -327,8 +329,14 @@ func UserFollowHandler(w http.ResponseWriter, r *http.Request) { func UserNotificationsHandler(w http.ResponseWriter, r *http.Request) { currentUser := GetUser(r) if currentUser.ID > 0 { - languages.SetTranslationFromRequest(viewProfileNotifTemplate, r) - htv := UserProfileNotifVariables{NewSearchForm(), NewNavigation(), currentUser, r.URL, mux.CurrentRoute(r)} + messages := msg.GetMessages(r) + T := languages.SetTranslationFromRequest(viewProfileNotifTemplate, r) + if r.URL.Query()["clear"] != nil { + notifierService.DeleteAllNotifications(currentUser.ID) + messages.AddInfo("infos", T("notifications_cleared")) + currentUser.Notifications = []model.Notification{} + } + htv := UserProfileNotifVariables{messages.GetAllInfos(), NewSearchForm(), NewNavigation(), currentUser, r.URL, mux.CurrentRoute(r)} err := viewProfileNotifTemplate.ExecuteTemplate(w, "index.html", htv) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/router/view_torrent_handler.go b/router/view_torrent_handler.go index 97c726f3..bb1fb599 100644 --- a/router/view_torrent_handler.go +++ b/router/view_torrent_handler.go @@ -9,6 +9,7 @@ import ( "github.com/NyaaPantsu/nyaa/db" "github.com/NyaaPantsu/nyaa/model" "github.com/NyaaPantsu/nyaa/service/captcha" + "github.com/NyaaPantsu/nyaa/service/notifier" "github.com/NyaaPantsu/nyaa/service/torrent" "github.com/NyaaPantsu/nyaa/service/user/permission" "github.com/NyaaPantsu/nyaa/util" @@ -22,19 +23,24 @@ func ViewHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) id := vars["id"] messages := msg.GetMessages(r) + user := GetUser(r) if (r.URL.Query()["success"] != nil) { messages.AddInfo("infos", "Torrent uploaded successfully!") } torrent, err := torrentService.GetTorrentById(id) + + if (r.URL.Query()["notif"] != nil) { + notifierService.ToggleReadNotification(torrent.Identifier(), user.ID) + } + if err != nil { NotFoundHandler(w, r) return } b := torrent.ToJSON() captchaID := "" - user := GetUser(r) if userPermission.NeedsCaptcha(user) { captchaID = captcha.GetID() } diff --git a/templates/_user_notifications.html b/templates/_user_notifications.html index fec1a2ed..1db0583c 100644 --- a/templates/_user_notifications.html +++ b/templates/_user_notifications.html @@ -1,15 +1,17 @@ {{define "profile_notifications_content"}} {{with .User}}
- Clear Notifications + Clear Notifications
+ {{ range (index $.Infos "infos")}} +
× {{ . }}
+ {{end}} {{ range .Notifications }} {{end}} diff --git a/translations/en-us.all.json b/translations/en-us.all.json index bcaa2473..6af5cb6a 100644 --- a/translations/en-us.all.json +++ b/translations/en-us.all.json @@ -759,6 +759,10 @@ "id": "no_database_dumps_available", "translation": "No database dumps are available at this moment." }, + { + "id": "notifications_cleared", + "translation": "Notifications erased!" + }, { "id": "my_notifications", "translation": "My Notifications"
-
- -

{{ .Content }}

+