@@ -133,7 +133,9 @@ export const addLabelIdThreadsSuccess = (threadIds, labelId) => ({
133133export 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
273303export 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-
401401export 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- } ) ;
0 commit comments