improve blocking stuff

This commit is contained in:
tsmethurst 2021-07-11 13:40:48 +02:00
commit f4dc4d0aa0
19 changed files with 270 additions and 22 deletions

View file

@ -45,9 +45,19 @@ func (p *processor) Get(requestingAccount *gtsmodel.Account, targetAccountID str
p.log.WithField("func", "AccountGet").Debugf("dereferencing account: %s", err)
}
var mastoAccount *apimodel.Account
var blocked bool
var err error
if requestingAccount != nil && targetAccount.ID == requestingAccount.ID {
if requestingAccount != nil {
blocked, err = p.db.Blocked(requestingAccount.ID, targetAccountID)
if err != nil {
return nil, fmt.Errorf("error checking account block: %s", err)
}
}
var mastoAccount *apimodel.Account
if blocked {
mastoAccount, err = p.tc.AccountToMastoBlocked(targetAccount)
} else if requestingAccount != nil && targetAccount.ID == requestingAccount.ID {
mastoAccount, err = p.tc.AccountToMastoSensitive(targetAccount)
} else {
mastoAccount, err = p.tc.AccountToMastoPublic(targetAccount)

View file

@ -43,7 +43,7 @@ func (p *processor) BlocksGet(authed *oauth.Auth, maxID string, sinceID string,
apiAccounts := []*apimodel.Account{}
for _, a := range accounts {
apiAccount, err := p.tc.AccountToMastoPublic(a)
apiAccount, err := p.tc.AccountToMastoBlocked(a)
if err != nil {
continue
}

View file

@ -99,7 +99,14 @@ func (p *processor) processFromClientAPI(clientMsg gtsmodel.FromClientAPI) error
return errors.New("block was not parseable as *gtsmodel.Block")
}
// TODO: remove any of the blocking account's statuses from the blocked account's timeline
// remove any of the blocking account's statuses from the blocked account's timeline, and vice versa
if err := p.timelineManager.WipeStatusesFromAccountID(block.AccountID, block.TargetAccountID); err != nil {
return err
}
if err := p.timelineManager.WipeStatusesFromAccountID(block.TargetAccountID, block.AccountID); err != nil {
return err
}
// TODO: same with notifications
// TODO: same with bookmarks

View file

@ -129,8 +129,18 @@ func (p *processor) processFromFederator(federatorMsg gtsmodel.FromFederator) er
}
case gtsmodel.ActivityStreamsBlock:
// CREATE A BLOCK
block, ok := federatorMsg.GTSModel.(*gtsmodel.Block)
if !ok {
return errors.New("block was not parseable as *gtsmodel.Block")
}
// TODO: remove any of the blocking account's statuses from the blocked account's timeline
// remove any of the blocking account's statuses from the blocked account's timeline, and vice versa
if err := p.timelineManager.WipeStatusesFromAccountID(block.AccountID, block.TargetAccountID); err != nil {
return err
}
if err := p.timelineManager.WipeStatusesFromAccountID(block.TargetAccountID, block.AccountID); err != nil {
return err
}
// TODO: same with notifications
// TODO: same with bookmarks
}