Skip to content

Commit f333dd1

Browse files
committed
Add user-status app
Signed-off-by: Georg Ehrke <[email protected]>
1 parent ebedbf1 commit f333dd1

38 files changed

Lines changed: 3957 additions & 0 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
!/apps/updatenotification
3939
!/apps/theming
4040
!/apps/twofactor_backupcodes
41+
!/apps/user_status
4142
!/apps/workflowengine
4243
/apps/files_external/3rdparty/irodsphp/PHPUnitTest
4344
/apps/files_external/3rdparty/irodsphp/web

apps/user_status/appinfo/app.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2020, Georg Ehrke
7+
*
8+
* @author Georg Ehrke <[email protected]>
9+
*
10+
* @license AGPL-3.0
11+
*
12+
* This code is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License, version 3,
14+
* as published by the Free Software Foundation.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License, version 3,
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>
23+
*
24+
*/
25+
26+
use OCA\UserStatus\AppInfo\Application;
27+
28+
/** @var Application $app */
29+
$app = \OC::$server->query(Application::class);
30+
$app->registerCapabilities();
31+
$app->registerEvents();

apps/user_status/appinfo/info.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
4+
<id>user_status</id>
5+
<name>User Status</name>
6+
<summary>User status</summary>
7+
<description><![CDATA[User status]]></description>
8+
<version>0.0.2</version>
9+
<licence>agpl</licence>
10+
<author mail="[email protected]" >Georg Ehrke</author>
11+
<namespace>UserStatus</namespace>
12+
<default_enable/>
13+
<category>social</category>
14+
<bugs>https://github.com/nextcloud/server</bugs>
15+
<dependencies>
16+
<nextcloud min-version="20" max-version="20"/>
17+
</dependencies>
18+
<background-jobs>
19+
<job>OCA\UserStatus\BackgroundJob\ClearOldStatusesBackgroundJob</job>
20+
</background-jobs>
21+
</info>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2020, Georg Ehrke
7+
*
8+
* @author Georg Ehrke <[email protected]>
9+
*
10+
* @license AGPL-3.0
11+
*
12+
* This code is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License, version 3,
14+
* as published by the Free Software Foundation.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License, version 3,
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>
23+
*
24+
*/
25+
26+
return [
27+
'ocs' => [
28+
// Routes for querying statuses
29+
['name' => 'Statuses#findAll', 'url' => '/api/v1/statuses', 'verb' => 'GET'],
30+
['name' => 'Statuses#find', 'url' => '/api/v1/statuses/{userId}', 'verb' => 'GET'],
31+
// Routes for manipulating your own status
32+
['name' => 'UserStatus#getStatus', 'url' => '/api/v1/user_status', 'verb' => 'GET'],
33+
['name' => 'UserStatus#setStatus', 'url' => '/api/v1/user_status/status', 'verb' => 'PUT'],
34+
['name' => 'UserStatus#setPredefinedMessage', 'url' => '/api/v1/user_status/message/predefined', 'verb' => 'PUT'],
35+
['name' => 'UserStatus#setCustomMessage', 'url' => '/api/v1/user_status/message/custom', 'verb' => 'PUT'],
36+
['name' => 'UserStatus#clearStatus', 'url' => '/api/v1/user_status', 'verb' => 'DELETE'],
37+
// Routes for listing default routes
38+
['name' => 'PredefinedStatus#findAll', 'url' => '/api/v1/predefined_statuses', 'verb' => 'GET']
39+
],
40+
];

apps/user_status/img/app.svg

Lines changed: 56 additions & 0 deletions
Loading
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2020, Georg Ehrke
7+
*
8+
* @author Georg Ehrke <[email protected]>
9+
*
10+
* @license AGPL-3.0
11+
*
12+
* This code is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License, version 3,
14+
* as published by the Free Software Foundation.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License, version 3,
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>
23+
*
24+
*/
25+
26+
namespace OCA\UserStatus\AppInfo;
27+
28+
use OCA\UserStatus\Capabilities;
29+
use OCA\UserStatus\Listener\UserDeletedListener;
30+
use OCA\UserStatus\Listener\UserLiveStatusListener;
31+
use OCP\AppFramework\App;
32+
use OCP\EventDispatcher\IEventDispatcher;
33+
use OCP\User\Events\UserDeletedEvent;
34+
use OCP\User\Events\UserLiveStatusEvent;
35+
36+
/**
37+
* Class Application
38+
*
39+
* @package OCA\UserStatus\AppInfo
40+
*/
41+
class Application extends App {
42+
43+
/** @var string */
44+
public const APP_ID = 'user_status';
45+
46+
/**
47+
* Application constructor.
48+
*
49+
* @param array $urlParams
50+
*/
51+
public function __construct(array $urlParams = []) {
52+
parent::__construct(self::APP_ID, $urlParams);
53+
}
54+
55+
/**
56+
* Registers capabilities that will be exposed
57+
* via the OCS API endpoint
58+
*/
59+
public function registerCapabilities(): void {
60+
$this->getContainer()
61+
->registerCapability(Capabilities::class);
62+
}
63+
64+
/**
65+
* Registers a listener for the user-delete event
66+
* to automatically delete a user's status on
67+
* account deletion
68+
*/
69+
public function registerEvents(): void {
70+
/** @var IEventDispatcher $dispatcher */
71+
$dispatcher = $this->getContainer()
72+
->query(IEventDispatcher::class);
73+
74+
$dispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedListener::class);
75+
$dispatcher->addServiceListener(UserLiveStatusEvent::class, UserLiveStatusListener::class);
76+
}
77+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2020, Georg Ehrke
7+
*
8+
* @author Georg Ehrke <[email protected]>
9+
*
10+
* @license AGPL-3.0
11+
*
12+
* This code is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License, version 3,
14+
* as published by the Free Software Foundation.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License, version 3,
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>
23+
*
24+
*/
25+
26+
namespace OCA\UserStatus\BackgroundJob;
27+
28+
use OCA\UserStatus\Db\UserStatusMapper;
29+
use OCP\AppFramework\Utility\ITimeFactory;
30+
use OCP\BackgroundJob\TimedJob;
31+
32+
/**
33+
* Class ClearOldStatusesBackgroundJob
34+
*
35+
* @package OCA\UserStatus\BackgroundJob
36+
*/
37+
class ClearOldStatusesBackgroundJob extends TimedJob {
38+
39+
/** @var UserStatusMapper */
40+
private $mapper;
41+
42+
/**
43+
* ClearOldStatusesBackgroundJob constructor.
44+
*
45+
* @param ITimeFactory $time
46+
* @param UserStatusMapper $mapper
47+
*/
48+
public function __construct(ITimeFactory $time,
49+
UserStatusMapper $mapper) {
50+
parent::__construct($time);
51+
$this->mapper = $mapper;
52+
53+
// Run every 15 minutes
54+
$this->setInterval(60 * 15);
55+
}
56+
57+
/**
58+
* @inheritDoc
59+
*/
60+
protected function run($argument) {
61+
$this->mapper->clearOlderThan($this->time->getTime());
62+
}
63+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2020, Georg Ehrke
7+
*
8+
* @author Georg Ehrke <[email protected]>
9+
*
10+
* @license AGPL-3.0
11+
*
12+
* This code is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License, version 3,
14+
* as published by the Free Software Foundation.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License, version 3,
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>
23+
*
24+
*/
25+
namespace OCA\UserStatus;
26+
27+
use OCA\UserStatus\Service\EmojiService;
28+
use OCP\Capabilities\ICapability;
29+
30+
/**
31+
* Class Capabilities
32+
*
33+
* @package OCA\UserStatus
34+
*/
35+
class Capabilities implements ICapability {
36+
37+
/** @var EmojiService */
38+
private $emojiService;
39+
40+
/**
41+
* Capabilities constructor.
42+
*
43+
* @param EmojiService $emojiService
44+
*/
45+
public function __construct(EmojiService $emojiService) {
46+
$this->emojiService = $emojiService;
47+
}
48+
49+
/**
50+
* @inheritDoc
51+
*/
52+
public function getCapabilities() {
53+
return [
54+
'user_status' => [
55+
'enabled' => true,
56+
'supports_emoji' => $this->emojiService->doesPlatformSupportEmoji(),
57+
],
58+
];
59+
}
60+
}

0 commit comments

Comments
 (0)