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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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.events.eventbus.EventBus;
  25. import com.dmdirc.parser.common.ChannelListModeItem;
  26. import java.util.Collection;
  27. import java.util.List;
  28. import java.util.Optional;
  29. import javax.annotation.Nullable;
  30. /**
  31. * A chat containing multiple participants.
  32. */
  33. public interface GroupChat extends Chat {
  34. /**
  35. * Enumeration of reasons for us leaving a group chat.
  36. */
  37. enum PartReason {
  38. /** We disconnected from the server. */
  39. DISCONNECTED,
  40. /** We issued a part request ourselves. */
  41. LOCAL_PART,
  42. /** A part for our user came from the server. */
  43. REMOTE_PART
  44. }
  45. /**
  46. * Returns the current topic for this channel.
  47. *
  48. * @return Current channel topic
  49. */
  50. Optional<Topic> getCurrentTopic();
  51. /**
  52. * Gets an event bus which will only contain events generated in relation to this channel.
  53. *
  54. * @return An event bus scoped to this channel.
  55. */
  56. EventBus getEventBus();
  57. /**
  58. * Retrieves the maximum length that a topic on this channel can be.
  59. *
  60. * @return The maximum length that this channel's topic may be
  61. */
  62. int getMaxTopicLength();
  63. /**
  64. * Refreshes the list of clients stored by this channel. Should be called when (visible) user
  65. * modes or nicknames change.
  66. */
  67. // TODO: Should probably not need this.
  68. void refreshClients();
  69. /**
  70. * Retrieve the topics that have been seen on this channel.
  71. *
  72. * @return A list of topics that have been seen on this channel, including the current one.
  73. */
  74. List<Topic> getTopics();
  75. /**
  76. * Determines if we are currently joined to the chat.
  77. *
  78. * @return True if joined, false otherwise.
  79. */
  80. boolean isOnChannel();
  81. /**
  82. * Returns the reason behind our last parting from this group chat. For example, if the
  83. * user manually left a chat and then subsequently disconnected from the server, the part
  84. * reason will be {@link PartReason#LOCAL_PART}.
  85. *
  86. * @return The reason for parting the chat. {@code null} if the chat has never been left.
  87. */
  88. PartReason getPartReason();
  89. /**
  90. * Joins the specified channel. This only makes sense if used after a call to part().
  91. */
  92. void join();
  93. /**
  94. * Parts this channel with the specified message. Parting does NOT close the channel window.
  95. *
  96. * @param reason The reason for parting the channel
  97. */
  98. void part(String reason);
  99. /**
  100. * Requests all available list modes for this channel.
  101. */
  102. void retrieveListModes();
  103. /**
  104. * Attempts to set the topic of this channel.
  105. *
  106. * @param topic The new topic to be used. An empty string will clear the current topic
  107. */
  108. void setTopic(String topic);
  109. /**
  110. * Gets the name of the chat.
  111. *
  112. * @return The current name of the group chat.
  113. */
  114. String getName();
  115. /**
  116. * Tries to retrieve a {@link GroupChatUser} from the current {@link GroupChat} for the
  117. * specified {@link User}.
  118. *
  119. * @param user User to find
  120. *
  121. * @return User on channel, or empty if the user is not on the channel
  122. */
  123. Optional<GroupChatUser> getUser(User user);
  124. /**
  125. * Returns the users available on this GroupChat.
  126. *
  127. * @return Users in the GroupChat
  128. */
  129. Collection<GroupChatUser> getUsers();
  130. /**
  131. * Kicks the specified user, optionally with the specified message.
  132. *
  133. * @param user User to kick
  134. * @param reason Reason for the kick
  135. */
  136. void kick(GroupChatUser user, Optional<String> reason);
  137. /**
  138. * Gets the items in the specified list mode category.
  139. *
  140. * @param mode The list mode to retrieve items for.
  141. * @return The known mode entries.
  142. */
  143. // TODO: Return a parser-neutral type
  144. // TODO: Don't assume mode types are always chars, use an abstraction
  145. Collection<ChannelListModeItem> getListModeItems(char mode);
  146. /**
  147. * Sets a mode on the group chat.
  148. *
  149. * @param mode The mode to set.
  150. * @param value The value of the mode, if any.
  151. */
  152. void setMode(char mode, @Nullable String value);
  153. /**
  154. * Unsets a mode on the group chat.
  155. *
  156. * @param mode The mode to unset.
  157. * @param value The value of the mode, if any.
  158. */
  159. void removeMode(char mode, String value);
  160. /**
  161. * Flushes all pending mode changes.
  162. */
  163. // TODO: Add a builder-type interface for batch mode changes, instead of add+flush.
  164. void flushModes();
  165. /**
  166. * Gets boolean modes for this chat.
  167. *
  168. * @return The current boolean (toggleable) modes.
  169. */
  170. // TODO: Don't use a String here, return a collection of some abstraction.
  171. String getModes();
  172. /**
  173. * Gets the value of the given mode for this chat.
  174. *
  175. * @param mode The mode to retrieve.
  176. * @return The current value of the mode.
  177. */
  178. String getModeValue(final char mode);
  179. /**
  180. * Requests information about all the {@link User}s in this GroupChat.
  181. */
  182. void requestUsersInfo();
  183. }