Add placeholder user for events by unknown actors
This commit is contained in:
parent
db85e831d9
commit
b01f60d273
3 changed files with 82 additions and 1 deletions
4
main.go
4
main.go
|
@ -159,6 +159,10 @@ func newServer() {
|
||||||
if err = storagenew.InsertSelf(); err != nil {
|
if err = storagenew.InsertSelf(); err != nil {
|
||||||
log.Fatal().Err(err).Msg("Failed to insert self properly")
|
log.Fatal().Err(err).Msg("Failed to insert self properly")
|
||||||
}
|
}
|
||||||
|
log.Info().Msg("Inserting placeholder/unknown user")
|
||||||
|
if err = storagenew.InsertUnknownActorPlaceholder(); err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("Failed to insert self properly")
|
||||||
|
}
|
||||||
if *shared.FlagStartDebugServer {
|
if *shared.FlagStartDebugServer {
|
||||||
go func() {
|
go func() {
|
||||||
log.Info().Msg("Starting debug server")
|
log.Info().Msg("Starting debug server")
|
||||||
|
|
|
@ -9,5 +9,8 @@ const (
|
||||||
Version = "0.0.1 pre-alpha"
|
Version = "0.0.1 pre-alpha"
|
||||||
// Username for the server actor
|
// Username for the server actor
|
||||||
ServerActorName = "server.actor"
|
ServerActorName = "server.actor"
|
||||||
|
// Username for the placeholder actor where the actual actor is unknown
|
||||||
|
// Examples include likes, boosts and followers / following
|
||||||
|
UnknownActorName = "unknown.actor"
|
||||||
FeedUsernameSuffix = "-feed"
|
FeedUsernameSuffix = "-feed"
|
||||||
)
|
)
|
||||||
|
|
74
storage-new/unknown.go
Normal file
74
storage-new/unknown.go
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
package storage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"database/sql"
|
||||||
|
|
||||||
|
"git.mstar.dev/mstar/goutils/other"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"git.mstar.dev/mstar/linstrom/shared"
|
||||||
|
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
|
||||||
|
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
var UnknownActorId string
|
||||||
|
|
||||||
|
func InsertUnknownActorPlaceholder() error {
|
||||||
|
dbUser, err := dbgen.User.GetByUsername(shared.UnknownActorName)
|
||||||
|
if err == nil {
|
||||||
|
UnknownActorId = dbUser.ID
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err != gorm.ErrRecordNotFound {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
server, err := dbgen.RemoteServer.Where(dbgen.RemoteServer.IsSelf.Is(true)).First()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
publicEdKeyBytes, privateEdKeyBytes, err := shared.GenerateKeypair(true)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
publicRsaKeyBytes, privateRsaKeyBytes, err := shared.GenerateKeypair(false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
pkeyId := make([]byte, 64)
|
||||||
|
_, err = rand.Read(pkeyId)
|
||||||
|
if err != nil {
|
||||||
|
return other.Error(
|
||||||
|
"storage",
|
||||||
|
"failed to generate passkey ID for linstrom account",
|
||||||
|
err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
user := models.User{
|
||||||
|
ID: shared.NewId(),
|
||||||
|
Username: shared.UnknownActorName,
|
||||||
|
Server: *server,
|
||||||
|
ServerId: server.ID,
|
||||||
|
DisplayName: "Placeholder user",
|
||||||
|
Description: "Placeholder user for when the actual users are unknown, like with Mastodon likes and boosts",
|
||||||
|
IsBot: true,
|
||||||
|
IconId: sql.NullString{Valid: false},
|
||||||
|
Background: nil,
|
||||||
|
BackgroundId: sql.NullString{Valid: false},
|
||||||
|
Banner: nil,
|
||||||
|
BannerId: sql.NullString{Valid: false},
|
||||||
|
Indexable: false,
|
||||||
|
PublicKeyEd: publicEdKeyBytes,
|
||||||
|
PrivateKeyEd: privateEdKeyBytes,
|
||||||
|
PublicKeyRsa: publicRsaKeyBytes,
|
||||||
|
PrivateKeyRsa: privateRsaKeyBytes,
|
||||||
|
Verified: true,
|
||||||
|
FinishedRegistration: true,
|
||||||
|
PasskeyId: pkeyId,
|
||||||
|
}
|
||||||
|
err = dbgen.User.Save(&user)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in a new issue