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 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package com.dmdirc.ktirc.model
  2. import com.dmdirc.ktirc.io.CaseMapping
  3. /**
  4. * Describes the state of a channel that the client has joined.
  5. */
  6. class ChannelState(val name: String, caseMappingProvider: () -> CaseMapping) {
  7. /**
  8. * Whether or not we are in the process of receiving a user list (which may span many messages).
  9. */
  10. var receivingUserList = false
  11. internal set
  12. /**
  13. * Whether or not we have discovered the full set of modes for the channel.
  14. */
  15. var modesDiscovered = false
  16. internal set
  17. /**
  18. * A map of all users in the channel to their current modes.
  19. */
  20. val users = ChannelUserMap(caseMappingProvider)
  21. /**
  22. * A map of modes set on the channel, and their values (if any).
  23. *
  24. * If [modesDiscovered] is false, this map may be missing modes that the server hasn't told us about.
  25. */
  26. var modes = HashMap<Char, String>()
  27. internal fun reset() {
  28. receivingUserList = false
  29. modesDiscovered = false
  30. users.clear()
  31. modes.clear()
  32. }
  33. }
  34. /**
  35. * Describes a user in a channel, and their modes.
  36. */
  37. data class ChannelUser(var nickname: String, var modes: String = "")
  38. /**
  39. * The types of supported channel modes, and what parameters they require.
  40. *
  41. * These must be sorted according to the order they are sent in the CHANMODES server feature.
  42. */
  43. enum class ChannelModeType {
  44. /** The mode adds or removes an entry for a list. It must have a param to add or remove. */
  45. List,
  46. /** The mode has a parameter that must be present to set it or unset it. */
  47. SetUnsetParameter,
  48. /** The mode has a parameter that must be present to set it, but is unset without one. */
  49. SetParameter,
  50. /** The mode does not take parameters in any case. */
  51. NoParameter;
  52. /**
  53. * Whether this mode requires a parameter to be set or not.
  54. */
  55. val needsParameterToSet: Boolean
  56. get() = this != NoParameter
  57. /**
  58. * Whether this mode requires a parameter to be unset or not.
  59. */
  60. val needsParameterToUnset: Boolean
  61. get() = this != NoParameter && this != SetParameter
  62. }