Skip to content

Commit

Permalink
Merge pull request #32626 from nextcloud/backport/32618/stable22
Browse files Browse the repository at this point in the history
[stable22] Fix status handling
  • Loading branch information
nickvergessen authored May 31, 2022
2 parents cb2b8de + e89a98b commit b6a4e3b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
4 changes: 2 additions & 2 deletions apps/user_status/js/user-status-menu.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions apps/user_status/lib/Listener/UserLiveStatusListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,17 @@ class UserLiveStatusListener implements IEventListener {
/** @var UserStatusMapper */
private $mapper;

/** @var StatusService */
private $statusService;

/** @var ITimeFactory */
private $timeFactory;

/**
* UserLiveStatusListener constructor.
*
* @param UserStatusMapper $mapper
* @param ITimeFactory $timeFactory
*/
public function __construct(UserStatusMapper $mapper,
StatusService $statusService,
ITimeFactory $timeFactory) {
$this->mapper = $mapper;
$this->statusService = $statusService;
$this->timeFactory = $timeFactory;
}

Expand All @@ -71,7 +70,7 @@ public function handle(Event $event): void {

$user = $event->getUser();
try {
$userStatus = $this->mapper->findByUserId($user->getUID());
$userStatus = $this->statusService->findByUserId($user->getUID());
} catch (DoesNotExistException $ex) {
$userStatus = new UserStatus();
$userStatus->setUserId($user->getUID());
Expand Down
19 changes: 15 additions & 4 deletions apps/user_status/src/store/userStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,23 @@ const mutations = {
*/
loadStatusFromServer(state, { status, statusIsUserDefined, message, icon, clearAt, messageIsPredefined, messageId }) {
state.status = status
state.statusIsUserDefined = statusIsUserDefined
state.message = message
state.icon = icon
state.clearAt = clearAt
state.messageIsPredefined = messageIsPredefined
state.messageId = messageId

// Don't overwrite certain values if the refreshing comes in via short updates
// E.g. from talk participant list which only has the status, message and icon
if (typeof statusIsUserDefined !== 'undefined') {
state.statusIsUserDefined = statusIsUserDefined
}
if (typeof clearAt !== 'undefined') {
state.clearAt = clearAt
}
if (typeof messageIsPredefined !== 'undefined') {
state.messageIsPredefined = messageIsPredefined
}
if (typeof messageId !== 'undefined') {
state.messageId = messageId
}
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCA\UserStatus\Db\UserStatusMapper;
use OCA\UserStatus\Listener\UserDeletedListener;
use OCA\UserStatus\Listener\UserLiveStatusListener;
use OCA\UserStatus\Service\StatusService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\GenericEvent;
Expand All @@ -41,7 +42,8 @@ class UserLiveStatusListenerTest extends TestCase {

/** @var UserStatusMapper|\PHPUnit\Framework\MockObject\MockObject */
private $mapper;

/** @var StatusService|\PHPUnit\Framework\MockObject\MockObject */
private $statusService;
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
private $timeFactory;

Expand All @@ -52,8 +54,9 @@ protected function setUp(): void {
parent::setUp();

$this->mapper = $this->createMock(UserStatusMapper::class);
$this->statusService = $this->createMock(StatusService::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->listener = new UserLiveStatusListener($this->mapper, $this->timeFactory);
$this->listener = new UserLiveStatusListener($this->mapper, $this->statusService, $this->timeFactory);
}

/**
Expand Down Expand Up @@ -85,12 +88,12 @@ public function testHandleWithCorrectEvent(string $userId,
$userStatus->setStatusTimestamp($previousTimestamp);
$userStatus->setIsUserDefined($previousIsUserDefined);

$this->mapper->expects($this->once())
$this->statusService->expects($this->once())
->method('findByUserId')
->with($userId)
->willReturn($userStatus);
} else {
$this->mapper->expects($this->once())
$this->statusService->expects($this->once())
->method('findByUserId')
->with($userId)
->willThrowException(new DoesNotExistException(''));
Expand Down

0 comments on commit b6a4e3b

Please sign in to comment.