mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-24 01:23:32 -06:00
Block/unblock (#96)
* remote + local block logic, incl. federation * improve blocking stuff * fiddle with display of blocked profiles * go fmt
This commit is contained in:
parent
c7da64922f
commit
846057f0d6
45 changed files with 1405 additions and 63 deletions
|
|
@ -39,16 +39,15 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
|
|||
"id": id.String(),
|
||||
},
|
||||
)
|
||||
l.Debugf("entering OWNS function with id %s", id.String())
|
||||
l.Tracef("entering OWNS function with id %s", id.String())
|
||||
|
||||
// if the id host isn't this instance host, we don't own this IRI
|
||||
if id.Host != f.config.Host {
|
||||
l.Debugf("we DO NOT own activity because the host is %s not %s", id.Host, f.config.Host)
|
||||
l.Tracef("we DO NOT own activity because the host is %s not %s", id.Host, f.config.Host)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// apparently it belongs to this host, so what *is* it?
|
||||
|
||||
// check if it's a status, eg /users/example_username/statuses/SOME_UUID_OF_A_STATUS
|
||||
if util.IsStatusesPath(id) {
|
||||
_, uid, err := util.ParseStatusesPath(id)
|
||||
|
|
@ -63,11 +62,10 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
|
|||
// an actual error happened
|
||||
return false, fmt.Errorf("database error fetching status with id %s: %s", uid, err)
|
||||
}
|
||||
l.Debug("we DO own this")
|
||||
l.Debugf("we own url %s", id.String())
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// check if it's a user, eg /users/example_username
|
||||
if util.IsUserPath(id) {
|
||||
username, err := util.ParseUserPath(id)
|
||||
if err != nil {
|
||||
|
|
@ -81,7 +79,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
|
|||
// an actual error happened
|
||||
return false, fmt.Errorf("database error fetching account with username %s: %s", username, err)
|
||||
}
|
||||
l.Debug("we DO own this")
|
||||
l.Debugf("we own url %s", id.String())
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
|
@ -98,7 +96,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
|
|||
// an actual error happened
|
||||
return false, fmt.Errorf("database error fetching account with username %s: %s", username, err)
|
||||
}
|
||||
l.Debug("we DO own this")
|
||||
l.Debugf("we own url %s", id.String())
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
|
@ -115,7 +113,57 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
|
|||
// an actual error happened
|
||||
return false, fmt.Errorf("database error fetching account with username %s: %s", username, err)
|
||||
}
|
||||
l.Debug("we DO own this")
|
||||
l.Debugf("we own url %s", id.String())
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if util.IsLikePath(id) {
|
||||
username, likeID, err := util.ParseLikedPath(id)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("error parsing like path for url %s: %s", id.String(), err)
|
||||
}
|
||||
if err := f.db.GetLocalAccountByUsername(username, >smodel.Account{}); err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); ok {
|
||||
// there are no entries for this username
|
||||
return false, nil
|
||||
}
|
||||
// an actual error happened
|
||||
return false, fmt.Errorf("database error fetching account with username %s: %s", username, err)
|
||||
}
|
||||
if err := f.db.GetByID(likeID, >smodel.StatusFave{}); err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); ok {
|
||||
// there are no entries
|
||||
return false, nil
|
||||
}
|
||||
// an actual error happened
|
||||
return false, fmt.Errorf("database error fetching like with id %s: %s", likeID, err)
|
||||
}
|
||||
l.Debugf("we own url %s", id.String())
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if util.IsBlockPath(id) {
|
||||
username, blockID, err := util.ParseBlockPath(id)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("error parsing block path for url %s: %s", id.String(), err)
|
||||
}
|
||||
if err := f.db.GetLocalAccountByUsername(username, >smodel.Account{}); err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); ok {
|
||||
// there are no entries for this username
|
||||
return false, nil
|
||||
}
|
||||
// an actual error happened
|
||||
return false, fmt.Errorf("database error fetching account with username %s: %s", username, err)
|
||||
}
|
||||
if err := f.db.GetByID(blockID, >smodel.Block{}); err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); ok {
|
||||
// there are no entries
|
||||
return false, nil
|
||||
}
|
||||
// an actual error happened
|
||||
return false, fmt.Errorf("database error fetching block with id %s: %s", blockID, err)
|
||||
}
|
||||
l.Debugf("we own url %s", id.String())
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue