Reject messenger.init: cloud connection failed

- messenger.init() is now rejected when connection to cloud fails (ie, direct, group or pipeline connections)
This commit is contained in:
sairajzero 2023-02-12 02:30:03 +05:30
parent afd9b733cd
commit 450e193dad

View File

@ -39,7 +39,7 @@
}, },
marked: { marked: {
set: ui_fn => UI.marked = ui_fn set: ui_fn => UI.marked = ui_fn
}, }
}); });
const _loaded = {}; const _loaded = {};
@ -461,12 +461,16 @@
console.debug(newInbox); console.debug(newInbox);
UI.direct(newInbox) UI.direct(newInbox)
} }
floCloudAPI.requestApplicationData(null, { return new Promise((resolve, reject) => {
receiverID: user.id, floCloudAPI.requestApplicationData(null, {
lowerVectorClock: _loaded.appendix.lastReceived + 1, receiverID: user.id,
callback: callbackFn lowerVectorClock: _loaded.appendix.lastReceived + 1,
}).then(conn_id => directConnID = conn_id) callback: callbackFn
.catch(error => console.error("request-direct:", error)); }).then(conn_id => {
directConnID = conn_id;
resolve("Direct Inbox connected");
}).catch(error => reject(error))
})
} }
messenger.getMail = function (mailRef) { messenger.getMail = function (mailRef) {
@ -952,7 +956,7 @@
} }
} }
function requestGroupInbox(groupID) { function requestGroupInbox(groupID, _async = true) {
if (groupConnID[groupID]) { //close existing request connection (if any) if (groupConnID[groupID]) { //close existing request connection (if any)
floCloudAPI.closeRequest(groupConnID[groupID]); floCloudAPI.closeRequest(groupConnID[groupID]);
delete groupConnID[groupID]; delete groupConnID[groupID];
@ -988,13 +992,22 @@
console.debug(newInbox); console.debug(newInbox);
UI.group(newInbox); UI.group(newInbox);
} }
floCloudAPI.requestApplicationData(null, { let fn = floCloudAPI.requestApplicationData(null, {
receiverID: groupID, receiverID: groupID,
lowerVectorClock: _loaded.appendix[`lastReceived_${groupID}`] + 1, lowerVectorClock: _loaded.appendix[`lastReceived_${groupID}`] + 1,
callback: callbackFn callback: callbackFn
}).then(conn_id => groupConnID[groupID] = conn_id) });
.catch(error => console.error(`request-group(${groupID}):`, error)) if (_async) {
fn.then(conn_id => groupConnID[groupID] = conn_id)
.catch(error => console.error(`request-group(${groupID}):`, error))
} else {
return new Promise((resolve, reject) => {
fn.then(conn_id => {
groupConnID[groupID] = conn_id;
resolve(`Connected to group ${groupID}`);
}).catch(error => reject(error))
});
}
} }
//messenger startups //messenger startups
@ -1016,16 +1029,19 @@
UI.mails(data.mails); UI.mails(data.mails);
UI.marked(data.marked); UI.marked(data.marked);
//request data from cloud //request data from cloud
requestDirectInbox(); let promises = [];
promises.push(requestDirectInbox());
for (let g in data.groups) for (let g in data.groups)
if (data.groups[g].disabled !== true) if (data.groups[g].disabled !== true)
requestGroupInbox(g); promises.push(requestGroupInbox(g, false));
for (let p in data.pipeline) for (let p in data.pipeline)
if (data.pipeline[p].disabled !== true) if (data.pipeline[p].disabled !== true)
requestPipelineInbox(p, data.pipeline[p].model); promises.push(requestPipelineInbox(p, data.pipeline[p].model, false));
loadDataFromBlockchain() loadDataFromBlockchain().then(result => {
.then(result => resolve("Messenger initiated")) Promise.all(promises)
.catch(error => reject(error)) .then(result => resolve("Messenger initiated"))
.catch(error => reject(error))
}).catch(error => reject(error))
}).catch(error => reject(error)); }).catch(error => reject(error));
}) })
}) })
@ -1228,7 +1244,7 @@
}) })
} }
function requestPipelineInbox(pipeID, model) { function requestPipelineInbox(pipeID, model, _async = true) {
if (pipeConnID[pipeID]) { //close existing request connection (if any) if (pipeConnID[pipeID]) { //close existing request connection (if any)
floCloudAPI.closeRequest(pipeConnID[pipeID]); floCloudAPI.closeRequest(pipeConnID[pipeID]);
delete pipeConnID[pipeID]; delete pipeConnID[pipeID];
@ -1261,12 +1277,22 @@
UI.pipeline(model, newInbox); UI.pipeline(model, newInbox);
} }
floCloudAPI.requestApplicationData(null, { let fn = floCloudAPI.requestApplicationData(null, {
receiverID: pipeID, receiverID: pipeID,
lowerVectorClock: _loaded.appendix[`lastReceived_${pipeID}`] + 1, lowerVectorClock: _loaded.appendix[`lastReceived_${pipeID}`] + 1,
callback: callbackFn callback: callbackFn
}).then(conn_id => pipeConnID[pipeID] = conn_id) });
.catch(error => console.error(`request-pipeline(${pipeID}):`, error)) if (_async) {
fn.then(conn_id => pipeConnID[pipeID] = conn_id)
.catch(error => console.error(`request-pipeline(${pipeID}):`, error))
} else {
return new Promise((resolve, reject) => {
fn.then(conn_id => {
pipeConnID[pipeID] = conn_id;
resolve(`Connected to pipeline ${pipeID}`);
}).catch(error => reject(error))
});
}
} }
const disablePipeline = messenger.disablePipeline = function (pipeID) { const disablePipeline = messenger.disablePipeline = function (pipeID) {