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,
|
mailsAtom,
|
||||||
memberGroupsAtom,
|
memberGroupsAtom,
|
||||||
mutedGroupsAtom,
|
mutedGroupsAtom,
|
||||||
|
myGroupsWhereIAmAdminAtom,
|
||||||
oldPinnedAppsAtom,
|
oldPinnedAppsAtom,
|
||||||
qMailLastEnteredTimestampAtom,
|
qMailLastEnteredTimestampAtom,
|
||||||
settingsLocalLastUpdatedAtom,
|
settingsLocalLastUpdatedAtom,
|
||||||
@@ -484,6 +485,9 @@ function App() {
|
|||||||
const resetLastPaymentSeenTimestampAtom = useResetAtom(
|
const resetLastPaymentSeenTimestampAtom = useResetAtom(
|
||||||
lastPaymentSeenTimestampAtom
|
lastPaymentSeenTimestampAtom
|
||||||
);
|
);
|
||||||
|
const resetMyGroupsWhereIAmAdminAtom = useResetAtom(
|
||||||
|
myGroupsWhereIAmAdminAtom
|
||||||
|
);
|
||||||
const resetGroupsOwnerNamesAtom = useResetAtom(groupsOwnerNamesAtom);
|
const resetGroupsOwnerNamesAtom = useResetAtom(groupsOwnerNamesAtom);
|
||||||
const resetGroupAnnouncementsAtom = useResetAtom(groupAnnouncementsAtom);
|
const resetGroupAnnouncementsAtom = useResetAtom(groupAnnouncementsAtom);
|
||||||
const resetMutedGroupsAtom = useResetAtom(mutedGroupsAtom);
|
const resetMutedGroupsAtom = useResetAtom(mutedGroupsAtom);
|
||||||
@@ -510,6 +514,7 @@ function App() {
|
|||||||
resetTimestampEnterAtom();
|
resetTimestampEnterAtom();
|
||||||
resettxListAtomAtom();
|
resettxListAtomAtom();
|
||||||
resetmemberGroupsAtomAtom();
|
resetmemberGroupsAtomAtom();
|
||||||
|
resetMyGroupsWhereIAmAdminAtom();
|
||||||
};
|
};
|
||||||
|
|
||||||
const contextValue = useMemo(
|
const contextValue = useMemo(
|
||||||
|
@@ -289,8 +289,10 @@ export const AppsPrivate = ({ myName, myAddress }) => {
|
|||||||
}
|
}
|
||||||
}, [myAddress]);
|
}, [myAddress]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getNames();
|
if (isOpenPrivateModal) {
|
||||||
}, [getNames]);
|
getNames();
|
||||||
|
}
|
||||||
|
}, [getNames, isOpenPrivateModal]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@@ -66,6 +66,7 @@ import {
|
|||||||
isRunningPublicNodeAtom,
|
isRunningPublicNodeAtom,
|
||||||
memberGroupsAtom,
|
memberGroupsAtom,
|
||||||
mutedGroupsAtom,
|
mutedGroupsAtom,
|
||||||
|
myGroupsWhereIAmAdminAtom,
|
||||||
selectedGroupIdAtom,
|
selectedGroupIdAtom,
|
||||||
timestampEnterDataAtom,
|
timestampEnterDataAtom,
|
||||||
} from '../../atoms/global';
|
} from '../../atoms/global';
|
||||||
@@ -75,6 +76,7 @@ import { WalletsAppWrapper } from './WalletsAppWrapper';
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { GroupList } from './GroupList';
|
import { GroupList } from './GroupList';
|
||||||
import { useAtom, useSetAtom } from 'jotai';
|
import { useAtom, useSetAtom } from 'jotai';
|
||||||
|
import { requestQueueGroupJoinRequests } from './GroupJoinRequests';
|
||||||
|
|
||||||
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('&');
|
||||||
@@ -401,6 +403,7 @@ export const Group = ({
|
|||||||
const [timestampEnterData, setTimestampEnterData] = useAtom(
|
const [timestampEnterData, setTimestampEnterData] = useAtom(
|
||||||
timestampEnterDataAtom
|
timestampEnterDataAtom
|
||||||
);
|
);
|
||||||
|
const groupsPropertiesRef = useRef({});
|
||||||
const [chatMode, setChatMode] = useState('groups');
|
const [chatMode, setChatMode] = useState('groups');
|
||||||
const [newChat, setNewChat] = useState(false);
|
const [newChat, setNewChat] = useState(false);
|
||||||
const [openSnack, setOpenSnack] = useState(false);
|
const [openSnack, setOpenSnack] = useState(false);
|
||||||
@@ -458,7 +461,7 @@ export const Group = ({
|
|||||||
const setGroupsOwnerNames = useSetAtom(groupsOwnerNamesAtom);
|
const setGroupsOwnerNames = useSetAtom(groupsOwnerNamesAtom);
|
||||||
|
|
||||||
const setUserInfoForLevels = useSetAtom(addressInfoControllerAtom);
|
const setUserInfoForLevels = useSetAtom(addressInfoControllerAtom);
|
||||||
|
const setMyGroupsWhereIAmAdmin = useSetAtom(myGroupsWhereIAmAdminAtom);
|
||||||
const isPrivate = useMemo(() => {
|
const isPrivate = useMemo(() => {
|
||||||
if (selectedGroup?.groupId === '0') return false;
|
if (selectedGroup?.groupId === '0') return false;
|
||||||
if (!selectedGroup?.groupId || !groupsProperties[selectedGroup?.groupId])
|
if (!selectedGroup?.groupId || !groupsProperties[selectedGroup?.groupId])
|
||||||
@@ -898,6 +901,10 @@ export const Group = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
groupsPropertiesRef.current = groupsProperties;
|
||||||
|
}, [groupsProperties]);
|
||||||
|
|
||||||
const getGroupsProperties = useCallback(async (address) => {
|
const getGroupsProperties = useCallback(async (address) => {
|
||||||
try {
|
try {
|
||||||
const url = `${getBaseApiReact()}/groups/member/${address}`;
|
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(() => {
|
useEffect(() => {
|
||||||
if (!myAddress) return;
|
if (!myAddress) return;
|
||||||
if (
|
if (
|
||||||
areKeysEqual(
|
!areKeysEqual(
|
||||||
groups?.map((grp) => grp?.groupId),
|
groups?.map((grp) => grp?.groupId),
|
||||||
Object.keys(groupsProperties)
|
Object.keys(groupsPropertiesRef.current)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
// TODO: empty block. Check it!
|
|
||||||
} else {
|
|
||||||
getGroupsProperties(myAddress);
|
getGroupsProperties(myAddress);
|
||||||
|
getGroupsWhereIAmAMember(groups);
|
||||||
}
|
}
|
||||||
}, [groups, myAddress]);
|
}, [groups, myAddress]);
|
||||||
|
|
||||||
|
@@ -39,40 +39,14 @@ export const GroupJoinRequests = ({
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [txList] = useAtom(txListAtom);
|
const [txList] = useAtom(txListAtom);
|
||||||
|
|
||||||
const setMyGroupsWhereIAmAdmin = useSetAtom(myGroupsWhereIAmAdminAtom);
|
const [myGroupsWhereIAmAdmin] = useAtom(myGroupsWhereIAmAdminAtom);
|
||||||
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const getJoinRequests = async () => {
|
const getJoinRequests = async () => {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
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(
|
const res = await Promise.all(
|
||||||
groupsAsAdmin.map(async (group) => {
|
myGroupsWhereIAmAdmin.map(async (group) => {
|
||||||
const joinRequestResponse =
|
const joinRequestResponse =
|
||||||
await requestQueueGroupJoinRequests.enqueue(() => {
|
await requestQueueGroupJoinRequests.enqueue(() => {
|
||||||
return fetch(
|
return fetch(
|
||||||
@@ -96,12 +70,12 @@ export const GroupJoinRequests = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (myAddress && groups.length > 0) {
|
if (myAddress && myGroupsWhereIAmAdmin.length > 0) {
|
||||||
getJoinRequests();
|
getJoinRequests();
|
||||||
} else {
|
} else {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, [myAddress, groups]);
|
}, [myAddress, myGroupsWhereIAmAdmin]);
|
||||||
|
|
||||||
const filteredJoinRequests = useMemo(() => {
|
const filteredJoinRequests = useMemo(() => {
|
||||||
return groupsWithJoinRequests.map((group) => {
|
return groupsWithJoinRequests.map((group) => {
|
||||||
|
Reference in New Issue
Block a user