Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Remove method calls - Stage 1 #26149

Merged
merged 30 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
549e38a
remove method calls for room menu component
ggazzo Jul 6, 2022
0c2a0a6
Merge remote-tracking branch 'origin/develop' into chore/remove-metho…
ggazzo Jul 8, 2022
4200410
Chore: Remove setUserStatus method call (#26186)
yash-rajpal Jul 8, 2022
60ab310
Chore: Remove custom user status method calls (#26191)
yash-rajpal Jul 8, 2022
5ebc759
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into chor…
ggazzo Jul 8, 2022
36ba7de
Merge branch 'chore/remove-method-call' of github.com:RocketChat/Rock…
ggazzo Jul 8, 2022
8b99366
Chore: Remove meteor call on AccountBox (#26202)
Jul 8, 2022
72f0c73
Chore: useMethod remove - AssetSettingInput (#26198)
juliajforesti Jul 11, 2022
9531e08
Chore: useMethod remove - InformationRoute (#26189)
juliajforesti Jul 11, 2022
04de2fd
Merge branch 'develop' into chore/remove-method-call
ggazzo Jul 22, 2022
c2721ed
rooms.saveRoomSettings'
ggazzo Jul 26, 2022
056c9b7
spotlight
ggazzo Jul 26, 2022
89d1733
Merge branch 'chore/remove-method-call' of github.com:RocketChat/Rock…
ggazzo Jul 26, 2022
40cd2a5
ci
ggazzo Jul 26, 2022
7282ca3
misc
ggazzo Jul 29, 2022
d986245
Merge remote-tracking branch 'origin/develop' into chore/remove-metho…
ggazzo Jul 29, 2022
cb4261c
Chore: Replace `useMethodData` (#26208)
tassoevan Jul 29, 2022
e470fb3
Merge branch 'develop' into chore/remove-method-call
ggazzo Aug 5, 2022
274a1ef
Merge remote-tracking branch 'origin/develop' into chore/remove-metho…
ggazzo Aug 5, 2022
330c936
Merge branch 'chore/remove-method-call' of github.com:RocketChat/Rock…
ggazzo Aug 5, 2022
2178f71
lint
ggazzo Aug 5, 2022
a83205e
remove is idle react query
ggazzo Aug 6, 2022
edfa621
Merge remote-tracking branch 'origin/develop' into chore/remove-metho…
ggazzo Aug 8, 2022
fce2d9c
FacebookPageContainer
ggazzo Aug 8, 2022
1192548
undo SettingsProvider
ggazzo Aug 9, 2022
a315927
Merge remote-tracking branch 'origin/develop' into chore/remove-metho…
ggazzo Aug 9, 2022
20470cb
Merge remote-tracking branch 'origin/develop' into chore/remove-metho…
ggazzo Aug 9, 2022
0e73eab
Merge branch 'develop' into chore/remove-method-call
ggazzo Aug 10, 2022
5df00d0
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into chor…
tassoevan Aug 12, 2022
ceb9a7b
Merge branch 'develop' into chore/remove-method-call
kodiakhq[bot] Aug 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions apps/meteor/app/api/server/v1/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,25 @@ API.v1.addRoute(
{ authRequired: true },
{
async post() {
const [asset, { refreshAllClients }, assetName] = await getUploadFormData({
request: this.request,
});
const [asset, { refreshAllClients, assetName: customName }, fileName] = await getUploadFormData(
{
request: this.request,
},
{ field: 'asset' },
);

const assetName = customName || fileName;
const assetsKeys = Object.keys(RocketChatAssets.assets);

const isValidAsset = assetsKeys.includes(assetName);
if (!isValidAsset) {
throw new Meteor.Error('error-invalid-asset', 'Invalid asset');
}

Meteor.runAsUser(this.userId, () => {
Meteor.call('setAsset', asset.fileBuffer, asset.mimetype, assetName);
if (refreshAllClients) {
Meteor.call('refreshClients');
}
});
Meteor.call('setAsset', asset.fileBuffer, asset.mimetype, assetName);
if (refreshAllClients) {
Meteor.call('refreshClients');
}

return API.v1.success();
},
Expand Down
6 changes: 3 additions & 3 deletions apps/meteor/app/e2e/client/tabbar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo, useCallback } from 'react';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useSetting, usePermission, useMethod } from '@rocket.chat/ui-contexts';
import { useSetting, usePermission, useEndpoint } from '@rocket.chat/ui-contexts';

import { addAction } from '../../../client/views/room/lib/Toolbox';
import { useReactiveValue } from '../../../client/hooks/useReactiveValue';
Expand All @@ -13,10 +13,10 @@ addAction('e2e', ({ room }) => {
const canEditRoom = usePermission('edit-room', room._id);
const hasPermission = (room.t === 'd' || (canEditRoom && canToggleE2e)) && e2eReady;

const toggleE2E = useMethod('saveRoomSettings');
const toggleE2E = useEndpoint('POST', '/v1/rooms.saveRoomSettings');

const action = useMutableCallback(() => {
toggleE2E(room._id, 'encrypted', !room.encrypted);
toggleE2E({ rid: room._id, encrypted: !room.encrypted });
});

const enabledOnRoom = !!room.encrypted;
Expand Down
7 changes: 4 additions & 3 deletions apps/meteor/app/ui-utils/client/lib/AccountBox.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { IUIActionButton, IUActionButtonWhen } from '@rocket.chat/apps-engine/definition/ui/IUIActionButtonDescriptor';
import type { UserStatus } from '@rocket.chat/core-typings';
import { ReactiveVar } from 'meteor/reactive-var';
import { Tracker } from 'meteor/tracker';
import { Meteor } from 'meteor/meteor';

import { SideNav } from './SideNav';
import { applyDropdownActionButtonFilters } from '../../../ui-message/client/actionButtons/lib/applyButtonFilters';
import { APIClient } from '../../../utils/client';

export interface IAppAccountBoxItem extends IUIActionButton {
name: string;
Expand All @@ -31,8 +32,8 @@ export class AccountBoxBase {

private status = 0;

public setStatus(status: number, statusText: string): any {
return Meteor.call('setUserStatus', status, statusText);
public setStatus(status: UserStatus, statusText: string): any {
return APIClient.post('/v1/users.setStatus', { status, message: statusText });
}

public open(): void {
Expand Down
38 changes: 0 additions & 38 deletions apps/meteor/client/hooks/useMethodData.ts

This file was deleted.

29 changes: 0 additions & 29 deletions apps/meteor/client/hooks/usePolledMethodData.ts

This file was deleted.

36 changes: 28 additions & 8 deletions apps/meteor/client/sidebar/RoomMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
useTranslation,
TranslationKey,
Fields,
useEndpoint,
} from '@rocket.chat/ui-contexts';
import React, { memo, ReactElement, useMemo } from 'react';

Expand Down Expand Up @@ -39,6 +40,24 @@ type RoomMenuProps = {
name?: string;
};

const closeEndpoints = {
p: '/v1/groups.close',
c: '/v1/channels.close',
d: '/v1/im.close',

v: '/v1/channels.close',
l: '/v1/groups.close',
} as const;

const leaveEndpoints = {
p: '/v1/groups.leave',
c: '/v1/channels.leave',
d: '/v1/im.leave',

v: '/v1/channels.leave',
l: '/v1/groups.leave',
} as const;

const RoomMenu = ({ rid, unread, threadUnread, alert, roomOpen, type, cl, name = '' }: RoomMenuProps): ReactElement => {
const t = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();
Expand All @@ -54,11 +73,12 @@ const RoomMenu = ({ rid, unread, threadUnread, alert, roomOpen, type, cl, name =

const dontAskHideRoom = useDontAskAgain('hideRoom');

const hideRoom = useMethod('hideRoom');
const readMessages = useMethod('readMessages');
const hideRoom = useEndpoint('POST', closeEndpoints[type]);
const readMessages = useEndpoint('POST', '/v1/subscriptions.read');
const toggleFavorite = useEndpoint('POST', '/v1/rooms.favorite');
const leaveRoom = useEndpoint('POST', leaveEndpoints[type]);

const unreadMessages = useMethod('unreadMessages');
const toggleFavorite = useMethod('toggleFavorite');
const leaveRoom = useMethod('leaveRoom');

const isUnread = alert || unread || threadUnread;

Expand All @@ -78,7 +98,7 @@ const RoomMenu = ({ rid, unread, threadUnread, alert, roomOpen, type, cl, name =
const handleLeave = useMutableCallback(() => {
const leave = async (): Promise<void> => {
try {
await leaveRoom(rid);
await leaveRoom({ roomId: rid });
if (roomOpen) {
router.push({});
}
Expand Down Expand Up @@ -106,7 +126,7 @@ const RoomMenu = ({ rid, unread, threadUnread, alert, roomOpen, type, cl, name =
const handleHide = useMutableCallback(async () => {
const hide = async (): Promise<void> => {
try {
await hideRoom(rid);
await hideRoom({ roomId: rid });
} catch (error) {
dispatchToastMessage({ type: 'error', message: String(error) });
}
Expand Down Expand Up @@ -140,7 +160,7 @@ const RoomMenu = ({ rid, unread, threadUnread, alert, roomOpen, type, cl, name =
const handleToggleRead = useMutableCallback(async () => {
try {
if (isUnread) {
await readMessages(rid);
await readMessages({ rid });
return;
}
await unreadMessages(null, rid);
Expand All @@ -157,7 +177,7 @@ const RoomMenu = ({ rid, unread, threadUnread, alert, roomOpen, type, cl, name =

const handleToggleFavorite = useMutableCallback(async () => {
try {
await toggleFavorite(rid, !isFavorite);
await toggleFavorite({ roomId: rid, favorite: !isFavorite });
} catch (error) {
dispatchToastMessage({ type: 'error', message: String(error) });
}
Expand Down
9 changes: 5 additions & 4 deletions apps/meteor/client/sidebar/header/EditStatusModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { IUser } from '@rocket.chat/core-typings';
import { Field, TextInput, FieldGroup, Modal, Button } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useToastMessageDispatch, useSetting, useMethod, useTranslation } from '@rocket.chat/ui-contexts';
import { useToastMessageDispatch, useSetting, useTranslation, useEndpoint } from '@rocket.chat/ui-contexts';
import React, { ReactElement, useState, ChangeEvent, useCallback } from 'react';

import UserStatusMenu from '../../components/UserStatusMenu';
Expand All @@ -15,14 +15,15 @@ type EditStatusModalProps = {

const EditStatusModal = ({ onClose, userStatus, userStatusText }: EditStatusModalProps): ReactElement => {
const allowUserStatusMessageChange = useSetting('Accounts_AllowUserStatusMessageChange');
const setUserStatus = useMethod('setUserStatus');
const dispatchToastMessage = useToastMessageDispatch();

const t = useTranslation();
const [statusText, setStatusText] = useState(userStatusText);
const [statusType, setStatusType] = useState(userStatus);
const [statusTextError, setStatusTextError] = useState<string | undefined>();

const setUserStatus = useEndpoint('POST', '/v1/users.setStatus');

const handleStatusText = useMutableCallback((e: ChangeEvent<HTMLInputElement>): void => {
setStatusText(e.currentTarget.value);

Expand All @@ -37,14 +38,14 @@ const EditStatusModal = ({ onClose, userStatus, userStatusText }: EditStatusModa

const handleSaveStatus = useCallback(async () => {
try {
await setUserStatus(statusType, statusText);
await setUserStatus({ message: statusText, status: statusType });
dispatchToastMessage({ type: 'success', message: t('StatusMessage_Changed_Successfully') });
} catch (error) {
dispatchToastMessage({ type: 'error', message: String(error) });
}

onClose();
}, [dispatchToastMessage, statusType, statusText, setUserStatus, onClose, t]);
}, [dispatchToastMessage, setUserStatus, statusText, statusType, onClose, t]);

return (
<Modal>
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/sidebar/header/UserDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const isDefaultStatus = (id: string): boolean => (Object.values(UserStatusEnum)
const isDefaultStatusName = (_name: string, id: string): _name is UserStatusEnum => isDefaultStatus(id);

const setStatus = (status: typeof userStatus.list['']): void => {
AccountBox.setStatus(status.statusType as unknown as number, !isDefaultStatus(status.id) ? status.name : '');
AccountBox.setStatus(status.statusType, !isDefaultStatus(status.id) ? status.name : '');
callbacks.run('userStatusManuallySet', status);
};

Expand Down
Loading