2015-11-30 17:15:57 +00:00
|
|
|
/*
|
2016-01-07 04:06:39 +00:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2017-02-17 11:44:56 +00:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2015-11-30 17:15:57 +00: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:
|
|
|
|
// - Search results component
|
|
|
|
// - Drag and drop
|
|
|
|
// - File uploading - uploadFile()
|
|
|
|
|
2017-08-28 12:46:09 +00:00
|
|
|
import shouldHideEvent from "../../shouldHideEvent";
|
|
|
|
|
2015-11-30 17:15:57 +00:00
|
|
|
var React = require("react");
|
|
|
|
var ReactDOM = require("react-dom");
|
2017-07-12 12:58:14 +00:00
|
|
|
import Promise from 'bluebird';
|
2015-11-30 17:15:57 +00:00
|
|
|
var classNames = require("classnames");
|
|
|
|
var Matrix = require("matrix-js-sdk");
|
2017-05-25 10:39:08 +00:00
|
|
|
import { _t } from '../../languageHandler';
|
2015-11-30 17:15:57 +00:00
|
|
|
|
2017-04-22 14:40:29 +00:00
|
|
|
var UserSettingsStore = require('../../UserSettingsStore');
|
2015-11-30 17:15:57 +00:00
|
|
|
var MatrixClientPeg = require("../../MatrixClientPeg");
|
|
|
|
var ContentMessages = require("../../ContentMessages");
|
|
|
|
var Modal = require("../../Modal");
|
|
|
|
var sdk = require('../../index');
|
|
|
|
var CallHandler = require('../../CallHandler');
|
|
|
|
var Resend = require("../../Resend");
|
|
|
|
var dis = require("../../dispatcher");
|
2016-01-08 03:22:38 +00:00
|
|
|
var Tinter = require("../../Tinter");
|
2016-02-04 18:06:24 +00:00
|
|
|
var rate_limited_func = require('../../ratelimitedfunc');
|
2016-03-07 22:27:35 +00:00
|
|
|
var ObjectUtils = require('../../ObjectUtils');
|
2016-09-12 17:32:44 +00:00
|
|
|
var Rooms = require('../../Rooms');
|
2015-11-30 17:15:57 +00:00
|
|
|
|
2016-10-17 13:03:37 +00:00
|
|
|
import KeyCode from '../../KeyCode';
|
|
|
|
|
2016-06-20 08:22:55 +00:00
|
|
|
import UserProvider from '../../autocomplete/UserProvider';
|
|
|
|
|
2017-05-24 15:56:13 +00:00
|
|
|
import RoomViewStore from '../../stores/RoomViewStore';
|
2017-09-07 16:08:36 +00:00
|
|
|
import RoomScrollStateStore from '../../stores/RoomScrollStateStore';
|
2017-05-24 15:56:13 +00:00
|
|
|
|
2017-06-28 11:02:07 +00:00
|
|
|
let DEBUG = false;
|
2017-06-27 16:39:29 +00:00
|
|
|
let debuglog = function() {};
|
2015-11-30 17:15:57 +00:00
|
|
|
|
2017-07-12 09:21:43 +00:00
|
|
|
const BROWSER_SUPPORTS_SANDBOX = 'sandbox' in document.createElement('iframe');
|
|
|
|
|
2016-02-10 18:27:40 +00:00
|
|
|
if (DEBUG) {
|
2016-01-04 16:28:32 +00:00
|
|
|
// using bind means that we get to keep useful line numbers in the console
|
2017-06-27 16:39:29 +00:00
|
|
|
debuglog = console.log.bind(console);
|
2016-01-04 16:28:32 +00:00
|
|
|
}
|
|
|
|
|
2015-11-30 17:15:57 +00:00
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'RoomView',
|
|
|
|
propTypes: {
|
2016-01-18 17:39:23 +00:00
|
|
|
ConferenceHandler: React.PropTypes.any,
|
2016-02-03 15:18:18 +00:00
|
|
|
|
2017-04-28 12:22:55 +00:00
|
|
|
// Called with the credentials of a registered user (if they were a ROU that
|
|
|
|
// transitioned to PWLU)
|
|
|
|
onRegistered: React.PropTypes.func,
|
2016-06-14 11:56:37 +00:00
|
|
|
|
2016-03-17 18:38:25 +00:00
|
|
|
// An object representing a third party invite to join this room
|
|
|
|
// Fields:
|
|
|
|
// * inviteSignUrl (string) The URL used to join this room from an email invite
|
|
|
|
// (given as part of the link in the invite email)
|
|
|
|
// * invitedEmail (string) The email address that was invited to this room
|
|
|
|
thirdPartyInvite: React.PropTypes.object,
|
2016-02-23 10:15:07 +00:00
|
|
|
|
2016-03-01 18:23:57 +00:00
|
|
|
// Any data about the room that would normally come from the Home Server
|
|
|
|
// but has been passed out-of-band, eg. the room name and avatar URL
|
|
|
|
// from an email invite (a workaround for the fact that we can't
|
|
|
|
// get this information from the HS using an email invite).
|
2016-03-02 11:51:47 +00:00
|
|
|
// Fields:
|
|
|
|
// * name (string) The room's name
|
|
|
|
// * avatarUrl (string) The mxc:// avatar URL for the room
|
2016-03-02 14:04:51 +00:00
|
|
|
// * inviterName (string) The display name of the person who
|
|
|
|
// * invited us tovthe room
|
2016-03-01 18:23:57 +00:00
|
|
|
oobData: React.PropTypes.object,
|
|
|
|
|
2016-04-15 17:45:40 +00:00
|
|
|
// is the RightPanel collapsed?
|
2016-09-13 11:18:22 +00:00
|
|
|
collapsedRhs: React.PropTypes.bool,
|
2015-11-30 17:15:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
2016-06-14 13:38:45 +00:00
|
|
|
room: null,
|
|
|
|
roomId: null,
|
|
|
|
roomLoading: true,
|
2017-06-05 08:52:39 +00:00
|
|
|
peekLoading: false,
|
2017-06-16 17:24:07 +00:00
|
|
|
shouldPeek: true,
|
2017-04-21 11:56:59 +00:00
|
|
|
|
2017-06-08 14:37:30 +00:00
|
|
|
// The event to be scrolled to initially
|
2017-06-08 16:26:08 +00:00
|
|
|
initialEventId: null,
|
2017-06-08 14:37:30 +00:00
|
|
|
// The offset in pixels from the event with which to scroll vertically
|
2017-06-08 16:26:08 +00:00
|
|
|
initialEventPixelOffset: null,
|
2017-06-08 14:37:30 +00:00
|
|
|
// Whether to highlight the event scrolled to
|
2017-06-08 16:26:08 +00:00
|
|
|
isInitialEventHighlighted: null,
|
2017-04-21 11:56:59 +00:00
|
|
|
|
2017-05-19 00:29:11 +00:00
|
|
|
forwardingEvent: null,
|
2015-11-30 17:15:57 +00:00
|
|
|
editingRoomSettings: false,
|
|
|
|
uploadingRoomSettings: false,
|
|
|
|
numUnreadMessages: 0,
|
|
|
|
draggingFile: false,
|
|
|
|
searching: false,
|
|
|
|
searchResults: null,
|
2017-02-03 00:40:40 +00:00
|
|
|
unsentMessageError: '',
|
2015-12-14 23:37:34 +00:00
|
|
|
callState: null,
|
2016-01-13 13:22:58 +00:00
|
|
|
guestsCanJoin: false,
|
2016-01-18 17:39:23 +00:00
|
|
|
canPeek: false,
|
2017-05-17 20:15:57 +00:00
|
|
|
showApps: false,
|
2016-02-03 08:03:10 +00:00
|
|
|
|
2016-06-28 16:11:47 +00:00
|
|
|
// error object, as from the matrix client/server API
|
2016-06-28 13:59:45 +00:00
|
|
|
// If we failed to load information about the room,
|
|
|
|
// store the error here.
|
2016-06-24 14:34:07 +00:00
|
|
|
roomLoadError: null,
|
2016-02-03 08:03:10 +00:00
|
|
|
|
|
|
|
// this is true if we are fully scrolled-down, and are looking at
|
|
|
|
// the end of the live timeline. It has the effect of hiding the
|
|
|
|
// 'scroll to bottom' knob, among a couple of other things.
|
|
|
|
atEndOfLiveTimeline: true,
|
2016-02-23 15:46:27 +00:00
|
|
|
|
2016-02-24 17:26:34 +00:00
|
|
|
showTopUnreadMessagesBar: false,
|
|
|
|
|
2016-02-23 15:46:27 +00:00
|
|
|
auxPanelMaxHeight: undefined,
|
2017-01-23 15:01:39 +00:00
|
|
|
|
|
|
|
statusBarVisible: false,
|
2017-01-20 14:22:27 +00:00
|
|
|
};
|
2015-11-30 17:15:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
componentWillMount: function() {
|
2016-07-15 15:14:05 +00:00
|
|
|
this.dispatcherRef = dis.register(this.onAction);
|
|
|
|
MatrixClientPeg.get().on("Room", this.onRoom);
|
|
|
|
MatrixClientPeg.get().on("Room.timeline", this.onRoomTimeline);
|
2017-02-17 11:44:56 +00:00
|
|
|
MatrixClientPeg.get().on("Room.name", this.onRoomName);
|
2016-07-15 15:14:05 +00:00
|
|
|
MatrixClientPeg.get().on("Room.accountData", this.onRoomAccountData);
|
|
|
|
MatrixClientPeg.get().on("RoomState.members", this.onRoomStateMember);
|
2017-02-17 15:50:30 +00:00
|
|
|
MatrixClientPeg.get().on("RoomMember.membership", this.onRoomMemberMembership);
|
2016-07-20 17:14:16 +00:00
|
|
|
MatrixClientPeg.get().on("accountData", this.onAccountData);
|
2016-07-15 15:14:05 +00:00
|
|
|
|
2017-08-28 12:46:09 +00:00
|
|
|
this._syncedSettings = UserSettingsStore.getSyncedSettings();
|
|
|
|
|
2017-05-24 15:56:13 +00:00
|
|
|
// Start listening for RoomViewStore updates
|
2017-06-01 17:01:30 +00:00
|
|
|
this._roomStoreToken = RoomViewStore.addListener(this._onRoomViewStoreUpdate);
|
2017-05-24 15:56:13 +00:00
|
|
|
this._onRoomViewStoreUpdate(true);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onRoomViewStoreUpdate: function(initial) {
|
|
|
|
if (this.unmounted) {
|
|
|
|
return;
|
2016-06-14 10:37:04 +00:00
|
|
|
}
|
2017-09-11 16:57:52 +00:00
|
|
|
|
|
|
|
if (!initial && this.state.roomId !== RoomViewStore.getRoomId()) {
|
|
|
|
// RoomView explicitly does not support changing what room
|
|
|
|
// is being viewed: instead it should just be re-mounted when
|
|
|
|
// switching rooms. Therefore, if the room ID changes, we
|
|
|
|
// ignore this. We either need to do this or add code to handle
|
|
|
|
// saving the scroll position (otherwise we end up saving the
|
2017-09-11 17:39:30 +00:00
|
|
|
// scroll position against the wrong room).
|
|
|
|
|
|
|
|
// Given that doing the setState here would cause a bunch of
|
|
|
|
// unnecessary work, we just ignore the change since we know
|
|
|
|
// that if the current room ID has changed from what we thought
|
|
|
|
// it was, it means we're about to be unmounted.
|
2017-09-11 16:57:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-08 13:17:49 +00:00
|
|
|
const newState = {
|
2017-05-24 15:56:13 +00:00
|
|
|
roomId: RoomViewStore.getRoomId(),
|
|
|
|
roomAlias: RoomViewStore.getRoomAlias(),
|
2017-06-01 17:01:30 +00:00
|
|
|
roomLoading: RoomViewStore.isRoomLoading(),
|
|
|
|
roomLoadError: RoomViewStore.getRoomLoadError(),
|
2017-05-24 15:56:13 +00:00
|
|
|
joining: RoomViewStore.isJoining(),
|
2017-06-08 14:47:41 +00:00
|
|
|
initialEventId: RoomViewStore.getInitialEventId(),
|
|
|
|
isInitialEventHighlighted: RoomViewStore.isInitialEventHighlighted(),
|
2017-06-16 15:12:52 +00:00
|
|
|
forwardingEvent: RoomViewStore.getForwardingEvent(),
|
2017-06-16 17:24:07 +00:00
|
|
|
shouldPeek: RoomViewStore.shouldPeek(),
|
2017-06-08 13:17:49 +00:00
|
|
|
};
|
|
|
|
|
2017-06-16 17:24:07 +00:00
|
|
|
// finished joining, start waiting for a room and show a spinner. See onRoom.
|
|
|
|
newState.waitingForRoom = this.state.joining && !newState.joining &&
|
|
|
|
!RoomViewStore.getJoinError();
|
|
|
|
|
2017-06-14 15:53:21 +00:00
|
|
|
// Temporary logging to diagnose https://github.com/vector-im/riot-web/issues/4307
|
|
|
|
console.log(
|
|
|
|
'RVS update:',
|
|
|
|
newState.roomId,
|
|
|
|
newState.roomAlias,
|
|
|
|
'loading?', newState.roomLoading,
|
|
|
|
'joining?', newState.joining,
|
2017-06-16 17:24:07 +00:00
|
|
|
'initial?', initial,
|
|
|
|
'waiting?', newState.waitingForRoom,
|
|
|
|
'shouldPeek?', newState.shouldPeek,
|
2017-06-14 15:53:21 +00:00
|
|
|
);
|
|
|
|
|
2017-06-14 15:48:34 +00:00
|
|
|
// NB: This does assume that the roomID will not change for the lifetime of
|
|
|
|
// the RoomView instance
|
|
|
|
if (initial) {
|
|
|
|
newState.room = MatrixClientPeg.get().getRoom(newState.roomId);
|
2017-09-08 17:11:13 +00:00
|
|
|
if (newState.room) {
|
|
|
|
newState.unsentMessageError = this._getUnsentMessageError(newState.room);
|
|
|
|
newState.showApps = this._shouldShowApps(newState.room);
|
|
|
|
this._onRoomLoaded(newState.room);
|
|
|
|
}
|
2017-06-14 15:48:34 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 12:39:22 +00:00
|
|
|
if (this.state.roomId === null && newState.roomId !== null) {
|
|
|
|
// Get the scroll state for the new room
|
2017-09-07 16:08:36 +00:00
|
|
|
|
|
|
|
// If an event ID wasn't specified, default to the one saved for this room
|
2017-09-07 16:16:32 +00:00
|
|
|
// in the scroll state store. Assume initialEventPixelOffset should be set.
|
2017-09-07 16:08:36 +00:00
|
|
|
if (!newState.initialEventId) {
|
|
|
|
const roomScrollState = RoomScrollStateStore.getScrollState(newState.roomId);
|
|
|
|
if (roomScrollState) {
|
|
|
|
newState.initialEventId = roomScrollState.focussedEvent;
|
|
|
|
newState.initialEventPixelOffset = roomScrollState.pixelOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-08 14:38:58 +00:00
|
|
|
// Clear the search results when clicking a search result (which changes the
|
2017-06-08 14:47:41 +00:00
|
|
|
// currently scrolled to event, this.state.initialEventId).
|
|
|
|
if (this.state.initialEventId !== newState.initialEventId) {
|
2017-06-08 13:17:49 +00:00
|
|
|
newState.searchResults = null;
|
|
|
|
}
|
|
|
|
|
2017-09-08 16:06:46 +00:00
|
|
|
this.setState(newState);
|
|
|
|
// At this point, newState.roomId could be null (e.g. the alias might not
|
|
|
|
// have been resolved yet) so anything called here must handle this case.
|
2017-09-08 16:39:10 +00:00
|
|
|
|
2017-09-08 16:06:46 +00:00
|
|
|
// We pass the new state into this function for it to read: it needs to
|
|
|
|
// observe the new state but we don't want to put it in the setState
|
|
|
|
// callback because this would prevent the setStates from being batched,
|
|
|
|
// ie. cause it to render RoomView twice rather than the once that is necessary.
|
|
|
|
if (initial) {
|
2017-09-08 17:11:13 +00:00
|
|
|
this._setupRoom(newState.room, newState.roomId, newState.joining, newState.shouldPeek);
|
2017-09-08 16:06:46 +00:00
|
|
|
}
|
2016-06-14 10:37:04 +00:00
|
|
|
},
|
|
|
|
|
2017-09-08 17:11:13 +00:00
|
|
|
_setupRoom: function(room, roomId, joining, shouldPeek) {
|
2016-01-07 16:22:17 +00: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-06-14 10:37:04 +00:00
|
|
|
// Note that peeking works by room ID and room ID only, as opposed to joining
|
|
|
|
// which must be by alias or invite wherever possible (peeking currently does
|
|
|
|
// not work over federation).
|
2016-01-27 07:54:15 +00:00
|
|
|
|
2017-06-15 10:49:16 +00:00
|
|
|
// NB. We peek if we have never seen the room before (i.e. js-sdk does not know
|
|
|
|
// about it). We don't peek in the historical case where we were joined but are
|
|
|
|
// now not joined because the js-sdk peeking API will clobber our historical room,
|
|
|
|
// making it impossible to indicate a newly joined room.
|
2017-09-08 16:56:53 +00:00
|
|
|
if (!joining && roomId) {
|
2016-06-20 15:30:51 +00:00
|
|
|
if (this.props.autoJoin) {
|
|
|
|
this.onJoinButtonClicked();
|
2017-09-08 16:56:53 +00:00
|
|
|
} else if (!room && shouldPeek) {
|
|
|
|
console.log("Attempting to peek into room %s", roomId);
|
2017-06-05 08:52:39 +00:00
|
|
|
this.setState({
|
|
|
|
peekLoading: true,
|
|
|
|
});
|
2017-09-08 16:56:53 +00:00
|
|
|
MatrixClientPeg.get().peekInRoom(roomId).then((room) => {
|
2016-02-10 18:27:40 +00:00
|
|
|
this.setState({
|
2016-06-20 15:30:51 +00:00
|
|
|
room: room,
|
2017-06-05 08:52:39 +00:00
|
|
|
peekLoading: false,
|
2016-02-10 18:27:40 +00:00
|
|
|
});
|
2016-06-20 15:30:51 +00:00
|
|
|
this._onRoomLoaded(room);
|
|
|
|
}, (err) => {
|
|
|
|
// This won't necessarily be a MatrixError, but we duck-type
|
|
|
|
// here and say if it's got an 'errcode' key with the right value,
|
|
|
|
// it means we can't peek.
|
|
|
|
if (err.errcode == "M_GUEST_ACCESS_FORBIDDEN") {
|
|
|
|
// This is fine: the room just isn't peekable (we assume).
|
|
|
|
this.setState({
|
2017-06-05 08:52:39 +00:00
|
|
|
peekLoading: false,
|
2016-06-20 15:30:51 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}).done();
|
|
|
|
}
|
2017-06-15 13:21:23 +00:00
|
|
|
} else if (room) {
|
|
|
|
// Stop peeking because we have joined this room previously
|
2016-03-18 19:23:30 +00:00
|
|
|
MatrixClientPeg.get().stopPeeking();
|
2016-02-10 18:27:40 +00:00
|
|
|
}
|
2015-11-30 17:15:57 +00:00
|
|
|
},
|
|
|
|
|
2017-06-13 13:19:06 +00:00
|
|
|
_shouldShowApps: function(room) {
|
2017-07-12 09:21:43 +00:00
|
|
|
if (!BROWSER_SUPPORTS_SANDBOX) return false;
|
|
|
|
|
2017-07-11 11:15:27 +00:00
|
|
|
const appsStateEvents = room.currentState.getStateEvents('im.vector.modular.widgets');
|
|
|
|
// any valid widget = show apps
|
|
|
|
for (let i = 0; i < appsStateEvents.length; i++) {
|
|
|
|
if (appsStateEvents[i].getContent().type && appsStateEvents[i].getContent().url) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2017-06-13 13:19:06 +00:00
|
|
|
},
|
|
|
|
|
2016-10-17 13:03:37 +00:00
|
|
|
componentDidMount: function() {
|
|
|
|
var call = this._getCallForRoom();
|
|
|
|
var callState = call ? call.call_state : "ended";
|
|
|
|
this.setState({
|
|
|
|
callState: callState
|
|
|
|
});
|
|
|
|
|
|
|
|
this._updateConfCallNotification();
|
|
|
|
|
2017-04-29 05:25:30 +00:00
|
|
|
window.addEventListener('beforeunload', this.onPageUnload);
|
2016-10-17 13:03:37 +00:00
|
|
|
window.addEventListener('resize', this.onResize);
|
|
|
|
this.onResize();
|
|
|
|
|
|
|
|
document.addEventListener("keydown", this.onKeyDown);
|
|
|
|
|
|
|
|
// 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 &&
|
|
|
|
this.state.room.getLiveTimeline() &&
|
|
|
|
this.state.room.getLiveTimeline().getEvents() &&
|
|
|
|
this.state.room.getLiveTimeline().getEvents().length <= 6)
|
|
|
|
{
|
|
|
|
var inviteBox = document.getElementById("mx_SearchableEntityList_query");
|
|
|
|
setTimeout(function() {
|
|
|
|
if (inviteBox) {
|
|
|
|
inviteBox.focus();
|
|
|
|
}
|
|
|
|
}, 50);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-03-07 22:27:35 +00:00
|
|
|
shouldComponentUpdate: function(nextProps, nextState) {
|
|
|
|
return (!ObjectUtils.shallowEqual(this.props, nextProps) ||
|
|
|
|
!ObjectUtils.shallowEqual(this.state, nextState));
|
|
|
|
},
|
|
|
|
|
2016-10-17 13:03:37 +00:00
|
|
|
componentDidUpdate: function() {
|
|
|
|
if (this.refs.roomView) {
|
|
|
|
var roomView = ReactDOM.findDOMNode(this.refs.roomView);
|
|
|
|
if (!roomView.ondrop) {
|
|
|
|
roomView.addEventListener('drop', this.onDrop);
|
|
|
|
roomView.addEventListener('dragover', this.onDragOver);
|
|
|
|
roomView.addEventListener('dragleave', this.onDragLeaveOrEnd);
|
|
|
|
roomView.addEventListener('dragend', this.onDragLeaveOrEnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-30 17:15:57 +00:00
|
|
|
componentWillUnmount: function() {
|
2016-01-11 11:38:04 +00: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-11-04 09:28:35 +00:00
|
|
|
// update the scroll map before we get unmounted
|
2017-09-08 12:39:22 +00:00
|
|
|
if (this.state.roomId) {
|
|
|
|
RoomScrollStateStore.setScrollState(this.state.roomId, this._getScrollState());
|
|
|
|
}
|
2016-11-04 09:28:35 +00:00
|
|
|
|
2016-01-15 15:23:02 +00: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 10:19:07 +00:00
|
|
|
// deleted anyway, so it doesn't matter if the event listeners
|
|
|
|
// don't get cleaned up.
|
2016-01-15 15:23:02 +00: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 17:15:57 +00:00
|
|
|
}
|
|
|
|
dis.unregister(this.dispatcherRef);
|
|
|
|
if (MatrixClientPeg.get()) {
|
2016-02-04 13:06:59 +00:00
|
|
|
MatrixClientPeg.get().removeListener("Room", this.onRoom);
|
2015-11-30 17:15:57 +00:00
|
|
|
MatrixClientPeg.get().removeListener("Room.timeline", this.onRoomTimeline);
|
2017-02-17 11:44:56 +00:00
|
|
|
MatrixClientPeg.get().removeListener("Room.name", this.onRoomName);
|
2016-01-08 03:22:38 +00:00
|
|
|
MatrixClientPeg.get().removeListener("Room.accountData", this.onRoomAccountData);
|
2015-11-30 17:15:57 +00:00
|
|
|
MatrixClientPeg.get().removeListener("RoomState.members", this.onRoomStateMember);
|
2017-02-17 15:50:30 +00:00
|
|
|
MatrixClientPeg.get().removeListener("RoomMember.membership", this.onRoomMemberMembership);
|
2016-07-21 12:49:31 +00:00
|
|
|
MatrixClientPeg.get().removeListener("accountData", this.onAccountData);
|
2015-11-30 17:15:57 +00:00
|
|
|
}
|
2015-12-13 04:32:48 +00:00
|
|
|
|
2017-04-29 05:25:30 +00:00
|
|
|
window.removeEventListener('beforeunload', this.onPageUnload);
|
2016-04-22 16:05:48 +00:00
|
|
|
window.removeEventListener('resize', this.onResize);
|
2016-01-08 03:22:38 +00:00
|
|
|
|
2016-10-17 13:03:37 +00:00
|
|
|
document.removeEventListener("keydown", this.onKeyDown);
|
|
|
|
|
2017-06-01 17:01:30 +00:00
|
|
|
// Remove RoomStore listener
|
|
|
|
if (this._roomStoreToken) {
|
|
|
|
this._roomStoreToken.remove();
|
|
|
|
}
|
|
|
|
|
2016-08-10 12:39:47 +00:00
|
|
|
// cancel any pending calls to the rate_limited_funcs
|
|
|
|
this._updateRoomMembers.cancelPendingCall();
|
|
|
|
|
2016-04-16 00:00:10 +00:00
|
|
|
// no need to do this as Dir & Settings are now overlays. It just burnt CPU.
|
|
|
|
// console.log("Tinter.tint from RoomView.unmount");
|
|
|
|
// Tinter.tint(); // reset colourscheme
|
2015-11-30 17:15:57 +00:00
|
|
|
},
|
|
|
|
|
2017-04-29 05:25:30 +00:00
|
|
|
onPageUnload(event) {
|
|
|
|
if (ContentMessages.getCurrentUploads().length > 0) {
|
|
|
|
return event.returnValue =
|
2017-05-23 14:16:31 +00:00
|
|
|
_t("You seem to be uploading files, are you sure you want to quit?");
|
2017-05-03 15:36:57 +00:00
|
|
|
} else if (this._getCallForRoom() && this.state.callState !== 'ended') {
|
|
|
|
return event.returnValue =
|
2017-05-23 14:16:31 +00:00
|
|
|
_t("You seem to be in a call, are you sure you want to quit?");
|
2017-04-29 05:25:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2016-10-17 13:03:37 +00:00
|
|
|
onKeyDown: function(ev) {
|
2016-11-08 18:04:22 +00:00
|
|
|
let handled = false;
|
|
|
|
const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0;
|
|
|
|
let ctrlCmdOnly;
|
|
|
|
if (isMac) {
|
|
|
|
ctrlCmdOnly = ev.metaKey && !ev.altKey && !ev.ctrlKey && !ev.shiftKey;
|
|
|
|
} else {
|
|
|
|
ctrlCmdOnly = ev.ctrlKey && !ev.altKey && !ev.metaKey && !ev.shiftKey;
|
|
|
|
}
|
2016-10-17 13:03:37 +00:00
|
|
|
|
|
|
|
switch (ev.keyCode) {
|
|
|
|
case KeyCode.KEY_D:
|
2016-11-08 18:04:22 +00:00
|
|
|
if (ctrlCmdOnly) {
|
2016-10-17 13:03:37 +00:00
|
|
|
this.onMuteAudioClick();
|
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KeyCode.KEY_E:
|
2016-11-08 18:04:22 +00:00
|
|
|
if (ctrlCmdOnly) {
|
2016-10-17 13:03:37 +00:00
|
|
|
this.onMuteVideoClick();
|
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handled) {
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-30 17:15:57 +00:00
|
|
|
onAction: function(payload) {
|
|
|
|
switch (payload.action) {
|
|
|
|
case 'message_send_failed':
|
|
|
|
case 'message_sent':
|
2016-03-21 16:49:07 +00:00
|
|
|
case 'message_send_cancelled':
|
2015-11-30 17:15:57 +00:00
|
|
|
this.setState({
|
2017-02-03 00:40:40 +00:00
|
|
|
unsentMessageError: this._getUnsentMessageError(this.state.room),
|
2015-11-30 17:15:57 +00:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'notifier_enabled':
|
2015-12-02 18:16:16 +00:00
|
|
|
case 'upload_failed':
|
|
|
|
case 'upload_started':
|
|
|
|
case 'upload_finished':
|
2015-11-30 17:15:57 +00:00
|
|
|
this.forceUpdate();
|
|
|
|
break;
|
|
|
|
case 'call_state':
|
2015-12-14 23:37:34 +00: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;
|
|
|
|
}
|
|
|
|
|
2016-04-12 18:25:07 +00:00
|
|
|
var call = this._getCallForRoom();
|
2015-12-14 23:37:34 +00:00
|
|
|
var callState;
|
|
|
|
|
|
|
|
if (call) {
|
|
|
|
callState = call.call_state;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
callState = "ended";
|
2015-11-30 17:15:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// possibly remove the conf call notification if we're now in
|
|
|
|
// the conf
|
|
|
|
this._updateConfCallNotification();
|
2015-12-14 23:37:34 +00:00
|
|
|
|
|
|
|
this.setState({
|
2017-05-17 20:15:57 +00:00
|
|
|
callState: callState,
|
2015-12-14 23:37:34 +00:00
|
|
|
});
|
|
|
|
|
2017-05-17 20:15:57 +00:00
|
|
|
break;
|
|
|
|
case 'appsDrawer':
|
|
|
|
this.setState({
|
2017-06-28 11:21:05 +00:00
|
|
|
showApps: payload.show,
|
2017-05-17 20:15:57 +00:00
|
|
|
});
|
2015-11-30 17:15:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-01-27 07:54:15 +00:00
|
|
|
onRoomTimeline: function(ev, room, toStartOfTimeline, removed, data) {
|
2016-01-11 11:38:04 +00:00
|
|
|
if (this.unmounted) return;
|
2015-11-30 17:15:57 +00:00
|
|
|
|
2016-01-27 07:54:15 +00:00
|
|
|
// ignore events for other rooms
|
2016-09-09 01:09:12 +00:00
|
|
|
if (!room) return;
|
2016-04-12 18:25:07 +00:00
|
|
|
if (!this.state.room || room.roomId != this.state.room.roomId) return;
|
2016-01-27 07:54:15 +00:00
|
|
|
|
2016-09-08 21:48:44 +00:00
|
|
|
// ignore events from filtered timelines
|
|
|
|
if (data.timeline.getTimelineSet() !== room.getUnfilteredTimelineSet()) return;
|
|
|
|
|
2016-07-18 09:47:03 +00:00
|
|
|
if (ev.getType() === "org.matrix.room.preview_urls") {
|
|
|
|
this._updatePreviewUrlVisibility(room);
|
2016-07-18 00:35:42 +00:00
|
|
|
}
|
|
|
|
|
2016-01-27 07:54:15 +00:00
|
|
|
// ignore anything but real-time updates at the end of the room:
|
|
|
|
// updates from pagination will happen when the paginate completes.
|
|
|
|
if (toStartOfTimeline || !data || !data.liveEvent) return;
|
2015-11-30 17:15:57 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2016-01-27 07:54:15 +00:00
|
|
|
if (ev.getSender() !== MatrixClientPeg.get().credentials.userId) {
|
2015-11-30 17:15:57 +00:00
|
|
|
// update unread count when scrolled up
|
2016-02-03 08:03:10 +00:00
|
|
|
if (!this.state.searchResults && this.state.atEndOfLiveTimeline) {
|
2016-01-27 07:54:15 +00:00
|
|
|
// no change
|
2017-08-28 12:46:09 +00:00
|
|
|
} else if (!shouldHideEvent(ev, this._syncedSettings)) {
|
2016-04-18 00:34:45 +00:00
|
|
|
this.setState((state, props) => {
|
2016-01-27 07:54:15 +00:00
|
|
|
return {numUnreadMessages: state.numUnreadMessages + 1};
|
|
|
|
});
|
2015-11-30 17:15:57 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-14 13:06:31 +00:00
|
|
|
|
2016-07-15 17:10:56 +00:00
|
|
|
// update the tab complete list as it depends on who most recently spoke,
|
2016-07-14 13:06:31 +00:00
|
|
|
// and that has probably just changed
|
2016-07-15 15:10:27 +00:00
|
|
|
if (ev.sender) {
|
2017-02-10 17:04:52 +00:00
|
|
|
UserProvider.getInstance().onUserSpoke(ev.sender);
|
2016-07-15 15:10:27 +00:00
|
|
|
}
|
2016-01-18 20:05:33 +00:00
|
|
|
},
|
2016-01-18 19:56:35 +00:00
|
|
|
|
2017-02-17 11:44:56 +00:00
|
|
|
onRoomName: function(room) {
|
|
|
|
if (this.state.room && room.roomId == this.state.room.roomId) {
|
|
|
|
this.forceUpdate();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-03-22 15:06:52 +00:00
|
|
|
canResetTimeline: function() {
|
|
|
|
if (!this.refs.messagePanel) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this.refs.messagePanel.canResetTimeline();
|
|
|
|
},
|
|
|
|
|
2016-02-10 18:27:40 +00:00
|
|
|
// called when state.room is first initialised (either at initial load,
|
|
|
|
// after a successful peek, or after we join the room).
|
|
|
|
_onRoomLoaded: function(room) {
|
2017-03-01 15:41:13 +00:00
|
|
|
this._warnAboutEncryption(room);
|
2016-02-10 18:27:40 +00:00
|
|
|
this._calculatePeekRules(room);
|
2016-07-20 11:03:13 +00:00
|
|
|
this._updatePreviewUrlVisibility(room);
|
2017-06-23 16:52:50 +00:00
|
|
|
UserProvider.getInstance().setUserListFromRoom(room);
|
2016-02-16 16:05:27 +00:00
|
|
|
},
|
|
|
|
|
2017-05-24 15:56:13 +00:00
|
|
|
_warnAboutEncryption: function(room) {
|
2017-03-01 15:41:13 +00:00
|
|
|
if (!MatrixClientPeg.get().isRoomEncrypted(room.roomId)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let userHasUsedEncryption = false;
|
|
|
|
if (localStorage) {
|
|
|
|
userHasUsedEncryption = localStorage.getItem('mx_user_has_used_encryption');
|
|
|
|
}
|
|
|
|
if (!userHasUsedEncryption) {
|
2017-03-01 15:55:15 +00:00
|
|
|
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
2017-07-27 16:19:18 +00:00
|
|
|
Modal.createTrackedDialog('E2E Warning', '', QuestionDialog, {
|
2017-05-25 17:20:48 +00:00
|
|
|
title: _t("Warning!"),
|
2017-03-01 15:41:13 +00:00
|
|
|
hasCancelButton: false,
|
|
|
|
description: (
|
|
|
|
<div>
|
2017-05-23 14:16:31 +00:00
|
|
|
<p>{ _t("End-to-end encryption is in beta and may not be reliable") }.</p>
|
2017-05-25 19:04:28 +00:00
|
|
|
<p>{ _t("You should not yet trust it to secure data") }.</p>
|
|
|
|
<p>{ _t("Devices will not yet be able to decrypt history from before they joined the room") }.</p>
|
2017-05-23 14:16:31 +00:00
|
|
|
<p>{ _t("Encrypted messages will not be visible on clients that do not yet implement encryption") }.</p>
|
2017-03-01 15:41:13 +00:00
|
|
|
</div>
|
|
|
|
),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (localStorage) {
|
|
|
|
localStorage.setItem('mx_user_has_used_encryption', true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-01-18 20:05:33 +00: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 17:39:23 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-07-18 00:35:42 +00:00
|
|
|
_updatePreviewUrlVisibility: function(room) {
|
2016-07-20 17:17:09 +00:00
|
|
|
// console.log("_updatePreviewUrlVisibility");
|
2016-07-20 11:03:13 +00:00
|
|
|
|
2016-07-18 00:35:42 +00:00
|
|
|
// check our per-room overrides
|
|
|
|
var roomPreviewUrls = room.getAccountData("org.matrix.room.preview_urls");
|
2016-07-20 11:03:13 +00:00
|
|
|
if (roomPreviewUrls && roomPreviewUrls.getContent().disable !== undefined) {
|
2016-07-18 00:35:42 +00:00
|
|
|
this.setState({
|
2016-07-20 11:03:13 +00:00
|
|
|
showUrlPreview: !roomPreviewUrls.getContent().disable
|
2016-07-18 00:35:42 +00:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check our global disable override
|
2016-07-20 11:03:13 +00:00
|
|
|
var userRoomPreviewUrls = MatrixClientPeg.get().getAccountData("org.matrix.preview_urls");
|
|
|
|
if (userRoomPreviewUrls && userRoomPreviewUrls.getContent().disable) {
|
2016-07-18 00:35:42 +00:00
|
|
|
this.setState({
|
|
|
|
showUrlPreview: false
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check the room state event
|
|
|
|
var roomStatePreviewUrls = room.currentState.getStateEvents('org.matrix.room.preview_urls', '');
|
2016-07-20 11:03:13 +00:00
|
|
|
if (roomStatePreviewUrls && roomStatePreviewUrls.getContent().disable) {
|
2016-07-18 00:35:42 +00:00
|
|
|
this.setState({
|
2016-07-18 00:39:24 +00:00
|
|
|
showUrlPreview: false
|
2016-07-18 00:35:42 +00:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise, we assume they're on.
|
|
|
|
this.setState({
|
2016-07-18 00:39:24 +00:00
|
|
|
showUrlPreview: true
|
2016-07-18 00:35:42 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-02-04 11:29:00 +00:00
|
|
|
onRoom: function(room) {
|
2017-05-24 15:56:13 +00:00
|
|
|
if (!room || room.roomId !== this.state.roomId) {
|
|
|
|
return;
|
2016-02-04 11:29:00 +00:00
|
|
|
}
|
2017-05-24 15:56:13 +00:00
|
|
|
this.setState({
|
|
|
|
room: room,
|
2017-06-15 10:49:16 +00:00
|
|
|
waitingForRoom: false,
|
2017-05-24 15:56:13 +00:00
|
|
|
}, () => {
|
|
|
|
this._onRoomLoaded(room);
|
|
|
|
});
|
2016-02-04 11:29:00 +00:00
|
|
|
},
|
|
|
|
|
2016-01-08 03:22:38 +00:00
|
|
|
updateTint: function() {
|
2016-04-12 18:25:07 +00:00
|
|
|
var room = this.state.room;
|
2016-01-08 03:22:38 +00:00
|
|
|
if (!room) return;
|
|
|
|
|
2016-01-13 13:15:13 +00:00
|
|
|
var color_scheme_event = room.getAccountData("org.matrix.room.color_scheme");
|
2016-01-08 03:22:38 +00:00
|
|
|
var color_scheme = {};
|
|
|
|
if (color_scheme_event) {
|
|
|
|
color_scheme = color_scheme_event.getContent();
|
|
|
|
// XXX: we should validate the event
|
2016-04-16 00:00:10 +00:00
|
|
|
}
|
|
|
|
console.log("Tinter.tint from updateTint");
|
2016-01-08 03:22:38 +00:00
|
|
|
Tinter.tint(color_scheme.primary_color, color_scheme.secondary_color);
|
|
|
|
},
|
|
|
|
|
2016-07-20 17:14:16 +00:00
|
|
|
onAccountData: function(event) {
|
|
|
|
if (event.getType() === "org.matrix.preview_urls" && this.state.room) {
|
|
|
|
this._updatePreviewUrlVisibility(this.state.room);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-07-20 11:03:13 +00:00
|
|
|
onRoomAccountData: function(event, room) {
|
|
|
|
if (room.roomId == this.state.roomId) {
|
2016-07-18 00:35:42 +00:00
|
|
|
if (event.getType() === "org.matrix.room.color_scheme") {
|
2016-01-08 03:22:38 +00:00
|
|
|
var color_scheme = event.getContent();
|
|
|
|
// XXX: we should validate the event
|
2016-04-16 00:00:10 +00:00
|
|
|
console.log("Tinter.tint from onRoomAccountData");
|
2016-01-08 03:22:38 +00:00
|
|
|
Tinter.tint(color_scheme.primary_color, color_scheme.secondary_color);
|
|
|
|
}
|
2016-07-18 00:35:42 +00:00
|
|
|
else if (event.getType() === "org.matrix.room.preview_urls") {
|
2016-07-20 11:03:13 +00:00
|
|
|
this._updatePreviewUrlVisibility(room);
|
2016-07-18 00:35:42 +00:00
|
|
|
}
|
2016-01-08 03:22:38 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-07-26 17:15:26 +00:00
|
|
|
onRoomStateMember: function(ev, state, member) {
|
2016-04-12 18:25:07 +00:00
|
|
|
// ignore if we don't have a room yet
|
|
|
|
if (!this.state.room) {
|
|
|
|
return;
|
2015-12-22 15:38:23 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 18:25:07 +00:00
|
|
|
// ignore members in other rooms
|
|
|
|
if (member.roomId !== this.state.room.roomId) {
|
2015-11-30 17:15:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-04-12 18:25:07 +00:00
|
|
|
|
2016-07-26 17:15:26 +00:00
|
|
|
this._updateRoomMembers();
|
|
|
|
},
|
|
|
|
|
2017-02-17 15:50:30 +00:00
|
|
|
onRoomMemberMembership: function(ev, member, oldMembership) {
|
|
|
|
if (member.userId == MatrixClientPeg.get().credentials.userId) {
|
2017-06-15 10:49:16 +00:00
|
|
|
|
|
|
|
if (member.membership === 'join') {
|
|
|
|
this.setState({
|
|
|
|
waitingForRoom: false,
|
|
|
|
});
|
2017-06-15 12:32:56 +00:00
|
|
|
} else {
|
|
|
|
this.forceUpdate();
|
2017-06-15 10:49:16 +00:00
|
|
|
}
|
2017-02-17 15:50:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-07-26 17:19:25 +00:00
|
|
|
// rate limited because a power level change will emit an event for every
|
|
|
|
// member in the room.
|
2016-07-26 17:15:26 +00:00
|
|
|
_updateRoomMembers: new rate_limited_func(function() {
|
2016-10-26 12:09:53 +00:00
|
|
|
// a member state changed in this room
|
2016-10-26 14:32:09 +00:00
|
|
|
// refresh the conf call notification state
|
2016-10-26 12:09:53 +00:00
|
|
|
this._updateConfCallNotification();
|
|
|
|
|
|
|
|
// refresh the tab complete list
|
2017-02-10 17:04:52 +00:00
|
|
|
UserProvider.getInstance().setUserListFromRoom(this.state.room);
|
2016-04-12 18:25:07 +00:00
|
|
|
|
|
|
|
// if we are now a member of the room, where we were not before, that
|
|
|
|
// means we have finished joining a room we were previously peeking
|
|
|
|
// into.
|
|
|
|
var me = MatrixClientPeg.get().credentials.userId;
|
|
|
|
if (this.state.joining && this.state.room.hasMembershipState(me, "join")) {
|
2016-09-20 16:59:46 +00:00
|
|
|
// Having just joined a room, check to see if it looks like a DM room, and if so,
|
|
|
|
// mark it as one. This is to work around the fact that some clients don't support
|
|
|
|
// is_direct. We should remove this once they do.
|
|
|
|
const me = this.state.room.getMember(MatrixClientPeg.get().credentials.userId);
|
|
|
|
if (Rooms.looksLikeDirectMessageRoom(this.state.room, me)) {
|
|
|
|
// XXX: There's not a whole lot we can really do if this fails: at best
|
|
|
|
// perhaps we could try a couple more times, but since it's a temporary
|
|
|
|
// compatability workaround, let's not bother.
|
|
|
|
Rooms.setDMRoom(this.state.room.roomId, me.events.member.getSender()).done();
|
|
|
|
}
|
2016-04-12 18:25:07 +00:00
|
|
|
}
|
2016-07-26 16:58:19 +00:00
|
|
|
}, 500),
|
2015-11-30 17:15:57 +00:00
|
|
|
|
2017-02-03 00:40:40 +00:00
|
|
|
_getUnsentMessageError: function(room) {
|
|
|
|
const unsentMessages = this._getUnsentMessages(room);
|
|
|
|
if (!unsentMessages.length) return "";
|
|
|
|
for (const event of unsentMessages) {
|
|
|
|
if (!event.error || event.error.name !== "UnknownDeviceError") {
|
2017-06-07 10:40:46 +00:00
|
|
|
return _t("Some of your messages have not been sent.");
|
2017-02-03 00:40:40 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-23 14:16:31 +00:00
|
|
|
return _t("Message not sent due to unknown devices being present");
|
2015-11-30 17:15:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_getUnsentMessages: function(room) {
|
|
|
|
if (!room) { return []; }
|
2016-03-17 22:26:06 +00:00
|
|
|
return room.getPendingEvents().filter(function(ev) {
|
2015-11-30 17:15:57 +00:00
|
|
|
return ev.status === Matrix.EventStatus.NOT_SENT;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateConfCallNotification: function() {
|
2016-04-12 18:25:07 +00:00
|
|
|
var room = this.state.room;
|
2015-11-30 17:15:57 +00:00
|
|
|
if (!room || !this.props.ConferenceHandler) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var confMember = room.getMember(
|
2016-04-12 18:25:07 +00:00
|
|
|
this.props.ConferenceHandler.getConferenceUserIdForRoom(room.roomId)
|
2015-11-30 17:15:57 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
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"
|
|
|
|
)
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-03-24 00:13:32 +00:00
|
|
|
onSearchResultsResize: function() {
|
2016-03-24 02:14:16 +00:00
|
|
|
dis.dispatch({ action: 'timeline_resize' }, true);
|
2016-03-24 00:13:32 +00:00
|
|
|
},
|
|
|
|
|
2015-12-22 15:18:50 +00:00
|
|
|
onSearchResultsFillRequest: function(backwards) {
|
2017-01-20 14:22:27 +00:00
|
|
|
if (!backwards) {
|
2017-07-12 13:02:00 +00:00
|
|
|
return Promise.resolve(false);
|
2017-01-20 14:22:27 +00:00
|
|
|
}
|
2015-11-30 17:15:57 +00:00
|
|
|
|
2015-12-22 18:15:32 +00:00
|
|
|
if (this.state.searchResults.next_batch) {
|
2016-01-04 16:28:32 +00:00
|
|
|
debuglog("requesting more search results");
|
2016-01-05 15:51:16 +00:00
|
|
|
var searchPromise = MatrixClientPeg.get().backPaginateRoomEventsSearch(
|
|
|
|
this.state.searchResults);
|
|
|
|
return this._handleSearchResult(searchPromise);
|
2015-12-22 15:18:50 +00:00
|
|
|
} else {
|
2016-01-04 16:28:32 +00:00
|
|
|
debuglog("no more search results");
|
2017-07-12 13:02:00 +00:00
|
|
|
return Promise.resolve(false);
|
2015-12-22 15:18:50 +00:00
|
|
|
}
|
|
|
|
},
|
2015-11-30 17:15:57 +00:00
|
|
|
|
|
|
|
onResendAllClick: function() {
|
2017-02-27 13:39:12 +00:00
|
|
|
Resend.resendUnsentEvents(this.state.room);
|
2015-11-30 17:15:57 +00:00
|
|
|
},
|
|
|
|
|
2016-03-21 16:49:07 +00:00
|
|
|
onCancelAllClick: function() {
|
2017-02-27 13:39:12 +00:00
|
|
|
Resend.cancelUnsentEvents(this.state.room);
|
2016-03-21 16:49:07 +00:00
|
|
|
},
|
|
|
|
|
2015-11-30 17:15:57 +00:00
|
|
|
onJoinButtonClicked: function(ev) {
|
2017-05-24 15:56:13 +00:00
|
|
|
const cli = MatrixClientPeg.get();
|
2017-04-28 12:22:55 +00:00
|
|
|
|
|
|
|
// If the user is a ROU, allow them to transition to a PWLU
|
2017-04-28 12:38:35 +00:00
|
|
|
if (cli && cli.isGuest()) {
|
2017-05-24 15:56:13 +00:00
|
|
|
// Join this room once the user has registered and logged in
|
2017-06-02 15:25:14 +00:00
|
|
|
const signUrl = this.props.thirdPartyInvite ?
|
|
|
|
this.props.thirdPartyInvite.inviteSignUrl : undefined;
|
2017-05-24 15:56:13 +00:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'do_after_sync_prepared',
|
|
|
|
deferred_action: {
|
|
|
|
action: 'join_room',
|
2017-06-02 15:25:14 +00:00
|
|
|
opts: { inviteSignUrl: signUrl },
|
2017-05-24 15:56:13 +00:00
|
|
|
},
|
|
|
|
});
|
2016-02-04 11:49:10 +00:00
|
|
|
|
2017-05-25 16:04:42 +00:00
|
|
|
// Don't peek whilst registering otherwise getPendingEventList complains
|
|
|
|
// Do this by indicating our intention to join
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'will_join',
|
2016-02-04 11:49:10 +00:00
|
|
|
});
|
2017-05-25 16:04:42 +00:00
|
|
|
|
2017-04-28 12:22:55 +00:00
|
|
|
const SetMxIdDialog = sdk.getComponent('views.dialogs.SetMxIdDialog');
|
2017-07-27 16:19:18 +00:00
|
|
|
const close = Modal.createTrackedDialog('Set MXID', '', SetMxIdDialog, {
|
2017-05-10 13:22:17 +00:00
|
|
|
homeserverUrl: cli.getHomeserverUrl(),
|
2017-04-28 12:22:55 +00:00
|
|
|
onFinished: (submitted, credentials) => {
|
2017-05-24 15:56:13 +00:00
|
|
|
if (submitted) {
|
|
|
|
this.props.onRegistered(credentials);
|
2017-05-25 16:04:42 +00:00
|
|
|
} else {
|
2017-06-07 10:55:24 +00:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'cancel_after_sync_prepared',
|
|
|
|
});
|
2017-05-25 16:04:42 +00:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'cancel_join',
|
|
|
|
});
|
2017-04-28 12:22:55 +00:00
|
|
|
}
|
2017-05-10 13:22:17 +00:00
|
|
|
},
|
|
|
|
onDifferentServerClicked: (ev) => {
|
|
|
|
dis.dispatch({action: 'start_registration'});
|
|
|
|
close();
|
|
|
|
},
|
2017-05-29 00:32:31 +00:00
|
|
|
onLoginClick: (ev) => {
|
|
|
|
dis.dispatch({action: 'start_login'});
|
|
|
|
close();
|
|
|
|
},
|
2017-05-10 13:22:17 +00:00
|
|
|
}).close;
|
2017-05-24 15:56:13 +00:00
|
|
|
return;
|
2016-02-04 11:49:10 +00:00
|
|
|
}
|
|
|
|
|
2017-07-12 13:02:00 +00:00
|
|
|
Promise.resolve().then(() => {
|
2017-05-24 15:56:13 +00:00
|
|
|
const signUrl = this.props.thirdPartyInvite ?
|
|
|
|
this.props.thirdPartyInvite.inviteSignUrl : undefined;
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'join_room',
|
|
|
|
opts: { inviteSignUrl: signUrl },
|
2017-04-28 12:22:55 +00:00
|
|
|
});
|
2017-05-24 15:56:13 +00:00
|
|
|
|
2016-09-12 17:32:44 +00:00
|
|
|
// if this is an invite and has the 'direct' hint set, mark it as a DM room now.
|
|
|
|
if (this.state.room) {
|
|
|
|
const me = this.state.room.getMember(MatrixClientPeg.get().credentials.userId);
|
2016-09-16 15:45:35 +00:00
|
|
|
if (me && me.membership == 'invite') {
|
2016-09-12 17:32:44 +00:00
|
|
|
if (me.events.member.getContent().is_direct) {
|
2016-09-20 15:08:11 +00:00
|
|
|
// The 'direct' hint is there, so declare that this is a DM room for
|
|
|
|
// whoever invited us.
|
2016-09-12 17:32:44 +00:00
|
|
|
return Rooms.setDMRoom(this.state.room.roomId, me.events.member.getSender());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-12 13:02:00 +00:00
|
|
|
return Promise.resolve();
|
2015-11-30 17:15:57 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onMessageListScroll: function(ev) {
|
2016-02-10 18:27:40 +00:00
|
|
|
if (this.refs.messagePanel.isAtEndOfLiveTimeline()) {
|
|
|
|
this.setState({
|
|
|
|
numUnreadMessages: 0,
|
|
|
|
atEndOfLiveTimeline: true,
|
|
|
|
});
|
2016-01-24 01:51:01 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-02-10 18:27:40 +00:00
|
|
|
this.setState({
|
|
|
|
atEndOfLiveTimeline: false,
|
|
|
|
});
|
2015-12-17 23:04:32 +00:00
|
|
|
}
|
2016-02-24 17:26:34 +00:00
|
|
|
this._updateTopUnreadMessagesBar();
|
2015-11-30 17:15:57 +00: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) {
|
2016-05-31 22:59:36 +00:00
|
|
|
if (MatrixClientPeg.get().isGuest()) {
|
2017-05-15 16:31:26 +00:00
|
|
|
dis.dispatch({action: 'view_set_mxid'});
|
2016-05-31 22:59:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-30 17:15:57 +00:00
|
|
|
ContentMessages.sendContentToRoom(
|
2016-04-12 18:25:07 +00:00
|
|
|
file, this.state.room.roomId, MatrixClientPeg.get()
|
2017-03-09 10:44:09 +00:00
|
|
|
).done(undefined, (error) => {
|
|
|
|
if (error.name === "UnknownDeviceError") {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'unknown_device_error',
|
|
|
|
err: error,
|
|
|
|
room: this.state.room,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
2017-03-12 22:59:41 +00:00
|
|
|
console.error("Failed to upload file " + file + " " + error);
|
2017-08-10 14:17:52 +00:00
|
|
|
Modal.createTrackedDialog('Failed to upload file', '', ErrorDialog, {
|
2017-05-23 14:16:31 +00:00
|
|
|
title: _t('Failed to upload file'),
|
|
|
|
description: ((error && error.message) ? error.message : _t("Server may be unavailable, overloaded, or the file too big")),
|
2015-11-30 17:15:57 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onSearch: function(term, scope) {
|
2015-12-18 11:11:41 +00:00
|
|
|
this.setState({
|
|
|
|
searchTerm: term,
|
|
|
|
searchScope: scope,
|
2015-12-22 18:15:32 +00:00
|
|
|
searchResults: {},
|
2015-12-18 11:11:41 +00:00
|
|
|
searchHighlights: [],
|
|
|
|
});
|
2015-11-30 17:15:57 +00:00
|
|
|
|
2015-12-22 15:18:50 +00: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 18:15:32 +00: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: [
|
2016-04-12 18:25:07 +00:00
|
|
|
this.state.room.roomId
|
2015-12-22 18:15:32 +00:00
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-01-05 15:51:16 +00:00
|
|
|
debuglog("sending search request");
|
2015-12-22 18:15:32 +00:00
|
|
|
|
2016-01-04 16:54:27 +00:00
|
|
|
var searchPromise = MatrixClientPeg.get().searchRoomEvents({
|
|
|
|
filter: filter,
|
|
|
|
term: term,
|
|
|
|
});
|
|
|
|
this._handleSearchResult(searchPromise).done();
|
2015-12-18 11:11:41 +00:00
|
|
|
},
|
|
|
|
|
2015-12-22 18:15:32 +00:00
|
|
|
_handleSearchResult: function(searchPromise) {
|
2015-12-18 11:11:41 +00:00
|
|
|
var self = this;
|
2016-01-04 16:54:27 +00: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 03:22:44 +00:00
|
|
|
|
2015-12-22 18:15:32 +00:00
|
|
|
this.setState({
|
|
|
|
searchInProgress: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
return searchPromise.then(function(results) {
|
2016-01-04 16:28:32 +00:00
|
|
|
debuglog("search complete");
|
2016-01-11 11:38:04 +00:00
|
|
|
if (self.unmounted || !self.state.searching || self.searchId != localSearchId) {
|
2015-12-11 03:22:44 +00:00
|
|
|
console.error("Discarding stale search results");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-05 15:28:32 +00: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 11:11:41 +00:00
|
|
|
|
2015-12-22 18:15:32 +00:00
|
|
|
// For overlapping highlights,
|
2015-12-18 11:11:41 +00:00
|
|
|
// favour longer (more specific) terms first
|
2016-01-08 13:25:03 +00:00
|
|
|
highlights = highlights.sort(function(a, b) {
|
2017-01-20 14:22:27 +00:00
|
|
|
return b.length - a.length; });
|
2015-11-30 17:15:57 +00:00
|
|
|
|
|
|
|
self.setState({
|
2015-12-18 11:11:41 +00:00
|
|
|
searchHighlights: highlights,
|
2015-12-22 18:15:32 +00:00
|
|
|
searchResults: results,
|
2015-11-30 17:15:57 +00:00
|
|
|
});
|
|
|
|
}, function(error) {
|
|
|
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
2017-03-12 22:59:41 +00:00
|
|
|
console.error("Search failed: " + error);
|
2017-08-10 14:17:52 +00:00
|
|
|
Modal.createTrackedDialog('Search failed', '', ErrorDialog, {
|
2017-05-23 14:16:31 +00:00
|
|
|
title: _t("Search failed"),
|
|
|
|
description: ((error && error.message) ? error.message : _t("Server may be unavailable, overloaded, or search timed out :(")),
|
2015-11-30 17:15:57 +00:00
|
|
|
});
|
2015-12-11 02:25:33 +00:00
|
|
|
}).finally(function() {
|
|
|
|
self.setState({
|
|
|
|
searchInProgress: false
|
|
|
|
});
|
2015-12-22 18:15:32 +00:00
|
|
|
});
|
2015-12-18 11:11:41 +00:00
|
|
|
},
|
|
|
|
|
2015-12-22 15:18:50 +00:00
|
|
|
getSearchResultTiles: function() {
|
2015-11-30 17:15:57 +00:00
|
|
|
var EventTile = sdk.getComponent('rooms.EventTile');
|
2015-12-23 10:10:08 +00:00
|
|
|
var SearchResultTile = sdk.getComponent('rooms.SearchResultTile');
|
2016-03-20 23:51:43 +00:00
|
|
|
var Spinner = sdk.getComponent("elements.Spinner");
|
|
|
|
|
2015-12-22 18:15:32 +00:00
|
|
|
var cli = MatrixClientPeg.get();
|
2015-11-30 17:15:57 +00:00
|
|
|
|
2015-12-22 15:18:50 +00:00
|
|
|
// XXX: todo: merge overlapping results somehow?
|
|
|
|
// XXX: why doesn't searching on name work?
|
|
|
|
|
2015-12-22 18:15:32 +00:00
|
|
|
if (this.state.searchResults.results === undefined) {
|
|
|
|
// awaiting results
|
|
|
|
return [];
|
|
|
|
}
|
2015-12-22 15:18:50 +00:00
|
|
|
|
2015-12-22 18:15:32 +00:00
|
|
|
var ret = [];
|
|
|
|
|
2016-03-20 23:51:43 +00:00
|
|
|
if (this.state.searchInProgress) {
|
|
|
|
ret.push(<li key="search-spinner">
|
|
|
|
<Spinner />
|
|
|
|
</li>);
|
|
|
|
}
|
|
|
|
|
2015-12-22 18:15:32 +00:00
|
|
|
if (!this.state.searchResults.next_batch) {
|
|
|
|
if (this.state.searchResults.results.length == 0) {
|
2015-12-22 15:18:50 +00:00
|
|
|
ret.push(<li key="search-top-marker">
|
2017-05-23 14:16:31 +00:00
|
|
|
<h2 className="mx_RoomView_topMarker">{ _t("No results") }</h2>
|
2015-12-22 15:18:50 +00:00
|
|
|
</li>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
ret.push(<li key="search-top-marker">
|
2017-05-23 14:16:31 +00:00
|
|
|
<h2 className="mx_RoomView_topMarker">{ _t("No more results") }</h2>
|
2015-12-22 15:18:50 +00:00
|
|
|
</li>
|
|
|
|
);
|
2015-12-21 12:39:10 +00:00
|
|
|
}
|
2015-12-22 15:18:50 +00:00
|
|
|
}
|
2015-12-21 12:39:10 +00:00
|
|
|
|
2016-04-01 23:36:19 +00:00
|
|
|
// once dynamic content in the search results load, make the scrollPanel check
|
2016-02-22 17:19:04 +00:00
|
|
|
// the scroll offsets.
|
2016-04-01 23:36:19 +00:00
|
|
|
var onWidgetLoad = () => {
|
2016-02-22 17:19:04 +00:00
|
|
|
var scrollPanel = this.refs.searchResultsPanel;
|
|
|
|
if (scrollPanel) {
|
|
|
|
scrollPanel.checkScroll();
|
|
|
|
}
|
2017-01-20 14:22:27 +00:00
|
|
|
};
|
2016-02-22 17:19:04 +00:00
|
|
|
|
2015-12-22 15:18:50 +00:00
|
|
|
var lastRoomId;
|
2015-12-10 13:58:06 +00:00
|
|
|
|
2015-12-22 18:15:32 +00: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();
|
2016-02-22 12:54:22 +00:00
|
|
|
var roomId = mxEv.getRoomId();
|
2015-12-18 16:42:46 +00:00
|
|
|
|
2015-12-22 15:18:50 +00: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 16:42:46 +00:00
|
|
|
|
2015-12-22 15:18:50 +00:00
|
|
|
if (this.state.searchScope === 'All') {
|
|
|
|
if(roomId != lastRoomId) {
|
2016-01-06 16:46:29 +00: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.
|
2017-05-23 14:16:31 +00:00
|
|
|
var roomName = room ? room.name : _t("Unknown room %(roomId)s", { roomId: roomId });
|
2016-01-06 16:46:29 +00:00
|
|
|
|
|
|
|
ret.push(<li key={mxEv.getId() + "-room"}>
|
2017-05-23 14:16:31 +00:00
|
|
|
<h1>{ _t("Room") }: { roomName }</h1>
|
2016-01-06 16:46:29 +00:00
|
|
|
</li>);
|
2015-12-22 15:18:50 +00:00
|
|
|
lastRoomId = roomId;
|
2015-11-30 17:15:57 +00:00
|
|
|
}
|
2015-12-22 15:18:50 +00:00
|
|
|
}
|
2015-11-30 17:15:57 +00:00
|
|
|
|
2016-02-22 12:54:22 +00:00
|
|
|
var resultLink = "#/room/"+roomId+"/"+mxEv.getId();
|
2016-02-17 19:50:04 +00:00
|
|
|
|
2015-12-23 10:10:08 +00:00
|
|
|
ret.push(<SearchResultTile key={mxEv.getId()}
|
|
|
|
searchResult={result}
|
2016-01-29 11:19:27 +00:00
|
|
|
searchHighlights={this.state.searchHighlights}
|
2016-02-22 17:19:04 +00:00
|
|
|
resultLink={resultLink}
|
2016-04-01 23:36:19 +00:00
|
|
|
onWidgetLoad={onWidgetLoad}/>);
|
2015-11-30 17:15:57 +00:00
|
|
|
}
|
2015-12-22 15:18:50 +00:00
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
2015-11-30 17:15:57 +00:00
|
|
|
onSettingsClick: function() {
|
2016-01-20 23:09:36 +00:00
|
|
|
this.showSettings(true);
|
2015-11-30 17:15:57 +00:00
|
|
|
},
|
|
|
|
|
2016-02-04 15:26:12 +00:00
|
|
|
onSettingsSaveClick: function() {
|
2016-04-12 17:01:49 +00:00
|
|
|
if (!this.refs.room_settings) return;
|
|
|
|
|
2015-11-30 17:15:57 +00:00
|
|
|
this.setState({
|
|
|
|
uploadingRoomSettings: true,
|
|
|
|
});
|
2016-04-22 16:05:48 +00:00
|
|
|
|
2016-03-29 14:21:16 +00:00
|
|
|
var newName = this.refs.header.getEditedName();
|
|
|
|
if (newName !== undefined) {
|
|
|
|
this.refs.room_settings.setName(newName);
|
|
|
|
}
|
|
|
|
var newTopic = this.refs.header.getEditedTopic();
|
|
|
|
if (newTopic !== undefined) {
|
|
|
|
this.refs.room_settings.setTopic(newTopic);
|
|
|
|
}
|
2016-04-22 16:05:48 +00:00
|
|
|
|
2016-02-04 15:26:12 +00:00
|
|
|
this.refs.room_settings.save().then((results) => {
|
2017-01-20 14:22:27 +00:00
|
|
|
var fails = results.filter(function(result) { return result.state !== "fulfilled"; });
|
2016-02-05 14:38:28 +00:00
|
|
|
console.log("Settings saved with %s errors", fails.length);
|
2016-02-04 15:26:12 +00:00
|
|
|
if (fails.length) {
|
|
|
|
fails.forEach(function(result) {
|
|
|
|
console.error(result.reason);
|
|
|
|
});
|
|
|
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
2017-07-27 16:19:18 +00:00
|
|
|
Modal.createTrackedDialog('Failed to save room settings', '', ErrorDialog, {
|
2017-05-23 14:16:31 +00:00
|
|
|
title: _t("Failed to save settings"),
|
2017-01-20 14:22:27 +00:00
|
|
|
description: fails.map(function(result) { return result.reason; }).join("\n"),
|
2016-02-04 15:26:12 +00:00
|
|
|
});
|
|
|
|
// still editing room settings
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.setState({
|
|
|
|
editingRoomSettings: false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}).finally(() => {
|
|
|
|
this.setState({
|
|
|
|
uploadingRoomSettings: false,
|
|
|
|
editingRoomSettings: false
|
|
|
|
});
|
2016-02-05 11:59:19 +00:00
|
|
|
}).done();
|
2015-11-30 17:15:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onCancelClick: function() {
|
2016-04-16 00:00:10 +00:00
|
|
|
console.log("updateTint from onCancelClick");
|
2016-01-08 03:22:38 +00:00
|
|
|
this.updateTint();
|
2017-04-21 11:56:59 +00:00
|
|
|
this.setState({
|
|
|
|
editingRoomSettings: false,
|
|
|
|
});
|
2017-06-16 15:12:52 +00:00
|
|
|
if (this.state.forwardingEvent) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'forward_event',
|
|
|
|
event: null,
|
|
|
|
});
|
|
|
|
}
|
2017-04-21 17:45:28 +00:00
|
|
|
dis.dispatch({action: 'focus_composer'});
|
2015-11-30 17:15:57 +00:00
|
|
|
},
|
|
|
|
|
2015-12-13 13:49:28 +00:00
|
|
|
onLeaveClick: function() {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'leave_room',
|
2016-04-12 18:25:07 +00:00
|
|
|
room_id: this.state.room.roomId,
|
2015-12-13 13:49:28 +00:00
|
|
|
});
|
2015-12-16 16:06:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onForgetClick: function() {
|
2016-04-12 18:25:07 +00:00
|
|
|
MatrixClientPeg.get().forget(this.state.room.roomId).done(function() {
|
2015-12-16 16:06:29 +00:00
|
|
|
dis.dispatch({ action: 'view_next_room' });
|
|
|
|
}, function(err) {
|
2017-05-23 14:16:31 +00:00
|
|
|
var errCode = err.errcode || _t("unknown error code");
|
2015-12-18 16:56:37 +00:00
|
|
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
2017-08-10 12:49:11 +00:00
|
|
|
Modal.createTrackedDialog('Failed to forget room', '', ErrorDialog, {
|
2017-05-23 14:16:31 +00:00
|
|
|
title: _t("Error"),
|
|
|
|
description: _t("Failed to forget room %(errCode)s", { errCode: errCode }),
|
2015-12-18 16:56:37 +00:00
|
|
|
});
|
2015-12-16 16:06:29 +00:00
|
|
|
});
|
2015-12-13 13:49:28 +00:00
|
|
|
},
|
|
|
|
|
2015-11-30 17:15:57 +00:00
|
|
|
onRejectButtonClicked: function(ev) {
|
|
|
|
var self = this;
|
|
|
|
this.setState({
|
|
|
|
rejecting: true
|
|
|
|
});
|
2016-06-20 17:05:58 +00:00
|
|
|
MatrixClientPeg.get().leave(this.state.roomId).done(function() {
|
2015-11-30 17:15:57 +00:00
|
|
|
dis.dispatch({ action: 'view_next_room' });
|
|
|
|
self.setState({
|
|
|
|
rejecting: false
|
|
|
|
});
|
2016-02-15 18:59:44 +00:00
|
|
|
}, function(error) {
|
|
|
|
console.error("Failed to reject invite: %s", error);
|
|
|
|
|
|
|
|
var msg = error.message ? error.message : JSON.stringify(error);
|
|
|
|
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
2017-08-10 14:17:52 +00:00
|
|
|
Modal.createTrackedDialog('Failed to reject invite', '', ErrorDialog, {
|
2017-05-23 14:16:31 +00:00
|
|
|
title: _t("Failed to reject invite"),
|
|
|
|
description: msg,
|
2016-02-15 18:59:44 +00:00
|
|
|
});
|
|
|
|
|
2015-11-30 17:15:57 +00:00
|
|
|
self.setState({
|
|
|
|
rejecting: false,
|
2016-02-15 18:59:44 +00:00
|
|
|
rejectError: error
|
2015-11-30 17:15:57 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-03-10 15:56:58 +00:00
|
|
|
onRejectThreepidInviteButtonClicked: function(ev) {
|
2016-03-11 10:20:52 +00:00
|
|
|
// We can reject 3pid invites in the same way that we accept them,
|
|
|
|
// using /leave rather than /join. In the short term though, we
|
|
|
|
// just ignore them.
|
|
|
|
// https://github.com/vector-im/vector-web/issues/1134
|
2016-03-10 15:56:58 +00:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room_directory',
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-11-30 17:15:57 +00:00
|
|
|
onSearchClick: function() {
|
|
|
|
this.setState({ searching: true });
|
|
|
|
},
|
|
|
|
|
2017-01-20 14:22:27 +00:00
|
|
|
onCancelSearchClick: function() {
|
2015-12-18 16:42:46 +00:00
|
|
|
this.setState({
|
|
|
|
searching: false,
|
|
|
|
searchResults: null,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-02-03 08:03:10 +00:00
|
|
|
// jump down to the bottom of this room, where new events are arriving
|
|
|
|
jumpToLiveTimeline: function() {
|
2016-02-10 18:27:40 +00:00
|
|
|
this.refs.messagePanel.jumpToLiveTimeline();
|
2017-04-21 00:06:00 +00:00
|
|
|
dis.dispatch({action: 'focus_composer'});
|
2015-12-18 16:42:46 +00:00
|
|
|
},
|
|
|
|
|
2016-02-24 17:26:34 +00:00
|
|
|
// jump up to wherever our read marker is
|
|
|
|
jumpToReadMarker: function() {
|
|
|
|
this.refs.messagePanel.jumpToReadMarker();
|
|
|
|
},
|
|
|
|
|
|
|
|
// update the read marker to match the read-receipt
|
2016-04-13 11:46:36 +00:00
|
|
|
forgetReadMarker: function(ev) {
|
|
|
|
ev.stopPropagation();
|
2016-02-24 17:26:34 +00:00
|
|
|
this.refs.messagePanel.forgetReadMarker();
|
|
|
|
},
|
|
|
|
|
|
|
|
// decide whether or not the top 'unread messages' bar should be shown
|
|
|
|
_updateTopUnreadMessagesBar: function() {
|
2017-01-20 14:22:27 +00:00
|
|
|
if (!this.refs.messagePanel) {
|
2016-02-24 17:26:34 +00:00
|
|
|
return;
|
2017-01-20 14:22:27 +00:00
|
|
|
}
|
2016-02-24 17:26:34 +00:00
|
|
|
|
2017-04-27 13:03:54 +00:00
|
|
|
const showBar = this.refs.messagePanel.canJumpToReadMarker();
|
2016-03-10 15:55:03 +00:00
|
|
|
if (this.state.showTopUnreadMessagesBar != showBar) {
|
|
|
|
this.setState({showTopUnreadMessagesBar: showBar},
|
|
|
|
this.onChildResize);
|
|
|
|
}
|
2016-02-24 17:26:34 +00:00
|
|
|
},
|
|
|
|
|
2015-12-10 21:34:10 +00:00
|
|
|
// get the current scroll position of the room, so that it can be
|
2016-02-01 16:31:12 +00:00
|
|
|
// restored when we switch back to it.
|
|
|
|
//
|
2016-11-04 09:28:35 +00:00
|
|
|
_getScrollState: function() {
|
2015-12-22 15:18:50 +00:00
|
|
|
var messagePanel = this.refs.messagePanel;
|
|
|
|
if (!messagePanel) return null;
|
|
|
|
|
2016-02-04 16:17:03 +00:00
|
|
|
// if we're following the live timeline, we want to return null; that
|
|
|
|
// means that, if we switch back, we will jump to the read-up-to mark.
|
|
|
|
//
|
|
|
|
// That should be more intuitive than slavishly preserving the current
|
|
|
|
// scroll state, in the case where the room advances in the meantime
|
|
|
|
// (particularly in the case that the user reads some stuff on another
|
|
|
|
// device).
|
|
|
|
//
|
|
|
|
if (this.state.atEndOfLiveTimeline) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-02-01 16:31:12 +00:00
|
|
|
var scrollState = messagePanel.getScrollState();
|
2015-12-18 16:42:46 +00:00
|
|
|
|
2016-02-03 08:03:10 +00:00
|
|
|
if (scrollState.stuckAtBottom) {
|
2016-02-01 16:31:12 +00:00
|
|
|
// we don't really expect to be in this state, but it will
|
2016-02-03 08:03:10 +00:00
|
|
|
// occasionally happen when no scroll state has been set on the
|
|
|
|
// messagePanel (ie, we didn't have an initial event (so it's
|
|
|
|
// probably a new room), there has been no user-initiated scroll, and
|
|
|
|
// no read-receipts have arrived to update the scroll position).
|
|
|
|
//
|
|
|
|
// Return null, which will cause us to scroll to last unread on
|
|
|
|
// reload.
|
2016-02-01 16:31:12 +00:00
|
|
|
return null;
|
2015-12-10 16:26:36 +00:00
|
|
|
}
|
2016-02-01 16:31:12 +00:00
|
|
|
|
|
|
|
return {
|
2016-02-03 08:03:10 +00:00
|
|
|
focussedEvent: scrollState.trackedScrollToken,
|
2016-02-01 16:31:12 +00:00
|
|
|
pixelOffset: scrollState.pixelOffset,
|
|
|
|
};
|
2015-12-10 16:26:36 +00:00
|
|
|
},
|
|
|
|
|
2015-12-13 04:32:48 +00: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 13:03:37 +00:00
|
|
|
|
2016-01-15 15:53:53 +00:00
|
|
|
// header + footer + status + give us at least 120px of scrollback at all times.
|
2016-01-15 14:22:17 +00:00
|
|
|
var auxPanelMaxHeight = window.innerHeight -
|
|
|
|
(83 + // height of RoomHeader
|
|
|
|
36 + // height of the status area
|
|
|
|
72 + // minimum height of the message compmoser
|
2016-01-20 23:09:36 +00:00
|
|
|
(this.state.editingRoomSettings ? (window.innerHeight * 0.3) : 120)); // amount of desired scrollback
|
2016-01-10 13:03:37 +00: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;
|
|
|
|
|
2016-03-08 12:16:34 +00:00
|
|
|
this.setState({auxPanelMaxHeight: auxPanelMaxHeight});
|
|
|
|
|
|
|
|
// changing the maxHeight on the auxpanel will trigger a callback go
|
|
|
|
// onChildResize, so no need to worry about that here.
|
2015-12-13 04:32:48 +00:00
|
|
|
},
|
|
|
|
|
2015-12-15 00:01:47 +00:00
|
|
|
onFullscreenClick: function() {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'video_fullscreen',
|
|
|
|
fullscreen: true
|
|
|
|
}, true);
|
|
|
|
},
|
|
|
|
|
2015-12-14 23:37:34 +00:00
|
|
|
onMuteAudioClick: function() {
|
2016-04-12 18:25:07 +00:00
|
|
|
var call = this._getCallForRoom();
|
2015-12-14 23:37:34 +00:00
|
|
|
if (!call) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var newState = !call.isMicrophoneMuted();
|
|
|
|
call.setMicrophoneMuted(newState);
|
2016-10-17 13:03:37 +00:00
|
|
|
this.forceUpdate(); // TODO: just update the voip buttons
|
2015-12-14 23:37:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onMuteVideoClick: function() {
|
2016-04-12 18:25:07 +00:00
|
|
|
var call = this._getCallForRoom();
|
2015-12-14 23:37:34 +00:00
|
|
|
if (!call) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var newState = !call.isLocalVideoMuted();
|
|
|
|
call.setLocalVideoMuted(newState);
|
2016-10-17 13:03:37 +00:00
|
|
|
this.forceUpdate(); // TODO: just update the voip buttons
|
2015-12-14 23:37:34 +00:00
|
|
|
},
|
|
|
|
|
2016-01-11 15:28:59 +00:00
|
|
|
onChildResize: function() {
|
2016-03-14 12:46:13 +00:00
|
|
|
// no longer anything to do here
|
2016-01-11 15:28:59 +00:00
|
|
|
},
|
|
|
|
|
2017-01-23 15:01:39 +00:00
|
|
|
onStatusBarVisible: function() {
|
2017-01-26 17:03:01 +00:00
|
|
|
if (this.unmounted) return;
|
2017-01-23 15:01:39 +00:00
|
|
|
this.setState({
|
|
|
|
statusBarVisible: true,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onStatusBarHidden: function() {
|
2017-01-26 17:03:01 +00:00
|
|
|
if (this.unmounted) return;
|
2017-01-23 15:01:39 +00:00
|
|
|
this.setState({
|
|
|
|
statusBarVisible: false,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-01-17 03:59:31 +00:00
|
|
|
showSettings: function(show) {
|
|
|
|
// XXX: this is a bit naughty; we should be doing this via props
|
|
|
|
if (show) {
|
|
|
|
this.setState({editingRoomSettings: true});
|
2016-03-08 12:16:34 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-04-05 12:14:11 +00:00
|
|
|
/**
|
|
|
|
* called by the parent component when PageUp/Down/etc is pressed.
|
|
|
|
*
|
|
|
|
* We pass it down to the scroll panel.
|
|
|
|
*/
|
|
|
|
handleScrollKey: function(ev) {
|
|
|
|
var panel;
|
|
|
|
if(this.refs.searchResultsPanel) {
|
|
|
|
panel = this.refs.searchResultsPanel;
|
|
|
|
} else if(this.refs.messagePanel) {
|
|
|
|
panel = this.refs.messagePanel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(panel) {
|
|
|
|
panel.handleScrollKey(ev);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-04-12 18:25:07 +00:00
|
|
|
/**
|
|
|
|
* get any current call for this room
|
|
|
|
*/
|
|
|
|
_getCallForRoom: function() {
|
|
|
|
if (!this.state.room) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return CallHandler.getCallForRoom(this.state.room.roomId);
|
|
|
|
},
|
|
|
|
|
2016-03-08 12:16:34 +00:00
|
|
|
// this has to be a proper method rather than an unnamed function,
|
|
|
|
// otherwise react calls it with null on each update.
|
|
|
|
_gatherTimelinePanelRef: function(r) {
|
|
|
|
this.refs.messagePanel = r;
|
|
|
|
if(r) {
|
2016-04-16 00:00:10 +00:00
|
|
|
console.log("updateTint from RoomView._gatherTimelinePanelRef");
|
2016-03-08 12:16:34 +00:00
|
|
|
this.updateTint();
|
2016-01-17 03:59:31 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-30 17:15:57 +00:00
|
|
|
render: function() {
|
2017-04-21 11:56:59 +00:00
|
|
|
const RoomHeader = sdk.getComponent('rooms.RoomHeader');
|
|
|
|
const MessageComposer = sdk.getComponent('rooms.MessageComposer');
|
|
|
|
const ForwardMessage = sdk.getComponent("rooms.ForwardMessage");
|
|
|
|
const RoomSettings = sdk.getComponent("rooms.RoomSettings");
|
|
|
|
const AuxPanel = sdk.getComponent("rooms.AuxPanel");
|
|
|
|
const SearchBar = sdk.getComponent("rooms.SearchBar");
|
|
|
|
const ScrollPanel = sdk.getComponent("structures.ScrollPanel");
|
|
|
|
const TintableSvg = sdk.getComponent("elements.TintableSvg");
|
|
|
|
const RoomPreviewBar = sdk.getComponent("rooms.RoomPreviewBar");
|
|
|
|
const Loader = sdk.getComponent("elements.Spinner");
|
|
|
|
const TimelinePanel = sdk.getComponent("structures.TimelinePanel");
|
2015-11-30 17:15:57 +00:00
|
|
|
|
2017-06-15 14:32:01 +00:00
|
|
|
// Whether the preview bar spinner should be shown. We do this when joining or
|
|
|
|
// when waiting for a room to be returned by js-sdk when joining
|
|
|
|
const previewBarSpinner = this.state.joining || this.state.waitingForRoom;
|
2015-11-30 17:15:57 +00:00
|
|
|
|
2016-02-10 18:27:40 +00:00
|
|
|
if (!this.state.room) {
|
2017-06-05 08:52:39 +00:00
|
|
|
if (this.state.roomLoading || this.state.peekLoading) {
|
2017-05-30 10:21:33 +00:00
|
|
|
return (
|
|
|
|
<div className="mx_RoomView">
|
|
|
|
<Loader />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
var inviterName = undefined;
|
|
|
|
if (this.props.oobData) {
|
|
|
|
inviterName = this.props.oobData.inviterName;
|
|
|
|
}
|
|
|
|
var invitedEmail = undefined;
|
|
|
|
if (this.props.thirdPartyInvite) {
|
|
|
|
invitedEmail = this.props.thirdPartyInvite.invitedEmail;
|
2016-01-18 17:39:23 +00:00
|
|
|
}
|
2016-03-01 18:23:57 +00:00
|
|
|
|
2017-05-30 10:21:33 +00:00
|
|
|
// We have no room object for this room, only the ID.
|
|
|
|
// We've got to this room by following a link, possibly a third party invite.
|
2017-06-16 10:10:55 +00:00
|
|
|
const roomAlias = this.state.roomAlias;
|
2017-05-30 10:21:33 +00:00
|
|
|
return (
|
|
|
|
<div className="mx_RoomView">
|
|
|
|
<RoomHeader ref="header"
|
|
|
|
room={this.state.room}
|
|
|
|
oobData={this.props.oobData}
|
|
|
|
collapsedRhs={ this.props.collapsedRhs }
|
|
|
|
/>
|
|
|
|
<div className="mx_RoomView_auxPanel">
|
|
|
|
<RoomPreviewBar onJoinClick={ this.onJoinButtonClicked }
|
|
|
|
onForgetClick={ this.onForgetClick }
|
|
|
|
onRejectClick={ this.onRejectThreepidInviteButtonClicked }
|
|
|
|
canPreview={ false } error={ this.state.roomLoadError }
|
2017-06-16 10:10:55 +00:00
|
|
|
roomAlias={roomAlias}
|
2017-06-15 14:32:01 +00:00
|
|
|
spinner={previewBarSpinner}
|
2017-05-30 10:21:33 +00:00
|
|
|
inviterName={inviterName}
|
|
|
|
invitedEmail={invitedEmail}
|
|
|
|
room={this.state.room}
|
2016-04-15 17:45:40 +00:00
|
|
|
/>
|
2016-01-18 17:39:23 +00:00
|
|
|
</div>
|
2017-05-30 10:21:33 +00:00
|
|
|
<div className="mx_RoomView_messagePanel"></div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2015-11-30 17:15:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var myUserId = MatrixClientPeg.get().credentials.userId;
|
2015-12-14 15:36:34 +00:00
|
|
|
var myMember = this.state.room.getMember(myUserId);
|
|
|
|
if (myMember && myMember.membership == 'invite') {
|
2015-11-30 17:15:57 +00:00
|
|
|
if (this.state.joining || this.state.rejecting) {
|
|
|
|
return (
|
|
|
|
<div className="mx_RoomView">
|
|
|
|
<Loader />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
2015-12-14 15:36:34 +00:00
|
|
|
var inviteEvent = myMember.events.member;
|
|
|
|
var inviterName = inviteEvent.sender ? inviteEvent.sender.name : inviteEvent.getSender();
|
2016-01-18 17:39:23 +00: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 20:15:12 +00:00
|
|
|
|
2016-03-17 18:38:25 +00:00
|
|
|
// We have a regular invite for this room.
|
2015-11-30 17:15:57 +00:00
|
|
|
return (
|
|
|
|
<div className="mx_RoomView">
|
2016-09-13 18:00:35 +00:00
|
|
|
<RoomHeader
|
|
|
|
ref="header"
|
|
|
|
room={this.state.room}
|
|
|
|
collapsedRhs={ this.props.collapsedRhs }
|
|
|
|
/>
|
2016-01-18 17:39:23 +00:00
|
|
|
<div className="mx_RoomView_auxPanel">
|
2016-04-22 16:05:48 +00:00
|
|
|
<RoomPreviewBar onJoinClick={ this.onJoinButtonClicked }
|
2017-02-17 15:50:30 +00:00
|
|
|
onForgetClick={ this.onForgetClick }
|
2016-01-18 17:39:23 +00:00
|
|
|
onRejectClick={ this.onRejectButtonClicked }
|
|
|
|
inviterName={ inviterName }
|
2016-06-24 14:34:07 +00:00
|
|
|
canPreview={ false }
|
2017-06-15 14:32:01 +00:00
|
|
|
spinner={previewBarSpinner}
|
2016-04-12 16:18:32 +00:00
|
|
|
room={this.state.room}
|
2016-02-09 16:55:03 +00:00
|
|
|
/>
|
2015-11-30 17:15:57 +00:00
|
|
|
</div>
|
2016-01-18 20:15:12 +00:00
|
|
|
<div className="mx_RoomView_messagePanel"></div>
|
2015-11-30 17:15:57 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-02-08 16:43:08 +00:00
|
|
|
}
|
2015-11-30 17:15:57 +00:00
|
|
|
|
2016-02-08 16:43:08 +00:00
|
|
|
// We have successfully loaded this room, and are not previewing.
|
|
|
|
// Display the "normal" room view.
|
|
|
|
|
2016-04-12 18:25:07 +00:00
|
|
|
var call = this._getCallForRoom();
|
2016-02-08 18:04:54 +00:00
|
|
|
var inCall = false;
|
|
|
|
if (call && (this.state.callState !== 'ended' && this.state.callState !== 'ringing')) {
|
|
|
|
inCall = true;
|
|
|
|
}
|
|
|
|
|
2016-02-08 16:43:08 +00:00
|
|
|
var scrollheader_classes = classNames({
|
|
|
|
mx_RoomView_scrollheader: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
var statusBar;
|
2017-01-26 18:07:42 +00:00
|
|
|
let isStatusAreaExpanded = true;
|
2016-02-08 16:43:08 +00:00
|
|
|
|
|
|
|
if (ContentMessages.getCurrentUploads().length > 0) {
|
|
|
|
var UploadBar = sdk.getComponent('structures.UploadBar');
|
2017-01-20 14:22:27 +00:00
|
|
|
statusBar = <UploadBar room={this.state.room} />;
|
2016-02-08 16:43:08 +00:00
|
|
|
} else if (!this.state.searchResults) {
|
2016-02-08 18:04:54 +00:00
|
|
|
var RoomStatusBar = sdk.getComponent('structures.RoomStatusBar');
|
2017-01-26 18:07:42 +00:00
|
|
|
isStatusAreaExpanded = this.state.statusBarVisible;
|
2016-02-08 18:04:54 +00:00
|
|
|
statusBar = <RoomStatusBar
|
|
|
|
room={this.state.room}
|
|
|
|
numUnreadMessages={this.state.numUnreadMessages}
|
2017-02-03 00:40:40 +00:00
|
|
|
unsentMessageError={this.state.unsentMessageError}
|
2016-02-08 18:04:54 +00:00
|
|
|
atEndOfLiveTimeline={this.state.atEndOfLiveTimeline}
|
|
|
|
hasActiveCall={inCall}
|
2016-02-09 11:36:57 +00:00
|
|
|
onResendAllClick={this.onResendAllClick}
|
2016-03-21 16:49:07 +00:00
|
|
|
onCancelAllClick={this.onCancelAllClick}
|
2016-02-09 11:36:57 +00:00
|
|
|
onScrollToBottomClick={this.jumpToLiveTimeline}
|
2016-02-23 11:06:16 +00:00
|
|
|
onResize={this.onChildResize}
|
2017-01-23 15:01:39 +00:00
|
|
|
onVisible={this.onStatusBarVisible}
|
|
|
|
onHidden={this.onStatusBarHidden}
|
2017-02-09 10:30:06 +00:00
|
|
|
whoIsTypingLimit={3}
|
2017-01-23 15:01:39 +00:00
|
|
|
/>;
|
2016-02-08 16:43:08 +00:00
|
|
|
}
|
2015-11-30 17:15:57 +00:00
|
|
|
|
2017-04-21 11:56:59 +00:00
|
|
|
let aux = null;
|
2017-05-30 10:20:41 +00:00
|
|
|
let hideCancel = false;
|
2016-02-08 16:43:08 +00:00
|
|
|
if (this.state.editingRoomSettings) {
|
|
|
|
aux = <RoomSettings ref="room_settings" onSaveClick={this.onSettingsSaveClick} onCancelClick={this.onCancelClick} room={this.state.room} />;
|
2017-04-21 11:56:59 +00:00
|
|
|
} else if (this.state.uploadingRoomSettings) {
|
2016-02-08 16:43:08 +00:00
|
|
|
aux = <Loader/>;
|
2017-05-30 10:22:27 +00:00
|
|
|
} else if (this.state.forwardingEvent !== null) {
|
2017-06-16 15:12:52 +00:00
|
|
|
aux = <ForwardMessage onCancelClick={this.onCancelClick} />;
|
2017-04-21 11:56:59 +00:00
|
|
|
} else if (this.state.searching) {
|
2017-05-30 10:20:41 +00:00
|
|
|
hideCancel = true; // has own cancel
|
2016-02-08 16:43:08 +00:00
|
|
|
aux = <SearchBar ref="search_bar" searchInProgress={this.state.searchInProgress } onCancelClick={this.onCancelSearchClick} onSearch={this.onSearch}/>;
|
2017-04-21 11:56:59 +00:00
|
|
|
} else if (!myMember || myMember.membership !== "join") {
|
2016-03-18 16:06:36 +00:00
|
|
|
// We do have a room object for this room, but we're not currently in it.
|
|
|
|
// We may have a 3rd party invite to it.
|
2016-03-10 15:56:58 +00:00
|
|
|
var inviterName = undefined;
|
|
|
|
if (this.props.oobData) {
|
|
|
|
inviterName = this.props.oobData.inviterName;
|
|
|
|
}
|
2016-03-17 18:38:25 +00:00
|
|
|
var invitedEmail = undefined;
|
|
|
|
if (this.props.thirdPartyInvite) {
|
|
|
|
invitedEmail = this.props.thirdPartyInvite.invitedEmail;
|
|
|
|
}
|
2017-05-30 10:20:41 +00:00
|
|
|
hideCancel = true;
|
2016-02-08 16:43:08 +00:00
|
|
|
aux = (
|
2016-06-24 14:34:07 +00:00
|
|
|
<RoomPreviewBar onJoinClick={this.onJoinButtonClicked}
|
2017-02-17 15:50:30 +00:00
|
|
|
onForgetClick={ this.onForgetClick }
|
2016-03-17 18:38:25 +00:00
|
|
|
onRejectClick={this.onRejectThreepidInviteButtonClicked}
|
2017-06-15 14:32:01 +00:00
|
|
|
spinner={previewBarSpinner}
|
2016-03-10 15:56:58 +00:00
|
|
|
inviterName={inviterName}
|
2016-03-17 18:38:25 +00:00
|
|
|
invitedEmail={invitedEmail}
|
|
|
|
canPreview={this.state.canPeek}
|
2016-04-12 16:18:32 +00:00
|
|
|
room={this.state.room}
|
2016-02-09 16:55:03 +00:00
|
|
|
/>
|
2016-02-08 16:43:08 +00:00
|
|
|
);
|
|
|
|
}
|
2015-12-18 17:23:46 +00:00
|
|
|
|
2016-02-23 15:46:27 +00:00
|
|
|
var auxPanel = (
|
|
|
|
<AuxPanel ref="auxPanel" room={this.state.room}
|
2017-06-13 13:19:38 +00:00
|
|
|
userId={MatrixClientPeg.get().credentials.userId}
|
2016-02-23 15:46:27 +00:00
|
|
|
conferenceHandler={this.props.ConferenceHandler}
|
|
|
|
draggingFile={this.state.draggingFile}
|
|
|
|
displayConfCallNotification={this.state.displayConfCallNotification}
|
|
|
|
maxHeight={this.state.auxPanelMaxHeight}
|
2017-05-17 20:15:57 +00:00
|
|
|
onResize={this.onChildResize}
|
2017-06-27 16:39:29 +00:00
|
|
|
showApps={this.state.showApps && !this.state.editingRoomSettings} >
|
2016-02-23 15:46:27 +00:00
|
|
|
{ aux }
|
|
|
|
</AuxPanel>
|
|
|
|
);
|
2015-12-15 00:01:47 +00:00
|
|
|
|
2016-02-08 16:43:08 +00:00
|
|
|
var messageComposer, searchInfo;
|
|
|
|
var canSpeak = (
|
|
|
|
// joined and not showing search results
|
|
|
|
myMember && (myMember.membership == 'join') && !this.state.searchResults
|
|
|
|
);
|
|
|
|
if (canSpeak) {
|
|
|
|
messageComposer =
|
|
|
|
<MessageComposer
|
2017-05-17 20:15:57 +00:00
|
|
|
room={this.state.room}
|
|
|
|
onResize={this.onChildResize}
|
|
|
|
uploadFile={this.uploadFile}
|
|
|
|
callState={this.state.callState}
|
|
|
|
opacity={ this.props.opacity }
|
|
|
|
showApps={ this.state.showApps }
|
|
|
|
/>;
|
2016-02-08 16:43:08 +00:00
|
|
|
}
|
2015-12-14 23:37:34 +00:00
|
|
|
|
2016-02-08 16:43:08 +00: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) {
|
|
|
|
searchInfo = {
|
|
|
|
searchTerm : this.state.searchTerm,
|
|
|
|
searchScope : this.state.searchScope,
|
|
|
|
searchCount : this.state.searchResults.count,
|
|
|
|
};
|
|
|
|
}
|
2015-12-14 23:37:34 +00:00
|
|
|
|
2016-02-08 18:04:54 +00:00
|
|
|
if (inCall) {
|
2016-02-08 16:43:08 +00:00
|
|
|
var zoomButton, voiceMuteButton, videoMuteButton;
|
|
|
|
|
|
|
|
if (call.type === "video") {
|
|
|
|
zoomButton = (
|
2017-05-23 14:16:31 +00:00
|
|
|
<div className="mx_RoomView_voipButton" onClick={this.onFullscreenClick} title={ _t("Fill screen") }>
|
2016-02-08 16:43:08 +00:00
|
|
|
<TintableSvg src="img/fullscreen.svg" width="29" height="22" style={{ marginTop: 1, marginRight: 4 }}/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
videoMuteButton =
|
|
|
|
<div className="mx_RoomView_voipButton" onClick={this.onMuteVideoClick}>
|
2017-02-19 23:43:55 +00:00
|
|
|
<TintableSvg src={call.isLocalVideoMuted() ? "img/video-unmute.svg" : "img/video-mute.svg"}
|
2017-05-23 14:16:31 +00:00
|
|
|
alt={call.isLocalVideoMuted() ? _t("Click to unmute video") : _t("Click to mute video")}
|
2016-02-08 16:43:08 +00:00
|
|
|
width="31" height="27"/>
|
2017-01-20 14:22:27 +00:00
|
|
|
</div>;
|
2015-12-14 23:37:34 +00:00
|
|
|
}
|
2016-02-08 16:43:08 +00:00
|
|
|
voiceMuteButton =
|
|
|
|
<div className="mx_RoomView_voipButton" onClick={this.onMuteAudioClick}>
|
2017-02-19 23:43:55 +00:00
|
|
|
<TintableSvg src={call.isMicrophoneMuted() ? "img/voice-unmute.svg" : "img/voice-mute.svg"}
|
2017-05-23 14:16:31 +00:00
|
|
|
alt={call.isMicrophoneMuted() ? _t("Click to unmute audio") : _t("Click to mute audio")}
|
2016-02-08 16:43:08 +00:00
|
|
|
width="21" height="26"/>
|
2017-01-20 14:22:27 +00:00
|
|
|
</div>;
|
2015-12-14 23:37:34 +00:00
|
|
|
|
2016-02-08 18:04:54 +00:00
|
|
|
// wrap the existing status bar into a 'callStatusBar' which adds more knobs.
|
2016-02-08 16:43:08 +00:00
|
|
|
statusBar =
|
|
|
|
<div className="mx_RoomView_callStatusBar">
|
|
|
|
{ voiceMuteButton }
|
|
|
|
{ videoMuteButton }
|
|
|
|
{ zoomButton }
|
|
|
|
{ statusBar }
|
|
|
|
<TintableSvg className="mx_RoomView_voipChevron" src="img/voip-chevron.svg" width="22" height="17"/>
|
2017-01-20 14:22:27 +00:00
|
|
|
</div>;
|
2016-02-08 16:43:08 +00:00
|
|
|
}
|
2016-02-01 16:31:12 +00:00
|
|
|
|
2016-02-08 16:43:08 +00: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 = (
|
2016-04-12 16:18:32 +00:00
|
|
|
<ScrollPanel ref="searchResultsPanel"
|
|
|
|
className="mx_RoomView_messagePanel mx_RoomView_searchResultsPanel"
|
|
|
|
onFillRequest={ this.onSearchResultsFillRequest }
|
|
|
|
onResize={ this.onSearchResultsResize }
|
|
|
|
style={{ opacity: this.props.opacity }}
|
|
|
|
>
|
2016-02-08 16:43:08 +00:00
|
|
|
<li className={scrollheader_classes}></li>
|
|
|
|
{this.getSearchResultTiles()}
|
|
|
|
</ScrollPanel>
|
|
|
|
);
|
|
|
|
hideMessagePanel = true;
|
|
|
|
}
|
2015-12-22 15:18:50 +00:00
|
|
|
|
2017-06-08 14:47:41 +00:00
|
|
|
const shouldHighlight = this.state.isInitialEventHighlighted;
|
2017-06-08 13:17:49 +00:00
|
|
|
let highlightedEventId = null;
|
|
|
|
if (this.state.forwardingEvent) {
|
|
|
|
highlightedEventId = this.state.forwardingEvent.getId();
|
|
|
|
} else if (shouldHighlight) {
|
2017-06-08 14:47:41 +00:00
|
|
|
highlightedEventId = this.state.initialEventId;
|
2017-06-08 13:17:49 +00:00
|
|
|
}
|
|
|
|
|
2016-07-20 17:16:54 +00:00
|
|
|
// console.log("ShowUrlPreview for %s is %s", this.state.room.roomId, this.state.showUrlPreview);
|
2016-02-10 18:27:40 +00:00
|
|
|
var messagePanel = (
|
2016-03-08 12:16:34 +00:00
|
|
|
<TimelinePanel ref={this._gatherTimelinePanelRef}
|
2017-08-30 12:32:07 +00:00
|
|
|
timelineSet={this.state.room.getUnfilteredTimelineSet()}
|
|
|
|
showReadReceipts={!UserSettingsStore.getSyncedSetting('hideReadReceipts', false)}
|
|
|
|
manageReadReceipts={true}
|
|
|
|
manageReadMarkers={true}
|
|
|
|
hidden={hideMessagePanel}
|
|
|
|
highlightedEventId={highlightedEventId}
|
|
|
|
eventId={this.state.initialEventId}
|
|
|
|
eventPixelOffset={this.state.initialEventPixelOffset}
|
|
|
|
onScroll={ this.onMessageListScroll }
|
|
|
|
onReadMarkerUpdated={ this._updateTopUnreadMessagesBar }
|
|
|
|
showUrlPreview = { this.state.showUrlPreview }
|
|
|
|
opacity={ this.props.opacity }
|
|
|
|
className="mx_RoomView_messagePanel"
|
2016-02-10 18:27:40 +00:00
|
|
|
/>);
|
2016-02-08 16:43:08 +00:00
|
|
|
|
2016-02-24 17:26:34 +00:00
|
|
|
var topUnreadMessagesBar = null;
|
|
|
|
if (this.state.showTopUnreadMessagesBar) {
|
|
|
|
var TopUnreadMessagesBar = sdk.getComponent('rooms.TopUnreadMessagesBar');
|
|
|
|
topUnreadMessagesBar = (
|
2016-04-13 10:17:04 +00:00
|
|
|
<div className="mx_RoomView_topUnreadMessagesBar mx_fadable" style={{ opacity: this.props.opacity }}>
|
2016-02-24 17:26:34 +00:00
|
|
|
<TopUnreadMessagesBar
|
|
|
|
onScrollUpClick={this.jumpToReadMarker}
|
|
|
|
onCloseClick={this.forgetReadMarker}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-01-23 15:01:39 +00:00
|
|
|
let statusBarAreaClass = "mx_RoomView_statusArea mx_fadable";
|
2017-01-26 18:07:42 +00:00
|
|
|
if (isStatusAreaExpanded) {
|
2017-01-23 15:01:39 +00:00
|
|
|
statusBarAreaClass += " mx_RoomView_statusArea_expanded";
|
|
|
|
}
|
2016-02-24 17:26:34 +00:00
|
|
|
|
2016-02-08 16:43:08 +00:00
|
|
|
return (
|
|
|
|
<div className={ "mx_RoomView" + (inCall ? " mx_RoomView_inCall" : "") } ref="roomView">
|
|
|
|
<RoomHeader ref="header" room={this.state.room} searchInfo={searchInfo}
|
2016-03-02 11:56:18 +00:00
|
|
|
oobData={this.props.oobData}
|
2016-02-08 16:43:08 +00:00
|
|
|
editing={this.state.editingRoomSettings}
|
2016-04-12 17:01:49 +00:00
|
|
|
saving={this.state.uploadingRoomSettings}
|
2017-05-11 16:35:06 +00:00
|
|
|
inRoom={myMember && myMember.membership === 'join'}
|
2016-09-13 18:00:35 +00:00
|
|
|
collapsedRhs={ this.props.collapsedRhs }
|
2016-02-08 16:43:08 +00:00
|
|
|
onSearchClick={this.onSearchClick}
|
|
|
|
onSettingsClick={this.onSettingsClick}
|
|
|
|
onSaveClick={this.onSettingsSaveClick}
|
2017-05-30 10:20:41 +00:00
|
|
|
onCancelClick={(aux && !hideCancel) ? this.onCancelClick : null}
|
|
|
|
onForgetClick={(myMember && myMember.membership === "leave") ? this.onForgetClick : null}
|
|
|
|
onLeaveClick={(myMember && myMember.membership === "join") ? this.onLeaveClick : null}
|
|
|
|
/>
|
2016-02-23 15:46:27 +00:00
|
|
|
{ auxPanel }
|
2016-02-24 17:26:34 +00:00
|
|
|
{ topUnreadMessagesBar }
|
2016-02-08 16:43:08 +00:00
|
|
|
{ messagePanel }
|
|
|
|
{ searchResultsPanel }
|
2017-01-23 15:01:39 +00:00
|
|
|
<div className={statusBarAreaClass} style={{opacity: this.props.opacity}}>
|
2016-02-08 16:43:08 +00:00
|
|
|
<div className="mx_RoomView_statusAreaBox">
|
|
|
|
<div className="mx_RoomView_statusAreaBox_line"></div>
|
|
|
|
{ statusBar }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{ messageComposer }
|
|
|
|
</div>
|
|
|
|
);
|
2015-11-30 17:15:57 +00:00
|
|
|
},
|
|
|
|
});
|