diff --git a/src/matrix-client.vala b/src/matrix-client.vala index ee6de07..161e109 100644 --- a/src/matrix-client.vala +++ b/src/matrix-client.vala @@ -50,6 +50,22 @@ public interface Matrix.Client : GLib.Object { @event(string? room_id, Json.Node raw_event, Matrix.Event.Base? matrix_event) {} + /** + * This signal is emitted when polling is started. + */ + public signal void + polling_started(); + + /** + * This signal gets invoked when polling is stopped due to any + * reason. + * + * @param error gets set to an actual error if polling is stopped + * due to one + */ + public signal void + polling_stopped(GLib.Error? error); + /** * Callback function delegate for the event signal. * diff --git a/src/matrix-http-client.vala b/src/matrix-http-client.vala index 56ce550..a48b44b 100644 --- a/src/matrix-http-client.vala +++ b/src/matrix-http-client.vala @@ -368,9 +368,20 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client { || (error is Matrix.Error.M_UNKNOWN_TOKEN) || (error is Matrix.Error.M_UNAUTHORIZED)) { try { + token = null; + token_refresh((i, ct, jc, rc, err) => { login_finished((error == null) || (error is Matrix.Error.NONE)); + + if (token == null) { + refresh_token = null; + polling_stopped(err); + + try { + stop_polling(false); + } catch (GLib.Error e) {} + } } , null); } catch (Matrix.Error e) {} } @@ -384,6 +395,7 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client { if ((error == null) || (error.code < 500)) { begin_polling(); } else if ((error != null) && error.code >= 500) { + polling_stopped(error); stop_polling(false); } } catch (Matrix.Error e) {} @@ -404,6 +416,10 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client { throw e; } + if (_polling == false) { + polling_started(); + } + _polling = true; }