Skip to content

Commit acc1619

Browse files
Erika Perugachinot-gabriel
authored andcommitted
Removethreads (#394)
* Update reducer REMOVE_THREADS * Update version 0.11.0
1 parent f36b0f0 commit acc1619

File tree

13 files changed

+74
-95
lines changed

13 files changed

+74
-95
lines changed

electron_app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "criptext",
3-
"version": "0.9.3",
3+
"version": "0.11.0",
44
"author": {
55
"name": "Criptext Inc.",
66
"email": "[email protected]",

electron_app/src/utils/EmailUtils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const formIncomingEmailFromData = ({
7777
const content = body || '';
7878
const preview = body
7979
? removeHTMLTags(content)
80-
.slice(0, 50)
80+
.slice(0, 100)
8181
.trim()
8282
: '';
8383
const status = isToMe ? EmailStatus.NONE : EmailStatus.DELIVERED;
@@ -132,7 +132,7 @@ const formOutgoingEmailFromData = ({
132132
key: Date.now(),
133133
subject: textSubject,
134134
content: body,
135-
preview: removeHTMLTags(body).slice(0, 50),
135+
preview: removeHTMLTags(body).slice(0, 100),
136136
date: Date.now(),
137137
status: EmailStatus.SENDING,
138138
unread: false,

email_mailbox/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "email_mailbox",
3-
"version": "0.9.3",
3+
"version": "0.11.0",
44
"private": true,
55
"dependencies": {
66
"animejs": "^2.2.0",

email_mailbox/src/actions/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ import {
2020
removeLabelIdThreadDraftSuccess,
2121
removeLabelIdThreads,
2222
removeLabelIdThreadsSuccess,
23-
removeThread,
24-
removeThreadsByThreadIdsOnSuccess,
2523
updateEmailIdsThread,
2624
updateUnreadThreads,
2725
updateUnreadThreadsSuccess,
28-
searchThreads,
2926
removeThreads,
27+
removeThreadsSuccess,
28+
searchThreads,
3029
sendOpenEvent,
3130
updateStatusThread
3231
} from './threads';
@@ -96,11 +95,10 @@ export {
9695
removeLabelIdThreads,
9796
removeLabelIdThreadsSuccess,
9897
removeLabelOnSuccess,
99-
removeThread,
10098
removeFeedItem,
10199
removeFeedItemSuccess,
102100
removeThreads,
103-
removeThreadsByThreadIdsOnSuccess,
101+
removeThreadsSuccess,
104102
selectFeedItem,
105103
selectThread,
106104
searchThreads,

email_mailbox/src/actions/threads.js

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ export const addLabelIdThreadsSuccess = (threadIds, labelId) => ({
133133
export const addMoveLabelIdThreads = ({ threadsParams, labelId, notMove }) => {
134134
return async dispatch => {
135135
try {
136-
const threadIds = threadsParams.map(param => param.threadIdDB);
136+
const threadIds = threadsParams
137+
.map(param => param.threadIdDB)
138+
.filter(item => item !== null);
137139
const dbReponse = await Promise.all(
138140
threadIds.map(async threadId => {
139141
const threadEmails = await getEmailsByThreadId(threadId);
@@ -260,14 +262,42 @@ export const removeLabelIdThreadsSuccess = (threadIds, labelId) => ({
260262
labelId
261263
});
262264

263-
export const removeThread = threadId => ({
264-
type: Thread.REMOVE_THREAD,
265-
targetThread: threadId
266-
});
265+
export const removeThreads = threadsParams => {
266+
return async dispatch => {
267+
try {
268+
const emailIds = threadsParams
269+
.map(param => param.emailId)
270+
.filter(item => item !== null);
271+
const threadIds = threadsParams
272+
.map(param => param.threadIdDB)
273+
.filter(item => item !== null);
274+
if (threadIds.length) {
275+
const eventParams = {
276+
cmd: SocketCommand.PEER_THREAD_DELETED_PERMANENTLY,
277+
params: { threadIds }
278+
};
279+
const { status } = await postPeerEvent(eventParams);
280+
if (status === 200) {
281+
await deleteEmailsByThreadId(threadIds);
282+
dispatch(removeThreadsSuccess(threadIds));
283+
} else {
284+
sendRemoveThreadsErrorMessage();
285+
}
286+
}
287+
if (emailIds.length) {
288+
await deleteEmailsByIds(emailIds);
289+
dispatch(removeThreadsSuccess(emailIds));
290+
}
291+
dispatch(loadFeedItems(true));
292+
} catch (e) {
293+
sendRemoveThreadsErrorMessage();
294+
}
295+
};
296+
};
267297

268-
export const removeThreadsSuccess = threadsIds => ({
298+
export const removeThreadsSuccess = uniqueIds => ({
269299
type: Thread.REMOVE_THREADS,
270-
threadsIds
300+
uniqueIds
271301
});
272302

273303
export const selectThread = threadId => ({
@@ -368,36 +398,6 @@ export const loadEvents = params => {
368398
};
369399
};
370400

371-
export const removeThreads = (threadsParams, isDraft) => {
372-
return async dispatch => {
373-
try {
374-
const storeIds = threadsParams.map(param => param.threadIdStore);
375-
const threadIds = threadsParams
376-
.map(param => param.threadIdDB)
377-
.filter(item => item !== null);
378-
379-
const eventParams = {
380-
cmd: SocketCommand.PEER_THREAD_DELETED_PERMANENTLY,
381-
params: { threadIds }
382-
};
383-
const { status } = await postPeerEvent(eventParams);
384-
if (status === 200) {
385-
const dbResponse = isDraft
386-
? await deleteEmailsByIds(storeIds)
387-
: await deleteEmailsByThreadId(threadIds);
388-
if (dbResponse) {
389-
dispatch(removeThreadsSuccess(storeIds));
390-
dispatch(loadFeedItems(true));
391-
}
392-
} else {
393-
sendRemoveThreadsErrorMessage();
394-
}
395-
} catch (e) {
396-
sendRemoveThreadsErrorMessage();
397-
}
398-
};
399-
};
400-
401401
export const sendOpenEvent = threadId => {
402402
return async () => {
403403
try {
@@ -427,8 +427,3 @@ const formRemoveThreadLabelParams = (emails, labelId) => {
427427
labelIds: [labelId]
428428
};
429429
};
430-
431-
export const removeThreadsByThreadIdsOnSuccess = threadIds => ({
432-
type: Thread.REMOVE_THREADS_BY_THREAD_ID,
433-
threadIds
434-
});

email_mailbox/src/actions/types.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export const Thread = {
1111
REMOVE_LABELID_THREAD: 'REMOVE_LABELID_THREAD',
1212
REMOVE_LABELID_THREAD_DRAFT: 'REMOVE_LABELID_THREAD_DRAFT',
1313
REMOVE_LABELID_THREADS: 'REMOVE_LABELID_THREADS',
14-
REMOVE_THREAD: 'REMOVE_THREAD',
1514
REMOVE_THREADS: 'REMOVE_THREADS',
1615
REMOVE_THREADS_BY_THREAD_ID: 'REMOVE_THREADS_BY_THREAD_ID',
1716
UPDATE_EMAILIDS_THREAD: 'UPDATE_EMAILIDS_THREAD',

email_mailbox/src/components/HeaderThreadOptionsWrapper.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class HeaderThreadOptionsWrapper extends Component {
105105
currentLabelId === LabelType.inbox.id ||
106106
currentLabelId === LabelType.sent.id ||
107107
currentLabelId === LabelType.starred.id ||
108+
currentLabelId === LabelType.draft.id ||
108109
currentLabelId === LabelType.allmail.id
109110
);
110111
};
@@ -113,8 +114,7 @@ class HeaderThreadOptionsWrapper extends Component {
113114
const currentLabelId = LabelType[this.props.mailboxSelected].id;
114115
return (
115116
currentLabelId === LabelType.spam.id ||
116-
currentLabelId === LabelType.trash.id ||
117-
currentLabelId === LabelType.draft.id
117+
currentLabelId === LabelType.trash.id
118118
);
119119
};
120120

@@ -139,18 +139,13 @@ class HeaderThreadOptionsWrapper extends Component {
139139
};
140140

141141
handleClickDeleteThread = () => {
142-
const currentLabelId = LabelType[this.props.mailboxSelected].id;
143-
if (currentLabelId === LabelType.draft.id) {
144-
this.props.onRemoveDrafts(this.props.threadsSelected);
145-
} else {
146-
confirmPermanentDeleteThread(response => {
147-
closeDialog();
148-
if (response === CONFIRM_RESPONSE) {
149-
const backFirst = true;
150-
this.props.onRemoveThreads(this.props.threadsSelected, backFirst);
151-
}
152-
});
153-
}
142+
confirmPermanentDeleteThread(response => {
143+
closeDialog();
144+
if (response === CONFIRM_RESPONSE) {
145+
const backFirst = true;
146+
this.props.onRemoveThreads(this.props.threadsSelected, backFirst);
147+
}
148+
});
154149
};
155150

156151
handleClickMoveToInbox = () => {
@@ -195,7 +190,6 @@ HeaderThreadOptionsWrapper.propTypes = {
195190
onAddLabel: PropTypes.func,
196191
onAddMoveLabel: PropTypes.func,
197192
onMarkRead: PropTypes.func,
198-
onRemoveDrafts: PropTypes.func,
199193
onRemoveLabel: PropTypes.func,
200194
onRemoveThreads: PropTypes.func,
201195
threadsSelected: PropTypes.array

email_mailbox/src/components/SearchHints.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const SearchHints = props => (
3333
{props.threads.map((thread, index) => (
3434
<SearchMail
3535
key={index}
36-
id={thread.get('id')}
36+
id={thread.get('threadId')}
3737
preview={thread.get('preview')}
3838
date={thread.get('date')}
3939
participants={thread.get('fromContactName')}

email_mailbox/src/containers/HeaderThreadOptions.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const defineOneThreadSelected = (threads, threadId) => {
1010
});
1111
return [
1212
{
13-
threadIdStore: thread.get('threadId'),
1413
threadIdDB: thread.get('threadId')
1514
}
1615
];
@@ -22,7 +21,7 @@ const defineThreadsSelected = (threads, itemsChecked) => {
2221
.toArray()
2322
.map(thread => ({
2423
threadIdDB: thread.get('threadId'),
25-
uniqueId: thread.get('uniqueId')
24+
emailId: !thread.get('threadId') ? thread.get('id') : null
2625
}));
2726
};
2827

@@ -91,7 +90,9 @@ const mapStateToProps = (state, ownProps) => {
9190
const threadsSelected = ownProps.itemsChecked
9291
? defineThreadsSelected(threads, ownProps.itemsChecked)
9392
: defineOneThreadSelected(threads, ownProps.threadIdSelected);
94-
const uniqueIdsSelected = threadsSelected.map(thread => thread.uniqueId);
93+
const uniqueIdsSelected = threadsSelected.map(
94+
thread => thread.threadIdDB || thread.emailId
95+
);
9596
const threadsLabelIds = getLabelIdsFromThreadIds(threads, uniqueIdsSelected);
9697
const labels = getLabelIncluded(state.get('labels'), threadsLabelIds);
9798
const markAsUnread = ownProps.itemsChecked
@@ -149,21 +150,15 @@ const mapDispatchToProps = (dispatch, ownProps) => {
149150
() => ownProps.onBackOption()
150151
);
151152
},
152-
onRemoveThreads: async (threadsIds, backFirst) => {
153+
onRemoveThreads: async (threadIds, backFirst) => {
153154
if (backFirst) {
154155
await ownProps.onBackOption();
155-
dispatch(actions.removeThreads(threadsIds));
156+
dispatch(actions.removeThreads(threadIds));
156157
} else {
157-
dispatch(actions.removeThreads(threadsIds)).then(() =>
158+
dispatch(actions.removeThreads(threadIds)).then(() =>
158159
ownProps.onBackOption()
159160
);
160161
}
161-
},
162-
onRemoveDrafts: params => {
163-
const isDraft = true;
164-
dispatch(actions.removeThreads(params, isDraft)).then(() =>
165-
ownProps.onBackOption()
166-
);
167162
}
168163
};
169164
};

email_mailbox/src/containers/Message.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const mapDispatchToProps = (dispatch, ownProps) => {
9090
const labelId = LabelType.trash.id;
9191
const emails = await getEmailsByLabelIds([labelId]);
9292
const threadsParams = emails.map(email => ({
93-
threadIdStore: email.id,
93+
emailId: email.id,
9494
threadIdDB: email.threadId
9595
}));
9696
dispatch(removeThreads(threadsParams));

0 commit comments

Comments
 (0)