Merge pull request #32618 from nextcloud/bugfix/noid/fix-status-handling

Fix status handling
This commit is contained in:
Joas Schilling 2022-05-27 11:20:25 +02:00 committed by GitHub
commit 9ad5b301ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 34 additions and 18 deletions

View file

@ -43,11 +43,14 @@ use OCP\UserStatus\IUserStatus;
*/
class UserLiveStatusListener implements IEventListener {
private UserStatusMapper $mapper;
private StatusService $statusService;
private ITimeFactory $timeFactory;
public function __construct(UserStatusMapper $mapper,
StatusService $statusService,
ITimeFactory $timeFactory) {
$this->mapper = $mapper;
$this->statusService = $statusService;
$this->timeFactory = $timeFactory;
}
@ -62,7 +65,7 @@ class UserLiveStatusListener implements IEventListener {
$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());

View file

@ -38,7 +38,6 @@ use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\Exception;
use OCP\IConfig;
use OCP\IEmojiHelper;
use OCP\IUser;
use OCP\UserStatus\IUserStatus;
/**

View file

@ -55,14 +55,14 @@
<ClearAtSelect :clear-at="clearAt"
@select-clear-at="setClearAt" />
<div class="status-buttons">
<ButtonVue wide="true"
<ButtonVue :wide="true"
type="tertiary"
:text="$t('user_status', 'Clear status message')"
:disabled="isSavingStatus"
@click="clearStatus">
{{ $t('user_status', 'Clear status message') }}
</ButtonVue>
<ButtonVue wide="true"
<ButtonVue :wide="true"
type="primary"
:text="$t('user_status', 'Set status message')"
:disabled="isSavingStatus"

View file

@ -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
}
},
}

View file

@ -30,6 +30,7 @@ use OCA\UserStatus\Db\UserStatus;
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;
@ -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;
@ -52,8 +54,9 @@ class UserLiveStatusListenerTest extends TestCase {
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);
}
/**
@ -85,12 +88,12 @@ class UserLiveStatusListenerTest extends TestCase {
$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(''));

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long