Add follower and following collections
All checks were successful
/ docker (push) Successful in 4m34s

This commit is contained in:
Melody Becker 2025-05-11 18:28:51 +02:00
parent b75db5676b
commit af6ff2dd30
Signed by: mstar
SSH key fingerprint: SHA256:vkXfS9FG2pVNVfvDrzd1VW9n8VJzqqdKQGljxxX8uK8
11 changed files with 431 additions and 22 deletions

View file

@ -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())
}