action_generator.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright 2015 OpenMarket Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import logging
  15. from typing import TYPE_CHECKING
  16. from synapse.events import EventBase
  17. from synapse.events.snapshot import EventContext
  18. from synapse.push.bulk_push_rule_evaluator import BulkPushRuleEvaluator
  19. from synapse.util.metrics import Measure
  20. if TYPE_CHECKING:
  21. from synapse.server import HomeServer
  22. logger = logging.getLogger(__name__)
  23. class ActionGenerator:
  24. def __init__(self, hs: "HomeServer"):
  25. self.clock = hs.get_clock()
  26. self.bulk_evaluator = BulkPushRuleEvaluator(hs)
  27. # really we want to get all user ids and all profile tags too,
  28. # since we want the actions for each profile tag for every user and
  29. # also actions for a client with no profile tag for each user.
  30. # Currently the event stream doesn't support profile tags on an
  31. # event stream, so we just run the rules for a client with no profile
  32. # tag (ie. we just need all the users).
  33. async def handle_push_actions_for_event(
  34. self, event: EventBase, context: EventContext
  35. ) -> None:
  36. with Measure(self.clock, "action_for_event_by_user"):
  37. await self.bulk_evaluator.action_for_event_by_user(event, context)