This neatly allows to pass the room object passed to the "invited" event
directly to :join_room(). This way the user does not need to know that
rooms have a "room_id" attribute.
This allows hooking to both room join and room leave events at the client
level, which apart from being more orthogonal, may be more convenient
sometimes.
The __pairs metamethod was introduced in 5.2, so instead of using pairs()
on http.headers values, use its :each() method — which is what the __pairs
metamethod calls anyway.
When receiving a HTTP response without a statusline, "nil" is returned as
reponse headers and status line values, but the response code will still
be "200 Success", which is quite not right as there wasn't ever a response
status code received. This patch adds a check for a status line, and returns
with an early error if needed.
This condition can be triggered by trying to speak plain HTTP to a
HTTPS-enabled server, e.g. using http://matrix.org:8448 instead of
https://matrix.org:8448 as homeserver URL.
This removes the support for passing values to eventable.functions() and
eventable.object() which are bound to be passed to handlers. On top of
simplifying the code overall, this also avoids having three different
implementations of the fire() function.
In the existing code, the only case in which a handler argument is fixed
is for objects which pass themselves. This use case is covered by
eventable.object(), so the removed code was not realy ever used.
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".
* Support debug-logging to stderr by defining the MATRIX_EVENTABLE_DEBUG_LOG
environment variable.
* Support for unhooking handlers from events.
* Simplify the low-level interface: eventable.functions() now returns the
created functions directly, cutting down on an intermediate table.
* A new eventable.object() allows adding :hook(), :unhook() and :fire()
methods to any table. Firing events always sends the table itself as first
event parameter when firing any event.
The matrix.eventable module/function returns a table with a pair of functions
which can be used to connect event handlers to events, and to generate them.
Basic usage is as follows:
obj = eventable()
obj.hook("event-name", print) -- Handle the event with "print"
obj.fire("event-name", "Hello, world") -- Prints "Hello, world"
This initial implementation has the following limitations:
* Event handlers are always invoked in the same order in which they have been
connected using the .hook() function.
* Individual event handlers cannot be disconnected. Only disconnecting all
handlers for en event at once is possible via .hook("event", nil).
The old prefix could be confusing if the homeserver URL used the https://
scheme, and the new one better conveys that it is matrix.api who is doing
the logging.
This introduces a get_http_factory() function which will try to load
a HTTP client library according to the following logic:
1. If the MATRIX_API_HTTP_CLIENT environment variable is defined, it is
taken as the name of a HTTP client library.
2. Otherwise, if the function paramter is non-nil it is used as the name
of the HTTP client library to load.
3. Otherwise, the available HTTP client libraries are tried in order,
and the first one which can be require()'d successfully will be
used. For now this has only the "chttp" client.
This avoids the potential issue in which the status code would be "nil" or
"false", which HTTP client libraries may choose to signal an error condition.
* The :quote and :unquote methods are now plain functions and no longer
receive the "self" parameter. This allows to directly use the utility
functions provided by the HTTP client library.
* Renamed CqHttpClient to plain "httclient". The variable itself is local
to the script so it does not need to be unique.