Fix lost group chat messages
@@ -1247,6 +1247,23 @@ WonMessage.prototype = {
"@type": type,
})
.then(result => {
+ const graphs = result["@graph"];
+ if (graphs && graphs.length > 1) {
+ const msgUri = that.getMessageUri();
+ const msgGraphIndex = graphs.findIndex(
+ elem => elem["@id"] === msgUri
+ );
+ if (msgGraphIndex != 0 && msgGraphIndex != -1) {
+ let newGraphs = [];
+ newGraphs.push(graphs[msgGraphIndex]);
+ result["@graph"] = newGraphs.concat(
+ graphs.filter(elem => elem["@id"] === msgUri)
+ );
+
+ that.framedMessage = result;
+ return result;
+ }
+ }
that.framedMessage = result;
return result;
});
@@ -1257,7 +1274,14 @@ WonMessage.prototype = {
},
getProperty: function(property) {
- let val = this.__getFramedMessage()["@graph"][0][property];
+ const framedMsgGraphs = this.__getFramedMessage()["@graph"];
+ framedMsgGraphs &&
+ framedMsgGraphs.length > 1 &&
+ console.warn(
+ "framedMessage contains more than one graph!, ",
+ framedMsgGraphs
+ );
+ let val = framedMsgGraphs[0][property];
if (val) {
return this.__singleValueOrArray(val);
}
@@ -1271,7 +1295,15 @@ WonMessage.prototype = {
}
},
getPropertyFromRemoteMessage: function(property) {
- const remoteMessage = this.__getFramedMessage()["@graph"][0][
+ const framedMsgGraphs = this.__getFramedMessage()["@graph"];
+ framedMsgGraphs &&
+ framedMsgGraphs.length > 1 &&
+ console.warn(
+ "framedMessage contains more than one graph!, ",
+ framedMsgGraphs
+ );
+ const remoteMessage =
+ framedMsgGraphs[0][
"http://purl.org/webofneeds/message#hasCorrespondingRemoteMessage"
];
if (remoteMessage) {
@@ -1338,6 +1370,37 @@ WonMessage.prototype = {
return createArray(
this.getProperty("http://purl.org/webofneeds/message#hasForwardedMessage")
);
+ /*let uris;
+ let val = this.__getFramedMessage()["@graph"][0]["http://purl.org/webofneeds/message#hasForwardedMessage"];
+ if (val) {
+ uris = this.__singleValueOrArray(val);
+ } else {
+ const remoteMessage = this.__getFramedMessage()["@graph"][0]["http://purl.org/webofneeds/message#hasCorrespondingRemoteMessage"];
+ if (remoteMessage) {
+ val = remoteMessage["http://purl.org/webofneeds/message#hasForwardedMessage"];
+ if (val) {
+ uris = this.__singleValueOrArray(val);
+ }
+ }
+ }
+
+ if(uris) {
+ return createArray(uris);
+ }
+ val = this.__getFramedMessage()["@graph"][1]["http://purl.org/webofneeds/message#hasForwardedMessage"];
+ if (val) {
+ uris = this.__singleValueOrArray(val);
+ } else {
+ const remoteMessage2 = this.__getFramedMessage()["@graph"][1]["http://purl.org/webofneeds/message#hasCorrespondingRemoteMessage"];
+ if (remoteMessage2) {
+ val = remoteMessage2["http://purl.org/webofneeds/message#hasForwardedMessage"];
+ if (val) {
+ uris = this.__singleValueOrArray(val);
+ }
+ }
+ }
+
+ return createArray(uris); */
},
getReceivedTimestamp: function() {
return this.getPropertyFromLocalMessage(
