group list optimizations

This commit is contained in:
PhilReact 2025-04-29 17:27:14 +03:00
parent 8bc414356a
commit 6ee01a4ec3
9 changed files with 937 additions and 740 deletions

View File

@ -1,15 +1,15 @@
import type { CapacitorConfig } from '@capacitor/cli'; import type { CapacitorConfig } from "@capacitor/cli";
const config: CapacitorConfig = { const config: CapacitorConfig = {
appId: 'org.Qortal.Qortal-Hub', appId: "org.Qortal.Qortal-Hub",
appName: 'Qortal-Hub', appName: "Qortal-Hub",
webDir: 'dist', webDir: "dist",
"plugins": { plugins: {
"LocalNotifications": { LocalNotifications: {
"smallIcon": "qort", smallIcon: "qort",
"iconColor": "#09b6e8" iconColor: "#09b6e8",
} },
} },
}; };
export default config; export default config;

View File

@ -100,6 +100,8 @@ import { useRecoilState, useResetRecoilState, useSetRecoilState } from 'recoil';
import { import {
canSaveSettingToQdnAtom, canSaveSettingToQdnAtom,
enabledDevModeAtom, enabledDevModeAtom,
groupAnnouncementsAtom,
groupChatTimestampsAtom,
groupsOwnerNamesAtom, groupsOwnerNamesAtom,
groupsPropertiesAtom, groupsPropertiesAtom,
hasSettingsChangedAtom, hasSettingsChangedAtom,
@ -107,11 +109,13 @@ import {
isUsingImportExportSettingsAtom, isUsingImportExportSettingsAtom,
lastPaymentSeenTimestampAtom, lastPaymentSeenTimestampAtom,
mailsAtom, mailsAtom,
mutedGroupsAtom,
oldPinnedAppsAtom, oldPinnedAppsAtom,
qMailLastEnteredTimestampAtom, qMailLastEnteredTimestampAtom,
settingsLocalLastUpdatedAtom, settingsLocalLastUpdatedAtom,
settingsQDNLastUpdatedAtom, settingsQDNLastUpdatedAtom,
sortablePinnedAppsAtom, sortablePinnedAppsAtom,
timestampEnterDataAtom,
} from './atoms/global'; } from './atoms/global';
import { NotAuthenticated } from './ExtStates/NotAuthenticated'; import { NotAuthenticated } from './ExtStates/NotAuthenticated';
import { handleGetFileFromIndexedDB } from './utils/indexedDB'; import { handleGetFileFromIndexedDB } from './utils/indexedDB';
@ -479,6 +483,15 @@ function App() {
lastPaymentSeenTimestampAtom lastPaymentSeenTimestampAtom
); );
const resetGroupsOwnerNamesAtom = useResetRecoilState(groupsOwnerNamesAtom); const resetGroupsOwnerNamesAtom = useResetRecoilState(groupsOwnerNamesAtom);
const resetGroupAnnouncementsAtom = useResetRecoilState(
groupAnnouncementsAtom
);
const resetMutedGroupsAtom = useResetRecoilState(mutedGroupsAtom);
const resetGroupChatTimestampsAtom = useResetRecoilState(
groupChatTimestampsAtom
);
const resetTimestampEnterAtom = useResetRecoilState(timestampEnterDataAtom);
const resetAllRecoil = () => { const resetAllRecoil = () => {
resetAtomSortablePinnedAppsAtom(); resetAtomSortablePinnedAppsAtom();
@ -492,6 +505,10 @@ function App() {
resetGroupPropertiesAtom(); resetGroupPropertiesAtom();
resetLastPaymentSeenTimestampAtom(); resetLastPaymentSeenTimestampAtom();
resetGroupsOwnerNamesAtom(); resetGroupsOwnerNamesAtom();
resetGroupAnnouncementsAtom();
resetMutedGroupsAtom();
resetGroupChatTimestampsAtom();
resetTimestampEnterAtom();
}; };
const handleSetGlobalApikey = (key) => { const handleSetGlobalApikey = (key) => {

View File

@ -201,3 +201,73 @@ export const isOpenBlockedModalAtom = atom({
key: 'isOpenBlockedModalAtom', key: 'isOpenBlockedModalAtom',
default: false, default: false,
}); });
export const groupsOwnerNamesSelector = selectorFamily({
key: 'groupsOwnerNamesSelector',
get:
(key) =>
({ get }) => {
const data = get(groupsOwnerNamesAtom);
return data[key] || null; // Return the value for the key or null if not found
},
});
export const groupAnnouncementsAtom = atom({
key: 'groupAnnouncementsAtom',
default: {},
});
export const groupAnnouncementSelector = selectorFamily({
key: 'groupAnnouncementSelector',
get:
(key) =>
({ get }) => {
const data = get(groupAnnouncementsAtom);
return data[key] || null; // Return the value for the key or null if not found
},
});
export const groupPropertySelector = selectorFamily({
key: 'groupPropertySelector',
get:
(key) =>
({ get }) => {
const data = get(groupsPropertiesAtom);
return data[key] || null; // Return the value for the key or null if not found
},
});
export const mutedGroupsAtom = atom({
key: 'mutedGroupsAtom',
default: [],
});
export const groupChatTimestampsAtom = atom({
key: 'groupChatTimestampsAtom',
default: {},
});
export const groupChatTimestampSelector = selectorFamily({
key: 'groupChatTimestampSelector',
get:
(key) =>
({ get }) => {
const data = get(groupChatTimestampsAtom);
return data[key] || null; // Return the value for the key or null if not found
},
});
export const timestampEnterDataAtom = atom({
key: 'timestampEnterDataAtom',
default: {},
});
export const timestampEnterDataSelector = selectorFamily({
key: 'timestampEnterDataSelector',
get:
(key) =>
({ get }) => {
const data = get(timestampEnterDataAtom);
return data[key] || null; // Return the value for the key or null if not found
},
});

View File

@ -75,6 +75,21 @@ const getBadgeImg = (level) => {
} }
}; };
const UserBadge = React.memo(({ userInfo }) => {
return (
<Tooltip disableFocusListener title={`level ${userInfo ?? 0}`}>
<img
style={{
visibility: userInfo !== undefined ? 'visible' : 'hidden',
width: '30px',
height: 'auto',
}}
src={getBadgeImg(userInfo)}
/>
</Tooltip>
);
});
export const MessageItem = React.memo( export const MessageItem = React.memo(
({ ({
message, message,
@ -210,16 +225,7 @@ export const MessageItem = React.memo(
{message?.senderName?.charAt(0)} {message?.senderName?.charAt(0)}
</Avatar> </Avatar>
</WrapperUserAction> </WrapperUserAction>
<Tooltip disableFocusListener title={`level ${userInfo ?? 0}`}> <UserBadge userInfo={userInfo} />
<img
style={{
visibility: userInfo !== undefined ? 'visible' : 'hidden',
width: '30px',
height: 'auto',
}}
src={getBadgeImg(userInfo)}
/>
</Tooltip>
</Box> </Box>
)} )}

View File

@ -1,4 +1,4 @@
import { useCallback, useEffect, useMemo, useRef } from 'react'; import React, { useCallback, useEffect, useMemo, useRef } from 'react';
import { EditorProvider, useCurrentEditor } from '@tiptap/react'; import { EditorProvider, useCurrentEditor } from '@tiptap/react';
import StarterKit from '@tiptap/starter-kit'; import StarterKit from '@tiptap/starter-kit';
import { Color } from '@tiptap/extension-color'; import { Color } from '@tiptap/extension-color';
@ -41,26 +41,27 @@ function textMatcher(doc, from) {
return { start, query }; return { start, query };
} }
const MenuBar = ({ const MenuBar = React.memo(
({
setEditorRef, setEditorRef,
isChat, isChat,
isDisabledEditorEnter, isDisabledEditorEnter,
setIsDisabledEditorEnter, setIsDisabledEditorEnter,
}) => { }) => {
const { editor } = useCurrentEditor(); const { editor } = useCurrentEditor();
const fileInputRef = useRef(null); const fileInputRef = useRef(null);
const theme = useTheme(); const theme = useTheme();
if (!editor) {
return null;
}
useEffect(() => { useEffect(() => {
if (editor && setEditorRef) { if (editor && setEditorRef) {
setEditorRef(editor); setEditorRef(editor);
} }
}, [editor, setEditorRef]); }, [editor, setEditorRef]);
if (!editor) {
return null;
}
const handleImageUpload = async (file) => { const handleImageUpload = async (file) => {
let compressedFile; let compressedFile;
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
@ -329,7 +330,8 @@ const MenuBar = ({
</div> </div>
</div> </div>
); );
}; }
);
const extensions = [ const extensions = [
Color.configure({ types: [TextStyle.name, ListItem.name] }), Color.configure({ types: [TextStyle.name, ListItem.name] }),
@ -373,10 +375,10 @@ export default ({
? extensions.filter((item) => item?.name !== 'image') ? extensions.filter((item) => item?.name !== 'image')
: extensions; : extensions;
const editorRef = useRef(null); const editorRef = useRef(null);
const setEditorRefFunc = (editorInstance) => { const setEditorRefFunc = useCallback((editorInstance) => {
editorRef.current = editorInstance; editorRef.current = editorInstance;
setEditorRef(editorInstance); setEditorRef(editorInstance);
}; }, []);
// const users = [ // const users = [
// { id: 1, label: 'Alice' }, // { id: 1, label: 'Alice' },

View File

@ -10,6 +10,8 @@ import {
import MailOutlineIcon from '@mui/icons-material/MailOutline'; import MailOutlineIcon from '@mui/icons-material/MailOutline';
import NotificationsOffIcon from '@mui/icons-material/NotificationsOff'; import NotificationsOffIcon from '@mui/icons-material/NotificationsOff';
import { executeEvent } from '../utils/events'; import { executeEvent } from '../utils/events';
import { useRecoilState } from 'recoil';
import { mutedGroupsAtom } from '../atoms/global';
const CustomStyledMenu = styled(Menu)(({ theme }) => ({ const CustomStyledMenu = styled(Menu)(({ theme }) => ({
'& .MuiPaper-root': { '& .MuiPaper-root': {
@ -28,16 +30,12 @@ const CustomStyledMenu = styled(Menu)(({ theme }) => ({
}, },
})); }));
export const ContextMenu = ({ export const ContextMenu = ({ children, groupId, getUserSettings }) => {
children,
groupId,
getUserSettings,
mutedGroups,
}) => {
const [menuPosition, setMenuPosition] = useState(null); const [menuPosition, setMenuPosition] = useState(null);
const longPressTimeout = useRef(null); const longPressTimeout = useRef(null);
const preventClick = useRef(false); // Flag to prevent click after long-press or right-click const preventClick = useRef(false); // Flag to prevent click after long-press or right-click
const theme = useTheme(); const theme = useTheme();
const [mutedGroups] = useRecoilState(mutedGroupsAtom);
const isMuted = useMemo(() => { const isMuted = useMemo(() => {
return mutedGroups.includes(groupId); return mutedGroups.includes(groupId);
}, [mutedGroups, groupId]); }, [mutedGroups, groupId]);

View File

@ -199,6 +199,8 @@ export const AddGroup = ({ address, open, setOpen }) => {
}; };
}, []); }, []);
if (!open) return null;
return ( return (
<Fragment> <Fragment>
<Dialog <Dialog

View File

@ -68,10 +68,14 @@ import { AdminSpace } from '../Chat/AdminSpace';
import { useRecoilState, useSetRecoilState } from 'recoil'; import { useRecoilState, useSetRecoilState } from 'recoil';
import { import {
addressInfoControllerAtom, addressInfoControllerAtom,
groupAnnouncementsAtom,
groupChatTimestampsAtom,
groupsOwnerNamesAtom, groupsOwnerNamesAtom,
groupsPropertiesAtom, groupsPropertiesAtom,
isOpenBlockedModalAtom, isOpenBlockedModalAtom,
mutedGroupsAtom,
selectedGroupIdAtom, selectedGroupIdAtom,
timestampEnterDataAtom,
} from '../../atoms/global'; } from '../../atoms/global';
import { sortArrayByTimestampAndGroupName } from '../../utils/time'; import { sortArrayByTimestampAndGroupName } from '../../utils/time';
import PersonOffIcon from '@mui/icons-material/PersonOff'; import PersonOffIcon from '@mui/icons-material/PersonOff';
@ -80,6 +84,7 @@ import NoEncryptionGmailerrorredIcon from '@mui/icons-material/NoEncryptionGmail
import { BlockedUsersModal } from './BlockedUsersModal'; import { BlockedUsersModal } from './BlockedUsersModal';
import { WalletsAppWrapper } from './WalletsAppWrapper'; import { WalletsAppWrapper } from './WalletsAppWrapper';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { GroupList } from './GroupList';
export const getPublishesFromAdmins = async (admins: string[], groupId) => { export const getPublishesFromAdmins = async (admins: string[], groupId) => {
const queryString = admins.map((name) => `name=${name}`).join('&'); const queryString = admins.map((name) => `name=${name}`).join('&');
@ -117,7 +122,7 @@ interface GroupProps {
balance: number; balance: number;
} }
const timeDifferenceForNotificationChats = 900000; export const timeDifferenceForNotificationChats = 900000;
export const requestQueueMemberNames = new RequestQueueWithPromise(5); export const requestQueueMemberNames = new RequestQueueWithPromise(5);
export const requestQueueAdminMemberNames = new RequestQueueWithPromise(5); export const requestQueueAdminMemberNames = new RequestQueueWithPromise(5);
@ -410,7 +415,9 @@ export const Group = ({
const { setMemberGroups, rootHeight, isRunningPublicNode } = const { setMemberGroups, rootHeight, isRunningPublicNode } =
useContext(MyContext); useContext(MyContext);
const lastGroupNotification = useRef<null | number>(null); const lastGroupNotification = useRef<null | number>(null);
const [timestampEnterData, setTimestampEnterData] = useState({}); const [timestampEnterData, setTimestampEnterData] = useRecoilState(
timestampEnterDataAtom
);
const [chatMode, setChatMode] = useState('groups'); const [chatMode, setChatMode] = useState('groups');
const [newChat, setNewChat] = useState(false); const [newChat, setNewChat] = useState(false);
const [openSnack, setOpenSnack] = React.useState(false); const [openSnack, setOpenSnack] = React.useState(false);
@ -421,7 +428,10 @@ export const Group = ({
const [firstSecretKeyInCreation, setFirstSecretKeyInCreation] = const [firstSecretKeyInCreation, setFirstSecretKeyInCreation] =
React.useState(false); React.useState(false);
const [groupSection, setGroupSection] = React.useState('home'); const [groupSection, setGroupSection] = React.useState('home');
const [groupAnnouncements, setGroupAnnouncements] = React.useState({}); const [groupAnnouncements, setGroupAnnouncements] = useRecoilState(
groupAnnouncementsAtom
);
const [defaultThread, setDefaultThread] = React.useState(null); const [defaultThread, setDefaultThread] = React.useState(null);
const [isOpenDrawer, setIsOpenDrawer] = React.useState(false); const [isOpenDrawer, setIsOpenDrawer] = React.useState(false);
const setIsOpenBlockedUserModal = useSetRecoilState(isOpenBlockedModalAtom); const setIsOpenBlockedUserModal = useSetRecoilState(isOpenBlockedModalAtom);
@ -429,7 +439,7 @@ export const Group = ({
const [hideCommonKeyPopup, setHideCommonKeyPopup] = React.useState(false); const [hideCommonKeyPopup, setHideCommonKeyPopup] = React.useState(false);
const [isLoadingGroupMessage, setIsLoadingGroupMessage] = React.useState(''); const [isLoadingGroupMessage, setIsLoadingGroupMessage] = React.useState('');
const [drawerMode, setDrawerMode] = React.useState('groups'); const [drawerMode, setDrawerMode] = React.useState('groups');
const [mutedGroups, setMutedGroups] = useState([]); const setMutedGroups = useSetRecoilState(mutedGroupsAtom);
const [mobileViewMode, setMobileViewMode] = useState('home'); const [mobileViewMode, setMobileViewMode] = useState('home');
const [mobileViewModeKeepOpen, setMobileViewModeKeepOpen] = useState(''); const [mobileViewModeKeepOpen, setMobileViewModeKeepOpen] = useState('');
const isFocusedRef = useRef(true); const isFocusedRef = useRef(true);
@ -443,7 +453,9 @@ export const Group = ({
const settimeoutForRefetchSecretKey = useRef(null); const settimeoutForRefetchSecretKey = useRef(null);
const { clearStatesMessageQueueProvider } = useMessageQueue(); const { clearStatesMessageQueueProvider } = useMessageQueue();
const initiatedGetMembers = useRef(false); const initiatedGetMembers = useRef(false);
const [groupChatTimestamps, setGroupChatTimestamps] = React.useState({}); const [groupChatTimestamps, setGroupChatTimestamps] = useRecoilState(
groupChatTimestampsAtom
);
const [appsMode, setAppsMode] = useState('home'); const [appsMode, setAppsMode] = useState('home');
const [appsModeDev, setAppsModeDev] = useState('home'); const [appsModeDev, setAppsModeDev] = useState('home');
const [isOpenSideViewDirects, setIsOpenSideViewDirects] = useState(false); const [isOpenSideViewDirects, setIsOpenSideViewDirects] = useState(false);
@ -500,7 +512,7 @@ export const Group = ({
selectedDirectRef.current = selectedDirect; selectedDirectRef.current = selectedDirect;
}, [selectedDirect]); }, [selectedDirect]);
const getUserSettings = async () => { const getUserSettings = useCallback(async () => {
try { try {
return new Promise((res, rej) => { return new Promise((res, rej) => {
window window
@ -522,13 +534,13 @@ export const Group = ({
} catch (error) { } catch (error) {
console.log('error', error); console.log('error', error);
} }
}; }, [setMutedGroups]);
useEffect(() => { useEffect(() => {
getUserSettings(); getUserSettings();
}, []); }, [getUserSettings]);
const getTimestampEnterChat = async () => { const getTimestampEnterChat = useCallback(async () => {
try { try {
return new Promise((res, rej) => { return new Promise((res, rej) => {
window window
@ -548,7 +560,7 @@ export const Group = ({
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
}; }, []);
const refreshHomeDataFunc = () => { const refreshHomeDataFunc = () => {
setGroupSection('default'); setGroupSection('default');
@ -650,41 +662,45 @@ export const Group = ({
return hasUnread; return hasUnread;
}, [groupAnnouncements, groups]); }, [groupAnnouncements, groups]);
const getSecretKey = async ( const getSecretKey = useCallback(
loadingGroupParam?: boolean, async (loadingGroupParam?: boolean, secretKeyToPublish?: boolean) => {
secretKeyToPublish?: boolean
) => {
try { try {
setIsLoadingGroupMessage('Locating encryption keys'); setIsLoadingGroupMessage('Locating encryption keys');
pauseAllQueues(); pauseAllQueues();
let dataFromStorage; let dataFromStorage;
let publishFromStorage; let publishFromStorage;
let adminsFromStorage; let adminsFromStorage;
if ( if (
secretKeyToPublish && secretKeyToPublish &&
secretKey && secretKey &&
lastFetchedSecretKey.current && lastFetchedSecretKey.current &&
Date.now() - lastFetchedSecretKey.current < 600000 Date.now() - lastFetchedSecretKey.current < 600000
) ) {
return secretKey; return secretKey;
}
if (loadingGroupParam) { if (loadingGroupParam) {
setIsLoadingGroup(true); setIsLoadingGroup(true);
} }
if (selectedGroup?.groupId !== selectedGroupRef.current.groupId) { if (selectedGroup?.groupId !== selectedGroupRef.current.groupId) {
if (settimeoutForRefetchSecretKey.current) { if (settimeoutForRefetchSecretKey.current) {
clearTimeout(settimeoutForRefetchSecretKey.current); clearTimeout(settimeoutForRefetchSecretKey.current);
} }
return; return;
} }
const prevGroupId = selectedGroupRef.current.groupId; const prevGroupId = selectedGroupRef.current.groupId;
// const validApi = await findUsableApi();
const { names, addresses, both } = const { names, addresses, both } =
adminsFromStorage || (await getGroupAdmins(selectedGroup?.groupId)); adminsFromStorage || (await getGroupAdmins(selectedGroup?.groupId));
setAdmins(addresses); setAdmins(addresses);
setAdminsWithNames(both); setAdminsWithNames(both);
if (!names.length) {
throw new Error('Network error'); if (!names.length) throw new Error('Network error');
}
const publish = const publish =
publishFromStorage || publishFromStorage ||
(await getPublishesFromAdmins(names, selectedGroup?.groupId)); (await getPublishesFromAdmins(names, selectedGroup?.groupId));
@ -695,6 +711,7 @@ export const Group = ({
} }
return; return;
} }
if (publish === false) { if (publish === false) {
setTriedToFetchSecretKey(true); setTriedToFetchSecretKey(true);
settimeoutForRefetchSecretKey.current = setTimeout(() => { settimeoutForRefetchSecretKey.current = setTimeout(() => {
@ -702,29 +719,33 @@ export const Group = ({
}, 120000); }, 120000);
return false; return false;
} }
setSecretKeyPublishDate(publish?.updated || publish?.created); setSecretKeyPublishDate(publish?.updated || publish?.created);
let data; let data;
if (dataFromStorage) { if (dataFromStorage) {
data = dataFromStorage; data = dataFromStorage;
} else { } else {
// const shouldRebuild = !secretKeyPublishDate || (publish?.update && publish?.updated > secretKeyPublishDate)
setIsLoadingGroupMessage('Downloading encryption keys'); setIsLoadingGroupMessage('Downloading encryption keys');
const res = await fetch( const res = await fetch(
`${getBaseApiReact()}/arbitrary/DOCUMENT_PRIVATE/${publish.name}/${ `${getBaseApiReact()}/arbitrary/DOCUMENT_PRIVATE/${publish.name}/${publish.identifier}?encoding=base64&rebuild=true`
publish.identifier
}?encoding=base64&rebuild=true`
); );
data = await res.text(); data = await res.text();
} }
const decryptedKey: any = await decryptResource(data); const decryptedKey: any = await decryptResource(data);
const dataint8Array = base64ToUint8Array(decryptedKey.data); const dataint8Array = base64ToUint8Array(decryptedKey.data);
const decryptedKeyToObject = uint8ArrayToObject(dataint8Array); const decryptedKeyToObject = uint8ArrayToObject(dataint8Array);
if (!validateSecretKey(decryptedKeyToObject))
if (!validateSecretKey(decryptedKeyToObject)) {
throw new Error('SecretKey is not valid'); throw new Error('SecretKey is not valid');
}
setSecretKeyDetails(publish); setSecretKeyDetails(publish);
setSecretKey(decryptedKeyToObject); setSecretKey(decryptedKeyToObject);
lastFetchedSecretKey.current = Date.now(); lastFetchedSecretKey.current = Date.now();
setMemberCountFromSecretKeyData(decryptedKey.count); setMemberCountFromSecretKeyData(decryptedKey.count);
window window
.sendMessage('setGroupData', { .sendMessage('setGroupData', {
groupId: selectedGroup?.groupId, groupId: selectedGroup?.groupId,
@ -758,7 +779,22 @@ export const Group = ({
setIsLoadingGroupMessage(''); setIsLoadingGroupMessage('');
resumeAllQueues(); resumeAllQueues();
} }
}; },
[
secretKey,
selectedGroup?.groupId,
setIsLoadingGroup,
setIsLoadingGroupMessage,
setSecretKey,
setSecretKeyDetails,
setTriedToFetchSecretKey,
setFirstSecretKeyInCreation,
setMemberCountFromSecretKeyData,
setAdmins,
setAdminsWithNames,
setSecretKeyPublishDate,
]
);
const getAdminsForPublic = async (selectedGroup) => { const getAdminsForPublic = async (selectedGroup) => {
try { try {
@ -1050,8 +1086,6 @@ export const Group = ({
triedToFetchSecretKey, triedToFetchSecretKey,
]); ]);
console.log('groupOwner?.owner', groupOwner);
const notifyAdmin = async (admin) => { const notifyAdmin = async (admin) => {
try { try {
setIsLoadingNotifyAdmin(true); setIsLoadingNotifyAdmin(true);
@ -1327,8 +1361,6 @@ export const Group = ({
}; };
}, []); }, []);
console.log('selectedGroup', selectedGroup);
const openGroupChatFromNotification = (e) => { const openGroupChatFromNotification = (e) => {
if (isLoadingOpenSectionFromNotification.current) return; if (isLoadingOpenSectionFromNotification.current) return;
@ -1498,9 +1530,9 @@ export const Group = ({
}; };
}, [groups, selectedGroup]); }, [groups, selectedGroup]);
const handleSecretKeyCreationInProgress = () => { const handleSecretKeyCreationInProgress = useCallback(() => {
setFirstSecretKeyInCreation(true); setFirstSecretKeyInCreation(true);
}; }, []);
const goToHome = async () => { const goToHome = async () => {
setDesktopViewMode('home'); setDesktopViewMode('home');
@ -1811,112 +1843,7 @@ export const Group = ({
); );
}; };
const renderGroups = () => { const selectGroupFunc = useCallback((group) => {
return (
<div
style={{
display: 'flex',
width: '380px',
flexDirection: 'column',
alignItems: 'flex-start',
height: '100%',
background: theme.palette.background.surface,
borderRadius: '0px 15px 15px 0px',
padding: '0px 2px',
}}
>
<Box
sx={{
width: '100%',
alignItems: 'center',
justifyContent: 'center',
display: 'flex',
gap: '10px',
}}
>
<ButtonBase
onClick={() => {
setDesktopSideView('groups');
}}
>
<IconWrapper
color={
groupChatHasUnread || groupsAnnHasUnread
? theme.palette.other.unread
: desktopSideView === 'groups'
? theme.palette.text.primary
: theme.palette.text.secondary
}
label="Groups"
selected={desktopSideView === 'groups'}
customWidth="75px"
>
<HubsIcon
height={24}
color={
groupChatHasUnread || groupsAnnHasUnread
? theme.palette.other.unread
: desktopSideView === 'groups'
? theme.palette.text.primary
: theme.palette.text.secondary
}
/>
</IconWrapper>
</ButtonBase>
<ButtonBase
onClick={() => {
setDesktopSideView('directs');
}}
>
<IconWrapper
customWidth="75px"
color={
directChatHasUnread
? theme.palette.other.unread
: desktopSideView === 'directs'
? theme.palette.text.primary
: theme.palette.text.secondary
}
label="Messaging"
selected={desktopSideView === 'directs'}
>
<MessagingIcon
height={24}
color={
directChatHasUnread
? theme.palette.other.unread
: desktopSideView === 'directs'
? theme.palette.text.primary
: theme.palette.text.secondary
}
/>
</IconWrapper>
</ButtonBase>
</Box>
<div
style={{
alignItems: 'flex-start',
display: 'flex',
flexDirection: 'column',
flexGrow: 1,
left: chatMode === 'directs' && '-1000px',
overflowY: 'auto',
position: chatMode === 'directs' && 'fixed',
visibility: chatMode === 'directs' && 'hidden',
width: '100%',
}}
>
{groups.map((group: any) => (
<List
sx={{
width: '100%',
}}
className="group-list"
dense={true}
>
<ListItem
onClick={() => {
setMobileViewMode('group'); setMobileViewMode('group');
setDesktopSideView('groups'); setDesktopSideView('groups');
initiatedGetMembers.current = false; initiatedGetMembers.current = false;
@ -1943,195 +1870,7 @@ export const Group = ({
setTimeout(() => { setTimeout(() => {
setSelectedGroup(group); setSelectedGroup(group);
}, 200); }, 200);
}} }, []);
sx={{
display: 'flex',
background:
group?.groupId === selectedGroup?.groupId &&
theme.palette.action.selected,
borderRadius: '2px',
cursor: 'pointer',
flexDirection: 'column',
padding: '2px',
width: '100%',
'&:hover': {
backgroundColor: 'action.hover', // background on hover
},
}}
>
<ContextMenu
mutedGroups={mutedGroups}
getUserSettings={getUserSettings}
groupId={group.groupId}
>
<Box
sx={{
alignItems: 'center',
display: 'flex',
width: '100%',
}}
>
<ListItemAvatar>
{groupsOwnerNames[group?.groupId] ? (
<Avatar
alt={group?.groupName?.charAt(0)}
src={`${getBaseApiReact()}/arbitrary/THUMBNAIL/${
groupsOwnerNames[group?.groupId]
}/qortal_group_avatar_${group?.groupId}?async=true`}
>
{group?.groupName?.charAt(0).toUpperCase()}
</Avatar>
) : (
<Avatar alt={group?.groupName?.charAt(0)}>
{' '}
{group?.groupName?.charAt(0).toUpperCase() || 'G'}
</Avatar>
)}
</ListItemAvatar>
<ListItemText
primary={
group.groupId === '0' ? 'General' : group.groupName
}
secondary={
!group?.timestamp
? 'no messages'
: `last message: ${formatEmailDate(group?.timestamp)}`
}
primaryTypographyProps={{
style: {
color:
group?.groupId === selectedGroup?.groupId &&
theme.palette.text.primary,
fontSize: '16px',
},
}} // Change the color of the primary text
secondaryTypographyProps={{
style: {
color:
group?.groupId === selectedGroup?.groupId &&
theme.palette.text.primary,
fontSize: '12px',
},
}}
sx={{
width: '150px',
fontFamily: 'Inter',
fontSize: '16px',
}}
/>
{groupAnnouncements[group?.groupId] &&
!groupAnnouncements[group?.groupId]?.seentimestamp && (
<CampaignIcon
sx={{
color: theme.palette.other.unread,
marginRight: '5px',
marginBottom: 'auto',
}}
/>
)}
<Box
sx={{
display: 'flex',
flexDirection: 'column',
gap: '5px',
justifyContent: 'flex-start',
height: '100%',
marginBottom: 'auto',
}}
>
{group?.data &&
groupChatTimestamps[group?.groupId] &&
group?.sender !== myAddress &&
group?.timestamp &&
((!timestampEnterData[group?.groupId] &&
Date.now() - group?.timestamp <
timeDifferenceForNotificationChats) ||
timestampEnterData[group?.groupId] <
group?.timestamp) && (
<MarkChatUnreadIcon
sx={{
color: theme.palette.other.unread,
}}
/>
)}
{groupsProperties[group?.groupId]?.isOpen === false && (
<LockIcon
sx={{
color: theme.palette.other.positive,
marginBottom: 'auto',
}}
/>
)}
</Box>
</Box>
</ContextMenu>
</ListItem>
</List>
))}
</div>
<div
style={{
display: 'flex',
gap: '10px',
justifyContent: 'center',
padding: '10px',
width: '100%',
}}
>
{chatMode === 'groups' && (
<>
<CustomButton
onClick={() => {
setOpenAddGroup(true);
}}
>
<AddCircleOutlineIcon
sx={{
color: theme.palette.text.primary,
}}
/>
Group
</CustomButton>
{!isRunningPublicNode && (
<CustomButton
onClick={() => {
setIsOpenBlockedUserModal(true);
}}
sx={{
minWidth: 'unset',
padding: '10px',
}}
>
<PersonOffIcon
sx={{
color: theme.palette.text.primary,
}}
/>
</CustomButton>
)}
</>
)}
{chatMode === 'directs' && (
<CustomButton
onClick={() => {
setNewChat(true);
setSelectedDirect(null);
setIsOpenDrawer(false);
}}
>
<CreateIcon
sx={{
color: theme.palette.text.primary,
}}
/>
New Chat
</CustomButton>
)}
</div>
</div>
);
};
return ( return (
<> <>
@ -2176,9 +1915,24 @@ export const Group = ({
/> />
)} )}
{desktopViewMode === 'chat' && {desktopViewMode === 'chat' && desktopSideView !== 'directs' && (
desktopSideView !== 'directs' && <GroupList
renderGroups()} selectGroupFunc={selectGroupFunc}
setDesktopSideView={setDesktopSideView}
groupChatHasUnread={groupChatHasUnread}
groupsAnnHasUnread={groupsAnnHasUnread}
desktopSideView={desktopSideView}
directChatHasUnread={directChatHasUnread}
chatMode={chatMode}
groups={groups}
selectedGroup={selectedGroup}
getUserSettings={getUserSettings}
setOpenAddGroup={setOpenAddGroup}
isRunningPublicNode={isRunningPublicNode}
setIsOpenBlockedUserModal={setIsOpenBlockedUserModal}
myAddress={myAddress}
/>
)}
{desktopViewMode === 'chat' && {desktopViewMode === 'chat' &&
desktopSideView === 'directs' && desktopSideView === 'directs' &&
@ -2318,7 +2072,7 @@ export const Group = ({
isPrivate={isPrivate} isPrivate={isPrivate}
setSecretKey={setSecretKey} setSecretKey={setSecretKey}
handleNewEncryptionNotification={setNewEncryptionNotification} handleNewEncryptionNotification={setNewEncryptionNotification}
hide={groupSection !== 'chat' || selectedDirect || newChat} hide={groupSection !== 'chat' || !!selectedDirect || newChat}
hideView={!(desktopViewMode === 'chat' && selectedGroup)} hideView={!(desktopViewMode === 'chat' && selectedGroup)}
handleSecretKeyCreationInProgress={ handleSecretKeyCreationInProgress={
handleSecretKeyCreationInProgress handleSecretKeyCreationInProgress

View File

@ -0,0 +1,348 @@
import {
Avatar,
Box,
ButtonBase,
List,
ListItem,
ListItemAvatar,
ListItemText,
useTheme,
} from '@mui/material';
import React, { useCallback } from 'react';
import { IconWrapper } from '../Desktop/DesktopFooter';
import { HubsIcon } from '../../assets/Icons/HubsIcon';
import { MessagingIcon } from '../../assets/Icons/MessagingIcon';
import { ContextMenu } from '../ContextMenu';
import { getBaseApiReact } from '../../App';
import { formatEmailDate } from './QMailMessages';
import CampaignIcon from '@mui/icons-material/Campaign';
import MarkChatUnreadIcon from '@mui/icons-material/MarkChatUnread';
import LockIcon from '@mui/icons-material/Lock';
import { CustomButton } from '../../styles/App-styles';
import AddCircleOutlineIcon from '@mui/icons-material/AddCircleOutline';
import PersonOffIcon from '@mui/icons-material/PersonOff';
import {
groupAnnouncementSelector,
groupChatTimestampSelector,
groupPropertySelector,
groupsOwnerNamesSelector,
timestampEnterDataSelector,
} from '../../atoms/global';
import { useRecoilValue } from 'recoil';
import { timeDifferenceForNotificationChats } from './Group';
export const GroupList = ({
selectGroupFunc,
setDesktopSideView,
groupChatHasUnread,
groupsAnnHasUnread,
desktopSideView,
directChatHasUnread,
chatMode,
groups,
selectedGroup,
getUserSettings,
setOpenAddGroup,
isRunningPublicNode,
setIsOpenBlockedUserModal,
myAddress,
}) => {
const theme = useTheme();
return (
<div
style={{
display: 'flex',
width: '380px',
flexDirection: 'column',
alignItems: 'flex-start',
height: '100%',
background: theme.palette.background.surface,
borderRadius: '0px 15px 15px 0px',
padding: '0px 2px',
}}
>
<Box
sx={{
width: '100%',
alignItems: 'center',
justifyContent: 'center',
display: 'flex',
gap: '10px',
}}
>
<ButtonBase
onClick={() => {
setDesktopSideView('groups');
}}
>
<IconWrapper
color={
groupChatHasUnread || groupsAnnHasUnread
? theme.palette.other.unread
: desktopSideView === 'groups'
? theme.palette.text.primary
: theme.palette.text.secondary
}
label="Groups"
selected={desktopSideView === 'groups'}
customWidth="75px"
>
<HubsIcon
height={24}
color={
groupChatHasUnread || groupsAnnHasUnread
? theme.palette.other.unread
: desktopSideView === 'groups'
? theme.palette.text.primary
: theme.palette.text.secondary
}
/>
</IconWrapper>
</ButtonBase>
<ButtonBase
onClick={() => {
setDesktopSideView('directs');
}}
>
<IconWrapper
customWidth="75px"
color={
directChatHasUnread
? theme.palette.other.unread
: desktopSideView === 'directs'
? theme.palette.text.primary
: theme.palette.text.secondary
}
label="Messaging"
selected={desktopSideView === 'directs'}
>
<MessagingIcon
height={24}
color={
directChatHasUnread
? theme.palette.other.unread
: desktopSideView === 'directs'
? theme.palette.text.primary
: theme.palette.text.secondary
}
/>
</IconWrapper>
</ButtonBase>
</Box>
<div
style={{
alignItems: 'flex-start',
display: 'flex',
flexDirection: 'column',
flexGrow: 1,
left: chatMode === 'directs' && '-1000px',
overflowY: 'auto',
position: chatMode === 'directs' && 'fixed',
visibility: chatMode === 'directs' && 'hidden',
width: '100%',
}}
>
<List
sx={{
width: '100%',
}}
className="group-list"
dense={false}
>
{groups.map((group: any) => (
<GroupItem
selectGroupFunc={selectGroupFunc}
key={group.groupId}
group={group}
selectedGroup={selectedGroup}
getUserSettings={getUserSettings}
myAddress={myAddress}
/>
))}
</List>
</div>
<div
style={{
display: 'flex',
gap: '10px',
justifyContent: 'center',
padding: '10px',
width: '100%',
}}
>
<>
<CustomButton
onClick={() => {
setOpenAddGroup(true);
}}
>
<AddCircleOutlineIcon
sx={{
color: theme.palette.text.primary,
}}
/>
Group
</CustomButton>
{!isRunningPublicNode && (
<CustomButton
onClick={() => {
setIsOpenBlockedUserModal(true);
}}
sx={{
minWidth: 'unset',
padding: '10px',
}}
>
<PersonOffIcon
sx={{
color: theme.palette.text.primary,
}}
/>
</CustomButton>
)}
</>
</div>
</div>
);
};
const GroupItem = React.memo(
({ selectGroupFunc, group, selectedGroup, getUserSettings, myAddress }) => {
const theme = useTheme();
const ownerName = useRecoilValue(groupsOwnerNamesSelector(group?.groupId));
const announcement = useRecoilValue(
groupAnnouncementSelector(group?.groupId)
);
const groupProperty = useRecoilValue(groupPropertySelector(group?.groupId));
const groupChatTimestamp = useRecoilValue(
groupChatTimestampSelector(group?.groupId)
);
const timestampEnterData = useRecoilValue(
timestampEnterDataSelector(group?.groupId)
);
const selectGroupHandler = useCallback(() => {
selectGroupFunc(group);
}, [group, selectGroupFunc]);
return (
<ListItem
onClick={selectGroupHandler}
sx={{
display: 'flex',
background:
group?.groupId === selectedGroup?.groupId &&
theme.palette.action.selected,
borderRadius: '2px',
cursor: 'pointer',
flexDirection: 'column',
padding: '10px',
width: '100%',
'&:hover': {
backgroundColor: 'action.hover', // background on hover
},
}}
>
<ContextMenu getUserSettings={getUserSettings} groupId={group.groupId}>
<Box
sx={{
alignItems: 'center',
display: 'flex',
width: '100%',
}}
>
<ListItemAvatar>
{ownerName ? (
<Avatar
alt={group?.groupName?.charAt(0)}
src={`${getBaseApiReact()}/arbitrary/THUMBNAIL/${
ownerName
}/qortal_group_avatar_${group?.groupId}?async=true`}
>
{group?.groupName?.charAt(0).toUpperCase()}
</Avatar>
) : (
<Avatar alt={group?.groupName?.charAt(0)}>
{' '}
{group?.groupName?.charAt(0).toUpperCase() || 'G'}
</Avatar>
)}
</ListItemAvatar>
<ListItemText
primary={group.groupId === '0' ? 'General' : group.groupName}
secondary={
!group?.timestamp
? 'no messages'
: `last message: ${formatEmailDate(group?.timestamp)}`
}
primaryTypographyProps={{
style: {
color:
group?.groupId === selectedGroup?.groupId &&
theme.palette.text.primary,
fontSize: '16px',
},
}} // Change the color of the primary text
secondaryTypographyProps={{
style: {
color:
group?.groupId === selectedGroup?.groupId &&
theme.palette.text.primary,
fontSize: '12px',
},
}}
sx={{
width: '150px',
fontFamily: 'Inter',
fontSize: '16px',
}}
/>
{announcement && !announcement?.seentimestamp && (
<CampaignIcon
sx={{
color: theme.palette.other.unread,
marginRight: '5px',
marginBottom: 'auto',
}}
/>
)}
<Box
sx={{
display: 'flex',
flexDirection: 'column',
gap: '5px',
justifyContent: 'flex-start',
height: '100%',
marginBottom: 'auto',
}}
>
{group?.data &&
groupChatTimestamp &&
group?.sender !== myAddress &&
group?.timestamp &&
((!timestampEnterData &&
Date.now() - group?.timestamp <
timeDifferenceForNotificationChats) ||
timestampEnterData < group?.timestamp) && (
<MarkChatUnreadIcon
sx={{
color: theme.palette.other.unread,
}}
/>
)}
{groupProperty?.isOpen === false && (
<LockIcon
sx={{
color: theme.palette.other.positive,
marginBottom: 'auto',
}}
/>
)}
</Box>
</Box>
</ContextMenu>
</ListItem>
);
}
);