diff options
-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) { |