Skip to content

Commit

Permalink
Merge branch 'develop' into fix/action-menu-overflow-in-moderation-page
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Dec 4, 2024
2 parents 43224d5 + f8ecbd7 commit b3572bf
Show file tree
Hide file tree
Showing 19 changed files with 130 additions and 252 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-mangos-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixed an issue that caused clients to not properly receive certain server notifications right after login
5 changes: 5 additions & 0 deletions .changeset/selfish-fishes-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

fixes mail export form "To additional emails" field validation
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ declare module '@rocket.chat/ddp-client' {
}

Meteor.methods<ServerMethods>({
// eslint-disable-next-line complexity
async updateIncomingIntegration(integrationId, integration) {
if (!this.userId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
Expand Down Expand Up @@ -175,6 +176,7 @@ Meteor.methods<ServerMethods>({
emoji: integration.emoji,
alias: integration.alias,
channel: channels,
...('username' in integration && { username: integration.username }),
...(isFrozen
? {}
: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import type { IMessage } from '@rocket.chat/core-typings';
import { useToastMessageDispatch } from '@rocket.chat/ui-contexts';
import { useEndpoint, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
import { useQueryClient, useMutation } from '@tanstack/react-query';
import { useTranslation } from 'react-i18next';

import { sdk } from '../../../../app/utils/client/lib/SDKClient';
import { updatePinMessage } from '../../../lib/mutationEffects/updatePinMessage';
import { roomsQueryKeys } from '../../../lib/queryKeys';

export const usePinMessageMutation = () => {
const { t } = useTranslation();
const pinMessageEndpoint = useEndpoint('POST', '/v1/chat.pinMessage');
const dispatchToastMessage = useToastMessageDispatch();

const queryClient = useQueryClient();

return useMutation({
mutationFn: async (message: IMessage) => {
await sdk.call('pinMessage', message);
mutationFn: async (message: IMessage) => pinMessageEndpoint({ messageId: message._id }),
onMutate: (message) => {
updatePinMessage(message, { pinned: true });
},
onSuccess: (_data) => {
dispatchToastMessage({ type: 'success', message: t('Message_has_been_pinned') });
},
onError: (error) => {
onError: (error, message) => {
dispatchToastMessage({ type: 'error', message: error });
updatePinMessage(message, { pinned: false });
},
onSettled: (_data, _error, message) => {
queryClient.invalidateQueries(roomsQueryKeys.pinnedMessages(message.rid));
Expand Down
23 changes: 22 additions & 1 deletion apps/meteor/client/components/message/toolbar/MessageToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import type { IMessage, IRoom, ISubscription, ITranslatedMessage } from '@rocket
import { isThreadMessage, isRoomFederated, isVideoConfMessage, isE2EEMessage } from '@rocket.chat/core-typings';
import { MessageToolbar as FuselageMessageToolbar, MessageToolbarItem } from '@rocket.chat/fuselage';
import { useFeaturePreview } from '@rocket.chat/ui-client';
import { useUser, useSettings, useTranslation, useMethod, useLayoutHiddenActions } from '@rocket.chat/ui-contexts';
import { useUser, useSettings, useTranslation, useMethod, useLayoutHiddenActions, useSetting } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import type { ComponentProps, ReactElement } from 'react';
import React, { memo, useMemo, useRef } from 'react';

import MessageActionMenu from './MessageActionMenu';
import MessageToolbarStarsActionMenu from './MessageToolbarStarsActionMenu';
import { useJumpToMessageContextAction } from './useJumpToMessageContextAction';
import { useNewDiscussionMessageAction } from './useNewDiscussionMessageAction';
import { usePermalinkStar } from './usePermalinkStar';
import { usePinMessageAction } from './usePinMessageAction';
Expand Down Expand Up @@ -88,6 +89,7 @@ const MessageToolbar = ({
const starsAction = useMessageActionAppsActionButtons(context, 'ai');

const { messageToolbox: hiddenActions } = useLayoutHiddenActions();
const allowStarring = useSetting('Message_AllowStarring');

// TODO: move this to another place
useWebDAVMessageAction();
Expand All @@ -97,6 +99,25 @@ const MessageToolbar = ({
useUnstarMessageAction(message, { room, user });
usePermalinkStar(message, { subscription, user });

useJumpToMessageContextAction(message, {
id: 'jump-to-message',
order: 100,
context: ['mentions', 'threads', 'videoconf-threads', 'message-mobile', 'search'],
});

useJumpToMessageContextAction(message, {
id: 'jump-to-pin-message',
order: 100,
hidden: !subscription,
context: ['pinned', 'direct'],
});
useJumpToMessageContextAction(message, {
id: 'jump-to-star-message',
hidden: !allowStarring || !subscription,
order: 100,
context: ['starred'],
});

const actionsQueryResult = useQuery({
queryKey: roomsQueryKeys.messageActionsWithParameters(room._id, message),
queryFn: async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { IMessage } from '@rocket.chat/core-typings';
import { useEffect } from 'react';

import type { MessageActionContext } from '../../../../app/ui-utils/client/lib/MessageAction';
import { MessageAction } from '../../../../app/ui-utils/client/lib/MessageAction';
import { setMessageJumpQueryStringParameter } from '../../../lib/utils/setMessageJumpQueryStringParameter';

export const useJumpToMessageContextAction = (
message: IMessage,
{ id, order, hidden, context }: { id: string; order: number; hidden?: boolean; context: MessageActionContext[] },
) => {
useEffect(() => {
if (hidden) {
return;
}

MessageAction.addButton({
id,
icon: 'jump',
label: 'Jump_to_message',
context,
async action() {
setMessageJumpQueryStringParameter(message._id);
},
order,
group: 'message',
});

return () => {
MessageAction.removeButton(id);
};
}, [hidden, context, id, message._id, order]);
};
2 changes: 1 addition & 1 deletion apps/meteor/client/lib/errors/NotAuthorizedError.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RocketChatError } from './RocketChatError';

export class NotAuthorizedError extends RocketChatError<'not-authorized'> {
constructor(message = 'Not authorized', details?: string) {
constructor(message = 'Not authorized', details?: unknown) {
super('not-authorized', message, details);
}
}
7 changes: 7 additions & 0 deletions apps/meteor/client/lib/errors/PinMessagesNotAllowed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { RocketChatError } from './RocketChatError';

export class PinMessagesNotAllowed extends RocketChatError<'error-pinning-message'> {
constructor(message = 'Pinning messages is not allowed', details?: unknown) {
super('error-pinning-message', message, details);
}
}
22 changes: 22 additions & 0 deletions apps/meteor/client/lib/mutationEffects/updatePinMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { IMessage } from '@rocket.chat/core-typings';

import { Messages } from '../../../app/models/client';
import { PinMessagesNotAllowed } from '../errors/PinMessagesNotAllowed';

export const updatePinMessage = (message: IMessage, data: Partial<IMessage>) => {
const msg = Messages.findOne({ _id: message._id });

if (!msg) {
throw new PinMessagesNotAllowed('Error pinning message', {
method: 'pinMessage',
});
}

Messages.update(
{
_id: message._id,
rid: message.rid,
},
{ $set: data },
);
};
24 changes: 23 additions & 1 deletion apps/meteor/client/meteorOverrides/ddpOverREST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,35 @@ const withDDPOverREST = (_send: (this: Meteor.IMeteorConnection, message: Meteor
sdk.rest
.post(`/v1/${endpoint}/${method}`, restParams)
.then(({ message: _message }) => {
processResult(_message);
// Calling Meteor.loginWithToken before processing the result of the first login will ensure that the new login request
// is added to the top of the list of methodInvokers.
// The request itself will only be sent after the first login result is processed, but
// the Accounts.onLogin callbacks will be called before this request is effectively sent;
// This way, any requests done inside of onLogin callbacks will be added to the list
// and processed only after the Meteor.loginWithToken request is done
// So, the effective order is:
// 1. regular login with password is sent
// 2. result of the password login is received
// 3. login with token is added to the list of pending requests
// 4. result of the password login is processed
// 5. Accounts.onLogin callbacks are triggered, Meteor.userId is set
// 6. the request for the login with token is effectively sent
// 7. login with token result is processed
// 8. requests initiated inside of the Accounts.onLogin callback are then finally sent
//
// Keep in mind that there's a difference in how meteor3 processes the request results, compared to older meteor versions
// On meteor3, any collection writes triggered by a request result are done async, which means that the `processResult` call
// will not immediatelly trigger the callbacks, like it used to in older versions.
// That means that on meteor3+, it doesn't really make a difference if processResult is called before or after the Meteor.loginWithToken here
// as the result will be processed async, the loginWithToken call will be initiated before it is effectively processed anyway.
if (message.method === 'login') {
const parsedMessage = DDPCommon.parseDDP(_message) as { result?: { token?: string } };
if (parsedMessage.result?.token) {
Meteor.loginWithToken(parsedMessage.result.token);
}
}

processResult(_message);
})
.catch((error) => {
console.error(error);
Expand Down
2 changes: 0 additions & 2 deletions apps/meteor/client/methods/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
import './openRoom';
import './pinMessage';
import './unpinMessage';
import './updateMessage';
53 changes: 0 additions & 53 deletions apps/meteor/client/methods/pinMessage.ts

This file was deleted.

97 changes: 0 additions & 97 deletions apps/meteor/client/methods/updateMessage.ts

This file was deleted.

4 changes: 0 additions & 4 deletions apps/meteor/client/startup/actionButtons/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
import './jumpToMessage';
import './jumpToPinMessage';
import './jumpToSearchMessage';
import './jumpToStarMessage';
import './permalinkPinned';
import './unpinMessage';
Loading

0 comments on commit b3572bf

Please sign in to comment.