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 committed Feb 13, 2025
1 parent cdd910f commit 53ce899
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
1 change: 1 addition & 0 deletions lib/Service/AutoCompletion/AutoCompleteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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 @@ -127,9 +127,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 @@ -52,6 +52,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 @@ -84,7 +84,7 @@
<div>
<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 @@ -137,7 +137,7 @@
<div>
<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 @@ -190,7 +190,7 @@
<div>
<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 @@ -1422,15 +1422,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 1430 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 1431 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 @@ -37,8 +37,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 @@ -50,7 +50,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 @@ -72,10 +72,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
1 change: 1 addition & 0 deletions tests/Unit/Service/GroupsIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function testGetMatchingGroups(): void {
'label' => 'first test group (Namespace1)',
'email' => 'namespace1:testgroup',
'photo' => null,
'source' => 'groups',
]
],
$actual
Expand Down

0 comments on commit 53ce899

Please sign in to comment.