Skip to content

Commit

Permalink
Merge branch 'develop' into feature
Browse files Browse the repository at this point in the history
  • Loading branch information
abirc8010 committed Sep 20, 2024
2 parents c8d28a8 + 65d2a45 commit 8b1efd4
Show file tree
Hide file tree
Showing 53 changed files with 1,571 additions and 160 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-ladybugs-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed error during sendmessage client stub
5 changes: 5 additions & 0 deletions .changeset/five-coats-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/fuselage-ui-kit': patch
---

Fixed an error that incorrectly showed conference calls as not answered after they ended
5 changes: 5 additions & 0 deletions .changeset/kind-llamas-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Changed the contextualbar behavior based on chat size instead the viewport
7 changes: 7 additions & 0 deletions .changeset/late-planes-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@rocket.chat/meteor": minor
"@rocket.chat/core-typings": patch
"@rocket.chat/i18n": patch
---

Added a new setting to enable mentions in end to end encrypted channels
5 changes: 5 additions & 0 deletions .changeset/sweet-nails-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed inconsistency between the markdown parser from the composer and the rest of the application when using bold and italics in a text.
10 changes: 10 additions & 0 deletions .changeset/witty-lemons-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@rocket.chat/core-services': minor
'@rocket.chat/model-typings': minor
'@rocket.chat/core-typings': minor
'@rocket.chat/rest-typings': minor
'@rocket.chat/ui-client': minor
'@rocket.chat/meteor': minor
---

Implemented new feature preview for Sidepanel
35 changes: 35 additions & 0 deletions .github/workflows/release-candidate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Release candidate cut
on:
schedule:
- cron: '28 0 20 * *' # run at minute 28 to avoid the chance of delay due to high load on GH
jobs:
new-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
fetch-depth: 0
token: ${{ secrets.CI_PAT }}

- name: Setup NodeJS
uses: ./.github/actions/setup-node
with:
node-version: 14.21.3
cache-modules: true
install: true
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- uses: rharkor/caching-for-turbo@v1.5

- name: Build packages
run: yarn build

- name: 'Start release candidate'
uses: ./packages/release-action
with:
action: next
base-ref: ${{ github.ref_name }}
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.CI_PAT }}
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ API.v1.addRoute(
throw new Meteor.Error('error-emoji-param-not-provided', 'The required "emoji" param is missing.');
}

await executeSetReaction(this.userId, emoji, msg._id, this.bodyParams.shouldReact);
await executeSetReaction(this.userId, emoji, msg, this.bodyParams.shouldReact);

return API.v1.success();
},
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ API.v1.addRoute(
const discussionParent =
room.prid &&
(await Rooms.findOneById<Pick<IRoom, 'name' | 'fname' | 't' | 'prid' | 'u'>>(room.prid, {
projection: { name: 1, fname: 1, t: 1, prid: 1, u: 1 },
projection: { name: 1, fname: 1, t: 1, prid: 1, u: 1, sidepanel: 1 },
}));
const { team, parentRoom } = await Team.getRoomInfo(room);
const parent = discussionParent || parentRoom;
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/lib/client/methods/sendMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Meteor.methods<ServerMethods>({

await onClientMessageReceived(message as IMessage).then((message) => {
ChatMessage.insert(message);
return callbacks.run('afterSaveMessage', message, room);
return callbacks.run('afterSaveMessage', message, { room });
});
},
});
2 changes: 1 addition & 1 deletion apps/meteor/app/lib/server/methods/updateMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { hasPermissionAsync } from '../../../authorization/server/functions/hasP
import { settings } from '../../../settings/server';
import { updateMessage } from '../functions/updateMessage';

const allowedEditedFields = ['tshow', 'alias', 'attachments', 'avatar', 'emoji', 'msg', 'customFields', 'content'];
const allowedEditedFields = ['tshow', 'alias', 'attachments', 'avatar', 'emoji', 'msg', 'customFields', 'content', 'e2eMentions'];

export async function executeUpdateMessage(
uid: IUser['_id'],
Expand Down
20 changes: 15 additions & 5 deletions apps/meteor/app/mentions/server/Mentions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Mentions is a named function that will process Mentions
* @param {Object} message - The message object
*/
import type { IMessage, IRoom, IUser } from '@rocket.chat/core-typings';
import { isE2EEMessage, type IMessage, type IRoom, type IUser } from '@rocket.chat/core-typings';

import { type MentionsParserArgs, MentionsParser } from '../lib/MentionsParser';

Expand Down Expand Up @@ -43,8 +43,13 @@ export class MentionsServer extends MentionsParser {
});
}

async getUsersByMentions({ msg, rid, u: sender }: Pick<IMessage, 'msg' | 'rid' | 'u'>): Promise<IMessage['mentions']> {
const mentions = this.getUserMentions(msg);
async getUsersByMentions(message: IMessage): Promise<IMessage['mentions']> {
const { msg, rid, u: sender, e2eMentions }: Pick<IMessage, 'msg' | 'rid' | 'u' | 't' | 'e2eMentions'> = message;

const mentions =
isE2EEMessage(message) && e2eMentions?.e2eUserMentions && e2eMentions?.e2eUserMentions.length > 0
? e2eMentions?.e2eUserMentions
: this.getUserMentions(msg);
const mentionsAll: { _id: string; username: string }[] = [];
const userMentions = [];

Expand All @@ -67,8 +72,13 @@ export class MentionsServer extends MentionsParser {
return [...mentionsAll, ...(userMentions.length ? await this.getUsers(userMentions) : [])];
}

async getChannelbyMentions({ msg }: Pick<IMessage, 'msg'>) {
const channels = this.getChannelMentions(msg);
async getChannelbyMentions(message: IMessage) {
const { msg, e2eMentions }: Pick<IMessage, 'msg' | 't' | 'e2eMentions'> = message;

const channels =
isE2EEMessage(message) && e2eMentions?.e2eChannelMentions && e2eMentions?.e2eChannelMentions.length > 0
? e2eMentions?.e2eChannelMentions
: this.getChannelMentions(msg);
return this.getChannels(channels.map((c) => c.trim().substr(1)));
}

Expand Down
109 changes: 61 additions & 48 deletions apps/meteor/app/reactions/server/setReaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,46 @@ import type { IMessage, IRoom, IUser } from '@rocket.chat/core-typings';
import type { ServerMethods } from '@rocket.chat/ddp-client';
import { Messages, EmojiCustom, Rooms, Users } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';
import _ from 'underscore';

import { callbacks } from '../../../lib/callbacks';
import { i18n } from '../../../server/lib/i18n';
import { canAccessRoomAsync } from '../../authorization/server';
import { hasPermissionAsync } from '../../authorization/server/functions/hasPermission';
import { emoji } from '../../emoji/server';
import { isTheLastMessage } from '../../lib/server/functions/isTheLastMessage';
import { notifyOnRoomChangedById, notifyOnMessageChange } from '../../lib/server/lib/notifyListener';
import { notifyOnMessageChange } from '../../lib/server/lib/notifyListener';

const removeUserReaction = (message: IMessage, reaction: string, username: string) => {
export const removeUserReaction = (message: IMessage, reaction: string, username: string) => {
if (!message.reactions) {
return message;
}

message.reactions[reaction].usernames.splice(message.reactions[reaction].usernames.indexOf(username), 1);
if (message.reactions[reaction].usernames.length === 0) {
const idx = message.reactions[reaction].usernames.indexOf(username);

// user not found in reaction array
if (idx === -1) {
return message;
}

message.reactions[reaction].usernames.splice(idx, 1);
if (!message.reactions[reaction].usernames.length) {
delete message.reactions[reaction];
}
return message;
};

async function setReaction(room: IRoom, user: IUser, message: IMessage, reaction: string, shouldReact?: boolean) {
reaction = `:${reaction.replace(/:/g, '')}:`;
export async function setReaction(
room: Pick<IRoom, '_id' | 'muted' | 'unmuted' | 'reactWhenReadOnly' | 'ro' | 'lastMessage' | 'federated'>,
user: IUser,
message: IMessage,
reaction: string,
userAlreadyReacted?: boolean,
) {
await Message.beforeReacted(message, room);

if (!emoji.list[reaction] && (await EmojiCustom.findByNameOrAlias(reaction, {}).count()) === 0) {
throw new Meteor.Error('error-not-allowed', 'Invalid emoji provided.', {
method: 'setReaction',
if (Array.isArray(room.muted) && room.muted.includes(user.username as string)) {
throw new Meteor.Error('error-not-allowed', i18n.t('You_have_been_muted', { lng: user.language }), {
rid: room._id,
});
}

Expand All @@ -42,50 +54,23 @@ async function setReaction(room: IRoom, user: IUser, message: IMessage, reaction
}
}

if (Array.isArray(room.muted) && room.muted.indexOf(user.username as string) !== -1) {
throw new Meteor.Error('error-not-allowed', i18n.t('You_have_been_muted', { lng: user.language }), {
rid: room._id,
});
}

// if (!('reactions' in message)) {
// return;
// }

await Message.beforeReacted(message, room);

const userAlreadyReacted =
message.reactions &&
Boolean(message.reactions[reaction]) &&
message.reactions[reaction].usernames.indexOf(user.username as string) !== -1;
// When shouldReact was not informed, toggle the reaction.
if (shouldReact === undefined) {
shouldReact = !userAlreadyReacted;
}

if (userAlreadyReacted === shouldReact) {
return;
}

let isReacted;

if (userAlreadyReacted) {
const oldMessage = JSON.parse(JSON.stringify(message));
removeUserReaction(message, reaction, user.username as string);
if (_.isEmpty(message.reactions)) {
if (Object.keys(message.reactions || {}).length === 0) {
delete message.reactions;
await Messages.unsetReactions(message._id);
if (isTheLastMessage(room, message)) {
await Rooms.unsetReactionsInLastMessage(room._id);
void notifyOnRoomChangedById(room._id);
}
await Messages.unsetReactions(message._id);
} else {
await Messages.setReactions(message._id, message.reactions);
if (isTheLastMessage(room, message)) {
await Rooms.setReactionsInLastMessage(room._id, message.reactions);
}
}
await callbacks.run('afterUnsetReaction', message, { user, reaction, shouldReact, oldMessage });
void callbacks.run('afterUnsetReaction', message, { user, reaction, shouldReact: false, oldMessage });

isReacted = false;
} else {
Expand All @@ -101,33 +86,61 @@ async function setReaction(room: IRoom, user: IUser, message: IMessage, reaction
await Messages.setReactions(message._id, message.reactions);
if (isTheLastMessage(room, message)) {
await Rooms.setReactionsInLastMessage(room._id, message.reactions);
void notifyOnRoomChangedById(room._id);
}
await callbacks.run('afterSetReaction', message, { user, reaction, shouldReact });

void callbacks.run('afterSetReaction', message, { user, reaction, shouldReact: true });

isReacted = true;
}

await Apps.self?.triggerEvent(AppEvents.IPostMessageReacted, message, user, reaction, isReacted);
void Apps.self?.triggerEvent(AppEvents.IPostMessageReacted, message, user, reaction, isReacted);

void notifyOnMessageChange({
id: message._id,
});
}

export async function executeSetReaction(userId: string, reaction: string, messageId: IMessage['_id'], shouldReact?: boolean) {
const user = await Users.findOneById(userId);
export async function executeSetReaction(
userId: string,
reaction: string,
messageParam: IMessage['_id'] | IMessage,
shouldReact?: boolean,
) {
// Check if the emoji is valid before proceeding
const reactionWithoutColons = reaction.replace(/:/g, '');
reaction = `:${reactionWithoutColons}:`;

if (!emoji.list[reaction] && (await EmojiCustom.countByNameOrAlias(reactionWithoutColons)) === 0) {
throw new Meteor.Error('error-not-allowed', 'Invalid emoji provided.', {
method: 'setReaction',
});
}

const user = await Users.findOneById(userId);
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'setReaction' });
}

const message = await Messages.findOneById(messageId);
const message = typeof messageParam === 'string' ? await Messages.findOneById(messageParam) : messageParam;
if (!message) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setReaction' });
}

const room = await Rooms.findOneById(message.rid);
const userAlreadyReacted =
message.reactions && Boolean(message.reactions[reaction]) && message.reactions[reaction].usernames.includes(user.username as string);

// When shouldReact was not informed, toggle the reaction.
if (shouldReact === undefined) {
shouldReact = !userAlreadyReacted;
}

if (userAlreadyReacted === shouldReact) {
return;
}

const room = await Rooms.findOneById<
Pick<IRoom, '_id' | 'ro' | 'muted' | 'reactWhenReadOnly' | 'lastMessage' | 't' | 'prid' | 'federated'>
>(message.rid, { projection: { _id: 1, ro: 1, muted: 1, reactWhenReadOnly: 1, lastMessage: 1, t: 1, prid: 1, federated: 1 } });
if (!room) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setReaction' });
}
Expand All @@ -136,7 +149,7 @@ export async function executeSetReaction(userId: string, reaction: string, messa
throw new Meteor.Error('not-authorized', 'Not Authorized', { method: 'setReaction' });
}

return setReaction(room, user, message, reaction, shouldReact);
return setReaction(room, user, message, reaction, userAlreadyReacted);
}

declare module '@rocket.chat/ddp-client' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ContextualbarDialogProps = AriaDialogProps & ComponentProps<typeof Contextu
const ContextualbarDialog = (props: ContextualbarDialogProps) => {
const ref = useRef(null);
const { dialogProps } = useDialog({ 'aria-labelledby': 'contextualbarTitle', ...props }, ref);
const sizes = useLayoutSizes();
const { contextualBar } = useLayoutSizes();
const position = useLayoutContextualBarPosition();
const { closeTab } = useRoomToolbox();

Expand All @@ -42,12 +42,12 @@ const ContextualbarDialog = (props: ContextualbarDialogProps) => {
<FocusScope autoFocus restoreFocus>
<FeaturePreview feature='contextualbarResizable'>
<FeaturePreviewOn>
<ContextualbarResizable defaultWidth={sizes.contextualBar}>
<ContextualbarResizable defaultWidth={contextualBar}>
<Contextualbar ref={callbackRef} width='100%' position={position} {...dialogProps} {...props} />
</ContextualbarResizable>
</FeaturePreviewOn>
<FeaturePreviewOff>
<Contextualbar ref={callbackRef} width={sizes.contextualBar} position={position} {...dialogProps} {...props} />
<Contextualbar ref={callbackRef} width={contextualBar} position={position} {...dialogProps} {...props} />
</FeaturePreviewOff>
</FeaturePreview>
</FocusScope>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { FeaturePreview } from '@rocket.chat/ui-client';
import type { ReactElement } from 'react';
import React from 'react';

import { useSidePanelNavigationScreenSize } from '../hooks/useSidePanelNavigation';

export const FeaturePreviewSidePanelNavigation = ({ children }: { children: ReactElement[] }) => {
const disabled = !useSidePanelNavigationScreenSize();
return <FeaturePreview feature='sidepanelNavigation' disabled={disabled} children={children} />;
};
Loading

0 comments on commit 8b1efd4

Please sign in to comment.