Add follower and following collections
All checks were successful
/ docker (push) Successful in 4m34s
All checks were successful
/ docker (push) Successful in 4m34s
This commit is contained in:
parent
b75db5676b
commit
af6ff2dd30
11 changed files with 431 additions and 22 deletions
|
@ -589,9 +589,15 @@ type IUserToUserRelationDo interface {
|
|||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
|
||||
GetFollowersForId(id string) (result []string, err error)
|
||||
GetFollowerInboxesForId(id string) (result []string, err error)
|
||||
GetFollowerApLinksPagedForId(id string, page int) (result []string, err error)
|
||||
GetFollowingApLinksPagedForId(id string, page int) (result []string, err error)
|
||||
CountFollowersForId(id string) (result int, err error)
|
||||
CountFollowingForId(id string) (result int, err error)
|
||||
}
|
||||
|
||||
// Get all inbox links for accounts following the user with the specified id
|
||||
//
|
||||
// SELECT u.inbox_link
|
||||
// FROM user_to_user_relations r
|
||||
// LEFT JOIN user_remote_links u
|
||||
|
@ -600,7 +606,7 @@ type IUserToUserRelationDo interface {
|
|||
//
|
||||
// r.target_user_id = @id AND
|
||||
// r.relation = 'follow'
|
||||
func (u userToUserRelationDo) GetFollowersForId(id string) (result []string, err error) {
|
||||
func (u userToUserRelationDo) GetFollowerInboxesForId(id string) (result []string, err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
|
@ -614,6 +620,106 @@ func (u userToUserRelationDo) GetFollowersForId(id string) (result []string, err
|
|||
return
|
||||
}
|
||||
|
||||
// Get all Ids of the accounts following the user with the specified id
|
||||
//
|
||||
// SELECT u.ap_link
|
||||
// FROM user_to_user_relations r
|
||||
// LEFT JOIN user_remote_links u
|
||||
// ON r.user_id = u.user_id
|
||||
// WHERE
|
||||
//
|
||||
// r.target_user_id = @id AND
|
||||
// r.relation = 'follow'
|
||||
//
|
||||
// LIMIT 50
|
||||
// OFFSET @page * 50
|
||||
func (u userToUserRelationDo) GetFollowerApLinksPagedForId(id string, page int) (result []string, err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, id)
|
||||
params = append(params, page)
|
||||
generateSQL.WriteString("SELECT u.ap_link FROM user_to_user_relations r LEFT JOIN user_remote_links u ON r.user_id = u.user_id WHERE r.target_user_id = ? AND r.relation = 'follow' LIMIT 50 OFFSET ? * 50 ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = u.UnderlyingDB().Raw(generateSQL.String(), params...).Find(&result) // ignore_security_alert
|
||||
err = executeSQL.Error
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Get all Ids of the accounts followed by the user with the specified id
|
||||
//
|
||||
// SELECT u.ap_link
|
||||
// FROM user_to_user_relations r
|
||||
// LEFT JOIN user_remote_links u
|
||||
// ON r.user_id = u.user_id
|
||||
// WHERE
|
||||
//
|
||||
// r.user_id = @id AND
|
||||
// r.relation = 'follow'
|
||||
//
|
||||
// LIMIT 50
|
||||
// OFFSET @page * 50
|
||||
func (u userToUserRelationDo) GetFollowingApLinksPagedForId(id string, page int) (result []string, err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, id)
|
||||
params = append(params, page)
|
||||
generateSQL.WriteString("SELECT u.ap_link FROM user_to_user_relations r LEFT JOIN user_remote_links u ON r.user_id = u.user_id WHERE r.user_id = ? AND r.relation = 'follow' LIMIT 50 OFFSET ? * 50 ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = u.UnderlyingDB().Raw(generateSQL.String(), params...).Find(&result) // ignore_security_alert
|
||||
err = executeSQL.Error
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Count the accounts following the user with the specified id
|
||||
//
|
||||
// SELECT COUNT(*)
|
||||
// FROM user_to_user_relations r
|
||||
// WHERE
|
||||
//
|
||||
// r.target_user_id = @id AND
|
||||
// r.relation = 'follow'
|
||||
func (u userToUserRelationDo) CountFollowersForId(id string) (result int, err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, id)
|
||||
generateSQL.WriteString("SELECT COUNT(*) FROM user_to_user_relations r WHERE r.target_user_id = ? AND r.relation = 'follow' ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = u.UnderlyingDB().Raw(generateSQL.String(), params...).Take(&result) // ignore_security_alert
|
||||
err = executeSQL.Error
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Count the accounts following the user with the specified id
|
||||
//
|
||||
// SELECT COUNT(*)
|
||||
// FROM user_to_user_relations r
|
||||
// WHERE
|
||||
//
|
||||
// r.user_id = @id AND
|
||||
// r.relation = 'follow'
|
||||
func (u userToUserRelationDo) CountFollowingForId(id string) (result int, err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, id)
|
||||
generateSQL.WriteString("SELECT COUNT(*) FROM user_to_user_relations r WHERE r.user_id = ? AND r.relation = 'follow' ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = u.UnderlyingDB().Raw(generateSQL.String(), params...).Take(&result) // ignore_security_alert
|
||||
err = executeSQL.Error
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (u userToUserRelationDo) Debug() IUserToUserRelationDo {
|
||||
return u.withDO(u.DO.Debug())
|
||||
}
|
||||
|
|
|
@ -1660,11 +1660,13 @@ type IUserDo interface {
|
|||
|
||||
GetByUsernameUnrestricted(username string) (result *models.User, err error)
|
||||
GetByUsername(username string) (result *models.User, err error)
|
||||
GetById(id string) (result *models.User, err error)
|
||||
GetPagedTruePublic(pageNr uint) (result []models.User, err error)
|
||||
GetPagedAllDeleted(pageNr uint) (result []models.User, err error)
|
||||
GetPagedAllNonDeleted(pageNr uint) (result []models.User, err error)
|
||||
GdprUsers() (err error)
|
||||
GetRemoteAccountByApUrl(url string) (result *models.User, err error)
|
||||
DoesUserWithIdExist(id string) (result bool, err error)
|
||||
}
|
||||
|
||||
// Get a user by a username, ignoring all restrictions on that user
|
||||
|
@ -1709,6 +1711,31 @@ func (u userDo) GetByUsername(username string) (result *models.User, err error)
|
|||
return
|
||||
}
|
||||
|
||||
// Get a user by the id.
|
||||
// Restricted to users visible to ActivityPub
|
||||
//
|
||||
// SELECT * FROM @@table WHERE
|
||||
//
|
||||
// id = @id AND
|
||||
// deleted_at IS NULL AND
|
||||
// finished_registration = true AND
|
||||
// verified = true
|
||||
//
|
||||
// LIMIT 1
|
||||
func (u userDo) GetById(id string) (result *models.User, err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, id)
|
||||
generateSQL.WriteString("SELECT * FROM users WHERE id = ? AND deleted_at IS NULL AND finished_registration = true AND verified = true LIMIT 1 ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = u.UnderlyingDB().Raw(generateSQL.String(), params...).Take(&result) // ignore_security_alert
|
||||
err = executeSQL.Error
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Get all true public accounts (verified & no restricted follow & indexable)
|
||||
// in a paged manner, sorted by date saved
|
||||
//
|
||||
|
@ -1820,6 +1847,31 @@ func (u userDo) GetRemoteAccountByApUrl(url string) (result *models.User, err er
|
|||
return
|
||||
}
|
||||
|
||||
// Does a user with the given Id exist?
|
||||
// The user must be visible from AP
|
||||
//
|
||||
// SELECT EXISTS(
|
||||
//
|
||||
// SELECT * FROM @@table WHERE
|
||||
// id = @id AND
|
||||
// deleted_at IS NULL AND
|
||||
// verified = true
|
||||
//
|
||||
// )
|
||||
func (u userDo) DoesUserWithIdExist(id string) (result bool, err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, id)
|
||||
generateSQL.WriteString("SELECT EXISTS( SELECT * FROM users WHERE id = ? AND deleted_at IS NULL AND verified = true ) ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = u.UnderlyingDB().Raw(generateSQL.String(), params...).Take(&result) // ignore_security_alert
|
||||
err = executeSQL.Error
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (u userDo) Debug() IUserDo {
|
||||
return u.withDO(u.DO.Debug())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue