2015-10-07 20:19:29 +03:00
|
|
|
/*
|
2016-01-07 07:06:39 +03:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2018-06-19 09:56:04 +03:00
|
|
|
Copyright 2018 New Vector Ltd
|
2015-10-07 20:19:29 +03: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 09:57:28 +03:00
|
|
|
import React from 'react';
|
|
|
|
import sdk from '../../../index';
|
|
|
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
2017-06-08 14:33:29 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2015-10-07 20:19:29 +03:00
|
|
|
|
2015-11-26 20:10:36 +03:00
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'ChangeDisplayName',
|
2015-10-07 20:19:29 +03:00
|
|
|
|
2018-06-19 09:56:04 +03:00
|
|
|
_getDisplayName: async function() {
|
2017-10-11 19:56:17 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
2018-06-19 09:56:04 +03:00
|
|
|
try {
|
|
|
|
const res = await cli.getProfileInfo(cli.getUserId());
|
|
|
|
return res.displayname;
|
|
|
|
} catch (e) {
|
2016-07-29 19:35:48 +03:00
|
|
|
throw new Error("Failed to fetch display name");
|
2018-06-19 09:56:04 +03:00
|
|
|
}
|
2015-10-07 20:19:29 +03:00
|
|
|
},
|
|
|
|
|
2018-06-19 09:57:28 +03:00
|
|
|
_changeDisplayName: function(newDisplayname) {
|
2017-10-11 19:56:17 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
2018-06-19 09:57:28 +03:00
|
|
|
return cli.setDisplayName(newDisplayname).catch(function(e) {
|
|
|
|
throw new Error("Failed to set display name", e);
|
2015-10-07 20:19:29 +03:00
|
|
|
});
|
|
|
|
},
|
2015-11-26 20:10:36 +03:00
|
|
|
|
|
|
|
render: function() {
|
2017-10-11 19:56:17 +03:00
|
|
|
const EditableTextContainer = sdk.getComponent('elements.EditableTextContainer');
|
2016-07-29 19:35:48 +03:00
|
|
|
return (
|
|
|
|
<EditableTextContainer
|
|
|
|
getInitialValue={this._getDisplayName}
|
2017-06-08 14:33:29 +03:00
|
|
|
placeholder={_t("No display name")}
|
2017-03-02 20:29:06 +03:00
|
|
|
blurToSubmit={true}
|
2016-07-29 19:35:48 +03:00
|
|
|
onSubmit={this._changeDisplayName} />
|
|
|
|
);
|
2017-10-11 19:56:17 +03:00
|
|
|
},
|
2015-11-26 20:10:36 +03:00
|
|
|
});
|