Work on AS activities and objects
All checks were successful
/ docker (push) Successful in 4m15s

This commit is contained in:
Melody Becker 2025-04-29 21:35:58 +02:00
parent d32818af09
commit cfa0566c6d
Signed by: mstar
SSH key fingerprint: SHA256:vkXfS9FG2pVNVfvDrzd1VW9n8VJzqqdKQGljxxX8uK8
39 changed files with 2276 additions and 183 deletions

View file

@ -2,10 +2,12 @@ package models
// A list of all models stored in the database
var AllTypes = []any{
&ActivitystreamsActivity{},
&Emote{},
&Feed{},
&MediaMetadata{},
&Note{},
&NoteEdit{},
&NoteToAttachment{},
&NoteToBoost{},
&NoteToEmote{},

View file

@ -0,0 +1,32 @@
package models
import "database/sql/driver"
type ActivitystreamsActivityTargetType uint32
const (
ActivitystreamsActivityTargetUnknown ActivitystreamsActivityTargetType = iota
ActivitystreamsActivityTargetActivity
ActivitystreamsActivityTargetNote
ActivitystreamsActivityTargetUser
ActivitystreamsActivityTargetBoost
ActivitystreamsActivityTargetReaction
)
func (n *ActivitystreamsActivityTargetType) Value() (driver.Value, error) {
return n, nil
}
func (ct *ActivitystreamsActivityTargetType) Scan(value any) error {
*ct = ActivitystreamsActivityTargetType(value.(uint32))
return nil
}
var AllActivitystreamsActivityTargetTypes = []ActivitystreamsActivityTargetType{
ActivitystreamsActivityTargetUnknown,
ActivitystreamsActivityTargetActivity,
ActivitystreamsActivityTargetNote,
ActivitystreamsActivityTargetUser,
ActivitystreamsActivityTargetBoost,
ActivitystreamsActivityTargetReaction,
}

View file

@ -0,0 +1,7 @@
package models
type ActivitystreamsActivity struct {
Type string `gorm:"type:activitystreams_activity_type"`
ObjectId string
ObjectType uint32 // Target type: ActivitystreamsActivityTargetType
}

View file

@ -0,0 +1,78 @@
package models
import "database/sql/driver"
type ActivitystreamsActivityType string
const (
ActivityUnknown = ActivitystreamsActivityType("unknown")
ActivityAccept = ActivitystreamsActivityType("accept")
ActivityAdd = ActivitystreamsActivityType("add")
ActivityAnnounce = ActivitystreamsActivityType("announce")
ActivityArrive = ActivitystreamsActivityType("arrive")
ActivityBlock = ActivitystreamsActivityType("block")
ActivityCreate = ActivitystreamsActivityType("create")
ActivityDelete = ActivitystreamsActivityType("delete")
ActivityDislike = ActivitystreamsActivityType("dislike")
ActivityFlag = ActivitystreamsActivityType("flag")
ActivityFollow = ActivitystreamsActivityType("follow")
ActivityIgnore = ActivitystreamsActivityType("ignore")
ActivityInvite = ActivitystreamsActivityType("invite")
ActivityJoin = ActivitystreamsActivityType("join")
ActivityLeave = ActivitystreamsActivityType("leave")
ActivityLike = ActivitystreamsActivityType("like")
ActivityListen = ActivitystreamsActivityType("listen")
ActivityMove = ActivitystreamsActivityType("move")
ActivityOffer = ActivitystreamsActivityType("offer")
ActivityQuestion = ActivitystreamsActivityType("question")
ActivityRead = ActivitystreamsActivityType("read")
ActivityReject = ActivitystreamsActivityType("reject")
ActivityRemove = ActivitystreamsActivityType("remove")
ActivityTentativeAccept = ActivitystreamsActivityType("tentative-accept")
ActivityTentativeReject = ActivitystreamsActivityType("tentative-reject")
ActivityTravel = ActivitystreamsActivityType("travel")
ActivityUndo = ActivitystreamsActivityType("undo")
ActivityUpdate = ActivitystreamsActivityType("update")
ActivityView = ActivitystreamsActivityType("view")
)
var AllActivitystreamsActivityTypes = []ActivitystreamsActivityType{
ActivityUnknown,
ActivityAccept,
ActivityAdd,
ActivityAnnounce,
ActivityArrive,
ActivityBlock,
ActivityCreate,
ActivityDelete,
ActivityDislike,
ActivityFlag,
ActivityFollow,
ActivityIgnore,
ActivityInvite,
ActivityJoin,
ActivityLeave,
ActivityLike,
ActivityListen,
ActivityMove,
ActivityOffer,
ActivityQuestion,
ActivityRead,
ActivityReject,
ActivityRemove,
ActivityTentativeAccept,
ActivityTentativeReject,
ActivityTravel,
ActivityUndo,
ActivityUpdate,
ActivityView,
}
func (r *ActivitystreamsActivityType) Value() (driver.Value, error) {
return r, nil
}
func (ct *ActivitystreamsActivityType) Scan(value any) error {
*ct = ActivitystreamsActivityType(value.(string))
return nil
}

View file

@ -0,0 +1,6 @@
package models
// Not sure an extra table is even needed for AS objects
// since endpoints get the ID from the url anyway
type ActivitystreamsObject struct {
}

View file

@ -0,0 +1,46 @@
package models
import "database/sql/driver"
type ActivitystreamsObjectType string
const (
ObjectTypeUnknown = ActivitystreamsObjectType("unknown")
ObjectTypeArticle = ActivitystreamsObjectType("article")
ObjectTypeAudio = ActivitystreamsObjectType("audio")
ObjectTypeDocument = ActivitystreamsObjectType("document")
ObjectTypeEvent = ActivitystreamsObjectType("event")
ObjectTypeImage = ActivitystreamsObjectType("image")
ObjectTypeNote = ActivitystreamsObjectType("note")
ObjectTypePage = ActivitystreamsObjectType("page")
ObjectTypePlace = ActivitystreamsObjectType("place")
ObjectTypeProfile = ActivitystreamsObjectType("profile")
ObjectTypeRelationship = ActivitystreamsObjectType("relationsjip")
ObjectTypeTombstone = ActivitystreamsObjectType("tombstone")
ObjectTypeVideo = ActivitystreamsObjectType("video")
)
var AllActivitystreamsObjectTypes = []ActivitystreamsObjectType{
ObjectTypeUnknown,
ObjectTypeArticle,
ObjectTypeAudio,
ObjectTypeDocument,
ObjectTypeEvent,
ObjectTypeImage,
ObjectTypeNote,
ObjectTypePage,
ObjectTypePlace,
ObjectTypeProfile,
ObjectTypeRelationship,
ObjectTypeTombstone,
ObjectTypeVideo,
}
func (r *ActivitystreamsObjectType) Value() (driver.Value, error) {
return r, nil
}
func (ct *ActivitystreamsObjectType) Scan(value any) error {
*ct = ActivitystreamsObjectType(value.(string))
return nil
}

View file

@ -29,10 +29,11 @@ type Note struct {
Origin RemoteServer
OriginId uint
AttachmentRelations []NoteToAttachment `gorm:"foreignKey:NoteId"` // Attachments added on to this note
EmoteRelations []NoteToEmote `gorm:"foreignKey:NoteId"` // Emotes used in this note
PingRelations []NoteToPing `gorm:"foreignKey:NoteId"` // Pings/mentions this note performs
Tags []NoteTag `gorm:"foreignKey:NoteId"` // Tags this note contains
AttachmentRelations []NoteToAttachment `gorm:"foreignKey:NoteId;constraint:OnDelete:CASCADE"` // Attachments added on to this note
EmoteRelations []NoteToEmote `gorm:"foreignKey:NoteId;constraint:OnDelete:CASCADE"` // Emotes used in this note
PingRelations []NoteToPing `gorm:"foreignKey:NoteId;constraint:OnDelete:CASCADE"` // Pings/mentions this note performs
Tags []NoteTag `gorm:"foreignKey:NoteId;constraint:OnDelete:CASCADE"` // Tags this note contains
Edits []NoteEdit `gorm:"foreignKey:NoteId;constraint:OnDelete:CASCADE"` // All edits done to this note
}
type INote interface {

View file

@ -0,0 +1,45 @@
package models
import (
"time"
"gorm.io/gen"
)
// NoteEdit denotes one edit done to one known note.
// The table is (within this application) append only
// (Except for the case where a note is hard deleted,
// where the edits for it also need to be deleted.
// Direct access to the db also circumvents this).
// Every edit will append one entry per edited field, denoting
// the field and how it was changed, in chronological order
type NoteEdit struct {
Note Note
NoteId string `gorm:"primaryKey;autoIncrement:false;<-:create"`
EditNr uint64 `gorm:"primaryKey;autoIncrement:false;<-:create"`
CreatedAt time.Time `gorm:"<-:create"`
Before string `gorm:"<-:create"`
After string `gorm:"<-:create"`
Field string `gorm:"<-:create"` // What was edited
}
type INoteEdit interface {
// Append a new edit to a note
//
// INSERT INTO @@table
// (note_id, edit_nr, created_at, before, after, field)
// VALUES (
// @note_id,
// (SELECT COUNT(*) FROM @@table WHERE note_id = @noteId)+1,
// NOW(),
// @before,
// @after,
// @field
// )
AppendEdit(noteId, before, after, field string) error
// Find all edits for a field
//
// SELECT * FROM @@table WHERE note_id = @noteId AND field = @field
FindEditsForField(noteId, field string) ([]gen.T, error)
}