Skip to content
Snippets Groups Projects
Commit 17753f0c authored by Kegan Dougal's avatar Kegan Dougal
Browse files

Add stub ApplicationServiceApi and glue it with the handler.

parent 94a5db9f
No related branches found
No related tags found
No related merge requests found
...@@ -31,10 +31,11 @@ class ApplicationService(object): ...@@ -31,10 +31,11 @@ class ApplicationService(object):
# values. # values.
NS_LIST = [NS_USERS, NS_ALIASES, NS_ROOMS] NS_LIST = [NS_USERS, NS_ALIASES, NS_ROOMS]
def __init__(self, token, url=None, namespaces=None): def __init__(self, token, url=None, namespaces=None, txn_id=None):
self.token = token self.token = token
self.url = url self.url = url
self.namespaces = self._check_namespaces(namespaces) self.namespaces = self._check_namespaces(namespaces)
self.txn_id = None
def _check_namespaces(self, namespaces): def _check_namespaces(self, namespaces):
# Sanity check that it is of the form: # Sanity check that it is of the form:
......
...@@ -13,3 +13,24 @@ ...@@ -13,3 +13,24 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
class ApplicationServiceApi(object):
"""This class manages HS -> AS communications, including querying and
pushing.
"""
def __init__(self, hs):
self.hs_token = "_hs_token_" # TODO extract hs token
def query_user(self, service, user_id):
pass
def query_alias(self, service, alias):
pass
def push_bulk(self, service, events):
pass
def push(self, service, event):
pass
...@@ -18,6 +18,7 @@ from twisted.internet import defer ...@@ -18,6 +18,7 @@ from twisted.internet import defer
from ._base import BaseHandler from ._base import BaseHandler
from synapse.api.errors import Codes, StoreError, SynapseError from synapse.api.errors import Codes, StoreError, SynapseError
from synapse.appservice import ApplicationService from synapse.appservice import ApplicationService
from synapse.appservice.api import ApplicationServiceApi
import logging import logging
...@@ -29,6 +30,7 @@ class ApplicationServicesHandler(BaseHandler): ...@@ -29,6 +30,7 @@ class ApplicationServicesHandler(BaseHandler):
def __init__(self, hs): def __init__(self, hs):
super(ApplicationServicesHandler, self).__init__(hs) super(ApplicationServicesHandler, self).__init__(hs)
self.appservice_api = ApplicationServiceApi(hs)
@defer.inlineCallbacks @defer.inlineCallbacks
def register(self, app_service): def register(self, app_service):
...@@ -97,7 +99,12 @@ class ApplicationServicesHandler(BaseHandler): ...@@ -97,7 +99,12 @@ class ApplicationServicesHandler(BaseHandler):
) )
for user_service in user_query_services: for user_service in user_query_services:
# this needs to block XXX: Need to feed response back to caller # this needs to block XXX: Need to feed response back to caller
pass # TODO poke User Query API is_known_user = self.appservice_api.query_user(
user_service, event
)
if is_known_user:
# the user exists now,so don't query more ASes.
break
# Do we know this room alias exists? If not, poke the room alias query # Do we know this room alias exists? If not, poke the room alias query
# API for all services which match that room alias regex. # API for all services which match that room alias regex.
...@@ -109,8 +116,13 @@ class ApplicationServicesHandler(BaseHandler): ...@@ -109,8 +116,13 @@ class ApplicationServicesHandler(BaseHandler):
) )
for alias_service in alias_query_services: for alias_service in alias_query_services:
# this needs to block XXX: Need to feed response back to caller # this needs to block XXX: Need to feed response back to caller
pass # TODO poke Room Alias Query API is_known_alias = self.appservice_api.query_alias(
alias_service, event
)
if is_known_alias:
# the alias exists now so don't query more ASes.
break
# Fork off pushes to these services - XXX First cut, best effort # Fork off pushes to these services - XXX First cut, best effort
for service in services: for service in services:
pass # TODO push event to service self.appservice_api.push(service, event)
...@@ -216,6 +216,7 @@ class ApplicationServiceStore(SQLBaseStore): ...@@ -216,6 +216,7 @@ class ApplicationServiceStore(SQLBaseStore):
except IndexError: except IndexError:
logger.error("Bad namespace enum '%s'. %s", ns_int, res) logger.error("Bad namespace enum '%s'. %s", ns_int, res)
# TODO get last successful txn id f.e. service
for service in services.values(): for service in services.values():
logger.info("Found application service: %s", service) logger.info("Found application service: %s", service)
self.cache.services.append(ApplicationService( self.cache.services.append(ApplicationService(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment