From 4bd7ae51312f2ad5c0d051d60408067167ca28ba Mon Sep 17 00:00:00 2001
From: Michael Telatynski <7t3chguy@gmail.com>
Date: Thu, 1 Oct 2020 15:49:22 +0100
Subject: [PATCH] Show server errors from saving profile settings
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
---
.../views/settings/ProfileSettings.js | 35 +++++++++++--------
src/i18n/strings/en_EN.json | 2 ++
2 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/src/components/views/settings/ProfileSettings.js b/src/components/views/settings/ProfileSettings.js
index 651aa9f48d..ddaec19d74 100644
--- a/src/components/views/settings/ProfileSettings.js
+++ b/src/components/views/settings/ProfileSettings.js
@@ -21,6 +21,8 @@ import Field from "../elements/Field";
import {User} from "matrix-js-sdk";
import { getHostingLink } from '../../../utils/HostingLink';
import * as sdk from "../../../index";
+import Modal from "../../../Modal";
+import ErrorDialog from "../dialogs/ErrorDialog";
export default class ProfileSettings extends React.Component {
constructor() {
@@ -84,21 +86,26 @@ export default class ProfileSettings extends React.Component {
const client = MatrixClientPeg.get();
const newState = {};
- // TODO: What do we do about errors?
+ try {
+ if (this.state.originalDisplayName !== this.state.displayName) {
+ await client.setDisplayName(this.state.displayName);
+ newState.originalDisplayName = this.state.displayName;
+ }
- if (this.state.originalDisplayName !== this.state.displayName) {
- await client.setDisplayName(this.state.displayName);
- newState.originalDisplayName = this.state.displayName;
- }
-
- if (this.state.avatarFile) {
- const uri = await client.uploadContent(this.state.avatarFile);
- await client.setAvatarUrl(uri);
- newState.avatarUrl = client.mxcUrlToHttp(uri, 96, 96, 'crop', false);
- newState.originalAvatarUrl = newState.avatarUrl;
- newState.avatarFile = null;
- } else if (this.state.originalAvatarUrl !== this.state.avatarUrl) {
- await client.setAvatarUrl(""); // use empty string as Synapse 500s on undefined
+ if (this.state.avatarFile) {
+ const uri = await client.uploadContent(this.state.avatarFile);
+ await client.setAvatarUrl(uri);
+ newState.avatarUrl = client.mxcUrlToHttp(uri, 96, 96, 'crop', false);
+ newState.originalAvatarUrl = newState.avatarUrl;
+ newState.avatarFile = null;
+ } else if (this.state.originalAvatarUrl !== this.state.avatarUrl) {
+ await client.setAvatarUrl(""); // use empty string as Synapse 500s on undefined
+ }
+ } catch (err) {
+ Modal.createTrackedDialog('Failed to save profile', '', ErrorDialog, {
+ title: _t("Failed to save your profile"),
+ description: ((err && err.message) ? err.message : _t("The operation could not be completed")),
+ });
}
this.setState(newState);
diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json
index a377663570..17c1858c90 100644
--- a/src/i18n/strings/en_EN.json
+++ b/src/i18n/strings/en_EN.json
@@ -714,6 +714,8 @@
"Off": "Off",
"On": "On",
"Noisy": "Noisy",
+ "Failed to save your profile": "Failed to save your profile",
+ "The operation could not be completed": "The operation could not be completed",
"Upgrade to your own domain": "Upgrade to your own domain",
"Profile": "Profile",
"Display Name": "Display Name",