77 Commits

Author SHA1 Message Date
5062c9dd15 Trying again 2026-04-20 12:20:25 -04:00
f844be04b0 make_unimplemented_handler 2026-04-20 12:13:51 -04:00
eb8fff42bf One more 2026-04-20 12:08:30 -04:00
d94c1342b0 Additional bug fixes 2026-04-20 12:02:12 -04:00
cb4945d469 Extra checks 2026-04-20 11:50:11 -04:00
5bbb2e6afa syntax 2026-04-20 11:11:30 -04:00
5756d8ba39 Close parenthases 2026-04-20 10:44:01 -04:00
9e95b1fd78 Handle nil value in client _sync 2026-04-20 10:35:36 -04:00
joenas
151355a790 Trying to get things to work with minetest mod security:
Require is only allowed at init, with request_insecure_environment()
2017-08-07 11:46:06 +02:00
Adrian Perez de Castro
2946b55810 Make :sync() always add a "since" query parameter if available
...which ensures that multiple consecutive requests to /sync paginate
properly.
2017-02-05 14:11:55 +01:00
Adrian Perez de Castro
be1ee939ee Make :sync() call the API endpoint always at least once
Othewise it could happen that a request to /sync would not be done even
once depending on how the "stop" callback is defined.
2017-02-05 13:50:40 +01:00
Adrian Perez de Castro
ae18e3374d 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.
2017-02-05 11:14:25 +01:00
Adrian Perez de Castro
fda9fa4e41 Return event_id from room methods that send messages
The "event_id" returned by the HS is returned directly, instead of
a lone table with a single "event_id" member, for the following methods:

  room:send_text()
  room:send_emote()
  room:send_notice()
2016-10-24 18:00:09 +03:00
Adrian Perez de Castro
f420a7a8a7 CI: Correct cjson -> lua-cjson 2016-07-10 02:47:04 +03:00
Adrian Perez de Castro
e6da7d88c3 Add new client:find_room(room_id_or_alias) method
This allows searching a (previosly joined) room given either their room
identifier or any of the room aliases.
2016-07-10 02:43:50 +03:00
Adrian Perez de Castro
876ca4ccc7 CI: Install the cjson dependency 2016-07-10 02:42:48 +03:00
Adrian Perez de Castro
ed7353afc2 Import a few unit test specs for matrix.room 2016-07-10 02:39:13 +03:00
Adrian Perez de Castro
fcbcbbe8d8 detailUtfTerm: Make it play nicer with Travis-CI 2016-07-10 02:38:27 +03:00
Adrian Perez de Castro
2316b25317 Give more details on unit test output
This adds an output handler for Busted which reuses the built-in "utfTerminal"
handler, and augments it by showing the name of each suite/test as it is run.
2016-07-10 01:48:37 +03:00
Adrian Perez de Castro
0422c47178 Make room:get_alias_or_id() return the shortest alias
This makes the room:get_alias_or_id() method return the shortest of the room
aliases in case that a canonical_alias is not set. In general this will save
screen real estate when a client uses the method to get a readable room
identifier to display to the user.
2016-07-10 01:45:49 +03:00
Adrian Perez de Castro
0fa555f6a8 client-cqchat.lua: Actually exit when Ctrl-D is entered 2016-07-09 01:01:31 +03:00
Adrian Perez de Castro
bb23740c1c Beautify examples/client-cqchat.lua 2016-07-09 00:32:25 +03:00
Adrian Perez de Castro
c2de4bfd85 Add method room:get_alias_or_id()
This new methods returns the most adequate identifier for a room:

1. If defined, the room's canonical alias.
2. Otherwise, the first alias.
3. As a last resort, the room identifier is returned.
2016-07-09 00:30:59 +03:00
Adrian Perez de Castro
eee489678b Add (crappy) but functional interactive cqueues-based chat client 2016-07-08 21:17:41 +03:00
Adrian Perez de Castro
522908d984 Add echobot.lua example 2016-07-05 01:15:23 +03:00
Adrian Perez de Castro
b0cbf93b7e Use a callback in client:sync() to determine when to stop the loop
Instead of adding more and more possible conditions on which the while-loop
inside client:sync() could stop, support passing a callback function which is
used to determine when to stop the loop.

The old "so N iterations behaviour" can be achieved with something like:

  function iterate_n_times(n)
    return function ()
      n = n - 1
      return n == 0
    end
  end
  client:sync(iterate_n_times(10))

If no function is passed, the client:sync() function loops forever.
2016-07-05 01:09:51 +03:00
Adrian Perez de Castro
cadda45130 Handle "join" events properly
This handles the fact that when using the /sync endpoint, events for already
joined rooms are also in the "join" dictionary in the response. The firing of
the "joined" event is moved to client:_make_room() and done only the first
time that the room creation is requested.

This also fixes bogus behavior: previosly, when a message was sent to a room
there would be multiople places where the "joined" event would be fired, and
message events pushed multile times onto the room object, which would call
the event handlers more than once for each message. Ugh.
2016-07-05 01:03:23 +03:00
Adrian Perez de Castro
bad6e6ee16 Allow passing a room object to client:join_room()
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.
2016-07-05 01:01:34 +03:00
Adrian Perez de Castro
e51b67aef6 Fire "message" events for rooms which receive messages 2016-07-05 00:59:55 +03:00
Adrian Perez de Castro
f879cd68e6 Have matrix.client fire "left" events when leaving a room
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.
2016-07-05 00:58:33 +03:00
Adrian Perez de Castro
a50931c3f6 Use room.client instead of room._client
This hints that the "client" attribute can be used from user code.
And it can.
2016-07-05 00:57:12 +03:00
Adrian Perez de Castro
30eec81619 Update client-send-message.lua to not do an initial sync
The initial sync is not needed, provided that the user has to supply anyway
the room ID or alias in the command line of the script.
2016-07-04 18:34:23 +03:00
Adrian Perez de Castro
51c8eda815 Fix conversion of http.headers in Lua 5.1 and LuaJIT
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.
2016-07-04 18:23:35 +03:00
Adrian Perez de Castro
0aa232965c Workaround LuaSocket's lax response validation
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.
2016-07-04 17:52:39 +03:00
Adrian Perez de Castro
43470d72d1 Add examples on how to send messages to rooms
This adds two similar examples, one using matrix.client, and the other using
matrix.api.
2016-07-04 13:44:23 +03:00
Adrian Perez de Castro
fabb5330d1 First pass at client:sync()
For the moment only the amount of iterations, or processing events foerever,
can be specified. The timeout is not yet configurable.
2016-07-04 03:19:16 +03:00
Adrian Perez de Castro
02b3d880a6 Log the identifier of the batch of events being requested 2016-07-04 03:18:43 +03:00
Adrian Perez de Castro
9cd4e13310 Use xpcall() instead of pcall() to obtain tracebacks
Printing a traceback is much more help when debugging event handling.
2016-07-04 03:17:25 +03:00
Adrian Perez de Castro
c1492cd39a Add missing string format parameter when loggign property changes 2016-07-04 03:16:46 +03:00
Adrian Perez de Castro
b861b37dbb Fix typo "ince" -> "since" in api:sync() 2016-07-04 03:16:10 +03:00
Adrian Perez de Castro
c67a5506bf README: Add build/coverage status badges 2016-07-03 22:57:39 +03:00
Adrian Perez de Castro
7952f15053 eventable: Fix unhooking of handlers 2016-07-03 22:55:28 +03:00
Adrian Perez de Castro
f295145331 CI: Ignore LuaRocks base directory for coverage report 2016-07-03 22:43:59 +03:00
Adrian Perez de Castro
f52aadc7c6 CI: Test also with LuaJIT 2.0 and 2.1 2016-07-03 22:38:43 +03:00
Adrian Perez de Castro
477fb65cf6 CI: Include only matrix/ subdir for code coverage report 2016-07-03 22:33:36 +03:00
Adrian Perez de Castro
76d137009b Use busted for unit testing 2016-07-03 22:25:31 +03:00
Adrian Perez de Castro
4e9899dbb5 Simplify matrix.eventable for the common use cases
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.
2016-07-03 22:21:33 +03:00
Adrian Perez de Castro
72060d8a32 Fix tests for matrix.eventable 2016-07-03 15:27:59 +03:00
Adrian Perez de Castro
a8ebe24d38 CI: Do nothing in "install" step
This is needed to override the default action of the "python" build type,
which is installing from requirements.txt with pip.
2016-07-03 15:24:12 +03:00
Adrian Perez de Castro
513aac201d CI: Configure Travis-CI 2016-07-03 15:21:14 +03:00