entry.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. Date time.Time `json:"published_at"`
  31. CreatedAt time.Time `json:"created_at"`
  32. ChangedAt time.Time `json:"changed_at"`
  33. Content string `json:"content"`
  34. Author string `json:"author"`
  35. ShareCode string `json:"share_code"`
  36. Starred bool `json:"starred"`
  37. ReadingTime int `json:"reading_time"`
  38. Enclosures EnclosureList `json:"enclosures"`
  39. Feed *Feed `json:"feed,omitempty"`
  40. Tags []string `json:"tags"`
  41. }
  42. func NewEntry() *Entry {
  43. return &Entry{
  44. Enclosures: make(EnclosureList, 0),
  45. Tags: make([]string, 0),
  46. Feed: &Feed{
  47. Category: &Category{},
  48. Icon: &FeedIcon{},
  49. },
  50. }
  51. }
  52. // ShouldMarkAsReadOnView Return whether the entry should be marked as viewed considering all user settings and entry state.
  53. func (e *Entry) ShouldMarkAsReadOnView(user *User) bool {
  54. // Already read, no need to mark as read again. Removed entries are not marked as read
  55. if e.Status != EntryStatusUnread {
  56. return false
  57. }
  58. // There is an enclosure, markAsRead will happen at enclosure completion time, no need to mark as read on view
  59. if user.MarkReadOnMediaPlayerCompletion && e.Enclosures.ContainsAudioOrVideo() {
  60. return false
  61. }
  62. // The user wants to mark as read on view
  63. return user.MarkReadOnView
  64. }
  65. // Entries represents a list of entries.
  66. type Entries []*Entry
  67. // EntriesStatusUpdateRequest represents a request to change entries status.
  68. type EntriesStatusUpdateRequest struct {
  69. EntryIDs []int64 `json:"entry_ids"`
  70. Status string `json:"status"`
  71. }
  72. // EntryUpdateRequest represents a request to update an entry.
  73. type EntryUpdateRequest struct {
  74. Title *string `json:"title"`
  75. Content *string `json:"content"`
  76. }
  77. func (e *EntryUpdateRequest) Patch(entry *Entry) {
  78. if e.Title != nil && *e.Title != "" {
  79. entry.Title = *e.Title
  80. }
  81. if e.Content != nil && *e.Content != "" {
  82. entry.Content = *e.Content
  83. }
  84. }