{_t("You'll need to authenticate with the server to confirm the upgrade.")}
@@ -411,9 +463,9 @@ export default class CreateSecretStorageDialog extends React.PureComponent {
return
;
+ }
+
+ _renderPhasePassPhraseConfirm() {
+ const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
+ const Field = sdk.getComponent('views.elements.Field');
+
+ let matchText;
+ let changeText;
+ if (this.state.passPhraseConfirm === this.state.passPhrase) {
+ matchText = _t("That matches!");
+ changeText = _t("Use a different passphrase?");
+ } else if (!this.state.passPhrase.startsWith(this.state.passPhraseConfirm)) {
+ // only tell them they're wrong if they've actually gone wrong.
+ // Security concious readers will note that if you left riot-web unattended
+ // on this screen, this would make it easy for a malicious person to guess
+ // your passphrase one letter at a time, but they could get this faster by
+ // just opening the browser's developer tools and reading it.
+ // Note that not having typed anything at all will not hit this clause and
+ // fall through so empty box === no hint.
+ matchText = _t("That doesn't match.");
+ changeText = _t("Go back to set it again.");
}
+ let passPhraseMatch = null;
+ if (matchText) {
+ passPhraseMatch =
{_t(
- "Store your Recovery Key somewhere safe, it can be used to unlock your encrypted messages & data.",
+ "Your recovery key is a safety net - you can use it to restore " +
+ "access to your encrypted messages if you forget your recovery passphrase.",
+ )}
+
{_t(
+ "Keep a copy of it somewhere secure, like a password manager or even a safe.",
)}
;
}
- _renderPhaseIntro() {
- let cancelButton;
- if (this.props.force) {
- // if this is a forced key reset then aborting will just leave the old keys
- // in place, and is thereforece just 'cancel'
- cancelButton = ;
- } else {
- // if it's setting up from scratch then aborting leaves the user without
- // crypto set up, so they skipping the setup.
- cancelButton = ;
- }
-
+ _renderPhaseDone() {
+ const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
return
{_t(
- "Create a Recovery Key to store encryption keys & secrets with your account data. " +
- "If you lose access to this login you’ll need it to unlock your data.",
+ "You can now verify your other devices, " +
+ "and other users to keep your chats safe.",
)}
{_t(
"Without completing security on this session, it won’t have " +
"access to encrypted messages.",
)}
@@ -542,15 +716,21 @@ export default class CreateSecretStorageDialog extends React.PureComponent {
_titleForPhase(phase) {
switch (phase) {
- case PHASE_INTRO:
- return _t('Create a Recovery Key');
case PHASE_MIGRATE:
- return _t('Upgrade your Recovery Key');
+ return _t('Upgrade your encryption');
+ case PHASE_PASSPHRASE:
+ return _t('Set up encryption');
+ case PHASE_PASSPHRASE_CONFIRM:
+ return _t('Confirm recovery passphrase');
case PHASE_CONFIRM_SKIP:
return _t('Are you sure?');
case PHASE_SHOWKEY:
+ case PHASE_KEEPITSAFE:
+ return _t('Make a copy of your recovery key');
case PHASE_STORING:
- return _t('Store your Recovery Key');
+ return _t('Setting up keys');
+ case PHASE_DONE:
+ return _t("You're done!");
default:
return '';
}
@@ -561,6 +741,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent {
let content;
if (this.state.error) {
+ const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
content =
{_t("Unable to set up secret storage")}
@@ -579,16 +760,27 @@ export default class CreateSecretStorageDialog extends React.PureComponent {
case PHASE_LOADERROR:
content = this._renderPhaseLoadError();
break;
- case PHASE_INTRO:
- content = this._renderPhaseIntro();
- break;
case PHASE_MIGRATE:
content = this._renderPhaseMigrate();
break;
+ case PHASE_PASSPHRASE:
+ content = this._renderPhasePassPhrase();
+ break;
+ case PHASE_PASSPHRASE_CONFIRM:
+ content = this._renderPhasePassPhraseConfirm();
+ break;
case PHASE_SHOWKEY:
- case PHASE_STORING:
content = this._renderPhaseShowKey();
break;
+ case PHASE_KEEPITSAFE:
+ content = this._renderPhaseKeepItSafe();
+ break;
+ case PHASE_STORING:
+ content = this._renderBusyPhase();
+ break;
+ case PHASE_DONE:
+ content = this._renderPhaseDone();
+ break;
case PHASE_CONFIRM_SKIP:
content = this._renderPhaseSkipConfirm();
break;
@@ -605,7 +797,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent {
onFinished={this.props.onFinished}
title={this._titleForPhase(this.state.phase)}
headerImage={headerImage}
- hasCancel={this.props.hasCancel}
+ hasCancel={this.props.hasCancel && [PHASE_PASSPHRASE].includes(this.state.phase)}
fixedWidth={false}
>
{_t(
- "If you've forgotten your recovery key you can " +
- "", {}, {
- button: sub =>
- {sub}
- ,
- },
- )}
);
- } else if (phase === PHASE_RECOVERY_KEY) {
- const store = SetupEncryptionStore.sharedInstance();
- let keyPrompt;
- if (keyHasPassphrase(store.keyInfo)) {
- keyPrompt = _t(
- "Enter your Recovery Key or enter a Recovery Passphrase to continue.", {},
- {
- a: sub => {sub},
- },
- );
- } else {
- keyPrompt = _t("Enter your Recovery Key to continue.");
- }
-
- const Field = sdk.getComponent('elements.Field');
- return ;
} else if (phase === PHASE_DONE) {
let message;
if (this.state.backupInfo) {
diff --git a/src/components/views/dialogs/keybackup/RestoreKeyBackupDialog.js b/src/components/views/dialogs/keybackup/RestoreKeyBackupDialog.js
index 87ba6f7396..dd34dfbbf0 100644
--- a/src/components/views/dialogs/keybackup/RestoreKeyBackupDialog.js
+++ b/src/components/views/dialogs/keybackup/RestoreKeyBackupDialog.js
@@ -88,7 +88,7 @@ export default class RestoreKeyBackupDialog extends React.PureComponent {
_onResetRecoveryClick = () => {
this.props.onFinished(false);
- accessSecretStorage(() => {}, {forceReset: true});
+ accessSecretStorage(() => {}, /* forceReset = */ true);
}
_onRecoveryKeyChange = (e) => {
diff --git a/src/components/views/dialogs/secretstorage/AccessSecretStorageDialog.js b/src/components/views/dialogs/secretstorage/AccessSecretStorageDialog.js
index 43697f8ee7..e2ceadfbb9 100644
--- a/src/components/views/dialogs/secretstorage/AccessSecretStorageDialog.js
+++ b/src/components/views/dialogs/secretstorage/AccessSecretStorageDialog.js
@@ -32,9 +32,6 @@ export default class AccessSecretStorageDialog extends React.PureComponent {
keyInfo: PropTypes.object.isRequired,
// Function from one of { passphrase, recoveryKey } -> boolean
checkPrivateKey: PropTypes.func.isRequired,
- // If true, only prompt for a passphrase and do not offer to restore with
- // a recovery key or reset keys.
- passphraseOnly: PropTypes.bool,
}
constructor(props) {
@@ -61,7 +58,7 @@ export default class AccessSecretStorageDialog extends React.PureComponent {
_onResetRecoveryClick = () => {
// Re-enter the access flow, but resetting storage this time around.
this.props.onFinished(false);
- accessSecretStorage(() => {}, {forceReset: true});
+ accessSecretStorage(() => {}, /* forceReset = */ true);
}
_onRecoveryKeyChange = (e) => {
@@ -167,7 +164,7 @@ export default class AccessSecretStorageDialog extends React.PureComponent {
primaryDisabled={this.state.passPhrase.length === 0}
/>
- {this.props.passphraseOnly ? null : _t(
+ {_t(
"If you've forgotten your recovery passphrase you can "+
"use your recovery key or " +
"set up new recovery options."
@@ -237,7 +234,7 @@ export default class AccessSecretStorageDialog extends React.PureComponent {
primaryDisabled={!this.state.recoveryKeyValid}
/>
- {this.props.passphraseOnly ? null : _t(
+ {_t(
"If you've forgotten your recovery key you can "+
"."
, {}, {
diff --git a/src/components/views/rooms/RoomSublist2.tsx b/src/components/views/rooms/RoomSublist2.tsx
index bfa210ebf9..08a41570e3 100644
--- a/src/components/views/rooms/RoomSublist2.tsx
+++ b/src/components/views/rooms/RoomSublist2.tsx
@@ -41,6 +41,11 @@ import { ListAlgorithm, SortAlgorithm } from "../../../stores/room-list/algorith
* warning disappears. *
*******************************************************************/
+const SHOW_N_BUTTON_HEIGHT = 32; // As defined by CSS
+const RESIZE_HANDLE_HEIGHT = 4; // As defined by CSS
+
+const MAX_PADDING_HEIGHT = SHOW_N_BUTTON_HEIGHT + RESIZE_HANDLE_HEIGHT;
+
interface IProps {
forRooms: boolean;
rooms?: Room[];
@@ -105,7 +110,7 @@ export default class RoomSublist2 extends React.Component {
};
private onShowAllClick = () => {
- this.props.layout.visibleTiles = this.numTiles;
+ this.props.layout.visibleTiles = this.props.layout.tilesWithPadding(this.numTiles, MAX_PADDING_HEIGHT);
this.forceUpdate(); // because the layout doesn't trigger a re-render
};
@@ -359,7 +364,7 @@ export default class RoomSublist2 extends React.Component {
{showMoreText}
);
- } else if (tiles.length <= nVisible) {
+ } else if (tiles.length <= nVisible && tiles.length > this.props.layout.minVisibleTiles) {
// we have all tiles visible - add a button to show less
let showLessText = (
@@ -393,18 +398,16 @@ export default class RoomSublist2 extends React.Component {
// goes backwards and can become wildly incorrect (visibleTiles says 18 when there's
// only mathematically 7 possible).
- const showMoreHeight = 32; // As defined by CSS
- const resizeHandleHeight = 4; // As defined by CSS
-
// The padding is variable though, so figure out what we need padding for.
let padding = 0;
- if (showNButton) padding += showMoreHeight;
- if (handles.length > 0) padding += resizeHandleHeight;
+ if (showNButton) padding += SHOW_N_BUTTON_HEIGHT;
+ padding += RESIZE_HANDLE_HEIGHT; // always append the handle height
- const minTilesPx = layout.calculateTilesToPixelsMin(tiles.length, layout.minVisibleTiles, padding);
+ const relativeTiles = layout.tilesWithPadding(tiles.length, padding);
+ const minTilesPx = layout.calculateTilesToPixelsMin(relativeTiles, layout.minVisibleTiles, padding);
const maxTilesPx = layout.tilesToPixelsWithPadding(tiles.length, padding);
- const tilesWithoutPadding = Math.min(tiles.length, layout.visibleTiles);
- const tilesPx = layout.calculateTilesToPixelsMin(tiles.length, tilesWithoutPadding, padding);
+ const tilesWithoutPadding = Math.min(relativeTiles, layout.visibleTiles);
+ const tilesPx = layout.calculateTilesToPixelsMin(relativeTiles, tilesWithoutPadding, padding);
content = (
{
this.setState({ error: null });
try {
- await accessSecretStorage(() => undefined, {forceReset});
+ await accessSecretStorage(() => undefined, forceReset);
} catch (e) {
this.setState({ error: e });
console.error("Error bootstrapping secret storage", e);
diff --git a/src/components/views/settings/tabs/user/LabsUserSettingsTab.js b/src/components/views/settings/tabs/user/LabsUserSettingsTab.js
index 3e69107159..9724b9934f 100644
--- a/src/components/views/settings/tabs/user/LabsUserSettingsTab.js
+++ b/src/components/views/settings/tabs/user/LabsUserSettingsTab.js
@@ -66,7 +66,6 @@ export default class LabsUserSettingsTab extends React.Component {
-
);
diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json
index 5de33ada55..b659979fde 100644
--- a/src/i18n/strings/en_EN.json
+++ b/src/i18n/strings/en_EN.json
@@ -480,7 +480,6 @@
"Send read receipts for messages (requires compatible homeserver to disable)": "Send read receipts for messages (requires compatible homeserver to disable)",
"Show previews/thumbnails for images": "Show previews/thumbnails for images",
"Enable message search in encrypted rooms": "Enable message search in encrypted rooms",
- "Keep recovery passphrase in memory for this session": "Keep recovery passphrase in memory for this session",
"How fast should messages be downloaded.": "How fast should messages be downloaded.",
"Manually verify all remote sessions": "Manually verify all remote sessions",
"IRC display name width": "IRC display name width",
@@ -2068,7 +2067,6 @@
"Account settings": "Account settings",
"Could not load user profile": "Could not load user profile",
"Verify this login": "Verify this login",
- "Recovery Key": "Recovery Key",
"Session verified": "Session verified",
"Failed to send email": "Failed to send email",
"The email address linked to your account must be entered.": "The email address linked to your account must be entered.",
@@ -2122,16 +2120,10 @@
"You can now close this window or log in to your new account.": "You can now close this window or log in to your new account.",
"Registration Successful": "Registration Successful",
"Create your account": "Create your account",
- "This isn't the recovery key for your account": "This isn't the recovery key for your account",
- "This isn't a valid recovery key": "This isn't a valid recovery key",
- "Looks good!": "Looks good!",
- "Use Recovery Key or Passphrase": "Use Recovery Key or Passphrase",
- "Use Recovery Key": "Use Recovery Key",
"Confirm your identity by verifying this login from one of your other sessions, granting it access to encrypted messages.": "Confirm your identity by verifying this login from one of your other sessions, granting it access to encrypted messages.",
"This requires the latest Riot on your other devices:": "This requires the latest Riot on your other devices:",
"or another cross-signing capable Matrix client": "or another cross-signing capable Matrix client",
- "Enter your Recovery Key or enter a Recovery Passphrase to continue.": "Enter your Recovery Key or enter a Recovery Passphrase to continue.",
- "Enter your Recovery Key to continue.": "Enter your Recovery Key to continue.",
+ "Use Recovery Passphrase or Key": "Use Recovery Passphrase or Key",
"Your new session is now verified. It has access to your encrypted messages, and other users will see it as trusted.": "Your new session is now verified. It has access to your encrypted messages, and other users will see it as trusted.",
"Your new session is now verified. Other users will see it as trusted.": "Your new session is now verified. Other users will see it as trusted.",
"Without completing security on this session, it won’t have access to encrypted messages.": "Without completing security on this session, it won’t have access to encrypted messages.",
@@ -2175,43 +2167,47 @@
"Confirm encryption setup": "Confirm encryption setup",
"Click the button below to confirm setting up encryption.": "Click the button below to confirm setting up encryption.",
"Enter your account password to confirm the upgrade:": "Enter your account password to confirm the upgrade:",
+ "Restore your key backup to upgrade your encryption": "Restore your key backup to upgrade your encryption",
+ "Restore": "Restore",
"You'll need to authenticate with the server to confirm the upgrade.": "You'll need to authenticate with the server to confirm the upgrade.",
- "Upgrade your Recovery Key to store encryption keys & secrets with your account data. If you lose access to this login you'll need it to unlock your data.": "Upgrade your Recovery Key to store encryption keys & secrets with your account data. If you lose access to this login you'll need it to unlock your data.",
- "Store your Recovery Key somewhere safe, it can be used to unlock your encrypted messages & data.": "Store your Recovery Key somewhere safe, it can be used to unlock your encrypted messages & data.",
- "Download": "Download",
- "Copy": "Copy",
- "Unable to query secret storage status": "Unable to query secret storage status",
- "Retry": "Retry",
- "Create a Recovery Key to store encryption keys & secrets with your account data. If you lose access to this login you’ll need it to unlock your data.": "Create a Recovery Key to store encryption keys & secrets with your account data. If you lose access to this login you’ll need it to unlock your data.",
- "Create a Recovery Key": "Create a Recovery Key",
- "Upgrade your Recovery Key": "Upgrade your Recovery Key",
- "Store your Recovery Key": "Store your Recovery Key",
- "Unable to set up secret storage": "Unable to set up secret storage",
- "We'll store an encrypted copy of your keys on our server. Secure your backup with a recovery passphrase.": "We'll store an encrypted copy of your keys on our server. Secure your backup with a recovery passphrase.",
- "For maximum security, this should be different from your account password.": "For maximum security, this should be different from your account password.",
+ "Upgrade this session to allow it to verify other sessions, granting them access to encrypted messages and marking them as trusted for other users.": "Upgrade this session to allow it to verify other sessions, granting them access to encrypted messages and marking them as trusted for other users.",
+ "Set a recovery passphrase to secure encrypted information and recover it if you log out. This should be different to your account password:": "Set a recovery passphrase to secure encrypted information and recover it if you log out. This should be different to your account password:",
"Enter a recovery passphrase": "Enter a recovery passphrase",
"Great! This recovery passphrase looks strong enough.": "Great! This recovery passphrase looks strong enough.",
+ "Back up encrypted message keys": "Back up encrypted message keys",
"Set up with a recovery key": "Set up with a recovery key",
"That matches!": "That matches!",
"Use a different passphrase?": "Use a different passphrase?",
"That doesn't match.": "That doesn't match.",
"Go back to set it again.": "Go back to set it again.",
- "Please enter your recovery passphrase a second time to confirm.": "Please enter your recovery passphrase a second time to confirm.",
- "Repeat your recovery passphrase...": "Repeat your recovery passphrase...",
+ "Enter your recovery passphrase a second time to confirm it.": "Enter your recovery passphrase a second time to confirm it.",
+ "Confirm your recovery passphrase": "Confirm your recovery passphrase",
"Your recovery key is a safety net - you can use it to restore access to your encrypted messages if you forget your recovery passphrase.": "Your recovery key is a safety net - you can use it to restore access to your encrypted messages if you forget your recovery passphrase.",
"Keep a copy of it somewhere secure, like a password manager or even a safe.": "Keep a copy of it somewhere secure, like a password manager or even a safe.",
"Your recovery key": "Your recovery key",
+ "Copy": "Copy",
+ "Download": "Download",
"Your recovery key has been copied to your clipboard, paste it to:": "Your recovery key has been copied to your clipboard, paste it to:",
"Your recovery key is in your Downloads folder.": "Your recovery key is in your Downloads folder.",
"Print it and store it somewhere safe": "Print it and store it somewhere safe",
"Save it on a USB key or backup drive": "Save it on a USB key or backup drive",
"Copy it to your personal cloud storage": "Copy it to your personal cloud storage",
+ "Unable to query secret storage status": "Unable to query secret storage status",
+ "Retry": "Retry",
+ "You can now verify your other devices, and other users to keep your chats safe.": "You can now verify your other devices, and other users to keep your chats safe.",
+ "Upgrade your encryption": "Upgrade your encryption",
+ "Confirm recovery passphrase": "Confirm recovery passphrase",
+ "Make a copy of your recovery key": "Make a copy of your recovery key",
+ "You're done!": "You're done!",
+ "Unable to set up secret storage": "Unable to set up secret storage",
+ "We'll store an encrypted copy of your keys on our server. Secure your backup with a recovery passphrase.": "We'll store an encrypted copy of your keys on our server. Secure your backup with a recovery passphrase.",
+ "For maximum security, this should be different from your account password.": "For maximum security, this should be different from your account password.",
+ "Please enter your recovery passphrase a second time to confirm.": "Please enter your recovery passphrase a second time to confirm.",
+ "Repeat your recovery passphrase...": "Repeat your recovery passphrase...",
"Your keys are being backed up (the first backup could take a few minutes).": "Your keys are being backed up (the first backup could take a few minutes).",
"Without setting up Secure Message Recovery, you won't be able to restore your encrypted message history if you log out or use another session.": "Without setting up Secure Message Recovery, you won't be able to restore your encrypted message history if you log out or use another session.",
"Set up Secure Message Recovery": "Set up Secure Message Recovery",
"Secure your backup with a recovery passphrase": "Secure your backup with a recovery passphrase",
- "Confirm your recovery passphrase": "Confirm your recovery passphrase",
- "Make a copy of your recovery key": "Make a copy of your recovery key",
"Starting backup...": "Starting backup...",
"Success!": "Success!",
"Create key backup": "Create key backup",
diff --git a/src/settings/Settings.js b/src/settings/Settings.js
index 225af15ec8..5e439a1d71 100644
--- a/src/settings/Settings.js
+++ b/src/settings/Settings.js
@@ -521,11 +521,6 @@ export const SETTINGS = {
displayName: _td("Enable message search in encrypted rooms"),
default: true,
},
- "keepSecretStoragePassphraseForSession": {
- supportedLevels: ['device', 'config'],
- displayName: _td("Keep recovery passphrase in memory for this session"),
- default: false,
- },
"crawlerSleepTime": {
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,
displayName: _td("How fast should messages be downloaded."),
diff --git a/src/stores/SetupEncryptionStore.js b/src/stores/SetupEncryptionStore.js
index cc64e24a03..ae1f998b02 100644
--- a/src/stores/SetupEncryptionStore.js
+++ b/src/stores/SetupEncryptionStore.js
@@ -20,11 +20,10 @@ import { accessSecretStorage, AccessCancelledError } from '../CrossSigningManage
import { PHASE_DONE as VERIF_PHASE_DONE } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
export const PHASE_INTRO = 0;
-export const PHASE_RECOVERY_KEY = 1;
-export const PHASE_BUSY = 2;
-export const PHASE_DONE = 3; //final done stage, but still showing UX
-export const PHASE_CONFIRM_SKIP = 4;
-export const PHASE_FINISHED = 5; //UX can be closed
+export const PHASE_BUSY = 1;
+export const PHASE_DONE = 2; //final done stage, but still showing UX
+export const PHASE_CONFIRM_SKIP = 3;
+export const PHASE_FINISHED = 4; //UX can be closed
export class SetupEncryptionStore extends EventEmitter {
static sharedInstance() {
@@ -37,19 +36,11 @@ export class SetupEncryptionStore extends EventEmitter {
return;
}
this._started = true;
- this.phase = PHASE_BUSY;
+ this.phase = PHASE_INTRO;
this.verificationRequest = null;
this.backupInfo = null;
-
- // ID of the key that the secrets we want are encrypted with
- this.keyId = null;
- // Descriptor of the key that the secrets we want are encrypted with
- this.keyInfo = null;
-
MatrixClientPeg.get().on("crypto.verification.request", this.onVerificationRequest);
MatrixClientPeg.get().on('userTrustStatusChanged', this._onUserTrustStatusChanged);
-
- this.fetchKeyInfo();
}
stop() {
@@ -66,49 +57,7 @@ export class SetupEncryptionStore extends EventEmitter {
}
}
- async fetchKeyInfo() {
- const keys = await MatrixClientPeg.get().isSecretStored('m.cross_signing.master', false);
- if (Object.keys(keys).length === 0) {
- this.keyId = null;
- this.keyInfo = null;
- } else {
- // If the secret is stored under more than one key, we just pick an arbitrary one
- this.keyId = Object.keys(keys)[0];
- this.keyInfo = keys[this.keyId];
- }
-
- this.phase = PHASE_INTRO;
- this.emit("update");
- }
-
- async startKeyReset() {
- try {
- await accessSecretStorage(() => {}, {forceReset: true});
- // If the keys are reset, the trust status event will fire and we'll change state
- } catch (e) {
- // dialog was cancelled - stay on the current screen
- }
- }
-
- async useRecoveryKey() {
- this.phase = PHASE_RECOVERY_KEY;
- this.emit("update");
- }
-
- cancelUseRecoveryKey() {
- this.phase = PHASE_INTRO;
- this.emit("update");
- }
-
- async setupWithRecoveryKey(recoveryKey) {
- this.startTrustCheck({[this.keyId]: recoveryKey});
- }
-
async usePassPhrase() {
- this.startTrustCheck();
- }
-
- async startTrustCheck(withKeys) {
this.phase = PHASE_BUSY;
this.emit("update");
const cli = MatrixClientPeg.get();
@@ -135,9 +84,6 @@ export class SetupEncryptionStore extends EventEmitter {
// to advance before this.
await cli.restoreKeyBackupWithSecretStorage(backupInfo);
}
- }, {
- withKeys,
- passphraseOnly: true,
}).catch(reject);
} catch (e) {
console.error(e);
diff --git a/src/stores/room-list/ListLayout.ts b/src/stores/room-list/ListLayout.ts
index f17001f64e..ebc7b95854 100644
--- a/src/stores/room-list/ListLayout.ts
+++ b/src/stores/room-list/ListLayout.ts
@@ -92,8 +92,12 @@ export class ListLayout {
return this.tilesToPixels(Math.min(maxTiles, n)) + padding;
}
- public tilesToPixelsWithPadding(n: number, padding: number): number {
- return this.tilesToPixels(n) + padding;
+ public tilesWithPadding(n: number, paddingPx: number): number {
+ return this.pixelsToTiles(this.tilesToPixelsWithPadding(n, paddingPx));
+ }
+
+ public tilesToPixelsWithPadding(n: number, paddingPx: number): number {
+ return this.tilesToPixels(n) + paddingPx;
}
public tilesToPixels(n: number): number {
diff --git a/src/stores/room-list/algorithms/Algorithm.ts b/src/stores/room-list/algorithms/Algorithm.ts
index d145149cc7..052c58bb83 100644
--- a/src/stores/room-list/algorithms/Algorithm.ts
+++ b/src/stores/room-list/algorithms/Algorithm.ts
@@ -508,16 +508,14 @@ export class Algorithm extends EventEmitter {
return true;
}
- if (cause === RoomUpdateCause.NewRoom) {
- // TODO: Be smarter and insert rather than regen the planet.
- await this.setKnownRooms([room, ...this.rooms]);
- return true;
- }
-
- if (cause === RoomUpdateCause.RoomRemoved) {
- // TODO: Be smarter and splice rather than regen the planet.
- await this.setKnownRooms(this.rooms.filter(r => r !== room));
- return true;
+ // If the update is for a room change which might be the sticky room, prevent it. We
+ // need to make sure that the causes (NewRoom and RoomRemoved) are still triggered though
+ // as the sticky room relies on this.
+ if (cause !== RoomUpdateCause.NewRoom && cause !== RoomUpdateCause.RoomRemoved) {
+ if (this.stickyRoom === room) {
+ console.warn(`[RoomListDebug] Received ${cause} update for sticky room ${room.roomId} - ignoring`);
+ return false;
+ }
}
let tags = this.roomIdsToTags[room.roomId];
diff --git a/src/stores/room-list/algorithms/list-ordering/ImportanceAlgorithm.ts b/src/stores/room-list/algorithms/list-ordering/ImportanceAlgorithm.ts
index 325aaf19e6..6e09b0f8d3 100644
--- a/src/stores/room-list/algorithms/list-ordering/ImportanceAlgorithm.ts
+++ b/src/stores/room-list/algorithms/list-ordering/ImportanceAlgorithm.ts
@@ -87,7 +87,7 @@ export class ImportanceAlgorithm extends OrderingAlgorithm {
public constructor(tagId: TagID, initialSortingAlgorithm: SortAlgorithm) {
super(tagId, initialSortingAlgorithm);
- console.log("Constructed an ImportanceAlgorithm");
+ console.log(`[RoomListDebug] Constructed an ImportanceAlgorithm for ${tagId}`);
}
// noinspection JSMethodCanBeStatic
@@ -151,8 +151,36 @@ export class ImportanceAlgorithm extends OrderingAlgorithm {
}
}
+ private async handleSplice(room: Room, cause: RoomUpdateCause): Promise {
+ if (cause === RoomUpdateCause.NewRoom) {
+ const category = this.getRoomCategory(room);
+ this.alterCategoryPositionBy(category, 1, this.indices);
+ this.cachedOrderedRooms.splice(this.indices[category], 0, room); // splice in the new room (pre-adjusted)
+ } else if (cause === RoomUpdateCause.RoomRemoved) {
+ const roomIdx = this.getRoomIndex(room);
+ if (roomIdx === -1) return false; // no change
+ const oldCategory = this.getCategoryFromIndices(roomIdx, this.indices);
+ this.alterCategoryPositionBy(oldCategory, -1, this.indices);
+ this.cachedOrderedRooms.splice(roomIdx, 1); // remove the room
+ } else {
+ throw new Error(`Unhandled splice: ${cause}`);
+ }
+ }
+
+ private getRoomIndex(room: Room): number {
+ let roomIdx = this.cachedOrderedRooms.indexOf(room);
+ if (roomIdx === -1) { // can only happen if the js-sdk's store goes sideways.
+ console.warn(`Degrading performance to find missing room in "${this.tagId}": ${room.roomId}`);
+ roomIdx = this.cachedOrderedRooms.findIndex(r => r.roomId === room.roomId);
+ }
+ return roomIdx;
+ }
+
public async handleRoomUpdate(room: Room, cause: RoomUpdateCause): Promise {
- // TODO: Handle NewRoom and RoomRemoved
+ if (cause === RoomUpdateCause.NewRoom || cause === RoomUpdateCause.RoomRemoved) {
+ return this.handleSplice(room, cause);
+ }
+
if (cause !== RoomUpdateCause.Timeline && cause !== RoomUpdateCause.ReadReceipt) {
throw new Error(`Unsupported update cause: ${cause}`);
}
@@ -162,11 +190,7 @@ export class ImportanceAlgorithm extends OrderingAlgorithm {
return; // Nothing to do here.
}
- let roomIdx = this.cachedOrderedRooms.indexOf(room);
- if (roomIdx === -1) { // can only happen if the js-sdk's store goes sideways.
- console.warn(`Degrading performance to find missing room in "${this.tagId}": ${room.roomId}`);
- roomIdx = this.cachedOrderedRooms.findIndex(r => r.roomId === room.roomId);
- }
+ const roomIdx = this.getRoomIndex(room);
if (roomIdx === -1) {
throw new Error(`Room ${room.roomId} has no index in ${this.tagId}`);
}
@@ -188,12 +212,18 @@ export class ImportanceAlgorithm extends OrderingAlgorithm {
// room from the array.
}
- // The room received an update, so take out the slice and sort it. This should be relatively
- // quick because the room is inserted at the top of the category, and most popular sorting
- // algorithms will deal with trying to keep the active room at the top/start of the category.
- // For the few algorithms that will have to move the thing quite far (alphabetic with a Z room
- // for example), the list should already be sorted well enough that it can rip through the
- // array and slot the changed room in quickly.
+ // Sort the category now that we've dumped the room in
+ await this.sortCategory(category);
+
+ return true; // change made
+ }
+
+ private async sortCategory(category: Category) {
+ // This should be relatively quick because the room is usually inserted at the top of the
+ // category, and most popular sorting algorithms will deal with trying to keep the active
+ // room at the top/start of the category. For the few algorithms that will have to move the
+ // thing quite far (alphabetic with a Z room for example), the list should already be sorted
+ // well enough that it can rip through the array and slot the changed room in quickly.
const nextCategoryStartIdx = category === CATEGORY_ORDER[CATEGORY_ORDER.length - 1]
? Number.MAX_SAFE_INTEGER
: this.indices[CATEGORY_ORDER[CATEGORY_ORDER.indexOf(category) + 1]];
@@ -202,8 +232,6 @@ export class ImportanceAlgorithm extends OrderingAlgorithm {
const unsortedSlice = this.cachedOrderedRooms.splice(startIdx, numSort);
const sorted = await sortRoomsWithAlgorithm(unsortedSlice, this.tagId, this.sortingAlgorithm);
this.cachedOrderedRooms.splice(startIdx, 0, ...sorted);
-
- return true; // change made
}
// noinspection JSMethodCanBeStatic
@@ -230,14 +258,29 @@ export class ImportanceAlgorithm extends OrderingAlgorithm {
// We also need to update subsequent categories as they'll all shift by nRooms, so we
// loop over the order to achieve that.
- for (let i = CATEGORY_ORDER.indexOf(fromCategory) + 1; i < CATEGORY_ORDER.length; i++) {
- const nextCategory = CATEGORY_ORDER[i];
- indices[nextCategory] -= nRooms;
- }
+ this.alterCategoryPositionBy(fromCategory, -nRooms, indices);
+ this.alterCategoryPositionBy(toCategory, +nRooms, indices);
+ }
- for (let i = CATEGORY_ORDER.indexOf(toCategory) + 1; i < CATEGORY_ORDER.length; i++) {
- const nextCategory = CATEGORY_ORDER[i];
- indices[nextCategory] += nRooms;
+ private alterCategoryPositionBy(category: Category, n: number, indices: ICategoryIndex) {
+ // Note: when we alter a category's index, we actually have to modify the ones following
+ // the target and not the target itself.
+
+ // XXX: If this ever actually gets more than one room passed to it, it'll need more index
+ // handling. For instance, if 45 rooms are removed from the middle of a 50 room list, the
+ // index for the categories will be way off.
+
+ const nextOrderIndex = CATEGORY_ORDER.indexOf(category) + 1
+ if (n > 0) {
+ for (let i = nextOrderIndex; i < CATEGORY_ORDER.length; i++) {
+ const nextCategory = CATEGORY_ORDER[i];
+ indices[nextCategory] += Math.abs(n);
+ }
+ } else if (n < 0) {
+ for (let i = nextOrderIndex; i < CATEGORY_ORDER.length; i++) {
+ const nextCategory = CATEGORY_ORDER[i];
+ indices[nextCategory] -= Math.abs(n);
+ }
}
// Do a quick check to see if we've completely broken the index
diff --git a/src/stores/room-list/algorithms/list-ordering/NaturalAlgorithm.ts b/src/stores/room-list/algorithms/list-ordering/NaturalAlgorithm.ts
index cce7372986..96a3f58d2c 100644
--- a/src/stores/room-list/algorithms/list-ordering/NaturalAlgorithm.ts
+++ b/src/stores/room-list/algorithms/list-ordering/NaturalAlgorithm.ts
@@ -28,7 +28,7 @@ export class NaturalAlgorithm extends OrderingAlgorithm {
public constructor(tagId: TagID, initialSortingAlgorithm: SortAlgorithm) {
super(tagId, initialSortingAlgorithm);
- console.log("Constructed a NaturalAlgorithm");
+ console.log(`[RoomListDebug] Constructed a NaturalAlgorithm for ${tagId}`);
}
public async setRooms(rooms: Room[]): Promise {
@@ -36,11 +36,19 @@ export class NaturalAlgorithm extends OrderingAlgorithm {
}
public async handleRoomUpdate(room, cause): Promise {
- // TODO: Handle NewRoom and RoomRemoved
- if (cause !== RoomUpdateCause.Timeline && cause !== RoomUpdateCause.ReadReceipt) {
+ const isSplice = cause === RoomUpdateCause.NewRoom || cause === RoomUpdateCause.RoomRemoved;
+ const isInPlace = cause === RoomUpdateCause.Timeline || cause === RoomUpdateCause.ReadReceipt;
+ if (!isSplice && !isInPlace) {
throw new Error(`Unsupported update cause: ${cause}`);
}
+ if (cause === RoomUpdateCause.NewRoom) {
+ this.cachedOrderedRooms.push(room);
+ } else if (cause === RoomUpdateCause.RoomRemoved) {
+ const idx = this.cachedOrderedRooms.indexOf(room);
+ if (idx >= 0) this.cachedOrderedRooms.splice(idx, 1);
+ }
+
// TODO: Optimize this to avoid useless operations
// For example, we can skip updates to alphabetic (sometimes) and manually ordered tags
this.cachedOrderedRooms = await sortRoomsWithAlgorithm(this.cachedOrderedRooms, this.tagId, this.sortingAlgorithm);
diff --git a/src/stores/room-list/algorithms/list-ordering/OrderingAlgorithm.ts b/src/stores/room-list/algorithms/list-ordering/OrderingAlgorithm.ts
index 263e8a4cd4..f581e30630 100644
--- a/src/stores/room-list/algorithms/list-ordering/OrderingAlgorithm.ts
+++ b/src/stores/room-list/algorithms/list-ordering/OrderingAlgorithm.ts
@@ -67,6 +67,5 @@ export abstract class OrderingAlgorithm {
* @param cause The cause of the update.
* @returns True if the update requires the Algorithm to update the presentation layers.
*/
- // XXX: TODO: We assume this will only ever be a position update and NOT a NewRoom or RemoveRoom change!!
public abstract handleRoomUpdate(room: Room, cause: RoomUpdateCause): Promise;
}
diff --git a/test/end-to-end-tests/src/usecases/signup.js b/test/end-to-end-tests/src/usecases/signup.js
index 2859aadbda..aa9f6b7efa 100644
--- a/test/end-to-end-tests/src/usecases/signup.js
+++ b/test/end-to-end-tests/src/usecases/signup.js
@@ -79,7 +79,20 @@ module.exports = async function signup(session, username, password, homeserver)
const acceptButton = await session.query('.mx_InteractiveAuthEntryComponents_termsSubmit');
await acceptButton.click();
- const xsignContButton = await session.query('.mx_CreateSecretStorageDialog .mx_Dialog_buttons .mx_Dialog_primary');
+ //plow through cross-signing setup by entering arbitrary details
+ //TODO: It's probably important for the tests to know the passphrase
+ const xsigningPassphrase = 'a7eaXcjpa9!Yl7#V^h$B^%dovHUVX'; // https://xkcd.com/221/
+ let passphraseField = await session.query('.mx_CreateSecretStorageDialog_passPhraseField input');
+ await session.replaceInputText(passphraseField, xsigningPassphrase);
+ await session.delay(1000); // give it a second to analyze our passphrase for security
+ let xsignContButton = await session.query('.mx_CreateSecretStorageDialog .mx_Dialog_buttons .mx_Dialog_primary');
+ await xsignContButton.click();
+
+ //repeat passphrase entry
+ passphraseField = await session.query('.mx_CreateSecretStorageDialog_passPhraseField input');
+ await session.replaceInputText(passphraseField, xsigningPassphrase);
+ await session.delay(1000); // give it a second to analyze our passphrase for security
+ xsignContButton = await session.query('.mx_CreateSecretStorageDialog .mx_Dialog_buttons .mx_Dialog_primary');
await xsignContButton.click();
//ignore the recovery key
@@ -88,11 +101,13 @@ module.exports = async function signup(session, username, password, homeserver)
await copyButton.click();
//acknowledge that we copied the recovery key to a safe place
- const copyContinueButton = await session.query(
- '.mx_CreateSecretStorageDialog .mx_Dialog_buttons .mx_Dialog_primary',
- );
+ const copyContinueButton = await session.query('.mx_CreateSecretStorageDialog .mx_Dialog_primary');
await copyContinueButton.click();
+ //acknowledge that we're done cross-signing setup and our keys are safe
+ const doneOkButton = await session.query('.mx_CreateSecretStorageDialog .mx_Dialog_primary');
+ await doneOkButton.click();
+
//wait for registration to finish so the hash gets set
//onhashchange better?