From 03c109174257deb363c036be9b411fb6915bcb8e Mon Sep 17 00:00:00 2001 From: Adrian Perez de Castro Date: Sun, 3 Jul 2016 15:06:25 +0300 Subject: [PATCH] Allow skipping the automatic sync on login/registration This removes the currently unused "limit" parameter from client:login_with_password() and client:register_with_password(), and adds a new "no_sync" parameter. When the flag is set, the call to client:_sync() is skipped. This can be useful for small scripts which do not need to do a sync after login, yet they would rather user the higher level "matrix.client" instead of the low level "matrix.api". For example, a simple script to send a message to an already-known room given its ID could skip the sync in order to be faster, without needing to revert to using "matrix.api". --- matrix/client.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/matrix/client.lua b/matrix/client.lua index 6c33ca3..af82422 100644 --- a/matrix/client.lua +++ b/matrix/client.lua @@ -314,24 +314,26 @@ function Client:__tostring() return self.__name .. "{" .. self._api.base_url .. "}" end -function Client:register_with_password(username, password, limit) +function Client:register_with_password(username, password, no_sync) return self:_logged_in(self._api:register("m.login.password", - { user = username, password = password }), limit) + { user = username, password = password }), no_sync) end -function Client:login_with_password(username, password, limit) +function Client:login_with_password(username, password, no_sync) return self:_logged_in(self._api:login("m.login.password", - { user = username, password = password }), limit) + { user = username, password = password }), no_sync) end -function Client:_logged_in(response, limit) +function Client:_logged_in(response, no_sync) self._log("logged-in: %s", response.user_id) self.user_id = response.user_id self.homeserver = response.home_server self.token = response.access_token self._api.token = response.access_token self:fire("logged-in") - self:_sync() + if not no_sync then + self:_sync() + end return self.token end