-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
11 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,9 @@ | |
@dataclass_json | ||
@dataclass | ||
class Config: | ||
# Inviters to ignore the following list for | ||
deny_inviters: list[str] | ||
|
||
# Allow invited users to join | ||
allow_invited: bool = True | ||
|
||
|
@@ -59,6 +62,12 @@ async def is_mit_student(self, user: str) -> bool: | |
affiliation = await self.get_affiliation(user) | ||
print(f"[uplink_synapse_module] {user}'s affiliation is {affiliation}") | ||
return affiliation == '[email protected]' | ||
|
||
async def who_invited(self, user: str, room: str) -> bool: | ||
event_key = ('m.room.member', user) | ||
state = await self.api.get_room_state(room, [event_key]) | ||
invitation = state[event_key] | ||
return invitation.sender | ||
|
||
async def user_may_join_room(self, user: str, room: str, is_invited: bool): | ||
# We are choosing to use the empty string as state key since we don't need one | ||
|
@@ -72,7 +81,8 @@ async def user_may_join_room(self, user: str, room: str, is_invited: bool): | |
|
||
print("[uplink_synapse_module] user_may_join_room called on", user, "and", room) | ||
# Allow invited users to join if the config says so | ||
if self.config.allow_invited and is_invited: | ||
if self.config.allow_invited and is_invited \ | ||
and await self.who_invited(user, room) not in self.config.deny_inviters: | ||
print("[uplink_synapse_module]", "user was invited, accepting") | ||
return NOT_SPAM | ||
if await self.is_mit_student(user): | ||
|