Room version based on room ID

This commit is contained in:
2025-10-07 16:21:28 -04:00
parent 316358a82a
commit 7e77f009db
4 changed files with 33 additions and 10 deletions

View File

@@ -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]