From 73f8792b757236935f5a6cffe7a649b2e08313bf Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Mon, 11 Apr 2022 23:45:00 -0400 Subject: [PATCH] Set history & join rules to match KakaoTalk behaviour --- .../kt/types/channel/channel_type.py | 4 ++++ matrix_appservice_kakaotalk/portal.py | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/matrix_appservice_kakaotalk/kt/types/channel/channel_type.py b/matrix_appservice_kakaotalk/kt/types/channel/channel_type.py index 634c702..10b0424 100644 --- a/matrix_appservice_kakaotalk/kt/types/channel/channel_type.py +++ b/matrix_appservice_kakaotalk/kt/types/channel/channel_type.py @@ -30,6 +30,10 @@ class KnownChannelType(str, Enum): def is_direct(cls, value: Union["KnownChannelType", str]) -> bool: return value in [cls.DirectChat, cls.MemoChat] + @classmethod + def is_open(cls, value: Union["KnownChannelType", str]) -> bool: + return value in [cls.OM, cls.OD] + ChannelType = Union[KnownChannelType, str] # Substitute for ChannelType = "name1" | ... | "nameN" | str diff --git a/matrix_appservice_kakaotalk/portal.py b/matrix_appservice_kakaotalk/portal.py index 77b12cd..f8f34a0 100644 --- a/matrix_appservice_kakaotalk/portal.py +++ b/matrix_appservice_kakaotalk/portal.py @@ -40,6 +40,8 @@ from mautrix.types import ( EventType, FileInfo, ImageInfo, + JoinRule, + JoinRulesStateEventContent, LocationMessageEventContent, MediaInfo, MediaMessageEventContent, @@ -630,6 +632,17 @@ class Portal(DBPortal, BasePortal): "content": self.bridge_info, }, ] + if KnownChannelType.is_open(info.channel_info.type): + initial_state.extend(( + { + "type": str(EventType.ROOM_JOIN_RULES), + "content": JoinRulesStateEventContent(join_rule=JoinRule.PUBLIC).serialize(), + }, + { + "type": "m.room.guest_access", + "content": {"guest_access": "forbidden"}, + }, + )) invites = [] if self.config["bridge.encryption.default"] and self.matrix.e2ee: self.encrypted = True