Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

CapabilitiesState.kt 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package com.dmdirc.ktirc.model
  2. /**
  3. * Describes the state of capability negotiation with the server.
  4. */
  5. class CapabilitiesState {
  6. /** The current negotiation state. */
  7. var negotiationState: CapabilitiesNegotiationState = CapabilitiesNegotiationState.AWAITING_LIST
  8. internal set
  9. // TODO: These should only be mutable internally
  10. /** The capabilities that were advertised by the server. */
  11. val advertisedCapabilities = HashMap<Capability, String>()
  12. /** The capabilities that we have agreed to enable. */
  13. val enabledCapabilities = HashMap<Capability, String>()
  14. }
  15. /**
  16. * The state of negotiations with the server.
  17. */
  18. enum class CapabilitiesNegotiationState {
  19. /**
  20. * We have requested a list of capabilities and are awaiting a reply.
  21. */
  22. AWAITING_LIST,
  23. /**
  24. * We have sent a list of capabilities to enable, and are awaiting an acknowledgement.
  25. */
  26. AWAITING_ACK,
  27. /**
  28. * Negotiation has completed.
  29. */
  30. FINISHED
  31. }
  32. /**
  33. * IRCv3 capabilities supported by the client.
  34. */
  35. @Suppress("unused")
  36. sealed class Capability(val name: String) {
  37. // Capabilities that enable more information in message tags:
  38. /** Messages are tagged with the server time they originated at. */
  39. object ServerTimeMessageTag : Capability("server-time")
  40. /** Messages are tagged with the sender's account name. */
  41. object UserAccountMessageTag : Capability("account-tag")
  42. // Capabilities that extend existing commands to supply extra information:
  43. /** Hosts are included for users in NAMES messages. */
  44. object HostsInNamesReply : Capability("userhost-in-names")
  45. /** Multiple mode prefixes are returned per-user in NAMES messages. */
  46. object MultipleUserModePrefixes : Capability("multi-prefix")
  47. /** The user's account and real name are provided when they join a channel. */
  48. object AccountAndRealNameInJoinMessages : Capability("extended-join")
  49. // Capabilities that affect how messages are sent/received:
  50. /** Messages sent by the client are echo'd back on successful delivery. */
  51. object EchoMessages : Capability("echo-message")
  52. // Capabilities that notify us of changes to other clients:
  53. /** Receive a notification when a user's account changes. */
  54. object AccountChangeMessages : Capability("account-notify") // TODO: Add processor
  55. /** Receive a notification when a user's away state changes. */
  56. object AwayStateMessages : Capability("away-notify") // TODO: Add processor
  57. /** Receive a notification when a user's host changes, instead of a quit/join. */
  58. object HostChangeMessages : Capability("chghost") // TODO: Add processor
  59. }
  60. internal val capabilities: Map<String, Capability> by lazy {
  61. Capability::class.nestedClasses.map { it.objectInstance as Capability }.associateBy { it.name }
  62. }