Cleanup code + fixes

This commit is contained in:
DianaXWiki 2026-04-16 16:19:46 +03:00
parent 6c8070bdee
commit 82852d1e52
4 changed files with 13 additions and 24 deletions

View File

@ -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) {

View File

@ -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); }

View File

@ -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);

View File

@ -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 () {