User Info fetch latest RoomMember instead of showing historical data

This commit is contained in:
Michael Telatynski 2019-12-28 17:51:38 +00:00
parent 6ef6b5909f
commit a0cb6ce302

View File

@ -1020,6 +1020,8 @@ const UserInfo = ({user, groupId, roomId, onClose}) => {
// Load room if we are given a room id and memoize it // Load room if we are given a room id and memoize it
const room = useMemo(() => roomId ? cli.getRoom(roomId) : null, [cli, roomId]); const room = useMemo(() => roomId ? cli.getRoom(roomId) : null, [cli, roomId]);
// fetch latest room member if we have a room, so we don't show historical information
const member = useMemo(() => room ? room.getMember(user.userId) : user, [room, user]);
// only display the devices list if our client supports E2E // only display the devices list if our client supports E2E
const _enableDevices = cli.isCryptoEnabled(); const _enableDevices = cli.isCryptoEnabled();
@ -1051,7 +1053,7 @@ const UserInfo = ({user, groupId, roomId, onClose}) => {
setPendingUpdateCount(pendingUpdateCount - 1); setPendingUpdateCount(pendingUpdateCount - 1);
}, [pendingUpdateCount]); }, [pendingUpdateCount]);
const roomPermissions = useRoomPermissions(cli, room, user); const roomPermissions = useRoomPermissions(cli, room, member);
const onSynapseDeactivate = useCallback(async () => { const onSynapseDeactivate = useCallback(async () => {
const QuestionDialog = sdk.getComponent('views.dialogs.QuestionDialog'); const QuestionDialog = sdk.getComponent('views.dialogs.QuestionDialog');
@ -1084,7 +1086,6 @@ const UserInfo = ({user, groupId, roomId, onClose}) => {
}, [cli, user.userId]); }, [cli, user.userId]);
const onMemberAvatarClick = useCallback(() => { const onMemberAvatarClick = useCallback(() => {
const member = user;
const avatarUrl = member.getMxcAvatarUrl ? member.getMxcAvatarUrl() : member.avatarUrl; const avatarUrl = member.getMxcAvatarUrl ? member.getMxcAvatarUrl() : member.avatarUrl;
if (!avatarUrl) return; if (!avatarUrl) return;
@ -1096,7 +1097,7 @@ const UserInfo = ({user, groupId, roomId, onClose}) => {
}; };
Modal.createDialog(ImageView, params, "mx_Dialog_lightbox"); Modal.createDialog(ImageView, params, "mx_Dialog_lightbox");
}, [cli, user]); }, [cli, member]);
let synapseDeactivateButton; let synapseDeactivateButton;
let spinner; let spinner;
@ -1113,11 +1114,11 @@ const UserInfo = ({user, groupId, roomId, onClose}) => {
} }
let adminToolsContainer; let adminToolsContainer;
if (room && user.roomId) { if (room && member.roomId) {
adminToolsContainer = ( adminToolsContainer = (
<RoomAdminToolsContainer <RoomAdminToolsContainer
powerLevels={powerLevels} powerLevels={powerLevels}
member={user} member={member}
room={room} room={room}
startUpdating={startUpdating} startUpdating={startUpdating}
stopUpdating={stopUpdating}> stopUpdating={stopUpdating}>
@ -1147,20 +1148,20 @@ const UserInfo = ({user, groupId, roomId, onClose}) => {
spinner = <Loader imgClassName="mx_ContextualMenu_spinner" />; spinner = <Loader imgClassName="mx_ContextualMenu_spinner" />;
} }
const displayName = user.name || user.displayname; const displayName = member.name || member.displayname;
let presenceState; let presenceState;
let presenceLastActiveAgo; let presenceLastActiveAgo;
let presenceCurrentlyActive; let presenceCurrentlyActive;
let statusMessage; let statusMessage;
if (user instanceof RoomMember && user.user) { if (member instanceof RoomMember && member.user) {
presenceState = user.user.presence; presenceState = member.user.presence;
presenceLastActiveAgo = user.user.lastActiveAgo; presenceLastActiveAgo = member.user.lastActiveAgo;
presenceCurrentlyActive = user.user.currentlyActive; presenceCurrentlyActive = member.user.currentlyActive;
if (SettingsStore.isFeatureEnabled("feature_custom_status")) { if (SettingsStore.isFeatureEnabled("feature_custom_status")) {
statusMessage = user.user._unstable_statusMessage; statusMessage = member.user._unstable_statusMessage;
} }
} }
@ -1190,13 +1191,13 @@ const UserInfo = ({user, groupId, roomId, onClose}) => {
<div> <div>
<div> <div>
<MemberAvatar <MemberAvatar
member={user} member={member}
width={2 * 0.3 * window.innerHeight} // 2x@30vh width={2 * 0.3 * window.innerHeight} // 2x@30vh
height={2 * 0.3 * window.innerHeight} // 2x@30vh height={2 * 0.3 * window.innerHeight} // 2x@30vh
resizeMethod="scale" resizeMethod="scale"
fallbackUserId={user.userId} fallbackUserId={member.userId}
onClick={onMemberAvatarClick} onClick={onMemberAvatarClick}
urls={user.avatarUrl ? [user.avatarUrl] : undefined} /> urls={member.avatarUrl ? [member.avatarUrl] : undefined} />
</div> </div>
</div> </div>
</div> </div>
@ -1210,10 +1211,14 @@ const UserInfo = ({user, groupId, roomId, onClose}) => {
title={_t('Close')} />; title={_t('Close')} />;
} }
const memberDetails = <PowerLevelSection const memberDetails = (
powerLevels={powerLevels} <PowerLevelSection
user={user} room={room} roomPermissions={roomPermissions} powerLevels={powerLevels}
/>; user={member}
room={room}
roomPermissions={roomPermissions}
/>
);
const isRoomEncrypted = useIsEncrypted(cli, room); const isRoomEncrypted = useIsEncrypted(cli, room);
// undefined means yet to be loaded, null means failed to load, otherwise list of devices // undefined means yet to be loaded, null means failed to load, otherwise list of devices
@ -1349,7 +1354,7 @@ const UserInfo = ({user, groupId, roomId, onClose}) => {
devices={devices} devices={devices}
canInvite={roomPermissions.canInvite} canInvite={roomPermissions.canInvite}
isIgnored={isIgnored} isIgnored={isIgnored}
member={user} /> member={member} />
{ adminToolsContainer } { adminToolsContainer }