Unify ICAL parsing and omit property group names.

The property groups were causing us issues and making it very hard
to handle these properties. And since we were not dealing with them
anyway, it's better to just remove them (standard allows this).

ical.js doesn't deal with them correctly, which is the source of this
problem. More info:
https://github.com/mozilla-comm/ical.js/issues/411
master
Tom Hacohen 5 years ago
parent b4634abff4
commit 052543261f

@ -12,9 +12,7 @@ import IconDelete from '@material-ui/icons/Delete';
import IconEdit from '@material-ui/icons/Edit'; import IconEdit from '@material-ui/icons/Edit';
import IconError from '@material-ui/icons/Error'; import IconError from '@material-ui/icons/Error';
import * as ICAL from 'ical.js'; import { TaskType, EventType, ContactType, parseString } from '../pim-types';
import { TaskType, EventType, ContactType } from '../pim-types';
import * as EteSync from 'etesync'; import * as EteSync from 'etesync';
@ -44,9 +42,9 @@ class JournalEntries extends React.PureComponent {
} }
const entries = this.props.entries.map((syncEntry, idx) => { const entries = this.props.entries.map((syncEntry, idx) => {
let parsed; let comp;
try { try {
parsed = ICAL.parse(syncEntry.content); comp = parseString(syncEntry.content);
} catch (e) { } catch (e) {
const icon = (<IconError style={{ color: 'red' }} />); const icon = (<IconError style={{ color: 'red' }} />);
return ( return (
@ -63,7 +61,6 @@ class JournalEntries extends React.PureComponent {
/> />
); );
} }
const comp = new ICAL.Component(parsed);
let icon; let icon;
if (syncEntry.action === EteSync.SyncEntryAction.Add) { if (syncEntry.action === EteSync.SyncEntryAction.Add) {

@ -1,7 +1,5 @@
import { List } from 'immutable'; import { List } from 'immutable';
import * as ICAL from 'ical.js';
import { EventType, ContactType, TaskType } from './pim-types'; import { EventType, ContactType, TaskType } from './pim-types';
import { store } from './store'; import { store } from './store';
import { addError } from './store/actions'; import { addError } from './store/actions';
@ -14,15 +12,14 @@ export function syncEntriesToItemMap(
entries.forEach((syncEntry) => { entries.forEach((syncEntry) => {
// FIXME: this is a terrible hack to handle parsing errors // FIXME: this is a terrible hack to handle parsing errors
let parsed; let comp;
try { try {
parsed = ICAL.parse(syncEntry.content); comp = ContactType.parse(syncEntry.content);
} catch (e) { } catch (e) {
e.message = `${e.message}\nWhile processing: ${syncEntry.content}`; e.message = `${e.message}\nWhile processing: ${syncEntry.content}`;
store.dispatch(addError(undefined as any, e)); store.dispatch(addError(undefined as any, e));
return; return;
} }
const comp = new ContactType(new ICAL.Component(parsed));
// FIXME:Hack // FIXME:Hack
(comp as any).journalUid = collection.uid; (comp as any).journalUid = collection.uid;
@ -69,15 +66,14 @@ function syncEntriesToCalendarItemMap<T extends EventType>(
entries.forEach((syncEntry) => { entries.forEach((syncEntry) => {
// FIXME: this is a terrible hack to handle parsing errors // FIXME: this is a terrible hack to handle parsing errors
let parsed; let comp;
try { try {
parsed = ICAL.parse(syncEntry.content); comp = ItemType.parse(syncEntry.content);
} catch (e) { } catch (e) {
e.message = `${e.message}\nWhile processing: ${syncEntry.content}`; e.message = `${e.message}\nWhile processing: ${syncEntry.content}`;
store.dispatch(addError(undefined as any, e)); store.dispatch(addError(undefined as any, e));
return; return;
} }
const comp = ItemType.fromVCalendar(new ICAL.Component(parsed));
if (comp === null) { if (comp === null) {
return; return;

@ -43,6 +43,11 @@ export function timezoneLoadFromName(timezone: string | null) {
return retZone; 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 { export class EventType extends ICAL.Event implements PimType {
public static isEvent(comp: ICAL.Component) { public static isEvent(comp: ICAL.Component) {
return !!comp.getFirstSubcomponent('vevent'); return !!comp.getFirstSubcomponent('vevent');
@ -55,6 +60,10 @@ export class EventType extends ICAL.Event implements PimType {
return event.clone(); return event.clone();
} }
public static parse(content: string) {
return EventType.fromVCalendar(parseString(content));
}
public color: string; public color: string;
get timezone() { get timezone() {
@ -119,6 +128,10 @@ export class TaskType extends EventType {
return task.clone(); return task.clone();
} }
public static parse(content: string) {
return TaskType.fromVCalendar(parseString(content));
}
public color: string; public color: string;
constructor(comp?: ICAL.Component | null) { constructor(comp?: ICAL.Component | null) {
@ -181,6 +194,13 @@ export class TaskType extends EventType {
export class ContactType implements PimType { export class ContactType implements PimType {
public comp: ICAL.Component; 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) { constructor(comp: ICAL.Component) {
this.comp = comp; this.comp = comp;
} }

Loading…
Cancel
Save