Import: make sure imported contacts/events/tasks have a uid.

Fixes #71.
master
Tom Hacohen 5 years ago
parent b54f25eee9
commit db75d82322

@ -18,6 +18,7 @@ import { addEntries } from '../store/actions';
import { createJournalEntry } from '../etesync-helpers'; import { createJournalEntry } from '../etesync-helpers';
import * as EteSync from 'etesync'; import * as EteSync from 'etesync';
import * as uuid from 'uuid';
import * as ICAL from 'ical.js'; import * as ICAL from 'ical.js';
import { ContactType, EventType, TaskType, PimType } from '../pim-types'; import { ContactType, EventType, TaskType, PimType } from '../pim-types';
@ -155,7 +156,13 @@ class ImportDialog extends React.Component<PropsType> {
private onFileDropContact(acceptedFiles: File[], rejectedFiles: File[]) { private onFileDropContact(acceptedFiles: File[], rejectedFiles: File[]) {
const itemsCreator = (fileText: string) => { const itemsCreator = (fileText: string) => {
const mainComp = ICAL.parse(fileText); const mainComp = ICAL.parse(fileText);
return mainComp.map((comp) => new ContactType(new ICAL.Component(comp))); return mainComp.map((comp) => {
const ret = new ContactType(new ICAL.Component(comp));
if (!ret.uid) {
ret.uid = uuid.v4();
}
return ret;
});
}; };
this.onFileDropCommon(itemsCreator, acceptedFiles, rejectedFiles); this.onFileDropCommon(itemsCreator, acceptedFiles, rejectedFiles);
@ -165,7 +172,11 @@ class ImportDialog extends React.Component<PropsType> {
const itemsCreator = (fileText: string) => { const itemsCreator = (fileText: string) => {
const calendarComp = new ICAL.Component(ICAL.parse(fileText)); const calendarComp = new ICAL.Component(ICAL.parse(fileText));
return calendarComp.getAllSubcomponents('vevent').map((comp) => { return calendarComp.getAllSubcomponents('vevent').map((comp) => {
return new EventType(comp); const ret = new EventType(comp);
if (!ret.uid) {
ret.uid = uuid.v4();
}
return ret;
}); });
}; };
@ -176,7 +187,11 @@ class ImportDialog extends React.Component<PropsType> {
const itemsCreator = (fileText: string) => { const itemsCreator = (fileText: string) => {
const calendarComp = new ICAL.Component(ICAL.parse(fileText)); const calendarComp = new ICAL.Component(ICAL.parse(fileText));
return calendarComp.getAllSubcomponents('vtodo').map((comp) => { return calendarComp.getAllSubcomponents('vtodo').map((comp) => {
return new TaskType(comp); const ret = new TaskType(comp);
if (!ret.uid) {
ret.uid = uuid.v4();
}
return ret;
}); });
}; };

@ -214,6 +214,10 @@ export class ContactType implements PimType {
return this.comp.getFirstPropertyValue('uid'); return this.comp.getFirstPropertyValue('uid');
} }
set uid(uid: string) {
this.comp.updatePropertyWithValue('uid', uid);
}
get fn() { get fn() {
return this.comp.getFirstPropertyValue('fn'); return this.comp.getFirstPropertyValue('fn');
} }

Loading…
Cancel
Save