action_generator.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 twisted.internet import defer
  17. from synapse.util.metrics import Measure
  18. from .bulk_push_rule_evaluator import BulkPushRuleEvaluator
  19. logger = logging.getLogger(__name__)
  20. class ActionGenerator(object):
  21. def __init__(self, hs):
  22. self.hs = hs
  23. self.clock = hs.get_clock()
  24. self.store = hs.get_datastore()
  25. self.bulk_evaluator = BulkPushRuleEvaluator(hs)
  26. # really we want to get all user ids and all profile tags too,
  27. # since we want the actions for each profile tag for every user and
  28. # also actions for a client with no profile tag for each user.
  29. # Currently the event stream doesn't support profile tags on an
  30. # event stream, so we just run the rules for a client with no profile
  31. # tag (ie. we just need all the users).
  32. @defer.inlineCallbacks
  33. def handle_push_actions_for_event(self, event, context):
  34. with Measure(self.clock, "action_for_event_by_user"):
  35. yield self.bulk_evaluator.action_for_event_by_user(event, context)