diff --git a/controllers/feed/helpers.go b/controllers/feed/helpers.go index 7a49e013..4fb788dd 100644 --- a/controllers/feed/helpers.go +++ b/controllers/feed/helpers.go @@ -39,6 +39,7 @@ func getTorrentList(c *gin.Context) (torrents []models.Torrent, createdAsTime ti title = "Sukebei Pantsu" } + pagenum := 1 if page == "" && offset > 0 { // first page for offset is 0 pagenum = offset + 1 @@ -86,7 +87,12 @@ func getTorrentList(c *gin.Context) (torrents []models.Torrent, createdAsTime ti user = 0 } - _, torrents, _, err = search.AuthorizedQuery(c, pagenum, currentUser.CurrentOrJanitor(uint(user)), currentUser.CurrentOrJanitor(uint(user))) + var searchParam search.TorrentParam + searchParam, torrents, _, err = search.AuthorizedQuery(c, pagenum, currentUser.CurrentOrJanitor(uint(user)), currentUser.CurrentOrJanitor(uint(user))) + + if searchParam.NameLike != "" { + title += " - " + searchParam.NameLike + } return } diff --git a/controllers/torrent/comment.go b/controllers/torrent/comment.go index 4924edd1..5bf0b704 100644 --- a/controllers/torrent/comment.go +++ b/controllers/torrent/comment.go @@ -9,11 +9,10 @@ import ( "github.com/NyaaPantsu/nyaa/controllers/router" "github.com/NyaaPantsu/nyaa/models/comments" "github.com/NyaaPantsu/nyaa/models/torrents" + "github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/utils/captcha" - "github.com/NyaaPantsu/nyaa/utils/filelist" msg "github.com/NyaaPantsu/nyaa/utils/messages" "github.com/NyaaPantsu/nyaa/utils/sanitize" - "github.com/NyaaPantsu/nyaa/templates" "github.com/gin-gonic/gin" ) @@ -39,6 +38,9 @@ func PostCommentHandler(c *gin.Context) { if currentUser.IsBanned() { messages.AddErrorT("errors", "account_banned") } + if torrent.Status == models.TorrentStatusBlocked && !currentUser.CurrentOrJanitor(torrent.UploaderID) { + messages.AddErrorT("errors", "torrent_locked") + } content := sanitize.Sanitize(c.PostForm("comment"), "comment") userID := currentUser.ID @@ -60,12 +62,5 @@ func PostCommentHandler(c *gin.Context) { } } - captchaID := "" - //Generate a captcha - if currentUser.NeedsCaptcha() { - captchaID = captcha.GetID() - } - - folder := filelist.FileListToFolder(torrent.FileList, "root") - templates.Torrent(c, torrent.ToJSON(), folder, captchaID) + ViewHandler(c) } diff --git a/models/torrent.go b/models/torrent.go index a533157f..41da309c 100644 --- a/models/torrent.go +++ b/models/torrent.go @@ -312,7 +312,11 @@ func (t *Torrent) ToJSON() TorrentJSON { } for _, c := range t.Comments { if c.User != nil { - commentsJSON = append(commentsJSON, CommentJSON{Username: c.User.Username, UserID: int(c.User.ID), UserStatus: c.User.GetRole(), Content: sanitize.MarkdownToHTML(c.Content), Date: c.CreatedAt.UTC(), UserAvatar: c.User.MD5}) + role := c.User.GetRole() + if t.UploaderID == c.User.ID && !c.User.IsBanned() { + role = "userstatus_uploader" + } + commentsJSON = append(commentsJSON, CommentJSON{Username: c.User.Username, UserID: int(c.User.ID), UserStatus: role, Content: sanitize.MarkdownToHTML(c.Content), Date: c.CreatedAt.UTC(), UserAvatar: c.User.MD5}) } else { commentsJSON = append(commentsJSON, CommentJSON{}) } diff --git a/models/torrents/helpers.go b/models/torrents/helpers.go index a04f1ad8..8285dc18 100644 --- a/models/torrents/helpers.go +++ b/models/torrents/helpers.go @@ -37,13 +37,11 @@ func NewTorrentEvent(user *models.User, torrent *models.Torrent) error { url := "/view/" + strconv.FormatUint(uint64(torrent.ID), 10) if user.ID > 0 && config.Get().Users.DefaultUserSettings["new_torrent"] { // If we are a member and notifications for new torrents are enabled user.GetFollowers() // We populate the liked field for users - if len(user.Followers) > 0 { // If we are followed by at least someone - for _, follower := range user.Followers { - follower.ParseSettings() // We need to call it before checking settings - if follower.Settings.Get("new_torrent") { - T, _, _ := publicSettings.TfuncAndLanguageWithFallback(follower.Language, follower.Language) // We need to send the notification to every user in their language - notifications.NotifyUser(&follower, torrent.Identifier(), fmt.Sprintf(T("new_torrent_uploaded"), torrent.Name, user.Username), url, follower.Settings.Get("new_torrent_email")) - } + for _, follower := range user.Followers { + follower.ParseSettings() // We need to call it before checking settings + if follower.Settings.Get("new_torrent") { + T, _, _ := publicSettings.TfuncAndLanguageWithFallback(follower.Language, follower.Language) // We need to send the notification to every user in their language + notifications.NotifyUser(&follower, torrent.Identifier(), fmt.Sprintf(T("new_torrent_uploaded"), torrent.Name, user.Username), url, follower.Settings.Get("new_torrent_email")) } } } diff --git a/models/user.go b/models/user.go index 5016d931..05d98c69 100644 --- a/models/user.go +++ b/models/user.go @@ -260,17 +260,19 @@ func (u *User) ToJSON() UserJSON { } // GetLikings : Gets who is followed by the user -func (u *User) GetLikings() { +func (u *User) GetLikings() int { var liked []User ORM.Joins("JOIN user_follows on user_follows.following=?", u.ID).Where("users.user_id = user_follows.user_id").Group("users.user_id").Find(&liked) u.Likings = liked + return len(u.Likings) } // GetFollowers : Gets who is following the user -func (u *User) GetFollowers() { +func (u *User) GetFollowers() int { var likings []User ORM.Joins("JOIN user_follows on user_follows.user_id=?", u.ID).Where("users.user_id = user_follows.following").Group("users.user_id").Find(&likings) u.Followers = likings + return len(u.Followers) } // SetFollow : Makes a user follow another @@ -278,6 +280,7 @@ func (u *User) SetFollow(follower *User) { if follower.ID > 0 && u.ID > 0 { var userFollows = UserFollows{UserID: u.ID, FollowerID: follower.ID} ORM.Create(&userFollows) + u.Likings = append(u.Likings, *follower) } } @@ -286,6 +289,15 @@ func (u *User) RemoveFollow(follower *User) { if follower.ID > 0 && u.ID > 0 { var userFollows = UserFollows{UserID: u.ID, FollowerID: follower.ID} ORM.Delete(&userFollows) + for i, followr := range u.Likings { + if followr.ID == follower.ID { + u.Likings[i] = u.Likings[len(u.Likings)-1] + // The very last follower will take the place of the one that is getting deleted in the array + u.Likings = u.Likings[:len(u.Likings)-1] + // We now proceed to delete the very last array element since it got copied to another position + return + } + } } } diff --git a/public/css/main.css b/public/css/main.css index da2eebd8..79c6483e 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -452,8 +452,12 @@ select.form-input { margin-bottom: 0; width: 85px!important; } +.refine-container-2 [name="hash"] { + float: right; + width: 187px!important; +} .refine-date { - width: 98px!important; + width: 135px!important; } .categories a { @@ -462,7 +466,7 @@ select.form-input { padding: 10px 5px; } -#announce { +.announce { margin-bottom: 4px; padding: 7px 10px; background-color: #D9EDF7; @@ -470,7 +474,7 @@ select.form-input { border-radius: 7px; } -#announce:before { +.announce:before { content: "!"; vertical-align: middle; float: left; @@ -478,6 +482,13 @@ select.form-input { font-size: 2.2em; font-weight: bold; } +.announcement-content :first-child { + margin-top: 0; +} + +.announcement-content :last-child { + margin-bottom: 0; +} .results { padding: 0!important; @@ -857,6 +868,9 @@ html, body { float: none!important; max-width: none; } + .refine-container-2 [name="hash"] { + float: none; + } .upload-form-table .table-checkboxes { padding: 3px 0!important; width: 100%; diff --git a/public/css/themes/classic.css b/public/css/themes/classic.css index 4e693089..791e1279 100644 --- a/public/css/themes/classic.css +++ b/public/css/themes/classic.css @@ -767,14 +767,9 @@ span.tag { .torrent-info-data #subscribe-link::before, .torrent-info-data #subscribe-link:: after { color: #111111; } -.content > p:first-child+div.centered+div.refine+div #reportPopup { - top: 145px; -} -.content > p:first-child+div#announce+div.refine+div #reportPopup { - top: 110px; -} -.content > div#announce:first-child+div.refine+div #reportPopup { - top: 65px; + +.box { + position: relative; } #reportPopup { text-decoration: underline dotted; @@ -783,8 +778,8 @@ span.tag { background: none; color: #106655!important; position: absolute; - top: 103px; - right: 11px; + top: 6px; + right: 0; } .comment-content :first-child { margin-top: 5px; diff --git a/public/css/themes/classic_colors.css b/public/css/themes/classic_colors.css index 29f2a4b7..57d0cab6 100644 --- a/public/css/themes/classic_colors.css +++ b/public/css/themes/classic_colors.css @@ -163,7 +163,7 @@ td.tr-le, .error-text { background-size: 100%; } -#announce { +.announce { color: #3a4249; background-color: #fff5e7; border-color: #ecd2ae; diff --git a/public/css/themes/tomorrow.css b/public/css/themes/tomorrow.css index d9bd6513..b01a4c71 100644 --- a/public/css/themes/tomorrow.css +++ b/public/css/themes/tomorrow.css @@ -238,7 +238,7 @@ a.form-input[class*="btn"]:hover { background: #cc4f4f; } -#announce { +.announce { color: #3a4249; background-color: #F4E0C9; border-color: #ae875b; diff --git a/templates/admin/announcement_form.jet.html b/templates/admin/announcement_form.jet.html index 5ce2bbe3..4f8b5c64 100644 --- a/templates/admin/announcement_form.jet.html +++ b/templates/admin/announcement_form.jet.html @@ -7,7 +7,7 @@