Automatic update people list

Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
Ajay Bura 2021-10-29 18:11:02 +05:30
parent 8711658e75
commit 6fdace07c8
2 changed files with 22 additions and 11 deletions

View file

@ -92,6 +92,9 @@ function ProfileFooter({ roomId, userId, onRequestClose }) {
const [isInviting, setIsInviting] = useState(false); const [isInviting, setIsInviting] = useState(false);
const [isInvited, setIsInvited] = useState(member?.membership === 'invite'); const [isInvited, setIsInvited] = useState(member?.membership === 'invite');
const myPowerlevel = room.getMember(mx.getUserId()).powerLevel;
const canIKick = room.currentState.hasSufficientPowerLevelFor('kick', myPowerlevel);
useEffect(() => () => { useEffect(() => () => {
isMountedRef.current = false; isMountedRef.current = false;
}, []); }, []);
@ -180,8 +183,11 @@ function ProfileFooter({ roomId, userId, onRequestClose }) {
{isCreatingDM ? 'Creating room...' : 'Message'} {isCreatingDM ? 'Creating room...' : 'Message'}
</Button> </Button>
{ member?.membership === 'join' && <Button>Mention</Button>} { member?.membership === 'join' && <Button>Mention</Button>}
{room.canInvite(mx.getUserId()) && isInvitable && ( { (isInvited ? canIKick : room.canInvite(mx.getUserId())) && isInvitable && (
<Button onClick={toggleInvite}> <Button
onClick={toggleInvite}
disabled={isInviting}
>
{ {
isInvited isInvited
? `${isInviting ? 'Disinviting...' : 'Disinvite'}` ? `${isInviting ? 'Disinviting...' : 'Disinvite'}`

View file

@ -103,30 +103,35 @@ function PeopleDrawer({ roomId }) {
}, [memberList]); }, [memberList]);
useEffect(() => { useEffect(() => {
let isGettingMembers = true;
const updateMemberList = (event) => {
if (isGettingMembers) return;
console.log(event?.event?.room_id);
if (event && event?.event?.room_id !== roomId) return;
setMemberList(
simplyfiMembers(
getMembersWithMembership(membership)
.sort(AtoZ).sort(sortByPowerLevel),
),
);
};
searchRef.current.value = ''; searchRef.current.value = '';
setMemberList( updateMemberList();
simplyfiMembers(
getMembersWithMembership(membership)
.sort(AtoZ).sort(sortByPowerLevel),
),
);
room.loadMembersIfNeeded().then(() => { room.loadMembersIfNeeded().then(() => {
isGettingMembers = false;
if (isRoomChanged) return; if (isRoomChanged) return;
setMemberList( updateMemberList();
simplyfiMembers(
getMembersWithMembership(membership)
.sort(AtoZ).sort(sortByPowerLevel),
),
);
}); });
asyncSearch.on(asyncSearch.RESULT_SENT, handleSearchData); asyncSearch.on(asyncSearch.RESULT_SENT, handleSearchData);
mx.on('RoomMember.membership', updateMemberList);
return () => { return () => {
isRoomChanged = true; isRoomChanged = true;
setMemberList([]); setMemberList([]);
setSearchedMembers(null); setSearchedMembers(null);
setItemCount(PER_PAGE_MEMBER); setItemCount(PER_PAGE_MEMBER);
asyncSearch.removeListener(asyncSearch.RESULT_SENT, handleSearchData); asyncSearch.removeListener(asyncSearch.RESULT_SENT, handleSearchData);
mx.removeListener('RoomMember.membership', updateMemberList);
}; };
}, [roomId, membership]); }, [roomId, membership]);