domain blocking more work

This commit is contained in:
tsmethurst 2021-06-30 12:02:28 +02:00
commit 99eb3bf564
11 changed files with 160 additions and 58 deletions

View file

@ -2,6 +2,7 @@ package visibility
import (
"errors"
"net/url"
"fmt"
@ -16,6 +17,15 @@ func (f *filter) StatusVisible(targetStatus *gtsmodel.Status, requestingAccount
"statusID": targetStatus.ID,
})
uri, err := url.Parse(targetStatus.URI)
if err != nil {
return false, fmt.Errorf("StatusVisible: error parsing uri: %s", targetStatus.URI)
}
if blocked, err := f.blockedDomain(uri.Host); blocked || err != nil {
l.Debugf("domain %s is blocked", uri.Host)
return blocked, err
}
aaaaaaaaaa
relevantAccounts, err := f.pullRelevantAccountsFromStatus(targetStatus)
if err != nil {
l.Debugf("error pulling relevant accounts for status %s: %s", targetStatus.ID, err)

View file

@ -3,6 +3,7 @@ package visibility
import (
"fmt"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
@ -79,3 +80,20 @@ type relevantAccounts struct {
BoostedReplyToAccount *gtsmodel.Account
MentionedAccounts []*gtsmodel.Account
}
func (f *filter) blockedDomain(host string) (bool, error) {
b := &gtsmodel.DomainBlock{}
err := f.db.GetWhere([]db.Where{{Key: "domain", Value: host, CaseInsensitive: true}}, b)
if err == nil {
// block exists
return true, nil
}
if _, ok := err.(db.ErrNoEntries); ok {
// there are no entries so there's no block
return false, nil
}
// there's an actual error
return false, err
}