Skip to content
Merged
61 changes: 42 additions & 19 deletions src/injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,16 @@ const start = async () => {
version1: string,
version2: string
): boolean {
const v1 = version1.match(/\d+/g)?.map(Number) || [];
const v2 = version2.match(/\d+/g)?.map(Number) || [];
// Extract only the core version number (before any suffix like -develop, -rc, etc.)
const cleanVersion1 = version1.split('-')[0];
const cleanVersion2 = version2.split('-')[0];

for (let i = 0; i < 3; i++) {
const v1 = cleanVersion1.split('.').map(Number);
const v2 = cleanVersion2.split('.').map(Number);

// Compare each version part
const maxLength = Math.max(v1.length, v2.length);
for (let i = 0; i < maxLength; i++) {
const n1 = v1[i] || 0;
const n2 = v2[i] || 0;

Expand All @@ -78,7 +84,7 @@ const start = async () => {
}
}

return true;
return true; // Equal versions
}

const userPresenceModulePath = versionIsGreaterOrEqualsTo(
Expand Down Expand Up @@ -164,27 +170,44 @@ const start = async () => {
});
}

Tracker.autorun(() => {
// Helper function to get Outlook settings based on server version
const getOutlookSettings = () => {
const userToken = Meteor._localStorage.getItem('Meteor.loginToken');
const userId = Meteor.userId();
const outlookCalendarEnabled = settings.get('Outlook_Calendar_Enabled');
const outlookExchangeUrl = settings.get('Outlook_Calendar_Exchange_Url');
if (!userToken || !userId || !outlookCalendarEnabled || !outlookExchangeUrl)
return;
window.RocketChatDesktop.setUserToken(userToken, userId);

window.RocketChatDesktop.setOutlookExchangeUrl(outlookExchangeUrl, userId);
});
if (!versionIsGreaterOrEqualsTo(serverInfo.version, '7.8.0')) {
// Pre-7.8.0: Use global server settings
return {
userToken,
userId: Meteor.userId(),
outlookCalendarEnabled: settings.get('Outlook_Calendar_Enabled'),
outlookExchangeUrl: settings.get('Outlook_Calendar_Exchange_Url'),
};
}
// 7.8.0+: Use user-specific settings
const user = Meteor.user();
const outlookSettings = user?.settings?.calendar?.outlook;
return {
userToken,
userId: user?._id,
outlookCalendarEnabled: outlookSettings?.Enabled,
outlookExchangeUrl: outlookSettings?.Exchange_Url,
};
};

Tracker.autorun(() => {
const userToken = Meteor._localStorage.getItem('Meteor.loginToken');
const userId = Meteor.userId();
const outlookCalendarEnabled = settings.get('Outlook_Calendar_Enabled');
const outlookExchangeUrl = settings.get('Outlook_Calendar_Exchange_Url');
if (!userToken || !userId || !outlookCalendarEnabled || !outlookExchangeUrl)
const { userToken, userId, outlookCalendarEnabled, outlookExchangeUrl } =
getOutlookSettings();

if (
!userToken ||
!userId ||
!outlookCalendarEnabled ||
!outlookExchangeUrl
) {
return;
window.RocketChatDesktop.setUserToken(userToken, userId);
}

window.RocketChatDesktop.setUserToken(userToken, userId);
window.RocketChatDesktop.setOutlookExchangeUrl(outlookExchangeUrl, userId);
});

Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/OutlookCredentialsDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const OutlookCredentialsDialog = () => {
formState: { errors, isSubmitting },
} = useForm<AuthPayload>({
mode: 'onChange',
defaultValues: { rememberCredentials: false },
defaultValues: { rememberCredentials: true },
});

const { rememberCredentials } = watch();
Expand Down
3 changes: 3 additions & 0 deletions src/ui/components/SideBar/ServerButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type ServerButtonProps = {
onDragEnd: (event: DragEvent) => void;
onDragEnter: (event: DragEvent) => void;
onDrop: (event: DragEvent) => void;
exchangeUrl?: string;
};

type ServerActionType =
Expand All @@ -74,6 +75,7 @@ const ServerButton = ({
isSupportedVersion,
supportedVersionsSource,
supportedVersions,
exchangeUrl,
onDragStart,
onDragEnd,
onDragEnter,
Expand Down Expand Up @@ -261,6 +263,7 @@ const ServerButton = ({
target={serverInfoTarget}
url={url}
version={version}
exchangeUrl={exchangeUrl}
supportedVersions={supportedVersions}
isSupportedVersion={isSupportedVersion}
supportedVersionsSource={supportedVersionsSource}
Expand Down
26 changes: 26 additions & 0 deletions src/ui/components/SideBar/ServerInfoDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type ServerInfoDropdownProps = {
target: RefObject<HTMLElement>;
url: string;
version?: string;
exchangeUrl?: string;
isSupportedVersion?: boolean;
supportedVersionsSource?: 'server' | 'cloud' | 'builtin';
supportedVersions?: SupportedVersions;
Expand All @@ -34,6 +35,7 @@ const ServerInfoDropdown = ({
target,
url,
version,
exchangeUrl,
isSupportedVersion,
supportedVersionsSource,
supportedVersions,
Expand Down Expand Up @@ -144,6 +146,30 @@ const ServerInfoDropdown = ({
</Box>
</OptionContent>
</Option>
{exchangeUrl && (
<Option>
<OptionIcon name='mail' />
<OptionContent style={{ minWidth: 0, overflow: 'visible' }}>
<Box>
<Box fontWeight='bold'>Outlook Exchange URL:</Box>
<Box
fontSize='x12'
color='hint'
style={{
wordBreak: 'break-word',
overflowWrap: 'break-word',
whiteSpace: 'normal',
lineHeight: '1.4',
hyphens: 'auto',
maxWidth: '100%',
}}
>
{exchangeUrl}
</Box>
</Box>
</OptionContent>
</Option>
)}
{supportedVersions && (
<>
<OptionDivider />
Expand Down
1 change: 1 addition & 0 deletions src/ui/components/SideBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export const SideBar = () => {
isSupportedVersion={server.isSupportedVersion}
supportedVersionsSource={server.supportedVersionsSource}
supportedVersions={server.supportedVersions}
exchangeUrl={server.outlookCredentials?.serverUrl}
isShortcutVisible={isEachShortcutVisible}
onDragStart={handleDragStart(server.url)}
onDragEnd={handleDragEnd}
Expand Down