Fix NEXT/LAST incorrect behavior

This commit is contained in:
ChronosX88 2022-02-05 20:25:38 +03:00
parent 352bcf75cd
commit 6aa7450792
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A
2 changed files with 14 additions and 10 deletions

View File

@ -175,24 +175,24 @@ func (sb *SQLiteBackend) GetArticleNumbers(g *models.Group, low, high int64) ([]
func (sb *SQLiteBackend) GetLastArticleByNum(g *models.Group, a *models.Article) (models.Article, error) {
var lastArticle models.Article
if err := sb.db.Get(&lastArticle, "SELECT articles.* FROM articles INNER JOIN articles_to_groups atg on atg.article_id = articles.id WHERE atg.article_number < ? AND atg.group_id = ? LIMIT 1", a.ArticleNumber, g.ID); err != nil {
if err := sb.db.Get(&lastArticle, "SELECT articles.* FROM articles INNER JOIN articles_to_groups atg on atg.article_id = articles.id WHERE atg.article_number < ? AND atg.group_id = ? ORDER BY atg.article_number DESC LIMIT 1", a.ArticleNumber, g.ID); err != nil {
return lastArticle, err
}
if err := sb.db.Get(&a.ArticleNumber, "SELECT article_number FROM articles_to_groups WHERE article_id = ?", a.ID); err != nil {
if err := sb.db.Get(&lastArticle.ArticleNumber, "SELECT article_number FROM articles_to_groups WHERE article_id = ?", lastArticle.ID); err != nil {
return lastArticle, err
}
return lastArticle, json.Unmarshal([]byte(a.HeaderRaw), &a.Header)
return lastArticle, json.Unmarshal([]byte(lastArticle.HeaderRaw), &lastArticle.Header)
}
func (sb *SQLiteBackend) GetNextArticleByNum(g *models.Group, a *models.Article) (models.Article, error) {
var lastArticle models.Article
if err := sb.db.Get(&lastArticle, "SELECT articles.* FROM articles INNER JOIN articles_to_groups atg on atg.article_id = articles.id WHERE atg.article_number > ? AND atg.group_id = ? LIMIT 1", a.ArticleNumber, g.ID); err != nil {
return lastArticle, err
var nextArticle models.Article
if err := sb.db.Get(&nextArticle, "SELECT articles.* FROM articles INNER JOIN articles_to_groups atg on atg.article_id = articles.id WHERE atg.article_number > ? AND atg.group_id = ? ORDER BY atg.article_number LIMIT 1", a.ArticleNumber, g.ID); err != nil {
return nextArticle, err
}
if err := sb.db.Get(&a.ArticleNumber, "SELECT article_number FROM articles_to_groups WHERE article_id = ?", a.ID); err != nil {
return lastArticle, err
if err := sb.db.Get(&nextArticle.ArticleNumber, "SELECT article_number FROM articles_to_groups WHERE article_id = ?", nextArticle.ID); err != nil {
return nextArticle, err
}
return lastArticle, json.Unmarshal([]byte(a.HeaderRaw), &a.Header)
return nextArticle, json.Unmarshal([]byte(nextArticle.HeaderRaw), &nextArticle.Header)
}
func (sb *SQLiteBackend) GetNewArticlesSince(timestamp int64) ([]string, error) {

View File

@ -664,6 +664,8 @@ func (h *Handler) handleLast(s *Session, command string, arguments []string, id
return err
}
s.currentArticle = &a
return s.tconn.PrintfLine(protocol.NNTPResponse{Code: 223, Message: fmt.Sprintf("%d %s retrieved", a.ArticleNumber, a.Header.Get("Message-ID"))}.String())
}
@ -700,7 +702,9 @@ func (h *Handler) handleNext(s *Session, command string, arguments []string, id
return err
}
return s.tconn.PrintfLine(protocol.NNTPResponse{Code: 223, Message: fmt.Sprintf("%d %s retrieved", a.ArticleNumber, a.Header.Get("Message-ID"))}.String())
s.currentArticle = &a
return s.tconn.PrintfLine(protocol.NNTPResponse{Code: 223, Message: fmt.Sprintf("%d %s retrieved", a.ArticleNumber, a.Header.Get("Message-Id"))}.String())
}
func (h *Handler) Handle(s *Session, message string, id uint) error {