diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-04-07 19:43:15 -0700 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-04-08 20:15:45 -0700 |
commit | b476d6c52bb634a3aa4dbe2c2e05b61686091e2e (patch) | |
tree | 53c3bfd43fe356a74a0700d802a407d60f148963 | |
parent | b4baab7d6b401c182f31fb65b5d13c42e98fd4d4 (diff) | |
download | patchfoo-b476d6c52bb634a3aa4dbe2c2e05b61686091e2e.tar.gz patchfoo-b476d6c52bb634a3aa4dbe2c2e05b61686091e2e.zip |
Retry publish on "expected previous" error
-rw-r--r-- | lib/app.js | 24 |
1 files changed, 19 insertions, 5 deletions
@@ -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) { |