Merge pull request #4451 from humhub/enh/addUserFollowsToLive

Enh/add user follows to live #3994
This commit is contained in:
buddh4 2020-10-09 17:53:19 +02:00 committed by GitHub
commit 635974f9da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

View File

@ -39,5 +39,7 @@ HumHub Changelog
- Enh #4401: Allow to use less variable name in value of another less variable
- Fix #4434: Fix title quoting for space icons in widget “Member in these spaces”
- Fix #4428: Replace db Expression time now with func date('Y-m-d G:i:s')
- Enh #3994: Live event legitimation array include followed users
- Enh #3994: Live event legitimation consider `cached` argument in processing data
- Fix #4452: `humhub.ui.filter.getActiveFilterCount` returns wrong value with exclude array option
- Fix #4452: Ignore `scope` profile filter in stream filter count and hasActiveFilters

View File

@ -50,7 +50,7 @@ class Module extends \humhub\components\Module
{
$legitimation = Yii::$app->cache->get(self::$legitimateCachePrefix . $user->id);
if ($legitimation === false) {
if (!$cached || $legitimation === false) {
$legitimation = [
Content::VISIBILITY_PUBLIC => [],
Content::VISIBILITY_PRIVATE => [],
@ -84,6 +84,11 @@ class Module extends \humhub\components\Module
$legitimation[Content::VISIBILITY_PUBLIC][] = $space->contentContainerRecord->id;
}
// Collect users which the user follows
foreach (Follow::getFollowedUserQuery($user)->all() as $followedUser) {
$legitimation[Content::VISIBILITY_PUBLIC][] = $followedUser->contentContainerRecord->id;
}
Yii::$app->cache->set(self::$legitimateCachePrefix . $user->id, $legitimation);
Yii::$app->live->driver->onContentContainerLegitimationChanged($user, $legitimation);
};

View File

@ -174,6 +174,26 @@ class Follow extends \yii\db\ActiveRecord
return Space::find()->where(['exists', $subQuery]);
}
/**
* @param \humhub\modules\user\models\User $user
* @param null $withNotifications
* @return ActiveQueryUser
*/
public static function getFollowedUserQuery(User $user, $withNotifications = null)
{
$subQuery = self::find()
->where(['user_follow.user_id' => $user->id, 'user_follow.object_model' => User::class])
->andWhere('user_follow.object_id=user.id');
if ($withNotifications === true) {
$subQuery->andWhere(['user_follow.send_notifications' => 1]);
} elseif ($withNotifications === false) {
$subQuery->andWhere(['user_follow.send_notifications' => 0]);
}
return User::find()->where(['exists', $subQuery]);
}
/**
* Returns all active users following the given $target record.
* If $withNotifications is set only follower with the given send_notifications setting are returned.