2016-02-10 21:27:40 +03:00
|
|
|
/*
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
2017-04-26 19:26:53 +03:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2019-03-12 12:37:00 +03:00
|
|
|
Copyright 2019 New Vector Ltd
|
2020-01-28 23:36:24 +03:00
|
|
|
Copyright 2019-2020 The Matrix.org Foundation C.I.C.
|
2016-02-10 21:27:40 +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.
|
|
|
|
*/
|
|
|
|
|
2017-10-29 10:43:52 +03:00
|
|
|
import SettingsStore from "../../settings/SettingsStore";
|
2019-12-08 15:16:17 +03:00
|
|
|
import React, {createRef} from 'react';
|
2019-08-30 12:34:59 +03:00
|
|
|
import ReactDOM from "react-dom";
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2019-12-21 00:41:07 +03:00
|
|
|
import {EventTimeline} from "matrix-js-sdk";
|
|
|
|
import * as Matrix from "matrix-js-sdk";
|
2017-05-25 13:39:08 +03:00
|
|
|
import { _t } from '../../languageHandler';
|
2019-12-21 00:13:46 +03:00
|
|
|
import {MatrixClientPeg} from "../../MatrixClientPeg";
|
2019-12-20 04:19:56 +03:00
|
|
|
import * as ObjectUtils from "../../ObjectUtils";
|
2019-12-21 00:41:07 +03:00
|
|
|
import UserActivity from "../../UserActivity";
|
|
|
|
import Modal from "../../Modal";
|
2020-05-14 05:41:41 +03:00
|
|
|
import dis from "../../dispatcher/dispatcher";
|
2019-12-21 00:41:07 +03:00
|
|
|
import * as sdk from "../../index";
|
2020-01-10 00:15:38 +03:00
|
|
|
import { Key } from '../../Keyboard';
|
2018-12-11 18:19:22 +03:00
|
|
|
import Timer from '../../utils/Timer';
|
2019-07-12 18:40:51 +03:00
|
|
|
import shouldHideEvent from '../../shouldHideEvent';
|
2019-06-12 19:52:34 +03:00
|
|
|
import EditorStateTransfer from '../../utils/EditorStateTransfer';
|
2019-12-21 00:43:06 +03:00
|
|
|
import {haveTileForEvent} from "../views/rooms/EventTile";
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const PAGINATE_SIZE = 20;
|
|
|
|
const INITIAL_SIZE = 20;
|
2018-12-11 18:19:22 +03:00
|
|
|
const READ_RECEIPT_INTERVAL_MS = 500;
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const DEBUG = false;
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2019-05-01 16:30:25 +03:00
|
|
|
let debuglog = function() {};
|
2016-02-10 21:27:40 +03:00
|
|
|
if (DEBUG) {
|
|
|
|
// using bind means that we get to keep useful line numbers in the console
|
2019-05-01 16:30:25 +03:00
|
|
|
debuglog = console.log.bind(console);
|
2016-02-10 21:27:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Component which shows the event timeline in a room view.
|
|
|
|
*
|
|
|
|
* Also responsible for handling and sending read receipts.
|
|
|
|
*/
|
2020-08-29 14:14:16 +03:00
|
|
|
class TimelinePanel extends React.Component {
|
|
|
|
static propTypes = {
|
2016-09-06 02:59:17 +03:00
|
|
|
// The js-sdk EventTimelineSet object for the timeline sequence we are
|
|
|
|
// representing. This may or may not have a room, depending on what it's
|
|
|
|
// a timeline representing. If it has a room, we maintain RRs etc for
|
|
|
|
// that room.
|
2017-12-26 04:03:18 +03:00
|
|
|
timelineSet: PropTypes.object.isRequired,
|
2016-09-06 02:59:17 +03:00
|
|
|
|
2017-12-26 04:03:18 +03:00
|
|
|
showReadReceipts: PropTypes.bool,
|
2016-09-06 02:59:17 +03:00
|
|
|
// Enable managing RRs and RMs. These require the timelineSet to have a room.
|
2017-12-26 04:03:18 +03:00
|
|
|
manageReadReceipts: PropTypes.bool,
|
|
|
|
manageReadMarkers: PropTypes.bool,
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2016-02-11 18:38:13 +03:00
|
|
|
// true to give the component a 'display: none' style.
|
2017-12-26 04:03:18 +03:00
|
|
|
hidden: PropTypes.bool,
|
2016-02-10 21:27:40 +03:00
|
|
|
|
|
|
|
// ID of an event to highlight. If undefined, no event will be highlighted.
|
|
|
|
// typically this will be either 'eventId' or undefined.
|
2017-12-26 04:03:18 +03:00
|
|
|
highlightedEventId: PropTypes.string,
|
2016-02-10 21:27:40 +03:00
|
|
|
|
|
|
|
// id of an event to jump to. If not given, will go to the end of the
|
|
|
|
// live timeline.
|
2017-12-26 04:03:18 +03:00
|
|
|
eventId: PropTypes.string,
|
2016-02-10 21:27:40 +03:00
|
|
|
|
|
|
|
// where to position the event given by eventId, in pixels from the
|
2016-02-24 20:26:34 +03:00
|
|
|
// bottom of the viewport. If not given, will try to put the event
|
2016-03-10 19:44:50 +03:00
|
|
|
// half way down the viewport.
|
2017-12-26 04:03:18 +03:00
|
|
|
eventPixelOffset: PropTypes.number,
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2016-07-18 03:35:42 +03:00
|
|
|
// Should we show URL Previews
|
2017-12-26 04:03:18 +03:00
|
|
|
showUrlPreview: PropTypes.bool,
|
2016-07-18 03:35:42 +03:00
|
|
|
|
2016-02-10 21:27:40 +03:00
|
|
|
// callback which is called when the panel is scrolled.
|
2017-12-26 04:03:18 +03:00
|
|
|
onScroll: PropTypes.func,
|
2016-02-24 20:26:34 +03:00
|
|
|
|
|
|
|
// callback which is called when the read-up-to mark is updated.
|
2017-12-26 04:03:18 +03:00
|
|
|
onReadMarkerUpdated: PropTypes.func,
|
2016-04-12 19:18:32 +03:00
|
|
|
|
2020-01-17 12:04:53 +03:00
|
|
|
// callback which is called when we wish to paginate the timeline
|
|
|
|
// window.
|
|
|
|
onPaginationRequest: PropTypes.func,
|
|
|
|
|
2016-08-24 17:48:19 +03:00
|
|
|
// maximum number of events to show in a timeline
|
2017-12-26 04:03:18 +03:00
|
|
|
timelineCap: PropTypes.number,
|
2016-09-07 04:16:29 +03:00
|
|
|
|
|
|
|
// classname to use for the messagepanel
|
2017-12-26 04:03:18 +03:00
|
|
|
className: PropTypes.string,
|
2016-09-11 04:14:27 +03:00
|
|
|
|
|
|
|
// shape property to be passed to EventTiles
|
2017-12-26 04:03:18 +03:00
|
|
|
tileShape: PropTypes.string,
|
2017-02-02 19:32:10 +03:00
|
|
|
|
2020-09-09 11:50:08 +03:00
|
|
|
// placeholder to use if the timeline is empty
|
|
|
|
empty: PropTypes.node,
|
2019-05-21 19:23:19 +03:00
|
|
|
|
|
|
|
// whether to show reactions for an event
|
|
|
|
showReactions: PropTypes.bool,
|
2020-05-26 17:56:16 +03:00
|
|
|
|
|
|
|
// whether to use the irc layout
|
|
|
|
useIRCLayout: PropTypes.bool,
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2016-02-24 20:26:34 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
// a map from room id to read marker event timestamp
|
|
|
|
static roomReadMarkerTsMap = {};
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
static defaultProps = {
|
|
|
|
// By default, disable the timelineCap in favour of unpaginating based on
|
|
|
|
// event tile heights. (See _unpaginateEvents)
|
|
|
|
timelineCap: Number.MAX_VALUE,
|
|
|
|
className: 'mx_RoomView_messagePanel',
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
debuglog("TimelinePanel: mounting");
|
|
|
|
|
|
|
|
this.lastRRSentEventId = undefined;
|
|
|
|
this.lastRMSentEventId = undefined;
|
|
|
|
|
|
|
|
this._messagePanel = createRef();
|
|
|
|
|
2016-09-06 02:59:17 +03:00
|
|
|
// XXX: we could track RM per TimelineSet rather than per Room.
|
|
|
|
// but for now we just do it per room for simplicity.
|
2017-04-12 17:05:39 +03:00
|
|
|
let initialReadMarker = null;
|
2016-09-06 02:59:17 +03:00
|
|
|
if (this.props.manageReadMarkers) {
|
2017-04-18 16:44:43 +03:00
|
|
|
const readmarker = this.props.timelineSet.room.getAccountData('m.fully_read');
|
2017-05-20 00:45:56 +03:00
|
|
|
if (readmarker) {
|
2017-04-18 17:13:05 +03:00
|
|
|
initialReadMarker = readmarker.getContent().event_id;
|
2017-04-12 17:05:39 +03:00
|
|
|
} else {
|
|
|
|
initialReadMarker = this._getCurrentReadReceipt();
|
|
|
|
}
|
2016-09-06 02:59:17 +03:00
|
|
|
}
|
2016-02-24 20:26:34 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
this.state = {
|
2016-02-10 21:27:40 +03:00
|
|
|
events: [],
|
2019-07-05 16:37:19 +03:00
|
|
|
liveEvents: [],
|
2016-02-10 21:27:40 +03:00
|
|
|
timelineLoading: true, // track whether our room timeline is loading
|
2016-04-08 16:58:24 +03:00
|
|
|
|
2020-01-28 23:36:24 +03:00
|
|
|
// the index of the first event that is to be shown
|
|
|
|
firstVisibleEventIndex: 0,
|
|
|
|
|
2016-04-08 16:58:24 +03:00
|
|
|
// canBackPaginate == false may mean:
|
|
|
|
//
|
|
|
|
// * we haven't (successfully) loaded the timeline yet, or:
|
|
|
|
//
|
|
|
|
// * we have got to the point where the room was created, or:
|
|
|
|
//
|
|
|
|
// * the server indicated that there were no more visible events
|
|
|
|
// (normally implying we got to the start of the room), or:
|
|
|
|
//
|
|
|
|
// * we gave up asking the server for more events
|
|
|
|
canBackPaginate: false,
|
|
|
|
|
|
|
|
// canForwardPaginate == false may mean:
|
|
|
|
//
|
|
|
|
// * we haven't (successfully) loaded the timeline yet
|
|
|
|
//
|
|
|
|
// * we have got to the end of time and are now tracking the live
|
|
|
|
// timeline, or:
|
|
|
|
//
|
|
|
|
// * the server indicated that there were no more visible events
|
|
|
|
// (not sure if this ever happens when we're not at the live
|
|
|
|
// timeline), or:
|
|
|
|
//
|
|
|
|
// * we are looking at some historical point, but gave up asking
|
|
|
|
// the server for more events
|
|
|
|
canForwardPaginate: false,
|
2016-02-24 20:26:34 +03:00
|
|
|
|
|
|
|
// start with the read-marker visible, so that we see its animated
|
2016-09-06 02:59:17 +03:00
|
|
|
// disappearance when switching into the room.
|
2016-02-24 20:26:34 +03:00
|
|
|
readMarkerVisible: true,
|
|
|
|
|
|
|
|
readMarkerEventId: initialReadMarker,
|
2016-02-24 16:38:55 +03:00
|
|
|
|
|
|
|
backPaginating: false,
|
|
|
|
forwardPaginating: false,
|
2017-04-26 19:26:53 +03:00
|
|
|
|
|
|
|
// cache of matrixClient.getSyncState() (but from the 'sync' event)
|
2017-05-05 12:48:54 +03:00
|
|
|
clientSyncState: MatrixClientPeg.get().getSyncState(),
|
2017-05-20 00:45:56 +03:00
|
|
|
|
|
|
|
// should the event tiles have twelve hour times
|
2017-10-29 10:43:52 +03:00
|
|
|
isTwelveHour: SettingsStore.getValue("showTwelveHourTimestamps"),
|
2017-05-27 02:14:16 +03:00
|
|
|
|
|
|
|
// always show timestamps on event tiles?
|
2017-10-29 10:43:52 +03:00
|
|
|
alwaysShowTimestamps: SettingsStore.getValue("alwaysShowTimestamps"),
|
2019-09-17 19:34:30 +03:00
|
|
|
|
|
|
|
// how long to show the RM for when it's visible in the window
|
|
|
|
readMarkerInViewThresholdMs: SettingsStore.getValue("readMarkerInViewThresholdMs"),
|
|
|
|
|
|
|
|
// how long to show the RM for when it's scrolled off-screen
|
|
|
|
readMarkerOutOfViewThresholdMs: SettingsStore.getValue("readMarkerOutOfViewThresholdMs"),
|
2016-02-10 21:27:40 +03:00
|
|
|
};
|
2018-12-11 18:19:22 +03:00
|
|
|
|
2016-02-10 21:27:40 +03:00
|
|
|
this.dispatcherRef = dis.register(this.onAction);
|
|
|
|
MatrixClientPeg.get().on("Room.timeline", this.onRoomTimeline);
|
2016-02-25 21:28:07 +03:00
|
|
|
MatrixClientPeg.get().on("Room.timelineReset", this.onRoomTimelineReset);
|
2016-02-23 15:56:54 +03:00
|
|
|
MatrixClientPeg.get().on("Room.redaction", this.onRoomRedaction);
|
2019-06-04 19:44:48 +03:00
|
|
|
// same event handler as Room.redaction as for both we just do forceUpdate
|
|
|
|
MatrixClientPeg.get().on("Room.redactionCancelled", this.onRoomRedaction);
|
2016-03-04 17:47:11 +03:00
|
|
|
MatrixClientPeg.get().on("Room.receipt", this.onRoomReceipt);
|
2016-03-09 18:45:56 +03:00
|
|
|
MatrixClientPeg.get().on("Room.localEchoUpdated", this.onLocalEchoUpdated);
|
2017-04-12 17:05:39 +03:00
|
|
|
MatrixClientPeg.get().on("Room.accountData", this.onAccountData);
|
2017-08-24 13:35:01 +03:00
|
|
|
MatrixClientPeg.get().on("Event.decrypted", this.onEventDecrypted);
|
2019-05-16 16:43:32 +03:00
|
|
|
MatrixClientPeg.get().on("Event.replaced", this.onEventReplaced);
|
2017-04-26 19:26:53 +03:00
|
|
|
MatrixClientPeg.get().on("sync", this.onSync);
|
2020-08-29 14:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: [REACT-WARNING] Move into constructor
|
2020-08-29 14:57:11 +03:00
|
|
|
// eslint-disable-next-line camelcase
|
2020-08-29 14:51:37 +03:00
|
|
|
UNSAFE_componentWillMount() {
|
|
|
|
if (this.props.manageReadReceipts) {
|
|
|
|
this.updateReadReceiptOnUserActivity();
|
|
|
|
}
|
|
|
|
if (this.props.manageReadMarkers) {
|
|
|
|
this.updateReadMarkerOnUserActivity();
|
|
|
|
}
|
2016-02-10 21:27:40 +03:00
|
|
|
|
|
|
|
this._initTimeline(this.props);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2020-04-01 23:35:39 +03:00
|
|
|
// TODO: [REACT-WARNING] Replace with appropriate lifecycle event
|
2020-08-29 14:57:11 +03:00
|
|
|
// eslint-disable-next-line camelcase
|
2020-08-29 14:14:16 +03:00
|
|
|
UNSAFE_componentWillReceiveProps(newProps) {
|
2016-09-06 02:59:17 +03:00
|
|
|
if (newProps.timelineSet !== this.props.timelineSet) {
|
|
|
|
// throw new Error("changing timelineSet on a TimelinePanel is not supported");
|
2016-02-27 01:38:05 +03:00
|
|
|
|
|
|
|
// regrettably, this does happen; in particular, when joining a
|
|
|
|
// room with /join. In that case, there are two Rooms in
|
|
|
|
// circulation - one which is created by the MatrixClient.joinRoom
|
|
|
|
// call and used to create the RoomView, and a second which is
|
|
|
|
// created by the sync loop once the room comes back down the /sync
|
|
|
|
// pipe. Once the latter happens, our room is replaced with the new one.
|
|
|
|
//
|
|
|
|
// for now, just warn about this. But we're going to end up paginating
|
|
|
|
// both rooms separately, and it's all bad.
|
2016-09-06 02:59:17 +03:00
|
|
|
console.warn("Replacing timelineSet on a TimelinePanel - confusion may ensue");
|
2016-02-10 21:27:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (newProps.eventId != this.props.eventId) {
|
|
|
|
console.log("TimelinePanel switching to eventId " + newProps.eventId +
|
|
|
|
" (was " + this.props.eventId + ")");
|
|
|
|
return this._initTimeline(newProps);
|
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
2016-04-19 20:29:25 +03:00
|
|
|
if (!ObjectUtils.shallowEqual(this.props, nextProps)) {
|
|
|
|
if (DEBUG) {
|
|
|
|
console.group("Timeline.shouldComponentUpdate: props change");
|
|
|
|
console.log("props before:", this.props);
|
|
|
|
console.log("props after:", nextProps);
|
|
|
|
console.groupEnd();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ObjectUtils.shallowEqual(this.state, nextState)) {
|
|
|
|
if (DEBUG) {
|
|
|
|
console.group("Timeline.shouldComponentUpdate: state change");
|
|
|
|
console.log("state before:", this.state);
|
|
|
|
console.log("state after:", nextState);
|
|
|
|
console.groupEnd();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2016-03-08 01:27:35 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
componentWillUnmount() {
|
2016-02-10 21:27:40 +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;
|
2018-12-11 18:19:22 +03:00
|
|
|
if (this._readReceiptActivityTimer) {
|
|
|
|
this._readReceiptActivityTimer.abort();
|
|
|
|
this._readReceiptActivityTimer = null;
|
|
|
|
}
|
|
|
|
if (this._readMarkerActivityTimer) {
|
|
|
|
this._readMarkerActivityTimer.abort();
|
|
|
|
this._readMarkerActivityTimer = null;
|
|
|
|
}
|
2016-02-10 21:27:40 +03:00
|
|
|
|
|
|
|
dis.unregister(this.dispatcherRef);
|
2016-02-16 02:04:21 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const client = MatrixClientPeg.get();
|
2016-02-16 02:04:21 +03:00
|
|
|
if (client) {
|
|
|
|
client.removeListener("Room.timeline", this.onRoomTimeline);
|
2016-02-25 21:28:07 +03:00
|
|
|
client.removeListener("Room.timelineReset", this.onRoomTimelineReset);
|
2016-02-23 15:56:54 +03:00
|
|
|
client.removeListener("Room.redaction", this.onRoomRedaction);
|
2019-06-04 19:44:48 +03:00
|
|
|
client.removeListener("Room.redactionCancelled", this.onRoomRedaction);
|
2016-03-04 17:47:11 +03:00
|
|
|
client.removeListener("Room.receipt", this.onRoomReceipt);
|
2016-03-09 18:45:56 +03:00
|
|
|
client.removeListener("Room.localEchoUpdated", this.onLocalEchoUpdated);
|
2017-04-19 12:18:25 +03:00
|
|
|
client.removeListener("Room.accountData", this.onAccountData);
|
2017-08-24 13:35:01 +03:00
|
|
|
client.removeListener("Event.decrypted", this.onEventDecrypted);
|
2019-05-16 16:43:32 +03:00
|
|
|
client.removeListener("Event.replaced", this.onEventReplaced);
|
2017-04-26 19:26:53 +03:00
|
|
|
client.removeListener("sync", this.onSync);
|
2016-02-16 02:04:21 +03:00
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
onMessageListUnfillRequest = (backwards, scrollToken) => {
|
2017-04-05 19:52:05 +03:00
|
|
|
// If backwards, unpaginate from the back (i.e. the start of the timeline)
|
2017-10-11 19:56:17 +03:00
|
|
|
const dir = backwards ? EventTimeline.BACKWARDS : EventTimeline.FORWARDS;
|
2016-11-16 17:25:52 +03:00
|
|
|
debuglog("TimelinePanel: unpaginating events in direction", dir);
|
|
|
|
|
2017-04-04 15:28:26 +03:00
|
|
|
// All tiles are inserted by MessagePanel to have a scrollToken === eventId, and
|
|
|
|
// this particular event should be the first or last to be unpaginated.
|
2017-10-11 19:56:17 +03:00
|
|
|
const eventId = scrollToken;
|
2016-11-16 17:25:52 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const marker = this.state.events.findIndex(
|
2016-11-16 17:25:52 +03:00
|
|
|
(ev) => {
|
|
|
|
return ev.getId() === eventId;
|
2017-10-11 19:56:17 +03:00
|
|
|
},
|
2016-11-16 17:25:52 +03:00
|
|
|
);
|
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const count = backwards ? marker + 1 : this.state.events.length - marker;
|
2016-11-16 17:25:52 +03:00
|
|
|
|
|
|
|
if (count > 0) {
|
|
|
|
debuglog("TimelinePanel: Unpaginating", count, "in direction", dir);
|
2016-11-16 19:10:23 +03:00
|
|
|
this._timelineWindow.unpaginate(count, backwards);
|
2016-11-18 14:15:14 +03:00
|
|
|
|
|
|
|
// We can now paginate in the unpaginated direction
|
|
|
|
const canPaginateKey = (backwards) ? 'canBackPaginate' : 'canForwardPaginate';
|
2020-01-28 23:36:24 +03:00
|
|
|
const { events, liveEvents, firstVisibleEventIndex } = this._getEvents();
|
2016-11-16 17:25:52 +03:00
|
|
|
this.setState({
|
2016-11-18 14:15:14 +03:00
|
|
|
[canPaginateKey]: true,
|
2019-07-05 16:37:19 +03:00
|
|
|
events,
|
|
|
|
liveEvents,
|
2020-01-28 23:36:24 +03:00
|
|
|
firstVisibleEventIndex,
|
2016-11-16 17:25:52 +03:00
|
|
|
});
|
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-11-16 17:25:52 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
onPaginationRequest = (timelineWindow, direction, size) => {
|
2020-01-17 12:04:53 +03:00
|
|
|
if (this.props.onPaginationRequest) {
|
|
|
|
return this.props.onPaginationRequest(timelineWindow, direction, size);
|
|
|
|
} else {
|
|
|
|
return timelineWindow.paginate(direction, size);
|
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2020-01-17 12:04:53 +03:00
|
|
|
|
2016-02-10 21:27:40 +03:00
|
|
|
// set off a pagination request.
|
2020-08-29 14:14:16 +03:00
|
|
|
onMessageListFillRequest = backwards => {
|
2018-01-12 21:17:03 +03:00
|
|
|
if (!this._shouldPaginate()) return Promise.resolve(false);
|
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const dir = backwards ? EventTimeline.BACKWARDS : EventTimeline.FORWARDS;
|
|
|
|
const canPaginateKey = backwards ? 'canBackPaginate' : 'canForwardPaginate';
|
|
|
|
const paginatingKey = backwards ? 'backPaginating' : 'forwardPaginating';
|
2016-04-08 16:58:24 +03:00
|
|
|
|
|
|
|
if (!this.state[canPaginateKey]) {
|
|
|
|
debuglog("TimelinePanel: have given up", dir, "paginating this timeline");
|
2017-07-12 16:02:00 +03:00
|
|
|
return Promise.resolve(false);
|
2016-04-08 16:58:24 +03:00
|
|
|
}
|
|
|
|
|
2017-11-16 16:19:36 +03:00
|
|
|
if (!this._timelineWindow.canPaginate(dir)) {
|
2016-04-08 16:58:24 +03:00
|
|
|
debuglog("TimelinePanel: can't", dir, "paginate any further");
|
|
|
|
this.setState({[canPaginateKey]: false});
|
2017-07-12 16:02:00 +03:00
|
|
|
return Promise.resolve(false);
|
2016-02-10 21:27:40 +03:00
|
|
|
}
|
2016-04-08 16:58:24 +03:00
|
|
|
|
2020-01-28 23:36:24 +03:00
|
|
|
if (backwards && this.state.firstVisibleEventIndex !== 0) {
|
|
|
|
debuglog("TimelinePanel: won't", dir, "paginate past first visible event");
|
|
|
|
return Promise.resolve(false);
|
|
|
|
}
|
|
|
|
|
2016-02-10 21:27:40 +03:00
|
|
|
debuglog("TimelinePanel: Initiating paginate; backwards:"+backwards);
|
2016-04-08 16:58:24 +03:00
|
|
|
this.setState({[paginatingKey]: true});
|
2016-02-24 16:38:55 +03:00
|
|
|
|
2020-01-17 12:04:53 +03:00
|
|
|
return this.onPaginationRequest(this._timelineWindow, dir, PAGINATE_SIZE).then((r) => {
|
2016-02-29 17:09:42 +03:00
|
|
|
if (this.unmounted) { return; }
|
|
|
|
|
2016-02-10 21:27:40 +03:00
|
|
|
debuglog("TimelinePanel: paginate complete backwards:"+backwards+"; success:"+r);
|
2016-04-21 15:37:31 +03:00
|
|
|
|
2020-01-28 23:36:24 +03:00
|
|
|
const { events, liveEvents, firstVisibleEventIndex } = this._getEvents();
|
2017-10-11 19:56:17 +03:00
|
|
|
const newState = {
|
2016-04-08 16:58:24 +03:00
|
|
|
[paginatingKey]: false,
|
|
|
|
[canPaginateKey]: r,
|
2019-07-05 16:37:19 +03:00
|
|
|
events,
|
|
|
|
liveEvents,
|
2020-01-28 23:36:24 +03:00
|
|
|
firstVisibleEventIndex,
|
2016-04-21 15:37:31 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// moving the window in this direction may mean that we can now
|
|
|
|
// paginate in the other where we previously could not.
|
2017-10-11 19:56:17 +03:00
|
|
|
const otherDirection = backwards ? EventTimeline.FORWARDS : EventTimeline.BACKWARDS;
|
|
|
|
const canPaginateOtherWayKey = backwards ? 'canForwardPaginate' : 'canBackPaginate';
|
2016-04-21 15:37:31 +03:00
|
|
|
if (!this.state[canPaginateOtherWayKey] &&
|
|
|
|
this._timelineWindow.canPaginate(otherDirection)) {
|
|
|
|
debuglog('TimelinePanel: can now', otherDirection, 'paginate again');
|
|
|
|
newState[canPaginateOtherWayKey] = true;
|
|
|
|
}
|
|
|
|
|
2017-08-30 21:14:26 +03:00
|
|
|
// Don't resolve until the setState has completed: we need to let
|
2017-08-30 23:44:10 +03:00
|
|
|
// the component update before we consider the pagination completed,
|
2017-08-30 21:14:26 +03:00
|
|
|
// otherwise we'll end up paginating in all the history the js-sdk
|
|
|
|
// has in memory because we never gave the component a chance to scroll
|
|
|
|
// itself into the right place
|
2017-08-30 23:44:10 +03:00
|
|
|
return new Promise((resolve) => {
|
|
|
|
this.setState(newState, () => {
|
2020-01-28 23:36:24 +03:00
|
|
|
// we can continue paginating in the given direction if:
|
|
|
|
// - _timelineWindow.paginate says we can
|
|
|
|
// - we're paginating forwards, or we won't be trying to
|
|
|
|
// paginate backwards past the first visible event
|
|
|
|
resolve(r && (!backwards || firstVisibleEventIndex === 0));
|
2017-08-30 23:44:10 +03:00
|
|
|
});
|
2017-08-30 21:14:26 +03:00
|
|
|
});
|
2016-02-10 21:27:40 +03:00
|
|
|
});
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
onMessageListScroll = e => {
|
2016-02-24 20:26:34 +03:00
|
|
|
if (this.props.onScroll) {
|
2017-07-11 19:21:41 +03:00
|
|
|
this.props.onScroll(e);
|
2016-02-24 20:26:34 +03:00
|
|
|
}
|
|
|
|
|
2016-09-06 02:59:17 +03:00
|
|
|
if (this.props.manageReadMarkers) {
|
2018-12-11 18:19:22 +03:00
|
|
|
const rmPosition = this.getReadMarkerPosition();
|
2016-09-06 02:59:17 +03:00
|
|
|
// we hide the read marker when it first comes onto the screen, but if
|
|
|
|
// it goes back off the top of the screen (presumably because the user
|
|
|
|
// clicks on the 'jump to bottom' button), we need to re-enable it.
|
2018-12-11 18:19:22 +03:00
|
|
|
if (rmPosition < 0) {
|
2016-09-06 02:59:17 +03:00
|
|
|
this.setState({readMarkerVisible: true});
|
|
|
|
}
|
2018-12-11 18:19:22 +03:00
|
|
|
|
|
|
|
// if read marker position goes between 0 and -1/1,
|
|
|
|
// (and user is active), switch timeout
|
|
|
|
const timeout = this._readMarkerTimeout(rmPosition);
|
|
|
|
// NO-OP when timeout already has set to the given value
|
|
|
|
this._readMarkerActivityTimer.changeTimeout(timeout);
|
2016-02-24 20:26:34 +03:00
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-02-24 20:26:34 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
onAction = payload => {
|
2018-12-11 18:19:22 +03:00
|
|
|
if (payload.action === 'ignore_state_changed') {
|
|
|
|
this.forceUpdate();
|
2016-02-10 21:27:40 +03:00
|
|
|
}
|
2019-05-06 18:41:15 +03:00
|
|
|
if (payload.action === "edit_event") {
|
2019-06-12 19:52:34 +03:00
|
|
|
const editState = payload.event ? new EditorStateTransfer(payload.event) : null;
|
|
|
|
this.setState({editState}, () => {
|
2019-12-08 15:16:17 +03:00
|
|
|
if (payload.event && this._messagePanel.current) {
|
|
|
|
this._messagePanel.current.scrollToEventIfNeeded(
|
2019-05-24 16:38:51 +03:00
|
|
|
payload.event.getId(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2019-05-06 18:41:15 +03:00
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
onRoomTimeline = (ev, room, toStartOfTimeline, removed, data) => {
|
2016-09-09 00:48:44 +03:00
|
|
|
// ignore events for other timeline sets
|
|
|
|
if (data.timeline.getTimelineSet() !== this.props.timelineSet) return;
|
2016-02-10 21:27:40 +03: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;
|
|
|
|
|
2019-12-08 15:16:17 +03:00
|
|
|
if (!this._messagePanel.current) return;
|
2016-02-24 20:26:34 +03:00
|
|
|
|
2019-12-08 15:16:17 +03:00
|
|
|
if (!this._messagePanel.current.getScrollState().stuckAtBottom) {
|
2016-04-19 20:29:25 +03:00
|
|
|
// we won't load this event now, because we don't want to push any
|
|
|
|
// events off the other end of the timeline. But we need to note
|
|
|
|
// that we can now paginate.
|
|
|
|
this.setState({canForwardPaginate: true});
|
|
|
|
return;
|
|
|
|
}
|
2016-03-01 13:41:56 +03:00
|
|
|
|
|
|
|
// tell the timeline window to try to advance itself, but not to make
|
|
|
|
// an http request to do so.
|
2016-02-10 21:27:40 +03:00
|
|
|
//
|
2016-03-01 13:41:56 +03:00
|
|
|
// we deliberately avoid going via the ScrollPanel for this call - the
|
|
|
|
// ScrollPanel might already have an active pagination promise, which
|
|
|
|
// will fail, but would stop us passing the pagination request to the
|
2016-04-19 20:29:25 +03:00
|
|
|
// timeline window.
|
2016-03-01 13:41:56 +03:00
|
|
|
//
|
|
|
|
// see https://github.com/vector-im/vector-web/issues/1035
|
2019-11-18 13:03:05 +03:00
|
|
|
this._timelineWindow.paginate(EventTimeline.FORWARDS, 1, false).then(() => {
|
2016-04-20 01:45:51 +03:00
|
|
|
if (this.unmounted) { return; }
|
|
|
|
|
2020-01-28 23:36:24 +03:00
|
|
|
const { events, liveEvents, firstVisibleEventIndex } = this._getEvents();
|
2019-07-05 16:37:19 +03:00
|
|
|
const lastLiveEvent = liveEvents[liveEvents.length - 1];
|
2016-04-20 01:45:51 +03:00
|
|
|
|
2019-07-05 16:37:19 +03:00
|
|
|
const updatedState = {
|
|
|
|
events,
|
|
|
|
liveEvents,
|
2020-01-28 23:36:24 +03:00
|
|
|
firstVisibleEventIndex,
|
2019-07-05 16:37:19 +03:00
|
|
|
};
|
2016-04-20 01:45:51 +03:00
|
|
|
|
2019-05-01 16:30:25 +03:00
|
|
|
let callRMUpdated;
|
2016-09-06 02:59:17 +03:00
|
|
|
if (this.props.manageReadMarkers) {
|
|
|
|
// when a new event arrives when the user is not watching the
|
|
|
|
// window, but the window is in its auto-scroll mode, make sure the
|
|
|
|
// read marker is visible.
|
|
|
|
//
|
|
|
|
// We ignore events we have sent ourselves; we don't want to see the
|
|
|
|
// read-marker when a remote echo of an event we have just sent takes
|
2019-03-12 12:37:38 +03:00
|
|
|
// more than the timeout on userActiveRecently.
|
2016-09-06 02:59:17 +03:00
|
|
|
//
|
2017-10-11 19:56:17 +03:00
|
|
|
const myUserId = MatrixClientPeg.get().credentials.userId;
|
|
|
|
const sender = ev.sender ? ev.sender.userId : null;
|
2019-05-01 16:30:25 +03:00
|
|
|
callRMUpdated = false;
|
2019-03-12 12:37:55 +03:00
|
|
|
if (sender != myUserId && !UserActivity.sharedInstance().userActiveRecently()) {
|
2016-09-06 02:59:17 +03:00
|
|
|
updatedState.readMarkerVisible = true;
|
2019-07-05 16:37:19 +03:00
|
|
|
} else if (lastLiveEvent && this.getReadMarkerPosition() === 0) {
|
2016-09-06 02:59:17 +03:00
|
|
|
// we know we're stuckAtBottom, so we can advance the RM
|
|
|
|
// immediately, to save a later render cycle
|
2017-04-12 17:12:37 +03:00
|
|
|
|
2019-07-05 16:37:19 +03:00
|
|
|
this._setReadMarker(lastLiveEvent.getId(), lastLiveEvent.getTs(), true);
|
2016-09-06 02:59:17 +03:00
|
|
|
updatedState.readMarkerVisible = false;
|
2019-07-05 16:37:19 +03:00
|
|
|
updatedState.readMarkerEventId = lastLiveEvent.getId();
|
2019-01-21 19:35:40 +03:00
|
|
|
callRMUpdated = true;
|
2016-09-06 02:59:17 +03:00
|
|
|
}
|
2016-04-20 01:45:51 +03:00
|
|
|
}
|
|
|
|
|
2019-01-21 19:35:40 +03:00
|
|
|
this.setState(updatedState, () => {
|
2019-12-08 15:16:17 +03:00
|
|
|
this._messagePanel.current.updateTimelineMinHeight();
|
2019-01-21 19:35:40 +03:00
|
|
|
if (callRMUpdated) {
|
|
|
|
this.props.onReadMarkerUpdated();
|
|
|
|
}
|
|
|
|
});
|
2016-04-20 01:45:51 +03:00
|
|
|
});
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
onRoomTimelineReset = (room, timelineSet) => {
|
2016-09-10 12:46:30 +03:00
|
|
|
if (timelineSet !== this.props.timelineSet) return;
|
2016-02-25 21:28:07 +03:00
|
|
|
|
2019-12-08 15:16:17 +03:00
|
|
|
if (this._messagePanel.current && this._messagePanel.current.isAtBottom()) {
|
2016-02-25 21:28:07 +03:00
|
|
|
this._loadTimeline();
|
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-02-25 21:28:07 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
canResetTimeline = () => this._messagePanel.current && this._messagePanel.current.isAtBottom();
|
2017-03-22 18:06:52 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
onRoomRedaction = (ev, room) => {
|
2016-02-23 15:56:54 +03:00
|
|
|
if (this.unmounted) return;
|
|
|
|
|
|
|
|
// ignore events for other rooms
|
2016-09-06 02:59:17 +03:00
|
|
|
if (room !== this.props.timelineSet.room) return;
|
2016-02-23 15:56:54 +03:00
|
|
|
|
|
|
|
// we could skip an update if the event isn't in our timeline,
|
|
|
|
// but that's probably an early optimisation.
|
|
|
|
this.forceUpdate();
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-02-23 15:56:54 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
onEventReplaced = (replacedEvent, room) => {
|
2019-05-14 17:20:34 +03:00
|
|
|
if (this.unmounted) return;
|
|
|
|
|
|
|
|
// ignore events for other rooms
|
|
|
|
if (room !== this.props.timelineSet.room) return;
|
|
|
|
|
|
|
|
// we could skip an update if the event isn't in our timeline,
|
|
|
|
// but that's probably an early optimisation.
|
2019-05-15 13:49:43 +03:00
|
|
|
this.forceUpdate();
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2019-05-14 17:20:34 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
onRoomReceipt = (ev, room) => {
|
2016-03-04 17:47:11 +03:00
|
|
|
if (this.unmounted) return;
|
|
|
|
|
|
|
|
// ignore events for other rooms
|
2016-09-06 02:59:17 +03:00
|
|
|
if (room !== this.props.timelineSet.room) return;
|
2016-03-04 17:47:11 +03:00
|
|
|
|
|
|
|
this.forceUpdate();
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-03-04 17:47:11 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
onLocalEchoUpdated = (ev, room, oldEventId) => {
|
2016-03-09 18:45:56 +03:00
|
|
|
if (this.unmounted) return;
|
|
|
|
|
|
|
|
// ignore events for other rooms
|
2016-09-06 02:59:17 +03:00
|
|
|
if (room !== this.props.timelineSet.room) return;
|
2016-03-09 18:45:56 +03:00
|
|
|
|
2016-03-18 01:26:06 +03:00
|
|
|
this._reloadEvents();
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-03-09 18:45:56 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
onAccountData = (ev, room) => {
|
2017-04-12 17:05:39 +03:00
|
|
|
if (this.unmounted) return;
|
|
|
|
|
|
|
|
// ignore events for other rooms
|
|
|
|
if (room !== this.props.timelineSet.room) return;
|
|
|
|
|
2017-04-18 16:44:43 +03:00
|
|
|
if (ev.getType() !== "m.fully_read") return;
|
2017-04-12 17:05:39 +03:00
|
|
|
|
2017-04-19 12:27:43 +03:00
|
|
|
// XXX: roomReadMarkerTsMap not updated here so it is now inconsistent. Replace
|
|
|
|
// this mechanism of determining where the RM is relative to the view-port with
|
|
|
|
// one supported by the server (the client needs more than an event ID).
|
2017-04-12 17:05:39 +03:00
|
|
|
this.setState({
|
2017-04-19 12:20:53 +03:00
|
|
|
readMarkerEventId: ev.getContent().event_id,
|
2017-04-12 17:05:39 +03:00
|
|
|
}, this.props.onReadMarkerUpdated);
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-03-09 18:45:56 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
onEventDecrypted = ev => {
|
2019-05-22 12:08:16 +03:00
|
|
|
// Can be null for the notification timeline, etc.
|
|
|
|
if (!this.props.timelineSet.room) return;
|
|
|
|
|
2017-08-24 13:35:01 +03:00
|
|
|
// Need to update as we don't display event tiles for events that
|
|
|
|
// haven't yet been decrypted. The event will have just been updated
|
|
|
|
// in place so we just need to re-render.
|
|
|
|
// TODO: We should restrict this to only events in our timeline,
|
|
|
|
// but possibly the event tile itself should just update when this
|
|
|
|
// happens to save us re-rendering the whole timeline.
|
2017-08-24 13:55:39 +03:00
|
|
|
if (ev.getRoomId() === this.props.timelineSet.room.roomId) {
|
|
|
|
this.forceUpdate();
|
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2017-08-24 13:35:01 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
onSync = (state, prevState, data) => {
|
2017-04-26 19:26:53 +03:00
|
|
|
this.setState({clientSyncState: state});
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2017-04-26 19:26:53 +03:00
|
|
|
|
2018-12-11 18:19:22 +03:00
|
|
|
_readMarkerTimeout(readMarkerPosition) {
|
|
|
|
return readMarkerPosition === 0 ?
|
2019-09-17 19:34:30 +03:00
|
|
|
this.state.readMarkerInViewThresholdMs :
|
|
|
|
this.state.readMarkerOutOfViewThresholdMs;
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2018-12-11 18:19:22 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
async updateReadMarkerOnUserActivity() {
|
2018-12-11 18:19:22 +03:00
|
|
|
const initialTimeout = this._readMarkerTimeout(this.getReadMarkerPosition());
|
|
|
|
this._readMarkerActivityTimer = new Timer(initialTimeout);
|
|
|
|
|
|
|
|
while (this._readMarkerActivityTimer) { //unset on unmount
|
2019-03-12 12:37:00 +03:00
|
|
|
UserActivity.sharedInstance().timeWhileActiveRecently(this._readMarkerActivityTimer);
|
2018-12-11 18:19:22 +03:00
|
|
|
try {
|
|
|
|
await this._readMarkerActivityTimer.finished();
|
2019-05-01 16:30:25 +03:00
|
|
|
} catch (e) { continue; /* aborted */ }
|
2018-12-11 18:19:22 +03:00
|
|
|
// outside of try/catch to not swallow errors
|
|
|
|
this.updateReadMarker();
|
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2018-12-11 18:19:22 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
async updateReadReceiptOnUserActivity() {
|
2018-12-11 18:19:22 +03:00
|
|
|
this._readReceiptActivityTimer = new Timer(READ_RECEIPT_INTERVAL_MS);
|
|
|
|
while (this._readReceiptActivityTimer) { //unset on unmount
|
2019-03-12 12:37:00 +03:00
|
|
|
UserActivity.sharedInstance().timeWhileActiveNow(this._readReceiptActivityTimer);
|
2018-12-11 18:19:22 +03:00
|
|
|
try {
|
|
|
|
await this._readReceiptActivityTimer.finished();
|
2019-05-01 16:30:25 +03:00
|
|
|
} catch (e) { continue; /* aborted */ }
|
2018-12-11 18:19:22 +03:00
|
|
|
// outside of try/catch to not swallow errors
|
|
|
|
this.sendReadReceipt();
|
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2018-12-11 18:19:22 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
sendReadReceipt = () => {
|
2019-02-08 19:44:03 +03:00
|
|
|
if (SettingsStore.getValue("lowBandwidth")) return;
|
|
|
|
|
2019-12-08 15:16:17 +03:00
|
|
|
if (!this._messagePanel.current) return;
|
2016-09-06 02:59:17 +03:00
|
|
|
if (!this.props.manageReadReceipts) return;
|
2016-10-26 15:19:36 +03:00
|
|
|
// This happens on user_activity_end which is delayed, and it's
|
|
|
|
// very possible have logged out within that timeframe, so check
|
|
|
|
// we still have a client.
|
2017-05-04 18:42:41 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
2017-05-09 19:36:19 +03:00
|
|
|
// if no client or client is guest don't send RR or RM
|
2017-05-04 18:42:41 +03:00
|
|
|
if (!cli || cli.isGuest()) return;
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2017-05-11 11:31:59 +03:00
|
|
|
let shouldSendRR = true;
|
2017-05-09 19:36:19 +03:00
|
|
|
|
2017-05-11 11:31:59 +03:00
|
|
|
const currentRREventId = this._getCurrentReadReceipt(true);
|
|
|
|
const currentRREventIndex = this._indexForEventId(currentRREventId);
|
2016-02-10 21:27:40 +03:00
|
|
|
// We want to avoid sending out read receipts when we are looking at
|
2017-05-09 19:36:19 +03:00
|
|
|
// events in the past which are before the latest RR.
|
2016-02-10 21:27:40 +03:00
|
|
|
//
|
|
|
|
// For now, let's apply a heuristic: if (a) the event corresponding to
|
|
|
|
// the latest RR (either from the server, or sent by ourselves) doesn't
|
|
|
|
// appear in our timeline, and (b) we could forward-paginate the event
|
|
|
|
// timeline, then don't send any more RRs.
|
|
|
|
//
|
|
|
|
// This isn't watertight, as we could be looking at a section of
|
|
|
|
// timeline which is *after* the latest RR (so we should actually send
|
|
|
|
// RRs) - but that is a bit of a niche case. It will sort itself out when
|
|
|
|
// the user eventually hits the live timeline.
|
|
|
|
//
|
2017-05-11 11:31:59 +03:00
|
|
|
if (currentRREventId && currentRREventIndex === null &&
|
2016-02-10 21:27:40 +03:00
|
|
|
this._timelineWindow.canPaginate(EventTimeline.FORWARDS)) {
|
2017-05-11 11:31:59 +03:00
|
|
|
shouldSendRR = false;
|
2016-02-10 21:27:40 +03:00
|
|
|
}
|
|
|
|
|
2017-05-10 16:51:47 +03:00
|
|
|
const lastReadEventIndex = this._getLastDisplayedEventIndex({
|
|
|
|
ignoreOwn: true,
|
2016-02-24 20:26:34 +03:00
|
|
|
});
|
2017-05-09 19:36:19 +03:00
|
|
|
if (lastReadEventIndex === null) {
|
2017-05-11 11:31:59 +03:00
|
|
|
shouldSendRR = false;
|
2017-05-09 19:36:19 +03:00
|
|
|
}
|
2017-05-10 16:51:47 +03:00
|
|
|
let lastReadEvent = this.state.events[lastReadEventIndex];
|
2017-05-11 11:31:59 +03:00
|
|
|
shouldSendRR = shouldSendRR &&
|
2017-05-10 16:55:58 +03:00
|
|
|
// Only send a RR if the last read event is ahead in the timeline relative to
|
2017-05-10 16:42:06 +03:00
|
|
|
// the current RR event.
|
2017-05-11 11:31:59 +03:00
|
|
|
lastReadEventIndex > currentRREventIndex &&
|
2017-05-10 16:42:06 +03:00
|
|
|
// Only send a RR if the last RR set != the one we would send
|
2017-05-11 11:20:34 +03:00
|
|
|
this.lastRRSentEventId != lastReadEvent.getId();
|
2017-05-09 19:36:19 +03:00
|
|
|
|
2017-05-10 16:42:06 +03:00
|
|
|
// Only send a RM if the last RM sent != the one we would send
|
2017-05-11 11:31:59 +03:00
|
|
|
const shouldSendRM =
|
2017-05-10 16:51:47 +03:00
|
|
|
this.lastRMSentEventId != this.state.readMarkerEventId;
|
2016-02-10 21:27:40 +03:00
|
|
|
|
|
|
|
// we also remember the last read receipt we sent to avoid spamming the
|
|
|
|
// same one at the server repeatedly
|
2017-05-11 11:31:59 +03:00
|
|
|
if (shouldSendRR || shouldSendRM) {
|
|
|
|
if (shouldSendRR) {
|
2017-05-11 11:20:34 +03:00
|
|
|
this.lastRRSentEventId = lastReadEvent.getId();
|
2017-05-10 16:48:01 +03:00
|
|
|
} else {
|
|
|
|
lastReadEvent = null;
|
|
|
|
}
|
2017-05-10 16:51:47 +03:00
|
|
|
this.lastRMSentEventId = this.state.readMarkerEventId;
|
2017-04-12 17:05:39 +03:00
|
|
|
|
2019-09-06 22:02:18 +03:00
|
|
|
const roomId = this.props.timelineSet.room.roomId;
|
|
|
|
const hiddenRR = !SettingsStore.getValue("sendReadReceipts", roomId);
|
2019-09-06 05:30:19 +03:00
|
|
|
|
2017-05-09 19:36:19 +03:00
|
|
|
debuglog('TimelinePanel: Sending Read Markers for ',
|
2017-05-09 12:03:40 +03:00
|
|
|
this.props.timelineSet.room.roomId,
|
|
|
|
'rm', this.state.readMarkerEventId,
|
2017-05-10 16:48:01 +03:00
|
|
|
lastReadEvent ? 'rr ' + lastReadEvent.getId() : '',
|
2019-09-06 05:30:19 +03:00
|
|
|
' hidden:' + hiddenRR,
|
2017-05-09 12:03:40 +03:00
|
|
|
);
|
2017-04-19 12:14:57 +03:00
|
|
|
MatrixClientPeg.get().setRoomReadMarkers(
|
2017-04-12 17:05:39 +03:00
|
|
|
this.props.timelineSet.room.roomId,
|
|
|
|
this.state.readMarkerEventId,
|
2017-05-10 16:48:01 +03:00
|
|
|
lastReadEvent, // Could be null, in which case no RR is sent
|
2019-09-06 05:30:19 +03:00
|
|
|
{hidden: hiddenRR},
|
2017-04-20 16:34:59 +03:00
|
|
|
).catch((e) => {
|
|
|
|
// /read_markers API is not implemented on this HS, fallback to just RR
|
2017-05-10 16:48:01 +03:00
|
|
|
if (e.errcode === 'M_UNRECOGNIZED' && lastReadEvent) {
|
2017-04-20 16:34:59 +03:00
|
|
|
return MatrixClientPeg.get().sendReadReceipt(
|
2017-05-10 16:48:01 +03:00
|
|
|
lastReadEvent,
|
2019-09-06 05:30:19 +03:00
|
|
|
{hidden: hiddenRR},
|
2019-07-05 16:37:19 +03:00
|
|
|
).catch((e) => {
|
|
|
|
console.error(e);
|
2017-05-11 11:20:34 +03:00
|
|
|
this.lastRRSentEventId = undefined;
|
2017-04-20 16:34:59 +03:00
|
|
|
});
|
2019-07-05 16:37:19 +03:00
|
|
|
} else {
|
|
|
|
console.error(e);
|
2017-04-20 16:34:59 +03:00
|
|
|
}
|
2016-02-10 21:27:40 +03:00
|
|
|
// it failed, so allow retries next time the user is active
|
2017-05-11 11:20:34 +03:00
|
|
|
this.lastRRSentEventId = undefined;
|
2017-05-10 16:51:47 +03:00
|
|
|
this.lastRMSentEventId = undefined;
|
2016-02-10 21:27:40 +03:00
|
|
|
});
|
2017-03-29 16:08:31 +03:00
|
|
|
|
|
|
|
// do a quick-reset of our unreadNotificationCount to avoid having
|
|
|
|
// to wait from the remote echo from the homeserver.
|
2017-03-29 16:12:50 +03:00
|
|
|
// we only do this if we're right at the end, because we're just assuming
|
|
|
|
// that sending an RR for the latest message will set our notif counter
|
|
|
|
// to zero: it may not do this if we send an RR for somewhere before the end.
|
|
|
|
if (this.isAtEndOfLiveTimeline()) {
|
|
|
|
this.props.timelineSet.room.setUnreadNotificationCount('total', 0);
|
|
|
|
this.props.timelineSet.room.setUnreadNotificationCount('highlight', 0);
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'on_room_read',
|
2018-03-14 17:29:55 +03:00
|
|
|
roomId: this.props.timelineSet.room.roomId,
|
2017-03-29 16:12:50 +03:00
|
|
|
});
|
|
|
|
}
|
2016-02-10 21:27:40 +03:00
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2016-02-24 20:26:34 +03:00
|
|
|
// if the read marker is on the screen, we can now assume we've caught up to the end
|
|
|
|
// of the screen, so move the marker down to the bottom of the screen.
|
2020-08-29 14:14:16 +03:00
|
|
|
updateReadMarker = () => {
|
2016-09-06 02:59:17 +03:00
|
|
|
if (!this.props.manageReadMarkers) return;
|
2018-12-11 18:19:22 +03:00
|
|
|
if (this.getReadMarkerPosition() === 1) {
|
|
|
|
// the read marker is at an event below the viewport,
|
|
|
|
// we don't want to rewind it.
|
2016-02-24 20:26:34 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// move the RM to *after* the message at the bottom of the screen. This
|
|
|
|
// avoids a problem whereby we never advance the RM if there is a huge
|
|
|
|
// message which doesn't fit on the screen.
|
2017-10-11 19:56:17 +03:00
|
|
|
const lastDisplayedIndex = this._getLastDisplayedEventIndex({
|
2016-02-24 20:26:34 +03:00
|
|
|
allowPartial: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (lastDisplayedIndex === null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-11 19:56:17 +03:00
|
|
|
const lastDisplayedEvent = this.state.events[lastDisplayedIndex];
|
2016-02-24 20:26:34 +03:00
|
|
|
this._setReadMarker(lastDisplayedEvent.getId(),
|
|
|
|
lastDisplayedEvent.getTs());
|
|
|
|
|
|
|
|
// the read-marker should become invisible, so that if the user scrolls
|
|
|
|
// down, they don't see it.
|
2017-11-16 16:19:36 +03:00
|
|
|
if (this.state.readMarkerVisible) {
|
2016-02-24 20:26:34 +03:00
|
|
|
this.setState({
|
|
|
|
readMarkerVisible: false,
|
|
|
|
});
|
|
|
|
}
|
2020-06-12 16:17:06 +03:00
|
|
|
|
|
|
|
// Send the updated read marker (along with read receipt) to the server
|
|
|
|
this.sendReadReceipt();
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-02-24 20:26:34 +03:00
|
|
|
|
2016-03-22 19:34:12 +03:00
|
|
|
|
|
|
|
// advance the read marker past any events we sent ourselves.
|
2020-08-29 14:14:16 +03:00
|
|
|
_advanceReadMarkerPastMyEvents() {
|
2016-09-06 02:59:17 +03:00
|
|
|
if (!this.props.manageReadMarkers) return;
|
|
|
|
|
2019-07-05 16:37:19 +03:00
|
|
|
// we call `_timelineWindow.getEvents()` rather than using
|
|
|
|
// `this.state.liveEvents`, because React batches the update to the
|
|
|
|
// latter, so it may not have been updated yet.
|
2017-10-11 19:56:17 +03:00
|
|
|
const events = this._timelineWindow.getEvents();
|
2016-03-22 19:34:12 +03:00
|
|
|
|
|
|
|
// first find where the current RM is
|
2019-05-01 16:30:25 +03:00
|
|
|
let i;
|
|
|
|
for (i = 0; i < events.length; i++) {
|
2017-01-20 17:22:27 +03:00
|
|
|
if (events[i].getId() == this.state.readMarkerEventId) {
|
2016-03-22 19:34:12 +03:00
|
|
|
break;
|
2017-01-20 17:22:27 +03:00
|
|
|
}
|
2016-03-22 19:34:12 +03:00
|
|
|
}
|
|
|
|
if (i >= events.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now think about advancing it
|
2017-10-11 19:56:17 +03:00
|
|
|
const myUserId = MatrixClientPeg.get().credentials.userId;
|
2016-03-23 12:49:22 +03:00
|
|
|
for (i++; i < events.length; i++) {
|
2019-05-01 16:30:25 +03:00
|
|
|
const ev = events[i];
|
2016-03-22 19:34:12 +03:00
|
|
|
if (!ev.sender || ev.sender.userId != myUserId) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// i is now the first unread message which we didn't send ourselves.
|
|
|
|
i--;
|
|
|
|
|
2019-05-01 16:30:25 +03:00
|
|
|
const ev = events[i];
|
2016-03-22 19:34:12 +03:00
|
|
|
this._setReadMarker(ev.getId(), ev.getTs());
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2016-03-22 19:34:12 +03:00
|
|
|
|
2016-02-10 21:27:40 +03:00
|
|
|
/* jump down to the bottom of this room, where new events are arriving
|
|
|
|
*/
|
2020-08-29 14:14:16 +03:00
|
|
|
jumpToLiveTimeline = () => {
|
2016-02-10 21:27:40 +03:00
|
|
|
// if we can't forward-paginate the existing timeline, then there
|
|
|
|
// is no point reloading it - just jump straight to the bottom.
|
|
|
|
//
|
|
|
|
// Otherwise, reload the timeline rather than trying to paginate
|
|
|
|
// through all of space-time.
|
|
|
|
if (this._timelineWindow.canPaginate(EventTimeline.FORWARDS)) {
|
|
|
|
this._loadTimeline();
|
|
|
|
} else {
|
2019-12-08 15:16:17 +03:00
|
|
|
if (this._messagePanel.current) {
|
|
|
|
this._messagePanel.current.scrollToBottom();
|
2016-02-10 21:27:40 +03:00
|
|
|
}
|
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2016-03-10 19:44:50 +03:00
|
|
|
/* scroll to show the read-up-to marker. We put it 1/3 of the way down
|
|
|
|
* the container.
|
2016-02-24 20:26:34 +03:00
|
|
|
*/
|
2020-08-29 14:14:16 +03:00
|
|
|
jumpToReadMarker = () => {
|
2016-09-06 02:59:17 +03:00
|
|
|
if (!this.props.manageReadMarkers) return;
|
2019-12-08 15:16:17 +03:00
|
|
|
if (!this._messagePanel.current) return;
|
2016-09-06 02:59:17 +03:00
|
|
|
if (!this.state.readMarkerEventId) return;
|
2016-03-09 10:52:45 +03:00
|
|
|
|
|
|
|
// we may not have loaded the event corresponding to the read-marker
|
|
|
|
// into the _timelineWindow. In that case, attempts to scroll to it
|
|
|
|
// will fail.
|
|
|
|
//
|
|
|
|
// a quick way to figure out if we've loaded the relevant event is
|
|
|
|
// simply to check if the messagepanel knows where the read-marker is.
|
2019-12-08 15:16:17 +03:00
|
|
|
const ret = this._messagePanel.current.getReadMarkerPosition();
|
2016-03-09 10:52:45 +03:00
|
|
|
if (ret !== null) {
|
|
|
|
// The messagepanel knows where the RM is, so we must have loaded
|
|
|
|
// the relevant event.
|
2019-12-08 15:16:17 +03:00
|
|
|
this._messagePanel.current.scrollToEvent(this.state.readMarkerEventId,
|
2016-03-10 19:44:50 +03:00
|
|
|
0, 1/3);
|
2016-03-31 02:51:23 +03:00
|
|
|
return;
|
2016-03-09 10:52:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Looks like we haven't loaded the event corresponding to the read-marker.
|
|
|
|
// As with jumpToLiveTimeline, we want to reload the timeline around the
|
|
|
|
// read-marker.
|
2016-03-10 19:44:50 +03:00
|
|
|
this._loadTimeline(this.state.readMarkerEventId, 0, 1/3);
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-02-24 20:26:34 +03:00
|
|
|
|
|
|
|
/* update the read-up-to marker to match the read receipt
|
|
|
|
*/
|
2020-08-29 14:14:16 +03:00
|
|
|
forgetReadMarker = () => {
|
2016-09-06 02:59:17 +03:00
|
|
|
if (!this.props.manageReadMarkers) return;
|
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const rmId = this._getCurrentReadReceipt();
|
2016-02-24 20:26:34 +03:00
|
|
|
|
|
|
|
// see if we know the timestamp for the rr event
|
2017-10-11 19:56:17 +03:00
|
|
|
const tl = this.props.timelineSet.getTimelineForEvent(rmId);
|
|
|
|
let rmTs;
|
2016-02-24 20:26:34 +03:00
|
|
|
if (tl) {
|
2017-10-11 19:56:17 +03:00
|
|
|
const event = tl.getEvents().find((e) => { return e.getId() == rmId; });
|
2016-02-24 20:26:34 +03:00
|
|
|
if (event) {
|
|
|
|
rmTs = event.getTs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._setReadMarker(rmId, rmTs);
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-02-24 20:26:34 +03:00
|
|
|
|
2016-02-10 21:27:40 +03:00
|
|
|
/* return true if the content is fully scrolled down and we are
|
|
|
|
* at the end of the live timeline.
|
|
|
|
*/
|
2020-08-29 14:14:16 +03:00
|
|
|
isAtEndOfLiveTimeline = () => {
|
2019-12-08 15:16:17 +03:00
|
|
|
return this._messagePanel.current
|
|
|
|
&& this._messagePanel.current.isAtBottom()
|
2016-02-10 21:27:40 +03:00
|
|
|
&& this._timelineWindow
|
|
|
|
&& !this._timelineWindow.canPaginate(EventTimeline.FORWARDS);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2016-02-10 21:27:40 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* get the current scroll state. See ScrollPanel.getScrollState for
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* returns null if we are not mounted.
|
|
|
|
*/
|
2020-08-29 14:14:16 +03:00
|
|
|
getScrollState = () => {
|
2019-12-08 15:16:17 +03:00
|
|
|
if (!this._messagePanel.current) { return null; }
|
|
|
|
return this._messagePanel.current.getScrollState();
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2016-02-24 20:26:34 +03:00
|
|
|
// returns one of:
|
|
|
|
//
|
|
|
|
// null: there is no read marker
|
|
|
|
// -1: read marker is above the window
|
|
|
|
// 0: read marker is visible
|
|
|
|
// +1: read marker is below the window
|
2020-08-29 14:14:16 +03:00
|
|
|
getReadMarkerPosition = () => {
|
2016-09-06 02:59:17 +03:00
|
|
|
if (!this.props.manageReadMarkers) return null;
|
2019-12-08 15:16:17 +03:00
|
|
|
if (!this._messagePanel.current) return null;
|
2016-09-06 02:59:17 +03:00
|
|
|
|
2019-12-08 15:16:17 +03:00
|
|
|
const ret = this._messagePanel.current.getReadMarkerPosition();
|
2016-02-24 20:26:34 +03:00
|
|
|
if (ret !== null) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the messagePanel doesn't know where the read marker is.
|
|
|
|
// if we know the timestamp of the read marker, make a guess based on that.
|
2017-04-12 17:09:56 +03:00
|
|
|
const rmTs = TimelinePanel.roomReadMarkerTsMap[this.props.timelineSet.room.roomId];
|
2016-02-27 02:05:41 +03:00
|
|
|
if (rmTs && this.state.events.length > 0) {
|
2016-02-24 20:26:34 +03:00
|
|
|
if (rmTs < this.state.events[0].getTs()) {
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-02-24 20:26:34 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
canJumpToReadMarker = () => {
|
2017-04-27 18:52:40 +03:00
|
|
|
// 1. Do not show jump bar if neither the RM nor the RR are set.
|
|
|
|
// 3. We want to show the bar if the read-marker is off the top of the screen.
|
|
|
|
// 4. Also, if pos === null, the event might not be paginated - show the unread bar
|
2017-04-27 16:03:54 +03:00
|
|
|
const pos = this.getReadMarkerPosition();
|
2018-12-11 18:19:22 +03:00
|
|
|
const ret = this.state.readMarkerEventId !== null && // 1.
|
2017-04-27 18:52:40 +03:00
|
|
|
(pos < 0 || pos === null); // 3., 4.
|
2018-12-11 18:19:22 +03:00
|
|
|
return ret;
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2017-04-27 16:03:54 +03:00
|
|
|
|
2019-05-01 16:30:25 +03:00
|
|
|
/*
|
2016-04-05 15:14:11 +03:00
|
|
|
* called by the parent component when PageUp/Down/etc is pressed.
|
|
|
|
*
|
|
|
|
* We pass it down to the scroll panel.
|
|
|
|
*/
|
2020-08-29 14:14:16 +03:00
|
|
|
handleScrollKey = ev => {
|
2019-12-08 15:16:17 +03:00
|
|
|
if (!this._messagePanel.current) { return; }
|
2016-04-05 15:14:11 +03:00
|
|
|
|
|
|
|
// jump to the live timeline on ctrl-end, rather than the end of the
|
|
|
|
// timeline window.
|
2019-12-16 20:14:03 +03:00
|
|
|
if (ev.ctrlKey && !ev.shiftKey && !ev.altKey && !ev.metaKey && ev.key === Key.END) {
|
2016-04-05 15:14:11 +03:00
|
|
|
this.jumpToLiveTimeline();
|
|
|
|
} else {
|
2019-12-08 15:16:17 +03:00
|
|
|
this._messagePanel.current.handleScrollKey(ev);
|
2016-04-05 15:14:11 +03:00
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-04-05 15:14:11 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
_initTimeline(props) {
|
2017-10-11 19:56:17 +03:00
|
|
|
const initialEvent = props.eventId;
|
|
|
|
const pixelOffset = props.eventPixelOffset;
|
2016-03-10 19:44:50 +03:00
|
|
|
|
|
|
|
// if a pixelOffset is given, it is relative to the bottom of the
|
|
|
|
// container. If not, put the event in the middle of the container.
|
2017-10-11 19:56:17 +03:00
|
|
|
let offsetBase = 1;
|
2016-03-10 19:44:50 +03:00
|
|
|
if (pixelOffset == null) {
|
|
|
|
offsetBase = 0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._loadTimeline(initialEvent, pixelOffset, offsetBase);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2016-02-10 21:27:40 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* (re)-load the event timeline, and initialise the scroll state, centered
|
|
|
|
* around the given event.
|
|
|
|
*
|
|
|
|
* @param {string?} eventId the event to focus on. If undefined, will
|
|
|
|
* scroll to the bottom of the room.
|
|
|
|
*
|
|
|
|
* @param {number?} pixelOffset offset to position the given event at
|
2016-03-10 19:44:50 +03:00
|
|
|
* (pixels from the offsetBase). If omitted, defaults to 0.
|
|
|
|
*
|
|
|
|
* @param {number?} offsetBase the reference point for the pixelOffset. 0
|
|
|
|
* means the top of the container, 1 means the bottom, and fractional
|
|
|
|
* values mean somewhere in the middle. If omitted, it defaults to 0.
|
2016-02-10 21:27:40 +03:00
|
|
|
*
|
|
|
|
* returns a promise which will resolve when the load completes.
|
|
|
|
*/
|
2020-08-29 14:14:16 +03:00
|
|
|
_loadTimeline(eventId, pixelOffset, offsetBase) {
|
2016-02-26 15:25:46 +03:00
|
|
|
this._timelineWindow = new Matrix.TimelineWindow(
|
2016-09-06 02:59:17 +03:00
|
|
|
MatrixClientPeg.get(), this.props.timelineSet,
|
2016-08-24 17:48:19 +03:00
|
|
|
{windowLimit: this.props.timelineCap});
|
2016-02-26 15:25:46 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const onLoaded = () => {
|
2019-02-22 18:23:05 +03:00
|
|
|
// clear the timeline min-height when
|
|
|
|
// (re)loading the timeline
|
2019-12-08 15:16:17 +03:00
|
|
|
if (this._messagePanel.current) {
|
|
|
|
this._messagePanel.current.onTimelineReset();
|
2019-02-22 18:23:05 +03:00
|
|
|
}
|
2016-03-18 01:26:06 +03:00
|
|
|
this._reloadEvents();
|
2016-02-26 15:25:46 +03:00
|
|
|
|
2016-03-22 19:34:12 +03:00
|
|
|
// If we switched away from the room while there were pending
|
|
|
|
// outgoing events, the read-marker will be before those events.
|
|
|
|
// We need to skip over any which have subsequently been sent.
|
|
|
|
this._advanceReadMarkerPastMyEvents();
|
|
|
|
|
2016-04-08 16:58:24 +03:00
|
|
|
this.setState({
|
|
|
|
canBackPaginate: this._timelineWindow.canPaginate(EventTimeline.BACKWARDS),
|
|
|
|
canForwardPaginate: this._timelineWindow.canPaginate(EventTimeline.FORWARDS),
|
|
|
|
timelineLoading: false,
|
|
|
|
}, () => {
|
2016-02-10 21:27:40 +03:00
|
|
|
// initialise the scroll state of the message panel
|
2019-12-08 15:16:17 +03:00
|
|
|
if (!this._messagePanel.current) {
|
2016-03-18 01:26:06 +03:00
|
|
|
// this shouldn't happen - we know we're mounted because
|
|
|
|
// we're in a setState callback, and we know
|
|
|
|
// timelineLoading is now false, so render() should have
|
|
|
|
// mounted the message panel.
|
2016-02-10 21:27:40 +03:00
|
|
|
console.log("can't initialise scroll state because " +
|
|
|
|
"messagePanel didn't load");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (eventId) {
|
2019-12-08 15:16:17 +03:00
|
|
|
this._messagePanel.current.scrollToEvent(eventId, pixelOffset,
|
2016-03-10 19:44:50 +03:00
|
|
|
offsetBase);
|
2016-02-10 21:27:40 +03:00
|
|
|
} else {
|
2019-12-08 15:16:17 +03:00
|
|
|
this._messagePanel.current.scrollToBottom();
|
2016-02-10 21:27:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
this.sendReadReceipt();
|
|
|
|
});
|
2016-02-26 15:25:46 +03:00
|
|
|
};
|
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const onError = (error) => {
|
2019-05-01 16:30:25 +03:00
|
|
|
this.setState({ timelineLoading: false });
|
2017-06-08 00:41:02 +03:00
|
|
|
console.error(
|
|
|
|
`Error loading timeline panel at ${eventId}: ${error}`,
|
|
|
|
);
|
2017-10-11 19:56:17 +03:00
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
2016-03-21 20:29:33 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
let onFinished;
|
2016-03-21 20:29:33 +03:00
|
|
|
|
|
|
|
// if we were given an event ID, then when the user closes the
|
|
|
|
// dialog, let's jump to the end of the timeline. If we weren't,
|
|
|
|
// something has gone badly wrong and rather than causing a loop of
|
|
|
|
// undismissable dialogs, let's just give up.
|
|
|
|
if (eventId) {
|
|
|
|
onFinished = () => {
|
|
|
|
// go via the dispatcher so that the URL is updated
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
2017-03-30 19:18:22 +03:00
|
|
|
room_id: this.props.timelineSet.room.roomId,
|
2016-03-21 20:29:33 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2019-05-01 16:30:25 +03:00
|
|
|
let message;
|
|
|
|
if (error.errcode == 'M_FORBIDDEN') {
|
|
|
|
message = _t(
|
|
|
|
"Tried to load a specific point in this room's timeline, but you " +
|
|
|
|
"do not have permission to view the message in question.",
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
message = _t(
|
|
|
|
"Tried to load a specific point in this room's timeline, but was " +
|
|
|
|
"unable to find it.",
|
|
|
|
);
|
|
|
|
}
|
2017-08-10 17:17:52 +03:00
|
|
|
Modal.createTrackedDialog('Failed to load timeline position', '', ErrorDialog, {
|
2017-05-23 17:16:31 +03:00
|
|
|
title: _t("Failed to load timeline position"),
|
2016-03-22 20:33:46 +03:00
|
|
|
description: message,
|
2016-03-21 20:29:33 +03:00
|
|
|
onFinished: onFinished,
|
|
|
|
});
|
2017-01-20 17:22:27 +03:00
|
|
|
};
|
2016-03-21 20:29:33 +03:00
|
|
|
|
|
|
|
// if we already have the event in question, TimelineWindow.load
|
|
|
|
// returns a resolved promise.
|
|
|
|
//
|
|
|
|
// In this situation, we don't really want to defer the update of the
|
|
|
|
// state to the next event loop, because it makes room-switching feel
|
|
|
|
// quite slow. So we detect that situation and shortcut straight to
|
|
|
|
// calling _reloadEvents and updating the state.
|
|
|
|
|
2019-11-14 16:52:17 +03:00
|
|
|
const timeline = this.props.timelineSet.getTimelineForEvent(eventId);
|
|
|
|
if (timeline) {
|
|
|
|
// This is a hot-path optimization by skipping a promise tick
|
|
|
|
// by repeating a no-op sync branch in TimelineSet.getTimelineForEvent & MatrixClient.getEventTimeline
|
2019-11-18 22:00:22 +03:00
|
|
|
this._timelineWindow.load(eventId, INITIAL_SIZE); // in this branch this method will happen in sync time
|
2016-02-26 15:25:46 +03:00
|
|
|
onLoaded();
|
2016-03-21 20:29:33 +03:00
|
|
|
} else {
|
2019-11-14 16:52:17 +03:00
|
|
|
const prom = this._timelineWindow.load(eventId, INITIAL_SIZE);
|
2016-03-21 20:29:33 +03:00
|
|
|
this.setState({
|
|
|
|
events: [],
|
2019-07-05 16:37:19 +03:00
|
|
|
liveEvents: [],
|
2016-04-08 16:58:24 +03:00
|
|
|
canBackPaginate: false,
|
|
|
|
canForwardPaginate: false,
|
2016-03-21 20:29:33 +03:00
|
|
|
timelineLoading: true,
|
|
|
|
});
|
2019-11-14 16:52:17 +03:00
|
|
|
prom.then(onLoaded, onError);
|
2016-02-26 15:25:46 +03:00
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2016-03-18 01:26:06 +03:00
|
|
|
// handle the completion of a timeline load or localEchoUpdate, by
|
|
|
|
// reloading the events from the timelinewindow and pending event list into
|
|
|
|
// the state.
|
2020-08-29 14:14:16 +03:00
|
|
|
_reloadEvents() {
|
2016-02-10 21:27:40 +03:00
|
|
|
// we might have switched rooms since the load started - just bin
|
|
|
|
// the results if so.
|
|
|
|
if (this.unmounted) return;
|
|
|
|
|
2019-07-05 16:37:19 +03:00
|
|
|
this.setState(this._getEvents());
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2016-04-20 01:45:51 +03:00
|
|
|
|
|
|
|
// get the list of events from the timeline window and the pending event list
|
2020-08-29 14:14:16 +03:00
|
|
|
_getEvents() {
|
2017-10-11 19:56:17 +03:00
|
|
|
const events = this._timelineWindow.getEvents();
|
2020-01-28 23:36:24 +03:00
|
|
|
const firstVisibleEventIndex = this._checkForPreJoinUISI(events);
|
2016-03-18 01:26:06 +03:00
|
|
|
|
2019-07-05 16:37:19 +03:00
|
|
|
// Hold onto the live events separately. The read receipt and read marker
|
|
|
|
// should use this list, so that they don't advance into pending events.
|
|
|
|
const liveEvents = [...events];
|
|
|
|
|
2016-03-18 01:26:06 +03:00
|
|
|
// if we're at the end of the live timeline, append the pending events
|
|
|
|
if (!this._timelineWindow.canPaginate(EventTimeline.FORWARDS)) {
|
2017-01-20 17:22:27 +03:00
|
|
|
events.push(...this.props.timelineSet.getPendingEvents());
|
2016-03-18 01:26:06 +03:00
|
|
|
}
|
|
|
|
|
2019-07-05 16:37:19 +03:00
|
|
|
return {
|
|
|
|
events,
|
|
|
|
liveEvents,
|
2020-01-28 23:36:24 +03:00
|
|
|
firstVisibleEventIndex,
|
2019-07-05 16:37:19 +03:00
|
|
|
};
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2020-01-28 23:36:24 +03:00
|
|
|
/**
|
|
|
|
* Check for undecryptable messages that were sent while the user was not in
|
|
|
|
* the room.
|
|
|
|
*
|
|
|
|
* @param {Array<MatrixEvent>} events The timeline events to check
|
|
|
|
*
|
|
|
|
* @return {Number} The index within `events` of the event after the most recent
|
|
|
|
* undecryptable event that was sent while the user was not in the room. If no
|
|
|
|
* such events were found, then it returns 0.
|
|
|
|
*/
|
2020-08-29 14:14:16 +03:00
|
|
|
_checkForPreJoinUISI(events) {
|
2020-01-28 23:36:24 +03:00
|
|
|
const room = this.props.timelineSet.room;
|
|
|
|
|
|
|
|
if (events.length === 0 || !room ||
|
|
|
|
!MatrixClientPeg.get().isRoomEncrypted(room.roomId)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const userId = MatrixClientPeg.get().credentials.userId;
|
|
|
|
|
|
|
|
// get the user's membership at the last event by getting the timeline
|
|
|
|
// that the event belongs to, and traversing the timeline looking for
|
|
|
|
// that event, while keeping track of the user's membership
|
2020-01-29 15:00:02 +03:00
|
|
|
let i;
|
|
|
|
let userMembership = "leave";
|
|
|
|
for (i = events.length - 1; i >= 0; i--) {
|
|
|
|
const timeline = room.getTimelineForEvent(events[i].getId());
|
|
|
|
if (!timeline) {
|
|
|
|
// Somehow, it seems to be possible for live events to not have
|
|
|
|
// a timeline, even though that should not happen. :(
|
2020-08-03 18:02:26 +03:00
|
|
|
// https://github.com/vector-im/element-web/issues/12120
|
2020-01-29 15:00:02 +03:00
|
|
|
console.warn(
|
|
|
|
`Event ${events[i].getId()} in room ${room.roomId} is live, ` +
|
|
|
|
`but it does not have a timeline`,
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const userMembershipEvent =
|
|
|
|
timeline.getState(EventTimeline.FORWARDS).getMember(userId);
|
|
|
|
userMembership = userMembershipEvent ? userMembershipEvent.membership : "leave";
|
|
|
|
const timelineEvents = timeline.getEvents();
|
|
|
|
for (let j = timelineEvents.length - 1; j >= 0; j--) {
|
|
|
|
const event = timelineEvents[j];
|
|
|
|
if (event.getId() === events[i].getId()) {
|
|
|
|
break;
|
|
|
|
} else if (event.getStateKey() === userId
|
|
|
|
&& event.getType() === "m.room.member") {
|
|
|
|
const prevContent = event.getPrevContent();
|
|
|
|
userMembership = prevContent.membership || "leave";
|
|
|
|
}
|
2020-01-28 23:36:24 +03:00
|
|
|
}
|
2020-01-29 15:00:02 +03:00
|
|
|
break;
|
2020-01-28 23:36:24 +03:00
|
|
|
}
|
|
|
|
|
2020-01-29 15:00:02 +03:00
|
|
|
// now go through the rest of the events and find the first undecryptable
|
2020-01-28 23:36:24 +03:00
|
|
|
// one that was sent when the user wasn't in the room
|
2020-01-29 15:00:02 +03:00
|
|
|
for (; i >= 0; i--) {
|
2020-01-28 23:36:24 +03:00
|
|
|
const event = events[i];
|
|
|
|
if (event.getStateKey() === userId
|
|
|
|
&& event.getType() === "m.room.member") {
|
|
|
|
const prevContent = event.getPrevContent();
|
|
|
|
userMembership = prevContent.membership || "leave";
|
|
|
|
} else if (userMembership === "leave" &&
|
|
|
|
(event.isDecryptionFailure() || event.isBeingDecrypted())) {
|
|
|
|
// reached an undecryptable message when the user wasn't in
|
|
|
|
// the room -- don't try to load any more
|
|
|
|
// Note: for now, we assume that events that are being decrypted are
|
|
|
|
// not decryptable
|
|
|
|
return i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2020-01-28 23:36:24 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
_indexForEventId(evId) {
|
2017-10-11 19:56:17 +03:00
|
|
|
for (let i = 0; i < this.state.events.length; ++i) {
|
2016-02-10 21:27:40 +03:00
|
|
|
if (evId == this.state.events[i].getId()) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
_getLastDisplayedEventIndex(opts) {
|
2016-02-24 20:26:34 +03:00
|
|
|
opts = opts || {};
|
2017-10-11 19:56:17 +03:00
|
|
|
const ignoreOwn = opts.ignoreOwn || false;
|
|
|
|
const allowPartial = opts.allowPartial || false;
|
2016-02-24 20:26:34 +03:00
|
|
|
|
2019-12-08 15:16:17 +03:00
|
|
|
const messagePanel = this._messagePanel.current;
|
2019-12-19 19:09:19 +03:00
|
|
|
if (!messagePanel) return null;
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2020-01-18 03:07:37 +03:00
|
|
|
const messagePanelNode = ReactDOM.findDOMNode(messagePanel);
|
|
|
|
if (!messagePanelNode) return null; // sometimes this happens for fresh rooms/post-sync
|
|
|
|
const wrapperRect = messagePanelNode.getBoundingClientRect();
|
2017-10-11 19:56:17 +03:00
|
|
|
const myUserId = MatrixClientPeg.get().credentials.userId;
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2019-07-12 18:40:51 +03:00
|
|
|
const isNodeInView = (node) => {
|
|
|
|
if (node) {
|
|
|
|
const boundingRect = node.getBoundingClientRect();
|
|
|
|
if ((allowPartial && boundingRect.top < wrapperRect.bottom) ||
|
|
|
|
(!allowPartial && boundingRect.bottom < wrapperRect.bottom)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2019-07-17 11:18:51 +03:00
|
|
|
// We keep track of how many of the adjacent events didn't have a tile
|
2019-07-15 15:01:28 +03:00
|
|
|
// but should have the read receipt moved past them, so
|
2019-07-12 18:40:51 +03:00
|
|
|
// we can include those once we find the last displayed (visible) event.
|
2019-07-15 15:01:28 +03:00
|
|
|
// The counter is not started for events we don't want
|
|
|
|
// to send a read receipt for (our own events, local echos).
|
2019-07-12 18:40:51 +03:00
|
|
|
let adjacentInvisibleEventCount = 0;
|
2019-07-05 16:37:19 +03:00
|
|
|
// Use `liveEvents` here because we don't want the read marker or read
|
|
|
|
// receipt to advance into pending events.
|
|
|
|
for (let i = this.state.liveEvents.length - 1; i >= 0; --i) {
|
|
|
|
const ev = this.state.liveEvents[i];
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const node = messagePanel.getNodeForEventId(ev.getId());
|
2019-07-12 18:40:51 +03:00
|
|
|
const isInView = isNodeInView(node);
|
|
|
|
|
2019-07-15 15:01:28 +03:00
|
|
|
// when we've reached the first visible event, and the previous
|
|
|
|
// events were all invisible (with the first one not being ignored),
|
|
|
|
// return the index of the first invisible event.
|
2019-07-12 18:40:51 +03:00
|
|
|
if (isInView && adjacentInvisibleEventCount !== 0) {
|
|
|
|
return i + adjacentInvisibleEventCount;
|
2019-07-15 15:02:41 +03:00
|
|
|
}
|
|
|
|
if (node && !isInView) {
|
|
|
|
// has node but not in view, so reset adjacent invisible events
|
|
|
|
adjacentInvisibleEventCount = 0;
|
|
|
|
}
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2019-07-17 11:19:44 +03:00
|
|
|
const shouldIgnore = !!ev.status || // local echo
|
2019-07-15 15:02:41 +03:00
|
|
|
(ignoreOwn && ev.sender && ev.sender.userId == myUserId); // own message
|
2019-12-21 00:43:06 +03:00
|
|
|
const isWithoutTile = !haveTileForEvent(ev) || shouldHideEvent(ev);
|
2019-07-15 15:02:41 +03:00
|
|
|
|
2019-07-17 11:18:51 +03:00
|
|
|
if (isWithoutTile || !node) {
|
2019-07-15 15:02:41 +03:00
|
|
|
// don't start counting if the event should be ignored,
|
|
|
|
// but continue counting if we were already so the offset
|
|
|
|
// to the previous invisble event that didn't need to be ignored
|
|
|
|
// doesn't get messed up
|
|
|
|
if (!shouldIgnore || (shouldIgnore && adjacentInvisibleEventCount !== 0)) {
|
|
|
|
++adjacentInvisibleEventCount;
|
2019-07-12 18:40:51 +03:00
|
|
|
}
|
2019-07-15 15:02:41 +03:00
|
|
|
continue;
|
|
|
|
}
|
2019-06-03 19:51:40 +03:00
|
|
|
|
2019-07-15 15:02:41 +03:00
|
|
|
if (shouldIgnore) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-06-03 19:51:40 +03:00
|
|
|
|
2019-07-15 15:02:41 +03:00
|
|
|
if (isInView) {
|
|
|
|
return i;
|
2019-06-03 19:51:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-12 18:40:51 +03:00
|
|
|
return null;
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2016-02-10 21:27:40 +03:00
|
|
|
|
|
|
|
/**
|
2019-05-01 16:30:25 +03:00
|
|
|
* Get the id of the event corresponding to our user's latest read-receipt.
|
2016-02-23 16:24:38 +03:00
|
|
|
*
|
|
|
|
* @param {Boolean} ignoreSynthesized If true, return only receipts that
|
|
|
|
* have been sent by the server, not
|
|
|
|
* implicit ones generated by the JS
|
|
|
|
* SDK.
|
2019-05-01 16:30:25 +03:00
|
|
|
* @return {String} the event ID
|
2016-02-10 21:27:40 +03:00
|
|
|
*/
|
2020-08-29 14:14:16 +03:00
|
|
|
_getCurrentReadReceipt(ignoreSynthesized) {
|
2017-10-11 19:56:17 +03:00
|
|
|
const client = MatrixClientPeg.get();
|
2016-02-10 21:27:40 +03:00
|
|
|
// the client can be null on logout
|
2017-01-20 17:22:27 +03:00
|
|
|
if (client == null) {
|
2016-02-10 21:27:40 +03:00
|
|
|
return null;
|
2017-01-20 17:22:27 +03:00
|
|
|
}
|
2016-02-10 21:27:40 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const myUserId = client.credentials.userId;
|
2016-09-06 02:59:17 +03:00
|
|
|
return this.props.timelineSet.room.getEventReadUpTo(myUserId, ignoreSynthesized);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2016-02-11 18:38:13 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
_setReadMarker(eventId, eventTs, inhibitSetState) {
|
2017-10-11 19:56:17 +03:00
|
|
|
const roomId = this.props.timelineSet.room.roomId;
|
2016-09-06 02:59:17 +03:00
|
|
|
|
2017-04-19 12:46:08 +03:00
|
|
|
// don't update the state (and cause a re-render) if there is
|
|
|
|
// no change to the RM.
|
2017-04-12 17:05:39 +03:00
|
|
|
if (eventId === this.state.readMarkerEventId) {
|
2016-02-24 20:26:34 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// in order to later figure out if the read marker is
|
|
|
|
// above or below the visible timeline, we stash the timestamp.
|
2016-09-06 02:59:17 +03:00
|
|
|
TimelinePanel.roomReadMarkerTsMap[roomId] = eventTs;
|
2016-02-24 20:26:34 +03:00
|
|
|
|
2016-04-20 01:45:51 +03:00
|
|
|
if (inhibitSetState) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:05:39 +03:00
|
|
|
// Do the local echo of the RM
|
2016-02-24 20:26:34 +03:00
|
|
|
// run the render cycle before calling the callback, so that
|
|
|
|
// getReadMarkerPosition() returns the right thing.
|
|
|
|
this.setState({
|
|
|
|
readMarkerEventId: eventId,
|
|
|
|
}, this.props.onReadMarkerUpdated);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2016-02-11 18:38:13 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
_shouldPaginate() {
|
2018-01-12 21:17:03 +03:00
|
|
|
// don't try to paginate while events in the timeline are
|
|
|
|
// still being decrypted. We don't render events while they're
|
|
|
|
// being decrypted, so they don't take up space in the timeline.
|
|
|
|
// This means we can pull quite a lot of events into the timeline
|
|
|
|
// and end up trying to render a lot of events.
|
|
|
|
return !this.state.events.some((e) => {
|
|
|
|
return e.isBeingDecrypted();
|
|
|
|
});
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2018-01-12 21:17:03 +03:00
|
|
|
|
2020-08-29 14:51:37 +03:00
|
|
|
getRelationsForEvent = (...args) => this.props.timelineSet.getRelationsForEvent(...args);
|
2019-05-08 20:16:27 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
render() {
|
2017-10-11 19:56:17 +03:00
|
|
|
const MessagePanel = sdk.getComponent("structures.MessagePanel");
|
|
|
|
const Loader = sdk.getComponent("elements.Spinner");
|
2016-02-11 18:38:13 +03:00
|
|
|
|
|
|
|
// just show a spinner while the timeline loads.
|
|
|
|
//
|
|
|
|
// put it in a div of the right class (mx_RoomView_messagePanel) so
|
|
|
|
// that the order in the roomview flexbox is correct, and
|
|
|
|
// mx_RoomView_messageListWrapper to position the inner div in the
|
|
|
|
// right place.
|
|
|
|
//
|
|
|
|
// Note that the click-on-search-result functionality relies on the
|
|
|
|
// fact that the messagePanel is hidden while the timeline reloads,
|
|
|
|
// but that the RoomHeader (complete with search term) continues to
|
|
|
|
// exist.
|
|
|
|
if (this.state.timelineLoading) {
|
|
|
|
return (
|
2018-02-13 17:13:47 +03:00
|
|
|
<div className="mx_RoomView_messagePanelSpinner">
|
|
|
|
<Loader />
|
|
|
|
</div>
|
2016-02-11 18:38:13 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-02-03 14:11:37 +03:00
|
|
|
if (this.state.events.length == 0 && !this.state.canBackPaginate && this.props.empty) {
|
2017-02-02 19:32:10 +03:00
|
|
|
return (
|
2019-05-07 17:40:02 +03:00
|
|
|
<div className={this.props.className + " mx_RoomView_messageListWrapper"}>
|
|
|
|
<div className="mx_RoomView_empty">{this.props.empty}</div>
|
|
|
|
</div>
|
2017-02-02 19:32:10 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:38:13 +03:00
|
|
|
// give the messagepanel a stickybottom if we're at the end of the
|
|
|
|
// live timeline, so that the arrival of new events triggers a
|
|
|
|
// scroll.
|
|
|
|
//
|
|
|
|
// Make sure that stickyBottom is *false* if we can paginate
|
|
|
|
// forwards, otherwise if somebody hits the bottom of the loaded
|
|
|
|
// events when viewing historical messages, we get stuck in a loop
|
|
|
|
// of paginating our way through the entire history of the room.
|
2017-10-11 19:56:17 +03:00
|
|
|
const stickyBottom = !this._timelineWindow.canPaginate(EventTimeline.FORWARDS);
|
2017-04-26 16:05:09 +03:00
|
|
|
|
2018-08-30 16:39:48 +03:00
|
|
|
// If the state is PREPARED or CATCHUP, we're still waiting for the js-sdk to sync with
|
2017-04-26 16:05:09 +03:00
|
|
|
// the HS and fetch the latest events, so we are effectively forward paginating.
|
|
|
|
const forwardPaginating = (
|
2018-08-30 16:39:48 +03:00
|
|
|
this.state.forwardPaginating ||
|
|
|
|
['PREPARED', 'CATCHUP'].includes(this.state.clientSyncState)
|
2017-04-26 16:05:09 +03:00
|
|
|
);
|
2020-01-28 23:36:24 +03:00
|
|
|
const events = this.state.firstVisibleEventIndex
|
|
|
|
? this.state.events.slice(this.state.firstVisibleEventIndex)
|
|
|
|
: this.state.events;
|
2016-02-11 18:38:13 +03:00
|
|
|
return (
|
2019-12-08 15:16:17 +03:00
|
|
|
<MessagePanel
|
|
|
|
ref={this._messagePanel}
|
2019-05-07 17:40:02 +03:00
|
|
|
room={this.props.timelineSet.room}
|
|
|
|
permalinkCreator={this.props.permalinkCreator}
|
|
|
|
hidden={this.props.hidden}
|
|
|
|
backPaginating={this.state.backPaginating}
|
|
|
|
forwardPaginating={forwardPaginating}
|
2020-01-28 23:36:24 +03:00
|
|
|
events={events}
|
2019-05-07 17:40:02 +03:00
|
|
|
highlightedEventId={this.props.highlightedEventId}
|
|
|
|
readMarkerEventId={this.state.readMarkerEventId}
|
|
|
|
readMarkerVisible={this.state.readMarkerVisible}
|
|
|
|
suppressFirstDateSeparator={this.state.canBackPaginate}
|
|
|
|
showUrlPreview={this.props.showUrlPreview}
|
|
|
|
showReadReceipts={this.props.showReadReceipts}
|
|
|
|
ourUserId={MatrixClientPeg.get().credentials.userId}
|
|
|
|
stickyBottom={stickyBottom}
|
|
|
|
onScroll={this.onMessageListScroll}
|
|
|
|
onFillRequest={this.onMessageListFillRequest}
|
|
|
|
onUnfillRequest={this.onMessageListUnfillRequest}
|
|
|
|
isTwelveHour={this.state.isTwelveHour}
|
|
|
|
alwaysShowTimestamps={this.state.alwaysShowTimestamps}
|
|
|
|
className={this.props.className}
|
|
|
|
tileShape={this.props.tileShape}
|
|
|
|
resizeNotifier={this.props.resizeNotifier}
|
2019-05-08 20:16:27 +03:00
|
|
|
getRelationsForEvent={this.getRelationsForEvent}
|
2019-06-12 19:52:34 +03:00
|
|
|
editState={this.state.editState}
|
2019-05-21 19:23:19 +03:00
|
|
|
showReactions={this.props.showReactions}
|
2020-05-26 17:56:16 +03:00
|
|
|
useIRCLayout={this.props.useIRCLayout}
|
2016-02-11 18:38:13 +03:00
|
|
|
/>
|
|
|
|
);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
|
|
|
}
|
2016-02-24 20:26:34 +03:00
|
|
|
|
2019-12-20 03:45:24 +03:00
|
|
|
export default TimelinePanel;
|