entry.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package model // import "miniflux.app/v2/internal/model"
  4. import (
  5. "time"
  6. )
  7. // Entry statuses and default sorting order.
  8. const (
  9. EntryStatusUnread = "unread"
  10. EntryStatusRead = "read"
  11. DefaultSortingOrder = "published_at"
  12. DefaultSortingDirection = "asc"
  13. )
  14. // MaxEntryLimit is the maximum allowed value for the "limit" query parameter
  15. // and for the user "entries_per_page" preference.
  16. const MaxEntryLimit = 1000
  17. // MaxEntryIDsLimit is the maximum allowed value for the "limit" query parameter
  18. // for the entry ID list endpoints.
  19. const MaxEntryIDsLimit = 10000
  20. // Entry represents a feed item in the system.
  21. type Entry struct {
  22. ID int64 `json:"id"`
  23. UserID int64 `json:"user_id"`
  24. FeedID int64 `json:"feed_id"`
  25. Status string `json:"status"`
  26. Hash string `json:"hash"`
  27. Title string `json:"title"`
  28. URL string `json:"url"`
  29. CommentsURL string `json:"comments_url"`
  30. Language string `json:"language"`
  31. Date time.Time `json:"published_at"`
  32. CreatedAt time.Time `json:"created_at"`
  33. ChangedAt time.Time `json:"changed_at"`
  34. Content string `json:"content"`
  35. Author string `json:"author"`
  36. ShareCode string `json:"share_code"`
  37. Starred bool `json:"starred"`
  38. ReadingTime int `json:"reading_time"`
  39. Enclosures EnclosureList `json:"enclosures"`
  40. Feed *Feed `json:"feed,omitempty"`
  41. Tags []string `json:"tags"`
  42. }
  43. func NewEntry() *Entry {
  44. return &Entry{
  45. Enclosures: make(EnclosureList, 0),
  46. Tags: make([]string, 0),
  47. Feed: &Feed{
  48. Category: &Category{},
  49. Icon: &FeedIcon{},
  50. },
  51. }
  52. }
  53. // ShouldMarkAsReadOnView Return whether the entry should be marked as viewed considering all user settings and entry state.
  54. func (e *Entry) ShouldMarkAsReadOnView(user *User) bool {
  55. // Already read, no need to mark as read again. Removed entries are not marked as read
  56. if e.Status != EntryStatusUnread {
  57. return false
  58. }
  59. // There is an enclosure, markAsRead will happen at enclosure completion time, no need to mark as read on view
  60. if user.MarkReadOnMediaPlayerCompletion && e.Enclosures.ContainsAudioOrVideo() {
  61. return false
  62. }
  63. // The user wants to mark as read on view
  64. return user.MarkReadOnView
  65. }
  66. // Entries represents a list of entries.
  67. type Entries []*Entry
  68. // EntriesStatusUpdateRequest represents a request to change entries status.
  69. type EntriesStatusUpdateRequest struct {
  70. EntryIDs []int64 `json:"entry_ids"`
  71. Status string `json:"status"`
  72. Starred *bool `json:"starred"`
  73. }
  74. // EntryUpdateRequest represents a request to update an entry.
  75. type EntryUpdateRequest struct {
  76. Title *string `json:"title"`
  77. Content *string `json:"content"`
  78. }
  79. func (e *EntryUpdateRequest) Patch(entry *Entry) {
  80. if e.Title != nil && *e.Title != "" {
  81. entry.Title = *e.Title
  82. }
  83. if e.Content != nil && *e.Content != "" {
  84. entry.Content = *e.Content
  85. }
  86. }