diff --git a/data/model/emote-set.model.go b/data/model/emote-set.model.go index 4bb56d74..bffb47f2 100644 --- a/data/model/emote-set.model.go +++ b/data/model/emote-set.model.go @@ -45,6 +45,8 @@ func (x *modelizer) EmoteSet(v structures.EmoteSet) EmoteSetModel { if v.Owner != nil { u := x.User(*v.Owner).ToPartial() + u.Connections = nil // clear the connections field of emote set owners as it's not needed here + owner = &u } else if !v.OwnerID.IsZero() { owner = &UserPartialModel{ID: v.OwnerID} @@ -71,6 +73,12 @@ func (x *modelizer) ActiveEmote(v structures.ActiveEmote) ActiveEmoteModel { var data *EmotePartialModel if v.Emote != nil { + // TODO: This is a workaround due to active emote flags not being implemented + // this mirrors the emote's flags to the value in the active emote + if v.Emote.Flags.Has(structures.EmoteFlagsZeroWidth) { + v.Flags = v.Flags.Set(structures.ActiveEmoteFlagZeroWidth) + } + e := x.Emote(*v.Emote).ToPartial() data = &e } diff --git a/data/model/emote.model.go b/data/model/emote.model.go index 1fad2205..34f55089 100644 --- a/data/model/emote.model.go +++ b/data/model/emote.model.go @@ -104,6 +104,8 @@ func (x *modelizer) Emote(v structures.Emote) EmoteModel { if v.Owner != nil { u := x.User(*v.Owner).ToPartial() + u.Connections = nil // clear the connections field of emote owners as it's not needed here + owner = &u } diff --git a/data/model/user.gql.model.go b/data/model/user.gql.model.go index b89de514..4fc691fb 100644 --- a/data/model/user.gql.model.go +++ b/data/model/user.gql.model.go @@ -39,6 +39,11 @@ func (xm UserModel) GQL() *model.User { } func (xm UserPartialModel) GQL() *model.UserPartial { + connections := make([]*model.UserConnection, len(xm.Connections)) + for i, c := range xm.Connections { + connections[i] = c.GQL() + } + return &model.UserPartial{ ID: xm.ID, Type: string(xm.UserType), @@ -48,6 +53,7 @@ func (xm UserPartialModel) GQL() *model.UserPartial { CreatedAt: xm.ID.Timestamp(), Style: xm.Style.GQL(), Roles: xm.RoleIDs, + Connections: connections, } } diff --git a/data/model/user.model.go b/data/model/user.model.go index 9e67418c..d408414d 100644 --- a/data/model/user.model.go +++ b/data/model/user.model.go @@ -24,17 +24,18 @@ type UserModel struct { Style UserStyle `json:"style"` Editors []UserEditorModel `json:"editors,omitempty"` RoleIDs []primitive.ObjectID `json:"roles"` - Connections []UserConnectionModel `json:"connections"` + Connections []UserConnectionModel `json:"connections,omitempty"` } type UserPartialModel struct { - ID primitive.ObjectID `json:"id"` - UserType UserTypeModel `json:"type,omitempty" enums:",BOT,SYSTEM"` - Username string `json:"username"` - DisplayName string `json:"display_name"` - AvatarURL string `json:"avatar_url,omitempty"` - Style UserStyle `json:"style"` - RoleIDs []primitive.ObjectID `json:"roles"` + ID primitive.ObjectID `json:"id"` + UserType UserTypeModel `json:"type,omitempty" enums:",BOT,SYSTEM"` + Username string `json:"username"` + DisplayName string `json:"display_name"` + AvatarURL string `json:"avatar_url,omitempty"` + Style UserStyle `json:"style"` + RoleIDs []primitive.ObjectID `json:"roles"` + Connections []UserConnectionModel `json:"connections"` } type UserStyle struct { @@ -156,6 +157,7 @@ func (um UserModel) ToPartial() UserPartialModel { Style: um.Style, DisplayName: um.DisplayName, RoleIDs: um.RoleIDs, + Connections: um.Connections, } } diff --git a/data/mutate/emote.mutation.go b/data/mutate/emote.mutation.go index b59e4106..a3f6b53a 100644 --- a/data/mutate/emote.mutation.go +++ b/data/mutate/emote.mutation.go @@ -216,7 +216,7 @@ func (m *Mutate) EditEmote(ctx context.Context, eb *structures.EmoteBuilder, opt structures.EmoteFlagsContentTwitchDisallowed, } for _, flag := range privilegedBits { - if f&flag != init.Flags&flag { + if f.Has(flag) { return errors.ErrInsufficientPrivilege().SetDetail("Not allowed to modify flag %s", flag.String()) } } diff --git a/data/mutate/emote_set.active_emote.mutation.go b/data/mutate/emote_set.active_emote.mutation.go index acb0aaf9..ca3bbb71 100644 --- a/data/mutate/emote_set.active_emote.mutation.go +++ b/data/mutate/emote_set.active_emote.mutation.go @@ -146,7 +146,7 @@ func (m *Mutate) EditEmotesInSet(ctx context.Context, esb *structures.EmoteSetBu // ADD EMOTE case structures.ListItemActionAdd: // Handle emote privacy - if utils.BitField.HasBits(int64(tgt.emote.Flags), int64(structures.EmoteFlagsPrivate)) { + if tgt.emote.Flags.Has(structures.EmoteFlagsPrivate) { usable := false // Usable if actor has Bypass Privacy permission if actor.HasPermission(structures.RolePermissionBypassPrivacy) { @@ -172,12 +172,12 @@ func (m *Mutate) EditEmotesInSet(ctx context.Context, esb *structures.EmoteSetBu if !usable { return errors.ErrInsufficientPrivilege().SetFields(errors.Fields{ "EMOTE_ID": tgt.ID.Hex(), - }).SetDetail("emote is private") + }).SetDetail("Private Emote") } } // Check zero-width permission - if set.Owner == nil || tgt.emote.Flags&structures.EmoteFlagsZeroWidth != 0 && !set.Owner.HasPermission(structures.RolePermissionFeatureZeroWidthEmoteType) { + if set.Owner == nil || tgt.emote.Flags.Value()&structures.EmoteFlagsZeroWidth != 0 && !set.Owner.HasPermission(structures.RolePermissionFeatureZeroWidthEmoteType) { return errors.ErrInsufficientPrivilege().SetDetail("You must be a subscriber to use zero-width emotes") } diff --git a/data/mutate/emote_set.create.mutation.go b/data/mutate/emote_set.create.mutation.go index d69d69ec..1357556b 100644 --- a/data/mutate/emote_set.create.mutation.go +++ b/data/mutate/emote_set.create.mutation.go @@ -113,7 +113,7 @@ type EmoteSetMutationSetEmoteItem struct { Action structures.ListItemAction ID primitive.ObjectID Name string - Flags structures.ActiveEmoteFlag + Flags structures.BitField[structures.ActiveEmoteFlag] emote *structures.Emote } diff --git a/go.mod b/go.mod index 90cf0838..4f9b7c37 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/h2non/filetype v1.1.3 github.com/json-iterator/go v1.1.12 github.com/prometheus/client_golang v1.13.0 - github.com/seventv/common v0.0.0-20221016024045-2dd13e9f94b0 + github.com/seventv/common v0.0.0-20221017024442-4139fcc3eb8d github.com/seventv/compactdisc v0.0.0-20220830002302-eb0e50b2ee91 github.com/seventv/image-processor/go v0.0.0-20220930061650-07bfacb8a36b github.com/seventv/message-queue/go v0.0.0-20220721124044-9fd23bda9643 diff --git a/go.sum b/go.sum index 47cc73c6..9b8d4211 100644 --- a/go.sum +++ b/go.sum @@ -442,10 +442,10 @@ github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d h1:Q+gqLBOPkFGHyCJx github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d/go.mod h1:Gy+0tqhJvgGlqnTF8CVGP0AaGRjwBtXs/a5PA0Y3+A4= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= -github.com/seventv/common v0.0.0-20220930065455-7356f20dcaae h1:uBgnys9WqishgKFq1OdGRKD0VQVzbc6PVVCujBfNTvU= -github.com/seventv/common v0.0.0-20220930065455-7356f20dcaae/go.mod h1:jHHFe3uNMyzb/ReDqMvaI/A1euvV/PW/G+2PhcWQqWw= github.com/seventv/common v0.0.0-20221016024045-2dd13e9f94b0 h1:zBgRfDjQx/I9Rb/Ozw6gJ6OJ6nXeCGP+NOR9iCgeRXo= github.com/seventv/common v0.0.0-20221016024045-2dd13e9f94b0/go.mod h1:jHHFe3uNMyzb/ReDqMvaI/A1euvV/PW/G+2PhcWQqWw= +github.com/seventv/common v0.0.0-20221017024442-4139fcc3eb8d h1:rDxbKNIvxzZTXqMLsCuIRCO957mmmjN61KvUIIt6S/s= +github.com/seventv/common v0.0.0-20221017024442-4139fcc3eb8d/go.mod h1:jHHFe3uNMyzb/ReDqMvaI/A1euvV/PW/G+2PhcWQqWw= github.com/seventv/compactdisc v0.0.0-20220830002302-eb0e50b2ee91 h1:Ea9415Yq3xZNNrKSlq4XyOViZ0gFWgqOKRxsN0ILOhk= github.com/seventv/compactdisc v0.0.0-20220830002302-eb0e50b2ee91/go.mod h1:f9JVdhYnBwWk8Rn2w0lL0rWXxZAkWuYBAdvMq1f+eno= github.com/seventv/image-processor/go v0.0.0-20220930061650-07bfacb8a36b h1:mRFpu2jZwswMQNEATI4K2xolqLj7ws4w/QRI18NqAG0= diff --git a/internal/gql/v2/helpers/transform.go b/internal/gql/v2/helpers/transform.go index 2063df74..d3b121c1 100644 --- a/internal/gql/v2/helpers/transform.go +++ b/internal/gql/v2/helpers/transform.go @@ -30,11 +30,11 @@ func EmoteStructureToModel(s structures.Emote, cdnURL string) *model.Emote { vis |= int(v2structures.EmoteVisibilityUnlisted) } - if utils.BitField.HasBits(int64(s.Flags), int64(structures.EmoteFlagsZeroWidth)) { + if s.Flags.Has(structures.EmoteFlagsZeroWidth) { vis |= int(v2structures.EmoteVisibilityZeroWidth) } - if utils.BitField.HasBits(int64(s.Flags), int64(structures.EmoteFlagsPrivate)) { + if s.Flags.Has(structures.EmoteFlagsPrivate) { vis |= int(v2structures.EmoteVisibilityPrivate) } diff --git a/internal/gql/v2/resolvers/mutation/mutation.emote.go b/internal/gql/v2/resolvers/mutation/mutation.emote.go index 5faf6b8a..1e20ae08 100644 --- a/internal/gql/v2/resolvers/mutation/mutation.emote.go +++ b/internal/gql/v2/resolvers/mutation/mutation.emote.go @@ -59,7 +59,7 @@ func (r *Resolver) EditEmote(ctx context.Context, opt model.EmoteInput, reason * if opt.Visibility != nil { vis := int64(*opt.Visibility) - flags := emote.Flags + flags := emote.Flags.Value() readModRequests := func() error { // Fetch mod request @@ -137,7 +137,7 @@ func (r *Resolver) EditEmote(ctx context.Context, opt model.EmoteInput, reason * flags |= structures.EmoteFlagsPrivate } - eb.SetFlags(flags) + eb.SetFlags(structures.BitField[structures.EmoteFlag](flags)) } if err = r.Ctx.Inst().Mutate.EditEmote(ctx, eb, mutate.EmoteEditOptions{ diff --git a/internal/gql/v2/resolvers/user/user.go b/internal/gql/v2/resolvers/user/user.go index 38e797dd..65f85bbc 100644 --- a/internal/gql/v2/resolvers/user/user.go +++ b/internal/gql/v2/resolvers/user/user.go @@ -71,7 +71,7 @@ func (r *Resolver) Emotes(ctx context.Context, obj *model.User) ([]*model.Emote, em.Name = emote.Name } - zw := emote.Emote.Flags&structures.EmoteFlagsZeroWidth != 0 + zw := emote.Emote.Flags.Value()&structures.EmoteFlagsZeroWidth != 0 if zw && !utils.BitField.HasBits(int64(obj.Permissions), int64(structures.RolePermissionFeatureZeroWidthEmoteType)) { continue // omit zero-width if unprivileged } @@ -107,7 +107,7 @@ func (r *Resolver) EmoteIds(ctx context.Context, obj *model.User) ([]string, err } if e.Emote != nil { - zw := e.Emote.Flags&structures.EmoteFlagsZeroWidth != 0 + zw := e.Emote.Flags.Value()&structures.EmoteFlagsZeroWidth != 0 if zw && !utils.BitField.HasBits(int64(obj.Permissions), int64(structures.RolePermissionFeatureZeroWidthEmoteType)) { continue // omit zero-width if unprivileged } diff --git a/internal/gql/v3/resolvers/emote/emote.ops.go b/internal/gql/v3/resolvers/emote/emote.ops.go index 0a7e741e..d342a15f 100644 --- a/internal/gql/v3/resolvers/emote/emote.ops.go +++ b/internal/gql/v3/resolvers/emote/emote.ops.go @@ -193,7 +193,7 @@ func (r *ResolverOps) Update(ctx context.Context, obj *model.EmoteOps, params mo } // Edit flags if params.Flags != nil { - f := structures.EmoteFlag(*params.Flags) + f := structures.BitField[structures.EmoteFlag](structures.EmoteFlag(*params.Flags)) eb.SetFlags(f) } diff --git a/internal/rest/v3/routes/emotes/emotes.create.go b/internal/rest/v3/routes/emotes/emotes.create.go index 8e5eaa51..24c719c9 100644 --- a/internal/rest/v3/routes/emotes/emotes.create.go +++ b/internal/rest/v3/routes/emotes/emotes.create.go @@ -19,7 +19,6 @@ import ( "github.com/seventv/common/structures/v3" "github.com/seventv/common/structures/v3/query" "github.com/seventv/common/svc/s3" - "github.com/seventv/common/utils" "github.com/seventv/image-processor/go/container" "github.com/seventv/image-processor/go/task" messagequeue "github.com/seventv/message-queue/go" @@ -114,7 +113,7 @@ func (r *create) Handler(ctx *rest.Ctx) rest.APIError { var ( name string tags []string - flags structures.EmoteFlag + flags structures.BitField[structures.EmoteFlag] ) // these validations are all "free" as in we can do them before we download the file they try to upload. @@ -137,11 +136,11 @@ func (r *create) Handler(ctx *rest.Ctx) rest.APIError { // Validate: Flags { if args.Flags != 0 { - if utils.BitField.HasBits(int64(args.Flags), int64(structures.EmoteFlagsPrivate)) { - flags |= structures.EmoteFlagsPrivate + if args.Flags.Has(structures.EmoteFlagsPrivate) { + flags.Set(structures.EmoteFlagsPrivate) } - if utils.BitField.HasBits(int64(args.Flags), int64(structures.EmoteFlagsZeroWidth)) { - flags |= structures.EmoteFlagsZeroWidth + if args.Flags.Has(structures.EmoteFlagsZeroWidth) { + flags.Set(structures.EmoteFlagsZeroWidth) } } } @@ -376,12 +375,12 @@ func (r *create) Handler(ctx *rest.Ctx) rest.APIError { } type createData struct { - Name string `json:"name"` - Description string `json:"description"` - ParentID *primitive.ObjectID `json:"parent_id"` - Diverged bool `json:"diverged"` - Tags []string `json:"tags"` - Flags structures.EmoteFlag `json:"flags"` + Name string `json:"name"` + Description string `json:"description"` + ParentID *primitive.ObjectID `json:"parent_id"` + Diverged bool `json:"diverged"` + Tags []string `json:"tags"` + Flags structures.BitField[structures.EmoteFlag] `json:"flags"` } var (