mirror of
https://mau.dev/maunium/synapse.git
synced 2024-09-11 04:09:34 +02:00
Use transport client directly
This commit is contained in:
parent
3e703eb04e
commit
68f34e85ce
1 changed files with 25 additions and 18 deletions
|
@ -32,15 +32,17 @@ logger = logging.getLogger(__name__)
|
||||||
# TODO: Add group memebership /sync
|
# TODO: Add group memebership /sync
|
||||||
|
|
||||||
|
|
||||||
def _create_rerouter(name):
|
def _create_rerouter(func_name):
|
||||||
|
"""Returns a function that looks at the group id and calls the function
|
||||||
|
on federation or the local group server if the group is local
|
||||||
|
"""
|
||||||
def f(self, group_id, *args, **kwargs):
|
def f(self, group_id, *args, **kwargs):
|
||||||
if self.is_mine_id(group_id):
|
if self.is_mine_id(group_id):
|
||||||
return getattr(self.groups_server_handler, name)(
|
return getattr(self.groups_server_handler, func_name)(
|
||||||
group_id, *args, **kwargs
|
group_id, *args, **kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
repl_layer = self.hs.get_replication_layer()
|
return getattr(self.transport_client, func_name)(group_id, *args, **kwargs)
|
||||||
return getattr(repl_layer, name)(group_id, *args, **kwargs)
|
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,6 +52,7 @@ class GroupsLocalHandler(object):
|
||||||
self.store = hs.get_datastore()
|
self.store = hs.get_datastore()
|
||||||
self.room_list_handler = hs.get_room_list_handler()
|
self.room_list_handler = hs.get_room_list_handler()
|
||||||
self.groups_server_handler = hs.get_groups_server_handler()
|
self.groups_server_handler = hs.get_groups_server_handler()
|
||||||
|
self.transport_client = hs.get_federation_transport_client()
|
||||||
self.auth = hs.get_auth()
|
self.auth = hs.get_auth()
|
||||||
self.clock = hs.get_clock()
|
self.clock = hs.get_clock()
|
||||||
self.keyring = hs.get_keyring()
|
self.keyring = hs.get_keyring()
|
||||||
|
@ -82,15 +85,19 @@ class GroupsLocalHandler(object):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_group_summary(self, group_id, requester_user_id):
|
def get_group_summary(self, group_id, requester_user_id):
|
||||||
|
"""Get the group summary for a group.
|
||||||
|
|
||||||
|
If the group is remote we check that the users have valid attestations.
|
||||||
|
"""
|
||||||
if self.is_mine_id(group_id):
|
if self.is_mine_id(group_id):
|
||||||
res = yield self.groups_server_handler.get_group_summary(
|
res = yield self.groups_server_handler.get_group_summary(
|
||||||
group_id, requester_user_id
|
group_id, requester_user_id
|
||||||
)
|
)
|
||||||
defer.returnValue(res)
|
defer.returnValue(res)
|
||||||
|
|
||||||
repl_layer = self.hs.get_replication_layer()
|
res = yield self.transport_client.get_group_summary(group_id, requester_user_id)
|
||||||
res = yield repl_layer.get_group_summary(group_id, requester_user_id)
|
|
||||||
|
|
||||||
|
# Loop through the users and validate the attestations.
|
||||||
chunk = res["users_section"]["users"]
|
chunk = res["users_section"]["users"]
|
||||||
valid_users = []
|
valid_users = []
|
||||||
for entry in chunk:
|
for entry in chunk:
|
||||||
|
@ -121,8 +128,7 @@ class GroupsLocalHandler(object):
|
||||||
group_id, user_id, content
|
group_id, user_id, content
|
||||||
)
|
)
|
||||||
|
|
||||||
repl_layer = self.hs.get_replication_layer()
|
return self.transport_client.create_group(group_id, user_id, content) # TODO
|
||||||
return repl_layer.create_group(group_id, user_id, content) # TODO
|
|
||||||
|
|
||||||
def add_room(self, group_id, user_id, room_id, content):
|
def add_room(self, group_id, user_id, room_id, content):
|
||||||
if self.is_mine_id(group_id):
|
if self.is_mine_id(group_id):
|
||||||
|
@ -130,8 +136,9 @@ class GroupsLocalHandler(object):
|
||||||
group_id, user_id, room_id, content
|
group_id, user_id, room_id, content
|
||||||
)
|
)
|
||||||
|
|
||||||
repl_layer = self.hs.get_replication_layer()
|
return self.transport_client.add_room_to_group(
|
||||||
return repl_layer.add_room_to_group(group_id, user_id, room_id, content) # TODO
|
group_id, user_id, room_id, content,
|
||||||
|
) # TODO
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_users_in_group(self, group_id, requester_user_id):
|
def get_users_in_group(self, group_id, requester_user_id):
|
||||||
|
@ -141,8 +148,9 @@ class GroupsLocalHandler(object):
|
||||||
)
|
)
|
||||||
defer.returnValue(res)
|
defer.returnValue(res)
|
||||||
|
|
||||||
repl_layer = self.hs.get_replication_layer()
|
res = yield self.transport_client.get_users_in_group(
|
||||||
res = yield repl_layer.get_users_in_group(group_id, requester_user_id) # TODO
|
group_id, requester_user_id,
|
||||||
|
) # TODO
|
||||||
|
|
||||||
chunk = res["chunk"]
|
chunk = res["chunk"]
|
||||||
valid_entries = []
|
valid_entries = []
|
||||||
|
@ -179,8 +187,9 @@ class GroupsLocalHandler(object):
|
||||||
local_attestation = self.attestations.create_attestation(group_id, user_id)
|
local_attestation = self.attestations.create_attestation(group_id, user_id)
|
||||||
content["attestation"] = local_attestation
|
content["attestation"] = local_attestation
|
||||||
|
|
||||||
repl_layer = self.hs.get_replication_layer()
|
res = yield self.transport_client.accept_group_invite(
|
||||||
res = yield repl_layer.accept_group_invite(group_id, user_id, content)
|
group_id, user_id, content,
|
||||||
|
)
|
||||||
|
|
||||||
remote_attestation = res["attestation"]
|
remote_attestation = res["attestation"]
|
||||||
|
|
||||||
|
@ -211,8 +220,7 @@ class GroupsLocalHandler(object):
|
||||||
group_id, user_id, requester_user_id, content,
|
group_id, user_id, requester_user_id, content,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
repl_layer = self.hs.get_replication_layer()
|
res = yield self.transport_client.invite_to_group(
|
||||||
res = yield repl_layer.invite_to_group(
|
|
||||||
group_id, user_id, content,
|
group_id, user_id, content,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -257,8 +265,7 @@ class GroupsLocalHandler(object):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
content["requester_user_id"] = requester_user_id
|
content["requester_user_id"] = requester_user_id
|
||||||
repl_layer = self.hs.get_replication_layer()
|
res = yield self.transport_client.remove_user_from_group(
|
||||||
res = yield repl_layer.remove_user_from_group(
|
|
||||||
group_id, user_id, content
|
group_id, user_id, content
|
||||||
) # TODO
|
) # TODO
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue