From dff031397ea8853975b28ace7df9f0b19164406b Mon Sep 17 00:00:00 2001 From: mstar Date: Mon, 5 May 2025 17:33:34 +0200 Subject: [PATCH] More activity stuff --- storage-new/dbgen/activities.gen.go | 394 +++++++++++++++++ .../dbgen/activitystreams_activities.gen.go | 68 +-- storage-new/dbgen/collections.gen.go | 6 +- storage-new/dbgen/gen.go | 416 +++++++++--------- storage-new/migrations.go | 14 + storage-new/models/0allTypes.go | 2 +- ...ityTargetType.go => ActivityTargetType.go} | 0 ...ctivityToObject.go => ActivityToObject.go} | 2 +- ...streamsActivityType.go => ActivityType.go} | 0 .../{ActivityCollection.go => Collection.go} | 2 +- storage-new/models/CollectionTargetType.go | 28 ++ temp.toml | 2 +- web/debug/posts.go | 23 +- web/public/api/activitypub/activityCreate.go | 6 +- 14 files changed, 710 insertions(+), 253 deletions(-) create mode 100644 storage-new/dbgen/activities.gen.go rename storage-new/models/{ActivitystreamsActivityTargetType.go => ActivityTargetType.go} (100%) rename storage-new/models/{ActivitystreamsActivityToObject.go => ActivityToObject.go} (84%) rename storage-new/models/{ActivitystreamsActivityType.go => ActivityType.go} (100%) rename storage-new/models/{ActivityCollection.go => Collection.go} (64%) create mode 100644 storage-new/models/CollectionTargetType.go diff --git a/storage-new/dbgen/activities.gen.go b/storage-new/dbgen/activities.gen.go new file mode 100644 index 0000000..fadbb33 --- /dev/null +++ b/storage-new/dbgen/activities.gen.go @@ -0,0 +1,394 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package dbgen + +import ( + "context" + "database/sql" + + "git.mstar.dev/mstar/linstrom/storage-new/models" + "gorm.io/gorm" + "gorm.io/gorm/clause" + "gorm.io/gorm/schema" + + "gorm.io/gen" + "gorm.io/gen/field" + + "gorm.io/plugin/dbresolver" +) + +func newActivity(db *gorm.DB, opts ...gen.DOOption) activity { + _activity := activity{} + + _activity.activityDo.UseDB(db, opts...) + _activity.activityDo.UseModel(&models.Activity{}) + + tableName := _activity.activityDo.TableName() + _activity.ALL = field.NewAsterisk(tableName) + _activity.Id = field.NewString(tableName, "id") + _activity.Type = field.NewString(tableName, "type") + _activity.ObjectId = field.NewString(tableName, "object_id") + _activity.ObjectType = field.NewUint32(tableName, "object_type") + + _activity.fillFieldMap() + + return _activity +} + +type activity struct { + activityDo + + ALL field.Asterisk + Id field.String + Type field.String + ObjectId field.String + ObjectType field.Uint32 + + fieldMap map[string]field.Expr +} + +func (a activity) Table(newTableName string) *activity { + a.activityDo.UseTable(newTableName) + return a.updateTableName(newTableName) +} + +func (a activity) As(alias string) *activity { + a.activityDo.DO = *(a.activityDo.As(alias).(*gen.DO)) + return a.updateTableName(alias) +} + +func (a *activity) updateTableName(table string) *activity { + a.ALL = field.NewAsterisk(table) + a.Id = field.NewString(table, "id") + a.Type = field.NewString(table, "type") + a.ObjectId = field.NewString(table, "object_id") + a.ObjectType = field.NewUint32(table, "object_type") + + a.fillFieldMap() + + return a +} + +func (a *activity) GetFieldByName(fieldName string) (field.OrderExpr, bool) { + _f, ok := a.fieldMap[fieldName] + if !ok || _f == nil { + return nil, false + } + _oe, ok := _f.(field.OrderExpr) + return _oe, ok +} + +func (a *activity) fillFieldMap() { + a.fieldMap = make(map[string]field.Expr, 4) + a.fieldMap["id"] = a.Id + a.fieldMap["type"] = a.Type + a.fieldMap["object_id"] = a.ObjectId + a.fieldMap["object_type"] = a.ObjectType +} + +func (a activity) clone(db *gorm.DB) activity { + a.activityDo.ReplaceConnPool(db.Statement.ConnPool) + return a +} + +func (a activity) replaceDB(db *gorm.DB) activity { + a.activityDo.ReplaceDB(db) + return a +} + +type activityDo struct{ gen.DO } + +type IActivityDo interface { + gen.SubQuery + Debug() IActivityDo + WithContext(ctx context.Context) IActivityDo + WithResult(fc func(tx gen.Dao)) gen.ResultInfo + ReplaceDB(db *gorm.DB) + ReadDB() IActivityDo + WriteDB() IActivityDo + As(alias string) gen.Dao + Session(config *gorm.Session) IActivityDo + Columns(cols ...field.Expr) gen.Columns + Clauses(conds ...clause.Expression) IActivityDo + Not(conds ...gen.Condition) IActivityDo + Or(conds ...gen.Condition) IActivityDo + Select(conds ...field.Expr) IActivityDo + Where(conds ...gen.Condition) IActivityDo + Order(conds ...field.Expr) IActivityDo + Distinct(cols ...field.Expr) IActivityDo + Omit(cols ...field.Expr) IActivityDo + Join(table schema.Tabler, on ...field.Expr) IActivityDo + LeftJoin(table schema.Tabler, on ...field.Expr) IActivityDo + RightJoin(table schema.Tabler, on ...field.Expr) IActivityDo + Group(cols ...field.Expr) IActivityDo + Having(conds ...gen.Condition) IActivityDo + Limit(limit int) IActivityDo + Offset(offset int) IActivityDo + Count() (count int64, err error) + Scopes(funcs ...func(gen.Dao) gen.Dao) IActivityDo + Unscoped() IActivityDo + Create(values ...*models.Activity) error + CreateInBatches(values []*models.Activity, batchSize int) error + Save(values ...*models.Activity) error + First() (*models.Activity, error) + Take() (*models.Activity, error) + Last() (*models.Activity, error) + Find() ([]*models.Activity, error) + FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Activity, err error) + FindInBatches(result *[]*models.Activity, batchSize int, fc func(tx gen.Dao, batch int) error) error + Pluck(column field.Expr, dest interface{}) error + Delete(...*models.Activity) (info gen.ResultInfo, err error) + Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + Updates(value interface{}) (info gen.ResultInfo, err error) + UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + UpdateColumns(value interface{}) (info gen.ResultInfo, err error) + UpdateFrom(q gen.SubQuery) gen.Dao + Attrs(attrs ...field.AssignExpr) IActivityDo + Assign(attrs ...field.AssignExpr) IActivityDo + Joins(fields ...field.RelationField) IActivityDo + Preload(fields ...field.RelationField) IActivityDo + FirstOrInit() (*models.Activity, error) + FirstOrCreate() (*models.Activity, error) + FindByPage(offset int, limit int) (result []*models.Activity, count int64, err error) + ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Rows() (*sql.Rows, error) + Row() *sql.Row + Scan(result interface{}) (err error) + Returning(value interface{}, columns ...string) IActivityDo + UnderlyingDB() *gorm.DB + schema.Tabler +} + +func (a activityDo) Debug() IActivityDo { + return a.withDO(a.DO.Debug()) +} + +func (a activityDo) WithContext(ctx context.Context) IActivityDo { + return a.withDO(a.DO.WithContext(ctx)) +} + +func (a activityDo) ReadDB() IActivityDo { + return a.Clauses(dbresolver.Read) +} + +func (a activityDo) WriteDB() IActivityDo { + return a.Clauses(dbresolver.Write) +} + +func (a activityDo) Session(config *gorm.Session) IActivityDo { + return a.withDO(a.DO.Session(config)) +} + +func (a activityDo) Clauses(conds ...clause.Expression) IActivityDo { + return a.withDO(a.DO.Clauses(conds...)) +} + +func (a activityDo) Returning(value interface{}, columns ...string) IActivityDo { + return a.withDO(a.DO.Returning(value, columns...)) +} + +func (a activityDo) Not(conds ...gen.Condition) IActivityDo { + return a.withDO(a.DO.Not(conds...)) +} + +func (a activityDo) Or(conds ...gen.Condition) IActivityDo { + return a.withDO(a.DO.Or(conds...)) +} + +func (a activityDo) Select(conds ...field.Expr) IActivityDo { + return a.withDO(a.DO.Select(conds...)) +} + +func (a activityDo) Where(conds ...gen.Condition) IActivityDo { + return a.withDO(a.DO.Where(conds...)) +} + +func (a activityDo) Order(conds ...field.Expr) IActivityDo { + return a.withDO(a.DO.Order(conds...)) +} + +func (a activityDo) Distinct(cols ...field.Expr) IActivityDo { + return a.withDO(a.DO.Distinct(cols...)) +} + +func (a activityDo) Omit(cols ...field.Expr) IActivityDo { + return a.withDO(a.DO.Omit(cols...)) +} + +func (a activityDo) Join(table schema.Tabler, on ...field.Expr) IActivityDo { + return a.withDO(a.DO.Join(table, on...)) +} + +func (a activityDo) LeftJoin(table schema.Tabler, on ...field.Expr) IActivityDo { + return a.withDO(a.DO.LeftJoin(table, on...)) +} + +func (a activityDo) RightJoin(table schema.Tabler, on ...field.Expr) IActivityDo { + return a.withDO(a.DO.RightJoin(table, on...)) +} + +func (a activityDo) Group(cols ...field.Expr) IActivityDo { + return a.withDO(a.DO.Group(cols...)) +} + +func (a activityDo) Having(conds ...gen.Condition) IActivityDo { + return a.withDO(a.DO.Having(conds...)) +} + +func (a activityDo) Limit(limit int) IActivityDo { + return a.withDO(a.DO.Limit(limit)) +} + +func (a activityDo) Offset(offset int) IActivityDo { + return a.withDO(a.DO.Offset(offset)) +} + +func (a activityDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IActivityDo { + return a.withDO(a.DO.Scopes(funcs...)) +} + +func (a activityDo) Unscoped() IActivityDo { + return a.withDO(a.DO.Unscoped()) +} + +func (a activityDo) Create(values ...*models.Activity) error { + if len(values) == 0 { + return nil + } + return a.DO.Create(values) +} + +func (a activityDo) CreateInBatches(values []*models.Activity, batchSize int) error { + return a.DO.CreateInBatches(values, batchSize) +} + +// Save : !!! underlying implementation is different with GORM +// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) +func (a activityDo) Save(values ...*models.Activity) error { + if len(values) == 0 { + return nil + } + return a.DO.Save(values) +} + +func (a activityDo) First() (*models.Activity, error) { + if result, err := a.DO.First(); err != nil { + return nil, err + } else { + return result.(*models.Activity), nil + } +} + +func (a activityDo) Take() (*models.Activity, error) { + if result, err := a.DO.Take(); err != nil { + return nil, err + } else { + return result.(*models.Activity), nil + } +} + +func (a activityDo) Last() (*models.Activity, error) { + if result, err := a.DO.Last(); err != nil { + return nil, err + } else { + return result.(*models.Activity), nil + } +} + +func (a activityDo) Find() ([]*models.Activity, error) { + result, err := a.DO.Find() + return result.([]*models.Activity), err +} + +func (a activityDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Activity, err error) { + buf := make([]*models.Activity, 0, batchSize) + err = a.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { + defer func() { results = append(results, buf...) }() + return fc(tx, batch) + }) + return results, err +} + +func (a activityDo) FindInBatches(result *[]*models.Activity, batchSize int, fc func(tx gen.Dao, batch int) error) error { + return a.DO.FindInBatches(result, batchSize, fc) +} + +func (a activityDo) Attrs(attrs ...field.AssignExpr) IActivityDo { + return a.withDO(a.DO.Attrs(attrs...)) +} + +func (a activityDo) Assign(attrs ...field.AssignExpr) IActivityDo { + return a.withDO(a.DO.Assign(attrs...)) +} + +func (a activityDo) Joins(fields ...field.RelationField) IActivityDo { + for _, _f := range fields { + a = *a.withDO(a.DO.Joins(_f)) + } + return &a +} + +func (a activityDo) Preload(fields ...field.RelationField) IActivityDo { + for _, _f := range fields { + a = *a.withDO(a.DO.Preload(_f)) + } + return &a +} + +func (a activityDo) FirstOrInit() (*models.Activity, error) { + if result, err := a.DO.FirstOrInit(); err != nil { + return nil, err + } else { + return result.(*models.Activity), nil + } +} + +func (a activityDo) FirstOrCreate() (*models.Activity, error) { + if result, err := a.DO.FirstOrCreate(); err != nil { + return nil, err + } else { + return result.(*models.Activity), nil + } +} + +func (a activityDo) FindByPage(offset int, limit int) (result []*models.Activity, count int64, err error) { + result, err = a.Offset(offset).Limit(limit).Find() + if err != nil { + return + } + + if size := len(result); 0 < limit && 0 < size && size < limit { + count = int64(size + offset) + return + } + + count, err = a.Offset(-1).Limit(-1).Count() + return +} + +func (a activityDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { + count, err = a.Count() + if err != nil { + return + } + + err = a.Offset(offset).Limit(limit).Scan(result) + return +} + +func (a activityDo) Scan(result interface{}) (err error) { + return a.DO.Scan(result) +} + +func (a activityDo) Delete(models ...*models.Activity) (result gen.ResultInfo, err error) { + return a.DO.Delete(models) +} + +func (a *activityDo) withDO(do gen.Dao) *activityDo { + a.DO = *do.(*gen.DO) + return a +} diff --git a/storage-new/dbgen/activitystreams_activities.gen.go b/storage-new/dbgen/activitystreams_activities.gen.go index b52f570..0ff85b1 100644 --- a/storage-new/dbgen/activitystreams_activities.gen.go +++ b/storage-new/dbgen/activitystreams_activities.gen.go @@ -23,7 +23,7 @@ func newActivitystreamsActivity(db *gorm.DB, opts ...gen.DOOption) activitystrea _activitystreamsActivity := activitystreamsActivity{} _activitystreamsActivity.activitystreamsActivityDo.UseDB(db, opts...) - _activitystreamsActivity.activitystreamsActivityDo.UseModel(&models.ActivitystreamsActivity{}) + _activitystreamsActivity.activitystreamsActivityDo.UseModel(&models.Activity{}) tableName := _activitystreamsActivity.activitystreamsActivityDo.TableName() _activitystreamsActivity.ALL = field.NewAsterisk(tableName) @@ -129,17 +129,17 @@ type IActivitystreamsActivityDo interface { Count() (count int64, err error) Scopes(funcs ...func(gen.Dao) gen.Dao) IActivitystreamsActivityDo Unscoped() IActivitystreamsActivityDo - Create(values ...*models.ActivitystreamsActivity) error - CreateInBatches(values []*models.ActivitystreamsActivity, batchSize int) error - Save(values ...*models.ActivitystreamsActivity) error - First() (*models.ActivitystreamsActivity, error) - Take() (*models.ActivitystreamsActivity, error) - Last() (*models.ActivitystreamsActivity, error) - Find() ([]*models.ActivitystreamsActivity, error) - FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.ActivitystreamsActivity, err error) - FindInBatches(result *[]*models.ActivitystreamsActivity, batchSize int, fc func(tx gen.Dao, batch int) error) error + Create(values ...*models.Activity) error + CreateInBatches(values []*models.Activity, batchSize int) error + Save(values ...*models.Activity) error + First() (*models.Activity, error) + Take() (*models.Activity, error) + Last() (*models.Activity, error) + Find() ([]*models.Activity, error) + FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Activity, err error) + FindInBatches(result *[]*models.Activity, batchSize int, fc func(tx gen.Dao, batch int) error) error Pluck(column field.Expr, dest interface{}) error - Delete(...*models.ActivitystreamsActivity) (info gen.ResultInfo, err error) + Delete(...*models.Activity) (info gen.ResultInfo, err error) Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error) UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) Updates(value interface{}) (info gen.ResultInfo, err error) @@ -151,9 +151,9 @@ type IActivitystreamsActivityDo interface { Assign(attrs ...field.AssignExpr) IActivitystreamsActivityDo Joins(fields ...field.RelationField) IActivitystreamsActivityDo Preload(fields ...field.RelationField) IActivitystreamsActivityDo - FirstOrInit() (*models.ActivitystreamsActivity, error) - FirstOrCreate() (*models.ActivitystreamsActivity, error) - FindByPage(offset int, limit int) (result []*models.ActivitystreamsActivity, count int64, err error) + FirstOrInit() (*models.Activity, error) + FirstOrCreate() (*models.Activity, error) + FindByPage(offset int, limit int) (result []*models.Activity, count int64, err error) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) Rows() (*sql.Rows, error) Row() *sql.Row @@ -255,57 +255,57 @@ func (a activitystreamsActivityDo) Unscoped() IActivitystreamsActivityDo { return a.withDO(a.DO.Unscoped()) } -func (a activitystreamsActivityDo) Create(values ...*models.ActivitystreamsActivity) error { +func (a activitystreamsActivityDo) Create(values ...*models.Activity) error { if len(values) == 0 { return nil } return a.DO.Create(values) } -func (a activitystreamsActivityDo) CreateInBatches(values []*models.ActivitystreamsActivity, batchSize int) error { +func (a activitystreamsActivityDo) CreateInBatches(values []*models.Activity, batchSize int) error { return a.DO.CreateInBatches(values, batchSize) } // Save : !!! underlying implementation is different with GORM // The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) -func (a activitystreamsActivityDo) Save(values ...*models.ActivitystreamsActivity) error { +func (a activitystreamsActivityDo) Save(values ...*models.Activity) error { if len(values) == 0 { return nil } return a.DO.Save(values) } -func (a activitystreamsActivityDo) First() (*models.ActivitystreamsActivity, error) { +func (a activitystreamsActivityDo) First() (*models.Activity, error) { if result, err := a.DO.First(); err != nil { return nil, err } else { - return result.(*models.ActivitystreamsActivity), nil + return result.(*models.Activity), nil } } -func (a activitystreamsActivityDo) Take() (*models.ActivitystreamsActivity, error) { +func (a activitystreamsActivityDo) Take() (*models.Activity, error) { if result, err := a.DO.Take(); err != nil { return nil, err } else { - return result.(*models.ActivitystreamsActivity), nil + return result.(*models.Activity), nil } } -func (a activitystreamsActivityDo) Last() (*models.ActivitystreamsActivity, error) { +func (a activitystreamsActivityDo) Last() (*models.Activity, error) { if result, err := a.DO.Last(); err != nil { return nil, err } else { - return result.(*models.ActivitystreamsActivity), nil + return result.(*models.Activity), nil } } -func (a activitystreamsActivityDo) Find() ([]*models.ActivitystreamsActivity, error) { +func (a activitystreamsActivityDo) Find() ([]*models.Activity, error) { result, err := a.DO.Find() - return result.([]*models.ActivitystreamsActivity), err + return result.([]*models.Activity), err } -func (a activitystreamsActivityDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.ActivitystreamsActivity, err error) { - buf := make([]*models.ActivitystreamsActivity, 0, batchSize) +func (a activitystreamsActivityDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Activity, err error) { + buf := make([]*models.Activity, 0, batchSize) err = a.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { defer func() { results = append(results, buf...) }() return fc(tx, batch) @@ -313,7 +313,7 @@ func (a activitystreamsActivityDo) FindInBatch(batchSize int, fc func(tx gen.Dao return results, err } -func (a activitystreamsActivityDo) FindInBatches(result *[]*models.ActivitystreamsActivity, batchSize int, fc func(tx gen.Dao, batch int) error) error { +func (a activitystreamsActivityDo) FindInBatches(result *[]*models.Activity, batchSize int, fc func(tx gen.Dao, batch int) error) error { return a.DO.FindInBatches(result, batchSize, fc) } @@ -339,23 +339,23 @@ func (a activitystreamsActivityDo) Preload(fields ...field.RelationField) IActiv return &a } -func (a activitystreamsActivityDo) FirstOrInit() (*models.ActivitystreamsActivity, error) { +func (a activitystreamsActivityDo) FirstOrInit() (*models.Activity, error) { if result, err := a.DO.FirstOrInit(); err != nil { return nil, err } else { - return result.(*models.ActivitystreamsActivity), nil + return result.(*models.Activity), nil } } -func (a activitystreamsActivityDo) FirstOrCreate() (*models.ActivitystreamsActivity, error) { +func (a activitystreamsActivityDo) FirstOrCreate() (*models.Activity, error) { if result, err := a.DO.FirstOrCreate(); err != nil { return nil, err } else { - return result.(*models.ActivitystreamsActivity), nil + return result.(*models.Activity), nil } } -func (a activitystreamsActivityDo) FindByPage(offset int, limit int) (result []*models.ActivitystreamsActivity, count int64, err error) { +func (a activitystreamsActivityDo) FindByPage(offset int, limit int) (result []*models.Activity, count int64, err error) { result, err = a.Offset(offset).Limit(limit).Find() if err != nil { return @@ -384,7 +384,7 @@ func (a activitystreamsActivityDo) Scan(result interface{}) (err error) { return a.DO.Scan(result) } -func (a activitystreamsActivityDo) Delete(models ...*models.ActivitystreamsActivity) (result gen.ResultInfo, err error) { +func (a activitystreamsActivityDo) Delete(models ...*models.Activity) (result gen.ResultInfo, err error) { return a.DO.Delete(models) } diff --git a/storage-new/dbgen/collections.gen.go b/storage-new/dbgen/collections.gen.go index 7629edf..b530c36 100644 --- a/storage-new/dbgen/collections.gen.go +++ b/storage-new/dbgen/collections.gen.go @@ -29,7 +29,7 @@ func newCollection(db *gorm.DB, opts ...gen.DOOption) collection { _collection.ALL = field.NewAsterisk(tableName) _collection.Id = field.NewString(tableName, "id") _collection.TargetId = field.NewString(tableName, "target_id") - _collection.TargetType = field.NewUint32(tableName, "target_type") + _collection.TargetType = field.NewString(tableName, "target_type") _collection.fillFieldMap() @@ -42,7 +42,7 @@ type collection struct { ALL field.Asterisk Id field.String TargetId field.String - TargetType field.Uint32 + TargetType field.String fieldMap map[string]field.Expr } @@ -61,7 +61,7 @@ func (c *collection) updateTableName(table string) *collection { c.ALL = field.NewAsterisk(table) c.Id = field.NewString(table, "id") c.TargetId = field.NewString(table, "target_id") - c.TargetType = field.NewUint32(table, "target_type") + c.TargetType = field.NewString(table, "target_type") c.fillFieldMap() diff --git a/storage-new/dbgen/gen.go b/storage-new/dbgen/gen.go index 1a5caa9..78688ff 100644 --- a/storage-new/dbgen/gen.go +++ b/storage-new/dbgen/gen.go @@ -16,42 +16,42 @@ import ( ) var ( - Q = new(Query) - AccessToken *accessToken - ActivitystreamsActivity *activitystreamsActivity - Collection *collection - Emote *emote - Feed *feed - LoginProcessToken *loginProcessToken - MediaMetadata *mediaMetadata - Note *note - NoteEdit *noteEdit - NoteTag *noteTag - NoteToAttachment *noteToAttachment - NoteToBoost *noteToBoost - NoteToEmote *noteToEmote - NoteToFeed *noteToFeed - NoteToPing *noteToPing - Notification *notification - Reaction *reaction - RemoteServer *remoteServer - RemoteServerMetadata *remoteServerMetadata - Role *role - User *user - UserAuthMethod *userAuthMethod - UserInfoField *userInfoField - UserRemoteLinks *userRemoteLinks - UserToBeing *userToBeing - UserToPronoun *userToPronoun - UserToRole *userToRole - UserToTag *userToTag - UserToUserRelation *userToUserRelation + Q = new(Query) + AccessToken *accessToken + Activity *activity + Collection *collection + Emote *emote + Feed *feed + LoginProcessToken *loginProcessToken + MediaMetadata *mediaMetadata + Note *note + NoteEdit *noteEdit + NoteTag *noteTag + NoteToAttachment *noteToAttachment + NoteToBoost *noteToBoost + NoteToEmote *noteToEmote + NoteToFeed *noteToFeed + NoteToPing *noteToPing + Notification *notification + Reaction *reaction + RemoteServer *remoteServer + RemoteServerMetadata *remoteServerMetadata + Role *role + User *user + UserAuthMethod *userAuthMethod + UserInfoField *userInfoField + UserRemoteLinks *userRemoteLinks + UserToBeing *userToBeing + UserToPronoun *userToPronoun + UserToRole *userToRole + UserToTag *userToTag + UserToUserRelation *userToUserRelation ) func SetDefault(db *gorm.DB, opts ...gen.DOOption) { *Q = *Use(db, opts...) AccessToken = &Q.AccessToken - ActivitystreamsActivity = &Q.ActivitystreamsActivity + Activity = &Q.Activity Collection = &Q.Collection Emote = &Q.Emote Feed = &Q.Feed @@ -83,107 +83,107 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) { func Use(db *gorm.DB, opts ...gen.DOOption) *Query { return &Query{ - db: db, - AccessToken: newAccessToken(db, opts...), - ActivitystreamsActivity: newActivitystreamsActivity(db, opts...), - Collection: newCollection(db, opts...), - Emote: newEmote(db, opts...), - Feed: newFeed(db, opts...), - LoginProcessToken: newLoginProcessToken(db, opts...), - MediaMetadata: newMediaMetadata(db, opts...), - Note: newNote(db, opts...), - NoteEdit: newNoteEdit(db, opts...), - NoteTag: newNoteTag(db, opts...), - NoteToAttachment: newNoteToAttachment(db, opts...), - NoteToBoost: newNoteToBoost(db, opts...), - NoteToEmote: newNoteToEmote(db, opts...), - NoteToFeed: newNoteToFeed(db, opts...), - NoteToPing: newNoteToPing(db, opts...), - Notification: newNotification(db, opts...), - Reaction: newReaction(db, opts...), - RemoteServer: newRemoteServer(db, opts...), - RemoteServerMetadata: newRemoteServerMetadata(db, opts...), - Role: newRole(db, opts...), - User: newUser(db, opts...), - UserAuthMethod: newUserAuthMethod(db, opts...), - UserInfoField: newUserInfoField(db, opts...), - UserRemoteLinks: newUserRemoteLinks(db, opts...), - UserToBeing: newUserToBeing(db, opts...), - UserToPronoun: newUserToPronoun(db, opts...), - UserToRole: newUserToRole(db, opts...), - UserToTag: newUserToTag(db, opts...), - UserToUserRelation: newUserToUserRelation(db, opts...), + db: db, + AccessToken: newAccessToken(db, opts...), + Activity: newActivity(db, opts...), + Collection: newCollection(db, opts...), + Emote: newEmote(db, opts...), + Feed: newFeed(db, opts...), + LoginProcessToken: newLoginProcessToken(db, opts...), + MediaMetadata: newMediaMetadata(db, opts...), + Note: newNote(db, opts...), + NoteEdit: newNoteEdit(db, opts...), + NoteTag: newNoteTag(db, opts...), + NoteToAttachment: newNoteToAttachment(db, opts...), + NoteToBoost: newNoteToBoost(db, opts...), + NoteToEmote: newNoteToEmote(db, opts...), + NoteToFeed: newNoteToFeed(db, opts...), + NoteToPing: newNoteToPing(db, opts...), + Notification: newNotification(db, opts...), + Reaction: newReaction(db, opts...), + RemoteServer: newRemoteServer(db, opts...), + RemoteServerMetadata: newRemoteServerMetadata(db, opts...), + Role: newRole(db, opts...), + User: newUser(db, opts...), + UserAuthMethod: newUserAuthMethod(db, opts...), + UserInfoField: newUserInfoField(db, opts...), + UserRemoteLinks: newUserRemoteLinks(db, opts...), + UserToBeing: newUserToBeing(db, opts...), + UserToPronoun: newUserToPronoun(db, opts...), + UserToRole: newUserToRole(db, opts...), + UserToTag: newUserToTag(db, opts...), + UserToUserRelation: newUserToUserRelation(db, opts...), } } type Query struct { db *gorm.DB - AccessToken accessToken - ActivitystreamsActivity activitystreamsActivity - Collection collection - Emote emote - Feed feed - LoginProcessToken loginProcessToken - MediaMetadata mediaMetadata - Note note - NoteEdit noteEdit - NoteTag noteTag - NoteToAttachment noteToAttachment - NoteToBoost noteToBoost - NoteToEmote noteToEmote - NoteToFeed noteToFeed - NoteToPing noteToPing - Notification notification - Reaction reaction - RemoteServer remoteServer - RemoteServerMetadata remoteServerMetadata - Role role - User user - UserAuthMethod userAuthMethod - UserInfoField userInfoField - UserRemoteLinks userRemoteLinks - UserToBeing userToBeing - UserToPronoun userToPronoun - UserToRole userToRole - UserToTag userToTag - UserToUserRelation userToUserRelation + AccessToken accessToken + Activity activity + Collection collection + Emote emote + Feed feed + LoginProcessToken loginProcessToken + MediaMetadata mediaMetadata + Note note + NoteEdit noteEdit + NoteTag noteTag + NoteToAttachment noteToAttachment + NoteToBoost noteToBoost + NoteToEmote noteToEmote + NoteToFeed noteToFeed + NoteToPing noteToPing + Notification notification + Reaction reaction + RemoteServer remoteServer + RemoteServerMetadata remoteServerMetadata + Role role + User user + UserAuthMethod userAuthMethod + UserInfoField userInfoField + UserRemoteLinks userRemoteLinks + UserToBeing userToBeing + UserToPronoun userToPronoun + UserToRole userToRole + UserToTag userToTag + UserToUserRelation userToUserRelation } func (q *Query) Available() bool { return q.db != nil } func (q *Query) clone(db *gorm.DB) *Query { return &Query{ - db: db, - AccessToken: q.AccessToken.clone(db), - ActivitystreamsActivity: q.ActivitystreamsActivity.clone(db), - Collection: q.Collection.clone(db), - Emote: q.Emote.clone(db), - Feed: q.Feed.clone(db), - LoginProcessToken: q.LoginProcessToken.clone(db), - MediaMetadata: q.MediaMetadata.clone(db), - Note: q.Note.clone(db), - NoteEdit: q.NoteEdit.clone(db), - NoteTag: q.NoteTag.clone(db), - NoteToAttachment: q.NoteToAttachment.clone(db), - NoteToBoost: q.NoteToBoost.clone(db), - NoteToEmote: q.NoteToEmote.clone(db), - NoteToFeed: q.NoteToFeed.clone(db), - NoteToPing: q.NoteToPing.clone(db), - Notification: q.Notification.clone(db), - Reaction: q.Reaction.clone(db), - RemoteServer: q.RemoteServer.clone(db), - RemoteServerMetadata: q.RemoteServerMetadata.clone(db), - Role: q.Role.clone(db), - User: q.User.clone(db), - UserAuthMethod: q.UserAuthMethod.clone(db), - UserInfoField: q.UserInfoField.clone(db), - UserRemoteLinks: q.UserRemoteLinks.clone(db), - UserToBeing: q.UserToBeing.clone(db), - UserToPronoun: q.UserToPronoun.clone(db), - UserToRole: q.UserToRole.clone(db), - UserToTag: q.UserToTag.clone(db), - UserToUserRelation: q.UserToUserRelation.clone(db), + db: db, + AccessToken: q.AccessToken.clone(db), + Activity: q.Activity.clone(db), + Collection: q.Collection.clone(db), + Emote: q.Emote.clone(db), + Feed: q.Feed.clone(db), + LoginProcessToken: q.LoginProcessToken.clone(db), + MediaMetadata: q.MediaMetadata.clone(db), + Note: q.Note.clone(db), + NoteEdit: q.NoteEdit.clone(db), + NoteTag: q.NoteTag.clone(db), + NoteToAttachment: q.NoteToAttachment.clone(db), + NoteToBoost: q.NoteToBoost.clone(db), + NoteToEmote: q.NoteToEmote.clone(db), + NoteToFeed: q.NoteToFeed.clone(db), + NoteToPing: q.NoteToPing.clone(db), + Notification: q.Notification.clone(db), + Reaction: q.Reaction.clone(db), + RemoteServer: q.RemoteServer.clone(db), + RemoteServerMetadata: q.RemoteServerMetadata.clone(db), + Role: q.Role.clone(db), + User: q.User.clone(db), + UserAuthMethod: q.UserAuthMethod.clone(db), + UserInfoField: q.UserInfoField.clone(db), + UserRemoteLinks: q.UserRemoteLinks.clone(db), + UserToBeing: q.UserToBeing.clone(db), + UserToPronoun: q.UserToPronoun.clone(db), + UserToRole: q.UserToRole.clone(db), + UserToTag: q.UserToTag.clone(db), + UserToUserRelation: q.UserToUserRelation.clone(db), } } @@ -197,102 +197,102 @@ func (q *Query) WriteDB() *Query { func (q *Query) ReplaceDB(db *gorm.DB) *Query { return &Query{ - db: db, - AccessToken: q.AccessToken.replaceDB(db), - ActivitystreamsActivity: q.ActivitystreamsActivity.replaceDB(db), - Collection: q.Collection.replaceDB(db), - Emote: q.Emote.replaceDB(db), - Feed: q.Feed.replaceDB(db), - LoginProcessToken: q.LoginProcessToken.replaceDB(db), - MediaMetadata: q.MediaMetadata.replaceDB(db), - Note: q.Note.replaceDB(db), - NoteEdit: q.NoteEdit.replaceDB(db), - NoteTag: q.NoteTag.replaceDB(db), - NoteToAttachment: q.NoteToAttachment.replaceDB(db), - NoteToBoost: q.NoteToBoost.replaceDB(db), - NoteToEmote: q.NoteToEmote.replaceDB(db), - NoteToFeed: q.NoteToFeed.replaceDB(db), - NoteToPing: q.NoteToPing.replaceDB(db), - Notification: q.Notification.replaceDB(db), - Reaction: q.Reaction.replaceDB(db), - RemoteServer: q.RemoteServer.replaceDB(db), - RemoteServerMetadata: q.RemoteServerMetadata.replaceDB(db), - Role: q.Role.replaceDB(db), - User: q.User.replaceDB(db), - UserAuthMethod: q.UserAuthMethod.replaceDB(db), - UserInfoField: q.UserInfoField.replaceDB(db), - UserRemoteLinks: q.UserRemoteLinks.replaceDB(db), - UserToBeing: q.UserToBeing.replaceDB(db), - UserToPronoun: q.UserToPronoun.replaceDB(db), - UserToRole: q.UserToRole.replaceDB(db), - UserToTag: q.UserToTag.replaceDB(db), - UserToUserRelation: q.UserToUserRelation.replaceDB(db), + db: db, + AccessToken: q.AccessToken.replaceDB(db), + Activity: q.Activity.replaceDB(db), + Collection: q.Collection.replaceDB(db), + Emote: q.Emote.replaceDB(db), + Feed: q.Feed.replaceDB(db), + LoginProcessToken: q.LoginProcessToken.replaceDB(db), + MediaMetadata: q.MediaMetadata.replaceDB(db), + Note: q.Note.replaceDB(db), + NoteEdit: q.NoteEdit.replaceDB(db), + NoteTag: q.NoteTag.replaceDB(db), + NoteToAttachment: q.NoteToAttachment.replaceDB(db), + NoteToBoost: q.NoteToBoost.replaceDB(db), + NoteToEmote: q.NoteToEmote.replaceDB(db), + NoteToFeed: q.NoteToFeed.replaceDB(db), + NoteToPing: q.NoteToPing.replaceDB(db), + Notification: q.Notification.replaceDB(db), + Reaction: q.Reaction.replaceDB(db), + RemoteServer: q.RemoteServer.replaceDB(db), + RemoteServerMetadata: q.RemoteServerMetadata.replaceDB(db), + Role: q.Role.replaceDB(db), + User: q.User.replaceDB(db), + UserAuthMethod: q.UserAuthMethod.replaceDB(db), + UserInfoField: q.UserInfoField.replaceDB(db), + UserRemoteLinks: q.UserRemoteLinks.replaceDB(db), + UserToBeing: q.UserToBeing.replaceDB(db), + UserToPronoun: q.UserToPronoun.replaceDB(db), + UserToRole: q.UserToRole.replaceDB(db), + UserToTag: q.UserToTag.replaceDB(db), + UserToUserRelation: q.UserToUserRelation.replaceDB(db), } } type queryCtx struct { - AccessToken IAccessTokenDo - ActivitystreamsActivity IActivitystreamsActivityDo - Collection ICollectionDo - Emote IEmoteDo - Feed IFeedDo - LoginProcessToken ILoginProcessTokenDo - MediaMetadata IMediaMetadataDo - Note INoteDo - NoteEdit INoteEditDo - NoteTag INoteTagDo - NoteToAttachment INoteToAttachmentDo - NoteToBoost INoteToBoostDo - NoteToEmote INoteToEmoteDo - NoteToFeed INoteToFeedDo - NoteToPing INoteToPingDo - Notification INotificationDo - Reaction IReactionDo - RemoteServer IRemoteServerDo - RemoteServerMetadata IRemoteServerMetadataDo - Role IRoleDo - User IUserDo - UserAuthMethod IUserAuthMethodDo - UserInfoField IUserInfoFieldDo - UserRemoteLinks IUserRemoteLinksDo - UserToBeing IUserToBeingDo - UserToPronoun IUserToPronounDo - UserToRole IUserToRoleDo - UserToTag IUserToTagDo - UserToUserRelation IUserToUserRelationDo + AccessToken IAccessTokenDo + Activity IActivityDo + Collection ICollectionDo + Emote IEmoteDo + Feed IFeedDo + LoginProcessToken ILoginProcessTokenDo + MediaMetadata IMediaMetadataDo + Note INoteDo + NoteEdit INoteEditDo + NoteTag INoteTagDo + NoteToAttachment INoteToAttachmentDo + NoteToBoost INoteToBoostDo + NoteToEmote INoteToEmoteDo + NoteToFeed INoteToFeedDo + NoteToPing INoteToPingDo + Notification INotificationDo + Reaction IReactionDo + RemoteServer IRemoteServerDo + RemoteServerMetadata IRemoteServerMetadataDo + Role IRoleDo + User IUserDo + UserAuthMethod IUserAuthMethodDo + UserInfoField IUserInfoFieldDo + UserRemoteLinks IUserRemoteLinksDo + UserToBeing IUserToBeingDo + UserToPronoun IUserToPronounDo + UserToRole IUserToRoleDo + UserToTag IUserToTagDo + UserToUserRelation IUserToUserRelationDo } func (q *Query) WithContext(ctx context.Context) *queryCtx { return &queryCtx{ - AccessToken: q.AccessToken.WithContext(ctx), - ActivitystreamsActivity: q.ActivitystreamsActivity.WithContext(ctx), - Collection: q.Collection.WithContext(ctx), - Emote: q.Emote.WithContext(ctx), - Feed: q.Feed.WithContext(ctx), - LoginProcessToken: q.LoginProcessToken.WithContext(ctx), - MediaMetadata: q.MediaMetadata.WithContext(ctx), - Note: q.Note.WithContext(ctx), - NoteEdit: q.NoteEdit.WithContext(ctx), - NoteTag: q.NoteTag.WithContext(ctx), - NoteToAttachment: q.NoteToAttachment.WithContext(ctx), - NoteToBoost: q.NoteToBoost.WithContext(ctx), - NoteToEmote: q.NoteToEmote.WithContext(ctx), - NoteToFeed: q.NoteToFeed.WithContext(ctx), - NoteToPing: q.NoteToPing.WithContext(ctx), - Notification: q.Notification.WithContext(ctx), - Reaction: q.Reaction.WithContext(ctx), - RemoteServer: q.RemoteServer.WithContext(ctx), - RemoteServerMetadata: q.RemoteServerMetadata.WithContext(ctx), - Role: q.Role.WithContext(ctx), - User: q.User.WithContext(ctx), - UserAuthMethod: q.UserAuthMethod.WithContext(ctx), - UserInfoField: q.UserInfoField.WithContext(ctx), - UserRemoteLinks: q.UserRemoteLinks.WithContext(ctx), - UserToBeing: q.UserToBeing.WithContext(ctx), - UserToPronoun: q.UserToPronoun.WithContext(ctx), - UserToRole: q.UserToRole.WithContext(ctx), - UserToTag: q.UserToTag.WithContext(ctx), - UserToUserRelation: q.UserToUserRelation.WithContext(ctx), + AccessToken: q.AccessToken.WithContext(ctx), + Activity: q.Activity.WithContext(ctx), + Collection: q.Collection.WithContext(ctx), + Emote: q.Emote.WithContext(ctx), + Feed: q.Feed.WithContext(ctx), + LoginProcessToken: q.LoginProcessToken.WithContext(ctx), + MediaMetadata: q.MediaMetadata.WithContext(ctx), + Note: q.Note.WithContext(ctx), + NoteEdit: q.NoteEdit.WithContext(ctx), + NoteTag: q.NoteTag.WithContext(ctx), + NoteToAttachment: q.NoteToAttachment.WithContext(ctx), + NoteToBoost: q.NoteToBoost.WithContext(ctx), + NoteToEmote: q.NoteToEmote.WithContext(ctx), + NoteToFeed: q.NoteToFeed.WithContext(ctx), + NoteToPing: q.NoteToPing.WithContext(ctx), + Notification: q.Notification.WithContext(ctx), + Reaction: q.Reaction.WithContext(ctx), + RemoteServer: q.RemoteServer.WithContext(ctx), + RemoteServerMetadata: q.RemoteServerMetadata.WithContext(ctx), + Role: q.Role.WithContext(ctx), + User: q.User.WithContext(ctx), + UserAuthMethod: q.UserAuthMethod.WithContext(ctx), + UserInfoField: q.UserInfoField.WithContext(ctx), + UserRemoteLinks: q.UserRemoteLinks.WithContext(ctx), + UserToBeing: q.UserToBeing.WithContext(ctx), + UserToPronoun: q.UserToPronoun.WithContext(ctx), + UserToRole: q.UserToRole.WithContext(ctx), + UserToTag: q.UserToTag.WithContext(ctx), + UserToUserRelation: q.UserToUserRelation.WithContext(ctx), } } diff --git a/storage-new/migrations.go b/storage-new/migrations.go index 2da2092..e221ba3 100644 --- a/storage-new/migrations.go +++ b/storage-new/migrations.go @@ -37,6 +37,9 @@ func Migrate(db *gorm.DB) error { if err := createActitiystreamsActivityType(db); err != nil { return other.Error("storage", "Failed to create Activitystreams Activity type", err) } + if err := createCollectionTarget(db); err != nil { + return other.Error("storage", "Failed t ocreate collections target type", err) + } if err := migrateTypes(db); err != nil { return other.Error("storage", "Failed to automigrate data structs", err) } @@ -126,6 +129,17 @@ func createActitiystreamsActivityTargetType(db *gorm.DB) error { ) } +func createCollectionTarget(db *gorm.DB) error { + return migrateEnum( + db, + "collection_target_type", + sliceutils.Map( + models.AllCollectionTargetTypes, + func(t models.CollectionTargetType) string { return string(t) }, + ), + ) +} + // Helper function for ensuring the existence of an enum with the given values func migrateEnum(db *gorm.DB, name string, values []string) error { if err := db.Exec("DROP TYPE IF EXISTS " + name + " CASCADE;").Error; err != nil { diff --git a/storage-new/models/0allTypes.go b/storage-new/models/0allTypes.go index dc77365..4e2d4f9 100644 --- a/storage-new/models/0allTypes.go +++ b/storage-new/models/0allTypes.go @@ -2,8 +2,8 @@ package models // A list of all models stored in the database var AllTypes = []any{ + &Activity{}, &Collection{}, - &ActivitystreamsActivity{}, &Emote{}, &Feed{}, &MediaMetadata{}, diff --git a/storage-new/models/ActivitystreamsActivityTargetType.go b/storage-new/models/ActivityTargetType.go similarity index 100% rename from storage-new/models/ActivitystreamsActivityTargetType.go rename to storage-new/models/ActivityTargetType.go diff --git a/storage-new/models/ActivitystreamsActivityToObject.go b/storage-new/models/ActivityToObject.go similarity index 84% rename from storage-new/models/ActivitystreamsActivityToObject.go rename to storage-new/models/ActivityToObject.go index a08797a..b36a26c 100644 --- a/storage-new/models/ActivitystreamsActivityToObject.go +++ b/storage-new/models/ActivityToObject.go @@ -1,6 +1,6 @@ package models -type ActivitystreamsActivity struct { +type Activity struct { Id string `gorm:"primarykey"` Type string `gorm:"type:activitystreams_activity_type"` ObjectId string diff --git a/storage-new/models/ActivitystreamsActivityType.go b/storage-new/models/ActivityType.go similarity index 100% rename from storage-new/models/ActivitystreamsActivityType.go rename to storage-new/models/ActivityType.go diff --git a/storage-new/models/ActivityCollection.go b/storage-new/models/Collection.go similarity index 64% rename from storage-new/models/ActivityCollection.go rename to storage-new/models/Collection.go index 065af66..d17b570 100644 --- a/storage-new/models/ActivityCollection.go +++ b/storage-new/models/Collection.go @@ -3,5 +3,5 @@ package models type Collection struct { Id string `gorm:"primarykey"` TargetId string - TargetType uint32 + TargetType string `orm:"type:collection_target_type"` } diff --git a/storage-new/models/CollectionTargetType.go b/storage-new/models/CollectionTargetType.go new file mode 100644 index 0000000..28940bd --- /dev/null +++ b/storage-new/models/CollectionTargetType.go @@ -0,0 +1,28 @@ +package models + +import "database/sql/driver" + +type CollectionTargetType string + +const ( + CollectionTargetUnknown = CollectionTargetType("unknown") + CollectionTargetPinnedNotes = CollectionTargetType("pinned") + CollectionTargetReactions = CollectionTargetType("reactions") + CollectionTargetBoostsAndQuotes = CollectionTargetType("boosts") +) + +var AllCollectionTargetTypes = []CollectionTargetType{ + CollectionTargetUnknown, + CollectionTargetPinnedNotes, + CollectionTargetReactions, + CollectionTargetBoostsAndQuotes, +} + +func (n *CollectionTargetType) Value() (driver.Value, error) { + return n, nil +} + +func (ct *CollectionTargetType) Scan(value any) error { + *ct = CollectionTargetType(value.(uint32)) + return nil +} diff --git a/temp.toml b/temp.toml index dd4bba2..3c0f2d4 100644 --- a/temp.toml +++ b/temp.toml @@ -1,7 +1,7 @@ [general] protocol = "https" domain = "lhr.life" - subdomain = "61f6e346a99d58" + subdomain = "e8adf969423370" private_port = 8080 public_port = 443 diff --git a/web/debug/posts.go b/web/debug/posts.go index 6e6470e..93c0b9d 100644 --- a/web/debug/posts.go +++ b/web/debug/posts.go @@ -11,6 +11,7 @@ import ( "github.com/rs/zerolog/hlog" "gorm.io/gorm" + "git.mstar.dev/mstar/linstrom/shared" "git.mstar.dev/mstar/linstrom/storage-new" "git.mstar.dev/mstar/linstrom/storage-new/dbgen" "git.mstar.dev/mstar/linstrom/storage-new/models" @@ -64,7 +65,7 @@ func postAs(w http.ResponseWriter, r *http.Request) { AccessLevel: models.NOTE_TARGET_PUBLIC, OriginId: 1, } - n.Select( + err = n.Select( n.CreatorId, n.RawContent, n.Remote, @@ -74,6 +75,26 @@ func postAs(w http.ResponseWriter, r *http.Request) { n.AccessLevel, n.OriginId, ).Create(¬e) + if err != nil { + log.Error(). + Err(err). + Str("username", data.Username). + Str("content", data.Content). + Msg("Failed to create message") + webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError) + return + } + activity := models.Activity{ + Id: shared.NewId(), + Type: string(models.ActivityCreate), + ObjectId: note.ID, + ObjectType: uint32(models.ActivitystreamsActivityTargetNote), + } + a := dbgen.Activity + err = a.Create(&activity) + if err != nil { + log.Error().Err(err).Msg("Failed to create activity for new note") + } } func notesFrom(w http.ResponseWriter, r *http.Request) { diff --git a/web/public/api/activitypub/activityCreate.go b/web/public/api/activitypub/activityCreate.go index 365ee8c..2285e24 100644 --- a/web/public/api/activitypub/activityCreate.go +++ b/web/public/api/activitypub/activityCreate.go @@ -58,9 +58,9 @@ func activityCreate(w http.ResponseWriter, r *http.Request) { // getting the final result func createFromStorage(ctx context.Context, id string) (*activityCreateOut, error) { // log := log.Ctx(ctx) - asa := dbgen.ActivitystreamsActivity - activity, err := asa.Where(asa.Type.Eq(string(models.ActivityCreate))). - Where(asa.Id.Eq(id)). + a := dbgen.Activity + activity, err := a.Where(a.Type.Eq(string(models.ActivityCreate))). + Where(a.Id.Eq(id)). First() if err != nil { return nil, err