Skip to content

Commit

Permalink
Merge branch 'develop' into fix/im.counters-return-null-before-openin…
Browse files Browse the repository at this point in the history
…g-dm
  • Loading branch information
KevLehman authored Dec 6, 2024
2 parents 8096af2 + 072a749 commit 3951cca
Show file tree
Hide file tree
Showing 21 changed files with 406 additions and 174 deletions.
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.
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.

1 change: 0 additions & 1 deletion apps/meteor/app/reactions/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import './init';
import './methods/setReaction';
43 changes: 0 additions & 43 deletions apps/meteor/app/reactions/client/init.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,9 +12,11 @@ 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';
import { useReactionMessageAction } from './useReactionMessageAction';
import { useReplyInThreadMessageAction } from './useReplyInThreadMessageAction';
import { useStarMessageAction } from './useStarMessageAction';
import { useUnFollowMessageAction } from './useUnFollowMessageAction';
Expand Down Expand Up @@ -131,6 +133,8 @@ const MessageToolbar = ({
order: 100,
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]);
};
Loading

0 comments on commit 3951cca

Please sign in to comment.