mirror of
https://github.com/Qortal/qortal-mobile.git
synced 2025-06-20 06:41:21 +00:00
fix getting list of groups where user is admin
This commit is contained in:
parent
b2b7820017
commit
7e34886d15
@ -129,6 +129,7 @@ import {
|
|||||||
isUsingImportExportSettingsAtom,
|
isUsingImportExportSettingsAtom,
|
||||||
lastEnteredGroupIdAtom,
|
lastEnteredGroupIdAtom,
|
||||||
mailsAtom,
|
mailsAtom,
|
||||||
|
myGroupsWhereIAmAdminAtom,
|
||||||
oldPinnedAppsAtom,
|
oldPinnedAppsAtom,
|
||||||
qMailLastEnteredTimestampAtom,
|
qMailLastEnteredTimestampAtom,
|
||||||
settingsLocalLastUpdatedAtom,
|
settingsLocalLastUpdatedAtom,
|
||||||
@ -563,6 +564,9 @@ function App() {
|
|||||||
const resetAtomQMailLastEnteredTimestampAtom = useResetRecoilState(qMailLastEnteredTimestampAtom)
|
const resetAtomQMailLastEnteredTimestampAtom = useResetRecoilState(qMailLastEnteredTimestampAtom)
|
||||||
const resetAtomMailsAtom = useResetRecoilState(mailsAtom)
|
const resetAtomMailsAtom = useResetRecoilState(mailsAtom)
|
||||||
const resetLastEnteredGroupIdAtom = useResetRecoilState(lastEnteredGroupIdAtom)
|
const resetLastEnteredGroupIdAtom = useResetRecoilState(lastEnteredGroupIdAtom)
|
||||||
|
const resetMyGroupsWhereIAmAdminAtom = useResetRecoilState(
|
||||||
|
myGroupsWhereIAmAdminAtom
|
||||||
|
);
|
||||||
const resetAllRecoil = () => {
|
const resetAllRecoil = () => {
|
||||||
resetAtomSortablePinnedAppsAtom();
|
resetAtomSortablePinnedAppsAtom();
|
||||||
resetAtomCanSaveSettingToQdnAtom();
|
resetAtomCanSaveSettingToQdnAtom();
|
||||||
@ -574,6 +578,7 @@ function App() {
|
|||||||
resetAtomMailsAtom()
|
resetAtomMailsAtom()
|
||||||
resetGroupPropertiesAtom()
|
resetGroupPropertiesAtom()
|
||||||
resetLastEnteredGroupIdAtom()
|
resetLastEnteredGroupIdAtom()
|
||||||
|
resetMyGroupsWhereIAmAdminAtom()
|
||||||
};
|
};
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isMobile) return;
|
if (!isMobile) return;
|
||||||
|
@ -215,8 +215,10 @@ export const AppsPrivate = ({myName, myAddress}) => {
|
|||||||
}
|
}
|
||||||
}, [myAddress]);
|
}, [myAddress]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (isOpenPrivateModal) {
|
||||||
getNames();
|
getNames();
|
||||||
}, [getNames]);
|
}
|
||||||
|
}, [getNames, isOpenPrivateModal]);
|
||||||
|
|
||||||
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
|
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
|
||||||
setValueTabPrivateApp(newValue);
|
setValueTabPrivateApp(newValue);
|
||||||
|
@ -67,7 +67,7 @@ import HomeIcon from "@mui/icons-material/Home";
|
|||||||
import CloseIcon from "@mui/icons-material/Close";
|
import CloseIcon from "@mui/icons-material/Close";
|
||||||
|
|
||||||
import { ThingsToDoInitial } from "./ThingsToDoInitial";
|
import { ThingsToDoInitial } from "./ThingsToDoInitial";
|
||||||
import { GroupJoinRequests } from "./GroupJoinRequests";
|
import { GroupJoinRequests, requestQueueGroupJoinRequests } from "./GroupJoinRequests";
|
||||||
import { GroupForum } from "../Chat/GroupForum";
|
import { GroupForum } from "../Chat/GroupForum";
|
||||||
import { GroupInvites } from "./GroupInvites";
|
import { GroupInvites } from "./GroupInvites";
|
||||||
import {
|
import {
|
||||||
@ -100,7 +100,7 @@ import { formatEmailDate } from "./QMailMessages";
|
|||||||
import { useHandleMobileNativeBack } from "../../hooks/useHandleMobileNativeBack";
|
import { useHandleMobileNativeBack } from "../../hooks/useHandleMobileNativeBack";
|
||||||
import { AdminSpace } from "../Chat/AdminSpace";
|
import { AdminSpace } from "../Chat/AdminSpace";
|
||||||
import { useRecoilState, useSetRecoilState } from "recoil";
|
import { useRecoilState, useSetRecoilState } from "recoil";
|
||||||
import { addressInfoControllerAtom, groupsPropertiesAtom, isOpenBlockedModalAtom, lastEnteredGroupIdAtom, selectedGroupIdAtom } from "../../atoms/global";
|
import { addressInfoControllerAtom, groupsPropertiesAtom, isOpenBlockedModalAtom, lastEnteredGroupIdAtom, myGroupsWhereIAmAdminAtom, selectedGroupIdAtom } from "../../atoms/global";
|
||||||
import { sortArrayByTimestampAndGroupName } from "../../utils/time";
|
import { sortArrayByTimestampAndGroupName } from "../../utils/time";
|
||||||
import { BlockedUsersModal } from "./BlockedUsersModal";
|
import { BlockedUsersModal } from "./BlockedUsersModal";
|
||||||
import { GlobalTouchMenu } from "../GlobalTouchMenu";
|
import { GlobalTouchMenu } from "../GlobalTouchMenu";
|
||||||
@ -472,6 +472,9 @@ export const Group = ({
|
|||||||
const { setMemberGroups, memberGroups, rootHeight, isRunningPublicNode } = useContext(MyContext);
|
const { setMemberGroups, memberGroups, rootHeight, isRunningPublicNode } = useContext(MyContext);
|
||||||
const lastGroupNotification = useRef<null | number>(null);
|
const lastGroupNotification = useRef<null | number>(null);
|
||||||
const [timestampEnterData, setTimestampEnterData] = useState({});
|
const [timestampEnterData, setTimestampEnterData] = useState({});
|
||||||
|
const groupsPropertiesRef = useRef({});
|
||||||
|
const setMyGroupsWhereIAmAdmin = useSetRecoilState(myGroupsWhereIAmAdminAtom);
|
||||||
|
|
||||||
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);
|
||||||
@ -536,6 +539,9 @@ export const Group = ({
|
|||||||
useEffect(()=> {
|
useEffect(()=> {
|
||||||
timestampEnterDataRef.current = timestampEnterData
|
timestampEnterDataRef.current = timestampEnterData
|
||||||
}, [timestampEnterData])
|
}, [timestampEnterData])
|
||||||
|
useEffect(() => {
|
||||||
|
groupsPropertiesRef.current = groupsProperties;
|
||||||
|
}, [groupsProperties]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
isFocusedRef.current = isFocused;
|
isFocusedRef.current = isFocused;
|
||||||
@ -988,15 +994,50 @@ 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(areKeysEqual(groups?.map((grp)=> grp?.groupId), Object.keys(groupsProperties))){
|
if (
|
||||||
} else {
|
!areKeysEqual(
|
||||||
getGroupsProperties(myAddress)
|
groups?.map((grp) => grp?.groupId),
|
||||||
|
Object.keys(groupsPropertiesRef.current)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
getGroupsProperties(myAddress);
|
||||||
|
getGroupsWhereIAmAMember(groups);
|
||||||
}
|
}
|
||||||
}, [groups, myAddress])
|
}, [groups, myAddress]);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Handler function for incoming messages
|
// Handler function for incoming messages
|
||||||
|
@ -17,7 +17,7 @@ import { CustomLoader } from "../../common/CustomLoader";
|
|||||||
import { getBaseApi } from "../../background";
|
import { getBaseApi } from "../../background";
|
||||||
import { MyContext, getBaseApiReact, isMobile } from "../../App";
|
import { MyContext, getBaseApiReact, isMobile } from "../../App";
|
||||||
import { myGroupsWhereIAmAdminAtom } from "../../atoms/global";
|
import { myGroupsWhereIAmAdminAtom } from "../../atoms/global";
|
||||||
import { useSetRecoilState } from "recoil";
|
import { useRecoilState, useSetRecoilState } from "recoil";
|
||||||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
||||||
import ExpandLessIcon from '@mui/icons-material/ExpandLess';
|
import ExpandLessIcon from '@mui/icons-material/ExpandLess';
|
||||||
export const requestQueueGroupJoinRequests = new RequestQueueWithPromise(2)
|
export const requestQueueGroupJoinRequests = new RequestQueueWithPromise(2)
|
||||||
@ -28,66 +28,44 @@ export const GroupJoinRequests = ({ myAddress, groups, setOpenManageMembers, get
|
|||||||
const [groupsWithJoinRequests, setGroupsWithJoinRequests] = React.useState([])
|
const [groupsWithJoinRequests, setGroupsWithJoinRequests] = React.useState([])
|
||||||
const [loading, setLoading] = React.useState(true)
|
const [loading, setLoading] = React.useState(true)
|
||||||
const {txList, setTxList} = React.useContext(MyContext)
|
const {txList, setTxList} = React.useContext(MyContext)
|
||||||
const setMyGroupsWhereIAmAdmin = useSetRecoilState(
|
const [myGroupsWhereIAmAdmin] = useRecoilState(myGroupsWhereIAmAdminAtom);
|
||||||
myGroupsWhereIAmAdminAtom
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
const getJoinRequests = async () => {
|
const getJoinRequests = async () => {
|
||||||
try {
|
try {
|
||||||
setLoading(true)
|
setLoading(true);
|
||||||
|
const res = await Promise.all(
|
||||||
let groupsAsAdmin = []
|
myGroupsWhereIAmAdmin.map(async (group) => {
|
||||||
const getAllGroupsAsAdmin = groups.filter((item)=> item.groupId !== '0').map(async (group)=> {
|
const joinRequestResponse =
|
||||||
|
await requestQueueGroupJoinRequests.enqueue(() => {
|
||||||
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)=> {
|
|
||||||
|
|
||||||
const joinRequestResponse = await requestQueueGroupJoinRequests.enqueue(()=> {
|
|
||||||
return fetch(
|
return fetch(
|
||||||
`${getBaseApiReact()}/groups/joinrequests/${group.groupId}`
|
`${getBaseApiReact()}/groups/joinrequests/${group.groupId}`
|
||||||
);
|
);
|
||||||
})
|
});
|
||||||
|
|
||||||
const joinRequestData = await joinRequestResponse.json()
|
const joinRequestData = await joinRequestResponse.json();
|
||||||
return {
|
return {
|
||||||
group,
|
group,
|
||||||
data: joinRequestData
|
data: joinRequestData,
|
||||||
}
|
};
|
||||||
}))
|
})
|
||||||
setGroupsWithJoinRequests(res)
|
);
|
||||||
|
setGroupsWithJoinRequests(res);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.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 = React.useMemo(()=> {
|
const filteredJoinRequests = React.useMemo(()=> {
|
||||||
return groupsWithJoinRequests.map((group)=> {
|
return groupsWithJoinRequests.map((group)=> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user