Allow collapsing ReplyThread from MessageContextMenu

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
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.onQuoteClick = this.onQuoteClick.bind(this);
this.canCollapse = this.canCollapse.bind(this);
this.collapse = this.collapse.bind(this);
} }
componentWillMount() { componentWillMount() {
@ -64,6 +66,14 @@ export default class ReplyThread extends React.Component {
this.unmounted = true; this.unmounted = true;
} }
canCollapse() {
return this.state.events.length > 1;
}
collapse() {
this.initialize();
}
async initialize() { async initialize() {
const {parentEv} = this.props; const {parentEv} = this.props;
const inReplyTo = ReplyThread.getInReplyTo(parentEv); 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)) { if (!SettingsStore.isFeatureEnabled("feature_rich_quoting") || !ReplyThread.getInReplyTo(parentEv)) {
return <div />; return <div />;
} }
return <ReplyThread parentEv={parentEv} onWidgetLoad={onWidgetLoad} />; return <ReplyThread parentEv={parentEv} onWidgetLoad={onWidgetLoad} ref={ref} />;
} }
render() { render() {

View file

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