Add support for saving entries to shared journals.

master
Tom Hacohen 7 years ago
parent 71e20bb65f
commit 9c740a4c4d

@ -26,7 +26,7 @@ import PimMain from './PimMain';
import { routeResolver } from '../App'; import { routeResolver } from '../App';
import { store, CredentialsData } from '../store'; import { store, CredentialsData, UserInfoData } from '../store';
import { SyncInfo } from '../SyncGate'; import { SyncInfo } from '../SyncGate';
@ -193,6 +193,7 @@ const CollectionRoutes = withRouter(
class Pim extends React.PureComponent { class Pim extends React.PureComponent {
props: { props: {
etesync: CredentialsData; etesync: CredentialsData;
userInfo: UserInfoData;
syncInfo: SyncInfo; syncInfo: SyncInfo;
history: History; history: History;
}; };
@ -215,7 +216,8 @@ class Pim extends React.PureComponent {
let action = (originalEvent === undefined) ? EteSync.SyncEntryAction.Add : EteSync.SyncEntryAction.Change; let action = (originalEvent === undefined) ? EteSync.SyncEntryAction.Add : EteSync.SyncEntryAction.Change;
let saveEvent = store.dispatch( let saveEvent = store.dispatch(
createJournalEntry(this.props.etesync, journal, syncJournal.journalEntries, action, item.toIcal())); createJournalEntry(
this.props.etesync, this.props.userInfo, journal, syncJournal.journalEntries, action, item.toIcal()));
(saveEvent as any).then(() => { (saveEvent as any).then(() => {
this.props.history.goBack(); this.props.history.goBack();
}); });
@ -232,7 +234,8 @@ class Pim extends React.PureComponent {
let action = EteSync.SyncEntryAction.Delete; let action = EteSync.SyncEntryAction.Delete;
let deleteItem = store.dispatch( let deleteItem = store.dispatch(
createJournalEntry(this.props.etesync, journal, syncJournal.journalEntries, action, item.toIcal())); createJournalEntry(
this.props.etesync, this.props.userInfo, journal, syncJournal.journalEntries, action, item.toIcal()));
(deleteItem as any).then(() => { (deleteItem as any).then(() => {
this.props.history.push(routeResolver.getRoute('pim')); this.props.history.push(routeResolver.getRoute('pim'));
}); });

@ -157,6 +157,7 @@ class SyncGate extends React.PureComponent {
render={({match, history}) => ( render={({match, history}) => (
<PimRouter <PimRouter
etesync={this.props.etesync} etesync={this.props.etesync}
userInfo={this.props.userInfo.value!}
syncInfo={journalMap} syncInfo={journalMap}
history={history} history={history}
/> />

@ -2,11 +2,12 @@ import { List } from 'immutable';
import * as EteSync from './api/EteSync'; import * as EteSync from './api/EteSync';
import { CredentialsData } from './store'; import { CredentialsData, UserInfoData } from './store';
import { createEntries } from './store/actions'; import { createEntries } from './store/actions';
export function createJournalEntry( export function createJournalEntry(
etesync: CredentialsData, etesync: CredentialsData,
userInfo: UserInfoData,
journal: EteSync.Journal, journal: EteSync.Journal,
existingEntries: List<EteSync.Entry>, existingEntries: List<EteSync.Entry>,
action: EteSync.SyncEntryAction, action: EteSync.SyncEntryAction,
@ -26,7 +27,15 @@ export function createJournalEntry(
prevUid = last.uid; prevUid = last.uid;
} }
const cryptoManager = new EteSync.CryptoManager(derived, journal.uid, journal.version); let cryptoManager: EteSync.CryptoManager;
if (journal.key) {
const keyPair = userInfo.getKeyPair(new EteSync.CryptoManager(derived, 'userInfo', userInfo.version));
const asymmetricCryptoManager = new EteSync.AsymmetricCryptoManager(keyPair);
const derivedJournalKey = asymmetricCryptoManager.decryptBytes(journal.key);
cryptoManager = EteSync.CryptoManager.fromDerivedKey(derivedJournalKey, journal.version);
} else {
cryptoManager = new EteSync.CryptoManager(derived, journal.uid, journal.version);
}
let entry = new EteSync.Entry(); let entry = new EteSync.Entry();
entry.setSyncEntry(cryptoManager, syncEntry, prevUid); entry.setSyncEntry(cryptoManager, syncEntry, prevUid);

Loading…
Cancel
Save