Skip to content

Commit 0d688fd

Browse files
committed
caching display name
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 138f001 commit 0d688fd

34 files changed

+670
-194
lines changed

appinfo/routes.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
['name' => 'Shares#create', 'url' => '/v1/circles/{circleUniqueId}/share', 'verb' => 'PUT'],
6767

6868
['name' => 'GlobalScale#event', 'url' => '/v1/gs/event', 'verb' => 'POST'],
69-
['name' => 'GlobalScale#asyncBroadcast', 'url' => '/v1/gs/broadcast/{token}', 'verb' => 'PUT'],
69+
['name' => 'GlobalScale#asyncBroadcast', 'url' => '/v1/gs/broadcast/async/{token}/', 'verb' => 'POST'],
7070
['name' => 'GlobalScale#broadcast', 'url' => '/v1/gs/broadcast', 'verb' => 'POST'],
7171
['name' => 'GlobalScale#status', 'url' => '/v1/gs/status', 'verb' => 'POST']
7272
]

js/circles.app.results.members.js

+11-25
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,14 @@ var resultMembers = {
176176
}
177177

178178
if (result.status === 1) {
179-
OCA.notification.onSuccess(
180-
t('circles', "The member '{name}' was added to the circle",
181-
{name: result.display}));
179+
OCA.notification.onSuccess(t('circles', "A new member was added to the circle"));
182180

183181
nav.displayMembers(result.members);
184182
return;
185183
}
186184

187185
OCA.notification.onFail(
188-
t('circles', "The member '{name}' could not be added to the circle",
189-
{name: result.display}) +
186+
t('circles', "Member could not be added to the circle") +
190187
': ' + ((result.error) ? result.error : t('circles', 'no error message')));
191188
},
192189

@@ -216,16 +213,13 @@ var resultMembers = {
216213
}
217214

218215
if (result.status === 1) {
219-
OCA.notification.onSuccess(
220-
t('circles', "The contact '{contact}' was added to the circle",
221-
{contact: result.display}));
216+
OCA.notification.onSuccess(t('circles', "A new contact was added to the circle"));
222217

223218
nav.displayMembers(result.members);
224219
return;
225220
}
226221
OCA.notification.onFail(
227-
t('circles', "The contact '{contact}' could not be added to the circle",
228-
{contact: result.display}) +
222+
t('circles', "Contact could not be added to the circle") +
229223
': ' + ((result.error) ? result.error : t('circles', 'no error message')));
230224
},
231225

@@ -234,15 +228,13 @@ var resultMembers = {
234228

235229
if (result.status === 1) {
236230
OCA.notification.onSuccess(
237-
t('circles', "The member '{name}' was invited to the circle",
238-
{name: result.display}));
231+
t('circles', "A new member was invited to the circle"));
239232

240233
nav.displayMembers(result.members);
241234
return;
242235
}
243236
OCA.notification.onFail(
244-
t('circles', "The member '{name}' could not be invited to the circle",
245-
{name: result.display}) +
237+
t('circles', "Member could not be invited to the circle") +
246238
': ' + ((result.error) ? result.error : t('circles', 'no error message')));
247239
},
248240

@@ -301,33 +293,27 @@ var resultMembers = {
301293
$(this).hide(300);
302294
}
303295
});
304-
OCA.notification.onSuccess(
305-
t('circles', "The member '{name}' was removed from the circle",
306-
{name: result.display}));
296+
OCA.notification.onSuccess(t('circles', "Member was removed from the circle"));
307297
return;
308298
}
309299

310300
OCA.notification.onFail(
311-
t('circles', "The member '{name}' could not be removed from the circle",
312-
{name: result.display}) +
313-
': ' +
314-
((result.error) ? result.error : t('circles', 'no error message')));
301+
t('circles', "Member could not be removed from the circle") +
302+
': ' + ((result.error) ? result.error : t('circles', 'no error message')));
315303
},
316304

317305
levelMemberResult: function(result) {
318306
if (result.status === 1) {
319307
OCA.notification.onSuccess(
320-
t('circles', "Member '{name}' updated",
321-
{name: result.display}));
308+
t('circles', "Member updated"));
322309

323310
nav.displayMembers(result.members);
324311
return;
325312
}
326313

327314
nav.displayMembers('');
328315
OCA.notification.onFail(
329-
t('circles', "The member '{name}' could not be updated", {name: result.display}) +
330-
': ' +
316+
t('circles', "Member could not be updated") + ': ' +
331317
((result.error) ? result.error : t('circles', 'no error message')));
332318
}
333319

lib/Activity/ProviderParser.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ protected function generateExternalMemberParameter(Member $member) {
301301
return [
302302
'type' => $member->getTypeName(),
303303
'id' => $member->getUserId(),
304-
'name' => $member->getDisplayName() . ' (' . $member->getTypeString() . ')',
305-
'_parsed' => $member->getDisplayName()
304+
'name' => $member->getCachedName() . ' (' . $member->getTypeString() . ')',
305+
'_parsed' => $member->getCachedName()
306306
];
307307
}
308308

lib/Api/Sharees.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,8 @@ private static function addResultEntry(&$result, $entry, $exact = false) {
9696
'shareType' => Share::SHARE_TYPE_CIRCLE,
9797
'shareWith' => $entry->getUniqueId(),
9898
'circleInfo' => $entry->getInfo(),
99-
'circleOwner' => MiscService::getDisplay(
100-
$entry->getOwner()
101-
->getUserId(), Member::TYPE_USER
102-
)
99+
'circleOwner' => $entry->getOwner()
100+
->getCachedName()
103101
],
104102
];
105103

lib/Api/v1/Circles.php

+14-11
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
use OCA\Circles\Service\CirclesService;
4141
use OCA\Circles\Service\FederatedLinkService;
4242
use OCA\Circles\Service\MembersService;
43-
use OCA\Circles\Service\MiscService;
4443
use OCA\Circles\Service\SharingFrameService;
4544
use OCP\AppFramework\QueryException;
4645
use OCP\Util;
@@ -199,8 +198,8 @@ public static function listCircles($type, $name = '', $level = 0, $userId = '',
199198

200199
if ($userId === '') {
201200
$userId = OC::$server->getUserSession()
202-
->getUser()
203-
->getUID();
201+
->getUser()
202+
->getUID();
204203
}
205204

206205
return $c->query(CirclesService::class)
@@ -464,7 +463,7 @@ public static function linkCircle($circleUniqueId, $remote) {
464463
*/
465464
public static function generateLink($circleUniqueId) {
466465
return OC::$server->getURLGenerator()
467-
->linkToRoute('circles.Navigation.navigate') . '#' . $circleUniqueId;
466+
->linkToRoute('circles.Navigation.navigate') . '#' . $circleUniqueId;
468467
}
469468

470469

@@ -479,7 +478,7 @@ public static function generateLink($circleUniqueId) {
479478
*/
480479
public static function generateAbsoluteLink($circleUniqueId) {
481480
return OC::$server->getURLGenerator()
482-
->linkToRouteAbsolute('circles.Navigation.navigate') . '#' . $circleUniqueId;
481+
->linkToRouteAbsolute('circles.Navigation.navigate') . '#' . $circleUniqueId;
483482
}
484483

485484

@@ -494,7 +493,7 @@ public static function generateAbsoluteLink($circleUniqueId) {
494493
*/
495494
public static function generateRemoteLink(FederatedLink $link) {
496495
return OC::$server->getURLGenerator()
497-
->linkToRoute('circles.Navigation.navigate') . '#' . $link->getUniqueId()
496+
->linkToRoute('circles.Navigation.navigate') . '#' . $link->getUniqueId()
498497
. '-' . $link->getToken();
499498
}
500499

@@ -505,11 +504,15 @@ public static function generateRemoteLink(FederatedLink $link) {
505504
* @return array
506505
*/
507506
public static function generateUserParameter(SharingFrame $frame) {
508-
509507
if ($frame->getCloudId() !== null) {
510508
$name = $frame->getAuthor() . '@' . $frame->getCloudId();
511509
} else {
512-
$name = MiscService::getDisplay($frame->getAuthor(), self::TYPE_USER);
510+
try {
511+
$membersService = \OC::$server->query(MembersService::class);
512+
$name = $membersService->getUserDisplayName($frame->getAuthor(), false);
513+
} catch (QueryException $e) {
514+
$name = $frame->getAuthor();
515+
}
513516
}
514517

515518
return [
@@ -542,16 +545,16 @@ public static function generateCircleParameter(SharingFrame $frame) {
542545
/**
543546
* Get a list of objects which are shred with $circleUniqueId.
544547
*
545-
* @since 0.14.0
546-
*
547548
* @param array $circleUniqueIds
548549
*
549550
* @return string[] array of object ids or empty array if none found
551+
* @since 0.14.0
552+
*
550553
*/
551554
public static function getFilesForCircles($circleUniqueIds) {
552555
$c = self::getContainer();
553556

554557
return $c->query(CirclesService::class)
555-
->getFilesForCircles($circleUniqueIds);
558+
->getFilesForCircles($circleUniqueIds);
556559
}
557560
}

lib/Circles/FileSharingBroadcaster.php

+12-21
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,9 @@ function(SharesToken $shareToken) {
292292
}
293293

294294
if ($circle->getViewer() === null) {
295-
$author = $circle->getOwner()
296-
->getUserId();
295+
$author = $circle->getOwner();
297296
} else {
298-
$author = $circle->getViewer()
299-
->getUserId();
297+
$author = $circle->getViewer();
300298
}
301299

302300
$recipient = $member->getUserId();
@@ -314,9 +312,7 @@ function(SharesToken $shareToken) {
314312
$recipient = $emails[0];
315313
}
316314

317-
$this->sendMailExitingShares(
318-
$circle, $unknownShares, MiscService::getDisplay($author, Member::TYPE_USER), $member, $recipient
319-
);
315+
$this->sendMailExitingShares($circle, $unknownShares, $author, $member, $recipient);
320316
}
321317

322318

@@ -413,17 +409,13 @@ private function sharedByMail(
413409
$this->l10n = OC::$server->getL10N(Application::APP_NAME, $lang);
414410
}
415411

412+
$displayName = $this->miscService->getDisplayName($share->getSharedBy());
416413
try {
417414
$this->sendMail(
418415
$share->getNode()
419-
->getName(), $link,
420-
MiscService::getDisplay($share->getSharedBy(), Member::TYPE_USER),
421-
$circle->getName(), $email
422-
);
423-
$this->sendPasswordByMail(
424-
$share, MiscService::getDisplay($share->getSharedBy(), Member::TYPE_USER),
425-
$email, $password
416+
->getName(), $link, $displayName, $circle->getName(), $email
426417
);
418+
$this->sendPasswordByMail($share, $displayName, $email, $password);
427419
} catch (Exception $e) {
428420
OC::$server->getLogger()
429421
->log(1, 'Circles::sharedByMail - mail were not sent: ' . $e->getMessage());
@@ -589,12 +581,12 @@ private function generateEmailTemplate($subject, $text, $fileName, $link, $autho
589581
/**
590582
* @param Circle $circle
591583
* @param array $unknownShares
592-
* @param string $author
584+
* @param Member $author
593585
* @param Member $member
594586
* @param string $recipient
595587
*/
596588
public function sendMailExitingShares(
597-
Circle $circle, array $unknownShares, $author, Member $member, $recipient
589+
Circle $circle, array $unknownShares, Member $author, Member $member, string $recipient
598590
) {
599591
$data = [];
600592

@@ -615,9 +607,9 @@ public function sendMailExitingShares(
615607
}
616608

617609
try {
618-
$template = $this->generateMailExitingShares($author, $circle->getName());
610+
$template = $this->generateMailExitingShares($author->getCachedName(), $circle->getName());
619611
$this->fillMailExistingShares($template, $data);
620-
$this->sendMailExistingShares($template, $author, $recipient);
612+
$this->sendMailExistingShares($template, $author->getCachedName(), $recipient);
621613
$this->sendPasswordExistingShares($author, $recipient, $password);
622614
} catch (Exception $e) {
623615
$this->logger->log(2, 'Failed to send mail about existing share ' . $e->getMessage());
@@ -628,19 +620,18 @@ public function sendMailExitingShares(
628620
/**
629621
* @param $author
630622
* @param string $email
631-
*
632623
* @param $password
633624
*
634625
* @throws Exception
635626
*/
636-
protected function sendPasswordExistingShares($author, $email, $password) {
627+
protected function sendPasswordExistingShares(Member $author, string $email, string $password) {
637628
if (!$this->configService->sendPasswordByMail() || $password === '') {
638629
return;
639630
}
640631

641632
$message = $this->mailer->createMessage();
642633

643-
$authorUser = $this->userManager->get($author);
634+
$authorUser = $this->userManager->get($author->getUserId());
644635
$authorName = ($authorUser instanceof IUser) ? $authorUser->getDisplayName() : $author;
645636
$authorEmail = ($authorUser instanceof IUser) ? $authorUser->getEMailAddress() : null;
646637

lib/Collaboration/v1/CollaboratorSearchPlugin.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,8 @@ private function addResultEntry(Circle $circle) {
109109
'shareType' => Share::SHARE_TYPE_CIRCLE,
110110
'shareWith' => $circle->getUniqueId(),
111111
'circleInfo' => $circle->getInfo(),
112-
'circleOwner' => MiscService::getDisplay(
113-
$circle->getOwner()
114-
->getUserId(), Member::TYPE_USER
115-
)
112+
'circleOwner' => $circle->getOwner()
113+
->getCachedName()
116114
],
117115
];
118116
}

lib/Command/CirclesSync.php

+25-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030
namespace OCA\Circles\Command;
3131

3232
use OC\Core\Command\Base;
33-
use OCA\Circles\Exceptions\CircleDoesNotExistException;
3433
use OCA\Circles\Exceptions\GSStatusException;
34+
use OCA\Circles\Service\CirclesService;
3535
use OCA\Circles\Service\GSUpstreamService;
36+
use OCA\Circles\Service\MembersService;
3637
use OCP\IL10N;
3738
use Symfony\Component\Console\Input\InputInterface;
3839
use Symfony\Component\Console\Output\OutputInterface;
@@ -49,6 +50,12 @@ class CirclesSync extends Base {
4950
/** @var IL10N */
5051
private $l10n;
5152

53+
/** @var MembersService */
54+
private $membersService;
55+
56+
/** @var CirclesService */
57+
private $circlesService;
58+
5259
/** @var GSUpstreamService */
5360
private $gsUpstreamService;
5461

@@ -57,11 +64,18 @@ class CirclesSync extends Base {
5764
* CirclesSync constructor.
5865
*
5966
* @param IL10N $l10n
67+
* @param CirclesService $circlesService
68+
* @param MembersService $membersService
6069
* @param GSUpstreamService $gsUpstreamService
6170
*/
62-
public function __construct(IL10N $l10n, GSUpstreamService $gsUpstreamService) {
71+
public function __construct(
72+
IL10N $l10n, CirclesService $circlesService, MembersService $membersService,
73+
GSUpstreamService $gsUpstreamService
74+
) {
6375
parent::__construct();
6476
$this->l10n = $l10n;
77+
$this->circlesService = $circlesService;
78+
$this->membersService = $membersService;
6579
$this->gsUpstreamService = $gsUpstreamService;
6680
}
6781

@@ -81,10 +95,17 @@ protected function configure() {
8195
* @param OutputInterface $output
8296
*
8397
* @return int
84-
* @throws GSStatusException
8598
*/
8699
protected function execute(InputInterface $input, OutputInterface $output): int {
87-
$this->gsUpstreamService->synchronize();
100+
$circles = $this->circlesService->getCirclesToSync();
101+
foreach ($circles as $circle) {
102+
$this->membersService->updateCachedFromCircle($circle);
103+
}
104+
105+
try {
106+
$this->gsUpstreamService->synchronize($circles);
107+
} catch (GSStatusException $e) {
108+
}
88109

89110
return 0;
90111
}

0 commit comments

Comments
 (0)