Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3406 from matrix-org/t3chguy/reply_to_search_results
Browse files Browse the repository at this point in the history
Fix replying from search results for this and all rooms
  • Loading branch information
t3chguy authored Sep 11, 2019
2 parents 379fab8 + 80add7b commit 81ea230
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/components/structures/RoomView.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ module.exports = createReactClass({
payload.data.description || payload.data.name);
break;
case 'picture_snapshot':
return ContentMessages.sharedInstance().sendContentListToRoom(
ContentMessages.sharedInstance().sendContentListToRoom(
[payload.file], this.state.room.roomId, MatrixClientPeg.get(),
);
break;
Expand Down Expand Up @@ -624,6 +624,11 @@ module.exports = createReactClass({
showApps: payload.show,
});
break;
case 'reply_to_event':
if (this.state.searchResults && payload.event.getRoomId() === this.state.roomId && !this.unmounted) {
this.onCancelSearchClick();
}
break;
}
},

Expand Down
9 changes: 6 additions & 3 deletions src/components/views/rooms/ReplyPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,28 @@ export default class ReplyPreview extends React.Component {

constructor(props, context) {
super(props, context);
this.unmounted = false;

this.state = {
event: null,
event: RoomViewStore.getQuotingEvent(),
};

this._onRoomViewStoreUpdate = this._onRoomViewStoreUpdate.bind(this);

this._roomStoreToken = RoomViewStore.addListener(this._onRoomViewStoreUpdate);
this._onRoomViewStoreUpdate();
}

componentWillUnmount() {
this.unmounted = true;

// Remove RoomStore listener
if (this._roomStoreToken) {
this._roomStoreToken.remove();
}
}

_onRoomViewStoreUpdate() {
if (this.unmounted) return;

const event = RoomViewStore.getQuotingEvent();
if (this.state.event !== event) {
this.setState({ event });
Expand Down
21 changes: 18 additions & 3 deletions src/stores/RoomViewStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,19 @@ class RoomViewStore extends Store {
});
break;
case 'reply_to_event':
this._setState({
replyingToEvent: payload.event,
});
// If currently viewed room does not match the room in which we wish to reply then change rooms
// this can happen when performing a search across all rooms
if (payload.event && payload.event.getRoomId() !== this._state.roomId) {
dis.dispatch({
action: 'view_room',
room_id: payload.event.getRoomId(),
replyingToEvent: payload.event,
});
} else {
this._setState({
replyingToEvent: payload.event,
});
}
break;
case 'open_room_settings': {
const RoomSettingsDialog = sdk.getComponent("dialogs.RoomSettingsDialog");
Expand Down Expand Up @@ -147,6 +157,11 @@ class RoomViewStore extends Store {
isEditingSettings: false,
};

// Allow being given an event to be replied to when switching rooms but sanity check its for this room
if (payload.replyingToEvent && payload.replyingToEvent.getRoomId() === payload.room_id) {
newState.replyingToEvent = payload.replyingToEvent;
}

if (this._state.forwardingEvent) {
dis.dispatch({
action: 'send_event',
Expand Down

0 comments on commit 81ea230

Please sign in to comment.