federation state_ids
This commit is contained in:
@@ -1,13 +1,17 @@
|
|||||||
from flask import jsonify, Response, request, send_file, abort, Blueprint
|
from flask import jsonify, Response, request, send_file, abort, Blueprint
|
||||||
|
import json, time, os, threading
|
||||||
import vona.globals as globals
|
import vona.globals as globals
|
||||||
import vona.config as config
|
import vona.config as config
|
||||||
import json
|
|
||||||
import time
|
|
||||||
import os
|
|
||||||
|
|
||||||
server = Blueprint("federation", __name__)
|
server = Blueprint("federation", __name__)
|
||||||
|
http = globals.http_client()
|
||||||
|
|
||||||
|
|
||||||
|
class bullshit:
|
||||||
|
def get_json():
|
||||||
|
return {}
|
||||||
|
|
||||||
def send_join(request, roomId) -> dict:
|
def send_join(request, roomId) -> dict:
|
||||||
event_chain = []
|
event_chain = []
|
||||||
event_hashes = []
|
event_hashes = []
|
||||||
@@ -296,10 +300,6 @@ async def make_join(roomId, userId):
|
|||||||
except:
|
except:
|
||||||
return not_invited()
|
return not_invited()
|
||||||
|
|
||||||
class bullshit:
|
|
||||||
def get_json():
|
|
||||||
return {}
|
|
||||||
|
|
||||||
state = send_join(
|
state = send_join(
|
||||||
request=bullshit,
|
request=bullshit,
|
||||||
roomId=roomId
|
roomId=roomId
|
||||||
@@ -476,10 +476,6 @@ async def discover_common_rooms():
|
|||||||
async def backfill(room):
|
async def backfill(room):
|
||||||
# TODO: burger king foot lettuce
|
# TODO: burger king foot lettuce
|
||||||
|
|
||||||
class bullshit:
|
|
||||||
def get_json():
|
|
||||||
return {}
|
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"origin": config.server_name,
|
"origin": config.server_name,
|
||||||
"origin_server_ts": int(str(time.time() * 1000).split(".")[0]),
|
"origin_server_ts": int(str(time.time() * 1000).split(".")[0]),
|
||||||
@@ -495,3 +491,63 @@ async def extremities(room):
|
|||||||
globals.make_event_id(seed=f"6_{room}"),
|
globals.make_event_id(seed=f"6_{room}"),
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@server.route("/_matrix/federation/v1/state_ids/<room>")
|
||||||
|
async def state_ids(room):
|
||||||
|
if (
|
||||||
|
"event_id" in request.args
|
||||||
|
and request.args["event_id"].strip() != ""
|
||||||
|
):
|
||||||
|
evt = request.args["event_id"]
|
||||||
|
def explode():
|
||||||
|
return jsonify({
|
||||||
|
"errcode": "M_NOT_FOUND",
|
||||||
|
"error": f"Could not find event {evt}"
|
||||||
|
}), 404
|
||||||
|
|
||||||
|
|
||||||
|
if ":" not in evt:
|
||||||
|
return explode()
|
||||||
|
if ":" in room:
|
||||||
|
if room.split(":")[1] != config.server_name:
|
||||||
|
return explode()
|
||||||
|
else:
|
||||||
|
return explode()
|
||||||
|
|
||||||
|
server_name = evt.split(":")[1]
|
||||||
|
|
||||||
|
if server_name == config.server_name:
|
||||||
|
state = send_join(bullshit, room)["state"]
|
||||||
|
event_ids = []
|
||||||
|
|
||||||
|
for event in state:
|
||||||
|
event_ids.append(event["event_id"])
|
||||||
|
|
||||||
|
if evt in event_ids:
|
||||||
|
return jsonify({
|
||||||
|
"auth_chain_ids": [event_ids],
|
||||||
|
"pdu_ids": [event_ids]
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
return explode()
|
||||||
|
|
||||||
|
try:
|
||||||
|
resp = http.get(
|
||||||
|
path=request.full_path,
|
||||||
|
destination=server_name,
|
||||||
|
)
|
||||||
|
|
||||||
|
if resp.status_code != 200:
|
||||||
|
raise
|
||||||
|
|
||||||
|
return jsonify(resp.json())
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return explode()
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"errcode": "M_MISSING_PARAM",
|
||||||
|
"error": "Query parameter 'event_id' was not specified"
|
||||||
|
}), 400
|
||||||
|
|||||||
Reference in New Issue
Block a user