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:
		| @@ -50,6 +50,22 @@ public interface Matrix.Client : GLib.Object { | |||||||
|     @event(string? room_id, Json.Node raw_event, Matrix.Event.Base? matrix_event) |     @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. |      * Callback function delegate for the event signal. | ||||||
|      * |      * | ||||||
|   | |||||||
| @@ -368,9 +368,20 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client { | |||||||
|                    || (error is Matrix.Error.M_UNKNOWN_TOKEN) |                    || (error is Matrix.Error.M_UNKNOWN_TOKEN) | ||||||
|                    || (error is Matrix.Error.M_UNAUTHORIZED)) { |                    || (error is Matrix.Error.M_UNAUTHORIZED)) { | ||||||
|             try { |             try { | ||||||
|  |                 token = null; | ||||||
|  |  | ||||||
|                 token_refresh((i, ct, jc, rc, err) => { |                 token_refresh((i, ct, jc, rc, err) => { | ||||||
|                         login_finished((error == null) |                         login_finished((error == null) | ||||||
|                                        || (error is Matrix.Error.NONE)); |                                        || (error is Matrix.Error.NONE)); | ||||||
|  |  | ||||||
|  |                         if (token == null) { | ||||||
|  |                             refresh_token = null; | ||||||
|  |                             polling_stopped(err); | ||||||
|  |  | ||||||
|  |                             try { | ||||||
|  |                                 stop_polling(false); | ||||||
|  |                             } catch (GLib.Error e) {} | ||||||
|  |                         } | ||||||
|                     } , null); |                     } , null); | ||||||
|             } catch (Matrix.Error e) {} |             } catch (Matrix.Error e) {} | ||||||
|         } |         } | ||||||
| @@ -384,6 +395,7 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client { | |||||||
|                 if ((error == null) || (error.code < 500)) { |                 if ((error == null) || (error.code < 500)) { | ||||||
|                     begin_polling(); |                     begin_polling(); | ||||||
|                 } else if ((error != null) && error.code >= 500) { |                 } else if ((error != null) && error.code >= 500) { | ||||||
|  |                     polling_stopped(error); | ||||||
|                     stop_polling(false); |                     stop_polling(false); | ||||||
|                 } |                 } | ||||||
|             } catch (Matrix.Error e) {} |             } catch (Matrix.Error e) {} | ||||||
| @@ -404,6 +416,10 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client { | |||||||
|             throw e; |             throw e; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         if (_polling == false) { | ||||||
|  |             polling_started(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         _polling = true; |         _polling = true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user