diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py
index 728cc7849d..d4a2f02fc2 100644
--- a/synapse/appservice/__init__.py
+++ b/synapse/appservice/__init__.py
@@ -14,7 +14,7 @@
# limitations under the License.
import logging
import re
-from typing import TYPE_CHECKING, List, Optional, Match, Iterable
+from typing import TYPE_CHECKING, Iterable, List, Match, Optional
from synapse.api.constants import EventTypes
from synapse.events import EventBase
@@ -132,7 +132,7 @@ class ApplicationService:
raise ValueError("Expected string for 'regex' in ns '%s'" % ns)
return namespaces
- def _matches_regex(self, test_string: str, namespace_key: str)-> Optional[Match]:
+ def _matches_regex(self, test_string: str, namespace_key: str) -> Optional[Match]:
for regex_obj in self.namespaces[namespace_key]:
if regex_obj["regex"].match(test_string):
return regex_obj
@@ -255,7 +255,7 @@ class ApplicationService:
def is_interested_in_user(self, user_id: str) -> bool:
return (
- self._matches_regex(user_id, ApplicationService.NS_USERS)
+ bool(self._matches_regex(user_id, ApplicationService.NS_USERS))
or user_id == self.sender
)
@@ -290,7 +290,7 @@ class ApplicationService:
if regex_obj["exclusive"]
]
- def get_groups_for_user(self, user_id: str)-> Iterable[str]:
+ def get_groups_for_user(self, user_id: str) -> Iterable[str]:
"""Get the groups that this user is associated with by this AS
Args:
@@ -324,7 +324,7 @@ class AppServiceTransaction:
service: ApplicationService,
id: int,
events: List[EventBase],
- ephemeral: Optional[List[JsonDict]] = None,
+ ephemeral: List[JsonDict],
):
self.service = service
self.id = id
@@ -335,7 +335,7 @@ class AppServiceTransaction:
"""Sends this transaction using the provided AS API interface.
Args:
- as_api(ApplicationServiceApi): The API to use to send.
+ as_api: The API to use to send.
Returns:
True if the transaction was sent.
"""
diff --git a/synapse/appservice/api.py b/synapse/appservice/api.py
index e16912814c..01d5c208cc 100644
--- a/synapse/appservice/api.py
+++ b/synapse/appservice/api.py
@@ -206,7 +206,7 @@ class ApplicationServiceApi(SimpleHttpClient):
self,
service: "ApplicationService",
events: List[EventBase],
- ephemeral: Optional[List[JsonDict]] = None,
+ ephemeral: List[JsonDict],
txn_id: Optional[int] = None,
):
if service.url is None:
diff --git a/synapse/appservice/scheduler.py b/synapse/appservice/scheduler.py
index 7aa534d65d..a55bc119cb 100644
--- a/synapse/appservice/scheduler.py
+++ b/synapse/appservice/scheduler.py
@@ -49,7 +49,7 @@ This is all tied together by the AppServiceScheduler which DIs the required
components.
"""
import logging
-from typing import Any, List, Optional
+from typing import List, Optional
from synapse.appservice import ApplicationService, ApplicationServiceState
from synapse.events import EventBase
diff --git a/synapse/storage/databases/main/appservice.py b/synapse/storage/databases/main/appservice.py
index f7241c65b3..62e4692ace 100644
--- a/synapse/storage/databases/main/appservice.py
+++ b/synapse/storage/databases/main/appservice.py
@@ -15,7 +15,7 @@
# limitations under the License.
import logging
import re
-from typing import List, Optional
+from typing import List
from synapse.appservice import ApplicationService, AppServiceTransaction
from synapse.config.appservice import load_appservices
@@ -179,14 +179,16 @@ class ApplicationServiceTransactionWorkerStore(
self,
service: ApplicationService,
events: List[EventBase],
- ephemeral: Optional[JsonDict] = None,
+ ephemeral: List[JsonDict],
) -> AppServiceTransaction:
"""Atomically creates a new transaction for this application service
- with the given list of events.
+ with the given list of events. Ephemeral events are NOT persisted to the
+ database and are not resent if a transaction is retried.
Args:
service: The service who the transaction is for.
- events: A list of events to put in the transaction.
+ events: A list of persistent events to put in the transaction.
+ ephemeral: A list of ephemeral events to put in the transaction.
Returns:
A new transaction.
diff --git a/synapse/storage/databases/main/receipts.py b/synapse/storage/databases/main/receipts.py
index 66862acb7d..dbb4887985 100644
--- a/synapse/storage/databases/main/receipts.py
+++ b/synapse/storage/databases/main/receipts.py
@@ -123,15 +123,6 @@ class ReceiptsWorkerStore(SQLBaseStore, metaclass=abc.ABCMeta):
for row in rows
}
- async def get_linearized_receipts_for_all_rooms(
- self, to_key: int, from_key: Optional[int] = None
- ) -> List[dict]:
- results = await self._get_linearized_receipts_for_all_rooms(
- to_key, from_key=from_key
- )
-
- return results
-
async def get_linearized_receipts_for_rooms(
self, room_ids: List[str], to_key: int, from_key: Optional[int] = None
) -> List[dict]:
@@ -284,7 +275,7 @@ class ReceiptsWorkerStore(SQLBaseStore, metaclass=abc.ABCMeta):
return results
@cached(num_args=2,)
- async def _get_linearized_receipts_for_all_rooms(
+ async def get_linearized_receipts_for_all_rooms(
self, to_key: int, from_key: Optional[int] = None
):
def f(txn):
@@ -305,7 +296,7 @@ class ReceiptsWorkerStore(SQLBaseStore, metaclass=abc.ABCMeta):
return self.db_pool.cursor_to_dict(txn)
txn_results = await self.db_pool.runInteraction(
- "_get_linearized_receipts_for_all_rooms", f
+ "get_linearized_receipts_for_all_rooms", f
)
results = {}
diff --git a/tests/appservice/test_scheduler.py b/tests/appservice/test_scheduler.py
index f0bb5bb304..63840b9b03 100644
--- a/tests/appservice/test_scheduler.py
+++ b/tests/appservice/test_scheduler.py
@@ -203,7 +203,7 @@ class ApplicationServiceSchedulerQueuerTestCase(unittest.TestCase):
service = Mock(id=4)
event = Mock()
self.queuer.enqueue_event(service, event)
- self.txn_ctrl.send.assert_called_once_with(service, [event], None)
+ self.txn_ctrl.send.assert_called_once_with(service, [event], [])
def test_send_single_event_with_queue(self):
d = defer.Deferred()
@@ -219,11 +219,11 @@ class ApplicationServiceSchedulerQueuerTestCase(unittest.TestCase):
# Send more events: expect send() to NOT be called multiple times.
self.queuer.enqueue_event(service, event2)
self.queuer.enqueue_event(service, event3)
- self.txn_ctrl.send.assert_called_with(service, [event], None)
+ self.txn_ctrl.send.assert_called_with(service, [event], [])
self.assertEquals(1, self.txn_ctrl.send.call_count)
# Resolve the send event: expect the queued events to be sent
d.callback(service)
- self.txn_ctrl.send.assert_called_with(service, [event2, event3], None)
+ self.txn_ctrl.send.assert_called_with(service, [event2, event3], [])
self.assertEquals(2, self.txn_ctrl.send.call_count)
def test_multiple_service_queues(self):
@@ -249,15 +249,15 @@ class ApplicationServiceSchedulerQueuerTestCase(unittest.TestCase):
# send events for different ASes and make sure they are sent
self.queuer.enqueue_event(srv1, srv_1_event)
self.queuer.enqueue_event(srv1, srv_1_event2)
- self.txn_ctrl.send.assert_called_with(srv1, [srv_1_event], None)
+ self.txn_ctrl.send.assert_called_with(srv1, [srv_1_event], [])
self.queuer.enqueue_event(srv2, srv_2_event)
self.queuer.enqueue_event(srv2, srv_2_event2)
- self.txn_ctrl.send.assert_called_with(srv2, [srv_2_event], None)
+ self.txn_ctrl.send.assert_called_with(srv2, [srv_2_event], [])
# make sure callbacks for a service only send queued events for THAT
# service
srv_2_defer.callback(srv2)
- self.txn_ctrl.send.assert_called_with(srv2, [srv_2_event2], None)
+ self.txn_ctrl.send.assert_called_with(srv2, [srv_2_event2], [])
self.assertEquals(3, self.txn_ctrl.send.call_count)
def test_send_single_ephemeral_no_queue(self):
@@ -281,19 +281,18 @@ class ApplicationServiceSchedulerQueuerTestCase(unittest.TestCase):
)
service = Mock(id=4)
event_list_1 = [Mock(event_id="event1"), Mock(event_id="event2")]
-
- # Send more events: expect send() to NOT be called multiple times.
event_list_2 = [Mock(event_id="event3"), Mock(event_id="event4")]
event_list_3 = [Mock(event_id="event5"), Mock(event_id="event6")]
# Send an event and don't resolve it just yet.
self.queuer.enqueue_ephemeral(service, event_list_1)
-
+ # Send more events: expect send() to NOT be called multiple times.
self.queuer.enqueue_ephemeral(service, event_list_2)
self.queuer.enqueue_ephemeral(service, event_list_3)
self.txn_ctrl.send.assert_called_with(service, [], event_list_1)
self.assertEquals(1, self.txn_ctrl.send.call_count)
- # Resolve the send event: expect the queued events to be sent
+ # Resolve txn_ctrl.send
d.callback(service)
+ # Expect the queued events to be sent
self.txn_ctrl.send.assert_called_with(service, [], event_list_2 + event_list_3)
self.assertEquals(2, self.txn_ctrl.send.call_count)
|