More helpful display when the event stream fails, wiping it when the connection is regained.

This commit is contained in:
Kegan Dougal 2014-08-14 17:40:27 +01:00
parent e6c62d5d7f
commit 5de086b736
2 changed files with 10 additions and 5 deletions

View File

@ -25,7 +25,8 @@ angular.module('RoomController', [])
user_id: matrixService.config().user_id, user_id: matrixService.config().user_id,
events_from: "END", // when to start the event stream from. events_from: "END", // when to start the event stream from.
earliest_token: "END", // stores how far back we've paginated. earliest_token: "END", // stores how far back we've paginated.
can_paginate: true can_paginate: true, // this is toggled off when we run out of items
stream_failure: undefined // the response when the stream fails
}; };
$scope.messages = []; $scope.messages = [];
$scope.members = {}; $scope.members = {};
@ -76,7 +77,7 @@ angular.module('RoomController', [])
} }
}, },
function(error) { function(error) {
console.log("paginateBackMessages Ruh roh: " + JSON.stringify(error)); console.log("Failed to paginateBackMessages: " + JSON.stringify(error));
} }
) )
}; };
@ -89,6 +90,7 @@ angular.module('RoomController', [])
"timeout": 5000 "timeout": 5000
}}) }})
.then(function(response) { .then(function(response) {
$scope.state.stream_failure = undefined;
console.log("Got response from "+$scope.state.events_from+" to "+response.data.end); console.log("Got response from "+$scope.state.events_from+" to "+response.data.end);
$scope.state.events_from = response.data.end; $scope.state.events_from = response.data.end;
$scope.feedback = ""; $scope.feedback = "";
@ -102,7 +104,7 @@ angular.module('RoomController', [])
$timeout(shortPoll, 0); $timeout(shortPoll, 0);
} }
}, function(response) { }, function(response) {
$scope.feedback = "Can't stream: " + response.data; $scope.state.stream_failure = response;
if (response.status == 403) { if (response.status == 403) {
$scope.stopPoll = true; $scope.stopPoll = true;
@ -215,7 +217,7 @@ angular.module('RoomController', [])
// Join the room // Join the room
matrixService.join($scope.room_id).then( matrixService.join($scope.room_id).then(
function() { function() {
console.log("Joined room"); console.log("Joined room "+$scope.room_id);
// Now start reading from the stream // Now start reading from the stream
$timeout(shortPoll, 0); $timeout(shortPoll, 0);

View File

@ -86,7 +86,10 @@
<button ng-click="inviteUser(userIDToInvite)">Invite</button> <button ng-click="inviteUser(userIDToInvite)">Invite</button>
</span> </span>
<button ng-click="leaveRoom()">Leave</button> <button ng-click="leaveRoom()">Leave</button>
<button ng-click="loadMoreHistory()" ng-disabled="!state.can_paginate">MOAR HISTORY</button> <button ng-click="loadMoreHistory()" ng-disabled="!state.can_paginate">Load more history</button>
<div ng-hide="!state.stream_failure">
{{ state.stream_failure.data.error || "Connection failure" }}
</div>
</div> </div>
</div> </div>