mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-07-29 13:11:23 +00:00
fix getting list of groups where user is admin
This commit is contained in:
@@ -108,6 +108,7 @@ import {
|
||||
mailsAtom,
|
||||
memberGroupsAtom,
|
||||
mutedGroupsAtom,
|
||||
myGroupsWhereIAmAdminAtom,
|
||||
oldPinnedAppsAtom,
|
||||
qMailLastEnteredTimestampAtom,
|
||||
settingsLocalLastUpdatedAtom,
|
||||
@@ -484,6 +485,9 @@ function App() {
|
||||
const resetLastPaymentSeenTimestampAtom = useResetAtom(
|
||||
lastPaymentSeenTimestampAtom
|
||||
);
|
||||
const resetMyGroupsWhereIAmAdminAtom = useResetAtom(
|
||||
myGroupsWhereIAmAdminAtom
|
||||
);
|
||||
const resetGroupsOwnerNamesAtom = useResetAtom(groupsOwnerNamesAtom);
|
||||
const resetGroupAnnouncementsAtom = useResetAtom(groupAnnouncementsAtom);
|
||||
const resetMutedGroupsAtom = useResetAtom(mutedGroupsAtom);
|
||||
@@ -510,6 +514,7 @@ function App() {
|
||||
resetTimestampEnterAtom();
|
||||
resettxListAtomAtom();
|
||||
resetmemberGroupsAtomAtom();
|
||||
resetMyGroupsWhereIAmAdminAtom();
|
||||
};
|
||||
|
||||
const contextValue = useMemo(
|
||||
|
@@ -289,8 +289,10 @@ export const AppsPrivate = ({ myName, myAddress }) => {
|
||||
}
|
||||
}, [myAddress]);
|
||||
useEffect(() => {
|
||||
getNames();
|
||||
}, [getNames]);
|
||||
if (isOpenPrivateModal) {
|
||||
getNames();
|
||||
}
|
||||
}, [getNames, isOpenPrivateModal]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@@ -66,6 +66,7 @@ import {
|
||||
isRunningPublicNodeAtom,
|
||||
memberGroupsAtom,
|
||||
mutedGroupsAtom,
|
||||
myGroupsWhereIAmAdminAtom,
|
||||
selectedGroupIdAtom,
|
||||
timestampEnterDataAtom,
|
||||
} from '../../atoms/global';
|
||||
@@ -75,6 +76,7 @@ import { WalletsAppWrapper } from './WalletsAppWrapper';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { GroupList } from './GroupList';
|
||||
import { useAtom, useSetAtom } from 'jotai';
|
||||
import { requestQueueGroupJoinRequests } from './GroupJoinRequests';
|
||||
|
||||
export const getPublishesFromAdmins = async (admins: string[], groupId) => {
|
||||
const queryString = admins.map((name) => `name=${name}`).join('&');
|
||||
@@ -401,6 +403,7 @@ export const Group = ({
|
||||
const [timestampEnterData, setTimestampEnterData] = useAtom(
|
||||
timestampEnterDataAtom
|
||||
);
|
||||
const groupsPropertiesRef = useRef({});
|
||||
const [chatMode, setChatMode] = useState('groups');
|
||||
const [newChat, setNewChat] = useState(false);
|
||||
const [openSnack, setOpenSnack] = useState(false);
|
||||
@@ -458,7 +461,7 @@ export const Group = ({
|
||||
const setGroupsOwnerNames = useSetAtom(groupsOwnerNamesAtom);
|
||||
|
||||
const setUserInfoForLevels = useSetAtom(addressInfoControllerAtom);
|
||||
|
||||
const setMyGroupsWhereIAmAdmin = useSetAtom(myGroupsWhereIAmAdminAtom);
|
||||
const isPrivate = useMemo(() => {
|
||||
if (selectedGroup?.groupId === '0') return false;
|
||||
if (!selectedGroup?.groupId || !groupsProperties[selectedGroup?.groupId])
|
||||
@@ -898,6 +901,10 @@ export const Group = ({
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
groupsPropertiesRef.current = groupsProperties;
|
||||
}, [groupsProperties]);
|
||||
|
||||
const getGroupsProperties = useCallback(async (address) => {
|
||||
try {
|
||||
const url = `${getBaseApiReact()}/groups/member/${address}`;
|
||||
@@ -917,17 +924,48 @@ export const Group = ({
|
||||
}
|
||||
}, []);
|
||||
|
||||
const getGroupsWhereIAmAMember = useCallback(async (groups) => {
|
||||
try {
|
||||
let groupsAsAdmin = [];
|
||||
const getAllGroupsAsAdmin = groups
|
||||
.filter((item) => item.groupId !== '0')
|
||||
.map(async (group) => {
|
||||
const isAdminResponse = await requestQueueGroupJoinRequests.enqueue(
|
||||
() => {
|
||||
return fetch(
|
||||
`${getBaseApiReact()}/groups/members/${group.groupId}?limit=0&onlyAdmins=true`
|
||||
);
|
||||
}
|
||||
);
|
||||
const isAdminData = await isAdminResponse.json();
|
||||
|
||||
const findMyself = isAdminData?.members?.find(
|
||||
(member) => member.member === myAddress
|
||||
);
|
||||
|
||||
if (findMyself) {
|
||||
groupsAsAdmin.push(group);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
await Promise.all(getAllGroupsAsAdmin);
|
||||
setMyGroupsWhereIAmAdmin(groupsAsAdmin);
|
||||
} catch (error) {
|
||||
console.error();
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!myAddress) return;
|
||||
if (
|
||||
areKeysEqual(
|
||||
!areKeysEqual(
|
||||
groups?.map((grp) => grp?.groupId),
|
||||
Object.keys(groupsProperties)
|
||||
Object.keys(groupsPropertiesRef.current)
|
||||
)
|
||||
) {
|
||||
// TODO: empty block. Check it!
|
||||
} else {
|
||||
getGroupsProperties(myAddress);
|
||||
getGroupsWhereIAmAMember(groups);
|
||||
}
|
||||
}, [groups, myAddress]);
|
||||
|
||||
|
@@ -39,40 +39,14 @@ export const GroupJoinRequests = ({
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [txList] = useAtom(txListAtom);
|
||||
|
||||
const setMyGroupsWhereIAmAdmin = useSetAtom(myGroupsWhereIAmAdminAtom);
|
||||
const [myGroupsWhereIAmAdmin] = useAtom(myGroupsWhereIAmAdminAtom);
|
||||
|
||||
const theme = useTheme();
|
||||
const getJoinRequests = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
let groupsAsAdmin = [];
|
||||
const getAllGroupsAsAdmin = groups
|
||||
.filter((item) => item.groupId !== '0')
|
||||
.map(async (group) => {
|
||||
const isAdminResponse = await requestQueueGroupJoinRequests.enqueue(
|
||||
() => {
|
||||
return fetch(
|
||||
`${getBaseApiReact()}/groups/members/${group.groupId}?limit=0&onlyAdmins=true`
|
||||
);
|
||||
}
|
||||
);
|
||||
const isAdminData = await isAdminResponse.json();
|
||||
|
||||
const findMyself = isAdminData?.members?.find(
|
||||
(member) => member.member === myAddress
|
||||
);
|
||||
|
||||
if (findMyself) {
|
||||
groupsAsAdmin.push(group);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
await Promise.all(getAllGroupsAsAdmin);
|
||||
setMyGroupsWhereIAmAdmin(groupsAsAdmin);
|
||||
const res = await Promise.all(
|
||||
groupsAsAdmin.map(async (group) => {
|
||||
myGroupsWhereIAmAdmin.map(async (group) => {
|
||||
const joinRequestResponse =
|
||||
await requestQueueGroupJoinRequests.enqueue(() => {
|
||||
return fetch(
|
||||
@@ -96,12 +70,12 @@ export const GroupJoinRequests = ({
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (myAddress && groups.length > 0) {
|
||||
if (myAddress && myGroupsWhereIAmAdmin.length > 0) {
|
||||
getJoinRequests();
|
||||
} else {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [myAddress, groups]);
|
||||
}, [myAddress, myGroupsWhereIAmAdmin]);
|
||||
|
||||
const filteredJoinRequests = useMemo(() => {
|
||||
return groupsWithJoinRequests.map((group) => {
|
||||
|
Reference in New Issue
Block a user