Refactor remove resend_all_events and cancel_all_events dispatches

This commit is contained in:
Luke Barnard 2017-02-27 13:39:12 +00:00
parent b68b0e25c8
commit 7221900497
4 changed files with 17 additions and 28 deletions

View file

@ -20,6 +20,20 @@ var sdk = require('./index');
var Modal = require('./Modal');
module.exports = {
resendUnsentEvents: function(room) {
room.getPendingEvents().filter(function(ev) {
return ev.status === Matrix.EventStatus.NOT_SENT;
}).forEach(function(event) {
module.exports.resend(event);
});
},
cancelUnsentEvents: function(room) {
room.getPendingEvents().filter(function(ev) {
return ev.status === Matrix.EventStatus.NOT_SENT;
}).forEach(function(event) {
module.exports.removeFromQueue(event);
});
},
resend: function(event) {
const room = MatrixClientPeg.get().getRoom(event.getRoomId());
MatrixClientPeg.get().resendEvent(
@ -47,7 +61,6 @@ module.exports = {
});
});
},
removeFromQueue: function(event) {
MatrixClientPeg.get().cancelPendingEvent(event);
dis.dispatch({

View file

@ -26,7 +26,6 @@ var ContextualMenu = require("./ContextualMenu");
var RoomListSorter = require("../../RoomListSorter");
var UserActivity = require("../../UserActivity");
var Presence = require("../../Presence");
var Resend = require("../../Resend");
var dis = require("../../dispatcher");
var Login = require("./login/Login");
@ -522,20 +521,6 @@ module.exports = React.createClass({
case 'set_theme':
this._onSetTheme(payload.value);
break;
case 'resend_all_events':
payload.room.getPendingEvents().filter(function(ev) {
return ev.status === Matrix.EventStatus.NOT_SENT;
}).forEach(function(event) {
Resend.resend(event);
});
break;
case 'cancel_all_events':
payload.room.getPendingEvents().filter(function(ev) {
return ev.status === Matrix.EventStatus.NOT_SENT;
}).forEach(function(event) {
Resend.removeFromQueue(event);
});
break;
case 'on_logged_in':
this._onLoggedIn();
break;

View file

@ -716,17 +716,11 @@ module.exports = React.createClass({
},
onResendAllClick: function() {
dis.dispatch({
action: 'resend_all_events',
room: this.state.room,
});
Resend.resendUnsentEvents(this.state.room);
},
onCancelAllClick: function() {
dis.dispatch({
action: 'cancel_all_events',
room: this.state.room,
});
Resend.cancelUnsentEvents(this.state.room);
},
onJoinButtonClicked: function(ev) {

View file

@ -159,10 +159,7 @@ export default React.createClass({
<button className="mx_Dialog_primary" autoFocus={ true }
onClick={() => {
this.props.onFinished();
dis.dispatch({
action: 'resend_all_events',
room: this.props.room,
});
Resend.resendUnsentEvents(this.props.room);
}}>
Send anyway
</button>