Search in sources :

Example 1 with PrivateMessage

use of net.jforum.entities.PrivateMessage in project jforum2 by rafaelsteil.

the class GenericPrivateMessageDAO method selectFromSent.

/**
	 * @see net.jforum.dao.PrivateMessageDAO#selectFromSent(net.jforum.entities.User)
	 */
public List selectFromSent(User user) {
    String query = SystemGlobals.getSql("PrivateMessageModel.baseListing");
    query = query.replaceAll("#FILTER#", SystemGlobals.getSql("PrivateMessageModel.sent"));
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(query);
        p.setInt(1, user.getId());
        List pmList = new ArrayList();
        rs = p.executeQuery();
        while (rs.next()) {
            PrivateMessage pm = this.getPm(rs, false);
            User toUser = new User();
            toUser.setId(rs.getInt("user_id"));
            toUser.setUsername(rs.getString("username"));
            pm.setToUser(toUser);
            pmList.add(pm);
        }
        return pmList;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : User(net.jforum.entities.User) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ArrayList(java.util.ArrayList) List(java.util.List) PrivateMessage(net.jforum.entities.PrivateMessage) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 2 with PrivateMessage

use of net.jforum.entities.PrivateMessage in project jforum2 by rafaelsteil.

the class GenericPrivateMessageDAO method getPm.

protected PrivateMessage getPm(ResultSet rs, boolean full) throws SQLException {
    PrivateMessage pm = new PrivateMessage();
    Post p = new Post();
    pm.setId(rs.getInt("privmsgs_id"));
    pm.setType(rs.getInt("privmsgs_type"));
    p.setTime(new Date(rs.getTimestamp("privmsgs_date").getTime()));
    p.setSubject(rs.getString("privmsgs_subject"));
    SimpleDateFormat df = new SimpleDateFormat(SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
    pm.setFormatedDate(df.format(p.getTime()));
    if (full) {
        UserDAO um = DataAccessDriver.getInstance().newUserDAO();
        pm.setFromUser(um.selectById(rs.getInt("privmsgs_from_userid")));
        pm.setToUser(um.selectById(rs.getInt("privmsgs_to_userid")));
        p.setBbCodeEnabled(rs.getInt("privmsgs_enable_bbcode") == 1);
        p.setSignatureEnabled(rs.getInt("privmsgs_attach_sig") == 1);
        p.setHtmlEnabled(rs.getInt("privmsgs_enable_html") == 1);
        p.setSmiliesEnabled(rs.getInt("privmsgs_enable_smilies") == 1);
        p.setText(this.getPmText(rs));
    }
    pm.setPost(p);
    return pm;
}
Also used : UserDAO(net.jforum.dao.UserDAO) Post(net.jforum.entities.Post) PrivateMessage(net.jforum.entities.PrivateMessage) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 3 with PrivateMessage

use of net.jforum.entities.PrivateMessage in project jforum2 by rafaelsteil.

the class PrivateMessageAction method reply.

public void reply() {
    if (!SessionFacade.isLogged()) {
        this.setTemplateName(ViewCommon.contextToLogin());
        return;
    }
    int id = this.request.getIntParameter("id");
    PrivateMessage pm = new PrivateMessage();
    pm.setId(id);
    pm = DataAccessDriver.getInstance().newPrivateMessageDAO().selectById(pm);
    int userId = SessionFacade.getUserSession().getUserId();
    if (pm.getToUser().getId() != userId && pm.getFromUser().getId() != userId) {
        this.setTemplateName(TemplateKeys.PM_READ_DENIED);
        this.context.put("message", I18n.getMessage("PrivateMessage.readDenied"));
        return;
    }
    pm.getPost().setSubject(I18n.getMessage("PrivateMessage.replyPrefix") + pm.getPost().getSubject());
    this.context.put("pm", pm);
    this.context.put("pmReply", true);
    this.sendFormCommon(DataAccessDriver.getInstance().newUserDAO().selectById(SessionFacade.getUserSession().getUserId()));
}
Also used : PrivateMessage(net.jforum.entities.PrivateMessage)

Example 4 with PrivateMessage

use of net.jforum.entities.PrivateMessage in project jforum2 by rafaelsteil.

the class PrivateMessageAction method read.

public void read() {
    if (!SessionFacade.isLogged()) {
        this.setTemplateName(ViewCommon.contextToLogin());
        return;
    }
    int id = this.request.getIntParameter("id");
    PrivateMessage pm = new PrivateMessage();
    pm.setId(id);
    pm = DataAccessDriver.getInstance().newPrivateMessageDAO().selectById(pm);
    // Don't allow the read of messages that don't belongs
    // to the current user
    UserSession us = SessionFacade.getUserSession();
    int userId = us.getUserId();
    if (pm.getToUser().getId() == userId || pm.getFromUser().getId() == userId) {
        pm.getPost().setText(PostCommon.preparePostForDisplay(pm.getPost()).getText());
        // Update the message status, if needed
        if (pm.getType() == PrivateMessageType.NEW) {
            pm.setType(PrivateMessageType.READ);
            DataAccessDriver.getInstance().newPrivateMessageDAO().updateType(pm);
            int totalMessages = us.getPrivateMessages();
            if (totalMessages > 0) {
                us.setPrivateMessages(totalMessages - 1);
            }
        }
        User u = pm.getFromUser();
        ViewCommon.prepareUserSignature(u);
        this.context.put("pm", pm);
        this.setTemplateName(TemplateKeys.PM_READ);
    } else {
        this.setTemplateName(TemplateKeys.PM_READ_DENIED);
        this.context.put("message", I18n.getMessage("PrivateMessage.readDenied"));
    }
}
Also used : User(net.jforum.entities.User) UserSession(net.jforum.entities.UserSession) PrivateMessage(net.jforum.entities.PrivateMessage)

Example 5 with PrivateMessage

use of net.jforum.entities.PrivateMessage in project jforum2 by rafaelsteil.

the class PrivateMessageAction method delete.

public void delete() {
    if (!SessionFacade.isLogged()) {
        this.setTemplateName(ViewCommon.contextToLogin());
        return;
    }
    String[] ids = this.request.getParameterValues("id");
    if (ids != null && ids.length > 0) {
        PrivateMessage[] deleteList = new PrivateMessage[ids.length];
        int unreadCount = 0;
        PrivateMessageDAO dao = DataAccessDriver.getInstance().newPrivateMessageDAO();
        for (int i = 0; i < ids.length; i++) {
            PrivateMessage pm = dao.selectById(new PrivateMessage(Integer.parseInt(ids[i])));
            if (pm.getType() == PrivateMessageType.NEW) {
                unreadCount++;
            }
            deleteList[i] = pm;
        }
        UserSession userSession = SessionFacade.getUserSession();
        dao.delete(deleteList, userSession.getUserId());
        // Subtracts the number of delete messages
        int total = userSession.getPrivateMessages() - unreadCount;
        if (total < 0) {
            total = 0;
        }
        userSession.setPrivateMessages(total);
    }
    this.setTemplateName(TemplateKeys.PM_DELETE);
    this.context.put("message", I18n.getMessage("PrivateMessage.deleteDone", new String[] { this.request.getContextPath() + "/pm/inbox" + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION) }));
}
Also used : PrivateMessageDAO(net.jforum.dao.PrivateMessageDAO) UserSession(net.jforum.entities.UserSession) PrivateMessage(net.jforum.entities.PrivateMessage)

Aggregations

PrivateMessage (net.jforum.entities.PrivateMessage)9 User (net.jforum.entities.User)4 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 List (java.util.List)3 UserSession (net.jforum.entities.UserSession)3 DatabaseException (net.jforum.exceptions.DatabaseException)3 ArrayList (java.util.ArrayList)2 UserDAO (net.jforum.dao.UserDAO)2 Post (net.jforum.entities.Post)2 Connection (java.sql.Connection)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 PrivateMessageDAO (net.jforum.dao.PrivateMessageDAO)1 EmailSenderTask (net.jforum.util.mail.EmailSenderTask)1 PrivateMessageSpammer (net.jforum.util.mail.PrivateMessageSpammer)1