-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] notification of share through email moved to background job #217
base: master
Are you sure you want to change the base?
Conversation
adbbc02
to
f575504
Compare
f575504
to
dde984e
Compare
Codecov Report
@@ Coverage Diff @@
## master #217 +/- ##
============================================
- Coverage 89.55% 89.07% -0.48%
- Complexity 134 161 +27
============================================
Files 18 19 +1
Lines 536 604 +68
============================================
+ Hits 480 538 +58
- Misses 56 66 +10
Continue to review full report at Codecov.
|
It is better to move the notification of share using email to background job. This prevents timeout or long time wait to notify the user(s). Signed-off-by: Sujith H <[email protected]>
dde984e
to
a3aae6b
Compare
Do we want to move all these notifications to the background job? I expected to use the background job only for big groups... |
@jvillafanez Only email notifications are moved to background jobs. When user tries to share a file/folder to a group/user the notification to the user(s) would be received normally ( as that part is not touched ). |
* @param string $shareFullId | ||
* @return null | ||
*/ | ||
public function emailNotify($shareFullId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently unused
$this->mailer = $mailer ? $mailer : \OC::$server->getMailer(); | ||
$this->config = $config ? $config : \OC::$server->getConfig(); | ||
|
||
$optionsStorage = new OptionsStorage($this->config); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better rely on DI
* @param $notificationURL | ||
* @return string | ||
*/ | ||
public function fixURL($notificationURL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this needed?
* | ||
* @package OCA\Notifications\BackgroundJob | ||
*/ | ||
class MailNotificationSender extends Job { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
either extend the (private) QueuedJob class or implement the public interface.
/** | ||
* @param $shareFullId | ||
*/ | ||
public function sendNotify($shareFullId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unless there is a reason to call this method from the outside, keep the method private
$users = []; | ||
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { | ||
//Notify all the group members | ||
$group = $this->groupManager->get($share->getSharedWith()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if the group doesn't exist? it might have been deleted after the notification was generated
$users = $group->getUsers(); | ||
} elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { | ||
$users[] = $this->userManager->get($share->getSharedWith()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Abort the function if it doesn't match any of those share types? This way is clearer that we are handling this case.
|
||
foreach ($users as $user) { | ||
if ($user->getEMailAddress() === null) { | ||
\OC::$server->getLogger()->warning("Mail notification can not be sent to " . $user->getUID() . " for share " . $share->getName() . " as email for user is not set"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the injected logger
$acceptAction->setLink($fileLink, 'POST'); | ||
$notification->addAction($acceptAction); | ||
|
||
if (\count($notificationList) < $maxCountSendNotification) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it make a difference to send the emails like this? It took a while to understand what you're doing here. Sending the emails one by one would be easier, so unless there is a real advantage I'd prefer to go through the easy route.
} else { | ||
$this->sendNotify($this->getArgument()['shareFullId']); | ||
} | ||
\OC::$server->getJobList()->removeById($this->getId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As said, better use the QueuedJob and let it handle this by itself.
It is better to move the notification of share using
email to background job. This prevents timeout or long
time wait to notify the user(s).
Signed-off-by: Sujith H [email protected]