Allow collapsing ReplyThread from MessageContextMenu

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
pull/21833/head
Michael Telatynski 2018-04-13 12:28:58 +01:00
parent 8b1e411d6b
commit a90bd6cd4f
No known key found for this signature in database
GPG Key ID: 3F879DA5AD802A5E
2 changed files with 20 additions and 6 deletions

View File

@ -52,6 +52,8 @@ export default class ReplyThread extends React.Component {
};
this.onQuoteClick = this.onQuoteClick.bind(this);
this.canCollapse = this.canCollapse.bind(this);
this.collapse = this.collapse.bind(this);
}
componentWillMount() {
@ -64,6 +66,14 @@ export default class ReplyThread extends React.Component {
this.unmounted = true;
}
canCollapse() {
return this.state.events.length > 1;
}
collapse() {
this.initialize();
}
async initialize() {
const {parentEv} = this.props;
const inReplyTo = ReplyThread.getInReplyTo(parentEv);
@ -227,11 +237,11 @@ export default class ReplyThread extends React.Component {
};
}
static getQuote(parentEv, onWidgetLoad) {
static getThread(parentEv, onWidgetLoad, ref) {
if (!SettingsStore.isFeatureEnabled("feature_rich_quoting") || !ReplyThread.getInReplyTo(parentEv)) {
return <div />;
}
return <ReplyThread parentEv={parentEv} onWidgetLoad={onWidgetLoad} />;
return <ReplyThread parentEv={parentEv} onWidgetLoad={onWidgetLoad} ref={ref} />;
}
render() {

View File

@ -18,7 +18,7 @@ limitations under the License.
'use strict';
import Reply from "../elements/ReplyThread";
import ReplyThread from "../elements/ReplyThread";
const React = require('react');
import PropTypes from 'prop-types';
@ -302,12 +302,16 @@ module.exports = withMatrixClient(React.createClass({
const x = buttonRect.right + window.pageXOffset;
const y = (buttonRect.top + (buttonRect.height / 2) + window.pageYOffset) - 19;
const self = this;
const {tile, replyThread} = this.refs;
ContextualMenu.createMenu(MessageContextMenu, {
chevronOffset: 10,
mxEvent: this.props.mxEvent,
left: x,
top: y,
eventTileOps: this.refs.tile && this.refs.tile.getEventTileOps ? this.refs.tile.getEventTileOps() : undefined,
eventTileOps: tile && tile.getEventTileOps ? tile.getEventTileOps() : undefined,
collapseReplyThread: replyThread && replyThread.canCollapse() ? replyThread.collapse : undefined,
onFinished: function() {
self.setState({menu: false});
},
@ -662,7 +666,7 @@ module.exports = withMatrixClient(React.createClass({
{ this._renderE2EPadlock() }
{
this.props.tileShape === 'reply_preview'
&& Reply.getQuote(this.props.mxEvent, this.props.onWidgetLoad)
&& ReplyThread.getThread(this.props.mxEvent, this.props.onWidgetLoad, 'replyThread')
}
<EventTileType ref="tile"
mxEvent={this.props.mxEvent}
@ -687,7 +691,7 @@ module.exports = withMatrixClient(React.createClass({
{ timestamp }
</a>
{ this._renderE2EPadlock() }
{ Reply.getQuote(this.props.mxEvent, this.props.onWidgetLoad) }
{ ReplyThread.getThread(this.props.mxEvent, this.props.onWidgetLoad, 'replyThread') }
<EventTileType ref="tile"
mxEvent={this.props.mxEvent}
highlights={this.props.highlights}