Assign User Group to mChat Room

Chat rooms for mChat with optional password protection and 1-on-1 chats
Post Reply
mortalites
Donor
Posts: 8
Joined: 30 Jul 2018, 17:20

Assign User Group to mChat Room

#1

Post by mortalites » 14 Aug 2018, 20:39

Hopefully i can explain what I am looking for. I would like the ability to create a Room and then assign a User Group to it. So for instance I would like a special room for Patreons/Donors. So if a user is apart of that group they will have access to that specific room.

Thanks

Voice4Vision
Donor
Posts: 4
Joined: 29 Dec 2017, 21:41

Re: Assign User Group to mChat Room

#2

Post by Voice4Vision » 15 Aug 2018, 16:58

mortalites, I honestly believe this would make for a great feature. I could use this to allow for Staff communication or even VIP's in contacting me for private live support.

User avatar
kasimi
mChat developer
Posts: 795
Joined: 06 Oct 2016, 09:56
Location: Germany
Contact:

Re: Assign User Group to mChat Room

#3

Post by kasimi » 15 Aug 2018, 19:35

@mortalites Adding this feature into Rooms is possible but quite a lot of work. An easier solution that we could set up much quicker is to manually add code to your Room's listener file that adds a user to a lockprivate room of your choice when he is added to a certain group. This won't affect users that are already in the the group though, but there might be a way to one-time add those as well. I'd have too look into it. Let me know if you're interested in jumping into the code.

@Voice4Vision You can do this without any code edits, though not fully automated: create a new lockprivate room and invite your staff or VIPs to it. The room won't be visible to anyone except for those you invite. There you have your hidden live support room. :D

User avatar
kasimi
mChat developer
Posts: 795
Joined: 06 Oct 2016, 09:56
Location: Germany
Contact:

Re: Assign User Group to mChat Room

#4

Post by kasimi » 17 Aug 2018, 08:57

Alright, here's how you would need to edit the code to automatically send an invitation to a user when he joins a group. It should work for protected rooms as well, but I haven't tested the code at all.

In ext/kasimi/mchatrooms/event/main_listener.php, find the getSubscribedEvents() method and add this new listener to the array:

Code: Select all

- This code is only accessible to donors -
Below the getSubscribedEvents() method, add this new event handler method:

Code: Select all

- This code is only accessible to donors -
This code means that when someone is added to group 123, it sends an invitation to that user for room 456 with the message "Welcome!". You can of course add more lines to the $group_to_room array, for example:

Code: Select all

- This code is only accessible to donors -

yorick
Donor
Posts: 4
Joined: 21 Sep 2018, 14:07

Re: Assign User Group to mChat Room

#5

Post by yorick » 21 Sep 2018, 14:10

+1 to mortalites feature request. This'd be quite useful.

The code work-around is appreciated, I might subscribe just for that.

Any idea on how to one-time apply that to existing group users? Maybe a SQL query?

yorick
Donor
Posts: 4
Joined: 21 Sep 2018, 14:07

Re: Assign User Group to mChat Room

#6

Post by yorick » 22 Sep 2018, 08:31

In case folk are reading this and wondering how to get those values, that'd be done from mysql. Either command line or phpMyAdmin, some way of running a sql query.

Code: Select all

- This code is only accessible to donors -
Replace the admin user, db name, and group and room names; ditch the less-than greater-than; keep any quotes.

Users are assigned to rooms in phpbb_mchat_rooms_users, by their id.

The next bits are all command line. There may be a way to do this through phpMyAdmin.

User membership in a group can be output to a file.

Code: Select all

- This code is only accessible to donors -
Now that the user IDs are in the file "groupmembers", put this into the DB:

Code: Select all

- This code is only accessible to donors -
As before, things in <> are placeholders and need to be replaced. Keep the single quotes though. No space between -p and the <password>.

User avatar
kasimi
mChat developer
Posts: 795
Joined: 06 Oct 2016, 09:56
Location: Germany
Contact:

Re: Assign User Group to mChat Room

#7

Post by kasimi » 22 Sep 2018, 08:36

yorick wrote:
21 Sep 2018, 14:10
Any idea on how to one-time apply that to existing group users? Maybe a SQL query?
Hi yorick, thanks for joining and sharing. :wave:

Keep in mind that your solution doesn't send any notifications.

You can send multiple invites to existing users with the Invite users feature at the top of the Rooms list. Just grab a list of all users in your group from the ACP's groups page and paste them in the text box. It works for protected as well as private rooms and users get a notification they can click on to quickly join the room.

yorick
Donor
Posts: 4
Joined: 21 Sep 2018, 14:07

Re: Assign User Group to mChat Room

#8

Post by yorick » 22 Sep 2018, 08:37

@kasimi, I added your code to main_listener.php. When a user is deleted, I'm assuming removing them from any rooms they belong to is handled by the existing cleanup code?

Added in 34 seconds:
kasimi wrote:
22 Sep 2018, 08:36
Keep in mind that your solution doesn't send any notifications.

You can send multiple invites to existing users with the Invite users feature at the top of the Rooms list. Just grab a list of all users in your group from the ACP's groups page and paste them in the text box. It works for protected as well as private rooms and users get a notification they can click on to quickly join the room.
That's much better, thanks!

User avatar
kasimi
mChat developer
Posts: 795
Joined: 06 Oct 2016, 09:56
Location: Germany
Contact:

Re: Assign User Group to mChat Room

#9

Post by kasimi » 22 Sep 2018, 08:47

yorick wrote:
22 Sep 2018, 08:37
When a user is deleted, I'm assuming removing them from any rooms they belong to is handled by the existing cleanup code?
Yes, although I just found that sessions for deleted users in public and protected rooms weren't deleted until the room itself is deleted. This will be improved in the next Rooms update. :+1:

Post Reply

Who is online

Users browsing this forum: rammstein and 1 guest