Skip to content

Commit

Permalink
Merge branch 'develop' into fix-incorrect-cache-set
Browse files Browse the repository at this point in the history
  • Loading branch information
debdutdeb committed Jul 19, 2024
2 parents c12b7a2 + 47819cd commit 8e09b4d
Show file tree
Hide file tree
Showing 62 changed files with 518 additions and 468 deletions.
5 changes: 0 additions & 5 deletions .changeset/cuddly-ravens-swim.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/funny-wolves-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixed issue where bad word filtering was not working in the UI for messages
5 changes: 5 additions & 0 deletions .changeset/lucky-countries-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixed the disappearance of some settings after navigation under network latency.
5 changes: 5 additions & 0 deletions .changeset/thin-windows-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixes an issue not displaying all groups in settings list
5 changes: 5 additions & 0 deletions .changeset/violet-brooms-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Security Hotfix (https://docs.rocket.chat/guides/security/security-updates)
13 changes: 13 additions & 0 deletions .changeset/witty-bats-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/apps": patch
"@rocket.chat/core-services": patch
"@rocket.chat/core-typings": patch
"@rocket.chat/fuselage-ui-kit": patch
"@rocket.chat/rest-typings": patch
"@rocket.chat/ddp-streamer": patch
"@rocket.chat/presence": patch
"rocketchat-services": patch
---

Added the `user` param to apps-engine update method call, allowing apps' new `onUpdate` hook to know who triggered the update.
17 changes: 17 additions & 0 deletions apps/meteor/app/apps/server/converters/cachedFunction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const cachedFunction = <F extends (...args: any[]) => any>(fn: F) => {
const cache = new Map<string, unknown>();

return ((...args) => {
const cacheKey = JSON.stringify(args);

if (cache.has(cacheKey)) {
return cache.get(cacheKey) as ReturnType<F>;
}

const result = fn(...args);

cache.set(cacheKey, result);

return result;
}) as F;
};
18 changes: 15 additions & 3 deletions apps/meteor/app/apps/server/converters/messages.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Messages, Rooms, Users } from '@rocket.chat/models';
import { Random } from '@rocket.chat/random';

import { cachedFunction } from './cachedFunction';
import { transformMappedData } from './transformMappedData';

export class AppMessagesConverter {
mem = new WeakMap();

constructor(orch) {
this.orch = orch;
}
Expand All @@ -19,6 +22,15 @@ export class AppMessagesConverter {
return undefined;
}

const cache =
this.mem.get(msgObj) ??
new Map([
['room', cachedFunction(this.orch.getConverters().get('rooms').convertById.bind(this.orch.getConverters().get('rooms')))],
['user', cachedFunction(this.orch.getConverters().get('users').convertById.bind(this.orch.getConverters().get('users')))],
]);

this.mem.set(msgObj, cache);

const map = {
id: '_id',
threadId: 'tmid',
Expand All @@ -37,7 +49,7 @@ export class AppMessagesConverter {
token: 'token',
blocks: 'blocks',
room: async (message) => {
const result = await this.orch.getConverters().get('rooms').convertById(message.rid);
const result = await cache.get('room')(message.rid);
delete message.rid;
return result;
},
Expand All @@ -49,7 +61,7 @@ export class AppMessagesConverter {
return undefined;
}

return this.orch.getConverters().get('users').convertById(editedBy._id);
return cache.get('user')(editedBy._id);
},
attachments: async (message) => {
const result = await this._convertAttachmentsToApp(message.attachments);
Expand All @@ -61,7 +73,7 @@ export class AppMessagesConverter {
return undefined;
}

let user = await this.orch.getConverters().get('users').convertById(message.u._id);
let user = await cache.get('user')(message.u._id);

// When the sender of the message is a Guest (livechat) and not a user
if (!user) {
Expand Down
19 changes: 1 addition & 18 deletions apps/meteor/app/apps/server/converters/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { IUser } from '@rocket.chat/core-typings';
import { isEditedMessage, type IMessage } from '@rocket.chat/core-typings';
import { Messages } from '@rocket.chat/models';

import { cachedFunction } from './cachedFunction';
import { transformMappedData } from './transformMappedData';

// eslint-disable-next-line @typescript-eslint/naming-convention
Expand All @@ -18,24 +19,6 @@ interface Orchestrator {
};
}

const cachedFunction = <F extends (...args: any[]) => any>(fn: F) => {
const cache = new Map<string, unknown>();

return ((...args) => {
const cacheKey = JSON.stringify(args);

if (cache.has(cacheKey)) {
return cache.get(cacheKey) as ReturnType<F>;
}

const result = fn(...args);

cache.set(cacheKey, result);

return result;
}) as F;
};

export class AppThreadsConverter implements IAppThreadsConverter {
constructor(
private readonly orch: {
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/app/discussion/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
// Other UI extensions
import './lib/messageTypes/discussionMessage';
import './createDiscussionMessageAction';

This file was deleted.

2 changes: 1 addition & 1 deletion apps/meteor/app/e2e/client/rocketchat.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class E2E extends Emitter {
delete this.instancesByRoomId[rid];
}

async persistKeys(
private async persistKeys(
{ public_key, private_key }: KeyPair,
password: string,
{ force }: { force: boolean } = { force: false },
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/app/settings/server/SettingsRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ export class SettingsRegistry {
const settingFromCodeOverwritten = overwriteSetting(settingFromCode);

const settingStored = this.store.getSetting(_id);

const settingStoredOverwritten = settingStored && overwriteSetting(settingStored);

try {
Expand Down
2 changes: 0 additions & 2 deletions apps/meteor/app/ui-utils/lib/MessageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export type MessageType = {
id: MessageTypesValues;
system?: boolean;
/* deprecated */
render?: (message: IMessage) => string;
/* deprecated */
template?: (message: IMessage) => unknown;
message: TranslationKey;
data?: (message: IMessage) => Record<string, string>;
Expand Down
3 changes: 0 additions & 3 deletions apps/meteor/app/ui-utils/server/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ export const Message = {
parse(msg: IMessage, language: string) {
const messageType = MessageTypes.getType(msg);
if (messageType) {
if (messageType.render) {
return messageType.render(msg);
}
if (messageType.template) {
// Render message
return;
Expand Down
13 changes: 1 addition & 12 deletions apps/meteor/client/components/Page/PageScrollableContent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { css } from '@rocket.chat/css-in-js';
import type { Scrollable } from '@rocket.chat/fuselage';
import { Box } from '@rocket.chat/fuselage';
import type { ComponentProps } from 'react';
Expand Down Expand Up @@ -26,17 +25,7 @@ const PageScrollableContent = forwardRef<HTMLElement, PageScrollableContentProps
borderBlockEndColor={borderBlockEndColor}
>
<CustomScrollbars onScroll={onScrollContent as CustomScrollbarsProps['onScroll']} ref={ref}>
<Box
className={css`
transform: translateZ(0);
`}
height='100%'
paddingBlock={16}
paddingInline={24}
display='flex'
flexDirection='column'
{...props}
/>
<Box paddingBlock={16} paddingInline={24} display='flex' flexDirection='column' {...props} />
</CustomScrollbars>
</Box>
);
Expand Down
11 changes: 3 additions & 8 deletions apps/meteor/client/components/message/variants/SystemMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,9 @@ const SystemMessage = ({ message, showUserAvatar, ...props }: SystemMessageProps
)}
</MessageNameContainer>
{messageType && (
<MessageSystemBody
data-qa-type='system-message-body'
dangerouslySetInnerHTML={{
__html: messageType.render
? messageType.render(message)
: t(messageType.message, messageType.data ? messageType.data(message) : {}),
}}
/>
<MessageSystemBody data-qa-type='system-message-body'>
{t(messageType.message, messageType.data ? messageType.data(message) : {})}
</MessageSystemBody>
)}
<MessageSystemTimestamp title={formatDateAndTime(message.ts)}>{formatTime(message.ts)}</MessageSystemTimestamp>
</MessageSystemBlock>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PrivateSettingsCachedCollection extends CachedCollection<ISetting> {
async setupListener(): Promise<void> {
sdk.stream('notify-logged', [this.eventName as 'private-settings-changed'], async (t: string, { _id, ...record }: { _id: string }) => {
this.log('record received', t, { _id, ...record });
this.collection.upsert({ _id }, record);
this.collection.update({ _id }, { $set: record }, { upsert: true });
this.sync();
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,55 @@
import { css } from '@rocket.chat/css-in-js';
import { Box, Button, ButtonGroup } from '@rocket.chat/fuselage';
import { useToggle } from '@rocket.chat/fuselage-hooks';
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ReactElement, ReactNode } from 'react';
import React from 'react';
import { createPortal } from 'react-dom';

const CodeMirrorBox = ({ label, children }: { label: ReactNode; children: ReactElement }) => {
const t = useTranslation();
const [fullScreen, toggleFullScreen] = useToggle(false);

const fullScreenStyle = css`
position: fixed;
z-index: 100;
top: 0;
right: 0;
bottom: 0;
left: 0;
display: flex;
flex-direction: column;
width: auto;
height: auto;
padding: 40px;
align-items: stretch;
`;

return (
<Box
backgroundColor='light'
className={['code-mirror-box', fullScreen && 'code-mirror-box-fullscreen', fullScreen && fullScreenStyle].filter(Boolean)}
>
{fullScreen && (
if (fullScreen) {
return createPortal(
<Box
className='code-mirror-box code-mirror-box-fullscreen'
color='default'
backgroundColor='light'
position='absolute'
zIndex={100}
display='flex'
flexDirection='column'
width='100%'
height='100%'
p={40}
>
<Box fontScale='p1' mbe={4}>
{label}
</Box>
)}
<Box display='flex' flexDirection='column' height='100%' role='code' aria-label={typeof label === 'string' ? label : undefined}>
{children}
</Box>
<Box mbs={8}>
<ButtonGroup>
<Button primary onClick={(): void => toggleFullScreen()}>
{t('Exit_Full_Screen')}
</Button>
</ButtonGroup>
</Box>
</Box>,
document.getElementById('main-content') as HTMLElement,
);
}

return (
<Box className='code-mirror-box'>
<Box display='flex' flexDirection='column' height='100%' role='code' aria-label={typeof label === 'string' ? label : undefined}>
{children}
</Box>
<Box mbs={8}>
<ButtonGroup>
<Button primary onClick={(): void => toggleFullScreen()}>
{fullScreen ? t('Exit_Full_Screen') : t('Full_Screen')}
{t('Full_Screen')}
</Button>
</ButtonGroup>
</Box>
Expand Down
7 changes: 6 additions & 1 deletion apps/meteor/ee/server/apps/communication/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,12 @@ export class AppsRestApi {
return API.v1.internalError('private_app_install_disabled');
}

const aff = await manager.update(buff, permissionsGranted);
const user = orchestrator
?.getConverters()
?.get('users')
?.convertToApp(await Meteor.userAsync());

const aff = await manager.update(buff, permissionsGranted, { user, loadApp: true });
const info: IAppInfo & { status?: AppStatus } = aff.getAppInfo();

if (aff.hasStorageError()) {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/server/services/messages/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ export class MessageService extends ServiceClassInternal implements IMessageServ

message = await mentionServer.execute(message);
message = await this.cannedResponse.replacePlaceholders({ message, room, user });
message = await this.markdownParser.parseMarkdown({ message, config: this.getMarkdownConfig() });
message = await this.badWords.filterBadWords({ message });
message = await this.markdownParser.parseMarkdown({ message, config: this.getMarkdownConfig() });
message = await this.spotify.convertSpotifyLinks({ message });
message = await this.jumpToMessage.createAttachmentForMessageURLs({
message,
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/tests/e2e/image-gallery.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ test.describe.serial('Image Gallery', async () => {
});

test.afterAll(async ({ api }) => {
await poHomeChannel.page.close();
await deleteChannel(api, targetChannel);
await deleteChannel(api, targetChannelLargeImage);
});
Expand Down
Loading

0 comments on commit 8e09b4d

Please sign in to comment.