|
| 1 | +/* |
| 2 | + * Fractale - Self-organisation for humans. |
| 3 | + * Copyright (C) 2022 Fractale Co |
| 4 | + * |
| 5 | + * This file is part of Fractale. |
| 6 | + * |
| 7 | + * This program is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU Affero General Public License as |
| 9 | + * published by the Free Software Foundation, either version 3 of the |
| 10 | + * License, or (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU Affero General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Affero General Public License |
| 18 | + * along with Fractale. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +package graph |
| 22 | + |
| 23 | +import ( |
| 24 | + //"fmt" |
| 25 | + "context" |
| 26 | + "strings" |
| 27 | + "strconv" |
| 28 | + "github.com/99designs/gqlgen/graphql" |
| 29 | + "fractale/fractal6.go/graph/model" |
| 30 | + "fractale/fractal6.go/web/auth" |
| 31 | + . "fractale/fractal6.go/tools" |
| 32 | +) |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +func addReactionInputHook(ctx context.Context, obj interface{}, next graphql.Resolver) (interface{}, error) { |
| 37 | + // Get User context |
| 38 | + ctx, uctx, err := auth.GetUserContext(ctx) |
| 39 | + if err != nil { return nil, LogErr("Access denied", err) } |
| 40 | + |
| 41 | + data, err := next(ctx) |
| 42 | + if err != nil { |
| 43 | + return data, err |
| 44 | + } |
| 45 | + |
| 46 | + // Move pendingCandidate to candidate if email exists in User |
| 47 | + newData := data.([]*model.AddReactionInput) |
| 48 | + for i, input := range newData { |
| 49 | + ids := []string{uctx.Username, *input.Comment.ID, strconv.Itoa(input.Type)} |
| 50 | + reactionid := strings.Join(ids, "#") |
| 51 | + input.Reactionid = &reactionid |
| 52 | + newData[i] = input |
| 53 | + } |
| 54 | + |
| 55 | + return newData, err |
| 56 | +} |
0 commit comments