entry.go 2.7 KB

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