remove profile_images as we are not using it

pull/2142/head
Audric Ackermann 3 years ago
parent 98bdd53bd5
commit ceb5317160
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

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

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

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

@ -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 // tslint:disable-next-line: max-func-body-length
async function onSubmit(convoId: string, membersAfterUpdate: Array<string>) { async function onSubmit(convoId: string, membersAfterUpdate: Array<string>) {

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

@ -292,19 +292,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public async cleanup() { public async cleanup() {
await deleteExternalFilesOfConversation(this.attributes); 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) { 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) { public async setSubscriberCount(count: number) {
if (this.get('subscriberCount') !== count) { if (this.get('subscriberCount') !== count) {
this.set({ subscriberCount: count }); this.set({ subscriberCount: count });

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

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

1
ts/window.d.ts vendored

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

Loading…
Cancel
Save