Merge pull request #1112 from matrix-org/t3chguy/fix_forwarding
make forward_event be friendly with the RVS stuffs
This commit is contained in:
commit
bccf398ab5
4 changed files with 53 additions and 35 deletions
|
@ -523,6 +523,9 @@ module.exports = React.createClass({
|
||||||
payload.releaseNotes,
|
payload.releaseNotes,
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
case 'send_event':
|
||||||
|
this.onSendEvent(payload.room_id, payload.event);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1267,6 +1270,27 @@ module.exports = React.createClass({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onSendEvent: function(roomId, event) {
|
||||||
|
const cli = MatrixClientPeg.get();
|
||||||
|
if (!cli) {
|
||||||
|
dis.dispatch({action: 'message_send_failed'});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cli.sendEvent(roomId, event.getType(), event.getContent()).done(() => {
|
||||||
|
dis.dispatch({action: 'message_sent'});
|
||||||
|
}, (err) => {
|
||||||
|
if (err.name === 'UnknownDeviceError') {
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'unknown_device_error',
|
||||||
|
err: err,
|
||||||
|
room: cli.getRoom(roomId),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
dis.dispatch({action: 'message_send_failed'});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
updateStatusIndicator: function(state, prevState) {
|
updateStatusIndicator: function(state, prevState) {
|
||||||
let notifCount = 0;
|
let notifCount = 0;
|
||||||
|
|
||||||
|
|
|
@ -169,6 +169,7 @@ module.exports = React.createClass({
|
||||||
initialEventId: RoomViewStore.getInitialEventId(),
|
initialEventId: RoomViewStore.getInitialEventId(),
|
||||||
initialEventPixelOffset: RoomViewStore.getInitialEventPixelOffset(),
|
initialEventPixelOffset: RoomViewStore.getInitialEventPixelOffset(),
|
||||||
isInitialEventHighlighted: RoomViewStore.isInitialEventHighlighted(),
|
isInitialEventHighlighted: RoomViewStore.isInitialEventHighlighted(),
|
||||||
|
forwardingEvent: RoomViewStore.getForwardingEvent(),
|
||||||
shouldPeek: RoomViewStore.shouldPeek(),
|
shouldPeek: RoomViewStore.shouldPeek(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -457,11 +458,6 @@ module.exports = React.createClass({
|
||||||
callState: callState
|
callState: callState
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
|
||||||
case 'forward_event':
|
|
||||||
this.setState({
|
|
||||||
forwardingEvent: payload.content,
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1169,8 +1165,13 @@ module.exports = React.createClass({
|
||||||
this.updateTint();
|
this.updateTint();
|
||||||
this.setState({
|
this.setState({
|
||||||
editingRoomSettings: false,
|
editingRoomSettings: false,
|
||||||
forwardingEvent: null,
|
|
||||||
});
|
});
|
||||||
|
if (this.state.forwardingEvent) {
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'forward_event',
|
||||||
|
event: null,
|
||||||
|
});
|
||||||
|
}
|
||||||
dis.dispatch({action: 'focus_composer'});
|
dis.dispatch({action: 'focus_composer'});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1581,7 +1582,7 @@ module.exports = React.createClass({
|
||||||
} else if (this.state.uploadingRoomSettings) {
|
} else if (this.state.uploadingRoomSettings) {
|
||||||
aux = <Loader/>;
|
aux = <Loader/>;
|
||||||
} else if (this.state.forwardingEvent !== null) {
|
} else if (this.state.forwardingEvent !== null) {
|
||||||
aux = <ForwardMessage onCancelClick={this.onCancelClick} currentRoomId={this.state.room.roomId} mxEvent={this.state.forwardingEvent} />;
|
aux = <ForwardMessage onCancelClick={this.onCancelClick} />;
|
||||||
} else if (this.state.searching) {
|
} else if (this.state.searching) {
|
||||||
hideCancel = true; // has own cancel
|
hideCancel = true; // has own cancel
|
||||||
aux = <SearchBar ref="search_bar" searchInProgress={this.state.searchInProgress } onCancelClick={this.onCancelSearchClick} onSearch={this.onSearch}/>;
|
aux = <SearchBar ref="search_bar" searchInProgress={this.state.searchInProgress } onCancelClick={this.onCancelSearchClick} onSearch={this.onSearch}/>;
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { _t } from '../../../languageHandler';
|
import { _t } from '../../../languageHandler';
|
||||||
import MatrixClientPeg from '../../../MatrixClientPeg';
|
|
||||||
import dis from '../../../dispatcher';
|
import dis from '../../../dispatcher';
|
||||||
import KeyCode from '../../../KeyCode';
|
import KeyCode from '../../../KeyCode';
|
||||||
|
|
||||||
|
@ -26,11 +25,6 @@ module.exports = React.createClass({
|
||||||
displayName: 'ForwardMessage',
|
displayName: 'ForwardMessage',
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
currentRoomId: React.PropTypes.string.isRequired,
|
|
||||||
|
|
||||||
/* the MatrixEvent to be forwarded */
|
|
||||||
mxEvent: React.PropTypes.object.isRequired,
|
|
||||||
|
|
||||||
onCancelClick: React.PropTypes.func.isRequired,
|
onCancelClick: React.PropTypes.func.isRequired,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -44,7 +38,6 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
this.dispatcherRef = dis.register(this.onAction);
|
|
||||||
document.addEventListener('keydown', this._onKeyDown);
|
document.addEventListener('keydown', this._onKeyDown);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -54,30 +47,9 @@ module.exports = React.createClass({
|
||||||
sideOpacity: 1.0,
|
sideOpacity: 1.0,
|
||||||
middleOpacity: 1.0,
|
middleOpacity: 1.0,
|
||||||
});
|
});
|
||||||
dis.unregister(this.dispatcherRef);
|
|
||||||
document.removeEventListener('keydown', this._onKeyDown);
|
document.removeEventListener('keydown', this._onKeyDown);
|
||||||
},
|
},
|
||||||
|
|
||||||
onAction: function(payload) {
|
|
||||||
if (payload.action === 'view_room') {
|
|
||||||
const event = this.props.mxEvent;
|
|
||||||
const Client = MatrixClientPeg.get();
|
|
||||||
Client.sendEvent(payload.room_id, event.getType(), event.getContent()).done(() => {
|
|
||||||
dis.dispatch({action: 'message_sent'});
|
|
||||||
}, (err) => {
|
|
||||||
if (err.name === "UnknownDeviceError") {
|
|
||||||
dis.dispatch({
|
|
||||||
action: 'unknown_device_error',
|
|
||||||
err: err,
|
|
||||||
room: Client.getRoom(payload.room_id),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
dis.dispatch({action: 'message_send_failed'});
|
|
||||||
});
|
|
||||||
if (this.props.currentRoomId === payload.room_id) this.props.onCancelClick();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
_onKeyDown: function(ev) {
|
_onKeyDown: function(ev) {
|
||||||
switch (ev.keyCode) {
|
switch (ev.keyCode) {
|
||||||
case KeyCode.ESCAPE:
|
case KeyCode.ESCAPE:
|
||||||
|
|
|
@ -55,6 +55,8 @@ const INITIAL_STATE = {
|
||||||
// pixelOffset: the number of pixels the window is scrolled down
|
// pixelOffset: the number of pixels the window is scrolled down
|
||||||
// from the focussedEvent.
|
// from the focussedEvent.
|
||||||
scrollStateMap: {},
|
scrollStateMap: {},
|
||||||
|
|
||||||
|
forwardingEvent: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,6 +118,11 @@ class RoomViewStore extends Store {
|
||||||
case 'update_scroll_state':
|
case 'update_scroll_state':
|
||||||
this._updateScrollState(payload);
|
this._updateScrollState(payload);
|
||||||
break;
|
break;
|
||||||
|
case 'forward_event':
|
||||||
|
this._setState({
|
||||||
|
forwardingEvent: payload.event,
|
||||||
|
});
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,6 +134,7 @@ class RoomViewStore extends Store {
|
||||||
initialEventId: payload.event_id,
|
initialEventId: payload.event_id,
|
||||||
initialEventPixelOffset: undefined,
|
initialEventPixelOffset: undefined,
|
||||||
isInitialEventHighlighted: payload.highlighted,
|
isInitialEventHighlighted: payload.highlighted,
|
||||||
|
forwardingEvent: null,
|
||||||
roomLoading: false,
|
roomLoading: false,
|
||||||
roomLoadError: null,
|
roomLoadError: null,
|
||||||
// should peek by default
|
// should peek by default
|
||||||
|
@ -143,6 +151,14 @@ class RoomViewStore extends Store {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this._state.forwardingEvent) {
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'send_event',
|
||||||
|
room_id: newState.roomId,
|
||||||
|
event: this._state.forwardingEvent,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this._setState(newState);
|
this._setState(newState);
|
||||||
} else if (payload.room_alias) {
|
} else if (payload.room_alias) {
|
||||||
// Resolve the alias and then do a second dispatch with the room ID acquired
|
// Resolve the alias and then do a second dispatch with the room ID acquired
|
||||||
|
@ -279,6 +295,11 @@ class RoomViewStore extends Store {
|
||||||
return this._state.joinError;
|
return this._state.joinError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The mxEvent if one is about to be forwarded
|
||||||
|
getForwardingEvent() {
|
||||||
|
return this._state.forwardingEvent;
|
||||||
|
}
|
||||||
|
|
||||||
shouldPeek() {
|
shouldPeek() {
|
||||||
return this._state.shouldPeek;
|
return this._state.shouldPeek;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue