Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/user_status/js/user-status-menu.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/user_status/js/user-status-menu.js.map

Large diffs are not rendered by default.

40 changes: 29 additions & 11 deletions apps/user_status/lib/Controller/HeartbeatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
*/
namespace OCA\UserStatus\Controller;

use OCA\UserStatus\Db\UserStatus;
use OCA\UserStatus\Service\StatusService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Utility\ITimeFactory;
Expand All @@ -46,24 +49,20 @@ class HeartbeatController extends Controller {
/** @var ITimeFactory */
private $timeFactory;

/**
* HeartbeatController constructor.
*
* @param string $appName
* @param IRequest $request
* @param IEventDispatcher $eventDispatcher
* @param IUserSession $userSession
* @param ITimeFactory $timeFactory
*/
/** @var StatusService */
private $service;

public function __construct(string $appName,
IRequest $request,
IEventDispatcher $eventDispatcher,
IUserSession $userSession,
ITimeFactory $timeFactory) {
ITimeFactory $timeFactory,
StatusService $service) {
parent::__construct($appName, $request);
$this->eventDispatcher = $eventDispatcher;
$this->userSession = $userSession;
$this->timeFactory = $timeFactory;
$this->service = $service;
}

/**
Expand All @@ -90,6 +89,25 @@ public function heartbeat(string $status): JSONResponse {
)
);

return new JSONResponse([], Http::STATUS_NO_CONTENT);
try {
$userStatus = $this->service->findByUserId($user->getUID());
} catch (DoesNotExistException $ex) {
return new JSONResponse([], Http::STATUS_NO_CONTENT);
}

return new JSONResponse($this->formatStatus($userStatus));
}

private function formatStatus(UserStatus $status): array {
return [
'userId' => $status->getUserId(),
'message' => $status->getCustomMessage(),
'messageId' => $status->getMessageId(),
'messageIsPredefined' => $status->getMessageId() !== null,
'icon' => $status->getCustomIcon(),
'clearAt' => $status->getClearAt(),
'status' => $status->getStatus(),
'statusIsUserDefined' => $status->getIsUserDefined(),
];
}
}
9 changes: 6 additions & 3 deletions apps/user_status/src/UserStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,15 @@ export default {
*/
async _backgroundHeartbeat() {
try {
await sendHeartbeat(this.isAway)
const status = await sendHeartbeat(this.isAway)
if (status?.userId) {
this.$store.dispatch('setStatusFromHeartbeat', status)
} else {
await this.$store.dispatch('reFetchStatusFromServer')
}
} catch (error) {
console.debug('Failed sending heartbeat, got: ' + error.response.status)
return
}
await this.$store.dispatch('reFetchStatusFromServer')
},
},
}
Expand Down
3 changes: 2 additions & 1 deletion apps/user_status/src/services/heartbeatService.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ import { generateUrl } from '@nextcloud/router'
*/
const sendHeartbeat = async(isAway) => {
const url = generateUrl('/apps/user_status/heartbeat')
await HttpClient.put(url, {
const response = await HttpClient.put(url, {
status: isAway ? 'away' : 'online',
})
return response.data
}

export {
Expand Down
19 changes: 19 additions & 0 deletions apps/user_status/src/store/userStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,25 @@ const actions = {
commit('loadStatusFromServer', status)
},

/**
* Stores the status we got in the reply of the heartbeat
*
* @param {Object} vuex The Vuex destructuring object
* @param {Function} vuex.commit The Vuex commit function
* @param {Object} status The data destructuring object
* @param {String} status.status The status type
* @param {Boolean} status.statusIsUserDefined Whether or not this status is user-defined
* @param {String} status.message The message
* @param {String} status.icon The icon
* @param {Number} status.clearAt When to automatically clear the status
* @param {Boolean} status.messageIsPredefined Whether or not the message is predefined
* @param {String} status.messageId The id of the predefined message
* @returns {Promise<void>}
*/
async setStatusFromHeartbeat({ commit }, status) {
commit('loadStatusFromServer', status)
},

/**
* Loads the server from the initial state
*
Expand Down