From ae18e3374dc395a64508315082d8f79038c9e16d Mon Sep 17 00:00:00 2001 From: Adrian Perez de Castro Date: Sun, 5 Feb 2017 11:14:25 +0100 Subject: [PATCH] Support implicitly syncing on login Whether to sync after connecting or not is desired depends on the application, and it's better to remove the possibility of doing so. Having to done one explicit call to :sync() is not a big deal, and makes the intention of code using the module clearer. And our code simpler. --- matrix/client.lua | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/matrix/client.lua b/matrix/client.lua index b2d8fee..82de2fe 100644 --- a/matrix/client.lua +++ b/matrix/client.lua @@ -323,43 +323,35 @@ Client.__name = "matrix.client" Client.__index = Client setmetatable(Client, { __call = function (self, base_url, token, http_client) - local c = eventable.object(setmetatable({ + return eventable.object(setmetatable({ presence = {}, -- Indexed by user_id rooms = {}, -- Indexed by room_id _log = get_debug_log_function(), _api = API(base_url, token, http_client), }, Client)) - -- Do an initial sync if a token was provided on construction. - if token then - c:_sync() - end - return c end }) function Client:__tostring() return self.__name .. "{" .. self._api.base_url .. "}" end -function Client:register_with_password(username, password, no_sync) +function Client:register_with_password(username, password) return self:_logged_in(self._api:register("m.login.password", - { user = username, password = password }), no_sync) + { user = username, password = password })) end -function Client:login_with_password(username, password, no_sync) +function Client:login_with_password(username, password) return self:_logged_in(self._api:login("m.login.password", - { user = username, password = password }), no_sync) + { user = username, password = password })) end -function Client:_logged_in(response, no_sync) +function Client:_logged_in(response) 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") - if not no_sync then - self:_sync() - end return self.token end