Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
hexadecibal committed Oct 16, 2022
2 parents b927a92 + 6767475 commit 051a72d
Show file tree
Hide file tree
Showing 24 changed files with 519 additions and 143 deletions.
32 changes: 19 additions & 13 deletions app/composer_window/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ const Composer = (props: Props) => {
bodyAsHtml: htmlBody
};

console.log('FROM EMAIL', from);
console.log(eml);

if (htmlBody !== editorState) {
setEditorState(htmlBody);
}
Expand All @@ -183,7 +180,6 @@ const Composer = (props: Props) => {

// When in the Draft folder and Inline, message is set through the Selector
useEffect(() => {
console.log('FIRING OFF 186')
if (
isInline &&
folder?.name === 'Drafts' &&
Expand All @@ -201,21 +197,29 @@ const Composer = (props: Props) => {
draft.from = JSON.parse(email.fromJSON);
handleEmailUpdate(draft, draft.bodyAsHtml || '', mb);
setMailbox(mb);

const data = assembleFromDataSet(mb, namespaces, aliases);
setFromDataSet(data);

if (draft.from.length === 1) {
setFromAddress(draft.from);
const isInSet =
data.filter(d => d.address === draft.from[0].address).length > 0;

if (!isInSet) {
data.push(draft.from[0]);
}
} else {
setFromAddress([draft.from[0]]);
setFromAddress([data[0]]);
}

setFromDataSet(data);

setPrefillRecipients(rcp.ui);
if (draft.to.length > 0) {
setActiveSendButton(true);
}

if (prevMsgIdRef.current !== draft.emailId) {
// console.log('PREV EMAIL GUARD', message);
prevMsgIdRef.current = draft.emailId;
}
})
Expand All @@ -233,8 +237,6 @@ const Composer = (props: Props) => {
// We get the draft email from the IPC Draft storage that was initialized by 'RENDERER::ingestDraftForInlineComposer' or 'RENDERER::showComposerWindow'
// In another electron window, the redux store is unavailable
useEffect(() => {
// console.log('FIRING OFF 235')

if (folder?.name !== 'Drafts' || (folder?.name === 'Drafts' && !isInline)) {
ipcRenderer.on('WINDOW_IPC::contentReady', (event, content, windowID) => {
console.log('IPC event handler', content, windowID);
Expand All @@ -254,20 +256,25 @@ const Composer = (props: Props) => {
? rcp.data.from
: JSON.parse(draft.fromJSON);

console.log(draft);

const data = assembleFromDataSet(
content.mailbox,
content.namespaces,
content.aliases
);
setFromDataSet(data);

if (draft.from.length === 1) {
setFromAddress(draft.from);
const isInSet =
data.filter(d => d.address === draft.from[0].address).length > 0;

if (!isInSet) {
data.push(draft.from[0]);
}
} else {
setFromAddress([data[0]]);
}

setFromDataSet(data);
handleEmailUpdate(draft, draft.bodyAsHtml, content.mailbox);
setMailbox(content.mailbox);
setPrefillRecipients(rcp.ui);
Expand Down Expand Up @@ -304,7 +311,6 @@ const Composer = (props: Props) => {
}, [editorState, email]);

useEffect(() => {
// console.log('ALL READY?', composerReady, editorReady, prevMsgIdRef.current);
if (
editorReady &&
composerReady &&
Expand Down
85 changes: 63 additions & 22 deletions app/ipc/Window.ipc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ITS ME
const { ipcMain, nativeTheme, dialog, BrowserView } = require('electron');
const path = require('path');
const { emailTransform, assembleFromDataSet } = require('../utils/draft.utils');
const store = require('../Store');
const { Console } = require('console');

module.exports = (windowManager, createMainWindow, createLoginWindow) => {
const saveDraft = payload => {
Expand Down Expand Up @@ -197,34 +197,75 @@ module.exports = (windowManager, createMainWindow, createLoginWindow) => {
ipcMain.handle(
'RENDERER::ingestDraftForInlineComposer',
async (event, content) => {
const { message, mailbox, namespaces, aliases, editorAction } = content;

// console.log(content);
const {
message,
mailbox,
namespaces,
aliases,
editorAction,
currentEmailAddress
} = content;

const newDraft = emailTransform(message, editorAction, true);

// console.log(newDraft);


const data = assembleFromDataSet(mailbox, namespaces, aliases);

// console.log(data);

let filteredArray = [];
if (message['toJSON']) {
filteredArray = data.filter(value =>
JSON.parse(message['toJSON'])
.map(m => m.address.replace(/[-+#]/gm, ''))
.includes(value.address.replace(/[-+#]/gm, ''))
);
// Original Message
const OrigFromArr = message.fromJSON ? JSON.parse(message.fromJSON) : [];
let OrigToArr = message.toJSON ? JSON.parse(message.toJSON) : [];
let OrigCcArr = message.ccJSON ? JSON.parse(message.ccJSON) : [];
let OrigBccArr = message.bccJSON ? JSON.parse(message.bccJSON) : [];
let fromArr = [];
let toArr = [];
let ccArr = [];
let bccArr = [];

switch (editorAction) {
case 'replyAll':
toArr = OrigFromArr;
const arr = OrigToArr.filter(
recip =>
recip.address.replace(/[-+#]/gm, '') !==
currentEmailAddress.replace(/[-+#]/gm, '')
);
toArr = [...toArr, ...arr];
break;
case 'reply':
toArr = OrigFromArr;
ccArr = [];
bccArr = [];
break;
case 'forward':
toArr = [];
ccArr = [];
bccArr = [];
break;
default:
break;
}

if (filteredArray.length === 1) {
newDraft.from = filteredArray;
} else {
newDraft.from = data[0]; // which should be the main account
}
// console.log('WINDOWSIPC::DRAFT', newDraft);
fromArr = OrigToArr.filter(
recip =>
recip.address.replace(/[-+#]/gm, '') ===
currentEmailAddress.replace(/[-+#]/gm, '')
).map(f => {
return {
name: f.name.length === 0 ? f.address : f.name,
address: f.address
}
});

// New Message recipients
newDraft.to = toArr;
newDraft.toJSON = JSON.stringify(toArr);
newDraft.cc = toArr;
newDraft.ccJSON = JSON.stringify(ccArr);
newDraft.cc = toArr;
newDraft.ccJSON = JSON.stringify(ccArr);
newDraft.from = fromArr;
newDraft.fromJSON = JSON.stringify(fromArr);
newDraft.bcc = toArr;
newDraft.bccJSON = JSON.stringify(bccArr);

store.setInitialDraft(newDraft);
store.setNewDraft(null);
Expand Down
4 changes: 2 additions & 2 deletions app/login_window/routes/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const Login = () => {
}

const onChangeAcct = (obj: any) => {
setIsRemembered(false);
setLoading(false);
setActiveAcct(obj);
};

Expand Down Expand Up @@ -205,7 +205,7 @@ const Login = () => {
label="Account"
data={accounts}
selected={activeAcct}
onChange={setActiveAcct}
onChange={onChangeAcct}
icon="people"
className=""
/>
Expand Down
37 changes: 21 additions & 16 deletions app/main_window/actions/account/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ export const updateProfileFailure = (error: Error) => {
};
};

export const updateProfile = (data: {
displayName: string;
avatar: string;
}) => {
export const updateProfile = (
data: {
displayName: string;
avatar: string;
},
localOnly = false
) => {
return async (dispatch: Dispatch, getState: GetState) => {
dispatch(updateProfileRequest());

Expand All @@ -56,19 +59,21 @@ export const updateProfile = (data: {
}
} = getState();

try {
console.log('PROFILE DATA', data, allIds[0]);
// We purposefully only let this method update two parameters
await AccountService.updateAccount({
accountId,
...data
});
if (!localOnly) {
try {
console.log('PROFILE DATA', data, allIds[0]);
// We purposefully only let this method update two parameters
await AccountService.updateAccount({
accountId,
...data
});

// We want to change the Display Name of the primary mailbox at the same time.
await MailboxService.updateMailboxName(allIds[0], data.displayName);
} catch (error) {
dispatch(updateProfileFailure(error));
return error;
// We want to change the Display Name of the primary mailbox at the same time.
await MailboxService.updateMailboxName(allIds[0], data.displayName);
} catch (error) {
dispatch(updateProfileFailure(error));
return error;
}
}

dispatch(updateProfileSuccess(data, allIds[0]));
Expand Down
56 changes: 36 additions & 20 deletions app/main_window/actions/contacts/contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const fetchRolladex = () => {

try {
const result = await Contact.getAllContacts();

contacts = result.map((c: any) => {
// const address = c.address ? JSON.parse(c.address) : [];
// const phone = c.phone ? JSON.parse(c.phone) : [];
Expand Down Expand Up @@ -98,22 +98,33 @@ export const contactSaveFailure = (error: Error) => {
};
};

export const commitContactsUpdates = (contact: ContactType) => {
export const commitContactsUpdates = (
contact: ContactType,
localOnly = false
) => {
return async (dispatch: Dispatch) => {
dispatch(contactSaveRequest());
let c;
try {
if ('contactId' in contact) {
await Contact.updateContact(contact);
c = contact;
} else {
const result = await Contact.createContacts([contact]);
c = result[0];

// We may want to skip updating the Drive Collection
// i.e. in case of a collection:update event
if (!localOnly) {
try {
if ('contactId' in contact) {
await Contact.updateContact(contact);
c = contact;
} else {
const result = await Contact.createContacts([contact]);
c = result[0];
}
} catch (error) {
dispatch(contactSaveFailure(error));
return error;
}
} catch (error) {
dispatch(contactSaveFailure(error));
return error;
} else {
c = contact;
}

dispatch(contactSaveSuccess(c));

return c;
Expand All @@ -136,7 +147,7 @@ export const CONTACT_DELETION_REQUEST_SUCCESS =
export const contactDeletionSuccess = (contactId: any) => {
return {
type: CONTACT_DELETION_REQUEST_SUCCESS,
contactId: contactId
contactId
};
};

Expand All @@ -149,15 +160,20 @@ export const contactDeletionFailure = (error: Error) => {
};
};

export const deleteContact = (contactId: number) => {
export const deleteContact = (contactId: number, localOnly = false) => {
return async (dispatch: Dispatch) => {
dispatch(contactDeletionRequest());
try {
console.log('DELETE ', contactId)
await Contact.removeContact(contactId);
} catch (error) {
dispatch(contactDeletionFailure(error));
return error;

// We may want to skip updating the Drive Collection
// i.e. in case of a collection:update event
if (!localOnly) {
try {
console.log('DELETE ', contactId);
await Contact.removeContact(contactId);
} catch (error) {
dispatch(contactDeletionFailure(error));
return error;
}
}

dispatch(contactDeletionSuccess(contactId));
Expand Down
Loading

0 comments on commit 051a72d

Please sign in to comment.