From 2791a9951f9640b8fb33efa652df3405850e622b Mon Sep 17 00:00:00 2001 From: ewin Date: Mon, 3 Mar 2025 13:40:05 -0500 Subject: [PATCH] Add ContentType to internal models --- internal/gtsmodel/status.go | 27 +++++++++++++++++++++++++++ internal/gtsmodel/statusedit.go | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/internal/gtsmodel/status.go b/internal/gtsmodel/status.go index e170e7464..852ba887b 100644 --- a/internal/gtsmodel/status.go +++ b/internal/gtsmodel/status.go @@ -74,6 +74,7 @@ type Status struct { PendingApproval *bool `bun:",nullzero,notnull,default:false"` // If true then status is a reply or boost wrapper that must be Approved by the reply-ee or boost-ee before being fully distributed. PreApproved bool `bun:"-"` // If true, then status is a reply to or boost wrapper of a status on our instance, has permission to do the interaction, and an Accept should be sent out for it immediately. Field not stored in the DB. ApprovedByURI string `bun:",nullzero"` // URI of an Accept Activity that approves the Announce or Create Activity that this status was/will be attached to. + ContentType StatusContentType `bun:",nullzero"` // TODO } // GetID implements timeline.Timelineable{}. @@ -376,6 +377,32 @@ func (v Visibility) String() string { } } +// StatusContentType is the content type with which a status's text is +// parsed. Can be either plain or markdown. Empty will default to plain. +type StatusContentType enumType + +const ( + // The "unset" + StatusContentTypePlain StatusContentType = 1 + StatusContentTypeMarkdown StatusContentType = 2 + StatusContentTypeDefault = StatusContentTypePlain +) + +// String returns the actual MIME string corresponding to a content type. +// NOMERGE: is this actually necessary? i copied this because Visibility has it +// but it kinda seems like it's only used as part of the preferences stuff. do i +// need to touch that for this +func (v StatusContentType) String() string { + switch v { + case StatusContentTypePlain: + return "text/plain" + case StatusContentTypeMarkdown: + return "text/markdown" + default: + panic("invalid status content type") + } +} + // Content models the simple string content // of a status along with its ContentMap, // which contains content entries keyed by diff --git a/internal/gtsmodel/statusedit.go b/internal/gtsmodel/statusedit.go index 199d47736..68987cea9 100644 --- a/internal/gtsmodel/statusedit.go +++ b/internal/gtsmodel/statusedit.go @@ -40,7 +40,7 @@ type StatusEdit struct { PollVotes []int `bun:",array"` // Poll vote count at time of status edit, only set if poll votes were reset. StatusID string `bun:"type:CHAR(26),nullzero,notnull"` // The originating status ID this is a historical edit of. CreatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"` // The creation time of this version of the status content (according to receiving server). - + ContentType StatusContentType `bun:",nullzero"` // TODO // We don't bother having a *gtsmodel.Status model here // as the StatusEdit is always just attached to a Status, // so it doesn't need a self-reference back to it.