Package rocks.xmpp.extensions.muc
Class ChatRoom
- java.lang.Object
-
- rocks.xmpp.im.chat.Chat
-
- rocks.xmpp.extensions.muc.ChatRoom
-
- All Implemented Interfaces:
Comparable<ChatRoom>
public final class ChatRoom extends Chat implements Comparable<ChatRoom>
Represents a multi-user chat room.Use this class to enter a chat room, to send and receive messages, invite others and to manage members (e.g. kick or ban a user, grant admin status, etc.).
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddInvitationDeclineListener(Consumer<InvitationDeclineEvent> invitationDeclineListener)Adds a invitation decline listener, which allows to listen for invitation declines.voidaddOccupantListener(Consumer<OccupantEvent> occupantListener)Adds an occupant listener, which allows to listen for presence changes of occupants, e.g.voidaddSubjectChangeListener(Consumer<SubjectChangeEvent> subjectChangeListener)Adds a subject change listener, which allows to listen for subject changes.AsyncResult<IQ>banUser(Jid user, String reason)Bans a user.AsyncResult<IQ>changeAffiliation(Affiliation affiliation, Jid user, String reason)Changes the affiliation for an user.AsyncResult<IQ>changeAffiliationsOrRoles(List<Item> items)Changes multiple affiliations or roles.voidchangeAvailabilityStatus(Presence.Show show, String status)Changes the availability status.AsyncResult<Presence>changeNickname(String newNickname)Changes the nickname.AsyncResult<IQ>changeRole(Role role, String nickname, String reason)Changes the role for an occupant.AsyncResult<Message>changeSubject(String subject)Changes the room subject.intcompareTo(ChatRoom o)Compares this chat service first by their name and then by their service address.AsyncResult<IQ>configure(RoomConfiguration roomConfiguration)Configures this room.AsyncResult<IQ>destroy()Destroys the room.AsyncResult<IQ>destroy(String reason)Destroys the room.AsyncResult<Set<String>>discoverAllowableTraffic()Discovers the allowable traffic, i.e. the allowed extensions.AsyncResult<List<String>>discoverOccupants()Gets the occupants in this room, i.e. their nicknames.AsyncResult<String>discoverReservedNickname()Gets your reserved room nickname.AsyncResult<Presence>enter(String nick)Enters the room.AsyncResult<Presence>enter(String nick, String password)Enters the room with a password.AsyncResult<Presence>enter(String nick, String password, DiscussionHistory history)Enters the room with a password and requests history messages.AsyncResult<Presence>enter(String nick, DiscussionHistory history)Enters the room and requests history messages.AsyncResult<Void>exit()Exits the room.AsyncResult<Void>exit(String message)Exits the room with a custom message.JidgetAddress()Gets the room address.AsyncResult<List<Item>>getAdmins()Gets the admins of the room.AsyncResult<List<Item>>getBanList()Gets the ban list.AsyncResult<DataForm>getConfigurationForm()Gets the configuration form for the room.AsyncResult<List<Item>>getMembers()Gets the members of the room.AsyncResult<List<Item>>getModerators()Gets the moderators.StringgetName()Gets the name for this room.StringgetNick()Gets the nickname in this room.OccupantgetOccupant(String nickname)Gets an occupant by nickname.Collection<Occupant>getOccupants()Gets the occupants, while being in the room.AsyncResult<List<Item>>getOutcasts()Gets the outcasts of the room.AsyncResult<List<Item>>getOwners()Gets the owners of the room.AsyncResult<DataForm>getRegistrationForm()Gets the data form necessary to register with the room.AsyncResult<RoomInformation>getRoomInformation()Gets the room information for this chat room.AsyncResult<List<Item>>getVoiceList()Gets the voice list.AsyncResult<IQ>grantAdminStatus(Jid user, String reason)Grants admin status to a user.AsyncResult<IQ>grantMembership(Jid user, String nick, String reason)Grants membership to a user.AsyncResult<IQ>grantModeratorStatus(String nickname, String reason)Grants moderator status to a participant or visitor.AsyncResult<IQ>grantOwnerStatus(Jid user, String reason)Grants owner status to a user.AsyncResult<IQ>grantVoice(String nickname, String reason)Grants voice to a visitor.booleanhasEntered()Indicates, if you have entered the room.voidinvite(Jid invitee, String reason)Invites another user to the room.voidinvite(Jid invitee, String reason, boolean direct)Invites another user to the room.AsyncResult<IQ>kickOccupant(String nickname, String reason)Kicks an occupant from the room.AsyncResult<IQ>register(Registration registration)Registers with the room.voidremoveInvitationDeclineListener(Consumer<InvitationDeclineEvent> invitationDeclineListener)Removes a previously added invitation decline listener.voidremoveOccupantListener(Consumer<OccupantEvent> occupantListener)Removes a previously added occupant listener.voidremoveSubjectChangeListener(Consumer<SubjectChangeEvent> subjectChangeListener)Removes a previously added subject change listener.voidrequestVoice()Requests voice in a moderated room.AsyncResult<IQ>revokeAdminStatus(Jid user, String reason)Revokes a user's admin status.AsyncResult<IQ>revokeMembership(Jid user, String reason)Revokes a user's membership.AsyncResult<IQ>revokeModeratorStatus(String nickname, String reason)Revokes moderator status from a participant or visitor.AsyncResult<IQ>revokeOwnerStatus(Jid user, String reason)Revokes a user's owner status.AsyncResult<IQ>revokeVoice(String nickname, String reason)Revokes voice from a participant.SendTask<Message>sendMessage(String message)Sends a message to the room.SendTask<Message>sendMessage(Message message)Sends a message to the room.StringtoString()-
Methods inherited from class rocks.xmpp.im.chat.Chat
addInboundMessageListener, removeInboundMessageListener
-
-
-
-
Method Detail
-
addInvitationDeclineListener
public void addInvitationDeclineListener(Consumer<InvitationDeclineEvent> invitationDeclineListener)
Adds a invitation decline listener, which allows to listen for invitation declines.- Parameters:
invitationDeclineListener- The listener.- See Also:
removeInvitationDeclineListener(Consumer)
-
removeInvitationDeclineListener
public void removeInvitationDeclineListener(Consumer<InvitationDeclineEvent> invitationDeclineListener)
Removes a previously added invitation decline listener.- Parameters:
invitationDeclineListener- The listener.- See Also:
addInvitationDeclineListener(Consumer)
-
addSubjectChangeListener
public void addSubjectChangeListener(Consumer<SubjectChangeEvent> subjectChangeListener)
Adds a subject change listener, which allows to listen for subject changes.- Parameters:
subjectChangeListener- The listener.- See Also:
removeSubjectChangeListener(Consumer)
-
removeSubjectChangeListener
public void removeSubjectChangeListener(Consumer<SubjectChangeEvent> subjectChangeListener)
Removes a previously added subject change listener.- Parameters:
subjectChangeListener- The listener.- See Also:
addSubjectChangeListener(Consumer)
-
addOccupantListener
public void addOccupantListener(Consumer<OccupantEvent> occupantListener)
Adds an occupant listener, which allows to listen for presence changes of occupants, e.g. "joins" and "leaves".- Parameters:
occupantListener- The listener.- See Also:
removeOccupantListener(Consumer)
-
removeOccupantListener
public void removeOccupantListener(Consumer<OccupantEvent> occupantListener)
Removes a previously added occupant listener.- Parameters:
occupantListener- The listener.- See Also:
addOccupantListener(Consumer)
-
enter
public AsyncResult<Presence> enter(String nick)
Enters the room.- Parameters:
nick- The nickname.- Returns:
- The async result with the self-presence returned by the chat room.
-
enter
public AsyncResult<Presence> enter(String nick, String password)
Enters the room with a password.- Parameters:
nick- The nickname.password- The password.- Returns:
- The async result with the self-presence returned by the chat room.
-
enter
public AsyncResult<Presence> enter(String nick, DiscussionHistory history)
Enters the room and requests history messages.- Parameters:
nick- The nickname.history- The history.- Returns:
- The async result with the self-presence returned by the chat room.
-
enter
public final AsyncResult<Presence> enter(String nick, String password, DiscussionHistory history)
Enters the room with a password and requests history messages.- Parameters:
nick- The nickname.password- The password.history- The history.- Returns:
- The async result with the self-presence returned by the chat room.
-
changeSubject
public AsyncResult<Message> changeSubject(String subject)
Changes the room subject.- Parameters:
subject- The subject.- Returns:
- The async result with the message returned by the chat room.
-
sendMessage
public SendTask<Message> sendMessage(String message)
Sends a message to the room.- Specified by:
sendMessagein classChat- Parameters:
message- The message text.- Returns:
- The sent message.
-
sendMessage
public SendTask<Message> sendMessage(Message message)
Sends a message to the room.- Specified by:
sendMessagein classChat- Parameters:
message- The message.- Returns:
- The sent message.
-
changeNickname
public final AsyncResult<Presence> changeNickname(String newNickname)
Changes the nickname.- Parameters:
newNickname- The new nickname.- Returns:
- The async result with the presence returned by the chat room.
- See Also:
- 7.6 Changing Nickname
-
changeAvailabilityStatus
public void changeAvailabilityStatus(Presence.Show show, String status)
Changes the availability status.- Parameters:
show- The 'show' value.status- The status.- See Also:
- 7.7 Changing Availability Status
-
invite
public void invite(Jid invitee, String reason)
Invites another user to the room. The invitation will be mediated by the room.- Parameters:
invitee- The invitee.reason- The reason.- See Also:
- 7.8 Inviting Another User to a Room
-
invite
public void invite(Jid invitee, String reason, boolean direct)
Invites another user to the room. The invitation will be either mediated by the room or direct.- Parameters:
invitee- The invitee.reason- The reason.direct- True, if the message is sent directly to the invitee; false if it is mediated by the room.- See Also:
- 7.8.1 Direct Invitation, 7.8.2 Mediated Invitation
-
getRegistrationForm
public AsyncResult<DataForm> getRegistrationForm()
Gets the data form necessary to register with the room.- Returns:
- The async result with the data form.
- See Also:
- 7.10 Registering with a Room,
RoomRegistration
-
register
public AsyncResult<IQ> register(Registration registration)
Registers with the room.- Parameters:
registration- The registration.- Returns:
- The async result.
- See Also:
- 7.10 Registering with a Room,
RoomRegistration
-
discoverReservedNickname
public AsyncResult<String> discoverReservedNickname()
Gets your reserved room nickname.- Returns:
- The async result with the reserved nickname or null, if you don't have a reserved nickname.
-
requestVoice
public void requestVoice()
Requests voice in a moderated room.- See Also:
- 7.13 Requesting Voice
-
exit
public AsyncResult<Void> exit()
Exits the room.- Returns:
- The async result.
- See Also:
- 7.14 Exiting a Room
-
exit
public final AsyncResult<Void> exit(String message)
Exits the room with a custom message.- Parameters:
message- The exit message.- Returns:
- The async result.
- See Also:
- 7.14 Exiting a Room
-
hasEntered
public final boolean hasEntered()
Indicates, if you have entered the room. When you exit the room, this method returns false.- Returns:
- If you entered the room.
- See Also:
enter(String),exit()
-
getVoiceList
public AsyncResult<List<Item>> getVoiceList()
Gets the voice list.- Returns:
- The async result with the voice list.
- See Also:
- 8.5 Modifying the Voice List
-
changeAffiliationsOrRoles
public AsyncResult<IQ> changeAffiliationsOrRoles(List<Item> items)
Changes multiple affiliations or roles.- Parameters:
items- The items.- Returns:
- The async result.
- See Also:
- 8.5 Modifying the Voice List, 9.5 Modifying the Member List, 9.8 Modifying the Moderator List, 10.5 Modifying the Owner List, 10.8 Modifying the Admin List
-
getBanList
public AsyncResult<List<Item>> getBanList()
Gets the ban list.- Returns:
- The async result with the ban list.
- See Also:
- 9.2 Modifying the Ban List
-
changeAffiliation
public final AsyncResult<IQ> changeAffiliation(Affiliation affiliation, Jid user, String reason)
Changes the affiliation for an user.Use this method for one of the following use cases:
- Banning a User (affiliation =
Affiliation.OUTCAST) - Granting Membership (affiliation =
Affiliation.MEMBER) - Revoking Membership (affiliation =
Affiliation.NONE) - Granting Admin Status (affiliation =
Affiliation.ADMIN) - Revoking Admin Status (affiliation =
Affiliation.MEMBER) - Granting Owner Status (affiliation =
Affiliation.OWNER) - Revoking Owner Status (affiliation =
Affiliation.ADMIN)
- Parameters:
affiliation- The new affiliation for the user.user- The user.reason- The reason.- Returns:
- The async result.
- See Also:
- 9.1 Banning a User, 9.3 Granting Membership, 9.4 Revoking Membership, 10.3 Granting Owner Status, 10.4 Revoking Owner Status, 10.6 Granting Admin Status, 10.7 Revoking Admin Status
- Banning a User (affiliation =
-
banUser
public final AsyncResult<IQ> banUser(Jid user, String reason)
Bans a user. Note that you must be an owner or admin of the room.- Parameters:
user- The user.reason- The reason (optional). May benull.- Returns:
- The async result.
- See Also:
- 9.1 Banning a User
-
grantMembership
public final AsyncResult<IQ> grantMembership(Jid user, String nick, String reason)
Grants membership to a user. Note that you must be an owner or admin of the room.- Parameters:
user- The user.nick- The nick (optional). That nick becomes the user's default nick in the room if that functionality is supported by the implementation. May benull.reason- The reason (optional). May benull.- Returns:
- The async result.
- See Also:
- 9.3 Granting Membership,
revokeMembership(Jid, String)
-
revokeMembership
public final AsyncResult<IQ> revokeMembership(Jid user, String reason)
Revokes a user's membership. Note that you must be an owner or admin of the room.- Parameters:
user- The user.reason- The reason (optional). May benull.- Returns:
- The async result.
- See Also:
- 9.4 Revoking Membership,
grantMembership(Jid, String, String)
-
grantOwnerStatus
public final AsyncResult<IQ> grantOwnerStatus(Jid user, String reason)
Grants owner status to a user. Note that you must be an owner of the room.- Parameters:
user- The user.reason- The reason (optional). May benull.- Returns:
- The async result.
- See Also:
- 10.3 Granting Owner Status,
revokeOwnerStatus(Jid, String)
-
revokeOwnerStatus
public final AsyncResult<IQ> revokeOwnerStatus(Jid user, String reason)
Revokes a user's owner status. The new status of the user will be 'admin'. Note that you must be an owner of the room. This method does basically the same asgrantAdminStatus(Jid, String)}.- Parameters:
user- The user.reason- The reason (optional). May benull.- Returns:
- The async result.
- See Also:
- 10.4 Revoking Owner Status,
grantOwnerStatus(Jid, String)
-
grantAdminStatus
public final AsyncResult<IQ> grantAdminStatus(Jid user, String reason)
Grants admin status to a user. Note that you must be an owner of the room. This method does basically the same asrevokeOwnerStatus(Jid, String).- Parameters:
user- The user.reason- The reason (optional). May benull.- Returns:
- The async result.
- See Also:
- 10.6 Granting Admin Status,
revokeAdminStatus(Jid, String)
-
revokeAdminStatus
public final AsyncResult<IQ> revokeAdminStatus(Jid user, String reason)
Revokes a user's admin status. The new status of the user will be 'member'. Note that you must be an owner of the room.- Parameters:
user- The user.reason- The reason (optional). May benull.- Returns:
- The async result.
- See Also:
- 10.7 Revoking Admin Status,
grantAdminStatus(Jid, String)
-
changeRole
public final AsyncResult<IQ> changeRole(Role role, String nickname, String reason)
Changes the role for an occupant.Use this method for one of the following use cases:
- Kicking an Occupant (role =
Role.NONE) - Granting Voice to a Visitor (role =
Role.PARTICIPANT) - Revoking Voice from a Participant (affiliation =
Role.VISITOR) - Granting Moderator Status (role =
Role.MODERATOR) - Revoking Moderator Status (role =
Role.PARTICIPANT)
- Parameters:
role- The new role for the user.nickname- The occupant's nickname.reason- The reason.- Returns:
- The async result.
- See Also:
- 8.2 Kicking an Occupant, 8.3 Granting Voice to a Visitor, 8.4 Revoking Voice from a Participant, 9.6 Granting Moderator Status, 9.7 Revoking Moderator Status
- Kicking an Occupant (role =
-
kickOccupant
public final AsyncResult<IQ> kickOccupant(String nickname, String reason)
Kicks an occupant from the room. Note that you must be a moderator in the room.- Parameters:
nickname- The nickname.reason- The reason (optional). May benull.- Returns:
- The async result.
- See Also:
- 8.2 Kicking an Occupant
-
grantVoice
public final AsyncResult<IQ> grantVoice(String nickname, String reason)
Grants voice to a visitor. Note that you must be a moderator in the room. This method does basically the same asrevokeModeratorStatus(String, String)}}.- Parameters:
nickname- The nickname.reason- The reason (optional). May benull.- Returns:
- The async result.
- See Also:
- 8.3 Granting Voice to a Visitor,
revokeVoice(String, String)
-
revokeVoice
public final AsyncResult<IQ> revokeVoice(String nickname, String reason)
Revokes voice from a participant. Note that you must be a moderator in the room.- Parameters:
nickname- The nickname.reason- The reason (optional). May benull.- Returns:
- The async result.
- See Also:
- 8.4 Revoking Voice from a Participant,
grantVoice(String, String)
-
grantModeratorStatus
public final AsyncResult<IQ> grantModeratorStatus(String nickname, String reason)
Grants moderator status to a participant or visitor. Note that you must be an admin in the room.- Parameters:
nickname- The nickname.reason- The reason (optional). May benull.- Returns:
- The async result.
- See Also:
- 9.6 Granting Moderator Status
-
revokeModeratorStatus
public final AsyncResult<IQ> revokeModeratorStatus(String nickname, String reason)
Revokes moderator status from a participant or visitor. Note that you must be an admin in the room. This method does basically the same asgrantVoice(String, String).- Parameters:
nickname- The nickname.reason- The reason (optional). May benull.- Returns:
- The async result.
- See Also:
- 9.7 Revoking Moderator Status
-
getOwners
public AsyncResult<List<Item>> getOwners()
Gets the owners of the room.- Returns:
- The async result with the owners.
- See Also:
- 9.5 Modifying the Member List
-
getOutcasts
public AsyncResult<List<Item>> getOutcasts()
Gets the outcasts of the room.- Returns:
- The async result with the outcasts.
- See Also:
- 9.5 Modifying the Member List
-
getAdmins
public AsyncResult<List<Item>> getAdmins()
Gets the admins of the room.- Returns:
- The async result with the admins.
- See Also:
- 9.5 Modifying the Member List
-
getMembers
public AsyncResult<List<Item>> getMembers()
Gets the members of the room.In the context of a members-only room, the member list is essentially a "whitelist" of people who are allowed to enter the room.
In the context of an open room, the member list is simply a list of users (bare JID and reserved nick) who are registered with the room.
- Returns:
- The async result with the members.
- See Also:
- 9.5 Modifying the Member List
-
getModerators
public AsyncResult<List<Item>> getModerators()
Gets the moderators.- Returns:
- The async result with the moderators.
- See Also:
- 9.8 Modifying the Moderator List
-
getRoomInformation
public AsyncResult<RoomInformation> getRoomInformation()
Gets the room information for this chat room.- Returns:
- The async result with the room info.
- See Also:
- 6.4 Querying for Room Information
-
discoverOccupants
public AsyncResult<List<String>> discoverOccupants()
Gets the occupants in this room, i.e. their nicknames. This method should be used, when you are not yet in the room.- Returns:
- The async result with the occupants.
- See Also:
- 6.5 Querying for Room Items,
getOccupants()
-
getOccupants
public Collection<Occupant> getOccupants()
Gets the occupants, while being in the room.- Returns:
- The occupants.
-
getOccupant
public Occupant getOccupant(String nickname)
Gets an occupant by nickname.- Parameters:
nickname- The occupant's nickname.- Returns:
- The occupant.
-
getConfigurationForm
public AsyncResult<DataForm> getConfigurationForm()
Gets the configuration form for the room. You can wrap the form intoRoomConfigurationfor easier processing.Use this method if you want to create a reserved room or configure an existing room.
- Returns:
- The async result with the configuration form.
- See Also:
RoomConfiguration, 10.1.3 Creating a Reserved Room,configure(RoomConfiguration)
-
configure
public AsyncResult<IQ> configure(RoomConfiguration roomConfiguration)
Configures this room.- Parameters:
roomConfiguration- The async result with the room configuration form.- Returns:
- The async result.
- See Also:
- 10.1.3 Creating a Reserved Room,
getConfigurationForm()
-
getName
public final String getName()
Gets the name for this room.- Returns:
- The room name.
-
getNick
public final String getNick()
Gets the nickname in this room. Usually this is the nick used to enter the room, but can also be a nickname assigned by the chat service.- Returns:
- The nickname in this room or
null, if not entered.
-
destroy
public AsyncResult<IQ> destroy(String reason)
Destroys the room.- Parameters:
reason- The reason for the room destruction.- Returns:
- The async result.
- See Also:
- 10.9 Destroying a Room
-
destroy
public final AsyncResult<IQ> destroy()
Destroys the room.- Returns:
- The async result.
- See Also:
- 10.9 Destroying a Room
-
getAddress
public Jid getAddress()
Gets the room address.- Returns:
- The room address.
-
discoverAllowableTraffic
public AsyncResult<Set<String>> discoverAllowableTraffic()
Discovers the allowable traffic, i.e. the allowed extensions.- Returns:
- The async result with the list of allowable features.
- See Also:
- 17.1.1 Allowable Traffic
-
compareTo
public int compareTo(ChatRoom o)
Compares this chat service first by their name and then by their service address.- Specified by:
compareToin interfaceComparable<ChatRoom>- Parameters:
o- The other chat service.- Returns:
- The comparison result.
-
-