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
8 changes: 4 additions & 4 deletions electron_app/src/windows/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const destroy = async ({ composerId, emailId }) => {
oldDraftEmail.id,
undefined
);
sendEventToMailbox('update-drafts', { operation: 'less', value: 1 });
sendEventToMailbox('update-drafts', true);
} else if (
type === composerEvents.REPLY ||
type === composerEvents.REPLY_ALL
Expand Down Expand Up @@ -175,10 +175,10 @@ const sendEventToMailbox = (eventName, data) => {
const saveDraftToDatabase = async (composerId, dataDraft) => {
const emailToEdit = globalManager.emailToEdit.get(composerId);
const { type, key } = emailToEdit || {};
let badgeOperation = {};
let shouldUpdateBadge = false;
if ((!type && !key) || type !== composerEvents.EDIT_DRAFT) {
await dbManager.createEmail(dataDraft);
badgeOperation = { operation: 'add', value: 1 };
shouldUpdateBadge = true;
} else {
const [oldEmail] = await dbManager.getEmailByKey(key);
const newEmailId = await dbManager.deleteEmailLabelAndContactByEmailId(
Expand All @@ -195,7 +195,7 @@ const saveDraftToDatabase = async (composerId, dataDraft) => {
return;
}
}
sendEventToMailbox('update-drafts', badgeOperation);
sendEventToMailbox('update-drafts', shouldUpdateBadge);
};

module.exports = {
Expand Down
15 changes: 0 additions & 15 deletions email_mailbox/src/actions/emails.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Email } from './types';
import {
getContactByIds,
getEmailsByThreadId,
updateUnreadEmailByThreadIds,
setMuteEmailById,
setUnreadEmailById,
updateEmail,
Expand All @@ -12,7 +11,6 @@ import {
} from '../utils/electronInterface';
import { EmailUtils } from '../utils/electronUtilsInterface';
import { loadContacts } from './contacts';
import { updateLabelSuccess } from './labels';
import { EmailStatus, SocketCommand } from '../utils/const';
import { unsendEmailFiles } from './files';
import {
Expand Down Expand Up @@ -139,19 +137,6 @@ export const removeEmailsOnSuccess = emailIds => ({
emailIds
});

export const updateUnreadEmails = (thread, label) => {
return async dispatch => {
try {
await updateUnreadEmailByThreadIds([thread.id], thread.unread);
if (label) {
dispatch(updateLabelSuccess(label));
}
} catch (e) {
// To do
}
};
};

export const unsendEmail = params => {
return async dispatch => {
const { key, emailId, contactIds, unsendDate } = params;
Expand Down
4 changes: 2 additions & 2 deletions email_mailbox/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
muteNotifications,
removeEmails,
removeEmailsOnSuccess,
updateUnreadEmails,
unsendEmail,
unsendEmailOnSuccess,
updateEmailLabels
Expand All @@ -47,6 +46,7 @@ import {
loadLabels,
removeLabel,
removeLabelOnSuccess,
updateBadgeLabels,
updateLabel,
updateLabelSuccess
} from './labels';
Expand Down Expand Up @@ -111,13 +111,13 @@ export {
unsendEmailFiles,
unsendEmailOnSuccess,
updateAllFeedItemsAsOlder,
updateBadgeLabels,
updateFeedItemSuccess,
updateEmailIdsThread,
updateEmailLabels,
updateLabel,
updateLabelSuccess,
updateStatusThread,
updateUnreadEmails,
updateUnreadThreads,
updateUnreadThreadsSuccess
};
131 changes: 91 additions & 40 deletions email_mailbox/src/actions/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,14 @@ import {
updateLabel as updateLabelDB,
deleteLabelById
} from '../utils/electronInterface';
import { sendUpdateLabelsErrorMessage } from './../utils/electronEventInterface';
import { SocketCommand } from '../utils/const';

export const addLabels = labels => {
return {
type: Label.ADD_BATCH,
labels: labels
};
};

export const updateLabelSuccess = label => {
return {
type: Label.UPDATE_SUCCESS,
label: label
};
};

export const addLabel = (label, isByEvent) => {
export const addLabel = label => {
return async dispatch => {
try {
const [response] = await createLabel(label);
if (response) {
const labelId = response;
const [labelId] = await createLabel(label);
if (labelId) {
const { text, color, visible } = label;
const labels = {
[labelId]: {
Expand All @@ -41,23 +27,26 @@ export const addLabel = (label, isByEvent) => {
visible
}
};
if (isByEvent) {
dispatch(addLabels(labels));
} else {
const eventParams = {
cmd: SocketCommand.PEER_LABEL_CREATED,
params: { color, text }
};
await postPeerEvent(eventParams);
dispatch(addLabels(labels));
}
const eventParams = {
cmd: SocketCommand.PEER_LABEL_CREATED,
params: { color: color.replace('#', ''), text }
};
await postPeerEvent(eventParams);
dispatch(addLabels(labels));
}
} catch (e) {
//TO DO
sendUpdateLabelsErrorMessage();
}
};
};

export const addLabels = labels => {
return {
type: Label.ADD_BATCH,
labels
};
};

export const loadLabels = () => {
return async dispatch => {
try {
Expand Down Expand Up @@ -85,11 +74,31 @@ export const loadLabels = () => {
labels[LabelType.draft.id].badge = badgeDraft[0].count;
dispatch(addLabels(labels));
} catch (e) {
// TO DO
sendUpdateLabelsErrorMessage();
}
};
};

export const removeLabel = id => {
return async dispatch => {
try {
const response = await deleteLabelById(id);
if (response) {
dispatch(removeLabelOnSuccess(id));
}
} catch (e) {
sendUpdateLabelsErrorMessage();
}
};
};

export const removeLabelOnSuccess = labelId => {
return {
type: Label.REMOVE,
labelId
};
};

export const updateLabel = ({ id, color, text, visible }) => {
return async dispatch => {
try {
Expand All @@ -98,27 +107,69 @@ export const updateLabel = ({ id, color, text, visible }) => {
dispatch(updateLabelSuccess({ id, color, text, visible }));
}
} catch (e) {
// TO DO
sendUpdateLabelsErrorMessage();
}
};
};

export const removeLabel = id => {
export const updateBadgeLabels = labelIds => {
return async dispatch => {
if (!labelIds.length) return;
try {
const response = await deleteLabelById(id);
if (response) {
dispatch(removeLabelOnSuccess(id));
}
const labelsFiltered = labelIds.filter(labelId => {
return (
labelId === LabelType.inbox.id ||
labelId === LabelType.spam.id ||
labelId === LabelType.draft.id
);
});
const labels = await Promise.all(
labelsFiltered.map(async labelId => {
if (labelId === LabelType.inbox.id) {
const rejectedLabelIds = [LabelType.spam.id, LabelType.trash.id];
const unreadInbox = await getEmailsUnredByLabelId({
labelId,
rejectedLabelIds
});
const badgeInbox = unreadInbox.length;
return {
id: String(labelId),
badge: badgeInbox
};
} else if (labelId === LabelType.spam.id) {
const unreadSpam = await getEmailsUnredByLabelId({
labelId
});
const badgeSpam = unreadSpam.length;
return {
id: String(labelId),
badge: badgeSpam
};
} else if (labelId === LabelType.draft.id) {
const badgeDraft = await getEmailsCounterByLabelId(labelId);
return {
id: String(labelId),
badge: badgeDraft[0].count
};
}
})
);
dispatch(updateBadgeLabelsSuccess(labels));
} catch (e) {
// TO DO
sendUpdateLabelsErrorMessage();
}
};
};
export const updateBadgeLabelsSuccess = labelIds => {
return {
type: Label.UPDATE_BADGE_LABELS,
labelIds
};
};

export const removeLabelOnSuccess = labelId => {
export const updateLabelSuccess = label => {
return {
type: Label.REMOVE_SUCCESS,
labelId
type: Label.UPDATE,
label
};
};
Loading