Add func to add ap links to local users (untested)
All checks were successful
/ docker (push) Successful in 4m27s
All checks were successful
/ docker (push) Successful in 4m27s
This commit is contained in:
parent
e69f53bbd7
commit
f991a1f353
7 changed files with 84 additions and 22 deletions
55
storage-new/genLinksForUser.go
Normal file
55
storage-new/genLinksForUser.go
Normal file
|
@ -0,0 +1,55 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"strings"
|
||||
|
||||
"git.mstar.dev/mstar/goutils/other"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"git.mstar.dev/mstar/linstrom/activitypub"
|
||||
"git.mstar.dev/mstar/linstrom/config"
|
||||
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
|
||||
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
||||
)
|
||||
|
||||
func EnsureLocalUserIdHasLinks(id string) error {
|
||||
if strings.HasPrefix(id, "http") {
|
||||
return nil
|
||||
}
|
||||
u := dbgen.User
|
||||
user, err := u.Where(u.ID.Eq(id)).Preload(u.RemoteInfo).First()
|
||||
switch err {
|
||||
case gorm.ErrRecordNotFound:
|
||||
return nil
|
||||
case nil:
|
||||
default:
|
||||
return other.Error("storage", "Failed to get user by id", err)
|
||||
}
|
||||
if user.RemoteInfo != nil {
|
||||
return nil
|
||||
}
|
||||
apId := activitypub.UserIdToApUrl(id)
|
||||
info := models.UserRemoteLinks{
|
||||
UserId: id,
|
||||
ApLink: apId,
|
||||
InboxLink: apId + "/inbox",
|
||||
ViewLink: sql.NullString{
|
||||
Valid: true,
|
||||
String: config.GlobalConfig.General.GetFullPublicUrl() + "/user/" + user.Username,
|
||||
},
|
||||
FollowersLink: sql.NullString{
|
||||
Valid: true,
|
||||
String: apId + "/followers",
|
||||
},
|
||||
FollowingLink: sql.NullString{
|
||||
Valid: true,
|
||||
String: apId + "/following",
|
||||
},
|
||||
}
|
||||
err = dbgen.UserRemoteLinks.Create(&info)
|
||||
if err != nil {
|
||||
return other.Error("storage", "Failed to store links for account", err)
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -33,6 +33,9 @@ func InsertSelf() error {
|
|||
if err != nil {
|
||||
return other.Error("storage", "failed to save/update self user", err)
|
||||
}
|
||||
if err = EnsureLocalUserIdHasLinks(user.ID); err != nil {
|
||||
return other.Error("storage", "failed to create ap links for self", err)
|
||||
}
|
||||
ServerActorId = user.ID
|
||||
if err = insertUserPronoun(user); err != nil {
|
||||
return other.Error("storage", "failed to save/update self user pronoun", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue