entry.go 2.8 KB

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