Room version based on room ID
This commit is contained in:
@@ -446,7 +446,7 @@ async def room_summary(roomId):
|
||||
"join_rule": "public",
|
||||
"room_type": "m.room",
|
||||
"membership": "join",
|
||||
"room_version": 2
|
||||
"room_version": globals.room_version_from_id(roomId)
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -4,14 +4,13 @@ import tomllib
|
||||
|
||||
addr: str = "127.0.0.1"
|
||||
port: int = 5000
|
||||
allow_registration: bool = False
|
||||
users_can_register: bool = False
|
||||
the_funny_number: int = 1337
|
||||
cat: str = "/etc/vona/cat.jpg"
|
||||
|
||||
server_name: str = ""
|
||||
signing_key: str = ""
|
||||
support: dict = {"contacts": []}
|
||||
users_can_register: bool = False
|
||||
|
||||
_CONFIG_PATH = Path("/etc/vona/config.toml")
|
||||
|
||||
@@ -57,7 +56,7 @@ def _validate_cat_path(cat_path: str) -> Path:
|
||||
|
||||
|
||||
def _apply_config(cfg: dict) -> None:
|
||||
global addr, port, allow_registration, server_name, signing_key, cat, support
|
||||
global addr, port, server_name, signing_key, cat, support, users_can_register
|
||||
|
||||
if "address" in cfg:
|
||||
addr = str(cfg["address"])
|
||||
@@ -68,9 +67,6 @@ def _apply_config(cfg: dict) -> None:
|
||||
except (TypeError, ValueError):
|
||||
_warn(f"Invalid port in config: {cfg.get('port')}; using default {port}")
|
||||
|
||||
if "allow_registration" in cfg:
|
||||
allow_registration = bool(cfg["allow_registration"])
|
||||
|
||||
if "server_name" in cfg:
|
||||
server_name = str(cfg["server_name"])
|
||||
else:
|
||||
|
||||
@@ -26,7 +26,7 @@ def send_join(request, roomId) -> dict:
|
||||
"content": {
|
||||
"m.federate": True,
|
||||
"creator": f"@vona:{server_name}",
|
||||
"room_version": "2"
|
||||
"room_version": globals.room_version_from_id(roomId)
|
||||
},
|
||||
"event_id": event_ids[0],
|
||||
"origin_server_ts": 1,
|
||||
@@ -350,7 +350,7 @@ async def make_join(roomId, userId):
|
||||
|
||||
return jsonify({
|
||||
"event": globals.hash_and_sign_event(join),
|
||||
"room_version": "2"
|
||||
"room_version": globals.room_version_from_id(roomId)
|
||||
})
|
||||
|
||||
@server.route("/_matrix/federation/v1/publicRooms", methods=["POST", "GET"])
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from collections import Counter
|
||||
import vona.config as config
|
||||
import nacl.signing
|
||||
import hashlib
|
||||
@@ -7,7 +8,7 @@ import copy
|
||||
import json
|
||||
import re
|
||||
|
||||
version = "25w41b"
|
||||
version = "1.4.2"
|
||||
|
||||
|
||||
def canonical_json(value):
|
||||
@@ -223,3 +224,29 @@ def hash_and_sign_event(event_object):
|
||||
signed_object = sign_json(stripped_object)
|
||||
event_object["signatures"] = signed_object["signatures"]
|
||||
return event_object
|
||||
|
||||
|
||||
def room_version_from_id(room_id):
|
||||
room_id_no_sigil = room_id.replace("!", "")
|
||||
|
||||
hexadecimal_room_id = bytes(room_id_no_sigil, "utf-8").hex()
|
||||
|
||||
if "1" not in hexadecimal_room_id and "2" not in hexadecimal_room_id:
|
||||
# NOTE: v2 if impossible from room ID alone
|
||||
hexadecimal_room_id = "2" + hexadecimal_room_id[1:]
|
||||
|
||||
def remove_chars(s):
|
||||
return re.sub("[^12]", "", s)
|
||||
|
||||
nums = remove_chars(hexadecimal_room_id)
|
||||
|
||||
def most_common_character(s):
|
||||
s = s.replace(" ", "").lower()
|
||||
|
||||
counts = Counter(s)
|
||||
|
||||
most_common = counts.most_common(1)
|
||||
|
||||
return most_common[0] if most_common else None
|
||||
|
||||
return most_common_character(nums)[0]
|
||||
|
||||
Reference in New Issue
Block a user