Replicate push actions

This commit is contained in:
Mark Haines 2016-04-21 15:25:47 +01:00
parent 68ebb81e86
commit c0d8e0eb63
2 changed files with 57 additions and 0 deletions

View File

@ -21,6 +21,7 @@ from synapse.storage import DataStore
from synapse.storage.room import RoomStore from synapse.storage.room import RoomStore
from synapse.storage.roommember import RoomMemberStore from synapse.storage.roommember import RoomMemberStore
from synapse.storage.event_federation import EventFederationStore from synapse.storage.event_federation import EventFederationStore
from synapse.storage.event_push_actions import EventPushActionsStore
from synapse.storage.state import StateStore from synapse.storage.state import StateStore
from synapse.util.caches.stream_change_cache import StreamChangeCache from synapse.util.caches.stream_change_cache import StreamChangeCache
@ -71,7 +72,16 @@ class SlavedEventStore(BaseSlavedStore):
get_invited_rooms_for_user = RoomMemberStore.__dict__[ get_invited_rooms_for_user = RoomMemberStore.__dict__[
"get_invited_rooms_for_user" "get_invited_rooms_for_user"
] ]
get_unread_event_push_actions_by_room_for_user = (
EventPushActionsStore.__dict__["get_unread_event_push_actions_by_room_for_user"]
)
get_unread_push_actions_for_user_in_range = (
DataStore.get_unread_push_actions_for_user_in_range.__func__
)
get_push_action_users_in_range = (
DataStore.get_push_action_users_in_range.__func__
)
get_event = DataStore.get_event.__func__ get_event = DataStore.get_event.__func__
get_current_state = DataStore.get_current_state.__func__ get_current_state = DataStore.get_current_state.__func__
get_current_state_for_key = DataStore.get_current_state_for_key.__func__ get_current_state_for_key = DataStore.get_current_state_for_key.__func__
@ -167,6 +177,10 @@ class SlavedEventStore(BaseSlavedStore):
self.get_latest_event_ids_in_room.invalidate((event.room_id,)) self.get_latest_event_ids_in_room.invalidate((event.room_id,))
self.get_unread_event_push_actions_by_room_for_user.invalidate_many(
(event.room_id,)
)
if not backfilled: if not backfilled:
self._events_stream_cache.entity_has_changed( self._events_stream_cache.entity_has_changed(
event.room_id, event.internal_metadata.stream_ordering event.room_id, event.internal_metadata.stream_ordering

View File

@ -266,6 +266,47 @@ class SlavedEventStoreTestCase(BaseSlavedStoreTestCase):
event.internal_metadata.stream_ordering event.internal_metadata.stream_ordering
)]) )])
@defer.inlineCallbacks
def test_push_actions_for_user(self):
yield self.persist(type="m.room.create", creator=USER_ID)
yield self.persist(type="m.room.join", key=USER_ID, membership="join")
yield self.persist(
type="m.room.join", sender=USER_ID, key=USER_ID_2, membership="join"
)
event1 = yield self.persist(
type="m.room.message", msgtype="m.text", body="hello"
)
yield self.replicate()
yield self.check(
"get_unread_event_push_actions_by_room_for_user",
[ROOM_ID, USER_ID_2, event1.event_id],
{"highlight_count": 0, "notify_count": 0}
)
yield self.persist(
type="m.room.message", msgtype="m.text", body="world",
push_actions=[(USER_ID_2, ["notify"])],
)
yield self.replicate()
yield self.check(
"get_unread_event_push_actions_by_room_for_user",
[ROOM_ID, USER_ID_2, event1.event_id],
{"highlight_count": 0, "notify_count": 1}
)
yield self.persist(
type="m.room.message", msgtype="m.text", body="world",
push_actions=[(USER_ID_2, [
"notify", {"set_tweak": "highlight", "value": True}
])],
)
yield self.replicate()
yield self.check(
"get_unread_event_push_actions_by_room_for_user",
[ROOM_ID, USER_ID_2, event1.event_id],
{"highlight_count": 1, "notify_count": 2}
)
event_id = 0 event_id = 0
@defer.inlineCallbacks @defer.inlineCallbacks
@ -273,6 +314,7 @@ class SlavedEventStoreTestCase(BaseSlavedStoreTestCase):
self, sender=USER_ID, room_id=ROOM_ID, type={}, key=None, internal={}, self, sender=USER_ID, room_id=ROOM_ID, type={}, key=None, internal={},
state=None, reset_state=False, backfill=False, state=None, reset_state=False, backfill=False,
depth=None, prev_events=[], auth_events=[], prev_state=[], redacts=None, depth=None, prev_events=[], auth_events=[], prev_state=[], redacts=None,
push_actions=[],
**content **content
): ):
""" """
@ -305,6 +347,7 @@ class SlavedEventStoreTestCase(BaseSlavedStoreTestCase):
self.event_id += 1 self.event_id += 1
context = EventContext(current_state=state) context = EventContext(current_state=state)
context.push_actions = push_actions
ordering = None ordering = None
if backfill: if backfill: