From 344cc079c5fdf9006d2661b80d9618b2a1011a93 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 3 Jul 2019 12:16:58 +0200 Subject: [PATCH 1/3] show /relations error in edit history dialog --- .../dialogs/_MessageEditHistoryDialog.scss | 5 +++ .../views/dialogs/MessageEditHistoryDialog.js | 32 ++++++++++++++++--- src/i18n/strings/en_EN.json | 3 ++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/res/css/views/dialogs/_MessageEditHistoryDialog.scss b/res/css/views/dialogs/_MessageEditHistoryDialog.scss index b80742bd24..951b863e6a 100644 --- a/res/css/views/dialogs/_MessageEditHistoryDialog.scss +++ b/res/css/views/dialogs/_MessageEditHistoryDialog.scss @@ -28,6 +28,11 @@ limitations under the License. flex: 1 1 auto; } +.mx_MessageEditHistoryDialog_error { + color: $warning-color; + text-align: center; +} + .mx_MessageEditHistoryDialog_edits { list-style-type: none; font-size: 14px; diff --git a/src/components/views/dialogs/MessageEditHistoryDialog.js b/src/components/views/dialogs/MessageEditHistoryDialog.js index 9d533eab56..bba000e013 100644 --- a/src/components/views/dialogs/MessageEditHistoryDialog.js +++ b/src/components/views/dialogs/MessageEditHistoryDialog.js @@ -30,6 +30,7 @@ export default class MessageEditHistoryDialog extends React.PureComponent { constructor(props) { super(props); this.state = { + error: null, events: [], nextBatch: null, isLoading: true, @@ -45,10 +46,17 @@ export default class MessageEditHistoryDialog extends React.PureComponent { const opts = {from: this.state.nextBatch}; const roomId = this.props.mxEvent.getRoomId(); const eventId = this.props.mxEvent.getId(); - const result = await MatrixClientPeg.get().relations( - roomId, eventId, "m.replace", "m.room.message", opts); + let result; let resolve; - const promise = new Promise(r => resolve = r); + let reject; + const promise = new Promise((_resolve, _reject) => {resolve = _resolve; reject = _reject;}); + try { + result = await MatrixClientPeg.get().relations( + roomId, eventId, "m.replace", "m.room.message", opts); + } catch (error) { + this.setState({error}, () => reject(error)); + return promise; + } this.setState({ events: this.state.events.concat(result.events), nextBatch: result.nextBatch, @@ -82,7 +90,23 @@ export default class MessageEditHistoryDialog extends React.PureComponent { render() { let content; if (this.state.error) { - content = this.state.error; + const {error} = this.state; + if (error.errcode === "M_UNRECOGNIZED") { + content = (

+ {_t("Your homeserver doesn't seem to support this feature.")} +

); + } else if (error.errcode) { + // some kind of error from the homeserver + content = (

+ {_t("Something went wrong!")} +

); + } else { + content = (

+ {_t("Could not reach your homeserver to fetch the edit history.")} +
+ {_t("Verify your internet connection or try again later.")} +

); + } } else if (this.state.isLoading) { const Spinner = sdk.getComponent("elements.Spinner"); content = ; diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index c84125d820..85cb6f1fe2 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1203,6 +1203,9 @@ "Manually export keys": "Manually export keys", "You'll lose access to your encrypted messages": "You'll lose access to your encrypted messages", "Are you sure you want to sign out?": "Are you sure you want to sign out?", + "Your homeserver doesn't seem to support this feature.": "Your homeserver doesn't seem to support this feature.", + "Could not reach your homeserver to fetch the edit history.": "Could not reach your homeserver to fetch the edit history.", + "Verify your internet connection or try again later.": "Verify your internet connection or try again later.", "Message edits": "Message edits", "If you run into any bugs or have feedback you'd like to share, please let us know on GitHub.": "If you run into any bugs or have feedback you'd like to share, please let us know on GitHub.", "To help avoid duplicate issues, please view existing issues first (and add a +1) or create a new issue if you can't find it.": "To help avoid duplicate issues, please view existing issues first (and add a +1) or create a new issue if you can't find it.", From e7e6af2592620dcfa4f780578d3cd8534cdc5e8c Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 3 Jul 2019 17:51:16 +0200 Subject: [PATCH 2/3] use existing strings --- src/components/views/dialogs/MessageEditHistoryDialog.js | 4 ++-- src/i18n/strings/en_EN.json | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/views/dialogs/MessageEditHistoryDialog.js b/src/components/views/dialogs/MessageEditHistoryDialog.js index bba000e013..0974ba7dfe 100644 --- a/src/components/views/dialogs/MessageEditHistoryDialog.js +++ b/src/components/views/dialogs/MessageEditHistoryDialog.js @@ -102,9 +102,9 @@ export default class MessageEditHistoryDialog extends React.PureComponent {

); } else { content = (

- {_t("Could not reach your homeserver to fetch the edit history.")} + {_t("Cannot reach homeserver")}
- {_t("Verify your internet connection or try again later.")} + {_t("Ensure you have a stable internet connection, or get in touch with the server admin")}

); } } else if (this.state.isLoading) { diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 85cb6f1fe2..0f1b6ebbc1 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1204,8 +1204,6 @@ "You'll lose access to your encrypted messages": "You'll lose access to your encrypted messages", "Are you sure you want to sign out?": "Are you sure you want to sign out?", "Your homeserver doesn't seem to support this feature.": "Your homeserver doesn't seem to support this feature.", - "Could not reach your homeserver to fetch the edit history.": "Could not reach your homeserver to fetch the edit history.", - "Verify your internet connection or try again later.": "Verify your internet connection or try again later.", "Message edits": "Message edits", "If you run into any bugs or have feedback you'd like to share, please let us know on GitHub.": "If you run into any bugs or have feedback you'd like to share, please let us know on GitHub.", "To help avoid duplicate issues, please view existing issues first (and add a +1) or create a new issue if you can't find it.": "To help avoid duplicate issues, please view existing issues first (and add a +1) or create a new issue if you can't find it.", From 4dc8de0e713e2dd2003475f93470e2495a51d513 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 3 Jul 2019 17:53:32 +0200 Subject: [PATCH 3/3] log server errors in edit history dialog --- src/components/views/dialogs/MessageEditHistoryDialog.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/views/dialogs/MessageEditHistoryDialog.js b/src/components/views/dialogs/MessageEditHistoryDialog.js index 0974ba7dfe..b30891488b 100644 --- a/src/components/views/dialogs/MessageEditHistoryDialog.js +++ b/src/components/views/dialogs/MessageEditHistoryDialog.js @@ -54,6 +54,10 @@ export default class MessageEditHistoryDialog extends React.PureComponent { result = await MatrixClientPeg.get().relations( roomId, eventId, "m.replace", "m.room.message", opts); } catch (error) { + // log if the server returned an error + if (error.errcode) { + console.error("fetching /relations failed with error", error); + } this.setState({error}, () => reject(error)); return promise; }