remove profile_images as we are not using it

This commit is contained in:
Audric Ackermann 2022-02-02 15:54:00 +11:00
parent 98bdd53bd5
commit ceb5317160
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4
9 changed files with 10 additions and 87 deletions

View File

@ -1,44 +0,0 @@
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,
};

View File

@ -1858,6 +1858,9 @@ function searchConversations(query, { limit } = {}) {
const orderByMessageCoalesceClause = `ORDER BY COALESCE(${MESSAGES_TABLE}.serverTimestamp, ${MESSAGES_TABLE}.sent_at, ${MESSAGES_TABLE}.received_at) DESC`;
function searchMessages(query, limit) {
if (!limit) {
throw new Error('searchMessages limit must be set');
}
const rows = globalInstance
.prepare(
`SELECT
@ -1872,7 +1875,7 @@ function searchMessages(query, limit) {
)
.all({
query,
limit: limit || 100,
limit,
});
return map(rows, row => ({

View File

@ -221,7 +221,6 @@ setInterval(() => {
window.loadImage = require('blueimp-load-image');
window.filesize = require('filesize');
window.profileImages = require('./app/profile_images');
window.React = require('react');
window.ReactDOM = require('react-dom');

View File

@ -103,13 +103,6 @@ const ZombiesList = ({ convoId }: { convoId: string }) => {
</>
);
};
// // Return members that would comprise the group given the
// // current state in `users`
// private getWouldBeMembers(users: Array<ContactType>) {
// return users.filter(d => {
// return (d.existingMember && !d.checkmarked) || (!d.existingMember && d.checkmarked);
// });
// }
// tslint:disable-next-line: max-func-body-length
async function onSubmit(convoId: string, membersAfterUpdate: Array<string>) {

View File

@ -25,7 +25,7 @@ import _ from 'lodash';
// tslint:disable-next-line: no-empty-interface
export type ConversationListItemProps = Pick<
ReduxConversationType,
'unreadCount' | 'id' | 'isSelected' | 'isBlocked' | 'mentionedUs' | 'unreadCount' | 'profileName'
'id' | 'isSelected' | 'isBlocked' | 'mentionedUs' | 'unreadCount' | 'profileName'
>;
/**

View File

@ -292,19 +292,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public async cleanup() {
await deleteExternalFilesOfConversation(this.attributes);
window.profileImages.removeImage(this.id);
}
public async updateProfileAvatar() {
if (this.isPublic()) {
return;
}
// Remove old identicons
if (window.profileImages.hasImage(this.id)) {
window.profileImages.removeImage(this.id);
await this.setProfileAvatar(null);
}
}
public async onExpired(_message: MessageModel) {
@ -1147,13 +1134,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
}
}
public async setGroupName(name: string) {
const profileName = this.get('name');
if (profileName !== name) {
this.set({ name });
await this.commit();
}
}
public async setSubscriberCount(count: number) {
if (this.get('subscriberCount') !== count) {
this.set({ subscriberCount: count });

View File

@ -110,7 +110,7 @@ export class ConversationController {
};
conversation.initialPromise = create();
conversation.initialPromise.then(async () => {
conversation.initialPromise.then(() => {
if (window?.inboxStore) {
window.inboxStore?.dispatch(
conversationActions.conversationAdded({
@ -120,11 +120,9 @@ export class ConversationController {
);
}
if (!conversation.isPublic()) {
await Promise.all([
conversation.updateProfileAvatar(),
// NOTE: we request snodes updating the cache, but ignore the result
void getSwarmFor(id),
]);
// NOTE: we request snodes updating the cache, but ignore the result
void getSwarmFor(id);
}
});
@ -274,13 +272,10 @@ export class ConversationController {
promises.push(conversation.updateLastMessage());
}
promises.concat([conversation.updateProfileName(), conversation.updateProfileAvatar()]);
promises.concat([conversation.updateProfileName()]);
});
await Promise.all(promises);
// Remove any unused images
window.profileImages.removeImagesNotInArray(this.conversations.map((c: any) => c.id));
window?.log?.info('ConversationController: done with initial fetch');
} catch (error) {
window?.log?.error(

View File

@ -18,7 +18,6 @@ import {
ConversationTypeEnum,
} from '../../../../models/conversation';
import { PubKey } from '../../../../session/types';
import { noop } from 'lodash';
import { generateFakeSnodes } from '../../../test-utils/utils';
// tslint:disable: chai-vague-errors
@ -52,7 +51,6 @@ describe('SwarmPolling', () => {
sandbox.stub(SnodePool, 'getSwarmFor').resolves(generateFakeSnodes(5));
sandbox.stub(SNodeAPI, 'retrieveNextMessages').resolves([]);
TestUtils.stubWindow('profileImages', { removeImagesNotInArray: noop, hasImage: noop });
TestUtils.stubWindow('inboxStore', undefined);
TestUtils.stubWindow('getGlobalOnlineStatus', () => true);
TestUtils.stubWindowLog();

1
ts/window.d.ts vendored
View File

@ -60,7 +60,6 @@ declare global {
userConfig: any;
versionInfo: any;
getConversations: () => ConversationCollection;
profileImages: any;
MediaRecorder: any;
contextMenuShown: boolean;