2016-02-10 14:03:46 +03:00
|
|
|
/*
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var React = require('react');
|
2016-02-24 20:26:34 +03:00
|
|
|
var ReactDOM = require("react-dom");
|
2016-03-24 03:13:32 +03:00
|
|
|
var dis = require("../../dispatcher");
|
2016-02-10 14:03:46 +03:00
|
|
|
var sdk = require('../../index');
|
|
|
|
|
2017-01-20 17:22:27 +03:00
|
|
|
var MatrixClientPeg = require('../../MatrixClientPeg');
|
2016-04-19 21:38:54 +03:00
|
|
|
|
2016-12-22 20:54:30 +03:00
|
|
|
const MILLIS_IN_DAY = 86400000;
|
|
|
|
|
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.
|
2016-02-10 14:03:46 +03:00
|
|
|
hidden: React.PropTypes.bool,
|
|
|
|
|
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
|
|
|
|
backPaginating: React.PropTypes.bool,
|
|
|
|
|
|
|
|
// true to show a spinner at the end of the timeline to indicate
|
|
|
|
// forward-pagination in progress
|
|
|
|
forwardPaginating: React.PropTypes.bool,
|
|
|
|
|
2016-02-10 14:03:46 +03:00
|
|
|
// the list of MatrixEvents to display
|
|
|
|
events: React.PropTypes.array.isRequired,
|
|
|
|
|
|
|
|
// ID of an event to highlight. If undefined, no event will be highlighted.
|
|
|
|
highlightedEventId: React.PropTypes.string,
|
|
|
|
|
2016-07-18 03:35:42 +03:00
|
|
|
// Should we show URL Previews
|
|
|
|
showUrlPreview: React.PropTypes.bool,
|
|
|
|
|
2016-02-10 14:03:46 +03:00
|
|
|
// event after which we should show a read marker
|
|
|
|
readMarkerEventId: React.PropTypes.string,
|
|
|
|
|
2016-02-24 20:26:34 +03:00
|
|
|
// whether the read marker should be visible
|
|
|
|
readMarkerVisible: React.PropTypes.bool,
|
|
|
|
|
2016-02-10 14:03:46 +03:00
|
|
|
// the userid of our user. This is used to suppress the read marker
|
|
|
|
// for pending messages.
|
|
|
|
ourUserId: React.PropTypes.string,
|
|
|
|
|
|
|
|
// true to suppress the date at the start of the timeline
|
|
|
|
suppressFirstDateSeparator: React.PropTypes.bool,
|
|
|
|
|
2016-09-08 05:01:38 +03:00
|
|
|
// whether to show read receipts
|
|
|
|
manageReadReceipts: React.PropTypes.bool,
|
|
|
|
|
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.
|
|
|
|
stickyBottom: React.PropTypes.bool,
|
|
|
|
|
|
|
|
// callback which is called when the panel is scrolled.
|
|
|
|
onScroll: React.PropTypes.func,
|
|
|
|
|
|
|
|
// callback which is called when more content is needed.
|
|
|
|
onFillRequest: React.PropTypes.func,
|
2016-04-12 19:18:32 +03:00
|
|
|
|
|
|
|
// opacity for dynamic UI fading effects
|
|
|
|
opacity: React.PropTypes.number,
|
2016-09-07 04:16:29 +03:00
|
|
|
|
|
|
|
// className for the panel
|
|
|
|
className: React.PropTypes.string.isRequired,
|
2016-09-11 04:14:27 +03:00
|
|
|
|
|
|
|
// shape parameter to be passed to EventTiles
|
|
|
|
tileShape: React.PropTypes.string,
|
2017-05-20 00:45:56 +03:00
|
|
|
|
|
|
|
// show twelve hour timestamps
|
|
|
|
isTwelveHour: React.PropTypes.bool,
|
2017-05-27 02:14:16 +03:00
|
|
|
|
|
|
|
// show timestamps always
|
|
|
|
alwaysShowTimestamps: React.PropTypes.bool,
|
2017-06-02 06:23:07 +03:00
|
|
|
|
|
|
|
// hide redacted events as per old behaviour
|
|
|
|
hideRedactions: React.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
|
|
|
|
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
|
|
|
|
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() {
|
|
|
|
var readMarker = this.refs.readMarkerNode;
|
|
|
|
var messageWrapper = this.refs.scrollPanel;
|
|
|
|
|
|
|
|
if (!readMarker || !messageWrapper) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var wrapperRect = ReactDOM.findDOMNode(messageWrapper).getBoundingClientRect();
|
|
|
|
var readMarkerRect = readMarker.getBoundingClientRect();
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
*
|
|
|
|
* mult: -1 to page up, +1 to page down
|
|
|
|
*/
|
|
|
|
scrollRelative: function(mult) {
|
|
|
|
if (this.refs.scrollPanel) {
|
|
|
|
this.refs.scrollPanel.scrollRelative(mult);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scroll up/down in response to a scroll key
|
|
|
|
*/
|
|
|
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
},
|
|
|
|
|
2016-02-10 14:03:46 +03:00
|
|
|
_getEventTiles: function() {
|
2017-05-20 00:45:56 +03:00
|
|
|
const EventTile = sdk.getComponent('rooms.EventTile');
|
|
|
|
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 = {};
|
|
|
|
|
2016-02-23 15:56:54 +03:00
|
|
|
var 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
|
|
|
|
// differently for the last event in the list.
|
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.
|
|
|
|
var lastShownEventIndex = -1;
|
|
|
|
var lastShownNonLocalEchoIndex = -1;
|
2016-02-23 15:56:54 +03:00
|
|
|
for (i = this.props.events.length-1; i >= 0; i--) {
|
|
|
|
var mxEv = this.props.events[i];
|
2016-02-10 14:03:46 +03:00
|
|
|
if (!EventTile.haveTileForEvent(mxEv)) {
|
2016-02-23 15:56:54 +03:00
|
|
|
continue;
|
2016-02-10 14:03:46 +03:00
|
|
|
}
|
|
|
|
|
2016-03-22 19:34:12 +03:00
|
|
|
if (lastShownEventIndex < 0) {
|
|
|
|
lastShownEventIndex = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-02-12 16:39:38 +03:00
|
|
|
var ret = [];
|
|
|
|
|
|
|
|
var prevEvent = null; // the last event we showed
|
|
|
|
|
2016-02-15 12:50:12 +03:00
|
|
|
// assume there is no read marker until proven otherwise
|
|
|
|
var readMarkerVisible = false;
|
|
|
|
|
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 &&
|
|
|
|
this.currentReadMarkerEventId != this.props.readMarkerEventId) {
|
|
|
|
this.currentGhostEventId = null;
|
|
|
|
}
|
|
|
|
|
2017-04-23 06:05:50 +03:00
|
|
|
var 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-04-27 16:16:50 +03:00
|
|
|
let mxEv = this.props.events[i];
|
|
|
|
let wantTile = true;
|
|
|
|
let eventId = mxEv.getId();
|
|
|
|
let readMarkerInMels = false;
|
2016-02-23 15:56:54 +03:00
|
|
|
|
|
|
|
if (!EventTile.haveTileForEvent(mxEv)) {
|
|
|
|
wantTile = false;
|
|
|
|
}
|
|
|
|
|
2017-04-27 16:16:50 +03:00
|
|
|
let last = (i == lastShownEventIndex);
|
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-03-03 18:42:24 +03:00
|
|
|
if (isMembershipChange(mxEv) &&
|
|
|
|
EventTile.haveTileForEvent(mxEv) &&
|
|
|
|
!mxEv.isRedacted()
|
|
|
|
) {
|
2016-11-16 17:42:30 +03:00
|
|
|
let 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())) {
|
2017-06-01 18:53:24 +03:00
|
|
|
let dateSeparator = <li key={ts1+'~'}><DateSeparator key={ts1+'~'} ts={ts1} showTwelveHour={this.props.isTwelveHour}/></li>;
|
2016-11-16 17:42:30 +03:00
|
|
|
ret.push(dateSeparator);
|
|
|
|
}
|
|
|
|
|
2016-11-09 19:03:35 +03:00
|
|
|
let summarisedEvents = [mxEv];
|
2016-11-16 17:42:30 +03:00
|
|
|
for (;i + 1 < this.props.events.length; i++) {
|
|
|
|
let collapsedMxEv = this.props.events[i + 1];
|
2016-11-08 19:34:02 +03:00
|
|
|
|
2017-01-11 14:27:07 +03:00
|
|
|
// Ignore redacted member events
|
|
|
|
if (!EventTile.haveTileForEvent(collapsedMxEv)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-11-16 17:42:30 +03:00
|
|
|
if (!isMembershipChange(collapsedMxEv) ||
|
2016-12-22 20:54:30 +03:00
|
|
|
this._wantsDateSeparator(this.props.events[i], collapsedMxEv.getDate())) {
|
2016-11-08 19:34:02 +03:00
|
|
|
break;
|
|
|
|
}
|
2016-11-09 19:03:35 +03:00
|
|
|
summarisedEvents.push(collapsedMxEv);
|
2016-11-08 19:34:02 +03:00
|
|
|
}
|
2016-11-16 17:42:30 +03:00
|
|
|
// At this point, i = the index of the last event in the summary sequence
|
2016-11-10 16:14:04 +03:00
|
|
|
|
2016-11-10 20:26:36 +03:00
|
|
|
let eventTiles = summarisedEvents.map(
|
|
|
|
(e) => {
|
2017-04-27 16:16:50 +03:00
|
|
|
if (e.getId() === this.props.readMarkerEventId) {
|
|
|
|
readMarkerInMels = true;
|
|
|
|
}
|
2016-11-16 17:42:30 +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.
|
|
|
|
let ret = this._getTilesForEvent(e, e);
|
2016-11-10 20:26:36 +03:00
|
|
|
prevEvent = e;
|
|
|
|
return ret;
|
2016-11-08 19:34:02 +03:00
|
|
|
}
|
2017-01-20 17:22:27 +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
|
|
|
|
2016-11-08 19:34:02 +03:00
|
|
|
ret.push(
|
2016-11-16 17:25:52 +03:00
|
|
|
<MemberEventListSummary
|
2016-12-14 18:31:35 +03:00
|
|
|
key={key}
|
2016-11-16 17:25:52 +03:00
|
|
|
events={summarisedEvents}
|
2017-02-20 13:59:11 +03:00
|
|
|
onToggle={this._onWidgetLoad} // Update scroll state
|
|
|
|
>
|
2016-11-16 17:25:52 +03:00
|
|
|
{eventTiles}
|
2016-11-10 16:25:48 +03:00
|
|
|
</MemberEventListSummary>
|
2016-11-08 19:34:02 +03:00
|
|
|
);
|
2017-04-27 16:16:50 +03:00
|
|
|
|
|
|
|
if (readMarkerInMels) {
|
|
|
|
ret.push(this._getReadMarkerTile(visible));
|
|
|
|
}
|
|
|
|
|
2016-11-09 19:03:35 +03:00
|
|
|
continue;
|
2016-11-08 19:34:02 +03:00
|
|
|
}
|
|
|
|
|
2016-02-23 15:56:54 +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
|
|
|
|
2016-03-22 19:34:12 +03:00
|
|
|
var isVisibleReadMarker = false;
|
|
|
|
|
2016-02-24 20:26:34 +03:00
|
|
|
if (eventId == this.props.readMarkerEventId) {
|
|
|
|
var visible = this.props.readMarkerVisible;
|
|
|
|
|
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.
|
2017-04-18 17:17:42 +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 &&
|
|
|
|
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');
|
2016-02-12 16:39:38 +03:00
|
|
|
var ret = [];
|
2016-02-10 14:03:46 +03:00
|
|
|
|
2016-02-12 16:39:38 +03:00
|
|
|
// is this a continuation of the previous message?
|
|
|
|
var continuation = false;
|
2017-03-06 13:26:26 +03:00
|
|
|
|
|
|
|
if (prevEvent !== null
|
2017-03-16 20:00:10 +03:00
|
|
|
&& prevEvent.sender && mxEv.sender
|
2016-02-12 16:39:38 +03:00
|
|
|
&& mxEv.sender.userId === prevEvent.sender.userId
|
|
|
|
&& mxEv.getType() == prevEvent.getType()) {
|
|
|
|
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.
|
2016-02-12 16:39:38 +03:00
|
|
|
var ts1 = mxEv.getTs();
|
2016-12-22 20:54:30 +03:00
|
|
|
var 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)) {
|
2017-06-01 18:53:24 +03:00
|
|
|
var dateSeparator = <li key={ts1}><DateSeparator key={ts1} ts={ts1} showTwelveHour={this.props.isTwelveHour}/></li>;
|
2016-02-12 16:39:38 +03:00
|
|
|
ret.push(dateSeparator);
|
|
|
|
continuation = false;
|
|
|
|
}
|
|
|
|
|
2017-06-02 06:39:44 +03:00
|
|
|
if (mxEv.isRedacted() && this.props.hideRedactions) return ret;
|
|
|
|
|
2016-02-12 16:39:38 +03:00
|
|
|
var eventId = mxEv.getId();
|
|
|
|
var highlight = (eventId == this.props.highlightedEventId);
|
|
|
|
|
|
|
|
// we can't use local echoes as scroll tokens, because their event IDs change.
|
|
|
|
// Local echos have a send "status".
|
|
|
|
var scrollToken = mxEv.status ? undefined : eventId;
|
|
|
|
|
2016-09-08 05:01:38 +03:00
|
|
|
var readReceipts;
|
|
|
|
if (this.props.manageReadReceipts) {
|
|
|
|
readReceipts = this._getReadReceiptsForEvent(mxEv);
|
|
|
|
}
|
2016-02-12 16:39:38 +03:00
|
|
|
ret.push(
|
|
|
|
<li key={eventId}
|
|
|
|
ref={this._collectEventNode.bind(this, eventId)}
|
2017-05-04 12:00:13 +03:00
|
|
|
data-scroll-tokens={scrollToken}>
|
2016-02-10 14:03:46 +03:00
|
|
|
<EventTile mxEvent={mxEv} continuation={continuation}
|
2017-03-06 17:20:24 +03:00
|
|
|
isRedacted={mxEv.isRedacted()}
|
2016-04-02 02:36:19 +03:00
|
|
|
onWidgetLoad={this._onWidgetLoad}
|
2016-04-19 21:38:54 +03:00
|
|
|
readReceipts={readReceipts}
|
2016-04-21 01:03:05 +03:00
|
|
|
readReceiptMap={this._readReceiptMap}
|
2016-07-18 03:35:42 +03:00
|
|
|
showUrlPreview={this.props.showUrlPreview}
|
2016-04-22 19:03:15 +03:00
|
|
|
checkUnmounting={this._isUnmounting}
|
2016-04-19 21:38:54 +03:00
|
|
|
eventSendStatus={mxEv.status}
|
2016-09-11 04:14:27 +03:00
|
|
|
tileShape={this.props.tileShape}
|
2017-05-20 00:45:56 +03:00
|
|
|
isTwelveHour={this.props.isTwelveHour}
|
2016-04-19 21:38:54 +03:00
|
|
|
last={last} isSelectedEvent={highlight}/>
|
2016-02-10 14:03:46 +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) {
|
|
|
|
// first event in the panel: depends if we could back-paginate from
|
|
|
|
// here.
|
|
|
|
return !this.props.suppressFirstDateSeparator;
|
|
|
|
}
|
2017-03-03 18:42:24 +03:00
|
|
|
const prevEventDate = prevEvent.getDate();
|
|
|
|
if (!nextEventDate || !prevEventDate) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-12-22 20:54:30 +03:00
|
|
|
// Return early for events that are > 24h apart
|
|
|
|
if (Math.abs(prevEvent.getTs() - nextEventDate.getTime()) > MILLIS_IN_DAY) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-12-21 12:48:41 +03:00
|
|
|
|
2016-12-22 20:54:30 +03:00
|
|
|
// Compare weekdays
|
2017-03-03 18:42:24 +03:00
|
|
|
return prevEventDate.getDay() !== nextEventDate.getDay();
|
2016-03-10 17:16:31 +03:00
|
|
|
},
|
|
|
|
|
2016-12-09 14:24:10 +03:00
|
|
|
// get a list of read receipts that should be shown next to this event
|
|
|
|
// Receipts are objects which have a '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
|
2016-12-09 14:24:10 +03:00
|
|
|
const room = MatrixClientPeg.get().getRoom(event.getRoomId());
|
2016-04-19 21:38:54 +03:00
|
|
|
if (!room) {
|
|
|
|
return null;
|
|
|
|
}
|
2016-12-09 14:24:10 +03:00
|
|
|
let receipts = [];
|
|
|
|
room.getReceiptsForEvent(event).forEach((r) => {
|
|
|
|
if (!r.userId || r.type !== "m.read" || r.userId === myUserId) {
|
|
|
|
return; // ignore non-read receipts and receipts from self.
|
|
|
|
}
|
|
|
|
let member = room.getMember(r.userId);
|
|
|
|
if (!member) {
|
|
|
|
return; // ignore unknown user IDs
|
|
|
|
}
|
|
|
|
receipts.push({
|
|
|
|
roomMember: member,
|
|
|
|
ts: r.data ? r.data.ts : 0,
|
|
|
|
});
|
|
|
|
});
|
2016-04-19 21:38:54 +03:00
|
|
|
|
2016-12-09 14:24:10 +03:00
|
|
|
return receipts.sort((r1, r2) => {
|
|
|
|
return r2.ts - r1.ts;
|
2016-04-19 21:38:54 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-02-24 20:26:34 +03:00
|
|
|
_getReadMarkerTile: function(visible) {
|
2016-02-12 16:39:38 +03:00
|
|
|
var 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">
|
|
|
|
{hr}
|
|
|
|
</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) {
|
|
|
|
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() {
|
2016-02-15 12:50:12 +03:00
|
|
|
var 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">
|
2016-02-12 16:39:38 +03:00
|
|
|
{hr}
|
|
|
|
</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.
|
|
|
|
_onWidgetLoad: function() {
|
|
|
|
var scrollPanel = this.refs.scrollPanel;
|
|
|
|
if (scrollPanel) {
|
2016-04-08 22:21:27 +03:00
|
|
|
scrollPanel.forceUpdate();
|
2016-04-02 02:36:19 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-03-24 03:13:32 +03:00
|
|
|
onResize: function() {
|
2016-03-24 04:12:51 +03:00
|
|
|
dis.dispatch({ action: 'timeline_resize' }, true);
|
2016-02-23 16:32:23 +03:00
|
|
|
},
|
|
|
|
|
2016-02-11 18:38:13 +03:00
|
|
|
render: function() {
|
|
|
|
var ScrollPanel = sdk.getComponent("structures.ScrollPanel");
|
2016-02-24 16:38:55 +03:00
|
|
|
var Spinner = sdk.getComponent("elements.Spinner");
|
|
|
|
var topSpinner, bottomSpinner;
|
|
|
|
if (this.props.backPaginating) {
|
|
|
|
topSpinner = <li key="_topSpinner"><Spinner /></li>;
|
|
|
|
}
|
|
|
|
if (this.props.forwardPaginating) {
|
|
|
|
bottomSpinner = <li key="_bottomSpinner"><Spinner /></li>;
|
|
|
|
}
|
|
|
|
|
2016-04-12 19:18:32 +03:00
|
|
|
var style = this.props.hidden ? { display: 'none' } : {};
|
|
|
|
style.opacity = this.props.opacity;
|
|
|
|
|
2017-05-27 02:14:16 +03:00
|
|
|
var className = this.props.className + " mx_fadable";
|
|
|
|
if (this.props.alwaysShowTimestamps) {
|
|
|
|
className += " mx_MessagePanel_alwaysShowTimestamps";
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:38:13 +03:00
|
|
|
return (
|
2017-05-27 02:14:16 +03:00
|
|
|
<ScrollPanel ref="scrollPanel" className={ className }
|
2016-04-19 21:38:54 +03:00
|
|
|
onScroll={ this.props.onScroll }
|
2016-03-24 03:13:32 +03:00
|
|
|
onResize={ this.onResize }
|
2016-02-11 18:38:13 +03:00
|
|
|
onFillRequest={ this.props.onFillRequest }
|
2016-11-16 17:25:52 +03:00
|
|
|
onUnfillRequest={ this.props.onUnfillRequest }
|
2016-04-12 19:18:32 +03:00
|
|
|
style={ style }
|
2016-02-11 18:38:13 +03:00
|
|
|
stickyBottom={ this.props.stickyBottom }>
|
2016-02-24 16:38:55 +03:00
|
|
|
{topSpinner}
|
2016-02-11 18:38:13 +03:00
|
|
|
{this._getEventTiles()}
|
2016-02-24 16:38:55 +03:00
|
|
|
{bottomSpinner}
|
2016-02-11 18:38:13 +03:00
|
|
|
</ScrollPanel>
|
|
|
|
);
|
|
|
|
},
|
2016-02-10 14:03:46 +03:00
|
|
|
});
|