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
|
2019-11-22 15:07:25 +03:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
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-12-08 15:16:17 +03:00
|
|
|
import React, {createRef} from 'react';
|
2017-06-15 21:57:48 +03:00
|
|
|
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';
|
2019-12-20 04:19:56 +03:00
|
|
|
import * as sdk from '../../index';
|
2016-02-10 14:03:46 +03:00
|
|
|
|
2019-12-21 00:13:46 +03:00
|
|
|
import {MatrixClientPeg} from '../../MatrixClientPeg';
|
2019-05-02 17:11:06 +03:00
|
|
|
import SettingsStore from '../../settings/SettingsStore';
|
2019-09-12 17:33:52 +03:00
|
|
|
import {_t} from "../../languageHandler";
|
2019-12-21 00:43:06 +03:00
|
|
|
import {haveTileForEvent} from "../views/rooms/EventTile";
|
2020-03-04 21:44:12 +03:00
|
|
|
import {textForEvent} from "../../TextForEvent";
|
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'];
|
|
|
|
|
2019-07-03 10:58:34 +03:00
|
|
|
const isMembershipChange = (e) => e.getType() === 'm.room.member' || e.getType() === 'm.room.third_party_invite';
|
|
|
|
|
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
|
|
|
*/
|
2019-11-22 15:07:25 +03:00
|
|
|
export default class MessagePanel extends React.Component {
|
2019-11-22 16:01:56 +03:00
|
|
|
static 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,
|
2019-11-22 15:07:25 +03:00
|
|
|
};
|
2016-02-10 14:03:46 +03:00
|
|
|
|
2019-11-22 16:11:36 +03:00
|
|
|
constructor() {
|
|
|
|
super();
|
2016-02-15 12:50:12 +03:00
|
|
|
|
2019-11-26 22:06:02 +03:00
|
|
|
this.state = {
|
|
|
|
// previous positions the read marker has been in, so we can
|
|
|
|
// display 'ghost' read markers that are animating away
|
|
|
|
ghostReadMarkers: [],
|
2020-02-09 00:21:30 +03:00
|
|
|
showTypingNotifications: SettingsStore.getValue("showTypingNotifications"),
|
2019-11-26 22:06:02 +03:00
|
|
|
};
|
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 = {};
|
|
|
|
|
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");
|
|
|
|
|
2019-11-22 16:11:36 +03:00
|
|
|
this._isMounted = false;
|
2019-12-08 15:16:17 +03:00
|
|
|
|
|
|
|
this._readMarkerNode = createRef();
|
|
|
|
this._whoIsTyping = createRef();
|
|
|
|
this._scrollPanel = createRef();
|
2020-02-09 00:21:30 +03:00
|
|
|
|
|
|
|
this._showTypingNotificationsWatcherRef =
|
2020-02-11 12:32:09 +03:00
|
|
|
SettingsStore.watchSetting("showTypingNotifications", null, this.onShowTypingNotificationsChange);
|
2019-11-22 16:11:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2016-04-22 19:03:15 +03:00
|
|
|
this._isMounted = true;
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
2016-04-22 19:03:15 +03:00
|
|
|
|
2019-11-22 15:07:25 +03:00
|
|
|
componentWillUnmount() {
|
2016-04-22 19:03:15 +03:00
|
|
|
this._isMounted = false;
|
2020-02-09 00:21:30 +03:00
|
|
|
SettingsStore.unwatchSetting(this._showTypingNotificationsWatcherRef);
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
2016-02-15 12:50:12 +03:00
|
|
|
|
2019-11-26 22:06:02 +03:00
|
|
|
componentDidUpdate(prevProps, prevState) {
|
|
|
|
if (prevProps.readMarkerVisible && this.props.readMarkerEventId !== prevProps.readMarkerEventId) {
|
|
|
|
const ghostReadMarkers = this.state.ghostReadMarkers;
|
|
|
|
ghostReadMarkers.push(prevProps.readMarkerEventId);
|
|
|
|
this.setState({
|
|
|
|
ghostReadMarkers,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-09 00:21:30 +03:00
|
|
|
onShowTypingNotificationsChange = () => {
|
|
|
|
this.setState({
|
|
|
|
showTypingNotifications: SettingsStore.getValue("showTypingNotifications"),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-02-10 14:03:46 +03:00
|
|
|
/* get the DOM node representing the given event */
|
2019-11-22 15:07:25 +03:00
|
|
|
getNodeForEventId(eventId) {
|
2016-02-10 14:03:46 +03:00
|
|
|
if (!this.eventNodes) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.eventNodes[eventId];
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
2016-02-10 14:03:46 +03:00
|
|
|
|
|
|
|
/* return true if the content is fully scrolled down right now; else false.
|
|
|
|
*/
|
2019-11-22 15:07:25 +03:00
|
|
|
isAtBottom() {
|
2019-12-08 15:16:17 +03:00
|
|
|
return this._scrollPanel.current && this._scrollPanel.current.isAtBottom();
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
2016-02-10 14:03:46 +03:00
|
|
|
|
|
|
|
/* get the current scroll state. See ScrollPanel.getScrollState for
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* returns null if we are not mounted.
|
|
|
|
*/
|
2019-11-22 15:07:25 +03:00
|
|
|
getScrollState() {
|
2019-12-08 15:16:17 +03:00
|
|
|
return this._scrollPanel.current ? this._scrollPanel.current.getScrollState() : null;
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
2016-02-10 14:03:46 +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 within the window
|
|
|
|
// +1: read marker is below the window
|
2019-11-22 15:07:25 +03:00
|
|
|
getReadMarkerPosition() {
|
2019-12-08 15:16:17 +03:00
|
|
|
const readMarker = this._readMarkerNode.current;
|
|
|
|
const messageWrapper = this._scrollPanel.current;
|
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;
|
|
|
|
}
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
2016-02-24 20:26:34 +03:00
|
|
|
|
2016-04-05 15:14:11 +03:00
|
|
|
/* jump to the top of the content.
|
|
|
|
*/
|
2019-11-22 15:07:25 +03:00
|
|
|
scrollToTop() {
|
2019-12-08 15:16:17 +03:00
|
|
|
if (this._scrollPanel.current) {
|
|
|
|
this._scrollPanel.current.scrollToTop();
|
2016-04-05 15:14:11 +03:00
|
|
|
}
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
2016-04-05 15:14:11 +03:00
|
|
|
|
2016-02-10 14:03:46 +03:00
|
|
|
/* jump to the bottom of the content.
|
|
|
|
*/
|
2019-11-22 15:07:25 +03:00
|
|
|
scrollToBottom() {
|
2019-12-08 15:16:17 +03:00
|
|
|
if (this._scrollPanel.current) {
|
|
|
|
this._scrollPanel.current.scrollToBottom();
|
2016-02-10 14:03:46 +03:00
|
|
|
}
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
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
|
|
|
*/
|
2019-11-22 15:07:25 +03:00
|
|
|
scrollRelative(mult) {
|
2019-12-08 15:16:17 +03:00
|
|
|
if (this._scrollPanel.current) {
|
|
|
|
this._scrollPanel.current.scrollRelative(mult);
|
2016-04-05 15:14:11 +03:00
|
|
|
}
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
2016-04-05 15:14:11 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2019-11-22 15:07:25 +03:00
|
|
|
handleScrollKey(ev) {
|
2019-12-08 15:16:17 +03:00
|
|
|
if (this._scrollPanel.current) {
|
|
|
|
this._scrollPanel.current.handleScrollKey(ev);
|
2016-04-05 15:14:11 +03:00
|
|
|
}
|
2019-11-22 15:07:25 +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
|
|
|
*/
|
2019-11-22 15:07:25 +03:00
|
|
|
scrollToEvent(eventId, pixelOffset, offsetBase) {
|
2019-12-08 15:16:17 +03:00
|
|
|
if (this._scrollPanel.current) {
|
|
|
|
this._scrollPanel.current.scrollToToken(eventId, pixelOffset, offsetBase);
|
2016-02-10 14:03:46 +03:00
|
|
|
}
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
2016-02-10 14:03:46 +03:00
|
|
|
|
2019-11-22 15:07:25 +03:00
|
|
|
scrollToEventIfNeeded(eventId) {
|
2019-05-24 16:38:51 +03:00
|
|
|
const node = this.eventNodes[eventId];
|
|
|
|
if (node) {
|
|
|
|
node.scrollIntoView({block: "nearest", behavior: "instant"});
|
|
|
|
}
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
2019-05-24 16:38:51 +03:00
|
|
|
|
2016-02-10 14:03:46 +03:00
|
|
|
/* check the scroll state and send out pagination requests if necessary.
|
|
|
|
*/
|
2019-11-22 15:07:25 +03:00
|
|
|
checkFillState() {
|
2019-12-08 15:16:17 +03:00
|
|
|
if (this._scrollPanel.current) {
|
|
|
|
this._scrollPanel.current.checkFillState();
|
2016-02-10 14:03:46 +03:00
|
|
|
}
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
2016-02-10 14:03:46 +03:00
|
|
|
|
2019-11-22 15:07:25 +03:00
|
|
|
_isUnmounting() {
|
2016-04-22 19:03:15 +03:00
|
|
|
return !this._isMounted;
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
2016-04-22 19:03:15 +03:00
|
|
|
|
2017-05-31 15:36:19 +03:00
|
|
|
// TODO: Implement granular (per-room) hide options
|
2019-11-22 15:07:25 +03:00
|
|
|
_shouldShowEvent(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;
|
|
|
|
}
|
|
|
|
|
2019-12-21 00:43:06 +03:00
|
|
|
if (!haveTileForEvent(mxEv)) {
|
2017-05-31 15:36:19 +03:00
|
|
|
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);
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
2017-05-31 15:36:19 +03:00
|
|
|
|
2019-11-26 22:06:02 +03:00
|
|
|
_readMarkerForEvent(eventId, isLastEvent) {
|
|
|
|
const visible = !isLastEvent && this.props.readMarkerVisible;
|
|
|
|
|
|
|
|
if (this.props.readMarkerEventId === eventId) {
|
|
|
|
let hr;
|
|
|
|
// 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 (visible) {
|
|
|
|
hr = <hr className="mx_RoomView_myReadMarker"
|
|
|
|
style={{opacity: 1, width: '99%'}}
|
|
|
|
/>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-12-08 15:16:17 +03:00
|
|
|
<li key={"readMarker_"+eventId} ref={this._readMarkerNode}
|
2019-11-26 22:06:02 +03:00
|
|
|
className="mx_RoomView_myReadMarker_container">
|
|
|
|
{ hr }
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
} else if (this.state.ghostReadMarkers.includes(eventId)) {
|
|
|
|
// We render 'ghost' read markers in the DOM while they
|
|
|
|
// transition away. This allows the actual read marker
|
|
|
|
// to be in the right place straight away without having
|
|
|
|
// to wait for the transition to finish.
|
|
|
|
// There are probably much simpler ways to do this transition,
|
|
|
|
// possibly using react-transition-group which handles keeping
|
|
|
|
// elements in the DOM whilst they transition out, although our
|
|
|
|
// case is a little more complex because only some of the items
|
|
|
|
// transition (ie. the read markers do but the event tiles do not)
|
|
|
|
// and TransitionGroup requires that all its children are Transitions.
|
|
|
|
const hr = <hr className="mx_RoomView_myReadMarker"
|
|
|
|
ref={this._collectGhostReadMarker}
|
|
|
|
onTransitionEnd={this._onGhostTransitionEnd}
|
|
|
|
data-eventid={eventId}
|
|
|
|
/>;
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
return (
|
|
|
|
<li key={"_readuptoghost_"+eventId}
|
|
|
|
className="mx_RoomView_myReadMarker_container">
|
|
|
|
{ hr }
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
_collectGhostReadMarker = (node) => {
|
|
|
|
if (node) {
|
|
|
|
// now the element has appeared, change the style which will trigger the CSS transition
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
node.style.width = '10%';
|
|
|
|
node.style.opacity = '0';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
_onGhostTransitionEnd = (ev) => {
|
|
|
|
// we can now clean up the ghost element
|
|
|
|
const finishedEventId = ev.target.dataset.eventid;
|
|
|
|
this.setState({
|
|
|
|
ghostReadMarkers: this.state.ghostReadMarkers.filter(eid => eid !== finishedEventId),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-11-22 15:07:25 +03:00
|
|
|
_getEventTiles() {
|
2016-02-12 16:39:38 +03:00
|
|
|
this.eventNodes = {};
|
|
|
|
|
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
|
|
|
|
2019-05-31 19:26:09 +03:00
|
|
|
this._readReceiptsByEvent = {};
|
|
|
|
if (this.props.showReadReceipts) {
|
|
|
|
this._readReceiptsByEvent = this._getReadReceiptsByShownEvent();
|
|
|
|
}
|
|
|
|
|
2020-02-11 23:19:32 +03:00
|
|
|
let grouper = null;
|
|
|
|
|
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
|
|
|
|
2020-02-11 23:19:32 +03:00
|
|
|
if (grouper) {
|
|
|
|
if (grouper.shouldGroup(mxEv)) {
|
|
|
|
grouper.add(mxEv);
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
// not part of group, so get the group tiles, close the
|
|
|
|
// group, and continue like a normal event
|
|
|
|
ret.push(...grouper.getTiles());
|
|
|
|
prevEvent = grouper.getNewPrevEvent();
|
|
|
|
grouper = null;
|
2019-09-12 17:33:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-11 23:19:32 +03:00
|
|
|
for (const Grouper of groupers) {
|
|
|
|
if (Grouper.canStartGroup(this, mxEv)) {
|
|
|
|
grouper = new Grouper(this, mxEv, prevEvent, lastShownEvent);
|
2017-04-27 16:16:50 +03:00
|
|
|
}
|
2016-11-08 19:34:02 +03:00
|
|
|
}
|
2020-02-11 23:19:32 +03:00
|
|
|
if (!grouper) {
|
|
|
|
const wantTile = this._shouldShowEvent(mxEv);
|
|
|
|
if (wantTile) {
|
|
|
|
// 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));
|
|
|
|
prevEvent = mxEv;
|
|
|
|
}
|
2016-11-08 19:34:02 +03:00
|
|
|
|
2020-02-11 23:19:32 +03:00
|
|
|
const readMarker = this._readMarkerForEvent(eventId, i >= lastShownNonLocalEchoIndex);
|
|
|
|
if (readMarker) ret.push(readMarker);
|
2016-02-23 15:56:54 +03:00
|
|
|
}
|
2020-02-11 23:19:32 +03:00
|
|
|
}
|
2016-02-12 16:39:38 +03:00
|
|
|
|
2020-02-11 23:19:32 +03:00
|
|
|
if (grouper) {
|
|
|
|
ret.push(...grouper.getTiles());
|
2016-02-12 16:39:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
2016-02-12 16:39:38 +03:00
|
|
|
|
2019-11-22 15:07:25 +03:00
|
|
|
_getTilesForEvent(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 &&
|
2020-03-20 12:41:43 +03:00
|
|
|
// if we don't have tile for previous event then it was shown by showHiddenEvents and has no SenderProfile
|
|
|
|
haveTileForEvent(prevEvent) && (mxEv.getType() === prevEvent.getType() || eventTypeContinues) &&
|
2018-06-16 11:45:06 +03:00
|
|
|
(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];
|
|
|
|
|
2019-11-29 05:45:37 +03:00
|
|
|
// Dev note: `this._isUnmounting.bind(this)` is important - it ensures that
|
|
|
|
// the function is run in the context of this class and not EventTile, therefore
|
|
|
|
// ensuring the right `this._mounted` variable is used by read receipts (which
|
|
|
|
// don't update their position if we, the MessagePanel, is unmounting).
|
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-07-17 18:56:15 +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}
|
2019-11-29 05:45:37 +03:00
|
|
|
checkUnmounting={this._isUnmounting.bind(this)}
|
2019-06-18 15:57:58 +03:00
|
|
|
eventSendStatus={mxEv.getAssociatedStatus()}
|
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;
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
2016-02-10 14:03:46 +03:00
|
|
|
|
2019-11-22 15:07:25 +03:00
|
|
|
_wantsDateSeparator(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);
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
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'.
|
2019-11-22 15:07:25 +03:00
|
|
|
_getReadReceiptsForEvent(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;
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
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.
|
2019-11-22 15:07:25 +03:00
|
|
|
_getReadReceiptsByShownEvent() {
|
2019-05-31 19:26:09 +03:00
|
|
|
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;
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
2016-04-19 21:38:54 +03:00
|
|
|
|
2019-11-22 15:07:25 +03:00
|
|
|
_collectEventNode = (eventId, node) => {
|
2016-02-10 14:03:46 +03:00
|
|
|
this.eventNodes[eventId] = node;
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
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-11-22 15:07:25 +03:00
|
|
|
_onHeightChanged = () => {
|
2019-12-08 15:16:17 +03:00
|
|
|
const scrollPanel = this._scrollPanel.current;
|
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-11-22 15:07:25 +03:00
|
|
|
};
|
2016-04-02 02:36:19 +03:00
|
|
|
|
2019-11-22 15:07:25 +03:00
|
|
|
_onTypingShown = () => {
|
2019-12-08 15:16:17 +03:00
|
|
|
const scrollPanel = this._scrollPanel.current;
|
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();
|
|
|
|
}
|
2019-11-22 15:07:25 +03:00
|
|
|
};
|
2019-03-20 19:02:53 +03:00
|
|
|
|
2019-11-22 15:07:25 +03:00
|
|
|
_onTypingHidden = () => {
|
2019-12-08 15:16:17 +03:00
|
|
|
const scrollPanel = this._scrollPanel.current;
|
2019-03-20 19:02:53 +03:00
|
|
|
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-11-22 15:07:25 +03:00
|
|
|
};
|
2018-11-13 11:15:16 +03:00
|
|
|
|
2019-11-22 15:07:25 +03:00
|
|
|
updateTimelineMinHeight() {
|
2019-12-08 15:16:17 +03:00
|
|
|
const scrollPanel = this._scrollPanel.current;
|
2019-01-21 19:35:40 +03:00
|
|
|
|
|
|
|
if (scrollPanel) {
|
2019-02-04 21:27:22 +03:00
|
|
|
const isAtBottom = scrollPanel.isAtBottom();
|
2019-12-08 15:16:17 +03:00
|
|
|
const whoIsTyping = this._whoIsTyping.current;
|
2019-02-04 21:27:22 +03:00
|
|
|
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-11-22 15:07:25 +03:00
|
|
|
}
|
2019-01-21 19:35:40 +03:00
|
|
|
|
2019-11-22 15:07:25 +03:00
|
|
|
onTimelineReset() {
|
2019-12-08 15:16:17 +03:00
|
|
|
const scrollPanel = this._scrollPanel.current;
|
2019-02-22 18:23:05 +03:00
|
|
|
if (scrollPanel) {
|
2019-03-20 19:02:53 +03:00
|
|
|
scrollPanel.clearPreventShrinking();
|
2019-02-22 18:23:05 +03:00
|
|
|
}
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
2019-02-22 18:23:05 +03:00
|
|
|
|
2019-11-22 15:07:25 +03:00
|
|
|
render() {
|
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;
|
2020-02-09 00:21:30 +03:00
|
|
|
if (this.props.room && !this.props.tileShape && this.state.showTypingNotifications) {
|
2019-03-20 19:02:53 +03:00
|
|
|
whoIsTyping = (<WhoIsTypingTile
|
|
|
|
room={this.props.room}
|
|
|
|
onShown={this._onTypingShown}
|
|
|
|
onHidden={this._onTypingHidden}
|
2019-12-08 15:16:17 +03:00
|
|
|
ref={this._whoIsTyping} />
|
2019-03-20 19:02:53 +03:00
|
|
|
);
|
2018-11-30 15:53:30 +03:00
|
|
|
}
|
|
|
|
|
2016-02-11 18:38:13 +03:00
|
|
|
return (
|
2019-12-08 15:16:17 +03:00
|
|
|
<ScrollPanel
|
|
|
|
ref={this._scrollPanel}
|
|
|
|
className={className}
|
|
|
|
onScroll={this.props.onScroll}
|
|
|
|
onResize={this.onResize}
|
|
|
|
onFillRequest={this.props.onFillRequest}
|
|
|
|
onUnfillRequest={this.props.onUnfillRequest}
|
|
|
|
style={style}
|
|
|
|
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>
|
|
|
|
);
|
2019-11-22 15:07:25 +03:00
|
|
|
}
|
|
|
|
}
|
2020-02-11 23:19:32 +03:00
|
|
|
|
|
|
|
/* Grouper classes determine when events can be grouped together in a summary.
|
|
|
|
* Groupers should have the following methods:
|
|
|
|
* - canStartGroup (static): determines if a new group should be started with the
|
|
|
|
* given event
|
|
|
|
* - shouldGroup: determines if the given event should be added to an existing group
|
|
|
|
* - add: adds an event to an existing group (should only be called if shouldGroup
|
|
|
|
* return true)
|
|
|
|
* - getTiles: returns the tiles that represent the group
|
|
|
|
* - getNewPrevEvent: returns the event that should be used as the new prevEvent
|
|
|
|
* when determining things such as whether a date separator is necessary
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Wrap initial room creation events into an EventListSummary
|
|
|
|
// Grouping only events sent by the same user that sent the `m.room.create` and only until
|
|
|
|
// the first non-state event or membership event which is not regarding the sender of the `m.room.create` event
|
|
|
|
class CreationGrouper {
|
2020-02-11 23:34:14 +03:00
|
|
|
static canStartGroup = function(panel, ev) {
|
2020-02-11 23:19:32 +03:00
|
|
|
return ev.getType() === "m.room.create";
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(panel, createEvent, prevEvent, lastShownEvent) {
|
|
|
|
this.panel = panel;
|
|
|
|
this.createEvent = createEvent;
|
|
|
|
this.prevEvent = prevEvent;
|
|
|
|
this.lastShownEvent = lastShownEvent;
|
|
|
|
this.events = [];
|
|
|
|
// events that we include in the group but then eject out and place
|
|
|
|
// above the group.
|
|
|
|
this.ejectedEvents = [];
|
2020-04-02 17:07:50 +03:00
|
|
|
this.readMarker = panel._readMarkerForEvent(
|
|
|
|
createEvent.getId(),
|
|
|
|
createEvent === lastShownEvent,
|
|
|
|
);
|
2020-02-11 23:19:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
shouldGroup(ev) {
|
|
|
|
const panel = this.panel;
|
|
|
|
const createEvent = this.createEvent;
|
|
|
|
if (!panel._shouldShowEvent(ev)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (panel._wantsDateSeparator(this.createEvent, ev.getDate())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (ev.getType() === "m.room.member"
|
|
|
|
&& (ev.getStateKey() !== createEvent.getSender() || ev.getContent()["membership"] !== "join")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (ev.isState() && ev.getSender() === createEvent.getSender()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
add(ev) {
|
|
|
|
const panel = this.panel;
|
2020-04-02 17:07:50 +03:00
|
|
|
this.readMarker = this.readMarker || panel._readMarkerForEvent(
|
|
|
|
ev.getId(),
|
|
|
|
ev === this.lastShownEvent,
|
|
|
|
);
|
2020-02-11 23:19:32 +03:00
|
|
|
if (!panel._shouldShowEvent(ev)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ev.getType() === "m.room.encryption") {
|
|
|
|
this.ejectedEvents.push(ev);
|
|
|
|
} else {
|
|
|
|
this.events.push(ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getTiles() {
|
2020-02-26 01:40:15 +03:00
|
|
|
// If we don't have any events to group, don't even try to group them. The logic
|
|
|
|
// below assumes that we have a group of events to deal with, but we might not if
|
|
|
|
// the events we were supposed to group were redacted.
|
|
|
|
if (!this.events || !this.events.length) return [];
|
|
|
|
|
2020-02-11 23:19:32 +03:00
|
|
|
const DateSeparator = sdk.getComponent('messages.DateSeparator');
|
|
|
|
const EventListSummary = sdk.getComponent('views.elements.EventListSummary');
|
|
|
|
|
|
|
|
const panel = this.panel;
|
|
|
|
const ret = [];
|
|
|
|
const createEvent = this.createEvent;
|
|
|
|
const lastShownEvent = this.lastShownEvent;
|
|
|
|
|
|
|
|
if (panel._wantsDateSeparator(this.prevEvent, createEvent.getDate())) {
|
|
|
|
const ts = createEvent.getTs();
|
|
|
|
ret.push(
|
2020-02-11 23:34:14 +03:00
|
|
|
<li key={ts+'~'}><DateSeparator key={ts+'~'} ts={ts} /></li>,
|
|
|
|
);
|
2020-02-11 23:19:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// If this m.room.create event should be shown (room upgrade) then show it before the summary
|
|
|
|
if (panel._shouldShowEvent(createEvent)) {
|
|
|
|
// pass in the createEvent as prevEvent as well so no extra DateSeparator is rendered
|
|
|
|
ret.push(...panel._getTilesForEvent(createEvent, createEvent, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const ejected of this.ejectedEvents) {
|
|
|
|
ret.push(...panel._getTilesForEvent(
|
2020-02-11 23:34:14 +03:00
|
|
|
createEvent, ejected, createEvent === lastShownEvent,
|
2020-02-11 23:19:32 +03:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
const eventTiles = this.events.map((e) => {
|
|
|
|
// In order to prevent DateSeparators from appearing in the expanded form
|
|
|
|
// of EventListSummary, 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 DateSeparator is inserted.
|
|
|
|
return panel._getTilesForEvent(e, e, e === lastShownEvent);
|
|
|
|
}).reduce((a, b) => a.concat(b), []);
|
|
|
|
// Get sender profile from the latest event in the summary as the m.room.create doesn't contain one
|
|
|
|
const ev = this.events[this.events.length - 1];
|
|
|
|
ret.push(
|
|
|
|
<EventListSummary
|
|
|
|
key="roomcreationsummary"
|
|
|
|
events={this.events}
|
|
|
|
onToggle={panel._onHeightChanged} // Update scroll state
|
|
|
|
summaryMembers={[ev.sender]}
|
|
|
|
summaryText={_t("%(creator)s created and configured the room.", {
|
|
|
|
creator: ev.sender ? ev.sender.name : ev.getSender(),
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{ eventTiles }
|
2020-02-11 23:34:14 +03:00
|
|
|
</EventListSummary>,
|
2020-02-11 23:19:32 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
if (this.readMarker) {
|
2020-02-11 23:34:14 +03:00
|
|
|
ret.push(this.readMarker);
|
2020-02-11 23:19:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
getNewPrevEvent() {
|
|
|
|
return this.createEvent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wrap consecutive member events in a ListSummary, ignore if redacted
|
|
|
|
class MemberGrouper {
|
2020-02-11 23:34:14 +03:00
|
|
|
static canStartGroup = function(panel, ev) {
|
2020-02-11 23:19:32 +03:00
|
|
|
return panel._shouldShowEvent(ev) && isMembershipChange(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(panel, ev, prevEvent, lastShownEvent) {
|
|
|
|
this.panel = panel;
|
2020-04-02 17:07:50 +03:00
|
|
|
this.readMarker = panel._readMarkerForEvent(
|
|
|
|
ev.getId(),
|
|
|
|
ev === lastShownEvent,
|
|
|
|
);
|
2020-02-11 23:19:32 +03:00
|
|
|
this.events = [ev];
|
|
|
|
this.prevEvent = prevEvent;
|
|
|
|
this.lastShownEvent = lastShownEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldGroup(ev) {
|
2020-02-29 03:09:19 +03:00
|
|
|
if (this.panel._wantsDateSeparator(this.events[0], ev.getDate())) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-02-11 23:19:32 +03:00
|
|
|
return isMembershipChange(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
add(ev) {
|
2020-03-03 03:52:20 +03:00
|
|
|
if (ev.getType() === 'm.room.member') {
|
2020-03-04 21:44:12 +03:00
|
|
|
// We'll just double check that it's worth our time to do so, through an
|
|
|
|
// ugly hack. If textForEvent returns something, we should group it for
|
|
|
|
// rendering but if it doesn't then we'll exclude it.
|
|
|
|
const renderText = textForEvent(ev);
|
|
|
|
if (!renderText || renderText.trim().length === 0) return; // quietly ignore
|
2020-03-03 03:52:20 +03:00
|
|
|
}
|
2020-04-02 17:07:50 +03:00
|
|
|
this.readMarker = this.readMarker || this.panel._readMarkerForEvent(
|
|
|
|
ev.getId(),
|
|
|
|
ev === this.lastShownEvent,
|
|
|
|
);
|
2020-02-11 23:19:32 +03:00
|
|
|
this.events.push(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
getTiles() {
|
2020-02-26 01:40:15 +03:00
|
|
|
// If we don't have any events to group, don't even try to group them. The logic
|
|
|
|
// below assumes that we have a group of events to deal with, but we might not if
|
|
|
|
// the events we were supposed to group were redacted.
|
|
|
|
if (!this.events || !this.events.length) return [];
|
|
|
|
|
2020-02-11 23:19:32 +03:00
|
|
|
const DateSeparator = sdk.getComponent('messages.DateSeparator');
|
|
|
|
const MemberEventListSummary = sdk.getComponent('views.elements.MemberEventListSummary');
|
|
|
|
|
|
|
|
const panel = this.panel;
|
2020-02-11 23:34:14 +03:00
|
|
|
const lastShownEvent = this.lastShownEvent;
|
2020-02-11 23:19:32 +03:00
|
|
|
const ret = [];
|
|
|
|
|
|
|
|
if (panel._wantsDateSeparator(this.prevEvent, this.events[0].getDate())) {
|
|
|
|
const ts = this.events[0].getTs();
|
|
|
|
ret.push(
|
2020-02-11 23:34:14 +03:00
|
|
|
<li key={ts+'~'}><DateSeparator key={ts+'~'} ts={ts} /></li>,
|
2020-02-11 23:19:32 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that the key of the MemberEventListSummary does not change with new
|
|
|
|
// member events. This will prevent it from being re-created unnecessarily, and
|
|
|
|
// instead will allow new props to be provided. In turn, the shouldComponentUpdate
|
|
|
|
// method on MELS can be used to prevent unnecessary renderings.
|
|
|
|
//
|
|
|
|
// 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-" + (
|
|
|
|
this.prevEvent ? this.events[0].getId() : "initial"
|
|
|
|
);
|
|
|
|
|
|
|
|
let highlightInMels;
|
|
|
|
let eventTiles = this.events.map((e) => {
|
|
|
|
if (e.getId() === panel.props.highlightedEventId) {
|
|
|
|
highlightInMels = true;
|
|
|
|
}
|
|
|
|
// 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 DateSeparator is inserted.
|
|
|
|
return panel._getTilesForEvent(e, e, e === lastShownEvent);
|
|
|
|
}).reduce((a, b) => a.concat(b), []);
|
|
|
|
|
|
|
|
if (eventTiles.length === 0) {
|
|
|
|
eventTiles = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.push(
|
|
|
|
<MemberEventListSummary key={key}
|
|
|
|
events={this.events}
|
|
|
|
onToggle={panel._onHeightChanged} // Update scroll state
|
|
|
|
startExpanded={highlightInMels}
|
|
|
|
>
|
|
|
|
{ eventTiles }
|
2020-02-11 23:34:14 +03:00
|
|
|
</MemberEventListSummary>,
|
2020-02-11 23:19:32 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
if (this.readMarker) {
|
|
|
|
ret.push(this.readMarker);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
getNewPrevEvent() {
|
|
|
|
return this.events[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// all the grouper classes that we use
|
|
|
|
const groupers = [CreationGrouper, MemberGrouper];
|