From 980ce7fdae4267f935fa7bd70138c09c48826f9b Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 21 Sep 2015 17:23:51 +0100 Subject: [PATCH] Remainder of the controllers from vector --- .../atoms/create_room/RoomAlias.js | 47 +++++++++++ src/controllers/molecules/ChangeAvatar.js | 69 ++++++++++++++++ src/controllers/molecules/ChangePassword.js | 78 +++++++++++++++++++ src/controllers/organisms/LogoutPrompt.js | 33 ++++++++ src/controllers/organisms/QuestionDialog.js | 37 +++++++++ src/controllers/organisms/UserSettings.js | 68 ++++++++++++++++ 6 files changed, 332 insertions(+) create mode 100644 src/controllers/atoms/create_room/RoomAlias.js create mode 100644 src/controllers/molecules/ChangeAvatar.js create mode 100644 src/controllers/molecules/ChangePassword.js create mode 100644 src/controllers/organisms/LogoutPrompt.js create mode 100644 src/controllers/organisms/QuestionDialog.js create mode 100644 src/controllers/organisms/UserSettings.js diff --git a/src/controllers/atoms/create_room/RoomAlias.js b/src/controllers/atoms/create_room/RoomAlias.js new file mode 100644 index 0000000000..b1176a2ab5 --- /dev/null +++ b/src/controllers/atoms/create_room/RoomAlias.js @@ -0,0 +1,47 @@ +/* +Copyright 2015 OpenMarket Ltd + +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. +*/ + +var React = require('react'); + +module.exports = { + propTypes: { + // Specifying a homeserver will make magical things happen when you, + // e.g. start typing in the room alias box. + homeserver: React.PropTypes.string, + alias: React.PropTypes.string, + onChange: React.PropTypes.func, + }, + + getDefaultProps: function() { + return { + onChange: function() {}, + alias: '', + }; + }, + + getAliasLocalpart: function() { + var room_alias = this.props.alias; + + if (room_alias && this.props.homeserver) { + var suffix = ":" + this.props.homeserver; + if (room_alias.startsWith("#") && room_alias.endsWith(suffix)) { + room_alias = room_alias.slice(1, -suffix.length); + } + } + + return room_alias; + }, +}; diff --git a/src/controllers/molecules/ChangeAvatar.js b/src/controllers/molecules/ChangeAvatar.js new file mode 100644 index 0000000000..b7eb3ec699 --- /dev/null +++ b/src/controllers/molecules/ChangeAvatar.js @@ -0,0 +1,69 @@ +/* +Copyright 2015 OpenMarket Ltd + +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. +*/ + +var React = require('react'); +var MatrixClientPeg = require("../../MatrixClientPeg"); + +var dis = require("../../dispatcher"); + +module.exports = { + propTypes: { + onFinished: React.PropTypes.func, + initialAvatarUrl: React.PropTypes.string.isRequired, + }, + + Phases: { + Display: "display", + Uploading: "uploading", + Error: "error", + }, + + getDefaultProps: function() { + return { + onFinished: function() {}, + }; + }, + + getInitialState: function() { + return { + avatarUrl: this.props.initialAvatarUrl, + phase: this.Phases.Display, + } + }, + + setAvatarFromFile: function(file) { + var newUrl = null; + + this.setState({ + phase: this.Phases.Uploading + }); + var self = this; + MatrixClientPeg.get().uploadContent(file).then(function(url) { + newUrl = url; + return MatrixClientPeg.get().setAvatarUrl(url); + }).done(function() { + self.setState({ + phase: self.Phases.Display, + avatarUrl: MatrixClientPeg.get().mxcUrlToHttp(newUrl) + }); + }, function(error) { + self.setState({ + phase: this.Phases.Error + }); + self.onError(error); + }); + }, +} diff --git a/src/controllers/molecules/ChangePassword.js b/src/controllers/molecules/ChangePassword.js new file mode 100644 index 0000000000..5cc73c5def --- /dev/null +++ b/src/controllers/molecules/ChangePassword.js @@ -0,0 +1,78 @@ +/* +Copyright 2015 OpenMarket Ltd + +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. +*/ + +'use strict'; + +var React = require('react'); +var MatrixClientPeg = require("../../MatrixClientPeg"); + +var dis = require("../../dispatcher"); + +module.exports = { + propTypes: { + onFinished: React.PropTypes.func, + }, + + Phases: { + Edit: "edit", + Uploading: "uploading", + Error: "error", + Success: "Success" + }, + + getDefaultProps: function() { + return { + onFinished: function() {}, + }; + }, + + getInitialState: function() { + return { + phase: this.Phases.Edit, + errorString: '' + } + }, + + changePassword: function(old_password, new_password) { + var cli = MatrixClientPeg.get(); + + var authDict = { + type: 'm.login.password', + user: cli.credentials.userId, + password: old_password + }; + + this.setState({ + phase: this.Phases.Uploading, + errorString: '', + }) + + var d = cli.setPassword(authDict, new_password); + + var self = this; + d.then(function() { + self.setState({ + phase: self.Phases.Success, + errorString: '', + }) + }, function(err) { + self.setState({ + phase: self.Phases.Error, + errorString: err.toString() + }) + }); + }, +} diff --git a/src/controllers/organisms/LogoutPrompt.js b/src/controllers/organisms/LogoutPrompt.js new file mode 100644 index 0000000000..5e5011ea97 --- /dev/null +++ b/src/controllers/organisms/LogoutPrompt.js @@ -0,0 +1,33 @@ +/* +Copyright 2015 OpenMarket Ltd + +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. +*/ + +var dis = require("../../dispatcher"); + +module.exports = { + logOut: function() { + dis.dispatch({action: 'logout'}); + if (this.props.onFinished) { + this.props.onFinished(); + } + }, + + cancelPrompt: function() { + if (this.props.onFinished) { + this.props.onFinished(); + } + } +}; + diff --git a/src/controllers/organisms/QuestionDialog.js b/src/controllers/organisms/QuestionDialog.js new file mode 100644 index 0000000000..8819ba2a01 --- /dev/null +++ b/src/controllers/organisms/QuestionDialog.js @@ -0,0 +1,37 @@ +/* +Copyright 2015 OpenMarket Ltd + +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. +*/ + +var React = require("react"); + +module.exports = { + propTypes: { + title: React.PropTypes.string, + description: React.PropTypes.string, + button: React.PropTypes.string, + focus: React.PropTypes.bool, + onFinished: React.PropTypes.func.isRequired, + }, + + getDefaultProps: function() { + var self = this; + return { + title: "", + description: "", + button: "OK", + focus: true, + }; + }, +}; diff --git a/src/controllers/organisms/UserSettings.js b/src/controllers/organisms/UserSettings.js new file mode 100644 index 0000000000..f8f811ae10 --- /dev/null +++ b/src/controllers/organisms/UserSettings.js @@ -0,0 +1,68 @@ +/* +Copyright 2015 OpenMarket Ltd + +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. +*/ + +var MatrixClientPeg = require("../../MatrixClientPeg"); +var React = require("react"); +var q = require('q'); +var dis = require("../../dispatcher"); +var version = require('../../../package.json').version; + +module.exports = { + Phases: { + Loading: "loading", + Display: "display", + }, + + getInitialState: function() { + return { + displayName: null, + avatarUrl: null, + threePids: [], + clientVersion: version, + phase: this.Phases.Loading, + }; + }, + + changeDisplayname: function(new_displayname) { + if (this.state.displayName == new_displayname) return; + + var self = this; + return MatrixClientPeg.get().setDisplayName(new_displayname).then( + function() { self.setState({displayName: new_displayname}); }, + function(err) { console.err(err); } + ); + }, + + componentWillMount: function() { + var self = this; + var cli = MatrixClientPeg.get(); + + var profile_d = cli.getProfileInfo(cli.credentials.userId); + var threepid_d = cli.getThreePids(); + + q.all([profile_d, threepid_d]).then( + function(resps) { + self.setState({ + displayName: resps[0].displayname, + avatarUrl: resps[0].avatar_url, + threepids: resps[1].threepids, + phase: self.Phases.Display, + }); + }, + function(err) { console.err(err); } + ); + } +}