Skip to content

Commit

Permalink
TED-48 completed, now all draft should have a defacto address when th…
Browse files Browse the repository at this point in the history
…ey are created.
  • Loading branch information
ynnelson committed Oct 19, 2022
1 parent f50c7cb commit 3780d5a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 16 deletions.
21 changes: 16 additions & 5 deletions app/composer_window/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,15 @@ const Composer = (props: Props) => {
draft.from = JSON.parse(email.fromJSON);
handleEmailUpdate(draft, draft.bodyAsHtml || '', mb);
setMailbox(mb);

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

console.log(data);

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

if (!isInSet) {
data.push(draft.from[0]);
Expand All @@ -230,6 +232,15 @@ const Composer = (props: Props) => {
placement: 'bottomEnd'
});
});
} else if (
isInline &&
folder?.name === 'Drafts' &&
dispatch !== null &&
message.emailId === null
) {
const data = assembleFromDataSet(mb, namespaces, aliases);
setFromAddress([data[0]]);
setFromDataSet(data);
}
}, [isInline, folder, message?.bodyAsHtml, message?.emailId]);

Expand Down Expand Up @@ -261,11 +272,11 @@ const Composer = (props: Props) => {
content.namespaces,
content.aliases
);

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

if (!isInSet) {
data.push(draft.from[0]);
Expand Down Expand Up @@ -397,7 +408,7 @@ const Composer = (props: Props) => {
const { value } = e.target;

const newEmail = clone(email);
newEmail.subject = value;
newEmail.subject = value || '';

handleEmailUpdate(newEmail);
};
Expand Down
4 changes: 2 additions & 2 deletions app/composer_window/components/FromInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const FromInput = (props: Props) => {
<Listbox.Options className="absolute z-10 mt-2 w-full bg-white shadow-lg max-h-60 rounded-md py-1 text-base ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none sm:text-sm">
{fromDataSet.map(email => (
<Listbox.Option
key={email.address}
key={email?.address}
className={({ active }) =>
classNames(
active ? 'bg-blue-200 text-gray-900' : 'text-gray-900',
Expand All @@ -72,7 +72,7 @@ const FromInput = (props: Props) => {
'block truncate'
)}
>
{email.address}
{email?.address}
</span>

{selected ? (
Expand Down
24 changes: 19 additions & 5 deletions app/ipc/Window.ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,27 @@ module.exports = (windowManager, createMainWindow, createLoginWindow) => {

// 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) : [];
const OrigToArr = message.toJSON ? JSON.parse(message.toJSON) : [];
const OrigCcArr = message.ccJSON ? JSON.parse(message.ccJSON) : [];
const OrigBccArr = message.bccJSON ? JSON.parse(message.bccJSON) : [];
let fromArr = [];
let toArr = [];
let ccArr = [];
let bccArr = [];

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
};
});

switch (editorAction) {
case 'replyAll':
case 'replyAll':
toArr = OrigFromArr;
const arr = OrigToArr.filter(
recip =>
Expand All @@ -241,6 +252,9 @@ module.exports = (windowManager, createMainWindow, createLoginWindow) => {
bccArr = [];
break;
default:
fromArr = [
{ name: currentEmailAddress, address: currentEmailAddress }
];
break;
}

Expand All @@ -252,7 +266,7 @@ module.exports = (windowManager, createMainWindow, createLoginWindow) => {
return {
name: f.name.length === 0 ? f.address : f.name,
address: f.address
}
};
});

// New Message recipients
Expand Down
1 change: 1 addition & 0 deletions app/main_window/components/Mail/Navigation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default function Navigation(props: Props) {
const newMessageAction = async () => {
await dispatch(clearActiveMessage(folderId));
dispatch(toggleEditor('brandNewComposer', true));
console.log(currentEmailAddress);
await ipcRenderer.invoke('RENDERER::ingestDraftForInlineComposer', {
mailbox,
namespaces,
Expand Down
8 changes: 4 additions & 4 deletions app/utils/contact.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const stringThemUp = (
currentIndex: number
) => {
const name =
current.name && current.name.trim() !== current.address.trim()
? `${current.name} ${complex ? `<${current.address}>` : ''}`
: `${current.address}`;
current?.name && current?.name.trim() !== current?.address.trim()
? `${current?.name} ${complex ? `<${current?.address}>` : ''}`
: `${current?.address}`;

let val = name;

Expand Down Expand Up @@ -52,7 +52,7 @@ const peopleHeaderParser = (

let previewHead;

if(from?.arr[0].length) {
if(Array.isArray(from?.arr[0])) {
from.arr[0] = from.arr[0][0]
}

Expand Down

0 comments on commit 3780d5a

Please sign in to comment.