Fix widgets re-appearing after being deleted

Widgets would sometimes briefly re-appear after having been deleted.
This was because of the following race:
 * User presses delete, send POST req, we set `deleting`. Widget hides.
 * POST request completes, we unset `deleting` so widget unhides.
 * State event comes down sync so widget hides again.

This fixes this by introducing `waitForRoomWidget` and using it to
wait until the state event comes down the sync until clearing the
`deleting` flag.

Since we now have `waitForRoomWidget`, this also uses it when adding
a widget so the 'widget saved' appears at the same time the widget
does.
This commit is contained in:
David Baker 2018-06-13 15:50:19 +01:00
parent 1cb794753e
commit 94125fb566
3 changed files with 64 additions and 9 deletions

View file

@ -324,7 +324,9 @@ export default class AppTile extends React.Component {
'im.vector.modular.widgets',
{}, // empty content
this.props.id,
).catch((e) => {
).then(() => {
return WidgetUtils.waitForRoomWidget(this.props.id, this.props.room.roomId, false);
}).catch((e) => {
console.error('Failed to delete widget', e);
}).finally(() => {
this.setState({deleting: false});