2015-10-07 17:19:29 +00:00
|
|
|
/*
|
2016-01-07 04:06:39 +00:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2018-06-19 06:56:04 +00:00
|
|
|
Copyright 2018 New Vector Ltd
|
2015-10-07 17:19:29 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2018-06-19 06:57:28 +00:00
|
|
|
import React from 'react';
|
|
|
|
import sdk from '../../../index';
|
|
|
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
2017-06-08 11:33:29 +00:00
|
|
|
import { _t } from '../../../languageHandler';
|
2015-10-07 17:19:29 +00:00
|
|
|
|
2015-11-26 17:10:36 +00:00
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'ChangeDisplayName',
|
2015-10-07 17:19:29 +00:00
|
|
|
|
2018-06-19 06:56:04 +00:00
|
|
|
_getDisplayName: async function() {
|
2017-10-11 16:56:17 +00:00
|
|
|
const cli = MatrixClientPeg.get();
|
2018-06-19 06:56:04 +00:00
|
|
|
try {
|
|
|
|
const res = await cli.getProfileInfo(cli.getUserId());
|
|
|
|
return res.displayname;
|
|
|
|
} catch (e) {
|
2016-07-29 16:35:48 +00:00
|
|
|
throw new Error("Failed to fetch display name");
|
2018-06-19 06:56:04 +00:00
|
|
|
}
|
2015-10-07 17:19:29 +00:00
|
|
|
},
|
|
|
|
|
2018-06-19 06:57:28 +00:00
|
|
|
_changeDisplayName: function(newDisplayname) {
|
2017-10-11 16:56:17 +00:00
|
|
|
const cli = MatrixClientPeg.get();
|
2018-06-19 06:57:28 +00:00
|
|
|
return cli.setDisplayName(newDisplayname).catch(function(e) {
|
|
|
|
throw new Error("Failed to set display name", e);
|
2015-10-07 17:19:29 +00:00
|
|
|
});
|
|
|
|
},
|
2015-11-26 17:10:36 +00:00
|
|
|
|
|
|
|
render: function() {
|
2017-10-11 16:56:17 +00:00
|
|
|
const EditableTextContainer = sdk.getComponent('elements.EditableTextContainer');
|
2016-07-29 16:35:48 +00:00
|
|
|
return (
|
|
|
|
<EditableTextContainer
|
|
|
|
getInitialValue={this._getDisplayName}
|
2017-06-08 11:33:29 +00:00
|
|
|
placeholder={_t("No display name")}
|
2017-03-02 17:29:06 +00:00
|
|
|
blurToSubmit={true}
|
2016-07-29 16:35:48 +00:00
|
|
|
onSubmit={this._changeDisplayName} />
|
|
|
|
);
|
2017-10-11 16:56:17 +00:00
|
|
|
},
|
2015-11-26 17:10:36 +00:00
|
|
|
});
|