diff --git a/protected/humhub/config/common.php b/protected/humhub/config/common.php index f617e68fd6..af884313a0 100644 --- a/protected/humhub/config/common.php +++ b/protected/humhub/config/common.php @@ -31,6 +31,9 @@ $config = [ 'class' => 'humhub\modules\notification\targets\MailTarget', 'renderer' => ['class' => 'humhub\modules\notification\renderer\MailRenderer'] ], + [ + 'class' => 'humhub\modules\notification\targets\MobileTarget' + ], ] ], 'log' => [ diff --git a/protected/humhub/docs/CHANGELOG.md b/protected/humhub/docs/CHANGELOG.md index eb6b5e2793..79df970b85 100644 --- a/protected/humhub/docs/CHANGELOG.md +++ b/protected/humhub/docs/CHANGELOG.md @@ -36,7 +36,9 @@ Important note for LDAP users: There is a new setting "ID Attribute" which shoul - Enh: Added default open content as modal action - Enh: Added possibility to add attachments in Notification MailTarget - Enh: Added surpressSendToOriginator Notification option - +- Chg: #2745 Removed `GroupPermission::instance()` for yii 2.0.13 compatibility +- Enh: Added `MobileTargetProvider` abstraction for mobile push notifications +- Enh: Added `humhub:notification:udpateCount` js event 1.2.2 (August 2, 2017) -------------------------------- diff --git a/protected/humhub/modules/notification/components/NotificationManager.php b/protected/humhub/modules/notification/components/NotificationManager.php index 521d3c18a9..6b0e6ad47c 100644 --- a/protected/humhub/modules/notification/components/NotificationManager.php +++ b/protected/humhub/modules/notification/components/NotificationManager.php @@ -8,6 +8,7 @@ namespace humhub\modules\notification\components; +use humhub\modules\notification\models\Notification; use Yii; use humhub\modules\user\models\User; use humhub\modules\space\models\Membership; @@ -48,7 +49,7 @@ class NotificationManager /** * Cached array of NotificationCategories - * @var type + * @var NotificationCategory[] */ protected $_categories; @@ -61,12 +62,12 @@ class NotificationManager */ public function sendBulk(BaseNotification $notification, $users) { - $recepients = $this->filterRecepients($notification, $users); + $recipients = $this->filterRecipients($notification, $users); - foreach ($recepients as $recepient) { - $notification->saveRecord($recepient); - foreach ($this->getTargets($recepient) as $target) { - $target->send($notification, $recepient); + foreach ($recipients as $recipient) { + $notification->saveRecord($recipient); + foreach ($this->getTargets($recipient) as $target) { + $target->send($notification, $recipient); } } } @@ -77,7 +78,7 @@ class NotificationManager * @param User[] $users * @return User[] array of unique user instances */ - protected function filterRecepients(BaseNotification $notification, $users) + protected function filterRecipients(BaseNotification $notification, $users) { $userIds = []; $filteredUsers = []; @@ -103,7 +104,7 @@ class NotificationManager */ public function send(BaseNotification $notification, User $user) { - return $this->sendBulk($notification, [$user]); + $this->sendBulk($notification, [$user]); } /** @@ -140,8 +141,8 @@ class NotificationManager /** * Factory function for receiving a target instance for the given class. * - * @param type $class - * @return type + * @param string $class + * @return BaseTarget */ public function getTarget($class) { @@ -158,7 +159,7 @@ class NotificationManager * * @param User $user * @param Space $space - * @return type + * @return boolean */ public function isFollowingSpace(User $user, Space $space) { @@ -270,7 +271,7 @@ class NotificationManager * Returns all spaces this user is not following. * * @param User $user - * @return type + * @return Space[] */ public function getNonNotificationSpaces(User $user = null, $limit = 25) { @@ -330,7 +331,7 @@ class NotificationManager /** * Defines the enable_html5_desktop_notifications setting for the given user or global if no user is given. * - * @param type $value + * @param integer $value * @param User $user */ public function setDesktopNoficationSettings($value = 0, User $user = null) @@ -344,7 +345,7 @@ class NotificationManager * Determines the enable_html5_desktop_notifications setting either for the given user or global if no user is given. * By default the setting is enabled. * @param User $user - * @return type + * @return integer */ public function getDesktopNoficationSettings(User $user = null) { @@ -360,11 +361,11 @@ class NotificationManager * * @param User $user user instance for which this settings will aplly * @param Space $space which notifications will be followed / unfollowed - * @param type $follow the setting value (true by default) - * @return type + * @param boolean $follow the setting value (true by default) */ public function setSpaceSetting(User $user = null, Space $space, $follow = true) { + /* @var $membership Membership */ $membership = $space->getMembership($user->id); if ($membership) { $membership->send_notifications = $follow; @@ -385,7 +386,7 @@ class NotificationManager /** * Returns all available Notifications * - * @return type + * @return BaseNotification[] */ public function getNotifications() { diff --git a/protected/humhub/modules/notification/resources/js/humhub.notification.js b/protected/humhub/modules/notification/resources/js/humhub.notification.js index 718f00be5e..92ea3d8cea 100644 --- a/protected/humhub/modules/notification/resources/js/humhub.notification.js +++ b/protected/humhub/modules/notification/resources/js/humhub.notification.js @@ -111,6 +111,8 @@ humhub.module('notification', function (module, require, $) { $('#badge-notifications').hide(); + event.trigger('humhub:notification:udpateCount', [$count]); + if (!$count) { updateTitle(false); $('#badge-notifications').html('0'); diff --git a/protected/humhub/modules/notification/targets/BaseTarget.php b/protected/humhub/modules/notification/targets/BaseTarget.php index 55c9ce474a..49fa35410e 100644 --- a/protected/humhub/modules/notification/targets/BaseTarget.php +++ b/protected/humhub/modules/notification/targets/BaseTarget.php @@ -38,7 +38,7 @@ abstract class BaseTarget extends \yii\base\Object /** * Default Renderer for this BaseTarget - * @var type + * @var Renderer */ public $renderer; @@ -172,8 +172,8 @@ abstract class BaseTarget extends \yii\base\Object /** * Returns the setting key for this target of the given $category. - * @param type $category - * @return type + * @param NotificationCategory $category + * @return string */ public function getSettingKey($category) { diff --git a/protected/humhub/modules/notification/targets/MobileTarget.php b/protected/humhub/modules/notification/targets/MobileTarget.php index c1f6f3721e..36bbec2909 100644 --- a/protected/humhub/modules/notification/targets/MobileTarget.php +++ b/protected/humhub/modules/notification/targets/MobileTarget.php @@ -10,6 +10,8 @@ namespace humhub\modules\notification\targets; use humhub\modules\user\models\User; use humhub\modules\notification\components\BaseNotification; +use Yii; +use yii\di\NotInstantiableException; /** * Mobile Target @@ -25,6 +27,22 @@ class MobileTarget extends BaseTarget */ public $id = 'mobile'; + /** + * @var MobileTargetProvider + */ + public $provider; + + public function init() + { + parent::init(); + + try { + $this->provider = Yii::$container->get(MobileTargetProvider::class); + } catch (NotInstantiableException $e) { + // No provider given + } + } + /** * Used to forward a BaseNotification object to a BaseTarget. * The notification target should handle the notification by pushing a Job to @@ -34,7 +52,9 @@ class MobileTarget extends BaseTarget */ public function handle(BaseNotification $notification, User $user) { - + if($this->provider) { + $this->provider->handle($notification, $user); + } } /** @@ -42,7 +62,16 @@ class MobileTarget extends BaseTarget */ public function getTitle() { - + return Yii::t('NotificationModule.targets', 'Mobile'); + } + + public function isActive(User $user = null) + { + if(!$this->provider) { + return false; + } + + return $this->provider->isActive($user); } } diff --git a/protected/humhub/modules/notification/targets/MobileTargetProvider.php b/protected/humhub/modules/notification/targets/MobileTargetProvider.php new file mode 100644 index 0000000000..b9d434deaa --- /dev/null +++ b/protected/humhub/modules/notification/targets/MobileTargetProvider.php @@ -0,0 +1,36 @@ +_spaceOwner != null) { return $this->_spaceOwner; } @@ -169,8 +168,8 @@ class SpaceModelMembership extends Behavior /** * Sets Owner for this workspace * - * @param type $userId - * @return type + * @param integer $userId + * @return boolean */ public function setAdmin($userId = null) { @@ -208,8 +207,8 @@ class SpaceModelMembership extends Behavior /** * Invites a not registered member to this space * - * @param type $email - * @param type $originatorUserId + * @param string $email + * @param integer $originatorUserId */ public function inviteMemberByEMail($email, $originatorUserId) { @@ -253,8 +252,8 @@ class SpaceModelMembership extends Behavior /** * Requests Membership * - * @param type $userId - * @param type $message + * @param integer $userId + * @param string $message */ public function requestMembership($userId, $message = "") { @@ -297,8 +296,8 @@ class SpaceModelMembership extends Behavior * If user is already invited, retrigger invitation. * If user is applicant approve it. * - * @param type $userId - * @param type $originatorId + * @param integer $userId + * @param integer $originatorId */ public function inviteMember($userId, $originatorId) { @@ -340,8 +339,8 @@ class SpaceModelMembership extends Behavior /** * Sends an Invite Notification to the given user. * - * @param type $userId - * @param type $originatorId + * @param integer $userId + * @param integer $originatorId */ protected function sendInviteNotification($userId, $originatorId) { @@ -359,8 +358,8 @@ class SpaceModelMembership extends Behavior * This can happens after an clicking "Request Membership" Link * after Approval or accepting an invite. * - * @param type $userId - * @param type $canLeave 0: user cannot cancel membership | 1: can cancel membership | 2: depending on space flag members_can_leave + * @param integer $userId + * @param integer $canLeave 0: user cannot cancel membership | 1: can cancel membership | 2: depending on space flag members_can_leave */ public function addMember($userId, $canLeave = 1) { diff --git a/protected/humhub/modules/space/models/Membership.php b/protected/humhub/modules/space/models/Membership.php index 5b72063b4e..72341922fb 100644 --- a/protected/humhub/modules/space/models/Membership.php +++ b/protected/humhub/modules/space/models/Membership.php @@ -22,7 +22,7 @@ use humhub\modules\space\models\Space; * @property string $request_message * @property string $last_visit * @property integer $show_at_dashboard - * @property boolean $can_leave + * @property integer $can_cancel_membership * @property string $group_id * @property string $created_at * @property integer $created_by diff --git a/static/js/humhub/humhub.client.pjax.js b/static/js/humhub/humhub.client.pjax.js index ad05365db2..22f95417ae 100644 --- a/static/js/humhub/humhub.client.pjax.js +++ b/static/js/humhub/humhub.client.pjax.js @@ -10,6 +10,14 @@ humhub.module('client.pjax', function (module, require, $) { module.installLoader(); } }; + + var post = function(evt) { + var $options = $.extend({}, module.config.options); + $options.url = evt.url; + $options.container = PJAX_CONTAINER_SELECTOR; + $options.type = 'POST'; + $.pjax($options); + }; var redirect = function(url) { $.pjax({url: url, container: PJAX_CONTAINER_SELECTOR, timeout : module.config.options.timeout}); @@ -95,6 +103,7 @@ humhub.module('client.pjax', function (module, require, $) { init: init, reload: reload, redirect: redirect, + post: post, isActive: isActive, installLoader: installLoader, });