Skip to content

Commit

Permalink
Merge branch 'develop' into fix/twitter-link-oembed-image
Browse files Browse the repository at this point in the history
  • Loading branch information
scuciatto authored Dec 17, 2024
2 parents 6643f4f + e2d286c commit 3acb2c9
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 60 deletions.
6 changes: 6 additions & 0 deletions .changeset/empty-pans-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/i18n": patch
---

Fixes the incorrect registration status shown on admin users page for federated remote users.
5 changes: 5 additions & 0 deletions .changeset/seven-owls-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed an issue that added potencially infinite callbacks to the same event, degrading performance over time.
98 changes: 44 additions & 54 deletions apps/meteor/client/hooks/useNotifyUser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AtLeast, ISubscription } from '@rocket.chat/core-typings';
import type { AtLeast, INotificationDesktop, ISubscription } from '@rocket.chat/core-typings';
import { useEffectEvent } from '@rocket.chat/fuselage-hooks';
import { useRouter, useStream, useUser, useUserPreference } from '@rocket.chat/ui-contexts';
import { useCallback, useEffect } from 'react';
import { useEffect } from 'react';

import { useEmbeddedLayout } from './useEmbeddedLayout';
import { CachedChatSubscription } from '../../app/models/client';
Expand All @@ -15,79 +16,68 @@ export const useNotifyUser = () => {
const notifyUserStream = useStream('notify-user');
const muteFocusedConversations = useUserPreference('muteFocusedConversations');

const notifyNewRoom = useCallback(
async (sub: AtLeast<ISubscription, 'rid'>): Promise<void> => {
if (!user || user.status === 'busy') {
return;
}
const notifyNewRoom = useEffectEvent(async (sub: AtLeast<ISubscription, 'rid'>): Promise<void> => {
if (!user || user.status === 'busy') {
return;
}

if ((!router.getRouteParameters().name || router.getRouteParameters().name !== sub.name) && !sub.ls && sub.alert === true) {
KonchatNotification.newRoom(sub.rid);
}
},
[router, user],
);
if ((!router.getRouteParameters().name || router.getRouteParameters().name !== sub.name) && !sub.ls && sub.alert === true) {
KonchatNotification.newRoom(sub.rid);
}
});

const notifyNewMessageAudioAndDesktop = useEffectEvent((notification: INotificationDesktop) => {
const hasFocus = document.hasFocus();

const openedRoomId = ['channel', 'group', 'direct'].includes(router.getRouteName() || '') ? RoomManager.opened : undefined;

const { rid } = notification.payload;
const messageIsInOpenedRoom = openedRoomId === rid;

const notifyNewMessageAudio = useCallback(
(rid?: string) => {
const hasFocus = document.hasFocus();
const messageIsInOpenedRoom = RoomManager.opened === rid;
fireGlobalEvent('notification', {
notification,
fromOpenedRoom: messageIsInOpenedRoom,
hasFocus,
});

if (isLayoutEmbedded) {
if (!hasFocus && messageIsInOpenedRoom) {
// Play a notification sound
void KonchatNotification.newMessage(rid);
}
} else if (!hasFocus || !messageIsInOpenedRoom || !muteFocusedConversations) {
if (isLayoutEmbedded) {
if (!hasFocus && messageIsInOpenedRoom) {
// Play a notification sound
void KonchatNotification.newMessage(rid);
void KonchatNotification.showDesktop(notification);
}
},
[isLayoutEmbedded, muteFocusedConversations],
);
} else if (!hasFocus || !messageIsInOpenedRoom || !muteFocusedConversations) {
// Play a notification sound
void KonchatNotification.newMessage(rid);
void KonchatNotification.showDesktop(notification);
}
});

useEffect(() => {
if (!user?._id) {
return;
}

notifyUserStream(`${user?._id}/notification`, (notification) => {
const openedRoomId = ['channel', 'group', 'direct'].includes(router.getRouteName() || '') ? RoomManager.opened : undefined;

const hasFocus = document.hasFocus();
const messageIsInOpenedRoom = openedRoomId === notification.payload.rid;
const unsubNotification = notifyUserStream(`${user._id}/notification`, notifyNewMessageAudioAndDesktop);

fireGlobalEvent('notification', {
notification,
fromOpenedRoom: messageIsInOpenedRoom,
hasFocus,
});

if (isLayoutEmbedded) {
if (!hasFocus && messageIsInOpenedRoom) {
// Show a notification.
KonchatNotification.showDesktop(notification);
}
} else if (!hasFocus || !messageIsInOpenedRoom) {
// Show a notification.
KonchatNotification.showDesktop(notification);
}

notifyNewMessageAudio(notification.payload.rid);
});

notifyUserStream(`${user?._id}/subscriptions-changed`, (action, sub) => {
if (action === 'removed') {
const unsubSubs = notifyUserStream(`${user._id}/subscriptions-changed`, (action, sub) => {
if (action !== 'inserted') {
return;
}

void notifyNewRoom(sub);
});

CachedChatSubscription.collection.find().observe({
const handle = CachedChatSubscription.collection.find().observe({
changed: (sub) => {
void notifyNewRoom(sub);
},
});
}, [isLayoutEmbedded, notifyNewMessageAudio, notifyNewRoom, notifyUserStream, router, user?._id]);

return () => {
unsubNotification();
unsubSubs();
handle.stop();
};
}, [isLayoutEmbedded, notifyNewMessageAudioAndDesktop, notifyNewRoom, notifyUserStream, router, user?._id]);
};
30 changes: 24 additions & 6 deletions apps/meteor/client/views/admin/users/UsersTable/UsersTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,40 @@ const UsersTableRow = ({
}: UsersTableRowProps): ReactElement => {
const { t } = useTranslation();

const { _id, emails, username = '', name = '', roles, status, active, avatarETag, lastLogin, type, freeSwitchExtension } = user;
const {
_id,
emails,
username = '',
name = '',
roles,
status,
active,
avatarETag,
lastLogin,
type,
freeSwitchExtension,
federated,
} = user;

const registrationStatusText = useMemo(() => {
const usersExcludedFromPending = ['bot', 'app'];

if (!active && lastLogin) {
return t('Deactivated');
}

if (federated) {
return t('Federated');
}

if (!lastLogin && !usersExcludedFromPending.includes(type)) {
return t('Pending');
}

if (active && lastLogin) {
return t('Active');
}

if (!active && lastLogin) {
return t('Deactivated');
}
}, [active, lastLogin, t, type]);
}, [active, lastLogin, t, type, federated]);

const roleNames = (roles || [])
.map((roleId) => (Roles.findOne(roleId, { fields: { name: 1 } }) as IRole | undefined)?.name)
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/locales/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2428,6 +2428,7 @@
"Federation_Matrix_serve_well_known_Alert": "Keep this off if using DNS srv records for federation, or use a reverse proxy to return static JSON if federation traffic is heavy. <a target=\"_blank\" href=\"https://matrix-org.github.io/synapse/latest/federate.html\">Read mode</a>.",
"Federation_Matrix_check_configuration": "Verify configuration",
"Federation_Matrix_configuration_status": "Configuration status",
"Federated": "Federated",
"Field": "Field",
"Field_removed": "Field removed",
"Field_required": "Field required",
Expand Down

0 comments on commit 3acb2c9

Please sign in to comment.