Search in sources :

Example 1 with Conversation

use of com.reucon.openfire.plugin.archive.model.Conversation in project Openfire by igniterealtime.

the class ArchiveManagerImpl method archiveMessage.

public void archiveMessage(Session session, Message message, boolean incoming) {
    final XMPPServer server = XMPPServer.getInstance();
    final ArchivedMessage.Direction direction;
    final ArchivedMessage archivedMessage;
    final Conversation conversation;
    final JID ownerJid;
    final JID withJid;
    // TODO support groupchat
    if (message.getType() != Message.Type.chat && message.getType() != Message.Type.normal) {
        return;
    }
    if (server.isLocal(message.getFrom()) && incoming) {
        ownerJid = message.getFrom();
        withJid = message.getTo();
        // sent by the owner => to
        direction = ArchivedMessage.Direction.to;
    } else if (server.isLocal(message.getTo()) && !incoming) {
        ownerJid = message.getTo();
        withJid = message.getFrom();
        // received by the owner => from
        direction = ArchivedMessage.Direction.from;
    } else {
        return;
    }
    archivedMessage = ArchiveFactory.createArchivedMessage(session, message, direction, withJid);
    if (archivedMessage.isEmpty()) {
        return;
    }
    conversation = determineConversation(ownerJid, withJid, message.getSubject(), message.getThread(), archivedMessage);
    archivedMessage.setConversation(conversation);
    persistenceManager.createMessage(archivedMessage);
    if (indexManager != null) {
        indexManager.indexObject(archivedMessage);
    }
}
Also used : XMPPServer(org.jivesoftware.openfire.XMPPServer) JID(org.xmpp.packet.JID) ArchivedMessage(com.reucon.openfire.plugin.archive.model.ArchivedMessage) Conversation(com.reucon.openfire.plugin.archive.model.Conversation)

Example 2 with Conversation

use of com.reucon.openfire.plugin.archive.model.Conversation in project Openfire by igniterealtime.

the class ArchiveManagerImpl method determineConversation.

private Conversation determineConversation(JID ownerJid, JID withJid, String subject, String thread, ArchivedMessage archivedMessage) {
    Conversation conversation = null;
    Collection<Conversation> staleConversations;
    staleConversations = new ArrayList<Conversation>();
    synchronized (activeConversations) {
        for (Conversation c : activeConversations) {
            if (c.isStale(conversationTimeout)) {
                staleConversations.add(c);
                continue;
            }
            if (matches(ownerJid, withJid, thread, c)) {
                conversation = c;
                break;
            }
        }
        activeConversations.removeAll(staleConversations);
        if (conversation == null) {
            final Participant p1;
            final Participant p2;
            conversation = new Conversation(archivedMessage.getTime(), ownerJid.toBareJID(), ownerJid.getResource(), withJid.toBareJID(), withJid.getResource(), subject, thread);
            persistenceManager.createConversation(conversation);
            p1 = new Participant(archivedMessage.getTime(), ownerJid.toBareJID());
            conversation.addParticipant(p1);
            persistenceManager.createParticipant(p1, conversation.getId());
            p2 = new Participant(archivedMessage.getTime(), withJid.toBareJID());
            conversation.addParticipant(p2);
            persistenceManager.createParticipant(p2, conversation.getId());
            activeConversations.add(conversation);
        } else {
            conversation.setEnd(archivedMessage.getTime());
            persistenceManager.updateConversationEnd(conversation);
        }
    }
    return conversation;
}
Also used : Participant(com.reucon.openfire.plugin.archive.model.Participant) Conversation(com.reucon.openfire.plugin.archive.model.Conversation)

Example 3 with Conversation

use of com.reucon.openfire.plugin.archive.model.Conversation in project Openfire by igniterealtime.

the class IQListHandler method handleIQ.

public IQ handleIQ(IQ packet) throws UnauthorizedException {
    IQ reply = IQ.createResultIQ(packet);
    ListRequest listRequest = new ListRequest(packet.getChildElement());
    JID from = packet.getFrom();
    Element listElement = reply.setChildElement("list", NAMESPACE);
    Collection<Conversation> conversations = list(from, listRequest);
    XmppResultSet resultSet = listRequest.getResultSet();
    for (Conversation conversation : conversations) {
        addChatElement(listElement, conversation);
    }
    if (resultSet != null) {
        listElement.add(resultSet.createResultElement());
    }
    return reply;
}
Also used : JID(org.xmpp.packet.JID) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) Conversation(com.reucon.openfire.plugin.archive.model.Conversation) XmppResultSet(com.reucon.openfire.plugin.archive.xep0059.XmppResultSet)

Example 4 with Conversation

use of com.reucon.openfire.plugin.archive.model.Conversation in project Openfire by igniterealtime.

the class JdbcPersistenceManager method getConversation.

private Conversation getConversation(Long conversationId, String ownerJid, String withJid, Date start) {
    Conversation conversation = null;
    StringBuilder querySB;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    querySB = new StringBuilder(SELECT_CONVERSATIONS);
    querySB.append(" WHERE ");
    if (conversationId != null) {
        querySB.append(CONVERSATION_ID).append(" = ? ");
    } else {
        querySB.append(CONVERSATION_OWNER_JID).append(" = ?");
        if (withJid != null) {
            querySB.append(" AND ");
            querySB.append(CONVERSATION_WITH_JID).append(" = ? ");
        }
        if (start != null) {
            querySB.append(" AND ");
            querySB.append(CONVERSATION_START_TIME).append(" = ? ");
        }
    }
    querySB.append(SELECT_CONVERSATIONS_GROUP_BY);
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(querySB.toString());
        int i = 1;
        if (conversationId != null) {
            pstmt.setLong(1, conversationId);
        } else {
            pstmt.setString(i++, ownerJid);
            if (withJid != null) {
                pstmt.setString(i++, withJid);
            }
            if (start != null) {
                pstmt.setLong(i++, dateToMillis(start));
            }
        }
        rs = pstmt.executeQuery();
        Log.debug("getConversation: SELECT_CONVERSATIONS: " + pstmt.toString());
        if (rs.next()) {
            conversation = extractConversation(rs);
        } else {
            return null;
        }
        rs.close();
        pstmt.close();
        pstmt = con.prepareStatement(SELECT_PARTICIPANTS_BY_CONVERSATION);
        pstmt.setLong(1, conversation.getId());
        rs = pstmt.executeQuery();
        Log.debug("getConversation: SELECT_PARTICIPANTS_BY_CONVERSATION: " + pstmt.toString());
        while (rs.next()) {
            for (Participant participant : extractParticipant(rs)) {
                conversation.addParticipant(participant);
            }
        }
        rs.close();
        pstmt.close();
        pstmt = con.prepareStatement(SELECT_MESSAGES_BY_CONVERSATION);
        pstmt.setLong(1, conversation.getId());
        pstmt.setString(2, conversation.getOwnerJid());
        rs = pstmt.executeQuery();
        Log.debug("getConversation: SELECT_MESSAGES_BY_CONVERSATION: " + pstmt.toString());
        while (rs.next()) {
            ArchivedMessage message;
            message = extractMessage(rs);
            message.setConversation(conversation);
            conversation.addMessage(message);
        }
    } catch (SQLException sqle) {
        Log.error("Error selecting conversation", sqle);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    return conversation;
}
Also used : Participant(com.reucon.openfire.plugin.archive.model.Participant) ArchivedMessage(com.reucon.openfire.plugin.archive.model.ArchivedMessage) SQLException(java.sql.SQLException) Connection(java.sql.Connection) XmppResultSet(com.reucon.openfire.plugin.archive.xep0059.XmppResultSet) ResultSet(java.sql.ResultSet) Conversation(com.reucon.openfire.plugin.archive.model.Conversation) PreparedStatement(java.sql.PreparedStatement)

Example 5 with Conversation

use of com.reucon.openfire.plugin.archive.model.Conversation in project Openfire by igniterealtime.

the class JdbcPersistenceManager method extractConversation.

private Conversation extractConversation(ResultSet rs) throws SQLException {
    final Conversation conversation;
    long id = rs.getLong("conversationID");
    Date startDate = millisToDate(rs.getLong("startDate"));
    String ownerJid = rs.getString("bareJID");
    String ownerResource = null;
    String withJid = getWithJidConversations(rs);
    String withResource = null;
    String subject = null;
    String thread = String.valueOf(id);
    conversation = new Conversation(startDate, ownerJid, ownerResource, withJid, withResource, subject, thread);
    conversation.setId(id);
    return conversation;
}
Also used : Conversation(com.reucon.openfire.plugin.archive.model.Conversation) Date(java.util.Date)

Aggregations

Conversation (com.reucon.openfire.plugin.archive.model.Conversation)9 XmppResultSet (com.reucon.openfire.plugin.archive.xep0059.XmppResultSet)6 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 ArchivedMessage (com.reucon.openfire.plugin.archive.model.ArchivedMessage)3 Participant (com.reucon.openfire.plugin.archive.model.Participant)2 Element (org.dom4j.Element)2 IQ (org.xmpp.packet.IQ)2 JID (org.xmpp.packet.JID)2 Date (java.util.Date)1 XMPPServer (org.jivesoftware.openfire.XMPPServer)1