aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-04-07 19:43:15 -0700
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-04-08 20:15:45 -0700
commitb476d6c52bb634a3aa4dbe2c2e05b61686091e2e (patch)
tree53c3bfd43fe356a74a0700d802a407d60f148963
parentb4baab7d6b401c182f31fb65b5d13c42e98fd4d4 (diff)
downloadpatchfoo-b476d6c52bb634a3aa4dbe2c2e05b61686091e2e.tar.gz
patchfoo-b476d6c52bb634a3aa4dbe2c2e05b61686091e2e.zip
Retry publish on "expected previous" error
-rw-r--r--lib/app.js24
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/app.js b/lib/app.js
index 25cb02c..6314284 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -100,12 +100,26 @@ App.prototype.getMsgDecrypted = function (key, cb) {
}
App.prototype.publish = function (content, cb) {
- if (Array.isArray(content.recps)) {
- recps = content.recps.map(u.linkDest)
- this.sbot.private.publish(content, recps, cb)
- } else {
- this.sbot.publish(content, cb)
+ var self = this
+ function tryPublish(triesLeft) {
+ if (Array.isArray(content.recps)) {
+ recps = content.recps.map(u.linkDest)
+ self.sbot.private.publish(content, recps, next)
+ } else {
+ self.sbot.publish(content, next)
+ }
+ function next(err, msg) {
+ if (err) {
+ if (triesLeft > 0) {
+ if (/^expected previous:/.test(err.message)) {
+ return tryPublish(triesLeft-1)
+ }
+ }
+ }
+ return cb(err, msg)
+ }
}
+ tryPublish(2)
}
App.prototype.addBlob = function (cb) {