Support shared journals in side menu too.

This code path needs to be merged with SyncGate.
master
Tom Hacohen 7 years ago
parent cf823f5efe
commit 719b0516f0

@ -4,12 +4,13 @@ import { ListItem } from '../widgets/List';
import * as EteSync from '../api/EteSync'; import * as EteSync from '../api/EteSync';
import { JournalsData, CredentialsData } from '../store'; import { JournalsData, UserInfoData, CredentialsData } from '../store';
class SideMenuJournals extends React.PureComponent { class SideMenuJournals extends React.PureComponent {
props: { props: {
etesync: CredentialsData; etesync: CredentialsData;
journals: JournalsData; journals: JournalsData;
userInfo: UserInfoData;
onItemClick: (journalUid: string) => void; onItemClick: (journalUid: string) => void;
}; };
@ -19,21 +20,21 @@ class SideMenuJournals extends React.PureComponent {
render() { render() {
const derived = this.props.etesync.encryptionKey; const derived = this.props.etesync.encryptionKey;
let asymmetricCryptoManager: EteSync.AsymmetricCryptoManager;
const journalMap = this.props.journals.reduce( const journalMap = this.props.journals.reduce(
(ret, journal) => { (ret, journal) => {
// FIXME: Skip shared journals for now let cryptoManager: EteSync.CryptoManager;
if (journal.key) { if (journal.key) {
const key = 'UNSUPPORTED'; if (!asymmetricCryptoManager) {
ret[key] = ret[key] || []; const userInfo = this.props.userInfo;
ret[key].push( const keyPair = userInfo.getKeyPair(new EteSync.CryptoManager(derived, 'userInfo', userInfo.version));
<ListItem asymmetricCryptoManager = new EteSync.AsymmetricCryptoManager(keyPair);
key={journal.uid} }
> const derivedJournalKey = asymmetricCryptoManager.decryptBytes(journal.key);
{journal.uid.slice(0, 20)} cryptoManager = EteSync.CryptoManager.fromDerivedKey(derivedJournalKey, journal.version);
</ListItem>
);
} else { } else {
let cryptoManager = new EteSync.CryptoManager(derived, journal.uid, journal.version); cryptoManager = new EteSync.CryptoManager(derived, journal.uid, journal.version);
}
let info = journal.getInfo(cryptoManager); let info = journal.getInfo(cryptoManager);
ret[info.type] = ret[info.type] || []; ret[info.type] = ret[info.type] || [];
ret[info.type].push( ret[info.type].push(
@ -41,13 +42,12 @@ class SideMenuJournals extends React.PureComponent {
{info.displayName} ({journal.uid.slice(0, 5)}) {info.displayName} ({journal.uid.slice(0, 5)})
</ListItem> </ListItem>
); );
}
return ret; return ret;
}, },
{ CALENDAR: [], { CALENDAR: [],
ADDRESS_BOOK: [], ADDRESS_BOOK: []
UNSUPPORTED: [] as Array<JSX.Element>}); });
return ( return (
<React.Fragment> <React.Fragment>
@ -60,13 +60,6 @@ class SideMenuJournals extends React.PureComponent {
primaryText="Calendars" primaryText="Calendars"
nestedItems={journalMap.CALENDAR} nestedItems={journalMap.CALENDAR}
/> />
{ journalMap.UNSUPPORTED && (
<ListItem
primaryText="UNSUPPORTED"
nestedItems={journalMap.UNSUPPORTED}
/>
)}
</React.Fragment> </React.Fragment>
); );
} }

@ -17,7 +17,7 @@ import ErrorBoundary from '../components/ErrorBoundary';
import { routeResolver, getPalette } from '../App'; import { routeResolver, getPalette } from '../App';
import { store, JournalsType, StoreState, CredentialsData } from '../store'; import { store, JournalsType, UserInfoData, StoreState, CredentialsData } from '../store';
import { logout } from '../store/actions'; import { logout } from '../store/actions';
import * as C from '../constants'; import * as C from '../constants';
@ -29,6 +29,7 @@ interface PropsType {
interface PropsTypeInner extends PropsType { interface PropsTypeInner extends PropsType {
journals: JournalsType; journals: JournalsType;
userInfo: UserInfoData;
history: History; history: History;
} }
@ -58,7 +59,9 @@ class SideMenu extends React.PureComponent {
let loggedInItems; let loggedInItems;
if (this.props.etesync) { if (this.props.etesync) {
const journals = (this.props.etesync.encryptionKey && this.props.journals && this.props.journals.value) && ( const journals = (this.props.etesync.encryptionKey && this.props.journals && this.props.journals.value
&& this.props.userInfo) && (
<React.Fragment> <React.Fragment>
<ListDivider /> <ListDivider />
<ListSubheader>Journals</ListSubheader> <ListSubheader>Journals</ListSubheader>
@ -66,6 +69,7 @@ class SideMenu extends React.PureComponent {
<SideMenuJournals <SideMenuJournals
etesync={this.props.etesync} etesync={this.props.etesync}
journals={this.props.journals.value} journals={this.props.journals.value}
userInfo={this.props.userInfo}
onItemClick={this.journalClicked} onItemClick={this.journalClicked}
/> />
</ErrorBoundary> </ErrorBoundary>
@ -113,6 +117,7 @@ class SideMenu extends React.PureComponent {
const mapStateToProps = (state: StoreState, props: PropsType) => { const mapStateToProps = (state: StoreState, props: PropsType) => {
return { return {
journals: state.cache.journals, journals: state.cache.journals,
userInfo: state.cache.userInfo.value,
}; };
}; };

Loading…
Cancel
Save