Skip to content

Commit

Permalink
fix(rn): update conversation
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 11, 2018
1 parent 94d34b5 commit 02b784e
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.concurrent.Future;
import java.util.concurrent.Semaphore;

import core.Core;
////import core.Core;

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public class BertyDevice {
Expand Down Expand Up @@ -71,7 +71,7 @@ public void run() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
try {
latchRdy.await();
Core.addToPeerStore(peerID, ma);
//// Core.addToPeerStore(peerID, ma);
} catch (Exception e) {
BertyUtils.logger("error", TAG, "waiting/writing failed: " + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.nio.charset.Charset;
import java.util.UUID;

import core.Core;
////import core.Core;

import static android.bluetooth.BluetoothGatt.GATT_FAILURE;
import static android.bluetooth.BluetoothGatt.GATT_SUCCESS;
Expand Down Expand Up @@ -164,7 +164,7 @@ public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId,
BertyDevice bDevice = BertyUtils.getDeviceFromAddr(device.getAddress());
if (charID.equals(BertyUtils.WRITER_UUID)) {
BertyUtils.logger("debug", TAG, "rep needed: " + responseNeeded + "prepared: " + preparedWrite + " transid: " + requestId + " offset: " + offset + " len: " + value.length);
Core.bytesToConn(bDevice.ma, value);
//// Core.bytesToConn(bDevice.ma, value);
if (responseNeeded) {
mBluetoothGattServer.sendResponse(device, requestId, GATT_SUCCESS, offset, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static android.bluetooth.BluetoothGattCharacteristic.PROPERTY_WRITE;
import static android.bluetooth.BluetoothGattService.SERVICE_TYPE_PRIMARY;

import core.Core;
////import core.Core;

@SuppressLint("LongLogTag")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
Expand All @@ -40,7 +40,7 @@ public class BertyUtils {
private static final String TAG = "utils";

public static void logger(String level, String tag, String log) {
Core.goLogger(tag, level, log);
//// Core.goLogger(tag, level, log);
}

public String ma;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class List extends PureComponent {

componentDidMount () {
this.props.screenProps.context.queries.AppVersion.fetch().then(data => {
this.setState({ version: data.AppVersion.version })
this.setState({ version: data.version })
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class DeviceInfos extends PureComponent {
this.setState({ refreshing: true }, async () => {
console.log(queries)
const data = await queries.DeviceInfos.fetch()
this.setState({ infos: data.DeviceInfos.infos, refreshing: false })
this.setState({ infos: data.infos, refreshing: false })
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default class Peers extends Component {

fetchPeers = () => {
this.props.screenProps.context.queries.Peers.fetch().then(data =>
this.updatePeers(data.Peers.list)
this.updatePeers(data.list)
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { btoa } from 'b64-lite'

import { parseEmbedded } from '../../helpers/json'
import { queries } from '..'
import EventStream from './EventStream'

export default context => ({
Expand All @@ -12,12 +8,9 @@ export default context => ({
updater &&
(async (store, data) => {
if (data.EventStream.kind === 301) {
const attributes = parseEmbedded(data.EventStream.attributes)
attributes.conversation.id = btoa(
'conversation:' + attributes.conversation.id
)
const conversation = await queries(context).Conversation.fetch({
id: attributes.conversation.id,
console.log(data.EventStream)
const conversation = await context.queries.Conversation.fetch({
id: data.EventStream.conversationId,
})

console.log('ConversationInvite: conversation: ', conversation)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import EventStream from './EventStream'
import { queries } from '..'

export default context => ({
...EventStream(context),
Expand All @@ -9,7 +8,7 @@ export default context => ({
updater &&
(async (store, data) => {
if (data.EventStream.kind === 302) {
const conversation = await queries(context).Conversation.fetch({
const conversation = await context.queries.Conversation.fetch({
id: data.EventStream.conversationId,
})
console.log('ConversationNewMessage: conversation:', conversation)
Expand Down
17 changes: 12 additions & 5 deletions client/react-native/common/relay/genericUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,26 @@ export default (fragment, alias, args) => {
ConnectionHandler.deleteNode(connection, data.id)
return
}
console.log(args)

// get all edges
const node =
store.get(data.id) ||
store.create(data.id, connectionHelper.getEdgeNodeType())
console.log('node', node)
const edges = connection.getLinkedRecords('edges')
const field = Case.camel(args.orderBy || args.sortBy || 'id')
const cursor =
field === 'id' ? atob(data.id).split(/:(.+)/)[1] : data[field]
field === 'id'
? atob(node.getValue('id')).split(/:(.+)/)[1]
: node.getValue(field)
console.log('cursor', cursor)
if (edges.length > 0 && edges.some(e => e.getValue('cursor') === cursor)) {
// update
return
}

console.log('add connection', { connection })
// add
const node =
store.get(data.id) ||
store.create(data.id, connectionHelper.getEdgeNodeType())
const edge = ConnectionHandler.createEdge(
store,
connection,
Expand All @@ -71,9 +76,11 @@ export default (fragment, alias, args) => {
edge.setValue(cursor, 'cursor')

if (connectionHelper.direction === 'forward' && args.orderDesc === false) {
console.log('forward')
ConnectionHandler.insertEdgeAfter(connection, edge, cursor)
return
}
console.log('backward')
ConnectionHandler.insertEdgeBefore(connection, edge, cursor)
}
}
16 changes: 8 additions & 8 deletions core/node/nodeapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ func (n *Node) GetEvent(ctx context.Context, input *gql.Node) (*p2p.Event, error
n.handleMutex(ctx)()

sql := n.sql(ctx)
var event *p2p.Event
if err := sql.First(event, "ID = ?", input.ID).Error; err != nil {
event := &p2p.Event{}
if err := sql.Where(input).First(event).Error; err != nil {
return nil, errorcodes.ErrDbNothingFound.Wrap(err)
}

Expand Down Expand Up @@ -337,8 +337,8 @@ func (n *Node) GetContact(ctx context.Context, input *gql.Node) (*entity.Contact
n.handleMutex(ctx)()

sql := n.sql(ctx)
var contact *entity.Contact
if err := sql.First(contact, "ID = ?", input.ID).Error; err != nil {
contact := &entity.Contact{}
if err := sql.Where(input).First(contact).Error; err != nil {
return nil, errorcodes.ErrDb.Wrap(err)
}

Expand Down Expand Up @@ -517,8 +517,8 @@ func (n *Node) GetConversation(ctx context.Context, input *gql.Node) (*entity.Co
n.handleMutex(ctx)()

sql := n.sql(ctx)
var conversation *entity.Conversation
if err := sql.First(conversation, "ID = ?", input.ID).Error; err != nil {
conversation := &entity.Conversation{}
if err := sql.Where(input).First(conversation).Error; err != nil {
return nil, errorcodes.ErrDbNothingFound.Wrap(err)
}

Expand All @@ -533,8 +533,8 @@ func (n *Node) GetConversationMember(ctx context.Context, input *gql.Node) (*ent
n.handleMutex(ctx)()

sql := n.sql(ctx)
var conversationMember *entity.ConversationMember
if err := sql.First(conversationMember, "ID = ?", input.ID).Error; err != nil {
conversationMember := &entity.ConversationMember{}
if err := sql.Where(input).First(conversationMember).Error; err != nil {
return nil, errorcodes.ErrDbNothingFound.Wrap(err)
}

Expand Down

0 comments on commit 02b784e

Please sign in to comment.