From db75d82322c961033a1f223c96d0183fc10ca2f3 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sat, 4 Jan 2020 23:25:28 +0200 Subject: [PATCH] Import: make sure imported contacts/events/tasks have a uid. Fixes #71. --- src/Journals/ImportDialog.tsx | 21 ++++++++++++++++++--- src/pim-types.ts | 4 ++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Journals/ImportDialog.tsx b/src/Journals/ImportDialog.tsx index 7eaec92..d580560 100644 --- a/src/Journals/ImportDialog.tsx +++ b/src/Journals/ImportDialog.tsx @@ -18,6 +18,7 @@ import { addEntries } from '../store/actions'; import { createJournalEntry } from '../etesync-helpers'; import * as EteSync from 'etesync'; +import * as uuid from 'uuid'; import * as ICAL from 'ical.js'; import { ContactType, EventType, TaskType, PimType } from '../pim-types'; @@ -155,7 +156,13 @@ class ImportDialog extends React.Component { private onFileDropContact(acceptedFiles: File[], rejectedFiles: File[]) { const itemsCreator = (fileText: string) => { 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); @@ -165,7 +172,11 @@ class ImportDialog extends React.Component { const itemsCreator = (fileText: string) => { const calendarComp = new ICAL.Component(ICAL.parse(fileText)); 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 { const itemsCreator = (fileText: string) => { const calendarComp = new ICAL.Component(ICAL.parse(fileText)); return calendarComp.getAllSubcomponents('vtodo').map((comp) => { - return new TaskType(comp); + const ret = new TaskType(comp); + if (!ret.uid) { + ret.uid = uuid.v4(); + } + return ret; }); }; diff --git a/src/pim-types.ts b/src/pim-types.ts index 891b7c4..2f9ff43 100644 --- a/src/pim-types.ts +++ b/src/pim-types.ts @@ -214,6 +214,10 @@ export class ContactType implements PimType { return this.comp.getFirstPropertyValue('uid'); } + set uid(uid: string) { + this.comp.updatePropertyWithValue('uid', uid); + } + get fn() { return this.comp.getFirstPropertyValue('fn'); }