/app/src/main/java/org/jivesoftware/smackx/muc/RoomInfo.java

https://bitbucket.org/ustyugov/jtalk · Java · 192 lines · 66 code · 16 blank · 110 comment · 4 complexity · c33f340e3ba05ec00303e1bbcafebeb5 MD5 · raw file

  1. /**
  2. * $RCSfile$
  3. * $Revision$
  4. * $Date$
  5. *
  6. * Copyright 2003-2007 Jive Software.
  7. *
  8. * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. package org.jivesoftware.smackx.muc;
  21. import org.jivesoftware.smackx.Form;
  22. import org.jivesoftware.smackx.packet.DiscoverInfo;
  23. import java.util.Iterator;
  24. /**
  25. * Represents the room information that was discovered using Service Discovery. It's possible to
  26. * obtain information about a room before joining the room but only for rooms that are public (i.e.
  27. * rooms that may be discovered).
  28. *
  29. * @author Gaston Dombiak
  30. */
  31. public class RoomInfo {
  32. /**
  33. * JID of the room. The node of the JID is commonly used as the ID of the room or name.
  34. */
  35. private String room;
  36. /**
  37. * Description of the room.
  38. */
  39. private String description = "";
  40. /**
  41. * Last known subject of the room.
  42. */
  43. private String subject = "";
  44. /**
  45. * Current number of occupants in the room.
  46. */
  47. private int occupantsCount = -1;
  48. /**
  49. * A room is considered members-only if an invitation is required in order to enter the room.
  50. * Any user that is not a member of the room won't be able to join the room unless the user
  51. * decides to register with the room (thus becoming a member).
  52. */
  53. private boolean membersOnly;
  54. /**
  55. * Moderated rooms enable only participants to speak. Users that join the room and aren't
  56. * participants can't speak (they are just visitors).
  57. */
  58. private boolean moderated;
  59. /**
  60. * Every presence packet can include the JID of every occupant unless the owner deactives this
  61. * configuration.
  62. */
  63. private boolean nonanonymous;
  64. /**
  65. * Indicates if users must supply a password to join the room.
  66. */
  67. private boolean passwordProtected;
  68. /**
  69. * Persistent rooms are saved to the database to make sure that rooms configurations can be
  70. * restored in case the server goes down.
  71. */
  72. private boolean persistent;
  73. RoomInfo(DiscoverInfo info) {
  74. super();
  75. this.room = info.getFrom();
  76. // Get the information based on the discovered features
  77. this.membersOnly = info.containsFeature("muc_membersonly");
  78. this.moderated = info.containsFeature("muc_moderated");
  79. this.nonanonymous = info.containsFeature("muc_nonanonymous");
  80. this.passwordProtected = info.containsFeature("muc_passwordprotected");
  81. this.persistent = info.containsFeature("muc_persistent");
  82. // Get the information based on the discovered extended information
  83. Form form = Form.getFormFrom(info);
  84. if (form != null) {
  85. this.description =
  86. form.getField("muc#roominfo_description").getValues().next();
  87. Iterator<String> values = form.getField("muc#roominfo_subject").getValues();
  88. if (values.hasNext()) {
  89. this.subject = values.next();
  90. }
  91. else {
  92. this.subject = "";
  93. }
  94. this.occupantsCount =
  95. Integer.parseInt(form.getField("muc#roominfo_occupants").getValues()
  96. .next());
  97. }
  98. }
  99. /**
  100. * Returns the JID of the room whose information was discovered.
  101. *
  102. * @return the JID of the room whose information was discovered.
  103. */
  104. public String getRoom() {
  105. return room;
  106. }
  107. /**
  108. * Returns the discovered description of the room.
  109. *
  110. * @return the discovered description of the room.
  111. */
  112. public String getDescription() {
  113. return description;
  114. }
  115. /**
  116. * Returns the discovered subject of the room. The subject may be empty if the room does not
  117. * have a subject.
  118. *
  119. * @return the discovered subject of the room.
  120. */
  121. public String getSubject() {
  122. return subject;
  123. }
  124. /**
  125. * Returns the discovered number of occupants that are currently in the room. If this
  126. * information was not discovered (i.e. the server didn't send it) then a value of -1 will be
  127. * returned.
  128. *
  129. * @return the number of occupants that are currently in the room or -1 if that information was
  130. * not provided by the server.
  131. */
  132. public int getOccupantsCount() {
  133. return occupantsCount;
  134. }
  135. /**
  136. * Returns true if the room has restricted the access so that only members may enter the room.
  137. *
  138. * @return true if the room has restricted the access so that only members may enter the room.
  139. */
  140. public boolean isMembersOnly() {
  141. return membersOnly;
  142. }
  143. /**
  144. * Returns true if the room enabled only participants to speak. Occupants with a role of
  145. * visitor won't be able to speak in the room.
  146. *
  147. * @return true if the room enabled only participants to speak.
  148. */
  149. public boolean isModerated() {
  150. return moderated;
  151. }
  152. /**
  153. * Returns true if presence packets will include the JID of every occupant.
  154. *
  155. * @return true if presence packets will include the JID of every occupant.
  156. */
  157. public boolean isNonanonymous() {
  158. return nonanonymous;
  159. }
  160. /**
  161. * Returns true if users musy provide a valid password in order to join the room.
  162. *
  163. * @return true if users musy provide a valid password in order to join the room.
  164. */
  165. public boolean isPasswordProtected() {
  166. return passwordProtected;
  167. }
  168. /**
  169. * Returns true if the room will persist after the last occupant have left the room.
  170. *
  171. * @return true if the room will persist after the last occupant have left the room.
  172. */
  173. public boolean isPersistent() {
  174. return persistent;
  175. }
  176. }