mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-18 10:47:29 -06:00
Merge branch 'superseriousbusiness:main' into add-rollback-command
This commit is contained in:
commit
c3ec3cda77
1025 changed files with 195758 additions and 139263 deletions
|
|
@ -48,6 +48,9 @@ type Application interface {
|
|||
// GetAllTokens ...
|
||||
GetAllTokens(ctx context.Context) ([]*gtsmodel.Token, error)
|
||||
|
||||
// GetTokenByID ...
|
||||
GetTokenByID(ctx context.Context, id string) (*gtsmodel.Token, error)
|
||||
|
||||
// GetTokenByCode ...
|
||||
GetTokenByCode(ctx context.Context, code string) (*gtsmodel.Token, error)
|
||||
|
||||
|
|
|
|||
|
|
@ -137,8 +137,9 @@ func (a *accountDB) GetAccountByURL(ctx context.Context, url string) (*gtsmodel.
|
|||
|
||||
func (a *accountDB) GetAccountByUsernameDomain(ctx context.Context, username string, domain string) (*gtsmodel.Account, error) {
|
||||
if domain != "" {
|
||||
// Normalize the domain as punycode
|
||||
var err error
|
||||
|
||||
// Normalize the domain as punycode
|
||||
domain, err = util.Punify(domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -174,6 +174,16 @@ func (a *applicationDB) GetAllTokens(ctx context.Context) ([]*gtsmodel.Token, er
|
|||
return tokens, nil
|
||||
}
|
||||
|
||||
func (a *applicationDB) GetTokenByID(ctx context.Context, code string) (*gtsmodel.Token, error) {
|
||||
return a.getTokenBy(
|
||||
"ID",
|
||||
func(t *gtsmodel.Token) error {
|
||||
return a.db.NewSelect().Model(t).Where("? = ?", bun.Ident("id"), code).Scan(ctx)
|
||||
},
|
||||
code,
|
||||
)
|
||||
}
|
||||
|
||||
func (a *applicationDB) GetTokenByCode(ctx context.Context, code string) (*gtsmodel.Token, error) {
|
||||
return a.getTokenBy(
|
||||
"Code",
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ type DBService struct {
|
|||
db.Timeline
|
||||
db.User
|
||||
db.Tombstone
|
||||
db.WebPush
|
||||
db.WorkerTask
|
||||
db *bun.DB
|
||||
}
|
||||
|
|
@ -344,6 +345,10 @@ func NewBunDBService(ctx context.Context, state *state.State) (db.DB, error) {
|
|||
db: db,
|
||||
state: state,
|
||||
},
|
||||
WebPush: &webPushDB{
|
||||
db: db,
|
||||
state: state,
|
||||
},
|
||||
WorkerTask: &workerTaskDB{
|
||||
db: db,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -36,12 +36,12 @@ type domainDB struct {
|
|||
state *state.State
|
||||
}
|
||||
|
||||
func (d *domainDB) CreateDomainAllow(ctx context.Context, allow *gtsmodel.DomainAllow) error {
|
||||
// Normalize the domain as punycode
|
||||
var err error
|
||||
allow.Domain, err = util.Punify(allow.Domain)
|
||||
func (d *domainDB) CreateDomainAllow(ctx context.Context, allow *gtsmodel.DomainAllow) (err error) {
|
||||
// Normalize the domain as punycode, note the extra
|
||||
// validation step for domain name write operations.
|
||||
allow.Domain, err = util.PunifySafely(allow.Domain)
|
||||
if err != nil {
|
||||
return err
|
||||
return gtserror.Newf("error punifying domain %s: %w", allow.Domain, err)
|
||||
}
|
||||
|
||||
// Attempt to store domain allow in DB
|
||||
|
|
@ -58,10 +58,10 @@ func (d *domainDB) CreateDomainAllow(ctx context.Context, allow *gtsmodel.Domain
|
|||
}
|
||||
|
||||
func (d *domainDB) GetDomainAllow(ctx context.Context, domain string) (*gtsmodel.DomainAllow, error) {
|
||||
// Normalize the domain as punycode
|
||||
// Normalize domain as punycode for lookup.
|
||||
domain, err := util.Punify(domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, gtserror.Newf("error punifying domain %s: %w", domain, err)
|
||||
}
|
||||
|
||||
// Check for easy case, domain referencing *us*
|
||||
|
|
@ -111,12 +111,12 @@ func (d *domainDB) GetDomainAllowByID(ctx context.Context, id string) (*gtsmodel
|
|||
return &allow, nil
|
||||
}
|
||||
|
||||
func (d *domainDB) UpdateDomainAllow(ctx context.Context, allow *gtsmodel.DomainAllow, columns ...string) error {
|
||||
// Normalize the domain as punycode
|
||||
var err error
|
||||
allow.Domain, err = util.Punify(allow.Domain)
|
||||
func (d *domainDB) UpdateDomainAllow(ctx context.Context, allow *gtsmodel.DomainAllow, columns ...string) (err error) {
|
||||
// Normalize the domain as punycode, note the extra
|
||||
// validation step for domain name write operations.
|
||||
allow.Domain, err = util.PunifySafely(allow.Domain)
|
||||
if err != nil {
|
||||
return err
|
||||
return gtserror.Newf("error punifying domain %s: %w", allow.Domain, err)
|
||||
}
|
||||
|
||||
// Ensure updated_at is set.
|
||||
|
|
@ -142,10 +142,10 @@ func (d *domainDB) UpdateDomainAllow(ctx context.Context, allow *gtsmodel.Domain
|
|||
}
|
||||
|
||||
func (d *domainDB) DeleteDomainAllow(ctx context.Context, domain string) error {
|
||||
// Normalize the domain as punycode
|
||||
// Normalize domain as punycode for lookup.
|
||||
domain, err := util.Punify(domain)
|
||||
if err != nil {
|
||||
return err
|
||||
return gtserror.Newf("error punifying domain %s: %w", domain, err)
|
||||
}
|
||||
|
||||
// Attempt to delete domain allow
|
||||
|
|
@ -163,11 +163,13 @@ func (d *domainDB) DeleteDomainAllow(ctx context.Context, domain string) error {
|
|||
}
|
||||
|
||||
func (d *domainDB) CreateDomainBlock(ctx context.Context, block *gtsmodel.DomainBlock) error {
|
||||
// Normalize the domain as punycode
|
||||
var err error
|
||||
block.Domain, err = util.Punify(block.Domain)
|
||||
|
||||
// Normalize the domain as punycode, note the extra
|
||||
// validation step for domain name write operations.
|
||||
block.Domain, err = util.PunifySafely(block.Domain)
|
||||
if err != nil {
|
||||
return err
|
||||
return gtserror.Newf("error punifying domain %s: %w", block.Domain, err)
|
||||
}
|
||||
|
||||
// Attempt to store domain block in DB
|
||||
|
|
@ -184,10 +186,10 @@ func (d *domainDB) CreateDomainBlock(ctx context.Context, block *gtsmodel.Domain
|
|||
}
|
||||
|
||||
func (d *domainDB) GetDomainBlock(ctx context.Context, domain string) (*gtsmodel.DomainBlock, error) {
|
||||
// Normalize the domain as punycode
|
||||
// Normalize domain as punycode for lookup.
|
||||
domain, err := util.Punify(domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, gtserror.Newf("error punifying domain %s: %w", domain, err)
|
||||
}
|
||||
|
||||
// Check for easy case, domain referencing *us*
|
||||
|
|
@ -238,11 +240,13 @@ func (d *domainDB) GetDomainBlockByID(ctx context.Context, id string) (*gtsmodel
|
|||
}
|
||||
|
||||
func (d *domainDB) UpdateDomainBlock(ctx context.Context, block *gtsmodel.DomainBlock, columns ...string) error {
|
||||
// Normalize the domain as punycode
|
||||
var err error
|
||||
block.Domain, err = util.Punify(block.Domain)
|
||||
|
||||
// Normalize the domain as punycode, note the extra
|
||||
// validation step for domain name write operations.
|
||||
block.Domain, err = util.PunifySafely(block.Domain)
|
||||
if err != nil {
|
||||
return err
|
||||
return gtserror.Newf("error punifying domain %s: %w", block.Domain, err)
|
||||
}
|
||||
|
||||
// Ensure updated_at is set.
|
||||
|
|
@ -268,10 +272,10 @@ func (d *domainDB) UpdateDomainBlock(ctx context.Context, block *gtsmodel.Domain
|
|||
}
|
||||
|
||||
func (d *domainDB) DeleteDomainBlock(ctx context.Context, domain string) error {
|
||||
// Normalize the domain as punycode
|
||||
// Normalize domain as punycode for lookup.
|
||||
domain, err := util.Punify(domain)
|
||||
if err != nil {
|
||||
return err
|
||||
return gtserror.Newf("error punifying domain %s: %w", domain, err)
|
||||
}
|
||||
|
||||
// Attempt to delete domain block
|
||||
|
|
@ -289,10 +293,10 @@ func (d *domainDB) DeleteDomainBlock(ctx context.Context, domain string) error {
|
|||
}
|
||||
|
||||
func (d *domainDB) IsDomainBlocked(ctx context.Context, domain string) (bool, error) {
|
||||
// Normalize the domain as punycode
|
||||
// Normalize domain as punycode for lookup.
|
||||
domain, err := util.Punify(domain)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return false, gtserror.Newf("error punifying domain %s: %w", domain, err)
|
||||
}
|
||||
|
||||
// Domain referencing *us* cannot be blocked.
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ func (d *domainDB) GetDomainPermissionDrafts(
|
|||
if domain != "" {
|
||||
var err error
|
||||
|
||||
// Normalize domain as punycode.
|
||||
// Normalize domain as punycode for lookup.
|
||||
domain, err = util.Punify(domain)
|
||||
if err != nil {
|
||||
return nil, gtserror.Newf("error punifying domain %s: %w", domain, err)
|
||||
|
|
@ -234,22 +234,23 @@ func (d *domainDB) GetDomainPermissionDrafts(
|
|||
|
||||
func (d *domainDB) PutDomainPermissionDraft(
|
||||
ctx context.Context,
|
||||
permDraft *gtsmodel.DomainPermissionDraft,
|
||||
draft *gtsmodel.DomainPermissionDraft,
|
||||
) error {
|
||||
var err error
|
||||
|
||||
// Normalize the domain as punycode
|
||||
permDraft.Domain, err = util.Punify(permDraft.Domain)
|
||||
// Normalize the domain as punycode, note the extra
|
||||
// validation step for domain name write operations.
|
||||
draft.Domain, err = util.PunifySafely(draft.Domain)
|
||||
if err != nil {
|
||||
return gtserror.Newf("error punifying domain %s: %w", permDraft.Domain, err)
|
||||
return gtserror.Newf("error punifying domain %s: %w", draft.Domain, err)
|
||||
}
|
||||
|
||||
return d.state.Caches.DB.DomainPermissionDraft.Store(
|
||||
permDraft,
|
||||
draft,
|
||||
func() error {
|
||||
_, err := d.db.
|
||||
NewInsert().
|
||||
Model(permDraft).
|
||||
Model(draft).
|
||||
Exec(ctx)
|
||||
return err
|
||||
},
|
||||
|
|
|
|||
|
|
@ -37,11 +37,13 @@ func (d *domainDB) PutDomainPermissionExclude(
|
|||
ctx context.Context,
|
||||
exclude *gtsmodel.DomainPermissionExclude,
|
||||
) error {
|
||||
// Normalize the domain as punycode
|
||||
var err error
|
||||
exclude.Domain, err = util.Punify(exclude.Domain)
|
||||
|
||||
// Normalize the domain as punycode, note the extra
|
||||
// validation step for domain name write operations.
|
||||
exclude.Domain, err = util.PunifySafely(exclude.Domain)
|
||||
if err != nil {
|
||||
return err
|
||||
return gtserror.Newf("error punifying domain %s: %w", exclude.Domain, err)
|
||||
}
|
||||
|
||||
// Attempt to store domain perm exclude in DB
|
||||
|
|
@ -58,10 +60,10 @@ func (d *domainDB) PutDomainPermissionExclude(
|
|||
}
|
||||
|
||||
func (d *domainDB) IsDomainPermissionExcluded(ctx context.Context, domain string) (bool, error) {
|
||||
// Normalize the domain as punycode
|
||||
// Normalize domain as punycode for lookup.
|
||||
domain, err := util.Punify(domain)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return false, gtserror.Newf("error punifying domain %s: %w", domain, err)
|
||||
}
|
||||
|
||||
// Func to scan list of all
|
||||
|
|
@ -177,7 +179,7 @@ func (d *domainDB) GetDomainPermissionExcludes(
|
|||
if domain != "" {
|
||||
var err error
|
||||
|
||||
// Normalize domain as punycode.
|
||||
// Normalize domain as punycode for lookup.
|
||||
domain, err = util.Punify(domain)
|
||||
if err != nil {
|
||||
return nil, gtserror.Newf("error punifying domain %s: %w", domain, err)
|
||||
|
|
|
|||
354
internal/db/bundb/domainpermissionsubscription.go
Normal file
354
internal/db/bundb/domainpermissionsubscription.go
Normal file
|
|
@ -0,0 +1,354 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package bundb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"slices"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/paging"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
func (d *domainDB) getDomainPermissionSubscription(
|
||||
ctx context.Context,
|
||||
lookup string,
|
||||
dbQuery func(*gtsmodel.DomainPermissionSubscription) error,
|
||||
keyParts ...any,
|
||||
) (*gtsmodel.DomainPermissionSubscription, error) {
|
||||
// Fetch perm subscription from database cache with loader callback.
|
||||
permSub, err := d.state.Caches.DB.DomainPermissionSubscription.LoadOne(
|
||||
lookup,
|
||||
// Only called if not cached.
|
||||
func() (*gtsmodel.DomainPermissionSubscription, error) {
|
||||
var permSub gtsmodel.DomainPermissionSubscription
|
||||
if err := dbQuery(&permSub); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &permSub, nil
|
||||
},
|
||||
keyParts...,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if gtscontext.Barebones(ctx) {
|
||||
// No need to fully populate.
|
||||
return permSub, nil
|
||||
}
|
||||
|
||||
if permSub.CreatedByAccount == nil {
|
||||
// Not set, fetch from database.
|
||||
permSub.CreatedByAccount, err = d.state.DB.GetAccountByID(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
permSub.CreatedByAccountID,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, gtserror.Newf("error populating created by account: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return permSub, nil
|
||||
}
|
||||
|
||||
func (d *domainDB) GetDomainPermissionSubscriptionByID(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
) (*gtsmodel.DomainPermissionSubscription, error) {
|
||||
return d.getDomainPermissionSubscription(
|
||||
ctx,
|
||||
"ID",
|
||||
func(permSub *gtsmodel.DomainPermissionSubscription) error {
|
||||
return d.db.
|
||||
NewSelect().
|
||||
Model(permSub).
|
||||
Where("? = ?", bun.Ident("domain_permission_subscription.id"), id).
|
||||
Scan(ctx)
|
||||
},
|
||||
id,
|
||||
)
|
||||
}
|
||||
|
||||
func (d *domainDB) GetDomainPermissionSubscriptions(
|
||||
ctx context.Context,
|
||||
permType gtsmodel.DomainPermissionType,
|
||||
page *paging.Page,
|
||||
) (
|
||||
[]*gtsmodel.DomainPermissionSubscription,
|
||||
error,
|
||||
) {
|
||||
var (
|
||||
// Get paging params.
|
||||
minID = page.GetMin()
|
||||
maxID = page.GetMax()
|
||||
limit = page.GetLimit()
|
||||
order = page.GetOrder()
|
||||
|
||||
// Make educated guess for slice size
|
||||
permSubIDs = make([]string, 0, limit)
|
||||
)
|
||||
|
||||
q := d.db.
|
||||
NewSelect().
|
||||
TableExpr(
|
||||
"? AS ?",
|
||||
bun.Ident("domain_permission_subscriptions"),
|
||||
bun.Ident("domain_permission_subscription"),
|
||||
).
|
||||
// Select only IDs from table
|
||||
Column("domain_permission_subscription.id")
|
||||
|
||||
// Return only items with id
|
||||
// lower than provided maxID.
|
||||
if maxID != "" {
|
||||
q = q.Where(
|
||||
"? < ?",
|
||||
bun.Ident("domain_permission_subscription.id"),
|
||||
maxID,
|
||||
)
|
||||
}
|
||||
|
||||
// Return only items with id
|
||||
// greater than provided minID.
|
||||
if minID != "" {
|
||||
q = q.Where(
|
||||
"? > ?",
|
||||
bun.Ident("domain_permission_subscription.id"),
|
||||
minID,
|
||||
)
|
||||
}
|
||||
|
||||
// Return only items with
|
||||
// given permission type.
|
||||
if permType != gtsmodel.DomainPermissionUnknown {
|
||||
q = q.Where(
|
||||
"? = ?",
|
||||
bun.Ident("domain_permission_subscription.permission_type"),
|
||||
permType,
|
||||
)
|
||||
}
|
||||
|
||||
if limit > 0 {
|
||||
// Limit amount of
|
||||
// items returned.
|
||||
q = q.Limit(limit)
|
||||
}
|
||||
|
||||
if order == paging.OrderAscending {
|
||||
// Page up.
|
||||
q = q.OrderExpr(
|
||||
"? ASC",
|
||||
bun.Ident("domain_permission_subscription.id"),
|
||||
)
|
||||
} else {
|
||||
// Page down.
|
||||
q = q.OrderExpr(
|
||||
"? DESC",
|
||||
bun.Ident("domain_permission_subscription.id"),
|
||||
)
|
||||
}
|
||||
|
||||
if err := q.Scan(ctx, &permSubIDs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Catch case of no items early
|
||||
if len(permSubIDs) == 0 {
|
||||
return nil, db.ErrNoEntries
|
||||
}
|
||||
|
||||
// If we're paging up, we still want items
|
||||
// to be sorted by ID desc, so reverse slice.
|
||||
if order == paging.OrderAscending {
|
||||
slices.Reverse(permSubIDs)
|
||||
}
|
||||
|
||||
// Allocate return slice (will be at most len permSubIDs).
|
||||
permSubs := make([]*gtsmodel.DomainPermissionSubscription, 0, len(permSubIDs))
|
||||
for _, id := range permSubIDs {
|
||||
permSub, err := d.GetDomainPermissionSubscriptionByID(ctx, id)
|
||||
if err != nil {
|
||||
log.Errorf(ctx, "error getting domain permission subscription %q: %v", id, err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Append to return slice
|
||||
permSubs = append(permSubs, permSub)
|
||||
}
|
||||
|
||||
return permSubs, nil
|
||||
}
|
||||
|
||||
func (d *domainDB) GetDomainPermissionSubscriptionsByPriority(
|
||||
ctx context.Context,
|
||||
permType gtsmodel.DomainPermissionType,
|
||||
) (
|
||||
[]*gtsmodel.DomainPermissionSubscription,
|
||||
error,
|
||||
) {
|
||||
permSubIDs := []string{}
|
||||
|
||||
q := d.db.
|
||||
NewSelect().
|
||||
TableExpr(
|
||||
"? AS ?",
|
||||
bun.Ident("domain_permission_subscriptions"),
|
||||
bun.Ident("domain_permission_subscription"),
|
||||
).
|
||||
// Select only IDs from table
|
||||
Column("domain_permission_subscription.id").
|
||||
// Select only subs of given perm type.
|
||||
Where(
|
||||
"? = ?",
|
||||
bun.Ident("domain_permission_subscription.permission_type"),
|
||||
permType,
|
||||
).
|
||||
// Order by priority descending.
|
||||
OrderExpr(
|
||||
"? DESC",
|
||||
bun.Ident("domain_permission_subscription.priority"),
|
||||
)
|
||||
|
||||
if err := q.Scan(ctx, &permSubIDs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Catch case of no items early
|
||||
if len(permSubIDs) == 0 {
|
||||
return nil, db.ErrNoEntries
|
||||
}
|
||||
|
||||
// Allocate return slice (will be at most len permSubIDs).
|
||||
permSubs := make([]*gtsmodel.DomainPermissionSubscription, 0, len(permSubIDs))
|
||||
for _, id := range permSubIDs {
|
||||
permSub, err := d.GetDomainPermissionSubscriptionByID(ctx, id)
|
||||
if err != nil {
|
||||
log.Errorf(ctx, "error getting domain permission subscription %q: %v", id, err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Append to return slice
|
||||
permSubs = append(permSubs, permSub)
|
||||
}
|
||||
|
||||
return permSubs, nil
|
||||
}
|
||||
|
||||
func (d *domainDB) PutDomainPermissionSubscription(
|
||||
ctx context.Context,
|
||||
permSubscription *gtsmodel.DomainPermissionSubscription,
|
||||
) error {
|
||||
return d.state.Caches.DB.DomainPermissionSubscription.Store(
|
||||
permSubscription,
|
||||
func() error {
|
||||
_, err := d.db.
|
||||
NewInsert().
|
||||
Model(permSubscription).
|
||||
Exec(ctx)
|
||||
return err
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (d *domainDB) UpdateDomainPermissionSubscription(
|
||||
ctx context.Context,
|
||||
permSubscription *gtsmodel.DomainPermissionSubscription,
|
||||
columns ...string,
|
||||
) error {
|
||||
return d.state.Caches.DB.DomainPermissionSubscription.Store(
|
||||
permSubscription,
|
||||
func() error {
|
||||
_, err := d.db.
|
||||
NewUpdate().
|
||||
Model(permSubscription).
|
||||
Where("? = ?", bun.Ident("id"), permSubscription.ID).
|
||||
Column(columns...).
|
||||
Exec(ctx)
|
||||
return err
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (d *domainDB) DeleteDomainPermissionSubscription(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
) error {
|
||||
// Delete the permSub from DB.
|
||||
q := d.db.NewDelete().
|
||||
TableExpr(
|
||||
"? AS ?",
|
||||
bun.Ident("domain_permission_subscriptions"),
|
||||
bun.Ident("domain_permission_subscription"),
|
||||
).
|
||||
Where(
|
||||
"? = ?",
|
||||
bun.Ident("domain_permission_subscription.id"),
|
||||
id,
|
||||
)
|
||||
|
||||
_, err := q.Exec(ctx)
|
||||
if err != nil && !errors.Is(err, db.ErrNoEntries) {
|
||||
return err
|
||||
}
|
||||
|
||||
// Invalidate any cached model by ID.
|
||||
d.state.Caches.DB.DomainPermissionSubscription.Invalidate("ID", id)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *domainDB) CountDomainPermissionSubscriptionPerms(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
) (int, error) {
|
||||
permSubscription, err := d.GetDomainPermissionSubscriptionByID(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
id,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
q := d.db.NewSelect()
|
||||
|
||||
if permSubscription.PermissionType == gtsmodel.DomainPermissionBlock {
|
||||
q = q.TableExpr(
|
||||
"? AS ?",
|
||||
bun.Ident("domain_blocks"),
|
||||
bun.Ident("perm"),
|
||||
)
|
||||
} else {
|
||||
q = q.TableExpr(
|
||||
"? AS ?",
|
||||
bun.Ident("domain_allows"),
|
||||
bun.Ident("perm"),
|
||||
)
|
||||
}
|
||||
|
||||
return q.
|
||||
Column("perm.id").
|
||||
Where("? = ?", bun.Ident("perm.subscription_id"), id).
|
||||
Count(ctx)
|
||||
}
|
||||
99
internal/db/bundb/domainpermissionsubscription_test.go
Normal file
99
internal/db/bundb/domainpermissionsubscription_test.go
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package bundb_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
)
|
||||
|
||||
type DomainPermissionSubscriptionTestSuite struct {
|
||||
BunDBStandardTestSuite
|
||||
}
|
||||
|
||||
func (suite *DomainPermissionSubscriptionTestSuite) TestCount() {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
testAccount = suite.testAccounts["admin_account"]
|
||||
permSub = >smodel.DomainPermissionSubscription{
|
||||
ID: "01JGV3VZ72K58BYW8H5GEVBZGN",
|
||||
PermissionType: gtsmodel.DomainPermissionBlock,
|
||||
CreatedByAccountID: testAccount.ID,
|
||||
CreatedByAccount: testAccount,
|
||||
URI: "https://example.org/whatever.csv",
|
||||
ContentType: gtsmodel.DomainPermSubContentTypeCSV,
|
||||
}
|
||||
perms = []*gtsmodel.DomainBlock{
|
||||
{
|
||||
ID: "01JGV42G72YCKN06AC51RZPFES",
|
||||
Domain: "whatever.com",
|
||||
CreatedByAccountID: testAccount.ID,
|
||||
CreatedByAccount: testAccount,
|
||||
SubscriptionID: permSub.ID,
|
||||
},
|
||||
{
|
||||
ID: "01JGV43ZQKYPHM2M0YBQDFDSD1",
|
||||
Domain: "aaaa.example.org",
|
||||
CreatedByAccountID: testAccount.ID,
|
||||
CreatedByAccount: testAccount,
|
||||
SubscriptionID: permSub.ID,
|
||||
},
|
||||
{
|
||||
ID: "01JGV444KDDC4WFG6MZQVM0N2Z",
|
||||
Domain: "bbbb.example.org",
|
||||
CreatedByAccountID: testAccount.ID,
|
||||
CreatedByAccount: testAccount,
|
||||
SubscriptionID: permSub.ID,
|
||||
},
|
||||
{
|
||||
ID: "01JGV44AFEMBWS6P6S72BQK376",
|
||||
Domain: "cccc.example.org",
|
||||
CreatedByAccountID: testAccount.ID,
|
||||
CreatedByAccount: testAccount,
|
||||
SubscriptionID: permSub.ID,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// Whack the perm sub in the DB.
|
||||
if err := suite.state.DB.PutDomainPermissionSubscription(ctx, permSub); err != nil {
|
||||
suite.FailNow(err.Error())
|
||||
}
|
||||
|
||||
// Whack the perms in the db.
|
||||
for _, perm := range perms {
|
||||
if err := suite.state.DB.CreateDomainBlock(ctx, perm); err != nil {
|
||||
suite.FailNow(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// Count 'em.
|
||||
count, err := suite.state.DB.CountDomainPermissionSubscriptionPerms(ctx, permSub.ID)
|
||||
if err != nil {
|
||||
suite.FailNow(err.Error())
|
||||
}
|
||||
|
||||
suite.Equal(4, count)
|
||||
}
|
||||
|
||||
func TestDomainPermissionSubscriptionTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(DomainPermissionSubscriptionTestSuite))
|
||||
}
|
||||
|
|
@ -158,8 +158,9 @@ func (i *instanceDB) CountInstanceDomains(ctx context.Context, domain string) (i
|
|||
}
|
||||
|
||||
func (i *instanceDB) GetInstance(ctx context.Context, domain string) (*gtsmodel.Instance, error) {
|
||||
// Normalize the domain as punycode
|
||||
var err error
|
||||
|
||||
// Normalize the domain as punycode
|
||||
domain, err = util.Punify(domain)
|
||||
if err != nil {
|
||||
return nil, gtserror.Newf("error punifying domain %s: %w", domain, err)
|
||||
|
|
@ -265,8 +266,9 @@ func (i *instanceDB) PopulateInstance(ctx context.Context, instance *gtsmodel.In
|
|||
func (i *instanceDB) PutInstance(ctx context.Context, instance *gtsmodel.Instance) error {
|
||||
var err error
|
||||
|
||||
// Normalize the domain as punycode
|
||||
instance.Domain, err = util.Punify(instance.Domain)
|
||||
// Normalize the domain as punycode, note the extra
|
||||
// validation step for domain name write operations.
|
||||
instance.Domain, err = util.PunifySafely(instance.Domain)
|
||||
if err != nil {
|
||||
return gtserror.Newf("error punifying domain %s: %w", instance.Domain, err)
|
||||
}
|
||||
|
|
@ -279,9 +281,11 @@ func (i *instanceDB) PutInstance(ctx context.Context, instance *gtsmodel.Instanc
|
|||
}
|
||||
|
||||
func (i *instanceDB) UpdateInstance(ctx context.Context, instance *gtsmodel.Instance, columns ...string) error {
|
||||
// Normalize the domain as punycode
|
||||
var err error
|
||||
instance.Domain, err = util.Punify(instance.Domain)
|
||||
|
||||
// Normalize the domain as punycode, note the extra
|
||||
// validation step for domain name write operations.
|
||||
instance.Domain, err = util.PunifySafely(instance.Domain)
|
||||
if err != nil {
|
||||
return gtserror.Newf("error punifying domain %s: %w", instance.Domain, err)
|
||||
}
|
||||
|
|
@ -349,8 +353,9 @@ func (i *instanceDB) GetInstanceAccounts(ctx context.Context, domain string, max
|
|||
limit = 0
|
||||
}
|
||||
|
||||
// Normalize the domain as punycode.
|
||||
var err error
|
||||
|
||||
// Normalize the domain as punycode
|
||||
domain, err = util.Punify(domain)
|
||||
if err != nil {
|
||||
return nil, gtserror.Newf("error punifying domain %s: %w", domain, err)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ package migrations
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
gtsmodel "github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20241022153016_domain_permission_draft_exclude"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package gtsmodel
|
||||
|
||||
import "time"
|
||||
|
||||
type DomainPermissionDraft struct {
|
||||
ID string `bun:"type:CHAR(26),pk,nullzero,notnull,unique"`
|
||||
CreatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"`
|
||||
UpdatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"`
|
||||
PermissionType uint8 `bun:",notnull,unique:domain_permission_drafts_permission_type_domain_subscription_id_uniq"`
|
||||
Domain string `bun:",nullzero,notnull,unique:domain_permission_drafts_permission_type_domain_subscription_id_uniq"`
|
||||
CreatedByAccountID string `bun:"type:CHAR(26),nullzero,notnull"`
|
||||
PrivateComment string `bun:",nullzero"`
|
||||
PublicComment string `bun:",nullzero"`
|
||||
Obfuscate *bool `bun:",nullzero,notnull,default:false"`
|
||||
SubscriptionID string `bun:"type:CHAR(26),unique:domain_permission_drafts_permission_type_domain_subscription_id_uniq"`
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package gtsmodel
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type DomainPermissionExclude struct {
|
||||
ID string `bun:"type:CHAR(26),pk,nullzero,notnull,unique"`
|
||||
CreatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"`
|
||||
UpdatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"`
|
||||
Domain string `bun:",nullzero,notnull,unique"`
|
||||
CreatedByAccountID string `bun:"type:CHAR(26),nullzero,notnull"`
|
||||
PrivateComment string `bun:",nullzero"`
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package gtsmodel
|
||||
|
||||
import "time"
|
||||
|
||||
type DomainPermissionSubscription struct {
|
||||
ID string `bun:"type:CHAR(26),pk,nullzero,notnull,unique"`
|
||||
Priority uint8 `bun:""`
|
||||
Title string `bun:",nullzero,unique"`
|
||||
PermissionType uint8 `bun:",nullzero,notnull"`
|
||||
AsDraft *bool `bun:",nullzero,notnull,default:true"`
|
||||
AdoptOrphans *bool `bun:",nullzero,notnull,default:false"`
|
||||
CreatedByAccountID string `bun:"type:CHAR(26),nullzero,notnull"`
|
||||
URI string `bun:",nullzero,notnull,unique"`
|
||||
ContentType uint16 `bun:",nullzero,notnull"`
|
||||
FetchUsername string `bun:",nullzero"`
|
||||
FetchPassword string `bun:",nullzero"`
|
||||
FetchedAt time.Time `bun:"type:timestamptz,nullzero"`
|
||||
SuccessfullyFetchedAt time.Time `bun:"type:timestamptz,nullzero"`
|
||||
LastModified time.Time `bun:"type:timestamptz,nullzero"`
|
||||
ETag string `bun:"etag,nullzero"`
|
||||
Error string `bun:",nullzero"`
|
||||
}
|
||||
|
|
@ -149,10 +149,10 @@ func notificationEnumMapping[T ~string]() map[T]new_gtsmodel.NotificationType {
|
|||
T(old_gtsmodel.NotificationFollowRequest): new_gtsmodel.NotificationFollowRequest,
|
||||
T(old_gtsmodel.NotificationMention): new_gtsmodel.NotificationMention,
|
||||
T(old_gtsmodel.NotificationReblog): new_gtsmodel.NotificationReblog,
|
||||
T(old_gtsmodel.NotificationFave): new_gtsmodel.NotificationFave,
|
||||
T(old_gtsmodel.NotificationFave): new_gtsmodel.NotificationFavourite,
|
||||
T(old_gtsmodel.NotificationPoll): new_gtsmodel.NotificationPoll,
|
||||
T(old_gtsmodel.NotificationStatus): new_gtsmodel.NotificationStatus,
|
||||
T(old_gtsmodel.NotificationSignup): new_gtsmodel.NotificationSignup,
|
||||
T(old_gtsmodel.NotificationSignup): new_gtsmodel.NotificationAdminSignup,
|
||||
T(old_gtsmodel.NotificationPendingFave): new_gtsmodel.NotificationPendingFave,
|
||||
T(old_gtsmodel.NotificationPendingReply): new_gtsmodel.NotificationPendingReply,
|
||||
T(old_gtsmodel.NotificationPendingReblog): new_gtsmodel.NotificationPendingReblog,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
func init() {
|
||||
up := func(ctx context.Context, db *bun.DB) error {
|
||||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
if _, err := tx.
|
||||
NewCreateTable().
|
||||
Model(>smodel.VAPIDKeyPair{}).
|
||||
IfNotExists().
|
||||
Exec(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
down := func(ctx context.Context, db *bun.DB) error {
|
||||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
if err := Migrations.Register(up, down); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
func init() {
|
||||
up := func(ctx context.Context, db *bun.DB) error {
|
||||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
if _, err := tx.
|
||||
NewCreateTable().
|
||||
Model(>smodel.WebPushSubscription{}).
|
||||
IfNotExists().
|
||||
Exec(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := tx.
|
||||
NewCreateIndex().
|
||||
Model(>smodel.WebPushSubscription{}).
|
||||
Index("web_push_subscriptions_account_id_idx").
|
||||
Column("account_id").
|
||||
IfNotExists().
|
||||
Exec(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
down := func(ctx context.Context, db *bun.DB) error {
|
||||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
if err := Migrations.Register(up, down); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
oldmodel "github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20250106114512_replace_statuses_updatedat_with_editedat"
|
||||
newmodel "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||
"github.com/uptrace/bun"
|
||||
"github.com/uptrace/bun/dialect"
|
||||
)
|
||||
|
||||
func init() {
|
||||
up := func(ctx context.Context, db *bun.DB) error {
|
||||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
var newStatus *newmodel.Status
|
||||
newStatusType := reflect.TypeOf(newStatus)
|
||||
|
||||
// Generate new Status.EditedAt column definition from bun.
|
||||
colDef, err := getBunColumnDef(tx, newStatusType, "EditedAt")
|
||||
if err != nil {
|
||||
return fmt.Errorf("error making column def: %w", err)
|
||||
}
|
||||
|
||||
log.Info(ctx, "adding statuses.edited_at column...")
|
||||
_, err = tx.NewAddColumn().Model(newStatus).
|
||||
ColumnExpr(colDef).
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error adding column: %w", err)
|
||||
}
|
||||
|
||||
var whereSQL string
|
||||
var whereArg []any
|
||||
|
||||
// Check for an empty length
|
||||
// EditIDs JSON array, with different
|
||||
// SQL depending on connected database.
|
||||
switch tx.Dialect().Name() {
|
||||
case dialect.SQLite:
|
||||
whereSQL = "NOT (json_array_length(?) = 0 OR ? IS NULL)"
|
||||
whereArg = []any{bun.Ident("edits"), bun.Ident("edits")}
|
||||
case dialect.PG:
|
||||
whereSQL = "NOT (CARDINALITY(?) = 0 OR ? IS NULL)"
|
||||
whereArg = []any{bun.Ident("edits"), bun.Ident("edits")}
|
||||
default:
|
||||
panic("unsupported db type")
|
||||
}
|
||||
|
||||
log.Info(ctx, "setting edited_at = updated_at where not empty(edits)...")
|
||||
res, err := tx.NewUpdate().Model(newStatus).Where(whereSQL, whereArg...).
|
||||
Set("? = ?",
|
||||
bun.Ident("edited_at"),
|
||||
bun.Ident("updated_at"),
|
||||
).
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error updating columns: %w", err)
|
||||
}
|
||||
|
||||
count, _ := res.RowsAffected()
|
||||
log.Infof(ctx, "updated %d statuses", count)
|
||||
|
||||
log.Info(ctx, "removing statuses.updated_at column...")
|
||||
_, err = tx.NewDropColumn().Model((*oldmodel.Status)(nil)).
|
||||
Column("updated_at").
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error dropping column: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
down := func(ctx context.Context, db *bun.DB) error {
|
||||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
if err := Migrations.Register(up, down); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package gtsmodel
|
||||
|
||||
// A policy URI is GoToSocial's internal representation of
|
||||
// one ActivityPub URI for an Actor or a Collection of Actors,
|
||||
// specific to the domain of enforcing interaction policies.
|
||||
//
|
||||
// A PolicyValue can be stored in the database either as one
|
||||
// of the Value constants defined below (to save space), OR as
|
||||
// a full-fledged ActivityPub URI.
|
||||
//
|
||||
// A PolicyValue should be translated to the canonical string
|
||||
// value of the represented URI when federating an item, or
|
||||
// from the canonical string value of the URI when receiving
|
||||
// or retrieving an item.
|
||||
//
|
||||
// For example, if the PolicyValue `followers` was being
|
||||
// federated outwards in an interaction policy attached to an
|
||||
// item created by the actor `https://example.org/users/someone`,
|
||||
// then it should be translated to their followers URI when sent,
|
||||
// eg., `https://example.org/users/someone/followers`.
|
||||
//
|
||||
// Likewise, if GoToSocial receives an item with an interaction
|
||||
// policy containing `https://example.org/users/someone/followers`,
|
||||
// and the item was created by `https://example.org/users/someone`,
|
||||
// then the followers URI would be converted to `followers`
|
||||
// for internal storage.
|
||||
type PolicyValue string
|
||||
|
||||
const (
|
||||
// Stand-in for ActivityPub magic public URI,
|
||||
// which encompasses every possible Actor URI.
|
||||
PolicyValuePublic PolicyValue = "public"
|
||||
// Stand-in for the Followers Collection of
|
||||
// the item owner's Actor.
|
||||
PolicyValueFollowers PolicyValue = "followers"
|
||||
// Stand-in for the Following Collection of
|
||||
// the item owner's Actor.
|
||||
PolicyValueFollowing PolicyValue = "following"
|
||||
// Stand-in for the Mutuals Collection of
|
||||
// the item owner's Actor.
|
||||
//
|
||||
// (TODO: Reserved, currently unused).
|
||||
PolicyValueMutuals PolicyValue = "mutuals"
|
||||
// Stand-in for Actor URIs tagged in the item.
|
||||
PolicyValueMentioned PolicyValue = "mentioned"
|
||||
// Stand-in for the Actor URI of the item owner.
|
||||
PolicyValueAuthor PolicyValue = "author"
|
||||
)
|
||||
|
||||
type PolicyValues []PolicyValue
|
||||
|
||||
// An InteractionPolicy determines which
|
||||
// interactions will be accepted for an
|
||||
// item, and according to what rules.
|
||||
type InteractionPolicy struct {
|
||||
// Conditions in which a Like
|
||||
// interaction will be accepted
|
||||
// for an item with this policy.
|
||||
CanLike PolicyRules
|
||||
// Conditions in which a Reply
|
||||
// interaction will be accepted
|
||||
// for an item with this policy.
|
||||
CanReply PolicyRules
|
||||
// Conditions in which an Announce
|
||||
// interaction will be accepted
|
||||
// for an item with this policy.
|
||||
CanAnnounce PolicyRules
|
||||
}
|
||||
|
||||
// PolicyRules represents the rules according
|
||||
// to which a certain interaction is permitted
|
||||
// to various Actor and Actor Collection URIs.
|
||||
type PolicyRules struct {
|
||||
// Always is for PolicyValues who are
|
||||
// permitted to do an interaction
|
||||
// without requiring approval.
|
||||
Always PolicyValues
|
||||
// WithApproval is for PolicyValues who
|
||||
// are conditionally permitted to do
|
||||
// an interaction, pending approval.
|
||||
WithApproval PolicyValues
|
||||
}
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package gtsmodel
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Status represents a user-created 'post' or
|
||||
// 'status' in the database, either remote or local
|
||||
type Status struct {
|
||||
ID string `bun:"type:CHAR(26),pk,nullzero,notnull,unique"` // id of this item in the database
|
||||
CreatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"` // when was item created
|
||||
UpdatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"` // when was item last updated
|
||||
FetchedAt time.Time `bun:"type:timestamptz,nullzero"` // when was item (remote) last fetched.
|
||||
PinnedAt time.Time `bun:"type:timestamptz,nullzero"` // Status was pinned by owning account at this time.
|
||||
URI string `bun:",unique,nullzero,notnull"` // activitypub URI of this status
|
||||
URL string `bun:",nullzero"` // web url for viewing this status
|
||||
Content string `bun:""` // content of this status; likely html-formatted but not guaranteed
|
||||
AttachmentIDs []string `bun:"attachments,array"` // Database IDs of any media attachments associated with this status
|
||||
TagIDs []string `bun:"tags,array"` // Database IDs of any tags used in this status
|
||||
MentionIDs []string `bun:"mentions,array"` // Database IDs of any mentions in this status
|
||||
EmojiIDs []string `bun:"emojis,array"` // Database IDs of any emojis used in this status
|
||||
Local *bool `bun:",nullzero,notnull,default:false"` // is this status from a local account?
|
||||
AccountID string `bun:"type:CHAR(26),nullzero,notnull"` // which account posted this status?
|
||||
AccountURI string `bun:",nullzero,notnull"` // activitypub uri of the owner of this status
|
||||
InReplyToID string `bun:"type:CHAR(26),nullzero"` // id of the status this status replies to
|
||||
InReplyToURI string `bun:",nullzero"` // activitypub uri of the status this status is a reply to
|
||||
InReplyToAccountID string `bun:"type:CHAR(26),nullzero"` // id of the account that this status replies to
|
||||
InReplyTo *Status `bun:"-"` // status corresponding to inReplyToID
|
||||
BoostOfID string `bun:"type:CHAR(26),nullzero"` // id of the status this status is a boost of
|
||||
BoostOfURI string `bun:"-"` // URI of the status this status is a boost of; field not inserted in the db, just for dereferencing purposes.
|
||||
BoostOfAccountID string `bun:"type:CHAR(26),nullzero"` // id of the account that owns the boosted status
|
||||
BoostOf *Status `bun:"-"` // status that corresponds to boostOfID
|
||||
ThreadID string `bun:"type:CHAR(26),nullzero"` // id of the thread to which this status belongs; only set for remote statuses if a local account is involved at some point in the thread, otherwise null
|
||||
EditIDs []string `bun:"edits,array"` //
|
||||
PollID string `bun:"type:CHAR(26),nullzero"` //
|
||||
ContentWarning string `bun:",nullzero"` // cw string for this status
|
||||
Visibility Visibility `bun:",nullzero,notnull"` // visibility entry for this status
|
||||
Sensitive *bool `bun:",nullzero,notnull,default:false"` // mark the status as sensitive?
|
||||
Language string `bun:",nullzero"` // what language is this status written in?
|
||||
CreatedWithApplicationID string `bun:"type:CHAR(26),nullzero"` // Which application was used to create this status?
|
||||
ActivityStreamsType string `bun:",nullzero,notnull"` // What is the activitystreams type of this status? See: https://www.w3.org/TR/activitystreams-vocabulary/#object-types. Will probably almost always be Note but who knows!.
|
||||
Text string `bun:""` // Original text of the status without formatting
|
||||
Federated *bool `bun:",notnull"` // This status will be federated beyond the local timeline(s)
|
||||
InteractionPolicy *InteractionPolicy `bun:""` // InteractionPolicy for this status. If null then the default InteractionPolicy should be assumed for this status's Visibility. Always null for boost wrappers.
|
||||
PendingApproval *bool `bun:",nullzero,notnull,default:false"` // If true then status is a reply or boost wrapper that must be Approved by the reply-ee or boost-ee before being fully distributed.
|
||||
PreApproved bool `bun:"-"` // If true, then status is a reply to or boost wrapper of a status on our instance, has permission to do the interaction, and an Accept should be sent out for it immediately. Field not stored in the DB.
|
||||
ApprovedByURI string `bun:",nullzero"` // URI of an Accept Activity that approves the Announce or Create Activity that this status was/will be attached to.
|
||||
}
|
||||
|
||||
// GetID implements timeline.Timelineable{}.
|
||||
func (s *Status) GetID() string {
|
||||
return s.ID
|
||||
}
|
||||
|
||||
// IsLocal returns true if this is a local
|
||||
// status (ie., originating from this instance).
|
||||
func (s *Status) IsLocal() bool {
|
||||
return s.Local != nil && *s.Local
|
||||
}
|
||||
|
||||
// enumType is the type we (at least, should) use
|
||||
// for database enum types. it is the largest size
|
||||
// supported by a PostgreSQL SMALLINT, since an
|
||||
// SQLite SMALLINT is actually variable in size.
|
||||
type enumType int16
|
||||
|
||||
// Visibility represents the
|
||||
// visibility granularity of a status.
|
||||
type Visibility enumType
|
||||
|
||||
const (
|
||||
// VisibilityNone means nobody can see this.
|
||||
// It's only used for web status visibility.
|
||||
VisibilityNone Visibility = 1
|
||||
|
||||
// VisibilityPublic means this status will
|
||||
// be visible to everyone on all timelines.
|
||||
VisibilityPublic Visibility = 2
|
||||
|
||||
// VisibilityUnlocked means this status will be visible to everyone,
|
||||
// but will only show on home timeline to followers, and in lists.
|
||||
VisibilityUnlocked Visibility = 3
|
||||
|
||||
// VisibilityFollowersOnly means this status is viewable to followers only.
|
||||
VisibilityFollowersOnly Visibility = 4
|
||||
|
||||
// VisibilityMutualsOnly means this status
|
||||
// is visible to mutual followers only.
|
||||
VisibilityMutualsOnly Visibility = 5
|
||||
|
||||
// VisibilityDirect means this status is
|
||||
// visible only to mentioned recipients.
|
||||
VisibilityDirect Visibility = 6
|
||||
|
||||
// VisibilityDefault is used when no other setting can be found.
|
||||
VisibilityDefault Visibility = VisibilityUnlocked
|
||||
)
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/util/xslices"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
func init() {
|
||||
up := func(ctx context.Context, db *bun.DB) error {
|
||||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
var edits []*gtsmodel.StatusEdit
|
||||
|
||||
// Select all status edits that
|
||||
// are not actually connected to
|
||||
// the status they reference.
|
||||
if err := tx.NewSelect().
|
||||
Model(&edits).
|
||||
Join("JOIN ? AS ? ON ? = ?",
|
||||
bun.Ident("statuses"),
|
||||
bun.Ident("status"),
|
||||
bun.Ident("status.id"),
|
||||
bun.Ident("status_edit.status_id"),
|
||||
).
|
||||
Where("CAST(? AS TEXT) NOT LIKE CONCAT(?, ?, ?)",
|
||||
bun.Ident("status.edits"),
|
||||
"%", bun.Ident("status_edit.id"), "%",
|
||||
).
|
||||
Column("id", "status_id", "created_at").
|
||||
Scan(ctx, &edits); err != nil {
|
||||
return fmt.Errorf("error selecting unlinked edits: %w", err)
|
||||
}
|
||||
|
||||
log.Infof(ctx, "relinking %d unlinked status edits", len(edits))
|
||||
|
||||
for _, edit := range edits {
|
||||
var status gtsmodel.Status
|
||||
|
||||
// Select the list of edits
|
||||
// CURRENTLY attached to the
|
||||
// status that edit references.
|
||||
if err := tx.NewSelect().
|
||||
Model(&status).
|
||||
Column("edits").
|
||||
Where("? = ?",
|
||||
bun.Ident("id"),
|
||||
edit.StatusID,
|
||||
).
|
||||
Scan(ctx); err != nil {
|
||||
return fmt.Errorf("error selecting status.edits: %w", err)
|
||||
}
|
||||
|
||||
// Select only the ID and creation
|
||||
// dates of all the other edits that
|
||||
// are attached to referenced status.
|
||||
if err := tx.NewSelect().
|
||||
Model(&status.Edits).
|
||||
Column("id", "created_at").
|
||||
Where("? IN (?)",
|
||||
bun.Ident("id"),
|
||||
bun.In(status.EditIDs),
|
||||
).
|
||||
Scan(ctx); err != nil {
|
||||
return fmt.Errorf("error selecting other status edits: %w", err)
|
||||
}
|
||||
|
||||
editID := func(e *gtsmodel.StatusEdit) string { return e.ID }
|
||||
|
||||
// Append this unlinked edit to status' list
|
||||
// of edits and then sort edits by creation.
|
||||
//
|
||||
// On tiny off-chance we end up with dupes,
|
||||
// we still deduplicate these status edits.
|
||||
status.Edits = append(status.Edits, edit)
|
||||
status.Edits = xslices.DeduplicateFunc(status.Edits, editID)
|
||||
slices.SortFunc(status.Edits, func(e1, e2 *gtsmodel.StatusEdit) int {
|
||||
const k = -1 // oldest at 0th, newest at nth
|
||||
switch c1, c2 := e1.CreatedAt, e2.CreatedAt; {
|
||||
case c1.Before(c2):
|
||||
return +k
|
||||
case c2.Before(c1):
|
||||
return -k
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
})
|
||||
|
||||
// Extract the IDs from edits to update the status edit IDs.
|
||||
status.EditIDs = xslices.Gather(nil, status.Edits, editID)
|
||||
|
||||
// Update the relevant status
|
||||
// edit IDs column in database.
|
||||
if _, err := tx.NewUpdate().
|
||||
Model(&status).
|
||||
Column("edits").
|
||||
Where("? = ?",
|
||||
bun.Ident("id"),
|
||||
edit.StatusID,
|
||||
).
|
||||
Exec(ctx); err != nil {
|
||||
return fmt.Errorf("error updating status.edits: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
down := func(ctx context.Context, db *bun.DB) error {
|
||||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
if err := Migrations.Register(up, down); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
gtsmodel "github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20241022153016_domain_permission_subscriptions"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
func init() {
|
||||
up := func(ctx context.Context, db *bun.DB) error {
|
||||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
// Create `domain_permission_subscriptions`.
|
||||
if _, err := tx.
|
||||
NewCreateTable().
|
||||
Model((*gtsmodel.DomainPermissionSubscription)(nil)).
|
||||
IfNotExists().
|
||||
Exec(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create indexes. Indices. Indie sexes.
|
||||
if _, err := tx.
|
||||
NewCreateIndex().
|
||||
Table("domain_permission_subscriptions").
|
||||
// Filter on permission type.
|
||||
Index("domain_permission_subscriptions_permission_type_idx").
|
||||
Column("permission_type").
|
||||
IfNotExists().
|
||||
Exec(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := tx.
|
||||
NewCreateIndex().
|
||||
Table("domain_permission_subscriptions").
|
||||
// Sort by priority DESC.
|
||||
Index("domain_permission_subscriptions_priority_order_idx").
|
||||
ColumnExpr("? DESC", bun.Ident("priority")).
|
||||
IfNotExists().
|
||||
Exec(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
down := func(ctx context.Context, db *bun.DB) error {
|
||||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
if err := Migrations.Register(up, down); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
func init() {
|
||||
up := func(ctx context.Context, db *bun.DB) error {
|
||||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
// Bail if "last_modified"
|
||||
// column already created.
|
||||
if exists, err := doesColumnExist(
|
||||
ctx,
|
||||
tx,
|
||||
"domain_permission_subscriptions",
|
||||
"last_modified",
|
||||
); err != nil {
|
||||
return err
|
||||
} else if exists {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Derive column definition.
|
||||
var permSub *gtsmodel.DomainPermissionSubscription
|
||||
permSubType := reflect.TypeOf(permSub)
|
||||
colDef, err := getBunColumnDef(tx, permSubType, "LastModified")
|
||||
if err != nil {
|
||||
return fmt.Errorf("error making column def: %w", err)
|
||||
}
|
||||
|
||||
log.Info(ctx, "adding domain_permission_subscriptions.last_modified column...")
|
||||
if _, err := tx.
|
||||
NewAddColumn().
|
||||
Model(permSub).
|
||||
ColumnExpr(colDef).
|
||||
Exec(ctx); err != nil {
|
||||
return fmt.Errorf("error adding column: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
down := func(ctx context.Context, db *bun.DB) error {
|
||||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
if err := Migrations.Register(up, down); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
gtsmodel "github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20241022153016_domain_permission_subscriptions"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
// This file exists because tobi is a silly billy and named two migration files
|
||||
// with the same date part, so the latter migration didn't always run properly.
|
||||
// The file just repeats migrations in 20250119112745_domain_permission_subscriptions.go,
|
||||
// which will be a noop in most cases, but will fix some issues for those who
|
||||
// were running snapshots between GtS v0.17.0 and GtS v0.18.0.
|
||||
//
|
||||
// See https://github.com/superseriousbusiness/gotosocial/pull/3679.
|
||||
func init() {
|
||||
up := func(ctx context.Context, db *bun.DB) error {
|
||||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
// Create `domain_permission_subscriptions`.
|
||||
if _, err := tx.
|
||||
NewCreateTable().
|
||||
Model((*gtsmodel.DomainPermissionSubscription)(nil)).
|
||||
IfNotExists().
|
||||
Exec(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create indexes. Indices. Indie sexes.
|
||||
if _, err := tx.
|
||||
NewCreateIndex().
|
||||
Table("domain_permission_subscriptions").
|
||||
// Filter on permission type.
|
||||
Index("domain_permission_subscriptions_permission_type_idx").
|
||||
Column("permission_type").
|
||||
IfNotExists().
|
||||
Exec(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := tx.
|
||||
NewCreateIndex().
|
||||
Table("domain_permission_subscriptions").
|
||||
// Sort by priority DESC.
|
||||
Index("domain_permission_subscriptions_priority_order_idx").
|
||||
ColumnExpr("? DESC", bun.Ident("priority")).
|
||||
IfNotExists().
|
||||
Exec(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
down := func(ctx context.Context, db *bun.DB) error {
|
||||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
if err := Migrations.Register(up, down); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
@ -66,7 +66,7 @@ func (suite *NotificationTestSuite) spamNotifs() {
|
|||
|
||||
notif := >smodel.Notification{
|
||||
ID: notifID,
|
||||
NotificationType: gtsmodel.NotificationFave,
|
||||
NotificationType: gtsmodel.NotificationFavourite,
|
||||
CreatedAt: time.Now(),
|
||||
TargetAccountID: targetAccountID,
|
||||
OriginAccountID: originAccountID,
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
|
||||
|
|
@ -158,17 +157,6 @@ func (p *pollDB) UpdatePoll(ctx context.Context, poll *gtsmodel.Poll, cols ...st
|
|||
|
||||
return p.state.Caches.DB.Poll.Store(poll, func() error {
|
||||
return p.db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
// Update the status' "updated_at" field.
|
||||
if _, err := tx.NewUpdate().
|
||||
Table("statuses").
|
||||
Where("? = ?", bun.Ident("id"), poll.StatusID).
|
||||
SetColumn("updated_at", "?", time.Now()).
|
||||
Exec(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Finally, update poll
|
||||
// columns in database.
|
||||
_, err := tx.NewUpdate().
|
||||
Model(poll).
|
||||
Column(cols...).
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@ func getFutureStatus() *gtsmodel.Status {
|
|||
MentionIDs: []string{},
|
||||
EmojiIDs: []string{},
|
||||
CreatedAt: theDistantFuture,
|
||||
UpdatedAt: theDistantFuture,
|
||||
Local: util.Ptr(true),
|
||||
AccountURI: "http://localhost:8080/users/admin",
|
||||
AccountID: "01F8MH17FWEB39HZJ76B6VXSKF",
|
||||
|
|
|
|||
270
internal/db/bundb/webpush.go
Normal file
270
internal/db/bundb/webpush.go
Normal file
|
|
@ -0,0 +1,270 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package bundb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
webpushgo "github.com/SherClockHolmes/webpush-go"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/state"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/util/xslices"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type webPushDB struct {
|
||||
db *bun.DB
|
||||
state *state.State
|
||||
}
|
||||
|
||||
func (w *webPushDB) GetVAPIDKeyPair(ctx context.Context) (*gtsmodel.VAPIDKeyPair, error) {
|
||||
var err error
|
||||
|
||||
vapidKeyPair, err := w.getVAPIDKeyPair(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if vapidKeyPair != nil {
|
||||
return vapidKeyPair, nil
|
||||
}
|
||||
|
||||
// If there aren't any, generate new ones.
|
||||
vapidKeyPair = >smodel.VAPIDKeyPair{}
|
||||
if vapidKeyPair.Private, vapidKeyPair.Public, err = webpushgo.GenerateVAPIDKeys(); err != nil {
|
||||
return nil, gtserror.Newf("error generating VAPID key pair: %w", err)
|
||||
}
|
||||
|
||||
// Store the keys in the database.
|
||||
if _, err = w.db.NewInsert().
|
||||
Model(vapidKeyPair).
|
||||
Exec(ctx); // nocollapse
|
||||
err != nil {
|
||||
if errors.Is(err, db.ErrAlreadyExists) {
|
||||
// Multiple concurrent attempts to generate new keys, and this one didn't win.
|
||||
// Get the results of the one that did.
|
||||
return w.getVAPIDKeyPair(ctx)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Cache the keys.
|
||||
w.state.Caches.DB.VAPIDKeyPair.Store(vapidKeyPair)
|
||||
|
||||
return vapidKeyPair, nil
|
||||
}
|
||||
|
||||
// getVAPIDKeyPair gets an existing VAPID key pair from cache or DB.
|
||||
// If there is no existing VAPID key pair, it returns nil, with no error.
|
||||
func (w *webPushDB) getVAPIDKeyPair(ctx context.Context) (*gtsmodel.VAPIDKeyPair, error) {
|
||||
// Look for cached keys.
|
||||
vapidKeyPair := w.state.Caches.DB.VAPIDKeyPair.Load()
|
||||
if vapidKeyPair != nil {
|
||||
return vapidKeyPair, nil
|
||||
}
|
||||
|
||||
// Look for previously generated keys in the database.
|
||||
vapidKeyPair = >smodel.VAPIDKeyPair{}
|
||||
if err := w.db.NewSelect().
|
||||
Model(vapidKeyPair).
|
||||
Limit(1).
|
||||
Scan(ctx); // nocollapse
|
||||
err != nil {
|
||||
if errors.Is(err, db.ErrNoEntries) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return vapidKeyPair, nil
|
||||
}
|
||||
|
||||
func (w *webPushDB) DeleteVAPIDKeyPair(ctx context.Context) error {
|
||||
// Delete any existing keys.
|
||||
if _, err := w.db.NewTruncateTable().
|
||||
Model((*gtsmodel.VAPIDKeyPair)(nil)).
|
||||
Exec(ctx); // nocollapse
|
||||
err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Clear the key cache.
|
||||
w.state.Caches.DB.VAPIDKeyPair.Store(nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *webPushDB) GetWebPushSubscriptionByTokenID(ctx context.Context, tokenID string) (*gtsmodel.WebPushSubscription, error) {
|
||||
subscription, err := w.state.Caches.DB.WebPushSubscription.LoadOne(
|
||||
"TokenID",
|
||||
func() (*gtsmodel.WebPushSubscription, error) {
|
||||
var subscription gtsmodel.WebPushSubscription
|
||||
err := w.db.
|
||||
NewSelect().
|
||||
Model(&subscription).
|
||||
Where("? = ?", bun.Ident("token_id"), tokenID).
|
||||
Scan(ctx)
|
||||
return &subscription, err
|
||||
},
|
||||
tokenID,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return subscription, nil
|
||||
}
|
||||
|
||||
func (w *webPushDB) PutWebPushSubscription(ctx context.Context, subscription *gtsmodel.WebPushSubscription) error {
|
||||
return w.state.Caches.DB.WebPushSubscription.Store(subscription, func() error {
|
||||
_, err := w.db.NewInsert().
|
||||
Model(subscription).
|
||||
Exec(ctx)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (w *webPushDB) UpdateWebPushSubscription(ctx context.Context, subscription *gtsmodel.WebPushSubscription, columns ...string) error {
|
||||
// Update database.
|
||||
result, err := w.db.
|
||||
NewUpdate().
|
||||
Model(subscription).
|
||||
Column(columns...).
|
||||
Where("? = ?", bun.Ident("id"), subscription.ID).
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return gtserror.Newf("error getting updated row count: %w", err)
|
||||
}
|
||||
if rowsAffected == 0 {
|
||||
return db.ErrNoEntries
|
||||
}
|
||||
|
||||
// Update cache.
|
||||
w.state.Caches.DB.WebPushSubscription.Put(subscription)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *webPushDB) DeleteWebPushSubscriptionByTokenID(ctx context.Context, tokenID string) error {
|
||||
// Deleted partial model for cache invalidation.
|
||||
var deleted gtsmodel.WebPushSubscription
|
||||
|
||||
// Delete subscription, returning subset of columns used by invalidation hook.
|
||||
if _, err := w.db.NewDelete().
|
||||
Model(&deleted).
|
||||
Where("? = ?", bun.Ident("token_id"), tokenID).
|
||||
Returning("?", bun.Ident("account_id")).
|
||||
Exec(ctx); // nocollapse
|
||||
err != nil && !errors.Is(err, db.ErrNoEntries) {
|
||||
return err
|
||||
}
|
||||
|
||||
// Invalidate cached subscription by token ID.
|
||||
w.state.Caches.DB.WebPushSubscription.Invalidate("TokenID", tokenID)
|
||||
|
||||
// Call invalidate hook directly.
|
||||
w.state.Caches.OnInvalidateWebPushSubscription(&deleted)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *webPushDB) GetWebPushSubscriptionsByAccountID(ctx context.Context, accountID string) ([]*gtsmodel.WebPushSubscription, error) {
|
||||
// Fetch IDs of all subscriptions created by this account.
|
||||
subscriptionIDs, err := loadPagedIDs(&w.state.Caches.DB.WebPushSubscriptionIDs, accountID, nil, func() ([]string, error) {
|
||||
// Subscription IDs not in cache. Perform DB query.
|
||||
var subscriptionIDs []string
|
||||
if _, err := w.db.
|
||||
NewSelect().
|
||||
Model((*gtsmodel.WebPushSubscription)(nil)).
|
||||
Column("id").
|
||||
Where("? = ?", bun.Ident("account_id"), accountID).
|
||||
Order("id DESC").
|
||||
Exec(ctx, &subscriptionIDs); // nocollapse
|
||||
err != nil && !errors.Is(err, db.ErrNoEntries) {
|
||||
return nil, err
|
||||
}
|
||||
return subscriptionIDs, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(subscriptionIDs) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Get each subscription by ID from the cache or DB.
|
||||
subscriptions, err := w.state.Caches.DB.WebPushSubscription.LoadIDs("ID",
|
||||
subscriptionIDs,
|
||||
func(uncached []string) ([]*gtsmodel.WebPushSubscription, error) {
|
||||
subscriptions := make([]*gtsmodel.WebPushSubscription, 0, len(uncached))
|
||||
if err := w.db.
|
||||
NewSelect().
|
||||
Model(&subscriptions).
|
||||
Where("? IN (?)", bun.Ident("id"), bun.In(uncached)).
|
||||
Scan(ctx); // nocollapse
|
||||
err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return subscriptions, nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Put the subscription structs in the same order as the filter IDs.
|
||||
xslices.OrderBy(
|
||||
subscriptions,
|
||||
subscriptionIDs,
|
||||
func(subscription *gtsmodel.WebPushSubscription) string {
|
||||
return subscription.ID
|
||||
},
|
||||
)
|
||||
|
||||
return subscriptions, nil
|
||||
}
|
||||
|
||||
func (w *webPushDB) DeleteWebPushSubscriptionsByAccountID(ctx context.Context, accountID string) error {
|
||||
// Deleted partial models for cache invalidation.
|
||||
var deleted []*gtsmodel.WebPushSubscription
|
||||
|
||||
// Delete subscriptions, returning subset of columns.
|
||||
if _, err := w.db.NewDelete().
|
||||
Model(&deleted).
|
||||
Where("? = ?", bun.Ident("account_id"), accountID).
|
||||
Returning("?", bun.Ident("account_id")).
|
||||
Exec(ctx); // nocollapse
|
||||
err != nil && !errors.Is(err, db.ErrNoEntries) {
|
||||
return err
|
||||
}
|
||||
|
||||
// Invalidate cached subscriptions by account ID.
|
||||
w.state.Caches.DB.WebPushSubscription.Invalidate("AccountID", accountID)
|
||||
|
||||
// Call invalidate hooks directly in case those entries weren't cached.
|
||||
for _, subscription := range deleted {
|
||||
w.state.Caches.OnInvalidateWebPushSubscription(subscription)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
81
internal/db/bundb/webpush_test.go
Normal file
81
internal/db/bundb/webpush_test.go
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package bundb_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
type WebPushTestSuite struct {
|
||||
BunDBStandardTestSuite
|
||||
}
|
||||
|
||||
// Get the text fixture VAPID key pair.
|
||||
func (suite *WebPushTestSuite) TestGetVAPIDKeyPair() {
|
||||
ctx := context.Background()
|
||||
|
||||
vapidKeyPair, err := suite.db.GetVAPIDKeyPair(ctx)
|
||||
suite.NoError(err)
|
||||
if !suite.NotNil(vapidKeyPair) {
|
||||
suite.FailNow("Got a nil VAPID key pair, can't continue")
|
||||
}
|
||||
suite.NotEmpty(vapidKeyPair.Private)
|
||||
suite.NotEmpty(vapidKeyPair.Public)
|
||||
|
||||
// Get it again. It should be the same one.
|
||||
vapidKeyPair2, err := suite.db.GetVAPIDKeyPair(ctx)
|
||||
suite.NoError(err)
|
||||
if suite.NotNil(vapidKeyPair2) {
|
||||
suite.Equal(vapidKeyPair.Private, vapidKeyPair2.Private)
|
||||
suite.Equal(vapidKeyPair.Public, vapidKeyPair2.Public)
|
||||
}
|
||||
}
|
||||
|
||||
// Generate a VAPID key pair when there isn't one.
|
||||
func (suite *WebPushTestSuite) TestGenerateVAPIDKeyPair() {
|
||||
ctx := context.Background()
|
||||
|
||||
// Delete the text fixture VAPID key pair.
|
||||
if err := suite.db.DeleteVAPIDKeyPair(ctx); !suite.NoError(err) {
|
||||
suite.FailNow("Test setup failed: DB error deleting fixture VAPID key pair: %v", err)
|
||||
}
|
||||
|
||||
// Get a new one.
|
||||
vapidKeyPair, err := suite.db.GetVAPIDKeyPair(ctx)
|
||||
suite.NoError(err)
|
||||
if !suite.NotNil(vapidKeyPair) {
|
||||
suite.FailNow("Got a nil VAPID key pair, can't continue")
|
||||
}
|
||||
suite.NotEmpty(vapidKeyPair.Private)
|
||||
suite.NotEmpty(vapidKeyPair.Public)
|
||||
|
||||
// Get it again. It should be the same one.
|
||||
vapidKeyPair2, err := suite.db.GetVAPIDKeyPair(ctx)
|
||||
suite.NoError(err)
|
||||
if suite.NotNil(vapidKeyPair2) {
|
||||
suite.Equal(vapidKeyPair.Private, vapidKeyPair2.Private)
|
||||
suite.Equal(vapidKeyPair.Public, vapidKeyPair2.Public)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebPushTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(WebPushTestSuite))
|
||||
}
|
||||
|
|
@ -58,5 +58,6 @@ type DB interface {
|
|||
Timeline
|
||||
User
|
||||
Tombstone
|
||||
WebPush
|
||||
WorkerTask
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,4 +132,44 @@ type Domain interface {
|
|||
|
||||
// IsDomainPermissionExcluded returns true if the given domain matches in the list of excluded domains.
|
||||
IsDomainPermissionExcluded(ctx context.Context, domain string) (bool, error)
|
||||
|
||||
/*
|
||||
Domain permission subscription stuff.
|
||||
*/
|
||||
|
||||
// GetDomainPermissionSubscriptionByID gets one DomainPermissionSubscription with the given ID.
|
||||
GetDomainPermissionSubscriptionByID(ctx context.Context, id string) (*gtsmodel.DomainPermissionSubscription, error)
|
||||
|
||||
// GetDomainPermissionSubscriptions returns a page of
|
||||
// DomainPermissionSubscriptions using the given parameters.
|
||||
GetDomainPermissionSubscriptions(
|
||||
ctx context.Context,
|
||||
permType gtsmodel.DomainPermissionType,
|
||||
page *paging.Page,
|
||||
) ([]*gtsmodel.DomainPermissionSubscription, error)
|
||||
|
||||
// GetDomainPermissionSubscriptionsByPriority returns *all* domain permission
|
||||
// subscriptions of the given permission type, sorted by priority descending.
|
||||
GetDomainPermissionSubscriptionsByPriority(
|
||||
ctx context.Context,
|
||||
permType gtsmodel.DomainPermissionType,
|
||||
) ([]*gtsmodel.DomainPermissionSubscription, error)
|
||||
|
||||
// PutDomainPermissionSubscription stores one DomainPermissionSubscription.
|
||||
PutDomainPermissionSubscription(ctx context.Context, permSub *gtsmodel.DomainPermissionSubscription) error
|
||||
|
||||
// UpdateDomainPermissionSubscription updates the provided
|
||||
// columns of one DomainPermissionSubscription.
|
||||
UpdateDomainPermissionSubscription(
|
||||
ctx context.Context,
|
||||
permSub *gtsmodel.DomainPermissionSubscription,
|
||||
columns ...string,
|
||||
) error
|
||||
|
||||
// DeleteDomainPermissionSubscription deletes one DomainPermissionSubscription with the given id.
|
||||
DeleteDomainPermissionSubscription(ctx context.Context, id string) error
|
||||
|
||||
// CountDomainPermissionSubscriptionPerms counts the number of permissions
|
||||
// currently managed by the domain permission subscription of the given ID.
|
||||
CountDomainPermissionSubscriptionPerms(ctx context.Context, id string) (int, error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,6 @@ func (f *ConversationFactory) NewTestStatus(localAccount *gtsmodel.Account, thre
|
|||
status := >smodel.Status{
|
||||
ID: statusID,
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: createdAt,
|
||||
URI: "http://localhost:8080/users/" + localAccount.Username + "/statuses/" + statusID,
|
||||
AccountID: localAccount.ID,
|
||||
AccountURI: localAccount.URI,
|
||||
|
|
|
|||
54
internal/db/webpush.go
Normal file
54
internal/db/webpush.go
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
)
|
||||
|
||||
// WebPush contains functions related to Web Push notifications.
|
||||
type WebPush interface {
|
||||
// GetVAPIDKeyPair retrieves the server's existing VAPID key pair, if there is one.
|
||||
// If there isn't one, it generates a new one, stores it, and returns that.
|
||||
GetVAPIDKeyPair(ctx context.Context) (*gtsmodel.VAPIDKeyPair, error)
|
||||
|
||||
// DeleteVAPIDKeyPair deletes the server's VAPID key pair.
|
||||
DeleteVAPIDKeyPair(ctx context.Context) error
|
||||
|
||||
// GetWebPushSubscriptionByTokenID retrieves an access token's Web Push subscription.
|
||||
// There may not be one, in which case an error will be returned.
|
||||
GetWebPushSubscriptionByTokenID(ctx context.Context, tokenID string) (*gtsmodel.WebPushSubscription, error)
|
||||
|
||||
// PutWebPushSubscription creates an access token's Web Push subscription.
|
||||
PutWebPushSubscription(ctx context.Context, subscription *gtsmodel.WebPushSubscription) error
|
||||
|
||||
// UpdateWebPushSubscription updates an access token's Web Push subscription.
|
||||
// There may not be one, in which case an error will be returned.
|
||||
UpdateWebPushSubscription(ctx context.Context, subscription *gtsmodel.WebPushSubscription, columns ...string) error
|
||||
|
||||
// DeleteWebPushSubscriptionByTokenID deletes an access token's Web Push subscription, if there is one.
|
||||
DeleteWebPushSubscriptionByTokenID(ctx context.Context, tokenID string) error
|
||||
|
||||
// GetWebPushSubscriptionsByAccountID retrieves an account's list of Web Push subscriptions.
|
||||
GetWebPushSubscriptionsByAccountID(ctx context.Context, accountID string) ([]*gtsmodel.WebPushSubscription, error)
|
||||
|
||||
// DeleteWebPushSubscriptionsByAccountID deletes an account's list of Web Push subscriptions.
|
||||
DeleteWebPushSubscriptionsByAccountID(ctx context.Context, accountID string) error
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue