entry.go 2.7 KB

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