Java Code Examples for org.xmpp.packet.Message#getSubject()

The following examples show how to use org.xmpp.packet.Message#getSubject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalMUCRoom.java    From Openfire with Apache License 2.0 6 votes vote down vote up
@Override
public void changeSubject(Message packet, MUCRole role) throws ForbiddenException {
    if ((canOccupantsChangeSubject() && role.getRole().compareTo(MUCRole.Role.visitor) < 0) ||
            MUCRole.Role.moderator == role.getRole()) {
        // Set the new subject to the room
        subject = packet.getSubject();
        MUCPersistenceManager.updateRoomSubject(this);
        // Notify all the occupants that the subject has changed
        packet.setFrom(role.getRoleAddress());
        send(packet, role);

        // Fire event signifying that the room's subject has changed.
        MUCEventDispatcher.roomSubjectChanged(getJID(), role.getUserAddress(), subject);

        // Let other cluster nodes that the room has been updated
        CacheFactory.doClusterTask(new RoomUpdatedEvent(this));
    }
    else {
        throw new ForbiddenException();
    }
}
 
Example 2
Source File: HistoryStrategy.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if the given message qualifies as a subject change request for
 * the target MUC room, per XEP-0045. Note that this does not validate whether 
 * the sender has permission to make the change, because subject change requests
 * may be loaded from history or processed "live" during a user's session.
 * 
 * Refer to http://xmpp.org/extensions/xep-0045.html#subject-mod for details.
 *
 * @param message the message to check
 * @return true if the given packet is a subject change request
 */
public boolean isSubjectChangeRequest(Message message) {
    
    // The subject is changed by sending a message of type "groupchat" to the <room@service>, 
    // where the <message/> MUST contain a <subject/> element that specifies the new subject 
    // but MUST NOT contain a <body/> element (or a <thread/> element).
    // Unfortunately, many clients do not follow these strict guidelines from the specs, so we
    // allow a lenient policy for detecting non-conforming subject change requests. This can be
    // configured by setting the "xmpp.muc.subject.change.strict" property to false (true by default).
    // An empty <subject/> value means that the room subject should be removed.

    return Message.Type.groupchat == message.getType() && 
            message.getSubject() != null && 
            (!isSubjectChangeStrict() || 
                (message.getBody() == null && 
                 message.getThread() == null));
}
 
Example 3
Source File: ConversationLogEntry.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new ConversationLogEntry that registers that a given message was sent to a given
 * room on a given date.
 * 
 * @param date the date when the message was sent to the room.
 * @param room the room that received the message.
 * @param message the message to log as part of the conversation in the room.
 * @param sender the real XMPPAddress of the sender (e.g. [email protected]). 
 */
public ConversationLogEntry(Date date, MUCRoom room, Message message, JID sender) {
    this.date = date;
    this.subject = message.getSubject();
    this.body = message.getBody();
    this.stanza = message.toXML();
    this.sender = sender;
    this.roomID = room.getID();
    this.nickname = message.getFrom().getResource();
}
 
Example 4
Source File: MultiUserChatServiceImpl.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
public void logConversation(final MUCRoom room, final Message message, final JID sender) {
    // Only log messages that have a subject or body. Otherwise ignore it.
    if (message.getSubject() != null || message.getBody() != null) {
        getArchiver().archive( new ConversationLogEntry( new Date(), room, message, sender) );
    }
}
 
Example 5
Source File: HistoryRequest.java    From Openfire with Apache License 2.0 4 votes vote down vote up
/**
 * Sends the smallest amount of traffic that meets any combination of the requested criteria.
 * 
 * @param joinRole the user that will receive the history.
 * @param roomHistory the history of the room.
 */
public void sendHistory(MUCRole joinRole, MUCRoomHistory roomHistory) {
    if (!isConfigured()) {
        Iterator<Message> history = roomHistory.getMessageHistory();
        while (history.hasNext()) {
            joinRole.send(history.next());
        }
    }
    else {
        if (getMaxChars() == 0) {
            // The user requested to receive no history
            return;
        }
        int accumulatedChars = 0;
        int accumulatedStanzas = 0;
        Element delayInformation;
        LinkedList<Message> historyToSend = new LinkedList<>();
        ListIterator<Message> iterator = roomHistory.getReverseMessageHistory();
        while (iterator.hasPrevious()) {
            Message message = iterator.previous();
            // Update number of characters to send
            String text = message.getBody() == null ? message.getSubject() : message.getBody();
            if (text == null) {
                // Skip this message since it has no body and no subject  
                continue;
            }
            accumulatedChars += text.length();
            if (getMaxChars() > -1 && accumulatedChars > getMaxChars()) {
                // Stop collecting history since we have exceded a limit
                break;
            }
            // Update number of messages to send
            accumulatedStanzas ++;
            if (getMaxStanzas() > -1 && accumulatedStanzas > getMaxStanzas()) {
                // Stop collecting history since we have exceded a limit
                break;
            }

            if (getSeconds() > -1 || getSince() != null) {
                delayInformation = message.getChildElement("delay", "urn:xmpp:delay");
                try {
                    // Get the date when the historic message was sent
                    Date delayedDate = xmppDateTime.parseString(delayInformation.attributeValue("stamp"));
                    if (getSince() != null && delayedDate != null && delayedDate.before(getSince())) {
                        // Stop collecting history since we have exceded a limit
                        break;
                    }
                    if (getSeconds() > -1) {
                        Date current = new Date();
                        long diff = (current.getTime() - delayedDate.getTime()) / 1000;
                        if (getSeconds() <= diff) {
                            // Stop collecting history since we have exceded a limit
                            break;
                        }
                    }
                }
                catch (Exception e) {
                    Log.error("Error parsing date from historic message", e);
                }

            }

            historyToSend.addFirst(message);
        }
        // Send the smallest amount of traffic to the user
        for (Object aHistoryToSend : historyToSend) {
            joinRole.send((Message) aHistoryToSend);
        }
    }
}