mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-12 19:49:59 +05:00
Cleanup code + fixes
This commit is contained in:
parent
6c8070bdee
commit
82852d1e52
@ -3396,7 +3396,6 @@ define([
|
||||
|
||||
var todo = function (actionCount) {
|
||||
crowdfundingState = true;
|
||||
common.getSframeChannel().query('Q_RECORD_CROWDFUNDING_SHOWN', { count: actionCount }, function () {});
|
||||
var dontShowAgain = function () {
|
||||
common.setAttribute(['general', 'crowdfunding'], false);
|
||||
Feedback.send('CROWDFUNDING_NEVER');
|
||||
@ -3409,7 +3408,7 @@ define([
|
||||
{
|
||||
name: Messages.crowdfunding_popup_no,
|
||||
className: 'cancel',
|
||||
iconClass: 'snooze',
|
||||
iconClass: 'crowdfunding-snooze',
|
||||
onClick: function () {
|
||||
Feedback.send('CROWDFUNDING_NO');
|
||||
}
|
||||
@ -3451,6 +3450,7 @@ define([
|
||||
buttons: buttons
|
||||
});
|
||||
UI.openCustomModal(modal, { wide: true });
|
||||
common.getSframeChannel().query('Q_RECORD_CROWDFUNDING_SHOWN', { count: actionCount }, function () {});
|
||||
};
|
||||
|
||||
if (force) {
|
||||
|
||||
@ -152,7 +152,7 @@ define([
|
||||
try {
|
||||
Object.keys(localStorage || {}).forEach(function (k) {
|
||||
// Remove everything in localStorage except CACHE and FS_hash
|
||||
if (/^CRYPTPAD_CACHE/.test(k) || /^LESS_CACHE/.test(k) || k === Constants.fileHashKey || /^CRYPTPAD_STORE|colortheme/.test(k) || /^cp_crowdfunding_/.test(k)) { return; }
|
||||
if (/^CRYPTPAD_CACHE/.test(k) || /^LESS_CACHE/.test(k) || k === Constants.fileHashKey || /^CRYPTPAD_STORE|colortheme/.test(k) || (!isDeletion && /^cp_crowdfunding_/.test(k))) { return; }
|
||||
localStorage.removeItem(k);
|
||||
});
|
||||
} catch (e) { console.error(e); }
|
||||
|
||||
@ -1045,7 +1045,12 @@ define([
|
||||
if (!Utils.LocalStore.isLoggedIn()) { return cb(crowdfundingGetLS()); }
|
||||
Cryptpad.getAttribute(CROWDFUNDING_DRIVE_KEY, function (e, metrics) {
|
||||
if (e || !metrics || typeof metrics !== 'object') {
|
||||
return cb(crowdfundingGetLS());
|
||||
return cb({
|
||||
visitCount: 0,
|
||||
firstSeen: null,
|
||||
lastShownAtCount: 0,
|
||||
lastShownAtTime: 0
|
||||
});
|
||||
}
|
||||
cb(metrics);
|
||||
});
|
||||
@ -1062,17 +1067,7 @@ define([
|
||||
} catch (e) {}
|
||||
return cb && cb();
|
||||
}
|
||||
Cryptpad.setAttribute(CROWDFUNDING_DRIVE_KEY, metrics, function (e) {
|
||||
if (!e) {
|
||||
return cb && cb();
|
||||
}
|
||||
try {
|
||||
['visitCount', 'firstSeen', 'lastShownAtCount', 'lastShownAtTime'].forEach(function (k) {
|
||||
if (metrics[k] !== null && metrics[k] !== undefined) {
|
||||
localStorage.setItem(CROWDFUNDING_PREFIX + k, String(metrics[k]));
|
||||
}
|
||||
});
|
||||
} catch (e) {}
|
||||
Cryptpad.setAttribute(CROWDFUNDING_DRIVE_KEY, metrics, function () {
|
||||
cb && cb();
|
||||
});
|
||||
};
|
||||
@ -1143,7 +1138,9 @@ define([
|
||||
scope: scope,
|
||||
ts: now
|
||||
}));
|
||||
} catch (e) {}
|
||||
} catch (e) {
|
||||
try { localStorage.removeItem(CROWDFUNDING_PREFIX + 'open_dedupe'); } catch (e2) {}
|
||||
}
|
||||
crowdfundingLastOpenScope = scope;
|
||||
crowdfundingLastOpenAt = now;
|
||||
crowdfundingIncrementAction(cb);
|
||||
|
||||
@ -8,15 +8,7 @@ define([
|
||||
'/components/nthen/index.js',
|
||||
], function (localForage, Cache, nThen) {
|
||||
nThen(function (w) {
|
||||
// Preserve crowdfunding keys across logout so counters survive session changes
|
||||
var crowdfundingEntries = Object.keys(localStorage).reduce(function (acc, k) {
|
||||
if (/^cp_crowdfunding_/.test(k)) { acc[k] = localStorage.getItem(k); }
|
||||
return acc;
|
||||
}, {});
|
||||
localStorage.clear();
|
||||
Object.keys(crowdfundingEntries).forEach(function (k) {
|
||||
try { localStorage.setItem(k, crowdfundingEntries[k]); } catch (e) {}
|
||||
});
|
||||
localForage.clear(w());
|
||||
Cache.clear(w());
|
||||
}).nThen(function () {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user