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.

GroupChat.java 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * Copyright (c) 2006-2015 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.interfaces;
  23. import com.dmdirc.Topic;
  24. import com.dmdirc.parser.common.ChannelListModeItem;
  25. import java.util.Collection;
  26. import java.util.List;
  27. import java.util.Optional;
  28. import javax.annotation.Nullable;
  29. /**
  30. * A chat containing multiple participants.
  31. */
  32. public interface GroupChat extends Chat {
  33. /**
  34. * Enumeration of reasons for us leaving a group chat.
  35. */
  36. enum PartReason {
  37. /** We disconnected from the server. */
  38. DISCONNECTED,
  39. /** We issued a part request ourselves. */
  40. LOCAL_PART,
  41. /** A part for our user came from the server. */
  42. REMOTE_PART
  43. }
  44. /**
  45. * Returns the current topic for this channel.
  46. *
  47. * @return Current channel topic
  48. */
  49. Optional<Topic> getCurrentTopic();
  50. /**
  51. * Gets an event bus which will only contain events generated in relation to this channel.
  52. *
  53. * @return An event bus scoped to this channel.
  54. */
  55. EventBus getEventBus();
  56. /**
  57. * Retrieves the maximum length that a topic on this channel can be.
  58. *
  59. * @return The maximum length that this channel's topic may be
  60. */
  61. int getMaxTopicLength();
  62. /**
  63. * Refreshes the list of clients stored by this channel. Should be called when (visible) user
  64. * modes or nicknames change.
  65. */
  66. // TODO: Should probably not need this.
  67. void refreshClients();
  68. /**
  69. * Retrieve the topics that have been seen on this channel.
  70. *
  71. * @return A list of topics that have been seen on this channel, including the current one.
  72. */
  73. List<Topic> getTopics();
  74. /**
  75. * Determines if we are currently joined to the chat.
  76. *
  77. * @return True if joined, false otherwise.
  78. */
  79. boolean isOnChannel();
  80. /**
  81. * Returns the reason behind our last parting from this group chat. For example, if the
  82. * user manually left a chat and then subsequently disconnected from the server, the part
  83. * reason will be {@link PartReason#LOCAL_PART}.
  84. *
  85. * @return The reason for parting the chat. {@code null} if the chat has never been left.
  86. */
  87. PartReason getPartReason();
  88. /**
  89. * Joins the specified channel. This only makes sense if used after a call to part().
  90. */
  91. void join();
  92. /**
  93. * Parts this channel with the specified message. Parting does NOT close the channel window.
  94. *
  95. * @param reason The reason for parting the channel
  96. */
  97. void part(String reason);
  98. /**
  99. * Requests all available list modes for this channel.
  100. */
  101. void retrieveListModes();
  102. /**
  103. * Attempts to set the topic of this channel.
  104. *
  105. * @param topic The new topic to be used. An empty string will clear the current topic
  106. */
  107. void setTopic(String topic);
  108. /**
  109. * Gets the name of the chat.
  110. *
  111. * @return The current name of the group chat.
  112. */
  113. String getName();
  114. /**
  115. * Tries to retrieve a {@link GroupChatUser} from the current {@link GroupChat} for the
  116. * specified {@link User}.
  117. *
  118. * @param user User to find
  119. *
  120. * @return User on channel, or empty if the user is not on the channel
  121. */
  122. Optional<GroupChatUser> getUser(User user);
  123. /**
  124. * Returns the users available on this GroupChat.
  125. *
  126. * @return Users in the GroupChat
  127. */
  128. Collection<GroupChatUser> getUsers();
  129. /**
  130. * Kicks the specified user, optionally with the specified message.
  131. *
  132. * @param user User to kick
  133. * @param reason Reason for the kick
  134. */
  135. void kick(GroupChatUser user, Optional<String> reason);
  136. /**
  137. * Gets the items in the specified list mode category.
  138. *
  139. * @param mode The list mode to retrieve items for.
  140. * @return The known mode entries.
  141. */
  142. // TODO: Return a parser-neutral type
  143. // TODO: Don't assume mode types are always chars, use an abstraction
  144. Collection<ChannelListModeItem> getListModeItems(char mode);
  145. /**
  146. * Sets a mode on the group chat.
  147. *
  148. * @param mode The mode to set.
  149. * @param value The value of the mode, if any.
  150. */
  151. void setMode(char mode, @Nullable String value);
  152. /**
  153. * Unsets a mode on the group chat.
  154. *
  155. * @param mode The mode to unset.
  156. * @param value The value of the mode, if any.
  157. */
  158. void removeMode(char mode, String value);
  159. /**
  160. * Flushes all pending mode changes.
  161. */
  162. // TODO: Add a builder-type interface for batch mode changes, instead of add+flush.
  163. void flushModes();
  164. /**
  165. * Gets boolean modes for this chat.
  166. *
  167. * @return The current boolean (toggleable) modes.
  168. */
  169. // TODO: Don't use a String here, return a collection of some abstraction.
  170. String getModes();
  171. /**
  172. * Gets the value of the given mode for this chat.
  173. *
  174. * @param mode The mode to retrieve.
  175. * @return The current value of the mode.
  176. */
  177. String getModeValue(final char mode);
  178. /**
  179. * Requests information about all the {@link User}s in this GroupChat.
  180. */
  181. void requestUsersInfo();
  182. }