diff --git a/src/components/JournalEntries.tsx b/src/components/JournalEntries.tsx
index 4d1f12e..c8afc43 100644
--- a/src/components/JournalEntries.tsx
+++ b/src/components/JournalEntries.tsx
@@ -12,9 +12,7 @@ import IconDelete from '@material-ui/icons/Delete';
import IconEdit from '@material-ui/icons/Edit';
import IconError from '@material-ui/icons/Error';
-import * as ICAL from 'ical.js';
-
-import { TaskType, EventType, ContactType } from '../pim-types';
+import { TaskType, EventType, ContactType, parseString } from '../pim-types';
import * as EteSync from 'etesync';
@@ -44,9 +42,9 @@ class JournalEntries extends React.PureComponent {
}
const entries = this.props.entries.map((syncEntry, idx) => {
- let parsed;
+ let comp;
try {
- parsed = ICAL.parse(syncEntry.content);
+ comp = parseString(syncEntry.content);
} catch (e) {
const icon = ();
return (
@@ -63,7 +61,6 @@ class JournalEntries extends React.PureComponent {
/>
);
}
- const comp = new ICAL.Component(parsed);
let icon;
if (syncEntry.action === EteSync.SyncEntryAction.Add) {
diff --git a/src/journal-processors.ts b/src/journal-processors.ts
index 5e573c1..10c7c4c 100644
--- a/src/journal-processors.ts
+++ b/src/journal-processors.ts
@@ -1,7 +1,5 @@
import { List } from 'immutable';
-import * as ICAL from 'ical.js';
-
import { EventType, ContactType, TaskType } from './pim-types';
import { store } from './store';
import { addError } from './store/actions';
@@ -14,15 +12,14 @@ export function syncEntriesToItemMap(
entries.forEach((syncEntry) => {
// FIXME: this is a terrible hack to handle parsing errors
- let parsed;
+ let comp;
try {
- parsed = ICAL.parse(syncEntry.content);
+ comp = ContactType.parse(syncEntry.content);
} catch (e) {
e.message = `${e.message}\nWhile processing: ${syncEntry.content}`;
store.dispatch(addError(undefined as any, e));
return;
}
- const comp = new ContactType(new ICAL.Component(parsed));
// FIXME:Hack
(comp as any).journalUid = collection.uid;
@@ -69,15 +66,14 @@ function syncEntriesToCalendarItemMap(
entries.forEach((syncEntry) => {
// FIXME: this is a terrible hack to handle parsing errors
- let parsed;
+ let comp;
try {
- parsed = ICAL.parse(syncEntry.content);
+ comp = ItemType.parse(syncEntry.content);
} catch (e) {
e.message = `${e.message}\nWhile processing: ${syncEntry.content}`;
store.dispatch(addError(undefined as any, e));
return;
}
- const comp = ItemType.fromVCalendar(new ICAL.Component(parsed));
if (comp === null) {
return;
diff --git a/src/pim-types.ts b/src/pim-types.ts
index 4917558..7a89216 100644
--- a/src/pim-types.ts
+++ b/src/pim-types.ts
@@ -43,6 +43,11 @@ export function timezoneLoadFromName(timezone: string | null) {
return retZone;
}
+export function parseString(content: string) {
+ content = content.replace(/^[a-zA-Z0-9]*\./gm, ''); // FIXME: ugly hack to ignore item groups.
+ return new ICAL.Component(ICAL.parse(content));
+}
+
export class EventType extends ICAL.Event implements PimType {
public static isEvent(comp: ICAL.Component) {
return !!comp.getFirstSubcomponent('vevent');
@@ -55,6 +60,10 @@ export class EventType extends ICAL.Event implements PimType {
return event.clone();
}
+ public static parse(content: string) {
+ return EventType.fromVCalendar(parseString(content));
+ }
+
public color: string;
get timezone() {
@@ -119,6 +128,10 @@ export class TaskType extends EventType {
return task.clone();
}
+ public static parse(content: string) {
+ return TaskType.fromVCalendar(parseString(content));
+ }
+
public color: string;
constructor(comp?: ICAL.Component | null) {
@@ -181,6 +194,13 @@ export class TaskType extends EventType {
export class ContactType implements PimType {
public comp: ICAL.Component;
+ public static parse(content: string) {
+ if (content.search(/davdroid/i)) {
+ console.log(content);
+ }
+ return new ContactType(parseString(content));
+ }
+
constructor(comp: ICAL.Component) {
this.comp = comp;
}