From be69658df69e2e80763588c8f8209a0ea7c18453 Mon Sep 17 00:00:00 2001 From: Abhinav Kumar Date: Sat, 17 Aug 2024 06:19:00 +0530 Subject: [PATCH] chore!: removed reportMessage method (#32633) --- .../ReportMessageModal/ReportMessageModal.tsx | 6 +- apps/meteor/server/methods/index.ts | 1 - apps/meteor/server/methods/reportMessage.ts | 97 ------------------- 3 files changed, 3 insertions(+), 101 deletions(-) delete mode 100644 apps/meteor/server/methods/reportMessage.ts diff --git a/apps/meteor/client/views/room/modals/ReportMessageModal/ReportMessageModal.tsx b/apps/meteor/client/views/room/modals/ReportMessageModal/ReportMessageModal.tsx index 1bf96c910a5a..4a4fc5c0c2da 100644 --- a/apps/meteor/client/views/room/modals/ReportMessageModal/ReportMessageModal.tsx +++ b/apps/meteor/client/views/room/modals/ReportMessageModal/ReportMessageModal.tsx @@ -1,7 +1,7 @@ import type { IMessage } from '@rocket.chat/core-typings'; import { css } from '@rocket.chat/css-in-js'; import { TextAreaInput, FieldGroup, Field, FieldRow, FieldError, Box } from '@rocket.chat/fuselage'; -import { useToastMessageDispatch, useTranslation, useMethod } from '@rocket.chat/ui-contexts'; +import { useToastMessageDispatch, useTranslation, useEndpoint } from '@rocket.chat/ui-contexts'; import type { ReactElement } from 'react'; import React from 'react'; import { useForm } from 'react-hook-form'; @@ -31,13 +31,13 @@ const ReportMessageModal = ({ message, onClose }: ReportMessageModalProps): Reac handleSubmit, } = useForm(); const dispatchToastMessage = useToastMessageDispatch(); - const reportMessage = useMethod('reportMessage'); + const reportMessage = useEndpoint('POST', '/v1/chat.reportMessage'); const { _id } = message; const handleReportMessage = async ({ description }: ReportMessageModalsFields): Promise => { try { - await reportMessage(_id, description); + await reportMessage({ messageId: _id, description }); dispatchToastMessage({ type: 'success', message: t('Report_has_been_sent') }); } catch (error) { dispatchToastMessage({ type: 'error', message: error }); diff --git a/apps/meteor/server/methods/index.ts b/apps/meteor/server/methods/index.ts index 8182c10f5008..6ae87421c11a 100644 --- a/apps/meteor/server/methods/index.ts +++ b/apps/meteor/server/methods/index.ts @@ -38,7 +38,6 @@ import './removeRoomLeader'; import './removeRoomModerator'; import './removeRoomOwner'; import './removeUserFromRoom'; -import './reportMessage'; import './requestDataDownload'; import './resetAvatar'; import './saveUserPreferences'; diff --git a/apps/meteor/server/methods/reportMessage.ts b/apps/meteor/server/methods/reportMessage.ts deleted file mode 100644 index a2a1deca45fa..000000000000 --- a/apps/meteor/server/methods/reportMessage.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { Apps, AppEvents } from '@rocket.chat/apps'; -import type { IMessage } from '@rocket.chat/core-typings'; -import type { ServerMethods } from '@rocket.chat/ddp-client'; -import { ModerationReports, Rooms, Users, Messages } from '@rocket.chat/models'; -import { check } from 'meteor/check'; -import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; -import { Meteor } from 'meteor/meteor'; - -import { canAccessRoomAsync } from '../../app/authorization/server/functions/canAccessRoom'; -import { methodDeprecationLogger } from '../../app/lib/server/lib/deprecationWarningLogger'; - -declare module '@rocket.chat/ddp-client' { - // eslint-disable-next-line @typescript-eslint/naming-convention - interface ServerMethods { - reportMessage(messageId: IMessage['_id'], description: string): Promise; - } -} - -Meteor.methods({ - async reportMessage(messageId, description) { - methodDeprecationLogger.method('reportMessage', '7.0.0'); - - check(messageId, String); - check(description, String); - - const uid = Meteor.userId(); - - if (!uid) { - throw new Meteor.Error('error-invalid-user', 'Invalid user', { - method: 'reportMessage', - }); - } - - const user = await Users.findOneById(uid); - - if (!user) { - throw new Meteor.Error('error-invalid-user', 'Invalid user', { - method: 'reportMessage', - }); - } - - if (description == null || description.trim() === '') { - throw new Meteor.Error('error-invalid-description', 'Invalid description', { - method: 'reportMessage', - }); - } - - const message = await Messages.findOneById(messageId); - if (!message) { - throw new Meteor.Error('error-invalid-message_id', 'Invalid message id', { - method: 'reportMessage', - }); - } - - const { rid } = message; - // If the user can't access the room where the message is, report that the message id is invalid - const room = await Rooms.findOneById(rid); - if (!room || !(await canAccessRoomAsync(room, { _id: user._id }))) { - throw new Meteor.Error('error-invalid-message_id', 'Invalid message id', { - method: 'reportMessage', - }); - } - - const reportedBy = { - _id: user._id, - username: user.username, - name: user.name, - createdAt: user.createdAt, - }; - - const roomInfo = { - _id: rid, - name: room.name, - t: room.t, - federated: room.federated, - fname: room.fname, - }; - - await ModerationReports.createWithMessageDescriptionAndUserId(message, description, roomInfo, reportedBy); - - await Apps.self?.triggerEvent(AppEvents.IPostMessageReported, message, await Meteor.userAsync(), description); - - return true; - }, -}); - -DDPRateLimiter.addRule( - { - type: 'method', - name: 'reportMessage', - userId() { - return true; - }, - }, - 5, - 60000, -);