Skip to content

Commit 66d11a2

Browse files
kesselbbackportbot[bot]
authored andcommitted
fix: recipient label should not contain email address
Signed-off-by: Daniel Kesselberg <[email protected]>
1 parent c02c83f commit 66d11a2

File tree

7 files changed

+47
-25
lines changed

7 files changed

+47
-25
lines changed

lib/Service/AutoCompletion/AutoCompleteService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function findMatches(string $userId, string $term): array {
5555
'id' => $address->getId(),
5656
'label' => $address->getDisplayName(),
5757
'email' => $address->getEmail(),
58+
'source' => 'collector',
5859
];
5960
}, $fromCollector);
6061

lib/Service/ContactsIntegration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ public function getMatchingRecipient(string $userId, string $term): array {
141141
$receivers[] = [
142142
'id' => $id,
143143
// Show full name if possible or fall back to email
144-
'label' => (empty($fn) ? $e : "$fn ($e)"),
144+
'label' => $fn,
145145
'email' => $e,
146146
'photo' => $photo,
147+
'source' => 'contacts',
147148
];
148149
}
149150
}

lib/Service/GroupsIntegration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function getMatchingGroups(string $term): array {
6666
'label' => $g['name'] . " (" . $gs->getNamespace() . ")",
6767
'email' => $gid,
6868
'photo' => null,
69+
'source' => 'groups',
6970
];
7071
}
7172
}

src/components/Composer.vue

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<div class="multiselect__tag multiselect__tag-custom">
7272
<ListItemIcon :no-margin="true"
7373
:name="option.label"
74-
:subname="showEmailAsSubname(option)"
74+
:subname="getSubnameForRecipient(option)"
7575
:icon-class="!option.id ? 'icon-user' : null"
7676
:url="option.photo" />
7777
</div>
@@ -127,7 +127,7 @@
127127
<div class="multiselect__tag multiselect__tag-custom">
128128
<ListItemIcon :no-margin="true"
129129
:name="option.label"
130-
:subname="showEmailAsSubname(option)"
130+
:subname="getSubnameForRecipient(option)"
131131
:url="option.photo"
132132
:icon-class="!option.id ? 'icon-user' : null" />
133133
</div>
@@ -177,7 +177,7 @@
177177
<div class="multiselect__tag multiselect__tag-custom">
178178
<ListItemIcon :no-margin="true"
179179
:name="option.label"
180-
:subname="showEmailAsSubname(option)"
180+
:subname="getSubnameForRecipient(option)"
181181
:url="option.photo"
182182
:icon-class="!option.id ? 'icon-user' : null" />
183183
</div>
@@ -1376,15 +1376,24 @@ export default {
13761376
},
13771377
13781378
/**
1379-
* Use the email address as subname if we have label
1379+
* Return the subname for recipient suggestion.
1380+
*
1381+
* Empty if label and email are the same or
1382+
* if the suggestion is a group.
13801383
*
13811384
* @param {{email: string, label: string}} option
13821385
* @return string
13831386
*/
1384-
showEmailAsSubname(option) {
1385-
return (option.label === option.email)
1386-
? ''
1387-
: option.email
1387+
getSubnameForRecipient(option) {
1388+
if (option.source && option.source === 'groups') {
1389+
return ''
1390+
}
1391+
1392+
if (option.label === option.email) {
1393+
return ''
1394+
}
1395+
1396+
return option.email
13881397
},
13891398
},
13901399
}

tests/Unit/Service/Autocompletion/AutoCompleteServiceTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public function testFindMatches() {
5151
$term = 'jo';
5252

5353
$contactsResult = [
54-
['id' => 12, 'label' => '"john doe" <[email protected]>', 'email' => '[email protected]'],
55-
['id' => 13, 'label' => '"joe doe" <[email protected]>', 'email' => '[email protected]'],
54+
['id' => 12, 'label' => '"john doe" <[email protected]>', 'email' => '[email protected]', 'source' => 'contacts'],
55+
['id' => 13, 'label' => '"joe doe" <[email protected]>', 'email' => '[email protected]', 'source' => 'contacts'],
5656
];
5757
$john = new CollectedAddress();
5858
$john->setId(1234);
@@ -64,7 +64,7 @@ public function testFindMatches() {
6464
];
6565

6666
$groupsResult = [
67-
['id' => 20, 'label' => 'Journalists', 'email' => 'Journalists']
67+
['id' => 20, 'label' => 'Journalists', 'email' => 'Journalists', 'source' => 'groups']
6868
];
6969

7070
$this->contactsIntegration->expects($this->once())
@@ -86,10 +86,10 @@ public function testFindMatches() {
8686
$response = $this->service->findMatches('testuser', $term);
8787

8888
$expected = [
89-
['id' => 12, 'label' => '"john doe" <[email protected]>', 'email' => '[email protected]'],
90-
['id' => 13, 'label' => '"joe doe" <[email protected]>', 'email' => '[email protected]'],
91-
['id' => 1234, 'label' => 'John Doe', 'email' => '[email protected]'],
92-
['id' => 20, 'label' => 'Journalists', 'email' => 'Journalists'],
89+
['id' => 12, 'label' => '"john doe" <[email protected]>', 'email' => '[email protected]', 'source' => 'contacts'],
90+
['id' => 13, 'label' => '"joe doe" <[email protected]>', 'email' => '[email protected]', 'source' => 'contacts'],
91+
['id' => 1234, 'label' => 'John Doe', 'email' => '[email protected]', 'source' => 'collector'],
92+
['id' => 20, 'label' => 'Journalists', 'email' => 'Journalists', 'source' => 'groups'],
9393
];
9494
$this->assertEquals($expected, $response);
9595
}

tests/Unit/Service/ContactsIntegrationTest.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,24 @@ public function testGetMatchingRecipient() {
103103
$expected = [
104104
[
105105
'id' => 'jf',
106-
'label' => 'Jonathan Frakes ([email protected])',
106+
'label' => 'Jonathan Frakes',
107107
'email' => '[email protected]',
108108
'photo' => null,
109+
'source' => 'contacts'
109110
],
110111
[
111112
'id' => 'jd',
112-
'label' => 'John Doe ([email protected])',
113+
'label' => 'John Doe',
113114
'email' => '[email protected]',
114115
'photo' => null,
116+
'source' => 'contacts'
115117
],
116118
[
117119
'id' => 'jd',
118-
'label' => 'John Doe ([email protected])',
120+
'label' => 'John Doe',
119121
'email' => '[email protected]',
120122
'photo' => null,
123+
'source' => 'contacts'
121124
],
122125
];
123126

@@ -170,21 +173,24 @@ public function testGetMatchingRecipientRestrictedToGroup() {
170173
$expected = [
171174
[
172175
'id' => 'jd',
173-
'label' => 'John Doe ([email protected])',
176+
'label' => 'John Doe',
174177
'email' => '[email protected]',
175178
'photo' => null,
179+
'source' => 'contacts'
176180
],
177181
[
178182
'id' => 'jd',
179-
'label' => 'John Doe ([email protected])',
183+
'label' => 'John Doe',
180184
'email' => '[email protected]',
181185
'photo' => null,
186+
'source' => 'contacts',
182187
],
183188
[
184189
'id' => 'js',
185-
'label' => 'Johann Strauss II ([email protected])',
190+
'label' => 'Johann Strauss II',
186191
'email' => '[email protected]',
187192
'photo' => null,
193+
'source' => 'contacts',
188194
],
189195
];
190196

@@ -222,9 +228,10 @@ public function testGetMatchingRecipientRestrictedToGroupFullMatchUserId() {
222228
$expected = [
223229
[
224230
'id' => 'jf',
225-
'label' => 'Jonathan Frakes ([email protected])',
231+
'label' => 'Jonathan Frakes',
226232
'email' => '[email protected]',
227233
'photo' => null,
234+
'source' => 'contacts',
228235
],
229236
];
230237

@@ -262,9 +269,10 @@ public function testGetMatchingRecipientRestrictedToGroupFullMatchFullName() {
262269
$expected = [
263270
[
264271
'id' => 'jf',
265-
'label' => 'Jonathan Frakes ([email protected])',
272+
'label' => 'Jonathan Frakes',
266273
'email' => '[email protected]',
267274
'photo' => null,
275+
'source' => 'contacts',
268276
],
269277
];
270278

@@ -302,9 +310,10 @@ public function testGetMatchingRecipientRestrictedToGroupFullMatchEmail() {
302310
$expected = [
303311
[
304312
'id' => 'jf',
305-
'label' => 'Jonathan Frakes ([email protected])',
313+
'label' => 'Jonathan Frakes',
306314
'email' => '[email protected]',
307315
'photo' => null,
316+
'source' => 'contacts',
308317
],
309318
];
310319

tests/Unit/Service/GroupsIntegrationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function testGetMatchingGroups(): void {
7676
'label' => 'first test group (Namespace1)',
7777
'email' => 'namespace1:testgroup',
7878
'photo' => null,
79+
'source' => 'groups',
7980
]
8081
],
8182
$actual

0 commit comments

Comments
 (0)