Add admin-only private chat messages and message deletion
Deploy with Docker Compose / deploy (push) Successful in 58s
Deploy with Docker Compose / deploy (push) Successful in 58s
Admins can flag a chat message as private so only other admin connections receive it, and can delete any message. Admin status is read from the auth cookies on the WebSocket upgrade request. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
@@ -118,6 +118,7 @@ type ComplexityRoot struct {
|
||||
CreatedAt func(childComplexity int) int
|
||||
FileURL func(childComplexity int) int
|
||||
ID func(childComplexity int) int
|
||||
Private func(childComplexity int) int
|
||||
}
|
||||
|
||||
Mutation struct {
|
||||
@@ -641,6 +642,12 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
|
||||
}
|
||||
|
||||
return e.ComplexityRoot.Message.ID(childComplexity), true
|
||||
case "Message.private":
|
||||
if e.ComplexityRoot.Message.Private == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.ComplexityRoot.Message.Private(childComplexity), true
|
||||
|
||||
case "Mutation.createActivity":
|
||||
if e.ComplexityRoot.Mutation.CreateActivity == nil {
|
||||
@@ -1559,6 +1566,8 @@ func (ec *executionContext) childFields_Message(ctx context.Context, field graph
|
||||
return ec.fieldContext_Message_authorId(ctx, field)
|
||||
case "fileUrl":
|
||||
return ec.fieldContext_Message_fileUrl(ctx, field)
|
||||
case "private":
|
||||
return ec.fieldContext_Message_private(ctx, field)
|
||||
case "createdAt":
|
||||
return ec.fieldContext_Message_createdAt(ctx, field)
|
||||
}
|
||||
@@ -3350,6 +3359,29 @@ func (ec *executionContext) fieldContext_Message_fileUrl(_ context.Context, fiel
|
||||
return graphql.NewScalarFieldContext("Message", field, false, false, errors.New("field of type String does not have child fields"))
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Message_private(ctx context.Context, field graphql.CollectedField, obj *models.Message) (ret graphql.Marshaler) {
|
||||
return graphql.ResolveField(
|
||||
ctx,
|
||||
ec.OperationContext,
|
||||
field,
|
||||
func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
||||
return ec.fieldContext_Message_private(ctx, field)
|
||||
},
|
||||
func(ctx context.Context) (any, error) {
|
||||
return obj.Private, nil
|
||||
},
|
||||
nil,
|
||||
func(ctx context.Context, selections ast.SelectionSet, v bool) graphql.Marshaler {
|
||||
return ec.marshalNBoolean2bool(ctx, selections, v)
|
||||
},
|
||||
true,
|
||||
true,
|
||||
)
|
||||
}
|
||||
func (ec *executionContext) fieldContext_Message_private(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||
return graphql.NewScalarFieldContext("Message", field, false, false, errors.New("field of type Boolean does not have child fields"))
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Message_createdAt(ctx context.Context, field graphql.CollectedField, obj *models.Message) (ret graphql.Marshaler) {
|
||||
return graphql.ResolveField(
|
||||
ctx,
|
||||
@@ -8595,6 +8627,11 @@ func (ec *executionContext) _Message(ctx context.Context, sel ast.SelectionSet,
|
||||
if out.Values[i] == graphql.RequiredNull {
|
||||
atomic.AddUint32(&out.Invalids, 1)
|
||||
}
|
||||
case "private":
|
||||
out.Values[i] = ec._Message_private(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
atomic.AddUint32(&out.Invalids, 1)
|
||||
}
|
||||
case "createdAt":
|
||||
out.Values[i] = ec._Message_createdAt(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
|
||||
@@ -24,7 +24,11 @@ func (r *messageResolver) AuthorID(ctx context.Context, obj *models.Message) (in
|
||||
// Messages is the resolver for the messages field.
|
||||
func (r *queryResolver) Messages(ctx context.Context) ([]*models.Message, error) {
|
||||
var messages []models.Message
|
||||
if err := r.Store.DB.Order("created_at DESC").Find(&messages).Error; err != nil {
|
||||
query := r.Store.DB.Order("created_at DESC")
|
||||
if !IsAdminFromCtx(ctx) {
|
||||
query = query.Where("private = ?", false)
|
||||
}
|
||||
if err := query.Find(&messages).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]*models.Message, len(messages))
|
||||
|
||||
@@ -3,6 +3,7 @@ type Message {
|
||||
content: String!
|
||||
authorId: Int!
|
||||
fileUrl: String
|
||||
private: Boolean!
|
||||
createdAt: Time!
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user