Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for room version 1 and 2 #5

Merged
merged 28 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion manage_last_admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
from typing import List, Tuple, Optional, Set, Iterable

import attr
from frozendict import frozendict
from synapse.events import EventBase
from synapse.module_api import ModuleApi, UserID
from synapse.types import StateMap
from synapse.api.room_versions import RoomVersion, EventFormatVersions
from synapse.util.stringutils import random_string


from manage_last_admin._constants import EventTypes, Membership

Expand Down Expand Up @@ -154,6 +156,7 @@ async def _on_room_leave(
"type": EventTypes.PowerLevels,
"content": power_levels_content,
"state_key": "",
**_maybe_get_event_id_dict_for_room_version(event.room_version, self._api.server_name()),
}
)

Expand Down Expand Up @@ -188,6 +191,7 @@ async def _promote_to_admins(
"type": EventTypes.PowerLevels,
"content": new_pl_content,
"state_key": "",
**_maybe_get_event_id_dict_for_room_version(event.room_version, self._api.server_name()),
}
)

Expand All @@ -210,6 +214,14 @@ def _is_local_user(self, user_id: str) -> bool:
# ID, then they were a local user
return user_id == local_user_id

def _maybe_get_event_id_dict_for_room_version(room_version: RoomVersion, server_name: str) -> dict:
"""If this room version needs it, generate an event id"""
if room_version.event_format != EventFormatVersions.ROOM_V1_V2:
return {}

random_id = random_string(43)
return {"event_id": "!%s:%s" % (random_id,server_name,)}


def _is_last_admin_leaving(
event: EventBase,
Expand Down
Loading
Loading