-
Notifications
You must be signed in to change notification settings - Fork 11.7k
refactor: remove startup from Meteor #35915
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import type { UserStatus } from '@rocket.chat/core-typings'; | ||
import { useUserId } from '@rocket.chat/ui-contexts'; | ||
import { Meteor } from 'meteor/meteor'; | ||
import { UserPresence } from 'meteor/rocketchat:user-presence'; | ||
import { Session } from 'meteor/session'; | ||
import moment from 'moment'; | ||
import { useState, useEffect } from 'react'; | ||
|
||
import { getUserPreference } from '../../app/utils/client'; | ||
import { sdk } from '../../app/utils/client/lib/SDKClient'; | ||
import { synchronizeUserData, removeLocalUserData } from '../lib/userData'; | ||
import { fireGlobalEvent } from '../lib/utils/fireGlobalEvent'; | ||
|
||
export const useStartup = () => { | ||
const [status, setStatus] = useState<UserStatus | undefined>(undefined); | ||
const uid = useUserId(); | ||
|
||
useEffect(() => { | ||
if (!uid) { | ||
removeLocalUserData(); | ||
return; | ||
} | ||
|
||
if (!Meteor.status().connected) { | ||
return; | ||
} | ||
|
||
if (Meteor.loggingIn()) { | ||
return; | ||
} | ||
|
||
const getUser = async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const getUser = async () => {
try {
const utcOffset = moment().utcOffset() / 60;
const user = await synchronizeUserData(uid);
if (!user) {
console.error('User data synchronization failed.'); // Or handle more gracefully
return;
}
if (user.utcOffset !== utcOffset) {
await sdk.call('userSetUtcOffset', utcOffset);
}
if (getUserPreference(user, 'enableAutoAway')) {
const idleTimeLimit = (getUserPreference(user, 'idleTimeLimit') as number | null | undefined) || 300;
UserPresence.awayTime = idleTimeLimit * 1000;
} else {
delete UserPresence.awayTime;
UserPresence.stopTimer();
}
setStatus(user.status);
UserPresence.start();
} catch (error) {
console.error('Error during user startup sequence:', error);
// Potentially set an error state or notify the user
}
}; The This issue appears in multiple locations:
Talk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction. |
||
const utcOffset = moment().utcOffset() / 60; | ||
const user = await synchronizeUserData(uid); | ||
if (!user) { | ||
return; | ||
} | ||
if (user.utcOffset !== utcOffset) { | ||
sdk.call('userSetUtcOffset', utcOffset); | ||
} | ||
|
||
if (getUserPreference(user, 'enableAutoAway')) { | ||
const idleTimeLimit = (getUserPreference(user, 'idleTimeLimit') as number | null | undefined) || 300; | ||
UserPresence.awayTime = idleTimeLimit * 1000; | ||
} else { | ||
delete UserPresence.awayTime; | ||
UserPresence.stopTimer(); | ||
} | ||
|
||
setStatus(user.status); | ||
UserPresence.start(); | ||
}; | ||
getUser(); | ||
}, [uid]); | ||
|
||
useEffect(() => { | ||
fireGlobalEvent('startup', true); | ||
Session.setDefault('AvatarRandom', 0); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (status) { | ||
fireGlobalEvent('status-changed', status); | ||
} | ||
}, [status]); | ||
}; |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
useStartup
hook lacks proper documentation, making it difficult to understand its purpose and usage.This issue appears in multiple locations:
Please add JSDoc comments to the
useStartup
hook to clearly explain its functionality and any side effects.Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.