The Codebase Consistency Update
This commit is contained in:
@@ -1,8 +1,18 @@
|
||||
from flask import jsonify, Response, request, send_file, abort, Blueprint
|
||||
import json, time, os, threading
|
||||
import vona.globals as globals
|
||||
import vona.config as config
|
||||
|
||||
import threading
|
||||
import json
|
||||
import time
|
||||
import os
|
||||
|
||||
from flask import (
|
||||
jsonify,
|
||||
Response,
|
||||
request,
|
||||
send_file,
|
||||
Blueprint,
|
||||
)
|
||||
|
||||
server = Blueprint("federation", __name__)
|
||||
http = globals.http_client()
|
||||
@@ -12,28 +22,28 @@ class bullshit:
|
||||
def get_json():
|
||||
return {}
|
||||
|
||||
def send_join(request, roomId) -> dict:
|
||||
def send_join(request, room) -> dict:
|
||||
event_chain = []
|
||||
event_hashes = []
|
||||
|
||||
event_ids = [
|
||||
globals.make_event_id(seed=f"1_{roomId}"),
|
||||
globals.make_event_id(seed=f"2_{roomId}"),
|
||||
globals.make_event_id(seed=f"3_{roomId}"),
|
||||
globals.make_event_id(seed=f"4_{roomId}"),
|
||||
globals.make_event_id(seed=f"5_{roomId}"),
|
||||
globals.make_event_id(seed=f"6_{roomId}"),
|
||||
globals.make_event_id(seed=f"1_{room}"),
|
||||
globals.make_event_id(seed=f"2_{room}"),
|
||||
globals.make_event_id(seed=f"3_{room}"),
|
||||
globals.make_event_id(seed=f"4_{room}"),
|
||||
globals.make_event_id(seed=f"5_{room}"),
|
||||
globals.make_event_id(seed=f"6_{room}"),
|
||||
]
|
||||
|
||||
create_event = {
|
||||
"content": {
|
||||
"m.federate": True,
|
||||
"creator": f"@vona:{config.server_name}",
|
||||
"room_version": globals.room_version_from_id(roomId)
|
||||
"room_version": globals.room_version_from_id(room)
|
||||
},
|
||||
"event_id": event_ids[0],
|
||||
"origin_server_ts": 1,
|
||||
"room_id": roomId,
|
||||
"room_id": room,
|
||||
"sender": f"@vona:{config.server_name}",
|
||||
"state_key": "",
|
||||
"depth": 1,
|
||||
@@ -56,7 +66,7 @@ def send_join(request, roomId) -> dict:
|
||||
"state_key": f"@vona:{config.server_name}",
|
||||
"type": "m.room.member",
|
||||
"event_id": event_ids[1],
|
||||
"room_id": roomId,
|
||||
"room_id": room,
|
||||
"depth": 2,
|
||||
"auth_events": [[
|
||||
screate_event["event_id"],
|
||||
@@ -78,7 +88,7 @@ def send_join(request, roomId) -> dict:
|
||||
}
|
||||
},
|
||||
"origin_server_ts": 3,
|
||||
"room_id": roomId,
|
||||
"room_id": room,
|
||||
"sender": f"@vona:{config.server_name}",
|
||||
"state_key": "",
|
||||
"type": "m.room.power_levels",
|
||||
@@ -113,7 +123,7 @@ def send_join(request, roomId) -> dict:
|
||||
"state_key": "",
|
||||
"type": "m.room.join_rules",
|
||||
"event_id": event_ids[3],
|
||||
"room_id": roomId,
|
||||
"room_id": room,
|
||||
"depth": 4,
|
||||
"auth_events": [
|
||||
[
|
||||
@@ -148,7 +158,7 @@ def send_join(request, roomId) -> dict:
|
||||
"state_key": "",
|
||||
"type": "m.room.guest_access",
|
||||
"event_id": event_ids[4],
|
||||
"room_id": roomId,
|
||||
"room_id": room,
|
||||
"auth_events": [
|
||||
[
|
||||
screate_event["event_id"],
|
||||
@@ -182,7 +192,7 @@ def send_join(request, roomId) -> dict:
|
||||
"origin_server_ts": 6,
|
||||
"depth": 6,
|
||||
"event_id": event_ids[5],
|
||||
"room_id": roomId,
|
||||
"room_id": room,
|
||||
"auth_events": [
|
||||
[
|
||||
screate_event["event_id"],
|
||||
@@ -278,16 +288,16 @@ async def thumbnail_media(media_id):
|
||||
"error": "Cat is too cute to thumbnail"
|
||||
}), 418
|
||||
|
||||
@server.route("/_matrix/federation/v1/send_join/<roomId>/<eventId>", methods=["PUT"])
|
||||
async def send_join_v1(roomId, eventId):
|
||||
return jsonify([200, send_join(request, roomId)])
|
||||
@server.route("/_matrix/federation/v1/send_join/<room>/<eventId>", methods=["PUT"])
|
||||
async def send_join_v1(room, eventId):
|
||||
return jsonify([200, send_join(request, room)])
|
||||
|
||||
@server.route("/_matrix/federation/v2/send_join/<roomId>/<eventId>", methods=["PUT"])
|
||||
async def send_join_v2(roomId, eventId):
|
||||
return jsonify(send_join(request, roomId))
|
||||
@server.route("/_matrix/federation/v2/send_join/<room>/<eventId>", methods=["PUT"])
|
||||
async def send_join_v2(room, eventId):
|
||||
return jsonify(send_join(request, room))
|
||||
|
||||
@server.route("/_matrix/federation/v1/make_join/<roomId>/<userId>")
|
||||
async def make_join(roomId, userId):
|
||||
@server.route("/_matrix/federation/v1/make_join/<room>/<user>")
|
||||
async def make_join(room, user):
|
||||
def not_invited():
|
||||
return jsonify({
|
||||
"errcode": "M_FORBIDDEN",
|
||||
@@ -295,14 +305,14 @@ async def make_join(roomId, userId):
|
||||
}), 403
|
||||
|
||||
try:
|
||||
if roomId.split(":")[1] != config.server_name:
|
||||
if room.split(":")[1] != config.server_name:
|
||||
return not_invited()
|
||||
except:
|
||||
return not_invited()
|
||||
|
||||
state = send_join(
|
||||
request=bullshit,
|
||||
roomId=roomId
|
||||
room=room
|
||||
)["state"]
|
||||
|
||||
join = {
|
||||
@@ -312,9 +322,9 @@ async def make_join(roomId, userId):
|
||||
},
|
||||
"origin": config.server_name,
|
||||
"origin_server_ts": 7,
|
||||
"room_id": roomId,
|
||||
"sender": userId,
|
||||
"state_key": userId,
|
||||
"room_id": room,
|
||||
"sender": user,
|
||||
"state_key": user,
|
||||
"type": "m.room.member",
|
||||
"depth": 7
|
||||
}
|
||||
@@ -341,7 +351,7 @@ async def make_join(roomId, userId):
|
||||
|
||||
return jsonify({
|
||||
"event": globals.hash_and_sign_event(join),
|
||||
"room_version": globals.room_version_from_id(roomId)
|
||||
"room_version": globals.room_version_from_id(room)
|
||||
})
|
||||
|
||||
|
||||
@@ -415,15 +425,6 @@ async def user_keys():
|
||||
|
||||
@server.route("/_matrix/federation/v2/invite/<room>/<txnId>", methods=["PUT"])
|
||||
async def invite_user_v2(room, txnId):
|
||||
return invite_user(request.data)
|
||||
|
||||
|
||||
@server.route("/_matrix/federation/v1/invite/<room>/<txnId>", methods=["PUT"])
|
||||
async def invite_user_v1(room, txnId):
|
||||
return [200, invite_user(request.json)]
|
||||
|
||||
|
||||
def invite_user(invite_data):
|
||||
if "event" in invite_data:
|
||||
if "room_version" in invite_data:
|
||||
if invite_data["room_version"] not in ["1", "2"]:
|
||||
@@ -436,7 +437,6 @@ def invite_user(invite_data):
|
||||
event = invite_data.get("event", {})
|
||||
content = event.get("content", {})
|
||||
|
||||
# NOTE to crispycat: I know you loooooove this syntax
|
||||
if (
|
||||
"content" in event
|
||||
and "membership" in content
|
||||
@@ -446,7 +446,7 @@ def invite_user(invite_data):
|
||||
and event["state_key"] == f"@vona:{config.server_name}"
|
||||
):
|
||||
return jsonify({
|
||||
"event": globals.sign_json_without_discard(invite_data["event"]),
|
||||
"event": globals.sign_json_without_discard(event),
|
||||
"room_version": invite_data["room_version"]
|
||||
})
|
||||
|
||||
@@ -457,8 +457,34 @@ def invite_user(invite_data):
|
||||
}), 403
|
||||
|
||||
|
||||
@server.route("/_matrix/federation/v1/hierarchy/<roomId>")
|
||||
async def space_hierachy(roomId):
|
||||
@server.route("/_matrix/federation/v1/invite/<room>/<txnId>", methods=["PUT"])
|
||||
async def invite_user_v1(room, txnId):
|
||||
event = request.json
|
||||
content = event.get("content", {})
|
||||
|
||||
if (
|
||||
"content" in event
|
||||
and "membership" in content
|
||||
and "state_key" in event
|
||||
and "room_id" in event
|
||||
and content["membership"] == "invite"
|
||||
and event["state_key"] == f"@vona:{config.server_name}"
|
||||
and "event_id" in event
|
||||
and ":" in event["event_id"]
|
||||
):
|
||||
return jsonify({
|
||||
"event": globals.sign_json_without_discard(event),
|
||||
"room_version": invite_data["room_version"]
|
||||
})
|
||||
|
||||
return jsonify({
|
||||
"errcode": "M_FORBIDDEN",
|
||||
"error": "Invalid invitation PDU"
|
||||
}), 403
|
||||
|
||||
|
||||
@server.route("/_matrix/federation/v1/hierarchy/<room>")
|
||||
async def space_hierachy(room):
|
||||
return jsonify({
|
||||
"errcode": "M_NOT_FOUND",
|
||||
"error": "Room does not exist."
|
||||
|
||||
Reference in New Issue
Block a user