Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(user_status): set OoO status and message #41461

Closed
wants to merge 2 commits into from

Conversation

miaulalala
Copy link
Contributor

@miaulalala miaulalala commented Nov 14, 2023

Summary

Set the user status to DND and the custom message to \OCA\DAV\Db\Absence::getStatus when an absence is in effect.

TODO

  • determine if an absence is in effect

Checklist

Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat

@ChristophWurst
Copy link
Member

ChristophWurst commented Nov 14, 2023

Going into DND works if I clear my test user's status and backup status from oc_user_status. Edit: but status is saved as user defined?! This means absence is never checked again, so DND will not end automatically.

Does not do anything if there is an existing backup status. Does this conflict with another automation?

Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not fully work as expected yet

apps/dav/lib/Service/AbsenceService.php Fixed Show fixed Hide fixed
apps/dav/lib/Service/AbsenceService.php Fixed Show fixed Hide fixed
apps/dav/lib/Service/AbsenceService.php Fixed Show fixed Hide fixed
apps/dav/lib/Service/AbsenceService.php Fixed Show fixed Hide fixed
apps/dav/lib/Service/AbsenceService.php Fixed Show fixed Hide fixed
apps/dav/lib/Db/Absence.php Fixed Show fixed Hide fixed
apps/dav/lib/Db/Absence.php Fixed Show fixed Hide fixed
apps/dav/lib/Service/AbsenceService.php Fixed Show fixed Hide fixed
apps/dav/lib/Service/AbsenceService.php Fixed Show fixed Hide fixed
apps/dav/lib/Service/AbsenceService.php Fixed Show fixed Hide fixed
apps/dav/lib/Service/AbsenceService.php Fixed Show fixed Hide fixed
lib/private/User/AvailabilityCoordinator.php Fixed Show fixed Hide fixed
apps/dav/lib/Service/AbsenceService.php Fixed Show fixed Hide fixed
apps/dav/lib/Service/AbsenceService.php Fixed Show fixed Hide fixed
apps/dav/lib/Service/AbsenceService.php Fixed Show fixed Hide fixed
apps/dav/lib/Service/AbsenceService.php Fixed Show fixed Hide fixed
apps/dav/lib/Service/AbsenceService.php Fixed Show fixed Hide fixed
@miaulalala
Copy link
Contributor Author

Going into DND works if I clear my test user's status and backup status from oc_user_status. Edit: but status is saved as user defined?! This means absence is never checked again, so DND will not end automatically.

Does not do anything if there is an existing backup status. Does this conflict with another automation?

This is a general problem with the current code - there is no reverting a DND status if I use setUserStatus; but setStatus does not allow for custom messages.

This needs to be fixed in the follow up ticket #41441 which will add a method to allow to also set a custom message for the different automations we have. This will also help with the inflationary use of setUserStatus as that set isUserDefined to true whether that is correct or not.

@blizzz blizzz mentioned this pull request Nov 14, 2023
Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting into OOO status works. Getting out doesn't

Like #41461 (comment) says

@ChristophWurst
Copy link
Member

What's missing here? :)

@ChristophWurst
Copy link
Member

ChristophWurst commented Nov 16, 2023

  • BUG: Could not resolve OCA\\DAV\\Listener\\UserPreferenceListener! Class \"OCA\\DAV\\Listener\\UserPreferenceListener\" does not exist when I try to update my availability

@ChristophWurst
Copy link
Member

To keep things reviewable, please stay with fixup commits. I can't follow your changes if I have to review the full diff with every push 🙏

@ChristophWurst
Copy link
Member

ChristophWurst commented Nov 16, 2023

  • BUG (at least with previous HEAD commit): Online status and online status change to OOO and its message. When OOO ends, DND ends, but status stays at OOO message.

Edit: happens with latest state as well

@ChristophWurst
Copy link
Member

  • BUG: online status is still always lost. I fully reset my status and am at Away after the next page reload

@ChristophWurst
Copy link
Member

@miaulalala could you please drop a few lines describing how status automation now works conceptually? I see the old availability automation is gone. OOO changes are also reflected instantly, so I assume there is no caching yet?

$qb = $this->db->getQueryBuilder();
$qb->delete($this->tableName)
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)))
->andWhere($qb->expr()->eq('message_id', $qb->createNamedParameter($messageId)))
// ->andWhere($qb->expr()->eq('message_id', $qb->createNamedParameter($messageId)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

$this->mapper->update($userStatus);
}
}
// The "online vs away" stuff will need to be reimplemented
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this leave the live status in any worse state than current master?

}
}
// The "online vs away" stuff will need to be reimplemented
// the Status Listerner should only update the status, but not touch the messages
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a change I don't think we can do for 28. this also needs new public APIs and likely breaking of the existing

// calendar status.
// If there is, we have a more up- to- date userDefined status which should take precedence.
$this->backupCurrentStatus($userId);
// @todo - when a user has the option set to set the status to DND outside of office hours, we should respect that
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo in this pr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly can do

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do it here if this is a required change

skip if it's optional or not needed. I just want to make sure this isn't forgotten if required

@@ -92,13 +94,14 @@ const mutations = {
* @param {string} data.icon The icon
* @param {number} data.clearAt When to automatically clear the status
*/
setCustomMessage(state, { message, icon, clearAt }) {
setCustomMessage(state, { message, icon, clearAt, isUserDefined = false }) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the frontend always sends false, so we could even remove the option

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even more confusing as everything the user can click in the frontend actually IS "user defined"

@@ -49,81 +52,89 @@ protected function setUp(): void {
$db = Server::get(IDBConnection::class);
$qb = $db->getQueryBuilder();
$qb->delete('user_status')->executeStatement();
$qb->delete('users')->executeStatement();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dangerous if someone runs this test without a separate testing environment. this happens occasionally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it target the specific user then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good!

// IUserStatus::ONLINE,
// null,
// false,
// );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code?

// ->method('insert');
// $this->mapper->expects($this->once())
// ->method('update')
// ->with($this->callback(function ($userStatus) use ($eventStatus, $eventTimestamp) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code?

@ChristophWurst
Copy link
Member

  • BUG still can't save availability settings. now with
{
	"ocs": {
		"meta": {
			"status": "failure",
			"statuscode": 400,
			"message": ""
		},
		"data": []
	}
}

no logs

Copy link
Member

@provokateurin provokateurin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far is I can see you are changing the behavior of isUserDefined which is a bad idea for backwards compatibility.

The OCS endpoint should not have the possibility to set it because a custom message is always set by the user.

CC @nickvergessen you know more of the internal logic here

@miaulalala
Copy link
Contributor Author

As far is I can see you are changing the behavior of isUserDefined which is a bad idea for backwards compatibility.

The OCS endpoint should not have the possibility to set it because a custom message is always set by the user.

CC @nickvergessen you know more of the internal logic here

But that is not true. The "In a call" automation sets a status that pretends to be set by the user when it is in fact not for example.

@provokateurin
Copy link
Member

But that is not true. The "In a call" automation sets a status that pretends to be set by the user when it is in fact not for example.

Ok that is good to hear. I wasn't really sure what is going on just looking at the code alone.

But I think the OCS endpoint still shouldn't have the option and always set it to true, do you agree?

@ChristophWurst
Copy link
Member

But I think the OCS endpoint still shouldn't have the option

as far as I can tell our frontend doesn't make use of the option either. ref #41461 (comment). we should be able to revert this change.

@miaulalala
Copy link
Contributor Author

miaulalala commented Nov 16, 2023

But I think the OCS endpoint still shouldn't have the option

as far as I can tell our frontend doesn't make use of the option either. ref #41461 (comment). we should be able to revert this change.

the frontend now does, at least if you set the status as a user in the status modal.

@miaulalala
Copy link
Contributor Author

miaulalala commented Nov 16, 2023

@miaulalala could you please drop a few lines describing how status automation now works conceptually? I see the old availability automation is gone. OOO changes are also reflected instantly, so I assume there is no caching yet?

the status itself i snot cached but the OOO data is. The cache is reset when an absence is created, updated or deleted as otherwise the change would never propagate.

Will drop a few lines after I've made the logic changes.

@ChristophWurst
Copy link
Member

Careful with using caches as consistent storage. Let's just let the cache expire a bit earlier because it is a local one. On a clustered setup you can only clear the cache of one instance. For the other instances it has to expire on its own. You could switch to a distributed cache but they are expensive and create a new bottleneck.

@provokateurin
Copy link
Member

the frontend now does, at least if you set the status as a user in the status modal.

but it sets the isUserChanged to true, right? then you still don't need to expose this as setCustomMessage was already setting it to true.

@nickvergessen
Copy link
Member

The "In a call" automation sets a status that pretends to be set by the user when it is in fact not for example.

Well just because there is no option to specify this via public OCP (not S) API. But the $createBackup set to true basically always means it's not set by the user?

@@ -192,7 +194,7 @@ public function clearMessage(): DataResponse {
* 200: Status reverted
*/
public function revertStatus(string $messageId): DataResponse {
$backupStatus = $this->service->revertUserStatus($this->userId, $messageId, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oo this means after ending a call your user status will always be killed?

@@ -241,7 +258,7 @@ public function setPredefinedMessage(string $userId,
$userStatus->setUserId($userId);
$userStatus->setStatus(IUserStatus::OFFLINE);
$userStatus->setStatusTimestamp(0);
$userStatus->setIsUserDefined(false);
$userStatus->setIsUserDefined(true); // all predefined messages are by default set by the user
Copy link
Member

@nickvergessen nickvergessen Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But offline is not settable by users, only invisible which is shown to others as "offline".
If you make Offline setIsUserDefined(true) coming online and interacting will no longer set any status?

Comment on lines +96 to +97
public const HOLIDAY_ICON = '🌴';
public const MEETING_ICON = '📅';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add @since

@@ -91,7 +94,8 @@ public function __construct(private UserStatusMapper $mapper,
private IEmojiHelper $emojiHelper,
private IConfig $config,
private IUserManager $userManager,
private CalendarStatusService $calendarStatusService) {
private CalendarStatusService $calendarStatusService,
public IAvailabilityCoordinator $coordinator) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public IAvailabilityCoordinator $coordinator) {
private IAvailabilityCoordinator $coordinator) {

@ChristophWurst
Copy link
Member

#41714

@miaulalala miaulalala closed this Nov 24, 2023
@ChristophWurst ChristophWurst deleted the enh/set-ooo-status branch November 24, 2023 11:18
@skjnldsv skjnldsv removed this from the Nextcloud 29 milestone Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

Out-of-office: Update user status
7 participants