Skip to content

Commit

Permalink
fix: app cache and ws notifications (#1144)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgithubprofile authored Nov 25, 2023
1 parent 3886f1f commit d7c357a
Showing 5 changed files with 43 additions and 29 deletions.
11 changes: 9 additions & 2 deletions js/image-uploader.js
Original file line number Diff line number Diff line change
@@ -15,11 +15,16 @@ ImageUploader = function(app) {
if (1 == 1) {

return self.uploadImage({ base64 }, 'peertube').catch(err => {
console.error(err)
return self.uploadImage({ base64 }, 'imgur')
}).catch(err => {
console.error(err)
return self.uploadImage({ base64 }, 'up1')
}).then(url => {
return Promise.resolve(url)
}).catch(err => {
console.error(err)
return Promise.reject(err)
})

}
@@ -99,15 +104,17 @@ ImageUploader = function(app) {
resolve(url)
}

p.fail = function(){
p.fail = function(e){

app.Logger.info({ actionId: "IMG_PEERTUBE_UPLOAD_FAILED" });

reject()
reject(e)
}

app.ajax.run(p)

}).catch((e) => {
reject(e)
});

return
9 changes: 7 additions & 2 deletions js/lib/client/resoursesdb.js
Original file line number Diff line number Diff line change
@@ -144,6 +144,7 @@ ResoursesDB = function(storageName, version, storages){
}

self.clearAll = function(key){
console.log('clearAll', key)
return transaction(key).then(items => {

const req = items.clear();
@@ -188,15 +189,19 @@ ResoursesDB = function(storageName, version, storages){

if (time >= req.result.cachedTo && !getold) {

if(useapptimeCorrection()){

if (useapptimeCorrection()){

var ttime = time - apptimeCorrection

if (ttime >= req.result.cachedTo) {
reject('delete');
return;
}

if(!getold){
reject('Data does not exist');
return;
}
}
else{
reject('delete');
49 changes: 25 additions & 24 deletions js/satolist.js
Original file line number Diff line number Diff line change
@@ -9777,7 +9777,7 @@ Platform = function (app, listofnodes) {
})
},

getNotifications: function (blockdif) {
getNotifications: function () {
var n = this;


@@ -9788,9 +9788,7 @@ Platform = function (app, listofnodes) {

return self.sdk.node.get.timepr().then(r => {

console.log('n.storage.block', n.storage.block)

return self.sdk.missed.get(n.storage.block - (blockdif || 0)).catch(e => {
return self.sdk.missed.get(n.storage.block).catch(e => {
if(e != 'block'){
return Promise.reject(e)
}
@@ -9826,6 +9824,8 @@ Platform = function (app, listofnodes) {

}).catch(e => {

console.error(e)

n.inited = false;
n.loading = false;

@@ -18257,7 +18257,7 @@ Platform = function (app, listofnodes) {
var socket;
var opened = false;
var closing = false;
var lost = 0;

var wait = null;

self.connected = {};
@@ -19510,7 +19510,11 @@ Platform = function (app, listofnodes) {
'newblocks': {
loadMore: function (data, clbk) {

if (data.block <= platform.currentBlock) {
var hb = (data.block || data.height)

if (hb <= platform.currentBlock) {

platform.sdk.notifications.wsBlock(hb)

if(clbk) clbk(0)

@@ -19520,13 +19524,12 @@ Platform = function (app, listofnodes) {

var s = platform.sdk.node.transactions;

var dif = platform.currentBlock - data.block
var dif = platform.currentBlock - hb

platform.currentBlock = data.block;
platform.currentBlock = hb;
platform.lasttimecheck = new Date()
platform.lastblocktime = new Date()

lost = data.block;

try{
localStorage['lastblock'] = platform.currentBlock
@@ -19540,7 +19543,7 @@ Platform = function (app, listofnodes) {

//self.reconnected = platform.currentBlock;

platform.sdk.notifications.wsBlock(data.height)
platform.sdk.notifications.wsBlock(hb)

_.each(s.unspent, function (unspents) {
_.each(unspents, function (txu) {
@@ -19552,7 +19555,7 @@ Platform = function (app, listofnodes) {

clbk(dif)

data.difference = platform.currentBlock - (data.block || data.height)
data.difference = platform.currentBlock - hb

platform.actions.ws.block(data)

@@ -19591,7 +19594,10 @@ Platform = function (app, listofnodes) {

loadMore: function (data, clbk) {

if (data.height <= platform.currentBlock) return
if (data.height <= platform.currentBlock) {
platform.sdk.notifications.wsBlock(data.data.height)
return
}

var s = platform.sdk.node.transactions;

@@ -19604,9 +19610,6 @@ Platform = function (app, listofnodes) {
}catch(e){

}

lost = platform.currentBlock;



platform.sdk.notifications.wsBlock(data.height)
@@ -20312,7 +20315,6 @@ Platform = function (app, listofnodes) {
}

closing = false;
//lost = platform.currentBlock;

self.close();

@@ -20387,10 +20389,10 @@ Platform = function (app, listofnodes) {

self.connected = {};

lost = platform.sdk.notifications.storage.block || platform.currentBlock || 0
//lost = platform.sdk.notifications.storage.block || platform.currentBlock || 0

console.log("block LOST", lost)
self.getMissed(true).then(() => {

self.getMissed().then(() => {
})

opened = true;
@@ -20556,23 +20558,21 @@ Platform = function (app, listofnodes) {

self.getMissed = function (initial) {

if (!initial && ((!platform.lastblocktime || (new Date() < platform.lastblocktime.addMinutes(3))) || (lost < 1))) return Promise.resolve()
if (!initial && ((!platform.lastblocktime || (new Date() < platform.lastblocktime.addMinutes(2))))) return Promise.resolve()

if (self.loadingMissed) return Promise.resolve()

self.loadingMissed = true;

return platform.sdk.node.get.timepr().then(r => {

return platform.sdk.missed.get(lost)
return platform.sdk.missed.get(platform.sdk.notifications.storage.block || platform.currentBlock || 0)

}).then(({block, notifications}) => {

self.messageHandler(block, function () {
self.loadingMissed = false;

lost = 0;

if(!notifications) return

lazyEach({
@@ -20591,6 +20591,8 @@ Platform = function (app, listofnodes) {

}).catch(e => {

console.error(e)

self.loadingMissed = false;

return Promise.reject(e)
@@ -20929,7 +20931,6 @@ Platform = function (app, listofnodes) {
self.close()

self.loadingMissed = false;
lost = 0;
}


2 changes: 1 addition & 1 deletion proxy16/node/notifications.js
Original file line number Diff line number Diff line change
@@ -327,7 +327,7 @@ class Notifications{

this.logger.w('system', 'info', `Notification: Firebase autocheck fail`)

destroy()
this.destroy()

try{
this.run()
1 change: 1 addition & 0 deletions tpls/indexcordova.html.tpl
Original file line number Diff line number Diff line change
@@ -127,5 +127,6 @@
__JSPOST__


<script async src="js/pwa-service-worker.js?v=v__PACKAGE-VERSION__"></script>
</body>
</html>

0 comments on commit d7c357a

Please sign in to comment.