/* 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('matrix-react-sdk/lib/MatrixClientPeg'); var dis = require('matrix-react-sdk/lib/dispatcher'); var sdk = require('matrix-react-sdk') var classNames = require("classnames"); var filesize = require('filesize'); var RoomViewController = require('../../../../controllers/organisms/RoomView') var Loader = require("react-loader"); module.exports = React.createClass({ displayName: 'RoomView', mixins: [RoomViewController], onSettingsClick: function() { this.setState({editingRoomSettings: true}); }, onSaveClick: function() { this.setState({ editingRoomSettings: false, uploadingRoomSettings: true, }); var new_name = this.refs.header.getRoomName(); var new_topic = this.refs.room_settings.getTopic(); var new_join_rule = this.refs.room_settings.getJoinRules(); var new_history_visibility = this.refs.room_settings.getHistoryVisibility(); var new_power_levels = this.refs.room_settings.getPowerLevels(); this.uploadNewState( new_name, new_topic, new_join_rule, new_history_visibility, new_power_levels ); }, onCancelClick: function() { this.setState(this.getInitialState()); }, onRejectButtonClicked: function(ev) { var self = this; this.setState({ rejecting: true }); MatrixClientPeg.get().leave(this.props.roomId).done(function() { dis.dispatch({ action: 'view_next_room' }); self.setState({ rejecting: false }); }, function(err) { console.error("Failed to reject invite: %s", err); self.setState({ rejecting: false, rejectError: err }); }); }, onSearchClick: function() { this.setState({ searching: true }); }, onConferenceNotificationClick: function() { dis.dispatch({ action: 'place_call', type: "video", room_id: this.props.roomId }); }, getUnreadMessagesString: function() { if (!this.state.numUnreadMessages) { return ""; } return this.state.numUnreadMessages + " new message" + (this.state.numUnreadMessages > 1 ? "s" : ""); }, scrollToBottom: function() { if (!this.refs.messageWrapper) return; var messageWrapper = this.refs.messageWrapper.getDOMNode(); messageWrapper.scrollTop = messageWrapper.scrollHeight; }, render: function() { var RoomHeader = sdk.getComponent('molecules.RoomHeader'); var MessageComposer = sdk.getComponent('molecules.MessageComposer'); var CallView = sdk.getComponent("molecules.voip.CallView"); var RoomSettings = sdk.getComponent("molecules.RoomSettings"); var SearchBar = sdk.getComponent("molecules.SearchBar"); if (!this.state.room) { if (this.props.roomId) { return (
); } else { return (
); } } var myUserId = MatrixClientPeg.get().credentials.userId; if (this.state.room.currentState.members[myUserId].membership == 'invite') { if (this.state.joining || this.state.rejecting) { 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!" : ""; var rejectErrorText = this.state.rejectError ? "Failed to reject invite!" : ""; return (
{inviteEvent.user_id} has invited you to a room

{joinErrorText}
{rejectErrorText}
); } } else { var scrollheader_classes = classNames({ mx_RoomView_scrollheader: true, loading: this.state.paginating }); var statusBar = (
); // for testing UI... // this.state.upload = { // uploadedBytes: 123493, // totalBytes: 347534, // fileName: "testing_fooble.jpg", // } if (this.state.upload) { var innerProgressStyle = { width: ((this.state.upload.uploadedBytes / this.state.upload.totalBytes) * 100) + '%' }; var uploadedSize = filesize(this.state.upload.uploadedBytes); var totalSize = filesize(this.state.upload.totalBytes); if (uploadedSize.replace(/^.* /,'') === totalSize.replace(/^.* /,'')) { uploadedSize = uploadedSize.replace(/ .*/, ''); } statusBar = (
{ uploadedSize } / { totalSize }
Uploading {this.state.upload.fileName}
); } else { var typingString = this.getWhoIsTypingString(); var unreadMsgs = this.getUnreadMessagesString(); // no conn bar trumps unread count since you can't get unread messages // without a connection! (technically may already have some but meh) // It also trumps the "some not sent" msg since you can't resend without // a connection! if (this.state.syncState === "ERROR") { statusBar = (
/!\
Connectivity to the server has been lost.
Sent messages will be stored until your connection has returned.
); } else if (this.state.hasUnsentMessages) { statusBar = (
/!\
Some of your messages have not been sent.
Resend all now or select individual messages to re-send.
); } // unread count trumps who is typing since the unread count is only // set when you've scrolled up else if (unreadMsgs) { statusBar = (
{unreadMsgs}
); } else if (typingString) { statusBar = (
...
{typingString}
); } } var aux = null; if (this.state.editingRoomSettings) { aux = ; } else if (this.state.uploadingRoomSettings) { aux = ; } else if (this.state.searching) { aux = ; } var conferenceCallNotification = null; if (this.state.displayConfCallNotification) { var supportedText; if (!MatrixClientPeg.get().supportsVoip()) { supportedText = " (unsupported)"; } conferenceCallNotification = (
Ongoing conference call {supportedText}
); } var fileDropTarget = null; if (this.state.draggingFile) { fileDropTarget =
Drop File Here
Drop File Here
; } return (
{ conferenceCallNotification } { aux }
{ fileDropTarget }
  1. {this.getEventTiles()}
{statusBar}
); } }, });