Skip to content
Merged

Feed #1054

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions electron_app/src/ipc/mailbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ ipc.answerRenderer(
openFolderWhenDone: !isInlineImage
}
);
return downloadedItem.getSavePath();
const newFilePath = downloadedItem.getSavePath();
return { filePath: newFilePath, filename };
} catch (e) {
if (!isInlineImage)
return mailboxWindow.send('display-message-error-download');
if (!isInlineImage) {
mailboxWindow.send('display-message-error-download');
return {};
}
}
if (!isInlineImage) mailboxWindow.showFileExplorer(filename);
}
Expand Down
5 changes: 3 additions & 2 deletions email_mailbox/src/components/FileWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
setCryptoInterfaces
} from './../utils/FileManager';
import File, { FileStatus } from './File';
import { downloadFileInFileSystem } from '../utils/ipc';
import { downloadFileInFileSystem, openFileExplorer } from '../utils/ipc';

class FileWrapper extends Component {
constructor(props) {
Expand Down Expand Up @@ -75,12 +75,13 @@ class FileWrapper extends Component {
status: FileStatus.DOWNLOADED
},
async () => {
await downloadFileInFileSystem({
const { filename } = await downloadFileInFileSystem({
url,
filename: this.props.file.name,
downloadType: 'attachment',
filesize: this.props.file.size
});
if (filename) openFileExplorer(filename);
}
);
}
Expand Down
48 changes: 1 addition & 47 deletions email_mailbox/src/containers/ActivityPanel.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,22 @@
import { connect } from 'react-redux';
import { loadFeedItems } from './../actions/index';
import ActivityPanelView from './../components/ActivityPanel';
import * as TimeUtils from './../utils/TimeUtils';
import { FeedItemType } from './../utils/const';
import string from '../lang';

const orderFeedsByDate = feeds => {
return feeds.sortBy(feed => feed.get('date')).reverse();
};

const setFeedTime = (feed, field) => {
return feed.set(field, TimeUtils.defineTimeByToday(feed.get(field)));
};

const clasifyFeeds = feeds => {
const newFeeds = feeds.filter(feed => !feed.get('seen'));
const oldFeeds = feeds.filter(feed => feed.get('seen'));
return { newFeeds, oldFeeds };
};

const defineFeedAction = feed => {
switch (feed.get('type')) {
case FeedItemType.DOWNLOADED.value:
return feed.set('action', string.activity.downloaded);
default:
return feed.set('action', string.activity.opened);
}
};

const setFeedTitle = (state, feed) => {
const feedContact = state.get('contacts').get(`${feed.get('contactId')}`);
if (!feedContact)
return feed.set(
'title',
`${string.activity.someone} ${feed.get('action')}`
);

const contactData = feedContact.toJS();
const { name, email } = contactData;
const title = `${name || email} ${feed.get('action')}`;
return feed.set('title', title);
};

const populateFeeds = (state, feeds) => {
return feeds
.map(feed => {
const emailData = feed.get('emailData');
if (emailData) {
feed = feed.set('isMuted', emailData.get('isMuted'));
feed = setFeedTime(feed, 'date');
feed = defineFeedAction(feed);
return setFeedTitle(state, feed);
}
return null;
})
.filter(item => item !== null);
};

const mapStateToProps = state => {
const feedItems = state.get('feeditems');
const feeds = feedItems.get('list').toList();
const orderedFeeds = orderFeedsByDate(feeds);
const populated = populateFeeds(state, orderedFeeds);
const { newFeeds, oldFeeds } = clasifyFeeds(populated);
const { newFeeds, oldFeeds } = clasifyFeeds(orderedFeeds);
const newFeedsPlain = newFeeds.toJS();
const feedItemIds = newFeedsPlain.map(feedItem => feedItem.id);
return {
Expand Down
4 changes: 2 additions & 2 deletions email_mailbox/src/containers/Email.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ const mapDispatchToProps = (dispatch, ownProps) => {
filename,
url
};
const filePath = await downloadFileInFileSystem(downloadParams);
addFilePathToResponseObject(filePath, cid);
const { filePath } = await downloadFileInFileSystem(downloadParams);
if (filePath) addFilePathToResponseObject(filePath, cid);
}
};
setFileSuccessHandler(handleSuccessDownloadInlineImage);
Expand Down
13 changes: 12 additions & 1 deletion email_mailbox/src/containers/FeedItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@ import { connect } from 'react-redux';
import { removeFeedItem, updateFeedItem } from '../actions/index';
import FeedItemWrapperView from '../components/FeedItemWrapper';
import { loadContacts } from '../actions/contacts';
import { myAccount } from './../utils/electronInterface';
import { appDomain } from './../utils/const';
import string from './../lang';

const mapStateToProps = (state, ownProps) => {
const { id, title, emailData, seen, date } = ownProps.feed;
const { id, action, contactId, emailData, seen, date } = ownProps.feed;
const { subject, threadId } = emailData;
const contact = state.get('contacts').get(`${contactId}`);
const name = contact ? contact.get('name') : '';
const email = contact ? contact.get('email') : '';
const myEmailAddress = myAccount.recipientId.includes('@')
? myAccount.recipientId
: `${myAccount.recipientId}@${appDomain}`;
const contactName = email === myEmailAddress ? string.activity.someone : name;
const title = contact ? `${contactName} ${action}` : '';
const subtitle = subject;
return {
id,
Expand Down
16 changes: 15 additions & 1 deletion email_mailbox/src/utils/FeedItemUtils.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { FeedItemType } from './const';
import {
getAllFeedItems,
getEmailsByArrayParam,
getFeedItemsCounterBySeen
} from './ipc';
import { defineTimeByToday } from './TimeUtils';
import string from './../lang';

export const defineFeedItems = async () => {
const allFeeds = await getAllFeedItems();
const badge = await getFeedItemsCounterBySeen(0);
const feeds = await Promise.all(
allFeeds.map(async feed => {
const [emailData] = await getEmailsByArrayParam({ ids: [feed.emailId] });
return { ...feed, emailData };
const action = defineFeedAction(feed.type);
const date = defineTimeByToday(feed.date);
return { ...feed, action, date, emailData };
})
);
const feedItems = feeds.reduce(
Expand All @@ -23,3 +28,12 @@ export const defineFeedItems = async () => {

return { feedItems, badge: badge[0].count };
};

const defineFeedAction = type => {
switch (type) {
case FeedItemType.DOWNLOADED.value:
return string.activity.downloaded;
default:
return string.activity.opened;
}
};
9 changes: 3 additions & 6 deletions email_mailbox/src/utils/electronEventInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,12 +631,9 @@ const handleEmailTrackingUpdate = async ({ rowid, params }) => {
const { domain, recipientId } = fromDomain;
const isOpened = type === EmailStatus.READ;
if (isOpened) {
let contactId = undefined;
if (domain === appDomain) {
const contactEmail = `${recipientId}@${appDomain}`;
const [contact] = await getContactByEmails([contactEmail]);
contactId = contact.id;
}
const contactEmail = `${recipientId}@${domain}`;
const [contact] = await getContactByEmails([contactEmail]);
const contactId = contact.id;
const feedItemParams = {
date,
type,
Expand Down