Skip to content

Commit

Permalink
feat: add message to uikit interaction (#29522)
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriel Casals <83978645+casalsgh@users.noreply.github.com>
  • Loading branch information
ggazzo and casalsgh committed Jun 14, 2023
1 parent cb0a92e commit c0c8df6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 21 deletions.
7 changes: 4 additions & 3 deletions apps/meteor/app/ui-message/client/actionButtons/messageBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ export const onAdded = (button: IUIActionButton): void =>
),
);
},
action() {
action(params) {
void triggerActionButtonAction({
rid: RoomManager.opened,
rid: params.rid,
tmid: params.tmid,
actionId: button.actionId,
appId: button.appId,
payload: { context: button.context },
payload: { context: button.context, message: params.chat.composer?.text },
});
},
});
Expand Down
11 changes: 2 additions & 9 deletions apps/meteor/app/ui-utils/client/lib/messageBox.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import type { IMessage, IRoom } from '@rocket.chat/core-typings';
import type { ContextType } from 'react';
import type { TranslationKey } from '@rocket.chat/ui-contexts';

import type { ChatContext } from '../../../../client/views/room/contexts/ChatContext';
import type { ChatAPI } from '../../../../client/lib/chats/ChatAPI';

type MessageBoxAction = {
label: TranslationKey;
id: string;
icon?: string;
action: (params: {
rid: IRoom['_id'];
tmid?: IMessage['_id'];
event: Event;
messageBox: HTMLElement;
chat: ContextType<typeof ChatContext>;
}) => void;
action: (params: { rid: IRoom['_id']; tmid?: IMessage['_id']; event: Event; chat: ChatAPI }) => void;
condition?: () => boolean;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React, { useRef, Fragment } from 'react';
import { messageBox } from '../../../../../../../../app/ui-utils/client';
import type { ChatAPI } from '../../../../../../../lib/chats/ChatAPI';
import { useDropdownVisibility } from '../../../../../../../sidebar/header/hooks/useDropdownVisibility';
import { useChat } from '../../../../../contexts/ChatContext';
import CreateDiscussionAction from './actions/CreateDiscussionAction';
import ShareLocationAction from './actions/ShareLocationAction';
import WebdavAction from './actions/WebdavAction';
Expand All @@ -19,7 +20,13 @@ type ActionsToolbarDropdownProps = {
actions?: ReactNode[];
};

const ActionsToolbarDropdown = ({ chatContext, isRecording, rid, tmid, actions, ...props }: ActionsToolbarDropdownProps) => {
const ActionsToolbarDropdown = ({ isRecording, rid, tmid, actions, ...props }: ActionsToolbarDropdownProps) => {
const chatContext = useChat();

if (!chatContext) {
throw new Error('useChat must be used within a ChatProvider');
}

const t = useTranslation();
const reference = useRef(null);
const target = useRef(null);
Expand Down Expand Up @@ -66,7 +73,17 @@ const ActionsToolbarDropdown = ({ chatContext, isRecording, rid, tmid, actions,
<Fragment key={index}>
<OptionTitle>{actionGroup.title}</OptionTitle>
{actionGroup.items.map((item) => (
<Option key={item.id} onClick={item.action as () => void}>
<Option
key={item.id}
onClick={(event) =>
item.action({
rid,
tmid,
event: event as unknown as Event,
chat: chatContext,
})
}
>
{item.icon && <OptionIcon name={item.icon as ComponentProps<typeof OptionIcon>['name']} />}
<OptionContent>{item.name}</OptionContent>
</Option>
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/ee/server/apps/communication/uikit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ const appsRoutes =
triggerId,
rid,
mid,
payload: { context },
payload: { context, message: msgText },
} = req.body;

const room = await orch.getConverters()?.get('rooms').convertById(rid);
Expand All @@ -300,6 +300,7 @@ const appsRoutes =
message,
payload: {
context,
...(msgText && { message: msgText }),
},
};

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
"@rocket.chat/account-utils": "workspace:^",
"@rocket.chat/agenda": "workspace:^",
"@rocket.chat/api-client": "workspace:^",
"@rocket.chat/apps-engine": "1.40.0-alpha.266",
"@rocket.chat/apps-engine": "1.40.0-alpha.275",
"@rocket.chat/base64": "workspace:^",
"@rocket.chat/cas-validate": "workspace:^",
"@rocket.chat/core-services": "workspace:^",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8022,9 +8022,9 @@ __metadata:
languageName: node
linkType: hard

"@rocket.chat/apps-engine@npm:1.40.0-alpha.266":
version: 1.40.0-alpha.266
resolution: "@rocket.chat/apps-engine@npm:1.40.0-alpha.266"
"@rocket.chat/apps-engine@npm:1.40.0-alpha.275":
version: 1.40.0-alpha.275
resolution: "@rocket.chat/apps-engine@npm:1.40.0-alpha.275"
dependencies:
adm-zip: ^0.5.9
cryptiles: ^4.1.3
Expand All @@ -8036,7 +8036,7 @@ __metadata:
vm2: ^3.9.19
peerDependencies:
"@rocket.chat/ui-kit": "*"
checksum: 5176cd8f365b0249cf9d6882e26eea0e0503d37d86d27018541ee9d34dd95feb10456192d64f2c7827c4051b651d76039c8b1a9e46e6e541f62f9991c950c5be
checksum: 77a4ad45c409397a7a8b1ef4ee2db67af75aa7a1f8a078cc59bc69681e8338ed90a110dfc279a46dc84d6bc93e4e43880ec1620a73837a6a9dcccbe055a51212
languageName: node
linkType: hard

Expand Down Expand Up @@ -8773,7 +8773,7 @@ __metadata:
"@rocket.chat/account-utils": "workspace:^"
"@rocket.chat/agenda": "workspace:^"
"@rocket.chat/api-client": "workspace:^"
"@rocket.chat/apps-engine": 1.40.0-alpha.266
"@rocket.chat/apps-engine": 1.40.0-alpha.275
"@rocket.chat/base64": "workspace:^"
"@rocket.chat/cas-validate": "workspace:^"
"@rocket.chat/core-services": "workspace:^"
Expand Down

0 comments on commit c0c8df6

Please sign in to comment.