Skip to content

Commit 812eeb7

Browse files
committed
fix(router): refactor the generating of a contact key
Code proposed by @cristianscheid Signed-off-by: silver <s.szmajduch@posteo.de>
1 parent 059c1b4 commit 812eeb7

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/models/contact.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export const MinimalContactProperties = [
2828
'EMAIL', 'UID', 'TEL', 'CATEGORIES', 'FN', 'ORG', 'N', 'X-PHONETIC-FIRST-NAME', 'X-PHONETIC-LAST-NAME', 'X-MANAGERSNAME', 'TITLE', 'NOTE', 'RELATED',
2929
].concat(ContactKindProperties)
3030

31+
export function generateContactKey(uid, addressbookId) {
32+
return Buffer.from(uid + '~' + addressbookId, 'utf8').toString('base64')
33+
}
34+
3135
export default class Contact {
3236
/**
3337
* Creates an instance of Contact
@@ -211,7 +215,7 @@ export default class Contact {
211215
* @memberof Contact
212216
*/
213217
get key() {
214-
return Buffer.from(this.uid + '~' + this.addressbook.id, 'utf8').toString('base64')
218+
return generateContactKey(this.uid, this.addressbook.id)
215219
}
216220

217221
/**

src/router/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
*/
55

66
import { generateUrl } from '@nextcloud/router'
7-
import { Buffer } from 'buffer'
87
import { createRouter, createWebHistory } from 'vue-router'
98
import Contacts from '../views/Contacts.vue'
109
import { GROUP_ALL_CONTACTS, ROUTE_CHART, ROUTE_CIRCLE, ROUTE_USER_GROUP } from '../models/constants.ts'
10+
import { generateContactKey } from '../models/contact.js'
1111

1212
// if index.php is in the url AND we got this far, then it's working:
1313
// let's keep using index.php in the url
@@ -65,7 +65,7 @@ export default createRouter({
6565
name: 'contact',
6666
params: {
6767
selectedGroup: GROUP_ALL_CONTACTS,
68-
selectedContact: Buffer.from(`${to.params.userId}~z-server-generated--system`, 'utf8').toString('base64'),
68+
selectedContact: generateContactKey(to.params.userId, 'z-server-generated--system'),
6969
},
7070
}),
7171
},

0 commit comments

Comments
 (0)