You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ChannelState.kt 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package com.dmdirc.ktirc.model
  2. import com.dmdirc.ktirc.io.CaseMapping
  3. import java.time.LocalDateTime
  4. /**
  5. * Describes the state of a channel that the client has joined.
  6. */
  7. class ChannelState(val name: String, caseMappingProvider: () -> CaseMapping) {
  8. /**
  9. * Whether or not we are in the process of receiving a user list (which may span many messages).
  10. */
  11. var receivingUserList = false
  12. internal set
  13. /**
  14. * Whether or not we have discovered the full set of modes for the channel.
  15. */
  16. var modesDiscovered = false
  17. internal set
  18. /**
  19. * Whether or not we have discovered or seen a channel topic. Subsequent discoveries are ignored.
  20. */
  21. internal var topicDiscovered = false
  22. /**
  23. * The current channel topic.
  24. */
  25. var topic = ChannelTopic()
  26. internal set
  27. /**
  28. * A map of all users in the channel to their current modes.
  29. */
  30. val users = ChannelUserMap(caseMappingProvider)
  31. /**
  32. * A map of modes set on the channel, and their values (if any).
  33. *
  34. * If [modesDiscovered] is false, this map may be missing modes that the server hasn't told us about.
  35. */
  36. var modes = HashMap<Char, String>()
  37. internal fun reset() {
  38. receivingUserList = false
  39. modesDiscovered = false
  40. topic = ChannelTopic()
  41. topicDiscovered = false
  42. users.clear()
  43. modes.clear()
  44. }
  45. }
  46. /**
  47. * Describes a channel topic, and when and by whom it was set.
  48. *
  49. * [topic] may be null if there is no topic set.
  50. *
  51. * [user] and [time] may not be known if the topic was set before we joined the channel, depending on when it
  52. * is checked and the exact behaviour of the IRC server.
  53. *
  54. * If the topic is cleared while we are present, then [topic] will be `null` but the [user] and [time] that it
  55. * was cleared will still be recorded.
  56. */
  57. data class ChannelTopic(val topic: String? = null, val user: User? = null, val time: LocalDateTime? = null)
  58. /**
  59. * Describes a user in a channel, and their modes.
  60. */
  61. data class ChannelUser(var nickname: String, var modes: String = "")
  62. /**
  63. * The types of supported channel modes, and what parameters they require.
  64. *
  65. * These must be sorted according to the order they are sent in the CHANMODES server feature.
  66. */
  67. enum class ChannelModeType {
  68. /** The mode adds or removes an entry for a list. It must have a param to add or remove. */
  69. List,
  70. /** The mode has a parameter that must be present to set it or unset it. */
  71. SetUnsetParameter,
  72. /** The mode has a parameter that must be present to set it, but is unset without one. */
  73. SetParameter,
  74. /** The mode does not take parameters in any case. */
  75. NoParameter;
  76. /**
  77. * Whether this mode requires a parameter to be set or not.
  78. */
  79. val needsParameterToSet: Boolean
  80. get() = this != NoParameter
  81. /**
  82. * Whether this mode requires a parameter to be unset or not.
  83. */
  84. val needsParameterToUnset: Boolean
  85. get() = this != NoParameter && this != SetParameter
  86. }