The Codebase Consistency Update

This commit is contained in:
2025-10-21 23:47:28 -04:00
parent 458d69da84
commit 6cc08fcb02
21 changed files with 339 additions and 130 deletions

View File

@@ -1,12 +1,23 @@
from flask import Blueprint, jsonify, request, send_file
from vona.federation import send_join
import vona.globals as globals
import vona.config as config
import asyncio
import random
import os
client = Blueprint("c2s", __name__)
from flask import (
Blueprint,
jsonify,
request,
send_file,
)
client = Blueprint("client", __name__)
from .groups import groups
client.register_blueprint(groups)
@client.route("/_matrix/client/v3/account/password", methods=["POST"])
@@ -22,10 +33,10 @@ client = Blueprint("c2s", __name__)
@client.route("/_matrix/client/v3/logout", methods=["POST"])
@client.route("/_matrix/client/r0/logout", methods=["POST"])
@client.route("/_matrix/client/v3/rooms/<room>/invite", methods=["POST"])
@client.route("/_matrix/client/v3/rooms/<roomId>/leave", methods=["POST"])
@client.route("/_matrix/client/r0/rooms/<roomId>/leave", methods=["POST"])
@client.route("/_matrix/client/v3/rooms/<roomId>/read_markers", methods=["POST"])
@client.route("/_matrix/client/r0/rooms/<roomId>/read_markers", methods=["POST"])
@client.route("/_matrix/client/v3/rooms/<room>/leave", methods=["POST"])
@client.route("/_matrix/client/r0/rooms/<room>/leave", methods=["POST"])
@client.route("/_matrix/client/v3/rooms/<room>/read_markers", methods=["POST"])
@client.route("/_matrix/client/r0/rooms/<room>/read_markers", methods=["POST"])
@client.route("/_matrix/client/v3/rooms/<room>/typing/<user>", methods=["PUT"])
@client.route("/_matrix/client/api/v1/rooms/<room>/typing/<user>", methods=["PUT"])
@client.route("/_matrix/client/v3/keys/device_signing/upload", methods=["POST"])
@@ -101,10 +112,10 @@ async def lock(user):
return jsonify({"locked": True})
@client.route("/_matrix/client/api/v1/rooms/<roomId>/members")
@client.route("/_matrix/client/v3/rooms/<roomId>/members")
@client.route("/_matrix/client/r0/rooms/<roomId>/members")
async def room_members(roomId):
@client.route("/_matrix/client/api/v1/rooms/<room>/members")
@client.route("/_matrix/client/v3/rooms/<room>/members")
@client.route("/_matrix/client/r0/rooms/<room>/members")
async def room_members(room):
return jsonify({
"chunk": [{
"content": {
@@ -112,9 +123,9 @@ async def room_members(roomId):
"displayname": "Vona",
"membership": "join"
},
"event_id": globals.make_event_id(seed=roomId),
"event_id": globals.make_event_id(seed=room),
"origin_server_ts": config.the_funny_number,
"room_id": roomId,
"room_id": room,
"sender": f"@vona:{config.server_name}",
"state_key": f"@vona:{config.server_name}",
"type": "m.room.member",
@@ -489,10 +500,10 @@ async def refresh():
})
@client.route("/_matrix/client/unstable/im.nheko.summary/rooms/<roomId>/summary")
@client.route("/_matrix/client/unstable/im.nheko.summary/summary/<roomId>")
@client.route("/_matrix/client/v1/room_summary/<roomId>")
async def room_summary(roomId):
@client.route("/_matrix/client/unstable/im.nheko.summary/rooms/<room>/summary")
@client.route("/_matrix/client/unstable/im.nheko.summary/summary/<room>")
@client.route("/_matrix/client/v1/room_summary/<room>")
async def room_summary(room):
return jsonify({
"room_id": globals.make_event_id().replace("$", "!"),
"avatar_url": f"mxc://{config.server_name}/cat",
@@ -504,7 +515,7 @@ async def room_summary(roomId):
"join_rule": "public",
"room_type": "m.room",
"membership": "join",
"room_version": globals.room_version_from_id(roomId)
"room_version": globals.room_version_from_id(room)
})
@@ -627,10 +638,10 @@ async def media_config():
return jsonify({"m.upload.size": config.the_funny_number * 69420})
@client.route("/_matrix/client/api/v1/profile/<userId>/<key>", methods=["GET", "PUT", "DELETE"])
@client.route("/_matrix/client/v3/profile/<userId>/<key>", methods=["GET", "PUT", "DELETE"])
@client.route("/_matrix/client/r0/profile/<userId>/<key>", methods=["GET", "PUT", "DELETE"])
async def profile_keys(userId, key):
@client.route("/_matrix/client/api/v1/profile/<user>/<key>", methods=["GET", "PUT", "DELETE"])
@client.route("/_matrix/client/v3/profile/<user>/<key>", methods=["GET", "PUT", "DELETE"])
@client.route("/_matrix/client/r0/profile/<user>/<key>", methods=["GET", "PUT", "DELETE"])
async def profile_keys(user, key):
if request.method == "GET":
if key == "avatar_url":
return jsonify({"avatar_url": f"mxc://{config.server_name}/cat"})
@@ -645,19 +656,19 @@ async def profile_keys(userId, key):
return jsonify({})
@client.route("/_matrix/client/v3/profile/<userId>")
@client.route("/_matrix/client/r0/profile/<userId>")
async def user_profile(userId):
@client.route("/_matrix/client/v3/profile/<user>")
@client.route("/_matrix/client/r0/profile/<user>")
async def user_profile(user):
return jsonify({
"avatar_url": f"mxc://{config.server_name}/cat",
"displayname": "Vona"
})
@client.route("/_matrix/client/api/v1/rooms/<roomId>/messages")
@client.route("/_matrix/client/v3/rooms/<roomId>/messages")
@client.route("/_matrix/client/r0/rooms/<roomId>/messages")
async def room_messages(roomId):
@client.route("/_matrix/client/api/v1/rooms/<room>/messages")
@client.route("/_matrix/client/v3/rooms/<room>/messages")
@client.route("/_matrix/client/r0/rooms/<room>/messages")
async def room_messages(room):
return jsonify({
"chunk": [{
"content": {
@@ -668,7 +679,7 @@ async def room_messages(roomId):
},
"event_id": globals.make_event_id(),
"origin_server_ts": config.the_funny_number,
"room_id": roomId,
"room_id": room,
"sender": f"@vona:{config.server_name}",
"type": "m.room.message"
}],

120
vona/client/groups.py Normal file
View File

@@ -0,0 +1,120 @@
import vona.globals as globals
import vona.config as config
import time
from flask import (
Blueprint,
jsonify,
request,
)
groups = Blueprint("groups", __name__)
# This implements the C2S API for groups
@groups.route("/_matrix/client/r0/groups/<group>/self/update_publicity", methods=["PUT"])
@groups.route("/_matrix/client/r0/groups/<group>/self/accept_invite", methods=["PUT"])
@groups.route("/_matrix/client/r0/groups/<group>/self/leave", methods=["PUT"])
@groups.route("/_matrix/client/r0/groups/<group>/admin/users/remove/<user>", methods=["PUT"])
@groups.route("/_matrix/client/r0/groups/<group>/admin/rooms/<room>", methods=["PUT", "DELETE"])
async def empty(**k):
return jsonify({})
@groups.route("/_matrix/client/r0/publicised_groups/<user>")
@groups.route("/_matrix/client/r0/joined_groups")
async def joined_groups(user=None):
return jsonify({
"groups": [f"+vona:{config.server_name}"]
})
@groups.route("/_matrix/client/r0/groups/<group>/summary")
async def summary(group):
return jsonify({
"profile": {
"name": "Vona",
"short_description": "",
"long_description": "",
"avatar_url": "",
"is_public": 1,
"is_openly_joinable": True
},
"users_section": {
"users": [],
"roles": {},
"total_user_count_estimate": 0
},
"rooms_section": {
"rooms": [],
"categories": {},
"total_room_count_estimate": 0
},
"user": {
"membership": "join",
"is_public": 1,
"is_privileged": 1,
"is_publicised": True
}
})
@groups.route("/_matrix/client/r0/groups/<group>/rooms")
async def rooms(group):
return jsonify({
"chunk": [],
"total_room_count_estimate": 0
})
@groups.route("/_matrix/client/r0/groups/<group>/invited_users")
async def invited_users(group):
return jsonify({
"chunk": [],
"total_user_count_estimate": 0
})
@groups.route("/_matrix/client/r0/groups/<group>/users")
async def users(group):
return jsonify({
"chunk": [
{
"user_id": f"@vona:{config.server_name}",
"displayname": "Vona",
"avatar_url": None,
"is_public": True,
"is_privileged": True,
"attestation": globals.sign_json({
"group_id": group,
"user_id": f"@vona:{config.server_name}",
"valid_until_ms": int(str(time.time() * 1000).split(".")[0])
})
}
],
"total_user_count_estimate": 1
})
@groups.route("/_matrix/client/r0/groups/<group>/profile", methods=["GET", "POST"])
async def profile(group):
if request.method == "POST":
return jsonify({})
return jsonify({
"name": "Vona",
"short_description": "",
"long_description": "",
"avatar_url": "",
"is_public": 1,
"is_openly_joinable": True
})
@groups.route("/_matrix/client/r0/create_group", methods=["POST"])
async def create_group():
return jsonify({
"group_id": f"+vona:{config.server_name}"
})