2016-02-10 14:03:46 +03:00
|
|
|
/*
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
2018-06-16 11:45:06 +03:00
|
|
|
Copyright 2018 New Vector Ltd
|
2016-02-10 14:03:46 +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.
|
|
|
|
*/
|
|
|
|
|
2019-05-30 16:57:44 +03:00
|
|
|
/* global Velocity */
|
|
|
|
|
2017-06-15 21:57:48 +03:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2017-10-25 13:09:48 +03:00
|
|
|
import classNames from 'classnames';
|
2017-07-21 22:22:01 +03:00
|
|
|
import shouldHideEvent from '../../shouldHideEvent';
|
2018-01-10 15:06:24 +03:00
|
|
|
import {wantsDateSeparator} from '../../DateUtils';
|
2017-06-15 21:57:48 +03:00
|
|
|
import sdk from '../../index';
|
2016-02-10 14:03:46 +03:00
|
|
|
|
2017-06-15 21:57:48 +03:00
|
|
|
import MatrixClientPeg from '../../MatrixClientPeg';
|
2019-05-02 17:11:06 +03:00
|
|
|
import SettingsStore from '../../settings/SettingsStore';
|
2016-04-19 21:38:54 +03:00
|
|
|
|
2018-06-16 11:45:06 +03:00
|
|
|
const CONTINUATION_MAX_INTERVAL = 5 * 60 * 1000; // 5 minutes
|
|
|
|
const continuedTypes = ['m.sticker', 'm.room.message'];
|
|
|
|
|
2016-02-15 12:50:12 +03:00
|
|
|
/* (almost) stateless UI component which builds the event tiles in the room timeline.
|
2016-02-10 14:03:46 +03:00
|
|
|
*/
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'MessagePanel',
|
|
|
|
|
|
|
|
propTypes: {
|
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 14:03:46 +03:00
|
|
|
|
2016-02-24 16:38:55 +03:00
|
|
|
// true to show a spinner at the top of the timeline to indicate
|
|
|
|
// back-pagination in progress
|
2017-12-26 04:03:18 +03:00
|
|
|
backPaginating: PropTypes.bool,
|
2016-02-24 16:38:55 +03:00
|
|
|
|
|
|
|
// true to show a spinner at the end of the timeline to indicate
|
|
|
|
// forward-pagination in progress
|
2017-12-26 04:03:18 +03:00
|
|
|
forwardPaginating: PropTypes.bool,
|
2016-02-24 16:38:55 +03:00
|
|
|
|
2016-02-10 14:03:46 +03:00
|
|
|
// the list of MatrixEvents to display
|
2017-12-26 04:03:18 +03:00
|
|
|
events: PropTypes.array.isRequired,
|
2016-02-10 14:03:46 +03:00
|
|
|
|
|
|
|
// ID of an event to highlight. If undefined, no event will be highlighted.
|
2017-12-26 04:03:18 +03:00
|
|
|
highlightedEventId: PropTypes.string,
|
2016-02-10 14:03:46 +03:00
|
|
|
|
2019-06-04 17:25:54 +03:00
|
|
|
// The room these events are all in together, if any.
|
|
|
|
// (The notification panel won't have a room here, for example.)
|
|
|
|
room: PropTypes.object,
|
|
|
|
|
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 14:03:46 +03:00
|
|
|
// event after which we should show a read marker
|
2017-12-26 04:03:18 +03:00
|
|
|
readMarkerEventId: PropTypes.string,
|
2016-02-10 14:03:46 +03:00
|
|
|
|
2016-02-24 20:26:34 +03:00
|
|
|
// whether the read marker should be visible
|
2017-12-26 04:03:18 +03:00
|
|
|
readMarkerVisible: PropTypes.bool,
|
2016-02-24 20:26:34 +03:00
|
|
|
|
2016-02-10 14:03:46 +03:00
|
|
|
// the userid of our user. This is used to suppress the read marker
|
|
|
|
// for pending messages.
|
2017-12-26 04:03:18 +03:00
|
|
|
ourUserId: PropTypes.string,
|
2016-02-10 14:03:46 +03:00
|
|
|
|
2017-09-06 19:40:58 +03:00
|
|
|
// true to suppress the date at the start of the timeline
|
2017-12-26 04:03:18 +03:00
|
|
|
suppressFirstDateSeparator: PropTypes.bool,
|
2017-09-06 19:40:58 +03:00
|
|
|
|
2016-09-08 05:01:38 +03:00
|
|
|
// whether to show read receipts
|
2017-12-26 04:03:18 +03:00
|
|
|
showReadReceipts: PropTypes.bool,
|
2016-09-08 05:01:38 +03:00
|
|
|
|
2016-02-10 14:03:46 +03:00
|
|
|
// true if updates to the event list should cause the scroll panel to
|
|
|
|
// scroll down when we are at the bottom of the window. See ScrollPanel
|
|
|
|
// for more details.
|
2017-12-26 04:03:18 +03:00
|
|
|
stickyBottom: PropTypes.bool,
|
2016-02-10 14:03:46 +03:00
|
|
|
|
|
|
|
// callback which is called when the panel is scrolled.
|
2017-12-26 04:03:18 +03:00
|
|
|
onScroll: PropTypes.func,
|
2016-02-10 14:03:46 +03:00
|
|
|
|
|
|
|
// callback which is called when more content is needed.
|
2017-12-26 04:03:18 +03:00
|
|
|
onFillRequest: PropTypes.func,
|
2016-04-12 19:18:32 +03:00
|
|
|
|
2016-09-07 04:16:29 +03:00
|
|
|
// className for the panel
|
2017-12-26 04:03:18 +03:00
|
|
|
className: PropTypes.string.isRequired,
|
2016-09-11 04:14:27 +03:00
|
|
|
|
|
|
|
// shape parameter to be passed to EventTiles
|
2017-12-26 04:03:18 +03:00
|
|
|
tileShape: PropTypes.string,
|
2017-05-20 00:45:56 +03:00
|
|
|
|
|
|
|
// show twelve hour timestamps
|
2017-12-26 04:03:18 +03:00
|
|
|
isTwelveHour: PropTypes.bool,
|
2017-05-27 02:14:16 +03:00
|
|
|
|
|
|
|
// show timestamps always
|
2017-12-26 04:03:18 +03:00
|
|
|
alwaysShowTimestamps: PropTypes.bool,
|
2019-05-08 20:16:27 +03:00
|
|
|
|
|
|
|
// helper function to access relations for an event
|
|
|
|
getRelationsForEvent: PropTypes.func,
|
2019-05-21 19:23:19 +03:00
|
|
|
|
|
|
|
// whether to show reactions for an event
|
|
|
|
showReactions: PropTypes.bool,
|
2016-02-10 14:03:46 +03:00
|
|
|
},
|
|
|
|
|
2016-02-15 12:50:12 +03:00
|
|
|
componentWillMount: function() {
|
|
|
|
// the event after which we put a visible unread marker on the last
|
|
|
|
// render cycle; null if readMarkerVisible was false or the RM was
|
|
|
|
// suppressed (eg because it was at the end of the timeline)
|
|
|
|
this.currentReadMarkerEventId = null;
|
|
|
|
|
|
|
|
// the event after which we are showing a disappearing read marker
|
|
|
|
// animation
|
|
|
|
this.currentGhostEventId = null;
|
2016-04-21 01:03:05 +03:00
|
|
|
|
|
|
|
// opaque readreceipt info for each userId; used by ReadReceiptMarker
|
|
|
|
// to manage its animations
|
|
|
|
this._readReceiptMap = {};
|
2016-04-22 19:03:15 +03:00
|
|
|
|
2019-06-04 13:12:52 +03:00
|
|
|
// Track read receipts by event ID. For each _shown_ event ID, we store
|
|
|
|
// the list of read receipts to display:
|
|
|
|
// [
|
|
|
|
// {
|
|
|
|
// userId: string,
|
|
|
|
// member: RoomMember,
|
|
|
|
// ts: number,
|
|
|
|
// },
|
|
|
|
// ]
|
|
|
|
// This is recomputed on each render. It's only stored on the component
|
|
|
|
// for ease of passing the data around since it's computed in one pass
|
|
|
|
// over all events.
|
|
|
|
this._readReceiptsByEvent = {};
|
|
|
|
|
2019-06-03 15:28:31 +03:00
|
|
|
// Track read receipts by user ID. For each user ID we've ever shown a
|
|
|
|
// a read receipt for, we store an object:
|
|
|
|
// {
|
2019-06-04 13:12:52 +03:00
|
|
|
// lastShownEventId: string,
|
|
|
|
// receipt: {
|
|
|
|
// userId: string,
|
|
|
|
// member: RoomMember,
|
|
|
|
// ts: number,
|
|
|
|
// },
|
2019-06-03 15:28:31 +03:00
|
|
|
// }
|
|
|
|
// so that we can always keep receipts displayed by reverting back to
|
|
|
|
// the last shown event for that user ID when needed. This may feel like
|
|
|
|
// it duplicates the receipt storage in the room, but at this layer, we
|
|
|
|
// are tracking _shown_ event IDs, which the JS SDK knows nothing about.
|
2019-06-04 13:12:52 +03:00
|
|
|
// This is recomputed on each render, using the data from the previous
|
|
|
|
// render as our fallback for any user IDs we can't match a receipt to a
|
|
|
|
// displayed event in the current render cycle.
|
2019-06-03 15:28:31 +03:00
|
|
|
this._readReceiptsByUserId = {};
|
|
|
|
|
2016-06-07 20:22:01 +03:00
|
|
|
// Remember the read marker ghost node so we can do the cleanup that
|
|
|
|
// Velocity requires
|
2016-06-07 21:55:24 +03:00
|
|
|
this._readMarkerGhostNode = null;
|
2016-06-07 20:22:01 +03:00
|
|
|
|
2019-06-04 17:07:23 +03:00
|
|
|
// Cache hidden events setting on mount since Settings is expensive to
|
|
|
|
// query, and we check this in a hot code path.
|
|
|
|
this._showHiddenEventsInTimeline =
|
|
|
|
SettingsStore.getValue("showHiddenEventsInTimeline");
|
|
|
|
|
2016-04-22 19:03:15 +03:00
|
|
|
this._isMounted = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
this._isMounted = false;
|
2016-02-15 12:50:12 +03:00
|
|
|
},
|
|
|
|
|
2016-02-10 14:03:46 +03:00
|
|
|
/* get the DOM node representing the given event */
|
|
|
|
getNodeForEventId: function(eventId) {
|
|
|
|
if (!this.eventNodes) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.eventNodes[eventId];
|
|
|
|
},
|
|
|
|
|
|
|
|
/* return true if the content is fully scrolled down right now; else false.
|
|
|
|
*/
|
|
|
|
isAtBottom: function() {
|
2016-02-12 16:39:38 +03:00
|
|
|
return this.refs.scrollPanel
|
2016-02-10 14:03:46 +03:00
|
|
|
&& this.refs.scrollPanel.isAtBottom();
|
|
|
|
},
|
|
|
|
|
|
|
|
/* get the current scroll state. See ScrollPanel.getScrollState for
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* returns null if we are not mounted.
|
|
|
|
*/
|
|
|
|
getScrollState: function() {
|
|
|
|
if (!this.refs.scrollPanel) { return null; }
|
|
|
|
return this.refs.scrollPanel.getScrollState();
|
|
|
|
},
|
|
|
|
|
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 within the window
|
|
|
|
// +1: read marker is below the window
|
|
|
|
getReadMarkerPosition: function() {
|
2017-10-11 19:56:17 +03:00
|
|
|
const readMarker = this.refs.readMarkerNode;
|
|
|
|
const messageWrapper = this.refs.scrollPanel;
|
2016-02-24 20:26:34 +03:00
|
|
|
|
|
|
|
if (!readMarker || !messageWrapper) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const wrapperRect = ReactDOM.findDOMNode(messageWrapper).getBoundingClientRect();
|
|
|
|
const readMarkerRect = readMarker.getBoundingClientRect();
|
2016-02-24 20:26:34 +03:00
|
|
|
|
|
|
|
// the read-marker pretends to have zero height when it is actually
|
|
|
|
// two pixels high; +2 here to account for that.
|
|
|
|
if (readMarkerRect.bottom + 2 < wrapperRect.top) {
|
|
|
|
return -1;
|
|
|
|
} else if (readMarkerRect.top < wrapperRect.bottom) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-04-05 15:14:11 +03:00
|
|
|
/* jump to the top of the content.
|
|
|
|
*/
|
|
|
|
scrollToTop: function() {
|
|
|
|
if (this.refs.scrollPanel) {
|
|
|
|
this.refs.scrollPanel.scrollToTop();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-02-10 14:03:46 +03:00
|
|
|
/* jump to the bottom of the content.
|
|
|
|
*/
|
|
|
|
scrollToBottom: function() {
|
|
|
|
if (this.refs.scrollPanel) {
|
|
|
|
this.refs.scrollPanel.scrollToBottom();
|
|
|
|
}
|
|
|
|
},
|
2016-04-19 21:38:54 +03:00
|
|
|
|
2016-04-05 15:14:11 +03:00
|
|
|
/**
|
|
|
|
* Page up/down.
|
|
|
|
*
|
2018-06-16 11:48:57 +03:00
|
|
|
* @param {number} mult: -1 to page up, +1 to page down
|
2016-04-05 15:14:11 +03:00
|
|
|
*/
|
|
|
|
scrollRelative: function(mult) {
|
|
|
|
if (this.refs.scrollPanel) {
|
|
|
|
this.refs.scrollPanel.scrollRelative(mult);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scroll up/down in response to a scroll key
|
2018-06-16 11:48:57 +03:00
|
|
|
*
|
|
|
|
* @param {KeyboardEvent} ev: the keyboard event to handle
|
2016-04-05 15:14:11 +03:00
|
|
|
*/
|
|
|
|
handleScrollKey: function(ev) {
|
|
|
|
if (this.refs.scrollPanel) {
|
2016-04-07 14:05:07 +03:00
|
|
|
this.refs.scrollPanel.handleScrollKey(ev);
|
2016-04-05 15:14:11 +03:00
|
|
|
}
|
|
|
|
},
|
2016-02-10 14:03:46 +03:00
|
|
|
|
|
|
|
/* jump to the given event id.
|
|
|
|
*
|
2016-03-10 19:44:50 +03:00
|
|
|
* offsetBase gives 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.
|
|
|
|
*
|
|
|
|
* pixelOffset gives the number of pixels *above* the offsetBase that the
|
|
|
|
* node (specifically, the bottom of it) will be positioned. If omitted, it
|
|
|
|
* defaults to 0.
|
2016-02-10 14:03:46 +03:00
|
|
|
*/
|
2016-03-10 19:44:50 +03:00
|
|
|
scrollToEvent: function(eventId, pixelOffset, offsetBase) {
|
2016-02-10 14:03:46 +03:00
|
|
|
if (this.refs.scrollPanel) {
|
2016-03-10 19:44:50 +03:00
|
|
|
this.refs.scrollPanel.scrollToToken(eventId, pixelOffset, offsetBase);
|
2016-02-10 14:03:46 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-05-24 16:38:51 +03:00
|
|
|
scrollToEventIfNeeded: function(eventId) {
|
|
|
|
const node = this.eventNodes[eventId];
|
|
|
|
if (node) {
|
|
|
|
node.scrollIntoView({block: "nearest", behavior: "instant"});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-02-10 14:03:46 +03:00
|
|
|
/* check the scroll state and send out pagination requests if necessary.
|
|
|
|
*/
|
|
|
|
checkFillState: function() {
|
|
|
|
if (this.refs.scrollPanel) {
|
|
|
|
this.refs.scrollPanel.checkFillState();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-04-22 19:03:15 +03:00
|
|
|
_isUnmounting: function() {
|
|
|
|
return !this._isMounted;
|
|
|
|
},
|
|
|
|
|
2017-05-31 15:36:19 +03:00
|
|
|
// TODO: Implement granular (per-room) hide options
|
|
|
|
_shouldShowEvent: function(mxEv) {
|
2017-09-15 05:47:24 +03:00
|
|
|
if (mxEv.sender && MatrixClientPeg.get().isUserIgnored(mxEv.sender.userId)) {
|
2017-09-15 05:16:56 +03:00
|
|
|
return false; // ignored = no show (only happens if the ignore happens after an event was received)
|
|
|
|
}
|
|
|
|
|
2019-06-04 17:07:23 +03:00
|
|
|
if (this._showHiddenEventsInTimeline) {
|
2019-05-02 17:11:06 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-31 15:36:19 +03:00
|
|
|
const EventTile = sdk.getComponent('rooms.EventTile');
|
|
|
|
if (!EventTile.haveTileForEvent(mxEv)) {
|
|
|
|
return false; // no tile = no show
|
|
|
|
}
|
|
|
|
|
2017-06-15 21:53:34 +03:00
|
|
|
// Always show highlighted event
|
|
|
|
if (this.props.highlightedEventId === mxEv.getId()) return true;
|
|
|
|
|
2017-10-29 10:43:52 +03:00
|
|
|
return !shouldHideEvent(mxEv);
|
2017-05-31 15:36:19 +03:00
|
|
|
},
|
|
|
|
|
2016-02-10 14:03:46 +03:00
|
|
|
_getEventTiles: function() {
|
2017-05-20 00:45:56 +03:00
|
|
|
const DateSeparator = sdk.getComponent('messages.DateSeparator');
|
2016-11-10 16:01:48 +03:00
|
|
|
const MemberEventListSummary = sdk.getComponent('views.elements.MemberEventListSummary');
|
2016-02-10 14:03:46 +03:00
|
|
|
|
2016-02-12 16:39:38 +03:00
|
|
|
this.eventNodes = {};
|
|
|
|
|
2018-06-16 11:48:57 +03:00
|
|
|
let visible = false;
|
2017-10-11 19:56:17 +03:00
|
|
|
let i;
|
2016-02-10 14:03:46 +03:00
|
|
|
|
2016-02-23 15:56:54 +03:00
|
|
|
// first figure out which is the last event in the list which we're
|
|
|
|
// actually going to show; this allows us to behave slightly
|
2017-07-22 14:03:32 +03:00
|
|
|
// differently for the last event in the list. (eg show timestamp)
|
2016-03-22 19:34:12 +03:00
|
|
|
//
|
|
|
|
// we also need to figure out which is the last event we show which isn't
|
|
|
|
// a local echo, to manage the read-marker.
|
2017-07-26 14:17:05 +03:00
|
|
|
let lastShownEvent;
|
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
let lastShownNonLocalEchoIndex = -1;
|
2016-02-23 15:56:54 +03:00
|
|
|
for (i = this.props.events.length-1; i >= 0; i--) {
|
2017-10-11 19:56:17 +03:00
|
|
|
const mxEv = this.props.events[i];
|
2017-05-31 15:36:19 +03:00
|
|
|
if (!this._shouldShowEvent(mxEv)) {
|
2016-02-23 15:56:54 +03:00
|
|
|
continue;
|
2016-02-10 14:03:46 +03:00
|
|
|
}
|
|
|
|
|
2017-07-26 14:17:05 +03:00
|
|
|
if (lastShownEvent === undefined) {
|
|
|
|
lastShownEvent = mxEv;
|
2016-03-22 19:34:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mxEv.status) {
|
|
|
|
// this is a local echo
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastShownNonLocalEchoIndex = i;
|
2016-02-23 15:56:54 +03:00
|
|
|
break;
|
2016-02-12 16:39:38 +03:00
|
|
|
}
|
2016-02-10 14:03:46 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const ret = [];
|
2016-02-12 16:39:38 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
let prevEvent = null; // the last event we showed
|
2016-02-12 16:39:38 +03:00
|
|
|
|
2016-02-15 12:50:12 +03:00
|
|
|
// assume there is no read marker until proven otherwise
|
2017-10-11 19:56:17 +03:00
|
|
|
let readMarkerVisible = false;
|
2016-02-15 12:50:12 +03:00
|
|
|
|
2016-03-31 20:19:57 +03:00
|
|
|
// if the readmarker has moved, cancel any active ghost.
|
|
|
|
if (this.currentReadMarkerEventId && this.props.readMarkerEventId &&
|
|
|
|
this.props.readMarkerVisible &&
|
2018-06-16 11:48:57 +03:00
|
|
|
this.currentReadMarkerEventId !== this.props.readMarkerEventId) {
|
2016-03-31 20:19:57 +03:00
|
|
|
this.currentGhostEventId = null;
|
|
|
|
}
|
|
|
|
|
2019-05-31 19:26:09 +03:00
|
|
|
this._readReceiptsByEvent = {};
|
|
|
|
if (this.props.showReadReceipts) {
|
|
|
|
this._readReceiptsByEvent = this._getReadReceiptsByShownEvent();
|
|
|
|
}
|
|
|
|
|
2017-07-21 22:43:03 +03:00
|
|
|
const isMembershipChange = (e) => e.getType() === 'm.room.member';
|
2016-11-10 16:03:17 +03:00
|
|
|
|
2016-02-23 15:56:54 +03:00
|
|
|
for (i = 0; i < this.props.events.length; i++) {
|
2017-10-11 19:56:17 +03:00
|
|
|
const mxEv = this.props.events[i];
|
|
|
|
const eventId = mxEv.getId();
|
|
|
|
const last = (mxEv === lastShownEvent);
|
2016-02-23 15:56:54 +03:00
|
|
|
|
2017-07-22 01:18:18 +03:00
|
|
|
const wantTile = this._shouldShowEvent(mxEv);
|
2016-02-23 15:56:54 +03:00
|
|
|
|
2017-01-11 14:27:07 +03:00
|
|
|
// Wrap consecutive member events in a ListSummary, ignore if redacted
|
2017-07-21 22:43:03 +03:00
|
|
|
if (isMembershipChange(mxEv) && wantTile) {
|
2017-08-14 17:40:49 +03:00
|
|
|
let readMarkerInMels = false;
|
2017-10-11 19:56:17 +03:00
|
|
|
const ts1 = mxEv.getTs();
|
2016-12-14 18:31:35 +03:00
|
|
|
// Ensure that the key of the MemberEventListSummary does not change with new
|
2016-12-15 16:16:36 +03:00
|
|
|
// member events. This will prevent it from being re-created unnecessarily, and
|
2016-12-14 18:31:35 +03:00
|
|
|
// instead will allow new props to be provided. In turn, the shouldComponentUpdate
|
|
|
|
// method on MELS can be used to prevent unnecessary renderings.
|
2016-12-15 21:26:41 +03:00
|
|
|
//
|
2017-02-22 19:54:32 +03:00
|
|
|
// Whilst back-paginating with a MELS at the top of the panel, prevEvent will be null,
|
|
|
|
// so use the key "membereventlistsummary-initial". Otherwise, use the ID of the first
|
|
|
|
// membership event, which will not change during forward pagination.
|
|
|
|
const key = "membereventlistsummary-" + (prevEvent ? mxEv.getId() : "initial");
|
2016-11-16 17:42:30 +03:00
|
|
|
|
2016-12-22 20:54:30 +03:00
|
|
|
if (this._wantsDateSeparator(prevEvent, mxEv.getDate())) {
|
2018-01-14 21:32:17 +03:00
|
|
|
const dateSeparator = <li key={ts1+'~'}><DateSeparator key={ts1+'~'} ts={ts1} /></li>;
|
2016-11-16 17:42:30 +03:00
|
|
|
ret.push(dateSeparator);
|
|
|
|
}
|
|
|
|
|
2017-08-14 17:40:49 +03:00
|
|
|
// If RM event is the first in the MELS, append the RM after MELS
|
|
|
|
if (mxEv.getId() === this.props.readMarkerEventId) {
|
|
|
|
readMarkerInMels = true;
|
|
|
|
}
|
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const summarisedEvents = [mxEv];
|
2016-11-16 17:42:30 +03:00
|
|
|
for (;i + 1 < this.props.events.length; i++) {
|
2017-07-21 22:43:03 +03:00
|
|
|
const collapsedMxEv = this.props.events[i + 1];
|
|
|
|
|
2017-08-16 15:20:32 +03:00
|
|
|
// Ignore redacted/hidden member events
|
|
|
|
if (!this._shouldShowEvent(collapsedMxEv)) {
|
2017-08-18 13:53:52 +03:00
|
|
|
// If this hidden event is the RM and in or at end of a MELS put RM after MELS.
|
|
|
|
if (collapsedMxEv.getId() === this.props.readMarkerEventId) {
|
|
|
|
readMarkerInMels = true;
|
|
|
|
}
|
2017-08-16 15:20:32 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-07-21 22:43:03 +03:00
|
|
|
if (!isMembershipChange(collapsedMxEv) ||
|
2017-10-25 14:52:51 +03:00
|
|
|
this._wantsDateSeparator(mxEv, collapsedMxEv.getDate())) {
|
2017-07-21 22:43:03 +03:00
|
|
|
break;
|
|
|
|
}
|
2016-11-08 19:34:02 +03:00
|
|
|
|
2017-07-21 22:43:03 +03:00
|
|
|
// If RM event is in MELS mark it as such and the RM will be appended after MELS.
|
|
|
|
if (collapsedMxEv.getId() === this.props.readMarkerEventId) {
|
|
|
|
readMarkerInMels = true;
|
2016-11-08 19:34:02 +03:00
|
|
|
}
|
2017-07-21 22:43:03 +03:00
|
|
|
|
2016-11-09 19:03:35 +03:00
|
|
|
summarisedEvents.push(collapsedMxEv);
|
2016-11-08 19:34:02 +03:00
|
|
|
}
|
2016-11-10 16:14:04 +03:00
|
|
|
|
2017-09-14 19:53:47 +03:00
|
|
|
let highlightInMels = false;
|
|
|
|
|
2017-07-26 14:17:05 +03:00
|
|
|
// At this point, i = the index of the last event in the summary sequence
|
2017-07-22 13:37:21 +03:00
|
|
|
let eventTiles = summarisedEvents.map((e) => {
|
2017-09-14 19:53:47 +03:00
|
|
|
if (e.getId() === this.props.highlightedEventId) {
|
|
|
|
highlightInMels = true;
|
|
|
|
}
|
2017-07-22 13:37:21 +03:00
|
|
|
// In order to prevent DateSeparators from appearing in the expanded form
|
|
|
|
// of MemberEventListSummary, render each member event as if the previous
|
|
|
|
// one was itself. This way, the timestamp of the previous event === the
|
|
|
|
// timestamp of the current event, and no DateSeperator is inserted.
|
2017-10-25 14:52:51 +03:00
|
|
|
return this._getTilesForEvent(e, e, e === lastShownEvent);
|
2017-07-22 13:37:21 +03:00
|
|
|
}).reduce((a, b) => a.concat(b));
|
2016-11-10 16:25:48 +03:00
|
|
|
|
2016-11-10 20:26:36 +03:00
|
|
|
if (eventTiles.length === 0) {
|
|
|
|
eventTiles = null;
|
|
|
|
}
|
2016-11-10 16:25:48 +03:00
|
|
|
|
2017-09-14 19:53:47 +03:00
|
|
|
ret.push(<MemberEventListSummary key={key}
|
|
|
|
events={summarisedEvents}
|
2019-03-06 14:27:16 +03:00
|
|
|
onToggle={this._onHeightChanged} // Update scroll state
|
2017-09-14 19:53:47 +03:00
|
|
|
startExpanded={highlightInMels}
|
|
|
|
>
|
2017-10-11 19:56:17 +03:00
|
|
|
{ eventTiles }
|
2017-09-14 19:53:47 +03:00
|
|
|
</MemberEventListSummary>);
|
2017-04-27 16:16:50 +03:00
|
|
|
|
|
|
|
if (readMarkerInMels) {
|
|
|
|
ret.push(this._getReadMarkerTile(visible));
|
|
|
|
}
|
|
|
|
|
2017-10-25 14:52:51 +03:00
|
|
|
prevEvent = mxEv;
|
2016-11-09 19:03:35 +03:00
|
|
|
continue;
|
2016-11-08 19:34:02 +03:00
|
|
|
}
|
|
|
|
|
2017-07-22 01:18:18 +03:00
|
|
|
if (wantTile) {
|
2016-03-04 16:49:15 +03:00
|
|
|
// make sure we unpack the array returned by _getTilesForEvent,
|
|
|
|
// otherwise react will auto-generate keys and we will end up
|
|
|
|
// replacing all of the DOM elements every time we paginate.
|
|
|
|
ret.push(...this._getTilesForEvent(prevEvent, mxEv, last));
|
2016-02-23 21:43:51 +03:00
|
|
|
prevEvent = mxEv;
|
2016-02-23 15:56:54 +03:00
|
|
|
}
|
2016-02-12 16:39:38 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
let isVisibleReadMarker = false;
|
2016-03-22 19:34:12 +03:00
|
|
|
|
2018-06-16 11:48:57 +03:00
|
|
|
if (eventId === this.props.readMarkerEventId) {
|
|
|
|
visible = this.props.readMarkerVisible;
|
2016-02-24 20:26:34 +03:00
|
|
|
|
2016-03-22 19:34:12 +03:00
|
|
|
// if the read marker comes at the end of the timeline (except
|
|
|
|
// for local echoes, which are excluded from RMs, because they
|
|
|
|
// don't have useful event ids), we don't want to show it, but
|
|
|
|
// we still want to create the <li/> for it so that the
|
|
|
|
// algorithms which depend on its position on the screen aren't
|
|
|
|
// confused.
|
|
|
|
if (i >= lastShownNonLocalEchoIndex) {
|
2016-02-24 20:26:34 +03:00
|
|
|
visible = false;
|
2016-02-12 16:39:38 +03:00
|
|
|
}
|
2016-02-24 20:26:34 +03:00
|
|
|
ret.push(this._getReadMarkerTile(visible));
|
|
|
|
readMarkerVisible = visible;
|
2016-03-22 19:34:12 +03:00
|
|
|
isVisibleReadMarker = visible;
|
2017-04-18 17:17:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: there should be no need for a ghost tile - we should just use a
|
2017-04-18 17:18:21 +03:00
|
|
|
// a dispatch (user_activity_end) to start the RM animation.
|
2018-06-16 11:48:57 +03:00
|
|
|
if (eventId === this.currentGhostEventId) {
|
2016-03-22 19:34:12 +03:00
|
|
|
// if we're showing an animation, continue to show it.
|
|
|
|
ret.push(this._getReadMarkerGhostTile());
|
|
|
|
} else if (!isVisibleReadMarker &&
|
2018-06-16 11:48:57 +03:00
|
|
|
eventId === this.currentReadMarkerEventId) {
|
2016-02-23 15:56:54 +03:00
|
|
|
// there is currently a read-up-to marker at this point, but no
|
|
|
|
// more. Show an animation of it disappearing.
|
|
|
|
ret.push(this._getReadMarkerGhostTile());
|
|
|
|
this.currentGhostEventId = eventId;
|
2016-02-10 14:03:46 +03:00
|
|
|
}
|
2016-02-12 16:39:38 +03:00
|
|
|
}
|
|
|
|
|
2016-02-15 12:50:12 +03:00
|
|
|
this.currentReadMarkerEventId = readMarkerVisible ? this.props.readMarkerEventId : null;
|
2016-02-12 16:39:38 +03:00
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getTilesForEvent: function(prevEvent, mxEv, last) {
|
2017-05-20 00:45:56 +03:00
|
|
|
const EventTile = sdk.getComponent('rooms.EventTile');
|
|
|
|
const DateSeparator = sdk.getComponent('messages.DateSeparator');
|
2017-10-11 19:56:17 +03:00
|
|
|
const ret = [];
|
2016-02-10 14:03:46 +03:00
|
|
|
|
2019-06-12 19:52:34 +03:00
|
|
|
const isEditing = this.props.editState &&
|
|
|
|
this.props.editState.getEvent().getId() === mxEv.getId();
|
2016-02-12 16:39:38 +03:00
|
|
|
// is this a continuation of the previous message?
|
2017-10-11 19:56:17 +03:00
|
|
|
let continuation = false;
|
2017-03-06 13:26:26 +03:00
|
|
|
|
2018-04-06 19:47:44 +03:00
|
|
|
// Some events should appear as continuations from previous events of
|
|
|
|
// different types.
|
2018-06-16 11:45:06 +03:00
|
|
|
|
2018-04-06 19:47:44 +03:00
|
|
|
const eventTypeContinues =
|
|
|
|
prevEvent !== null &&
|
|
|
|
continuedTypes.includes(mxEv.getType()) &&
|
|
|
|
continuedTypes.includes(prevEvent.getType());
|
|
|
|
|
2018-06-16 11:45:06 +03:00
|
|
|
// if there is a previous event and it has the same sender as this event
|
|
|
|
// and the types are the same/is in continuedTypes and the time between them is <= CONTINUATION_MAX_INTERVAL
|
|
|
|
if (prevEvent !== null && prevEvent.sender && mxEv.sender && mxEv.sender.userId === prevEvent.sender.userId &&
|
|
|
|
(mxEv.getType() === prevEvent.getType() || eventTypeContinues) &&
|
|
|
|
(mxEv.getTs() - prevEvent.getTs() <= CONTINUATION_MAX_INTERVAL)) {
|
2016-02-12 16:39:38 +03:00
|
|
|
continuation = true;
|
|
|
|
}
|
2016-02-10 14:03:46 +03:00
|
|
|
|
2016-09-12 00:49:05 +03:00
|
|
|
/*
|
2016-08-19 00:15:53 +03:00
|
|
|
// Work out if this is still a continuation, as we are now showing commands
|
|
|
|
// and /me messages with their own little avatar. The case of a change of
|
|
|
|
// event type (commands) is handled above, but we need to handle the /me
|
|
|
|
// messages seperately as they have a msgtype of 'm.emote' but are classed
|
|
|
|
// as normal messages
|
|
|
|
if (prevEvent !== null && prevEvent.sender && mxEv.sender
|
|
|
|
&& mxEv.sender.userId === prevEvent.sender.userId
|
|
|
|
&& mxEv.getType() == prevEvent.getType()
|
|
|
|
&& prevEvent.getContent().msgtype === 'm.emote') {
|
|
|
|
continuation = false;
|
|
|
|
}
|
2016-09-12 00:49:05 +03:00
|
|
|
*/
|
2016-08-19 00:15:53 +03:00
|
|
|
|
2016-03-10 17:16:31 +03:00
|
|
|
// local echoes have a fake date, which could even be yesterday. Treat them
|
|
|
|
// as 'today' for the date separators.
|
2017-10-11 19:56:17 +03:00
|
|
|
let ts1 = mxEv.getTs();
|
|
|
|
let eventDate = mxEv.getDate();
|
2016-03-10 17:16:31 +03:00
|
|
|
if (mxEv.status) {
|
2016-12-22 20:54:30 +03:00
|
|
|
eventDate = new Date();
|
|
|
|
ts1 = eventDate.getTime();
|
2016-03-10 17:16:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// do we need a date separator since the last event?
|
2016-12-22 20:54:30 +03:00
|
|
|
if (this._wantsDateSeparator(prevEvent, eventDate)) {
|
2018-01-14 21:32:17 +03:00
|
|
|
const dateSeparator = <li key={ts1}><DateSeparator key={ts1} ts={ts1} /></li>;
|
2016-02-12 16:39:38 +03:00
|
|
|
ret.push(dateSeparator);
|
|
|
|
continuation = false;
|
|
|
|
}
|
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const eventId = mxEv.getId();
|
2018-06-16 11:48:57 +03:00
|
|
|
const highlight = (eventId === this.props.highlightedEventId);
|
2016-02-12 16:39:38 +03:00
|
|
|
|
|
|
|
// we can't use local echoes as scroll tokens, because their event IDs change.
|
|
|
|
// Local echos have a send "status".
|
2017-10-11 19:56:17 +03:00
|
|
|
const scrollToken = mxEv.status ? undefined : eventId;
|
2016-02-12 16:39:38 +03:00
|
|
|
|
2019-05-31 19:26:09 +03:00
|
|
|
const readReceipts = this._readReceiptsByEvent[eventId];
|
|
|
|
|
2016-02-12 16:39:38 +03:00
|
|
|
ret.push(
|
2019-05-07 18:05:56 +03:00
|
|
|
<li key={eventId}
|
|
|
|
ref={this._collectEventNode.bind(this, eventId)}
|
|
|
|
data-scroll-tokens={scrollToken}
|
|
|
|
>
|
|
|
|
<EventTile mxEvent={mxEv}
|
|
|
|
continuation={continuation}
|
|
|
|
isRedacted={mxEv.isRedacted()}
|
2019-05-15 13:49:43 +03:00
|
|
|
replacingEventId={mxEv.replacingEventId()}
|
2019-06-12 19:52:34 +03:00
|
|
|
editState={isEditing && this.props.editState}
|
2019-05-07 18:05:56 +03:00
|
|
|
onHeightChanged={this._onHeightChanged}
|
|
|
|
readReceipts={readReceipts}
|
|
|
|
readReceiptMap={this._readReceiptMap}
|
|
|
|
showUrlPreview={this.props.showUrlPreview}
|
|
|
|
checkUnmounting={this._isUnmounting}
|
2019-06-18 14:47:33 +03:00
|
|
|
eventSendStatus={mxEv.getAssociatedLocalEchoStatus()}
|
2019-05-07 18:05:56 +03:00
|
|
|
tileShape={this.props.tileShape}
|
|
|
|
isTwelveHour={this.props.isTwelveHour}
|
|
|
|
permalinkCreator={this.props.permalinkCreator}
|
|
|
|
last={last}
|
|
|
|
isSelectedEvent={highlight}
|
2019-05-08 20:16:27 +03:00
|
|
|
getRelationsForEvent={this.props.getRelationsForEvent}
|
2019-05-21 19:23:19 +03:00
|
|
|
showReactions={this.props.showReactions}
|
2019-05-07 18:05:56 +03:00
|
|
|
/>
|
|
|
|
</li>,
|
2016-02-12 16:39:38 +03:00
|
|
|
);
|
2016-02-10 14:03:46 +03:00
|
|
|
|
2016-02-12 16:39:38 +03:00
|
|
|
return ret;
|
|
|
|
},
|
2016-02-10 14:03:46 +03:00
|
|
|
|
2016-12-22 20:54:30 +03:00
|
|
|
_wantsDateSeparator: function(prevEvent, nextEventDate) {
|
2016-03-10 17:16:31 +03:00
|
|
|
if (prevEvent == null) {
|
2017-09-06 19:40:58 +03:00
|
|
|
// first event in the panel: depends if we could back-paginate from
|
|
|
|
// here.
|
|
|
|
return !this.props.suppressFirstDateSeparator;
|
2016-03-10 17:16:31 +03:00
|
|
|
}
|
2018-01-10 15:06:24 +03:00
|
|
|
return wantsDateSeparator(prevEvent.getDate(), nextEventDate);
|
2016-03-10 17:16:31 +03:00
|
|
|
},
|
|
|
|
|
2019-05-31 19:26:09 +03:00
|
|
|
// Get a list of read receipts that should be shown next to this event
|
2018-10-10 17:14:09 +03:00
|
|
|
// Receipts are objects which have a 'userId', 'roomMember' and 'ts'.
|
2016-04-19 21:38:54 +03:00
|
|
|
_getReadReceiptsForEvent: function(event) {
|
2016-12-09 14:24:10 +03:00
|
|
|
const myUserId = MatrixClientPeg.get().credentials.userId;
|
2016-04-19 21:38:54 +03:00
|
|
|
|
|
|
|
// get list of read receipts, sorted most recent first
|
2019-06-04 17:25:54 +03:00
|
|
|
const { room } = this.props;
|
2016-04-19 21:38:54 +03:00
|
|
|
if (!room) {
|
|
|
|
return null;
|
|
|
|
}
|
2017-10-11 19:56:17 +03:00
|
|
|
const receipts = [];
|
2016-12-09 14:24:10 +03:00
|
|
|
room.getReceiptsForEvent(event).forEach((r) => {
|
|
|
|
if (!r.userId || r.type !== "m.read" || r.userId === myUserId) {
|
|
|
|
return; // ignore non-read receipts and receipts from self.
|
|
|
|
}
|
2017-09-15 05:25:02 +03:00
|
|
|
if (MatrixClientPeg.get().isUserIgnored(r.userId)) {
|
|
|
|
return; // ignore ignored users
|
|
|
|
}
|
2017-10-11 19:56:17 +03:00
|
|
|
const member = room.getMember(r.userId);
|
2016-12-09 14:24:10 +03:00
|
|
|
receipts.push({
|
2018-10-10 17:14:09 +03:00
|
|
|
userId: r.userId,
|
2016-12-09 14:24:10 +03:00
|
|
|
roomMember: member,
|
|
|
|
ts: r.data ? r.data.ts : 0,
|
|
|
|
});
|
|
|
|
});
|
2019-05-31 19:26:09 +03:00
|
|
|
return receipts;
|
|
|
|
},
|
2016-04-19 21:38:54 +03:00
|
|
|
|
2019-05-31 19:26:09 +03:00
|
|
|
// Get an object that maps from event ID to a list of read receipts that
|
|
|
|
// should be shown next to that event. If a hidden event has read receipts,
|
|
|
|
// they are folded into the receipts of the last shown event.
|
|
|
|
_getReadReceiptsByShownEvent: function() {
|
|
|
|
const receiptsByEvent = {};
|
2019-06-03 15:28:31 +03:00
|
|
|
const receiptsByUserId = {};
|
2019-05-31 19:26:09 +03:00
|
|
|
|
|
|
|
let lastShownEventId;
|
|
|
|
for (const event of this.props.events) {
|
|
|
|
if (this._shouldShowEvent(event)) {
|
|
|
|
lastShownEventId = event.getId();
|
|
|
|
}
|
|
|
|
if (!lastShownEventId) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-06-03 15:28:31 +03:00
|
|
|
|
2019-05-31 19:26:09 +03:00
|
|
|
const existingReceipts = receiptsByEvent[lastShownEventId] || [];
|
|
|
|
const newReceipts = this._getReadReceiptsForEvent(event);
|
|
|
|
receiptsByEvent[lastShownEventId] = existingReceipts.concat(newReceipts);
|
2019-06-03 15:28:31 +03:00
|
|
|
|
|
|
|
// Record these receipts along with their last shown event ID for
|
|
|
|
// each associated user ID.
|
|
|
|
for (const receipt of newReceipts) {
|
|
|
|
receiptsByUserId[receipt.userId] = {
|
|
|
|
lastShownEventId,
|
|
|
|
receipt,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's possible in some cases (for example, when a read receipt
|
|
|
|
// advances before we have paginated in the new event that it's marking
|
|
|
|
// received) that we can temporarily not have a matching event for
|
|
|
|
// someone which had one in the last. By looking through our previous
|
|
|
|
// mapping of receipts by user ID, we can cover recover any receipts
|
|
|
|
// that would have been lost by using the same event ID from last time.
|
|
|
|
for (const userId in this._readReceiptsByUserId) {
|
|
|
|
if (receiptsByUserId[userId]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const { lastShownEventId, receipt } = this._readReceiptsByUserId[userId];
|
|
|
|
const existingReceipts = receiptsByEvent[lastShownEventId] || [];
|
|
|
|
receiptsByEvent[lastShownEventId] = existingReceipts.concat(receipt);
|
|
|
|
receiptsByUserId[userId] = { lastShownEventId, receipt };
|
2019-05-31 19:26:09 +03:00
|
|
|
}
|
2019-06-03 15:28:31 +03:00
|
|
|
this._readReceiptsByUserId = receiptsByUserId;
|
2019-05-31 19:26:09 +03:00
|
|
|
|
|
|
|
// After grouping receipts by shown events, do another pass to sort each
|
|
|
|
// receipt list.
|
|
|
|
for (const eventId in receiptsByEvent) {
|
|
|
|
receiptsByEvent[eventId].sort((r1, r2) => {
|
|
|
|
return r2.ts - r1.ts;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return receiptsByEvent;
|
2016-04-19 21:38:54 +03:00
|
|
|
},
|
|
|
|
|
2016-02-24 20:26:34 +03:00
|
|
|
_getReadMarkerTile: function(visible) {
|
2017-10-11 19:56:17 +03:00
|
|
|
let hr;
|
2016-02-24 20:26:34 +03:00
|
|
|
if (visible) {
|
|
|
|
hr = <hr className="mx_RoomView_myReadMarker"
|
|
|
|
style={{opacity: 1, width: '99%'}}
|
|
|
|
/>;
|
|
|
|
}
|
2016-02-12 16:39:38 +03:00
|
|
|
|
|
|
|
return (
|
2016-02-24 20:26:34 +03:00
|
|
|
<li key="_readupto" ref="readMarkerNode"
|
2016-02-12 16:39:38 +03:00
|
|
|
className="mx_RoomView_myReadMarker_container">
|
2017-10-11 19:56:17 +03:00
|
|
|
{ hr }
|
2016-02-12 16:39:38 +03:00
|
|
|
</li>
|
|
|
|
);
|
|
|
|
},
|
2016-02-10 14:03:46 +03:00
|
|
|
|
2016-03-31 20:19:57 +03:00
|
|
|
_startAnimation: function(ghostNode) {
|
2016-06-07 21:55:24 +03:00
|
|
|
if (this._readMarkerGhostNode) {
|
|
|
|
Velocity.Utilities.removeData(this._readMarkerGhostNode);
|
2016-06-07 20:22:01 +03:00
|
|
|
}
|
2016-06-07 21:55:24 +03:00
|
|
|
this._readMarkerGhostNode = ghostNode;
|
2016-06-07 20:22:01 +03:00
|
|
|
|
|
|
|
if (ghostNode) {
|
2019-05-30 16:57:44 +03:00
|
|
|
// eslint-disable-next-line new-cap
|
2016-06-07 20:22:01 +03:00
|
|
|
Velocity(ghostNode, {opacity: '0', width: '10%'},
|
|
|
|
{duration: 400, easing: 'easeInSine',
|
|
|
|
delay: 1000});
|
|
|
|
}
|
2016-03-31 20:19:57 +03:00
|
|
|
},
|
2016-02-15 12:50:12 +03:00
|
|
|
|
2016-03-31 20:19:57 +03:00
|
|
|
_getReadMarkerGhostTile: function() {
|
2017-10-11 19:56:17 +03:00
|
|
|
const hr = <hr className="mx_RoomView_myReadMarker"
|
2016-02-12 16:39:38 +03:00
|
|
|
style={{opacity: 1, width: '99%'}}
|
2016-03-31 20:19:57 +03:00
|
|
|
ref={this._startAnimation}
|
2016-02-12 16:39:38 +03:00
|
|
|
/>;
|
2016-02-15 12:50:12 +03:00
|
|
|
|
|
|
|
// give it a key which depends on the event id. That will ensure that
|
|
|
|
// we get a new DOM node (restarting the animation) when the ghost
|
|
|
|
// moves to a different event.
|
2016-02-12 16:39:38 +03:00
|
|
|
return (
|
2016-02-15 12:50:12 +03:00
|
|
|
<li key={"_readuptoghost_"+this.currentGhostEventId}
|
2016-02-11 18:38:13 +03:00
|
|
|
className="mx_RoomView_myReadMarker_container">
|
2017-10-11 19:56:17 +03:00
|
|
|
{ hr }
|
2016-02-12 16:39:38 +03:00
|
|
|
</li>
|
|
|
|
);
|
2016-02-10 14:03:46 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_collectEventNode: function(eventId, node) {
|
|
|
|
this.eventNodes[eventId] = node;
|
|
|
|
},
|
2016-02-11 18:38:13 +03:00
|
|
|
|
2016-04-02 02:36:19 +03:00
|
|
|
// once dynamic content in the events load, make the scrollPanel check the
|
|
|
|
// scroll offsets.
|
2019-03-06 14:27:16 +03:00
|
|
|
_onHeightChanged: function() {
|
2017-10-11 19:56:17 +03:00
|
|
|
const scrollPanel = this.refs.scrollPanel;
|
2016-04-02 02:36:19 +03:00
|
|
|
if (scrollPanel) {
|
2019-03-20 19:37:34 +03:00
|
|
|
scrollPanel.checkScroll();
|
2016-04-02 02:36:19 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-03-20 19:02:53 +03:00
|
|
|
_onTypingShown: function() {
|
2018-11-13 11:15:16 +03:00
|
|
|
const scrollPanel = this.refs.scrollPanel;
|
2019-03-20 19:02:53 +03:00
|
|
|
// this will make the timeline grow, so checkScroll
|
|
|
|
scrollPanel.checkScroll();
|
2019-01-18 20:53:54 +03:00
|
|
|
if (scrollPanel && scrollPanel.getScrollState().stuckAtBottom) {
|
2019-03-20 19:02:53 +03:00
|
|
|
scrollPanel.preventShrinking();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onTypingHidden: function() {
|
|
|
|
const scrollPanel = this.refs.scrollPanel;
|
|
|
|
if (scrollPanel) {
|
|
|
|
// as hiding the typing notifications doesn't
|
|
|
|
// update the scrollPanel, we tell it to apply
|
|
|
|
// the shrinking prevention once the typing notifs are hidden
|
|
|
|
scrollPanel.updatePreventShrinking();
|
2019-03-20 19:38:05 +03:00
|
|
|
// order is important here as checkScroll will scroll down to
|
|
|
|
// reveal added padding to balance the notifs disappearing.
|
|
|
|
scrollPanel.checkScroll();
|
2018-11-13 11:15:16 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-01-21 19:35:40 +03:00
|
|
|
updateTimelineMinHeight: function() {
|
|
|
|
const scrollPanel = this.refs.scrollPanel;
|
|
|
|
|
|
|
|
if (scrollPanel) {
|
2019-02-04 21:27:22 +03:00
|
|
|
const isAtBottom = scrollPanel.isAtBottom();
|
|
|
|
const whoIsTyping = this.refs.whoIsTyping;
|
|
|
|
const isTypingVisible = whoIsTyping && whoIsTyping.isVisible();
|
2019-02-22 16:48:56 +03:00
|
|
|
// when messages get added to the timeline,
|
|
|
|
// but somebody else is still typing,
|
|
|
|
// update the min-height, so once the last
|
|
|
|
// person stops typing, no jumping occurs
|
2019-02-04 21:27:22 +03:00
|
|
|
if (isAtBottom && isTypingVisible) {
|
2019-03-20 19:02:53 +03:00
|
|
|
scrollPanel.preventShrinking();
|
2019-01-21 19:35:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-03-20 19:02:53 +03:00
|
|
|
onTimelineReset: function() {
|
2019-02-22 18:23:05 +03:00
|
|
|
const scrollPanel = this.refs.scrollPanel;
|
|
|
|
if (scrollPanel) {
|
2019-03-20 19:02:53 +03:00
|
|
|
scrollPanel.clearPreventShrinking();
|
2019-02-22 18:23:05 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-02-11 18:38:13 +03:00
|
|
|
render: function() {
|
2017-10-11 19:56:17 +03:00
|
|
|
const ScrollPanel = sdk.getComponent("structures.ScrollPanel");
|
2018-11-12 18:09:51 +03:00
|
|
|
const WhoIsTypingTile = sdk.getComponent("rooms.WhoIsTypingTile");
|
2017-10-11 19:56:17 +03:00
|
|
|
const Spinner = sdk.getComponent("elements.Spinner");
|
2018-06-16 11:48:57 +03:00
|
|
|
let topSpinner;
|
|
|
|
let bottomSpinner;
|
2016-02-24 16:38:55 +03:00
|
|
|
if (this.props.backPaginating) {
|
|
|
|
topSpinner = <li key="_topSpinner"><Spinner /></li>;
|
|
|
|
}
|
|
|
|
if (this.props.forwardPaginating) {
|
|
|
|
bottomSpinner = <li key="_bottomSpinner"><Spinner /></li>;
|
|
|
|
}
|
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const style = this.props.hidden ? { display: 'none' } : {};
|
2016-04-12 19:18:32 +03:00
|
|
|
|
2017-10-25 13:09:48 +03:00
|
|
|
const className = classNames(
|
2017-10-25 17:15:49 +03:00
|
|
|
this.props.className,
|
2017-10-25 13:09:48 +03:00
|
|
|
{
|
|
|
|
"mx_MessagePanel_alwaysShowTimestamps": this.props.alwaysShowTimestamps,
|
|
|
|
},
|
|
|
|
);
|
2017-05-27 02:14:16 +03:00
|
|
|
|
2018-11-30 15:53:30 +03:00
|
|
|
let whoIsTyping;
|
2019-05-20 23:53:15 +03:00
|
|
|
if (this.props.room && !this.props.tileShape) {
|
2019-03-20 19:02:53 +03:00
|
|
|
whoIsTyping = (<WhoIsTypingTile
|
|
|
|
room={this.props.room}
|
|
|
|
onShown={this._onTypingShown}
|
|
|
|
onHidden={this._onTypingHidden}
|
|
|
|
ref="whoIsTyping" />
|
|
|
|
);
|
2018-11-30 15:53:30 +03:00
|
|
|
}
|
|
|
|
|
2016-02-11 18:38:13 +03:00
|
|
|
return (
|
2017-10-11 19:56:17 +03:00
|
|
|
<ScrollPanel ref="scrollPanel" className={className}
|
|
|
|
onScroll={this.props.onScroll}
|
|
|
|
onResize={this.onResize}
|
|
|
|
onFillRequest={this.props.onFillRequest}
|
|
|
|
onUnfillRequest={this.props.onUnfillRequest}
|
|
|
|
style={style}
|
2019-03-12 18:36:12 +03:00
|
|
|
stickyBottom={this.props.stickyBottom}
|
|
|
|
resizeNotifier={this.props.resizeNotifier}>
|
2017-10-11 19:56:17 +03:00
|
|
|
{ topSpinner }
|
|
|
|
{ this._getEventTiles() }
|
2018-11-30 15:53:30 +03:00
|
|
|
{ whoIsTyping }
|
2017-10-11 19:56:17 +03:00
|
|
|
{ bottomSpinner }
|
2016-02-11 18:38:13 +03:00
|
|
|
</ScrollPanel>
|
|
|
|
);
|
|
|
|
},
|
2016-02-10 14:03:46 +03:00
|
|
|
});
|