Client: Add enter/leave room handlers

This commit is contained in:
Aleksandr Lushkin 2024-08-14 16:17:04 +02:00
parent 193c5f3fa9
commit ac8e3fbbeb
5 changed files with 77 additions and 1 deletions

View File

@ -33,3 +33,4 @@ export { default as useSettings } from "./useSettings";
export { default as usePublic } from "./usePublic";
export { default as useInsideGroup } from "./useInsideGroup";
export { default as useAccountsHotkeys } from "./useAccountsHotkeys";
export { default as useEnterLeaveRoom } from "./useEnterLeaveRoom";

View File

@ -0,0 +1,48 @@
// (c) Copyright Ascensio System SIA 2009-2024
//
// This program is a free software product.
// You can redistribute it and/or modify it under the terms
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
// any third-party rights.
//
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
//
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
//
// The interactive user interfaces in modified source and object code versions of the Program must
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
//
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
// trademark law for use of our trademarks.
//
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
import { useEffect } from "react";
import SelectedFolderStore from "SRC_DIR/store/SelectedFolderStore";
const useEnterLeaveRoom = (selectedFolderStore: SelectedFolderStore) => {
const { currentRoomId, enterRoom, leaveRoom } = selectedFolderStore;
useEffect(() => {
const roomId = currentRoomId;
if (roomId) {
enterRoom(roomId);
}
return () => {
if (roomId) {
leaveRoom(roomId);
}
};
}, [currentRoomId, enterRoom, leaveRoom]);
};
export default useEnterLeaveRoom;

View File

@ -58,6 +58,7 @@ import {
useSettings,
useGroups,
useInsideGroup,
useEnterLeaveRoom,
} from "./Hooks";
const PureHome = (props) => {
@ -299,6 +300,8 @@ const PureHome = (props) => {
isLoading,
});
useEnterLeaveRoom(selectedFolderStore);
const getContextModel = () => {
if (isFrame) return null;
return getFolderModel(t, true);

View File

@ -200,6 +200,12 @@ class SelectedFolderStore {
return this.pathParts && this.pathParts.length <= 1;
}
get currentRoomId() {
if (!this.inRoom || !this.pathParts[1]) return null;
return this.pathParts[1].id;
}
toDefault = () => {
this.folders = null;
this.parentId = 0;
@ -358,6 +364,24 @@ class SelectedFolderStore {
if (value.roomType) this.setInRoom(true);
});
};
enterRoom = (roomId: number) => {
const { socketHelper } = this.settingsStore;
socketHelper.emit({
command: "enterInRoom",
data: { roomPart: roomId },
});
};
leaveRoom = (roomId: number) => {
const { socketHelper } = this.settingsStore;
socketHelper.emit({
command: "leaveRoom",
data: { roomPart: roomId },
});
};
}
export default SelectedFolderStore;

View File

@ -59,7 +59,7 @@ export type TOptSocket = {
export type TEmit = {
command: string;
data: { roomParts: string | []; individual?: boolean };
data: { roomParts?: string | []; roomPart?: number; individual?: boolean };
room?: null | boolean;
};