Merge pull request #4284 from matrix-org/bwindels/showverifreqinsteadofmember

Show ongoing verification request straight away when navigating to member
This commit is contained in:
Bruno Windels 2020-03-27 10:19:31 +00:00 committed by GitHub
commit 528c820a2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 10 deletions

View file

@ -15,6 +15,7 @@ limitations under the License.
*/ */
import dis from '../dispatcher'; import dis from '../dispatcher';
import {pendingVerificationRequestForUser} from '../verification';
import {Store} from 'flux/utils'; import {Store} from 'flux/utils';
import SettingsStore, {SettingLevel} from "../settings/SettingsStore"; import SettingsStore, {SettingLevel} from "../settings/SettingsStore";
import {RIGHT_PANEL_PHASES, RIGHT_PANEL_PHASES_NO_ARGS} from "./RightPanelStorePhases"; import {RIGHT_PANEL_PHASES, RIGHT_PANEL_PHASES_NO_ARGS} from "./RightPanelStorePhases";
@ -135,7 +136,20 @@ export default class RightPanelStore extends Store {
break; break;
case 'set_right_panel_phase': { case 'set_right_panel_phase': {
const targetPhase = payload.phase; let targetPhase = payload.phase;
let refireParams = payload.refireParams;
// redirect to EncryptionPanel if there is an ongoing verification request
if (targetPhase === RIGHT_PANEL_PHASES.RoomMemberInfo) {
const {member} = payload.refireParams;
const pendingRequest = pendingVerificationRequestForUser(member);
if (pendingRequest) {
targetPhase = RIGHT_PANEL_PHASES.EncryptionPanel;
refireParams = {
verificationRequest: pendingRequest,
member,
};
}
}
if (!RIGHT_PANEL_PHASES[targetPhase]) { if (!RIGHT_PANEL_PHASES[targetPhase]) {
console.warn(`Tried to switch right panel to unknown phase: ${targetPhase}`); console.warn(`Tried to switch right panel to unknown phase: ${targetPhase}`);
return; return;
@ -153,7 +167,7 @@ export default class RightPanelStore extends Store {
}); });
} }
} else { } else {
if (targetPhase === this._state.lastRoomPhase && !payload.refireParams) { if (targetPhase === this._state.lastRoomPhase && !refireParams) {
this._setState({ this._setState({
showRoomPanel: !this._state.showRoomPanel, showRoomPanel: !this._state.showRoomPanel,
}); });
@ -161,7 +175,7 @@ export default class RightPanelStore extends Store {
this._setState({ this._setState({
lastRoomPhase: targetPhase, lastRoomPhase: targetPhase,
showRoomPanel: true, showRoomPanel: true,
lastRoomPhaseParams: payload.refireParams || {}, lastRoomPhaseParams: refireParams || {},
}); });
} }
} }
@ -170,7 +184,7 @@ export default class RightPanelStore extends Store {
dis.dispatch({ dis.dispatch({
action: 'after_right_panel_phase_change', action: 'after_right_panel_phase_change',
phase: targetPhase, phase: targetPhase,
...(payload.refireParams || {}), ...(refireParams || {}),
}); });
break; break;
} }

View file

@ -111,12 +111,7 @@ export async function verifyUser(user) {
if (!await enable4SIfNeeded()) { if (!await enable4SIfNeeded()) {
return; return;
} }
const cli = MatrixClientPeg.get(); const existingRequest = pendingVerificationRequestForUser(user);
const dmRoom = findDMForUser(cli, user.userId);
let existingRequest;
if (dmRoom) {
existingRequest = cli.findVerificationRequestDMInProgress(dmRoom.roomId);
}
dis.dispatch({ dis.dispatch({
action: "set_right_panel_phase", action: "set_right_panel_phase",
phase: RIGHT_PANEL_PHASES.EncryptionPanel, phase: RIGHT_PANEL_PHASES.EncryptionPanel,
@ -126,3 +121,11 @@ export async function verifyUser(user) {
}, },
}); });
} }
export function pendingVerificationRequestForUser(user) {
const cli = MatrixClientPeg.get();
const dmRoom = findDMForUser(cli, user.userId);
if (dmRoom) {
return cli.findVerificationRequestDMInProgress(dmRoom.roomId);
}
}