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.
35 lines
902 B
TypeScript
35 lines
902 B
TypeScript
7 years ago
|
import { List } from 'immutable';
|
||
|
|
||
7 years ago
|
import * as EteSync from './api/EteSync';
|
||
|
|
||
7 years ago
|
import { CredentialsData } from './store';
|
||
|
import { createEntries } from './store/actions';
|
||
7 years ago
|
|
||
|
export function createJournalEntry(
|
||
|
etesync: CredentialsData,
|
||
|
journal: EteSync.Journal,
|
||
7 years ago
|
existingEntries: List<EteSync.Entry>,
|
||
7 years ago
|
action: EteSync.SyncEntryAction,
|
||
7 years ago
|
content: string) {
|
||
|
|
||
|
let syncEntry = new EteSync.SyncEntry();
|
||
7 years ago
|
syncEntry.action = action;
|
||
7 years ago
|
|
||
|
syncEntry.content = content;
|
||
|
|
||
|
const derived = etesync.encryptionKey;
|
||
|
let prevUid: string | null = null;
|
||
|
|
||
|
const entries = existingEntries;
|
||
7 years ago
|
const last = entries.last();
|
||
|
if (last) {
|
||
|
prevUid = last.uid;
|
||
7 years ago
|
}
|
||
|
|
||
|
const cryptoManager = new EteSync.CryptoManager(derived, journal.uid, journal.version);
|
||
|
let entry = new EteSync.Entry();
|
||
|
entry.setSyncEntry(cryptoManager, syncEntry, prevUid);
|
||
|
|
||
|
return createEntries(etesync, journal.uid, [entry], prevUid);
|
||
|
}
|