From c425886a45c6970cb1e8d9281a82bc87f28d4e3a Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 22 Jun 2015 14:48:58 +0100 Subject: [PATCH] handle room invites --- css/molecules/RoomTile.css | 4 +++ css/organisms/RoomView.css | 11 ++++++ src/controllers/organisms/RoomView.js | 37 +++++++++++++++----- src/views/molecules/RoomTile.js | 6 +++- src/views/organisms/RoomView.js | 50 +++++++++++++++++++++------ 5 files changed, 88 insertions(+), 20 deletions(-) diff --git a/css/molecules/RoomTile.css b/css/molecules/RoomTile.css index a762b1cb..50a7157b 100644 --- a/css/molecules/RoomTile.css +++ b/css/molecules/RoomTile.css @@ -27,6 +27,10 @@ background-color: #66e; } +.mx_RoomTile.invited { + background-color: #6e6; +} + .mx_RoomTile:hover { background-color: #ff8; } diff --git a/css/organisms/RoomView.css b/css/organisms/RoomView.css index 87d94e94..5599039e 100644 --- a/css/organisms/RoomView.css +++ b/css/organisms/RoomView.css @@ -24,6 +24,17 @@ list-style-type: none; } +.mx_RoomView .mx_RoomView_invitePrompt { + text-align: center; + background-color: #ddd; + border: 1px solid black; + width: 400px; + margin-left: auto; + margin-right: auto; + margin-top: 200px; + padding: 50px; +} + .mx_RoomView .mx_MemberList { position: absolute; top: 35px; diff --git a/src/controllers/organisms/RoomView.js b/src/controllers/organisms/RoomView.js index 35e7aab1..673ba782 100644 --- a/src/controllers/organisms/RoomView.js +++ b/src/controllers/organisms/RoomView.js @@ -26,23 +26,44 @@ module.exports = { onRoomTimeline: function(ev, room, toStartOfTimeline) { if (room.roomId != this.props.roomId) return; - var messageUl = this.refs.messageList.getDOMNode(); - this.atBottom = messageUl.scrollHeight - messageUl.scrollTop <= messageUl.clientHeight; + + if (this.refs.messageList) { + var messageUl = this.refs.messageList.getDOMNode(); + this.atBottom = messageUl.scrollHeight - messageUl.scrollTop <= messageUl.clientHeight; + } this.setState({ room: MatrixClientPeg.get().getRoom(this.props.roomId) }); }, componentDidMount: function() { - var messageUl = this.refs.messageList.getDOMNode(); - messageUl.scrollTop = messageUl.scrollHeight; - }, - - componentDidUpdate: function() { - if (this.atBottom) { + if (this.refs.messageList) { var messageUl = this.refs.messageList.getDOMNode(); messageUl.scrollTop = messageUl.scrollHeight; } + }, + + componentDidUpdate: function() { + if (this.refs.messageList && this.atBottom) { + var messageUl = this.refs.messageList.getDOMNode(); + messageUl.scrollTop = messageUl.scrollHeight; + } + }, + + onJoinButtonClicked: function(ev) { + MatrixClientPeg.get().joinRoom(this.props.roomId).then(function() { + this.setState({ + joining: undefined + }); + }, function(error) { + this.setState({ + joining: undefined, + joinError: error + }); + }); + this.setState({ + joining: true + }); } }; diff --git a/src/views/molecules/RoomTile.js b/src/views/molecules/RoomTile.js index f77e881e..c772b06f 100644 --- a/src/views/molecules/RoomTile.js +++ b/src/views/molecules/RoomTile.js @@ -3,14 +3,18 @@ var classNames = require('classnames'); var RoomTileController = require("../../controllers/molecules/RoomTile"); +var MatrixClientPeg = require("../../MatrixClientPeg"); + module.exports = React.createClass({ displayName: 'RoomTile', mixins: [RoomTileController], render: function() { + var myUserId = MatrixClientPeg.get().credentials.userId; var classes = classNames({ 'mx_RoomTile': true, 'selected': this.props.selected, - 'unread': this.props.unread + 'unread': this.props.unread, + 'invited': this.props.room.currentState.members[myUserId].membership == 'invite' }); return (
diff --git a/src/views/organisms/RoomView.js b/src/views/organisms/RoomView.js index 1b8bf9da..24cda7cb 100644 --- a/src/views/organisms/RoomView.js +++ b/src/views/organisms/RoomView.js @@ -1,5 +1,7 @@ var React = require('react'); +var MatrixClientPeg = require("../../MatrixClientPeg"); + var ComponentBroker = require('../../ComponentBroker'); var MessageTile = ComponentBroker.get('molecules/MessageTile'); @@ -9,6 +11,8 @@ var MessageComposer = ComponentBroker.get('molecules/MessageComposer'); var RoomViewController = require("../../controllers/organisms/RoomView"); +var Loader = require("react-loader"); + module.exports = React.createClass({ displayName: 'RoomView', @@ -23,18 +27,42 @@ module.exports = React.createClass({ }, render: function() { - return ( -
- -
-
    - {this.getMessageTiles()} -
- + var myUserId = MatrixClientPeg.get().credentials.userId; + if (this.state.room.currentState.members[myUserId].membership == 'invite') { + if (this.state.joining) { + return ( +
+ +
+ ); + } else { + var inviteEvent = this.state.room.currentState.members[myUserId].events.member.event; + // XXX: Leaving this intentionally basic for now because invites are about to change totally + var joinErrorText = this.state.joinError ? "Failed to join room!" : ""; + return ( +
+
+
{inviteEvent.user_id} has invited you to a room
+ +
{joinErrorText}
+
+
+ ); + } + } else { + return ( +
+ +
+
    + {this.getMessageTiles()} +
+ +
+
- -
- ); + ); + } }, });