Search in sources :

Example 1 with MultiUserChatService

use of org.jivesoftware.openfire.muc.MultiUserChatService 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 2 with MultiUserChatService

use of org.jivesoftware.openfire.muc.MultiUserChatService 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)

Example 3 with MultiUserChatService

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

the class MUCRoomTask method getRoom.

public LocalMUCRoom getRoom() {
    MultiUserChatService mucService = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(subdomain);
    if (mucService == null) {
        throw new IllegalArgumentException("MUC service not found for subdomain: " + subdomain);
    }
    LocalMUCRoom room = (LocalMUCRoom) mucService.getChatRoom(roomName);
    if (room == null) {
        throw new IllegalArgumentException("Room not found: " + roomName);
    }
    return room;
}
Also used : LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom) MultiUserChatService(org.jivesoftware.openfire.muc.MultiUserChatService)

Example 4 with MultiUserChatService

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

the class RoomRemovedEvent method run.

@Override
public void run() {
    MultiUserChatService mucService = room.getMUCService();
    mucService.chatRoomRemoved(room);
}
Also used : MultiUserChatService(org.jivesoftware.openfire.muc.MultiUserChatService)

Example 5 with MultiUserChatService

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

the class OccupantUpdatedTask method run.

@Override
public void run() {
    final MultiUserChatService multiUserChatService = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(subdomain);
    ((MultiUserChatServiceImpl) multiUserChatService).getOccupantManager().process(this);
}
Also used : MultiUserChatService(org.jivesoftware.openfire.muc.MultiUserChatService)

Aggregations

MultiUserChatService (org.jivesoftware.openfire.muc.MultiUserChatService)17 MUCRoom (org.jivesoftware.openfire.muc.MUCRoom)5 MUCRole (org.jivesoftware.openfire.muc.MUCRole)3 MultiUserChatManager (org.jivesoftware.openfire.muc.MultiUserChatManager)3 MultiUserChatServiceImpl (org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl)3 JID (org.xmpp.packet.JID)3 ArchivedMessage (com.reucon.openfire.plugin.archive.model.ArchivedMessage)2 Date (java.util.Date)2 List (java.util.List)2 Lock (java.util.concurrent.locks.Lock)2 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)2 ServerFeaturesProvider (org.jivesoftware.openfire.disco.ServerFeaturesProvider)2 IQHandler (org.jivesoftware.openfire.handler.IQHandler)2 NotAllowedException (org.jivesoftware.openfire.muc.NotAllowedException)2 LocalMUCRoom (org.jivesoftware.openfire.muc.spi.LocalMUCRoom)2 XmppResultSet (com.reucon.openfire.plugin.archive.xep0059.XmppResultSet)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1