Dispatching event along with connections.connect.
@@ -6,6 +6,8 @@ import won from '../won-es6';
import Immutable from 'immutable';
+import jsonld from 'jsonld'; //import *after* the rdfstore to shadow its custom jsonld
+
import { getRandomPosInt } from '../utils';
import {
@@ -25,6 +27,8 @@ import {
is,
urisToLookupMap,
msStringToDate,
+ getIn,
+ jsonld2simpleFormat,
} from '../utils';
import {
@@ -126,26 +130,38 @@ export function connectionsConnect(connectionUri,message) {
return (dispatch, getState) => {
const state = getState();
const eventData = selectAllByConnections(state).get(connectionUri).toJS(); // TODO avoid toJS;
- //let eventData = state.getIn(['connections', 'connectionsDeprecated', connectionData.connection.uri])
- let messageData = null;
- let deferred = Q.defer();
- won.getConnectionWithEventUris(eventData.connection.uri).then(connection=> {
+ const messageDataP = won
+ .getConnectionWithEventUris(eventData.connection.uri)
+ .then(connection=> {
let msgToOpenFor = {event: eventData, connection: connection};
- buildConnectMessage(msgToOpenFor, message).then(messageData=> {
- deferred.resolve(messageData);
- })
+ return buildConnectMessage(msgToOpenFor, message)
});
- deferred.promise.then((action)=> {
+ messageDataP.then((action)=> {
dispatch(actionCreators.messages__send({eventUri: action.eventUri, message: action.message}));
+
+ jsonld.promises.frame(
+ action.message,
+ {
+ '@id': action.eventUri,
+ '@context': action.message['@context']
+ }
+ ).then(framed => {
+ let event = getIn(framed, ['@graph', 0]);
+ if(event) {
+ event['@context'] = framed['@context']; // context is needed by jsonld2simpleFormat for expanding prefixes in values
+ event = jsonld2simpleFormat(event);
+ }
+
dispatch({
type: actionTypes.connections.connect,
payload: {
connectionUri,
message,
eventUri: action.eventUri,
- event: action.message,
+ event: event,
}
});
+ });
})
}
}
