diff --git a/client/react-native/common/components/Screens/Chats/Detail.js b/client/react-native/common/components/Screens/Chats/Detail.js index de35809d0b..12883cb289 100644 --- a/client/react-native/common/components/Screens/Chats/Detail.js +++ b/client/react-native/common/components/Screens/Chats/Detail.js @@ -34,7 +34,7 @@ const Message = props => { isMyself ? textRight : textLeft, ]} > - {atob(props.data.attributes).trim()} + {JSON.parse(props.data.attributes).message.text} ) diff --git a/core/api/node/graphql/converts.go b/core/api/node/graphql/converts.go index bc757370e3..f8b5172360 100644 --- a/core/api/node/graphql/converts.go +++ b/core/api/node/graphql/converts.go @@ -184,6 +184,16 @@ func convertBytes(value *[]byte) *string { return &encoded } +func convertAttributes(e *p2p.Event) *string { + jsonBytes, err := e.GetJsonAttrs() + if err != nil { + logger().Error(err.Error()) + return nil + } + jsonString := string(jsonBytes) + return &jsonString +} + func convertEvent(event *p2p.Event) *model.BertyP2pEvent { if event == nil { return &model.BertyP2pEvent{} @@ -208,7 +218,7 @@ func convertEvent(event *p2p.Event) *model.BertyP2pEvent { ReceiverAPIVersion: convertUint32(event.ReceiverAPIVersion), ReceiverID: &event.ReceiverID, Kind: convertEventKind(event.Kind), - Attributes: convertBytes(&event.Attributes), + Attributes: convertAttributes(event), ConversationID: &conversationID, CreatedAt: &scalar.DateTime{Value: &event.CreatedAt}, UpdatedAt: &scalar.DateTime{Value: &event.UpdatedAt}, diff --git a/core/api/p2p/kind.go b/core/api/p2p/kind.go index 2bc11d4e90..21b9385614 100644 --- a/core/api/p2p/kind.go +++ b/core/api/p2p/kind.go @@ -1,6 +1,10 @@ package p2p -import "github.com/gogo/protobuf/proto" +import ( + "encoding/json" + + "github.com/gogo/protobuf/proto" +) func (e *Event) SetAttrs(attrs proto.Message) error { raw, err := proto.Marshal(attrs) @@ -10,3 +14,17 @@ func (e *Event) SetAttrs(attrs proto.Message) error { e.Attributes = raw return nil } + +func (e *Event) GetJsonAttrs() ([]byte, error) { + attrs, err := e.GetAttrs() + if err != nil { + return nil, err + } + + json, err := json.Marshal(attrs) + if err != nil { + return nil, err + } + + return json, nil +}