From b476d6c52bb634a3aa4dbe2c2e05b61686091e2e Mon Sep 17 00:00:00 2001 From: cel Date: Fri, 7 Apr 2017 19:43:15 -0700 Subject: Retry publish on "expected previous" error --- lib/app.js | 24 +++++++++++++++++++----- 1 file 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) { -- cgit v1.2.3