Skip to content
Merged
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
2 changes: 1 addition & 1 deletion electron_app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"electron-packager": "^10.1.2"
},
"dependencies": {
"@criptext/email-http-client": "^0.8.1",
"@criptext/email-http-client": "^0.8.2",
"knex": "^0.14.2",
"sqlite3": "^3.1.13",
"websocket": "^1.0.25"
Expand Down
20 changes: 12 additions & 8 deletions electron_app/src/DBManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { db, cleanDataBase, createTables, Table } = require('./models.js');
const { formContactsRow } = require('./utils/dataTableUtils.js');
const { noNulls } = require('./utils/ObjectUtils');

/* Account
----------------------------- */
Expand Down Expand Up @@ -564,16 +565,19 @@ const deleteEmailLabelAndContactByEmailId = (id, optionalEmailToSave) => {
});
};

const updateEmail = ({ id, key, threadId, date, isMuted, unread }) => {
const params = {};
if (key) params.key = key;
if (threadId) params.threadId = threadId;
if (date) params.date = date;
if (typeof unread === 'boolean') params.unread = unread;
if (typeof isMuted === 'boolean') params.isMuted = isMuted;
const updateEmail = ({ id, key, threadId, date, isMuted, unread, status }) => {
const params = noNulls({
key,
threadId,
date,
unread: typeof unread === 'boolean' ? unread : undefined,
isMuted: typeof isMuted === 'boolean' ? isMuted : undefined,
status
});
const whereParam = id ? { id } : { key };
return db
.table(Table.EMAIL)
.where({ id })
.where(whereParam)
.update(params);
};

Expand Down
4 changes: 2 additions & 2 deletions electron_app/src/clientManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class ClientManager {
return client.postKeyBundle(params);
}

postOpenEvent(params) {
return client.postOpenEvent(params);
postOpenEvent(metadataKeys) {
return client.postOpenEvent(metadataKeys);
}

postUser(params) {
Expand Down
2 changes: 1 addition & 1 deletion electron_app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
lodash "^4.2.0"
to-fast-properties "^2.0.0"

"@criptext/email-http-client@^0.8.1":
"@criptext/email-http-client@^0.8.2":
version "0.8.2"
resolved "https://registry.yarnpkg.com/@criptext/email-http-client/-/email-http-client-0.8.2.tgz#6e788b0ea3e2e959b7b6bd46829ede7caaa20ec4"
dependencies:
Expand Down
19 changes: 9 additions & 10 deletions email_composer/src/containers/Composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
myAccount,
throwError,
updateEmail,
updateEmailLabel,
saveDraftChanges,
errors,
deleteEmailsByIds,
Expand All @@ -26,6 +25,7 @@ import {
} from './../utils/ArrayUtils';
import signal from './../libs/signal';
import {
EmailStatus,
formOutgoingEmailFromData,
formDataToEditDraft,
formDataToReply
Expand Down Expand Up @@ -280,7 +280,7 @@ class ComposerWrapper extends Component {
this.setState({ status: Status.WAITING });
const { data, to, subject, body } = formOutgoingEmailFromData(
this.state,
LabelType.draft.id
LabelType.sent.id
);
let emailId, key;
try {
Expand Down Expand Up @@ -310,15 +310,14 @@ class ComposerWrapper extends Component {
const { metadataKey, date } = res.body;
const threadId = this.state.threadId || res.body.threadId;
key = metadataKey;
const emailParams = { id: emailId, key, threadId, date };
await updateEmail(emailParams);

const emailLabelParams = {
emailId,
oldLabelId: LabelType.draft.id,
newLabelId: LabelType.sent.id
const emailParams = {
id: emailId,
key,
threadId,
date,
status: EmailStatus.SENT
};
await updateEmailLabel(emailLabelParams);
await updateEmail(emailParams);

closeComposerWindow(emailId);
} catch (e) {
Expand Down
12 changes: 11 additions & 1 deletion email_composer/src/utils/EmailUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ const getCriptextRecipients = (recipients, type) => {
}));
};

export const EmailStatus = {
FAIL: 1,
UNSENT: 2,
NONE: 3,
SENDING: 4,
SENT: 5,
DELIVERED: 6,
READ: 7
};

export const formOutgoingEmailFromData = (composerData, labelId) => {
const recipients = {
to: composerData.toEmails,
Expand All @@ -52,7 +62,7 @@ export const formOutgoingEmailFromData = (composerData, labelId) => {
content: body,
preview: removeHTMLTags(body).slice(0, 21),
date: Date.now(),
status: 1,
status: EmailStatus.SENDING,
unread: false,
secure: true,
isMuted: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Object {
"preview": "
",
"secure": true,
"status": 1,
"status": 4,
"subject": "Subject",
"unread": false,
},
Expand Down
4 changes: 3 additions & 1 deletion email_mailbox/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
selectThreads,
removeThreads,
removeThreadsLabel,
sendOpenEvent
sendOpenEvent,
updateStatusThread
} from './threads';
import {
addEmails,
Expand Down Expand Up @@ -90,6 +91,7 @@ export {
updateFeedItemSuccess,
updateLabel,
updateLabelSuccess,
updateStatusThread,
updateUnreadEmails,
updateUnreadThread,
updateUnreadThreads
Expand Down
9 changes: 7 additions & 2 deletions email_mailbox/src/actions/threads.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ export const moveThreads = (threadIds, labelId) => ({
labelId
});

export const updateStatusThread = (threadId, status) => ({
type: Thread.UPDATE_STATUS,
threadId,
status
});

export const updateUnreadThread = thread => {
return {
type: Thread.UPDATE_UNREAD_THREAD,
Expand Down Expand Up @@ -308,8 +314,7 @@ export const sendOpenEvent = threadId => {
const unreadEmails = await getUnreadEmailsByThreadId(threadId);
if (unreadEmails.length > 0) {
const metadataKeys = unreadEmails.map(item => Number(item.key));
const params = { metadataKeys };
await postOpenEvent(params);
await postOpenEvent(metadataKeys);
}
} catch (e) {
// TO DO
Expand Down
3 changes: 2 additions & 1 deletion email_mailbox/src/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export const Thread = {
MOVE_THREADS: 'MOVE_THREADS',
UPDATE_UNREAD_THREADS: 'UPDATE_UNREAD_THREADS',
UPDATE_UNREAD_THREAD: 'UPDATE_UNREAD_THREAD',
ADD_EMAIL: 'UPDATE_THREAD_EMAIL_IDS'
ADD_EMAIL: 'UPDATE_THREAD_EMAIL_IDS',
UPDATE_STATUS: 'UPDATE_STATUS'
};

export const Contact = {
Expand Down
9 changes: 7 additions & 2 deletions email_mailbox/src/components/PanelWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ class PanelWrapper extends Component {
}
});

addEvent(Event.EMAIL_TRACKING_UPDATE, threadId => {
props.onMarkThreadAsOpen(threadId);
});

addEvent(Event.UPDATE_THREAD_EMAILS, eventParams => {
const newThreadId = eventParams.threadId;
props.onLoadEmails(newThreadId);
const { threadId } = eventParams;
props.onLoadEmails(threadId);
props.onAddEmailToThread({
threadId: this.state.sectionSelected.params.threadIdSelected,
emailId: eventParams.emailId
Expand Down Expand Up @@ -178,6 +182,7 @@ class PanelWrapper extends Component {
PanelWrapper.propTypes = {
onAddEmailToThread: PropTypes.func,
onLoadEmails: PropTypes.func,
onMarkThreadAsOpen: PropTypes.func,
onLoadThreads: PropTypes.func,
onUpdateOpenedAccount: PropTypes.func,
onUpdateTimestamp: PropTypes.func,
Expand Down
2 changes: 1 addition & 1 deletion email_mailbox/src/components/ThreadItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class ThreadItem extends Component {
return <i className="icon-checked status-sent" />;
case EmailStatus.DELIVERED:
return <i className="icon-checked status-delivered" />;
case EmailStatus.OPENED:
case EmailStatus.READ:
return <i className="icon-checked status-opened" />;
default:
return null;
Expand Down
8 changes: 7 additions & 1 deletion email_mailbox/src/containers/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
loadThreads,
updateLabelSuccess,
updateAllFeedItemsAsOlder,
loadEmails
loadEmails,
updateStatusThread
} from '../actions';
import PanelWrapper from '../components/PanelWrapper';
import {
Expand All @@ -13,6 +14,7 @@ import {
updateAccount
} from '../utils/electronInterface';
import { storeSeenTimestamp } from '../utils/storage';
import { EmailStatus } from '../utils/const';

const mapStateToProps = state => {
const threadsCount = state.get('threads').size;
Expand Down Expand Up @@ -46,6 +48,10 @@ const mapDispatchToProps = dispatch => {
const rejectedLabelIds = defineRejectedLabels(labelId);
dispatch(loadThreads({ ...params, ...rejectedLabelIds }));
},
onMarkThreadAsOpen: threadId => {
const readStatus = EmailStatus.READ;
dispatch(updateStatusThread(threadId, readStatus));
},
onUpdateOpenedAccount: async () => {
const opened = true;
const recipientId = myAccount.recipientId;
Expand Down
22 changes: 22 additions & 0 deletions email_mailbox/src/reducers/__tests__/threads.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,26 @@ describe('Set thread state by actions', () => {
const unread = emailUpdated.get('unread');
expect(unread).toBe(false);
});

it('should set thread param: status, action[UPDATE_STATUS]', () => {
const state = initState(threads);
const threadId = 1;
const newStatus = 2;
const action = actions.updateStatusThread(threadId, newStatus);
const newState = threadsReducer(state, action);
const emailUpdated = newState.get('0');
const status = emailUpdated.get('status');
expect(status).toBe(newStatus);
});

it('should not set thread param status because is undefined, action[UPDATE_STATUS]', () => {
const state = initState(threads);
const threadId = 1;
const badStatus = undefined;
const action = actions.updateStatusThread(threadId, badStatus);
const newState = threadsReducer(state, action);
const emailUpdated = newState.get('0');
const status = emailUpdated.get('status');
expect(status).not.toBe(badStatus);
});
});
17 changes: 16 additions & 1 deletion email_mailbox/src/reducers/threads.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,19 @@ const threads = (state = List([]), action) => {
if (threadItem.get('id') === threadId) {
return thread(threadItem, action);
}
return thread;
return threadItem;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer iterate with singular name: thread and so, you will return thread

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thread is the function for a item in thread list.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right!

});
}
case Thread.UPDATE_STATUS: {
const { status, threadId } = action;
if (!threadId || !status) {
return state;
}
return state.map(threadItem => {
if (threadItem.get('id') === threadId) {
return thread(threadItem, action);
}
return threadItem;
});
}
default:
Expand All @@ -150,6 +162,9 @@ const thread = (state, action) => {
case Thread.ADD_EMAIL: {
return state.set('emailIds', state.get('emailIds').push(action.emailId));
}
case Thread.UPDATE_STATUS: {
return state.set('status', action.status);
}
default:
return state;
}
Expand Down
3 changes: 2 additions & 1 deletion email_mailbox/src/utils/EmailUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { removeAppDomain, removeHTMLTags } from './StringUtils';
import signal from './../libs/signal';
import { EmailStatus } from './const';

const getContentMessage = async ({
bodyKey,
Expand Down Expand Up @@ -49,7 +50,7 @@ export const formIncomingEmailFromData = async data => {
preview,
subject: data.subject,
date: data.date,
status: 1,
status: EmailStatus.NONE,
unread: true,
secure: true,
isMuted: false
Expand Down
12 changes: 7 additions & 5 deletions email_mailbox/src/utils/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ export const FeedItemType = {
};

export const EmailStatus = {
UNSENT: -1,
NONE: 0,
SENT: 1,
DELIVERED: 2,
OPENED: 3
FAIL: 1,
UNSENT: 2,
NONE: 3,
SENDING: 4,
SENT: 5,
DELIVERED: 6,
READ: 7
};

export const SocketCommand = {
Expand Down
Loading