Feed insertions and other feed stuff
This commit is contained in:
parent
72e1c67488
commit
5232bb0741
7 changed files with 134 additions and 8 deletions
|
@ -594,6 +594,7 @@ type IUserToUserRelationDo interface {
|
|||
GetFollowingApLinksPagedForId(id string, page int) (result []string, err error)
|
||||
CountFollowersForId(id string) (result int, err error)
|
||||
CountFollowingForId(id string) (result int, err error)
|
||||
GetLocalFollowerIdsOfId(id string) (result []string, err error)
|
||||
}
|
||||
|
||||
// Get all inbox links for accounts following the user with the specified id
|
||||
|
@ -720,6 +721,34 @@ func (u userToUserRelationDo) CountFollowingForId(id string) (result int, err er
|
|||
return
|
||||
}
|
||||
|
||||
// Get the ids of all local accounts following the user with the target id
|
||||
//
|
||||
// SELECT
|
||||
// r.user_id
|
||||
// FROM
|
||||
//
|
||||
// user_to_user_relations r
|
||||
// LEFT JOIN users u ON r.user_id = u.id
|
||||
// LEFT JOIN remote_servers s ON u.server_id = s.id
|
||||
//
|
||||
// WHERE
|
||||
//
|
||||
// s.is_self = true
|
||||
// AND r.target_user_id = @id;
|
||||
func (u userToUserRelationDo) GetLocalFollowerIdsOfId(id string) (result []string, err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, id)
|
||||
generateSQL.WriteString("SELECT r.user_id FROM user_to_user_relations r LEFT JOIN users u ON r.user_id = u.id LEFT JOIN remote_servers s ON u.server_id = s.id WHERE s.is_self = true AND r.target_user_id = ?; ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = u.UnderlyingDB().Raw(generateSQL.String(), params...).Find(&result) // ignore_security_alert
|
||||
err = executeSQL.Error
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (u userToUserRelationDo) Debug() IUserToUserRelationDo {
|
||||
return u.withDO(u.DO.Debug())
|
||||
}
|
||||
|
|
|
@ -34,3 +34,4 @@ type Feed struct {
|
|||
|
||||
// Suffix added to feeds created as the default feed for a user
|
||||
const FeedDefaultSuffix = "-default"
|
||||
const GlobalFeedName = "global"
|
||||
|
|
|
@ -71,4 +71,17 @@ type IUserToUserRelation interface {
|
|||
// r.user_id = @id AND
|
||||
// r.relation = 'follow'
|
||||
CountFollowingForId(id string) (int, error)
|
||||
|
||||
// Get the ids of all local accounts following the user with the target id
|
||||
//
|
||||
// SELECT
|
||||
// r.user_id
|
||||
// FROM
|
||||
// user_to_user_relations r
|
||||
// LEFT JOIN users u ON r.user_id = u.id
|
||||
// LEFT JOIN remote_servers s ON u.server_id = s.id
|
||||
// WHERE
|
||||
// s.is_self = true
|
||||
// AND r.target_user_id = @id;
|
||||
GetLocalFollowerIdsOfId(id string) ([]string, error)
|
||||
}
|
||||
|
|
|
@ -43,6 +43,9 @@ func InsertSelf() error {
|
|||
if err = attachUserToRole(user); err != nil {
|
||||
return other.Error("storage", "failed to save/update self user to full admin role", err)
|
||||
}
|
||||
if err = insertGlobalFeed(user); err != nil {
|
||||
return other.Error("storage", "failed to ensure that the global feed exists", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -215,3 +218,26 @@ func attachUserToRole(user *models.User) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertGlobalFeed(serverActor *models.User) error {
|
||||
globalFeed, err := dbgen.Feed.Where(dbgen.Feed.Name.Eq(models.GlobalFeedName)).First()
|
||||
switch err {
|
||||
case nil:
|
||||
return nil
|
||||
case gorm.ErrRecordNotFound:
|
||||
globalFeed = &models.Feed{
|
||||
Owner: *serverActor,
|
||||
OwnerId: serverActor.ID,
|
||||
IsDefault: true,
|
||||
Name: models.GlobalFeedName,
|
||||
PublicKey: sql.NullString{Valid: false},
|
||||
}
|
||||
err = dbgen.Feed.Create(globalFeed)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue