Define polling-started and polling-stopped signals

Client.sync() invokes them when polling is started or stopped for any
reason.

Signed-off-by: Gergely Polonkai <gergely@polonkai.eu>
This commit is contained in:
Gergely Polonkai 2016-03-21 15:48:31 +01:00
parent 457371b25b
commit 5fedf09f76
2 changed files with 32 additions and 0 deletions

View File

@ -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.
*

View File

@ -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;
}