Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions data/model/emote-set.model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions data/model/emote.model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions data/model/user.gql.model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -48,6 +53,7 @@ func (xm UserPartialModel) GQL() *model.UserPartial {
CreatedAt: xm.ID.Timestamp(),
Style: xm.Style.GQL(),
Roles: xm.RoleIDs,
Connections: connections,
}
}

Expand Down
18 changes: 10 additions & 8 deletions data/model/user.model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -156,6 +157,7 @@ func (um UserModel) ToPartial() UserPartialModel {
Style: um.Style,
DisplayName: um.DisplayName,
RoleIDs: um.RoleIDs,
Connections: um.Connections,
}
}

Expand Down
2 changes: 1 addition & 1 deletion data/mutate/emote.mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
Expand Down
6 changes: 3 additions & 3 deletions data/mutate/emote_set.active_emote.mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion data/mutate/emote_set.create.mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions internal/gql/v2/helpers/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/gql/v2/resolvers/mutation/mutation.emote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions internal/gql/v2/resolvers/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/gql/v3/resolvers/emote/emote.ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
23 changes: 11 additions & 12 deletions internal/rest/v3/routes/emotes/emotes.create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand All @@ -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)
}
}
}
Expand Down Expand Up @@ -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 (
Expand Down