Commit 2b5b0939 authored by Boris Kocherov's avatar Boris Kocherov

erp5_web_jabber_client: fix messages loss, thx @cedric.leninivin

parent b2f63f39
......@@ -43,6 +43,30 @@
return gadget.state_parameter_dict.my_jid + '-' + jid;
}
function enqueueDefer(gadget, callback) {
var deferred = gadget.props.current_deferred;
// Unblock queue
if (deferred !== undefined) {
deferred.resolve("Another event added");
}
// Add next callback
try {
gadget.props.service_queue.push(callback);
} catch (error) {
throw new Error("Connection gadget already crashed... " +
gadget.props.service_queue.rejectedReason.toString());
}
// Block the queue
deferred = RSVP.defer();
gadget.props.current_deferred = deferred;
gadget.props.service_queue.push(function () {
return deferred.promise;
});
}
function getLog(gadget, jid, options) {
return wrapJioCall(gadget, 'getAttachment', [getStorageIdFromJid(gadget, jid), 'enclosure', options])
.push(undefined, function (error) {
......@@ -55,11 +79,21 @@
}
function addLog(gadget, jid, text, is_incoming) {
return getLog(gadget, jid, {format: 'text'})
.push(function (result) {
var new_history = result + getLogString(text, is_incoming);
return wrapJioCall(gadget, 'putAttachment', [getStorageIdFromJid(gadget, jid), 'enclosure', new_history]);
});
var deferred = RSVP.defer();
enqueueDefer(gadget, function () {
return getLog(gadget, jid, {format: 'text'})
.push(function (result) {
var new_history = result + getLogString(text, is_incoming);
return wrapJioCall(gadget, 'putAttachment', [getStorageIdFromJid(gadget, jid), 'enclosure', new_history]);
})
.push(function () {
deferred.resolve();
return true;
});
});
return new RSVP.Queue().push(function () {
return deferred.promise;
});
}
function dropConnectionGadget(gadget) {
......@@ -160,6 +194,9 @@
}
rJS(window)
.ready(function (g) {
g.props = {};
})
.allowPublicAcquisition("notifyXMPPConnecting", function () {
return;
......@@ -431,6 +468,22 @@
throw new Error('Unsupported putAttachment: ' + id + ' ' + name);
})
.declareService(function () {
// queue for addLog
var context = this;
context.props.service_queue = new RSVP.Queue();
enqueueDefer(context);
return new RSVP.Queue()
.push(function () {
return context.props.service_queue;
})
.push(function () {
throw new Error("Service should not have been stopped!");
});
})
.declareService(function () {
return loopEventListener(
window,
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>949.36462.22852.4232</string> </value>
<value> <string>949.57481.62457.42496</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1457082886.14</float>
<float>1458172700.61</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment