Truncate consecutive member events
This is needed for the IRC bridge to be able to do full membership list syncing without cluttering the message panel.
This commit is contained in:
parent
5a61a1e6e1
commit
cd241a4a17
2 changed files with 73 additions and 4 deletions
|
@ -20,6 +20,7 @@ var dis = require("../../dispatcher");
|
||||||
var sdk = require('../../index');
|
var sdk = require('../../index');
|
||||||
|
|
||||||
var MatrixClientPeg = require('../../MatrixClientPeg')
|
var MatrixClientPeg = require('../../MatrixClientPeg')
|
||||||
|
var TruncatedList = require('../views/elements/TruncatedList.js');
|
||||||
|
|
||||||
/* (almost) stateless UI component which builds the event tiles in the room timeline.
|
/* (almost) stateless UI component which builds the event tiles in the room timeline.
|
||||||
*/
|
*/
|
||||||
|
@ -286,6 +287,56 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
var last = (i == lastShownEventIndex);
|
var last = (i == lastShownEventIndex);
|
||||||
|
|
||||||
|
// Wrap consecutive member events in a TruncatedList
|
||||||
|
if (mxEv.getType() === 'm.room.member') {
|
||||||
|
// Prevent message continuations between truncations
|
||||||
|
prevEvent = null;
|
||||||
|
|
||||||
|
let collapsedEvents = [mxEv];
|
||||||
|
i++;
|
||||||
|
for (;i < this.props.events.length; i++) {
|
||||||
|
let collapsedMxEv = this.props.events[i];
|
||||||
|
|
||||||
|
if (collapsedMxEv.getType() !== 'm.room.member') {
|
||||||
|
i--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
collapsedEvents.push(collapsedMxEv);
|
||||||
|
}
|
||||||
|
let ePrev = null;
|
||||||
|
collapsedEvents = collapsedEvents.map(
|
||||||
|
(e) => {
|
||||||
|
let ret = this._getTilesForEvent(ePrev, e);
|
||||||
|
ePrev = e;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
).reduce((a,b) => a.concat(b));
|
||||||
|
|
||||||
|
let overflowElement = (overflowCount, totalCount, toggleTruncate, isExpanded) => {
|
||||||
|
if (isExpanded) {
|
||||||
|
return (
|
||||||
|
<div className="mx_EventTile_line">
|
||||||
|
<a onClick={toggleTruncate} href="javascript:;">collapse ^</a>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return (
|
||||||
|
<div className="mx_EventTile_line">
|
||||||
|
<a onClick={toggleTruncate} href="javascript:;">and {overflowCount} more...</a>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret.push(
|
||||||
|
<TruncatedList truncateAt={2} createOverflowElement={overflowElement}>
|
||||||
|
{collapsedEvents}
|
||||||
|
</TruncatedList>
|
||||||
|
);
|
||||||
|
|
||||||
|
wantTile = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (wantTile) {
|
if (wantTile) {
|
||||||
// make sure we unpack the array returned by _getTilesForEvent,
|
// make sure we unpack the array returned by _getTilesForEvent,
|
||||||
// otherwise react will auto-generate keys and we will end up
|
// otherwise react will auto-generate keys and we will end up
|
||||||
|
|
|
@ -28,10 +28,16 @@ module.exports = React.createClass({
|
||||||
createOverflowElement: React.PropTypes.func
|
createOverflowElement: React.PropTypes.func
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getInitialState: function() {
|
||||||
|
return {
|
||||||
|
enabled: true,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
getDefaultProps: function() {
|
getDefaultProps: function() {
|
||||||
return {
|
return {
|
||||||
truncateAt: 2,
|
truncateAt: 2,
|
||||||
createOverflowElement: function(overflowCount, totalCount) {
|
createOverflowElement: function(overflowCount, totalCount, toggleTruncate, isExpanded) {
|
||||||
return (
|
return (
|
||||||
<div>And {overflowCount} more...</div>
|
<div>And {overflowCount} more...</div>
|
||||||
);
|
);
|
||||||
|
@ -39,6 +45,12 @@ module.exports = React.createClass({
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
toggleTruncate: function() {
|
||||||
|
this.setState({
|
||||||
|
enabled: !this.state.enabled
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
var childsJsx = this.props.children;
|
var childsJsx = this.props.children;
|
||||||
var overflowJsx;
|
var overflowJsx;
|
||||||
|
@ -48,20 +60,26 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
var childCount = childArray.length;
|
var childCount = childArray.length;
|
||||||
|
|
||||||
if (this.props.truncateAt >= 0) {
|
if (this.state.enabled && this.props.truncateAt >= 0) {
|
||||||
var overflowCount = childCount - this.props.truncateAt;
|
var overflowCount = childCount - this.props.truncateAt;
|
||||||
|
|
||||||
if (overflowCount > 1) {
|
if (overflowCount > 1) {
|
||||||
overflowJsx = this.props.createOverflowElement(
|
overflowJsx = this.props.createOverflowElement(
|
||||||
overflowCount, childCount
|
overflowCount, childCount, this.toggleTruncate
|
||||||
);
|
);
|
||||||
|
|
||||||
// cut out the overflow elements
|
// cut out the overflow elements
|
||||||
childArray.splice(childCount - overflowCount, overflowCount);
|
childArray.splice(childCount - overflowCount, overflowCount);
|
||||||
childsJsx = childArray; // use what is left
|
childsJsx = childArray; // use what is left
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.state.enabled) {
|
||||||
|
overflowJsx = this.props.createOverflowElement(
|
||||||
|
0, childCount, this.toggleTruncate, true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={this.props.className}>
|
<div className={this.props.className}>
|
||||||
{childsJsx}
|
{childsJsx}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue