Skip to content

Commit

Permalink
fix(node): graphql resolver on event target addr
Browse files Browse the repository at this point in the history
Signed-off-by: Godefroy Ponsinet <godefroy.ponsinet@outlook.com>
  • Loading branch information
90dy authored and moul committed Mar 22, 2019
1 parent 237f9dd commit 7983568
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 88 deletions.
4 changes: 2 additions & 2 deletions client/react-native/common/schema.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions core/api/node/graphql/gqlgen.gen.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 15 additions & 9 deletions core/api/node/graphql/graph/generated/generated.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 42 additions & 3 deletions core/api/node/graphql/resolver.go
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -141,7 +142,33 @@ func (r *bertyEntityEventResolver) ID(ctx context.Context, obj *entity.Event) (s
}

func (r *bertyEntityEventResolver) TargetAddr(ctx context.Context, obj *entity.Event) (string, error) {
return "conversation:" + obj.TargetAddr, nil
kindStr := obj.Kind.String()

ok, err := regexp.MatchString("^Contact.*", kindStr)
if err != nil {
return "", err
}
if ok {
return "contact:" + obj.TargetAddr, nil
}

ok, err = regexp.MatchString("^Conversation.*", kindStr)
if err != nil {
return "", err
}
if ok {
return "conversation:" + obj.TargetAddr, nil
}

ok, err = regexp.MatchString("^Device.*", kindStr)
if err != nil {
return "", err
}
if ok {
return "device:" + obj.TargetAddr, nil
}

return obj.TargetAddr, nil
}

func (r *bertyEntityEventResolver) Attributes(ctx context.Context, obj *entity.Event) ([]byte, error) {
Expand Down Expand Up @@ -404,7 +431,13 @@ func (r *queryResolver) EventList(ctx context.Context, filter *entity.Event, raw
filter.ID = strings.SplitN(filter.ID, ":", 2)[1]
}
if filter.TargetAddr != "" {
filter.TargetAddr = strings.SplitN(filter.TargetAddr, ":", 2)[1]
ok, err := regexp.MatchString("^(contact|conversation|device):.*", filter.TargetAddr)
if err != nil {
return nil, err
}
if ok {
filter.TargetAddr = strings.SplitN(filter.TargetAddr, ":", 2)[1]
}
}
}

Expand Down Expand Up @@ -501,7 +534,13 @@ func (r *queryResolver) EventUnseen(ctx context.Context, filter *entity.Event, r
filter.ID = strings.SplitN(filter.ID, ":", 2)[1]
}
if filter.TargetAddr != "" {
filter.TargetAddr = strings.SplitN(filter.TargetAddr, ":", 2)[1]
ok, err := regexp.MatchString("^(contact|conversation|device):.*", filter.TargetAddr)
if err != nil {
return nil, err
}
if ok {
filter.TargetAddr = strings.SplitN(filter.TargetAddr, ":", 2)[1]
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/api/node/graphql/service.gen.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

140 changes: 70 additions & 70 deletions core/entity/event.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/entity/event.proto
Expand Up @@ -81,7 +81,7 @@ message Event {
TargetType target_type = 20;

// TragetAddr can be a contact ID, a conversation ID, a device ID
string target_addr = 21;
string target_addr = 21 [(gql.graphql_id) = true];

// Metadata represents additional metadata and is not stored in database
repeated MetadataKeyValue metadata = 99 [(gogoproto.moretags) = "gorm:\"-\""];
Expand Down

0 comments on commit 7983568

Please sign in to comment.