Return batchtime for when filtering the users for email

This commit is contained in:
Joas Schilling 2014-04-16 17:54:05 +02:00
Родитель b07dffb5f9
Коммит c1c5b944e8
1 изменённых файлов: 28 добавлений и 3 удалений

Просмотреть файл

@ -89,7 +89,6 @@ class Hooks {
$filteredStreamUsers = self::filterUsersBySetting(array_keys($affectedUsers), 'stream', $activity_type);
$filteredEmailUsers = self::filterUsersBySetting(array_keys($affectedUsers), 'email', $activity_type);
foreach ($affectedUsers as $user => $path) {
if (empty($filteredStreamUsers[$user]) && empty($filteredEmailUsers[$user])) {
continue;
@ -294,7 +293,8 @@ class Hooks {
* @param array $users
* @param string $method
* @param string $type
* @return array
* @return array Returns a "username => b:true" Map for method = stream
* Returns a "username => i:batchtime" Map for method = email
*/
public static function filterUsersBySetting($users, $method, $type) {
if (empty($users) || !is_array($users)) return array();
@ -328,12 +328,37 @@ class Hooks {
}
}
// Get the batch time setting from the database
if ($method == 'email') {
$chunkedFilteredUsers = array_chunk(array_keys($filteredUsers), 50);
foreach ($chunkedFilteredUsers as $chunk) {
$placeholders = (sizeof($chunk) == 50) ? $placeholders_50 : implode(',', array_fill(0, sizeof($chunk), '?'));
$query = \OCP\DB::prepare(
'SELECT `userid`, `configvalue` '
. ' FROM `*PREFIX*preferences` '
. ' WHERE `appid` = ? AND `configkey` = ? AND `userid` IN (' . $placeholders . ')');
$result = $query->execute(array_merge(array(
'activity',
'notify_setting_batchtime',
), $chunk));
while ($row = $result->fetchRow()) {
$filteredUsers[$row['userid']] = $row['configvalue'];
}
}
}
if (!empty($users)) {
// If the setting is enabled by default,
// we add all users that didn't set the preference yet.
if (\OCA\Activity\Data::getUserDefaultSetting($method, $type)) {
foreach ($users as $user) {
$filteredUsers[$user] = true;
if ($method == 'stream') {
$filteredUsers[$user] = true;
} else {
$filteredUsers[$user] = \OCA\Activity\Data::getUserDefaultSetting('setting', 'batchtime');
}
}
}
}