entry_prev_next.go 853 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package ui
  5. import (
  6. "github.com/miniflux/miniflux/model"
  7. "github.com/miniflux/miniflux/storage"
  8. )
  9. func (c *Controller) getEntryPrevNext(user *model.User, builder *storage.EntryQueryBuilder, entryID int64) (prev *model.Entry, next *model.Entry, err error) {
  10. builder.WithoutStatus(model.EntryStatusRemoved)
  11. builder.WithOrder(model.DefaultSortingOrder)
  12. builder.WithDirection(user.EntryDirection)
  13. entries, err := builder.GetEntries()
  14. if err != nil {
  15. return nil, nil, err
  16. }
  17. n := len(entries)
  18. for i := 0; i < n; i++ {
  19. if entries[i].ID == entryID {
  20. if i-1 >= 0 {
  21. prev = entries[i-1]
  22. }
  23. if i+1 < n {
  24. next = entries[i+1]
  25. }
  26. }
  27. }
  28. return prev, next, nil
  29. }