Class MUCOccupant

java.lang.Object
org.jivesoftware.openfire.muc.MUCOccupant
All Implemented Interfaces:
Externalizable, Serializable, Cacheable

public class MUCOccupant extends Object implements Cacheable, Externalizable
Defines the permissions and actions that a user currently may use in a particular room. Each MUCOccupant defines the relationship between a MUCRoom and a specific user that is joined to (is an occupant of) that room. Note that a MUCOccupant can exist only for a user that is currently an occupant of a room.
Author:
Gaston Dombiak
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    This constructor is provided to comply with the Externalizable interface contract.
    MUCOccupant(MUCRoom chatroom, String nickname, Role role, Affiliation affiliation, org.xmpp.packet.JID userJid, org.xmpp.packet.Presence presence)
    Create a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    augmentOutboundStanzaWithFMUCData(org.xmpp.packet.Packet packet)
    When sending data to a user that joined the room through FMUC (when the user is a user that is local to a remote chatroom that joined our room as a 'joining FMUC node'), then we'll need to add an 'fmuc' element to all data that we send it.
    void
    Changes the nickname of the occupant within the room to the new nickname.
    An empty instance that represents the room itself in the chatroom.
    boolean
     
    Obtain the affiliation state of the user, which is a long-lived association or connection with a room.
    int
    Returns the approximate size of the Object in bytes.
    protected MUCRoom
    Obtain the chat room that hosts this occupant.
    Obtain the nickname for the user in the chatroom.
    Obtain The user's occupant-id (as specified in XEP-0421).
    org.xmpp.packet.JID
    Returns the 'room@service/nick' by which the occupant is identified within the context of the room; contrast with getUserAddress().
    org.xmpp.packet.Presence
    Obtains a copy of the current presence status of an occupant of a chatroom.
    org.xmpp.packet.JID
    Obtain the XMPPAddress representing this occupant in a room in context of FMUC.
    Obtain the role state of the user.
    org.xmpp.packet.JID
    The JID of the user (the real JID, eg: 'user@domain/desktop`) that is the occupant of a room (as represented by this instance); contrast with getOccupantJID().
    int
     
    boolean
    Returns true if the user is one that is in the room as a result of that user being in another room that is federated with this room, through the FMUC protocol
    boolean
    Returns true if the room occupant does not want to get messages broadcast to all room occupants.
    void
     
    void
    send(org.xmpp.packet.Packet packet)
    Sends a packet to the user.
    void
    setPresence(org.xmpp.packet.Presence newPresence)
    Set the current presence status of a user in a chatroom.
    void
    setReportedFmucAddress(org.xmpp.packet.JID reportedFmucAddress)
     
     
    void
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • MUCOccupant

      public MUCOccupant()
      This constructor is provided to comply with the Externalizable interface contract. It should not be used directly.
    • MUCOccupant

      public MUCOccupant(MUCRoom chatroom, String nickname, Role role, Affiliation affiliation, org.xmpp.packet.JID userJid, org.xmpp.packet.Presence presence)
      Create a new instance.
      Parameters:
      chatroom - the room the occupant is in.
      nickname - the nickname of the user in the room.
      role - the role of the user in the room.
      affiliation - the affiliation of the user in the room.
      userJid - the 'real' JID of the user.
      presence - the presence sent by the user to join the room.
  • Method Details

    • createRoomSelfRepresentation

      public static MUCOccupant createRoomSelfRepresentation(@Nonnull MUCRoom room)
      An empty instance that represents the room itself in the chatroom. Chatrooms need to be able to speak (server messages) and so must have data representing their own 'occupancy' in the chatroom.
      Parameters:
      room - The room for which to return an instance.
      Returns:
      The representation of the room.
    • getPresence

      public org.xmpp.packet.Presence getPresence()
      Obtains a copy of the current presence status of an occupant of a chatroom. The 'from' address of the presence stanza is guaranteed to reflect the room address (as opposed to the real address) of the occupant..
      Returns:
      The presence of the user in the room.
    • setPresence

      public void setPresence(org.xmpp.packet.Presence newPresence)
      Set the current presence status of a user in a chatroom.
      Parameters:
      newPresence - The presence of the user in the room.
    • getRole

      public Role getRole()
      Obtain the role state of the user. A role is a temporary position or privilege level within a room, distinct from a user's long-lived affiliation with the room. A role lasts only for the duration of an occupant's visit to a room.
      Returns:
      The role status of this user.
    • getAffiliation

      public Affiliation getAffiliation()
      Obtain the affiliation state of the user, which is a long-lived association or connection with a room. Affiliation is distinct from role. An affiliation lasts across a user's visits to a room.
      Returns:
      The affiliation status of this user.
    • getNickname

      public String getNickname()
      Obtain the nickname for the user in the chatroom.
      Returns:
      The user's nickname in the room or null if invisible.
    • getOccupantId

      public String getOccupantId()
      Obtain The user's occupant-id (as specified in XEP-0421).
      Returns:
      the user's occupant-id.
    • changeNickname

      public void changeNickname(String nickname)
      Changes the nickname of the occupant within the room to the new nickname.
      Parameters:
      nickname - the new nickname of the occupant in the room.
    • getChatRoom

      protected MUCRoom getChatRoom()
      Obtain the chat room that hosts this occupant.
      Returns:
      The chatroom hosting this occupant.
    • getOccupantJID

      public org.xmpp.packet.JID getOccupantJID()
      Returns the 'room@service/nick' by which the occupant is identified within the context of the room; contrast with getUserAddress().
      Returns:
      The Jabber ID that represents this occupant in the room.
    • getUserAddress

      public org.xmpp.packet.JID getUserAddress()
      The JID of the user (the real JID, eg: 'user@domain/desktop`) that is the occupant of a room (as represented by this instance); contrast with getOccupantJID(). A null null value is returned when this instance is a self-representation of the room.
      Returns:
      The address of the user that joined the room or null if this instance represents to the room itself.
    • getReportedFmucAddress

      public org.xmpp.packet.JID getReportedFmucAddress()
      Obtain the XMPPAddress representing this occupant in a room in context of FMUC. This typically represents the XMPPAddress as it is known locally at the joining FMUC node. For users that are joined through FMUC from a remote node, this method will return the value as reported by the joining FMUC node. For users that are in the room, but connected directly to this instance of Openfire, this method returns null, even if the room is part of an FMUC node. Users that joined through server-to-server federation (as opposed to FMUC), will not have a FMUC address. Null is returned by this method for these users.
      Returns:
      The address of the user that joined the room through FMUC from a remote domain, or null.
    • setReportedFmucAddress

      public void setReportedFmucAddress(@Nonnull org.xmpp.packet.JID reportedFmucAddress)
    • isRemoteFmuc

      public boolean isRemoteFmuc()
      Returns true if the user is one that is in the room as a result of that user being in another room that is federated with this room, through the FMUC protocol
      Returns:
      true if this user is a user on a remote MUC room that is federated with this chatroom.
    • isVoiceOnly

      public boolean isVoiceOnly()
      Returns true if the room occupant does not want to get messages broadcast to all room occupants. This type of users are called "deaf" occupants. Deaf occupants will still be able to get private messages, presences, IQ packets or room history.

      To be a deaf occupant the initial presence sent to the room while joining the room has to include the following child element:

       <x xmlns='http://jivesoftware.org/protocol/muc'>
           <deaf-occupant/>
       </x>
       
      Note that this is a custom extension to the MUC specification.
      Returns:
      true if the room occupant does not want to get messages broadcasted to all room occupants.
    • send

      public void send(org.xmpp.packet.Packet packet)
      Sends a packet to the user. Note that sending a packet can modify it (notably, the 'to' address can be changed). If this is undesired (for example, because post-processing should not expose the modified 'to' address), then a copy of the original stanza should be provided as an argument to this method.
      Parameters:
      packet - The packet to send
      See Also:
    • augmentOutboundStanzaWithFMUCData

      public void augmentOutboundStanzaWithFMUCData(@Nonnull org.xmpp.packet.Packet packet)
      When sending data to a user that joined the room through FMUC (when the user is a user that is local to a remote chatroom that joined our room as a 'joining FMUC node'), then we'll need to add an 'fmuc' element to all data that we send it. The data that is to be added must include the 'from' address representing the FMUC role for the occupant that sent the stanza. We either use the reported FMUC address as passed down from other FMUC nodes, or we use the address of users connected locally to our server. This method will add an 'fmuc' child element to the stanza when the user is a user that joined through FMUC (is a member of a room that federates with the MUC room local to our server). If the provided stanza already contains an FMUC element with relevant data, this data is left unchanged.
      Parameters:
      packet - The stanza to augment
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getCachedSize

      public int getCachedSize() throws CannotCalculateSizeException
      Description copied from interface: Cacheable
      Returns the approximate size of the Object in bytes. The size should be considered to be a best estimate of how much memory the Object occupies and may be based on empirical trials or dynamic calculations.

      Specified by:
      getCachedSize in interface Cacheable
      Returns:
      the size of the Object in bytes.
      Throws:
      CannotCalculateSizeException - if the size cannot be calculated
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException