mirror of
https://github.com/humhub/humhub.git
synced 2025-01-16 21:58:17 +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',
|
||||
'renderer' => ['class' => 'humhub\modules\notification\renderer\MailRenderer']
|
||||
],
|
||||
[
|
||||
'class' => 'humhub\modules\notification\targets\MobileTarget'
|
||||
],
|
||||
]
|
||||
],
|
||||
'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 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)
|
||||
--------------------------------
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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');
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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.
|
||||
*
|
||||
* @param type $userId
|
||||
* @return type
|
||||
* @param integer $userId
|
||||
* @return boolean
|
||||
*/
|
||||
public function isMember($userId = "")
|
||||
{
|
||||
@ -135,11 +135,10 @@ class SpaceModelMembership extends Behavior
|
||||
/**
|
||||
* Gets Owner for this workspace
|
||||
*
|
||||
* @return type
|
||||
* @return User
|
||||
*/
|
||||
public function getSpaceOwner()
|
||||
{
|
||||
|
||||
if ($this->_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)
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user