Commit Graph

23 Commits

Author SHA1 Message Date
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
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
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
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
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
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
03c1091742 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".
2016-07-03 15:06:25 +03:00
Adrian Perez de Castro
bd811c859e Rename matrix.factory.* -> matrix.httpclient.*
The old name didn't really make much sense after all...
2016-07-01 05:10:22 +03:00
Adrian Perez de Castro
e128366f7f Use eventables in matrix.client, implement a chunk of functionality
Yeah, I know: commits should have been smaller and all that. Yadda-yadda.
2016-07-01 05:05:50 +03:00
Adrian Perez de Castro
a1cf21b839 Implement room:update_room_{topic,aliases,name} 2016-06-23 04:17:15 +03:00
Adrian Perez de Castro
56a57f2e89 Add __tostring metamethods to prototypes
This is nice to have, and aids with debugging and interactive usage.
2016-06-23 04:07:01 +03:00
Adrian Perez de Castro
cafb8724e3 Import rough implementation of matrix.client 2016-06-23 03:54:48 +03:00