diff --git a/app/src/main/java/com/github/gotify/service/WebSocketService.java b/app/src/main/java/com/github/gotify/service/WebSocketService.java
index fbce419..491ee17 100644
--- a/app/src/main/java/com/github/gotify/service/WebSocketService.java
+++ b/app/src/main/java/com/github/gotify/service/WebSocketService.java
@@ -35,6 +35,8 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
+import static com.github.gotify.api.Callback.call;
+
public class WebSocketService extends Service {
public static final String NEW_MESSAGE_BROADCAST =
@@ -105,7 +107,7 @@ public class WebSocketService extends Service {
cm,
alarmManager)
.onOpen(this::onOpen)
- .onClose(() -> foreground(getString(R.string.websocket_closed)))
+ .onClose(this::onClose)
.onBadRequest(this::onBadRequest)
.onNetworkFailure(
(min) -> foreground(getString(R.string.websocket_failed, min)))
@@ -122,6 +124,24 @@ public class WebSocketService extends Service {
picassoHandler.updateAppIds();
}
+ private void onClose() {
+ foreground(getString(R.string.websocket_closed_try_reconnect));
+ ClientFactory.userApiWithToken(settings)
+ .currentUser()
+ .enqueue(
+ call(
+ (ignored) -> this.doReconnect(),
+ (exception) -> {
+ if (exception.code() == 401) {
+ foreground(getString(R.string.websocket_closed_logout));
+ } else {
+ Log.i(
+ "WebSocket closed but the user still authenticated, trying to reconnect");
+ this.doReconnect();
+ }
+ }));
+ }
+
private void onDisconnect() {
foreground(getString(R.string.websocket_no_network));
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index a52569e..39c2848 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -21,7 +21,8 @@
Server returned 401 unauthorized while trying to get current user. This can be caused by deleting the client for this session.
Could not get current user. Server (%s) responded with code %d: body (first 200 chars): %s
Connection failed, trying again in %d minutes
- WebSocket closed; The client-token could be invalidated, please re-login
+ User action required: Please login, the authentication token isn\'t valid anymore.
+ Connection closed, trying to establish a new one.
Received %d messages while being disconnected
Delete all
Delete logs