2015-11-30 20:15:57 +03:00
|
|
|
/*
|
2016-01-07 07:06:39 +03:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2015-11-30 20:15:57 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TODO: This component is enormous! There's several things which could stand-alone:
|
|
|
|
// - Aux component
|
|
|
|
// - Search results component
|
|
|
|
// - Drag and drop
|
|
|
|
// - File uploading - uploadFile()
|
|
|
|
// - Timeline component (alllll the logic in getEventTiles())
|
|
|
|
|
|
|
|
var React = require("react");
|
|
|
|
var ReactDOM = require("react-dom");
|
|
|
|
var q = require("q");
|
|
|
|
var classNames = require("classnames");
|
|
|
|
var Matrix = require("matrix-js-sdk");
|
|
|
|
|
|
|
|
var MatrixClientPeg = require("../../MatrixClientPeg");
|
|
|
|
var ContentMessages = require("../../ContentMessages");
|
|
|
|
var WhoIsTyping = require("../../WhoIsTyping");
|
|
|
|
var Modal = require("../../Modal");
|
|
|
|
var sdk = require('../../index');
|
|
|
|
var CallHandler = require('../../CallHandler');
|
2015-12-21 13:59:10 +03:00
|
|
|
var TabComplete = require("../../TabComplete");
|
2015-12-22 18:38:23 +03:00
|
|
|
var MemberEntry = require("../../TabCompleteEntries").MemberEntry;
|
2016-01-13 20:46:36 +03:00
|
|
|
var CommandEntry = require("../../TabCompleteEntries").CommandEntry;
|
2015-11-30 20:15:57 +03:00
|
|
|
var Resend = require("../../Resend");
|
2016-01-13 20:46:36 +03:00
|
|
|
var SlashCommands = require("../../SlashCommands");
|
2015-11-30 20:15:57 +03:00
|
|
|
var dis = require("../../dispatcher");
|
2016-01-08 06:22:38 +03:00
|
|
|
var Tinter = require("../../Tinter");
|
2015-11-30 20:15:57 +03:00
|
|
|
|
|
|
|
var PAGINATE_SIZE = 20;
|
|
|
|
var INITIAL_SIZE = 20;
|
2016-01-09 00:18:47 +03:00
|
|
|
var SEND_READ_RECEIPT_DELAY = 2000;
|
2015-11-30 20:15:57 +03:00
|
|
|
|
2015-12-16 20:57:32 +03:00
|
|
|
var DEBUG_SCROLL = false;
|
|
|
|
|
2016-01-04 19:28:32 +03:00
|
|
|
if (DEBUG_SCROLL) {
|
|
|
|
// using bind means that we get to keep useful line numbers in the console
|
|
|
|
var debuglog = console.log.bind(console);
|
|
|
|
} else {
|
|
|
|
var debuglog = function () {};
|
|
|
|
}
|
|
|
|
|
2015-11-30 20:15:57 +03:00
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'RoomView',
|
|
|
|
propTypes: {
|
2016-01-18 20:39:23 +03:00
|
|
|
ConferenceHandler: React.PropTypes.any,
|
|
|
|
roomId: React.PropTypes.string,
|
|
|
|
autoPeek: React.PropTypes.bool, // should we try to peek the room on mount, or has whoever invoked us already initiated a peek?
|
2015-11-30 20:15:57 +03:00
|
|
|
},
|
|
|
|
|
2015-12-18 19:42:46 +03:00
|
|
|
/* properties in RoomView objects include:
|
|
|
|
*
|
|
|
|
* eventNodes: a map from event id to DOM node representing that event
|
|
|
|
*/
|
2015-11-30 20:15:57 +03:00
|
|
|
getInitialState: function() {
|
|
|
|
var room = this.props.roomId ? MatrixClientPeg.get().getRoom(this.props.roomId) : null;
|
|
|
|
return {
|
|
|
|
room: room,
|
|
|
|
messageCap: INITIAL_SIZE,
|
|
|
|
editingRoomSettings: false,
|
|
|
|
uploadingRoomSettings: false,
|
|
|
|
numUnreadMessages: 0,
|
|
|
|
draggingFile: false,
|
|
|
|
searching: false,
|
|
|
|
searchResults: null,
|
|
|
|
syncState: MatrixClientPeg.get().getSyncState(),
|
2015-12-13 07:32:48 +03:00
|
|
|
hasUnsentMessages: this._hasUnsentMessages(room),
|
2015-12-15 02:37:34 +03:00
|
|
|
callState: null,
|
2016-01-18 20:39:23 +03:00
|
|
|
autoPeekDone: false, // track whether our autoPeek (if any) has completed)
|
2016-01-13 16:22:58 +03:00
|
|
|
guestsCanJoin: false,
|
2016-01-18 20:39:23 +03:00
|
|
|
canPeek: false,
|
2016-01-15 21:49:12 +03:00
|
|
|
readMarkerEventId: room ? room.getEventReadUpTo(MatrixClientPeg.get().credentials.userId) : null,
|
2016-01-24 04:51:01 +03:00
|
|
|
readMarkerGhostEventId: undefined,
|
|
|
|
atBottom: true,
|
2015-11-30 20:15:57 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillMount: function() {
|
2016-01-20 19:39:25 +03:00
|
|
|
this.last_rr_sent_event_id = undefined;
|
2015-11-30 20:15:57 +03:00
|
|
|
this.dispatcherRef = dis.register(this.onAction);
|
2016-01-18 20:39:23 +03:00
|
|
|
MatrixClientPeg.get().on("Room", this.onNewRoom);
|
2015-11-30 20:15:57 +03:00
|
|
|
MatrixClientPeg.get().on("Room.timeline", this.onRoomTimeline);
|
|
|
|
MatrixClientPeg.get().on("Room.name", this.onRoomName);
|
2016-01-08 06:22:38 +03:00
|
|
|
MatrixClientPeg.get().on("Room.accountData", this.onRoomAccountData);
|
2015-11-30 20:15:57 +03:00
|
|
|
MatrixClientPeg.get().on("Room.receipt", this.onRoomReceipt);
|
|
|
|
MatrixClientPeg.get().on("RoomMember.typing", this.onRoomMemberTyping);
|
|
|
|
MatrixClientPeg.get().on("RoomState.members", this.onRoomStateMember);
|
|
|
|
MatrixClientPeg.get().on("sync", this.onSyncStateChange);
|
2015-12-21 13:59:10 +03:00
|
|
|
// xchat-style tab complete, add a colon if tab
|
|
|
|
// completing at the start of the text
|
|
|
|
this.tabComplete = new TabComplete({
|
2015-12-21 20:16:49 +03:00
|
|
|
allowLooping: false,
|
2015-12-21 20:58:36 +03:00
|
|
|
autoEnterTabComplete: true,
|
2015-12-22 14:14:36 +03:00
|
|
|
onClickCompletes: true,
|
2015-12-21 17:11:34 +03:00
|
|
|
onStateChange: (isCompleting) => {
|
|
|
|
this.forceUpdate();
|
|
|
|
}
|
2015-12-21 13:59:10 +03:00
|
|
|
});
|
2016-01-07 19:22:17 +03:00
|
|
|
// if this is an unknown room then we're in one of three states:
|
|
|
|
// - This is a room we can peek into (search engine) (we can /peek)
|
|
|
|
// - This is a room we can publicly join or were invited to. (we can /join)
|
|
|
|
// - This is a room we cannot join at all. (no action can help us)
|
|
|
|
// We can't try to /join because this may implicitly accept invites (!)
|
|
|
|
// We can /peek though. If it fails then we present the join UI. If it
|
|
|
|
// succeeds then great, show the preview (but we still may be able to /join!).
|
2016-01-18 23:05:33 +03:00
|
|
|
if (!this.state.room) {
|
|
|
|
if (this.props.autoPeek) {
|
|
|
|
console.log("Attempting to peek into room %s", this.props.roomId);
|
2016-01-20 18:38:34 +03:00
|
|
|
MatrixClientPeg.get().peekInRoom(this.props.roomId).catch((err) => {
|
2016-01-18 23:05:33 +03:00
|
|
|
console.error("Failed to peek into room: %s", err);
|
2016-01-19 19:18:08 +03:00
|
|
|
}).finally(() => {
|
2016-01-20 18:38:34 +03:00
|
|
|
// we don't need to do anything - JS SDK will emit Room events
|
|
|
|
// which will update the UI.
|
2016-01-19 18:18:16 +03:00
|
|
|
this.setState({
|
|
|
|
autoPeekDone: true
|
|
|
|
});
|
2016-01-18 20:39:23 +03:00
|
|
|
});
|
2016-01-18 23:05:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._calculatePeekRules(this.state.room);
|
2016-01-07 19:22:17 +03:00
|
|
|
}
|
2015-11-30 20:15:57 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
2016-01-11 14:38:04 +03:00
|
|
|
// set a boolean to say we've been unmounted, which any pending
|
|
|
|
// promises can use to throw away their results.
|
|
|
|
//
|
|
|
|
// (We could use isMounted, but facebook have deprecated that.)
|
|
|
|
this.unmounted = true;
|
|
|
|
|
2016-01-15 18:23:02 +03:00
|
|
|
if (this.refs.roomView) {
|
|
|
|
// disconnect the D&D event listeners from the room view. This
|
|
|
|
// is really just for hygiene - we're going to be
|
2015-12-18 13:19:07 +03:00
|
|
|
// deleted anyway, so it doesn't matter if the event listeners
|
|
|
|
// don't get cleaned up.
|
2016-01-15 18:23:02 +03:00
|
|
|
var roomView = ReactDOM.findDOMNode(this.refs.roomView);
|
|
|
|
roomView.removeEventListener('drop', this.onDrop);
|
|
|
|
roomView.removeEventListener('dragover', this.onDragOver);
|
|
|
|
roomView.removeEventListener('dragleave', this.onDragLeaveOrEnd);
|
|
|
|
roomView.removeEventListener('dragend', this.onDragLeaveOrEnd);
|
2015-11-30 20:15:57 +03:00
|
|
|
}
|
|
|
|
dis.unregister(this.dispatcherRef);
|
|
|
|
if (MatrixClientPeg.get()) {
|
2016-01-18 20:39:23 +03:00
|
|
|
MatrixClientPeg.get().removeListener("Room", this.onNewRoom);
|
2015-11-30 20:15:57 +03:00
|
|
|
MatrixClientPeg.get().removeListener("Room.timeline", this.onRoomTimeline);
|
|
|
|
MatrixClientPeg.get().removeListener("Room.name", this.onRoomName);
|
2016-01-08 06:22:38 +03:00
|
|
|
MatrixClientPeg.get().removeListener("Room.accountData", this.onRoomAccountData);
|
2015-11-30 20:15:57 +03:00
|
|
|
MatrixClientPeg.get().removeListener("Room.receipt", this.onRoomReceipt);
|
|
|
|
MatrixClientPeg.get().removeListener("RoomMember.typing", this.onRoomMemberTyping);
|
|
|
|
MatrixClientPeg.get().removeListener("RoomState.members", this.onRoomStateMember);
|
|
|
|
MatrixClientPeg.get().removeListener("sync", this.onSyncStateChange);
|
|
|
|
}
|
2015-12-13 07:32:48 +03:00
|
|
|
|
|
|
|
window.removeEventListener('resize', this.onResize);
|
2016-01-08 06:22:38 +03:00
|
|
|
|
|
|
|
Tinter.tint(); // reset colourscheme
|
2015-11-30 20:15:57 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onAction: function(payload) {
|
|
|
|
switch (payload.action) {
|
|
|
|
case 'message_send_failed':
|
|
|
|
case 'message_sent':
|
|
|
|
this.setState({
|
|
|
|
hasUnsentMessages: this._hasUnsentMessages(this.state.room)
|
|
|
|
});
|
|
|
|
case 'message_resend_started':
|
|
|
|
this.setState({
|
|
|
|
room: MatrixClientPeg.get().getRoom(this.props.roomId)
|
|
|
|
});
|
|
|
|
this.forceUpdate();
|
|
|
|
break;
|
|
|
|
case 'notifier_enabled':
|
2015-12-02 21:16:16 +03:00
|
|
|
case 'upload_failed':
|
|
|
|
case 'upload_started':
|
|
|
|
case 'upload_finished':
|
2015-11-30 20:15:57 +03:00
|
|
|
this.forceUpdate();
|
|
|
|
break;
|
|
|
|
case 'call_state':
|
2015-12-15 02:37:34 +03:00
|
|
|
// don't filter out payloads for room IDs other than props.room because
|
|
|
|
// we may be interested in the conf 1:1 room
|
|
|
|
|
|
|
|
if (!payload.room_id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var call = CallHandler.getCallForRoom(payload.room_id);
|
|
|
|
var callState;
|
|
|
|
|
|
|
|
if (call) {
|
2015-11-30 20:15:57 +03:00
|
|
|
// Call state has changed so we may be loading video elements
|
|
|
|
// which will obscure the message log.
|
|
|
|
// scroll to bottom
|
2015-12-16 16:31:36 +03:00
|
|
|
this.scrollToBottom();
|
2015-12-15 02:37:34 +03:00
|
|
|
callState = call.call_state;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
callState = "ended";
|
2015-11-30 20:15:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// possibly remove the conf call notification if we're now in
|
|
|
|
// the conf
|
|
|
|
this._updateConfCallNotification();
|
2015-12-15 02:37:34 +03:00
|
|
|
|
|
|
|
this.setState({
|
|
|
|
callState: callState
|
|
|
|
});
|
|
|
|
|
2015-11-30 20:15:57 +03:00
|
|
|
break;
|
|
|
|
case 'user_activity':
|
2016-01-14 19:01:31 +03:00
|
|
|
case 'user_activity_end':
|
|
|
|
// we could treat user_activity_end differently and not
|
|
|
|
// send receipts for messages that have arrived between
|
|
|
|
// the actual user activity and the time they stopped
|
|
|
|
// being active, but let's see if this is actually
|
|
|
|
// necessary.
|
2015-11-30 20:15:57 +03:00
|
|
|
this.sendReadReceipt();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-12-14 14:32:08 +03:00
|
|
|
onSyncStateChange: function(state, prevState) {
|
|
|
|
if (state === "SYNCING" && prevState === "SYNCING") {
|
|
|
|
return;
|
|
|
|
}
|
2015-11-30 20:15:57 +03:00
|
|
|
this.setState({
|
|
|
|
syncState: state
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// MatrixRoom still showing the messages from the old room?
|
|
|
|
// Set the key to the room_id. Sadly you can no longer get at
|
|
|
|
// the key from inside the component, or we'd check this in code.
|
|
|
|
/*componentWillReceiveProps: function(props) {
|
|
|
|
},*/
|
|
|
|
|
|
|
|
onRoomTimeline: function(ev, room, toStartOfTimeline) {
|
2016-01-11 14:38:04 +03:00
|
|
|
if (this.unmounted) return;
|
2015-11-30 20:15:57 +03:00
|
|
|
|
|
|
|
// ignore anything that comes in whilst paginating: we get one
|
|
|
|
// event for each new matrix event so this would cause a huge
|
|
|
|
// number of UI updates. Just update the UI when the paginate
|
|
|
|
// call returns.
|
|
|
|
if (this.state.paginating) return;
|
|
|
|
|
|
|
|
// no point handling anything while we're waiting for the join to finish:
|
|
|
|
// we'll only be showing a spinner.
|
|
|
|
if (this.state.joining) return;
|
|
|
|
if (room.roomId != this.props.roomId) return;
|
|
|
|
|
|
|
|
var currentUnread = this.state.numUnreadMessages;
|
|
|
|
if (!toStartOfTimeline &&
|
|
|
|
(ev.getSender() !== MatrixClientPeg.get().credentials.userId)) {
|
|
|
|
// update unread count when scrolled up
|
2015-12-22 18:18:50 +03:00
|
|
|
if (!this.state.searchResults && this.refs.messagePanel && this.refs.messagePanel.isAtBottom()) {
|
2015-11-30 20:15:57 +03:00
|
|
|
currentUnread = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
currentUnread += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
room: MatrixClientPeg.get().getRoom(this.props.roomId),
|
|
|
|
numUnreadMessages: currentUnread
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-01-18 20:39:23 +03:00
|
|
|
onNewRoom: function(room) {
|
|
|
|
if (room.roomId == this.props.roomId) {
|
|
|
|
this.setState({
|
|
|
|
room: room
|
|
|
|
});
|
2016-01-18 23:05:33 +03:00
|
|
|
}
|
2016-01-18 22:56:35 +03:00
|
|
|
|
2016-01-18 23:05:33 +03:00
|
|
|
this._calculatePeekRules(room);
|
|
|
|
},
|
2016-01-18 22:56:35 +03:00
|
|
|
|
2016-01-18 23:05:33 +03:00
|
|
|
_calculatePeekRules: function(room) {
|
|
|
|
var guestAccessEvent = room.currentState.getStateEvents("m.room.guest_access", "");
|
|
|
|
if (guestAccessEvent && guestAccessEvent.getContent().guest_access === "can_join") {
|
|
|
|
this.setState({
|
|
|
|
guestsCanJoin: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var historyVisibility = room.currentState.getStateEvents("m.room.history_visibility", "");
|
|
|
|
if (historyVisibility && historyVisibility.getContent().history_visibility === "world_readable") {
|
|
|
|
this.setState({
|
|
|
|
canPeek: true
|
|
|
|
});
|
2016-01-18 20:39:23 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-30 20:15:57 +03:00
|
|
|
onRoomName: function(room) {
|
|
|
|
if (room.roomId == this.props.roomId) {
|
|
|
|
this.setState({
|
|
|
|
room: room
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-01-08 06:22:38 +03:00
|
|
|
updateTint: function() {
|
|
|
|
var room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
|
|
|
if (!room) return;
|
|
|
|
|
2016-01-13 16:15:13 +03:00
|
|
|
var color_scheme_event = room.getAccountData("org.matrix.room.color_scheme");
|
2016-01-08 06:22:38 +03:00
|
|
|
var color_scheme = {};
|
|
|
|
if (color_scheme_event) {
|
|
|
|
color_scheme = color_scheme_event.getContent();
|
|
|
|
// XXX: we should validate the event
|
|
|
|
}
|
|
|
|
Tinter.tint(color_scheme.primary_color, color_scheme.secondary_color);
|
|
|
|
},
|
|
|
|
|
|
|
|
onRoomAccountData: function(room, event) {
|
|
|
|
if (room.roomId == this.props.roomId) {
|
2016-01-13 16:15:13 +03:00
|
|
|
if (event.getType === "org.matrix.room.color_scheme") {
|
2016-01-08 06:22:38 +03:00
|
|
|
var color_scheme = event.getContent();
|
|
|
|
// XXX: we should validate the event
|
|
|
|
Tinter.tint(color_scheme.primary_color, color_scheme.secondary_color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-30 20:15:57 +03:00
|
|
|
onRoomReceipt: function(receiptEvent, room) {
|
|
|
|
if (room.roomId == this.props.roomId) {
|
2016-01-12 19:38:09 +03:00
|
|
|
var readMarkerEventId = this.state.room.getEventReadUpTo(MatrixClientPeg.get().credentials.userId);
|
2016-01-09 00:18:47 +03:00
|
|
|
var readMarkerGhostEventId = this.state.readMarkerGhostEventId;
|
2016-01-12 19:38:09 +03:00
|
|
|
if (this.state.readMarkerEventId !== undefined && this.state.readMarkerEventId != readMarkerEventId) {
|
|
|
|
readMarkerGhostEventId = this.state.readMarkerEventId;
|
2016-01-09 00:18:47 +03:00
|
|
|
}
|
2016-01-12 20:18:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
// if the event after the one referenced in the read receipt if sent by us, do nothing since
|
|
|
|
// this is a temporary period before the synthesized receipt for our own message arrives
|
|
|
|
var readMarkerGhostEventIndex;
|
|
|
|
for (var i = 0; i < room.timeline.length; ++i) {
|
|
|
|
if (room.timeline[i].getId() == readMarkerGhostEventId) {
|
|
|
|
readMarkerGhostEventIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (readMarkerGhostEventIndex + 1 < room.timeline.length) {
|
|
|
|
var nextEvent = room.timeline[readMarkerGhostEventIndex + 1];
|
|
|
|
if (nextEvent.sender && nextEvent.sender.userId == MatrixClientPeg.get().credentials.userId) {
|
|
|
|
readMarkerGhostEventId = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-09 00:18:47 +03:00
|
|
|
this.setState({
|
2016-01-12 19:38:09 +03:00
|
|
|
readMarkerEventId: readMarkerEventId,
|
2016-01-09 00:18:47 +03:00
|
|
|
readMarkerGhostEventId: readMarkerGhostEventId,
|
|
|
|
});
|
2015-11-30 20:15:57 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onRoomMemberTyping: function(ev, member) {
|
|
|
|
this.forceUpdate();
|
|
|
|
},
|
|
|
|
|
|
|
|
onRoomStateMember: function(ev, state, member) {
|
2015-12-22 18:38:23 +03:00
|
|
|
if (member.roomId === this.props.roomId) {
|
|
|
|
// a member state changed in this room, refresh the tab complete list
|
|
|
|
this._updateTabCompleteList(this.state.room);
|
2016-01-20 18:25:40 +03:00
|
|
|
|
|
|
|
var room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
|
|
|
var me = MatrixClientPeg.get().credentials.userId;
|
|
|
|
if (this.state.joining && room.hasMembershipState(me, "join")) {
|
|
|
|
this.setState({
|
|
|
|
joining: false
|
|
|
|
});
|
|
|
|
}
|
2015-12-22 18:38:23 +03:00
|
|
|
}
|
|
|
|
|
2015-11-30 20:15:57 +03:00
|
|
|
if (!this.props.ConferenceHandler) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (member.roomId !== this.props.roomId ||
|
|
|
|
member.userId !== this.props.ConferenceHandler.getConferenceUserIdForRoom(member.roomId)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._updateConfCallNotification();
|
|
|
|
},
|
|
|
|
|
|
|
|
_hasUnsentMessages: function(room) {
|
|
|
|
return this._getUnsentMessages(room).length > 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getUnsentMessages: function(room) {
|
|
|
|
if (!room) { return []; }
|
|
|
|
// TODO: It would be nice if the JS SDK provided nicer constant-time
|
|
|
|
// constructs rather than O(N) (N=num msgs) on this.
|
|
|
|
return room.timeline.filter(function(ev) {
|
|
|
|
return ev.status === Matrix.EventStatus.NOT_SENT;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateConfCallNotification: function() {
|
|
|
|
var room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
|
|
|
if (!room || !this.props.ConferenceHandler) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var confMember = room.getMember(
|
|
|
|
this.props.ConferenceHandler.getConferenceUserIdForRoom(this.props.roomId)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!confMember) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var confCall = this.props.ConferenceHandler.getConferenceCallForRoom(confMember.roomId);
|
|
|
|
|
|
|
|
// A conf call notification should be displayed if there is an ongoing
|
|
|
|
// conf call but this cilent isn't a part of it.
|
|
|
|
this.setState({
|
|
|
|
displayConfCallNotification: (
|
|
|
|
(!confCall || confCall.call_state === "ended") &&
|
|
|
|
confMember.membership === "join"
|
|
|
|
)
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount: function() {
|
|
|
|
if (this.refs.messagePanel) {
|
2015-12-18 01:07:56 +03:00
|
|
|
this._initialiseMessagePanel();
|
2015-11-30 20:15:57 +03:00
|
|
|
}
|
|
|
|
|
2015-12-15 02:37:34 +03:00
|
|
|
var call = CallHandler.getCallForRoom(this.props.roomId);
|
|
|
|
var callState = call ? call.call_state : "ended";
|
|
|
|
this.setState({
|
|
|
|
callState: callState
|
|
|
|
});
|
|
|
|
|
2015-11-30 20:15:57 +03:00
|
|
|
this._updateConfCallNotification();
|
2015-12-13 07:32:48 +03:00
|
|
|
|
|
|
|
window.addEventListener('resize', this.onResize);
|
|
|
|
this.onResize();
|
2015-12-22 18:38:23 +03:00
|
|
|
|
2016-01-15 18:23:02 +03:00
|
|
|
if (this.refs.roomView) {
|
|
|
|
var roomView = ReactDOM.findDOMNode(this.refs.roomView);
|
|
|
|
roomView.addEventListener('drop', this.onDrop);
|
|
|
|
roomView.addEventListener('dragover', this.onDragOver);
|
|
|
|
roomView.addEventListener('dragleave', this.onDragLeaveOrEnd);
|
|
|
|
roomView.addEventListener('dragend', this.onDragLeaveOrEnd);
|
|
|
|
}
|
|
|
|
|
2015-12-22 18:38:23 +03:00
|
|
|
this._updateTabCompleteList(this.state.room);
|
2016-01-21 03:16:10 +03:00
|
|
|
|
|
|
|
// XXX: EVIL HACK to autofocus inviting on empty rooms.
|
|
|
|
// We use the setTimeout to avoid racing with focus_composer.
|
|
|
|
if (this.state.room && this.state.room.getJoinedMembers().length == 1) {
|
|
|
|
var inviteBox = document.getElementById("mx_SearchableEntityList_query");
|
|
|
|
setTimeout(function() {
|
|
|
|
inviteBox.focus();
|
|
|
|
}, 50);
|
|
|
|
}
|
2015-12-22 18:38:23 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateTabCompleteList: function(room) {
|
|
|
|
if (!room || !this.tabComplete) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.tabComplete.setCompletionList(
|
2016-01-13 20:46:36 +03:00
|
|
|
MemberEntry.fromMemberList(room.getJoinedMembers()).concat(
|
2016-01-14 17:39:58 +03:00
|
|
|
CommandEntry.fromCommands(SlashCommands.getCommandList())
|
2016-01-13 20:46:36 +03:00
|
|
|
)
|
2015-12-22 18:38:23 +03:00
|
|
|
);
|
2015-11-30 20:15:57 +03:00
|
|
|
},
|
|
|
|
|
2015-12-18 01:07:56 +03:00
|
|
|
_initialiseMessagePanel: function() {
|
|
|
|
var messagePanel = ReactDOM.findDOMNode(this.refs.messagePanel);
|
|
|
|
this.refs.messagePanel.initialised = true;
|
|
|
|
|
|
|
|
this.scrollToBottom();
|
|
|
|
this.sendReadReceipt();
|
2016-01-08 06:22:38 +03:00
|
|
|
|
|
|
|
this.updateTint();
|
2015-12-18 01:07:56 +03:00
|
|
|
},
|
|
|
|
|
2015-11-30 20:15:57 +03:00
|
|
|
componentDidUpdate: function() {
|
2015-12-18 01:07:56 +03:00
|
|
|
// we need to initialise the messagepanel if we've just joined the
|
|
|
|
// room. TODO: we really really ought to factor out messagepanel to a
|
|
|
|
// separate component to avoid this ridiculous dance.
|
|
|
|
if (!this.refs.messagePanel) return;
|
|
|
|
|
|
|
|
if (!this.refs.messagePanel.initialised) {
|
|
|
|
this._initialiseMessagePanel();
|
|
|
|
}
|
2015-11-30 20:15:57 +03:00
|
|
|
},
|
|
|
|
|
2015-12-10 23:53:21 +03:00
|
|
|
_paginateCompleted: function() {
|
2016-01-04 19:28:32 +03:00
|
|
|
debuglog("paginate complete");
|
2015-12-16 20:57:32 +03:00
|
|
|
|
2016-01-08 15:03:45 +03:00
|
|
|
// we might have switched rooms since the paginate started - just bin
|
|
|
|
// the results if so.
|
2016-01-11 14:38:04 +03:00
|
|
|
if (this.unmounted) return;
|
2016-01-08 15:03:45 +03:00
|
|
|
|
2015-12-10 23:53:21 +03:00
|
|
|
this.setState({
|
2016-01-08 15:03:45 +03:00
|
|
|
room: MatrixClientPeg.get().getRoom(this.props.roomId),
|
|
|
|
paginating: false,
|
2015-12-10 23:53:21 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-12-22 18:18:50 +03:00
|
|
|
onSearchResultsFillRequest: function(backwards) {
|
2015-12-24 03:10:21 +03:00
|
|
|
if (!backwards)
|
2016-01-04 19:28:32 +03:00
|
|
|
return q(false);
|
2015-11-30 20:15:57 +03:00
|
|
|
|
2015-12-22 21:15:32 +03:00
|
|
|
if (this.state.searchResults.next_batch) {
|
2016-01-04 19:28:32 +03:00
|
|
|
debuglog("requesting more search results");
|
2016-01-05 18:51:16 +03:00
|
|
|
var searchPromise = MatrixClientPeg.get().backPaginateRoomEventsSearch(
|
|
|
|
this.state.searchResults);
|
|
|
|
return this._handleSearchResult(searchPromise);
|
2015-12-22 18:18:50 +03:00
|
|
|
} else {
|
2016-01-04 19:28:32 +03:00
|
|
|
debuglog("no more search results");
|
|
|
|
return q(false);
|
2015-12-22 18:18:50 +03:00
|
|
|
}
|
|
|
|
},
|
2015-11-30 20:15:57 +03:00
|
|
|
|
2015-12-22 18:18:50 +03:00
|
|
|
// set off a pagination request.
|
|
|
|
onMessageListFillRequest: function(backwards) {
|
2015-12-24 03:10:21 +03:00
|
|
|
if (!backwards)
|
2016-01-04 19:28:32 +03:00
|
|
|
return q(false);
|
2015-12-18 02:04:32 +03:00
|
|
|
|
|
|
|
// Either wind back the message cap (if there are enough events in the
|
|
|
|
// timeline to do so), or fire off a pagination request.
|
|
|
|
|
|
|
|
if (this.state.messageCap < this.state.room.timeline.length) {
|
|
|
|
var cap = Math.min(this.state.messageCap + PAGINATE_SIZE, this.state.room.timeline.length);
|
2016-01-04 19:28:32 +03:00
|
|
|
debuglog("winding back message cap to", cap);
|
2015-12-18 02:04:32 +03:00
|
|
|
this.setState({messageCap: cap});
|
2016-01-04 19:28:32 +03:00
|
|
|
return q(true);
|
2015-12-18 02:04:32 +03:00
|
|
|
} else if(this.state.room.oldState.paginationToken) {
|
|
|
|
var cap = this.state.messageCap + PAGINATE_SIZE;
|
2016-01-04 19:28:32 +03:00
|
|
|
debuglog("starting paginate to cap", cap);
|
2015-12-18 02:04:32 +03:00
|
|
|
this.setState({messageCap: cap, paginating: true});
|
2015-12-24 03:10:21 +03:00
|
|
|
return MatrixClientPeg.get().scrollback(this.state.room, PAGINATE_SIZE).
|
|
|
|
finally(this._paginateCompleted).then(true);
|
2015-11-30 20:15:57 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-12-21 13:46:32 +03:00
|
|
|
// return true if there's more messages in the backlog which we aren't displaying
|
|
|
|
_canPaginate: function() {
|
|
|
|
return (this.state.messageCap < this.state.room.timeline.length) ||
|
|
|
|
this.state.room.oldState.paginationToken;
|
|
|
|
},
|
|
|
|
|
2015-11-30 20:15:57 +03:00
|
|
|
onResendAllClick: function() {
|
|
|
|
var eventsToResend = this._getUnsentMessages(this.state.room);
|
|
|
|
eventsToResend.forEach(function(event) {
|
|
|
|
Resend.resend(event);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onJoinButtonClicked: function(ev) {
|
|
|
|
var self = this;
|
2016-01-20 18:25:40 +03:00
|
|
|
MatrixClientPeg.get().joinRoom(this.props.roomId).done(function() {
|
|
|
|
// It is possible that there is no Room yet if state hasn't come down
|
|
|
|
// from /sync - joinRoom will resolve when the HTTP request to join succeeds,
|
|
|
|
// NOT when it comes down /sync. If there is no room, we'll keep the
|
|
|
|
// joining flag set until we see it. Likewise, if our state is not
|
|
|
|
// "join" we'll keep this flag set until it comes down /sync.
|
|
|
|
var room = MatrixClientPeg.get().getRoom(self.props.roomId);
|
|
|
|
var me = MatrixClientPeg.get().credentials.userId;
|
2015-11-30 20:15:57 +03:00
|
|
|
self.setState({
|
2016-01-20 18:25:40 +03:00
|
|
|
joining: room ? !room.hasMembershipState(me, "join") : true,
|
|
|
|
room: room
|
2015-11-30 20:15:57 +03:00
|
|
|
});
|
|
|
|
}, function(error) {
|
|
|
|
self.setState({
|
|
|
|
joining: false,
|
|
|
|
joinError: error
|
|
|
|
});
|
2016-01-07 19:22:17 +03:00
|
|
|
var msg = error.message ? error.message : JSON.stringify(error);
|
|
|
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
Modal.createDialog(ErrorDialog, {
|
|
|
|
title: "Failed to join room",
|
|
|
|
description: msg
|
|
|
|
});
|
2015-11-30 20:15:57 +03:00
|
|
|
});
|
|
|
|
this.setState({
|
|
|
|
joining: true
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onMessageListScroll: function(ev) {
|
2016-01-24 04:51:01 +03:00
|
|
|
if (this.refs.messagePanel.isAtBottom()) {
|
|
|
|
if (this.state.numUnreadMessages != 0) {
|
|
|
|
this.setState({ numUnreadMessages: 0 });
|
|
|
|
}
|
|
|
|
if (!this.state.atBottom) {
|
|
|
|
this.setState({ atBottom: true });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (this.state.atBottom) {
|
|
|
|
this.setState({ atBottom: false });
|
|
|
|
}
|
2015-12-18 02:04:32 +03:00
|
|
|
}
|
2015-11-30 20:15:57 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onDragOver: function(ev) {
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
|
|
|
|
ev.dataTransfer.dropEffect = 'none';
|
|
|
|
|
|
|
|
var items = ev.dataTransfer.items;
|
|
|
|
if (items.length == 1) {
|
|
|
|
if (items[0].kind == 'file') {
|
|
|
|
this.setState({ draggingFile : true });
|
|
|
|
ev.dataTransfer.dropEffect = 'copy';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onDrop: function(ev) {
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
this.setState({ draggingFile : false });
|
|
|
|
var files = ev.dataTransfer.files;
|
|
|
|
if (files.length == 1) {
|
|
|
|
this.uploadFile(files[0]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragLeaveOrEnd: function(ev) {
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
this.setState({ draggingFile : false });
|
|
|
|
},
|
|
|
|
|
|
|
|
uploadFile: function(file) {
|
|
|
|
var self = this;
|
|
|
|
ContentMessages.sendContentToRoom(
|
|
|
|
file, this.props.roomId, MatrixClientPeg.get()
|
2015-12-02 21:16:16 +03:00
|
|
|
).done(undefined, function(error) {
|
2015-11-30 20:15:57 +03:00
|
|
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
Modal.createDialog(ErrorDialog, {
|
|
|
|
title: "Failed to upload file",
|
|
|
|
description: error.toString()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
getWhoIsTypingString: function() {
|
|
|
|
return WhoIsTyping.whoIsTypingString(this.state.room);
|
|
|
|
},
|
|
|
|
|
|
|
|
onSearch: function(term, scope) {
|
2015-12-18 14:11:41 +03:00
|
|
|
this.setState({
|
|
|
|
searchTerm: term,
|
|
|
|
searchScope: scope,
|
2015-12-22 21:15:32 +03:00
|
|
|
searchResults: {},
|
2015-12-18 14:11:41 +03:00
|
|
|
searchHighlights: [],
|
|
|
|
});
|
2015-11-30 20:15:57 +03:00
|
|
|
|
2015-12-22 18:18:50 +03:00
|
|
|
// if we already have a search panel, we need to tell it to forget
|
|
|
|
// about its scroll state.
|
|
|
|
if (this.refs.searchResultsPanel) {
|
|
|
|
this.refs.searchResultsPanel.resetScrollState();
|
|
|
|
}
|
|
|
|
|
2015-12-22 21:15:32 +03:00
|
|
|
// make sure that we don't end up showing results from
|
|
|
|
// an aborted search by keeping a unique id.
|
|
|
|
//
|
|
|
|
// todo: should cancel any previous search requests.
|
|
|
|
this.searchId = new Date().getTime();
|
|
|
|
|
|
|
|
var filter;
|
|
|
|
if (scope === "Room") {
|
|
|
|
filter = {
|
|
|
|
// XXX: it's unintuitive that the filter for searching doesn't have the same shape as the v2 filter API :(
|
|
|
|
rooms: [
|
|
|
|
this.props.roomId
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-01-05 18:51:16 +03:00
|
|
|
debuglog("sending search request");
|
2015-12-22 21:15:32 +03:00
|
|
|
|
2016-01-04 19:54:27 +03:00
|
|
|
var searchPromise = MatrixClientPeg.get().searchRoomEvents({
|
|
|
|
filter: filter,
|
|
|
|
term: term,
|
|
|
|
});
|
|
|
|
this._handleSearchResult(searchPromise).done();
|
2015-12-18 14:11:41 +03:00
|
|
|
},
|
|
|
|
|
2015-12-22 21:15:32 +03:00
|
|
|
_handleSearchResult: function(searchPromise) {
|
2015-12-18 14:11:41 +03:00
|
|
|
var self = this;
|
2016-01-04 19:54:27 +03:00
|
|
|
|
|
|
|
// keep a record of the current search id, so that if the search terms
|
|
|
|
// change before we get a response, we can ignore the results.
|
|
|
|
var localSearchId = this.searchId;
|
2015-12-11 06:22:44 +03:00
|
|
|
|
2015-12-22 21:15:32 +03:00
|
|
|
this.setState({
|
|
|
|
searchInProgress: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
return searchPromise.then(function(results) {
|
2016-01-04 19:28:32 +03:00
|
|
|
debuglog("search complete");
|
2016-01-11 14:38:04 +03:00
|
|
|
if (self.unmounted || !self.state.searching || self.searchId != localSearchId) {
|
2015-12-11 06:22:44 +03:00
|
|
|
console.error("Discarding stale search results");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-05 18:28:32 +03:00
|
|
|
// postgres on synapse returns us precise details of the strings
|
|
|
|
// which actually got matched for highlighting.
|
|
|
|
//
|
|
|
|
// In either case, we want to highlight the literal search term
|
|
|
|
// whether it was used by the search engine or not.
|
|
|
|
|
|
|
|
var highlights = results.highlights;
|
|
|
|
if (highlights.indexOf(self.state.searchTerm) < 0) {
|
|
|
|
highlights = highlights.concat(self.state.searchTerm);
|
|
|
|
}
|
2015-12-18 14:11:41 +03:00
|
|
|
|
2015-12-22 21:15:32 +03:00
|
|
|
// For overlapping highlights,
|
2015-12-18 14:11:41 +03:00
|
|
|
// favour longer (more specific) terms first
|
2016-01-08 16:25:03 +03:00
|
|
|
highlights = highlights.sort(function(a, b) {
|
|
|
|
return b.length - a.length });
|
2015-11-30 20:15:57 +03:00
|
|
|
|
|
|
|
self.setState({
|
2015-12-18 14:11:41 +03:00
|
|
|
searchHighlights: highlights,
|
2015-12-22 21:15:32 +03:00
|
|
|
searchResults: results,
|
2015-11-30 20:15:57 +03:00
|
|
|
});
|
|
|
|
}, function(error) {
|
|
|
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
Modal.createDialog(ErrorDialog, {
|
|
|
|
title: "Search failed",
|
|
|
|
description: error.toString()
|
|
|
|
});
|
2015-12-11 05:25:33 +03:00
|
|
|
}).finally(function() {
|
|
|
|
self.setState({
|
|
|
|
searchInProgress: false
|
|
|
|
});
|
2015-12-22 21:15:32 +03:00
|
|
|
});
|
2015-12-18 14:11:41 +03:00
|
|
|
},
|
|
|
|
|
2015-11-30 20:15:57 +03:00
|
|
|
|
2015-12-22 18:18:50 +03:00
|
|
|
getSearchResultTiles: function() {
|
2015-11-30 20:15:57 +03:00
|
|
|
var EventTile = sdk.getComponent('rooms.EventTile');
|
2015-12-23 13:10:08 +03:00
|
|
|
var SearchResultTile = sdk.getComponent('rooms.SearchResultTile');
|
2015-12-22 21:15:32 +03:00
|
|
|
var cli = MatrixClientPeg.get();
|
2015-11-30 20:15:57 +03:00
|
|
|
|
2015-12-22 18:18:50 +03:00
|
|
|
// XXX: todo: merge overlapping results somehow?
|
|
|
|
// XXX: why doesn't searching on name work?
|
|
|
|
|
2015-12-22 21:15:32 +03:00
|
|
|
if (this.state.searchResults.results === undefined) {
|
|
|
|
// awaiting results
|
|
|
|
return [];
|
|
|
|
}
|
2015-12-22 18:18:50 +03:00
|
|
|
|
2015-12-22 21:15:32 +03:00
|
|
|
var ret = [];
|
|
|
|
|
|
|
|
if (!this.state.searchResults.next_batch) {
|
|
|
|
if (this.state.searchResults.results.length == 0) {
|
2015-12-22 18:18:50 +03:00
|
|
|
ret.push(<li key="search-top-marker">
|
|
|
|
<h2 className="mx_RoomView_topMarker">No results</h2>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
ret.push(<li key="search-top-marker">
|
|
|
|
<h2 className="mx_RoomView_topMarker">No more results</h2>
|
|
|
|
</li>
|
|
|
|
);
|
2015-12-21 15:39:10 +03:00
|
|
|
}
|
2015-12-22 18:18:50 +03:00
|
|
|
}
|
2015-12-21 15:39:10 +03:00
|
|
|
|
2015-12-22 18:18:50 +03:00
|
|
|
var lastRoomId;
|
2015-12-10 16:58:06 +03:00
|
|
|
|
2015-12-22 21:15:32 +03:00
|
|
|
for (var i = this.state.searchResults.results.length - 1; i >= 0; i--) {
|
|
|
|
var result = this.state.searchResults.results[i];
|
|
|
|
|
|
|
|
var mxEv = result.context.getEvent();
|
2015-12-18 19:42:46 +03:00
|
|
|
|
2015-12-22 18:18:50 +03:00
|
|
|
if (!EventTile.haveTileForEvent(mxEv)) {
|
|
|
|
// XXX: can this ever happen? It will make the result count
|
|
|
|
// not match the displayed count.
|
|
|
|
continue;
|
|
|
|
}
|
2015-12-18 19:42:46 +03:00
|
|
|
|
2015-12-22 18:18:50 +03:00
|
|
|
if (this.state.searchScope === 'All') {
|
2015-12-22 21:15:32 +03:00
|
|
|
var roomId = mxEv.getRoomId();
|
2015-12-22 18:18:50 +03:00
|
|
|
if(roomId != lastRoomId) {
|
2016-01-06 19:46:29 +03:00
|
|
|
var room = cli.getRoom(roomId);
|
|
|
|
|
|
|
|
// XXX: if we've left the room, we might not know about
|
|
|
|
// it. We should tell the js sdk to go and find out about
|
|
|
|
// it. But that's not an issue currently, as synapse only
|
|
|
|
// returns results for rooms we're joined to.
|
|
|
|
var roomName = room ? room.name : "Unknown room "+roomId;
|
|
|
|
|
|
|
|
ret.push(<li key={mxEv.getId() + "-room"}>
|
|
|
|
<h1>Room: { roomName }</h1>
|
|
|
|
</li>);
|
2015-12-22 18:18:50 +03:00
|
|
|
lastRoomId = roomId;
|
2015-11-30 20:15:57 +03:00
|
|
|
}
|
2015-12-22 18:18:50 +03:00
|
|
|
}
|
2015-11-30 20:15:57 +03:00
|
|
|
|
2015-12-23 13:10:08 +03:00
|
|
|
ret.push(<SearchResultTile key={mxEv.getId()}
|
|
|
|
searchResult={result}
|
|
|
|
searchHighlights={this.state.searchHighlights}/>);
|
2015-11-30 20:15:57 +03:00
|
|
|
}
|
2015-12-22 18:18:50 +03:00
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
|
|
|
getEventTiles: function() {
|
|
|
|
var DateSeparator = sdk.getComponent('messages.DateSeparator');
|
|
|
|
|
|
|
|
var ret = [];
|
|
|
|
var count = 0;
|
|
|
|
|
|
|
|
var EventTile = sdk.getComponent('rooms.EventTile');
|
2015-11-30 20:15:57 +03:00
|
|
|
|
2015-12-21 13:46:32 +03:00
|
|
|
var prevEvent = null; // the last event we showed
|
2015-12-22 14:04:39 +03:00
|
|
|
var startIdx = Math.max(0, this.state.room.timeline.length - this.state.messageCap);
|
2016-01-09 00:18:47 +03:00
|
|
|
var readMarkerIndex;
|
|
|
|
var ghostIndex;
|
2015-12-21 13:46:32 +03:00
|
|
|
for (var i = startIdx; i < this.state.room.timeline.length; i++) {
|
2015-11-30 20:15:57 +03:00
|
|
|
var mxEv = this.state.room.timeline[i];
|
|
|
|
|
|
|
|
if (!EventTile.haveTileForEvent(mxEv)) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-12-16 14:54:29 +03:00
|
|
|
if (this.props.ConferenceHandler && mxEv.getType() === "m.room.member") {
|
|
|
|
if (this.props.ConferenceHandler.isConferenceUser(mxEv.getSender()) ||
|
|
|
|
this.props.ConferenceHandler.isConferenceUser(mxEv.getStateKey())) {
|
|
|
|
continue; // suppress conf user join/parts
|
|
|
|
}
|
|
|
|
}
|
2015-11-30 20:15:57 +03:00
|
|
|
|
2016-01-12 19:38:09 +03:00
|
|
|
// now we've decided whether or not to show this message,
|
2016-01-09 00:18:47 +03:00
|
|
|
// add the read up to marker if appropriate
|
|
|
|
// doing this here means we implicitly do not show the marker
|
|
|
|
// if it's at the bottom
|
|
|
|
// NB. it would be better to decide where the read marker was going
|
|
|
|
// when the state changed rather than here in the render method, but
|
|
|
|
// this is where we decide what messages we show so it's the only
|
|
|
|
// place we know whether we're at the bottom or not.
|
|
|
|
var self = this;
|
2016-01-12 20:18:16 +03:00
|
|
|
var mxEvSender = mxEv.sender ? mxEv.sender.userId : null;
|
|
|
|
if (prevEvent && prevEvent.getId() == this.state.readMarkerEventId && mxEvSender != MatrixClientPeg.get().credentials.userId) {
|
2016-01-09 00:18:47 +03:00
|
|
|
var hr;
|
2016-01-12 17:13:42 +03:00
|
|
|
hr = (<hr className="mx_RoomView_myReadMarker" style={{opacity: 1, width: '99%'}} ref={function(n) {
|
2016-01-09 00:18:47 +03:00
|
|
|
self.readMarkerNode = n;
|
|
|
|
}} />);
|
|
|
|
readMarkerIndex = ret.length;
|
|
|
|
ret.push(<li key="_readupto" className="mx_RoomView_myReadMarker_container">{hr}</li>);
|
|
|
|
}
|
|
|
|
|
2015-12-21 13:46:32 +03:00
|
|
|
// is this a continuation of the previous message?
|
2015-11-30 20:15:57 +03:00
|
|
|
var continuation = false;
|
2015-12-21 13:46:32 +03:00
|
|
|
if (prevEvent !== null) {
|
|
|
|
if (mxEv.sender &&
|
|
|
|
prevEvent.sender &&
|
|
|
|
(mxEv.sender.userId === prevEvent.sender.userId) &&
|
|
|
|
(mxEv.getType() == prevEvent.getType())
|
2015-11-30 20:15:57 +03:00
|
|
|
)
|
|
|
|
{
|
|
|
|
continuation = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-21 13:46:32 +03:00
|
|
|
// do we need a date separator since the last event?
|
|
|
|
var ts1 = mxEv.getTs();
|
|
|
|
if ((prevEvent == null && !this._canPaginate()) ||
|
|
|
|
(prevEvent != null &&
|
|
|
|
new Date(prevEvent.getTs()).toDateString() !== new Date(ts1).toDateString())) {
|
|
|
|
var dateSeparator = <li key={ts1}><DateSeparator key={ts1} ts={ts1}/></li>;
|
|
|
|
ret.push(dateSeparator);
|
2015-11-30 20:15:57 +03:00
|
|
|
continuation = false;
|
|
|
|
}
|
|
|
|
|
2015-12-21 13:46:32 +03:00
|
|
|
var last = false;
|
|
|
|
if (i == this.state.room.timeline.length - 1) {
|
|
|
|
// XXX: we might not show a tile for the last event.
|
|
|
|
last = true;
|
|
|
|
}
|
|
|
|
|
2015-12-18 19:42:46 +03:00
|
|
|
var eventId = mxEv.getId();
|
2015-12-21 13:46:32 +03:00
|
|
|
ret.push(
|
2015-12-18 19:42:46 +03:00
|
|
|
<li key={eventId} ref={this._collectEventNode.bind(this, eventId)} data-scroll-token={eventId}>
|
|
|
|
<EventTile mxEvent={mxEv} continuation={continuation} last={last}/>
|
|
|
|
</li>
|
2015-11-30 20:15:57 +03:00
|
|
|
);
|
2015-12-21 13:46:32 +03:00
|
|
|
|
2016-01-09 00:18:47 +03:00
|
|
|
// A read up to marker has died and returned as a ghost!
|
|
|
|
// Lives in the dom as the ghost of the previous one while it fades away
|
|
|
|
if (eventId == this.state.readMarkerGhostEventId) {
|
2016-01-09 00:51:14 +03:00
|
|
|
ghostIndex = ret.length;
|
2016-01-07 14:18:41 +03:00
|
|
|
}
|
|
|
|
|
2015-12-21 13:46:32 +03:00
|
|
|
prevEvent = mxEv;
|
2015-11-30 20:15:57 +03:00
|
|
|
}
|
2015-12-21 13:46:32 +03:00
|
|
|
|
2016-01-09 00:18:47 +03:00
|
|
|
// splice the read marker ghost in now that we know whether the read receipt
|
|
|
|
// is the last element or not, because we only decide as we're going along.
|
|
|
|
if (readMarkerIndex === undefined && ghostIndex && ghostIndex <= ret.length) {
|
|
|
|
var hr;
|
2016-01-13 18:18:21 +03:00
|
|
|
hr = (<hr className="mx_RoomView_myReadMarker" style={{opacity: 1, width: '99%'}} ref={function(n) {
|
2016-01-12 20:48:34 +03:00
|
|
|
Velocity(n, {opacity: '0', width: '10%'}, {duration: 400, easing: 'easeInSine', delay: 1000, complete: function() {
|
2016-01-09 00:18:47 +03:00
|
|
|
self.setState({readMarkerGhostEventId: undefined});
|
|
|
|
}});
|
|
|
|
}} />);
|
|
|
|
ret.splice(ghostIndex, 0, (
|
|
|
|
<li key="_readuptoghost" className="mx_RoomView_myReadMarker_container">{hr}</li>
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2015-11-30 20:15:57 +03:00
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
2016-01-05 20:34:25 +03:00
|
|
|
uploadNewState: function(newVals) {
|
2015-11-30 20:15:57 +03:00
|
|
|
var old_name = this.state.room.name;
|
|
|
|
|
|
|
|
var old_topic = this.state.room.currentState.getStateEvents('m.room.topic', '');
|
|
|
|
if (old_topic) {
|
|
|
|
old_topic = old_topic.getContent().topic;
|
|
|
|
} else {
|
|
|
|
old_topic = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
var old_join_rule = this.state.room.currentState.getStateEvents('m.room.join_rules', '');
|
|
|
|
if (old_join_rule) {
|
|
|
|
old_join_rule = old_join_rule.getContent().join_rule;
|
|
|
|
} else {
|
|
|
|
old_join_rule = "invite";
|
|
|
|
}
|
|
|
|
|
|
|
|
var old_history_visibility = this.state.room.currentState.getStateEvents('m.room.history_visibility', '');
|
|
|
|
if (old_history_visibility) {
|
|
|
|
old_history_visibility = old_history_visibility.getContent().history_visibility;
|
|
|
|
} else {
|
|
|
|
old_history_visibility = "shared";
|
|
|
|
}
|
|
|
|
|
2016-01-17 05:48:55 +03:00
|
|
|
var old_guest_read = (old_history_visibility === "world_readable");
|
|
|
|
|
|
|
|
var old_guest_join = this.state.room.currentState.getStateEvents('m.room.guest_access', '');
|
|
|
|
if (old_guest_join) {
|
|
|
|
old_guest_join = (old_guest_join.getContent().guest_access === "can_join");
|
|
|
|
}
|
|
|
|
else {
|
2016-01-17 06:59:31 +03:00
|
|
|
old_guest_join = false;
|
2016-01-17 05:48:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var old_canonical_alias = this.state.room.currentState.getStateEvents('m.room.canonical_alias', '');
|
|
|
|
if (old_canonical_alias) {
|
|
|
|
old_canonical_alias = old_canonical_alias.getContent().alias;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
old_canonical_alias = "";
|
|
|
|
}
|
|
|
|
|
2015-11-30 20:15:57 +03:00
|
|
|
var deferreds = [];
|
|
|
|
|
2016-01-13 17:03:54 +03:00
|
|
|
if (old_name != newVals.name && newVals.name != undefined) {
|
2015-11-30 20:15:57 +03:00
|
|
|
deferreds.push(
|
2016-01-05 20:34:25 +03:00
|
|
|
MatrixClientPeg.get().setRoomName(this.state.room.roomId, newVals.name)
|
2015-11-30 20:15:57 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-01-05 20:34:25 +03:00
|
|
|
if (old_topic != newVals.topic && newVals.topic != undefined) {
|
2015-11-30 20:15:57 +03:00
|
|
|
deferreds.push(
|
2016-01-05 20:34:25 +03:00
|
|
|
MatrixClientPeg.get().setRoomTopic(this.state.room.roomId, newVals.topic)
|
2015-11-30 20:15:57 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-01-05 20:34:25 +03:00
|
|
|
if (old_join_rule != newVals.join_rule && newVals.join_rule != undefined) {
|
2015-11-30 20:15:57 +03:00
|
|
|
deferreds.push(
|
|
|
|
MatrixClientPeg.get().sendStateEvent(
|
|
|
|
this.state.room.roomId, "m.room.join_rules", {
|
2016-01-05 20:34:25 +03:00
|
|
|
join_rule: newVals.join_rule,
|
2015-11-30 20:15:57 +03:00
|
|
|
}, ""
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-01-22 20:01:15 +03:00
|
|
|
// XXX: EVIL HACK: for now, don't let Vector clobber 'joined' visibility to 'invited'
|
|
|
|
// just because it doesn't know about 'joined' yet. In future we should fix it
|
2016-01-22 18:51:27 +03:00
|
|
|
// properly - https://github.com/vector-im/vector-web/issues/731
|
2016-01-22 20:01:15 +03:00
|
|
|
if (old_history_visibility === "joined") {
|
|
|
|
old_history_visibility = "invited";
|
2016-01-22 18:51:27 +03:00
|
|
|
}
|
|
|
|
|
2016-01-18 20:39:23 +03:00
|
|
|
var visibilityDeferred;
|
2016-01-05 20:34:25 +03:00
|
|
|
if (old_history_visibility != newVals.history_visibility &&
|
|
|
|
newVals.history_visibility != undefined) {
|
2016-01-18 20:39:23 +03:00
|
|
|
visibilityDeferred =
|
2015-11-30 20:15:57 +03:00
|
|
|
MatrixClientPeg.get().sendStateEvent(
|
|
|
|
this.state.room.roomId, "m.room.history_visibility", {
|
2016-01-05 20:34:25 +03:00
|
|
|
history_visibility: newVals.history_visibility,
|
2015-11-30 20:15:57 +03:00
|
|
|
}, ""
|
2016-01-18 22:56:35 +03:00
|
|
|
);
|
2015-11-30 20:15:57 +03:00
|
|
|
}
|
|
|
|
|
2016-01-18 20:39:23 +03:00
|
|
|
if (old_guest_read != newVals.guest_read ||
|
|
|
|
old_guest_join != newVals.guest_join)
|
|
|
|
{
|
|
|
|
var guestDeferred =
|
|
|
|
MatrixClientPeg.get().setGuestAccess(this.state.room.roomId, {
|
|
|
|
allowRead: newVals.guest_read,
|
|
|
|
allowJoin: newVals.guest_join
|
|
|
|
});
|
|
|
|
|
|
|
|
if (visibilityDeferred) {
|
|
|
|
visibilityDeferred = visibilityDeferred.then(guestDeferred);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
visibilityDeferred = guestDeferred;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visibilityDeferred) {
|
|
|
|
deferreds.push(visibilityDeferred);
|
|
|
|
}
|
|
|
|
|
2016-01-14 21:06:48 +03:00
|
|
|
// setRoomMutePushRule will do nothing if there is no change
|
|
|
|
deferreds.push(
|
|
|
|
MatrixClientPeg.get().setRoomMutePushRule(
|
|
|
|
"global", this.state.room.roomId, newVals.are_notifications_muted
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2016-01-05 20:34:25 +03:00
|
|
|
if (newVals.power_levels) {
|
2015-11-30 20:15:57 +03:00
|
|
|
deferreds.push(
|
|
|
|
MatrixClientPeg.get().sendStateEvent(
|
2016-01-05 20:34:25 +03:00
|
|
|
this.state.room.roomId, "m.room.power_levels", newVals.power_levels, ""
|
2015-11-30 20:15:57 +03:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-01-17 05:48:55 +03:00
|
|
|
if (newVals.alias_operations) {
|
|
|
|
var oplist = [];
|
|
|
|
for (var i = 0; i < newVals.alias_operations.length; i++) {
|
|
|
|
var alias_operation = newVals.alias_operations[i];
|
|
|
|
switch (alias_operation.type) {
|
|
|
|
case 'put':
|
|
|
|
oplist.push(
|
|
|
|
MatrixClientPeg.get().createAlias(
|
|
|
|
alias_operation.alias, this.state.room.roomId
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'delete':
|
|
|
|
oplist.push(
|
|
|
|
MatrixClientPeg.get().deleteAlias(
|
|
|
|
alias_operation.alias
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log("Unknown alias operation, ignoring: " + alias_operation.type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oplist.length) {
|
|
|
|
var deferred = oplist[0];
|
|
|
|
oplist.splice(1).forEach(function (f) {
|
|
|
|
deferred = deferred.then(f);
|
|
|
|
});
|
|
|
|
deferreds.push(deferred);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-17 15:27:21 +03:00
|
|
|
if (newVals.tag_operations) {
|
|
|
|
// FIXME: should probably be factored out with alias_operations above
|
|
|
|
var oplist = [];
|
|
|
|
for (var i = 0; i < newVals.tag_operations.length; i++) {
|
|
|
|
var tag_operation = newVals.tag_operations[i];
|
|
|
|
switch (tag_operation.type) {
|
|
|
|
case 'put':
|
|
|
|
oplist.push(
|
|
|
|
MatrixClientPeg.get().setRoomTag(
|
|
|
|
this.props.roomId, tag_operation.tag, {}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'delete':
|
|
|
|
oplist.push(
|
|
|
|
MatrixClientPeg.get().deleteRoomTag(
|
|
|
|
this.props.roomId, tag_operation.tag
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log("Unknown tag operation, ignoring: " + tag_operation.type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oplist.length) {
|
|
|
|
var deferred = oplist[0];
|
|
|
|
oplist.splice(1).forEach(function (f) {
|
|
|
|
deferred = deferred.then(f);
|
|
|
|
});
|
|
|
|
deferreds.push(deferred);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-17 05:48:55 +03:00
|
|
|
if (old_canonical_alias !== newVals.canonical_alias) {
|
|
|
|
deferreds.push(
|
|
|
|
MatrixClientPeg.get().sendStateEvent(
|
|
|
|
this.state.room.roomId, "m.room.canonical_alias", {
|
|
|
|
alias: newVals.canonical_alias
|
|
|
|
}, ""
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-01-13 17:03:54 +03:00
|
|
|
if (newVals.color_scheme) {
|
2016-01-08 06:22:38 +03:00
|
|
|
deferreds.push(
|
|
|
|
MatrixClientPeg.get().setRoomAccountData(
|
2016-01-13 17:03:54 +03:00
|
|
|
this.state.room.roomId, "org.matrix.room.color_scheme", newVals.color_scheme
|
2016-01-08 06:22:38 +03:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-11-30 20:15:57 +03:00
|
|
|
if (deferreds.length) {
|
|
|
|
var self = this;
|
2016-01-17 05:48:55 +03:00
|
|
|
q.allSettled(deferreds).then(
|
|
|
|
function(results) {
|
|
|
|
var fails = results.filter(function(result) { return result.state !== "fulfilled" });
|
|
|
|
if (fails.length) {
|
|
|
|
fails.forEach(function(result) {
|
|
|
|
console.error(result.reason);
|
|
|
|
});
|
|
|
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
Modal.createDialog(ErrorDialog, {
|
|
|
|
title: "Failed to set state",
|
|
|
|
description: fails.map(function(result) { return result.reason }).join("\n"),
|
|
|
|
});
|
|
|
|
self.refs.room_settings.resetState();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
self.setState({
|
|
|
|
editingRoomSettings: false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}).finally(function() {
|
|
|
|
self.setState({
|
|
|
|
uploadingRoomSettings: false,
|
|
|
|
});
|
2015-11-30 20:15:57 +03:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
editingRoomSettings: false,
|
|
|
|
uploadingRoomSettings: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_collectEventNode: function(eventId, node) {
|
|
|
|
if (this.eventNodes == undefined) this.eventNodes = {};
|
|
|
|
this.eventNodes[eventId] = node;
|
|
|
|
},
|
|
|
|
|
|
|
|
_indexForEventId(evId) {
|
|
|
|
for (var i = 0; i < this.state.room.timeline.length; ++i) {
|
|
|
|
if (evId == this.state.room.timeline[i].getId()) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
sendReadReceipt: function() {
|
|
|
|
if (!this.state.room) return;
|
|
|
|
var currentReadUpToEventId = this.state.room.getEventReadUpTo(MatrixClientPeg.get().credentials.userId);
|
|
|
|
var currentReadUpToEventIndex = this._indexForEventId(currentReadUpToEventId);
|
|
|
|
|
|
|
|
var lastReadEventIndex = this._getLastDisplayedEventIndexIgnoringOwn();
|
|
|
|
if (lastReadEventIndex === null) return;
|
|
|
|
|
2016-01-20 19:39:25 +03:00
|
|
|
var lastReadEvent = this.state.room.timeline[lastReadEventIndex];
|
|
|
|
|
|
|
|
// we also remember the last read receipt we sent to avoid spamming the same one at the server repeatedly
|
|
|
|
if (lastReadEventIndex > currentReadUpToEventIndex && this.last_rr_sent_event_id != lastReadEvent.getId()) {
|
|
|
|
this.last_rr_sent_event_id = lastReadEvent.getId();
|
|
|
|
MatrixClientPeg.get().sendReadReceipt(lastReadEvent).catch(() => {
|
|
|
|
// it failed, so allow retries next time the user is active
|
|
|
|
this.last_rr_sent_event_id = undefined;
|
|
|
|
});
|
2015-11-30 20:15:57 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_getLastDisplayedEventIndexIgnoringOwn: function() {
|
|
|
|
if (this.eventNodes === undefined) return null;
|
|
|
|
|
|
|
|
var messageWrapper = this.refs.messagePanel;
|
|
|
|
if (messageWrapper === undefined) return null;
|
|
|
|
var wrapperRect = ReactDOM.findDOMNode(messageWrapper).getBoundingClientRect();
|
|
|
|
|
|
|
|
for (var i = this.state.room.timeline.length-1; i >= 0; --i) {
|
|
|
|
var ev = this.state.room.timeline[i];
|
|
|
|
|
|
|
|
if (ev.sender && ev.sender.userId == MatrixClientPeg.get().credentials.userId) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var node = this.eventNodes[ev.getId()];
|
|
|
|
if (!node) continue;
|
|
|
|
|
|
|
|
var boundingRect = node.getBoundingClientRect();
|
|
|
|
|
|
|
|
if (boundingRect.bottom < wrapperRect.bottom) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
onSettingsClick: function() {
|
2016-01-21 02:09:36 +03:00
|
|
|
this.showSettings(true);
|
2015-11-30 20:15:57 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onSaveClick: function() {
|
|
|
|
this.setState({
|
|
|
|
uploadingRoomSettings: true,
|
|
|
|
});
|
|
|
|
|
2016-01-05 20:34:25 +03:00
|
|
|
this.uploadNewState({
|
|
|
|
name: this.refs.header.getRoomName(),
|
2016-01-17 05:48:55 +03:00
|
|
|
topic: this.refs.header.getTopic(),
|
2016-01-05 20:34:25 +03:00
|
|
|
join_rule: this.refs.room_settings.getJoinRules(),
|
|
|
|
history_visibility: this.refs.room_settings.getHistoryVisibility(),
|
2016-01-14 21:06:48 +03:00
|
|
|
are_notifications_muted: this.refs.room_settings.areNotificationsMuted(),
|
2016-01-05 20:34:25 +03:00
|
|
|
power_levels: this.refs.room_settings.getPowerLevels(),
|
2016-01-17 05:48:55 +03:00
|
|
|
alias_operations: this.refs.room_settings.getAliasOperations(),
|
2016-01-17 15:27:21 +03:00
|
|
|
tag_operations: this.refs.room_settings.getTagOperations(),
|
2016-01-17 05:48:55 +03:00
|
|
|
canonical_alias: this.refs.room_settings.getCanonicalAlias(),
|
2016-01-05 20:34:25 +03:00
|
|
|
guest_join: this.refs.room_settings.canGuestsJoin(),
|
2016-01-13 17:03:54 +03:00
|
|
|
guest_read: this.refs.room_settings.canGuestsRead(),
|
|
|
|
color_scheme: this.refs.room_settings.getColorScheme(),
|
2016-01-05 20:34:25 +03:00
|
|
|
});
|
2015-11-30 20:15:57 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onCancelClick: function() {
|
2016-01-08 06:22:38 +03:00
|
|
|
this.updateTint();
|
2015-12-18 19:42:46 +03:00
|
|
|
this.setState({editingRoomSettings: false});
|
2015-11-30 20:15:57 +03:00
|
|
|
},
|
|
|
|
|
2015-12-13 16:49:28 +03:00
|
|
|
onLeaveClick: function() {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'leave_room',
|
|
|
|
room_id: this.props.roomId,
|
|
|
|
});
|
2015-12-16 19:06:29 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onForgetClick: function() {
|
|
|
|
MatrixClientPeg.get().forget(this.props.roomId).done(function() {
|
|
|
|
dis.dispatch({ action: 'view_next_room' });
|
|
|
|
}, function(err) {
|
2015-12-18 19:56:37 +03:00
|
|
|
var errCode = err.errcode || "unknown error code";
|
|
|
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
Modal.createDialog(ErrorDialog, {
|
|
|
|
title: "Error",
|
|
|
|
description: `Failed to forget room (${errCode})`
|
|
|
|
});
|
2015-12-16 19:06:29 +03:00
|
|
|
});
|
2015-12-13 16:49:28 +03:00
|
|
|
},
|
|
|
|
|
2015-11-30 20:15:57 +03:00
|
|
|
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 });
|
|
|
|
},
|
|
|
|
|
2015-12-18 19:42:46 +03:00
|
|
|
onCancelSearchClick: function () {
|
|
|
|
this.setState({
|
|
|
|
searching: false,
|
|
|
|
searchResults: null,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-11-30 20:15:57 +03:00
|
|
|
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() {
|
2015-12-22 18:18:50 +03:00
|
|
|
var messagePanel = this.refs.messagePanel;
|
|
|
|
if (!messagePanel) return;
|
|
|
|
messagePanel.scrollToBottom();
|
2015-11-30 20:15:57 +03:00
|
|
|
},
|
|
|
|
|
2015-12-10 19:26:36 +03:00
|
|
|
// scroll the event view to put the given event at the bottom.
|
|
|
|
//
|
|
|
|
// pixel_offset gives the number of pixels between the bottom of the event
|
|
|
|
// and the bottom of the container.
|
2015-12-11 00:44:30 +03:00
|
|
|
scrollToEvent: function(eventId, pixelOffset) {
|
2015-12-22 18:18:50 +03:00
|
|
|
var messagePanel = this.refs.messagePanel;
|
|
|
|
if (!messagePanel) return;
|
|
|
|
|
2015-12-11 00:44:30 +03:00
|
|
|
var idx = this._indexForEventId(eventId);
|
2015-12-10 19:26:36 +03:00
|
|
|
if (idx === null) {
|
|
|
|
// we don't seem to have this event in our timeline. Presumably
|
|
|
|
// it's fallen out of scrollback. We ought to backfill until we
|
|
|
|
// find it, but we'd have to be careful we didn't backfill forever
|
|
|
|
// looking for a non-existent event.
|
|
|
|
//
|
|
|
|
// for now, just scroll to the top of the buffer.
|
2015-12-11 00:44:30 +03:00
|
|
|
console.log("Refusing to scroll to unknown event "+eventId);
|
2015-12-22 18:18:50 +03:00
|
|
|
messagePanel.scrollToTop();
|
2015-12-10 19:26:36 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we might need to roll back the messagecap (to generate tiles for
|
2015-12-11 00:44:30 +03:00
|
|
|
// older messages). This just means telling getEventTiles to create
|
|
|
|
// tiles for events we already have in our timeline (we already know
|
|
|
|
// the event in question is in our timeline, so we shouldn't need to
|
|
|
|
// backfill).
|
|
|
|
//
|
|
|
|
// we actually wind back slightly further than the event in question,
|
|
|
|
// because we want the event to be at the *bottom* of the container.
|
|
|
|
// Don't roll it back past the timeline we have, though.
|
2015-12-10 19:26:36 +03:00
|
|
|
var minCap = this.state.room.timeline.length - Math.min(idx - INITIAL_SIZE, 0);
|
|
|
|
if (minCap > this.state.messageCap) {
|
|
|
|
this.setState({messageCap: minCap});
|
|
|
|
}
|
|
|
|
|
2015-12-18 19:42:46 +03:00
|
|
|
// the scrollTokens on our DOM nodes are the event IDs, so we can pass
|
|
|
|
// eventId directly into _scrollToToken.
|
2015-12-22 18:18:50 +03:00
|
|
|
messagePanel.scrollToToken(eventId, pixelOffset);
|
2015-12-18 19:42:46 +03:00
|
|
|
},
|
|
|
|
|
2015-12-11 00:34:10 +03:00
|
|
|
// get the current scroll position of the room, so that it can be
|
|
|
|
// restored when we switch back to it
|
|
|
|
getScrollState: function() {
|
2015-12-22 18:18:50 +03:00
|
|
|
var messagePanel = this.refs.messagePanel;
|
|
|
|
if (!messagePanel) return null;
|
|
|
|
|
|
|
|
return messagePanel.getScrollState();
|
2015-12-10 19:26:36 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
restoreScrollState: function(scrollState) {
|
2015-12-22 18:18:50 +03:00
|
|
|
var messagePanel = this.refs.messagePanel;
|
|
|
|
if (!messagePanel) return null;
|
2015-12-18 19:42:46 +03:00
|
|
|
|
2015-12-10 19:26:36 +03:00
|
|
|
if(scrollState.atBottom) {
|
|
|
|
// we were at the bottom before. Ideally we'd scroll to the
|
|
|
|
// 'read-up-to' mark here.
|
2015-12-22 18:18:50 +03:00
|
|
|
messagePanel.scrollToBottom();
|
|
|
|
|
2015-12-18 19:42:46 +03:00
|
|
|
} else if (scrollState.lastDisplayedScrollToken) {
|
|
|
|
// we might need to backfill, so we call scrollToEvent rather than
|
2015-12-22 18:18:50 +03:00
|
|
|
// scrollToToken here. The scrollTokens on our DOM nodes are the
|
2015-12-18 19:42:46 +03:00
|
|
|
// event IDs, so lastDisplayedScrollToken will be the event ID we need,
|
|
|
|
// and we can pass it directly into scrollToEvent.
|
|
|
|
this.scrollToEvent(scrollState.lastDisplayedScrollToken,
|
2015-12-10 19:26:36 +03:00
|
|
|
scrollState.pixelOffset);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-12-13 07:32:48 +03:00
|
|
|
onResize: function(e) {
|
|
|
|
// It seems flexbox doesn't give us a way to constrain the auxPanel height to have
|
|
|
|
// a minimum of the height of the video element, whilst also capping it from pushing out the page
|
|
|
|
// so we have to do it via JS instead. In this implementation we cap the height by putting
|
|
|
|
// a maxHeight on the underlying remote video tag.
|
2016-01-10 16:03:37 +03:00
|
|
|
|
2016-01-15 18:53:53 +03:00
|
|
|
// header + footer + status + give us at least 120px of scrollback at all times.
|
2016-01-15 17:22:17 +03:00
|
|
|
var auxPanelMaxHeight = window.innerHeight -
|
|
|
|
(83 + // height of RoomHeader
|
|
|
|
36 + // height of the status area
|
|
|
|
72 + // minimum height of the message compmoser
|
2016-01-21 02:09:36 +03:00
|
|
|
(this.state.editingRoomSettings ? (window.innerHeight * 0.3) : 120)); // amount of desired scrollback
|
2016-01-10 16:03:37 +03:00
|
|
|
|
|
|
|
// XXX: this is a bit of a hack and might possibly cause the video to push out the page anyway
|
|
|
|
// but it's better than the video going missing entirely
|
|
|
|
if (auxPanelMaxHeight < 50) auxPanelMaxHeight = 50;
|
|
|
|
|
2015-12-13 07:32:48 +03:00
|
|
|
if (this.refs.callView) {
|
2016-01-11 18:28:59 +03:00
|
|
|
var video = this.refs.callView.getVideoView().getRemoteVideoElement();
|
2015-12-13 07:32:48 +03:00
|
|
|
|
|
|
|
video.style.maxHeight = auxPanelMaxHeight + "px";
|
|
|
|
}
|
2016-01-10 16:03:37 +03:00
|
|
|
|
|
|
|
// we need to do this for general auxPanels too
|
|
|
|
if (this.refs.auxPanel) {
|
|
|
|
this.refs.auxPanel.style.maxHeight = auxPanelMaxHeight + "px";
|
|
|
|
}
|
2016-01-21 02:09:36 +03:00
|
|
|
|
|
|
|
// the above might have made the aux panel resize itself, so now
|
|
|
|
// we need to tell the gemini panel to adapt.
|
|
|
|
this.onChildResize();
|
2015-12-13 07:32:48 +03:00
|
|
|
},
|
|
|
|
|
2015-12-15 03:01:47 +03:00
|
|
|
onFullscreenClick: function() {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'video_fullscreen',
|
|
|
|
fullscreen: true
|
|
|
|
}, true);
|
|
|
|
},
|
|
|
|
|
2015-12-15 02:37:34 +03:00
|
|
|
onMuteAudioClick: function() {
|
|
|
|
var call = CallHandler.getCallForRoom(this.props.roomId);
|
|
|
|
if (!call) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var newState = !call.isMicrophoneMuted();
|
|
|
|
call.setMicrophoneMuted(newState);
|
|
|
|
this.setState({
|
|
|
|
audioMuted: newState
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onMuteVideoClick: function() {
|
|
|
|
var call = CallHandler.getCallForRoom(this.props.roomId);
|
|
|
|
if (!call) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var newState = !call.isLocalVideoMuted();
|
|
|
|
call.setLocalVideoMuted(newState);
|
|
|
|
this.setState({
|
|
|
|
videoMuted: newState
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-01-11 18:28:59 +03:00
|
|
|
onChildResize: function() {
|
|
|
|
// When the video or the message composer resizes, the scroll panel
|
|
|
|
// also changes size. Work around GeminiScrollBar fail by telling it
|
|
|
|
// about it. This also ensures that the scroll offset is updated.
|
|
|
|
if (this.refs.messagePanel) {
|
|
|
|
this.refs.messagePanel.forceUpdate();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-01-17 06:59:31 +03:00
|
|
|
showSettings: function(show) {
|
|
|
|
// XXX: this is a bit naughty; we should be doing this via props
|
|
|
|
if (show) {
|
|
|
|
this.setState({editingRoomSettings: true});
|
2016-01-21 02:09:36 +03:00
|
|
|
var self = this;
|
|
|
|
setTimeout(function() { self.onResize() }, 0);
|
2016-01-17 06:59:31 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-01-27 20:58:47 +03:00
|
|
|
onRegisterClicked: function() {
|
|
|
|
dis.dispatch({'action': 'logout'});
|
|
|
|
dis.dispatch({'action': 'start_registration'});
|
|
|
|
},
|
|
|
|
|
|
|
|
onLoginClicked: function() {
|
|
|
|
dis.dispatch({'action': 'logout'});
|
|
|
|
dis.dispatch({'action': 'start_login'});
|
|
|
|
},
|
|
|
|
|
2015-11-30 20:15:57 +03:00
|
|
|
render: function() {
|
|
|
|
var RoomHeader = sdk.getComponent('rooms.RoomHeader');
|
|
|
|
var MessageComposer = sdk.getComponent('rooms.MessageComposer');
|
|
|
|
var CallView = sdk.getComponent("voip.CallView");
|
|
|
|
var RoomSettings = sdk.getComponent("rooms.RoomSettings");
|
2015-12-01 14:19:25 +03:00
|
|
|
var SearchBar = sdk.getComponent("rooms.SearchBar");
|
2015-12-22 18:18:50 +03:00
|
|
|
var ScrollPanel = sdk.getComponent("structures.ScrollPanel");
|
2016-01-06 05:11:07 +03:00
|
|
|
var TintableSvg = sdk.getComponent("elements.TintableSvg");
|
2016-01-12 17:11:15 +03:00
|
|
|
var RoomPreviewBar = sdk.getComponent("rooms.RoomPreviewBar");
|
2015-11-30 20:15:57 +03:00
|
|
|
|
|
|
|
if (!this.state.room) {
|
|
|
|
if (this.props.roomId) {
|
2016-01-18 20:39:23 +03:00
|
|
|
if (this.props.autoPeek && !this.state.autoPeekDone) {
|
2016-01-18 22:56:35 +03:00
|
|
|
var Loader = sdk.getComponent("elements.Spinner");
|
2016-01-18 20:39:23 +03:00
|
|
|
return (
|
|
|
|
<div className="mx_RoomView">
|
|
|
|
<Loader />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var joinErrorText = this.state.joinError ? "Failed to join room!" : "";
|
|
|
|
return (
|
|
|
|
<div className="mx_RoomView">
|
|
|
|
<RoomHeader ref="header" room={this.state.room} simpleHeader="Join room"/>
|
|
|
|
<div className="mx_RoomView_auxPanel">
|
|
|
|
<RoomPreviewBar onJoinClick={ this.onJoinButtonClicked }
|
|
|
|
canJoin={ true } canPreview={ false }/>
|
|
|
|
<div className="error">{joinErrorText}</div>
|
|
|
|
</div>
|
2016-01-18 23:15:12 +03:00
|
|
|
<div className="mx_RoomView_messagePanel"></div>
|
2016-01-18 20:39:23 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-11-30 20:15:57 +03:00
|
|
|
return (
|
|
|
|
<div />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var myUserId = MatrixClientPeg.get().credentials.userId;
|
2015-12-14 18:36:34 +03:00
|
|
|
var myMember = this.state.room.getMember(myUserId);
|
|
|
|
if (myMember && myMember.membership == 'invite') {
|
2015-11-30 20:15:57 +03:00
|
|
|
if (this.state.joining || this.state.rejecting) {
|
|
|
|
var Loader = sdk.getComponent("elements.Spinner");
|
|
|
|
return (
|
|
|
|
<div className="mx_RoomView">
|
|
|
|
<Loader />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
2015-12-14 18:36:34 +03:00
|
|
|
var inviteEvent = myMember.events.member;
|
|
|
|
var inviterName = inviteEvent.sender ? inviteEvent.sender.name : inviteEvent.getSender();
|
2015-11-30 20:15:57 +03:00
|
|
|
// XXX: Leaving this intentionally basic for now because invites are about to change totally
|
2016-01-18 20:39:23 +03:00
|
|
|
// FIXME: This comment is now outdated - what do we need to fix? ^
|
2015-11-30 20:15:57 +03:00
|
|
|
var joinErrorText = this.state.joinError ? "Failed to join room!" : "";
|
|
|
|
var rejectErrorText = this.state.rejectError ? "Failed to reject invite!" : "";
|
2016-01-18 20:39:23 +03:00
|
|
|
|
|
|
|
// We deliberately don't try to peek into invites, even if we have permission to peek
|
|
|
|
// as they could be a spam vector.
|
|
|
|
// XXX: in future we could give the option of a 'Preview' button which lets them view anyway.
|
2016-01-18 23:15:12 +03:00
|
|
|
|
2015-11-30 20:15:57 +03:00
|
|
|
return (
|
|
|
|
<div className="mx_RoomView">
|
2016-01-21 03:45:22 +03:00
|
|
|
<RoomHeader ref="header" room={this.state.room}/>
|
2016-01-18 20:39:23 +03:00
|
|
|
<div className="mx_RoomView_auxPanel">
|
|
|
|
<RoomPreviewBar onJoinClick={ this.onJoinButtonClicked }
|
|
|
|
onRejectClick={ this.onRejectButtonClicked }
|
|
|
|
inviterName={ inviterName }
|
|
|
|
canJoin={ true } canPreview={ false }/>
|
2015-11-30 20:15:57 +03:00
|
|
|
<div className="error">{joinErrorText}</div>
|
|
|
|
<div className="error">{rejectErrorText}</div>
|
|
|
|
</div>
|
2016-01-18 23:15:12 +03:00
|
|
|
<div className="mx_RoomView_messagePanel"></div>
|
2015-11-30 20:15:57 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var scrollheader_classes = classNames({
|
|
|
|
mx_RoomView_scrollheader: true,
|
|
|
|
loading: this.state.paginating
|
|
|
|
});
|
|
|
|
|
2015-12-15 02:37:34 +03:00
|
|
|
var statusBar;
|
2015-11-30 20:15:57 +03:00
|
|
|
|
|
|
|
// for testing UI...
|
|
|
|
// this.state.upload = {
|
|
|
|
// uploadedBytes: 123493,
|
|
|
|
// totalBytes: 347534,
|
|
|
|
// fileName: "testing_fooble.jpg",
|
|
|
|
// }
|
|
|
|
|
2015-12-02 21:16:16 +03:00
|
|
|
if (ContentMessages.getCurrentUploads().length > 0) {
|
|
|
|
var UploadBar = sdk.getComponent('structures.UploadBar');
|
|
|
|
statusBar = <UploadBar room={this.state.room} />
|
2015-12-15 02:37:34 +03:00
|
|
|
} else if (!this.state.searchResults) {
|
2015-11-30 20:15:57 +03:00
|
|
|
var typingString = this.getWhoIsTypingString();
|
2015-12-02 20:37:53 +03:00
|
|
|
// typingString = "S͚͍̭̪̤͙̱͙̖̥͙̥̤̻̙͕͓͂̌ͬ͐̂k̜̝͎̰̥̻̼̂̌͛͗͊̅̒͂̊̍̍͌̈̈́͌̋̊ͬa͉̯͚̺̗̳̩ͪ̋̑͌̓̆̍̂̉̏̅̆ͧ̌̑v̲̲̪̝ͥ̌ͨͮͭ̊͆̾ͮ̍ͮ͑̚e̮̙͈̱̘͕̼̮͒ͩͨͫ̃͗̇ͩ͒ͣͦ͒̄̍͐ͣ̿ͥṘ̗̺͇̺̺͔̄́̊̓͊̍̃ͨ̚ā̼͎̘̟̼͎̜̪̪͚̋ͨͨͧ̓ͦͯͤ̄͆̋͂ͩ͌ͧͅt̙̙̹̗̦͖̞ͫͪ͑̑̅ͪ̃̚ͅ is typing...";
|
2015-11-30 20:15:57 +03:00
|
|
|
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 = (
|
2016-01-27 20:58:47 +03:00
|
|
|
<div className="mx_RoomView_warningBar">
|
2016-01-04 01:30:52 +03:00
|
|
|
<img src="img/warning.svg" width="24" height="23" title="/!\ " alt="/!\ "/>
|
2016-01-27 20:58:47 +03:00
|
|
|
<div className="mx_RoomView_warningBar_textArea">
|
|
|
|
<div className="mx_RoomView_warningBar_title">
|
2015-11-30 20:15:57 +03:00
|
|
|
Connectivity to the server has been lost.
|
|
|
|
</div>
|
2016-01-27 20:58:47 +03:00
|
|
|
<div className="mx_RoomView_warningBar_desc">
|
2015-11-30 20:15:57 +03:00
|
|
|
Sent messages will be stored until your connection has returned.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2015-12-21 17:11:34 +03:00
|
|
|
else if (this.tabComplete.isTabCompleting()) {
|
|
|
|
var TabCompleteBar = sdk.getComponent('rooms.TabCompleteBar');
|
|
|
|
statusBar = (
|
2015-12-22 03:47:04 +03:00
|
|
|
<div className="mx_RoomView_tabCompleteBar">
|
|
|
|
<div className="mx_RoomView_tabCompleteImage">...</div>
|
|
|
|
<div className="mx_RoomView_tabCompleteWrapper">
|
|
|
|
<TabCompleteBar entries={this.tabComplete.peek(6)} />
|
2016-01-04 01:34:56 +03:00
|
|
|
<div className="mx_RoomView_tabCompleteEol" title="->|">
|
2016-01-06 05:11:07 +03:00
|
|
|
<TintableSvg src="img/eol.svg" width="22" height="16"/>
|
2015-12-22 03:47:04 +03:00
|
|
|
Auto-complete
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2015-12-21 17:11:34 +03:00
|
|
|
);
|
|
|
|
}
|
2015-11-30 20:15:57 +03:00
|
|
|
else if (this.state.hasUnsentMessages) {
|
|
|
|
statusBar = (
|
2016-01-27 20:58:47 +03:00
|
|
|
<div className="mx_RoomView_warningBar">
|
2016-01-04 01:30:52 +03:00
|
|
|
<img src="img/warning.svg" width="24" height="23" title="/!\ " alt="/!\ "/>
|
2016-01-27 20:58:47 +03:00
|
|
|
<div className="mx_RoomView_warningBar_textArea">
|
|
|
|
<div className="mx_RoomView_warningBar_title">
|
2015-11-30 20:15:57 +03:00
|
|
|
Some of your messages have not been sent.
|
|
|
|
</div>
|
2016-01-27 20:58:47 +03:00
|
|
|
<div className="mx_RoomView_warningBar_desc">
|
2015-11-30 20:15:57 +03:00
|
|
|
<a className="mx_RoomView_resend_link"
|
|
|
|
onClick={ this.onResendAllClick }>
|
|
|
|
Resend all now
|
|
|
|
</a> or select individual messages to re-send.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// unread count trumps who is typing since the unread count is only
|
|
|
|
// set when you've scrolled up
|
|
|
|
else if (unreadMsgs) {
|
|
|
|
statusBar = (
|
|
|
|
<div className="mx_RoomView_unreadMessagesBar" onClick={ this.scrollToBottom }>
|
2016-01-24 04:51:01 +03:00
|
|
|
<img src="img/newmessages.svg" width="24" height="24" alt=""/>
|
2015-11-30 20:15:57 +03:00
|
|
|
{unreadMsgs}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (typingString) {
|
|
|
|
statusBar = (
|
|
|
|
<div className="mx_RoomView_typingBar">
|
|
|
|
<div className="mx_RoomView_typingImage">...</div>
|
2015-12-15 18:59:25 +03:00
|
|
|
<span className="mx_RoomView_typingText">{typingString}</span>
|
2015-11-30 20:15:57 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-01-24 04:51:01 +03:00
|
|
|
else if (!this.state.atBottom) {
|
|
|
|
statusBar = (
|
|
|
|
<div className="mx_RoomView_scrollToBottomBar" onClick={ this.scrollToBottom }>
|
2016-01-24 05:01:45 +03:00
|
|
|
<img src="img/scrolldown.svg" width="24" height="24" alt="Scroll to bottom of page" title="Scroll to bottom of page"/>
|
2016-01-24 04:51:01 +03:00
|
|
|
</div>
|
|
|
|
);
|
2016-01-27 20:58:47 +03:00
|
|
|
} else if (MatrixClientPeg.get().isGuest()) {
|
|
|
|
statusBar = (
|
|
|
|
<div className="mx_RoomView_warningBar">
|
|
|
|
<img src="img/warning.svg" width="24" height="23" title="/!\ " alt="/!\ "/>
|
|
|
|
<div className="mx_RoomView_warningBar_textArea">
|
|
|
|
<div className="mx_RoomView_warningBar_title">
|
|
|
|
You are using Vector as a guest.
|
|
|
|
</div>
|
|
|
|
<div className="mx_RoomView_warningBar_desc">
|
|
|
|
<a onClick={this.onRegisterClicked}>Register</a> or <a onClick={this.onLoginClicked}>log in</a> to access more rooms and features.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2016-01-24 04:51:01 +03:00
|
|
|
}
|
2015-11-30 20:15:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var aux = null;
|
|
|
|
if (this.state.editingRoomSettings) {
|
2016-01-17 06:59:31 +03:00
|
|
|
aux = <RoomSettings ref="room_settings" onSaveClick={this.onSaveClick} onCancelClick={this.onCancelClick} room={this.state.room} />;
|
2015-11-30 20:15:57 +03:00
|
|
|
}
|
|
|
|
else if (this.state.uploadingRoomSettings) {
|
|
|
|
var Loader = sdk.getComponent("elements.Spinner");
|
|
|
|
aux = <Loader/>;
|
|
|
|
}
|
|
|
|
else if (this.state.searching) {
|
2015-12-18 19:42:46 +03:00
|
|
|
aux = <SearchBar ref="search_bar" searchInProgress={this.state.searchInProgress } onCancelClick={this.onCancelSearchClick} onSearch={this.onSearch}/>;
|
2015-11-30 20:15:57 +03:00
|
|
|
}
|
2016-01-12 17:11:15 +03:00
|
|
|
else if (this.state.guestsCanJoin && MatrixClientPeg.get().isGuest() &&
|
|
|
|
(!myMember || myMember.membership !== "join")) {
|
|
|
|
aux = (
|
|
|
|
<RoomPreviewBar onJoinClick={this.onJoinButtonClicked} canJoin={true} />
|
|
|
|
);
|
|
|
|
}
|
2016-01-18 20:39:23 +03:00
|
|
|
else if (this.state.canPeek &&
|
|
|
|
(!myMember || myMember.membership !== "join")) {
|
|
|
|
aux = (
|
|
|
|
<RoomPreviewBar onJoinClick={this.onJoinButtonClicked} canJoin={true} />
|
|
|
|
);
|
|
|
|
}
|
2015-11-30 20:15:57 +03:00
|
|
|
|
|
|
|
var conferenceCallNotification = null;
|
|
|
|
if (this.state.displayConfCallNotification) {
|
|
|
|
var supportedText;
|
|
|
|
if (!MatrixClientPeg.get().supportsVoip()) {
|
|
|
|
supportedText = " (unsupported)";
|
|
|
|
}
|
|
|
|
conferenceCallNotification = (
|
|
|
|
<div className="mx_RoomView_ongoingConfCallNotification" onClick={this.onConferenceNotificationClick}>
|
|
|
|
Ongoing conference call {supportedText}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
var fileDropTarget = null;
|
|
|
|
if (this.state.draggingFile) {
|
|
|
|
fileDropTarget = <div className="mx_RoomView_fileDropTarget">
|
2016-01-04 01:34:56 +03:00
|
|
|
<div className="mx_RoomView_fileDropTargetLabel" title="Drop File Here">
|
2016-01-06 05:11:07 +03:00
|
|
|
<TintableSvg src="img/upload-big.svg" width="45" height="59"/><br/>
|
2016-01-15 18:23:02 +03:00
|
|
|
Drop file here to upload
|
2015-11-30 20:15:57 +03:00
|
|
|
</div>
|
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
|
2015-12-11 05:58:59 +03:00
|
|
|
var messageComposer, searchInfo;
|
2015-12-18 20:23:46 +03:00
|
|
|
var canSpeak = (
|
|
|
|
// joined and not showing search results
|
|
|
|
myMember && (myMember.membership == 'join') && !this.state.searchResults
|
|
|
|
);
|
|
|
|
if (canSpeak) {
|
2015-11-30 20:15:57 +03:00
|
|
|
messageComposer =
|
2015-12-21 13:59:10 +03:00
|
|
|
<MessageComposer
|
2016-01-11 18:28:59 +03:00
|
|
|
room={this.state.room} onResize={this.onChildResize} uploadFile={this.uploadFile}
|
2015-12-21 13:59:10 +03:00
|
|
|
callState={this.state.callState} tabComplete={this.tabComplete} />
|
2015-11-30 20:15:57 +03:00
|
|
|
}
|
2015-12-18 20:23:46 +03:00
|
|
|
|
|
|
|
// TODO: Why aren't we storing the term/scope/count in this format
|
|
|
|
// in this.state if this is what RoomHeader desires?
|
|
|
|
if (this.state.searchResults) {
|
2015-12-11 05:58:59 +03:00
|
|
|
searchInfo = {
|
|
|
|
searchTerm : this.state.searchTerm,
|
|
|
|
searchScope : this.state.searchScope,
|
2015-12-22 21:15:32 +03:00
|
|
|
searchCount : this.state.searchResults.count,
|
2015-12-18 20:23:46 +03:00
|
|
|
};
|
2015-12-11 05:58:59 +03:00
|
|
|
}
|
2015-11-30 20:15:57 +03:00
|
|
|
|
2015-12-15 02:37:34 +03:00
|
|
|
var call = CallHandler.getCallForRoom(this.props.roomId);
|
2015-12-17 05:49:09 +03:00
|
|
|
//var call = CallHandler.getAnyActiveCall();
|
2015-12-15 02:37:34 +03:00
|
|
|
var inCall = false;
|
2015-12-17 05:49:09 +03:00
|
|
|
if (call && (this.state.callState !== 'ended' && this.state.callState !== 'ringing')) {
|
2015-12-15 02:37:34 +03:00
|
|
|
inCall = true;
|
2015-12-15 03:01:47 +03:00
|
|
|
var zoomButton, voiceMuteButton, videoMuteButton;
|
2015-12-15 02:37:34 +03:00
|
|
|
|
|
|
|
if (call.type === "video") {
|
2015-12-15 03:01:47 +03:00
|
|
|
zoomButton = (
|
2016-01-04 01:34:56 +03:00
|
|
|
<div className="mx_RoomView_voipButton" onClick={this.onFullscreenClick} title="Fill screen">
|
2016-01-06 05:11:07 +03:00
|
|
|
<TintableSvg src="img/fullscreen.svg" width="29" height="22" style={{ marginTop: 1, marginRight: 4 }}/>
|
2015-12-15 03:01:47 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2015-12-15 02:37:34 +03:00
|
|
|
videoMuteButton =
|
2015-12-15 03:01:47 +03:00
|
|
|
<div className="mx_RoomView_voipButton" onClick={this.onMuteVideoClick}>
|
2016-01-04 01:30:52 +03:00
|
|
|
<img src={call.isLocalVideoMuted() ? "img/video-unmute.svg" : "img/video-mute.svg"}
|
|
|
|
alt={call.isLocalVideoMuted() ? "Click to unmute video" : "Click to mute video"}
|
|
|
|
width="31" height="27"/>
|
2015-12-15 02:37:34 +03:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
voiceMuteButton =
|
2015-12-15 03:01:47 +03:00
|
|
|
<div className="mx_RoomView_voipButton" onClick={this.onMuteAudioClick}>
|
2016-01-04 01:30:52 +03:00
|
|
|
<img src={call.isMicrophoneMuted() ? "img/voice-unmute.svg" : "img/voice-mute.svg"}
|
|
|
|
alt={call.isMicrophoneMuted() ? "Click to unmute audio" : "Click to mute audio"}
|
|
|
|
width="21" height="26"/>
|
2015-12-15 02:37:34 +03:00
|
|
|
</div>
|
|
|
|
|
|
|
|
if (!statusBar) {
|
|
|
|
statusBar =
|
|
|
|
<div className="mx_RoomView_callBar">
|
2016-01-04 01:30:52 +03:00
|
|
|
<img src="img/sound-indicator.svg" width="23" height="20"/>
|
2015-12-15 02:37:34 +03:00
|
|
|
<b>Active call</b>
|
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
|
|
|
|
statusBar =
|
|
|
|
<div className="mx_RoomView_callStatusBar">
|
|
|
|
{ voiceMuteButton }
|
|
|
|
{ videoMuteButton }
|
2015-12-15 03:01:47 +03:00
|
|
|
{ zoomButton }
|
2015-12-15 02:37:34 +03:00
|
|
|
{ statusBar }
|
2016-01-06 05:11:07 +03:00
|
|
|
<TintableSvg className="mx_RoomView_voipChevron" src="img/voip-chevron.svg" width="22" height="17"/>
|
2015-12-15 02:37:34 +03:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
|
2015-12-22 18:18:50 +03:00
|
|
|
// if we have search results, we keep the messagepanel (so that it preserves its
|
|
|
|
// scroll state), but hide it.
|
|
|
|
var searchResultsPanel;
|
|
|
|
var hideMessagePanel = false;
|
|
|
|
|
|
|
|
if (this.state.searchResults) {
|
|
|
|
searchResultsPanel = (
|
|
|
|
<ScrollPanel ref="searchResultsPanel" className="mx_RoomView_messagePanel"
|
|
|
|
onFillRequest={ this.onSearchResultsFillRequest }>
|
|
|
|
<li className={scrollheader_classes}></li>
|
|
|
|
{this.getSearchResultTiles()}
|
|
|
|
</ScrollPanel>
|
|
|
|
);
|
|
|
|
hideMessagePanel = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var messagePanel = (
|
|
|
|
<ScrollPanel ref="messagePanel" className="mx_RoomView_messagePanel"
|
|
|
|
onScroll={ this.onMessageListScroll }
|
|
|
|
onFillRequest={ this.onMessageListFillRequest }
|
|
|
|
style={ hideMessagePanel ? { display: 'none' } : {} } >
|
|
|
|
<li className={scrollheader_classes}></li>
|
|
|
|
{this.getEventTiles()}
|
|
|
|
</ScrollPanel>
|
|
|
|
);
|
|
|
|
|
2015-11-30 20:15:57 +03:00
|
|
|
return (
|
2016-01-15 18:23:02 +03:00
|
|
|
<div className={ "mx_RoomView" + (inCall ? " mx_RoomView_inCall" : "") } ref="roomView">
|
2015-12-16 19:06:29 +03:00
|
|
|
<RoomHeader ref="header" room={this.state.room} searchInfo={searchInfo}
|
|
|
|
editing={this.state.editingRoomSettings}
|
|
|
|
onSearchClick={this.onSearchClick}
|
|
|
|
onSettingsClick={this.onSettingsClick}
|
|
|
|
onSaveClick={this.onSaveClick}
|
|
|
|
onCancelClick={this.onCancelClick}
|
|
|
|
onForgetClick={
|
|
|
|
(myMember && myMember.membership === "leave") ? this.onForgetClick : null
|
|
|
|
}
|
|
|
|
onLeaveClick={
|
|
|
|
(myMember && myMember.membership === "join") ? this.onLeaveClick : null
|
|
|
|
} />
|
2016-01-10 16:03:37 +03:00
|
|
|
<div className="mx_RoomView_auxPanel" ref="auxPanel">
|
2016-01-15 18:23:02 +03:00
|
|
|
{ fileDropTarget }
|
2016-01-11 18:28:59 +03:00
|
|
|
<CallView ref="callView" room={this.state.room} ConferenceHandler={this.props.ConferenceHandler}
|
|
|
|
onResize={this.onChildResize} />
|
2015-11-30 20:15:57 +03:00
|
|
|
{ conferenceCallNotification }
|
|
|
|
{ aux }
|
|
|
|
</div>
|
2015-12-22 18:18:50 +03:00
|
|
|
{ messagePanel }
|
|
|
|
{ searchResultsPanel }
|
2015-11-30 20:15:57 +03:00
|
|
|
<div className="mx_RoomView_statusArea">
|
|
|
|
<div className="mx_RoomView_statusAreaBox">
|
|
|
|
<div className="mx_RoomView_statusAreaBox_line"></div>
|
2015-12-15 02:37:34 +03:00
|
|
|
{ statusBar }
|
2015-11-30 20:15:57 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{ messageComposer }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|