Search in sources :

Example 1 with MUCRoom

use of org.jivesoftware.openfire.muc.MUCRoom in project Openfire by igniterealtime.

the class MultiUserChatServiceImpl method getExtendedInfo.

@Override
public DataForm getExtendedInfo(String name, String node, JID senderJID) {
    if (name != null && node == null) {
        // Answer the extended info of a given room
        MUCRoom room = getChatRoom(name);
        if (room != null) {
            final DataForm dataForm = new DataForm(Type.result);
            final FormField fieldType = dataForm.addField();
            fieldType.setVariable("FORM_TYPE");
            fieldType.setType(FormField.Type.hidden);
            fieldType.addValue("http://jabber.org/protocol/muc#roominfo");
            final FormField fieldDescr = dataForm.addField();
            fieldDescr.setVariable("muc#roominfo_description");
            fieldDescr.setLabel(LocaleUtils.getLocalizedString("muc.extended.info.desc"));
            fieldDescr.addValue(room.getDescription());
            final FormField fieldSubj = dataForm.addField();
            fieldSubj.setVariable("muc#roominfo_subject");
            fieldSubj.setLabel(LocaleUtils.getLocalizedString("muc.extended.info.subject"));
            fieldSubj.addValue(room.getSubject());
            final FormField fieldOcc = dataForm.addField();
            fieldOcc.setVariable("muc#roominfo_occupants");
            fieldOcc.setLabel(LocaleUtils.getLocalizedString("muc.extended.info.occupants"));
            fieldOcc.addValue(Integer.toString(room.getOccupantsCount()));
            /*field = new XFormFieldImpl("muc#roominfo_lang");
                field.setLabel(LocaleUtils.getLocalizedString("muc.extended.info.language"));
                field.addValue(room.getLanguage());
                dataForm.addField(field);*/
            final FormField fieldDate = dataForm.addField();
            fieldDate.setVariable("x-muc#roominfo_creationdate");
            fieldDate.setLabel(LocaleUtils.getLocalizedString("muc.extended.info.creationdate"));
            fieldDate.addValue(XMPPDateTimeFormat.format(room.getCreationDate()));
            return dataForm;
        }
    }
    return null;
}
Also used : MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 2 with MUCRoom

use of org.jivesoftware.openfire.muc.MUCRoom in project Openfire by igniterealtime.

the class MultiUserChatServiceImpl method removeChatRoom.

private void removeChatRoom(String roomName, boolean notify) {
    MUCRoom room = localMUCRoomManager.removeRoom(roomName);
    if (room != null) {
        Log.info("removing chat room:" + roomName + "|" + room.getClass().getName());
        if (room instanceof LocalMUCRoom)
            GroupEventDispatcher.removeListener((LocalMUCRoom) room);
        totalChatTime += room.getChatLength();
        if (notify) {
            // Notify other cluster nodes that a room has been removed
            CacheFactory.doClusterTask(new RoomRemovedEvent((LocalMUCRoom) room));
        }
    } else {
        Log.info("No chatroom {} during removal.", roomName);
    }
}
Also used : MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) RoomRemovedEvent(org.jivesoftware.openfire.muc.cluster.RoomRemovedEvent)

Example 3 with MUCRoom

use of org.jivesoftware.openfire.muc.MUCRoom in project Openfire by igniterealtime.

the class GroupConversationInterceptor method occupantLeft.

public void occupantLeft(JID roomJID, JID user) {
    // Process this event in the senior cluster member or local JVM when not in a cluster
    if (ClusterManager.isSeniorClusterMember()) {
        conversationManager.leftGroupConversation(roomJID, user, new Date());
        // If there are no more occupants then consider the group conversarion over
        MUCRoom mucRoom = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(roomJID).getChatRoom(roomJID.getNode());
        if (mucRoom != null && mucRoom.getOccupantsCount() == 0) {
            conversationManager.roomConversationEnded(roomJID, new Date());
        }
    } else {
        ConversationEventsQueue eventsQueue = conversationManager.getConversationEventsQueue();
        eventsQueue.addGroupChatEvent(conversationManager.getRoomConversationKey(roomJID), ConversationEvent.occupantLeft(roomJID, user, new Date()));
    }
}
Also used : MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) Date(java.util.Date)

Example 4 with MUCRoom

use of org.jivesoftware.openfire.muc.MUCRoom in project Openfire by igniterealtime.

the class MucMamPersistenceManager method findMessages.

@Override
public Collection<ArchivedMessage> findMessages(Date startDate, Date endDate, String owner, String with, XmppResultSet xmppResultSet) {
    JID mucRoom = new JID(owner);
    MultiUserChatManager manager = XMPPServer.getInstance().getMultiUserChatManager();
    MultiUserChatService service = manager.getMultiUserChatService(mucRoom);
    MUCRoom room = service.getChatRoom(mucRoom.getNode());
    Connection connection = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    // If logging isn't enabled, do nothing.
    if (!room.isLogEnabled())
        return null;
    List<ArchivedMessage> msgs = new LinkedList<>();
    if (startDate == null) {
        startDate = new Date(0L);
    }
    if (endDate == null) {
        endDate = new Date();
    }
    int max = xmppResultSet.getMax();
    // TODO: Suppress this, since we don't yet have requestor information for access control.
    with = null;
    try {
        connection = DbConnectionManager.getConnection();
        StringBuilder sql = new StringBuilder(LOAD_HISTORY);
        if (with != null) {
            sql.append(WHERE_SENDER);
        }
        if (xmppResultSet.getAfter() != null) {
            sql.append(WHERE_AFTER);
        }
        if (xmppResultSet.getBefore() != null) {
            sql.append(WHERE_BEFORE);
        }
        sql.append(ORDER_BY);
        pstmt = connection.prepareStatement(sql.toString());
        pstmt.setString(1, StringUtils.dateToMillis(startDate));
        pstmt.setString(2, StringUtils.dateToMillis(endDate));
        pstmt.setLong(3, room.getID());
        int pos = 3;
        if (with != null) {
            pstmt.setString(++pos, with);
        }
        if (xmppResultSet.getAfter() != null) {
            pstmt.setLong(++pos, xmppResultSet.getAfter());
        }
        if (xmppResultSet.getBefore() != null) {
            pstmt.setLong(++pos, xmppResultSet.getBefore());
        }
        rs = pstmt.executeQuery();
        while (rs.next()) {
            String senderJID = rs.getString(1);
            String nickname = rs.getString(2);
            Date sentDate = new Date(Long.parseLong(rs.getString(3).trim()));
            String subject = rs.getString(4);
            String body = rs.getString(5);
            String stanza = rs.getString(6);
            long id = rs.getLong(7);
            if (stanza == null) {
                Message message = new Message();
                message.setType(Message.Type.groupchat);
                message.setSubject(subject);
                message.setBody(body);
                // Set the sender of the message
                if (nickname != null && nickname.trim().length() > 0) {
                    JID roomJID = room.getRole().getRoleAddress();
                    // Recreate the sender address based on the nickname and room's JID
                    message.setFrom(new JID(roomJID.getNode(), roomJID.getDomain(), nickname, true));
                } else {
                    // Set the room as the sender of the message
                    message.setFrom(room.getRole().getRoleAddress());
                }
                stanza = message.toString();
            }
            ArchivedMessage archivedMessage = new ArchivedMessage(sentDate, ArchivedMessage.Direction.from, null, null);
            archivedMessage.setStanza(stanza);
            archivedMessage.setId(id);
            msgs.add(archivedMessage);
        }
    } catch (SQLException e) {
        Log.error("SQL failure during MAM-MUC: ", e);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, connection);
    }
    // TODO - Not great, really should be done by suitable LIMIT stuff.
    // Would need to reverse ordering in some cases and then reverse results.
    boolean complete = true;
    xmppResultSet.setCount(msgs.size());
    while (msgs.size() > max) {
        msgs.remove(msgs.size() - 1);
        complete = false;
    }
    xmppResultSet.setComplete(complete);
    if (msgs.size() > 0) {
        xmppResultSet.setFirst(msgs.get(0).getId());
        if (msgs.size() > 1) {
            xmppResultSet.setLast(msgs.get(msgs.size() - 1).getId());
        }
    }
    return msgs;
}
Also used : JID(org.xmpp.packet.JID) MultiUserChatManager(org.jivesoftware.openfire.muc.MultiUserChatManager) ArchivedMessage(com.reucon.openfire.plugin.archive.model.ArchivedMessage) Message(org.xmpp.packet.Message) SQLException(java.sql.SQLException) Connection(java.sql.Connection) MultiUserChatService(org.jivesoftware.openfire.muc.MultiUserChatService) PreparedStatement(java.sql.PreparedStatement) LinkedList(java.util.LinkedList) Date(java.util.Date) MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) ArchivedMessage(com.reucon.openfire.plugin.archive.model.ArchivedMessage) ResultSet(java.sql.ResultSet) XmppResultSet(com.reucon.openfire.plugin.archive.xep0059.XmppResultSet)

Example 5 with MUCRoom

use of org.jivesoftware.openfire.muc.MUCRoom in project Openfire by igniterealtime.

the class GetNewMemberRoomsRequest method run.

@Override
public void run() {
    rooms = new ArrayList<>();
    // Get all services that have local occupants and include them in the reply
    for (MultiUserChatService mucService : XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatServices()) {
        // Get rooms that have local occupants and include them in the reply
        for (MUCRoom room : mucService.getChatRooms()) {
            LocalMUCRoom localRoom = (LocalMUCRoom) room;
            Collection<MUCRole> localOccupants = new ArrayList<>();
            for (MUCRole occupant : room.getOccupants()) {
                if (occupant.isLocal()) {
                    localOccupants.add(occupant);
                }
            }
            if (!localOccupants.isEmpty()) {
                rooms.add(new RoomInfo(localRoom, localOccupants));
            }
        }
    }
}
Also used : MUCRole(org.jivesoftware.openfire.muc.MUCRole) MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom) LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom) ArrayList(java.util.ArrayList) MultiUserChatService(org.jivesoftware.openfire.muc.MultiUserChatService)

Aggregations

MUCRoom (org.jivesoftware.openfire.muc.MUCRoom)20 ArrayList (java.util.ArrayList)6 Date (java.util.Date)5 Element (org.dom4j.Element)5 LocalMUCRoom (org.jivesoftware.openfire.muc.spi.LocalMUCRoom)5 JID (org.xmpp.packet.JID)5 MultiUserChatService (org.jivesoftware.openfire.muc.MultiUserChatService)4 NotAllowedException (org.jivesoftware.openfire.muc.NotAllowedException)3 DataForm (org.xmpp.forms.DataForm)3 ArchivedMessage (com.reucon.openfire.plugin.archive.model.ArchivedMessage)2 List (java.util.List)2 MUCRoomEntity (org.jivesoftware.openfire.entity.MUCRoomEntity)2 ConflictException (org.jivesoftware.openfire.muc.ConflictException)2 ForbiddenException (org.jivesoftware.openfire.muc.ForbiddenException)2 MUCRole (org.jivesoftware.openfire.muc.MUCRole)2 MUCRoomEntity (org.jivesoftware.openfire.plugin.rest.entity.MUCRoomEntity)2 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)2 FormField (org.xmpp.forms.FormField)2 IQ (org.xmpp.packet.IQ)2 Presence (org.xmpp.packet.Presence)2