Skip to content

Commit

Permalink
fix: reuse share object instead of getting it again when sending invi…
Browse files Browse the repository at this point in the history
…te mail

Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Mar 5, 2024
1 parent 75a31a1 commit d25ef91
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
3 changes: 1 addition & 2 deletions lib/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ public function handlePostShare(ShareCreatedEvent $event): void {
$this->mail->sendGuestInviteMail(
$uid,
$shareWith,
$share->getNodeType(),
$share->getNodeId(),
$share,
$token,
$lang
);
Expand Down
20 changes: 5 additions & 15 deletions lib/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function __construct(
* @param $uid
* @throws \Exception
*/
public function sendGuestInviteMail(string $uid, string $shareWith, string $itemType, string $itemSource, string $token, string $language = ''): void {
public function sendGuestInviteMail(string $uid, string $shareWith, Share\IShare $share, string $token, string $language = ''): void {
if ($language === '') {
$language = null;
}
Expand All @@ -102,22 +102,12 @@ public function sendGuestInviteMail(string $uid, string $shareWith, string $item
$replyTo = $this->userManager->get($uid)->getEMailAddress();
$senderDisplayName = $this->userSession->getUser()->getDisplayName();

$items = Share::getItemSharedWithUser($itemType, $itemSource, $shareWith);
$filename = trim($items[0]['file_target'], '/');
$subject = (string)$l10n->t('%s shared »%s« with you', [$senderDisplayName, $filename]);
$expiration = null;
if (isset($items[0]['expiration'])) {
try {
$date = new \DateTime($items[0]['expiration']);
$expiration = $date->getTimestamp();
} catch (\Exception $e) {
$this->logger->error("Couldn't read date: " . $e->getMessage(), ['app' => 'sharing']);
}
}

$filename = trim($share->getTarget(), '/');
$subject = $l10n->t('%s shared »%s« with you', [$senderDisplayName, $filename]);
$expiration = $share->getExpirationDate();

$link = $this->urlGenerator->linkToRouteAbsolute(
'files.viewcontroller.showFile', ['fileid' => $itemSource]
'files.viewcontroller.showFile', ['fileid' => $share->getNodeId()]
);

$emailTemplate = $this->mailer->createEMailTemplate('guest.invite');
Expand Down

0 comments on commit d25ef91

Please sign in to comment.