diff options
author | 2023-07-29 03:49:14 -0700 | |
---|---|---|
committer | 2023-07-29 12:49:14 +0200 | |
commit | b874e9251e00961f295e4c409e1b34da89fab4ed (patch) | |
tree | cb528816250f322707a90c0954c963886ea96c19 /internal/typeutils | |
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/typeutils')
-rw-r--r-- | internal/typeutils/converter.go | 2 | ||||
-rw-r--r-- | internal/typeutils/frontendtointernal.go | 10 | ||||
-rw-r--r-- | internal/typeutils/internaltofrontend.go | 20 |
3 files changed, 32 insertions, 0 deletions
diff --git a/internal/typeutils/converter.go b/internal/typeutils/converter.go index 00dbe26e8..9121564fb 100644 --- a/internal/typeutils/converter.go +++ b/internal/typeutils/converter.go @@ -94,6 +94,8 @@ type TypeConverter interface { ReportToAdminAPIReport(ctx context.Context, r *gtsmodel.Report, requestingAccount *gtsmodel.Account) (*apimodel.AdminReport, error) // ListToAPIList converts one gts model list into an api model list, for serving at /api/v1/lists/{id} ListToAPIList(ctx context.Context, l *gtsmodel.List) (*apimodel.List, error) + // MarkersToAPIMarker converts several gts model markers into an api marker, for serving at /api/v1/markers + MarkersToAPIMarker(ctx context.Context, markers []*gtsmodel.Marker) (*apimodel.Marker, error) /* INTERNAL (gts) MODEL TO FRONTEND (rss) MODEL diff --git a/internal/typeutils/frontendtointernal.go b/internal/typeutils/frontendtointernal.go index d57f36995..3bb0933f3 100644 --- a/internal/typeutils/frontendtointernal.go +++ b/internal/typeutils/frontendtointernal.go @@ -37,3 +37,13 @@ func APIVisToVis(m apimodel.Visibility) gtsmodel.Visibility { } return "" } + +func APIMarkerNameToMarkerName(m apimodel.MarkerName) gtsmodel.MarkerName { + switch m { + case apimodel.MarkerNameHome: + return gtsmodel.MarkerNameHome + case apimodel.MarkerNameNotifications: + return gtsmodel.MarkerNameNotifications + } + return "" +} diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 03d0bfcab..975214da7 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -1166,6 +1166,26 @@ func (c *converter) ListToAPIList(ctx context.Context, l *gtsmodel.List) (*apimo }, nil } +func (c *converter) MarkersToAPIMarker(ctx context.Context, markers []*gtsmodel.Marker) (*apimodel.Marker, error) { + apiMarker := &apimodel.Marker{} + for _, marker := range markers { + apiTimelineMarker := &apimodel.TimelineMarker{ + LastReadID: marker.LastReadID, + UpdatedAt: util.FormatISO8601(marker.UpdatedAt), + Version: marker.Version, + } + switch apimodel.MarkerName(marker.Name) { + case apimodel.MarkerNameHome: + apiMarker.Home = apiTimelineMarker + case apimodel.MarkerNameNotifications: + apiMarker.Notifications = apiTimelineMarker + default: + return nil, fmt.Errorf("unknown marker timeline name: %s", marker.Name) + } + } + return apiMarker, nil +} + // convertAttachmentsToAPIAttachments will convert a slice of GTS model attachments to frontend API model attachments, falling back to IDs if no GTS models supplied. func (c *converter) convertAttachmentsToAPIAttachments(ctx context.Context, attachments []*gtsmodel.MediaAttachment, attachmentIDs []string) ([]apimodel.Attachment, error) { var errs gtserror.MultiError |