mirror of
https://github.com/element-hq/synapse
synced 2024-09-04 02:00:05 +00:00
Serialize events before sending to ASes
This commit is contained in:
parent
131e036402
commit
0613666d9c
1 changed files with 10 additions and 0 deletions
|
@ -16,6 +16,7 @@ from twisted.internet import defer
|
||||||
|
|
||||||
from synapse.api.errors import CodeMessageException
|
from synapse.api.errors import CodeMessageException
|
||||||
from synapse.http.client import SimpleHttpClient
|
from synapse.http.client import SimpleHttpClient
|
||||||
|
from synapse.events.utils import serialize_event
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import urllib
|
import urllib
|
||||||
|
@ -30,6 +31,7 @@ class ApplicationServiceApi(SimpleHttpClient):
|
||||||
|
|
||||||
def __init__(self, hs):
|
def __init__(self, hs):
|
||||||
super(ApplicationServiceApi, self).__init__(hs)
|
super(ApplicationServiceApi, self).__init__(hs)
|
||||||
|
self.clock = hs.get_clock()
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def query_user(self, service, user_id):
|
def query_user(self, service, user_id):
|
||||||
|
@ -72,6 +74,8 @@ class ApplicationServiceApi(SimpleHttpClient):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def push_bulk(self, service, events):
|
def push_bulk(self, service, events):
|
||||||
|
events = self._serialize(events)
|
||||||
|
|
||||||
uri = service.url + ("/transactions/%s" %
|
uri = service.url + ("/transactions/%s" %
|
||||||
urllib.quote(str(0))) # TODO txn_ids
|
urllib.quote(str(0))) # TODO txn_ids
|
||||||
response = None
|
response = None
|
||||||
|
@ -98,3 +102,9 @@ class ApplicationServiceApi(SimpleHttpClient):
|
||||||
response = yield self.push_bulk(service, [event])
|
response = yield self.push_bulk(service, [event])
|
||||||
defer.returnValue(response)
|
defer.returnValue(response)
|
||||||
|
|
||||||
|
def _serialize(self, events):
|
||||||
|
time_now = self.clock.time_msec()
|
||||||
|
return [
|
||||||
|
serialize_event(e, time_now, as_client_event=True) for e in events
|
||||||
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue