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

feat: Add Hours, Minutes, Seconds fields while taking input as idleTimeLimit #33708

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
5 changes: 5 additions & 0 deletions .changeset/wild-sheep-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Enhanced userPresence options making it more human readable.
thepiyush-303 marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 8 additions & 1 deletion apps/meteor/client/startup/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ Meteor.startup(() => {
}

if (getUserPreference(user, 'enableAutoAway')) {
const idleTimeLimit = (getUserPreference(user, 'idleTimeLimit') as number | null | undefined) || 300;
const idleTimeLimitH = (getUserPreference(user, 'idleTimeLimitH') as number | null | undefined) || 0;
thepiyush-303 marked this conversation as resolved.
Show resolved Hide resolved

const idleTimeLimitM = (getUserPreference(user, 'idleTimeLimitM') as number | null | undefined) || 5;

const idleTimeLimitS = (getUserPreference(user, 'idleTimeLimitS') as number | null | undefined) || 0;

const idleTimeLimit = (idleTimeLimitH) * 3600 + (idleTimeLimitM)* 60 + (idleTimeLimitS);

UserPresence.awayTime = idleTimeLimit * 1000;
} else {
delete UserPresence.awayTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ const PreferencesUserPresenceSection = () => {
const { register, control } = useFormContext();

const enableAutoAwayId = useUniqueId();
const idleTimeLimit = useUniqueId();
const idleTimeLimitH = useUniqueId();
const idleTimeLimitM = useUniqueId();
const idleTimeLimitS = useUniqueId();


return (
<Accordion.Item title={t('User_Presence')}>
Expand All @@ -27,14 +30,19 @@ const PreferencesUserPresenceSection = () => {
</FieldRow>
</Field>
<Field>
<FieldLabel htmlFor={idleTimeLimit}>{t('Idle_Time_Limit')}</FieldLabel>
<FieldLabel htmlFor={idleTimeLimitH}>{t('Idle_Time_Limit')}</FieldLabel>
Copy link
Contributor

Choose a reason for hiding this comment

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

don't you have access to a OnChange callback or smth?
so you can update idleTimeLimit without needing to have 3 separate settings

<FieldRow>
<NumberInput id={idleTimeLimit} {...register('idleTimeLimit')} />
<FieldLabel htmlFor="idleTimeLimitH">{t('hours')} </FieldLabel>
<NumberInput id={idleTimeLimitH} {...register('idleTimeLimitH')} />
<FieldLabel htmlFor="idleTimeLimitM">{t('minutes')} </FieldLabel>
<NumberInput id={idleTimeLimitM} {...register('idleTimeLimitM')} max={59} min={0} />
<FieldLabel htmlFor="idleTimeLimitS">{t('seconds')} </FieldLabel>
<NumberInput id={idleTimeLimitS} {...register('idleTimeLimitS')} max={59} min={0} />
</FieldRow>
</Field>
</FieldGroup>
</Accordion.Item>
);
};

export default PreferencesUserPresenceSection;
export default PreferencesUserPresenceSection;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export type AccountPreferencesData = {
language?: string;
dontAskAgainList?: string[];
enableAutoAway?: boolean;
idleTimeLimit?: number;
idleTimeLimitH?: number;
idleTimeLimitM?: number;
idleTimeLimitS?: number;
desktopNotificationRequireInteraction?: boolean;
desktopNotifications?: string;
pushNotifications?: string;
Expand Down Expand Up @@ -43,8 +45,10 @@ export const useAccountPreferencesValues = (): AccountPreferencesData => {
const userDontAskAgainList = useUserPreference<{ action: string; label: string }[]>('dontAskAgainList') || [];
const dontAskAgainList = userDontAskAgainList.map(({ action }) => action);
const enableAutoAway = useUserPreference<boolean>('enableAutoAway');
const idleTimeLimit = useUserPreference<number>('idleTimeLimit');

const idleTimeLimitH = useUserPreference<number>('idleTimeLimitH');
thepiyush-303 marked this conversation as resolved.
Show resolved Hide resolved
const idleTimeLimitM = useUserPreference<number>('idleTimeLimitM');
const idleTimeLimitS = useUserPreference<number>('idleTimeLimitS');

const desktopNotificationRequireInteraction = useUserPreference<boolean>('desktopNotificationRequireInteraction');
const desktopNotifications = useUserPreference<string>('desktopNotifications');
const pushNotifications = useUserPreference<string>('pushNotifications');
Expand Down Expand Up @@ -76,7 +80,9 @@ export const useAccountPreferencesValues = (): AccountPreferencesData => {
language,
dontAskAgainList,
enableAutoAway,
idleTimeLimit,
idleTimeLimitH,
idleTimeLimitM,
idleTimeLimitS,
desktopNotificationRequireInteraction,
desktopNotifications,
pushNotifications,
Expand Down
13 changes: 11 additions & 2 deletions apps/meteor/server/methods/saveUserPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type UserPreferences = {
hideFlexTab: boolean;
sendOnEnter: string;
idleTimeLimit: number;
idleTimeLimitH: number;
idleTimeLimitM: number;
idleTimeLimitS: number;
sidebarShowFavorites: boolean;
sidebarShowUnread: boolean;
sidebarSortby: string;
Expand Down Expand Up @@ -107,6 +110,9 @@ export const saveUserPreferences = async (settings: Partial<UserPreferences>, us
displayAvatars: Match.Optional(Boolean),
hideFlexTab: Match.Optional(Boolean),
sendOnEnter: Match.Optional(String),
idleTimeLimitH: Match.Optional(Number),
idleTimeLimitM: Match.Optional(Number),
idleTimeLimitS: Match.Optional(Number),
idleTimeLimit: Match.Optional(Number),
sidebarShowFavorites: Match.Optional(Boolean),
sidebarShowUnread: Match.Optional(Boolean),
Expand Down Expand Up @@ -153,10 +159,13 @@ export const saveUserPreferences = async (settings: Partial<UserPreferences>, us
settings.emailNotificationMode = 'nothing';
}

if (settings.idleTimeLimit != null && settings.idleTimeLimit < 60) {
throw new Meteor.Error('invalid-idle-time-limit-value', 'Invalid idleTimeLimit');
const idleTimeLimit = (settings.idleTimeLimitH || 0) * 3600 + (settings.idleTimeLimitM || 0) * 60 + (settings.idleTimeLimitS || 0);
thepiyush-303 marked this conversation as resolved.
Show resolved Hide resolved

if (settings.idleTimeLimit != null && idleTimeLimit < 60) {
throw new Meteor.Error('invalid-idle-time-limit-value', 'Idle time limit must be at least 1 minutes.');
}


await Users.setPreferences(user._id, settings);

const diff = (Object.keys(settings) as (keyof UserPreferences)[]).reduce<Record<string, any>>((data, key) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/server/settings/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,4 +867,4 @@ export const createAccountSettings = () =>
i18nDescription: 'Password_History_Amount_Description',
});
});
});
});
14 changes: 12 additions & 2 deletions packages/rest-typings/src/v1/users/UsersSetPreferenceParamsPOST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export type UsersSetPreferencesParamsPOST = {
fontSize?: FontSize;
receiveLoginDetectionEmail?: boolean;
notifyCalendarEvents?: boolean;
idleTimeLimit?: number;
idleTimeLimitH?: number;
idleTimeLimitM?: number;
idleTimeLimitS?: number;
omnichannelTranscriptEmail?: boolean;
omnichannelTranscriptPDF?: boolean;
omnichannelHideConversationAfterClosing?: boolean;
Expand Down Expand Up @@ -231,7 +233,15 @@ const UsersSetPreferencesParamsPostSchema = {
type: 'boolean',
nullable: true,
},
idleTimeLimit: {
idleTimeLimitH: {
type: 'number',
nullable: true,
},
idleTimeLimitM: {
type: 'number',
nullable: true,
},
idleTimeLimitS: {
type: 'number',
nullable: true,
},
Expand Down