Skip to content

Commit 9b8bb67

Browse files
author
Julien Veyssier
authored
Merge pull request #87 from nextcloud/fix-contact-noname
refs #85 fix bug with unnamed contacts
2 parents e65dcbf + 22815c8 commit 9b8bb67

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

lib/Controller/ContactsController.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function getContacts() {
7070
$geo = $c['GEO'];
7171
if (strlen($geo) > 1) {
7272
array_push($result, [
73-
'FN'=>$c['FN'],
73+
'FN'=>$c['FN'] ?? $this->N2FN($c['N']) ?? '???',
7474
'URI'=>$c['URI'],
7575
'UID'=>$c['UID'],
7676
'ADR'=>'',
@@ -98,7 +98,7 @@ public function getContacts() {
9898
}
9999
if (strlen($geo) > 1) {
100100
array_push($result, [
101-
'FN'=>$c['FN'],
101+
'FN'=>$c['FN'] ?? $this->N2FN($c['N']) ?? '???',
102102
'URI'=>$c['URI'],
103103
'UID'=>$c['UID'],
104104
'ADR'=>$adr->getValue(),
@@ -117,6 +117,21 @@ public function getContacts() {
117117
return new DataResponse($result);
118118
}
119119

120+
private function N2FN(string $n) {
121+
if ($n) {
122+
$spl = explode($n, ';');
123+
if (count($spl) >= 4) {
124+
return $spl[3] + ' ' + $spl[1] + ' ' + $spl[0];
125+
}
126+
else {
127+
return null;
128+
}
129+
}
130+
else {
131+
return null;
132+
}
133+
}
134+
120135
/**
121136
* get all contacts
122137
* @NoAdminRequired
@@ -133,7 +148,7 @@ public function getAllContacts() {
133148
strcmp($uid, $userid) !== 0
134149
) {
135150
array_push($result, [
136-
'FN'=>$c['FN'],
151+
'FN'=>$c['FN'] ?? $this->N2FN($c['N']) ?? '???',
137152
'URI'=>$c['URI'],
138153
'UID'=>$c['UID'],
139154
'BOOKID'=>$c['addressbook-key'],

0 commit comments

Comments
 (0)