action_generator.py 1.6 KB

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