Skip to content

Commit

Permalink
refactor: Take away stale messageArgs() helper (RocketChat#33780)
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan authored Nov 1, 2024
1 parent 8949e21 commit 971249b
Show file tree
Hide file tree
Showing 20 changed files with 27 additions and 92 deletions.
6 changes: 2 additions & 4 deletions apps/meteor/app/autotranslate/client/lib/actionButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';

import { roomCoordinator } from '../../../../client/lib/rooms/roomCoordinator';
import { messageArgs } from '../../../../client/lib/utils/messageArgs';
import {
hasTranslationLanguageInAttachments,
hasTranslationLanguageInMessage,
Expand All @@ -25,8 +24,7 @@ Meteor.startup(() => {
label: 'Translate',
context: ['message', 'message-mobile', 'threads'],
type: 'interaction',
action(_, props) {
const { message = messageArgs(this).msg } = props;
action(_, { message }) {
const language = AutoTranslate.getLanguage(message.rid);
if (!hasTranslationLanguageInMessage(message, language) && !hasTranslationLanguageInAttachments(message.attachments, language)) {
(AutoTranslate.messageIdsToWait as any)[message._id] = true;
Expand Down Expand Up @@ -61,7 +59,7 @@ Meteor.startup(() => {
context: ['message', 'message-mobile', 'threads'],
type: 'interaction',
action(_, props) {
const { message = messageArgs(this).msg } = props;
const { message } = props;
const language = AutoTranslate.getLanguage(message.rid);
if (!hasTranslationLanguageInMessage(message, language) && !hasTranslationLanguageInAttachments(message.attachments, language)) {
(AutoTranslate.messageIdsToWait as any)[message._id] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Tracker } from 'meteor/tracker';
import CreateDiscussion from '../../../client/components/CreateDiscussion/CreateDiscussion';
import { imperativeModal } from '../../../client/lib/imperativeModal';
import { roomCoordinator } from '../../../client/lib/rooms/roomCoordinator';
import { messageArgs } from '../../../client/lib/utils/messageArgs';
import { hasPermission } from '../../authorization/client';
import { settings } from '../../settings/client';
import { MessageAction } from '../../ui-utils/client';
Expand All @@ -21,9 +20,7 @@ Meteor.startup(() => {
label: 'Discussion_start',
type: 'communication',
context: ['message', 'message-mobile', 'videoconf'],
async action(_, props) {
const { message = messageArgs(this).msg, room } = props;

async action(_, { message, room }) {
imperativeModal.open({
component: CreateDiscussion,
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Meteor } from 'meteor/meteor';

import { roomCoordinator } from '../../../client/lib/rooms/roomCoordinator';
import { dispatchToastMessage } from '../../../client/lib/toast';
import { messageArgs } from '../../../client/lib/utils/messageArgs';
import { router } from '../../../client/providers/RouterProvider';
import { ChatSubscription } from '../../models/client';
import { LegacyRoomManager, MessageAction } from '../../ui-utils/client';
Expand All @@ -15,9 +14,7 @@ Meteor.startup(() => {
label: 'Mark_unread',
context: ['message', 'message-mobile', 'threads'],
type: 'interaction',
async action(_, props) {
const { message = messageArgs(this).msg } = props;

async action(_, { message }) {
try {
const subscription = ChatSubscription.findOne({
rid: message.rid,
Expand Down
4 changes: 1 addition & 3 deletions apps/meteor/app/reactions/client/init.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Meteor } from 'meteor/meteor';

import { roomCoordinator } from '../../../client/lib/rooms/roomCoordinator';
import { messageArgs } from '../../../client/lib/utils/messageArgs';
import { MessageAction } from '../../ui-utils/client';
import { sdk } from '../../utils/client/lib/SDKClient';

Expand All @@ -11,8 +10,7 @@ Meteor.startup(() => {
icon: 'add-reaction',
label: 'Add_Reaction',
context: ['message', 'message-mobile', 'threads', 'federated', 'videoconf', 'videoconf-threads'],
action(event, props) {
const { message = messageArgs(this).msg, chat } = props;
action(event, { message, chat }) {
event?.stopPropagation();
chat?.emojiPicker.open(event?.currentTarget as Element, (emoji) => sdk.call('setReaction', `:${emoji}:`, message._id));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';

import { roomCoordinator } from '../../../../client/lib/rooms/roomCoordinator';
import { messageArgs } from '../../../../client/lib/utils/messageArgs';
import { router } from '../../../../client/providers/RouterProvider';
import { settings } from '../../../settings/client';
import { MessageAction } from '../../../ui-utils/client';
Expand All @@ -17,8 +16,7 @@ Meteor.startup(() => {
icon: 'thread',
label: 'Reply_in_thread',
context: ['message', 'message-mobile', 'federated', 'videoconf'],
action(e, props) {
const { message = messageArgs(this).msg } = props;
action(e, { message }) {
e?.stopPropagation();
router.navigate({
name: router.getRouteName()!,
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/app/ui-utils/client/lib/MessageAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export type MessageActionConfig = {
group?: MessageActionGroup | MessageActionGroup[];
context?: MessageActionContext[];
action: (
this: any,
e: Pick<Event, 'preventDefault' | 'stopPropagation' | 'currentTarget'> | undefined,
{
message,
Expand Down
26 changes: 9 additions & 17 deletions apps/meteor/app/ui-utils/client/lib/messageActionDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { getPermaLink } from '../../../../client/lib/getPermaLink';
import { imperativeModal } from '../../../../client/lib/imperativeModal';
import { roomCoordinator } from '../../../../client/lib/rooms/roomCoordinator';
import { dispatchToastMessage } from '../../../../client/lib/toast';
import { messageArgs } from '../../../../client/lib/utils/messageArgs';
import { router } from '../../../../client/providers/RouterProvider';
import ForwardMessageModal from '../../../../client/views/room/modals/ForwardMessageModal/ForwardMessageModal';
import ReactionListModal from '../../../../client/views/room/modals/ReactionListModal';
Expand All @@ -32,8 +31,7 @@ Meteor.startup(async () => {
context: ['message', 'message-mobile', 'threads', 'federated'],
role: 'link',
type: 'communication',
action(_, props) {
const { message = messageArgs(this).msg } = props;
action(_, { message }) {
roomCoordinator.openRouteLink(
'd',
{ name: message.u.username },
Expand Down Expand Up @@ -74,8 +72,7 @@ Meteor.startup(async () => {
label: 'Forward_message',
context: ['message', 'message-mobile', 'threads'],
type: 'communication',
async action(_, props) {
const { message = messageArgs(this).msg } = props;
async action(_, { message }) {
const permalink = await getPermaLink(message._id);
imperativeModal.open({
component: ForwardMessageModal,
Expand All @@ -100,9 +97,7 @@ Meteor.startup(async () => {
icon: 'quote',
label: 'Quote',
context: ['message', 'message-mobile', 'threads', 'federated'],
async action(_, props) {
const { message = messageArgs(this).msg, chat, autoTranslateOptions } = props;

async action(_, { message, chat, autoTranslateOptions }) {
if (message && autoTranslateOptions?.autoTranslateEnabled && autoTranslateOptions.showAutoTranslate(message)) {
message.msg =
message.translations && autoTranslateOptions.autoTranslateLanguage
Expand Down Expand Up @@ -130,9 +125,8 @@ Meteor.startup(async () => {
// classes: 'clipboard',
context: ['message', 'message-mobile', 'threads', 'federated', 'videoconf', 'videoconf-threads'],
type: 'duplication',
async action(_, props) {
async action(_, { message }) {
try {
const { message = messageArgs(this).msg } = props;
const permalink = await getPermaLink(message._id);
await navigator.clipboard.writeText(permalink);
dispatchToastMessage({ type: 'success', message: t('Copied') });
Expand All @@ -157,8 +151,7 @@ Meteor.startup(async () => {
// classes: 'clipboard',
context: ['message', 'message-mobile', 'threads', 'federated'],
type: 'duplication',
async action(_, props) {
const { message = messageArgs(this).msg } = props;
async action(_, { message }) {
const msgText = getMainMessageText(message).msg;
await navigator.clipboard.writeText(msgText);
dispatchToastMessage({ type: 'success', message: t('Copied') });
Expand All @@ -176,8 +169,7 @@ Meteor.startup(async () => {
label: 'Edit',
context: ['message', 'message-mobile', 'threads', 'federated'],
type: 'management',
async action(_, props) {
const { message = messageArgs(this).msg, chat } = props;
async action(_, { message, chat }) {
await chat?.messageEditing.editMessage(message);
},
condition({ message, subscription, settings, room, user }) {
Expand Down Expand Up @@ -220,7 +212,7 @@ Meteor.startup(async () => {
context: ['message', 'message-mobile', 'threads', 'federated', 'videoconf', 'videoconf-threads'],
color: 'alert',
type: 'management',
async action(this: unknown, _, { message = messageArgs(this).msg, chat }) {
async action(_, { message, chat }) {
await chat?.flows.requestMessageDeletion(message);
},
condition({ message, subscription, room, chat, user }) {
Expand Down Expand Up @@ -248,7 +240,7 @@ Meteor.startup(async () => {
context: ['message', 'message-mobile', 'threads', 'federated', 'videoconf', 'videoconf-threads'],
color: 'alert',
type: 'management',
action(this: unknown, _, { message = messageArgs(this).msg }) {
action(_, { message }) {
imperativeModal.open({
component: ReportMessageModal,
props: {
Expand All @@ -275,7 +267,7 @@ Meteor.startup(async () => {
label: 'Reactions',
context: ['message', 'message-mobile', 'threads', 'videoconf', 'videoconf-threads'],
type: 'interaction',
action(this: unknown, _, { message: { reactions = {} } = messageArgs(this).msg }) {
action(_, { message: { reactions = {} } }) {
imperativeModal.open({
component: ReactionListModal,
props: { reactions, onClose: imperativeModal.close },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React, { useEffect } from 'react';
import { MessageAction } from '../../../../app/ui-utils/client/lib/MessageAction';
import { getURL } from '../../../../app/utils/client';
import { useWebDAVAccountIntegrationsQuery } from '../../../hooks/webdav/useWebDAVAccountIntegrationsQuery';
import { messageArgs } from '../../../lib/utils/messageArgs';
import SaveToWebdavModal from '../../../views/room/webdav/SaveToWebdavModal';

export const useWebDAVMessageAction = () => {
Expand All @@ -26,8 +25,7 @@ export const useWebDAVMessageAction = () => {
condition: ({ message, subscription }) => {
return !!subscription && !!data?.length && !!message.file;
},
action(_, props) {
const { message = messageArgs(this).msg } = props;
action(_, { message }) {
const [attachment] = message.attachments || [];
const url = getURL(attachment.title_link as string, { full: true });

Expand Down
18 changes: 0 additions & 18 deletions apps/meteor/client/lib/utils/messageArgs.ts

This file was deleted.

4 changes: 1 addition & 3 deletions apps/meteor/client/startup/actionButtons/jumpToMessage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Meteor } from 'meteor/meteor';

import { MessageAction } from '../../../app/ui-utils/client';
import { messageArgs } from '../../lib/utils/messageArgs';
import { setMessageJumpQueryStringParameter } from '../../lib/utils/setMessageJumpQueryStringParameter';

Meteor.startup(() => {
Expand All @@ -10,8 +9,7 @@ Meteor.startup(() => {
icon: 'jump',
label: 'Jump_to_message',
context: ['mentions', 'threads', 'videoconf-threads'],
action(_, props) {
const { message = messageArgs(this).msg } = props;
action(_, { message }) {
setMessageJumpQueryStringParameter(message._id);
},
order: 100,
Expand Down
4 changes: 1 addition & 3 deletions apps/meteor/client/startup/actionButtons/jumpToPinMessage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Meteor } from 'meteor/meteor';

import { MessageAction } from '../../../app/ui-utils/client';
import { messageArgs } from '../../lib/utils/messageArgs';
import { setMessageJumpQueryStringParameter } from '../../lib/utils/setMessageJumpQueryStringParameter';

Meteor.startup(() => {
Expand All @@ -10,8 +9,7 @@ Meteor.startup(() => {
icon: 'jump',
label: 'Jump_to_message',
context: ['pinned', 'message-mobile', 'direct'],
action(_, props) {
const { message = messageArgs(this).msg } = props;
action(_, { message }) {
setMessageJumpQueryStringParameter(message._id);
},
condition({ subscription }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Meteor } from 'meteor/meteor';

import { MessageAction } from '../../../app/ui-utils/client';
import { messageArgs } from '../../lib/utils/messageArgs';
import { setMessageJumpQueryStringParameter } from '../../lib/utils/setMessageJumpQueryStringParameter';

Meteor.startup(() => {
Expand All @@ -10,8 +9,7 @@ Meteor.startup(() => {
icon: 'jump',
label: 'Jump_to_message',
context: ['search'],
async action(_, props) {
const { message = messageArgs(this).msg } = props;
async action(_, { message }) {
setMessageJumpQueryStringParameter(message._id);
},
order: 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Meteor } from 'meteor/meteor';

import { settings } from '../../../app/settings/client';
import { MessageAction } from '../../../app/ui-utils/client';
import { messageArgs } from '../../lib/utils/messageArgs';
import { setMessageJumpQueryStringParameter } from '../../lib/utils/setMessageJumpQueryStringParameter';

Meteor.startup(() => {
Expand All @@ -11,8 +10,7 @@ Meteor.startup(() => {
icon: 'jump',
label: 'Jump_to_message',
context: ['starred', 'threads', 'message-mobile', 'videoconf-threads'],
action(_, props) {
const { message = messageArgs(this).msg } = props;
action(_, { message }) {
setMessageJumpQueryStringParameter(message._id);
},
condition({ message, subscription, user }) {
Expand Down
4 changes: 1 addition & 3 deletions apps/meteor/client/startup/actionButtons/permalinkPinned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ import { MessageAction } from '../../../app/ui-utils/client';
import { t } from '../../../app/utils/lib/i18n';
import { getPermaLink } from '../../lib/getPermaLink';
import { dispatchToastMessage } from '../../lib/toast';
import { messageArgs } from '../../lib/utils/messageArgs';

Meteor.startup(() => {
MessageAction.addButton({
id: 'permalink-pinned',
icon: 'permalink',
label: 'Copy_link',
context: ['pinned'],
async action(_, props) {
async action(_, { message }) {
try {
const { message = messageArgs(this).msg } = props;
const permalink = await getPermaLink(message._id);
navigator.clipboard.writeText(permalink);
dispatchToastMessage({ type: 'success', message: t('Copied') });
Expand Down
4 changes: 1 addition & 3 deletions apps/meteor/client/startup/actionButtons/permalinkStar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { MessageAction } from '../../../app/ui-utils/client';
import { t } from '../../../app/utils/lib/i18n';
import { getPermaLink } from '../../lib/getPermaLink';
import { dispatchToastMessage } from '../../lib/toast';
import { messageArgs } from '../../lib/utils/messageArgs';

Meteor.startup(() => {
MessageAction.addButton({
Expand All @@ -14,9 +13,8 @@ Meteor.startup(() => {
label: 'Copy_link',
// classes: 'clipboard',
context: ['starred', 'threads', 'videoconf-threads'],
async action(_, props) {
async action(_, { message }) {
try {
const { message = messageArgs(this).msg } = props;
const permalink = await getPermaLink(message._id);
navigator.clipboard.writeText(permalink);
dispatchToastMessage({ type: 'success', message: t('Copied') });
Expand Down
4 changes: 1 addition & 3 deletions apps/meteor/client/startup/actionButtons/pinMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { imperativeModal } from '../../lib/imperativeModal';
import { queryClient } from '../../lib/queryClient';
import { roomCoordinator } from '../../lib/rooms/roomCoordinator';
import { dispatchToastMessage } from '../../lib/toast';
import { messageArgs } from '../../lib/utils/messageArgs';
import PinMessageModal from '../../views/room/modals/PinMessageModal';

Meteor.startup(() => {
Expand All @@ -18,8 +17,7 @@ Meteor.startup(() => {
label: 'Pin',
type: 'interaction',
context: ['pinned', 'message', 'message-mobile', 'threads', 'direct', 'videoconf', 'videoconf-threads'],
async action(_, props) {
const { message = messageArgs(this).msg } = props;
async action(_, { message }) {
const onConfirm = async () => {
message.pinned = true;
try {
Expand Down
5 changes: 1 addition & 4 deletions apps/meteor/client/startup/actionButtons/starMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { sdk } from '../../../app/utils/client/lib/SDKClient';
import { queryClient } from '../../lib/queryClient';
import { roomCoordinator } from '../../lib/rooms/roomCoordinator';
import { dispatchToastMessage } from '../../lib/toast';
import { messageArgs } from '../../lib/utils/messageArgs';

Meteor.startup(() => {
MessageAction.addButton({
Expand All @@ -15,9 +14,7 @@ Meteor.startup(() => {
label: 'Star',
type: 'interaction',
context: ['starred', 'message', 'message-mobile', 'threads', 'federated', 'videoconf', 'videoconf-threads'],
async action(_, props) {
const { message = messageArgs(this).msg } = props;

async action(_, { message }) {
try {
await sdk.call('starMessage', { ...message, starred: true });
queryClient.invalidateQueries(['rooms', message.rid, 'starred-messages']);
Expand Down
Loading

0 comments on commit 971249b

Please sign in to comment.