poljar / weechat-matrix

Weechat Matrix protocol script written in python
Other
958 stars 120 forks source link

List/accept/reject open invites #174

Open pinusc opened 4 years ago

pinusc commented 4 years ago

I'd like to make a suggestion to add a command to list all standing invites, printing the room name and ID. I realize that invites are printed in real-time, but they get buried fast; right now my workflow has to involve logging in through Riot and accepting the invite from there.

I suggest to add a /list-invites command. Then invites could be accepted with /join, and another command (/reject_invite?) could be created to reject them.

I haven't worked much with the matrix protocol but if it's simple enough I would be happy to work on this.

poljar commented 4 years ago

If you're interested in adding this, the client object will already have all the info to make this work client.invited_rooms is a dict from room_id to MatrixInvitedRoom.

The client object is stored inside a server object which can be accessed via a global, take a look at how other commands get to a server.

Making the completion for /join work is another thing that would be neat.

pinusc commented 4 years ago

Thank you!

I've been playing around with adding a new command, but it seems that client.invited_rooms is invariably empty (even though I do have standing invites). Here's the code:

def matrix_listinvites_command_cb(data, buffer, args):
    for server in SERVERS.values():
        if buffer in server.buffers.values() or buffer == server.server_buffer:
           # adding a sync doesn't change anything
            # server.sync(timeout=1000)
            server.info(server.client.invited_rooms)
            break
    return W.WEECHAT_RC_OK

On the nio documentation it says that this dictionary should be populated after a sync. I assume that the client syncs on connect (and then perioducally), but the dict is still empty. Evern after manually calling sync just to be sure. Am I doing anything wrong here?

poljar commented 4 years ago

You are correct that the client syncs on connect and periodically, you don't need to call sync there, besides it's a non-blocking call so you won't get a new sync in the next line anyways.

It seems that the way we restore the state doesn't give us the invited rooms, we are using full_state=True for the sync.

This sadly gives only the full state of the joined rooms. You may notice that if you delete all the data or connect to a server the first time the invited_rooms dict will be populated.

I'm afraid that there doesn't seem to exist an easy fix for this, there doesn't seem to be an API call that we can use to figure out the invited rooms after the initial sync. We'll need to store the invited rooms to the local when the client launches again.