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

@ -48,6 +48,10 @@ type TypeConverter interface {
// if something goes wrong. The returned account should be ready to serialize on an API level, and may NOT have sensitive fields.
// In other words, this is the public record that the server has of an account.
AccountToMastoPublic(account *gtsmodel.Account) (*model.Account, error)
// AccountToMastoBlocked takes a db model account as a param, and returns a mastotype account, or an error if
// something goes wrong. The returned account will be a bare minimum representation of the account. This function should be used
// when someone wants to view an account they've blocked.
AccountToMastoBlocked(account *gtsmodel.Account) (*model.Account, error)
// AppToMastoSensitive takes a db model application as a param, and returns a populated mastotype application, or an error
// if something goes wrong. The returned application should be ready to serialize on an API level, and may have sensitive fields
// (such as client id and client secret), so serve it only to an authorized user who should have permission to see it.

View file

@ -67,6 +67,7 @@ func (c *converter) StatusToBoost(s *gtsmodel.Status, boostingAccount *gtsmodel.
Language: s.Language,
Text: s.Text,
BoostOfID: s.ID,
BoostOfAccountID: s.AccountID,
Visibility: s.Visibility,
VisibilityAdvanced: s.VisibilityAdvanced,

View file

@ -173,6 +173,27 @@ func (c *converter) AccountToMastoPublic(a *gtsmodel.Account) (*model.Account, e
}, nil
}
func (c *converter) AccountToMastoBlocked(a *gtsmodel.Account) (*model.Account, error) {
var acct string
if a.Domain != "" {
// this is a remote user
acct = fmt.Sprintf("%s@%s", a.Username, a.Domain)
} else {
// this is a local user
acct = a.Username
}
return &model.Account{
ID: a.ID,
Username: a.Username,
Acct: acct,
DisplayName: a.Username,
Bot: a.Bot,
CreatedAt: a.CreatedAt.Format(time.RFC3339),
URL: a.URL,
}, nil
}
func (c *converter) AppToMastoSensitive(a *gtsmodel.Application) (*model.Application, error) {
return &model.Application{
ID: a.ID,