25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

62 satır
2.1 KiB

  1. # Copyright 2018 New Vector 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. from typing import TYPE_CHECKING, Iterable, Union
  15. from synapse.server_notices.consent_server_notices import ConsentServerNotices
  16. from synapse.server_notices.resource_limits_server_notices import (
  17. ResourceLimitsServerNotices,
  18. )
  19. from synapse.server_notices.worker_server_notices_sender import (
  20. WorkerServerNoticesSender,
  21. )
  22. if TYPE_CHECKING:
  23. from synapse.server import HomeServer
  24. class ServerNoticesSender(WorkerServerNoticesSender):
  25. """A centralised place which sends server notices automatically when
  26. Certain Events take place
  27. """
  28. def __init__(self, hs: "HomeServer"):
  29. super().__init__(hs)
  30. self._server_notices: Iterable[
  31. Union[ConsentServerNotices, ResourceLimitsServerNotices]
  32. ] = (
  33. ConsentServerNotices(hs),
  34. ResourceLimitsServerNotices(hs),
  35. )
  36. async def on_user_syncing(self, user_id: str) -> None:
  37. """Called when the user performs a sync operation.
  38. Args:
  39. user_id: mxid of user who synced
  40. """
  41. for sn in self._server_notices:
  42. await sn.maybe_send_server_notice_to_user(user_id)
  43. async def on_user_ip(self, user_id: str) -> None:
  44. """Called on the master when a worker process saw a client request.
  45. Args:
  46. user_id: mxid
  47. """
  48. # The synchrotrons use a stubbed version of ServerNoticesSender, so
  49. # we check for notices to send to the user in on_user_ip as well as
  50. # in on_user_syncing
  51. for sn in self._server_notices:
  52. await sn.maybe_send_server_notice_to_user(user_id)