-
Notifications
You must be signed in to change notification settings - Fork 13k
feat: set busy status on calendar appointments #35474
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
Merged
kodiakhq
merged 34 commits into
develop
from
feat/set-busy-status-on-calendar-appointments
Mar 20, 2025
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
4c4ae65
schedules status change on calendar item creation
ricardogarim f4356c5
adds Calendar_BusyStatus_Enabled setting
ricardogarim d0bf7e4
makes update and delete operations to verify existing crons
ricardogarim acabc00
removes crons when user manually changes status
ricardogarim 1c1a386
t adds endTime on CalendarEventCreateProps
ricardogarim b3638bf
enables Calendar_BusyStatus_Enabled setting
ricardogarim 67fe4cc
adds updateStatus method on Users model
ricardogarim f144965
splits status management into new file
ricardogarim 56fbb14
typecheck fix
ricardogarim 3df6595
adds unit tests
ricardogarim a4491d8
adds changeset
ricardogarim f47e039
fixes endTime initialization
ricardogarim aa6335f
moves db calls to models specific functions
ricardogarim 1263ebe
fixes unit tests
ricardogarim 93100fc
adds schedule overlapping tests
ricardogarim f6de7b7
moved some code to separate files
pierre-lehnen-rc 4f46eb6
finished moving tests
pierre-lehnen-rc e3501f4
fixed some tests, disabled others
pierre-lehnen-rc 6a7e275
removes unused import
ricardogarim 642add6
add e2e test
gabriellsh fc37624
add missing params to endpoints
pierre-lehnen-rc 4937f54
improved most unit tests
pierre-lehnen-rc bb6cd4f
Merge branch 'develop' into feat/set-busy-status-on-calendar-appointm…
pierre-lehnen-rc 625e368
Merge branch 'develop' into feat/set-busy-status-on-calendar-appointm…
scuciatto 263cfc6
Merge branch 'develop' into feat/set-busy-status-on-calendar-appointm…
2fad2e5
removes only flag from e2e test
ricardogarim 2655c48
Merge from develop
ricardogarim 483be88
fix types
ricardogarim 3e89d20
Merge branch 'develop' into feat/set-busy-status-on-calendar-appointm…
kodiakhq[bot] a5ff930
Merge branch 'develop' into feat/set-busy-status-on-calendar-appointm…
kodiakhq[bot] fdb95fa
Merge branch 'develop' into feat/set-busy-status-on-calendar-appointm…
kodiakhq[bot] 66c5e2d
Merge branch 'develop' into feat/set-busy-status-on-calendar-appointm…
kodiakhq[bot] dd4eebc
Merge branch 'develop' into feat/set-busy-status-on-calendar-appointm…
kodiakhq[bot] d00460d
Merge branch 'develop' into feat/set-busy-status-on-calendar-appointm…
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| '@rocket.chat/core-services': minor | ||
| '@rocket.chat/rest-typings': minor | ||
| '@rocket.chat/models': minor | ||
| '@rocket.chat/meteor': minor | ||
| --- | ||
|
|
||
| Adds automatic presence sync based on calendar events, updating the user’s status to “busy” when a meeting starts and reverting it afterward. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
apps/meteor/server/services/calendar/statusEvents/applyStatusChange.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { api } from '@rocket.chat/core-services'; | ||
| import { UserStatus } from '@rocket.chat/core-typings'; | ||
| import type { ICalendarEvent, IUser } from '@rocket.chat/core-typings'; | ||
| import { Users } from '@rocket.chat/models'; | ||
|
|
||
| import { setupAppointmentStatusChange } from './setupAppointmentStatusChange'; | ||
|
|
||
| export async function applyStatusChange({ | ||
| eventId, | ||
| uid, | ||
| startTime, | ||
| endTime, | ||
| status, | ||
| shouldScheduleRemoval, | ||
| }: { | ||
| eventId: ICalendarEvent['_id']; | ||
| uid: IUser['_id']; | ||
| startTime: Date; | ||
| endTime?: Date; | ||
| status?: UserStatus; | ||
| shouldScheduleRemoval?: boolean; | ||
| }): Promise<void> { | ||
| const user = await Users.findOneById(uid, { projection: { roles: 1, username: 1, name: 1, status: 1 } }); | ||
| if (!user || user.status === UserStatus.OFFLINE) { | ||
| return; | ||
| } | ||
|
|
||
| const newStatus = status ?? UserStatus.BUSY; | ||
| const previousStatus = user.status; | ||
|
|
||
| await Users.updateStatusAndStatusDefault(uid, newStatus, newStatus); | ||
|
|
||
| await api.broadcast('presence.status', { | ||
| user: { | ||
| status: newStatus, | ||
| _id: uid, | ||
| roles: user.roles, | ||
| username: user.username, | ||
| name: user.name, | ||
| }, | ||
| previousStatus, | ||
| }); | ||
|
|
||
| if (shouldScheduleRemoval && endTime) { | ||
| await setupAppointmentStatusChange(eventId, uid, startTime, endTime, previousStatus, false); | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
apps/meteor/server/services/calendar/statusEvents/cancelUpcomingStatusChanges.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import type { IUser } from '@rocket.chat/core-typings'; | ||
| import { cronJobs } from '@rocket.chat/cron'; | ||
| import { CalendarEvent } from '@rocket.chat/models'; | ||
|
|
||
| import { generateCronJobId } from './generateCronJobId'; | ||
| import { settings } from '../../../../app/settings/server'; | ||
|
|
||
| export async function cancelUpcomingStatusChanges(uid: IUser['_id'], endTime = new Date()): Promise<void> { | ||
| const hasBusyStatusSetting = settings.get<boolean>('Calendar_BusyStatus_Enabled'); | ||
| if (!hasBusyStatusSetting) { | ||
| return; | ||
| } | ||
|
|
||
| const events = await CalendarEvent.findEligibleEventsForCancelation(uid, endTime).toArray(); | ||
|
|
||
| for await (const event of events) { | ||
| const statusChangeJobId = generateCronJobId(event._id, event.uid, 'status'); | ||
| if (await cronJobs.has(statusChangeJobId)) { | ||
| await cronJobs.remove(statusChangeJobId); | ||
| } | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
apps/meteor/server/services/calendar/statusEvents/generateCronJobId.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import type { ICalendarEvent, IUser } from '@rocket.chat/core-typings'; | ||
|
|
||
| export function generateCronJobId(eventId: ICalendarEvent['_id'], uid: IUser['_id'], eventType: 'status' | 'reminder'): string { | ||
| if (!eventId || !uid || !eventType || (eventType !== 'status' && eventType !== 'reminder')) { | ||
| throw new Error('Missing required parameters. Please provide eventId, uid and eventType (status or reminder)'); | ||
| } | ||
|
|
||
| if (eventType === 'status') { | ||
| return `calendar-presence-status-${eventId}-${uid}`; | ||
| } | ||
|
|
||
| return `calendar-reminder-${eventId}-${uid}`; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.