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

Commit 27f38ae

Browse files
t3chguydbkr
authored andcommitted
make forward_message be friendly with the RVS stuffs
Signed-off-by: Michael Telatynski <[email protected]>
1 parent 12ad9a2 commit 27f38ae

File tree

4 files changed

+53
-35
lines changed

4 files changed

+53
-35
lines changed

src/components/structures/MatrixChat.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,9 @@ module.exports = React.createClass({
523523
payload.releaseNotes,
524524
);
525525
break;
526+
case 'send_event':
527+
this.onSendEvent(payload.room_id, payload.event);
528+
break;
526529
}
527530
},
528531

@@ -1267,6 +1270,27 @@ module.exports = React.createClass({
12671270
});
12681271
},
12691272

1273+
onSendEvent: function(roomId, event) {
1274+
const cli = MatrixClientPeg.get();
1275+
if (!cli) {
1276+
dis.dispatch({action: 'message_send_failed'});
1277+
return;
1278+
}
1279+
1280+
cli.sendEvent(roomId, event.getType(), event.getContent()).done(() => {
1281+
dis.dispatch({action: 'message_sent'});
1282+
}, (err) => {
1283+
if (err.name === 'UnknownDeviceError') {
1284+
dis.dispatch({
1285+
action: 'unknown_device_error',
1286+
err: err,
1287+
room: cli.getRoom(roomId),
1288+
});
1289+
}
1290+
dis.dispatch({action: 'message_send_failed'});
1291+
});
1292+
},
1293+
12701294
updateStatusIndicator: function(state, prevState) {
12711295
let notifCount = 0;
12721296

src/components/structures/RoomView.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ module.exports = React.createClass({
168168
initialEventId: RoomViewStore.getInitialEventId(),
169169
initialEventPixelOffset: RoomViewStore.getInitialEventPixelOffset(),
170170
isInitialEventHighlighted: RoomViewStore.isInitialEventHighlighted(),
171+
forwardingEvent: RoomViewStore.getForwardingEvent(),
171172
};
172173

173174
// Temporary logging to diagnose https://github.com/vector-im/riot-web/issues/4307
@@ -452,11 +453,6 @@ module.exports = React.createClass({
452453
callState: callState
453454
});
454455

455-
break;
456-
case 'forward_event':
457-
this.setState({
458-
forwardingEvent: payload.content,
459-
});
460456
break;
461457
}
462458
},
@@ -1164,8 +1160,13 @@ module.exports = React.createClass({
11641160
this.updateTint();
11651161
this.setState({
11661162
editingRoomSettings: false,
1167-
forwardingEvent: null,
11681163
});
1164+
if (this.state.forwardingEvent) {
1165+
dis.dispatch({
1166+
action: 'forward_event',
1167+
event: null,
1168+
});
1169+
}
11691170
dis.dispatch({action: 'focus_composer'});
11701171
},
11711172

@@ -1576,7 +1577,7 @@ module.exports = React.createClass({
15761577
} else if (this.state.uploadingRoomSettings) {
15771578
aux = <Loader/>;
15781579
} else if (this.state.forwardingEvent !== null) {
1579-
aux = <ForwardMessage onCancelClick={this.onCancelClick} currentRoomId={this.state.room.roomId} mxEvent={this.state.forwardingEvent} />;
1580+
aux = <ForwardMessage onCancelClick={this.onCancelClick} />;
15801581
} else if (this.state.searching) {
15811582
hideCancel = true; // has own cancel
15821583
aux = <SearchBar ref="search_bar" searchInProgress={this.state.searchInProgress } onCancelClick={this.onCancelSearchClick} onSearch={this.onSearch}/>;

src/components/views/rooms/ForwardMessage.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import React from 'react';
1919
import { _t } from '../../../languageHandler';
20-
import MatrixClientPeg from '../../../MatrixClientPeg';
2120
import dis from '../../../dispatcher';
2221
import KeyCode from '../../../KeyCode';
2322

@@ -26,11 +25,6 @@ module.exports = React.createClass({
2625
displayName: 'ForwardMessage',
2726

2827
propTypes: {
29-
currentRoomId: React.PropTypes.string.isRequired,
30-
31-
/* the MatrixEvent to be forwarded */
32-
mxEvent: React.PropTypes.object.isRequired,
33-
3428
onCancelClick: React.PropTypes.func.isRequired,
3529
},
3630

@@ -44,7 +38,6 @@ module.exports = React.createClass({
4438
},
4539

4640
componentDidMount: function() {
47-
this.dispatcherRef = dis.register(this.onAction);
4841
document.addEventListener('keydown', this._onKeyDown);
4942
},
5043

@@ -54,30 +47,9 @@ module.exports = React.createClass({
5447
sideOpacity: 1.0,
5548
middleOpacity: 1.0,
5649
});
57-
dis.unregister(this.dispatcherRef);
5850
document.removeEventListener('keydown', this._onKeyDown);
5951
},
6052

61-
onAction: function(payload) {
62-
if (payload.action === 'view_room') {
63-
const event = this.props.mxEvent;
64-
const Client = MatrixClientPeg.get();
65-
Client.sendEvent(payload.room_id, event.getType(), event.getContent()).done(() => {
66-
dis.dispatch({action: 'message_sent'});
67-
}, (err) => {
68-
if (err.name === "UnknownDeviceError") {
69-
dis.dispatch({
70-
action: 'unknown_device_error',
71-
err: err,
72-
room: Client.getRoom(payload.room_id),
73-
});
74-
}
75-
dis.dispatch({action: 'message_send_failed'});
76-
});
77-
if (this.props.currentRoomId === payload.room_id) this.props.onCancelClick();
78-
}
79-
},
80-
8153
_onKeyDown: function(ev) {
8254
switch (ev.keyCode) {
8355
case KeyCode.ESCAPE:

src/stores/RoomViewStore.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ const INITIAL_STATE = {
5555
// pixelOffset: the number of pixels the window is scrolled down
5656
// from the focussedEvent.
5757
scrollStateMap: {},
58+
59+
forwardingEvent: null,
5860
};
5961

6062
/**
@@ -116,6 +118,11 @@ class RoomViewStore extends Store {
116118
case 'update_scroll_state':
117119
this._updateScrollState(payload);
118120
break;
121+
case 'forward_event':
122+
this._setState({
123+
forwardingEvent: payload.event,
124+
});
125+
break;
119126
}
120127
}
121128

@@ -127,6 +134,7 @@ class RoomViewStore extends Store {
127134
initialEventId: payload.event_id,
128135
initialEventPixelOffset: undefined,
129136
isInitialEventHighlighted: payload.highlighted,
137+
forwardingEvent: null,
130138
roomLoading: false,
131139
roomLoadError: null,
132140
};
@@ -141,6 +149,14 @@ class RoomViewStore extends Store {
141149
}
142150
}
143151

152+
if (this._state.forwardingEvent) {
153+
dis.dispatch({
154+
action: 'send_event',
155+
room_id: newState.roomId,
156+
event: this._state.forwardingEvent,
157+
});
158+
}
159+
144160
this._setState(newState);
145161
} else if (payload.room_alias) {
146162
// Resolve the alias and then do a second dispatch with the room ID acquired
@@ -276,6 +292,11 @@ class RoomViewStore extends Store {
276292
getJoinError() {
277293
return this._state.joinError;
278294
}
295+
296+
// The mxEvent if one is about to be forwarded
297+
getForwardingEvent() {
298+
return this._state.forwardingEvent;
299+
}
279300
}
280301

281302
let singletonRoomViewStore = null;

0 commit comments

Comments
 (0)