You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4 KiB
TypeScript

import * as EteSync from './api/EteSync';
import { CredentialsData, UserInfoData } from './store';
import { addEntries } from './store/actions';
export function createJournalEntry(
etesync: CredentialsData,
userInfo: UserInfoData,
journal: EteSync.Journal,
prevUid: string | null,
action: EteSync.SyncEntryAction,
content: string) {
const syncEntry = new EteSync.SyncEntry();
syncEntry.action = action;
syncEntry.content = content;
return createJournalEntryFromSyncEntry(etesync, userInfo, journal, prevUid, syncEntry);
}
export function createJournalEntryFromSyncEntry(
etesync: CredentialsData,
userInfo: UserInfoData,
journal: EteSync.Journal,
prevUid: string | null,
syncEntry: EteSync.SyncEntry) {
const derived = etesync.encryptionKey;
const keyPair = userInfo.getKeyPair(userInfo.getCryptoManager(derived));
const cryptoManager = journal.getCryptoManager(derived, keyPair);
const entry = new EteSync.Entry();
entry.setSyncEntry(cryptoManager, syncEntry, prevUid);
return entry;
}
export function addJournalEntry(
etesync: CredentialsData,
userInfo: UserInfoData,
journal: EteSync.Journal,
prevUid: string | null,
action: EteSync.SyncEntryAction,
content: string) {
const entry = createJournalEntry(etesync, userInfo, journal, prevUid, action, content);
return addEntries(etesync, journal.uid, [entry], prevUid);
}