summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-03-15 11:32:41 +0100
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-03-15 11:32:41 +0100
commit3984f559e4c0a7d38cd093da08fec0c209eaa569 (patch)
tree3531d5c6c1d85efba171c8dec233b52d1b3e05bf /src
parentef3222e8008e09d16867ea72da067bde12825c27 (diff)
Repair and fix REV and repair on import
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/components/ContactDetails.vue12
-rw-r--r--src/services/checks/index.js2
-rw-r--r--src/services/checks/invalidREV.js56
-rw-r--r--src/store/addressbooks.js7
4 files changed, 71 insertions, 6 deletions
diff --git a/src/components/ContactDetails.vue b/src/components/ContactDetails.vue
index b740e0d5..38533a01 100644
--- a/src/components/ContactDetails.vue
+++ b/src/components/ContactDetails.vue
@@ -459,11 +459,13 @@ export default {
// scroll to selected contact if any
let list = document.getElementById('contacts-list')
let item = document.querySelector('#' + btoa(contact.key).slice(0, -2))
- let isAbove = list.scrollTop > item.offsetTop
- let isUnder = item.offsetTop + item.offsetHeight > list.scrollTop + list.offsetHeight
- // check if contact outside visible list area
- if (item && (isAbove || isUnder)) {
- list.scrollTo(0, item.offsetTop - item.offsetHeight / 2)
+ if (item) {
+ let isAbove = list.scrollTop > item.offsetTop
+ let isUnder = item.offsetTop + item.offsetHeight > list.scrollTop + list.offsetHeight
+ // check if contact outside visible list area
+ if (isAbove || isUnder) {
+ list.scrollTo(0, item.offsetTop - item.offsetHeight / 2)
+ }
}
}
},
diff --git a/src/services/checks/index.js b/src/services/checks/index.js
index de67af19..2ac0871d 100644
--- a/src/services/checks/index.js
+++ b/src/services/checks/index.js
@@ -21,9 +21,11 @@
*/
import badGenderType from './badGenderType'
+import invalidREV from './invalidREV'
import missingFN from './missingFN'
export default [
badGenderType,
+ invalidREV,
missingFN
]
diff --git a/src/services/checks/invalidREV.js b/src/services/checks/invalidREV.js
new file mode 100644
index 00000000..b9b4a63c
--- /dev/null
+++ b/src/services/checks/invalidREV.js
@@ -0,0 +1,56 @@
+/**
+ * @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import { VCardTime } from 'ical.js'
+
+// https://tools.ietf.org/html/rfc6350#section-6.7.4
+
+export default {
+ name: 'invalid REV',
+ run: contact => {
+ try {
+ if (contact.vCard.hasProperty('rev')
+ && contact.vCard.getFirstProperty('rev').getFirstValue()
+ && contact.vCard.getFirstProperty('rev').getFirstValue().icalclass === 'vcardtime') {
+ return false
+ }
+ } catch (error) {
+ return true
+ }
+ return true
+ },
+ fix: contact => {
+ try {
+ // removing old invalid data
+ contact.vCard.removeProperty('rev')
+
+ // creatiing new value
+ const rev = new VCardTime(null, null, 'date-time')
+ rev.fromUnixTime(Date.now() / 1000)
+ contact.vCard.addPropertyWithValue('rev', rev)
+
+ return true
+ } catch (error) {
+ return false
+ }
+ }
+}
diff --git a/src/store/addressbooks.js b/src/store/addressbooks.js
index 768b6a0f..8521c30c 100644
--- a/src/store/addressbooks.js
+++ b/src/store/addressbooks.js
@@ -27,8 +27,9 @@ import pLimit from 'p-limit'
import Contact from 'Models/contact'
-import parseVcf from 'Services/parseVcf'
import client from 'Services/cdav'
+import parseVcf from 'Services/parseVcf'
+import validate from 'Services/validate'
const addressbookModel = {
id: '',
@@ -401,6 +402,10 @@ const actions = {
// create the array of requests to send
contacts.map(async contact => {
+
+ // validate and repair if needed
+ validate(contact)
+
// Get vcard string
try {
let vData = ICAL.stringify(contact.vCard.jCal)