From 6d8c8e76f5d8ad7ceef181c3d877a3796b3b8a12 Mon Sep 17 00:00:00 2001 From: erikaperugachi Date: Wed, 10 Jul 2019 15:05:18 -0500 Subject: [PATCH 1/2] Add banner to file downloaded. Close #1044 --- electron_app/src/ipc/mailbox.js | 3 ++- email_mailbox/src/components/FileWrapper.js | 5 +++-- email_mailbox/src/containers/Email.js | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/electron_app/src/ipc/mailbox.js b/electron_app/src/ipc/mailbox.js index 679460493..de4d0953a 100644 --- a/electron_app/src/ipc/mailbox.js +++ b/electron_app/src/ipc/mailbox.js @@ -82,7 +82,8 @@ 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'); diff --git a/email_mailbox/src/components/FileWrapper.js b/email_mailbox/src/components/FileWrapper.js index eec00ee65..9f66ddfb8 100644 --- a/email_mailbox/src/components/FileWrapper.js +++ b/email_mailbox/src/components/FileWrapper.js @@ -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) { @@ -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 }); + openFileExplorer(filename); } ); } diff --git a/email_mailbox/src/containers/Email.js b/email_mailbox/src/containers/Email.js index c38bcdf7f..fd078b5f8 100644 --- a/email_mailbox/src/containers/Email.js +++ b/email_mailbox/src/containers/Email.js @@ -255,7 +255,7 @@ const mapDispatchToProps = (dispatch, ownProps) => { filename, url }; - const filePath = await downloadFileInFileSystem(downloadParams); + const { filePath } = await downloadFileInFileSystem(downloadParams); addFilePathToResponseObject(filePath, cid); } }; From 6de9d08e1454d04793ceccfc78679418c3fdfd18 Mon Sep 17 00:00:00 2001 From: erikaperugachi Date: Wed, 10 Jul 2019 18:21:09 -0500 Subject: [PATCH 2/2] Fix contact name to feed item. Fix #1053 --- electron_app/src/ipc/mailbox.js | 6 ++- email_mailbox/src/components/FileWrapper.js | 2 +- email_mailbox/src/containers/ActivityPanel.js | 48 +------------------ email_mailbox/src/containers/Email.js | 2 +- email_mailbox/src/containers/FeedItem.js | 13 ++++- email_mailbox/src/utils/FeedItemUtils.js | 16 ++++++- .../src/utils/electronEventInterface.js | 9 ++-- 7 files changed, 37 insertions(+), 59 deletions(-) diff --git a/electron_app/src/ipc/mailbox.js b/electron_app/src/ipc/mailbox.js index de4d0953a..1ed695ba4 100644 --- a/electron_app/src/ipc/mailbox.js +++ b/electron_app/src/ipc/mailbox.js @@ -85,8 +85,10 @@ ipc.answerRenderer( 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); } diff --git a/email_mailbox/src/components/FileWrapper.js b/email_mailbox/src/components/FileWrapper.js index 9f66ddfb8..3b867917f 100644 --- a/email_mailbox/src/components/FileWrapper.js +++ b/email_mailbox/src/components/FileWrapper.js @@ -81,7 +81,7 @@ class FileWrapper extends Component { downloadType: 'attachment', filesize: this.props.file.size }); - openFileExplorer(filename); + if (filename) openFileExplorer(filename); } ); } diff --git a/email_mailbox/src/containers/ActivityPanel.js b/email_mailbox/src/containers/ActivityPanel.js index b4934a07c..7392d088b 100644 --- a/email_mailbox/src/containers/ActivityPanel.js +++ b/email_mailbox/src/containers/ActivityPanel.js @@ -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 { diff --git a/email_mailbox/src/containers/Email.js b/email_mailbox/src/containers/Email.js index fd078b5f8..a829ef862 100644 --- a/email_mailbox/src/containers/Email.js +++ b/email_mailbox/src/containers/Email.js @@ -256,7 +256,7 @@ const mapDispatchToProps = (dispatch, ownProps) => { url }; const { filePath } = await downloadFileInFileSystem(downloadParams); - addFilePathToResponseObject(filePath, cid); + if (filePath) addFilePathToResponseObject(filePath, cid); } }; setFileSuccessHandler(handleSuccessDownloadInlineImage); diff --git a/email_mailbox/src/containers/FeedItem.js b/email_mailbox/src/containers/FeedItem.js index 0a96151ac..1e6bb014e 100644 --- a/email_mailbox/src/containers/FeedItem.js +++ b/email_mailbox/src/containers/FeedItem.js @@ -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, diff --git a/email_mailbox/src/utils/FeedItemUtils.js b/email_mailbox/src/utils/FeedItemUtils.js index 9e06dc82a..6d5f6e785 100644 --- a/email_mailbox/src/utils/FeedItemUtils.js +++ b/email_mailbox/src/utils/FeedItemUtils.js @@ -1,8 +1,11 @@ +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(); @@ -10,7 +13,9 @@ export const defineFeedItems = async () => { 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( @@ -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; + } +}; diff --git a/email_mailbox/src/utils/electronEventInterface.js b/email_mailbox/src/utils/electronEventInterface.js index 20e78acad..d892a2308 100644 --- a/email_mailbox/src/utils/electronEventInterface.js +++ b/email_mailbox/src/utils/electronEventInterface.js @@ -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,