Skip to content

Commit a9d126a

Browse files
committed
fix(federation): Fix returning "no display name" after cache result
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 878c4d5 commit a9d126a

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lib/private/Federation/CloudIdManager.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ public function resolveCloudId(string $cloudId): ICloudId {
119119
public function getDisplayNameFromContact(string $cloudId): ?string {
120120
$cachedName = $this->displayNameCache->get($cloudId);
121121
if ($cachedName !== null) {
122+
if ($cachedName === $cloudId) {
123+
return null;
124+
}
122125
return $cachedName;
123126
}
124127

@@ -138,8 +141,8 @@ public function getDisplayNameFromContact(string $cloudId): ?string {
138141
$this->displayNameCache->set($cloudId, $entry['FN'], 15 * 60);
139142
return $entry['FN'];
140143
} else {
141-
$this->displayNameCache->set($cloudId, $cloudID, 15 * 60);
142-
return $cloudID;
144+
$this->displayNameCache->set($cloudId, $cloudId, 15 * 60);
145+
return null;
143146
}
144147
}
145148
}

tests/lib/Federation/CloudIdManagerTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,34 @@ protected function setUp(): void {
5656
$this->overwriteService(ICloudIdManager::class, $this->cloudIdManager);
5757
}
5858

59+
public function dataGetDisplayNameFromContact(): array {
60+
return [
61+
['test1@example.tld', 'test', 'test'],
62+
['test2@example.tld', null, null],
63+
['test3@example.tld', 'test3@example', 'test3@example'],
64+
['test4@example.tld', 'test4@example.tld', null],
65+
];
66+
}
67+
68+
/**
69+
* @dataProvider dataGetDisplayNameFromContact
70+
*/
71+
public function testGetDisplayNameFromContact(string $cloudId, ?string $displayName, ?string $expected): void {
72+
$returnedContact = [
73+
'CLOUD' => [$cloudId],
74+
'FN' => $expected,
75+
];
76+
if ($displayName === null) {
77+
unset($returnedContact['FN']);
78+
}
79+
$this->contactsManager->method('search')
80+
->with($cloudId, ['CLOUD'])
81+
->willReturn([$returnedContact]);
82+
83+
$this->assertEquals($expected, $this->cloudIdManager->getDisplayNameFromContact($cloudId));
84+
$this->assertEquals($expected, $this->cloudIdManager->getDisplayNameFromContact($cloudId));
85+
}
86+
5987
public function cloudIdProvider(): array {
6088
return [
6189
['test@example.com', 'test', 'example.com', 'test@example.com'],

0 commit comments

Comments
 (0)