mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 06:08:21 +01:00
Enh: Added MobileTargetProvider
abstraction for mobile push notifications
Enh: Added `humhub:notification:udpateCount` js event
This commit is contained in:
parent
1100c92cbb
commit
b437373595
@ -31,6 +31,9 @@ $config = [
|
|||||||
'class' => 'humhub\modules\notification\targets\MailTarget',
|
'class' => 'humhub\modules\notification\targets\MailTarget',
|
||||||
'renderer' => ['class' => 'humhub\modules\notification\renderer\MailRenderer']
|
'renderer' => ['class' => 'humhub\modules\notification\renderer\MailRenderer']
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'class' => 'humhub\modules\notification\targets\MobileTarget'
|
||||||
|
],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'log' => [
|
'log' => [
|
||||||
|
@ -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 default open content as modal action
|
||||||
- Enh: Added possibility to add attachments in Notification MailTarget
|
- Enh: Added possibility to add attachments in Notification MailTarget
|
||||||
- Enh: Added surpressSendToOriginator Notification option
|
- 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)
|
1.2.2 (August 2, 2017)
|
||||||
--------------------------------
|
--------------------------------
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
namespace humhub\modules\notification\components;
|
namespace humhub\modules\notification\components;
|
||||||
|
|
||||||
|
use humhub\modules\notification\models\Notification;
|
||||||
use Yii;
|
use Yii;
|
||||||
use humhub\modules\user\models\User;
|
use humhub\modules\user\models\User;
|
||||||
use humhub\modules\space\models\Membership;
|
use humhub\modules\space\models\Membership;
|
||||||
@ -48,7 +49,7 @@ class NotificationManager
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Cached array of NotificationCategories
|
* Cached array of NotificationCategories
|
||||||
* @var type
|
* @var NotificationCategory[]
|
||||||
*/
|
*/
|
||||||
protected $_categories;
|
protected $_categories;
|
||||||
|
|
||||||
@ -61,12 +62,12 @@ class NotificationManager
|
|||||||
*/
|
*/
|
||||||
public function sendBulk(BaseNotification $notification, $users)
|
public function sendBulk(BaseNotification $notification, $users)
|
||||||
{
|
{
|
||||||
$recepients = $this->filterRecepients($notification, $users);
|
$recipients = $this->filterRecipients($notification, $users);
|
||||||
|
|
||||||
foreach ($recepients as $recepient) {
|
foreach ($recipients as $recipient) {
|
||||||
$notification->saveRecord($recepient);
|
$notification->saveRecord($recipient);
|
||||||
foreach ($this->getTargets($recepient) as $target) {
|
foreach ($this->getTargets($recipient) as $target) {
|
||||||
$target->send($notification, $recepient);
|
$target->send($notification, $recipient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,7 +78,7 @@ class NotificationManager
|
|||||||
* @param User[] $users
|
* @param User[] $users
|
||||||
* @return User[] array of unique user instances
|
* @return User[] array of unique user instances
|
||||||
*/
|
*/
|
||||||
protected function filterRecepients(BaseNotification $notification, $users)
|
protected function filterRecipients(BaseNotification $notification, $users)
|
||||||
{
|
{
|
||||||
$userIds = [];
|
$userIds = [];
|
||||||
$filteredUsers = [];
|
$filteredUsers = [];
|
||||||
@ -103,7 +104,7 @@ class NotificationManager
|
|||||||
*/
|
*/
|
||||||
public function send(BaseNotification $notification, User $user)
|
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.
|
* Factory function for receiving a target instance for the given class.
|
||||||
*
|
*
|
||||||
* @param type $class
|
* @param string $class
|
||||||
* @return type
|
* @return BaseTarget
|
||||||
*/
|
*/
|
||||||
public function getTarget($class)
|
public function getTarget($class)
|
||||||
{
|
{
|
||||||
@ -158,7 +159,7 @@ class NotificationManager
|
|||||||
*
|
*
|
||||||
* @param User $user
|
* @param User $user
|
||||||
* @param Space $space
|
* @param Space $space
|
||||||
* @return type
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function isFollowingSpace(User $user, Space $space)
|
public function isFollowingSpace(User $user, Space $space)
|
||||||
{
|
{
|
||||||
@ -270,7 +271,7 @@ class NotificationManager
|
|||||||
* Returns all spaces this user is not following.
|
* Returns all spaces this user is not following.
|
||||||
*
|
*
|
||||||
* @param User $user
|
* @param User $user
|
||||||
* @return type
|
* @return Space[]
|
||||||
*/
|
*/
|
||||||
public function getNonNotificationSpaces(User $user = null, $limit = 25)
|
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.
|
* 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
|
* @param User $user
|
||||||
*/
|
*/
|
||||||
public function setDesktopNoficationSettings($value = 0, User $user = null)
|
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.
|
* 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.
|
* By default the setting is enabled.
|
||||||
* @param User $user
|
* @param User $user
|
||||||
* @return type
|
* @return integer
|
||||||
*/
|
*/
|
||||||
public function getDesktopNoficationSettings(User $user = null)
|
public function getDesktopNoficationSettings(User $user = null)
|
||||||
{
|
{
|
||||||
@ -360,11 +361,11 @@ class NotificationManager
|
|||||||
*
|
*
|
||||||
* @param User $user user instance for which this settings will aplly
|
* @param User $user user instance for which this settings will aplly
|
||||||
* @param Space $space which notifications will be followed / unfollowed
|
* @param Space $space which notifications will be followed / unfollowed
|
||||||
* @param type $follow the setting value (true by default)
|
* @param boolean $follow the setting value (true by default)
|
||||||
* @return type
|
|
||||||
*/
|
*/
|
||||||
public function setSpaceSetting(User $user = null, Space $space, $follow = true)
|
public function setSpaceSetting(User $user = null, Space $space, $follow = true)
|
||||||
{
|
{
|
||||||
|
/* @var $membership Membership */
|
||||||
$membership = $space->getMembership($user->id);
|
$membership = $space->getMembership($user->id);
|
||||||
if ($membership) {
|
if ($membership) {
|
||||||
$membership->send_notifications = $follow;
|
$membership->send_notifications = $follow;
|
||||||
@ -385,7 +386,7 @@ class NotificationManager
|
|||||||
/**
|
/**
|
||||||
* Returns all available Notifications
|
* Returns all available Notifications
|
||||||
*
|
*
|
||||||
* @return type
|
* @return BaseNotification[]
|
||||||
*/
|
*/
|
||||||
public function getNotifications()
|
public function getNotifications()
|
||||||
{
|
{
|
||||||
|
@ -111,6 +111,8 @@ humhub.module('notification', function (module, require, $) {
|
|||||||
|
|
||||||
$('#badge-notifications').hide();
|
$('#badge-notifications').hide();
|
||||||
|
|
||||||
|
event.trigger('humhub:notification:udpateCount', [$count]);
|
||||||
|
|
||||||
if (!$count) {
|
if (!$count) {
|
||||||
updateTitle(false);
|
updateTitle(false);
|
||||||
$('#badge-notifications').html('0');
|
$('#badge-notifications').html('0');
|
||||||
|
@ -38,7 +38,7 @@ abstract class BaseTarget extends \yii\base\Object
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Renderer for this BaseTarget
|
* Default Renderer for this BaseTarget
|
||||||
* @var type
|
* @var Renderer
|
||||||
*/
|
*/
|
||||||
public $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.
|
* Returns the setting key for this target of the given $category.
|
||||||
* @param type $category
|
* @param NotificationCategory $category
|
||||||
* @return type
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getSettingKey($category)
|
public function getSettingKey($category)
|
||||||
{
|
{
|
||||||
|
@ -10,6 +10,8 @@ namespace humhub\modules\notification\targets;
|
|||||||
|
|
||||||
use humhub\modules\user\models\User;
|
use humhub\modules\user\models\User;
|
||||||
use humhub\modules\notification\components\BaseNotification;
|
use humhub\modules\notification\components\BaseNotification;
|
||||||
|
use Yii;
|
||||||
|
use yii\di\NotInstantiableException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mobile Target
|
* Mobile Target
|
||||||
@ -25,6 +27,22 @@ class MobileTarget extends BaseTarget
|
|||||||
*/
|
*/
|
||||||
public $id = 'mobile';
|
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.
|
* Used to forward a BaseNotification object to a BaseTarget.
|
||||||
* The notification target should handle the notification by pushing a Job to
|
* 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)
|
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()
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @link https://www.humhub.org/
|
||||||
|
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
|
||||||
|
* @license https://www.humhub.com/licences
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: buddha
|
||||||
|
* Date: 01.10.2017
|
||||||
|
* Time: 15:15
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace humhub\modules\notification\targets;
|
||||||
|
|
||||||
|
|
||||||
|
use humhub\modules\notification\components\BaseNotification;
|
||||||
|
use humhub\modules\user\models\User;
|
||||||
|
|
||||||
|
interface MobileTargetProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param BaseNotification $notification
|
||||||
|
* @param User $user
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function handle(BaseNotification $notification, User $user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param User|null $user
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isActive(User $user = null);
|
||||||
|
}
|
@ -32,8 +32,8 @@ class SpaceModelMembership extends Behavior
|
|||||||
/**
|
/**
|
||||||
* Checks if given Userid is Member of this Space.
|
* Checks if given Userid is Member of this Space.
|
||||||
*
|
*
|
||||||
* @param type $userId
|
* @param integer $userId
|
||||||
* @return type
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function isMember($userId = "")
|
public function isMember($userId = "")
|
||||||
{
|
{
|
||||||
@ -135,11 +135,10 @@ class SpaceModelMembership extends Behavior
|
|||||||
/**
|
/**
|
||||||
* Gets Owner for this workspace
|
* Gets Owner for this workspace
|
||||||
*
|
*
|
||||||
* @return type
|
* @return User
|
||||||
*/
|
*/
|
||||||
public function getSpaceOwner()
|
public function getSpaceOwner()
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->_spaceOwner != null) {
|
if ($this->_spaceOwner != null) {
|
||||||
return $this->_spaceOwner;
|
return $this->_spaceOwner;
|
||||||
}
|
}
|
||||||
@ -169,8 +168,8 @@ class SpaceModelMembership extends Behavior
|
|||||||
/**
|
/**
|
||||||
* Sets Owner for this workspace
|
* Sets Owner for this workspace
|
||||||
*
|
*
|
||||||
* @param type $userId
|
* @param integer $userId
|
||||||
* @return type
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function setAdmin($userId = null)
|
public function setAdmin($userId = null)
|
||||||
{
|
{
|
||||||
@ -208,8 +207,8 @@ class SpaceModelMembership extends Behavior
|
|||||||
/**
|
/**
|
||||||
* Invites a not registered member to this space
|
* Invites a not registered member to this space
|
||||||
*
|
*
|
||||||
* @param type $email
|
* @param string $email
|
||||||
* @param type $originatorUserId
|
* @param integer $originatorUserId
|
||||||
*/
|
*/
|
||||||
public function inviteMemberByEMail($email, $originatorUserId)
|
public function inviteMemberByEMail($email, $originatorUserId)
|
||||||
{
|
{
|
||||||
@ -253,8 +252,8 @@ class SpaceModelMembership extends Behavior
|
|||||||
/**
|
/**
|
||||||
* Requests Membership
|
* Requests Membership
|
||||||
*
|
*
|
||||||
* @param type $userId
|
* @param integer $userId
|
||||||
* @param type $message
|
* @param string $message
|
||||||
*/
|
*/
|
||||||
public function requestMembership($userId, $message = "")
|
public function requestMembership($userId, $message = "")
|
||||||
{
|
{
|
||||||
@ -297,8 +296,8 @@ class SpaceModelMembership extends Behavior
|
|||||||
* If user is already invited, retrigger invitation.
|
* If user is already invited, retrigger invitation.
|
||||||
* If user is applicant approve it.
|
* If user is applicant approve it.
|
||||||
*
|
*
|
||||||
* @param type $userId
|
* @param integer $userId
|
||||||
* @param type $originatorId
|
* @param integer $originatorId
|
||||||
*/
|
*/
|
||||||
public function inviteMember($userId, $originatorId)
|
public function inviteMember($userId, $originatorId)
|
||||||
{
|
{
|
||||||
@ -340,8 +339,8 @@ class SpaceModelMembership extends Behavior
|
|||||||
/**
|
/**
|
||||||
* Sends an Invite Notification to the given user.
|
* Sends an Invite Notification to the given user.
|
||||||
*
|
*
|
||||||
* @param type $userId
|
* @param integer $userId
|
||||||
* @param type $originatorId
|
* @param integer $originatorId
|
||||||
*/
|
*/
|
||||||
protected function sendInviteNotification($userId, $originatorId)
|
protected function sendInviteNotification($userId, $originatorId)
|
||||||
{
|
{
|
||||||
@ -359,8 +358,8 @@ class SpaceModelMembership extends Behavior
|
|||||||
* This can happens after an clicking "Request Membership" Link
|
* This can happens after an clicking "Request Membership" Link
|
||||||
* after Approval or accepting an invite.
|
* after Approval or accepting an invite.
|
||||||
*
|
*
|
||||||
* @param type $userId
|
* @param integer $userId
|
||||||
* @param type $canLeave 0: user cannot cancel membership | 1: can cancel membership | 2: depending on space flag members_can_leave
|
* @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)
|
public function addMember($userId, $canLeave = 1)
|
||||||
{
|
{
|
||||||
|
@ -22,7 +22,7 @@ use humhub\modules\space\models\Space;
|
|||||||
* @property string $request_message
|
* @property string $request_message
|
||||||
* @property string $last_visit
|
* @property string $last_visit
|
||||||
* @property integer $show_at_dashboard
|
* @property integer $show_at_dashboard
|
||||||
* @property boolean $can_leave
|
* @property integer $can_cancel_membership
|
||||||
* @property string $group_id
|
* @property string $group_id
|
||||||
* @property string $created_at
|
* @property string $created_at
|
||||||
* @property integer $created_by
|
* @property integer $created_by
|
||||||
|
@ -10,6 +10,14 @@ humhub.module('client.pjax', function (module, require, $) {
|
|||||||
module.installLoader();
|
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) {
|
var redirect = function(url) {
|
||||||
$.pjax({url: url, container: PJAX_CONTAINER_SELECTOR, timeout : module.config.options.timeout});
|
$.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,
|
init: init,
|
||||||
reload: reload,
|
reload: reload,
|
||||||
redirect: redirect,
|
redirect: redirect,
|
||||||
|
post: post,
|
||||||
isActive: isActive,
|
isActive: isActive,
|
||||||
installLoader: installLoader,
|
installLoader: installLoader,
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user