Modify channel topic before join?

Hi everyone,

I’m wondering if you can change the channel topic before you join a channel. For example, I send a call for room:2/3 but I want that call to return a connection to room:5 instead? Can I do this on the backend?

Thanks

Can you elaborate on your use case?

I’m building a backend for a chat app, all of the channels are with only two participants. What I want to do is send the ids of both participants and have the phoenix backend create a channel where the channel id is the result of the two ids being put through an unordered pairing function. This would allow the front end to send a topic like “room:2/3” or “room:3/2” and be put into the same channel.

The issue I’m having is that there isn’t a way for me to change the topic to “room:4” ( f(2,3) = 4 ) so that both participants are in the correct channel.

I could do some workarounds like subscribing to external topics, but that feels like overengineering.

Ah that makes sense. Instead of trying to do this as the channel join, I’d have an API that the client can hit, and have that API return the channel to join.

At that point, I might be better of putting the pairing function in the client.

Yes absolutely, if that’s possible I’d do that.

Why the complexity of the unordered pairing function? Why not just order the 2 ids, and let room:2/3 be the channel name? (If you need to map to a “single” id internally, just generate that and keep a mapping. But I’d be that even that is not really necessary.)

Instead of generating room id based on both user_id, I have a generated uuid for the room, and the room genserver holds state for members. If You are not a member, You are not allowed to join the channel.

The room is created by a matching system, where users have to agree to enter chat (Request, ACK). Thus, I know how to set members.

You can freely distribute uuid between users.

3 Likes

This is certainly a better solution but I’m still curious if my idea can even work.