diff options
author | 2023-07-29 03:49:14 -0700 | |
---|---|---|
committer | 2023-07-29 12:49:14 +0200 | |
commit | b874e9251e00961f295e4c409e1b34da89fab4ed (patch) | |
tree | cb528816250f322707a90c0954c963886ea96c19 /internal/api/model/marker.go | |
parent | [chore] Update activity dependency (#2031) (diff) | |
download | gotosocial-b874e9251e00961f295e4c409e1b34da89fab4ed.tar.xz |
[feature] Implement markers API (#1989)
* Implement markers API
Fixes #1856
* Correct import grouping in markers files
* Regenerate Swagger for markers API
* Shorten names for readability
* Cache markers for 6 hours
* Update DB ref
* Update envparsing.sh
Diffstat (limited to 'internal/api/model/marker.go')
-rw-r--r-- | internal/api/model/marker.go | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/internal/api/model/marker.go b/internal/api/model/marker.go index f64b75ab4..f2d5cb296 100644 --- a/internal/api/model/marker.go +++ b/internal/api/model/marker.go @@ -20,9 +20,9 @@ package model // Marker represents the last read position within a user's timelines. type Marker struct { // Information about the user's position in the home timeline. - Home *TimelineMarker `json:"home"` + Home *TimelineMarker `json:"home,omitempty"` // Information about the user's position in their notifications. - Notifications *TimelineMarker `json:"notifications"` + Notifications *TimelineMarker `json:"notifications,omitempty"` } // TimelineMarker contains information about a user's progress through a specific timeline. @@ -32,5 +32,46 @@ type TimelineMarker struct { // The timestamp of when the marker was set (ISO 8601 Datetime) UpdatedAt string `json:"updated_at"` // Used for locking to prevent write conflicts. - Version string `json:"version"` + Version int `json:"version"` +} + +// MarkerName is the name of one of the timelines we can store markers for. +type MarkerName string + +const ( + MarkerNameHome MarkerName = "home" + MarkerNameNotifications MarkerName = "notifications" + MarkerNameNumValues = 2 +) + +// MarkerPostRequest models a request to update one or more markers. +// This has two sets of fields to support a goofy nested map structure in both form data and JSON bodies. +// +// swagger:ignore +type MarkerPostRequest struct { + Home *MarkerPostRequestMarker `json:"home"` + FormHomeLastReadID string `form:"home[last_read_id]"` + Notifications *MarkerPostRequestMarker `json:"notifications"` + FormNotificationsLastReadID string `form:"notifications[last_read_id]"` +} + +type MarkerPostRequestMarker struct { + // The ID of the most recently viewed entity. + LastReadID string `json:"last_read_id"` +} + +// HomeLastReadID should be used instead of Home or FormHomeLastReadID. +func (r *MarkerPostRequest) HomeLastReadID() string { + if r.Home != nil { + return r.Home.LastReadID + } + return r.FormHomeLastReadID +} + +// NotificationsLastReadID should be used instead of Notifications or FormNotificationsLastReadID. +func (r *MarkerPostRequest) NotificationsLastReadID() string { + if r.Notifications != nil { + return r.Notifications.LastReadID + } + return r.FormNotificationsLastReadID } |