Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

98 linhas
3.0 KiB

  1. # Copyright 2014-2016 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. from typing import Any, Optional
  15. import attr
  16. from synapse.api.constants import PresenceState
  17. from synapse.types import JsonDict
  18. @attr.s(slots=True, auto_attribs=True)
  19. class UserDevicePresenceState:
  20. """
  21. Represents the current presence state of a user's device.
  22. user_id: The user ID.
  23. device_id: The user's device ID.
  24. state: The presence state, see PresenceState.
  25. last_active_ts: Time in msec that the device last interacted with server.
  26. last_sync_ts: Time in msec that the device last *completed* a sync
  27. (or event stream).
  28. """
  29. user_id: str
  30. device_id: Optional[str]
  31. state: str
  32. last_active_ts: int
  33. last_sync_ts: int
  34. @classmethod
  35. def default(
  36. cls, user_id: str, device_id: Optional[str]
  37. ) -> "UserDevicePresenceState":
  38. """Returns a default presence state."""
  39. return cls(
  40. user_id=user_id,
  41. device_id=device_id,
  42. state=PresenceState.OFFLINE,
  43. last_active_ts=0,
  44. last_sync_ts=0,
  45. )
  46. @attr.s(slots=True, frozen=True, auto_attribs=True)
  47. class UserPresenceState:
  48. """Represents the current presence state of the user.
  49. user_id: The user ID.
  50. state: The presence state, see PresenceState.
  51. last_active_ts: Time in msec that the user last interacted with server.
  52. last_federation_update_ts: Time in msec since either a) we sent a presence
  53. update to other servers or b) we received a presence update, depending
  54. on if is a local user or not.
  55. last_user_sync_ts: Time in msec that the user last *completed* a sync
  56. (or event stream).
  57. status_msg: User set status message.
  58. currently_active: True if the user is currently syncing.
  59. """
  60. user_id: str
  61. state: str
  62. last_active_ts: int
  63. last_federation_update_ts: int
  64. last_user_sync_ts: int
  65. status_msg: Optional[str]
  66. currently_active: bool
  67. def as_dict(self) -> JsonDict:
  68. return attr.asdict(self)
  69. def copy_and_replace(self, **kwargs: Any) -> "UserPresenceState":
  70. return attr.evolve(self, **kwargs)
  71. @classmethod
  72. def default(cls, user_id: str) -> "UserPresenceState":
  73. """Returns a default presence state."""
  74. return cls(
  75. user_id=user_id,
  76. state=PresenceState.OFFLINE,
  77. last_active_ts=0,
  78. last_federation_update_ts=0,
  79. last_user_sync_ts=0,
  80. status_msg=None,
  81. currently_active=False,
  82. )