synapse icon indicating copy to clipboard operation
synapse copied to clipboard

Disable / turn off direct messages

Open george-angel opened this issue 6 years ago • 6 comments

Description:

Hello, we have a rather specific use-case where we would like to use matrix internally for teams in the company, but we would like to only allow room conversations, no direct messages (apart from few select members may be).

Is this at all possible? Happy to hear any hacky solution you might have.

Currently we are looking to use Slack and to drop packages on the firewall where URI matches structures of a DM.

So yes, you could say we are flexible.

george-angel avatar Mar 13 '20 07:03 george-angel

Yes, you can do this by forbidding users on the server to issue invites; only to join rooms. The antispam module API in synapse has a can_invite hook which you can return false in.

ara4n avatar Mar 13 '20 08:03 ara4n

Brilliant - thank you very much.

george-angel avatar Mar 13 '20 08:03 george-angel

@george-angel Can you describe how you did that?

Did @ara4n mean "block_invites:true" in mjolnir.AntiSpam or something else?

a-fellerer avatar Feb 17 '21 11:02 a-fellerer

@Chatcloud we didn't end up using this, but looking through past commits this is the code used in the PoC:

spam.py:

import logging

logger = logging.getLogger(__name__)


class Checker:
    def __init__(self, config, api):
        self.config = config
        self.api = api

    def check_event_for_spam(self, foo):
        return False  # allow all events

    def user_may_invite(self, inviter_userid, invitee_userid, room_id):
        """
        prevent users from inviting others to rooms unless they are in the
        configured list of admins

        this is primarily done to block users from initiating direct messages
        """
        if inviter_userid in self.config["admins"]:
            return True
        return False

    def user_may_create_room(self, userid):
        return True  # allow all room creations

    def user_may_create_room_alias(self, userid, room_alias):
        return True  # allow all room aliases

    def user_may_publish_room(self, userid, room_id):
        return True  # allow publishing of all rooms

    def check_username_for_spam(self, user_profile):
        return False  # allow all usernames

    @staticmethod
    def parse_config(config):
        return config

george-angel avatar Feb 17 '21 11:02 george-angel

@Chatcloud - I have used a similar variation of the above spam file as well, but in our case we preferred to set "create_room" to false for non-admin users as this would prevent a DM from being created as well (a DM is effectively a room with only 2 people in it). This would mean that users can still invite other users to a room they are members in, BUT the caveat is that your admins will have to then create/manage the rooms and their members directly.

phewitt-uw avatar Feb 17 '21 12:02 phewitt-uw

@phewitt-uw that sounds good. Thank you!

a-fellerer avatar Feb 18 '21 06:02 a-fellerer