session-desktop/app/profile_images.js
Audric Ackermann 48e7a0e25f
Various UI fixes (#2070)
* cleanup unused convo json fields in db

* display a toast if the user is not approved yet on call OFFER received

* enable CBR for calls

* do not update active_at on configMessage if !!active_at

* remove mkdirp dependency

* disable call button if focused convo is blocked

* quote: do not include the full body in quote, but just the first 100

* click on the edit profile qr code padding

* Allow longer input for opengroup join overlay

Fixes #2068

* Fix overlay feature for start new session button

* make ringing depend on redux CALL status

* turn ON read-receipt by default
2021-12-08 14:15:54 +11:00

45 lines
1.1 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const { app } = require('electron').remote;
const userDataPath = app.getPath('userData');
const PATH = path.join(userDataPath, 'profileImages');
fs.mkdirSync(PATH, { recursive: true });
const hasImage = pubKey => fs.existsSync(getImagePath(pubKey));
const getImagePath = pubKey => `${PATH}/${pubKey}.png`;
const removeImage = pubKey => {
if (hasImage(pubKey)) {
fs.unlinkSync(getImagePath(pubKey));
}
};
const removeImagesNotInArray = pubKeyArray => {
fs.readdirSync(PATH)
// Get all files that end with png
.filter(file => file.includes('.png'))
// Strip the extension
.map(i => path.basename(i, '.png'))
// Get any file that is not in the pubKeyArray
.filter(i => !pubKeyArray.includes(i))
// Remove them
.forEach(i => removeImage(i));
};
const writePNGImage = (base64String, pubKey) => {
const imagePath = getImagePath(pubKey);
fs.writeFileSync(imagePath, base64String, 'base64');
return imagePath;
};
module.exports = {
writePNGImage,
getImagePath,
hasImage,
removeImage,
removeImagesNotInArray,
};