matrix-org / matrix-js-sdk

Matrix Client-Server SDK for JavaScript
Apache License 2.0
1.57k stars 583 forks source link

In the spirit of matrix-doc/specification/modules/guest_access.rst, Allow Guest to sendTyping + sendReceipt + sendMessage #1509

Open archywillhe opened 4 years ago

archywillhe commented 4 years ago

Is your feature request related to a problem? Please describe. Yes. The problem is that if we want to use matrix-js-sdk to build chat/RTC applications with a more guest-centric design it is difficult unless we create an user account with password in the background for them. (There is a whole thread on this: https://github.com/vector-im/element-web/issues/9264)

Describe the solution you'd like I would like to introduce changes to the SDK to allow guest send message, as well as enable guest to send typing notification.

So maybe remove

    if (this.isGuest()) {
        return Promise.resolve({}); // guests cannot send typing notifications so don't bother.
    }

in MatrixClient.prototype.sendTyping and MatrixClient.prototype.sendReceipt in src/client.js.

And then maybe need to do something in _sendCompleteEvent,etc too?


According to https://github.com/matrix-org/matrix-doc/blob/master/specification/modules/guest_access.rst#put-matrix-client-%CLIENT_MAJOR_VERSION%-rooms-roomid-send-eventtype-txnid :

The following API endpoints are allowed to be accessed by guest accounts for sending events:

POST /rooms/:room_id/join
POST /rooms/:room_id/leave
PUT /rooms/:room_id/send/m.room.message/:txn_id
PUT /sendToDevice/{eventType}/{txnId}

So it's implemented in Matrix that guest can PUT /rooms/:room_id/send/m.room.message/:txn_id?

I have not gone through synapse's source so I can't confirm that though.

Additional context This is my day 1 of reading matrix-js-sdk's source. So will appreaciate any pointers!

archywillhe commented 4 years ago

related: https://github.com/matrix-org/matrix-js-sdk/issues/998 https://github.com/nomadic-labs/safesupport-chatbox/issues/5

t3chguy commented 4 years ago

allow guest send message

It does.

Element Web used to use this function but then started requiring registration to start chatting out of their own choice, the technology allowed it.

archywillhe commented 3 years ago

@t3chguy it was implemented using the ILAG approach and doesn’t go through the guest API. Read more here https://github.com/vector-im/element-web/issues/9264

t3chguy commented 3 years ago

Yes. But before ILAG it used real guests. And even now if you have a Synapse configured to auto-join guests into a room then Element will let that guest speak. Youa re correct that typing and receipts don't work. But messages DO

archywillhe commented 3 years ago

Hmm I think I know what’s happening now. So the current sdk does allow for send message. But just not typing & receipt.

And in Element It is somehow designed that if you join a none-auto-join room as a guest, you won’t be able to do much. But auto-join lands you to a different GUI and you can send message.

Do you think the Matrix backend supports guest typing & receipt or it doesn’t?

t3chguy commented 3 years ago

This repo does not concern any GUI. It is a very low level library.

archywillhe commented 3 years ago

@t3chguy i was talking about the matrix react library because you mentioned Element.

t3chguy commented 3 years ago

In Element (matrix-react-sdk), it will prevent you from joining a room as a guest. But if you are somehow in one as that guest (directly manipulating the API or Synapse auto join) then it will let you do everything a guest is technically capable of doing.

archywillhe commented 3 years ago

Yeah by “join a room as guest” i meant more as turning on guest_access in Synapse and visiting a room as a guest. But indeed. That is more like guest preview than guest join.

I’ve been working on a hobby project https://lo.fish and right now I’m deciding whether to rewrite my backend in Eilixir or switch to using Matrix and write my front end into a Matrix client. My project relies heavily on guest access functionality, which I felt like is not something Matrix pays a lot of attentions in. (Of course you can argue that if enough interest is generated & there will be more pull requests on this & more will be done. Also can be nice if I can contribute some code to Matrix too.)

Eventually I will open source my project (i.e. as an Elixir+react framework or as a Matrix client). Right now I’m not sure if I should invest the time in Matrix and do it the Matrix way, or go for a more flexible approach (Elixir) and have more control over the architecture (but then of course if I want to enjoy things like decentralisation and E2E I will have to do more work. So this will also change the trajectory of my project.)