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

fix: user presence import #2656

Merged
merged 2 commits into from
May 5, 2023
Merged
Changes from all 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
33 changes: 31 additions & 2 deletions src/injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,46 @@ const start = (): void => {

window.RocketChatDesktop.setServerInfo(serverInfo);

function versionIsGreaterOrEqualsTo(
version1: string,
version2: string
): boolean {
const v1 = version1.match(/\d+/g)?.map(Number) || [];
const v2 = version2.match(/\d+/g)?.map(Number) || [];

for (let i = 0; i < 3; i++) {
const n1 = v1[i] || 0;
const n2 = v2[i] || 0;

if (n1 > n2) {
return true;
}
if (n1 < n2) {
return false;
}
}

return true;
}

function requireLegacyLibrary(path: string): any {
if (serverInfo.version.split('.')[0] >= 6) {
if (versionIsGreaterOrEqualsTo(serverInfo.version, '6.0.0')) {
path += '/client/index.ts';
}
return window.require(path);
}

const userPresenceRequire: string = versionIsGreaterOrEqualsTo(
serverInfo.version,
'6.3.0'
)
? 'meteor/rocketchat:user-presence'
: 'meteor/konecty:user-presence';

const { Meteor } = window.require('meteor/meteor');
const { Session } = window.require('meteor/session');
const { Tracker } = window.require('meteor/tracker');
const { UserPresence } = window.require('meteor/konecty:user-presence');
const { UserPresence } = window.require(userPresenceRequire);
const { settings } = requireLegacyLibrary('/app/settings');
const { getUserPreference } = requireLegacyLibrary('/app/utils');

Expand Down