mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 13:44:41 +08:00
34f68dcc0d
Summary: - WIP: Need to fix tests and some errors! - Refactors Category class to hold information about its type - Refactors CategoryStore to rely on observables instead of local caches - Adds and updates Observables and helpers - Refactors ContactStore to hold entire cache of contacts instead of per current account - Same for ContactRankingStore and other stores - Refactors method names for AccountStore + some helpers - Updates MailViewFilter to hold an account - Adds basic Unified filter - Replaces AccountStore.current calls with either: - The account of the currently focused MailViewFilter - The account associated with a thread, message, file, etc... - A parameter to be passed in - Arbitrarily, the first account in the AccountsStore Test Plan: - Unit tests Reviewers: evan, bengotow Differential Revision: https://phab.nylas.com/D2423
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
import {AccountStore, Actions} from 'nylas-exports';
|
|
import PrintWindow from './print-window';
|
|
|
|
class Printer {
|
|
|
|
constructor() {
|
|
this.unsub = Actions.printThread.listen(this._printThread);
|
|
}
|
|
|
|
_printThread(thread, htmlContent) {
|
|
if (!thread) throw new Error('Printing: No thread active!');
|
|
const account = AccountStore.accountForId(thread.accountId)
|
|
|
|
// Get the <nylas-styles> tag present in the document
|
|
const styleTag = document.getElementsByTagName('nylas-styles')[0];
|
|
// These iframes should correspond to the message iframes when a thread is
|
|
// focused
|
|
const iframes = document.getElementsByTagName('iframe');
|
|
// Grab the html inside the iframes
|
|
const messagesHtml = [].slice.call(iframes).map((iframe)=> {
|
|
return iframe.contentDocument.documentElement.innerHTML;
|
|
});
|
|
|
|
const win = new PrintWindow({
|
|
subject: thread.subject,
|
|
account: {
|
|
name: account.name,
|
|
email: account.emailAddress,
|
|
},
|
|
participants: thread.participants,
|
|
styleTags: styleTag.innerHTML,
|
|
htmlContent,
|
|
printMessages: JSON.stringify(messagesHtml),
|
|
});
|
|
win.load();
|
|
}
|
|
|
|
deactivate() {
|
|
this.unsub();
|
|
}
|
|
}
|
|
|
|
export default Printer;
|