Automatic update people list
Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
parent
8711658e75
commit
6fdace07c8
2 changed files with 22 additions and 11 deletions
|
@ -92,6 +92,9 @@ function ProfileFooter({ roomId, userId, onRequestClose }) {
|
|||
const [isInviting, setIsInviting] = useState(false);
|
||||
const [isInvited, setIsInvited] = useState(member?.membership === 'invite');
|
||||
|
||||
const myPowerlevel = room.getMember(mx.getUserId()).powerLevel;
|
||||
const canIKick = room.currentState.hasSufficientPowerLevelFor('kick', myPowerlevel);
|
||||
|
||||
useEffect(() => () => {
|
||||
isMountedRef.current = false;
|
||||
}, []);
|
||||
|
@ -180,8 +183,11 @@ function ProfileFooter({ roomId, userId, onRequestClose }) {
|
|||
{isCreatingDM ? 'Creating room...' : 'Message'}
|
||||
</Button>
|
||||
{ member?.membership === 'join' && <Button>Mention</Button>}
|
||||
{room.canInvite(mx.getUserId()) && isInvitable && (
|
||||
<Button onClick={toggleInvite}>
|
||||
{ (isInvited ? canIKick : room.canInvite(mx.getUserId())) && isInvitable && (
|
||||
<Button
|
||||
onClick={toggleInvite}
|
||||
disabled={isInviting}
|
||||
>
|
||||
{
|
||||
isInvited
|
||||
? `${isInviting ? 'Disinviting...' : 'Disinvite'}`
|
||||
|
|
|
@ -103,30 +103,35 @@ function PeopleDrawer({ roomId }) {
|
|||
}, [memberList]);
|
||||
|
||||
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 = '';
|
||||
setMemberList(
|
||||
simplyfiMembers(
|
||||
getMembersWithMembership(membership)
|
||||
.sort(AtoZ).sort(sortByPowerLevel),
|
||||
),
|
||||
);
|
||||
updateMemberList();
|
||||
room.loadMembersIfNeeded().then(() => {
|
||||
isGettingMembers = false;
|
||||
if (isRoomChanged) return;
|
||||
setMemberList(
|
||||
simplyfiMembers(
|
||||
getMembersWithMembership(membership)
|
||||
.sort(AtoZ).sort(sortByPowerLevel),
|
||||
),
|
||||
);
|
||||
updateMemberList();
|
||||
});
|
||||
|
||||
asyncSearch.on(asyncSearch.RESULT_SENT, handleSearchData);
|
||||
mx.on('RoomMember.membership', updateMemberList);
|
||||
return () => {
|
||||
isRoomChanged = true;
|
||||
setMemberList([]);
|
||||
setSearchedMembers(null);
|
||||
setItemCount(PER_PAGE_MEMBER);
|
||||
asyncSearch.removeListener(asyncSearch.RESULT_SENT, handleSearchData);
|
||||
mx.removeListener('RoomMember.membership', updateMemberList);
|
||||
};
|
||||
}, [roomId, membership]);
|
||||
|
||||
|
|
Loading…
Reference in a new issue