push.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2015, 2016 OpenMarket Ltd
  3. # Copyright 2017 New Vector Ltd
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. from ._base import Config
  17. class PushConfig(Config):
  18. section = "push"
  19. def read_config(self, config, **kwargs):
  20. push_config = config.get("push") or {}
  21. self.push_include_content = push_config.get("include_content", True)
  22. self.push_group_unread_count_by_room = push_config.get(
  23. "group_unread_count_by_room", True
  24. )
  25. # There was a a 'redact_content' setting but mistakenly read from the
  26. # 'email'section'. Check for the flag in the 'push' section, and log,
  27. # but do not honour it to avoid nasty surprises when people upgrade.
  28. if push_config.get("redact_content") is not None:
  29. print(
  30. "The push.redact_content content option has never worked. "
  31. "Please set push.include_content if you want this behaviour"
  32. )
  33. # Now check for the one in the 'email' section and honour it,
  34. # with a warning.
  35. push_config = config.get("email") or {}
  36. redact_content = push_config.get("redact_content")
  37. if redact_content is not None:
  38. print(
  39. "The 'email.redact_content' option is deprecated: "
  40. "please set push.include_content instead"
  41. )
  42. self.push_include_content = not redact_content
  43. def generate_config_section(self, config_dir_path, server_name, **kwargs):
  44. return """
  45. ## Push ##
  46. push:
  47. # Clients requesting push notifications can either have the body of
  48. # the message sent in the notification poke along with other details
  49. # like the sender, or just the event ID and room ID (`event_id_only`).
  50. # If clients choose the former, this option controls whether the
  51. # notification request includes the content of the event (other details
  52. # like the sender are still included). For `event_id_only` push, it
  53. # has no effect.
  54. #
  55. # For modern android devices the notification content will still appear
  56. # because it is loaded by the app. iPhone, however will send a
  57. # notification saying only that a message arrived and who it came from.
  58. #
  59. # The default value is "true" to include message details. Uncomment to only
  60. # include the event ID and room ID in push notification payloads.
  61. #
  62. #include_content: false
  63. # When a push notification is received, an unread count is also sent.
  64. # This number can either be calculated as the number of unread messages
  65. # for the user, or the number of *rooms* the user has unread messages in.
  66. #
  67. # The default value is "true", meaning push clients will see the number of
  68. # rooms with unread messages in them. Uncomment to instead send the number
  69. # of unread messages.
  70. #
  71. #group_unread_count_by_room: false
  72. """