Skip to content

Commit

Permalink
fix: recipient label should not contain email address
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kesselberg <[email protected]>
  • Loading branch information
kesselb authored and backportbot[bot] committed Feb 14, 2025
1 parent c02c83f commit 66d11a2
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 25 deletions.
1 change: 1 addition & 0 deletions lib/Service/AutoCompletion/AutoCompleteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function findMatches(string $userId, string $term): array {
'id' => $address->getId(),
'label' => $address->getDisplayName(),
'email' => $address->getEmail(),
'source' => 'collector',
];
}, $fromCollector);

Expand Down
3 changes: 2 additions & 1 deletion lib/Service/ContactsIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ public function getMatchingRecipient(string $userId, string $term): array {
$receivers[] = [
'id' => $id,
// Show full name if possible or fall back to email
'label' => (empty($fn) ? $e : "$fn ($e)"),
'label' => $fn,
'email' => $e,
'photo' => $photo,
'source' => 'contacts',
];
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/Service/GroupsIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function getMatchingGroups(string $term): array {
'label' => $g['name'] . " (" . $gs->getNamespace() . ")",
'email' => $gid,
'photo' => null,
'source' => 'groups',
];
}
}
Expand Down
25 changes: 17 additions & 8 deletions src/components/Composer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<div class="multiselect__tag multiselect__tag-custom">
<ListItemIcon :no-margin="true"
:name="option.label"
:subname="showEmailAsSubname(option)"
:subname="getSubnameForRecipient(option)"
:icon-class="!option.id ? 'icon-user' : null"
:url="option.photo" />
</div>
Expand Down Expand Up @@ -127,7 +127,7 @@
<div class="multiselect__tag multiselect__tag-custom">
<ListItemIcon :no-margin="true"
:name="option.label"
:subname="showEmailAsSubname(option)"
:subname="getSubnameForRecipient(option)"
:url="option.photo"
:icon-class="!option.id ? 'icon-user' : null" />
</div>
Expand Down Expand Up @@ -177,7 +177,7 @@
<div class="multiselect__tag multiselect__tag-custom">
<ListItemIcon :no-margin="true"
:name="option.label"
:subname="showEmailAsSubname(option)"
:subname="getSubnameForRecipient(option)"
:url="option.photo"
:icon-class="!option.id ? 'icon-user' : null" />
</div>
Expand Down Expand Up @@ -1376,15 +1376,24 @@ export default {
},
/**
* Use the email address as subname if we have label
* Return the subname for recipient suggestion.
*
* Empty if label and email are the same or
* if the suggestion is a group.
*
* @param {{email: string, label: string}} option

Check warning on line 1384 in src/components/Composer.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Missing JSDoc @param "option" description
* @return string

Check warning on line 1385 in src/components/Composer.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Missing JSDoc @return type
*/
showEmailAsSubname(option) {
return (option.label === option.email)
? ''
: option.email
getSubnameForRecipient(option) {
if (option.source && option.source === 'groups') {
return ''
}
if (option.label === option.email) {
return ''
}
return option.email
},
},
}
Expand Down
14 changes: 7 additions & 7 deletions tests/Unit/Service/Autocompletion/AutoCompleteServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public function testFindMatches() {
$term = 'jo';

$contactsResult = [
['id' => 12, 'label' => '"john doe" <[email protected]>', 'email' => '[email protected]'],
['id' => 13, 'label' => '"joe doe" <[email protected]>', 'email' => '[email protected]'],
['id' => 12, 'label' => '"john doe" <[email protected]>', 'email' => '[email protected]', 'source' => 'contacts'],
['id' => 13, 'label' => '"joe doe" <[email protected]>', 'email' => '[email protected]', 'source' => 'contacts'],
];
$john = new CollectedAddress();
$john->setId(1234);
Expand All @@ -64,7 +64,7 @@ public function testFindMatches() {
];

$groupsResult = [
['id' => 20, 'label' => 'Journalists', 'email' => 'Journalists']
['id' => 20, 'label' => 'Journalists', 'email' => 'Journalists', 'source' => 'groups']
];

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

$expected = [
['id' => 12, 'label' => '"john doe" <[email protected]>', 'email' => '[email protected]'],
['id' => 13, 'label' => '"joe doe" <[email protected]>', 'email' => '[email protected]'],
['id' => 1234, 'label' => 'John Doe', 'email' => '[email protected]'],
['id' => 20, 'label' => 'Journalists', 'email' => 'Journalists'],
['id' => 12, 'label' => '"john doe" <[email protected]>', 'email' => '[email protected]', 'source' => 'contacts'],
['id' => 13, 'label' => '"joe doe" <[email protected]>', 'email' => '[email protected]', 'source' => 'contacts'],
['id' => 1234, 'label' => 'John Doe', 'email' => '[email protected]', 'source' => 'collector'],
['id' => 20, 'label' => 'Journalists', 'email' => 'Journalists', 'source' => 'groups'],
];
$this->assertEquals($expected, $response);
}
Expand Down
27 changes: 18 additions & 9 deletions tests/Unit/Service/ContactsIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,24 @@ public function testGetMatchingRecipient() {
$expected = [
[
'id' => 'jf',
'label' => 'Jonathan Frakes ([email protected])',
'label' => 'Jonathan Frakes',
'email' => '[email protected]',
'photo' => null,
'source' => 'contacts'
],
[
'id' => 'jd',
'label' => 'John Doe ([email protected])',
'label' => 'John Doe',
'email' => '[email protected]',
'photo' => null,
'source' => 'contacts'
],
[
'id' => 'jd',
'label' => 'John Doe ([email protected])',
'label' => 'John Doe',
'email' => '[email protected]',
'photo' => null,
'source' => 'contacts'
],
];

Expand Down Expand Up @@ -170,21 +173,24 @@ public function testGetMatchingRecipientRestrictedToGroup() {
$expected = [
[
'id' => 'jd',
'label' => 'John Doe ([email protected])',
'label' => 'John Doe',
'email' => '[email protected]',
'photo' => null,
'source' => 'contacts'
],
[
'id' => 'jd',
'label' => 'John Doe ([email protected])',
'label' => 'John Doe',
'email' => '[email protected]',
'photo' => null,
'source' => 'contacts',
],
[
'id' => 'js',
'label' => 'Johann Strauss II ([email protected])',
'label' => 'Johann Strauss II',
'email' => '[email protected]',
'photo' => null,
'source' => 'contacts',
],
];

Expand Down Expand Up @@ -222,9 +228,10 @@ public function testGetMatchingRecipientRestrictedToGroupFullMatchUserId() {
$expected = [
[
'id' => 'jf',
'label' => 'Jonathan Frakes ([email protected])',
'label' => 'Jonathan Frakes',
'email' => '[email protected]',
'photo' => null,
'source' => 'contacts',
],
];

Expand Down Expand Up @@ -262,9 +269,10 @@ public function testGetMatchingRecipientRestrictedToGroupFullMatchFullName() {
$expected = [
[
'id' => 'jf',
'label' => 'Jonathan Frakes ([email protected])',
'label' => 'Jonathan Frakes',
'email' => '[email protected]',
'photo' => null,
'source' => 'contacts',
],
];

Expand Down Expand Up @@ -302,9 +310,10 @@ public function testGetMatchingRecipientRestrictedToGroupFullMatchEmail() {
$expected = [
[
'id' => 'jf',
'label' => 'Jonathan Frakes ([email protected])',
'label' => 'Jonathan Frakes',
'email' => '[email protected]',
'photo' => null,
'source' => 'contacts',
],
];

Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Service/GroupsIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function testGetMatchingGroups(): void {
'label' => 'first test group (Namespace1)',
'email' => 'namespace1:testgroup',
'photo' => null,
'source' => 'groups',
]
],
$actual
Expand Down

0 comments on commit 66d11a2

Please sign in to comment.