Skip to content

Commit

Permalink
Merge branch 'develop' into fix/roomMembers-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Dec 9, 2024
2 parents 0d5ad23 + ed69269 commit 28b77cd
Show file tree
Hide file tree
Showing 30 changed files with 581 additions and 171 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-pants-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Removes a validation that allowed only the room creator to propagate E2EE room keys. This was causing issues when the rooms were created via apps or some other integration, as the creator may not be online or able to create E2EE keys
5 changes: 5 additions & 0 deletions .changeset/green-shirts-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixes condition causing Omnichannel queue to start more than once.
5 changes: 5 additions & 0 deletions .changeset/proud-cups-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixes `im.counters` endpoint returning `null` on `unread` messages property for users that have never opened the queried DM
5 changes: 5 additions & 0 deletions .changeset/six-snails-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixes a behavior of the mentions parser that identified mentions inside markdown links text. Now, these components will be removed from the text before trying to parse mentions.
4 changes: 2 additions & 2 deletions apps/meteor/app/api/server/v1/im.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ API.v1.addRoute(

lm = room?.lm ? new Date(room.lm).toISOString() : new Date(room._updatedAt).toISOString(); // lm is the last message timestamp

if (subscription?.open) {
if (subscription) {
unreads = subscription.unread ?? null;
if (subscription.ls && room.msgs) {
unreads = subscription.unread;
unreadsFrom = new Date(subscription.ls).toISOString(); // last read timestamp
}
userMentions = subscription.userMentions;
Expand Down
12 changes: 1 addition & 11 deletions apps/meteor/app/e2e/client/rocketchat.e2e.room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,7 @@ export class E2ERoom extends Emitter {

try {
const room = Rooms.findOne({ _id: this.roomId })!;

Check warning on line 328 in apps/meteor/app/e2e/client/rocketchat.e2e.room.ts

View workflow job for this annotation

GitHub Actions / 🔎 Code Check / Code Lint

Forbidden non-null assertion
// Only room creator can set keys for room
if (!room.e2eKeyId && this.userShouldCreateKeys(room)) {
if (!room.e2eKeyId) {
this.setState(E2ERoomState.CREATING_KEYS);
await this.createGroupKey();
this.setState(E2ERoomState.READY);
Expand All @@ -343,15 +342,6 @@ export class E2ERoom extends Emitter {
}
}

userShouldCreateKeys(room: any) {
// On DMs, we'll allow any user to set the keys
if (room.t === 'd') {
return true;
}

return room.u._id === this.userId;
}

isSupportedRoomType(type: any) {
return roomCoordinator.getRoomDirectives(type).allowRoomSettingChange({}, RoomSettingsEnum.E2E);
}
Expand Down
10 changes: 8 additions & 2 deletions apps/meteor/app/mentions/lib/MentionsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,17 @@ export class MentionsParser {
return this.roomTemplate({ prefix, reference, channel, mention });
});

getUserMentions(str: string) {
getUserMentions(msg: string) {
// First remove the text inside md links
const str = msg.replace(/\[[^\]]*\]\([^)]+\)/g, '');
// Then do the match
return (str.match(this.userMentionRegex) || []).map((match) => match.trim());
}

getChannelMentions(str: string) {
getChannelMentions(msg: string) {
// First remove the text inside md links
const str = msg.replace(/\[[^\]]*\]\([^)]+\)/g, '');
// Then do the match
return (str.match(this.channelMentionRegex) || []).map((match) => match.trim());
}

Expand Down
48 changes: 0 additions & 48 deletions apps/meteor/app/message-mark-as-unread/client/actionButton.ts

This file was deleted.

1 change: 0 additions & 1 deletion apps/meteor/app/message-mark-as-unread/client/index.ts

This file was deleted.

69 changes: 47 additions & 22 deletions apps/meteor/client/components/UserCard/UserCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,34 @@ import React from 'react';

import { UserCard, UserCardRole, UserCardAction } from '.';

const user = {
name: 'guilherme.gazzo',
customStatus: '🛴 currently working on User Card',
roles: (
<>
<UserCardRole>Admin</UserCardRole>
<UserCardRole>Rocket.Chat</UserCardRole>
<UserCardRole>Team</UserCardRole>
</>
),
bio: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla tempus, eros convallis vulputate cursus, nisi neque eleifend libero, eget lacinia justo purus nec est. In at sodales ipsum. Sed lacinia quis purus eget pulvinar. Aenean eu pretium nunc, at aliquam magna. Praesent dignissim, tortor sed volutpat mattis, mauris diam pulvinar leo, porta commodo risus est non purus. Mauris in justo vel lorem ullamcorper hendrerit. Nam est metus, viverra a pellentesque vitae, ornare eget odio. Morbi tempor feugiat mattis. Morbi non felis tempor, aliquam justo sed, sagittis nibh. Mauris consequat ex metus. Praesent sodales sit amet nibh a vulputate. Integer commodo, mi vel bibendum sollicitudin, urna lectus accumsan ante, eget faucibus augue ex id neque. Aenean consectetur, orci a pellentesque mattis, tortor tellus fringilla elit, non ullamcorper risus nunc feugiat risus. Fusce sit amet nisi dapibus turpis commodo placerat. In tortor ante, vehicula sit amet augue et, imperdiet porta sem.',
localTime: 'Local Time: 7:44 AM',
};

export default {
title: 'Components/UserCard',
component: UserCard,
parameters: {
layout: 'centered',
},
args: {
name: 'guilherme.gazzo',
customStatus: '🛴 currently working on User Card',
roles: (
<>
<UserCardRole>Admin</UserCardRole>
<UserCardRole>Rocket.Chat</UserCardRole>
<UserCardRole>Team</UserCardRole>
</>
),
bio: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla tempus, eros convallis vulputate cursus, nisi neque eleifend libero, eget lacinia justo purus nec est. In at sodales ipsum. Sed lacinia quis purus eget pulvinar. Aenean eu pretium nunc, at aliquam magna. Praesent dignissim, tortor sed volutpat mattis, mauris diam pulvinar leo, porta commodo risus est non purus. Mauris in justo vel lorem ullamcorper hendrerit. Nam est metus, viverra a pellentesque vitae, ornare eget odio. Morbi tempor feugiat mattis. Morbi non felis tempor, aliquam justo sed, sagittis nibh. Mauris consequat ex metus. Praesent sodales sit amet nibh a vulputate. Integer commodo, mi vel bibendum sollicitudin, urna lectus accumsan ante, eget faucibus augue ex id neque. Aenean consectetur, orci a pellentesque mattis, tortor tellus fringilla elit, non ullamcorper risus nunc feugiat risus. Fusce sit amet nisi dapibus turpis commodo placerat. In tortor ante, vehicula sit amet augue et, imperdiet porta sem.',
user,
actions: (
<>
<UserCardAction icon='message' />
<UserCardAction icon='phone' />
</>
),
localTime: 'Local Time: 7:44 AM',
},
} satisfies Meta<typeof UserCard>;

Expand All @@ -36,18 +40,27 @@ export const Example = Template.bind({});

export const Nickname = Template.bind({});
Nickname.args = {
nickname: 'nicknamenickname',
user: {
...user,
nickname: 'nicknamenickname',
},
} as any;

export const LargeName = Template.bind({});
LargeName.args = {
customStatus: '🛴 currently working on User Card on User Card on User Card on User Card on User Card ',
name: 'guilherme.gazzo.guilherme.gazzo.guilherme.gazzo.guilherme.gazzo.guilherme.gazzo.guilherme.gazzo.guilherme.gazzo.guilherme.gazzo.',
user: {
...user,
customStatus: '🛴 currently working on User Card on User Card on User Card on User Card on User Card ',
name: 'guilherme.gazzo.guilherme.gazzo.guilherme.gazzo.guilherme.gazzo.guilherme.gazzo.guilherme.gazzo.guilherme.gazzo.guilherme.gazzo.',
},
} as any;

export const NoRoles = Template.bind({});
NoRoles.args = {
roles: undefined,
user: {
...user,
roles: undefined,
},
} as any;

export const NoActions = Template.bind({});
Expand All @@ -57,25 +70,37 @@ NoActions.args = {

export const NoLocalTime = Template.bind({});
NoLocalTime.args = {
localTime: undefined,
user: {
...user,
localTime: undefined,
},
} as any;

export const NoBio = Template.bind({});
NoBio.args = {
bio: undefined,
user: {
...user,
bio: undefined,
},
} as any;

export const NoBioAndNoLocalTime = Template.bind({});
NoBioAndNoLocalTime.args = {
bio: undefined,
localTime: undefined,
user: {
...user,
bio: undefined,
localTime: undefined,
},
} as any;

export const NoBioNoLocalTimeNoRoles = Template.bind({});
NoBioNoLocalTimeNoRoles.args = {
bio: undefined,
localTime: undefined,
roles: undefined,
user: {
...user,
bio: undefined,
localTime: undefined,
roles: undefined,
},
} as any;

export const Loading = () => <UserCard />;
34 changes: 14 additions & 20 deletions apps/meteor/client/components/UserCard/UserCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,27 @@ const clampStyle = css`
`;

type UserCardProps = {
onOpenUserInfo?: () => void;
name?: string;
username?: string;
etag?: string;
customStatus?: ReactNode;
roles?: ReactNode;
bio?: ReactNode;
status?: ReactNode;
user?: {
nickname?: string;
name?: string;
username?: string;
etag?: string;
customStatus?: ReactNode;
roles?: ReactNode;
bio?: ReactNode;
status?: ReactNode;
localTime?: ReactNode;
};
actions?: ReactNode;
localTime?: ReactNode;
onOpenUserInfo?: () => void;
onClose?: () => void;
nickname?: string;
} & ComponentProps<typeof UserCardDialog>;

const UserCard = ({
onOpenUserInfo,
name,
username,
etag,
customStatus,
roles,
bio,
status = <Status.Offline />,
user: { name, username, etag, customStatus, roles, bio, status = <Status.Offline />, localTime, nickname } = {},
actions,
localTime,
onOpenUserInfo,
onClose,
nickname,
...props
}: UserCardProps) => {
const { t } = useTranslation();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { IMessage, ISubscription } from '@rocket.chat/core-typings';
import { useToastMessageDispatch } from '@rocket.chat/ui-contexts';
import { useMutation } from '@tanstack/react-query';

import { LegacyRoomManager } from '../../../../app/ui-utils/client';
import { sdk } from '../../../../app/utils/client/lib/SDKClient';

export const useMarkAsUnreadMutation = () => {
const dispatchToastMessage = useToastMessageDispatch();

return useMutation({
mutationFn: async ({ message, subscription }: { message: IMessage; subscription: ISubscription }) => {
await LegacyRoomManager.close(subscription.t + subscription.name);
await sdk.call('unreadMessages', message);
},
onError: (error) => {
dispatchToastMessage({ type: 'error', message: error });
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import MessageActionMenu from './MessageActionMenu';
import MessageToolbarStarsActionMenu from './MessageToolbarStarsActionMenu';
import { useFollowMessageAction } from './useFollowMessageAction';
import { useJumpToMessageContextAction } from './useJumpToMessageContextAction';
import { useMarkAsUnreadMessageAction } from './useMarkAsUnreadMessageAction';
import { useNewDiscussionMessageAction } from './useNewDiscussionMessageAction';
import { usePermalinkAction } from './usePermalinkAction';
import { usePinMessageAction } from './usePinMessageAction';
Expand Down Expand Up @@ -133,6 +134,7 @@ const MessageToolbar = ({
context: ['starred'],
});
useReactionMessageAction(message, { user, room, subscription });
useMarkAsUnreadMessageAction(message, { user, room, subscription });

const actionsQueryResult = useQuery({
queryKey: roomsQueryKeys.messageActionsWithParameters(room._id, message),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { isOmnichannelRoom } from '@rocket.chat/core-typings';
import type { ISubscription, IMessage, IRoom, IUser } from '@rocket.chat/core-typings';
import { useRouter } from '@rocket.chat/ui-contexts';
import { useEffect } from 'react';

import { MessageAction } from '../../../../app/ui-utils/client';
import { useMarkAsUnreadMutation } from '../hooks/useMarkAsUnreadMutation';

export const useMarkAsUnreadMessageAction = (
message: IMessage,
{ user, room, subscription }: { user: IUser | undefined; room: IRoom; subscription: ISubscription | undefined },
) => {
const { mutateAsync: markAsUnread } = useMarkAsUnreadMutation();

const router = useRouter();

useEffect(() => {
if (isOmnichannelRoom(room) || !user) {
return;
}

if (!subscription) {
return;
}

if (message.u._id === user._id) {
return;
}

MessageAction.addButton({
id: 'mark-message-as-unread',
icon: 'flag',
label: 'Mark_unread',
context: ['message', 'message-mobile', 'threads'],
type: 'interaction',
async action() {
router.navigate('/home');
await markAsUnread({ message, subscription });
},
order: 4,
group: 'menu',
});
return () => {
MessageAction.removeButton('mark-message-as-unread');
};
}, [markAsUnread, message, room, router, subscription, user]);
};
1 change: 0 additions & 1 deletion apps/meteor/client/importPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import '../app/iframe-login/client';
import '../app/license/client';
import '../app/lib/client';
import '../app/livechat-enterprise/client';
import '../app/message-mark-as-unread/client';
import '../app/nextcloud/client';
import '../app/notifications/client';
import '../app/otr/client';
Expand Down
Loading

0 comments on commit 28b77cd

Please sign in to comment.