Skip to content

Commit

Permalink
Add user-status app
Browse files Browse the repository at this point in the history
Signed-off-by: Georg Ehrke <[email protected]>
  • Loading branch information
georgehrke committed Jun 23, 2020
1 parent d1b03f5 commit ab8cdbc
Show file tree
Hide file tree
Showing 39 changed files with 4,006 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
!/apps/updatenotification
!/apps/theming
!/apps/twofactor_backupcodes
!/apps/user_status
!/apps/workflowengine
/apps/files_external/3rdparty/irodsphp/PHPUnitTest
/apps/files_external/3rdparty/irodsphp/web
Expand Down
31 changes: 31 additions & 0 deletions apps/user_status/appinfo/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2020, Georg Ehrke
*
* @author Georg Ehrke <[email protected]>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

use OCA\UserStatus\AppInfo\Application;

/** @var Application $app */
$app = \OC::$server->query(Application::class);
$app->registerCapabilities();
$app->registerEvents();
21 changes: 21 additions & 0 deletions apps/user_status/appinfo/info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
<id>user_status</id>
<name>User Status</name>
<summary>User Status</summary>
<description><![CDATA[User Status]]></description>
<version>0.0.2</version>
<licence>agpl</licence>
<author mail="[email protected]" >Georg Ehrke</author>
<namespace>UserStatus</namespace>
<default_enable/>
<category>social</category>
<bugs>https://github.com/nextcloud/server</bugs>
<dependencies>
<nextcloud min-version="20" max-version="20"/>
</dependencies>
<background-jobs>
<job>OCA\UserStatus\BackgroundJob\ClearOldStatusesBackgroundJob</job>
</background-jobs>
</info>
40 changes: 40 additions & 0 deletions apps/user_status/appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2020, Georg Ehrke
*
* @author Georg Ehrke <[email protected]>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

return [
'ocs' => [
// Routes for querying statuses
['name' => 'Statuses#findAll', 'url' => '/api/v1/statuses', 'verb' => 'GET'],
['name' => 'Statuses#find', 'url' => '/api/v1/statuses/{userId}', 'verb' => 'GET'],
// Routes for manipulating your own status
['name' => 'UserStatus#getStatus', 'url' => '/api/v1/user_status', 'verb' => 'GET'],
['name' => 'UserStatus#setStatus', 'url' => '/api/v1/user_status/status', 'verb' => 'PUT'],
['name' => 'UserStatus#setPredefinedMessage', 'url' => '/api/v1/user_status/message/predefined', 'verb' => 'PUT'],
['name' => 'UserStatus#setCustomMessage', 'url' => '/api/v1/user_status/message/custom', 'verb' => 'PUT'],
['name' => 'UserStatus#clearStatus', 'url' => '/api/v1/user_status', 'verb' => 'DELETE'],
// Routes for listing default routes
['name' => 'PredefinedStatus#findAll', 'url' => '/api/v1/predefined_statuses', 'verb' => 'GET']
],
];
56 changes: 56 additions & 0 deletions apps/user_status/img/app.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions apps/user_status/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2020, Georg Ehrke
*
* @author Georg Ehrke <[email protected]>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\UserStatus\AppInfo;

use OCA\UserStatus\Capabilities;
use OCA\UserStatus\Listener\UserDeletedListener;
use OCA\UserStatus\Listener\UserLiveStatusListener;
use OCP\AppFramework\App;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\User\Events\UserDeletedEvent;
use OCP\User\Events\UserLiveStatusEvent;

/**
* Class Application
*
* @package OCA\UserStatus\AppInfo
*/
class Application extends App {

/** @var string */
public const APP_ID = 'user_status';

/**
* Application constructor.
*
* @param array $urlParams
*/
public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);
}

/**
* Registers capabilities that will be exposed
* via the OCS API endpoint
*/
public function registerCapabilities(): void {
$this->getContainer()
->registerCapability(Capabilities::class);
}

/**
* Registers a listener for the user-delete event
* to automatically delete a user's status on
* account deletion
*/
public function registerEvents(): void {
/** @var IEventDispatcher $dispatcher */
$dispatcher = $this->getContainer()
->query(IEventDispatcher::class);

$dispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedListener::class);
$dispatcher->addServiceListener(UserLiveStatusEvent::class, UserLiveStatusListener::class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2020, Georg Ehrke
*
* @author Georg Ehrke <[email protected]>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\UserStatus\BackgroundJob;

use OCA\UserStatus\Db\UserStatusMapper;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;

/**
* Class ClearOldStatusesBackgroundJob
*
* @package OCA\UserStatus\BackgroundJob
*/
class ClearOldStatusesBackgroundJob extends TimedJob {

/** @var UserStatusMapper */
private $mapper;

/**
* ClearOldStatusesBackgroundJob constructor.
*
* @param ITimeFactory $time
* @param UserStatusMapper $mapper
*/
public function __construct(ITimeFactory $time,
UserStatusMapper $mapper) {
parent::__construct($time);
$this->mapper = $mapper;

// Run every 15 minutes
$this->setInterval(60 * 15);
}

/**
* @inheritDoc
*/
protected function run($argument) {
$this->mapper->clearOlderThan($this->time->getTime());
}
}
60 changes: 60 additions & 0 deletions apps/user_status/lib/Capabilities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2020, Georg Ehrke
*
* @author Georg Ehrke <[email protected]>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\UserStatus;

use OCA\UserStatus\Service\EmojiService;
use OCP\Capabilities\ICapability;

/**
* Class Capabilities
*
* @package OCA\UserStatus
*/
class Capabilities implements ICapability {

/** @var EmojiService */
private $emojiService;

/**
* Capabilities constructor.
*
* @param EmojiService $emojiService
*/
public function __construct(EmojiService $emojiService) {
$this->emojiService = $emojiService;
}

/**
* @inheritDoc
*/
public function getCapabilities() {
return [
'user_status' => [
'enabled' => true,
'supports_emoji' => $this->emojiService->doesPlatformSupportEmoji(),
],
];
}
}
Loading

0 comments on commit ab8cdbc

Please sign in to comment.