mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-25 21:26:40 +00:00
convert statuses.visibility and notifications.notification_type columns from type string -> int for performance / space savings
This commit is contained in:
parent
301543616b
commit
759df1240a
|
@ -1027,7 +1027,7 @@ func ExtractVisibility(addressable Addressable, actorFollowersURI string) (gtsmo
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(to) == 0 && len(cc) == 0 {
|
if len(to) == 0 && len(cc) == 0 {
|
||||||
return "", gtserror.Newf("message wasn't TO or CC anyone")
|
return 0, gtserror.Newf("message wasn't TO or CC anyone")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assume most restrictive visibility,
|
// Assume most restrictive visibility,
|
||||||
|
|
|
@ -164,6 +164,18 @@ func (m *Module) NotificationsGETHandler(c *gin.Context) {
|
||||||
limit = int(i)
|
limit = int(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
types, errWithCode := apiutil.ParseNotificationTypes(c.QueryArray(TypesKey))
|
||||||
|
if errWithCode != nil {
|
||||||
|
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
exclTypes, errWithCode := apiutil.ParseNotificationTypes(c.QueryArray(ExcludeTypesKey))
|
||||||
|
if errWithCode != nil {
|
||||||
|
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
resp, errWithCode := m.processor.Timeline().NotificationsGet(
|
resp, errWithCode := m.processor.Timeline().NotificationsGet(
|
||||||
c.Request.Context(),
|
c.Request.Context(),
|
||||||
authed,
|
authed,
|
||||||
|
@ -171,8 +183,8 @@ func (m *Module) NotificationsGETHandler(c *gin.Context) {
|
||||||
c.Query(SinceIDKey),
|
c.Query(SinceIDKey),
|
||||||
c.Query(MinIDKey),
|
c.Query(MinIDKey),
|
||||||
limit,
|
limit,
|
||||||
c.QueryArray(TypesKey),
|
types,
|
||||||
c.QueryArray(ExcludeTypesKey),
|
exclTypes,
|
||||||
)
|
)
|
||||||
if errWithCode != nil {
|
if errWithCode != nil {
|
||||||
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
|
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
|
||||||
|
|
|
@ -18,11 +18,13 @@
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -216,6 +218,51 @@ func ParseInteractionReblogs(value string, defaultValue bool) (bool, gtserror.Wi
|
||||||
return parseBool(value, defaultValue, InteractionReblogsKey)
|
return parseBool(value, defaultValue, InteractionReblogsKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ParseNotificationType(value string) (gtsmodel.NotificationType, gtserror.WithCode) {
|
||||||
|
switch strings.ToLower(value) {
|
||||||
|
case "follow":
|
||||||
|
return gtsmodel.NotificationFollow, nil
|
||||||
|
case "follow_request":
|
||||||
|
return gtsmodel.NotificationFollowRequest, nil
|
||||||
|
case "mention":
|
||||||
|
return gtsmodel.NotificationMention, nil
|
||||||
|
case "reblog":
|
||||||
|
return gtsmodel.NotificationReblog, nil
|
||||||
|
case "favourite":
|
||||||
|
return gtsmodel.NotificationFave, nil
|
||||||
|
case "poll":
|
||||||
|
return gtsmodel.NotificationPoll, nil
|
||||||
|
case "status":
|
||||||
|
return gtsmodel.NotificationStatus, nil
|
||||||
|
case "admin.sign_up":
|
||||||
|
return gtsmodel.NotificationSignup, nil
|
||||||
|
case "pending.favourite":
|
||||||
|
return gtsmodel.NotificationPendingFave, nil
|
||||||
|
case "pending.reply":
|
||||||
|
return gtsmodel.NotificationPendingReply, nil
|
||||||
|
case "pending.reblog":
|
||||||
|
return gtsmodel.NotificationPendingReblog, nil
|
||||||
|
default:
|
||||||
|
text := fmt.Sprintf("unrecognized notification type %s", value)
|
||||||
|
return 0, gtserror.NewErrorBadRequest(errors.New(text), text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseNotificationTypes(values []string) ([]gtsmodel.NotificationType, gtserror.WithCode) {
|
||||||
|
if len(values) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
ntypes := make([]gtsmodel.NotificationType, len(values))
|
||||||
|
for i, value := range values {
|
||||||
|
ntype, errWithCode := ParseNotificationType(value)
|
||||||
|
if errWithCode != nil {
|
||||||
|
return nil, errWithCode
|
||||||
|
}
|
||||||
|
ntypes[i] = ntype
|
||||||
|
}
|
||||||
|
return ntypes, nil
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Parse functions for *REQUIRED* parameters.
|
Parse functions for *REQUIRED* parameters.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -106,7 +106,7 @@ func (suite *AccountTestSuite) populateTestStatus(testAccountKey string, status
|
||||||
status.URI = fmt.Sprintf("http://localhost:8080/users/%s/statuses/%s", testAccount.Username, status.ID)
|
status.URI = fmt.Sprintf("http://localhost:8080/users/%s/statuses/%s", testAccount.Username, status.ID)
|
||||||
status.Local = util.Ptr(true)
|
status.Local = util.Ptr(true)
|
||||||
|
|
||||||
if status.Visibility == "" {
|
if status.Visibility == 0 {
|
||||||
status.Visibility = gtsmodel.VisibilityDefault
|
status.Visibility = gtsmodel.VisibilityDefault
|
||||||
}
|
}
|
||||||
if status.ActivityStreamsType == "" {
|
if status.ActivityStreamsType == "" {
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
new_gtsmodel "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||||
|
|
||||||
oldmodel "github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20240620074530_interaction_policy"
|
oldmodel "github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20240620074530_interaction_policy"
|
||||||
|
@ -165,7 +166,16 @@ type spec struct {
|
||||||
// to new version of interaction policy.
|
// to new version of interaction policy.
|
||||||
for _, oldStatus := range oldStatuses {
|
for _, oldStatus := range oldStatuses {
|
||||||
// Start with default policy for this visibility.
|
// Start with default policy for this visibility.
|
||||||
v := gtsmodel.Visibility(oldStatus.Visibility)
|
v := func() gtsmodel.Visibility {
|
||||||
|
return map[oldmodel.Visibility]gtsmodel.Visibility{
|
||||||
|
oldmodel.VisibilityNone: new_gtsmodel.VisibilityNone,
|
||||||
|
oldmodel.VisibilityPublic: new_gtsmodel.VisibilityPublic,
|
||||||
|
oldmodel.VisibilityUnlocked: new_gtsmodel.VisibilityUnlocked,
|
||||||
|
oldmodel.VisibilityFollowersOnly: new_gtsmodel.VisibilityFollowersOnly,
|
||||||
|
oldmodel.VisibilityMutualsOnly: new_gtsmodel.VisibilityMutualsOnly,
|
||||||
|
oldmodel.VisibilityDirect: new_gtsmodel.VisibilityDirect,
|
||||||
|
}[oldStatus.Visibility]
|
||||||
|
}()
|
||||||
policy := gtsmodel.DefaultInteractionPolicyFor(v)
|
policy := gtsmodel.DefaultInteractionPolicyFor(v)
|
||||||
|
|
||||||
if !*oldStatus.Likeable {
|
if !*oldStatus.Likeable {
|
||||||
|
|
|
@ -22,40 +22,61 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
type Status struct {
|
type Status struct {
|
||||||
ID string `bun:"type:CHAR(26),pk,nullzero,notnull,unique"`
|
ID string `bun:"type:CHAR(26),pk,nullzero,notnull,unique"`
|
||||||
CreatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"`
|
CreatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"`
|
||||||
UpdatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"`
|
UpdatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"`
|
||||||
FetchedAt time.Time `bun:"type:timestamptz,nullzero"`
|
FetchedAt time.Time `bun:"type:timestamptz,nullzero"`
|
||||||
PinnedAt time.Time `bun:"type:timestamptz,nullzero"`
|
PinnedAt time.Time `bun:"type:timestamptz,nullzero"`
|
||||||
URI string `bun:",unique,nullzero,notnull"`
|
URI string `bun:",unique,nullzero,notnull"`
|
||||||
URL string `bun:",nullzero"`
|
URL string `bun:",nullzero"`
|
||||||
Content string `bun:""`
|
Content string `bun:""`
|
||||||
AttachmentIDs []string `bun:"attachments,array"`
|
AttachmentIDs []string `bun:"attachments,array"`
|
||||||
TagIDs []string `bun:"tags,array"`
|
TagIDs []string `bun:"tags,array"`
|
||||||
MentionIDs []string `bun:"mentions,array"`
|
MentionIDs []string `bun:"mentions,array"`
|
||||||
EmojiIDs []string `bun:"emojis,array"`
|
EmojiIDs []string `bun:"emojis,array"`
|
||||||
Local *bool `bun:",nullzero,notnull,default:false"`
|
Local *bool `bun:",nullzero,notnull,default:false"`
|
||||||
AccountID string `bun:"type:CHAR(26),nullzero,notnull"`
|
AccountID string `bun:"type:CHAR(26),nullzero,notnull"`
|
||||||
AccountURI string `bun:",nullzero,notnull"`
|
AccountURI string `bun:",nullzero,notnull"`
|
||||||
InReplyToID string `bun:"type:CHAR(26),nullzero"`
|
InReplyToID string `bun:"type:CHAR(26),nullzero"`
|
||||||
InReplyToURI string `bun:",nullzero"`
|
InReplyToURI string `bun:",nullzero"`
|
||||||
InReplyToAccountID string `bun:"type:CHAR(26),nullzero"`
|
InReplyToAccountID string `bun:"type:CHAR(26),nullzero"`
|
||||||
InReplyTo *Status `bun:"-"`
|
InReplyTo *Status `bun:"-"`
|
||||||
BoostOfID string `bun:"type:CHAR(26),nullzero"`
|
BoostOfID string `bun:"type:CHAR(26),nullzero"`
|
||||||
BoostOfURI string `bun:"-"`
|
BoostOfURI string `bun:"-"`
|
||||||
BoostOfAccountID string `bun:"type:CHAR(26),nullzero"`
|
BoostOfAccountID string `bun:"type:CHAR(26),nullzero"`
|
||||||
BoostOf *Status `bun:"-"`
|
BoostOf *Status `bun:"-"`
|
||||||
ThreadID string `bun:"type:CHAR(26),nullzero"`
|
ThreadID string `bun:"type:CHAR(26),nullzero"`
|
||||||
PollID string `bun:"type:CHAR(26),nullzero"`
|
PollID string `bun:"type:CHAR(26),nullzero"`
|
||||||
ContentWarning string `bun:",nullzero"`
|
ContentWarning string `bun:",nullzero"`
|
||||||
Visibility string `bun:",nullzero,notnull"`
|
Visibility Visibility `bun:",nullzero,notnull"`
|
||||||
Sensitive *bool `bun:",nullzero,notnull,default:false"`
|
Sensitive *bool `bun:",nullzero,notnull,default:false"`
|
||||||
Language string `bun:",nullzero"`
|
Language string `bun:",nullzero"`
|
||||||
CreatedWithApplicationID string `bun:"type:CHAR(26),nullzero"`
|
CreatedWithApplicationID string `bun:"type:CHAR(26),nullzero"`
|
||||||
ActivityStreamsType string `bun:",nullzero,notnull"`
|
ActivityStreamsType string `bun:",nullzero,notnull"`
|
||||||
Text string `bun:""`
|
Text string `bun:""`
|
||||||
Federated *bool `bun:",notnull"`
|
Federated *bool `bun:",notnull"`
|
||||||
Boostable *bool `bun:",notnull"`
|
Boostable *bool `bun:",notnull"`
|
||||||
Replyable *bool `bun:",notnull"`
|
Replyable *bool `bun:",notnull"`
|
||||||
Likeable *bool `bun:",notnull"`
|
Likeable *bool `bun:",notnull"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Visibility represents the visibility granularity of a status.
|
||||||
|
type Visibility string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// VisibilityNone means nobody can see this.
|
||||||
|
// It's only used for web status visibility.
|
||||||
|
VisibilityNone Visibility = "none"
|
||||||
|
// VisibilityPublic means this status will be visible to everyone on all timelines.
|
||||||
|
VisibilityPublic Visibility = "public"
|
||||||
|
// VisibilityUnlocked means this status will be visible to everyone, but will only show on home timeline to followers, and in lists.
|
||||||
|
VisibilityUnlocked Visibility = "unlocked"
|
||||||
|
// VisibilityFollowersOnly means this status is viewable to followers only.
|
||||||
|
VisibilityFollowersOnly Visibility = "followers_only"
|
||||||
|
// VisibilityMutualsOnly means this status is visible to mutual followers only.
|
||||||
|
VisibilityMutualsOnly Visibility = "mutuals_only"
|
||||||
|
// VisibilityDirect means this status is visible only to mentioned recipients.
|
||||||
|
VisibilityDirect Visibility = "direct"
|
||||||
|
// VisibilityDefault is used when no other setting can be found.
|
||||||
|
VisibilityDefault Visibility = VisibilityUnlocked
|
||||||
|
)
|
||||||
|
|
|
@ -0,0 +1,198 @@
|
||||||
|
// 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"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
old_gtsmodel "github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20241121121623_enum_strings_to_ints"
|
||||||
|
new_gtsmodel "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 {
|
||||||
|
var visIndices = []struct {
|
||||||
|
name string
|
||||||
|
cols []string
|
||||||
|
order string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "statuses_visibility_idx",
|
||||||
|
cols: []string{"visibility"},
|
||||||
|
order: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "statuses_profile_web_view_idx",
|
||||||
|
cols: []string{"account_id", "visibility"},
|
||||||
|
order: "id DESC",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "statuses_public_timeline_idx",
|
||||||
|
cols: []string{"visibility"},
|
||||||
|
order: "id DESC",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Before making changes to the visibility col
|
||||||
|
// we must drop all indices that rely on it.
|
||||||
|
for _, index := range visIndices {
|
||||||
|
if _, err := tx.NewDropIndex().
|
||||||
|
Index(index.name).
|
||||||
|
Exec(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now migrate old visibility column type over to new type.
|
||||||
|
if err := convertEnums(ctx, tx, "statuses", "visibility",
|
||||||
|
map[old_gtsmodel.Visibility]new_gtsmodel.Visibility{
|
||||||
|
old_gtsmodel.VisibilityNone: new_gtsmodel.VisibilityNone,
|
||||||
|
old_gtsmodel.VisibilityPublic: new_gtsmodel.VisibilityPublic,
|
||||||
|
old_gtsmodel.VisibilityUnlocked: new_gtsmodel.VisibilityUnlocked,
|
||||||
|
old_gtsmodel.VisibilityFollowersOnly: new_gtsmodel.VisibilityFollowersOnly,
|
||||||
|
old_gtsmodel.VisibilityMutualsOnly: new_gtsmodel.VisibilityMutualsOnly,
|
||||||
|
old_gtsmodel.VisibilityDirect: new_gtsmodel.VisibilityDirect,
|
||||||
|
}, nil); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recreate the visibility indices.
|
||||||
|
for _, index := range visIndices {
|
||||||
|
q := tx.NewCreateIndex().
|
||||||
|
Table("statuses").
|
||||||
|
Index(index.name).
|
||||||
|
Column(index.cols...)
|
||||||
|
if index.order != "" {
|
||||||
|
q = q.ColumnExpr(index.order)
|
||||||
|
}
|
||||||
|
if _, err := q.Exec(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Migrate over old notifications table column over to new column type.
|
||||||
|
if err := convertEnums(ctx, tx, "notifications", "notification_type", //nolint:revive
|
||||||
|
map[old_gtsmodel.NotificationType]new_gtsmodel.NotificationType{
|
||||||
|
old_gtsmodel.NotificationFollow: new_gtsmodel.NotificationFollow,
|
||||||
|
old_gtsmodel.NotificationFollowRequest: new_gtsmodel.NotificationFollowRequest,
|
||||||
|
old_gtsmodel.NotificationMention: new_gtsmodel.NotificationMention,
|
||||||
|
old_gtsmodel.NotificationReblog: new_gtsmodel.NotificationReblog,
|
||||||
|
old_gtsmodel.NotificationFave: new_gtsmodel.NotificationFave,
|
||||||
|
old_gtsmodel.NotificationPoll: new_gtsmodel.NotificationPoll,
|
||||||
|
old_gtsmodel.NotificationStatus: new_gtsmodel.NotificationStatus,
|
||||||
|
old_gtsmodel.NotificationSignup: new_gtsmodel.NotificationSignup,
|
||||||
|
old_gtsmodel.NotificationPendingFave: new_gtsmodel.NotificationPendingFave,
|
||||||
|
old_gtsmodel.NotificationPendingReply: new_gtsmodel.NotificationPendingReply,
|
||||||
|
old_gtsmodel.NotificationPendingReblog: new_gtsmodel.NotificationPendingReblog,
|
||||||
|
}, nil); 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// convertEnums performs a transaction that converts
|
||||||
|
// a table's column of our old-style enums (strings) to
|
||||||
|
// more performant and space-saving integer types.
|
||||||
|
func convertEnums[OldType ~string, NewType ~int](
|
||||||
|
ctx context.Context,
|
||||||
|
tx bun.Tx,
|
||||||
|
table string,
|
||||||
|
column string,
|
||||||
|
mapping map[OldType]NewType,
|
||||||
|
defaultValue *NewType,
|
||||||
|
) error {
|
||||||
|
if len(mapping) == 0 {
|
||||||
|
return errors.New("empty mapping")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate new column name.
|
||||||
|
newColumn := column + "_new"
|
||||||
|
|
||||||
|
log.Infof(ctx, "converting %s.%s enums; "+
|
||||||
|
"this may take a while, please don't interrupt!",
|
||||||
|
table, column,
|
||||||
|
)
|
||||||
|
|
||||||
|
var columnExpr string
|
||||||
|
var columnArgs []any
|
||||||
|
|
||||||
|
// Build new column expr with args.
|
||||||
|
columnExpr = "? INTEGER NOT NULL"
|
||||||
|
columnArgs = []any{bun.Ident(newColumn)}
|
||||||
|
if defaultValue != nil {
|
||||||
|
columnExpr += " DEFAULT ?"
|
||||||
|
columnArgs = append(columnArgs, *defaultValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add new column to database.
|
||||||
|
if _, err := tx.NewAddColumn().
|
||||||
|
Table(table).
|
||||||
|
ColumnExpr(columnExpr, columnArgs...).
|
||||||
|
Exec(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update existing values via mapping.
|
||||||
|
for old, new := range mapping {
|
||||||
|
if _, err := tx.NewUpdate().
|
||||||
|
Table(table).
|
||||||
|
Where("? = ?", bun.Ident(column), old).
|
||||||
|
Set("? = ?", bun.Ident(newColumn), new).
|
||||||
|
Exec(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drop the old column from table.
|
||||||
|
if _, err := tx.NewDropColumn().
|
||||||
|
Table(table).
|
||||||
|
ColumnExpr("?", bun.Ident(column)).
|
||||||
|
Exec(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rename new to old name.
|
||||||
|
if _, err := tx.NewRaw(
|
||||||
|
"ALTER TABLE ? RENAME COLUMN ? TO ?",
|
||||||
|
bun.Ident(table),
|
||||||
|
bun.Ident(newColumn),
|
||||||
|
bun.Ident(column),
|
||||||
|
).Exec(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
// 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"
|
||||||
|
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Notification models an alert/notification sent to an account about something like a reblog, like, new follow request, etc.
|
||||||
|
type Notification 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
|
||||||
|
NotificationType NotificationType `bun:",nullzero,notnull"` // Type of this notification
|
||||||
|
TargetAccountID string `bun:"type:CHAR(26),nullzero,notnull"` // ID of the account targeted by the notification (ie., who will receive the notification?)
|
||||||
|
TargetAccount *gtsmodel.Account `bun:"-"` // Account corresponding to TargetAccountID. Can be nil, always check first + select using ID if necessary.
|
||||||
|
OriginAccountID string `bun:"type:CHAR(26),nullzero,notnull"` // ID of the account that performed the action that created the notification.
|
||||||
|
OriginAccount *gtsmodel.Account `bun:"-"` // Account corresponding to OriginAccountID. Can be nil, always check first + select using ID if necessary.
|
||||||
|
StatusID string `bun:"type:CHAR(26),nullzero"` // If the notification pertains to a status, what is the database ID of that status?
|
||||||
|
Status *Status `bun:"-"` // Status corresponding to StatusID. Can be nil, always check first + select using ID if necessary.
|
||||||
|
Read *bool `bun:",nullzero,notnull,default:false"` // Notification has been seen/read
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotificationType describes the reason/type of this notification.
|
||||||
|
type NotificationType string
|
||||||
|
|
||||||
|
// Notification Types
|
||||||
|
const (
|
||||||
|
NotificationFollow NotificationType = "follow" // NotificationFollow -- someone followed you
|
||||||
|
NotificationFollowRequest NotificationType = "follow_request" // NotificationFollowRequest -- someone requested to follow you
|
||||||
|
NotificationMention NotificationType = "mention" // NotificationMention -- someone mentioned you in their status
|
||||||
|
NotificationReblog NotificationType = "reblog" // NotificationReblog -- someone boosted one of your statuses
|
||||||
|
NotificationFave NotificationType = "favourite" // NotificationFave -- someone faved/liked one of your statuses
|
||||||
|
NotificationPoll NotificationType = "poll" // NotificationPoll -- a poll you voted in or created has ended
|
||||||
|
NotificationStatus NotificationType = "status" // NotificationStatus -- someone you enabled notifications for has posted a status.
|
||||||
|
NotificationSignup NotificationType = "admin.sign_up" // NotificationSignup -- someone has submitted a new account sign-up to the instance.
|
||||||
|
NotificationPendingFave NotificationType = "pending.favourite" // Someone has faved a status of yours, which requires approval by you.
|
||||||
|
NotificationPendingReply NotificationType = "pending.reply" // Someone has replied to a status of yours, which requires approval by you.
|
||||||
|
NotificationPendingReblog NotificationType = "pending.reblog" // Someone has boosted a status of yours, which requires approval by you.
|
||||||
|
)
|
|
@ -0,0 +1,95 @@
|
||||||
|
// 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"
|
||||||
|
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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
|
||||||
|
Attachments []*gtsmodel.MediaAttachment `bun:"attached_media,rel:has-many"` // Attachments corresponding to attachmentIDs
|
||||||
|
TagIDs []string `bun:"tags,array"` // Database IDs of any tags used in this status
|
||||||
|
Tags []*gtsmodel.Tag `bun:"attached_tags,m2m:status_to_tags"` // Tags corresponding to tagIDs. https://bun.uptrace.dev/guide/relations.html#many-to-many-relation
|
||||||
|
MentionIDs []string `bun:"mentions,array"` // Database IDs of any mentions in this status
|
||||||
|
Mentions []*gtsmodel.Mention `bun:"attached_mentions,rel:has-many"` // Mentions corresponding to mentionIDs
|
||||||
|
EmojiIDs []string `bun:"emojis,array"` // Database IDs of any emojis used in this status
|
||||||
|
Emojis []*gtsmodel.Emoji `bun:"attached_emojis,m2m:status_to_emojis"` // Emojis corresponding to emojiIDs. https://bun.uptrace.dev/guide/relations.html#many-to-many-relation
|
||||||
|
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?
|
||||||
|
Account *gtsmodel.Account `bun:"rel:belongs-to"` // account corresponding to accountID
|
||||||
|
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
|
||||||
|
InReplyToAccount *gtsmodel.Account `bun:"rel:belongs-to"` // account corresponding to inReplyToAccountID
|
||||||
|
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
|
||||||
|
BoostOfAccount *gtsmodel.Account `bun:"rel:belongs-to"` // account that corresponds to boostOfAccountID
|
||||||
|
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
|
||||||
|
PollID string `bun:"type:CHAR(26),nullzero"` //
|
||||||
|
Poll *gtsmodel.Poll `bun:"-"` //
|
||||||
|
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?
|
||||||
|
CreatedWithApplication *gtsmodel.Application `bun:"rel:belongs-to"` // application corresponding to createdWithApplicationID
|
||||||
|
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 *gtsmodel.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.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Visibility represents the visibility granularity of a status.
|
||||||
|
type Visibility string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// VisibilityNone means nobody can see this.
|
||||||
|
// It's only used for web status visibility.
|
||||||
|
VisibilityNone Visibility = "none"
|
||||||
|
// VisibilityPublic means this status will be visible to everyone on all timelines.
|
||||||
|
VisibilityPublic Visibility = "public"
|
||||||
|
// VisibilityUnlocked means this status will be visible to everyone, but will only show on home timeline to followers, and in lists.
|
||||||
|
VisibilityUnlocked Visibility = "unlocked"
|
||||||
|
// VisibilityFollowersOnly means this status is viewable to followers only.
|
||||||
|
VisibilityFollowersOnly Visibility = "followers_only"
|
||||||
|
// VisibilityMutualsOnly means this status is visible to mutual followers only.
|
||||||
|
VisibilityMutualsOnly Visibility = "mutuals_only"
|
||||||
|
// VisibilityDirect means this status is visible only to mentioned recipients.
|
||||||
|
VisibilityDirect Visibility = "direct"
|
||||||
|
// VisibilityDefault is used when no other setting can be found.
|
||||||
|
VisibilityDefault Visibility = VisibilityUnlocked
|
||||||
|
)
|
|
@ -196,8 +196,8 @@ func (n *notificationDB) GetAccountNotifications(
|
||||||
sinceID string,
|
sinceID string,
|
||||||
minID string,
|
minID string,
|
||||||
limit int,
|
limit int,
|
||||||
types []string,
|
types []gtsmodel.NotificationType,
|
||||||
excludeTypes []string,
|
excludeTypes []gtsmodel.NotificationType,
|
||||||
) ([]*gtsmodel.Notification, error) {
|
) ([]*gtsmodel.Notification, error) {
|
||||||
// Ensure reasonable
|
// Ensure reasonable
|
||||||
if limit < 0 {
|
if limit < 0 {
|
||||||
|
@ -303,7 +303,7 @@ func (n *notificationDB) DeleteNotificationByID(ctx context.Context, id string)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *notificationDB) DeleteNotifications(ctx context.Context, types []string, targetAccountID string, originAccountID string) error {
|
func (n *notificationDB) DeleteNotifications(ctx context.Context, types []gtsmodel.NotificationType, targetAccountID string, originAccountID string) error {
|
||||||
if targetAccountID == "" && originAccountID == "" {
|
if targetAccountID == "" && originAccountID == "" {
|
||||||
return gtserror.New("one of targetAccountID or originAccountID must be set")
|
return gtserror.New("one of targetAccountID or originAccountID must be set")
|
||||||
}
|
}
|
||||||
|
|
|
@ -265,8 +265,8 @@ func (r *relationshipDB) AcceptFollowRequest(ctx context.Context, sourceAccountI
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete original follow request notification
|
// Delete original follow request notification
|
||||||
if err := r.state.DB.DeleteNotifications(ctx, []string{
|
if err := r.state.DB.DeleteNotifications(ctx, []gtsmodel.NotificationType{
|
||||||
string(gtsmodel.NotificationFollowRequest),
|
gtsmodel.NotificationFollowRequest,
|
||||||
}, targetAccountID, sourceAccountID); err != nil {
|
}, targetAccountID, sourceAccountID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -281,8 +281,8 @@ func (r *relationshipDB) RejectFollowRequest(ctx context.Context, sourceAccountI
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete follow request notification
|
// Delete follow request notification
|
||||||
return r.state.DB.DeleteNotifications(ctx, []string{
|
return r.state.DB.DeleteNotifications(ctx, []gtsmodel.NotificationType{
|
||||||
string(gtsmodel.NotificationFollowRequest),
|
gtsmodel.NotificationFollowRequest,
|
||||||
}, targetAccountID, sourceAccountID)
|
}, targetAccountID, sourceAccountID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ type Notification interface {
|
||||||
//
|
//
|
||||||
// Returned notifications will be ordered ID descending (ie., highest/newest to lowest/oldest).
|
// Returned notifications will be ordered ID descending (ie., highest/newest to lowest/oldest).
|
||||||
// If types is empty, *all* notification types will be included.
|
// If types is empty, *all* notification types will be included.
|
||||||
GetAccountNotifications(ctx context.Context, accountID string, maxID string, sinceID string, minID string, limit int, types []string, excludeTypes []string) ([]*gtsmodel.Notification, error)
|
GetAccountNotifications(ctx context.Context, accountID string, maxID string, sinceID string, minID string, limit int, types []gtsmodel.NotificationType, excludeTypes []gtsmodel.NotificationType) ([]*gtsmodel.Notification, error)
|
||||||
|
|
||||||
// GetNotificationByID returns one notification according to its id.
|
// GetNotificationByID returns one notification according to its id.
|
||||||
GetNotificationByID(ctx context.Context, id string) (*gtsmodel.Notification, error)
|
GetNotificationByID(ctx context.Context, id string) (*gtsmodel.Notification, error)
|
||||||
|
@ -64,7 +64,7 @@ type Notification interface {
|
||||||
// originate from originAccountID will be deleted.
|
// originate from originAccountID will be deleted.
|
||||||
//
|
//
|
||||||
// At least one parameter must not be an empty string.
|
// At least one parameter must not be an empty string.
|
||||||
DeleteNotifications(ctx context.Context, types []string, targetAccountID string, originAccountID string) error
|
DeleteNotifications(ctx context.Context, types []gtsmodel.NotificationType, targetAccountID string, originAccountID string) error
|
||||||
|
|
||||||
// DeleteNotificationsForStatus deletes all notifications that relate to
|
// DeleteNotificationsForStatus deletes all notifications that relate to
|
||||||
// the given statusID. This function is useful when a status has been deleted,
|
// the given statusID. This function is useful when a status has been deleted,
|
||||||
|
|
|
@ -224,7 +224,7 @@ func DefaultInteractionPolicyFor(v Visibility) *InteractionPolicy {
|
||||||
case VisibilityDirect:
|
case VisibilityDirect:
|
||||||
return DefaultInteractionPolicyDirect()
|
return DefaultInteractionPolicyDirect()
|
||||||
default:
|
default:
|
||||||
panic("visibility " + v + " not recognized")
|
panic("invalid visibility")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,20 +34,51 @@ type Notification struct {
|
||||||
Read *bool `bun:",nullzero,notnull,default:false"` // Notification has been seen/read
|
Read *bool `bun:",nullzero,notnull,default:false"` // Notification has been seen/read
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotificationType describes the reason/type of this notification.
|
// NotificationType describes the
|
||||||
type NotificationType string
|
// reason/type of this notification.
|
||||||
|
type NotificationType int
|
||||||
|
|
||||||
// Notification Types
|
|
||||||
const (
|
const (
|
||||||
NotificationFollow NotificationType = "follow" // NotificationFollow -- someone followed you
|
// Notification Types
|
||||||
NotificationFollowRequest NotificationType = "follow_request" // NotificationFollowRequest -- someone requested to follow you
|
NotificationFollow NotificationType = 1 // NotificationFollow -- someone followed you
|
||||||
NotificationMention NotificationType = "mention" // NotificationMention -- someone mentioned you in their status
|
NotificationFollowRequest NotificationType = 2 // NotificationFollowRequest -- someone requested to follow you
|
||||||
NotificationReblog NotificationType = "reblog" // NotificationReblog -- someone boosted one of your statuses
|
NotificationMention NotificationType = 3 // NotificationMention -- someone mentioned you in their status
|
||||||
NotificationFave NotificationType = "favourite" // NotificationFave -- someone faved/liked one of your statuses
|
NotificationReblog NotificationType = 4 // NotificationReblog -- someone boosted one of your statuses
|
||||||
NotificationPoll NotificationType = "poll" // NotificationPoll -- a poll you voted in or created has ended
|
NotificationFave NotificationType = 5 // NotificationFave -- someone faved/liked one of your statuses
|
||||||
NotificationStatus NotificationType = "status" // NotificationStatus -- someone you enabled notifications for has posted a status.
|
NotificationPoll NotificationType = 6 // NotificationPoll -- a poll you voted in or created has ended
|
||||||
NotificationSignup NotificationType = "admin.sign_up" // NotificationSignup -- someone has submitted a new account sign-up to the instance.
|
NotificationStatus NotificationType = 7 // NotificationStatus -- someone you enabled notifications for has posted a status.
|
||||||
NotificationPendingFave NotificationType = "pending.favourite" // Someone has faved a status of yours, which requires approval by you.
|
NotificationSignup NotificationType = 8 // NotificationSignup -- someone has submitted a new account sign-up to the instance.
|
||||||
NotificationPendingReply NotificationType = "pending.reply" // Someone has replied to a status of yours, which requires approval by you.
|
NotificationPendingFave NotificationType = 9 // Someone has faved a status of yours, which requires approval by you.
|
||||||
NotificationPendingReblog NotificationType = "pending.reblog" // Someone has boosted a status of yours, which requires approval by you.
|
NotificationPendingReply NotificationType = 10 // Someone has replied to a status of yours, which requires approval by you.
|
||||||
|
NotificationPendingReblog NotificationType = 11 // Someone has boosted a status of yours, which requires approval by you.
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// String returns a stringified, frontend API compatible form of NotificationType.
|
||||||
|
func (t NotificationType) String() string {
|
||||||
|
switch t {
|
||||||
|
case NotificationFollow:
|
||||||
|
return "follow"
|
||||||
|
case NotificationFollowRequest:
|
||||||
|
return "follow_request"
|
||||||
|
case NotificationMention:
|
||||||
|
return "mention"
|
||||||
|
case NotificationReblog:
|
||||||
|
return "reblog"
|
||||||
|
case NotificationFave:
|
||||||
|
return "favourite"
|
||||||
|
case NotificationPoll:
|
||||||
|
return "poll"
|
||||||
|
case NotificationStatus:
|
||||||
|
return "status"
|
||||||
|
case NotificationSignup:
|
||||||
|
return "admin.sign_up"
|
||||||
|
case NotificationPendingFave:
|
||||||
|
return "pending.favourite"
|
||||||
|
case NotificationPendingReply:
|
||||||
|
return "pending.reply"
|
||||||
|
case NotificationPendingReblog:
|
||||||
|
return "pending.reblog"
|
||||||
|
default:
|
||||||
|
panic("invalid notification type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -263,27 +263,58 @@ type StatusToEmoji struct {
|
||||||
Emoji *Emoji `bun:"rel:belongs-to"`
|
Emoji *Emoji `bun:"rel:belongs-to"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Visibility represents the visibility granularity of a status.
|
// Visibility represents the
|
||||||
type Visibility string
|
// visibility granularity of a status.
|
||||||
|
type Visibility int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// VisibilityNone means nobody can see this.
|
// VisibilityNone means nobody can see this.
|
||||||
// It's only used for web status visibility.
|
// It's only used for web status visibility.
|
||||||
VisibilityNone Visibility = "none"
|
VisibilityNone Visibility = 1
|
||||||
// VisibilityPublic means this status will be visible to everyone on all timelines.
|
|
||||||
VisibilityPublic Visibility = "public"
|
// VisibilityPublic means this status will
|
||||||
// VisibilityUnlocked means this status will be visible to everyone, but will only show on home timeline to followers, and in lists.
|
// be visible to everyone on all timelines.
|
||||||
VisibilityUnlocked Visibility = "unlocked"
|
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 means this status is viewable to followers only.
|
||||||
VisibilityFollowersOnly Visibility = "followers_only"
|
VisibilityFollowersOnly Visibility = 4
|
||||||
// VisibilityMutualsOnly means this status is visible to mutual followers only.
|
|
||||||
VisibilityMutualsOnly Visibility = "mutuals_only"
|
// VisibilityMutualsOnly means this status
|
||||||
// VisibilityDirect means this status is visible only to mentioned recipients.
|
// is visible to mutual followers only.
|
||||||
VisibilityDirect Visibility = "direct"
|
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 is used when no other setting can be found.
|
||||||
VisibilityDefault Visibility = VisibilityUnlocked
|
VisibilityDefault Visibility = VisibilityUnlocked
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// String returns a stringified, frontend API compatible form of Visibility.
|
||||||
|
func (v Visibility) String() string {
|
||||||
|
switch v {
|
||||||
|
case VisibilityNone:
|
||||||
|
return "none"
|
||||||
|
case VisibilityPublic:
|
||||||
|
return "public"
|
||||||
|
case VisibilityUnlocked:
|
||||||
|
return "unlocked"
|
||||||
|
case VisibilityFollowersOnly:
|
||||||
|
return "followers_only"
|
||||||
|
case VisibilityMutualsOnly:
|
||||||
|
return "mutuals_only"
|
||||||
|
case VisibilityDirect:
|
||||||
|
return "direct"
|
||||||
|
default:
|
||||||
|
panic("invalid visibility")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Content models the simple string content
|
// Content models the simple string content
|
||||||
// of a status along with its ContentMap,
|
// of a status along with its ContentMap,
|
||||||
// which contains content entries keyed by
|
// which contains content entries keyed by
|
||||||
|
|
|
@ -46,7 +46,7 @@ func (p *Processor) PreferencesGet(ctx context.Context, accountID string) (*apim
|
||||||
func mastoPrefVisibility(vis gtsmodel.Visibility) string {
|
func mastoPrefVisibility(vis gtsmodel.Visibility) string {
|
||||||
switch vis {
|
switch vis {
|
||||||
case gtsmodel.VisibilityPublic, gtsmodel.VisibilityDirect:
|
case gtsmodel.VisibilityPublic, gtsmodel.VisibilityDirect:
|
||||||
return string(vis)
|
return vis.String()
|
||||||
case gtsmodel.VisibilityUnlocked:
|
case gtsmodel.VisibilityUnlocked:
|
||||||
return "unlisted"
|
return "unlisted"
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -372,7 +372,7 @@ func (p *Processor) processVisibility(
|
||||||
|
|
||||||
// Fall back to account default, set
|
// Fall back to account default, set
|
||||||
// this back on the form for later use.
|
// this back on the form for later use.
|
||||||
case accountDefaultVis != "":
|
case accountDefaultVis != 0:
|
||||||
status.Visibility = accountDefaultVis
|
status.Visibility = accountDefaultVis
|
||||||
form.Visibility = p.converter.VisToAPIVis(ctx, accountDefaultVis)
|
form.Visibility = p.converter.VisToAPIVis(ctx, accountDefaultVis)
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,8 @@ func (p *Processor) NotificationsGet(
|
||||||
sinceID string,
|
sinceID string,
|
||||||
minID string,
|
minID string,
|
||||||
limit int,
|
limit int,
|
||||||
types []string,
|
types []gtsmodel.NotificationType,
|
||||||
excludeTypes []string,
|
excludeTypes []gtsmodel.NotificationType,
|
||||||
) (*apimodel.PageableResponse, gtserror.WithCode) {
|
) (*apimodel.PageableResponse, gtserror.WithCode) {
|
||||||
notifs, err := p.state.DB.GetAccountNotifications(
|
notifs, err := p.state.DB.GetAccountNotifications(
|
||||||
ctx,
|
ctx,
|
||||||
|
|
|
@ -542,7 +542,7 @@ func getNotifyLockURI(
|
||||||
) string {
|
) string {
|
||||||
builder := strings.Builder{}
|
builder := strings.Builder{}
|
||||||
builder.WriteString("notification:?")
|
builder.WriteString("notification:?")
|
||||||
builder.WriteString("type=" + string(notificationType))
|
builder.WriteString("type=" + notificationType.String())
|
||||||
builder.WriteString("&target=" + targetAccount.URI)
|
builder.WriteString("&target=" + targetAccount.URI)
|
||||||
builder.WriteString("&origin=" + originAccount.URI)
|
builder.WriteString("&origin=" + originAccount.URI)
|
||||||
if statusID != "" {
|
if statusID != "" {
|
||||||
|
|
|
@ -41,7 +41,7 @@ func APIVisToVis(m apimodel.Visibility) gtsmodel.Visibility {
|
||||||
case apimodel.VisibilityNone:
|
case apimodel.VisibilityNone:
|
||||||
return gtsmodel.VisibilityNone
|
return gtsmodel.VisibilityNone
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func APIMarkerNameToMarkerName(m apimodel.MarkerName) gtsmodel.MarkerName {
|
func APIMarkerNameToMarkerName(m apimodel.MarkerName) gtsmodel.MarkerName {
|
||||||
|
|
|
@ -1862,7 +1862,7 @@ func (c *Converter) NotificationToAPINotification(
|
||||||
|
|
||||||
return &apimodel.Notification{
|
return &apimodel.Notification{
|
||||||
ID: n.ID,
|
ID: n.ID,
|
||||||
Type: string(n.NotificationType),
|
Type: n.NotificationType.String(),
|
||||||
CreatedAt: util.FormatISO8601(n.CreatedAt),
|
CreatedAt: util.FormatISO8601(n.CreatedAt),
|
||||||
Account: apiAccount,
|
Account: apiAccount,
|
||||||
Status: apiStatus,
|
Status: apiStatus,
|
||||||
|
|
Loading…
Reference in a new issue