Skip to content

Commit

Permalink
fix(relay): refetch entities that has been removed by relay when update
Browse files Browse the repository at this point in the history
Signed-off-by: Godefroy Ponsinet <godefroy.ponsinet@outlook.com>
  • Loading branch information
90dy committed Dec 21, 2018
1 parent 08a4991 commit 4168ae8
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 52 deletions.
93 changes: 49 additions & 44 deletions client/react-native/common/components/Screens/Chats/Detail.js
Expand Up @@ -218,51 +218,56 @@ class Input extends PureComponent {
}
}

class Chat extends PureComponent {
render () {
const {
data,
navigation,
screenProps: {
context: { queries, subscriptions, fragments },
},
} = this.props
return (
<Flex.Rows>
<Pagination
style={[{ flex: 1 }, Platform.OS === 'web' ? { paddingTop: 48 } : {}]}
direction='forward'
query={queries.EventList.graphql}
variables={merge([
queries.EventList.defaultVariables,
{
filter: {
kind: 302,
conversationId: data.Conversation.id,
const Chat = fragments.Conversation(
class Chat extends PureComponent {
render () {
const {
data,
navigation,
screenProps: {
context: { queries, subscriptions, fragments },
},
} = this.props
return (
<Flex.Rows>
<Pagination
style={[
{ flex: 1 },
Platform.OS === 'web' ? { paddingTop: 48 } : {},
]}
direction='forward'
query={queries.EventList.graphql}
variables={merge([
queries.EventList.defaultVariables,
{
filter: {
kind: 302,
conversationId: data.id,
},
},
},
])}
subscriptions={[subscriptions.message]}
fragment={fragments.EventList}
alias='EventList'
renderItem={props => (
<MessageContainer
{...props}
navigation={navigation}
screenProps={this.props.screenProps}
conversation={data.Conversation}
/>
)}
inverted
/>
<Input
navigation={this.props.navigation}
screenProps={this.props.screenProps}
/>
</Flex.Rows>
)
])}
subscriptions={[subscriptions.message]}
fragment={fragments.EventList}
alias='EventList'
renderItem={props => (
<MessageContainer
{...props}
navigation={navigation}
screenProps={this.props.screenProps}
conversation={data}
/>
)}
inverted
/>
<Input
navigation={this.props.navigation}
screenProps={this.props.screenProps}
/>
</Flex.Rows>
)
}
}
}
)

export default class Detail extends PureComponent {
static navigationOptions = ({ navigation }) => ({
Expand Down Expand Up @@ -315,7 +320,7 @@ export default class Detail extends PureComponent {
<Chat
navigation={navigation}
screenProps={this.props.screenProps}
data={state.data}
data={state.data.Conversation}
/>
)
case state.error:
Expand Down
Expand Up @@ -17,7 +17,6 @@ const Item = fragments.Contact(
context,
} = this.props

status === 4 && console.log(this.props.data)
if (
[
enums.BertyEntityContactInputStatus.IsRequested,
Expand Down
2 changes: 1 addition & 1 deletion client/react-native/common/graphql/queries/Conversation.js
Expand Up @@ -22,6 +22,7 @@ const query = graphql`
topic: $topic
members: $members
) {
...Conversation
id
createdAt
updatedAt
Expand Down Expand Up @@ -56,7 +57,6 @@ const query = graphql`
conversationId
contactId
}
...Conversation
}
}
`
Expand Down
2 changes: 2 additions & 0 deletions client/react-native/common/graphql/subscriptions/Contact.js
Expand Up @@ -10,6 +10,8 @@ export default context => ({
]
if (entity != null) {
updater(store, entity, operation === 2)
operation !== 2 &&
context.queries.Contact.fetch({ filter: { id: entity.id } })
}
}),
}),
Expand Down
Expand Up @@ -10,6 +10,8 @@ export default context => ({
]
if (entity != null) {
updater(store, entity, operation === 2)
operation !== 2 &&
context.queries.Conversation.fetch({ id: entity.id })
}
}),
}),
Expand Down
9 changes: 4 additions & 5 deletions core/cmd/berty/daemon.go
Expand Up @@ -8,15 +8,14 @@ import (
"os"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"

"berty.tech/core/manager/account"
"berty.tech/core/network/p2p"
"berty.tech/core/pkg/banner"
"berty.tech/core/pkg/logmanager"
"berty.tech/core/pkg/notification"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)

type daemonOptions struct {
Expand Down Expand Up @@ -62,7 +61,7 @@ func daemonSetupFlags(flags *pflag.FlagSet, opts *daemonOptions) {
flags.StringSliceVar(&opts.bootstrap, "bootstrap", p2p.DefaultBootstrap, "boostrap peers")
flags.StringSliceVar(&opts.bindP2P, "bind-p2p", []string{"/ip4/0.0.0.0/tcp/0", "/ble/00000000-0000-0000-0000-000000000000"}, "p2p listening address")
// flags.StringSliceVar(&opts.bindP2P, "bind-p2p", []string{"/ip4/0.0.0.0/tcp/0"}, "p2p listening address")
flags.StringSliceVar(&opts.transportP2P, "transport-p2p", []string{"default", "ble"}, "p2p transport to enable")
flags.StringSliceVar(&opts.transportP2P, "transport-p2p", []string{"default" /*, "ble"*/}, "p2p transport to enable")
_ = viper.BindPFlags(flags)
}

Expand Down
9 changes: 8 additions & 1 deletion core/node/sql.go
Expand Up @@ -8,6 +8,7 @@ import (
"berty.tech/core/api/node"
"berty.tech/core/api/p2p"
"berty.tech/core/entity"
"berty.tech/core/sql"
"github.com/jinzhu/gorm"
opentracing "github.com/opentracing/opentracing-go"
"go.uber.org/zap"
Expand All @@ -16,7 +17,7 @@ import (
// WithSQL registers a gorm connection as the node database
func WithSQL(sql *gorm.DB) NewNodeOption {
return func(n *Node) {
n.sqlDriver = sql.Unscoped()
n.sqlDriver = sql.Set("gorm:auto_preload", true).Unscoped()
sql.Callback().Create().Register("berty:after_create", func(scope *gorm.Scope) { n.handleCommitLog("create", scope) })
sql.Callback().Update().Register("berty:after_update", func(scope *gorm.Scope) { n.handleCommitLog("update", scope) })
sql.Callback().Delete().Register("berty:after_delete", func(scope *gorm.Scope) { n.handleCommitLog("delete", scope) })
Expand Down Expand Up @@ -92,10 +93,16 @@ func (n *Node) createCommitLog(operation string, reflectValue reflect.Value) *no

switch data := reflectValue.Interface().(type) {
case *entity.Contact:
if operation != "delete" {
data, _ = sql.ContactByID(n.sqlDriver, data.ID)
}
log.Entity = &node.CommitLog_Entity{Contact: data}
case *entity.Device:
log.Entity = &node.CommitLog_Entity{Device: data}
case *entity.Conversation:
if operation != "delete" {
data, _ = sql.ConversationByID(n.sqlDriver, data.ID)
}
log.Entity = &node.CommitLog_Entity{Conversation: data}
case *entity.ConversationMember:
log.Entity = &node.CommitLog_Entity{ConversationMember: data}
Expand Down

0 comments on commit 4168ae8

Please sign in to comment.