Use new pendingEventList functionality from matrix-js-sdk

Update react-sdk to use `pendingEventOrdering`==`detached` instead of
`end`. Look for pending events in the pendingEvent list, and use
MatrixClient.cancelPendingEvent to, uh, cancel pending events.
This commit is contained in:
Richard van der Hoff 2016-03-17 22:26:06 +00:00
parent d1dbce8adf
commit b93af2d536
4 changed files with 26 additions and 35 deletions

View file

@ -32,18 +32,9 @@ module.exports = {
event: event event: event
}); });
}); });
dis.dispatch({
action: 'message_resend_started',
event: event
});
}, },
removeFromQueue: function(event) { removeFromQueue: function(event) {
MatrixClientPeg.get().getScheduler().removeEventFromQueue(event); MatrixClientPeg.get().cancelPendingEvent(event);
var room = MatrixClientPeg.get().getRoom(event.getRoomId()); },
if (!room) {
return;
}
room.removeEvents([event.getId()]);
}
}; };

View file

@ -702,7 +702,7 @@ module.exports = React.createClass({
UserActivity.start(); UserActivity.start();
Presence.start(); Presence.start();
cli.startClient({ cli.startClient({
pendingEventOrdering: "end", pendingEventOrdering: "detached",
initialSyncLimit: this.props.config.sync_timeline_limit || 20, initialSyncLimit: this.props.config.sync_timeline_limit || 20,
}); });
}, },

View file

@ -213,11 +213,6 @@ module.exports = React.createClass({
this.setState({ this.setState({
hasUnsentMessages: this._hasUnsentMessages(this.state.room) hasUnsentMessages: this._hasUnsentMessages(this.state.room)
}); });
case 'message_resend_started':
this.setState({
room: MatrixClientPeg.get().getRoom(this.props.roomId)
});
this.forceUpdate();
break; break;
case 'notifier_enabled': case 'notifier_enabled':
case 'upload_failed': case 'upload_failed':
@ -397,9 +392,7 @@ module.exports = React.createClass({
_getUnsentMessages: function(room) { _getUnsentMessages: function(room) {
if (!room) { return []; } if (!room) { return []; }
// TODO: It would be nice if the JS SDK provided nicer constant-time return room.getPendingEvents().filter(function(ev) {
// constructs rather than O(N) (N=num msgs) on this.
return room.timeline.filter(function(ev) {
return ev.status === Matrix.EventStatus.NOT_SENT; return ev.status === Matrix.EventStatus.NOT_SENT;
}); });
}, },

View file

@ -188,7 +188,7 @@ var TimelinePanel = React.createClass({
debuglog("TimelinePanel: paginate complete backwards:"+backwards+"; success:"+r); debuglog("TimelinePanel: paginate complete backwards:"+backwards+"; success:"+r);
this.setState({[statekey]: false}); this.setState({[statekey]: false});
this._onTimelineUpdated(); this._reloadEvents();
return r; return r;
}); });
}, },
@ -268,7 +268,7 @@ var TimelinePanel = React.createClass({
// //
// see https://github.com/vector-im/vector-web/issues/1035 // see https://github.com/vector-im/vector-web/issues/1035
this._timelineWindow.paginate(EventTimeline.FORWARDS, 1, false) this._timelineWindow.paginate(EventTimeline.FORWARDS, 1, false)
.done(this._onTimelineUpdated); .done(this._reloadEvents);
}, },
onRoomTimelineReset: function(room) { onRoomTimelineReset: function(room) {
@ -305,12 +305,7 @@ var TimelinePanel = React.createClass({
// ignore events for other rooms // ignore events for other rooms
if (room !== this.props.room) return; if (room !== this.props.room) return;
// Once the remote echo for an event arrives, we need to turn the this._reloadEvents();
// greyed-out event black. When the localEchoUpdated event is raised,
// the nested 'event' property within one of the events in
// _timelineWindow will have been replaced with the new event. So
// all that is left to do here is to make the message-panel re-render.
this.forceUpdate();
}, },
@ -558,16 +553,18 @@ var TimelinePanel = React.createClass({
// In this situation, we don't really want to defer the update of the // In this situation, we don't really want to defer the update of the
// state to the next event loop, because it makes room-switching feel // state to the next event loop, because it makes room-switching feel
// quite slow. So we detect that situation and shortcut straight to // quite slow. So we detect that situation and shortcut straight to
// calling _onTimelineUpdated and updating the state. // calling _reloadEvents and updating the state.
var onLoaded = () => { var onLoaded = () => {
this._onTimelineUpdated(); this._reloadEvents();
this.setState({timelineLoading: false}, () => { this.setState({timelineLoading: false}, () => {
// initialise the scroll state of the message panel // initialise the scroll state of the message panel
if (!this.refs.messagePanel) { if (!this.refs.messagePanel) {
// this shouldn't happen - _onTimelineUpdated checks we're // this shouldn't happen - we know we're mounted because
// mounted, and timelineLoading is now false. // we're in a setState callback, and we know
// timelineLoading is now false, so render() should have
// mounted the message panel.
console.log("can't initialise scroll state because " + console.log("can't initialise scroll state because " +
"messagePanel didn't load"); "messagePanel didn't load");
return; return;
@ -593,13 +590,23 @@ var TimelinePanel = React.createClass({
prom.done(); prom.done();
}, },
_onTimelineUpdated: function() { // handle the completion of a timeline load or localEchoUpdate, by
// reloading the events from the timelinewindow and pending event list into
// the state.
_reloadEvents: function() {
// we might have switched rooms since the load started - just bin // we might have switched rooms since the load started - just bin
// the results if so. // the results if so.
if (this.unmounted) return; if (this.unmounted) return;
var events = this._timelineWindow.getEvents();
// if we're at the end of the live timeline, append the pending events
if (!this._timelineWindow.canPaginate(EventTimeline.FORWARDS)) {
events.push(... this.props.room.getPendingEvents());
}
this.setState({ this.setState({
events: this._timelineWindow.getEvents(), events: events,
canBackPaginate: this._timelineWindow.canPaginate(EventTimeline.BACKWARDS), canBackPaginate: this._timelineWindow.canPaginate(EventTimeline.BACKWARDS),
}); });
}, },