/** * Send an event to the notifications of a user * * @param IEvent $event * @return null */ public function receive(IEvent $event) { $selfAction = $event->getAffectedUser() === $event->getAuthor(); $streamSetting = $this->userSettings->getUserSetting($event->getAffectedUser(), 'stream', $event->getType()); $emailSetting = $this->userSettings->getUserSetting($event->getAffectedUser(), 'email', $event->getType()); $emailSetting = $emailSetting ? $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'batchtime') : false; $types = $this->data->getNotificationTypes($this->l10nFactory->get('activity')); $typeData = $types[$event->getType()]; // User is not the author or wants to see their own actions $createStream = !$selfAction || $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'self'); // User can not control the setting $createStream = $createStream || is_array($typeData) && isset($typeData['methods']) && !in_array(IExtension::METHOD_STREAM, $typeData['methods']); // Add activity to stream if ($streamSetting && $createStream) { $this->data->send($event); } // User is not the author or wants to see their own actions $createEmail = !$selfAction || $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'selfemail'); // User can not control the setting $createEmail = $createEmail || is_array($typeData) && isset($typeData['methods']) && !in_array(IExtension::METHOD_MAIL, $typeData['methods']); // Add activity to mail queue if ($emailSetting && $createEmail) { $latestSend = $event->getTimestamp() + $emailSetting; $this->data->storeMail($event, $latestSend); } }
/** * Send an event to the notifications of a user * * @param IEvent $event * @return null */ public function receive(IEvent $event) { $selfAction = $event->getAffectedUser() === $event->getAuthor(); $streamSetting = $this->userSettings->getUserSetting($event->getAffectedUser(), 'stream', $event->getType()); $emailSetting = $this->userSettings->getUserSetting($event->getAffectedUser(), 'email', $event->getType()); $emailSetting = $emailSetting ? $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'batchtime') : false; // Add activity to stream if ($streamSetting && (!$selfAction || $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'self'))) { $this->data->send($event); } // Add activity to mail queue if ($emailSetting && (!$selfAction || $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'selfemail'))) { $latestSend = $event->getTimestamp() + $emailSetting; $this->data->storeMail($event, $latestSend); } }
/** * Send an event into the activity stream of a user * * @param string $app The app where this event is associated with * @param string $subject A short description of the event * @param array $subjectParams Array with parameters that are filled in the subject * @param string $message A longer description of the event * @param array $messageParams Array with parameters that are filled in the message * @param string $file The file including path where this event is associated with. (optional) * @param string $link A link where this event is associated with (optional) * @param string $affectedUser If empty the current user will be used * @param string $type Type of the notification * @param int $priority Priority of the notification * @return null */ public function receive($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority) { $selfAction = substr($subject, -5) === '_self'; $streamSetting = $this->userSettings->getUserSetting($affectedUser, 'stream', $type); $emailSetting = $this->userSettings->getUserSetting($affectedUser, 'email', $type); $emailSetting = $emailSetting ? $this->userSettings->getUserSetting($affectedUser, 'setting', 'batchtime') : false; // Add activity to stream if ($streamSetting && (!$selfAction || $this->userSettings->getUserSetting($affectedUser, 'setting', 'self'))) { Data::send($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority); } // Add activity to mail queue if ($emailSetting && (!$selfAction || $this->userSettings->getUserSetting($affectedUser, 'setting', 'selfemail'))) { $latestSend = time() + $emailSetting; Data::storeMail($app, $subject, $subjectParams, $affectedUser, $type, $latestSend); } }
/** * Adds the activity and email for a user when the settings require it * * @param string $user * @param string $subject * @param array $subjectParams * @param string $path * @param bool $isFile If the item is a file, we link to the parent directory * @param bool $streamSetting * @param int $emailSetting * @param string $type * @param int $priority */ protected function addNotificationsForUser($user, $subject, $subjectParams, $path, $isFile, $streamSetting, $emailSetting, $type = Data::TYPE_SHARED, $priority = IExtension::PRIORITY_MEDIUM) { if (!$streamSetting && !$emailSetting) { return; } $selfAction = substr($subject, -5) !== '_self'; $link = \OCP\Util::linkToAbsolute('files', 'index.php', array('dir' => $isFile ? dirname($path) : $path)); // Add activity to stream if ($streamSetting && (!$selfAction || $this->userSettings->getUserSetting($this->currentUser, 'setting', 'self'))) { $this->activityData->send('files', $subject, $subjectParams, '', array(), $path, $link, $user, $type, $priority); } // Add activity to mail queue if ($emailSetting && (!$selfAction || $this->userSettings->getUserSetting($this->currentUser, 'setting', 'selfemail'))) { $latestSend = time() + $emailSetting; $this->activityData->storeMail('files', $subject, $subjectParams, $user, $type, $latestSend); } }
/** * @dataProvider dataSend * * @param string $actionUser * @param string $affectedUser * @param string $expectedAuthor * @param string $expectedAffected * @param bool $expectedActivity */ public function testStoreMail($actionUser, $affectedUser, $expectedAuthor, $expectedAffected, $expectedActivity) { $mockSession = $this->getMockBuilder('\\OC\\User\\Session')->disableOriginalConstructor()->getMock(); $this->overwriteService('UserSession', $mockSession); $this->deleteTestMails(); $time = time(); $event = \OC::$server->getActivityManager()->generateEvent(); $event->setApp('test')->setType('type')->setAffectedUser($affectedUser)->setSubject('subject', [])->setTimestamp($time); $this->assertSame($expectedActivity, $this->data->storeMail($event, $time + 10)); $connection = \OC::$server->getDatabaseConnection(); $query = $connection->prepare('SELECT `amq_latest_send`, `amq_affecteduser` FROM `*PREFIX*activity_mq` WHERE `amq_appid` = ? ORDER BY `mail_id` DESC'); $query->execute(['test']); $row = $query->fetch(); if ($expectedActivity) { $this->assertEquals(['amq_latest_send' => $time + 10, 'amq_affecteduser' => $expectedAffected], $row); } else { $this->assertFalse($row); } $this->deleteTestMails(); $this->restoreService('UserSession'); }
/** * Adds the activity and email for a user when the settings require it * * @param string $user * @param string $subject * @param array $subjectParams * @param int $fileId * @param string $path * @param bool $isFile If the item is a file, we link to the parent directory * @param bool $streamSetting * @param int $emailSetting * @param string $type */ protected function addNotificationsForUser($user, $subject, $subjectParams, $fileId, $path, $isFile, $streamSetting, $emailSetting, $type = Files_Sharing::TYPE_SHARED) { if (!$streamSetting && !$emailSetting) { return; } $selfAction = $user === $this->currentUser; $app = $type === Files_Sharing::TYPE_SHARED ? 'files_sharing' : 'files'; $link = Util::linkToAbsolute('files', 'index.php', array('dir' => $isFile ? dirname($path) : $path)); $objectType = $fileId ? 'files' : ''; $event = $this->manager->generateEvent(); $event->setApp($app)->setType($type)->setAffectedUser($user)->setAuthor($this->currentUser)->setTimestamp(time())->setSubject($subject, $subjectParams)->setObject($objectType, $fileId, $path)->setLink($link); // Add activity to stream if ($streamSetting && (!$selfAction || $this->userSettings->getUserSetting($this->currentUser, 'setting', 'self'))) { $this->activityData->send($event); } // Add activity to mail queue if ($emailSetting && (!$selfAction || $this->userSettings->getUserSetting($this->currentUser, 'setting', 'selfemail'))) { $latestSend = time() + $emailSetting; $this->activityData->storeMail($event, $latestSend); } }