Fix up directory server to not require uploading room hosts. Update the room hosts table with the current room hosts (if we have them) on GET.
This commit is contained in:
parent
5f7cdbe0b8
commit
30bcbc433a
|
@ -37,7 +37,7 @@ class DirectoryHandler(BaseHandler):
|
||||||
)
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def create_association(self, room_alias, room_id, servers):
|
def create_association(self, room_alias, room_id, servers=None):
|
||||||
# TODO(erikj): Do auth.
|
# TODO(erikj): Do auth.
|
||||||
|
|
||||||
if not room_alias.is_mine:
|
if not room_alias.is_mine:
|
||||||
|
@ -48,6 +48,12 @@ class DirectoryHandler(BaseHandler):
|
||||||
|
|
||||||
# TODO(erikj): Check if there is a current association.
|
# TODO(erikj): Check if there is a current association.
|
||||||
|
|
||||||
|
if not servers:
|
||||||
|
servers = yield self.store.get_joined_hosts_for_room(room_id)
|
||||||
|
|
||||||
|
if not servers:
|
||||||
|
raise SynapseError(400, "Failed to get server list")
|
||||||
|
|
||||||
yield self.store.create_room_alias_association(
|
yield self.store.create_room_alias_association(
|
||||||
room_alias,
|
room_alias,
|
||||||
room_id,
|
room_id,
|
||||||
|
@ -83,6 +89,9 @@ class DirectoryHandler(BaseHandler):
|
||||||
defer.returnValue({})
|
defer.returnValue({})
|
||||||
return
|
return
|
||||||
|
|
||||||
|
extra_servers = yield self.store.get_joined_hosts_for_room(room_id)
|
||||||
|
servers = list(set(extra_servers) | set(servers))
|
||||||
|
|
||||||
defer.returnValue({
|
defer.returnValue({
|
||||||
"room_id": room_id,
|
"room_id": room_id,
|
||||||
"servers": servers,
|
"servers": servers,
|
||||||
|
|
|
@ -54,7 +54,7 @@ class ClientDirectoryServer(RestServlet):
|
||||||
logger.debug("Got room name: %s", room_alias.to_string())
|
logger.debug("Got room name: %s", room_alias.to_string())
|
||||||
|
|
||||||
room_id = content["room_id"]
|
room_id = content["room_id"]
|
||||||
servers = content["servers"]
|
servers = content["servers"] if "servers" in content else None
|
||||||
|
|
||||||
logger.debug("Got room_id: %s", room_id)
|
logger.debug("Got room_id: %s", room_id)
|
||||||
logger.debug("Got servers: %s", servers)
|
logger.debug("Got servers: %s", servers)
|
||||||
|
|
|
@ -50,6 +50,7 @@ class DirectoryTestCase(unittest.TestCase):
|
||||||
hs = HomeServer("test",
|
hs = HomeServer("test",
|
||||||
datastore=Mock(spec=[
|
datastore=Mock(spec=[
|
||||||
"get_association_from_room_alias",
|
"get_association_from_room_alias",
|
||||||
|
"get_joined_hosts_for_room",
|
||||||
]),
|
]),
|
||||||
http_client=None,
|
http_client=None,
|
||||||
resource_for_federation=Mock(),
|
resource_for_federation=Mock(),
|
||||||
|
@ -61,6 +62,10 @@ class DirectoryTestCase(unittest.TestCase):
|
||||||
|
|
||||||
self.datastore = hs.get_datastore()
|
self.datastore = hs.get_datastore()
|
||||||
|
|
||||||
|
def hosts(room_id):
|
||||||
|
return defer.succeed([])
|
||||||
|
self.datastore.get_joined_hosts_for_room.side_effect = hosts
|
||||||
|
|
||||||
self.my_room = hs.parse_roomalias("#my-room:test")
|
self.my_room = hs.parse_roomalias("#my-room:test")
|
||||||
self.remote_room = hs.parse_roomalias("#another:remote")
|
self.remote_room = hs.parse_roomalias("#another:remote")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue