linstrom/web/shared/Note.go
mstar 28a4f4121e
Some checks are pending
/ test (push) Waiting to run
See previous commit
2025-04-08 16:34:04 +02:00

57 lines
1.3 KiB
Go

package webshared
import (
"time"
"git.mstar.dev/mstar/linstrom/shared"
"git.mstar.dev/mstar/linstrom/storage-new/models"
)
type Note struct {
// ---- Section public data
ID string `json:"id"`
CreatedAt time.Time `json:"created_at"`
CreatorId string `json:"creator_id"`
ServerId uint `json:"server_id"`
RawContent string `json:"raw_content"`
ContentWarning *string `json:"content_warning"`
RepliesToId *string `json:"replies_to_id"`
QuotesId *string `json:"quotes_id"`
AccessLevel uint8 `json:"access_level"`
}
// Compile time interface implementation enforcement
var _ shared.Clonable = &Note{}
var _ shared.Sanitisable = &Note{}
func (note *Note) Sanitize() {
}
func (note *Note) Clone() shared.Clonable {
tmp := *note
return &tmp
}
func (n *Note) FromModel(m *models.Note) {
n.ID = m.ID
n.CreatedAt = m.CreatedAt
n.CreatorId = m.CreatorId
n.ServerId = m.OriginId
n.RawContent = m.RawContent
if m.ContentWarning.Valid {
n.ContentWarning = &m.ContentWarning.String
} else {
n.ContentWarning = nil
}
if m.RepliesTo.Valid {
n.RepliesToId = &m.RepliesTo.String
} else {
n.RepliesToId = nil
}
if m.Quotes.Valid {
n.QuotesId = &m.Quotes.String
} else {
n.QuotesId = nil
}
n.AccessLevel = uint8(m.AccessLevel)
}